Fortran: fix ICE with use with rename of namelist member [PR116530]
[official-gcc.git] / gcc / ada / sem_util.adb
blobac64b1ca549617f8a9abd4972675379474951a1a
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-2024, 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 Exp_Ch6; use Exp_Ch6;
34 with Exp_Ch11; use Exp_Ch11;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
38 with Itypes; use Itypes;
39 with Lib; use Lib;
40 with Lib.Xref; use Lib.Xref;
41 with Mutably_Tagged; use Mutably_Tagged;
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_Dim; use Sem_Dim;
57 with Sem_Disp; use Sem_Disp;
58 with Sem_Elab; use Sem_Elab;
59 with Sem_Eval; use Sem_Eval;
60 with Sem_Prag; use Sem_Prag;
61 with Sem_Res; use Sem_Res;
62 with Sem_Warn; use Sem_Warn;
63 with Sem_Type; use Sem_Type;
64 with Sinfo; use Sinfo;
65 with Sinfo.Nodes; use Sinfo.Nodes;
66 with Sinfo.Utils; use Sinfo.Utils;
67 with Sinput; use Sinput;
68 with Stand; use Stand;
69 with Style;
70 with Stringt; use Stringt;
71 with Targparm; use Targparm;
72 with Tbuild; use Tbuild;
73 with Ttypes; use Ttypes;
74 with Uname; use Uname;
75 with Warnsw; use Warnsw;
77 with GNAT.Heap_Sort_G;
78 with GNAT.HTable; use GNAT.HTable;
80 package body Sem_Util is
82 ---------------------------
83 -- Local Data Structures --
84 ---------------------------
86 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
87 -- A collection to hold the entities of the variables declared in package
88 -- System.Scalar_Values which describe the invalid values of scalar types.
90 Invalid_Binder_Values_Set : Boolean := False;
91 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
93 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
94 -- A collection to hold the invalid values of float types as specified by
95 -- pragma Initialize_Scalars.
97 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
98 -- A collection to hold the invalid values of integer types as specified
99 -- by pragma Initialize_Scalars.
101 -----------------------
102 -- Local Subprograms --
103 -----------------------
105 function Build_Component_Subtype
106 (C : List_Id;
107 Loc : Source_Ptr;
108 T : Entity_Id) return Node_Id;
109 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
110 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
111 -- Loc is the source location, T is the original subtype.
113 procedure Examine_Array_Bounds
114 (Typ : Entity_Id;
115 All_Static : out Boolean;
116 Has_Empty : out Boolean);
117 -- Inspect the index constraints of array type Typ. Flag All_Static is set
118 -- when all ranges are static. Flag Has_Empty is set only when All_Static
119 -- is set and indicates that at least one range is empty.
121 function Has_Enabled_Property
122 (Item_Id : Entity_Id;
123 Property : Name_Id) return Boolean;
124 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
125 -- Determine whether the state abstraction, object, or type denoted by
126 -- entity Item_Id has enabled property Property.
128 function Has_Null_Extension (T : Entity_Id) return Boolean;
129 -- T is a derived tagged type. Check whether the type extension is null.
130 -- If the parent type is fully initialized, T can be treated as such.
132 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean;
133 -- Determine whether arbitrary entity Id denotes an atomic object as per
134 -- RM C.6(7).
136 generic
137 with function Is_Effectively_Volatile_Entity
138 (Id : Entity_Id) return Boolean;
139 -- Function to use on object and type entities
140 function Is_Effectively_Volatile_Object_Shared
141 (N : Node_Id) return Boolean;
142 -- Shared function used to detect effectively volatile objects and
143 -- effectively volatile objects for reading.
145 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
146 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
147 -- with discriminants whose default values are static, examine only the
148 -- components in the selected variant to determine whether all of them
149 -- have a default.
151 function Is_Preelaborable_Function (Id : Entity_Id) return Boolean;
152 -- Ada 2022: Determine whether the specified function is suitable as the
153 -- name of a call in a preelaborable construct (RM 10.2.1(7/5)).
155 type Null_Status_Kind is
156 (Is_Null,
157 -- This value indicates that a subexpression is known to have a null
158 -- value at compile time.
160 Is_Non_Null,
161 -- This value indicates that a subexpression is known to have a non-null
162 -- value at compile time.
164 Unknown);
165 -- This value indicates that it cannot be determined at compile time
166 -- whether a subexpression yields a null or non-null value.
168 function Null_Status (N : Node_Id) return Null_Status_Kind;
169 -- Determine whether subexpression N of an access type yields a null value,
170 -- a non-null value, or the value cannot be determined at compile time. The
171 -- routine does not take simple flow diagnostics into account, it relies on
172 -- static facts such as the presence of null exclusions.
174 -----------------------------
175 -- Abstract_Interface_List --
176 -----------------------------
178 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
179 Nod : Node_Id;
181 begin
182 if Is_Concurrent_Type (Typ) then
184 -- If we are dealing with a synchronized subtype, go to the base
185 -- type, whose declaration has the interface list.
187 Nod := Declaration_Node (Base_Type (Typ));
189 if Nkind (Nod) in N_Full_Type_Declaration | N_Private_Type_Declaration
190 then
191 return Empty_List;
192 end if;
194 elsif Ekind (Typ) = E_Record_Type_With_Private then
195 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
196 Nod := Type_Definition (Parent (Typ));
198 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
199 if Present (Full_View (Typ))
200 and then
201 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
202 then
203 Nod := Type_Definition (Parent (Full_View (Typ)));
205 -- If the full-view is not available we cannot do anything else
206 -- here (the source has errors).
208 else
209 return Empty_List;
210 end if;
212 -- Support for generic formals with interfaces is still missing ???
214 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
215 return Empty_List;
217 else
218 pragma Assert
219 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
220 Nod := Parent (Typ);
221 end if;
223 elsif Ekind (Typ) = E_Record_Subtype then
224 Nod := Type_Definition (Parent (Etype (Typ)));
226 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
228 -- Recurse, because parent may still be a private extension. Also
229 -- note that the full view of the subtype or the full view of its
230 -- base type may (both) be unavailable.
232 return Abstract_Interface_List (Etype (Typ));
234 elsif Ekind (Typ) = E_Record_Type then
235 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
236 Nod := Formal_Type_Definition (Parent (Typ));
237 else
238 Nod := Type_Definition (Parent (Typ));
239 end if;
241 -- Otherwise the type is of a kind which does not implement interfaces
243 else
244 return Empty_List;
245 end if;
247 return Interface_List (Nod);
248 end Abstract_Interface_List;
250 ----------------------------------
251 -- Acquire_Warning_Match_String --
252 ----------------------------------
254 function Acquire_Warning_Match_String (Str_Lit : Node_Id) return String is
255 S : constant String := To_String (Strval (Str_Lit));
256 begin
257 if S = "" then
258 return "";
259 else
260 -- Put "*" before or after or both, if it's not already there
262 declare
263 F : constant Boolean := S (S'First) = '*';
264 L : constant Boolean := S (S'Last) = '*';
265 begin
266 if F then
267 if L then
268 return S;
269 else
270 return S & "*";
271 end if;
272 else
273 if L then
274 return "*" & S;
275 else
276 return "*" & S & "*";
277 end if;
278 end if;
279 end;
280 end if;
281 end Acquire_Warning_Match_String;
283 --------------------------------
284 -- Add_Access_Type_To_Process --
285 --------------------------------
287 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
288 L : Elist_Id;
290 begin
291 Ensure_Freeze_Node (E);
292 L := Access_Types_To_Process (Freeze_Node (E));
294 if No (L) then
295 L := New_Elmt_List;
296 Set_Access_Types_To_Process (Freeze_Node (E), L);
297 end if;
299 Append_Elmt (A, L);
300 end Add_Access_Type_To_Process;
302 --------------------------
303 -- Add_Block_Identifier --
304 --------------------------
306 procedure Add_Block_Identifier
307 (N : Node_Id;
308 Id : out Entity_Id;
309 Scope : Entity_Id := Current_Scope)
311 Loc : constant Source_Ptr := Sloc (N);
313 begin
314 pragma Assert (Nkind (N) = N_Block_Statement);
316 -- The block already has a label, return its entity
318 if Present (Identifier (N)) then
319 Id := Entity (Identifier (N));
321 -- Create a new block label and set its attributes
323 else
324 Id := New_Internal_Entity (E_Block, Scope, Loc, 'B');
325 Set_Etype (Id, Standard_Void_Type);
326 Set_Parent (Id, N);
327 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
328 Set_Block_Node (Id, Identifier (N));
329 end if;
330 end Add_Block_Identifier;
332 ----------------------------
333 -- Add_Global_Declaration --
334 ----------------------------
336 procedure Add_Global_Declaration (N : Node_Id) is
337 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
339 begin
340 if No (Declarations (Aux_Node)) then
341 Set_Declarations (Aux_Node, New_List);
342 end if;
344 Append_To (Declarations (Aux_Node), N);
345 Analyze (N);
346 end Add_Global_Declaration;
348 --------------------------------
349 -- Address_Integer_Convert_OK --
350 --------------------------------
352 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
353 begin
354 if Allow_Integer_Address
355 and then ((Is_Descendant_Of_Address (T1)
356 and then Is_Private_Type (T1)
357 and then Is_Integer_Type (T2))
358 or else
359 (Is_Descendant_Of_Address (T2)
360 and then Is_Private_Type (T2)
361 and then Is_Integer_Type (T1)))
362 then
363 return True;
364 else
365 return False;
366 end if;
367 end Address_Integer_Convert_OK;
369 -------------------
370 -- Address_Value --
371 -------------------
373 function Address_Value (N : Node_Id) return Node_Id is
374 Expr : Node_Id := N;
376 begin
377 loop
378 -- For constant, get constant expression
380 if Is_Entity_Name (Expr)
381 and then Ekind (Entity (Expr)) = E_Constant
382 then
383 Expr := Constant_Value (Entity (Expr));
385 -- For unchecked conversion, get result to convert
387 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
388 Expr := Expression (Expr);
390 -- For (common case) of To_Address call, get argument
392 elsif Nkind (Expr) = N_Function_Call
393 and then Is_Entity_Name (Name (Expr))
394 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
395 then
396 Expr := First_Actual (Expr);
398 -- We finally have the real expression
400 else
401 exit;
402 end if;
403 end loop;
405 return Expr;
406 end Address_Value;
408 -----------------
409 -- Addressable --
410 -----------------
412 function Addressable (V : Uint) return Boolean is
413 begin
414 if No (V) then
415 return False;
416 end if;
418 return V = Uint_8 or else
419 V = Uint_16 or else
420 V = Uint_32 or else
421 V = Uint_64 or else
422 (V = Uint_128 and then System_Max_Integer_Size = 128);
423 end Addressable;
425 function Addressable (V : Int) return Boolean is
426 begin
427 return V = 8 or else
428 V = 16 or else
429 V = 32 or else
430 V = 64 or else
431 V = System_Max_Integer_Size;
432 end Addressable;
434 ---------------------------------
435 -- Aggregate_Constraint_Checks --
436 ---------------------------------
438 procedure Aggregate_Constraint_Checks
439 (Exp : Node_Id;
440 Check_Typ : Entity_Id)
442 Exp_Typ : constant Entity_Id := Etype (Exp);
444 begin
445 if Raises_Constraint_Error (Exp) then
446 return;
447 end if;
449 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
450 -- component's type to force the appropriate accessibility checks.
452 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
453 -- force the corresponding run-time check
455 if Is_Access_Type (Check_Typ)
456 and then Is_Local_Anonymous_Access (Check_Typ)
457 then
458 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
459 Analyze_And_Resolve (Exp, Check_Typ);
460 Check_Unset_Reference (Exp);
461 end if;
463 -- What follows is really expansion activity, so check that expansion
464 -- is on and is allowed. In GNATprove mode, we also want check flags to
465 -- be added in the tree, so that the formal verification can rely on
466 -- those to be present. In GNATprove mode for formal verification, some
467 -- treatment typically only done during expansion needs to be performed
468 -- on the tree, but it should not be applied inside generics. Otherwise,
469 -- this breaks the name resolution mechanism for generic instances.
471 if not Expander_Active
472 and not (GNATprove_Mode and not Inside_A_Generic)
473 then
474 return;
475 end if;
477 if Is_Access_Type (Check_Typ)
478 and then Can_Never_Be_Null (Check_Typ)
479 and then not Can_Never_Be_Null (Exp_Typ)
480 then
481 Install_Null_Excluding_Check (Exp);
482 end if;
484 -- First check if we have to insert discriminant checks
486 if Has_Discriminants (Exp_Typ) then
487 Apply_Discriminant_Check (Exp, Check_Typ);
489 -- Next emit length checks for array aggregates
491 elsif Is_Array_Type (Exp_Typ) then
492 Apply_Length_Check (Exp, Check_Typ);
494 -- Finally emit scalar and string checks. If we are dealing with a
495 -- scalar literal we need to check by hand because the Etype of
496 -- literals is not necessarily correct.
498 elsif Is_Scalar_Type (Exp_Typ)
499 and then Compile_Time_Known_Value (Exp)
500 then
501 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
502 Apply_Compile_Time_Constraint_Error
503 (Exp, "value not in range of}??", CE_Range_Check_Failed,
504 Ent => Base_Type (Check_Typ),
505 Typ => Base_Type (Check_Typ));
507 elsif Is_Out_Of_Range (Exp, Check_Typ) then
508 Apply_Compile_Time_Constraint_Error
509 (Exp, "value not in range of}??", CE_Range_Check_Failed,
510 Ent => Check_Typ,
511 Typ => Check_Typ);
513 elsif not Range_Checks_Suppressed (Check_Typ) then
514 Apply_Scalar_Range_Check (Exp, Check_Typ);
515 end if;
517 -- Verify that target type is also scalar, to prevent view anomalies
518 -- in instantiations.
520 elsif (Is_Scalar_Type (Exp_Typ)
521 or else Nkind (Exp) = N_String_Literal)
522 and then Is_Scalar_Type (Check_Typ)
523 and then Exp_Typ /= Check_Typ
524 then
525 -- If expression is a constant, it is worthwhile checking whether it
526 -- is a bound of the type.
528 if Is_Entity_Name (Exp)
529 and then Ekind (Entity (Exp)) = E_Constant
530 then
531 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
532 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
533 or else
534 (Is_Entity_Name (Type_High_Bound (Check_Typ))
535 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
536 then
537 return;
538 end if;
539 end if;
541 -- Change Exp into Check_Typ'(Exp) to ensure that range checks are
542 -- performed at run time.
544 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
545 Analyze_And_Resolve (Exp, Check_Typ);
546 Check_Unset_Reference (Exp);
548 end if;
549 end Aggregate_Constraint_Checks;
551 -----------------------
552 -- Alignment_In_Bits --
553 -----------------------
555 function Alignment_In_Bits (E : Entity_Id) return Uint is
556 begin
557 return Alignment (E) * System_Storage_Unit;
558 end Alignment_In_Bits;
560 --------------------------------------
561 -- All_Composite_Constraints_Static --
562 --------------------------------------
564 function All_Composite_Constraints_Static
565 (Constr : Node_Id) return Boolean
567 begin
568 if No (Constr) or else Error_Posted (Constr) then
569 return True;
570 end if;
572 case Nkind (Constr) is
573 when N_Subexpr =>
574 if Nkind (Constr) in N_Has_Entity
575 and then Present (Entity (Constr))
576 then
577 if Is_Type (Entity (Constr)) then
578 return
579 not Is_Discrete_Type (Entity (Constr))
580 or else Is_OK_Static_Subtype (Entity (Constr));
581 end if;
583 elsif Nkind (Constr) = N_Range then
584 return
585 Is_OK_Static_Expression (Low_Bound (Constr))
586 and then
587 Is_OK_Static_Expression (High_Bound (Constr));
589 elsif Nkind (Constr) = N_Attribute_Reference
590 and then Attribute_Name (Constr) = Name_Range
591 then
592 return
593 Is_OK_Static_Expression
594 (Type_Low_Bound (Etype (Prefix (Constr))))
595 and then
596 Is_OK_Static_Expression
597 (Type_High_Bound (Etype (Prefix (Constr))));
598 end if;
600 return
601 No (Etype (Constr)) -- previous error
602 or else not Is_Discrete_Type (Etype (Constr))
603 or else Is_OK_Static_Expression (Constr);
605 when N_Discriminant_Association =>
606 return All_Composite_Constraints_Static (Expression (Constr));
608 when N_Range_Constraint =>
609 return
610 All_Composite_Constraints_Static (Range_Expression (Constr));
612 when N_Index_Or_Discriminant_Constraint =>
613 declare
614 One_Cstr : Entity_Id;
615 begin
616 One_Cstr := First (Constraints (Constr));
617 while Present (One_Cstr) loop
618 if not All_Composite_Constraints_Static (One_Cstr) then
619 return False;
620 end if;
622 Next (One_Cstr);
623 end loop;
624 end;
626 return True;
628 when N_Subtype_Indication =>
629 return
630 All_Composite_Constraints_Static (Subtype_Mark (Constr))
631 and then
632 All_Composite_Constraints_Static (Constraint (Constr));
634 when others =>
635 raise Program_Error;
636 end case;
637 end All_Composite_Constraints_Static;
639 ------------------------
640 -- Append_Entity_Name --
641 ------------------------
643 procedure Append_Entity_Name
644 (Buf : in out Bounded_String; E : Entity_Id)
646 Scop : constant Node_Id := Scope (E);
647 -- We recursively print the scope to Buf, and then print the simple
648 -- name, along with some special cases (see below). So for A.B.C.D,
649 -- recursively print A.B.C, then print D.
650 begin
651 -- If E is not a source entity, then skip the simple name and just
652 -- recursively print its scope. However, subprogram instances have
653 -- Comes_From_Source = False, but we do want to print the simple name
654 -- of the instance.
656 if not Comes_From_Source (E) then
657 if Is_Generic_Instance (E)
658 and then Ekind (E) in E_Function | E_Procedure
659 then
660 null;
661 else
662 Append_Entity_Name (Buf, Scope (E));
663 return;
664 end if;
665 end if;
667 -- Just print entity name if its scope is at the outer level
669 if No (Scop) or Scop = Standard_Standard then
670 null;
672 -- If scope comes from source, write scope and entity
674 elsif Comes_From_Source (Scop) then
675 Append_Entity_Name (Buf, Scop);
676 Append (Buf, '.');
678 -- Otherwise (non-source scope) skip one level
680 else
681 Append_Entity_Name (Buf, Scope (Scop));
682 Append (Buf, '.');
683 end if;
685 -- Print the simple name
687 declare
688 E_Name : Bounded_String;
689 begin
690 Append_Unqualified_Decoded (E_Name, Chars (E));
692 -- Remove trailing upper-case letters from the name (useful for
693 -- dealing with some cases of internal names generated in the case
694 -- of references from within a generic).
696 while E_Name.Length > 1
697 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
698 loop
699 E_Name.Length := E_Name.Length - 1;
700 end loop;
702 -- Adjust casing appropriately (gets name from source if possible)
704 Adjust_Name_Case (E_Name, Sloc (E));
705 Append (Buf, E_Name);
706 end;
707 end Append_Entity_Name;
709 ---------------------------------
710 -- Append_Inherited_Subprogram --
711 ---------------------------------
713 procedure Append_Inherited_Subprogram (S : Entity_Id) is
714 Par : constant Entity_Id := Alias (S);
715 -- The parent subprogram
717 Scop : constant Entity_Id := Scope (Par);
718 -- The scope of definition of the parent subprogram
720 Typ : constant Entity_Id := Defining_Entity (Parent (S));
721 -- The derived type of which S is a primitive operation
723 Decl : Node_Id;
724 Next_E : Entity_Id;
726 begin
727 if Ekind (Current_Scope) = E_Package
728 and then In_Private_Part (Current_Scope)
729 and then Has_Private_Declaration (Typ)
730 and then Is_Tagged_Type (Typ)
731 and then Scop = Current_Scope
732 then
733 -- The inherited operation is available at the earliest place after
734 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
735 -- relevant for type extensions. If the parent operation appears
736 -- after the type extension, the operation is not visible.
738 Decl := First
739 (Visible_Declarations
740 (Package_Specification (Current_Scope)));
741 while Present (Decl) loop
742 if Nkind (Decl) = N_Private_Extension_Declaration
743 and then Defining_Entity (Decl) = Typ
744 then
745 if Sloc (Decl) > Sloc (Par) then
746 Next_E := Next_Entity (Par);
747 Link_Entities (Par, S);
748 Link_Entities (S, Next_E);
749 return;
751 else
752 exit;
753 end if;
754 end if;
756 Next (Decl);
757 end loop;
758 end if;
760 -- If partial view is not a type extension, or it appears before the
761 -- subprogram declaration, insert normally at end of entity list.
763 Append_Entity (S, Current_Scope);
764 end Append_Inherited_Subprogram;
766 -----------------------------------------
767 -- Apply_Compile_Time_Constraint_Error --
768 -----------------------------------------
770 procedure Apply_Compile_Time_Constraint_Error
771 (N : Node_Id;
772 Msg : String;
773 Reason : RT_Exception_Code;
774 Ent : Entity_Id := Empty;
775 Typ : Entity_Id := Empty;
776 Loc : Source_Ptr := No_Location;
777 Warn : Boolean := False;
778 Emit_Message : Boolean := True)
780 Stat : constant Boolean := Is_Static_Expression (N);
781 R_Stat : constant Node_Id :=
782 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
783 Rtyp : Entity_Id;
785 begin
786 if No (Typ) then
787 Rtyp := Etype (N);
788 else
789 Rtyp := Typ;
790 end if;
792 if Emit_Message then
793 Discard_Node
794 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
795 end if;
797 -- Now we replace the node by an N_Raise_Constraint_Error node
798 -- This does not need reanalyzing, so set it as analyzed now.
800 Rewrite (N, R_Stat);
801 Set_Analyzed (N, True);
803 Set_Etype (N, Rtyp);
804 Set_Raises_Constraint_Error (N);
806 -- Now deal with possible local raise handling
808 Possible_Local_Raise (N, Standard_Constraint_Error);
810 -- If the original expression was marked as static, the result is
811 -- still marked as static, but the Raises_Constraint_Error flag is
812 -- always set so that further static evaluation is not attempted.
814 if Stat then
815 Set_Is_Static_Expression (N);
816 end if;
817 end Apply_Compile_Time_Constraint_Error;
819 ---------------------------
820 -- Async_Readers_Enabled --
821 ---------------------------
823 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
824 begin
825 return Has_Enabled_Property (Id, Name_Async_Readers);
826 end Async_Readers_Enabled;
828 ---------------------------
829 -- Async_Writers_Enabled --
830 ---------------------------
832 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
833 begin
834 return Has_Enabled_Property (Id, Name_Async_Writers);
835 end Async_Writers_Enabled;
837 --------------------------------------
838 -- Available_Full_View_Of_Component --
839 --------------------------------------
841 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
842 ST : constant Entity_Id := Scope (T);
843 SCT : constant Entity_Id := Scope (Component_Type (T));
844 begin
845 return In_Open_Scopes (ST)
846 and then In_Open_Scopes (SCT)
847 and then Scope_Depth (ST) >= Scope_Depth (SCT);
848 end Available_Full_View_Of_Component;
850 ----------------
851 -- Bad_Aspect --
852 ----------------
854 procedure Bad_Aspect
855 (N : Node_Id;
856 Nam : Name_Id;
857 Warn : Boolean := False)
859 begin
860 Error_Msg_Warn := Warn;
861 Error_Msg_N ("<<& is not a valid aspect identifier", N);
863 -- Check bad spelling
864 Error_Msg_Name_1 := Aspect_Spell_Check (Nam);
865 if Error_Msg_Name_1 /= No_Name then
866 Error_Msg_N -- CODEFIX
867 ("\<<possible misspelling of %", N);
868 end if;
869 end Bad_Aspect;
871 -------------------
872 -- Bad_Attribute --
873 -------------------
875 procedure Bad_Attribute
876 (N : Node_Id;
877 Nam : Name_Id;
878 Warn : Boolean := False)
880 begin
881 Error_Msg_Warn := Warn;
882 Error_Msg_N ("<<unrecognized attribute&", N);
884 -- Check for possible misspelling
886 Error_Msg_Name_1 := Attribute_Spell_Check (Nam);
887 if Error_Msg_Name_1 /= No_Name then
888 Error_Msg_N -- CODEFIX
889 ("\<<possible misspelling of %", N);
890 end if;
891 end Bad_Attribute;
893 --------------------------------
894 -- Bad_Predicated_Subtype_Use --
895 --------------------------------
897 procedure Bad_Predicated_Subtype_Use
898 (Msg : String;
899 N : Node_Id;
900 Typ : Entity_Id;
901 Suggest_Static : Boolean := False)
903 Gen : Entity_Id;
905 begin
906 -- Avoid cascaded errors
908 if Error_Posted (N) then
909 return;
910 end if;
912 if Inside_A_Generic then
913 Gen := Current_Scope;
914 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
915 Gen := Scope (Gen);
916 end loop;
918 if No (Gen) then
919 return;
920 end if;
922 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
923 Set_No_Predicate_On_Actual (Typ);
924 end if;
926 elsif Has_Predicates (Typ) then
927 if Is_Generic_Actual_Type (Typ) then
929 -- The restriction on loop parameters is only that the type
930 -- should only have static predicates.
932 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
933 and then not Has_Dynamic_Predicate_Aspect (Typ)
934 and then not Has_Ghost_Predicate_Aspect (Typ)
935 and then Is_OK_Static_Subtype (Typ)
936 then
937 return;
938 end if;
940 Gen := Current_Scope;
941 while not Is_Generic_Instance (Gen) loop
942 Gen := Scope (Gen);
943 end loop;
945 pragma Assert (Present (Gen));
947 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
948 Error_Msg_Warn := SPARK_Mode /= On;
949 Error_Msg_FE (Msg & "<<", N, Typ);
950 Error_Msg_F ("\Program_Error [<<", N);
952 Insert_Action (N,
953 Make_Raise_Program_Error (Sloc (N),
954 Reason => PE_Bad_Predicated_Generic_Type));
956 else
957 Error_Msg_FE (Msg, N, Typ);
958 end if;
960 else
961 Error_Msg_FE (Msg, N, Typ);
962 end if;
964 -- Suggest to use First_Valid/Last_Valid instead of First/Last/Range
965 -- if the predicate is static.
967 if not Has_Dynamic_Predicate_Aspect (Typ)
968 and then not Has_Ghost_Predicate_Aspect (Typ)
969 and then Has_Static_Predicate (Typ)
970 and then Nkind (N) = N_Attribute_Reference
971 then
972 declare
973 Aname : constant Name_Id := Attribute_Name (N);
974 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
975 begin
976 case Attr_Id is
977 when Attribute_First =>
978 Error_Msg_F ("\use attribute First_Valid instead", N);
979 when Attribute_Last =>
980 Error_Msg_F ("\use attribute Last_Valid instead", N);
981 when Attribute_Range =>
982 Error_Msg_F ("\use attributes First_Valid and "
983 & "Last_Valid instead", N);
984 when others =>
985 null;
986 end case;
987 end;
988 end if;
990 -- Emit an optional suggestion on how to remedy the error if the
991 -- context warrants it.
993 if Suggest_Static and then Has_Static_Predicate (Typ) then
994 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
995 end if;
996 end if;
997 end Bad_Predicated_Subtype_Use;
999 -----------------------------------------
1000 -- Bad_Unordered_Enumeration_Reference --
1001 -----------------------------------------
1003 function Bad_Unordered_Enumeration_Reference
1004 (N : Node_Id;
1005 T : Entity_Id) return Boolean
1007 begin
1008 return Is_Enumeration_Type (T)
1009 and then Warn_On_Unordered_Enumeration_Type
1010 and then not Is_Generic_Type (T)
1011 and then Comes_From_Source (N)
1012 and then not Has_Pragma_Ordered (T)
1013 and then not In_Same_Extended_Unit (N, T);
1014 end Bad_Unordered_Enumeration_Reference;
1016 ----------------------------
1017 -- Begin_Keyword_Location --
1018 ----------------------------
1020 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
1021 HSS : Node_Id;
1023 begin
1024 pragma Assert
1025 (Nkind (N) in
1026 N_Block_Statement |
1027 N_Entry_Body |
1028 N_Package_Body |
1029 N_Subprogram_Body |
1030 N_Task_Body);
1032 HSS := Handled_Statement_Sequence (N);
1034 -- When the handled sequence of statements comes from source, the
1035 -- location of the "begin" keyword is that of the sequence itself.
1036 -- Note that an internal construct may inherit a source sequence.
1038 if Comes_From_Source (HSS) then
1039 return Sloc (HSS);
1041 -- The parser generates an internal handled sequence of statements to
1042 -- capture the location of the "begin" keyword if present in the source.
1043 -- Since there are no source statements, the location of the "begin"
1044 -- keyword is effectively that of the "end" keyword.
1046 elsif Comes_From_Source (N) then
1047 return Sloc (HSS);
1049 -- Otherwise the construct is internal and should carry the location of
1050 -- the original construct which prompted its creation.
1052 else
1053 return Sloc (N);
1054 end if;
1055 end Begin_Keyword_Location;
1057 --------------------------
1058 -- Build_Actual_Subtype --
1059 --------------------------
1061 function Build_Actual_Subtype
1062 (T : Entity_Id;
1063 N : Node_Or_Entity_Id) return Node_Id
1065 Loc : Source_Ptr;
1066 -- Normally Sloc (N), but may point to corresponding body in some cases
1068 Constraints : List_Id;
1069 Decl : Node_Id;
1070 Discr : Entity_Id;
1071 Hi : Node_Id;
1072 Lo : Node_Id;
1073 Subt : Entity_Id;
1074 Disc_Type : Entity_Id;
1075 Obj : Node_Id;
1076 Index : Node_Id;
1078 begin
1079 Loc := Sloc (N);
1081 if Nkind (N) = N_Defining_Identifier then
1082 Obj := New_Occurrence_Of (N, Loc);
1084 -- If this is a formal parameter of a subprogram declaration, and
1085 -- we are compiling the body, we want the declaration for the
1086 -- actual subtype to carry the source position of the body, to
1087 -- prevent anomalies in gdb when stepping through the code.
1089 if Is_Formal (N) then
1090 declare
1091 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1092 begin
1093 if Nkind (Decl) = N_Subprogram_Declaration
1094 and then Present (Corresponding_Body (Decl))
1095 then
1096 Loc := Sloc (Corresponding_Body (Decl));
1097 end if;
1098 end;
1099 end if;
1101 else
1102 Obj := N;
1103 end if;
1105 if Is_Array_Type (T) then
1106 Constraints := New_List;
1107 Index := First_Index (T);
1109 for J in 1 .. Number_Dimensions (T) loop
1111 -- Build an array subtype declaration with the nominal subtype and
1112 -- the bounds of the actual. Add the declaration in front of the
1113 -- local declarations for the subprogram, for analysis before any
1114 -- reference to the formal in the body.
1116 -- If this is for an index with a fixed lower bound, then use
1117 -- the fixed lower bound as the lower bound of the actual
1118 -- subtype's corresponding index.
1120 if not Is_Constrained (T)
1121 and then Is_Fixed_Lower_Bound_Index_Subtype (Etype (Index))
1122 then
1123 Lo := New_Copy_Tree (Type_Low_Bound (Etype (Index)));
1125 else
1126 Lo :=
1127 Make_Attribute_Reference (Loc,
1128 Prefix =>
1129 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1130 Attribute_Name => Name_First,
1131 Expressions => New_List (
1132 Make_Integer_Literal (Loc, J)));
1133 end if;
1135 Hi :=
1136 Make_Attribute_Reference (Loc,
1137 Prefix =>
1138 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1139 Attribute_Name => Name_Last,
1140 Expressions => New_List (
1141 Make_Integer_Literal (Loc, J)));
1143 Append (Make_Range (Loc, Lo, Hi), Constraints);
1145 Next_Index (Index);
1146 end loop;
1148 -- If the type has unknown discriminants there is no constrained
1149 -- subtype to build. This is never called for a formal or for a
1150 -- lhs, so returning the type is ok ???
1152 elsif Has_Unknown_Discriminants (T) then
1153 return T;
1155 else
1156 Constraints := New_List;
1158 -- Type T is a generic derived type, inherit the discriminants from
1159 -- the parent type.
1161 if Is_Private_Type (T)
1162 and then No (Full_View (T))
1164 -- T was flagged as an error if it was declared as a formal
1165 -- derived type with known discriminants. In this case there
1166 -- is no need to look at the parent type since T already carries
1167 -- its own discriminants.
1169 and then not Error_Posted (T)
1170 then
1171 Disc_Type := Etype (Base_Type (T));
1172 else
1173 Disc_Type := T;
1174 end if;
1176 Discr := First_Discriminant (Disc_Type);
1177 while Present (Discr) loop
1178 Append_To (Constraints,
1179 Make_Selected_Component (Loc,
1180 Prefix =>
1181 Duplicate_Subexpr_No_Checks (Obj),
1182 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1183 Next_Discriminant (Discr);
1184 end loop;
1185 end if;
1187 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1188 Set_Is_Internal (Subt);
1190 Decl :=
1191 Make_Subtype_Declaration (Loc,
1192 Defining_Identifier => Subt,
1193 Subtype_Indication =>
1194 Make_Subtype_Indication (Loc,
1195 Subtype_Mark => New_Occurrence_Of (T, Loc),
1196 Constraint =>
1197 Make_Index_Or_Discriminant_Constraint (Loc,
1198 Constraints => Constraints)));
1200 Mark_Rewrite_Insertion (Decl);
1201 return Decl;
1202 end Build_Actual_Subtype;
1204 ---------------------------------------
1205 -- Build_Actual_Subtype_Of_Component --
1206 ---------------------------------------
1208 function Build_Actual_Subtype_Of_Component
1209 (T : Entity_Id;
1210 N : Node_Id) return Node_Id
1212 Loc : constant Source_Ptr := Sloc (N);
1213 P : constant Node_Id := Prefix (N);
1215 D : Elmt_Id;
1216 Id : Node_Id;
1217 Index_Typ : Entity_Id;
1218 Sel : Entity_Id := Empty;
1220 Desig_Typ : Entity_Id;
1221 -- This is either a copy of T, or if T is an access type, then it is
1222 -- the directly designated type of this access type.
1224 function Build_Access_Record_Constraint (C : List_Id) return List_Id;
1225 -- If the record component is a constrained access to the current
1226 -- record, the subtype has not been constructed during analysis of
1227 -- the enclosing record type (see Analyze_Access). In that case, build
1228 -- a constrained access subtype after replacing references to the
1229 -- enclosing discriminants with the corresponding discriminant values
1230 -- of the prefix.
1232 function Build_Actual_Array_Constraint return List_Id;
1233 -- If one or more of the bounds of the component depends on
1234 -- discriminants, build actual constraint using the discriminants
1235 -- of the prefix, as above.
1237 function Build_Actual_Record_Constraint return List_Id;
1238 -- Similar to previous one, for discriminated components constrained
1239 -- by the discriminant of the enclosing object.
1241 function Build_Discriminant_Reference
1242 (Discrim_Name : Node_Id; Obj : Node_Id := P) return Node_Id;
1243 -- Build a reference to the discriminant denoted by Discrim_Name.
1244 -- The prefix of the result is usually Obj, but it could be
1245 -- a prefix of Obj in some corner cases.
1247 function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id;
1248 -- Copy the subtree rooted at N and insert an explicit dereference if it
1249 -- is of an access type.
1251 -----------------------------------
1252 -- Build_Actual_Array_Constraint --
1253 -----------------------------------
1255 function Build_Actual_Array_Constraint return List_Id is
1256 Constraints : constant List_Id := New_List;
1257 Indx : Node_Id;
1258 Hi : Node_Id;
1259 Lo : Node_Id;
1260 Old_Hi : Node_Id;
1261 Old_Lo : Node_Id;
1263 begin
1264 Indx := First_Index (Desig_Typ);
1265 while Present (Indx) loop
1266 Old_Lo := Type_Low_Bound (Etype (Indx));
1267 Old_Hi := Type_High_Bound (Etype (Indx));
1269 if Denotes_Discriminant (Old_Lo) then
1270 Lo := Build_Discriminant_Reference (Old_Lo);
1271 else
1272 Lo := New_Copy_Tree (Old_Lo);
1274 -- The new bound will be reanalyzed in the enclosing
1275 -- declaration. For literal bounds that come from a type
1276 -- declaration, the type of the context must be imposed, so
1277 -- insure that analysis will take place. For non-universal
1278 -- types this is not strictly necessary.
1280 Set_Analyzed (Lo, False);
1281 end if;
1283 if Denotes_Discriminant (Old_Hi) then
1284 Hi := Build_Discriminant_Reference (Old_Hi);
1285 else
1286 Hi := New_Copy_Tree (Old_Hi);
1287 Set_Analyzed (Hi, False);
1288 end if;
1290 Append (Make_Range (Loc, Lo, Hi), Constraints);
1291 Next_Index (Indx);
1292 end loop;
1294 return Constraints;
1295 end Build_Actual_Array_Constraint;
1297 ------------------------------------
1298 -- Build_Actual_Record_Constraint --
1299 ------------------------------------
1301 function Build_Actual_Record_Constraint return List_Id is
1302 Constraints : constant List_Id := New_List;
1303 D : Elmt_Id;
1304 D_Val : Node_Id;
1306 begin
1307 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1308 while Present (D) loop
1309 if Denotes_Discriminant (Node (D)) then
1310 D_Val := Build_Discriminant_Reference (Node (D));
1311 else
1312 D_Val := New_Copy_Tree (Node (D));
1313 end if;
1315 Append (D_Val, Constraints);
1316 Next_Elmt (D);
1317 end loop;
1319 return Constraints;
1320 end Build_Actual_Record_Constraint;
1322 ----------------------------------
1323 -- Build_Discriminant_Reference --
1324 ----------------------------------
1326 function Build_Discriminant_Reference
1327 (Discrim_Name : Node_Id; Obj : Node_Id := P) return Node_Id
1329 Discrim : constant Entity_Id := Entity (Discrim_Name);
1331 function Obj_Is_Good_Prefix return Boolean;
1332 -- Returns True if Obj.Discrim makes sense; that is, if
1333 -- Obj has Discrim as one of its discriminants (or is an
1334 -- access value that designates such an object).
1336 ------------------------
1337 -- Obj_Is_Good_Prefix --
1338 ------------------------
1340 function Obj_Is_Good_Prefix return Boolean is
1341 Obj_Type : Entity_Id :=
1342 Implementation_Base_Type (Etype (Obj));
1344 Discriminated_Type : constant Entity_Id :=
1345 Implementation_Base_Type
1346 (Scope (Original_Record_Component (Discrim)));
1347 begin
1348 -- The order of the following two tests matters in the
1349 -- access-to-class-wide case.
1351 if Is_Access_Type (Obj_Type) then
1352 Obj_Type := Implementation_Base_Type
1353 (Designated_Type (Obj_Type));
1354 end if;
1356 if Is_Class_Wide_Type (Obj_Type) then
1357 Obj_Type := Implementation_Base_Type
1358 (Find_Specific_Type (Obj_Type));
1359 end if;
1361 -- If a type T1 defines a discriminant D1, then Obj.D1 is ok (for
1362 -- our purposes here) if T1 is an ancestor of the type of Obj.
1363 -- So that's what we would like to test for here.
1364 -- The bad news: Is_Ancestor is only defined in the tagged case.
1365 -- The good news: in the untagged case, Implementation_Base_Type
1366 -- looks through derived types so we can use a simpler test.
1368 if Is_Tagged_Type (Discriminated_Type) then
1369 return Is_Ancestor (Discriminated_Type, Obj_Type);
1370 else
1371 return Discriminated_Type = Obj_Type;
1372 end if;
1373 end Obj_Is_Good_Prefix;
1375 -- Start of processing for Build_Discriminant_Reference
1377 begin
1378 if not Obj_Is_Good_Prefix then
1379 -- If the given discriminant is not a component of the given
1380 -- object, then try the enclosing object.
1382 if Nkind (Obj) = N_Selected_Component then
1383 return Build_Discriminant_Reference
1384 (Discrim_Name => Discrim_Name,
1385 Obj => Prefix (Obj));
1386 elsif Nkind (Obj) in N_Has_Entity
1387 and then Nkind (Parent (Entity (Obj))) =
1388 N_Object_Renaming_Declaration
1389 then
1390 -- Look through a renaming (a corner case of a corner case).
1391 return Build_Discriminant_Reference
1392 (Discrim_Name => Discrim_Name,
1393 Obj => Name (Parent (Entity (Obj))));
1394 else
1395 -- We are in some unexpected case here, so revert to the
1396 -- old behavior (by falling through to it).
1397 null;
1398 end if;
1399 end if;
1401 return Make_Selected_Component (Loc,
1402 Prefix => Copy_And_Maybe_Dereference (Obj),
1403 Selector_Name => New_Occurrence_Of (Discrim, Loc));
1404 end Build_Discriminant_Reference;
1406 ------------------------------------
1407 -- Build_Access_Record_Constraint --
1408 ------------------------------------
1410 function Build_Access_Record_Constraint (C : List_Id) return List_Id is
1411 Constraints : constant List_Id := New_List;
1412 D : Node_Id;
1413 D_Val : Node_Id;
1415 begin
1416 -- Retrieve the constraint from the component declaration, because
1417 -- the component subtype has not been constructed and the component
1418 -- type is an unconstrained access.
1420 D := First (C);
1421 while Present (D) loop
1422 if Nkind (D) = N_Discriminant_Association
1423 and then Denotes_Discriminant (Expression (D))
1424 then
1425 D_Val := New_Copy_Tree (D);
1426 Set_Expression (D_Val,
1427 Make_Selected_Component (Loc,
1428 Prefix => Copy_And_Maybe_Dereference (P),
1429 Selector_Name =>
1430 New_Occurrence_Of (Entity (Expression (D)), Loc)));
1432 elsif Denotes_Discriminant (D) then
1433 D_Val := Make_Selected_Component (Loc,
1434 Prefix => Copy_And_Maybe_Dereference (P),
1435 Selector_Name => New_Occurrence_Of (Entity (D), Loc));
1437 else
1438 D_Val := New_Copy_Tree (D);
1439 end if;
1441 Append (D_Val, Constraints);
1442 Next (D);
1443 end loop;
1445 return Constraints;
1446 end Build_Access_Record_Constraint;
1448 --------------------------------
1449 -- Copy_And_Maybe_Dereference --
1450 --------------------------------
1452 function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id is
1453 New_N : constant Node_Id := New_Copy_Tree (N);
1455 begin
1456 if Is_Access_Type (Etype (N)) then
1457 return Make_Explicit_Dereference (Sloc (Parent (N)), New_N);
1459 else
1460 return New_N;
1461 end if;
1462 end Copy_And_Maybe_Dereference;
1464 -- Start of processing for Build_Actual_Subtype_Of_Component
1466 begin
1467 -- The subtype does not need to be created for a selected component
1468 -- in a Spec_Expression.
1470 if In_Spec_Expression then
1471 return Empty;
1473 -- More comments for the rest of this body would be good ???
1475 elsif Nkind (N) = N_Explicit_Dereference then
1476 if Is_Composite_Type (T)
1477 and then not Is_Constrained (T)
1478 and then not (Is_Class_Wide_Type (T)
1479 and then Is_Constrained (Root_Type (T)))
1480 and then not Has_Unknown_Discriminants (T)
1481 then
1482 -- If the type of the dereference is already constrained, it is an
1483 -- actual subtype.
1485 if Is_Array_Type (Etype (N))
1486 and then Is_Constrained (Etype (N))
1487 then
1488 return Empty;
1489 else
1490 Remove_Side_Effects (P);
1491 return Build_Actual_Subtype (T, N);
1492 end if;
1494 else
1495 return Empty;
1496 end if;
1498 elsif Nkind (N) = N_Selected_Component then
1499 -- The entity of the selected component allows us to retrieve
1500 -- the original constraint from its component declaration.
1502 Sel := Entity (Selector_Name (N));
1503 if Parent_Kind (Sel) /= N_Component_Declaration then
1504 return Empty;
1505 end if;
1506 end if;
1508 if Is_Access_Type (T) then
1509 Desig_Typ := Designated_Type (T);
1511 else
1512 Desig_Typ := T;
1513 end if;
1515 if Ekind (Desig_Typ) = E_Array_Subtype then
1516 Id := First_Index (Desig_Typ);
1518 -- Check whether an index bound is constrained by a discriminant
1520 while Present (Id) loop
1521 Index_Typ := Underlying_Type (Etype (Id));
1523 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1524 or else
1525 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1526 then
1527 Remove_Side_Effects (P);
1528 return
1529 Build_Component_Subtype
1530 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1531 end if;
1533 Next_Index (Id);
1534 end loop;
1536 elsif Is_Composite_Type (Desig_Typ)
1537 and then Has_Discriminants (Desig_Typ)
1538 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Desig_Typ))
1539 and then not Has_Unknown_Discriminants (Desig_Typ)
1540 then
1541 if Is_Private_Type (Desig_Typ)
1542 and then No (Discriminant_Constraint (Desig_Typ))
1543 then
1544 Desig_Typ := Full_View (Desig_Typ);
1545 end if;
1547 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1548 while Present (D) loop
1549 if Denotes_Discriminant (Node (D)) then
1550 Remove_Side_Effects (P);
1551 return
1552 Build_Component_Subtype (
1553 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1554 end if;
1556 Next_Elmt (D);
1557 end loop;
1559 -- Special processing for an access record component that is
1560 -- the target of an assignment. If the designated type is an
1561 -- unconstrained discriminated record we create its actual
1562 -- subtype now.
1564 elsif Ekind (T) = E_Access_Type
1565 and then Present (Sel)
1566 and then Has_Per_Object_Constraint (Sel)
1567 and then Nkind (Parent (N)) = N_Assignment_Statement
1568 and then N = Name (Parent (N))
1569 -- and then not Inside_Init_Proc
1570 -- and then Has_Discriminants (Desig_Typ)
1571 -- and then not Is_Constrained (Desig_Typ)
1572 then
1573 declare
1574 S_Indic : constant Node_Id :=
1575 (Subtype_Indication
1576 (Component_Definition (Parent (Sel))));
1577 Discs : List_Id;
1578 begin
1579 if Nkind (S_Indic) = N_Subtype_Indication then
1580 Discs := Constraints (Constraint (S_Indic));
1582 Remove_Side_Effects (P);
1583 return Build_Component_Subtype
1584 (Build_Access_Record_Constraint (Discs), Loc, T);
1585 else
1586 return Empty;
1587 end if;
1588 end;
1589 end if;
1591 -- If none of the above, the actual and nominal subtypes are the same
1593 return Empty;
1594 end Build_Actual_Subtype_Of_Component;
1596 -----------------------------
1597 -- Build_Component_Subtype --
1598 -----------------------------
1600 function Build_Component_Subtype
1601 (C : List_Id;
1602 Loc : Source_Ptr;
1603 T : Entity_Id) return Node_Id
1605 Subt : Entity_Id;
1606 Decl : Node_Id;
1608 begin
1609 -- Unchecked_Union components do not require component subtypes
1611 if Is_Unchecked_Union (T) then
1612 return Empty;
1613 end if;
1615 Subt := Make_Temporary (Loc, 'S');
1616 Set_Is_Internal (Subt);
1618 Decl :=
1619 Make_Subtype_Declaration (Loc,
1620 Defining_Identifier => Subt,
1621 Subtype_Indication =>
1622 Make_Subtype_Indication (Loc,
1623 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1624 Constraint =>
1625 Make_Index_Or_Discriminant_Constraint (Loc,
1626 Constraints => C)));
1628 Mark_Rewrite_Insertion (Decl);
1629 return Decl;
1630 end Build_Component_Subtype;
1632 -----------------------------
1633 -- Build_Constrained_Itype --
1634 -----------------------------
1636 procedure Build_Constrained_Itype
1637 (N : Node_Id;
1638 Typ : Entity_Id;
1639 New_Assoc_List : List_Id)
1641 Constrs : constant List_Id := New_List;
1642 Loc : constant Source_Ptr := Sloc (N);
1643 Def_Id : Entity_Id;
1644 Indic : Node_Id;
1645 New_Assoc : Node_Id;
1646 Subtyp_Decl : Node_Id;
1648 begin
1649 New_Assoc := First (New_Assoc_List);
1650 while Present (New_Assoc) loop
1652 -- There is exactly one choice in the component association (and
1653 -- it is either a discriminant, a component or the others clause).
1654 pragma Assert (List_Length (Choices (New_Assoc)) = 1);
1656 -- Duplicate expression for the discriminant and put it on the
1657 -- list of constraints for the itype declaration.
1659 if Is_Entity_Name (First (Choices (New_Assoc)))
1660 and then
1661 Ekind (Entity (First (Choices (New_Assoc)))) = E_Discriminant
1662 then
1663 Append_To (Constrs, Duplicate_Subexpr (Expression (New_Assoc)));
1664 end if;
1666 Next (New_Assoc);
1667 end loop;
1669 if Has_Unknown_Discriminants (Typ)
1670 and then Present (Underlying_Record_View (Typ))
1671 then
1672 Indic :=
1673 Make_Subtype_Indication (Loc,
1674 Subtype_Mark =>
1675 New_Occurrence_Of (Underlying_Record_View (Typ), Loc),
1676 Constraint =>
1677 Make_Index_Or_Discriminant_Constraint (Loc,
1678 Constraints => Constrs));
1679 else
1680 Indic :=
1681 Make_Subtype_Indication (Loc,
1682 Subtype_Mark =>
1683 New_Occurrence_Of (Base_Type (Typ), Loc),
1684 Constraint =>
1685 Make_Index_Or_Discriminant_Constraint (Loc,
1686 Constraints => Constrs));
1687 end if;
1689 Def_Id := Create_Itype (Ekind (Typ), N);
1691 Subtyp_Decl :=
1692 Make_Subtype_Declaration (Loc,
1693 Defining_Identifier => Def_Id,
1694 Subtype_Indication => Indic);
1695 Set_Parent (Subtyp_Decl, Parent (N));
1697 -- Itypes must be analyzed with checks off (see itypes.ads)
1699 Analyze (Subtyp_Decl, Suppress => All_Checks);
1701 Set_Etype (N, Def_Id);
1702 end Build_Constrained_Itype;
1704 ---------------------------
1705 -- Build_Default_Subtype --
1706 ---------------------------
1708 function Build_Default_Subtype
1709 (T : Entity_Id;
1710 N : Node_Id) return Entity_Id
1712 Loc : constant Source_Ptr := Sloc (N);
1713 Disc : Entity_Id;
1715 Bas : Entity_Id;
1716 -- The base type that is to be constrained by the defaults
1718 begin
1719 if not Has_Discriminants (T) or else Is_Constrained (T) then
1720 return T;
1721 end if;
1723 Bas := Base_Type (T);
1725 -- If T is non-private but its base type is private, this is the
1726 -- completion of a subtype declaration whose parent type is private
1727 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1728 -- are to be found in the full view of the base. Check that the private
1729 -- status of T and its base differ.
1731 if Is_Private_Type (Bas)
1732 and then not Is_Private_Type (T)
1733 and then Present (Full_View (Bas))
1734 then
1735 Bas := Full_View (Bas);
1736 end if;
1738 Disc := First_Discriminant (T);
1740 if No (Discriminant_Default_Value (Disc)) then
1741 return T;
1742 end if;
1744 declare
1745 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1746 Constraints : constant List_Id := New_List;
1747 Decl : Node_Id;
1749 begin
1750 while Present (Disc) loop
1751 Append_To (Constraints,
1752 New_Copy_Tree
1753 (Discriminant_Default_Value (Disc), New_Sloc => Loc));
1754 Next_Discriminant (Disc);
1755 end loop;
1757 Decl :=
1758 Make_Subtype_Declaration (Loc,
1759 Defining_Identifier => Act,
1760 Subtype_Indication =>
1761 Make_Subtype_Indication (Loc,
1762 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1763 Constraint =>
1764 Make_Index_Or_Discriminant_Constraint (Loc,
1765 Constraints => Constraints)));
1767 Insert_Action (N, Decl);
1769 -- If the context is a component declaration the subtype declaration
1770 -- will be analyzed when the enclosing type is frozen, otherwise do
1771 -- it now.
1773 if Ekind (Current_Scope) /= E_Record_Type then
1774 Analyze (Decl);
1775 end if;
1777 return Act;
1778 end;
1779 end Build_Default_Subtype;
1781 ------------------------------
1782 -- Build_Default_Subtype_OK --
1783 ------------------------------
1785 function Build_Default_Subtype_OK (T : Entity_Id) return Boolean is
1786 begin
1787 if Is_Constrained (T) then
1789 -- We won't build a new subtype if T is constrained
1791 return False;
1792 end if;
1794 return Is_Definite_Subtype (T) and then Is_Inherently_Limited_Type (T);
1795 end Build_Default_Subtype_OK;
1797 --------------------------------------------
1798 -- Build_Discriminal_Subtype_Of_Component --
1799 --------------------------------------------
1801 function Build_Discriminal_Subtype_Of_Component
1802 (T : Entity_Id) return Node_Id
1804 Loc : constant Source_Ptr := Sloc (T);
1805 D : Elmt_Id;
1806 Id : Node_Id;
1808 function Build_Discriminal_Array_Constraint return List_Id;
1809 -- If one or more of the bounds of the component depends on
1810 -- discriminants, build actual constraint using the discriminants
1811 -- of the prefix.
1813 function Build_Discriminal_Record_Constraint return List_Id;
1814 -- Similar to previous one, for discriminated components constrained by
1815 -- the discriminant of the enclosing object.
1817 ----------------------------------------
1818 -- Build_Discriminal_Array_Constraint --
1819 ----------------------------------------
1821 function Build_Discriminal_Array_Constraint return List_Id is
1822 Constraints : constant List_Id := New_List;
1823 Indx : Node_Id;
1824 Hi : Node_Id;
1825 Lo : Node_Id;
1826 Old_Hi : Node_Id;
1827 Old_Lo : Node_Id;
1829 begin
1830 Indx := First_Index (T);
1831 while Present (Indx) loop
1832 Old_Lo := Type_Low_Bound (Etype (Indx));
1833 Old_Hi := Type_High_Bound (Etype (Indx));
1835 if Denotes_Discriminant (Old_Lo) then
1836 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1838 else
1839 Lo := New_Copy_Tree (Old_Lo);
1840 end if;
1842 if Denotes_Discriminant (Old_Hi) then
1843 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1845 else
1846 Hi := New_Copy_Tree (Old_Hi);
1847 end if;
1849 Append (Make_Range (Loc, Lo, Hi), Constraints);
1850 Next_Index (Indx);
1851 end loop;
1853 return Constraints;
1854 end Build_Discriminal_Array_Constraint;
1856 -----------------------------------------
1857 -- Build_Discriminal_Record_Constraint --
1858 -----------------------------------------
1860 function Build_Discriminal_Record_Constraint return List_Id is
1861 Constraints : constant List_Id := New_List;
1862 D : Elmt_Id;
1863 D_Val : Node_Id;
1865 begin
1866 D := First_Elmt (Discriminant_Constraint (T));
1867 while Present (D) loop
1868 if Denotes_Discriminant (Node (D)) then
1869 D_Val :=
1870 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1871 else
1872 D_Val := New_Copy_Tree (Node (D));
1873 end if;
1875 Append (D_Val, Constraints);
1876 Next_Elmt (D);
1877 end loop;
1879 return Constraints;
1880 end Build_Discriminal_Record_Constraint;
1882 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1884 begin
1885 if Ekind (T) = E_Array_Subtype then
1886 Id := First_Index (T);
1887 while Present (Id) loop
1888 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1889 or else
1890 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1891 then
1892 return Build_Component_Subtype
1893 (Build_Discriminal_Array_Constraint, Loc, T);
1894 end if;
1896 Next_Index (Id);
1897 end loop;
1899 elsif Ekind (T) = E_Record_Subtype
1900 and then Has_Discriminants (T)
1901 and then not Has_Unknown_Discriminants (T)
1902 then
1903 D := First_Elmt (Discriminant_Constraint (T));
1904 while Present (D) loop
1905 if Denotes_Discriminant (Node (D)) then
1906 return Build_Component_Subtype
1907 (Build_Discriminal_Record_Constraint, Loc, T);
1908 end if;
1910 Next_Elmt (D);
1911 end loop;
1912 end if;
1914 -- If none of the above, the actual and nominal subtypes are the same
1916 return Empty;
1917 end Build_Discriminal_Subtype_Of_Component;
1919 ------------------------------
1920 -- Build_Elaboration_Entity --
1921 ------------------------------
1923 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1924 Loc : constant Source_Ptr := Sloc (N);
1925 Decl : Node_Id;
1926 Elab_Ent : Entity_Id;
1928 procedure Set_Package_Name (Ent : Entity_Id);
1929 -- Given an entity, sets the fully qualified name of the entity in
1930 -- Name_Buffer, with components separated by double underscores. This
1931 -- is a recursive routine that climbs the scope chain to Standard.
1933 ----------------------
1934 -- Set_Package_Name --
1935 ----------------------
1937 procedure Set_Package_Name (Ent : Entity_Id) is
1938 begin
1939 if Scope (Ent) /= Standard_Standard then
1940 Set_Package_Name (Scope (Ent));
1942 declare
1943 Nam : constant String := Get_Name_String (Chars (Ent));
1944 begin
1945 Name_Buffer (Name_Len + 1) := '_';
1946 Name_Buffer (Name_Len + 2) := '_';
1947 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1948 Name_Len := Name_Len + Nam'Length + 2;
1949 end;
1951 else
1952 Get_Name_String (Chars (Ent));
1953 end if;
1954 end Set_Package_Name;
1956 -- Start of processing for Build_Elaboration_Entity
1958 begin
1959 -- Ignore call if already constructed
1961 if Present (Elaboration_Entity (Spec_Id)) then
1962 return;
1964 -- Do not generate an elaboration entity in GNATprove move because the
1965 -- elaboration counter is a form of expansion.
1967 elsif GNATprove_Mode then
1968 return;
1970 -- See if we need elaboration entity
1972 -- We always need an elaboration entity when preserving control flow, as
1973 -- we want to remain explicit about the unit's elaboration order.
1975 elsif Opt.Suppress_Control_Flow_Optimizations then
1976 null;
1978 -- We always need an elaboration entity for the dynamic elaboration
1979 -- model, since it is needed to properly generate the PE exception for
1980 -- access before elaboration.
1982 elsif Dynamic_Elaboration_Checks then
1983 null;
1985 -- For the static model, we don't need the elaboration counter if this
1986 -- unit is sure to have no elaboration code, since that means there
1987 -- is no elaboration unit to be called. Note that we can't just decide
1988 -- after the fact by looking to see whether there was elaboration code,
1989 -- because that's too late to make this decision.
1991 elsif Restriction_Active (No_Elaboration_Code) then
1992 return;
1994 -- Similarly, for the static model, we can skip the elaboration counter
1995 -- if we have the No_Multiple_Elaboration restriction, since for the
1996 -- static model, that's the only purpose of the counter (to avoid
1997 -- multiple elaboration).
1999 elsif Restriction_Active (No_Multiple_Elaboration) then
2000 return;
2001 end if;
2003 -- Here we need the elaboration entity
2005 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
2006 -- name with dots replaced by double underscore. We have to manually
2007 -- construct this name, since it will be elaborated in the outer scope,
2008 -- and thus will not have the unit name automatically prepended.
2010 Set_Package_Name (Spec_Id);
2011 Add_Str_To_Name_Buffer ("_E");
2013 -- Create elaboration counter
2015 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
2016 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
2018 Decl :=
2019 Make_Object_Declaration (Loc,
2020 Defining_Identifier => Elab_Ent,
2021 Object_Definition =>
2022 New_Occurrence_Of (Standard_Short_Integer, Loc),
2023 Expression => Make_Integer_Literal (Loc, Uint_0));
2025 Push_Scope (Standard_Standard);
2026 Add_Global_Declaration (Decl);
2027 Pop_Scope;
2029 -- Reset True_Constant indication, since we will indeed assign a value
2030 -- to the variable in the binder main. We also kill the Current_Value
2031 -- and Last_Assignment fields for the same reason.
2033 Set_Is_True_Constant (Elab_Ent, False);
2034 Set_Current_Value (Elab_Ent, Empty);
2035 Set_Last_Assignment (Elab_Ent, Empty);
2037 -- We do not want any further qualification of the name (if we did not
2038 -- do this, we would pick up the name of the generic package in the case
2039 -- of a library level generic instantiation).
2041 Set_Has_Qualified_Name (Elab_Ent);
2042 Set_Has_Fully_Qualified_Name (Elab_Ent);
2043 end Build_Elaboration_Entity;
2045 --------------------------------
2046 -- Build_Explicit_Dereference --
2047 --------------------------------
2049 procedure Build_Explicit_Dereference
2050 (Expr : Node_Id;
2051 Disc : Entity_Id)
2053 Loc : constant Source_Ptr := Sloc (Expr);
2054 I : Interp_Index;
2055 It : Interp;
2057 begin
2058 -- An entity of a type with a reference aspect is overloaded with
2059 -- both interpretations: with and without the dereference. Now that
2060 -- the dereference is made explicit, set the type of the node properly,
2061 -- to prevent anomalies in the backend. Same if the expression is an
2062 -- overloaded function call whose return type has a reference aspect.
2064 if Is_Entity_Name (Expr) then
2065 Set_Etype (Expr, Etype (Entity (Expr)));
2067 -- The designated entity will not be examined again when resolving
2068 -- the dereference, so generate a reference to it now.
2070 Generate_Reference (Entity (Expr), Expr);
2072 elsif Nkind (Expr) = N_Function_Call then
2074 -- If the name of the indexing function is overloaded, locate the one
2075 -- whose return type has an implicit dereference on the desired
2076 -- discriminant, and set entity and type of function call.
2078 if Is_Overloaded (Name (Expr)) then
2079 Get_First_Interp (Name (Expr), I, It);
2081 while Present (It.Nam) loop
2082 if Ekind ((It.Typ)) = E_Record_Type
2083 and then First_Entity ((It.Typ)) = Disc
2084 then
2085 Set_Entity (Name (Expr), It.Nam);
2086 Set_Etype (Name (Expr), Etype (It.Nam));
2087 exit;
2088 end if;
2090 Get_Next_Interp (I, It);
2091 end loop;
2092 end if;
2094 -- Set type of call from resolved function name.
2096 Set_Etype (Expr, Etype (Name (Expr)));
2097 end if;
2099 Set_Is_Overloaded (Expr, False);
2101 -- The expression will often be a generalized indexing that yields a
2102 -- container element that is then dereferenced, in which case the
2103 -- generalized indexing call is also non-overloaded.
2105 if Nkind (Expr) = N_Indexed_Component
2106 and then Present (Generalized_Indexing (Expr))
2107 then
2108 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
2109 end if;
2111 Rewrite (Expr,
2112 Make_Explicit_Dereference (Loc,
2113 Prefix =>
2114 Make_Selected_Component (Loc,
2115 Prefix => Relocate_Node (Expr),
2116 Selector_Name => New_Occurrence_Of (Disc, Loc))));
2117 Set_Etype (Prefix (Expr), Etype (Disc));
2118 Set_Etype (Expr, Designated_Type (Etype (Disc)));
2119 end Build_Explicit_Dereference;
2121 ---------------------------
2122 -- Build_Overriding_Spec --
2123 ---------------------------
2125 function Build_Overriding_Spec
2126 (Op : Entity_Id;
2127 Typ : Entity_Id) return Node_Id
2129 Loc : constant Source_Ptr := Sloc (Typ);
2130 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
2131 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
2133 Formal_Spec : Node_Id;
2134 Formal_Type : Node_Id;
2135 New_Spec : Node_Id;
2137 begin
2138 New_Spec := Copy_Subprogram_Spec (Spec);
2140 Formal_Spec := First (Parameter_Specifications (New_Spec));
2141 while Present (Formal_Spec) loop
2142 Formal_Type := Parameter_Type (Formal_Spec);
2144 if Is_Entity_Name (Formal_Type)
2145 and then Entity (Formal_Type) = Par_Typ
2146 then
2147 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
2149 elsif Nkind (Formal_Type) = N_Access_Definition
2150 and then Entity (Subtype_Mark (Formal_Type)) = Par_Typ
2151 then
2152 Rewrite (Subtype_Mark (Formal_Type), New_Occurrence_Of (Typ, Loc));
2153 end if;
2155 Next (Formal_Spec);
2156 end loop;
2158 return New_Spec;
2159 end Build_Overriding_Spec;
2161 -------------------
2162 -- Build_Subtype --
2163 -------------------
2165 function Build_Subtype
2166 (Related_Node : Node_Id;
2167 Loc : Source_Ptr;
2168 Typ : Entity_Id;
2169 Constraints : List_Id)
2170 return Entity_Id
2172 Indic : Node_Id;
2173 Subtyp_Decl : Node_Id;
2174 Def_Id : Entity_Id;
2175 Btyp : Entity_Id := Base_Type (Typ);
2177 begin
2178 -- The Related_Node better be here or else we won't be able to
2179 -- attach new itypes to a node in the tree.
2181 pragma Assert (Present (Related_Node));
2183 -- If the view of the component's type is incomplete or private
2184 -- with unknown discriminants, then the constraint must be applied
2185 -- to the full type.
2187 if Has_Unknown_Discriminants (Btyp)
2188 and then Present (Underlying_Type (Btyp))
2189 then
2190 Btyp := Underlying_Type (Btyp);
2191 end if;
2193 Indic :=
2194 Make_Subtype_Indication (Loc,
2195 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
2196 Constraint =>
2197 Make_Index_Or_Discriminant_Constraint (Loc, Constraints));
2199 Def_Id := Create_Itype (Ekind (Typ), Related_Node);
2201 Subtyp_Decl :=
2202 Make_Subtype_Declaration (Loc,
2203 Defining_Identifier => Def_Id,
2204 Subtype_Indication => Indic);
2206 Set_Parent (Subtyp_Decl, Parent (Related_Node));
2208 -- Itypes must be analyzed with checks off (see package Itypes)
2210 Analyze (Subtyp_Decl, Suppress => All_Checks);
2212 if Is_Itype (Def_Id) and then Has_Predicates (Typ) then
2213 Inherit_Predicate_Flags (Def_Id, Typ);
2215 -- Indicate where the predicate function may be found
2217 if Is_Itype (Typ) then
2218 if Present (Predicate_Function (Def_Id)) then
2219 null;
2221 elsif Present (Predicate_Function (Typ)) then
2222 Set_Predicate_Function (Def_Id, Predicate_Function (Typ));
2224 else
2225 Set_Predicated_Parent (Def_Id, Predicated_Parent (Typ));
2226 end if;
2228 elsif No (Predicate_Function (Def_Id)) then
2229 Set_Predicated_Parent (Def_Id, Typ);
2230 end if;
2231 end if;
2233 return Def_Id;
2234 end Build_Subtype;
2236 -----------------------------------
2237 -- Cannot_Raise_Constraint_Error --
2238 -----------------------------------
2240 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
2242 function List_Cannot_Raise_CE (L : List_Id) return Boolean;
2243 -- Returns True if none of the list members cannot possibly raise
2244 -- Constraint_Error.
2246 --------------------------
2247 -- List_Cannot_Raise_CE --
2248 --------------------------
2250 function List_Cannot_Raise_CE (L : List_Id) return Boolean is
2251 N : Node_Id;
2252 begin
2253 N := First (L);
2254 while Present (N) loop
2255 if Cannot_Raise_Constraint_Error (N) then
2256 Next (N);
2257 else
2258 return False;
2259 end if;
2260 end loop;
2262 return True;
2263 end List_Cannot_Raise_CE;
2265 -- Start of processing for Cannot_Raise_Constraint_Error
2267 begin
2268 if Compile_Time_Known_Value (Expr) then
2269 return True;
2271 elsif Do_Range_Check (Expr) then
2272 return False;
2274 elsif Raises_Constraint_Error (Expr) then
2275 return False;
2277 else
2278 case Nkind (Expr) is
2279 when N_Identifier =>
2280 return True;
2282 when N_Expanded_Name =>
2283 return True;
2285 when N_Indexed_Component =>
2286 return not Do_Range_Check (Expr)
2287 and then Cannot_Raise_Constraint_Error (Prefix (Expr))
2288 and then List_Cannot_Raise_CE (Expressions (Expr));
2290 when N_Selected_Component =>
2291 return not Do_Discriminant_Check (Expr)
2292 and then Cannot_Raise_Constraint_Error (Prefix (Expr));
2294 when N_Attribute_Reference =>
2295 if Do_Overflow_Check (Expr) then
2296 return False;
2298 elsif No (Expressions (Expr)) then
2299 return True;
2301 else
2302 return List_Cannot_Raise_CE (Expressions (Expr));
2303 end if;
2305 when N_Type_Conversion =>
2306 if Do_Overflow_Check (Expr)
2307 or else Do_Length_Check (Expr)
2308 then
2309 return False;
2310 else
2311 return Cannot_Raise_Constraint_Error (Expression (Expr));
2312 end if;
2314 when N_Unchecked_Type_Conversion =>
2315 return Cannot_Raise_Constraint_Error (Expression (Expr));
2317 when N_Unary_Op =>
2318 if Do_Overflow_Check (Expr) then
2319 return False;
2320 else
2321 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2322 end if;
2324 when N_Op_Divide
2325 | N_Op_Mod
2326 | N_Op_Rem
2328 if Do_Division_Check (Expr)
2329 or else
2330 Do_Overflow_Check (Expr)
2331 then
2332 return False;
2333 else
2334 return
2335 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2336 and then
2337 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2338 end if;
2340 when N_Op_Add
2341 | N_Op_And
2342 | N_Op_Concat
2343 | N_Op_Eq
2344 | N_Op_Expon
2345 | N_Op_Ge
2346 | N_Op_Gt
2347 | N_Op_Le
2348 | N_Op_Lt
2349 | N_Op_Multiply
2350 | N_Op_Ne
2351 | N_Op_Or
2352 | N_Op_Rotate_Left
2353 | N_Op_Rotate_Right
2354 | N_Op_Shift_Left
2355 | N_Op_Shift_Right
2356 | N_Op_Shift_Right_Arithmetic
2357 | N_Op_Subtract
2358 | N_Op_Xor
2360 if Do_Overflow_Check (Expr) then
2361 return False;
2362 else
2363 return
2364 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2365 and then
2366 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2367 end if;
2369 when others =>
2370 return False;
2371 end case;
2372 end if;
2373 end Cannot_Raise_Constraint_Error;
2375 -------------------------------
2376 -- Check_Ambiguous_Aggregate --
2377 -------------------------------
2379 procedure Check_Ambiguous_Aggregate (Call : Node_Id) is
2380 Actual : Node_Id;
2382 begin
2383 if Ada_Version >= Ada_2022 then
2384 Actual := First_Actual (Call);
2385 while Present (Actual) loop
2386 if Nkind (Actual) = N_Aggregate then
2387 Error_Msg_N
2388 ("\add type qualification to aggregate actual", Actual);
2389 exit;
2390 end if;
2391 Next_Actual (Actual);
2392 end loop;
2393 end if;
2394 end Check_Ambiguous_Aggregate;
2396 -----------------------------------------
2397 -- Check_Dynamically_Tagged_Expression --
2398 -----------------------------------------
2400 procedure Check_Dynamically_Tagged_Expression
2401 (Expr : Node_Id;
2402 Typ : Entity_Id;
2403 Related_Nod : Node_Id)
2405 begin
2406 pragma Assert (Is_Tagged_Type (Typ));
2408 -- In order to avoid spurious errors when analyzing the expanded code,
2409 -- this check is done only for nodes that come from source and for
2410 -- actuals of generic instantiations.
2412 if (Comes_From_Source (Related_Nod)
2413 or else In_Generic_Actual (Expr))
2414 and then (Is_Class_Wide_Type (Etype (Expr))
2415 or else Is_Dynamically_Tagged (Expr))
2416 and then not Is_Class_Wide_Type (Typ)
2417 then
2418 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2419 end if;
2420 end Check_Dynamically_Tagged_Expression;
2422 --------------------------
2423 -- Check_Fully_Declared --
2424 --------------------------
2426 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2427 begin
2428 if Ekind (T) = E_Incomplete_Type then
2430 -- Ada 2005 (AI-50217): If the type is available through a limited
2431 -- with_clause, verify that its full view has been analyzed.
2433 if From_Limited_With (T)
2434 and then Present (Non_Limited_View (T))
2435 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2436 then
2437 -- The non-limited view is fully declared
2439 null;
2441 else
2442 Error_Msg_NE
2443 ("premature usage of incomplete}", N, First_Subtype (T));
2444 end if;
2446 -- Need comments for these tests ???
2448 elsif Has_Private_Component (T)
2449 and then not Is_Generic_Type (Root_Type (T))
2450 and then not In_Spec_Expression
2451 then
2452 -- Special case: if T is the anonymous type created for a single
2453 -- task or protected object, use the name of the source object.
2455 if Is_Concurrent_Type (T)
2456 and then not Comes_From_Source (T)
2457 and then Nkind (N) = N_Object_Declaration
2458 then
2459 Error_Msg_NE
2460 ("type of& has incomplete component",
2461 N, Defining_Identifier (N));
2462 else
2463 Error_Msg_NE
2464 ("premature usage of incomplete}",
2465 N, First_Subtype (T));
2466 end if;
2467 end if;
2468 end Check_Fully_Declared;
2470 -------------------------------------------
2471 -- Check_Function_With_Address_Parameter --
2472 -------------------------------------------
2474 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2475 F : Entity_Id;
2476 T : Entity_Id;
2478 begin
2479 F := First_Formal (Subp_Id);
2480 while Present (F) loop
2481 T := Etype (F);
2483 if Is_Private_Type (T) and then Present (Full_View (T)) then
2484 T := Full_View (T);
2485 end if;
2487 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2488 Set_Is_Pure (Subp_Id, False);
2489 exit;
2490 end if;
2492 Next_Formal (F);
2493 end loop;
2494 end Check_Function_With_Address_Parameter;
2496 -------------------------------------
2497 -- Check_Function_Writable_Actuals --
2498 -------------------------------------
2500 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2501 Writable_Actuals_List : Elist_Id := No_Elist;
2502 Identifiers_List : Elist_Id := No_Elist;
2503 Aggr_Error_Node : Node_Id := Empty;
2504 Error_Node : Node_Id := Empty;
2506 procedure Collect_Identifiers (N : Node_Id);
2507 -- In a single traversal of subtree N collect in Writable_Actuals_List
2508 -- all the actuals of functions with writable actuals, and in the list
2509 -- Identifiers_List collect all the identifiers that are not actuals of
2510 -- functions with writable actuals. If a writable actual is referenced
2511 -- twice as writable actual then Error_Node is set to reference its
2512 -- second occurrence, the error is reported, and the tree traversal
2513 -- is abandoned.
2515 -------------------------
2516 -- Collect_Identifiers --
2517 -------------------------
2519 procedure Collect_Identifiers (N : Node_Id) is
2521 function Check_Node (N : Node_Id) return Traverse_Result;
2522 -- Process a single node during the tree traversal to collect the
2523 -- writable actuals of functions and all the identifiers which are
2524 -- not writable actuals of functions.
2526 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2527 -- Returns True if List has a node whose Entity is Entity (N)
2529 ----------------
2530 -- Check_Node --
2531 ----------------
2533 function Check_Node (N : Node_Id) return Traverse_Result is
2534 Is_Writable_Actual : Boolean := False;
2535 Id : Entity_Id := Empty;
2536 -- Default init of Id for CodePeer
2538 begin
2539 if Nkind (N) = N_Identifier then
2541 -- No analysis possible if the entity is not decorated
2543 if No (Entity (N)) then
2544 return Skip;
2546 -- Don't collect identifiers of packages, called functions, etc
2548 elsif Ekind (Entity (N)) in
2549 E_Package | E_Function | E_Procedure | E_Entry
2550 then
2551 return Skip;
2553 -- For rewritten nodes, continue the traversal in the original
2554 -- subtree. Needed to handle aggregates in original expressions
2555 -- extracted from the tree by Remove_Side_Effects.
2557 elsif Is_Rewrite_Substitution (N) then
2558 Collect_Identifiers (Original_Node (N));
2559 return Skip;
2561 -- For now we skip aggregate discriminants, since they require
2562 -- performing the analysis in two phases to identify conflicts:
2563 -- first one analyzing discriminants and second one analyzing
2564 -- the rest of components (since at run time, discriminants are
2565 -- evaluated prior to components): too much computation cost
2566 -- to identify a corner case???
2568 elsif Nkind (Parent (N)) = N_Component_Association
2569 and then Nkind (Parent (Parent (N))) in
2570 N_Aggregate | N_Extension_Aggregate
2571 then
2572 declare
2573 Choice : constant Node_Id := First (Choices (Parent (N)));
2575 begin
2576 if Ekind (Entity (N)) = E_Discriminant then
2577 return Skip;
2579 elsif Expression (Parent (N)) = N
2580 and then Nkind (Choice) = N_Identifier
2581 and then Ekind (Entity (Choice)) = E_Discriminant
2582 then
2583 return Skip;
2584 end if;
2585 end;
2587 -- Analyze if N is a writable actual of a function
2589 elsif Nkind (Parent (N)) = N_Function_Call then
2590 declare
2591 Call : constant Node_Id := Parent (N);
2592 Actual : Node_Id;
2593 Formal : Node_Id;
2595 begin
2596 Id := Get_Called_Entity (Call);
2598 -- In case of previous error, no check is possible
2600 if No (Id) then
2601 return Abandon;
2602 end if;
2604 if Ekind (Id) in E_Function | E_Generic_Function
2605 and then Has_Out_Or_In_Out_Parameter (Id)
2606 then
2607 Formal := First_Formal (Id);
2608 Actual := First_Actual (Call);
2609 while Present (Actual) and then Present (Formal) loop
2610 if Actual = N then
2611 if Ekind (Formal) in E_Out_Parameter
2612 | E_In_Out_Parameter
2613 then
2614 Is_Writable_Actual := True;
2615 end if;
2617 exit;
2618 end if;
2620 Next_Formal (Formal);
2621 Next_Actual (Actual);
2622 end loop;
2623 end if;
2624 end;
2625 end if;
2627 if Is_Writable_Actual then
2629 -- Skip checking the error in non-elementary types since
2630 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2631 -- store this actual in Writable_Actuals_List since it is
2632 -- needed to perform checks on other constructs that have
2633 -- arbitrary order of evaluation (for example, aggregates).
2635 if not Is_Elementary_Type (Etype (N)) then
2636 if not Contains (Writable_Actuals_List, N) then
2637 Append_New_Elmt (N, To => Writable_Actuals_List);
2638 end if;
2640 -- Second occurrence of an elementary type writable actual
2642 elsif Contains (Writable_Actuals_List, N) then
2644 -- Report the error on the second occurrence of the
2645 -- identifier. We cannot assume that N is the second
2646 -- occurrence (according to their location in the
2647 -- sources), since Traverse_Func walks through Field2
2648 -- last (see comment in the body of Traverse_Func).
2650 declare
2651 Elmt : Elmt_Id;
2653 begin
2654 Elmt := First_Elmt (Writable_Actuals_List);
2655 while Present (Elmt)
2656 and then Entity (Node (Elmt)) /= Entity (N)
2657 loop
2658 Next_Elmt (Elmt);
2659 end loop;
2661 if Sloc (N) > Sloc (Node (Elmt)) then
2662 Error_Node := N;
2663 else
2664 Error_Node := Node (Elmt);
2665 end if;
2667 Error_Msg_NE
2668 ("value may be affected by call to & "
2669 & "because order of evaluation is arbitrary",
2670 Error_Node, Id);
2671 return Abandon;
2672 end;
2674 -- First occurrence of a elementary type writable actual
2676 else
2677 Append_New_Elmt (N, To => Writable_Actuals_List);
2678 end if;
2680 else
2681 if No (Identifiers_List) then
2682 Identifiers_List := New_Elmt_List;
2683 end if;
2685 Append_Unique_Elmt (N, Identifiers_List);
2686 end if;
2687 end if;
2689 return OK;
2690 end Check_Node;
2692 --------------
2693 -- Contains --
2694 --------------
2696 function Contains
2697 (List : Elist_Id;
2698 N : Node_Id) return Boolean
2700 pragma Assert (Nkind (N) in N_Has_Entity);
2702 Elmt : Elmt_Id;
2704 begin
2705 if No (List) then
2706 return False;
2707 end if;
2709 Elmt := First_Elmt (List);
2710 while Present (Elmt) loop
2711 if Entity (Node (Elmt)) = Entity (N) then
2712 return True;
2713 else
2714 Next_Elmt (Elmt);
2715 end if;
2716 end loop;
2718 return False;
2719 end Contains;
2721 ------------------
2722 -- Do_Traversal --
2723 ------------------
2725 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2726 -- The traversal procedure
2728 -- Start of processing for Collect_Identifiers
2730 begin
2731 if Present (Error_Node) then
2732 return;
2733 end if;
2735 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2736 return;
2737 end if;
2739 Do_Traversal (N);
2740 end Collect_Identifiers;
2742 -- Start of processing for Check_Function_Writable_Actuals
2744 begin
2745 -- The check only applies to Ada 2012 code on which Check_Actuals has
2746 -- been set, and only to constructs that have multiple constituents
2747 -- whose order of evaluation is not specified by the language.
2749 if Ada_Version < Ada_2012
2750 or else not Check_Actuals (N)
2751 or else Nkind (N) not in N_Op
2752 | N_Membership_Test
2753 | N_Range
2754 | N_Aggregate
2755 | N_Extension_Aggregate
2756 | N_Full_Type_Declaration
2757 | N_Function_Call
2758 | N_Procedure_Call_Statement
2759 | N_Entry_Call_Statement
2760 or else (Nkind (N) = N_Full_Type_Declaration
2761 and then not Is_Record_Type (Defining_Identifier (N)))
2763 -- In addition, this check only applies to source code, not to code
2764 -- generated by constraint checks.
2766 or else not Comes_From_Source (N)
2767 then
2768 return;
2769 end if;
2771 -- If a construct C has two or more direct constituents that are names
2772 -- or expressions whose evaluation may occur in an arbitrary order, at
2773 -- least one of which contains a function call with an in out or out
2774 -- parameter, then the construct is legal only if: for each name N that
2775 -- is passed as a parameter of mode in out or out to some inner function
2776 -- call C2 (not including the construct C itself), there is no other
2777 -- name anywhere within a direct constituent of the construct C other
2778 -- than the one containing C2, that is known to refer to the same
2779 -- object (RM 6.4.1(6.17/3)).
2781 case Nkind (N) is
2782 when N_Range =>
2783 Collect_Identifiers (Low_Bound (N));
2784 Collect_Identifiers (High_Bound (N));
2786 when N_Membership_Test
2787 | N_Op
2789 declare
2790 Expr : Node_Id;
2792 begin
2793 Collect_Identifiers (Left_Opnd (N));
2795 if Present (Right_Opnd (N)) then
2796 Collect_Identifiers (Right_Opnd (N));
2797 end if;
2799 if Nkind (N) in N_Membership_Test then
2800 Expr := First (Alternatives (N));
2801 while Present (Expr) loop
2802 Collect_Identifiers (Expr);
2804 Next (Expr);
2805 end loop;
2806 end if;
2807 end;
2809 when N_Full_Type_Declaration =>
2810 declare
2811 function Get_Record_Part (N : Node_Id) return Node_Id;
2812 -- Return the record part of this record type definition
2814 ---------------------
2815 -- Get_Record_Part --
2816 ---------------------
2818 function Get_Record_Part (N : Node_Id) return Node_Id is
2819 Type_Def : constant Node_Id := Type_Definition (N);
2820 begin
2821 if Nkind (Type_Def) = N_Derived_Type_Definition then
2822 return Record_Extension_Part (Type_Def);
2823 else
2824 return Type_Def;
2825 end if;
2826 end Get_Record_Part;
2828 Comp : Node_Id;
2829 Def_Id : Entity_Id := Defining_Identifier (N);
2830 Rec : Node_Id := Get_Record_Part (N);
2832 begin
2833 -- No need to perform any analysis if the record has no
2834 -- components
2836 if No (Rec) or else No (Component_List (Rec)) then
2837 return;
2838 end if;
2840 -- Collect the identifiers starting from the deepest
2841 -- derivation. Done to report the error in the deepest
2842 -- derivation.
2844 loop
2845 if Present (Component_List (Rec)) then
2846 Comp := First (Component_Items (Component_List (Rec)));
2847 while Present (Comp) loop
2848 if Nkind (Comp) = N_Component_Declaration
2849 and then Present (Expression (Comp))
2850 then
2851 Collect_Identifiers (Expression (Comp));
2852 end if;
2854 Next (Comp);
2855 end loop;
2856 end if;
2858 exit when No (Underlying_Type (Etype (Def_Id)))
2859 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2860 = Def_Id;
2862 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2863 Rec := Get_Record_Part (Parent (Def_Id));
2864 end loop;
2865 end;
2867 when N_Entry_Call_Statement
2868 | N_Subprogram_Call
2870 declare
2871 Id : constant Entity_Id := Get_Called_Entity (N);
2872 Formal : Node_Id;
2873 Actual : Node_Id;
2875 begin
2876 Formal := First_Formal (Id);
2877 Actual := First_Actual (N);
2878 while Present (Actual) and then Present (Formal) loop
2879 if Ekind (Formal) in E_Out_Parameter | E_In_Out_Parameter
2880 then
2881 Collect_Identifiers (Actual);
2882 end if;
2884 Next_Formal (Formal);
2885 Next_Actual (Actual);
2886 end loop;
2887 end;
2889 when N_Aggregate
2890 | N_Extension_Aggregate
2892 declare
2893 Assoc : Node_Id;
2894 Choice : Node_Id;
2895 Comp_Expr : Node_Id;
2897 begin
2898 -- Handle the N_Others_Choice of array aggregates with static
2899 -- bounds. There is no need to perform this analysis in
2900 -- aggregates without static bounds since we cannot evaluate
2901 -- if the N_Others_Choice covers several elements. There is
2902 -- no need to handle the N_Others choice of record aggregates
2903 -- since at this stage it has been already expanded by
2904 -- Resolve_Record_Aggregate.
2906 if Is_Array_Type (Etype (N))
2907 and then Nkind (N) = N_Aggregate
2908 and then Present (Aggregate_Bounds (N))
2909 and then Compile_Time_Known_Bounds (Etype (N))
2910 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2912 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2913 then
2914 declare
2915 Count_Components : Uint := Uint_0;
2916 Num_Components : Uint;
2917 Others_Assoc : Node_Id := Empty;
2918 Others_Choice : Node_Id := Empty;
2919 Others_Box_Present : Boolean := False;
2921 begin
2922 -- Count positional associations
2924 if Present (Expressions (N)) then
2925 Comp_Expr := First (Expressions (N));
2926 while Present (Comp_Expr) loop
2927 Count_Components := Count_Components + 1;
2928 Next (Comp_Expr);
2929 end loop;
2930 end if;
2932 -- Count the rest of elements and locate the N_Others
2933 -- choice (if any)
2935 Assoc := First (Component_Associations (N));
2936 while Present (Assoc) loop
2937 Choice := First (Choices (Assoc));
2938 while Present (Choice) loop
2939 if Nkind (Choice) = N_Others_Choice then
2940 Others_Assoc := Assoc;
2941 Others_Choice := Choice;
2942 Others_Box_Present := Box_Present (Assoc);
2944 -- Count several components
2946 elsif Nkind (Choice) in
2947 N_Range | N_Subtype_Indication
2948 or else (Is_Entity_Name (Choice)
2949 and then Is_Type (Entity (Choice)))
2950 then
2951 declare
2952 L, H : Node_Id;
2953 begin
2954 Get_Index_Bounds (Choice, L, H);
2955 pragma Assert
2956 (Compile_Time_Known_Value (L)
2957 and then Compile_Time_Known_Value (H));
2958 Count_Components :=
2959 Count_Components
2960 + Expr_Value (H) - Expr_Value (L) + 1;
2961 end;
2963 -- Count single component. No other case available
2964 -- since we are handling an aggregate with static
2965 -- bounds.
2967 else
2968 pragma Assert (Is_OK_Static_Expression (Choice)
2969 or else Nkind (Choice) = N_Identifier
2970 or else Nkind (Choice) = N_Integer_Literal);
2972 Count_Components := Count_Components + 1;
2973 end if;
2975 Next (Choice);
2976 end loop;
2978 Next (Assoc);
2979 end loop;
2981 Num_Components :=
2982 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2983 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2985 pragma Assert (Count_Components <= Num_Components);
2987 -- Handle the N_Others choice if it covers several
2988 -- components
2990 if Present (Others_Choice)
2991 and then (Num_Components - Count_Components) > 1
2992 then
2993 if not Others_Box_Present then
2995 -- At this stage, if expansion is active, the
2996 -- expression of the others choice has not been
2997 -- analyzed. Hence we generate a duplicate and
2998 -- we analyze it silently to have available the
2999 -- minimum decoration required to collect the
3000 -- identifiers.
3002 pragma Assert (Present (Others_Assoc));
3004 if not Expander_Active then
3005 Comp_Expr := Expression (Others_Assoc);
3006 else
3007 Comp_Expr :=
3008 New_Copy_Tree (Expression (Others_Assoc));
3009 Preanalyze_Without_Errors (Comp_Expr);
3010 end if;
3012 Collect_Identifiers (Comp_Expr);
3014 if Present (Writable_Actuals_List) then
3016 -- As suggested by Robert, at current stage we
3017 -- report occurrences of this case as warnings.
3019 Error_Msg_N
3020 ("writable function parameter may affect "
3021 & "value in other component because order "
3022 & "of evaluation is unspecified??",
3023 Node (First_Elmt (Writable_Actuals_List)));
3024 end if;
3025 end if;
3026 end if;
3027 end;
3029 -- For an array aggregate, a discrete_choice_list that has
3030 -- a nonstatic range is considered as two or more separate
3031 -- occurrences of the expression (RM 6.4.1(20/3)).
3033 elsif Is_Array_Type (Etype (N))
3034 and then Nkind (N) = N_Aggregate
3035 and then Present (Aggregate_Bounds (N))
3036 and then not Compile_Time_Known_Bounds (Etype (N))
3037 then
3038 -- Collect identifiers found in the dynamic bounds
3040 declare
3041 Count_Components : Natural := 0;
3042 Low, High : Node_Id;
3044 begin
3045 Assoc := First (Component_Associations (N));
3046 while Present (Assoc) loop
3047 Choice := First (Choices (Assoc));
3048 while Present (Choice) loop
3049 if Nkind (Choice) in
3050 N_Range | N_Subtype_Indication
3051 or else (Is_Entity_Name (Choice)
3052 and then Is_Type (Entity (Choice)))
3053 then
3054 Get_Index_Bounds (Choice, Low, High);
3056 if not Compile_Time_Known_Value (Low) then
3057 Collect_Identifiers (Low);
3059 if No (Aggr_Error_Node) then
3060 Aggr_Error_Node := Low;
3061 end if;
3062 end if;
3064 if not Compile_Time_Known_Value (High) then
3065 Collect_Identifiers (High);
3067 if No (Aggr_Error_Node) then
3068 Aggr_Error_Node := High;
3069 end if;
3070 end if;
3072 -- The RM rule is violated if there is more than
3073 -- a single choice in a component association.
3075 else
3076 Count_Components := Count_Components + 1;
3078 if No (Aggr_Error_Node)
3079 and then Count_Components > 1
3080 then
3081 Aggr_Error_Node := Choice;
3082 end if;
3084 if not Compile_Time_Known_Value (Choice) then
3085 Collect_Identifiers (Choice);
3086 end if;
3087 end if;
3089 Next (Choice);
3090 end loop;
3092 Next (Assoc);
3093 end loop;
3094 end;
3095 end if;
3097 -- Handle ancestor part of extension aggregates
3099 if Nkind (N) = N_Extension_Aggregate then
3100 Collect_Identifiers (Ancestor_Part (N));
3101 end if;
3103 -- Handle positional associations
3105 if Present (Expressions (N)) then
3106 Comp_Expr := First (Expressions (N));
3107 while Present (Comp_Expr) loop
3108 if not Is_OK_Static_Expression (Comp_Expr) then
3109 Collect_Identifiers (Comp_Expr);
3110 end if;
3112 Next (Comp_Expr);
3113 end loop;
3114 end if;
3116 -- Handle discrete associations
3118 if Present (Component_Associations (N)) then
3119 Assoc := First (Component_Associations (N));
3120 while Present (Assoc) loop
3122 if not Box_Present (Assoc) then
3123 Choice := First (Choices (Assoc));
3124 while Present (Choice) loop
3126 -- For now we skip discriminants since it requires
3127 -- performing the analysis in two phases: first one
3128 -- analyzing discriminants and second one analyzing
3129 -- the rest of components since discriminants are
3130 -- evaluated prior to components: too much extra
3131 -- work to detect a corner case???
3133 if Nkind (Choice) in N_Has_Entity
3134 and then Present (Entity (Choice))
3135 and then Ekind (Entity (Choice)) = E_Discriminant
3136 then
3137 null;
3139 elsif Box_Present (Assoc) then
3140 null;
3142 else
3143 if not Analyzed (Expression (Assoc)) then
3144 Comp_Expr :=
3145 New_Copy_Tree (Expression (Assoc));
3146 Set_Parent (Comp_Expr, Parent (N));
3147 Preanalyze_Without_Errors (Comp_Expr);
3148 else
3149 Comp_Expr := Expression (Assoc);
3150 end if;
3152 Collect_Identifiers (Comp_Expr);
3153 end if;
3155 Next (Choice);
3156 end loop;
3157 end if;
3159 Next (Assoc);
3160 end loop;
3161 end if;
3162 end;
3164 when others =>
3165 return;
3166 end case;
3168 -- No further action needed if we already reported an error
3170 if Present (Error_Node) then
3171 return;
3172 end if;
3174 -- Check violation of RM 6.20/3 in aggregates
3176 if Present (Aggr_Error_Node)
3177 and then Present (Writable_Actuals_List)
3178 then
3179 Error_Msg_N
3180 ("value may be affected by call in other component because they "
3181 & "are evaluated in unspecified order",
3182 Node (First_Elmt (Writable_Actuals_List)));
3183 return;
3184 end if;
3186 -- Check if some writable argument of a function is referenced
3188 if Present (Writable_Actuals_List)
3189 and then Present (Identifiers_List)
3190 then
3191 declare
3192 Elmt_1 : Elmt_Id;
3193 Elmt_2 : Elmt_Id;
3195 begin
3196 Elmt_1 := First_Elmt (Writable_Actuals_List);
3197 while Present (Elmt_1) loop
3198 Elmt_2 := First_Elmt (Identifiers_List);
3199 while Present (Elmt_2) loop
3200 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
3201 case Nkind (Parent (Node (Elmt_2))) is
3202 when N_Aggregate
3203 | N_Component_Association
3204 | N_Component_Declaration
3206 Error_Msg_N
3207 ("value may be affected by call in other "
3208 & "component because they are evaluated "
3209 & "in unspecified order",
3210 Node (Elmt_2));
3212 when N_Membership_Test =>
3213 Error_Msg_N
3214 ("value may be affected by call in other "
3215 & "alternative because they are evaluated "
3216 & "in unspecified order",
3217 Node (Elmt_2));
3219 when others =>
3220 Error_Msg_N
3221 ("value of actual may be affected by call in "
3222 & "other actual because they are evaluated "
3223 & "in unspecified order",
3224 Node (Elmt_2));
3225 end case;
3226 end if;
3228 Next_Elmt (Elmt_2);
3229 end loop;
3231 Next_Elmt (Elmt_1);
3232 end loop;
3233 end;
3234 end if;
3235 end Check_Function_Writable_Actuals;
3237 --------------------------------
3238 -- Check_Implicit_Dereference --
3239 --------------------------------
3241 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
3242 Disc : Entity_Id;
3243 Desig : Entity_Id;
3244 Nam : Node_Id;
3246 begin
3247 if Nkind (N) = N_Indexed_Component
3248 and then Present (Generalized_Indexing (N))
3249 then
3250 Nam := Generalized_Indexing (N);
3251 else
3252 Nam := N;
3253 end if;
3255 if Ada_Version < Ada_2012
3256 or else not Has_Implicit_Dereference (Base_Type (Typ))
3257 then
3258 return;
3260 elsif not Comes_From_Source (N)
3261 and then Nkind (N) /= N_Indexed_Component
3262 then
3263 return;
3265 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
3266 null;
3268 else
3269 Disc := First_Discriminant (Typ);
3270 while Present (Disc) loop
3271 if Has_Implicit_Dereference (Disc) then
3272 Desig := Designated_Type (Etype (Disc));
3273 Add_One_Interp (Nam, Disc, Desig);
3275 -- If the node is a generalized indexing, add interpretation
3276 -- to that node as well, for subsequent resolution.
3278 if Nkind (N) = N_Indexed_Component then
3279 Add_One_Interp (N, Disc, Desig);
3280 end if;
3282 -- If the operation comes from a generic unit and the context
3283 -- is a selected component, the selector name may be global
3284 -- and set in the instance already. Remove the entity to
3285 -- force resolution of the selected component, and the
3286 -- generation of an explicit dereference if needed.
3288 if In_Instance
3289 and then Nkind (Parent (Nam)) = N_Selected_Component
3290 then
3291 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3292 end if;
3294 exit;
3295 end if;
3297 Next_Discriminant (Disc);
3298 end loop;
3299 end if;
3300 end Check_Implicit_Dereference;
3302 ----------------------------------
3303 -- Check_Internal_Protected_Use --
3304 ----------------------------------
3306 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3307 S : Entity_Id;
3308 Prot : Entity_Id;
3310 begin
3311 Prot := Empty;
3313 S := Current_Scope;
3314 while Present (S) loop
3315 if S = Standard_Standard then
3316 exit;
3318 elsif Ekind (S) = E_Function
3319 and then Ekind (Scope (S)) = E_Protected_Type
3320 then
3321 Prot := Scope (S);
3322 exit;
3323 end if;
3325 S := Scope (S);
3326 end loop;
3328 if Present (Prot)
3329 and then Scope (Nam) = Prot
3330 and then Ekind (Nam) /= E_Function
3331 then
3332 -- An indirect function call (e.g. a callback within a protected
3333 -- function body) is not statically illegal. If the access type is
3334 -- anonymous and is the type of an access parameter, the scope of Nam
3335 -- will be the protected type, but it is not a protected operation.
3337 if Ekind (Nam) = E_Subprogram_Type
3338 and then Nkind (Associated_Node_For_Itype (Nam)) =
3339 N_Function_Specification
3340 then
3341 null;
3343 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3344 Error_Msg_N
3345 ("within protected function cannot use protected procedure in "
3346 & "renaming or as generic actual", N);
3348 elsif Nkind (N) = N_Attribute_Reference then
3349 Error_Msg_N
3350 ("within protected function cannot take access of protected "
3351 & "procedure", N);
3353 else
3354 Error_Msg_N
3355 ("within protected function, protected object is constant", N);
3356 Error_Msg_N
3357 ("\cannot call operation that may modify it", N);
3358 end if;
3359 end if;
3361 -- Verify that an internal call does not appear within a precondition
3362 -- of a protected operation. This implements AI12-0166.
3363 -- The precondition aspect has been rewritten as a pragma Precondition
3364 -- and we check whether the scope of the called subprogram is the same
3365 -- as that of the entity to which the aspect applies.
3367 if Convention (Nam) = Convention_Protected then
3368 declare
3369 P : Node_Id;
3371 begin
3372 P := Parent (N);
3373 while Present (P) loop
3374 if Nkind (P) = N_Pragma
3375 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3376 and then From_Aspect_Specification (P)
3377 and then
3378 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3379 then
3380 Error_Msg_N
3381 ("internal call cannot appear in precondition of "
3382 & "protected operation", N);
3383 return;
3385 elsif Nkind (P) = N_Pragma
3386 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3387 then
3388 -- Check whether call is in a case guard. It is legal in a
3389 -- consequence.
3391 P := N;
3392 while Present (P) loop
3393 if Nkind (Parent (P)) = N_Component_Association
3394 and then P /= Expression (Parent (P))
3395 then
3396 Error_Msg_N
3397 ("internal call cannot appear in case guard in a "
3398 & "contract case", N);
3399 end if;
3401 P := Parent (P);
3402 end loop;
3404 return;
3406 elsif Nkind (P) = N_Parameter_Specification
3407 and then Scope (Current_Scope) = Scope (Nam)
3408 and then Nkind (Parent (P)) in
3409 N_Entry_Declaration | N_Subprogram_Declaration
3410 then
3411 Error_Msg_N
3412 ("internal call cannot appear in default for formal of "
3413 & "protected operation", N);
3414 return;
3416 -- Prevent the search from going too far
3418 elsif Is_Body_Or_Package_Declaration (P) then
3419 exit;
3420 end if;
3422 P := Parent (P);
3423 end loop;
3424 end;
3425 end if;
3426 end Check_Internal_Protected_Use;
3428 ---------------------------------------
3429 -- Check_Later_Vs_Basic_Declarations --
3430 ---------------------------------------
3432 procedure Check_Later_Vs_Basic_Declarations
3433 (Decls : List_Id;
3434 During_Parsing : Boolean)
3436 Body_Sloc : Source_Ptr;
3437 Decl : Node_Id;
3439 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3440 -- Return whether Decl is considered as a declarative item.
3441 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3442 -- When During_Parsing is False, the semantics of SPARK is followed.
3444 -------------------------------
3445 -- Is_Later_Declarative_Item --
3446 -------------------------------
3448 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3449 begin
3450 if Nkind (Decl) in N_Later_Decl_Item then
3451 return True;
3453 elsif Nkind (Decl) = N_Pragma then
3454 return True;
3456 elsif During_Parsing then
3457 return False;
3459 -- In SPARK, a package declaration is not considered as a later
3460 -- declarative item.
3462 elsif Nkind (Decl) = N_Package_Declaration then
3463 return False;
3465 -- In SPARK, a renaming is considered as a later declarative item
3467 elsif Nkind (Decl) in N_Renaming_Declaration then
3468 return True;
3470 else
3471 return False;
3472 end if;
3473 end Is_Later_Declarative_Item;
3475 -- Start of processing for Check_Later_Vs_Basic_Declarations
3477 begin
3478 Decl := First (Decls);
3480 -- Loop through sequence of basic declarative items
3482 Outer : while Present (Decl) loop
3483 if Nkind (Decl) not in
3484 N_Subprogram_Body | N_Package_Body | N_Task_Body
3485 and then Nkind (Decl) not in N_Body_Stub
3486 then
3487 Next (Decl);
3489 -- Once a body is encountered, we only allow later declarative
3490 -- items. The inner loop checks the rest of the list.
3492 else
3493 Body_Sloc := Sloc (Decl);
3495 Inner : while Present (Decl) loop
3496 if not Is_Later_Declarative_Item (Decl) then
3497 if During_Parsing then
3498 if Ada_Version = Ada_83 then
3499 Error_Msg_Sloc := Body_Sloc;
3500 Error_Msg_N
3501 ("(Ada 83) decl cannot appear after body#", Decl);
3502 end if;
3503 end if;
3504 end if;
3506 Next (Decl);
3507 end loop Inner;
3508 end if;
3509 end loop Outer;
3510 end Check_Later_Vs_Basic_Declarations;
3512 ---------------------------
3513 -- Check_No_Hidden_State --
3514 ---------------------------
3516 procedure Check_No_Hidden_State (Id : Entity_Id) is
3517 Context : Entity_Id := Empty;
3518 Not_Visible : Boolean := False;
3519 Scop : Entity_Id;
3521 begin
3522 pragma Assert (Ekind (Id) in E_Abstract_State | E_Variable);
3524 -- Nothing to do for internally-generated abstract states and variables
3525 -- because they do not represent the hidden state of the source unit.
3527 if not Comes_From_Source (Id) then
3528 return;
3529 end if;
3531 -- Find the proper context where the object or state appears
3533 Scop := Scope (Id);
3534 while Present (Scop) loop
3535 Context := Scop;
3537 -- Keep track of the context's visibility
3539 Not_Visible := Not_Visible or else In_Private_Part (Context);
3541 -- Prevent the search from going too far
3543 if Context = Standard_Standard then
3544 return;
3546 -- Objects and states that appear immediately within a subprogram or
3547 -- entry inside a construct nested within a subprogram do not
3548 -- introduce a hidden state. They behave as local variable
3549 -- declarations. The same is true for elaboration code inside a block
3550 -- or a task.
3552 elsif Is_Subprogram_Or_Entry (Context)
3553 or else Ekind (Context) in E_Block | E_Task_Type
3554 then
3555 return;
3556 end if;
3558 -- Stop the traversal when a package subject to a null abstract state
3559 -- has been found.
3561 if Is_Package_Or_Generic_Package (Context)
3562 and then Has_Null_Abstract_State (Context)
3563 then
3564 exit;
3565 end if;
3567 Scop := Scope (Scop);
3568 end loop;
3570 -- At this point we know that there is at least one package with a null
3571 -- abstract state in visibility. Emit an error message unconditionally
3572 -- if the entity being processed is a state because the placement of the
3573 -- related package is irrelevant. This is not the case for objects as
3574 -- the intermediate context matters.
3576 if Present (Context)
3577 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3578 then
3579 Error_Msg_N ("cannot introduce hidden state &", Id);
3580 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3581 end if;
3582 end Check_No_Hidden_State;
3584 ---------------------------------------------
3585 -- Check_Nonoverridable_Aspect_Consistency --
3586 ---------------------------------------------
3588 procedure Check_Inherited_Nonoverridable_Aspects
3589 (Inheritor : Entity_Id;
3590 Interface_List : List_Id;
3591 Parent_Type : Entity_Id) is
3593 -- array needed for iterating over subtype values
3594 Nonoverridable_Aspects : constant array (Positive range <>) of
3595 Nonoverridable_Aspect_Id :=
3596 (Aspect_Default_Iterator,
3597 Aspect_Iterator_Element,
3598 Aspect_Implicit_Dereference,
3599 Aspect_Constant_Indexing,
3600 Aspect_Variable_Indexing,
3601 Aspect_Aggregate,
3602 Aspect_Max_Entry_Queue_Length
3603 -- , Aspect_No_Controlled_Parts
3606 -- Note that none of these 8 aspects can be specified (for a type)
3607 -- via a pragma. For 7 of them, the corresponding pragma does not
3608 -- exist. The Pragma_Id enumeration type does include
3609 -- Pragma_Max_Entry_Queue_Length, but that pragma is only use to
3610 -- specify the aspect for a protected entry or entry family, not for
3611 -- a type, and therefore cannot introduce the sorts of inheritance
3612 -- issues that we are concerned with in this procedure.
3614 type Entity_Array is array (Nat range <>) of Entity_Id;
3616 function Ancestor_Entities return Entity_Array;
3617 -- Returns all progenitors (including parent type, if present)
3619 procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3620 (Aspect : Nonoverridable_Aspect_Id;
3621 Ancestor_1 : Entity_Id;
3622 Aspect_Spec_1 : Node_Id;
3623 Ancestor_2 : Entity_Id;
3624 Aspect_Spec_2 : Node_Id);
3625 -- A given aspect has been specified for each of two ancestors;
3626 -- check that the two aspect specifications are compatible (see
3627 -- RM 13.1.1(18.5) and AI12-0211).
3629 -----------------------
3630 -- Ancestor_Entities --
3631 -----------------------
3633 function Ancestor_Entities return Entity_Array is
3634 Ifc_Count : constant Nat := List_Length (Interface_List);
3635 Ifc_Ancestors : Entity_Array (1 .. Ifc_Count);
3636 Ifc : Node_Id := First (Interface_List);
3637 begin
3638 for Idx in Ifc_Ancestors'Range loop
3639 Ifc_Ancestors (Idx) := Entity (Ifc);
3640 pragma Assert (Present (Ifc_Ancestors (Idx)));
3641 Ifc := Next (Ifc);
3642 end loop;
3643 pragma Assert (No (Ifc));
3644 if Present (Parent_Type) then
3645 return Parent_Type & Ifc_Ancestors;
3646 else
3647 return Ifc_Ancestors;
3648 end if;
3649 end Ancestor_Entities;
3651 -------------------------------------------------------
3652 -- Check_Consistency_For_One_Aspect_Of_Two_Ancestors --
3653 -------------------------------------------------------
3655 procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3656 (Aspect : Nonoverridable_Aspect_Id;
3657 Ancestor_1 : Entity_Id;
3658 Aspect_Spec_1 : Node_Id;
3659 Ancestor_2 : Entity_Id;
3660 Aspect_Spec_2 : Node_Id) is
3661 begin
3662 if not Is_Confirming (Aspect, Aspect_Spec_1, Aspect_Spec_2) then
3663 Error_Msg_Name_1 := Aspect_Names (Aspect);
3664 Error_Msg_Name_2 := Chars (Ancestor_1);
3665 Error_Msg_Name_3 := Chars (Ancestor_2);
3667 Error_Msg (
3668 "incompatible % aspects inherited from ancestors % and %",
3669 Sloc (Inheritor));
3670 end if;
3671 end Check_Consistency_For_One_Aspect_Of_Two_Ancestors;
3673 Ancestors : constant Entity_Array := Ancestor_Entities;
3675 -- start of processing for Check_Inherited_Nonoverridable_Aspects
3676 begin
3677 -- No Ada_Version check here; AI12-0211 is a binding interpretation.
3679 if Ancestors'Length < 2 then
3680 return; -- Inconsistency impossible; it takes 2 to disagree.
3681 elsif In_Instance_Body then
3682 return; -- No legality checking in an instance body.
3683 end if;
3685 for Aspect of Nonoverridable_Aspects loop
3686 declare
3687 First_Ancestor_With_Aspect : Entity_Id := Empty;
3688 First_Aspect_Spec, Current_Aspect_Spec : Node_Id := Empty;
3689 begin
3690 for Ancestor of Ancestors loop
3691 Current_Aspect_Spec := Find_Aspect (Ancestor, Aspect);
3692 if Present (Current_Aspect_Spec) then
3693 if Present (First_Ancestor_With_Aspect) then
3694 Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3695 (Aspect => Aspect,
3696 Ancestor_1 => First_Ancestor_With_Aspect,
3697 Aspect_Spec_1 => First_Aspect_Spec,
3698 Ancestor_2 => Ancestor,
3699 Aspect_Spec_2 => Current_Aspect_Spec);
3700 else
3701 First_Ancestor_With_Aspect := Ancestor;
3702 First_Aspect_Spec := Current_Aspect_Spec;
3703 end if;
3704 end if;
3705 end loop;
3706 end;
3707 end loop;
3708 end Check_Inherited_Nonoverridable_Aspects;
3710 -------------------
3711 -- Check_Parents --
3712 -------------------
3714 function Check_Parents (N : Node_Id; List : Elist_Id) return Boolean is
3716 function Check_Node
3717 (Parent_Node : Node_Id;
3718 N : Node_Id) return Traverse_Result;
3719 -- Process a single node.
3721 ----------------
3722 -- Check_Node --
3723 ----------------
3725 function Check_Node
3726 (Parent_Node : Node_Id;
3727 N : Node_Id) return Traverse_Result is
3728 begin
3729 if Nkind (N) = N_Identifier
3730 and then Parent (N) /= Parent_Node
3731 and then Present (Entity (N))
3732 and then Contains (List, Entity (N))
3733 then
3734 return Abandon;
3735 end if;
3737 return OK;
3738 end Check_Node;
3740 function Traverse is new Traverse_Func_With_Parent (Check_Node);
3742 -- Start of processing for Check_Parents
3744 begin
3745 return Traverse (N) = OK;
3746 end Check_Parents;
3748 -----------------------------
3749 -- Check_Part_Of_Reference --
3750 -----------------------------
3752 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3753 function Is_Enclosing_Package_Body
3754 (Body_Decl : Node_Id;
3755 Obj_Id : Entity_Id) return Boolean;
3756 pragma Inline (Is_Enclosing_Package_Body);
3757 -- Determine whether package body Body_Decl or its corresponding spec
3758 -- immediately encloses the declaration of object Obj_Id.
3760 function Is_Internal_Declaration_Or_Body
3761 (Decl : Node_Id) return Boolean;
3762 pragma Inline (Is_Internal_Declaration_Or_Body);
3763 -- Determine whether declaration or body denoted by Decl is internal
3765 function Is_Single_Declaration_Or_Body
3766 (Decl : Node_Id;
3767 Conc_Typ : Entity_Id) return Boolean;
3768 pragma Inline (Is_Single_Declaration_Or_Body);
3769 -- Determine whether protected/task declaration or body denoted by Decl
3770 -- belongs to single concurrent type Conc_Typ.
3772 function Is_Single_Task_Pragma
3773 (Prag : Node_Id;
3774 Task_Typ : Entity_Id) return Boolean;
3775 pragma Inline (Is_Single_Task_Pragma);
3776 -- Determine whether pragma Prag belongs to single task type Task_Typ
3778 -------------------------------
3779 -- Is_Enclosing_Package_Body --
3780 -------------------------------
3782 function Is_Enclosing_Package_Body
3783 (Body_Decl : Node_Id;
3784 Obj_Id : Entity_Id) return Boolean
3786 Obj_Context : Node_Id;
3788 begin
3789 -- Find the context of the object declaration
3791 Obj_Context := Parent (Declaration_Node (Obj_Id));
3793 if Nkind (Obj_Context) = N_Package_Specification then
3794 Obj_Context := Parent (Obj_Context);
3795 end if;
3797 -- The object appears immediately within the package body
3799 if Obj_Context = Body_Decl then
3800 return True;
3802 -- The object appears immediately within the corresponding spec
3804 elsif Nkind (Obj_Context) = N_Package_Declaration
3805 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3806 Obj_Context
3807 then
3808 return True;
3809 end if;
3811 return False;
3812 end Is_Enclosing_Package_Body;
3814 -------------------------------------
3815 -- Is_Internal_Declaration_Or_Body --
3816 -------------------------------------
3818 function Is_Internal_Declaration_Or_Body
3819 (Decl : Node_Id) return Boolean
3821 begin
3822 if Comes_From_Source (Decl) then
3823 return False;
3825 -- A body generated for an expression function which has not been
3826 -- inserted into the tree yet (In_Spec_Expression is True) is not
3827 -- considered internal.
3829 elsif Nkind (Decl) = N_Subprogram_Body
3830 and then Was_Expression_Function (Decl)
3831 and then not In_Spec_Expression
3832 then
3833 return False;
3834 end if;
3836 return True;
3837 end Is_Internal_Declaration_Or_Body;
3839 -----------------------------------
3840 -- Is_Single_Declaration_Or_Body --
3841 -----------------------------------
3843 function Is_Single_Declaration_Or_Body
3844 (Decl : Node_Id;
3845 Conc_Typ : Entity_Id) return Boolean
3847 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3849 begin
3850 return
3851 Present (Anonymous_Object (Spec_Id))
3852 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3853 end Is_Single_Declaration_Or_Body;
3855 ---------------------------
3856 -- Is_Single_Task_Pragma --
3857 ---------------------------
3859 function Is_Single_Task_Pragma
3860 (Prag : Node_Id;
3861 Task_Typ : Entity_Id) return Boolean
3863 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3865 begin
3866 -- To qualify, the pragma must be associated with single task type
3867 -- Task_Typ.
3869 return
3870 Is_Single_Task_Object (Task_Typ)
3871 and then Nkind (Decl) = N_Object_Declaration
3872 and then Defining_Entity (Decl) = Task_Typ;
3873 end Is_Single_Task_Pragma;
3875 -- Local variables
3877 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3878 Par : Node_Id;
3879 Prag_Nam : Name_Id;
3880 Prev : Node_Id;
3882 -- Start of processing for Check_Part_Of_Reference
3884 begin
3885 -- Nothing to do when the variable was recorded, but did not become a
3886 -- constituent of a single concurrent type.
3888 if No (Conc_Obj) then
3889 return;
3890 end if;
3892 -- Traverse the parent chain looking for a suitable context for the
3893 -- reference to the concurrent constituent.
3895 Prev := Ref;
3896 Par := Parent (Prev);
3897 while Present (Par) loop
3898 if Nkind (Par) = N_Pragma then
3899 Prag_Nam := Pragma_Name (Par);
3901 -- A concurrent constituent is allowed to appear in pragmas
3902 -- Initial_Condition and Initializes as this is part of the
3903 -- elaboration checks for the constituent (SPARK RM 9(3)).
3905 if Prag_Nam in Name_Initial_Condition | Name_Initializes then
3906 return;
3908 -- When the reference appears within pragma Depends or Global,
3909 -- check whether the pragma applies to a single task type. Note
3910 -- that the pragma may not encapsulated by the type definition,
3911 -- but this is still a valid context.
3913 elsif Prag_Nam in Name_Depends | Name_Global
3914 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3915 then
3916 return;
3917 end if;
3919 -- The reference appears somewhere in the definition of a single
3920 -- concurrent type (SPARK RM 9(3)).
3922 elsif Nkind (Par) in
3923 N_Single_Protected_Declaration | N_Single_Task_Declaration
3924 and then Defining_Entity (Par) = Conc_Obj
3925 then
3926 return;
3928 -- The reference appears within the declaration or body of a single
3929 -- concurrent type (SPARK RM 9(3)).
3931 elsif Nkind (Par) in N_Protected_Body
3932 | N_Protected_Type_Declaration
3933 | N_Task_Body
3934 | N_Task_Type_Declaration
3935 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3936 then
3937 return;
3939 -- The reference appears within the statement list of the object's
3940 -- immediately enclosing package (SPARK RM 9(3)).
3942 elsif Nkind (Par) = N_Package_Body
3943 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3944 and then Is_Enclosing_Package_Body (Par, Var_Id)
3945 then
3946 return;
3948 -- The reference has been relocated within an internally generated
3949 -- package or subprogram. Assume that the reference is legal as the
3950 -- real check was already performed in the original context of the
3951 -- reference.
3953 elsif Nkind (Par) in N_Package_Body
3954 | N_Package_Declaration
3955 | N_Subprogram_Body
3956 | N_Subprogram_Declaration
3957 and then Is_Internal_Declaration_Or_Body (Par)
3958 then
3959 return;
3961 -- The reference has been relocated to an inlined body for GNATprove.
3962 -- Assume that the reference is legal as the real check was already
3963 -- performed in the original context of the reference.
3965 elsif GNATprove_Mode
3966 and then Nkind (Par) = N_Subprogram_Body
3967 and then Chars (Defining_Entity (Par)) = Name_uParent
3968 then
3969 return;
3970 end if;
3972 Prev := Par;
3973 Par := Parent (Prev);
3974 end loop;
3976 -- At this point it is known that the reference does not appear within a
3977 -- legal context.
3979 Error_Msg_NE
3980 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3981 Error_Msg_Name_1 := Chars (Var_Id);
3983 if Is_Single_Protected_Object (Conc_Obj) then
3984 Error_Msg_NE
3985 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3987 else
3988 Error_Msg_NE
3989 ("\% is constituent of single task type &", Ref, Conc_Obj);
3990 end if;
3991 end Check_Part_Of_Reference;
3993 ------------------------------------------
3994 -- Check_Potentially_Blocking_Operation --
3995 ------------------------------------------
3997 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3998 S : Entity_Id;
4000 begin
4001 -- N is one of the potentially blocking operations listed in 9.5.1(8).
4002 -- When pragma Detect_Blocking is active, the run time will raise
4003 -- Program_Error. Here we only issue a warning, since we generally
4004 -- support the use of potentially blocking operations in the absence
4005 -- of the pragma.
4007 -- Indirect blocking through a subprogram call cannot be diagnosed
4008 -- statically without interprocedural analysis, so we do not attempt
4009 -- to do it here.
4011 S := Scope (Current_Scope);
4012 while Present (S) and then S /= Standard_Standard loop
4013 if Is_Protected_Type (S) then
4014 Error_Msg_N
4015 ("potentially blocking operation in protected operation??", N);
4016 return;
4017 end if;
4019 S := Scope (S);
4020 end loop;
4021 end Check_Potentially_Blocking_Operation;
4023 ------------------------------------
4024 -- Check_Previous_Null_Procedure --
4025 ------------------------------------
4027 procedure Check_Previous_Null_Procedure
4028 (Decl : Node_Id;
4029 Prev : Entity_Id)
4031 begin
4032 if Ekind (Prev) = E_Procedure
4033 and then Nkind (Parent (Prev)) = N_Procedure_Specification
4034 and then Null_Present (Parent (Prev))
4035 then
4036 Error_Msg_Sloc := Sloc (Prev);
4037 Error_Msg_N
4038 ("declaration cannot complete previous null procedure#", Decl);
4039 end if;
4040 end Check_Previous_Null_Procedure;
4042 ---------------------------------
4043 -- Check_Result_And_Post_State --
4044 ---------------------------------
4046 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
4047 procedure Check_Result_And_Post_State_In_Pragma
4048 (Prag : Node_Id;
4049 Result_Seen : in out Boolean);
4050 -- Determine whether pragma Prag mentions attribute 'Result and whether
4051 -- the pragma contains an expression that evaluates differently in pre-
4052 -- and post-state. Prag is a [refined] postcondition or a contract-cases
4053 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
4055 -------------------------------------------
4056 -- Check_Result_And_Post_State_In_Pragma --
4057 -------------------------------------------
4059 procedure Check_Result_And_Post_State_In_Pragma
4060 (Prag : Node_Id;
4061 Result_Seen : in out Boolean)
4063 procedure Check_Conjunct (Expr : Node_Id);
4064 -- Check an individual conjunct in a conjunction of Boolean
4065 -- expressions, connected by "and" or "and then" operators.
4067 procedure Check_Conjuncts (Expr : Node_Id);
4068 -- Apply the post-state check to every conjunct in an expression, in
4069 -- case this is a conjunction of Boolean expressions. Otherwise apply
4070 -- it to the expression as a whole.
4072 procedure Check_Expression (Expr : Node_Id);
4073 -- Perform the 'Result and post-state checks on a given expression
4075 function Is_Function_Result (N : Node_Id) return Traverse_Result;
4076 -- Attempt to find attribute 'Result in a subtree denoted by N
4078 function Mentions_Post_State (N : Node_Id) return Boolean;
4079 -- Determine whether a subtree denoted by N mentions any construct
4080 -- that denotes a post-state.
4082 procedure Check_Function_Result is
4083 new Traverse_Proc (Is_Function_Result);
4085 --------------------
4086 -- Check_Conjunct --
4087 --------------------
4089 procedure Check_Conjunct (Expr : Node_Id) is
4090 function Adjust_Message (Msg : String) return String;
4091 -- Prepend a prefix to the input message Msg denoting that the
4092 -- message applies to a conjunct in the expression, when this
4093 -- is the case.
4095 function Applied_On_Conjunct return Boolean;
4096 -- Returns True if the message applies to a conjunct in the
4097 -- expression, instead of the whole expression.
4099 function Has_Global_Output (Subp : Entity_Id) return Boolean;
4100 -- Returns True if Subp has an output in its Global contract
4102 function Has_No_Output (Subp : Entity_Id) return Boolean;
4103 -- Returns True if Subp has no declared output: no function
4104 -- result, no output parameter, and no output in its Global
4105 -- contract.
4107 --------------------
4108 -- Adjust_Message --
4109 --------------------
4111 function Adjust_Message (Msg : String) return String is
4112 begin
4113 if Applied_On_Conjunct then
4114 return "conjunct in " & Msg;
4115 else
4116 return Msg;
4117 end if;
4118 end Adjust_Message;
4120 -------------------------
4121 -- Applied_On_Conjunct --
4122 -------------------------
4124 function Applied_On_Conjunct return Boolean is
4125 begin
4126 -- Expr is the conjunct of an enclosing "and" expression
4128 return Nkind (Parent (Expr)) in N_Subexpr;
4129 end Applied_On_Conjunct;
4131 -----------------------
4132 -- Has_Global_Output --
4133 -----------------------
4135 function Has_Global_Output (Subp : Entity_Id) return Boolean is
4136 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
4137 List : Node_Id;
4138 Assoc : Node_Id;
4140 begin
4141 if No (Global) then
4142 return False;
4143 end if;
4145 List := Expression (Get_Argument (Global, Subp));
4147 -- Empty list (no global items) or single global item
4148 -- declaration (only input items).
4150 if Nkind (List) in N_Null
4151 | N_Expanded_Name
4152 | N_Identifier
4153 | N_Selected_Component
4154 then
4155 return False;
4157 -- Simple global list (only input items) or moded global list
4158 -- declaration.
4160 elsif Nkind (List) = N_Aggregate then
4161 if Present (Expressions (List)) then
4162 return False;
4164 else
4165 Assoc := First (Component_Associations (List));
4166 while Present (Assoc) loop
4167 if Chars (First (Choices (Assoc))) /= Name_Input then
4168 return True;
4169 end if;
4171 Next (Assoc);
4172 end loop;
4174 return False;
4175 end if;
4177 -- To accommodate partial decoration of disabled SPARK
4178 -- features, this routine may be called with illegal input.
4179 -- If this is the case, do not raise Program_Error.
4181 else
4182 return False;
4183 end if;
4184 end Has_Global_Output;
4186 -------------------
4187 -- Has_No_Output --
4188 -------------------
4190 function Has_No_Output (Subp : Entity_Id) return Boolean is
4191 Param : Entity_Id;
4193 begin
4194 -- A function has its result as output
4196 if Ekind (Subp) = E_Function then
4197 return False;
4198 end if;
4200 -- An OUT or IN OUT parameter is an output
4202 Param := First_Formal (Subp);
4203 while Present (Param) loop
4204 if Ekind (Param) in E_Out_Parameter | E_In_Out_Parameter then
4205 return False;
4206 end if;
4208 Next_Formal (Param);
4209 end loop;
4211 -- An item of mode Output or In_Out in the Global contract is
4212 -- an output.
4214 if Has_Global_Output (Subp) then
4215 return False;
4216 end if;
4218 return True;
4219 end Has_No_Output;
4221 -- Local variables
4223 Err_Node : Node_Id;
4224 -- Error node when reporting a warning on a (refined)
4225 -- postcondition.
4227 -- Start of processing for Check_Conjunct
4229 begin
4230 if Applied_On_Conjunct then
4231 Err_Node := Expr;
4232 else
4233 Err_Node := Prag;
4234 end if;
4236 -- Do not report missing reference to outcome in postcondition if
4237 -- either the postcondition is trivially True or False, or if the
4238 -- subprogram is ghost and has no declared output.
4240 if not Is_Trivial_Boolean (Expr)
4241 and then not Mentions_Post_State (Expr)
4242 and then not (Is_Ghost_Entity (Subp_Id)
4243 and then Has_No_Output (Subp_Id))
4244 and then not Is_Wrapper (Subp_Id)
4245 then
4246 case Pragma_Name (Prag) is
4247 when Name_Contract_Cases =>
4248 Error_Msg_NE (Adjust_Message
4249 ("contract case does not check the outcome of calling "
4250 & "&?.t?"), Expr, Subp_Id);
4252 when Name_Refined_Post =>
4253 Error_Msg_NE (Adjust_Message
4254 ("refined postcondition does not check the outcome of "
4255 & "calling &?.t?"), Err_Node, Subp_Id);
4257 when Name_Postcondition =>
4258 Error_Msg_NE (Adjust_Message
4259 ("postcondition does not check the outcome of calling "
4260 & "&?.t?"), Err_Node, Subp_Id);
4262 when others => pragma Assert (False);
4263 end case;
4264 end if;
4265 end Check_Conjunct;
4267 ---------------------
4268 -- Check_Conjuncts --
4269 ---------------------
4271 procedure Check_Conjuncts (Expr : Node_Id) is
4272 begin
4273 if Nkind (Expr) in N_Op_And | N_And_Then then
4274 Check_Conjuncts (Left_Opnd (Expr));
4275 Check_Conjuncts (Right_Opnd (Expr));
4276 else
4277 Check_Conjunct (Expr);
4278 end if;
4279 end Check_Conjuncts;
4281 ----------------------
4282 -- Check_Expression --
4283 ----------------------
4285 procedure Check_Expression (Expr : Node_Id) is
4286 begin
4287 if not Is_Trivial_Boolean (Expr) then
4288 Check_Function_Result (Expr);
4289 Check_Conjuncts (Expr);
4290 end if;
4291 end Check_Expression;
4293 ------------------------
4294 -- Is_Function_Result --
4295 ------------------------
4297 function Is_Function_Result (N : Node_Id) return Traverse_Result is
4298 begin
4299 if Is_Attribute_Result (N) then
4300 Result_Seen := True;
4301 return Abandon;
4303 -- Warn on infinite recursion if call is to current function
4305 elsif Nkind (N) = N_Function_Call
4306 and then Is_Entity_Name (Name (N))
4307 and then Entity (Name (N)) = Subp_Id
4308 and then not Is_Potentially_Unevaluated (N)
4309 then
4310 Error_Msg_NE
4311 ("call to & within its postcondition will lead to infinite "
4312 & "recursion?", N, Subp_Id);
4313 return OK;
4315 -- Continue the traversal
4317 else
4318 return OK;
4319 end if;
4320 end Is_Function_Result;
4322 -------------------------
4323 -- Mentions_Post_State --
4324 -------------------------
4326 function Mentions_Post_State (N : Node_Id) return Boolean is
4327 Post_State_Seen : Boolean := False;
4329 function Is_Post_State (N : Node_Id) return Traverse_Result;
4330 -- Attempt to find a construct that denotes a post-state. If this
4331 -- is the case, set flag Post_State_Seen.
4333 -------------------
4334 -- Is_Post_State --
4335 -------------------
4337 function Is_Post_State (N : Node_Id) return Traverse_Result is
4338 Ent : Entity_Id;
4340 begin
4341 if Nkind (N) in N_Explicit_Dereference | N_Function_Call then
4342 Post_State_Seen := True;
4343 return Abandon;
4345 elsif Nkind (N) in N_Expanded_Name | N_Identifier then
4346 Ent := Entity (N);
4348 -- Treat an undecorated reference as OK
4350 if No (Ent)
4352 -- A reference to an assignable entity is considered a
4353 -- change in the post-state of a subprogram.
4355 or else Ekind (Ent) in E_Generic_In_Out_Parameter
4356 | E_In_Out_Parameter
4357 | E_Out_Parameter
4358 | E_Variable
4360 -- The reference may be modified through a dereference
4362 or else (Is_Access_Type (Etype (Ent))
4363 and then Nkind (Parent (N)) =
4364 N_Selected_Component)
4365 then
4366 Post_State_Seen := True;
4367 return Abandon;
4368 end if;
4370 elsif Nkind (N) = N_Attribute_Reference then
4371 if Attribute_Name (N) = Name_Old then
4372 return Skip;
4374 elsif Attribute_Name (N) = Name_Result then
4375 Post_State_Seen := True;
4376 return Abandon;
4377 end if;
4378 end if;
4380 return OK;
4381 end Is_Post_State;
4383 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
4385 -- Start of processing for Mentions_Post_State
4387 begin
4388 Find_Post_State (N);
4390 return Post_State_Seen;
4391 end Mentions_Post_State;
4393 -- Local variables
4395 Expr : constant Node_Id :=
4396 Get_Pragma_Arg
4397 (First (Pragma_Argument_Associations (Prag)));
4398 Nam : constant Name_Id := Pragma_Name (Prag);
4399 CCase : Node_Id;
4401 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4403 begin
4404 -- Examine all consequences
4406 if Nam = Name_Contract_Cases then
4407 CCase := First (Component_Associations (Expr));
4408 while Present (CCase) loop
4409 Check_Expression (Expression (CCase));
4411 Next (CCase);
4412 end loop;
4414 -- Examine the expression of a postcondition
4416 else pragma Assert (Nam in Name_Postcondition | Name_Refined_Post);
4417 Check_Expression (Expr);
4418 end if;
4419 end Check_Result_And_Post_State_In_Pragma;
4421 -- Local variables
4423 Items : constant Node_Id := Contract (Subp_Id);
4424 Case_Prag : Node_Id := Empty;
4425 Post_Prag : Node_Id := Empty;
4426 Prag : Node_Id;
4427 Seen_In_Case : Boolean := False;
4428 Seen_In_Post : Boolean := False;
4429 Spec_Id : constant Entity_Id := Unique_Entity (Subp_Id);
4431 -- Start of processing for Check_Result_And_Post_State
4433 begin
4434 -- Do not check in instances, because we already checked the generic
4436 if In_Instance then
4437 return;
4439 -- The lack of attribute 'Result or a post-state is classified as a
4440 -- suspicious contract. Do not perform the check if the corresponding
4441 -- switch is not set.
4443 elsif not Warn_On_Suspicious_Contract then
4444 return;
4446 -- Nothing to do if there is no contract
4448 elsif No (Items) then
4449 return;
4451 -- If the subprogram has a contract Exceptional_Cases, it is often
4452 -- useful to refer only to the pre-state in the postcondition, to
4453 -- indicate when the subprogram might terminate normally.
4455 elsif Present (Get_Pragma (Subp_Id, Pragma_Exceptional_Cases)) then
4456 return;
4458 -- Same if the subprogram has a contract Always_Terminates => Cond,
4459 -- where Cond is not syntactically True.
4461 else
4462 declare
4463 Prag : constant Node_Id :=
4464 Get_Pragma (Subp_Id, Pragma_Always_Terminates);
4465 begin
4466 if Present (Prag)
4467 and then Present (Pragma_Argument_Associations (Prag))
4468 then
4469 declare
4470 Cond : constant Node_Id :=
4471 Get_Pragma_Arg
4472 (First (Pragma_Argument_Associations (Prag)));
4473 begin
4474 if not Compile_Time_Known_Value (Cond)
4475 or else not Is_True (Expr_Value (Cond))
4476 then
4477 return;
4478 end if;
4479 end;
4480 end if;
4481 end;
4482 end if;
4484 -- Examine all postconditions for attribute 'Result and a post-state
4486 Prag := Pre_Post_Conditions (Items);
4487 while Present (Prag) loop
4488 if Pragma_Name_Unmapped (Prag)
4489 in Name_Postcondition | Name_Refined_Post
4490 and then not Error_Posted (Prag)
4491 then
4492 Post_Prag := Prag;
4493 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4494 end if;
4496 Prag := Next_Pragma (Prag);
4497 end loop;
4499 -- Examine the contract cases of the subprogram for attribute 'Result
4500 -- and a post-state.
4502 Prag := Contract_Test_Cases (Items);
4503 while Present (Prag) loop
4504 if Pragma_Name (Prag) = Name_Contract_Cases
4505 and then not Error_Posted (Prag)
4506 then
4507 Case_Prag := Prag;
4508 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4509 end if;
4511 Prag := Next_Pragma (Prag);
4512 end loop;
4514 -- Do not emit any errors if the subprogram is not a function
4516 if Ekind (Spec_Id) not in E_Function | E_Generic_Function then
4517 null;
4519 -- Regardless of whether the function has postconditions or contract
4520 -- cases, or whether they mention attribute 'Result, an [IN] OUT formal
4521 -- parameter is always treated as a result.
4523 elsif Has_Out_Or_In_Out_Parameter (Spec_Id) then
4524 null;
4526 -- The function has both a postcondition and contract cases and they do
4527 -- not mention attribute 'Result.
4529 elsif Present (Case_Prag)
4530 and then not Seen_In_Case
4531 and then Present (Post_Prag)
4532 and then not Seen_In_Post
4533 then
4534 Error_Msg_N
4535 ("neither postcondition nor contract cases mention function "
4536 & "result?.t?", Post_Prag);
4538 -- The function has contract cases only and they do not mention
4539 -- attribute 'Result.
4541 elsif Present (Case_Prag) and then not Seen_In_Case then
4542 Error_Msg_N
4543 ("contract cases do not mention function result?.t?", Case_Prag);
4545 -- The function has non-trivial postconditions only and they do not
4546 -- mention attribute 'Result.
4548 elsif Present (Post_Prag)
4549 and then not Seen_In_Post
4550 and then not Is_Trivial_Boolean
4551 (Get_Pragma_Arg (First (Pragma_Argument_Associations (Post_Prag))))
4552 then
4553 Error_Msg_N
4554 ("postcondition does not mention function result?.t?", Post_Prag);
4555 end if;
4556 end Check_Result_And_Post_State;
4558 -----------------------------
4559 -- Check_State_Refinements --
4560 -----------------------------
4562 procedure Check_State_Refinements
4563 (Context : Node_Id;
4564 Is_Main_Unit : Boolean := False)
4566 procedure Check_Package (Pack : Node_Id);
4567 -- Verify that all abstract states of a [generic] package denoted by its
4568 -- declarative node Pack have proper refinement. Recursively verify the
4569 -- visible and private declarations of the [generic] package for other
4570 -- nested packages.
4572 procedure Check_Packages_In (Decls : List_Id);
4573 -- Seek out [generic] package declarations within declarative list Decls
4574 -- and verify the status of their abstract state refinement.
4576 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4577 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4579 -------------------
4580 -- Check_Package --
4581 -------------------
4583 procedure Check_Package (Pack : Node_Id) is
4584 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4585 Spec : constant Node_Id := Specification (Pack);
4586 States : constant Elist_Id :=
4587 Abstract_States (Defining_Entity (Pack));
4589 State_Elmt : Elmt_Id;
4590 State_Id : Entity_Id;
4592 begin
4593 -- Do not verify proper state refinement when the package is subject
4594 -- to pragma SPARK_Mode Off because this disables the requirement for
4595 -- state refinement.
4597 if SPARK_Mode_Is_Off (Pack) then
4598 null;
4600 -- State refinement can only occur in a completing package body. Do
4601 -- not verify proper state refinement when the body is subject to
4602 -- pragma SPARK_Mode Off because this disables the requirement for
4603 -- state refinement.
4605 elsif Present (Body_Id)
4606 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4607 then
4608 null;
4610 -- Do not verify proper state refinement when the package is an
4611 -- instance as this check was already performed in the generic.
4613 elsif Present (Generic_Parent (Spec)) then
4614 null;
4616 -- Otherwise examine the contents of the package
4618 else
4619 if Present (States) then
4620 State_Elmt := First_Elmt (States);
4621 while Present (State_Elmt) loop
4622 State_Id := Node (State_Elmt);
4624 -- Emit an error when a non-null state lacks refinement,
4625 -- but has Part_Of constituents or there is a package
4626 -- body (SPARK RM 7.1.4(4)). Constituents in private
4627 -- child packages, which are not known at this stage,
4628 -- independently require the existence of a package body.
4630 if not Is_Null_State (State_Id)
4631 and then No (Refinement_Constituents (State_Id))
4632 and then
4633 (Present (Part_Of_Constituents (State_Id))
4634 or else
4635 Present (Body_Id))
4636 then
4637 Error_Msg_N ("state & requires refinement", State_Id);
4638 Error_Msg_N ("\package body should have Refined_State "
4639 & "for state & with constituents", State_Id);
4640 end if;
4642 Next_Elmt (State_Elmt);
4643 end loop;
4644 end if;
4646 Check_Packages_In (Visible_Declarations (Spec));
4647 Check_Packages_In (Private_Declarations (Spec));
4648 end if;
4649 end Check_Package;
4651 -----------------------
4652 -- Check_Packages_In --
4653 -----------------------
4655 procedure Check_Packages_In (Decls : List_Id) is
4656 Decl : Node_Id;
4658 begin
4659 if Present (Decls) then
4660 Decl := First (Decls);
4661 while Present (Decl) loop
4662 if Nkind (Decl) in N_Generic_Package_Declaration
4663 | N_Package_Declaration
4664 then
4665 Check_Package (Decl);
4666 end if;
4668 Next (Decl);
4669 end loop;
4670 end if;
4671 end Check_Packages_In;
4673 -----------------------
4674 -- SPARK_Mode_Is_Off --
4675 -----------------------
4677 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4678 Id : constant Entity_Id := Defining_Entity (N);
4679 Prag : constant Node_Id := SPARK_Pragma (Id);
4681 begin
4682 -- Default the mode to "off" when the context is an instance and all
4683 -- SPARK_Mode pragmas found within are to be ignored.
4685 if Ignore_SPARK_Mode_Pragmas (Id) then
4686 return True;
4688 else
4689 return
4690 Present (Prag)
4691 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4692 end if;
4693 end SPARK_Mode_Is_Off;
4695 -- Start of processing for Check_State_Refinements
4697 begin
4698 -- A block may declare a nested package
4700 if Nkind (Context) = N_Block_Statement then
4701 Check_Packages_In (Declarations (Context));
4703 -- An entry, protected, subprogram, or task body may declare a nested
4704 -- package.
4706 elsif Nkind (Context) in N_Entry_Body
4707 | N_Protected_Body
4708 | N_Subprogram_Body
4709 | N_Task_Body
4710 then
4711 -- Do not verify proper state refinement when the body is subject to
4712 -- pragma SPARK_Mode Off because this disables the requirement for
4713 -- state refinement.
4715 if not SPARK_Mode_Is_Off (Context) then
4716 Check_Packages_In (Declarations (Context));
4717 end if;
4719 -- A package body may declare a nested package
4721 elsif Nkind (Context) = N_Package_Body then
4722 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4724 -- Do not verify proper state refinement when the body is subject to
4725 -- pragma SPARK_Mode Off because this disables the requirement for
4726 -- state refinement.
4728 if not SPARK_Mode_Is_Off (Context) then
4729 Check_Packages_In (Declarations (Context));
4730 end if;
4732 -- A library level [generic] package may declare a nested package
4734 elsif Nkind (Context) in
4735 N_Generic_Package_Declaration | N_Package_Declaration
4736 and then Is_Main_Unit
4737 then
4738 Check_Package (Context);
4739 end if;
4740 end Check_State_Refinements;
4742 ------------------------------
4743 -- Check_Unprotected_Access --
4744 ------------------------------
4746 procedure Check_Unprotected_Access
4747 (Context : Node_Id;
4748 Expr : Node_Id)
4750 Cont_Encl_Typ : Entity_Id;
4751 Pref_Encl_Typ : Entity_Id;
4753 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4754 -- Check whether Obj is a private component of a protected object.
4755 -- Return the protected type where the component resides, Empty
4756 -- otherwise.
4758 function Is_Public_Operation return Boolean;
4759 -- Verify that the enclosing operation is callable from outside the
4760 -- protected object, to minimize false positives.
4762 ------------------------------
4763 -- Enclosing_Protected_Type --
4764 ------------------------------
4766 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4767 begin
4768 if Is_Entity_Name (Obj) then
4769 declare
4770 Ent : Entity_Id := Entity (Obj);
4772 begin
4773 -- The object can be a renaming of a private component, use
4774 -- the original record component.
4776 if Is_Prival (Ent) then
4777 Ent := Prival_Link (Ent);
4778 end if;
4780 if Is_Protected_Type (Scope (Ent)) then
4781 return Scope (Ent);
4782 end if;
4783 end;
4784 end if;
4786 -- For indexed and selected components, recursively check the prefix
4788 if Nkind (Obj) in N_Indexed_Component | N_Selected_Component then
4789 return Enclosing_Protected_Type (Prefix (Obj));
4791 -- The object does not denote a protected component
4793 else
4794 return Empty;
4795 end if;
4796 end Enclosing_Protected_Type;
4798 -------------------------
4799 -- Is_Public_Operation --
4800 -------------------------
4802 function Is_Public_Operation return Boolean is
4803 S : Entity_Id;
4804 E : Entity_Id;
4806 begin
4807 S := Current_Scope;
4808 while Present (S) and then S /= Pref_Encl_Typ loop
4809 if Scope (S) = Pref_Encl_Typ then
4810 E := First_Entity (Pref_Encl_Typ);
4811 while Present (E)
4812 and then E /= First_Private_Entity (Pref_Encl_Typ)
4813 loop
4814 if E = S then
4815 return True;
4816 end if;
4818 Next_Entity (E);
4819 end loop;
4820 end if;
4822 S := Scope (S);
4823 end loop;
4825 return False;
4826 end Is_Public_Operation;
4828 -- Start of processing for Check_Unprotected_Access
4830 begin
4831 if Nkind (Expr) = N_Attribute_Reference
4832 and then Attribute_Name (Expr) = Name_Unchecked_Access
4833 then
4834 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4835 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4837 -- Check whether we are trying to export a protected component to a
4838 -- context with an equal or lower access level.
4840 if Present (Pref_Encl_Typ)
4841 and then No (Cont_Encl_Typ)
4842 and then Is_Public_Operation
4843 and then Scope_Depth (Pref_Encl_Typ)
4844 >= Static_Accessibility_Level
4845 (Context, Object_Decl_Level)
4846 then
4847 Error_Msg_N
4848 ("??possible unprotected access to protected data", Expr);
4849 end if;
4850 end if;
4851 end Check_Unprotected_Access;
4853 ------------------------------
4854 -- Check_Unused_Body_States --
4855 ------------------------------
4857 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4858 procedure Process_Refinement_Clause
4859 (Clause : Node_Id;
4860 States : Elist_Id);
4861 -- Inspect all constituents of refinement clause Clause and remove any
4862 -- matches from body state list States.
4864 procedure Report_Unused_Body_States (States : Elist_Id);
4865 -- Emit errors for each abstract state or object found in list States
4867 -------------------------------
4868 -- Process_Refinement_Clause --
4869 -------------------------------
4871 procedure Process_Refinement_Clause
4872 (Clause : Node_Id;
4873 States : Elist_Id)
4875 procedure Process_Constituent (Constit : Node_Id);
4876 -- Remove constituent Constit from body state list States
4878 -------------------------
4879 -- Process_Constituent --
4880 -------------------------
4882 procedure Process_Constituent (Constit : Node_Id) is
4883 Constit_Id : Entity_Id;
4885 begin
4886 -- Guard against illegal constituents. Only abstract states and
4887 -- objects can appear on the right hand side of a refinement.
4889 if Is_Entity_Name (Constit) then
4890 Constit_Id := Entity_Of (Constit);
4892 if Present (Constit_Id)
4893 and then Ekind (Constit_Id) in
4894 E_Abstract_State | E_Constant | E_Variable
4895 then
4896 Remove (States, Constit_Id);
4897 end if;
4898 end if;
4899 end Process_Constituent;
4901 -- Local variables
4903 Constit : Node_Id;
4905 -- Start of processing for Process_Refinement_Clause
4907 begin
4908 if Nkind (Clause) = N_Component_Association then
4909 Constit := Expression (Clause);
4911 -- Multiple constituents appear as an aggregate
4913 if Nkind (Constit) = N_Aggregate then
4914 Constit := First (Expressions (Constit));
4915 while Present (Constit) loop
4916 Process_Constituent (Constit);
4917 Next (Constit);
4918 end loop;
4920 -- Various forms of a single constituent
4922 else
4923 Process_Constituent (Constit);
4924 end if;
4925 end if;
4926 end Process_Refinement_Clause;
4928 -------------------------------
4929 -- Report_Unused_Body_States --
4930 -------------------------------
4932 procedure Report_Unused_Body_States (States : Elist_Id) is
4933 Posted : Boolean := False;
4934 State_Elmt : Elmt_Id;
4935 State_Id : Entity_Id;
4937 begin
4938 if Present (States) then
4939 State_Elmt := First_Elmt (States);
4940 while Present (State_Elmt) loop
4941 State_Id := Node (State_Elmt);
4943 -- Constants are part of the hidden state of a package, but the
4944 -- compiler cannot determine whether they have variable input
4945 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4946 -- hidden state. Do not emit an error when a constant does not
4947 -- participate in a state refinement, even though it acts as a
4948 -- hidden state.
4950 if Ekind (State_Id) = E_Constant then
4951 null;
4953 -- Overlays do not contribute to package state
4955 elsif Ekind (State_Id) = E_Variable
4956 and then Present (Ultimate_Overlaid_Entity (State_Id))
4957 then
4958 null;
4960 -- Generate an error message of the form:
4962 -- body of package ... has unused hidden states
4963 -- abstract state ... defined at ...
4964 -- variable ... defined at ...
4966 else
4967 if not Posted then
4968 Posted := True;
4969 SPARK_Msg_N
4970 ("body of package & has unused hidden states", Body_Id);
4971 end if;
4973 Error_Msg_Sloc := Sloc (State_Id);
4975 if Ekind (State_Id) = E_Abstract_State then
4976 SPARK_Msg_NE
4977 ("\abstract state & defined #", Body_Id, State_Id);
4979 else
4980 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4981 end if;
4982 end if;
4984 Next_Elmt (State_Elmt);
4985 end loop;
4986 end if;
4987 end Report_Unused_Body_States;
4989 -- Local variables
4991 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4992 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4993 Clause : Node_Id;
4994 States : Elist_Id;
4996 -- Start of processing for Check_Unused_Body_States
4998 begin
4999 -- Inspect the clauses of pragma Refined_State and determine whether all
5000 -- visible states declared within the package body participate in the
5001 -- refinement.
5003 if Present (Prag) then
5004 Clause := Expression (Get_Argument (Prag, Spec_Id));
5005 States := Collect_Body_States (Body_Id);
5007 -- Multiple non-null state refinements appear as an aggregate
5009 if Nkind (Clause) = N_Aggregate then
5010 Clause := First (Component_Associations (Clause));
5011 while Present (Clause) loop
5012 Process_Refinement_Clause (Clause, States);
5013 Next (Clause);
5014 end loop;
5016 -- Various forms of a single state refinement
5018 else
5019 Process_Refinement_Clause (Clause, States);
5020 end if;
5022 -- Ensure that all abstract states and objects declared in the
5023 -- package body state space are utilized as constituents.
5025 Report_Unused_Body_States (States);
5026 end if;
5027 end Check_Unused_Body_States;
5029 -----------------
5030 -- Choice_List --
5031 -----------------
5033 function Choice_List (N : Node_Id) return List_Id is
5034 begin
5035 if Nkind (N) = N_Iterated_Component_Association then
5036 return Discrete_Choices (N);
5037 else
5038 return Choices (N);
5039 end if;
5040 end Choice_List;
5042 ---------------------
5043 -- Class_Condition --
5044 ---------------------
5046 function Class_Condition
5047 (Kind : Condition_Kind;
5048 Subp : Entity_Id) return Node_Id is
5050 begin
5051 case Kind is
5052 when Class_Postcondition =>
5053 return Class_Postconditions (Subp);
5055 when Class_Precondition =>
5056 return Class_Preconditions (Subp);
5058 when Ignored_Class_Postcondition =>
5059 return Ignored_Class_Postconditions (Subp);
5061 when Ignored_Class_Precondition =>
5062 return Ignored_Class_Preconditions (Subp);
5063 end case;
5064 end Class_Condition;
5066 -------------------------
5067 -- Collect_Body_States --
5068 -------------------------
5070 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
5071 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
5072 -- Determine whether object Obj_Id is a suitable visible state of a
5073 -- package body.
5075 procedure Collect_Visible_States
5076 (Pack_Id : Entity_Id;
5077 States : in out Elist_Id);
5078 -- Gather the entities of all abstract states and objects declared in
5079 -- the visible state space of package Pack_Id.
5081 ----------------------------
5082 -- Collect_Visible_States --
5083 ----------------------------
5085 procedure Collect_Visible_States
5086 (Pack_Id : Entity_Id;
5087 States : in out Elist_Id)
5089 Item_Id : Entity_Id;
5091 begin
5092 -- Traverse the entity chain of the package and inspect all visible
5093 -- items.
5095 Item_Id := First_Entity (Pack_Id);
5096 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
5098 -- Do not consider internally generated items as those cannot be
5099 -- named and participate in refinement.
5101 if not Comes_From_Source (Item_Id) then
5102 null;
5104 elsif Ekind (Item_Id) = E_Abstract_State then
5105 Append_New_Elmt (Item_Id, States);
5107 elsif Ekind (Item_Id) in E_Constant | E_Variable
5108 and then Is_Visible_Object (Item_Id)
5109 then
5110 Append_New_Elmt (Item_Id, States);
5112 -- Recursively gather the visible states of a nested package
5113 -- except for nested package renamings.
5115 elsif Ekind (Item_Id) = E_Package
5116 and then No (Renamed_Entity (Item_Id))
5117 then
5118 Collect_Visible_States (Item_Id, States);
5119 end if;
5121 Next_Entity (Item_Id);
5122 end loop;
5123 end Collect_Visible_States;
5125 -----------------------
5126 -- Is_Visible_Object --
5127 -----------------------
5129 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
5130 begin
5131 -- Objects that map generic formals to their actuals are not visible
5132 -- from outside the generic instantiation.
5134 if Present (Corresponding_Generic_Association
5135 (Declaration_Node (Obj_Id)))
5136 then
5137 return False;
5139 -- Constituents of a single protected/task type act as components of
5140 -- the type and are not visible from outside the type.
5142 elsif Ekind (Obj_Id) = E_Variable
5143 and then Present (Encapsulating_State (Obj_Id))
5144 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
5145 then
5146 return False;
5148 else
5149 return True;
5150 end if;
5151 end Is_Visible_Object;
5153 -- Local variables
5155 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
5156 Decl : Node_Id;
5157 Item_Id : Entity_Id;
5158 States : Elist_Id := No_Elist;
5160 -- Start of processing for Collect_Body_States
5162 begin
5163 -- Inspect the declarations of the body looking for source objects,
5164 -- packages and package instantiations. Note that even though this
5165 -- processing is very similar to Collect_Visible_States, a package
5166 -- body does not have a First/Next_Entity list.
5168 Decl := First (Declarations (Body_Decl));
5169 while Present (Decl) loop
5171 -- Capture source objects as internally generated temporaries cannot
5172 -- be named and participate in refinement.
5174 if Nkind (Decl) = N_Object_Declaration then
5175 Item_Id := Defining_Entity (Decl);
5177 if Comes_From_Source (Item_Id)
5178 and then Is_Visible_Object (Item_Id)
5179 then
5180 Append_New_Elmt (Item_Id, States);
5181 end if;
5183 -- Capture the visible abstract states and objects of a source
5184 -- package [instantiation].
5186 elsif Nkind (Decl) = N_Package_Declaration then
5187 Item_Id := Defining_Entity (Decl);
5189 if Comes_From_Source (Item_Id) then
5190 Collect_Visible_States (Item_Id, States);
5191 end if;
5192 end if;
5194 Next (Decl);
5195 end loop;
5197 return States;
5198 end Collect_Body_States;
5200 ------------------------
5201 -- Collect_Interfaces --
5202 ------------------------
5204 procedure Collect_Interfaces
5205 (T : Entity_Id;
5206 Ifaces_List : out Elist_Id;
5207 Exclude_Parents : Boolean := False;
5208 Use_Full_View : Boolean := True)
5210 procedure Collect (Typ : Entity_Id);
5211 -- Subsidiary subprogram used to traverse the whole list
5212 -- of directly and indirectly implemented interfaces
5214 -------------
5215 -- Collect --
5216 -------------
5218 procedure Collect (Typ : Entity_Id) is
5219 Ancestor : Entity_Id;
5220 Full_T : Entity_Id;
5221 Id : Node_Id;
5222 Iface : Entity_Id;
5224 begin
5225 Full_T := Typ;
5227 -- Handle private types and subtypes
5229 if Use_Full_View
5230 and then Is_Private_Type (Typ)
5231 and then Present (Full_View (Typ))
5232 then
5233 Full_T := Full_View (Typ);
5235 if Ekind (Full_T) = E_Record_Subtype then
5236 Full_T := Etype (Typ);
5238 if Present (Full_View (Full_T)) then
5239 Full_T := Full_View (Full_T);
5240 end if;
5241 end if;
5242 end if;
5244 -- Include the ancestor if we are generating the whole list of
5245 -- abstract interfaces.
5247 if Etype (Full_T) /= Typ
5249 -- Protect the frontend against wrong sources. For example:
5251 -- package P is
5252 -- type A is tagged null record;
5253 -- type B is new A with private;
5254 -- type C is new A with private;
5255 -- private
5256 -- type B is new C with null record;
5257 -- type C is new B with null record;
5258 -- end P;
5260 and then Etype (Full_T) /= T
5261 then
5262 Ancestor := Etype (Full_T);
5263 Collect (Ancestor);
5265 if Is_Interface (Ancestor) and then not Exclude_Parents then
5266 Append_Unique_Elmt (Ancestor, Ifaces_List);
5267 end if;
5268 end if;
5270 -- Traverse the graph of ancestor interfaces
5272 Id := First (Abstract_Interface_List (Full_T));
5273 while Present (Id) loop
5274 Iface := Etype (Id);
5276 -- Protect against wrong uses. For example:
5277 -- type I is interface;
5278 -- type O is tagged null record;
5279 -- type Wrong is new I and O with null record; -- ERROR
5281 if Is_Interface (Iface) then
5282 if Exclude_Parents
5283 and then Etype (T) /= T
5284 and then Interface_Present_In_Ancestor (Etype (T), Iface)
5285 then
5286 null;
5287 else
5288 Collect (Iface);
5289 Append_Unique_Elmt (Iface, Ifaces_List);
5290 end if;
5291 end if;
5293 Next (Id);
5294 end loop;
5295 end Collect;
5297 -- Start of processing for Collect_Interfaces
5299 begin
5300 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
5301 Ifaces_List := New_Elmt_List;
5302 Collect (T);
5303 end Collect_Interfaces;
5305 ----------------------------------
5306 -- Collect_Interface_Components --
5307 ----------------------------------
5309 procedure Collect_Interface_Components
5310 (Tagged_Type : Entity_Id;
5311 Components_List : out Elist_Id)
5313 procedure Collect (Typ : Entity_Id);
5314 -- Subsidiary subprogram used to climb to the parents
5316 -------------
5317 -- Collect --
5318 -------------
5320 procedure Collect (Typ : Entity_Id) is
5321 Tag_Comp : Entity_Id;
5322 Parent_Typ : Entity_Id;
5324 begin
5325 -- Handle private types
5327 if Present (Full_View (Etype (Typ))) then
5328 Parent_Typ := Full_View (Etype (Typ));
5329 else
5330 Parent_Typ := Etype (Typ);
5331 end if;
5333 if Parent_Typ /= Typ
5335 -- Protect the frontend against wrong sources. For example:
5337 -- package P is
5338 -- type A is tagged null record;
5339 -- type B is new A with private;
5340 -- type C is new A with private;
5341 -- private
5342 -- type B is new C with null record;
5343 -- type C is new B with null record;
5344 -- end P;
5346 and then Parent_Typ /= Tagged_Type
5347 then
5348 Collect (Parent_Typ);
5349 end if;
5351 -- Collect the components containing tags of secondary dispatch
5352 -- tables.
5354 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
5355 while Present (Tag_Comp) loop
5356 pragma Assert (Present (Related_Type (Tag_Comp)));
5357 Append_Elmt (Tag_Comp, Components_List);
5359 Tag_Comp := Next_Tag_Component (Tag_Comp);
5360 end loop;
5361 end Collect;
5363 -- Start of processing for Collect_Interface_Components
5365 begin
5366 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
5367 and then Is_Tagged_Type (Tagged_Type));
5369 Components_List := New_Elmt_List;
5370 Collect (Tagged_Type);
5371 end Collect_Interface_Components;
5373 -----------------------------
5374 -- Collect_Interfaces_Info --
5375 -----------------------------
5377 procedure Collect_Interfaces_Info
5378 (T : Entity_Id;
5379 Ifaces_List : out Elist_Id;
5380 Components_List : out Elist_Id;
5381 Tags_List : out Elist_Id)
5383 Comps_List : Elist_Id;
5384 Comp_Elmt : Elmt_Id;
5385 Comp_Iface : Entity_Id;
5386 Iface_Elmt : Elmt_Id;
5387 Iface : Entity_Id;
5389 function Search_Tag (Iface : Entity_Id) return Entity_Id;
5390 -- Search for the secondary tag associated with the interface type
5391 -- Iface that is implemented by T.
5393 ----------------
5394 -- Search_Tag --
5395 ----------------
5397 function Search_Tag (Iface : Entity_Id) return Entity_Id is
5398 ADT : Elmt_Id;
5399 begin
5400 if not Is_CPP_Class (T) then
5401 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
5402 else
5403 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
5404 end if;
5406 while Present (ADT)
5407 and then Is_Tag (Node (ADT))
5408 and then Related_Type (Node (ADT)) /= Iface
5409 loop
5410 -- Skip secondary dispatch table referencing thunks to user
5411 -- defined primitives covered by this interface.
5413 pragma Assert (Has_Suffix (Node (ADT), 'P'));
5414 Next_Elmt (ADT);
5416 -- Skip secondary dispatch tables of Ada types
5418 if not Is_CPP_Class (T) then
5420 -- Skip secondary dispatch table referencing thunks to
5421 -- predefined primitives.
5423 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
5424 Next_Elmt (ADT);
5426 -- Skip secondary dispatch table referencing user-defined
5427 -- primitives covered by this interface.
5429 pragma Assert (Has_Suffix (Node (ADT), 'D'));
5430 Next_Elmt (ADT);
5432 -- Skip secondary dispatch table referencing predefined
5433 -- primitives.
5435 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
5436 Next_Elmt (ADT);
5437 end if;
5438 end loop;
5440 pragma Assert (Is_Tag (Node (ADT)));
5441 return Node (ADT);
5442 end Search_Tag;
5444 -- Start of processing for Collect_Interfaces_Info
5446 begin
5447 Collect_Interfaces (T, Ifaces_List);
5448 Collect_Interface_Components (T, Comps_List);
5450 -- Search for the record component and tag associated with each
5451 -- interface type of T.
5453 Components_List := New_Elmt_List;
5454 Tags_List := New_Elmt_List;
5456 Iface_Elmt := First_Elmt (Ifaces_List);
5457 while Present (Iface_Elmt) loop
5458 Iface := Node (Iface_Elmt);
5460 -- Associate the primary tag component and the primary dispatch table
5461 -- with all the interfaces that are parents of T
5463 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5464 Append_Elmt (First_Tag_Component (T), Components_List);
5465 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5467 -- Otherwise search for the tag component and secondary dispatch
5468 -- table of Iface
5470 else
5471 Comp_Elmt := First_Elmt (Comps_List);
5472 while Present (Comp_Elmt) loop
5473 Comp_Iface := Related_Type (Node (Comp_Elmt));
5475 if Comp_Iface = Iface
5476 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5477 then
5478 Append_Elmt (Node (Comp_Elmt), Components_List);
5479 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5480 exit;
5481 end if;
5483 Next_Elmt (Comp_Elmt);
5484 end loop;
5485 pragma Assert (Present (Comp_Elmt));
5486 end if;
5488 Next_Elmt (Iface_Elmt);
5489 end loop;
5490 end Collect_Interfaces_Info;
5492 ---------------------
5493 -- Collect_Parents --
5494 ---------------------
5496 procedure Collect_Parents
5497 (T : Entity_Id;
5498 List : out Elist_Id;
5499 Use_Full_View : Boolean := True)
5501 Current_Typ : Entity_Id := T;
5502 Parent_Typ : Entity_Id;
5504 begin
5505 List := New_Elmt_List;
5507 -- No action if the if the type has no parents
5509 if T = Etype (T) then
5510 return;
5511 end if;
5513 loop
5514 Parent_Typ := Etype (Current_Typ);
5516 if Is_Private_Type (Parent_Typ)
5517 and then Present (Full_View (Parent_Typ))
5518 and then Use_Full_View
5519 then
5520 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5521 end if;
5523 Append_Elmt (Parent_Typ, List);
5525 exit when Parent_Typ = Current_Typ;
5526 Current_Typ := Parent_Typ;
5527 end loop;
5528 end Collect_Parents;
5530 ----------------------------------
5531 -- Collect_Primitive_Operations --
5532 ----------------------------------
5534 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5535 B_Type : constant Entity_Id := Base_Type (T);
5537 function Match (E : Entity_Id) return Boolean;
5538 -- True if E's base type is B_Type, or E is of an anonymous access type
5539 -- and the base type of its designated type is B_Type.
5541 -----------
5542 -- Match --
5543 -----------
5545 function Match (E : Entity_Id) return Boolean is
5546 Etyp : Entity_Id := Etype (E);
5548 begin
5549 if Ekind (Etyp) = E_Anonymous_Access_Type then
5550 Etyp := Designated_Type (Etyp);
5551 end if;
5553 -- In Ada 2012 a primitive operation may have a formal of an
5554 -- incomplete view of the parent type.
5556 return Base_Type (Etyp) = B_Type
5557 or else
5558 (Ada_Version >= Ada_2012
5559 and then Ekind (Etyp) = E_Incomplete_Type
5560 and then Full_View (Etyp) = B_Type);
5561 end Match;
5563 -- Local variables
5565 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5566 B_Scope : Entity_Id := Scope (B_Type);
5567 Op_List : Elist_Id;
5568 Eq_Prims_List : Elist_Id := No_Elist;
5569 Formal : Entity_Id;
5570 Is_Prim : Boolean;
5571 Is_Type_In_Pkg : Boolean;
5572 Formal_Derived : Boolean := False;
5573 Id : Entity_Id;
5575 -- Start of processing for Collect_Primitive_Operations
5577 begin
5578 -- For tagged types, the primitive operations are collected as they
5579 -- are declared, and held in an explicit list which is simply returned.
5581 if Is_Tagged_Type (B_Type) then
5582 return Primitive_Operations (B_Type);
5584 -- An untagged generic type that is a derived type inherits the
5585 -- primitive operations of its parent type. Other formal types only
5586 -- have predefined operators, which are not explicitly represented.
5588 elsif Is_Generic_Type (B_Type) then
5589 if Nkind (B_Decl) = N_Formal_Type_Declaration
5590 and then Nkind (Formal_Type_Definition (B_Decl)) =
5591 N_Formal_Derived_Type_Definition
5592 then
5593 Formal_Derived := True;
5594 else
5595 return New_Elmt_List;
5596 end if;
5597 end if;
5599 Op_List := New_Elmt_List;
5601 if B_Scope = Standard_Standard then
5602 if B_Type = Standard_String then
5603 Append_Elmt (Standard_Op_Concat, Op_List);
5605 elsif B_Type = Standard_Wide_String then
5606 Append_Elmt (Standard_Op_Concatw, Op_List);
5608 else
5609 null;
5610 end if;
5612 -- Locate the primitive subprograms of the type
5614 else
5615 -- The primitive operations appear after the base type, except if the
5616 -- derivation happens within the private part of B_Scope and the type
5617 -- is a private type, in which case both the type and some primitive
5618 -- operations may appear before the base type, and the list of
5619 -- candidates starts after the type.
5621 if In_Open_Scopes (B_Scope)
5622 and then Scope (T) = B_Scope
5623 and then In_Private_Part (B_Scope)
5624 then
5625 Id := Next_Entity (T);
5627 -- In Ada 2012, If the type has an incomplete partial view, there may
5628 -- be primitive operations declared before the full view, so we need
5629 -- to start scanning from the incomplete view, which is earlier on
5630 -- the entity chain.
5632 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5633 and then Present (Incomplete_View (Parent (B_Type)))
5634 then
5635 Id := Incomplete_View (Parent (B_Type));
5637 -- If T is a derived from a type with an incomplete view declared
5638 -- elsewhere, that incomplete view is irrelevant, we want the
5639 -- operations in the scope of T.
5641 if Scope (Id) /= Scope (B_Type) then
5642 Id := Next_Entity (B_Type);
5643 end if;
5645 else
5646 Id := Next_Entity (B_Type);
5647 end if;
5649 -- Set flag if this is a type in a package spec
5651 Is_Type_In_Pkg :=
5652 Is_Package_Or_Generic_Package (B_Scope)
5653 and then
5654 Parent_Kind (Declaration_Node (First_Subtype (T))) /=
5655 N_Package_Body;
5657 while Present (Id) loop
5659 -- Test whether the result type or any of the parameter types of
5660 -- each subprogram following the type match that type when the
5661 -- type is declared in a package spec, is a derived type, or the
5662 -- subprogram is marked as primitive. (The Is_Primitive test is
5663 -- needed to find primitives of nonderived types in declarative
5664 -- parts that happen to override the predefined "=" operator.)
5666 -- Note that generic formal subprograms are not considered to be
5667 -- primitive operations and thus are never inherited.
5669 if Is_Overloadable (Id)
5670 and then (Is_Type_In_Pkg
5671 or else Is_Derived_Type (B_Type)
5672 or else Is_Primitive (Id))
5673 and then Parent_Kind (Parent (Id))
5674 not in N_Formal_Subprogram_Declaration
5675 then
5676 Is_Prim := False;
5678 if Match (Id) then
5679 Is_Prim := True;
5681 else
5682 Formal := First_Formal (Id);
5683 while Present (Formal) loop
5684 if Match (Formal) then
5685 Is_Prim := True;
5686 exit;
5687 end if;
5689 Next_Formal (Formal);
5690 end loop;
5691 end if;
5693 -- For a formal derived type, the only primitives are the ones
5694 -- inherited from the parent type. Operations appearing in the
5695 -- package declaration are not primitive for it.
5697 if Is_Prim
5698 and then (not Formal_Derived or else Present (Alias (Id)))
5699 then
5700 -- In the special case of an equality operator aliased to
5701 -- an overriding dispatching equality belonging to the same
5702 -- type, we don't include it in the list of primitives.
5703 -- This avoids inheriting multiple equality operators when
5704 -- deriving from untagged private types whose full type is
5705 -- tagged, which can otherwise cause ambiguities. Note that
5706 -- this should only happen for this kind of untagged parent
5707 -- type, since normally dispatching operations are inherited
5708 -- using the type's Primitive_Operations list.
5710 if Chars (Id) = Name_Op_Eq
5711 and then Is_Dispatching_Operation (Id)
5712 and then Present (Alias (Id))
5713 and then Present (Overridden_Operation (Alias (Id)))
5714 and then Base_Type (Etype (First_Entity (Id))) =
5715 Base_Type (Etype (First_Entity (Alias (Id))))
5716 then
5717 null;
5719 -- Include the subprogram in the list of primitives
5721 else
5722 Append_Elmt (Id, Op_List);
5724 -- Save collected equality primitives for later filtering
5725 -- (if we are processing a private type for which we can
5726 -- collect several candidates).
5728 if Inherits_From_Tagged_Full_View (T)
5729 and then Chars (Id) = Name_Op_Eq
5730 and then Etype (First_Formal (Id)) =
5731 Etype (Next_Formal (First_Formal (Id)))
5732 then
5733 Append_New_Elmt (Id, Eq_Prims_List);
5734 end if;
5735 end if;
5736 end if;
5737 end if;
5739 Next_Entity (Id);
5741 -- For a type declared in System, some of its operations may
5742 -- appear in the target-specific extension to System.
5744 if No (Id)
5745 and then Is_RTU (B_Scope, System)
5746 and then Present_System_Aux
5747 then
5748 B_Scope := System_Aux_Id;
5749 Id := First_Entity (System_Aux_Id);
5750 end if;
5751 end loop;
5753 -- Filter collected equality primitives
5755 if Inherits_From_Tagged_Full_View (T)
5756 and then Present (Eq_Prims_List)
5757 then
5758 declare
5759 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5760 Second : Elmt_Id;
5762 begin
5763 pragma Assert (No (Next_Elmt (First))
5764 or else No (Next_Elmt (Next_Elmt (First))));
5766 -- No action needed if we have collected a single equality
5767 -- primitive
5769 if Present (Next_Elmt (First)) then
5770 Second := Next_Elmt (First);
5772 if Is_Dispatching_Operation
5773 (Ultimate_Alias (Node (First)))
5774 then
5775 Remove (Op_List, Node (First));
5777 elsif Is_Dispatching_Operation
5778 (Ultimate_Alias (Node (Second)))
5779 then
5780 Remove (Op_List, Node (Second));
5782 else
5783 raise Program_Error;
5784 end if;
5785 end if;
5786 end;
5787 end if;
5788 end if;
5790 return Op_List;
5791 end Collect_Primitive_Operations;
5793 -----------------------------------
5794 -- Compile_Time_Constraint_Error --
5795 -----------------------------------
5797 function Compile_Time_Constraint_Error
5798 (N : Node_Id;
5799 Msg : String;
5800 Ent : Entity_Id := Empty;
5801 Loc : Source_Ptr := No_Location;
5802 Warn : Boolean := False;
5803 Extra_Msg : String := "") return Node_Id
5805 Msgc : String (1 .. Msg'Length + 3);
5806 -- Copy of message, with room for possible ?? or << and ! at end
5808 Msgl : Natural;
5809 Wmsg : Boolean;
5810 Eloc : Source_Ptr;
5812 begin
5813 -- If this is a warning, convert it into an error if we are in code
5814 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5815 -- warning. The rationale is that a compile-time constraint error should
5816 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5817 -- a few cases we prefer to issue a warning and generate both a suitable
5818 -- run-time error in GNAT and a suitable check message in GNATprove.
5819 -- Those cases are those that likely correspond to deactivated SPARK
5820 -- code, so that this kind of code can be compiled and analyzed instead
5821 -- of being rejected.
5823 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5825 -- A static constraint error in an instance body is not a fatal error.
5826 -- We choose to inhibit the message altogether, because there is no
5827 -- obvious node (for now) on which to post it. On the other hand the
5828 -- offending node must be replaced with a constraint_error in any case.
5830 -- No messages are generated if we already posted an error on this node
5832 if not Error_Posted (N) then
5833 if Loc /= No_Location then
5834 Eloc := Loc;
5835 else
5836 Eloc := Sloc (N);
5837 end if;
5839 -- Copy message to Msgc, converting any ? in the message into <
5840 -- instead, so that we have an error in GNATprove mode.
5842 Msgl := Msg'Length;
5844 for J in 1 .. Msgl loop
5845 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5846 Msgc (J) := '<';
5847 else
5848 Msgc (J) := Msg (J);
5849 end if;
5850 end loop;
5852 -- Message is a warning, even in Ada 95 case
5854 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5855 Wmsg := True;
5857 -- In Ada 83, all messages are warnings. In the private part and the
5858 -- body of an instance, constraint_checks are only warnings. We also
5859 -- make this a warning if the Warn parameter is set.
5861 elsif Warn
5862 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5863 or else In_Instance_Not_Visible
5864 then
5865 Msgl := Msgl + 1;
5866 Msgc (Msgl) := '<';
5867 Msgl := Msgl + 1;
5868 Msgc (Msgl) := '<';
5869 Wmsg := True;
5871 -- Otherwise we have a real error message (Ada 95 static case) and we
5872 -- make this an unconditional message. Note that in the warning case
5873 -- we do not make the message unconditional, it seems reasonable to
5874 -- delete messages like this (about exceptions that will be raised)
5875 -- in dead code.
5877 else
5878 Wmsg := False;
5879 Msgl := Msgl + 1;
5880 Msgc (Msgl) := '!';
5881 end if;
5883 -- One more test, skip the warning if the related expression is
5884 -- statically unevaluated, since we don't want to warn about what
5885 -- will happen when something is evaluated if it never will be
5886 -- evaluated.
5888 -- Suppress error reporting when checking that the expression of a
5889 -- static expression function is a potentially static expression,
5890 -- because we don't want additional errors being reported during the
5891 -- preanalysis of the expression (see Analyze_Expression_Function).
5893 if not Is_Statically_Unevaluated (N)
5894 and then not Checking_Potentially_Static_Expression
5895 then
5896 if Present (Ent) then
5897 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5898 else
5899 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5900 end if;
5902 -- Emit any extra message as a continuation
5904 if Extra_Msg /= "" then
5905 Error_Msg_N ('\' & Extra_Msg, N);
5906 end if;
5908 if Wmsg then
5910 -- Check whether the context is an Init_Proc
5912 if Inside_Init_Proc then
5913 declare
5914 Init_Proc_Type : constant Entity_Id :=
5915 Etype (First_Formal (Current_Scope_No_Loops));
5917 Conc_Typ : constant Entity_Id :=
5918 (if Present (Init_Proc_Type)
5919 and then Ekind (Init_Proc_Type) = E_Record_Type
5920 then Corresponding_Concurrent_Type (Init_Proc_Type)
5921 else Empty);
5923 begin
5924 -- Don't complain if the corresponding concurrent type
5925 -- doesn't come from source (i.e. a single task/protected
5926 -- object).
5928 if Present (Conc_Typ)
5929 and then not Comes_From_Source (Conc_Typ)
5930 then
5931 Error_Msg ("\& [<<", Eloc, N);
5933 else
5934 if GNATprove_Mode then
5935 Error_Msg
5936 ("\Constraint_Error would have been raised"
5937 & " for objects of this type", Eloc, N);
5938 else
5939 Error_Msg
5940 ("\Constraint_Error will be raised"
5941 & " for objects of this type", Eloc, N);
5942 end if;
5943 end if;
5944 end;
5946 else
5947 Error_Msg ("\Constraint_Error [<<", Eloc, N);
5948 end if;
5950 else
5951 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5952 Set_Error_Posted (N);
5953 end if;
5954 end if;
5955 end if;
5957 return N;
5958 end Compile_Time_Constraint_Error;
5960 ----------------------------
5961 -- Compute_Returns_By_Ref --
5962 ----------------------------
5964 procedure Compute_Returns_By_Ref (Func : Entity_Id) is
5965 Kind : constant Entity_Kind := Ekind (Func);
5966 Typ : constant Entity_Id := Etype (Func);
5968 begin
5969 -- Nothing to do for procedures
5971 if Kind in E_Procedure | E_Generic_Procedure
5972 or else (Kind = E_Subprogram_Type and then Typ = Standard_Void_Type)
5973 then
5974 null;
5976 -- The build-in-place protocols return a reference to the result
5978 elsif Is_Build_In_Place_Function (Func) then
5979 Set_Returns_By_Ref (Func);
5981 -- In Ada 95, limited types are returned by reference, but not if the
5982 -- convention is other than Ada.
5984 elsif Is_Inherently_Limited_Type (Typ)
5985 and then not Has_Foreign_Convention (Func)
5986 then
5987 Set_Returns_By_Ref (Func);
5988 end if;
5989 end Compute_Returns_By_Ref;
5991 --------------------------------
5992 -- Collect_Types_In_Hierarchy --
5993 --------------------------------
5995 function Collect_Types_In_Hierarchy
5996 (Typ : Entity_Id;
5997 Examine_Components : Boolean := False) return Elist_Id
5999 Results : Elist_Id;
6001 procedure Process_Type (Typ : Entity_Id);
6002 -- Collect type Typ if it satisfies function Predicate. Do so for its
6003 -- parent type, base type, progenitor types, and any component types.
6005 ------------------
6006 -- Process_Type --
6007 ------------------
6009 procedure Process_Type (Typ : Entity_Id) is
6010 Comp : Entity_Id;
6011 Iface_Elmt : Elmt_Id;
6013 begin
6014 if not Is_Type (Typ) or else Error_Posted (Typ) then
6015 return;
6016 end if;
6018 -- Collect the current type if it satisfies the predicate
6020 if Predicate (Typ) then
6021 Append_Elmt (Typ, Results);
6022 end if;
6024 -- Process component types
6026 if Examine_Components then
6028 -- Examine components and discriminants
6030 if Is_Concurrent_Type (Typ)
6031 or else Is_Incomplete_Or_Private_Type (Typ)
6032 or else Is_Record_Type (Typ)
6033 or else Has_Discriminants (Typ)
6034 then
6035 Comp := First_Component_Or_Discriminant (Typ);
6037 while Present (Comp) loop
6038 Process_Type (Etype (Comp));
6040 Next_Component_Or_Discriminant (Comp);
6041 end loop;
6043 -- Examine array components
6045 elsif Ekind (Typ) = E_Array_Type then
6046 Process_Type (Component_Type (Typ));
6047 end if;
6048 end if;
6050 -- Examine parent type
6052 if Etype (Typ) /= Typ then
6053 -- Prevent infinite recursion, which can happen in illegal
6054 -- programs. Silently return if illegal. For now, just deal
6055 -- with the 2-type cycle case. Larger cycles will get
6056 -- SIGSEGV at compile time from running out of stack.
6058 if Etype (Etype (Typ)) = Typ then
6059 if Total_Errors_Detected = 0 then
6060 raise Program_Error;
6061 else
6062 return;
6063 end if;
6064 end if;
6066 Process_Type (Etype (Typ));
6067 end if;
6069 -- Examine base type
6071 if Base_Type (Typ) /= Typ then
6072 Process_Type (Base_Type (Typ));
6073 end if;
6075 -- Examine interfaces
6077 if Is_Record_Type (Typ)
6078 and then Present (Interfaces (Typ))
6079 then
6080 Iface_Elmt := First_Elmt (Interfaces (Typ));
6081 while Present (Iface_Elmt) loop
6082 Process_Type (Node (Iface_Elmt));
6084 Next_Elmt (Iface_Elmt);
6085 end loop;
6086 end if;
6087 end Process_Type;
6089 -- Start of processing for Collect_Types_In_Hierarchy
6091 begin
6092 Results := New_Elmt_List;
6093 Process_Type (Typ);
6094 return Results;
6095 end Collect_Types_In_Hierarchy;
6097 -----------------------
6098 -- Conditional_Delay --
6099 -----------------------
6101 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
6102 begin
6103 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
6104 Set_Has_Delayed_Freeze (New_Ent);
6105 end if;
6106 end Conditional_Delay;
6108 -------------------------
6109 -- Copy_Component_List --
6110 -------------------------
6112 function Copy_Component_List
6113 (R_Typ : Entity_Id;
6114 Loc : Source_Ptr) return List_Id
6116 Comp : Node_Id;
6117 Comps : constant List_Id := New_List;
6119 begin
6120 Comp := First_Component (Underlying_Type (R_Typ));
6121 while Present (Comp) loop
6122 if Comes_From_Source (Comp) then
6123 declare
6124 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
6125 begin
6126 Append_To (Comps,
6127 Make_Component_Declaration (Loc,
6128 Defining_Identifier =>
6129 Make_Defining_Identifier (Loc, Chars (Comp)),
6130 Component_Definition =>
6131 New_Copy_Tree
6132 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
6133 end;
6134 end if;
6136 Next_Component (Comp);
6137 end loop;
6139 return Comps;
6140 end Copy_Component_List;
6142 -----------------------
6143 -- Copy_Ghost_Aspect --
6144 -----------------------
6146 procedure Copy_Ghost_Aspect (From : Node_Id; To : Node_Id) is
6147 pragma Assert (not Has_Aspects (To));
6148 Asp : Node_Id;
6150 begin
6151 if Has_Aspects (From) then
6152 Asp := Find_Aspect (Defining_Entity (From), Aspect_Ghost);
6154 if Present (Asp) then
6155 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
6156 end if;
6157 end if;
6158 end Copy_Ghost_Aspect;
6160 -------------------------
6161 -- Copy_Parameter_List --
6162 -------------------------
6164 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
6165 Loc : constant Source_Ptr := Sloc (Subp_Id);
6166 Plist : List_Id;
6167 Formal : Entity_Id := First_Formal (Subp_Id);
6169 begin
6170 if Present (Formal) then
6171 Plist := New_List;
6172 while Present (Formal) loop
6173 Append_To (Plist,
6174 Make_Parameter_Specification (Loc,
6175 Defining_Identifier =>
6176 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
6177 In_Present => In_Present (Parent (Formal)),
6178 Out_Present => Out_Present (Parent (Formal)),
6179 Parameter_Type =>
6180 New_Occurrence_Of (Etype (Formal), Loc),
6181 Expression =>
6182 New_Copy_Tree (Expression (Parent (Formal)))));
6184 Next_Formal (Formal);
6185 end loop;
6186 else
6187 Plist := No_List;
6188 end if;
6190 return Plist;
6191 end Copy_Parameter_List;
6193 ----------------------------
6194 -- Copy_SPARK_Mode_Aspect --
6195 ----------------------------
6197 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
6198 pragma Assert (not Has_Aspects (To));
6199 Asp : Node_Id;
6201 begin
6202 if Has_Aspects (From) then
6203 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
6205 if Present (Asp) then
6206 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
6207 end if;
6208 end if;
6209 end Copy_SPARK_Mode_Aspect;
6211 --------------------------
6212 -- Copy_Subprogram_Spec --
6213 --------------------------
6215 function Copy_Subprogram_Spec
6216 (Spec : Node_Id;
6217 New_Sloc : Source_Ptr := No_Location) return Node_Id
6219 Def_Id : Node_Id;
6220 Formal_Spec : Node_Id;
6221 Result : Node_Id;
6223 begin
6224 -- The structure of the original tree must be replicated without any
6225 -- alterations. Use New_Copy_Tree for this purpose.
6227 Result := New_Copy_Tree (Spec, New_Sloc => New_Sloc);
6229 -- However, the spec of a null procedure carries the corresponding null
6230 -- statement of the body (created by the parser), and this cannot be
6231 -- shared with the new subprogram spec.
6233 if Nkind (Result) = N_Procedure_Specification then
6234 Set_Null_Statement (Result, Empty);
6235 end if;
6237 -- Create a new entity for the defining unit name
6239 Def_Id := Defining_Unit_Name (Result);
6240 Set_Defining_Unit_Name (Result,
6241 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
6243 -- Create new entities for the formal parameters
6245 Formal_Spec := First (Parameter_Specifications (Result));
6246 while Present (Formal_Spec) loop
6247 Def_Id := Defining_Identifier (Formal_Spec);
6248 Set_Defining_Identifier (Formal_Spec,
6249 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
6251 Next (Formal_Spec);
6252 end loop;
6254 return Result;
6255 end Copy_Subprogram_Spec;
6257 --------------------------------
6258 -- Corresponding_Generic_Type --
6259 --------------------------------
6261 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
6262 Inst : Entity_Id;
6263 Gen : Entity_Id;
6264 Typ : Entity_Id;
6266 begin
6267 if not Is_Generic_Actual_Type (T) then
6268 return Any_Type;
6270 -- If the actual is the actual of an enclosing instance, resolution
6271 -- was correct in the generic.
6273 elsif Nkind (Parent (T)) = N_Subtype_Declaration
6274 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
6275 and then
6276 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
6277 then
6278 return Any_Type;
6280 else
6281 Inst := Scope (T);
6283 if Is_Wrapper_Package (Inst) then
6284 Inst := Related_Instance (Inst);
6285 end if;
6287 Gen :=
6288 Generic_Parent
6289 (Specification (Unit_Declaration_Node (Inst)));
6291 -- Generic actual has the same name as the corresponding formal
6293 Typ := First_Entity (Gen);
6294 while Present (Typ) loop
6295 if Chars (Typ) = Chars (T) then
6296 return Typ;
6297 end if;
6299 Next_Entity (Typ);
6300 end loop;
6302 return Any_Type;
6303 end if;
6304 end Corresponding_Generic_Type;
6306 --------------------------------
6307 -- Corresponding_Primitive_Op --
6308 --------------------------------
6310 function Corresponding_Primitive_Op
6311 (Ancestor_Op : Entity_Id;
6312 Descendant_Type : Entity_Id) return Entity_Id
6314 function Find_Untagged_Type_Of (Prim : Entity_Id) return Entity_Id;
6315 -- Search for the untagged type of the primitive operation Prim.
6317 function Profile_Matches_Ancestor (S : Entity_Id) return Boolean;
6318 -- Returns True if subprogram S has the proper profile for an
6319 -- overriding of Ancestor_Op (that is, corresponding formals either
6320 -- have the same type, or are corresponding controlling formals,
6321 -- and similarly for result types).
6323 ---------------------------
6324 -- Find_Untagged_Type_Of --
6325 ---------------------------
6327 function Find_Untagged_Type_Of (Prim : Entity_Id) return Entity_Id is
6328 E : Entity_Id := First_Entity (Scope (Prim));
6330 begin
6331 while Present (E) and then E /= Prim loop
6332 if not Is_Tagged_Type (E)
6333 and then Contains (Direct_Primitive_Operations (E), Prim)
6334 then
6335 return E;
6336 end if;
6338 Next_Entity (E);
6339 end loop;
6341 pragma Assert (False);
6342 return Empty;
6343 end Find_Untagged_Type_Of;
6345 Typ : constant Entity_Id :=
6346 (if Is_Dispatching_Operation (Ancestor_Op)
6347 then Find_Dispatching_Type (Ancestor_Op)
6348 else Find_Untagged_Type_Of (Ancestor_Op));
6350 ------------------------------
6351 -- Profile_Matches_Ancestor --
6352 ------------------------------
6354 function Profile_Matches_Ancestor (S : Entity_Id) return Boolean is
6355 F1 : Entity_Id := First_Formal (Ancestor_Op);
6356 F2 : Entity_Id := First_Formal (S);
6358 begin
6359 if Ekind (Ancestor_Op) /= Ekind (S) then
6360 return False;
6361 end if;
6363 -- ??? This should probably account for anonymous access formals,
6364 -- but the parent function (Corresponding_Primitive_Op) is currently
6365 -- only called for user-defined literal functions, which can't have
6366 -- such formals. But if this is ever used in a more general context
6367 -- it should be extended to handle such formals (and result types).
6369 while Present (F1) and then Present (F2) loop
6370 if Etype (F1) = Etype (F2)
6371 or else Is_Ancestor (Typ, Etype (F2))
6372 then
6373 Next_Formal (F1);
6374 Next_Formal (F2);
6375 else
6376 return False;
6377 end if;
6378 end loop;
6380 return No (F1)
6381 and then No (F2)
6382 and then (Etype (Ancestor_Op) = Etype (S)
6383 or else Is_Ancestor (Typ, Etype (S)));
6384 end Profile_Matches_Ancestor;
6386 -- Local variables
6388 Elmt : Elmt_Id;
6389 Subp : Entity_Id;
6391 -- Start of processing for Corresponding_Primitive_Op
6393 begin
6394 pragma Assert (Is_Ancestor (Typ, Descendant_Type)
6395 or else Is_Progenitor (Typ, Descendant_Type));
6397 Elmt := First_Elmt (Primitive_Operations (Descendant_Type));
6399 while Present (Elmt) loop
6400 Subp := Node (Elmt);
6402 -- For regular primitives we need to check the profile against
6403 -- the ancestor when the name matches the name of Ancestor_Op,
6404 -- but for predefined dispatching operations we cannot rely on
6405 -- the name of the primitive to identify a candidate since their
6406 -- name is internally built by adding a suffix to the name of the
6407 -- tagged type.
6409 if Chars (Subp) = Chars (Ancestor_Op)
6410 or else Is_Predefined_Dispatching_Operation (Subp)
6411 then
6412 -- Handle case where Ancestor_Op is a primitive of a progenitor.
6413 -- We rely on internal entities that map interface primitives:
6414 -- their attribute Interface_Alias references the interface
6415 -- primitive, and their Alias attribute references the primitive
6416 -- of Descendant_Type implementing that interface primitive.
6418 if Present (Interface_Alias (Subp)) then
6419 if Interface_Alias (Subp) = Ancestor_Op then
6420 return Alias (Subp);
6421 end if;
6423 -- Otherwise, return subprogram when profile matches its ancestor
6425 elsif Profile_Matches_Ancestor (Subp) then
6426 return Subp;
6427 end if;
6428 end if;
6430 Next_Elmt (Elmt);
6431 end loop;
6433 pragma Assert (False);
6434 return Empty;
6435 end Corresponding_Primitive_Op;
6437 --------------------
6438 -- Current_Entity --
6439 --------------------
6441 -- The currently visible definition for a given identifier is the
6442 -- one most chained at the start of the visibility chain, i.e. the
6443 -- one that is referenced by the Node_Id value of the name of the
6444 -- given identifier.
6446 function Current_Entity (N : Node_Id) return Entity_Id is
6447 begin
6448 return Get_Name_Entity_Id (Chars (N));
6449 end Current_Entity;
6451 -----------------------------
6452 -- Current_Entity_In_Scope --
6453 -----------------------------
6455 function Current_Entity_In_Scope (N : Name_Id) return Entity_Id is
6456 CS : constant Entity_Id := Current_Scope;
6458 E : Entity_Id;
6460 begin
6461 E := Get_Name_Entity_Id (N);
6463 if No (E) then
6464 null;
6466 elsif Scope_Is_Transient then
6467 while Present (E) loop
6468 exit when Scope (E) = CS or else Scope (E) = Scope (CS);
6470 E := Homonym (E);
6471 end loop;
6473 else
6474 while Present (E) loop
6475 exit when Scope (E) = CS;
6477 E := Homonym (E);
6478 end loop;
6479 end if;
6481 return E;
6482 end Current_Entity_In_Scope;
6484 -----------------------------
6485 -- Current_Entity_In_Scope --
6486 -----------------------------
6488 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
6489 begin
6490 return Current_Entity_In_Scope (Chars (N));
6491 end Current_Entity_In_Scope;
6493 -------------------
6494 -- Current_Scope --
6495 -------------------
6497 function Current_Scope return Entity_Id is
6498 begin
6499 if Scope_Stack.Last = -1 then
6500 return Standard_Standard;
6501 else
6502 declare
6503 C : constant Entity_Id :=
6504 Scope_Stack.Table (Scope_Stack.Last).Entity;
6505 begin
6506 if Present (C) then
6507 return C;
6508 else
6509 return Standard_Standard;
6510 end if;
6511 end;
6512 end if;
6513 end Current_Scope;
6515 ----------------------------
6516 -- Current_Scope_No_Loops --
6517 ----------------------------
6519 function Current_Scope_No_Loops return Entity_Id is
6520 S : Entity_Id;
6522 begin
6523 -- Examine the scope stack starting from the current scope and skip any
6524 -- internally generated loops.
6526 S := Current_Scope;
6527 while Present (S) and then S /= Standard_Standard loop
6528 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
6529 S := Scope (S);
6530 else
6531 exit;
6532 end if;
6533 end loop;
6535 return S;
6536 end Current_Scope_No_Loops;
6538 ------------------------
6539 -- Current_Subprogram --
6540 ------------------------
6542 function Current_Subprogram return Entity_Id is
6543 Scop : constant Entity_Id := Current_Scope;
6544 begin
6545 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
6546 return Scop;
6547 else
6548 return Enclosing_Subprogram (Scop);
6549 end if;
6550 end Current_Subprogram;
6552 ------------------------------
6553 -- CW_Or_Needs_Finalization --
6554 ------------------------------
6556 function CW_Or_Needs_Finalization (Typ : Entity_Id) return Boolean is
6557 begin
6558 return Is_Class_Wide_Type (Typ) or else Needs_Finalization (Typ);
6559 end CW_Or_Needs_Finalization;
6561 ---------------------
6562 -- Defining_Entity --
6563 ---------------------
6565 function Defining_Entity (N : Node_Id) return Entity_Id is
6566 Ent : constant Entity_Id := Defining_Entity_Or_Empty (N);
6568 begin
6569 if Present (Ent) then
6570 return Ent;
6572 else
6573 raise Program_Error;
6574 end if;
6575 end Defining_Entity;
6577 ------------------------------
6578 -- Defining_Entity_Or_Empty --
6579 ------------------------------
6581 function Defining_Entity_Or_Empty (N : Node_Id) return Entity_Id is
6582 begin
6583 case Nkind (N) is
6584 when N_Abstract_Subprogram_Declaration
6585 | N_Expression_Function
6586 | N_Formal_Subprogram_Declaration
6587 | N_Generic_Package_Declaration
6588 | N_Generic_Subprogram_Declaration
6589 | N_Package_Declaration
6590 | N_Subprogram_Body
6591 | N_Subprogram_Body_Stub
6592 | N_Subprogram_Declaration
6593 | N_Subprogram_Renaming_Declaration
6595 return Defining_Entity (Specification (N));
6597 when N_Component_Declaration
6598 | N_Defining_Program_Unit_Name
6599 | N_Discriminant_Specification
6600 | N_Entry_Body
6601 | N_Entry_Declaration
6602 | N_Entry_Index_Specification
6603 | N_Exception_Declaration
6604 | N_Exception_Renaming_Declaration
6605 | N_Formal_Object_Declaration
6606 | N_Formal_Package_Declaration
6607 | N_Formal_Type_Declaration
6608 | N_Full_Type_Declaration
6609 | N_Implicit_Label_Declaration
6610 | N_Incomplete_Type_Declaration
6611 | N_Iterator_Specification
6612 | N_Loop_Parameter_Specification
6613 | N_Number_Declaration
6614 | N_Object_Declaration
6615 | N_Object_Renaming_Declaration
6616 | N_Package_Body_Stub
6617 | N_Parameter_Specification
6618 | N_Private_Extension_Declaration
6619 | N_Private_Type_Declaration
6620 | N_Protected_Body
6621 | N_Protected_Body_Stub
6622 | N_Protected_Type_Declaration
6623 | N_Single_Protected_Declaration
6624 | N_Single_Task_Declaration
6625 | N_Subtype_Declaration
6626 | N_Task_Body
6627 | N_Task_Body_Stub
6628 | N_Task_Type_Declaration
6630 return Defining_Identifier (N);
6632 when N_Compilation_Unit =>
6633 return Defining_Entity (Unit (N));
6635 when N_Subunit =>
6636 return Defining_Entity (Proper_Body (N));
6638 when N_Function_Instantiation
6639 | N_Function_Specification
6640 | N_Generic_Function_Renaming_Declaration
6641 | N_Generic_Package_Renaming_Declaration
6642 | N_Generic_Procedure_Renaming_Declaration
6643 | N_Package_Body
6644 | N_Package_Instantiation
6645 | N_Package_Renaming_Declaration
6646 | N_Package_Specification
6647 | N_Procedure_Instantiation
6648 | N_Procedure_Specification
6650 declare
6651 Nam : constant Node_Id := Defining_Unit_Name (N);
6652 Err : Entity_Id := Empty;
6654 begin
6655 if Nkind (Nam) in N_Entity then
6656 return Nam;
6658 -- For Error, make up a name and attach to declaration so we
6659 -- can continue semantic analysis.
6661 elsif Nam = Error then
6662 Err := Make_Temporary (Sloc (N), 'T');
6663 Set_Defining_Unit_Name (N, Err);
6665 return Err;
6667 -- If not an entity, get defining identifier
6669 else
6670 return Defining_Identifier (Nam);
6671 end if;
6672 end;
6674 when N_Block_Statement
6675 | N_Loop_Statement
6677 return Entity (Identifier (N));
6679 when others =>
6680 return Empty;
6681 end case;
6682 end Defining_Entity_Or_Empty;
6684 --------------------------
6685 -- Denotes_Discriminant --
6686 --------------------------
6688 function Denotes_Discriminant
6689 (N : Node_Id;
6690 Check_Concurrent : Boolean := False) return Boolean
6692 E : Entity_Id;
6694 begin
6695 if not Is_Entity_Name (N) or else No (Entity (N)) then
6696 return False;
6697 else
6698 E := Entity (N);
6699 end if;
6701 -- If we are checking for a protected type, the discriminant may have
6702 -- been rewritten as the corresponding discriminal of the original type
6703 -- or of the corresponding concurrent record, depending on whether we
6704 -- are in the spec or body of the protected type.
6706 return Ekind (E) = E_Discriminant
6707 or else
6708 (Check_Concurrent
6709 and then Ekind (E) = E_In_Parameter
6710 and then Present (Discriminal_Link (E))
6711 and then
6712 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
6713 or else
6714 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
6715 end Denotes_Discriminant;
6717 -------------------------
6718 -- Denotes_Same_Object --
6719 -------------------------
6721 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
6722 function Is_Object_Renaming (N : Node_Id) return Boolean;
6723 -- Return true if N names an object renaming entity
6725 function Is_Valid_Renaming (N : Node_Id) return Boolean;
6726 -- For renamings, return False if the prefix of any dereference within
6727 -- the renamed object_name is a variable, or any expression within the
6728 -- renamed object_name contains references to variables or calls on
6729 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6731 ------------------------
6732 -- Is_Object_Renaming --
6733 ------------------------
6735 function Is_Object_Renaming (N : Node_Id) return Boolean is
6736 begin
6737 return Is_Entity_Name (N)
6738 and then Ekind (Entity (N)) in E_Variable | E_Constant
6739 and then Present (Renamed_Object (Entity (N)));
6740 end Is_Object_Renaming;
6742 -----------------------
6743 -- Is_Valid_Renaming --
6744 -----------------------
6746 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6747 begin
6748 if Is_Object_Renaming (N)
6749 and then not Is_Valid_Renaming (Renamed_Object (Entity (N)))
6750 then
6751 return False;
6752 end if;
6754 -- Check if any expression within the renamed object_name contains no
6755 -- references to variables nor calls on nonstatic functions.
6757 if Nkind (N) = N_Indexed_Component then
6758 declare
6759 Indx : Node_Id;
6761 begin
6762 Indx := First (Expressions (N));
6763 while Present (Indx) loop
6764 if not Is_OK_Static_Expression (Indx) then
6765 return False;
6766 end if;
6768 Next (Indx);
6769 end loop;
6770 end;
6772 elsif Nkind (N) = N_Slice then
6773 declare
6774 Rng : constant Node_Id := Discrete_Range (N);
6775 begin
6776 -- Bounds specified as a range
6778 if Nkind (Rng) = N_Range then
6779 if not Is_OK_Static_Range (Rng) then
6780 return False;
6781 end if;
6783 -- Bounds specified as a constrained subtype indication
6785 elsif Nkind (Rng) = N_Subtype_Indication then
6786 if not Is_OK_Static_Range
6787 (Range_Expression (Constraint (Rng)))
6788 then
6789 return False;
6790 end if;
6792 -- Bounds specified as a subtype name
6794 elsif not Is_OK_Static_Expression (Rng) then
6795 return False;
6796 end if;
6797 end;
6798 end if;
6800 if Has_Prefix (N) then
6801 declare
6802 P : constant Node_Id := Prefix (N);
6804 begin
6805 if Nkind (N) = N_Explicit_Dereference
6806 and then Is_Variable (P)
6807 then
6808 return False;
6810 elsif Is_Entity_Name (P)
6811 and then Ekind (Entity (P)) = E_Function
6812 then
6813 return False;
6815 elsif Nkind (P) = N_Function_Call then
6816 return False;
6817 end if;
6819 -- Recursion to continue traversing the prefix of the
6820 -- renaming expression
6822 return Is_Valid_Renaming (P);
6823 end;
6824 end if;
6826 return True;
6827 end Is_Valid_Renaming;
6829 -- Start of processing for Denotes_Same_Object
6831 begin
6832 -- Both names statically denote the same stand-alone object or
6833 -- parameter (RM 6.4.1(6.6/3)).
6835 if Is_Entity_Name (A1)
6836 and then Is_Entity_Name (A2)
6837 and then Entity (A1) = Entity (A2)
6838 then
6839 return True;
6841 -- Both names are selected_components, their prefixes are known to
6842 -- denote the same object, and their selector_names denote the same
6843 -- component (RM 6.4.1(6.7/3)).
6845 elsif Nkind (A1) = N_Selected_Component
6846 and then Nkind (A2) = N_Selected_Component
6847 then
6848 return Denotes_Same_Object (Prefix (A1), Prefix (A2))
6849 and then
6850 Entity (Selector_Name (A1)) = Entity (Selector_Name (A2));
6852 -- Both names are dereferences and the dereferenced names are known to
6853 -- denote the same object (RM 6.4.1(6.8/3)).
6855 elsif Nkind (A1) = N_Explicit_Dereference
6856 and then Nkind (A2) = N_Explicit_Dereference
6857 then
6858 return Denotes_Same_Object (Prefix (A1), Prefix (A2));
6860 -- Both names are indexed_components, their prefixes are known to denote
6861 -- the same object, and each of the pairs of corresponding index values
6862 -- are either both static expressions with the same static value or both
6863 -- names that are known to denote the same object (RM 6.4.1(6.9/3)).
6865 elsif Nkind (A1) = N_Indexed_Component
6866 and then Nkind (A2) = N_Indexed_Component
6867 then
6868 if not Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
6869 return False;
6870 else
6871 declare
6872 Indx1 : Node_Id;
6873 Indx2 : Node_Id;
6875 begin
6876 Indx1 := First (Expressions (A1));
6877 Indx2 := First (Expressions (A2));
6878 while Present (Indx1) loop
6880 -- Indexes must denote the same static value or same object
6882 if Is_OK_Static_Expression (Indx1) then
6883 if not Is_OK_Static_Expression (Indx2) then
6884 return False;
6886 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6887 return False;
6888 end if;
6890 elsif not Denotes_Same_Object (Indx1, Indx2) then
6891 return False;
6892 end if;
6894 Next (Indx1);
6895 Next (Indx2);
6896 end loop;
6898 return True;
6899 end;
6900 end if;
6902 -- Both names are slices, their prefixes are known to denote the same
6903 -- object, and the two slices have statically matching index constraints
6904 -- (RM 6.4.1(6.10/3)).
6906 elsif Nkind (A1) = N_Slice
6907 and then Nkind (A2) = N_Slice
6908 then
6909 if not Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
6910 return False;
6911 else
6912 declare
6913 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6915 begin
6916 Get_Index_Bounds (Discrete_Range (A1), Lo1, Hi1);
6917 Get_Index_Bounds (Discrete_Range (A2), Lo2, Hi2);
6919 -- Check whether bounds are statically identical. There is no
6920 -- attempt to detect partial overlap of slices.
6922 return Is_OK_Static_Expression (Lo1)
6923 and then Is_OK_Static_Expression (Lo2)
6924 and then Is_OK_Static_Expression (Hi1)
6925 and then Is_OK_Static_Expression (Hi2)
6926 and then Expr_Value (Lo1) = Expr_Value (Lo2)
6927 and then Expr_Value (Hi1) = Expr_Value (Hi2);
6928 end;
6929 end if;
6931 -- One of the two names statically denotes a renaming declaration whose
6932 -- renamed object_name is known to denote the same object as the other;
6933 -- the prefix of any dereference within the renamed object_name is not a
6934 -- variable, and any expression within the renamed object_name contains
6935 -- no references to variables nor calls on nonstatic functions (RM
6936 -- 6.4.1(6.11/3)).
6938 elsif Is_Object_Renaming (A1)
6939 and then Is_Valid_Renaming (A1)
6940 then
6941 return Denotes_Same_Object (Renamed_Object (Entity (A1)), A2);
6943 elsif Is_Object_Renaming (A2)
6944 and then Is_Valid_Renaming (A2)
6945 then
6946 return Denotes_Same_Object (A1, Renamed_Object (Entity (A2)));
6948 else
6949 return False;
6950 end if;
6951 end Denotes_Same_Object;
6953 -------------------------
6954 -- Denotes_Same_Prefix --
6955 -------------------------
6957 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6958 begin
6959 if Is_Entity_Name (A1) then
6960 if Nkind (A2) in N_Selected_Component | N_Indexed_Component
6961 and then not Is_Access_Type (Etype (A1))
6962 then
6963 return Denotes_Same_Object (A1, Prefix (A2))
6964 or else Denotes_Same_Prefix (A1, Prefix (A2));
6965 else
6966 return False;
6967 end if;
6969 elsif Is_Entity_Name (A2) then
6970 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6972 elsif Nkind (A1) in N_Selected_Component | N_Indexed_Component | N_Slice
6973 and then
6974 Nkind (A2) in N_Selected_Component | N_Indexed_Component | N_Slice
6975 then
6976 declare
6977 Root1, Root2 : Node_Id;
6978 Depth1, Depth2 : Nat := 0;
6980 begin
6981 Root1 := Prefix (A1);
6982 while not Is_Entity_Name (Root1) loop
6983 if Nkind (Root1) not in
6984 N_Selected_Component | N_Indexed_Component
6985 then
6986 return False;
6987 else
6988 Root1 := Prefix (Root1);
6989 end if;
6991 Depth1 := Depth1 + 1;
6992 end loop;
6994 Root2 := Prefix (A2);
6995 while not Is_Entity_Name (Root2) loop
6996 if Nkind (Root2) not in
6997 N_Selected_Component | N_Indexed_Component
6998 then
6999 return False;
7000 else
7001 Root2 := Prefix (Root2);
7002 end if;
7004 Depth2 := Depth2 + 1;
7005 end loop;
7007 -- If both have the same depth and they do not denote the same
7008 -- object, they are disjoint and no warning is needed.
7010 if Depth1 = Depth2 then
7011 return False;
7013 elsif Depth1 > Depth2 then
7014 Root1 := Prefix (A1);
7015 for J in 1 .. Depth1 - Depth2 - 1 loop
7016 Root1 := Prefix (Root1);
7017 end loop;
7019 return Denotes_Same_Object (Root1, A2);
7021 else
7022 Root2 := Prefix (A2);
7023 for J in 1 .. Depth2 - Depth1 - 1 loop
7024 Root2 := Prefix (Root2);
7025 end loop;
7027 return Denotes_Same_Object (A1, Root2);
7028 end if;
7029 end;
7031 else
7032 return False;
7033 end if;
7034 end Denotes_Same_Prefix;
7036 ----------------------
7037 -- Denotes_Variable --
7038 ----------------------
7040 function Denotes_Variable (N : Node_Id) return Boolean is
7041 begin
7042 return Is_Variable (N) and then Paren_Count (N) = 0;
7043 end Denotes_Variable;
7045 -----------------------------
7046 -- Depends_On_Discriminant --
7047 -----------------------------
7049 function Depends_On_Discriminant (N : Node_Id) return Boolean is
7050 L : Node_Id;
7051 H : Node_Id;
7053 begin
7054 Get_Index_Bounds (N, L, H);
7055 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
7056 end Depends_On_Discriminant;
7058 -------------------------------------
7059 -- Derivation_Too_Early_To_Inherit --
7060 -------------------------------------
7062 function Derivation_Too_Early_To_Inherit
7063 (Typ : Entity_Id; Streaming_Op : TSS_Name_Type) return Boolean is
7065 Btyp : constant Entity_Id := Implementation_Base_Type (Typ);
7066 Parent_Type : Entity_Id;
7068 Real_Rep : Node_Id;
7070 -- Start of processing for Derivation_Too_Early_To_Inherit
7072 begin
7073 if Is_Derived_Type (Btyp) then
7074 Parent_Type := Implementation_Base_Type (Etype (Btyp));
7075 pragma Assert (Parent_Type /= Btyp);
7077 if Has_Stream_Attribute_Definition
7078 (Parent_Type, Streaming_Op, Real_Rep => Real_Rep)
7080 and then In_Same_Extended_Unit (Btyp, Parent_Type)
7081 and then Instantiation (Get_Source_File_Index (Sloc (Btyp))) =
7082 Instantiation (Get_Source_File_Index (Sloc (Parent_Type)))
7083 then
7084 return Earlier_In_Extended_Unit (Btyp, Real_Rep);
7085 end if;
7086 end if;
7088 return False;
7089 end Derivation_Too_Early_To_Inherit;
7091 -------------------------
7092 -- Designate_Same_Unit --
7093 -------------------------
7095 function Designate_Same_Unit
7096 (Name1 : Node_Id;
7097 Name2 : Node_Id) return Boolean
7099 K1 : constant Node_Kind := Nkind (Name1);
7100 K2 : constant Node_Kind := Nkind (Name2);
7102 function Prefix_Node (N : Node_Id) return Node_Id;
7103 -- Returns the parent unit name node of a defining program unit name
7104 -- or the prefix if N is a selected component or an expanded name.
7106 function Select_Node (N : Node_Id) return Node_Id;
7107 -- Returns the defining identifier node of a defining program unit
7108 -- name or the selector node if N is a selected component or an
7109 -- expanded name.
7111 -----------------
7112 -- Prefix_Node --
7113 -----------------
7115 function Prefix_Node (N : Node_Id) return Node_Id is
7116 begin
7117 if Nkind (N) = N_Defining_Program_Unit_Name then
7118 return Name (N);
7119 else
7120 return Prefix (N);
7121 end if;
7122 end Prefix_Node;
7124 -----------------
7125 -- Select_Node --
7126 -----------------
7128 function Select_Node (N : Node_Id) return Node_Id is
7129 begin
7130 if Nkind (N) = N_Defining_Program_Unit_Name then
7131 return Defining_Identifier (N);
7132 else
7133 return Selector_Name (N);
7134 end if;
7135 end Select_Node;
7137 -- Start of processing for Designate_Same_Unit
7139 begin
7140 if K1 in N_Identifier | N_Defining_Identifier
7141 and then
7142 K2 in N_Identifier | N_Defining_Identifier
7143 then
7144 return Chars (Name1) = Chars (Name2);
7146 elsif K1 in N_Expanded_Name
7147 | N_Selected_Component
7148 | N_Defining_Program_Unit_Name
7149 and then
7150 K2 in N_Expanded_Name
7151 | N_Selected_Component
7152 | N_Defining_Program_Unit_Name
7153 then
7154 return
7155 Chars (Select_Node (Name1)) = Chars (Select_Node (Name2))
7156 and then
7157 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
7159 else
7160 return False;
7161 end if;
7162 end Designate_Same_Unit;
7164 ---------------------------------------------
7165 -- Diagnose_Iterated_Component_Association --
7166 ---------------------------------------------
7168 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
7169 Def_Id : constant Entity_Id := Defining_Identifier (N);
7170 Aggr : Node_Id;
7172 begin
7173 -- Determine whether the iterated component association appears within
7174 -- an aggregate. If this is the case, raise Program_Error because the
7175 -- iterated component association cannot be left in the tree as is and
7176 -- must always be processed by the related aggregate.
7178 Aggr := N;
7179 while Present (Aggr) loop
7180 if Nkind (Aggr) = N_Aggregate then
7181 raise Program_Error;
7183 -- Prevent the search from going too far
7185 elsif Is_Body_Or_Package_Declaration (Aggr) then
7186 exit;
7187 end if;
7189 Aggr := Parent (Aggr);
7190 end loop;
7192 -- At this point it is known that the iterated component association is
7193 -- not within an aggregate. This is really a quantified expression with
7194 -- a missing "all" or "some" quantifier.
7196 Error_Msg_N ("missing quantifier", Def_Id);
7198 -- Rewrite the iterated component association as True to prevent any
7199 -- cascaded errors.
7201 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
7202 Analyze (N);
7203 end Diagnose_Iterated_Component_Association;
7205 ------------------------
7206 -- Discriminated_Size --
7207 ------------------------
7209 function Discriminated_Size (Comp : Entity_Id) return Boolean is
7210 function Non_Static_Bound (Bound : Node_Id) return Boolean;
7211 -- Check whether the bound of an index is non-static and does denote
7212 -- a discriminant, in which case any object of the type (protected or
7213 -- otherwise) will have a non-static size.
7215 ----------------------
7216 -- Non_Static_Bound --
7217 ----------------------
7219 function Non_Static_Bound (Bound : Node_Id) return Boolean is
7220 begin
7221 if Is_OK_Static_Expression (Bound) then
7222 return False;
7224 -- If the bound is given by a discriminant it is non-static
7225 -- (A static constraint replaces the reference with the value).
7226 -- In an protected object the discriminant has been replaced by
7227 -- the corresponding discriminal within the protected operation.
7229 elsif Is_Entity_Name (Bound)
7230 and then
7231 (Ekind (Entity (Bound)) = E_Discriminant
7232 or else Present (Discriminal_Link (Entity (Bound))))
7233 then
7234 return False;
7236 else
7237 return True;
7238 end if;
7239 end Non_Static_Bound;
7241 -- Local variables
7243 Typ : constant Entity_Id := Etype (Comp);
7244 Index : Node_Id;
7246 -- Start of processing for Discriminated_Size
7248 begin
7249 if not Is_Array_Type (Typ) then
7250 return False;
7251 end if;
7253 if Ekind (Typ) = E_Array_Subtype then
7254 Index := First_Index (Typ);
7255 while Present (Index) loop
7256 if Non_Static_Bound (Low_Bound (Index))
7257 or else Non_Static_Bound (High_Bound (Index))
7258 then
7259 return False;
7260 end if;
7262 Next_Index (Index);
7263 end loop;
7265 return True;
7266 end if;
7268 return False;
7269 end Discriminated_Size;
7271 -----------------------------
7272 -- Effective_Reads_Enabled --
7273 -----------------------------
7275 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
7276 begin
7277 return Has_Enabled_Property (Id, Name_Effective_Reads);
7278 end Effective_Reads_Enabled;
7280 ------------------------------
7281 -- Effective_Writes_Enabled --
7282 ------------------------------
7284 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
7285 begin
7286 return Has_Enabled_Property (Id, Name_Effective_Writes);
7287 end Effective_Writes_Enabled;
7289 ------------------------------
7290 -- Enclosing_Comp_Unit_Node --
7291 ------------------------------
7293 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
7294 Current_Node : Node_Id;
7296 begin
7297 Current_Node := N;
7298 while Present (Current_Node)
7299 and then Nkind (Current_Node) /= N_Compilation_Unit
7300 loop
7301 Current_Node := Parent (Current_Node);
7302 end loop;
7304 return Current_Node;
7305 end Enclosing_Comp_Unit_Node;
7307 --------------------------
7308 -- Enclosing_CPP_Parent --
7309 --------------------------
7311 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
7312 Parent_Typ : Entity_Id := Typ;
7314 begin
7315 while not Is_CPP_Class (Parent_Typ)
7316 and then Etype (Parent_Typ) /= Parent_Typ
7317 loop
7318 Parent_Typ := Etype (Parent_Typ);
7320 if Is_Private_Type (Parent_Typ) then
7321 Parent_Typ := Full_View (Base_Type (Parent_Typ));
7322 end if;
7323 end loop;
7325 pragma Assert (Is_CPP_Class (Parent_Typ));
7326 return Parent_Typ;
7327 end Enclosing_CPP_Parent;
7329 ---------------------------
7330 -- Enclosing_Declaration --
7331 ---------------------------
7333 function Enclosing_Declaration (N : Node_Id) return Node_Id is
7334 Decl : Node_Id := N;
7336 begin
7337 while Present (Decl)
7338 and then not (Nkind (Decl) in N_Declaration
7339 or else
7340 Nkind (Decl) in N_Later_Decl_Item
7341 or else
7342 Nkind (Decl) in N_Renaming_Declaration
7343 or else
7344 Nkind (Decl) = N_Number_Declaration)
7345 loop
7346 Decl := Parent (Decl);
7347 end loop;
7349 -- cope with oddness in definition of N_Declaration
7350 if Nkind (Decl) in N_Subprogram_Specification then
7351 Decl := Parent (Decl);
7352 end if;
7354 return Decl;
7355 end Enclosing_Declaration;
7357 ----------------------------------------
7358 -- Enclosing_Declaration_Or_Statement --
7359 ----------------------------------------
7361 function Enclosing_Declaration_Or_Statement
7362 (N : Node_Id) return Node_Id
7364 Par : Node_Id;
7366 begin
7367 Par := N;
7368 while Present (Par) loop
7369 if Is_Declaration (Par) or else Is_Statement (Par) then
7370 return Par;
7372 -- Prevent the search from going too far
7374 elsif Is_Body_Or_Package_Declaration (Par) then
7375 exit;
7376 end if;
7378 Par := Parent (Par);
7379 end loop;
7381 return N;
7382 end Enclosing_Declaration_Or_Statement;
7384 ----------------------------
7385 -- Enclosing_Generic_Body --
7386 ----------------------------
7388 function Enclosing_Generic_Body (N : Node_Id) return Node_Id is
7389 Par : Node_Id;
7390 Spec_Id : Entity_Id;
7392 begin
7393 Par := Parent (N);
7394 while Present (Par) loop
7395 if Nkind (Par) in N_Package_Body | N_Subprogram_Body then
7396 Spec_Id := Corresponding_Spec (Par);
7398 if Present (Spec_Id)
7399 and then Nkind (Unit_Declaration_Node (Spec_Id)) in
7400 N_Generic_Declaration
7401 then
7402 return Par;
7403 end if;
7404 end if;
7406 Par := Parent (Par);
7407 end loop;
7409 return Empty;
7410 end Enclosing_Generic_Body;
7412 ----------------------------
7413 -- Enclosing_Generic_Unit --
7414 ----------------------------
7416 function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is
7417 Par : Node_Id;
7418 Spec_Decl : Node_Id;
7419 Spec_Id : Entity_Id;
7421 begin
7422 Par := Parent (N);
7423 while Present (Par) loop
7424 if Nkind (Par) in N_Generic_Declaration then
7425 return Par;
7427 elsif Nkind (Par) in N_Package_Body | N_Subprogram_Body then
7428 Spec_Id := Corresponding_Spec (Par);
7430 if Present (Spec_Id) then
7431 Spec_Decl := Unit_Declaration_Node (Spec_Id);
7433 if Nkind (Spec_Decl) in N_Generic_Declaration then
7434 return Spec_Decl;
7435 end if;
7436 end if;
7437 end if;
7439 Par := Parent (Par);
7440 end loop;
7442 return Empty;
7443 end Enclosing_Generic_Unit;
7445 -------------------
7446 -- Enclosing_HSS --
7447 -------------------
7449 function Enclosing_HSS (Stmt : Node_Id) return Node_Id is
7450 Par : Node_Id;
7451 begin
7452 pragma Assert (Is_Statement (Stmt));
7454 Par := Parent (Stmt);
7455 while Present (Par) loop
7457 if Nkind (Par) = N_Handled_Sequence_Of_Statements then
7458 return Par;
7460 -- Prevent the search from going too far
7462 elsif Is_Body_Or_Package_Declaration (Par) then
7463 return Empty;
7465 end if;
7467 Par := Parent (Par);
7468 end loop;
7470 return Par;
7471 end Enclosing_HSS;
7473 -------------------------------
7474 -- Enclosing_Lib_Unit_Entity --
7475 -------------------------------
7477 function Enclosing_Lib_Unit_Entity
7478 (E : Entity_Id := Current_Scope) return Entity_Id
7480 Unit_Entity : Entity_Id;
7482 begin
7483 -- Look for enclosing library unit entity by following scope links.
7484 -- Equivalent to, but faster than indexing through the scope stack.
7486 Unit_Entity := E;
7487 while (Present (Scope (Unit_Entity))
7488 and then Scope (Unit_Entity) /= Standard_Standard)
7489 and not Is_Child_Unit (Unit_Entity)
7490 loop
7491 Unit_Entity := Scope (Unit_Entity);
7492 end loop;
7494 return Unit_Entity;
7495 end Enclosing_Lib_Unit_Entity;
7497 -----------------------------
7498 -- Enclosing_Lib_Unit_Node --
7499 -----------------------------
7501 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
7502 Encl_Unit : Node_Id;
7504 begin
7505 Encl_Unit := Enclosing_Comp_Unit_Node (N);
7506 while Present (Encl_Unit)
7507 and then Nkind (Unit (Encl_Unit)) = N_Subunit
7508 loop
7509 Encl_Unit := Library_Unit (Encl_Unit);
7510 end loop;
7512 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
7513 return Encl_Unit;
7514 end Enclosing_Lib_Unit_Node;
7516 -----------------------
7517 -- Enclosing_Package --
7518 -----------------------
7520 function Enclosing_Package (N : Node_Or_Entity_Id) return Entity_Id is
7521 Dynamic_Scope : Entity_Id;
7523 begin
7524 -- Obtain the enclosing scope when N is a Node_Id - taking care to
7525 -- handle the case when the enclosing scope is already a package.
7527 if Nkind (N) not in N_Entity then
7528 declare
7529 Encl_Scop : constant Entity_Id := Find_Enclosing_Scope (N);
7530 begin
7531 if No (Encl_Scop) then
7532 return Empty;
7533 elsif Ekind (Encl_Scop) in
7534 E_Generic_Package | E_Package | E_Package_Body
7535 then
7536 return Encl_Scop;
7537 end if;
7539 return Enclosing_Package (Encl_Scop);
7540 end;
7541 end if;
7543 -- When N is already an Entity_Id proceed
7545 Dynamic_Scope := Enclosing_Dynamic_Scope (N);
7546 if Dynamic_Scope = Standard_Standard then
7547 return Standard_Standard;
7549 elsif Dynamic_Scope = Empty then
7550 return Empty;
7552 elsif Ekind (Dynamic_Scope) in
7553 E_Generic_Package | E_Package | E_Package_Body
7554 then
7555 return Dynamic_Scope;
7557 else
7558 return Enclosing_Package (Dynamic_Scope);
7559 end if;
7560 end Enclosing_Package;
7562 -------------------------------------
7563 -- Enclosing_Package_Or_Subprogram --
7564 -------------------------------------
7566 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
7567 S : Entity_Id;
7569 begin
7570 S := Scope (E);
7571 while Present (S) loop
7572 if Is_Package_Or_Generic_Package (S)
7573 or else Is_Subprogram_Or_Generic_Subprogram (S)
7574 then
7575 return S;
7577 else
7578 S := Scope (S);
7579 end if;
7580 end loop;
7582 return Empty;
7583 end Enclosing_Package_Or_Subprogram;
7585 --------------------------
7586 -- Enclosing_Subprogram --
7587 --------------------------
7589 function Enclosing_Subprogram (N : Node_Or_Entity_Id) return Entity_Id is
7590 Dyn_Scop : Entity_Id;
7591 Encl_Scop : Entity_Id;
7593 begin
7594 -- Obtain the enclosing scope when N is a Node_Id - taking care to
7595 -- handle the case when the enclosing scope is already a subprogram.
7597 if Nkind (N) not in N_Entity then
7598 Encl_Scop := Find_Enclosing_Scope (N);
7600 if No (Encl_Scop) then
7601 return Empty;
7602 elsif Ekind (Encl_Scop) in Subprogram_Kind then
7603 return Encl_Scop;
7604 end if;
7606 return Enclosing_Subprogram (Encl_Scop);
7607 end if;
7609 -- When N is already an Entity_Id proceed
7611 Dyn_Scop := Enclosing_Dynamic_Scope (N);
7612 if Dyn_Scop = Standard_Standard then
7613 return Empty;
7615 elsif Dyn_Scop = Empty then
7616 return Empty;
7618 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
7619 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
7621 elsif Ekind (Dyn_Scop) in E_Block | E_Loop | E_Return_Statement then
7622 return Enclosing_Subprogram (Dyn_Scop);
7624 elsif Ekind (Dyn_Scop) in E_Entry | E_Entry_Family then
7626 -- For a task entry or entry family, return the enclosing subprogram
7627 -- of the task itself.
7629 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
7630 return Enclosing_Subprogram (Dyn_Scop);
7632 -- A protected entry or entry family is rewritten as a protected
7633 -- procedure which is the desired enclosing subprogram. This is
7634 -- relevant when unnesting a procedure local to an entry body.
7636 else
7637 return Protected_Body_Subprogram (Dyn_Scop);
7638 end if;
7640 elsif Ekind (Dyn_Scop) = E_Task_Type then
7641 return Get_Task_Body_Procedure (Dyn_Scop);
7643 -- The scope may appear as a private type or as a private extension
7644 -- whose completion is a task or protected type.
7646 elsif Ekind (Dyn_Scop) in
7647 E_Limited_Private_Type | E_Record_Type_With_Private
7648 and then Present (Full_View (Dyn_Scop))
7649 and then Ekind (Full_View (Dyn_Scop)) in E_Task_Type | E_Protected_Type
7650 then
7651 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
7653 -- No body is generated if the protected operation is eliminated
7655 elsif not Is_Eliminated (Dyn_Scop)
7656 and then Present (Protected_Body_Subprogram (Dyn_Scop))
7657 then
7658 return Protected_Body_Subprogram (Dyn_Scop);
7660 else
7661 return Dyn_Scop;
7662 end if;
7663 end Enclosing_Subprogram;
7665 --------------------------
7666 -- End_Keyword_Location --
7667 --------------------------
7669 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
7670 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
7671 -- Return the source location of Nod's end label according to the
7672 -- following precedence rules:
7674 -- 1) If the end label exists, return its location
7675 -- 2) If Nod exists, return its location
7676 -- 3) Return the location of N
7678 -------------------
7679 -- End_Label_Loc --
7680 -------------------
7682 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
7683 Label : Node_Id;
7685 begin
7686 if Present (Nod) then
7687 Label := End_Label (Nod);
7689 if Present (Label) then
7690 return Sloc (Label);
7691 else
7692 return Sloc (Nod);
7693 end if;
7695 else
7696 return Sloc (N);
7697 end if;
7698 end End_Label_Loc;
7700 -- Local variables
7702 Owner : Node_Id := Empty;
7704 -- Start of processing for End_Keyword_Location
7706 begin
7707 if Nkind (N) in N_Block_Statement
7708 | N_Entry_Body
7709 | N_Package_Body
7710 | N_Subprogram_Body
7711 | N_Task_Body
7712 then
7713 Owner := Handled_Statement_Sequence (N);
7715 elsif Nkind (N) = N_Package_Declaration then
7716 Owner := Specification (N);
7718 elsif Nkind (N) = N_Protected_Body then
7719 Owner := N;
7721 elsif Nkind (N) in N_Protected_Type_Declaration
7722 | N_Single_Protected_Declaration
7723 then
7724 Owner := Protected_Definition (N);
7726 elsif Nkind (N) in N_Single_Task_Declaration | N_Task_Type_Declaration
7727 then
7728 Owner := Task_Definition (N);
7730 -- This routine should not be called with other contexts
7732 else
7733 pragma Assert (False);
7734 null;
7735 end if;
7737 return End_Label_Loc (Owner);
7738 end End_Keyword_Location;
7740 ------------------------
7741 -- Ensure_Freeze_Node --
7742 ------------------------
7744 procedure Ensure_Freeze_Node (E : Entity_Id) is
7745 FN : Node_Id;
7746 begin
7747 if No (Freeze_Node (E)) then
7748 FN := Make_Freeze_Entity (Sloc (E));
7749 Set_Has_Delayed_Freeze (E);
7750 Set_Freeze_Node (E, FN);
7751 Set_Access_Types_To_Process (FN, No_Elist);
7752 Set_TSS_Elist (FN, No_Elist);
7753 Set_Entity (FN, E);
7754 end if;
7755 end Ensure_Freeze_Node;
7757 ----------------
7758 -- Enter_Name --
7759 ----------------
7761 procedure Enter_Name (Def_Id : Entity_Id) is
7762 C : constant Entity_Id := Current_Entity (Def_Id);
7763 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7764 S : constant Entity_Id := Current_Scope;
7766 begin
7767 Generate_Definition (Def_Id);
7769 -- Add new name to current scope declarations. Check for duplicate
7770 -- declaration, which may or may not be a genuine error.
7772 if Present (E) then
7774 -- Case of previous entity entered because of a missing declaration
7775 -- or else a bad subtype indication. Best is to use the new entity,
7776 -- and make the previous one invisible.
7778 if Etype (E) = Any_Type then
7779 Set_Is_Immediately_Visible (E, False);
7781 -- Case of renaming declaration constructed for package instances.
7782 -- If there is an explicit declaration with the same identifier,
7783 -- the renaming is not immediately visible any longer, but remains
7784 -- visible through selected component notation.
7786 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7787 and then not Comes_From_Source (E)
7788 then
7789 Set_Is_Immediately_Visible (E, False);
7791 -- The new entity may be the package renaming, which has the
7792 -- same name as a generic formal which has been seen already.
7794 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7795 and then not Comes_From_Source (Def_Id)
7796 then
7797 Set_Is_Immediately_Visible (E, False);
7799 -- For a fat pointer corresponding to a remote access to subprogram,
7800 -- we use the same identifier as the RAS type, so that the proper
7801 -- name appears in the stub. This type is only retrieved through
7802 -- the RAS type and never by visibility, and is not added to the
7803 -- visibility list (see below).
7805 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7806 and then Ekind (Def_Id) = E_Record_Type
7807 and then Present (Corresponding_Remote_Type (Def_Id))
7808 then
7809 null;
7811 -- Case of an implicit operation or derived literal. The new entity
7812 -- hides the implicit one, which is removed from all visibility,
7813 -- i.e. the entity list of its scope, and homonym chain of its name.
7815 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7816 or else Is_Internal (E)
7817 then
7818 declare
7819 Decl : constant Node_Id := Parent (E);
7820 Prev : Entity_Id;
7821 Prev_Vis : Entity_Id;
7823 begin
7824 -- If E is an implicit declaration, it cannot be the first
7825 -- entity in the scope.
7827 Prev := First_Entity (Current_Scope);
7828 while Present (Prev) and then Next_Entity (Prev) /= E loop
7829 Next_Entity (Prev);
7830 end loop;
7832 if No (Prev) then
7834 -- If E is not on the entity chain of the current scope,
7835 -- it is an implicit declaration in the generic formal
7836 -- part of a generic subprogram. When analyzing the body,
7837 -- the generic formals are visible but not on the entity
7838 -- chain of the subprogram. The new entity will become
7839 -- the visible one in the body.
7841 pragma Assert
7842 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7843 null;
7845 else
7846 Link_Entities (Prev, Next_Entity (E));
7848 if No (Next_Entity (Prev)) then
7849 Set_Last_Entity (Current_Scope, Prev);
7850 end if;
7852 if E = Current_Entity (E) then
7853 Prev_Vis := Empty;
7855 else
7856 Prev_Vis := Current_Entity (E);
7857 while Homonym (Prev_Vis) /= E loop
7858 Prev_Vis := Homonym (Prev_Vis);
7859 end loop;
7860 end if;
7862 if Present (Prev_Vis) then
7864 -- Skip E in the visibility chain
7866 Set_Homonym (Prev_Vis, Homonym (E));
7868 else
7869 Set_Name_Entity_Id (Chars (E), Homonym (E));
7870 end if;
7872 -- The inherited operation cannot be retrieved
7873 -- by name, even though it may remain accesssible
7874 -- in some cases involving subprogram bodies without
7875 -- specs appearing in with_clauses..
7877 Set_Is_Immediately_Visible (E, False);
7878 end if;
7879 end;
7881 -- This section of code could use a comment ???
7883 elsif Present (Etype (E))
7884 and then Is_Concurrent_Type (Etype (E))
7885 and then E = Def_Id
7886 then
7887 return;
7889 -- If the homograph is a protected component renaming, it should not
7890 -- be hiding the current entity. Such renamings are treated as weak
7891 -- declarations.
7893 elsif Is_Prival (E) then
7894 Set_Is_Immediately_Visible (E, False);
7896 -- In this case the current entity is a protected component renaming.
7897 -- Perform minimal decoration by setting the scope and return since
7898 -- the prival should not be hiding other visible entities.
7900 elsif Is_Prival (Def_Id) then
7901 Set_Scope (Def_Id, Current_Scope);
7902 return;
7904 -- Analogous to privals, the discriminal generated for an entry index
7905 -- parameter acts as a weak declaration. Perform minimal decoration
7906 -- to avoid bogus errors.
7908 elsif Is_Discriminal (Def_Id)
7909 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7910 then
7911 Set_Scope (Def_Id, Current_Scope);
7912 return;
7914 -- In the body or private part of an instance, a type extension may
7915 -- introduce a component with the same name as that of an actual. The
7916 -- legality rule is not enforced, but the semantics of the full type
7917 -- with two components of same name are not clear at this point???
7919 elsif In_Instance_Not_Visible then
7920 null;
7922 -- When compiling a package body, some child units may have become
7923 -- visible. They cannot conflict with local entities that hide them.
7925 elsif Is_Child_Unit (E)
7926 and then In_Open_Scopes (Scope (E))
7927 and then not Is_Immediately_Visible (E)
7928 then
7929 null;
7931 -- Conversely, with front-end inlining we may compile the parent body
7932 -- first, and a child unit subsequently. The context is now the
7933 -- parent spec, and body entities are not visible.
7935 elsif Is_Child_Unit (Def_Id)
7936 and then Is_Package_Body_Entity (E)
7937 and then not In_Package_Body (Current_Scope)
7938 then
7939 null;
7941 -- Case of genuine duplicate declaration
7943 else
7944 Error_Msg_Sloc := Sloc (E);
7946 -- If the previous declaration is an incomplete type declaration
7947 -- this may be an attempt to complete it with a private type. The
7948 -- following avoids confusing cascaded errors.
7950 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7951 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7952 then
7953 Error_Msg_N
7954 ("incomplete type cannot be completed with a private " &
7955 "declaration", Parent (Def_Id));
7956 Set_Is_Immediately_Visible (E, False);
7957 Set_Full_View (E, Def_Id);
7959 -- An inherited component of a record conflicts with a new
7960 -- discriminant. The discriminant is inserted first in the scope,
7961 -- but the error should be posted on it, not on the component.
7963 elsif Ekind (E) = E_Discriminant
7964 and then Present (Scope (Def_Id))
7965 and then Scope (Def_Id) /= Current_Scope
7966 then
7967 Error_Msg_Sloc := Sloc (Def_Id);
7968 Error_Msg_N ("& conflicts with declaration#", E);
7969 return;
7971 -- If the name of the unit appears in its own context clause, a
7972 -- dummy package with the name has already been created, and the
7973 -- error emitted. Try to continue quietly.
7975 elsif Error_Posted (E)
7976 and then Sloc (E) = No_Location
7977 and then Nkind (Parent (E)) = N_Package_Specification
7978 and then Current_Scope = Standard_Standard
7979 then
7980 Set_Scope (Def_Id, Current_Scope);
7981 return;
7983 else
7984 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7986 -- Avoid cascaded messages with duplicate components in
7987 -- derived types.
7989 if Ekind (E) in E_Component | E_Discriminant then
7990 return;
7991 end if;
7992 end if;
7994 if Nkind (Parent (Parent (Def_Id))) =
7995 N_Generic_Subprogram_Declaration
7996 and then Def_Id =
7997 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7998 then
7999 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
8000 end if;
8002 -- If entity is in standard, then we are in trouble, because it
8003 -- means that we have a library package with a duplicated name.
8004 -- That's hard to recover from, so abort.
8006 if S = Standard_Standard then
8007 raise Unrecoverable_Error;
8009 -- Otherwise we continue with the declaration. Having two
8010 -- identical declarations should not cause us too much trouble.
8012 else
8013 null;
8014 end if;
8015 end if;
8016 end if;
8018 -- If we fall through, declaration is OK, at least OK enough to continue
8020 -- If Def_Id is a discriminant or a record component we are in the midst
8021 -- of inheriting components in a derived record definition. Preserve
8022 -- their Ekind and Etype.
8024 if Ekind (Def_Id) in E_Discriminant | E_Component then
8025 null;
8027 -- If a type is already set, leave it alone (happens when a type
8028 -- declaration is reanalyzed following a call to the optimizer).
8030 elsif Present (Etype (Def_Id)) then
8031 null;
8033 else
8034 Set_Etype (Def_Id, Any_Type); -- avoid cascaded errors
8035 end if;
8037 -- All entities except Itypes are immediately visible
8039 if not Is_Itype (Def_Id) then
8040 Set_Is_Immediately_Visible (Def_Id);
8041 Set_Current_Entity (Def_Id);
8042 end if;
8044 Set_Homonym (Def_Id, C);
8045 Append_Entity (Def_Id, S);
8046 Set_Public_Status (Def_Id);
8048 -- Warn if new entity hides an old one
8050 if Warn_On_Hiding and then Present (C) then
8051 Warn_On_Hiding_Entity (Def_Id, Hidden => C, Visible => Def_Id,
8052 On_Use_Clause => False);
8053 end if;
8054 end Enter_Name;
8056 ---------------
8057 -- Entity_Of --
8058 ---------------
8060 function Entity_Of (N : Node_Id) return Entity_Id is
8061 Id : Entity_Id;
8062 Ren : Node_Id;
8064 begin
8065 -- Assume that the arbitrary node does not have an entity
8067 Id := Empty;
8069 if Is_Entity_Name (N) then
8070 Id := Entity (N);
8072 -- Follow a possible chain of renamings to reach the earliest renamed
8073 -- source object.
8075 while Present (Id)
8076 and then Is_Object (Id)
8077 and then Present (Renamed_Object (Id))
8078 loop
8079 Ren := Renamed_Object (Id);
8081 -- The reference renames an abstract state or a whole object
8083 -- Obj : ...;
8084 -- Ren : ... renames Obj;
8086 if Is_Entity_Name (Ren) then
8088 -- Do not follow a renaming that goes through a generic formal,
8089 -- because these entities are hidden and must not be referenced
8090 -- from outside the generic.
8092 if Is_Hidden (Entity (Ren)) then
8093 exit;
8095 else
8096 Id := Entity (Ren);
8097 end if;
8099 -- The reference renames a function result. Check the original
8100 -- node in case expansion relocates the function call.
8102 -- Ren : ... renames Func_Call;
8104 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
8105 exit;
8107 -- Otherwise the reference renames something which does not yield
8108 -- an abstract state or a whole object. Treat the reference as not
8109 -- having a proper entity for SPARK legality purposes.
8111 else
8112 Id := Empty;
8113 exit;
8114 end if;
8115 end loop;
8116 end if;
8118 return Id;
8119 end Entity_Of;
8121 --------------------------
8122 -- Examine_Array_Bounds --
8123 --------------------------
8125 procedure Examine_Array_Bounds
8126 (Typ : Entity_Id;
8127 All_Static : out Boolean;
8128 Has_Empty : out Boolean)
8130 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
8131 -- Determine whether bound Bound is a suitable static bound
8133 ------------------------
8134 -- Is_OK_Static_Bound --
8135 ------------------------
8137 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
8138 begin
8139 return
8140 not Error_Posted (Bound)
8141 and then Is_OK_Static_Expression (Bound);
8142 end Is_OK_Static_Bound;
8144 -- Local variables
8146 Hi_Bound : Node_Id;
8147 Index : Node_Id;
8148 Lo_Bound : Node_Id;
8150 -- Start of processing for Examine_Array_Bounds
8152 begin
8153 -- An unconstrained array type does not have static bounds, and it is
8154 -- not known whether they are empty or not.
8156 if not Is_Constrained (Typ) then
8157 All_Static := False;
8158 Has_Empty := False;
8159 return;
8161 -- A string literal has static bounds, and is not empty as long as it
8162 -- contains at least one character.
8164 elsif Ekind (Typ) = E_String_Literal_Subtype then
8165 All_Static := True;
8166 Has_Empty := String_Literal_Length (Typ) = 0;
8167 return;
8168 end if;
8170 -- Assume that all bounds are static and not empty
8172 All_Static := True;
8173 Has_Empty := False;
8175 -- Examine each index
8177 Index := First_Index (Typ);
8178 while Present (Index) loop
8179 if Is_Discrete_Type (Etype (Index)) then
8180 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
8182 if Is_OK_Static_Bound (Lo_Bound)
8183 and then
8184 Is_OK_Static_Bound (Hi_Bound)
8185 then
8186 -- The static bounds produce an empty range
8188 if Is_Null_Range (Lo_Bound, Hi_Bound) then
8189 Has_Empty := True;
8190 end if;
8192 -- Otherwise at least one of the bounds is not static
8194 else
8195 All_Static := False;
8196 end if;
8198 -- Otherwise the index is non-discrete, therefore not static
8200 else
8201 All_Static := False;
8202 end if;
8204 Next_Index (Index);
8205 end loop;
8206 end Examine_Array_Bounds;
8208 -------------------
8209 -- Exceptions_OK --
8210 -------------------
8212 function Exceptions_OK return Boolean is
8213 begin
8214 return
8215 not (Restriction_Active (No_Exception_Handlers) or else
8216 Restriction_Active (No_Exception_Propagation) or else
8217 Restriction_Active (No_Exceptions));
8218 end Exceptions_OK;
8220 --------------------------
8221 -- Explain_Limited_Type --
8222 --------------------------
8224 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
8225 C : Entity_Id;
8227 begin
8228 -- For array, component type must be limited
8230 if Is_Array_Type (T) then
8231 Error_Msg_Node_2 := T;
8232 Error_Msg_NE
8233 ("\component type& of type& is limited", N, Component_Type (T));
8234 Explain_Limited_Type (Component_Type (T), N);
8236 elsif Is_Record_Type (T) then
8238 -- No need for extra messages if explicit limited record
8240 if Is_Limited_Record (Base_Type (T)) then
8241 return;
8242 end if;
8244 -- Otherwise find a limited component. Check only components that
8245 -- come from source, or inherited components that appear in the
8246 -- source of the ancestor.
8248 C := First_Component (T);
8249 while Present (C) loop
8250 if Is_Limited_Type (Etype (C))
8251 and then
8252 (Comes_From_Source (C)
8253 or else
8254 (Present (Original_Record_Component (C))
8255 and then
8256 Comes_From_Source (Original_Record_Component (C))))
8257 then
8258 Error_Msg_Node_2 := T;
8259 Error_Msg_NE ("\component& of type& has limited type", N, C);
8260 Explain_Limited_Type (Etype (C), N);
8261 return;
8262 end if;
8264 Next_Component (C);
8265 end loop;
8267 -- The type may be declared explicitly limited, even if no component
8268 -- of it is limited, in which case we fall out of the loop.
8269 return;
8270 end if;
8271 end Explain_Limited_Type;
8273 ---------------------------------------
8274 -- Expression_Of_Expression_Function --
8275 ---------------------------------------
8277 function Expression_Of_Expression_Function
8278 (Subp : Entity_Id) return Node_Id
8280 Expr_Func : Node_Id := Empty;
8282 begin
8283 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
8285 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
8286 N_Expression_Function
8287 then
8288 Expr_Func := Original_Node (Subprogram_Spec (Subp));
8290 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
8291 N_Expression_Function
8292 then
8293 Expr_Func := Original_Node (Subprogram_Body (Subp));
8295 else
8296 pragma Assert (False);
8297 null;
8298 end if;
8300 return Original_Node (Expression (Expr_Func));
8301 end Expression_Of_Expression_Function;
8303 -------------------------------
8304 -- Extensions_Visible_Status --
8305 -------------------------------
8307 function Extensions_Visible_Status
8308 (Id : Entity_Id) return Extensions_Visible_Mode
8310 Arg : Node_Id;
8311 Decl : Node_Id;
8312 Expr : Node_Id;
8313 Prag : Node_Id;
8314 Subp : Entity_Id;
8316 begin
8317 -- When a formal parameter is subject to Extensions_Visible, the pragma
8318 -- is stored in the contract of related subprogram.
8320 if Is_Formal (Id) then
8321 Subp := Scope (Id);
8323 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
8324 Subp := Id;
8326 -- No other construct carries this pragma
8328 else
8329 return Extensions_Visible_None;
8330 end if;
8332 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
8334 -- In certain cases analysis may request the Extensions_Visible status
8335 -- of an expression function before the pragma has been analyzed yet.
8336 -- Inspect the declarative items after the expression function looking
8337 -- for the pragma (if any).
8339 if No (Prag) and then Is_Expression_Function (Subp) then
8340 Decl := Next (Unit_Declaration_Node (Subp));
8341 while Present (Decl) loop
8342 if Nkind (Decl) = N_Pragma
8343 and then Pragma_Name (Decl) = Name_Extensions_Visible
8344 then
8345 Prag := Decl;
8346 exit;
8348 -- A source construct ends the region where Extensions_Visible may
8349 -- appear, stop the traversal. An expanded expression function is
8350 -- no longer a source construct, but it must still be recognized.
8352 elsif Comes_From_Source (Decl)
8353 or else
8354 (Nkind (Decl) in N_Subprogram_Body | N_Subprogram_Declaration
8355 and then Is_Expression_Function (Defining_Entity (Decl)))
8356 then
8357 exit;
8358 end if;
8360 Next (Decl);
8361 end loop;
8362 end if;
8364 -- Extract the value from the Boolean expression (if any)
8366 if Present (Prag) then
8367 Arg := First (Pragma_Argument_Associations (Prag));
8369 if Present (Arg) then
8370 Expr := Get_Pragma_Arg (Arg);
8372 -- When the associated subprogram is an expression function, the
8373 -- argument of the pragma may not have been analyzed.
8375 if not Analyzed (Expr) then
8376 Preanalyze_And_Resolve (Expr, Standard_Boolean);
8377 end if;
8379 -- Guard against cascading errors when the argument of pragma
8380 -- Extensions_Visible is not a valid static Boolean expression.
8382 if Error_Posted (Expr) then
8383 return Extensions_Visible_None;
8385 elsif Is_True (Expr_Value (Expr)) then
8386 return Extensions_Visible_True;
8388 else
8389 return Extensions_Visible_False;
8390 end if;
8392 -- Otherwise the aspect or pragma defaults to True
8394 else
8395 return Extensions_Visible_True;
8396 end if;
8398 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
8399 -- directly specified. In SPARK code, its value defaults to "False".
8401 elsif SPARK_Mode = On then
8402 return Extensions_Visible_False;
8404 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
8405 -- "True".
8407 else
8408 return Extensions_Visible_True;
8409 end if;
8410 end Extensions_Visible_Status;
8412 -----------------
8413 -- Find_Actual --
8414 -----------------
8416 procedure Find_Actual
8417 (N : Node_Id;
8418 Formal : out Entity_Id;
8419 Call : out Node_Id)
8421 Context : constant Node_Id := Parent (N);
8422 Actual : Node_Id;
8423 Call_Nam : Node_Id;
8424 Call_Ent : Node_Id := Empty;
8426 begin
8427 if Nkind (Context) in N_Indexed_Component | N_Selected_Component
8428 and then N = Prefix (Context)
8429 then
8430 Find_Actual (Context, Formal, Call);
8431 return;
8433 elsif Nkind (Context) = N_Parameter_Association
8434 and then N = Explicit_Actual_Parameter (Context)
8435 then
8436 Call := Parent (Context);
8438 elsif Nkind (Context) in N_Entry_Call_Statement
8439 | N_Function_Call
8440 | N_Procedure_Call_Statement
8441 then
8442 Call := Context;
8444 else
8445 Formal := Empty;
8446 Call := Empty;
8447 return;
8448 end if;
8450 -- If we have a call to a subprogram look for the parameter. Note that
8451 -- we exclude overloaded calls, since we don't know enough to be sure
8452 -- of giving the right answer in this case.
8454 if Nkind (Call) in N_Entry_Call_Statement
8455 | N_Function_Call
8456 | N_Procedure_Call_Statement
8457 then
8458 Call_Nam := Name (Call);
8460 -- A call to an entry family may appear as an indexed component
8462 if Nkind (Call_Nam) = N_Indexed_Component then
8463 Call_Nam := Prefix (Call_Nam);
8464 end if;
8466 -- A call to a protected or task entry appears as a selected
8467 -- component rather than an expanded name.
8469 if Nkind (Call_Nam) = N_Selected_Component then
8470 Call_Nam := Selector_Name (Call_Nam);
8471 end if;
8473 -- If Call_Nam is an entity name, get its entity
8475 if Is_Entity_Name (Call_Nam) then
8476 Call_Ent := Entity (Call_Nam);
8478 -- If it is a dereference, get the designated subprogram type
8480 elsif Nkind (Call_Nam) = N_Explicit_Dereference then
8481 declare
8482 Typ : Entity_Id := Etype (Prefix (Call_Nam));
8483 begin
8484 if Present (Full_View (Typ)) then
8485 Typ := Full_View (Typ);
8486 elsif Is_Private_Type (Typ)
8487 and then Present (Underlying_Full_View (Typ))
8488 then
8489 Typ := Underlying_Full_View (Typ);
8490 end if;
8492 if Is_Access_Type (Typ) then
8493 Call_Ent := Directly_Designated_Type (Typ);
8494 else
8495 pragma Assert (Has_Implicit_Dereference (Typ));
8496 Formal := Empty;
8497 Call := Empty;
8498 return;
8499 end if;
8500 end;
8501 end if;
8503 if Present (Call_Ent)
8504 and then (Is_Generic_Subprogram (Call_Ent)
8505 or else Is_Overloadable (Call_Ent)
8506 or else Ekind (Call_Ent) in E_Entry_Family
8507 | E_Subprogram_Body
8508 | E_Subprogram_Type)
8509 and then not Is_Overloaded (Call_Nam)
8510 then
8511 -- If node is name in call it is not an actual
8513 if N = Call_Nam then
8514 Formal := Empty;
8515 Call := Empty;
8516 return;
8517 end if;
8519 -- Fall here if we are definitely a parameter
8521 Actual := First_Actual (Call);
8522 Formal := First_Formal (Call_Ent);
8523 while Present (Formal) and then Present (Actual) loop
8524 if Actual = N then
8525 return;
8527 -- An actual that is the prefix in a prefixed call may have
8528 -- been rewritten in the call. Check if sloc and kinds and
8529 -- names match.
8531 elsif Sloc (Actual) = Sloc (N)
8532 and then Nkind (Actual) = N_Identifier
8533 and then Nkind (Actual) = Nkind (N)
8534 and then Chars (Actual) = Chars (N)
8535 then
8536 return;
8538 else
8539 Next_Actual (Actual);
8540 Next_Formal (Formal);
8541 end if;
8542 end loop;
8543 end if;
8544 end if;
8546 -- Fall through here if we did not find matching actual
8548 Formal := Empty;
8549 Call := Empty;
8550 end Find_Actual;
8552 ---------------------------
8553 -- Find_Body_Discriminal --
8554 ---------------------------
8556 function Find_Body_Discriminal
8557 (Spec_Discriminant : Entity_Id) return Entity_Id
8559 Tsk : Entity_Id;
8560 Disc : Entity_Id;
8562 begin
8563 -- If expansion is suppressed, then the scope can be the concurrent type
8564 -- itself rather than a corresponding concurrent record type.
8566 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
8567 Tsk := Scope (Spec_Discriminant);
8569 else
8570 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
8572 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
8573 end if;
8575 -- Find discriminant of original concurrent type, and use its current
8576 -- discriminal, which is the renaming within the task/protected body.
8578 Disc := First_Discriminant (Tsk);
8579 while Present (Disc) loop
8580 if Chars (Disc) = Chars (Spec_Discriminant) then
8581 return Discriminal (Disc);
8582 end if;
8584 Next_Discriminant (Disc);
8585 end loop;
8587 -- That loop should always succeed in finding a matching entry and
8588 -- returning. Fatal error if not.
8590 raise Program_Error;
8591 end Find_Body_Discriminal;
8593 -------------------------------------
8594 -- Find_Corresponding_Discriminant --
8595 -------------------------------------
8597 function Find_Corresponding_Discriminant
8598 (Id : Node_Id;
8599 Typ : Entity_Id) return Entity_Id
8601 Par_Disc : Entity_Id;
8602 Old_Disc : Entity_Id;
8603 New_Disc : Entity_Id;
8605 begin
8606 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
8608 -- The original type may currently be private, and the discriminant
8609 -- only appear on its full view.
8611 if Is_Private_Type (Scope (Par_Disc))
8612 and then not Has_Discriminants (Scope (Par_Disc))
8613 and then Present (Full_View (Scope (Par_Disc)))
8614 then
8615 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
8616 else
8617 Old_Disc := First_Discriminant (Scope (Par_Disc));
8618 end if;
8620 if Is_Class_Wide_Type (Typ) then
8621 New_Disc := First_Discriminant (Root_Type (Typ));
8622 else
8623 New_Disc := First_Discriminant (Typ);
8624 end if;
8626 while Present (Old_Disc) and then Present (New_Disc) loop
8627 if Old_Disc = Par_Disc then
8628 return New_Disc;
8629 end if;
8631 Next_Discriminant (Old_Disc);
8632 Next_Discriminant (New_Disc);
8633 end loop;
8635 -- Should always find it
8637 raise Program_Error;
8638 end Find_Corresponding_Discriminant;
8640 -------------------
8641 -- Find_DIC_Type --
8642 -------------------
8644 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
8645 Curr_Typ : Entity_Id;
8646 -- The current type being examined in the parent hierarchy traversal
8648 DIC_Typ : Entity_Id;
8649 -- The type which carries the DIC pragma. This variable denotes the
8650 -- partial view when private types are involved.
8652 Par_Typ : Entity_Id;
8653 -- The parent type of the current type. This variable denotes the full
8654 -- view when private types are involved.
8656 begin
8657 -- The input type defines its own DIC pragma, therefore it is the owner
8659 if Has_Own_DIC (Typ) then
8660 DIC_Typ := Typ;
8662 -- Otherwise the DIC pragma is inherited from a parent type
8664 else
8665 pragma Assert (Has_Inherited_DIC (Typ));
8667 -- Climb the parent chain
8669 Curr_Typ := Typ;
8670 loop
8671 -- Inspect the parent type. Do not consider subtypes as they
8672 -- inherit the DIC attributes from their base types.
8674 DIC_Typ := Base_Type (Etype (Curr_Typ));
8676 -- Look at the full view of a private type because the type may
8677 -- have a hidden parent introduced in the full view.
8679 Par_Typ := DIC_Typ;
8681 if Is_Private_Type (Par_Typ)
8682 and then Present (Full_View (Par_Typ))
8683 then
8684 Par_Typ := Full_View (Par_Typ);
8685 end if;
8687 -- Stop the climb once the nearest parent type which defines a DIC
8688 -- pragma of its own is encountered or when the root of the parent
8689 -- chain is reached.
8691 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8693 Curr_Typ := Par_Typ;
8694 end loop;
8695 end if;
8697 return DIC_Typ;
8698 end Find_DIC_Type;
8700 ----------------------------------
8701 -- Find_Enclosing_Iterator_Loop --
8702 ----------------------------------
8704 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8705 Constr : Node_Id;
8706 S : Entity_Id;
8708 begin
8709 -- Traverse the scope chain looking for an iterator loop. Such loops are
8710 -- usually transformed into blocks, hence the use of Original_Node.
8712 S := Id;
8713 while Present (S) and then S /= Standard_Standard loop
8714 if Ekind (S) = E_Loop
8715 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8716 then
8717 Constr := Original_Node (Label_Construct (Parent (S)));
8719 if Nkind (Constr) = N_Loop_Statement
8720 and then Present (Iteration_Scheme (Constr))
8721 and then Nkind (Iterator_Specification
8722 (Iteration_Scheme (Constr))) =
8723 N_Iterator_Specification
8724 then
8725 return S;
8726 end if;
8727 end if;
8729 S := Scope (S);
8730 end loop;
8732 return Empty;
8733 end Find_Enclosing_Iterator_Loop;
8735 --------------------------
8736 -- Find_Enclosing_Scope --
8737 --------------------------
8739 function Find_Enclosing_Scope (N : Node_Id) return Scope_Kind_Id is
8740 Par : Node_Id;
8742 begin
8743 -- If N is an entity, simply return its Scope
8745 if Nkind (N) in N_Entity then
8746 return Scope (N);
8747 end if;
8749 -- Examine the parent chain looking for a construct which defines a
8750 -- scope.
8752 Par := Parent (N);
8753 while Present (Par) loop
8754 case Nkind (Par) is
8756 -- The construct denotes a declaration, the proper scope is its
8757 -- entity.
8759 when N_Entry_Declaration
8760 | N_Expression_Function
8761 | N_Full_Type_Declaration
8762 | N_Generic_Package_Declaration
8763 | N_Generic_Subprogram_Declaration
8764 | N_Package_Declaration
8765 | N_Private_Extension_Declaration
8766 | N_Protected_Type_Declaration
8767 | N_Single_Protected_Declaration
8768 | N_Single_Task_Declaration
8769 | N_Subprogram_Declaration
8770 | N_Task_Type_Declaration
8772 return Defining_Entity (Par);
8774 -- The construct denotes a body, the proper scope is the entity of
8775 -- the corresponding spec or that of the body if the body does not
8776 -- complete a previous declaration.
8778 when N_Entry_Body
8779 | N_Package_Body
8780 | N_Protected_Body
8781 | N_Subprogram_Body
8782 | N_Task_Body
8784 return Unique_Defining_Entity (Par);
8786 -- Special cases
8788 -- Blocks carry either a source or an internally-generated scope,
8789 -- unless the block is a byproduct of exception handling.
8791 when N_Block_Statement =>
8792 if not Exception_Junk (Par) then
8793 return Entity (Identifier (Par));
8794 end if;
8796 -- Loops carry an internally-generated scope
8798 when N_Loop_Statement =>
8799 return Entity (Identifier (Par));
8801 -- Extended return statements carry an internally-generated scope
8803 when N_Extended_Return_Statement =>
8804 return Return_Statement_Entity (Par);
8806 -- A traversal from a subunit continues via the corresponding stub
8808 when N_Subunit =>
8809 Par := Corresponding_Stub (Par);
8811 when others =>
8812 null;
8813 end case;
8815 Par := Parent (Par);
8816 end loop;
8818 return Standard_Standard;
8819 end Find_Enclosing_Scope;
8821 ------------------------------------
8822 -- Find_Loop_In_Conditional_Block --
8823 ------------------------------------
8825 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8826 Stmt : Node_Id;
8828 begin
8829 Stmt := N;
8831 if Nkind (Stmt) = N_If_Statement then
8832 Stmt := First (Then_Statements (Stmt));
8833 end if;
8835 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8837 -- Inspect the statements of the conditional block. In general the loop
8838 -- should be the first statement in the statement sequence of the block,
8839 -- but the finalization machinery may have introduced extra object
8840 -- declarations.
8842 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8843 while Present (Stmt) loop
8844 if Nkind (Stmt) = N_Loop_Statement then
8845 return Stmt;
8846 end if;
8848 Next (Stmt);
8849 end loop;
8851 -- The expansion of attribute 'Loop_Entry produced a malformed block
8853 raise Program_Error;
8854 end Find_Loop_In_Conditional_Block;
8856 --------------------------
8857 -- Find_Overlaid_Entity --
8858 --------------------------
8860 procedure Find_Overlaid_Entity
8861 (N : Node_Id;
8862 Ent : out Entity_Id;
8863 Off : out Boolean)
8865 pragma Assert
8866 (Nkind (N) = N_Attribute_Definition_Clause
8867 and then Chars (N) = Name_Address);
8869 Expr : Node_Id;
8871 begin
8872 -- We are looking for one of the two following forms:
8874 -- for X'Address use Y'Address
8876 -- or
8878 -- Const : constant Address := expr;
8879 -- ...
8880 -- for X'Address use Const;
8882 -- In the second case, the expr is either Y'Address, or recursively a
8883 -- constant that eventually references Y'Address.
8885 Ent := Empty;
8886 Off := False;
8888 Expr := Expression (N);
8890 -- This loop checks the form of the expression for Y'Address, using
8891 -- recursion to deal with intermediate constants.
8893 loop
8894 -- Check for Y'Address
8896 if Nkind (Expr) = N_Attribute_Reference
8897 and then Attribute_Name (Expr) = Name_Address
8898 then
8899 Expr := Prefix (Expr);
8900 exit;
8902 -- Check for Const where Const is a constant entity
8904 elsif Is_Entity_Name (Expr)
8905 and then Ekind (Entity (Expr)) = E_Constant
8906 then
8907 Expr := Constant_Value (Entity (Expr));
8909 -- Anything else does not need checking
8911 else
8912 return;
8913 end if;
8914 end loop;
8916 -- This loop checks the form of the prefix for an entity, using
8917 -- recursion to deal with intermediate components.
8919 loop
8920 -- Check for Y where Y is an entity
8922 if Is_Entity_Name (Expr) then
8923 Ent := Entity (Expr);
8925 -- If expansion is disabled, then we might see an entity of a
8926 -- protected component or of a discriminant of a concurrent unit.
8927 -- Ignore such entities, because further warnings for overlays
8928 -- expect this routine to only collect entities of entire objects.
8930 if Ekind (Ent) in E_Component | E_Discriminant then
8931 pragma Assert
8932 (not Expander_Active
8933 and then Is_Concurrent_Type (Scope (Ent)));
8934 Ent := Empty;
8935 end if;
8936 return;
8938 -- Check for components
8940 elsif Nkind (Expr) in N_Selected_Component | N_Indexed_Component then
8941 Expr := Prefix (Expr);
8942 Off := True;
8944 -- Anything else does not need checking
8946 else
8947 return;
8948 end if;
8949 end loop;
8950 end Find_Overlaid_Entity;
8952 -------------------------
8953 -- Find_Parameter_Type --
8954 -------------------------
8956 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8957 begin
8958 if Nkind (Param) /= N_Parameter_Specification then
8959 return Empty;
8961 -- For an access parameter, obtain the type from the formal entity
8962 -- itself, because access to subprogram nodes do not carry a type.
8963 -- Shouldn't we always use the formal entity ???
8965 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8966 return Etype (Defining_Identifier (Param));
8968 else
8969 return Etype (Parameter_Type (Param));
8970 end if;
8971 end Find_Parameter_Type;
8973 -----------------------------------
8974 -- Find_Placement_In_State_Space --
8975 -----------------------------------
8977 procedure Find_Placement_In_State_Space
8978 (Item_Id : Entity_Id;
8979 Placement : out State_Space_Kind;
8980 Pack_Id : out Entity_Id)
8982 function Inside_Package_Body (Id : Entity_Id) return Boolean;
8983 function Inside_Private_Part (Id : Entity_Id) return Boolean;
8984 -- Return True if Id is declared directly within the package body
8985 -- and the package private parts, respectively. We cannot use
8986 -- In_Private_Part/In_Body_Part flags, as these are only set during the
8987 -- analysis of the package itself, while Find_Placement_In_State_Space
8988 -- can be called on an entity of another package.
8990 ------------------------
8991 -- Inside_Package_Body --
8992 ------------------------
8994 function Inside_Package_Body (Id : Entity_Id) return Boolean is
8995 Spec_Id : constant Entity_Id := Scope (Id);
8996 Body_Decl : constant Opt_N_Package_Body_Id := Package_Body (Spec_Id);
8997 Decl : constant Node_Id := Enclosing_Declaration (Id);
8998 begin
8999 if Present (Body_Decl)
9000 and then Is_List_Member (Decl)
9001 and then List_Containing (Decl) = Declarations (Body_Decl)
9002 then
9003 return True;
9004 else
9005 return False;
9006 end if;
9007 end Inside_Package_Body;
9009 -------------------------
9010 -- Inside_Private_Part --
9011 -------------------------
9013 function Inside_Private_Part (Id : Entity_Id) return Boolean is
9014 Spec_Id : constant Entity_Id := Scope (Id);
9015 Private_Decls : constant List_Id :=
9016 Private_Declarations (Package_Specification (Spec_Id));
9017 Decl : constant Node_Id := Enclosing_Declaration (Id);
9018 begin
9019 if Is_List_Member (Decl)
9020 and then List_Containing (Decl) = Private_Decls
9021 then
9022 return True;
9024 elsif Ekind (Id) = E_Package
9025 and then Is_Private_Library_Unit (Id)
9026 then
9027 return True;
9029 else
9030 return False;
9031 end if;
9032 end Inside_Private_Part;
9034 -- Local variables
9036 Context : Entity_Id;
9038 -- Start of processing for Find_Placement_In_State_Space
9040 begin
9041 -- Assume that the item does not appear in the state space of a package
9043 Placement := Not_In_Package;
9045 -- Climb the scope stack and examine the enclosing context
9047 Context := Item_Id;
9048 Pack_Id := Scope (Context);
9049 while Present (Pack_Id) and then Pack_Id /= Standard_Standard loop
9050 if Is_Package_Or_Generic_Package (Pack_Id) then
9052 -- A package body is a cut off point for the traversal as the
9053 -- item cannot be visible to the outside from this point on.
9055 if Inside_Package_Body (Context) then
9056 Placement := Body_State_Space;
9057 return;
9059 -- The private part of a package is a cut off point for the
9060 -- traversal as the item cannot be visible to the outside
9061 -- from this point on.
9063 elsif Inside_Private_Part (Context) then
9064 Placement := Private_State_Space;
9065 return;
9067 -- The item or its enclosing package appear in the visible state
9068 -- space of a generic package.
9070 elsif Ekind (Pack_Id) = E_Generic_Package then
9071 Placement := Not_In_Package;
9072 Pack_Id := Empty;
9073 return;
9075 -- When the item appears in the visible state space of a package,
9076 -- continue to climb the scope stack as this may not be the final
9077 -- state space.
9079 else
9080 Placement := Visible_State_Space;
9082 -- The visible state space of a child unit acts as the proper
9083 -- placement of an item, unless this is a private child unit.
9085 if Is_Child_Unit (Pack_Id)
9086 and then not Is_Private_Library_Unit (Pack_Id)
9087 then
9088 return;
9089 end if;
9090 end if;
9092 -- The item or its enclosing package appear in a construct that has
9093 -- no state space.
9095 else
9096 Placement := Not_In_Package;
9097 Pack_Id := Empty;
9098 return;
9099 end if;
9101 Context := Scope (Context);
9102 Pack_Id := Scope (Context);
9103 end loop;
9104 end Find_Placement_In_State_Space;
9106 -----------------------
9107 -- Find_Primitive_Eq --
9108 -----------------------
9110 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
9111 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
9112 -- Search for the equality primitive; return Empty if the primitive is
9113 -- not found.
9115 ------------------
9116 -- Find_Eq_Prim --
9117 ------------------
9119 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
9120 Prim : Entity_Id;
9121 Prim_Elmt : Elmt_Id;
9123 begin
9124 Prim_Elmt := First_Elmt (Prims_List);
9125 while Present (Prim_Elmt) loop
9126 Prim := Node (Prim_Elmt);
9128 -- Locate primitive equality with the right signature
9130 if Chars (Prim) = Name_Op_Eq
9131 and then Etype (First_Formal (Prim)) =
9132 Etype (Next_Formal (First_Formal (Prim)))
9133 and then Base_Type (Etype (Prim)) = Standard_Boolean
9134 then
9135 return Prim;
9136 end if;
9138 Next_Elmt (Prim_Elmt);
9139 end loop;
9141 return Empty;
9142 end Find_Eq_Prim;
9144 -- Local Variables
9146 Eq_Prim : Entity_Id;
9147 Full_Type : Entity_Id;
9149 -- Start of processing for Find_Primitive_Eq
9151 begin
9152 if Is_Private_Type (Typ) then
9153 Full_Type := Underlying_Type (Typ);
9154 else
9155 Full_Type := Typ;
9156 end if;
9158 if No (Full_Type) then
9159 return Empty;
9160 end if;
9162 Full_Type := Base_Type (Full_Type);
9164 -- When the base type itself is private, use the full view
9166 if Is_Private_Type (Full_Type) then
9167 Full_Type := Underlying_Type (Full_Type);
9168 end if;
9170 if Is_Class_Wide_Type (Full_Type) then
9171 Full_Type := Root_Type (Full_Type);
9172 end if;
9174 if not Is_Tagged_Type (Full_Type) then
9175 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
9177 -- If this is an untagged private type completed with a derivation of
9178 -- an untagged private type whose full view is a tagged type, we use
9179 -- the primitive operations of the private parent type (since it does
9180 -- not have a full view, and also because its equality primitive may
9181 -- have been overridden in its untagged full view). If no equality was
9182 -- defined for it then take its dispatching equality primitive.
9184 elsif Inherits_From_Tagged_Full_View (Typ) then
9185 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
9187 if No (Eq_Prim) then
9188 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
9189 end if;
9191 else
9192 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
9193 end if;
9195 return Eq_Prim;
9196 end Find_Primitive_Eq;
9198 ------------------------
9199 -- Find_Specific_Type --
9200 ------------------------
9202 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
9203 Typ : Entity_Id := Root_Type (CW);
9205 begin
9206 if Ekind (Typ) = E_Incomplete_Type then
9207 if From_Limited_With (Typ) then
9208 Typ := Non_Limited_View (Typ);
9209 else
9210 Typ := Full_View (Typ);
9211 end if;
9212 end if;
9214 if Is_Private_Type (Typ)
9215 and then not Is_Tagged_Type (Typ)
9216 and then Present (Full_View (Typ))
9217 then
9218 return Full_View (Typ);
9219 else
9220 return Typ;
9221 end if;
9222 end Find_Specific_Type;
9224 -----------------------------
9225 -- Find_Static_Alternative --
9226 -----------------------------
9228 function Find_Static_Alternative (N : Node_Id) return Node_Id is
9229 Expr : constant Node_Id := Expression (N);
9230 Val : constant Uint := Expr_Value (Expr);
9231 Alt : Node_Id;
9232 Choice : Node_Id;
9234 begin
9235 Alt := First (Alternatives (N));
9237 Search : loop
9238 if Nkind (Alt) /= N_Pragma then
9239 Choice := First (Discrete_Choices (Alt));
9240 while Present (Choice) loop
9242 -- Others choice, always matches
9244 if Nkind (Choice) = N_Others_Choice then
9245 exit Search;
9247 -- Range, check if value is in the range
9249 elsif Nkind (Choice) = N_Range then
9250 exit Search when
9251 Val >= Expr_Value (Low_Bound (Choice))
9252 and then
9253 Val <= Expr_Value (High_Bound (Choice));
9255 -- Choice is a subtype name. Note that we know it must
9256 -- be a static subtype, since otherwise it would have
9257 -- been diagnosed as illegal.
9259 elsif Is_Entity_Name (Choice)
9260 and then Is_Type (Entity (Choice))
9261 then
9262 exit Search when Is_In_Range (Expr, Etype (Choice),
9263 Assume_Valid => False);
9265 -- Choice is a subtype indication
9267 elsif Nkind (Choice) = N_Subtype_Indication then
9268 declare
9269 C : constant Node_Id := Constraint (Choice);
9270 R : constant Node_Id := Range_Expression (C);
9272 begin
9273 exit Search when
9274 Val >= Expr_Value (Low_Bound (R))
9275 and then
9276 Val <= Expr_Value (High_Bound (R));
9277 end;
9279 -- Choice is a simple expression
9281 else
9282 exit Search when Val = Expr_Value (Choice);
9283 end if;
9285 Next (Choice);
9286 end loop;
9287 end if;
9289 Next (Alt);
9290 pragma Assert (Present (Alt));
9291 end loop Search;
9293 -- The above loop *must* terminate by finding a match, since we know the
9294 -- case statement is valid, and the value of the expression is known at
9295 -- compile time. When we fall out of the loop, Alt points to the
9296 -- alternative that we know will be selected at run time.
9298 return Alt;
9299 end Find_Static_Alternative;
9301 ------------------
9302 -- First_Actual --
9303 ------------------
9305 function First_Actual (Node : Node_Id) return Node_Id is
9306 N : Node_Id;
9308 begin
9309 if No (Parameter_Associations (Node)) then
9310 return Empty;
9311 end if;
9313 N := First (Parameter_Associations (Node));
9315 if Nkind (N) = N_Parameter_Association then
9316 return First_Named_Actual (Node);
9317 else
9318 return N;
9319 end if;
9320 end First_Actual;
9322 ------------------
9323 -- First_Global --
9324 ------------------
9326 function First_Global
9327 (Subp : Entity_Id;
9328 Global_Mode : Name_Id;
9329 Refined : Boolean := False) return Node_Id
9331 function First_From_Global_List
9332 (List : Node_Id;
9333 Global_Mode : Name_Id := Name_Input) return Entity_Id;
9334 -- Get the first item with suitable mode from List
9336 ----------------------------
9337 -- First_From_Global_List --
9338 ----------------------------
9340 function First_From_Global_List
9341 (List : Node_Id;
9342 Global_Mode : Name_Id := Name_Input) return Entity_Id
9344 Assoc : Node_Id;
9346 begin
9347 -- Empty list (no global items)
9349 if Nkind (List) = N_Null then
9350 return Empty;
9352 -- Single global item declaration (only input items)
9354 elsif Nkind (List) in N_Expanded_Name | N_Identifier then
9355 if Global_Mode = Name_Input then
9356 return List;
9357 else
9358 return Empty;
9359 end if;
9361 -- Simple global list (only input items) or moded global list
9362 -- declaration.
9364 elsif Nkind (List) = N_Aggregate then
9365 if Present (Expressions (List)) then
9366 if Global_Mode = Name_Input then
9367 return First (Expressions (List));
9368 else
9369 return Empty;
9370 end if;
9372 else
9373 Assoc := First (Component_Associations (List));
9374 while Present (Assoc) loop
9376 -- When we find the desired mode in an association, call
9377 -- recursively First_From_Global_List as if the mode was
9378 -- Name_Input, in order to reuse the existing machinery
9379 -- for the other cases.
9381 if Chars (First (Choices (Assoc))) = Global_Mode then
9382 return First_From_Global_List (Expression (Assoc));
9383 end if;
9385 Next (Assoc);
9386 end loop;
9388 return Empty;
9389 end if;
9391 -- To accommodate partial decoration of disabled SPARK features,
9392 -- this routine may be called with illegal input. If this is the
9393 -- case, do not raise Program_Error.
9395 else
9396 return Empty;
9397 end if;
9398 end First_From_Global_List;
9400 -- Local variables
9402 Global : Node_Id := Empty;
9403 Body_Id : Entity_Id;
9405 -- Start of processing for First_Global
9407 begin
9408 pragma Assert (Global_Mode in Name_In_Out
9409 | Name_Input
9410 | Name_Output
9411 | Name_Proof_In);
9413 -- Retrieve the suitable pragma Global or Refined_Global. In the second
9414 -- case, it can only be located on the body entity.
9416 if Refined then
9417 if Is_Subprogram_Or_Generic_Subprogram (Subp) then
9418 Body_Id := Subprogram_Body_Entity (Subp);
9420 elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then
9421 Body_Id := Corresponding_Body (Parent (Subp));
9423 -- ??? It should be possible to retrieve the Refined_Global on the
9424 -- task body associated to the task object. This is not yet possible.
9426 elsif Is_Single_Task_Object (Subp) then
9427 Body_Id := Empty;
9429 else
9430 Body_Id := Empty;
9431 end if;
9433 if Present (Body_Id) then
9434 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
9435 end if;
9436 else
9437 Global := Get_Pragma (Subp, Pragma_Global);
9438 end if;
9440 -- No corresponding global if pragma is not present
9442 if No (Global) then
9443 return Empty;
9445 -- Otherwise retrieve the corresponding list of items depending on the
9446 -- Global_Mode.
9448 else
9449 return First_From_Global_List
9450 (Expression (Get_Argument (Global, Subp)), Global_Mode);
9451 end if;
9452 end First_Global;
9454 -------------
9455 -- Fix_Msg --
9456 -------------
9458 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
9459 Is_Task : constant Boolean :=
9460 Ekind (Id) in E_Task_Body | E_Task_Type
9461 or else Is_Single_Task_Object (Id);
9462 Msg_Last : constant Natural := Msg'Last;
9463 Msg_Index : Natural;
9464 Res : String (Msg'Range) := (others => ' ');
9465 Res_Index : Natural;
9467 begin
9468 -- Copy all characters from the input message Msg to result Res with
9469 -- suitable replacements.
9471 Msg_Index := Msg'First;
9472 Res_Index := Res'First;
9473 while Msg_Index <= Msg_Last loop
9475 -- Replace "subprogram" with a different word
9477 if Msg_Index <= Msg_Last - 10
9478 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
9479 then
9480 if Is_Entry (Id) then
9481 Res (Res_Index .. Res_Index + 4) := "entry";
9482 Res_Index := Res_Index + 5;
9484 elsif Is_Task then
9485 Res (Res_Index .. Res_Index + 8) := "task type";
9486 Res_Index := Res_Index + 9;
9488 else
9489 Res (Res_Index .. Res_Index + 9) := "subprogram";
9490 Res_Index := Res_Index + 10;
9491 end if;
9493 Msg_Index := Msg_Index + 10;
9495 -- Replace "protected" with a different word
9497 elsif Msg_Index <= Msg_Last - 9
9498 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
9499 and then Is_Task
9500 then
9501 Res (Res_Index .. Res_Index + 3) := "task";
9502 Res_Index := Res_Index + 4;
9503 Msg_Index := Msg_Index + 9;
9505 -- Otherwise copy the character
9507 else
9508 Res (Res_Index) := Msg (Msg_Index);
9509 Msg_Index := Msg_Index + 1;
9510 Res_Index := Res_Index + 1;
9511 end if;
9512 end loop;
9514 return Res (Res'First .. Res_Index - 1);
9515 end Fix_Msg;
9517 -------------------------
9518 -- From_Nested_Package --
9519 -------------------------
9521 function From_Nested_Package (T : Entity_Id) return Boolean is
9522 Pack : constant Entity_Id := Scope (T);
9524 begin
9525 return
9526 Ekind (Pack) = E_Package
9527 and then not Is_Frozen (Pack)
9528 and then not Scope_Within_Or_Same (Current_Scope, Pack)
9529 and then In_Open_Scopes (Scope (Pack));
9530 end From_Nested_Package;
9532 -----------------------
9533 -- Gather_Components --
9534 -----------------------
9536 procedure Gather_Components
9537 (Typ : Entity_Id;
9538 Comp_List : Node_Id;
9539 Governed_By : List_Id;
9540 Into : Elist_Id;
9541 Report_Errors : out Boolean;
9542 Allow_Compile_Time : Boolean := False;
9543 Include_Interface_Tag : Boolean := False)
9545 Assoc : Node_Id;
9546 Variant : Node_Id;
9547 Discrete_Choice : Node_Id;
9548 Comp_Item : Node_Id;
9549 Discrim : Entity_Id;
9550 Discrim_Name : Node_Id;
9552 type Discriminant_Value_Status is
9553 (Static_Expr, Static_Subtype, Bad);
9554 subtype Good_Discrim_Value_Status is Discriminant_Value_Status
9555 range Static_Expr .. Static_Subtype; -- range excludes Bad
9557 Discrim_Value : Node_Id;
9558 Discrim_Value_Subtype : Node_Id;
9559 Discrim_Value_Status : Discriminant_Value_Status := Bad;
9561 function OK_Scope_For_Discrim_Value_Error_Messages return Boolean is
9562 (Scope (Original_Record_Component
9563 (Entity (First (Choices (Assoc))))) = Typ);
9564 -- Used to avoid generating error messages having a source position
9565 -- which refers to somewhere (e.g., a discriminant value in a derived
9566 -- tagged type declaration) unrelated to the offending construct. This
9567 -- is required for correctness - clients of Gather_Components such as
9568 -- Sem_Ch3.Create_Constrained_Components depend on this function
9569 -- returning True while processing semantically correct examples;
9570 -- generating an error message in this case would be wrong.
9572 begin
9573 Report_Errors := False;
9575 if No (Comp_List) or else Null_Present (Comp_List) then
9576 return;
9577 end if;
9579 Comp_Item := First (Component_Items (Comp_List));
9580 while Present (Comp_Item) loop
9582 -- Skip the tag of a tagged record, as well as all items that are not
9583 -- user components (anonymous types, rep clauses, Parent field,
9584 -- controller field).
9586 if Nkind (Comp_Item) = N_Component_Declaration then
9587 declare
9588 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
9589 begin
9590 if not (Is_Tag (Comp)
9591 and then not
9592 (Include_Interface_Tag
9593 and then Etype (Comp) = RTE (RE_Interface_Tag)))
9594 and then Chars (Comp) /= Name_uParent
9595 then
9596 Append_Elmt (Comp, Into);
9597 end if;
9598 end;
9599 end if;
9601 Next (Comp_Item);
9602 end loop;
9604 if No (Variant_Part (Comp_List)) then
9605 return;
9606 else
9607 Discrim_Name := Name (Variant_Part (Comp_List));
9608 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
9609 end if;
9611 -- Look for the discriminant that governs this variant part.
9612 -- The discriminant *must* be in the Governed_By List
9614 Assoc := First (Governed_By);
9615 Find_Constraint : loop
9616 Discrim := First (Choices (Assoc));
9617 pragma Assert (No (Next (Discrim)));
9619 exit Find_Constraint when
9620 Chars (Discrim_Name) = Chars (Discrim)
9621 or else
9622 (Present (Corresponding_Discriminant (Entity (Discrim)))
9623 and then Chars (Corresponding_Discriminant
9624 (Entity (Discrim))) = Chars (Discrim_Name))
9625 or else
9626 Chars (Original_Record_Component (Entity (Discrim))) =
9627 Chars (Discrim_Name);
9629 if No (Next (Assoc)) then
9630 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
9632 -- If the type is a tagged type with inherited discriminants,
9633 -- use the stored constraint on the parent in order to find
9634 -- the values of discriminants that are otherwise hidden by an
9635 -- explicit constraint. Renamed discriminants are handled in
9636 -- the code above.
9638 -- If several parent discriminants are renamed by a single
9639 -- discriminant of the derived type, the call to obtain the
9640 -- Corresponding_Discriminant field only retrieves the last
9641 -- of them. We recover the constraint on the others from the
9642 -- Stored_Constraint as well.
9644 -- An inherited discriminant may have been constrained in a
9645 -- later ancestor (not the immediate parent) so we must examine
9646 -- the stored constraint of all of them to locate the inherited
9647 -- value.
9649 declare
9650 C : Elmt_Id;
9651 D : Entity_Id;
9652 T : Entity_Id := Typ;
9654 begin
9655 while Is_Derived_Type (T) loop
9656 if Present (Stored_Constraint (T)) then
9657 D := First_Discriminant (Etype (T));
9658 C := First_Elmt (Stored_Constraint (T));
9659 while Present (D) and then Present (C) loop
9660 if Chars (Discrim_Name) = Chars (D) then
9661 if Is_Entity_Name (Node (C))
9662 and then Entity (Node (C)) = Entity (Discrim)
9663 then
9664 -- D is renamed by Discrim, whose value is
9665 -- given in Assoc.
9667 null;
9669 else
9670 Assoc :=
9671 Make_Component_Association (Sloc (Typ),
9672 New_List
9673 (New_Occurrence_Of (D, Sloc (Typ))),
9674 Duplicate_Subexpr_No_Checks (Node (C)));
9675 end if;
9677 exit Find_Constraint;
9678 end if;
9680 Next_Discriminant (D);
9681 Next_Elmt (C);
9682 end loop;
9683 end if;
9685 -- Discriminant may be inherited from ancestor
9687 T := Etype (T);
9688 end loop;
9689 end;
9690 end if;
9691 end if;
9693 Next (Assoc);
9695 if No (Assoc) then
9696 Error_Msg_NE
9697 ("missing value for discriminant&",
9698 First (Governed_By), Discrim_Name);
9700 Report_Errors := True;
9701 return;
9702 end if;
9703 end loop Find_Constraint;
9705 Discrim_Value := Expression (Assoc);
9707 if Is_OK_Static_Expression (Discrim_Value)
9708 or else (Allow_Compile_Time
9709 and then Compile_Time_Known_Value (Discrim_Value))
9710 then
9711 Discrim_Value_Status := Static_Expr;
9712 else
9713 if Ada_Version >= Ada_2022 then
9714 if Is_Rewrite_Substitution (Discrim_Value)
9715 and then Nkind (Discrim_Value) = N_Type_Conversion
9716 and then Etype (Original_Node (Discrim_Value))
9717 = Etype (Expression (Discrim_Value))
9718 then
9719 Discrim_Value_Subtype := Etype (Original_Node (Discrim_Value));
9720 -- An unhelpful (for this code) type conversion may be
9721 -- introduced in some cases; deal with it.
9722 else
9723 Discrim_Value_Subtype := Etype (Discrim_Value);
9724 end if;
9726 if Is_OK_Static_Subtype (Discrim_Value_Subtype) and then
9727 not Is_Null_Range (Type_Low_Bound (Discrim_Value_Subtype),
9728 Type_High_Bound (Discrim_Value_Subtype))
9729 then
9730 -- Is_Null_Range test doesn't account for predicates, as in
9731 -- subtype Null_By_Predicate is Natural
9732 -- with Static_Predicate => Null_By_Predicate < 0;
9733 -- so test for that null case separately.
9735 if not Has_Static_Predicate (Discrim_Value_Subtype)
9736 or else Present (First (Static_Discrete_Predicate
9737 (Discrim_Value_Subtype)))
9738 then
9739 Discrim_Value_Status := Static_Subtype;
9740 end if;
9741 end if;
9742 end if;
9744 if Discrim_Value_Status = Bad then
9746 -- If the variant part is governed by a discriminant of the type
9747 -- this is an error. If the variant part and the discriminant are
9748 -- inherited from an ancestor this is legal (AI05-220) unless the
9749 -- components are being gathered for an aggregate, in which case
9750 -- the caller must check Report_Errors.
9752 -- In Ada 2022 the above rules are relaxed. A nonstatic governing
9753 -- discriminant is OK as long as it has a static subtype and
9754 -- every value of that subtype (and there must be at least one)
9755 -- selects the same variant.
9757 if OK_Scope_For_Discrim_Value_Error_Messages then
9758 if Ada_Version >= Ada_2022 then
9759 Error_Msg_FE
9760 ("value for discriminant & must be static or " &
9761 "discriminant's nominal subtype must be static " &
9762 "and non-null!",
9763 Discrim_Value, Discrim);
9764 else
9765 Error_Msg_FE
9766 ("value for discriminant & must be static!",
9767 Discrim_Value, Discrim);
9768 end if;
9769 Why_Not_Static (Discrim_Value);
9770 end if;
9772 Report_Errors := True;
9773 return;
9774 end if;
9775 end if;
9777 Search_For_Discriminant_Value : declare
9778 Low : Node_Id;
9779 High : Node_Id;
9781 UI_High : Uint;
9782 UI_Low : Uint;
9783 UI_Discrim_Value : Uint;
9785 begin
9786 case Good_Discrim_Value_Status'(Discrim_Value_Status) is
9787 when Static_Expr =>
9788 UI_Discrim_Value := Expr_Value (Discrim_Value);
9789 when Static_Subtype =>
9790 -- Arbitrarily pick one value of the subtype and look
9791 -- for the variant associated with that value; we will
9792 -- check later that the same variant is associated with
9793 -- all of the other values of the subtype.
9794 if Has_Static_Predicate (Discrim_Value_Subtype) then
9795 declare
9796 Range_Or_Expr : constant Node_Id :=
9797 First (Static_Discrete_Predicate
9798 (Discrim_Value_Subtype));
9799 begin
9800 if Nkind (Range_Or_Expr) = N_Range then
9801 UI_Discrim_Value :=
9802 Expr_Value (Low_Bound (Range_Or_Expr));
9803 else
9804 UI_Discrim_Value := Expr_Value (Range_Or_Expr);
9805 end if;
9806 end;
9807 else
9808 UI_Discrim_Value :=
9809 Expr_Value (Type_Low_Bound (Discrim_Value_Subtype));
9810 end if;
9811 end case;
9813 Find_Discrete_Value : while Present (Variant) loop
9815 -- If a choice is a subtype with a static predicate, it must
9816 -- be rewritten as an explicit list of non-predicated choices.
9818 Expand_Static_Predicates_In_Choices (Variant);
9820 Discrete_Choice := First (Discrete_Choices (Variant));
9821 while Present (Discrete_Choice) loop
9822 exit Find_Discrete_Value when
9823 Nkind (Discrete_Choice) = N_Others_Choice;
9825 Get_Index_Bounds (Discrete_Choice, Low, High);
9827 UI_Low := Expr_Value (Low);
9828 UI_High := Expr_Value (High);
9830 exit Find_Discrete_Value when
9831 UI_Low <= UI_Discrim_Value
9832 and then
9833 UI_High >= UI_Discrim_Value;
9835 Next (Discrete_Choice);
9836 end loop;
9838 Next_Non_Pragma (Variant);
9839 end loop Find_Discrete_Value;
9840 end Search_For_Discriminant_Value;
9842 -- The case statement must include a variant that corresponds to the
9843 -- value of the discriminant, unless the discriminant type has a
9844 -- static predicate. In that case the absence of an others_choice that
9845 -- would cover this value becomes a run-time error (3.8.1 (21.1/2)).
9847 if No (Variant)
9848 and then not Has_Static_Predicate (Etype (Discrim_Name))
9849 then
9850 Error_Msg_NE
9851 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9852 Report_Errors := True;
9853 return;
9854 end if;
9856 -- If we have found the corresponding choice, recursively add its
9857 -- components to the Into list. The nested components are part of
9858 -- the same record type.
9860 if Present (Variant) then
9861 if Discrim_Value_Status = Static_Subtype then
9862 declare
9863 Discrim_Value_Subtype_Intervals :
9864 constant Interval_Lists.Discrete_Interval_List :=
9865 Interval_Lists.Type_Intervals (Discrim_Value_Subtype);
9867 Variant_Intervals :
9868 constant Interval_Lists.Discrete_Interval_List :=
9869 Interval_Lists.Choice_List_Intervals
9870 (Discrete_Choices => Discrete_Choices (Variant));
9871 begin
9872 if not Interval_Lists.Is_Subset
9873 (Subset => Discrim_Value_Subtype_Intervals,
9874 Of_Set => Variant_Intervals)
9875 then
9876 if OK_Scope_For_Discrim_Value_Error_Messages then
9877 Error_Msg_NE
9878 ("no single variant is associated with all values of " &
9879 "the subtype of discriminant value &",
9880 Discrim_Value, Discrim);
9881 end if;
9882 Report_Errors := True;
9883 return;
9884 end if;
9885 end;
9886 end if;
9888 Gather_Components
9889 (Typ, Component_List (Variant), Governed_By, Into,
9890 Report_Errors, Allow_Compile_Time);
9891 end if;
9892 end Gather_Components;
9894 ------------------------
9895 -- Get_Actual_Subtype --
9896 ------------------------
9898 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9899 Typ : constant Entity_Id := Etype (N);
9900 Utyp : Entity_Id := Underlying_Type (Typ);
9901 Decl : Node_Id;
9902 Atyp : Entity_Id;
9904 begin
9905 if No (Utyp) then
9906 Utyp := Typ;
9907 end if;
9909 -- If what we have is an identifier that references a subprogram
9910 -- formal, or a variable or constant object, then we get the actual
9911 -- subtype from the referenced entity if one has been built.
9913 if Nkind (N) in N_Identifier | N_Expanded_Name
9914 and then
9915 (Is_Formal (Entity (N))
9916 or else Ekind (Entity (N)) = E_Constant
9917 or else Ekind (Entity (N)) = E_Variable)
9918 and then Present (Actual_Subtype (Entity (N)))
9919 then
9920 return Actual_Subtype (Entity (N));
9922 -- Similarly, if we have an explicit dereference, then we get the
9923 -- actual subtype from the node itself if one has been built.
9925 elsif Nkind (N) = N_Explicit_Dereference
9926 and then Present (Actual_Designated_Subtype (N))
9927 then
9928 return Actual_Designated_Subtype (N);
9930 -- Actual subtype of unchecked union is always itself. We never need
9931 -- the "real" actual subtype. If we did, we couldn't get it anyway
9932 -- because the discriminant is not available. The restrictions on
9933 -- Unchecked_Union are designed to make sure that this is OK.
9935 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9936 return Typ;
9938 -- Here for the unconstrained case, we must find actual subtype
9939 -- No actual subtype is available, so we must build it on the fly.
9941 -- Checking the type, not the underlying type, for constrainedness
9942 -- seems to be necessary. Maybe all the tests should be on the type???
9944 elsif not Is_Constrained (Typ)
9945 and then (Is_Array_Type (Utyp)
9946 or else (Is_Record_Type (Utyp)
9947 and then Has_Discriminants (Utyp)))
9948 and then not Has_Unknown_Discriminants (Utyp)
9949 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9950 then
9951 -- Nothing to do if in spec expression (why not???)
9953 if In_Spec_Expression then
9954 return Typ;
9956 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9958 -- If the type has no discriminants, there is no subtype to
9959 -- build, even if the underlying type is discriminated.
9961 return Typ;
9963 -- Else build the actual subtype
9965 else
9966 Decl := Build_Actual_Subtype (Typ, N);
9968 -- The call may yield a declaration, or just return the entity
9970 if Decl = Typ then
9971 return Typ;
9972 end if;
9974 Atyp := Defining_Identifier (Decl);
9976 -- If Build_Actual_Subtype generated a new declaration then use it
9978 if Atyp /= Typ then
9980 -- The actual subtype is an Itype, so analyze the declaration,
9981 -- but do not attach it to the tree, to get the type defined.
9983 Set_Parent (Decl, N);
9984 Set_Is_Itype (Atyp);
9985 Analyze (Decl, Suppress => All_Checks);
9986 Set_Associated_Node_For_Itype (Atyp, N);
9987 if Expander_Active then
9988 Set_Has_Delayed_Freeze (Atyp, False);
9990 -- We need to freeze the actual subtype immediately. This is
9991 -- needed because otherwise this Itype will not get frozen
9992 -- at all; it is always safe to freeze on creation because
9993 -- any associated types must be frozen at this point.
9995 -- On the other hand, if we are performing preanalysis on
9996 -- a conjured-up copy of a name (see calls to
9997 -- Preanalyze_Range in sem_ch5.adb) then we don't want
9998 -- to freeze Atyp, now or ever. In this case, the tree
9999 -- we eventually pass to the back end should contain no
10000 -- references to Atyp (and a freeze node would contain
10001 -- such a reference). That's why Expander_Active is tested.
10003 Freeze_Itype (Atyp, N);
10004 end if;
10005 return Atyp;
10007 -- Otherwise we did not build a declaration, so return original
10009 else
10010 return Typ;
10011 end if;
10012 end if;
10014 -- For all remaining cases, the actual subtype is the same as
10015 -- the nominal type.
10017 else
10018 return Typ;
10019 end if;
10020 end Get_Actual_Subtype;
10022 -------------------------------------
10023 -- Get_Actual_Subtype_If_Available --
10024 -------------------------------------
10026 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
10027 begin
10028 -- If what we have is an identifier that references a subprogram
10029 -- formal, or a variable or constant object, then we get the actual
10030 -- subtype from the referenced entity if one has been built.
10032 if Nkind (N) in N_Identifier | N_Expanded_Name
10033 and then
10034 (Is_Formal (Entity (N))
10035 or else Ekind (Entity (N)) = E_Constant
10036 or else Ekind (Entity (N)) = E_Variable)
10037 and then Present (Actual_Subtype (Entity (N)))
10038 then
10039 return Actual_Subtype (Entity (N));
10041 -- Similarly, if we have an explicit dereference, then we get the
10042 -- actual subtype from the node itself if one has been built.
10044 elsif Nkind (N) = N_Explicit_Dereference
10045 and then Present (Actual_Designated_Subtype (N))
10046 then
10047 return Actual_Designated_Subtype (N);
10049 -- Otherwise the Etype of N is returned unchanged
10051 else
10052 return Etype (N);
10053 end if;
10054 end Get_Actual_Subtype_If_Available;
10056 ------------------------
10057 -- Get_Body_From_Stub --
10058 ------------------------
10060 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
10061 begin
10062 return Proper_Body (Unit (Library_Unit (N)));
10063 end Get_Body_From_Stub;
10065 ---------------------
10066 -- Get_Cursor_Type --
10067 ---------------------
10069 function Get_Cursor_Type
10070 (Aspect : Node_Id;
10071 Typ : Entity_Id) return Entity_Id
10073 Assoc : Node_Id;
10074 Func : Entity_Id;
10075 First_Op : Entity_Id;
10076 Cursor : Entity_Id;
10078 begin
10079 -- If error already detected, return
10081 if Error_Posted (Aspect) then
10082 return Any_Type;
10083 end if;
10085 -- The cursor type for an Iterable aspect is the return type of a
10086 -- non-overloaded First primitive operation. Locate association for
10087 -- First.
10089 Assoc := First (Component_Associations (Expression (Aspect)));
10090 First_Op := Any_Id;
10091 while Present (Assoc) loop
10092 if Chars (First (Choices (Assoc))) = Name_First then
10093 First_Op := Expression (Assoc);
10094 exit;
10095 end if;
10097 Next (Assoc);
10098 end loop;
10100 if First_Op = Any_Id then
10101 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
10102 return Any_Type;
10104 elsif not Analyzed (First_Op) then
10105 Analyze (First_Op);
10106 end if;
10108 Cursor := Any_Type;
10110 -- Locate function with desired name and profile in scope of type
10111 -- In the rare case where the type is an integer type, a base type
10112 -- is created for it, check that the base type of the first formal
10113 -- of First matches the base type of the domain.
10115 Func := First_Entity (Scope (Typ));
10116 while Present (Func) loop
10117 if Chars (Func) = Chars (First_Op)
10118 and then Ekind (Func) = E_Function
10119 and then Present (First_Formal (Func))
10120 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
10121 and then No (Next_Formal (First_Formal (Func)))
10122 then
10123 if Cursor /= Any_Type then
10124 Error_Msg_N
10125 ("operation First for iterable type must be unique", Aspect);
10126 return Any_Type;
10127 else
10128 Cursor := Etype (Func);
10129 end if;
10130 end if;
10132 Next_Entity (Func);
10133 end loop;
10135 -- If not found, no way to resolve remaining primitives
10137 if Cursor = Any_Type then
10138 Error_Msg_N
10139 ("primitive operation for Iterable type must appear in the same "
10140 & "list of declarations as the type", Aspect);
10141 end if;
10143 return Cursor;
10144 end Get_Cursor_Type;
10146 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
10147 begin
10148 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
10149 end Get_Cursor_Type;
10151 -------------------------------
10152 -- Get_Default_External_Name --
10153 -------------------------------
10155 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
10156 begin
10157 Get_Decoded_Name_String (Chars (E));
10159 if Opt.External_Name_Imp_Casing = Uppercase then
10160 Set_Casing (All_Upper_Case);
10161 else
10162 Set_Casing (All_Lower_Case);
10163 end if;
10165 return
10166 Make_String_Literal (Sloc (E),
10167 Strval => String_From_Name_Buffer);
10168 end Get_Default_External_Name;
10170 --------------------------
10171 -- Get_Enclosing_Object --
10172 --------------------------
10174 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
10175 begin
10176 if Is_Entity_Name (N) then
10177 return Entity (N);
10178 else
10179 case Nkind (N) is
10180 when N_Indexed_Component
10181 | N_Selected_Component
10182 | N_Slice
10184 -- If not generating code, a dereference may be left implicit.
10185 -- In thoses cases, return Empty.
10187 if Is_Access_Type (Etype (Prefix (N))) then
10188 return Empty;
10189 else
10190 return Get_Enclosing_Object (Prefix (N));
10191 end if;
10193 when N_Type_Conversion =>
10194 return Get_Enclosing_Object (Expression (N));
10196 when others =>
10197 return Empty;
10198 end case;
10199 end if;
10200 end Get_Enclosing_Object;
10202 -------------------------------
10203 -- Get_Enclosing_Deep_Object --
10204 -------------------------------
10206 function Get_Enclosing_Deep_Object (N : Node_Id) return Entity_Id is
10207 begin
10208 if Is_Entity_Name (N) then
10209 return Entity (N);
10210 else
10211 case Nkind (N) is
10212 when N_Explicit_Dereference
10213 | N_Indexed_Component
10214 | N_Selected_Component
10215 | N_Slice
10217 return Get_Enclosing_Deep_Object (Prefix (N));
10219 when N_Type_Conversion =>
10220 return Get_Enclosing_Deep_Object (Expression (N));
10222 when others =>
10223 return Empty;
10224 end case;
10225 end if;
10226 end Get_Enclosing_Deep_Object;
10228 ---------------------------
10229 -- Get_Enum_Lit_From_Pos --
10230 ---------------------------
10232 function Get_Enum_Lit_From_Pos
10233 (T : Entity_Id;
10234 Pos : Uint;
10235 Loc : Source_Ptr) return Node_Id
10237 Btyp : Entity_Id := Base_Type (T);
10238 Lit : Node_Id;
10239 LLoc : Source_Ptr;
10241 begin
10242 -- In the case where the literal is of type Character, Wide_Character
10243 -- or Wide_Wide_Character or of a type derived from them, there needs
10244 -- to be some special handling since there is no explicit chain of
10245 -- literals to search. Instead, an N_Character_Literal node is created
10246 -- with the appropriate Char_Code and Chars fields.
10248 if Is_Standard_Character_Type (T) then
10249 Set_Character_Literal_Name (UI_To_CC (Pos));
10251 return
10252 Make_Character_Literal (Loc,
10253 Chars => Name_Find,
10254 Char_Literal_Value => Pos);
10256 -- For all other cases, we have a complete table of literals, and
10257 -- we simply iterate through the chain of literal until the one
10258 -- with the desired position value is found.
10260 else
10261 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
10262 Btyp := Full_View (Btyp);
10263 end if;
10265 Lit := First_Literal (Btyp);
10267 -- Position in the enumeration type starts at 0
10269 if Pos < 0 then
10270 raise Constraint_Error;
10271 end if;
10273 for J in 1 .. UI_To_Int (Pos) loop
10274 Next_Literal (Lit);
10276 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
10277 -- inside the loop to avoid calling Next_Literal on Empty.
10279 if No (Lit) then
10280 raise Constraint_Error;
10281 end if;
10282 end loop;
10284 -- Create a new node from Lit, with source location provided by Loc
10285 -- if not equal to No_Location, or by copying the source location of
10286 -- Lit otherwise.
10288 LLoc := Loc;
10290 if LLoc = No_Location then
10291 LLoc := Sloc (Lit);
10292 end if;
10294 return New_Occurrence_Of (Lit, LLoc);
10295 end if;
10296 end Get_Enum_Lit_From_Pos;
10298 ----------------------
10299 -- Get_Fullest_View --
10300 ----------------------
10302 function Get_Fullest_View
10303 (E : Entity_Id;
10304 Include_PAT : Boolean := True;
10305 Recurse : Boolean := True) return Entity_Id
10307 New_E : Entity_Id := Empty;
10309 begin
10310 -- Prevent cascaded errors
10312 if No (E) then
10313 return E;
10314 end if;
10316 -- Look at each kind of entity to see where we may need to go deeper.
10318 case Ekind (E) is
10319 when Incomplete_Kind =>
10320 if From_Limited_With (E) then
10321 New_E := Non_Limited_View (E);
10322 elsif Present (Full_View (E)) then
10323 New_E := Full_View (E);
10324 elsif Ekind (E) = E_Incomplete_Subtype then
10325 New_E := Etype (E);
10326 end if;
10328 when Private_Kind =>
10329 if Present (Underlying_Full_View (E)) then
10330 New_E := Underlying_Full_View (E);
10331 elsif Present (Full_View (E)) then
10332 New_E := Full_View (E);
10333 elsif Etype (E) /= E then
10334 New_E := Etype (E);
10335 end if;
10337 when Array_Kind =>
10338 if Include_PAT and then Present (Packed_Array_Impl_Type (E)) then
10339 New_E := Packed_Array_Impl_Type (E);
10340 end if;
10342 when E_Record_Subtype =>
10343 if Present (Cloned_Subtype (E)) then
10344 New_E := Cloned_Subtype (E);
10345 end if;
10347 when E_Class_Wide_Type =>
10348 New_E := Root_Type (E);
10350 when E_Class_Wide_Subtype =>
10351 if Present (Equivalent_Type (E)) then
10352 New_E := Equivalent_Type (E);
10353 elsif Present (Cloned_Subtype (E)) then
10354 New_E := Cloned_Subtype (E);
10355 end if;
10357 when E_Protected_Subtype
10358 | E_Protected_Type
10359 | E_Task_Subtype
10360 | E_Task_Type
10362 if Present (Corresponding_Record_Type (E)) then
10363 New_E := Corresponding_Record_Type (E);
10364 end if;
10366 when E_Access_Protected_Subprogram_Type
10367 | E_Anonymous_Access_Protected_Subprogram_Type
10369 if Present (Equivalent_Type (E)) then
10370 New_E := Equivalent_Type (E);
10371 end if;
10373 when E_Access_Subtype =>
10374 New_E := Base_Type (E);
10376 when others =>
10377 null;
10378 end case;
10380 -- If we found a fuller view, either return it or recurse. Otherwise,
10381 -- return our input.
10383 return (if No (New_E) then E
10384 elsif Recurse then Get_Fullest_View (New_E, Include_PAT, Recurse)
10385 else New_E);
10386 end Get_Fullest_View;
10388 ------------------------
10389 -- Get_Generic_Entity --
10390 ------------------------
10392 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
10393 Ent : constant Entity_Id := Entity (Name (N));
10394 begin
10395 if Present (Renamed_Entity (Ent)) then
10396 return Renamed_Entity (Ent);
10397 else
10398 return Ent;
10399 end if;
10400 end Get_Generic_Entity;
10402 -------------------------------------
10403 -- Get_Incomplete_View_Of_Ancestor --
10404 -------------------------------------
10406 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
10407 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10408 Par_Scope : Entity_Id;
10409 Par_Type : Entity_Id;
10411 begin
10412 -- The incomplete view of an ancestor is only relevant for private
10413 -- derived types in child units.
10415 if not Is_Derived_Type (E)
10416 or else not Is_Child_Unit (Cur_Unit)
10417 then
10418 return Empty;
10420 else
10421 Par_Scope := Scope (Cur_Unit);
10422 if No (Par_Scope) then
10423 return Empty;
10424 end if;
10426 Par_Type := Etype (Base_Type (E));
10428 -- Traverse list of ancestor types until we find one declared in
10429 -- a parent or grandparent unit (two levels seem sufficient).
10431 while Present (Par_Type) loop
10432 if Scope (Par_Type) = Par_Scope
10433 or else Scope (Par_Type) = Scope (Par_Scope)
10434 then
10435 return Par_Type;
10437 elsif not Is_Derived_Type (Par_Type) then
10438 return Empty;
10440 else
10441 Par_Type := Etype (Base_Type (Par_Type));
10442 end if;
10443 end loop;
10445 -- If none found, there is no relevant ancestor type.
10447 return Empty;
10448 end if;
10449 end Get_Incomplete_View_Of_Ancestor;
10451 ----------------------
10452 -- Get_Index_Bounds --
10453 ----------------------
10455 procedure Get_Index_Bounds
10456 (N : Node_Id;
10457 L : out Node_Id;
10458 H : out Node_Id;
10459 Use_Full_View : Boolean := False)
10461 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
10462 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
10463 -- Typ qualifies, the scalar range is obtained from the full view of the
10464 -- type.
10466 --------------------------
10467 -- Scalar_Range_Of_Type --
10468 --------------------------
10470 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
10471 T : Entity_Id := Typ;
10473 begin
10474 if Use_Full_View and then Present (Full_View (T)) then
10475 T := Full_View (T);
10476 end if;
10478 return Scalar_Range (T);
10479 end Scalar_Range_Of_Type;
10481 -- Local variables
10483 Kind : constant Node_Kind := Nkind (N);
10484 Rng : Node_Id;
10486 -- Start of processing for Get_Index_Bounds
10488 begin
10489 if Kind = N_Range then
10490 L := Low_Bound (N);
10491 H := High_Bound (N);
10493 elsif Kind = N_Subtype_Indication then
10494 Rng := Range_Expression (Constraint (N));
10496 if Rng = Error then
10497 L := Error;
10498 H := Error;
10499 return;
10501 else
10502 L := Low_Bound (Range_Expression (Constraint (N)));
10503 H := High_Bound (Range_Expression (Constraint (N)));
10504 end if;
10506 elsif Is_Entity_Name (N)
10507 and then Present (Entity (N))
10508 and then Is_Type (Entity (N))
10509 then
10510 Rng := Scalar_Range_Of_Type (Entity (N));
10512 if Error_Posted (Rng) then
10513 L := Error;
10514 H := Error;
10516 elsif Nkind (Rng) = N_Subtype_Indication then
10517 Get_Index_Bounds (Rng, L, H);
10519 else
10520 L := Low_Bound (Rng);
10521 H := High_Bound (Rng);
10522 end if;
10524 else
10525 -- N is an expression, indicating a range with one value
10527 L := N;
10528 H := N;
10529 end if;
10530 end Get_Index_Bounds;
10532 function Get_Index_Bounds
10533 (N : Node_Id;
10534 Use_Full_View : Boolean := False) return Range_Nodes is
10535 Result : Range_Nodes;
10536 begin
10537 Get_Index_Bounds (N, Result.First, Result.Last, Use_Full_View);
10538 return Result;
10539 end Get_Index_Bounds;
10541 function Get_Index_Bounds
10542 (N : Node_Id;
10543 Use_Full_View : Boolean := False) return Range_Values is
10544 Nodes : constant Range_Nodes := Get_Index_Bounds (N, Use_Full_View);
10545 begin
10546 return (Expr_Value (Nodes.First), Expr_Value (Nodes.Last));
10547 end Get_Index_Bounds;
10549 -----------------------------
10550 -- Get_Interfacing_Aspects --
10551 -----------------------------
10553 procedure Get_Interfacing_Aspects
10554 (Iface_Asp : Node_Id;
10555 Conv_Asp : out Node_Id;
10556 EN_Asp : out Node_Id;
10557 Expo_Asp : out Node_Id;
10558 Imp_Asp : out Node_Id;
10559 LN_Asp : out Node_Id;
10560 Do_Checks : Boolean := False)
10562 procedure Save_Or_Duplication_Error
10563 (Asp : Node_Id;
10564 To : in out Node_Id);
10565 -- Save the value of aspect Asp in node To. If To already has a value,
10566 -- then this is considered a duplicate use of aspect. Emit an error if
10567 -- flag Do_Checks is set.
10569 -------------------------------
10570 -- Save_Or_Duplication_Error --
10571 -------------------------------
10573 procedure Save_Or_Duplication_Error
10574 (Asp : Node_Id;
10575 To : in out Node_Id)
10577 begin
10578 -- Detect an extra aspect and issue an error
10580 if Present (To) then
10581 if Do_Checks then
10582 Error_Msg_Name_1 := Chars (Identifier (Asp));
10583 Error_Msg_Sloc := Sloc (To);
10584 Error_Msg_N ("aspect % previously given #", Asp);
10585 end if;
10587 -- Otherwise capture the aspect
10589 else
10590 To := Asp;
10591 end if;
10592 end Save_Or_Duplication_Error;
10594 -- Local variables
10596 Asp : Node_Id;
10597 Asp_Id : Aspect_Id;
10599 -- The following variables capture each individual aspect
10601 Conv : Node_Id := Empty;
10602 EN : Node_Id := Empty;
10603 Expo : Node_Id := Empty;
10604 Imp : Node_Id := Empty;
10605 LN : Node_Id := Empty;
10607 -- Start of processing for Get_Interfacing_Aspects
10609 begin
10610 -- The input interfacing aspect should reside in an aspect specification
10611 -- list.
10613 pragma Assert (Is_List_Member (Iface_Asp));
10615 -- Examine the aspect specifications of the related entity. Find and
10616 -- capture all interfacing aspects. Detect duplicates and emit errors
10617 -- if applicable.
10619 Asp := First (List_Containing (Iface_Asp));
10620 while Present (Asp) loop
10621 Asp_Id := Get_Aspect_Id (Asp);
10623 if Asp_Id = Aspect_Convention then
10624 Save_Or_Duplication_Error (Asp, Conv);
10626 elsif Asp_Id = Aspect_External_Name then
10627 Save_Or_Duplication_Error (Asp, EN);
10629 elsif Asp_Id = Aspect_Export then
10630 Save_Or_Duplication_Error (Asp, Expo);
10632 elsif Asp_Id = Aspect_Import then
10633 Save_Or_Duplication_Error (Asp, Imp);
10635 elsif Asp_Id = Aspect_Link_Name then
10636 Save_Or_Duplication_Error (Asp, LN);
10637 end if;
10639 Next (Asp);
10640 end loop;
10642 Conv_Asp := Conv;
10643 EN_Asp := EN;
10644 Expo_Asp := Expo;
10645 Imp_Asp := Imp;
10646 LN_Asp := LN;
10647 end Get_Interfacing_Aspects;
10649 ---------------------------------
10650 -- Get_Iterable_Type_Primitive --
10651 ---------------------------------
10653 function Get_Iterable_Type_Primitive
10654 (Typ : Entity_Id;
10655 Nam : Name_Id) return Entity_Id
10657 pragma Assert
10658 (Is_Type (Typ)
10659 and then
10660 Nam in Name_Element
10661 | Name_First
10662 | Name_Has_Element
10663 | Name_Last
10664 | Name_Next
10665 | Name_Previous);
10667 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
10668 Assoc : Node_Id;
10670 begin
10671 if No (Funcs) then
10672 return Empty;
10674 else
10675 Assoc := First (Component_Associations (Funcs));
10676 while Present (Assoc) loop
10677 if Chars (First (Choices (Assoc))) = Nam then
10678 return Entity (Expression (Assoc));
10679 end if;
10681 Next (Assoc);
10682 end loop;
10684 return Empty;
10685 end if;
10686 end Get_Iterable_Type_Primitive;
10688 ---------------------------
10689 -- Get_Library_Unit_Name --
10690 ---------------------------
10692 function Get_Library_Unit_Name (Decl_Node : Node_Id) return String_Id is
10693 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
10694 Buf : Bounded_String;
10695 begin
10696 Get_Unit_Name_String (Buf, Unit_Name_Id);
10698 -- Remove the last seven characters (" (spec)" or " (body)")
10700 Buf.Length := Buf.Length - 7;
10701 pragma Assert (Buf.Chars (Buf.Length + 1) = ' ');
10703 return String_From_Name_Buffer (Buf);
10704 end Get_Library_Unit_Name;
10706 --------------------------
10707 -- Get_Max_Queue_Length --
10708 --------------------------
10710 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
10711 pragma Assert (Is_Entry (Id));
10712 PMQL : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
10713 PMEQL : constant Entity_Id :=
10714 Get_Pragma (Id, Pragma_Max_Entry_Queue_Length);
10715 Max : Uint;
10717 begin
10718 -- A value of 0 or -1 represents no maximum specified, and entries and
10719 -- entry families with no Max_Queue_Length aspect or pragma default to
10720 -- it.
10722 -- We have already checked that there is at most one of these pragmas
10724 if Present (PMQL) then
10725 Max := Expr_Value
10726 (Expression (First (Pragma_Argument_Associations (PMQL))));
10727 elsif Present (PMEQL) then
10728 Max := Expr_Value
10729 (Expression (First (Pragma_Argument_Associations (PMEQL))));
10730 else
10731 Max := Uint_0;
10732 end if;
10734 -- Since -1 and 0 are equivalent, return 0 for instances of -1 for
10735 -- uniformity.
10737 if Max = -1 then
10738 Max := Uint_0;
10739 end if;
10741 return Max;
10742 end Get_Max_Queue_Length;
10744 ------------------------
10745 -- Get_Name_Entity_Id --
10746 ------------------------
10748 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
10749 begin
10750 return Entity_Id (Get_Name_Table_Int (Id));
10751 end Get_Name_Entity_Id;
10753 ------------------------------
10754 -- Get_Name_From_CTC_Pragma --
10755 ------------------------------
10757 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
10758 Arg : constant Node_Id :=
10759 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
10760 begin
10761 return Strval (Expr_Value_S (Arg));
10762 end Get_Name_From_CTC_Pragma;
10764 -----------------------
10765 -- Get_Parent_Entity --
10766 -----------------------
10768 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
10769 begin
10770 if Nkind (Unit) = N_Package_Body
10771 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
10772 then
10773 return Defining_Entity
10774 (Specification (Instance_Spec (Original_Node (Unit))));
10775 elsif Nkind (Unit) = N_Package_Instantiation then
10776 return Defining_Entity (Specification (Instance_Spec (Unit)));
10777 else
10778 return Defining_Entity (Unit);
10779 end if;
10780 end Get_Parent_Entity;
10782 -------------------
10783 -- Get_Pragma_Id --
10784 -------------------
10786 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
10787 begin
10788 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
10789 end Get_Pragma_Id;
10791 ------------------------
10792 -- Get_Qualified_Name --
10793 ------------------------
10795 function Get_Qualified_Name
10796 (Id : Entity_Id;
10797 Suffix : Entity_Id := Empty) return Name_Id
10799 Suffix_Nam : Name_Id := No_Name;
10801 begin
10802 if Present (Suffix) then
10803 Suffix_Nam := Chars (Suffix);
10804 end if;
10806 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
10807 end Get_Qualified_Name;
10809 function Get_Qualified_Name
10810 (Nam : Name_Id;
10811 Suffix : Name_Id := No_Name;
10812 Scop : Entity_Id := Current_Scope) return Name_Id
10814 procedure Add_Scope (S : Entity_Id);
10815 -- Add the fully qualified form of scope S to the name buffer. The
10816 -- format is:
10817 -- s-1__s__
10819 ---------------
10820 -- Add_Scope --
10821 ---------------
10823 procedure Add_Scope (S : Entity_Id) is
10824 begin
10825 if S = Empty then
10826 null;
10828 elsif S = Standard_Standard then
10829 null;
10831 else
10832 Add_Scope (Scope (S));
10833 Get_Name_String_And_Append (Chars (S));
10834 Add_Str_To_Name_Buffer ("__");
10835 end if;
10836 end Add_Scope;
10838 -- Start of processing for Get_Qualified_Name
10840 begin
10841 Name_Len := 0;
10842 Add_Scope (Scop);
10844 -- Append the base name after all scopes have been chained
10846 Get_Name_String_And_Append (Nam);
10848 -- Append the suffix (if present)
10850 if Suffix /= No_Name then
10851 Add_Str_To_Name_Buffer ("__");
10852 Get_Name_String_And_Append (Suffix);
10853 end if;
10855 return Name_Find;
10856 end Get_Qualified_Name;
10858 -----------------------
10859 -- Get_Reason_String --
10860 -----------------------
10862 procedure Get_Reason_String (N : Node_Id) is
10863 begin
10864 if Nkind (N) = N_String_Literal then
10865 Store_String_Chars (Strval (N));
10867 elsif Nkind (N) = N_Op_Concat then
10868 Get_Reason_String (Left_Opnd (N));
10869 Get_Reason_String (Right_Opnd (N));
10871 -- If not of required form, error
10873 else
10874 Error_Msg_N
10875 ("Reason for pragma Warnings has wrong form", N);
10876 Error_Msg_N
10877 ("\must be string literal or concatenation of string literals", N);
10878 return;
10879 end if;
10880 end Get_Reason_String;
10882 --------------------------------
10883 -- Get_Reference_Discriminant --
10884 --------------------------------
10886 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
10887 D : Entity_Id;
10889 begin
10890 D := First_Discriminant (Typ);
10891 while Present (D) loop
10892 if Has_Implicit_Dereference (D) then
10893 return D;
10894 end if;
10895 Next_Discriminant (D);
10896 end loop;
10898 return Empty;
10899 end Get_Reference_Discriminant;
10901 ---------------------------
10902 -- Get_Referenced_Object --
10903 ---------------------------
10905 function Get_Referenced_Object (N : Node_Id) return Node_Id is
10906 R : Node_Id;
10908 begin
10909 R := N;
10910 while Is_Entity_Name (R)
10911 and then Is_Object (Entity (R))
10912 and then Present (Renamed_Object (Entity (R)))
10913 loop
10914 R := Renamed_Object (Entity (R));
10915 end loop;
10917 return R;
10918 end Get_Referenced_Object;
10920 ------------------------
10921 -- Get_Renamed_Entity --
10922 ------------------------
10924 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
10925 R : Entity_Id := E;
10926 begin
10927 while Present (Renamed_Entity (R)) loop
10928 R := Renamed_Entity (R);
10929 end loop;
10931 return R;
10932 end Get_Renamed_Entity;
10934 -----------------------
10935 -- Get_Return_Object --
10936 -----------------------
10938 function Get_Return_Object (N : Node_Id) return Entity_Id is
10939 Decl : Node_Id;
10941 begin
10942 Decl := First (Return_Object_Declarations (N));
10943 while Present (Decl) loop
10944 exit when Nkind (Decl) = N_Object_Declaration
10945 and then Is_Return_Object (Defining_Identifier (Decl));
10946 Next (Decl);
10947 end loop;
10949 pragma Assert (Present (Decl));
10950 return Defining_Identifier (Decl);
10951 end Get_Return_Object;
10953 ---------------------------
10954 -- Get_Subprogram_Entity --
10955 ---------------------------
10957 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
10958 Subp : Node_Id;
10959 Subp_Id : Entity_Id;
10961 begin
10962 if Nkind (Nod) = N_Accept_Statement then
10963 Subp := Entry_Direct_Name (Nod);
10965 elsif Nkind (Nod) = N_Slice then
10966 Subp := Prefix (Nod);
10968 else
10969 Subp := Name (Nod);
10970 end if;
10972 -- Strip the subprogram call
10974 loop
10975 if Nkind (Subp) in N_Explicit_Dereference
10976 | N_Indexed_Component
10977 | N_Selected_Component
10978 then
10979 Subp := Prefix (Subp);
10981 elsif Nkind (Subp) in N_Type_Conversion
10982 | N_Unchecked_Type_Conversion
10983 then
10984 Subp := Expression (Subp);
10986 else
10987 exit;
10988 end if;
10989 end loop;
10991 -- Extract the entity of the subprogram call
10993 if Is_Entity_Name (Subp) then
10994 Subp_Id := Entity (Subp);
10996 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
10997 Subp_Id := Directly_Designated_Type (Subp_Id);
10998 end if;
11000 if Is_Subprogram (Subp_Id) then
11001 return Subp_Id;
11002 else
11003 return Empty;
11004 end if;
11006 -- The search did not find a construct that denotes a subprogram
11008 else
11009 return Empty;
11010 end if;
11011 end Get_Subprogram_Entity;
11013 -----------------------------
11014 -- Get_Task_Body_Procedure --
11015 -----------------------------
11017 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
11018 begin
11019 -- Note: A task type may be the completion of a private type with
11020 -- discriminants. When performing elaboration checks on a task
11021 -- declaration, the current view of the type may be the private one,
11022 -- and the procedure that holds the body of the task is held in its
11023 -- underlying type.
11025 -- This is an odd function, why not have Task_Body_Procedure do
11026 -- the following digging???
11028 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
11029 end Get_Task_Body_Procedure;
11031 -------------------------------
11032 -- Get_User_Defined_Equality --
11033 -------------------------------
11035 function Get_User_Defined_Equality (E : Entity_Id) return Entity_Id is
11036 Prim : Elmt_Id;
11038 begin
11039 Prim := First_Elmt (Collect_Primitive_Operations (E));
11040 while Present (Prim) loop
11041 if Is_User_Defined_Equality (Node (Prim)) then
11042 return Node (Prim);
11043 end if;
11045 Next_Elmt (Prim);
11046 end loop;
11048 return Empty;
11049 end Get_User_Defined_Equality;
11051 ---------------
11052 -- Get_Views --
11053 ---------------
11055 procedure Get_Views
11056 (Typ : Entity_Id;
11057 Priv_Typ : out Entity_Id;
11058 Full_Typ : out Entity_Id;
11059 UFull_Typ : out Entity_Id;
11060 CRec_Typ : out Entity_Id)
11062 IP_View : Entity_Id;
11064 begin
11065 -- Assume that none of the views can be recovered
11067 Priv_Typ := Empty;
11068 Full_Typ := Empty;
11069 UFull_Typ := Empty;
11070 CRec_Typ := Empty;
11072 -- The input type is the corresponding record type of a protected or a
11073 -- task type.
11075 if Ekind (Typ) = E_Record_Type
11076 and then Is_Concurrent_Record_Type (Typ)
11077 then
11078 CRec_Typ := Typ;
11079 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
11080 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
11082 -- Otherwise the input type denotes an arbitrary type
11084 else
11085 IP_View := Incomplete_Or_Partial_View (Typ);
11087 -- The input type denotes the full view of a private type
11089 if Present (IP_View) then
11090 Priv_Typ := IP_View;
11091 Full_Typ := Typ;
11093 -- The input type is a private type
11095 elsif Is_Private_Type (Typ) then
11096 Priv_Typ := Typ;
11097 Full_Typ := Full_View (Priv_Typ);
11099 -- Otherwise the input type does not have any views
11101 else
11102 Full_Typ := Typ;
11103 end if;
11105 if Present (Full_Typ) and then Is_Private_Type (Full_Typ) then
11106 UFull_Typ := Underlying_Full_View (Full_Typ);
11108 if Present (UFull_Typ)
11109 and then Ekind (UFull_Typ) in E_Protected_Type | E_Task_Type
11110 then
11111 CRec_Typ := Corresponding_Record_Type (UFull_Typ);
11112 end if;
11114 else
11115 if Present (Full_Typ)
11116 and then Ekind (Full_Typ) in E_Protected_Type | E_Task_Type
11117 then
11118 CRec_Typ := Corresponding_Record_Type (Full_Typ);
11119 end if;
11120 end if;
11121 end if;
11122 end Get_Views;
11124 ------------------------------
11125 -- Has_Compatible_Alignment --
11126 ------------------------------
11128 function Has_Compatible_Alignment
11129 (Obj : Entity_Id;
11130 Expr : Node_Id;
11131 Layout_Done : Boolean) return Alignment_Result
11133 function Has_Compatible_Alignment_Internal
11134 (Obj : Entity_Id;
11135 Expr : Node_Id;
11136 Layout_Done : Boolean;
11137 Default : Alignment_Result) return Alignment_Result;
11138 -- This is the internal recursive function that actually does the work.
11139 -- There is one additional parameter, which says what the result should
11140 -- be if no alignment information is found, and there is no definite
11141 -- indication of compatible alignments. At the outer level, this is set
11142 -- to Unknown, but for internal recursive calls in the case where types
11143 -- are known to be correct, it is set to Known_Compatible.
11145 ---------------------------------------
11146 -- Has_Compatible_Alignment_Internal --
11147 ---------------------------------------
11149 function Has_Compatible_Alignment_Internal
11150 (Obj : Entity_Id;
11151 Expr : Node_Id;
11152 Layout_Done : Boolean;
11153 Default : Alignment_Result) return Alignment_Result
11155 Result : Alignment_Result := Known_Compatible;
11156 -- Holds the current status of the result. Note that once a value of
11157 -- Known_Incompatible is set, it is sticky and does not get changed
11158 -- to Unknown (the value in Result only gets worse as we go along,
11159 -- never better).
11161 Offs : Uint := No_Uint;
11162 -- Set to a factor of the offset from the base object when Expr is a
11163 -- selected or indexed component, based on Component_Bit_Offset and
11164 -- Component_Size respectively. A negative value is used to represent
11165 -- a value that is not known at compile time.
11167 procedure Check_Prefix;
11168 -- Checks the prefix recursively in the case where the expression
11169 -- is an indexed or selected component.
11171 procedure Set_Result (R : Alignment_Result);
11172 -- If R represents a worse outcome (unknown instead of known
11173 -- compatible, or known incompatible), then set Result to R.
11175 ------------------
11176 -- Check_Prefix --
11177 ------------------
11179 procedure Check_Prefix is
11180 begin
11181 -- The subtlety here is that in doing a recursive call to check
11182 -- the prefix, we have to decide what to do in the case where we
11183 -- don't find any specific indication of an alignment problem.
11185 -- At the outer level, we normally set Unknown as the result in
11186 -- this case, since we can only set Known_Compatible if we really
11187 -- know that the alignment value is OK, but for the recursive
11188 -- call, in the case where the types match, and we have not
11189 -- specified a peculiar alignment for the object, we are only
11190 -- concerned about suspicious rep clauses, the default case does
11191 -- not affect us, since the compiler will, in the absence of such
11192 -- rep clauses, ensure that the alignment is correct.
11194 if Default = Known_Compatible
11195 or else
11196 (Etype (Obj) = Etype (Expr)
11197 and then (not Known_Alignment (Obj)
11198 or else
11199 Alignment (Obj) = Alignment (Etype (Obj))))
11200 then
11201 Set_Result
11202 (Has_Compatible_Alignment_Internal
11203 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
11205 -- In all other cases, we need a full check on the prefix
11207 else
11208 Set_Result
11209 (Has_Compatible_Alignment_Internal
11210 (Obj, Prefix (Expr), Layout_Done, Unknown));
11211 end if;
11212 end Check_Prefix;
11214 ----------------
11215 -- Set_Result --
11216 ----------------
11218 procedure Set_Result (R : Alignment_Result) is
11219 begin
11220 if R > Result then
11221 Result := R;
11222 end if;
11223 end Set_Result;
11225 -- Start of processing for Has_Compatible_Alignment_Internal
11227 begin
11228 -- If Expr is a selected component, we must make sure there is no
11229 -- potentially troublesome component clause and that the record is
11230 -- not packed if the layout is not done.
11232 if Nkind (Expr) = N_Selected_Component then
11234 -- Packing generates unknown alignment if layout is not done
11236 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
11237 Set_Result (Unknown);
11238 end if;
11240 -- Check prefix and component offset
11242 Check_Prefix;
11243 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
11245 -- If Expr is an indexed component, we must make sure there is no
11246 -- potentially troublesome Component_Size clause and that the array
11247 -- is not bit-packed if the layout is not done.
11249 elsif Nkind (Expr) = N_Indexed_Component then
11250 declare
11251 Typ : constant Entity_Id := Etype (Prefix (Expr));
11253 begin
11254 -- Packing generates unknown alignment if layout is not done
11256 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
11257 Set_Result (Unknown);
11258 end if;
11260 -- Check prefix and component offset (or at least size)
11262 Check_Prefix;
11263 Offs := Indexed_Component_Bit_Offset (Expr);
11264 if No (Offs) then
11265 Offs := Component_Size (Typ);
11266 end if;
11267 end;
11268 end if;
11270 -- If we have a null offset, the result is entirely determined by
11271 -- the base object and has already been computed recursively.
11273 if Present (Offs) and then Offs = Uint_0 then
11274 null;
11276 -- Case where we know the alignment of the object
11278 elsif Known_Alignment (Obj) then
11279 declare
11280 ObjA : constant Uint := Alignment (Obj);
11281 ExpA : Uint := No_Uint;
11282 SizA : Uint := No_Uint;
11284 begin
11285 -- If alignment of Obj is 1, then we are always OK
11287 if ObjA = 1 then
11288 Set_Result (Known_Compatible);
11290 -- Alignment of Obj is greater than 1, so we need to check
11292 else
11293 -- If we have an offset, see if it is compatible
11295 if Present (Offs) and then Offs > Uint_0 then
11296 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
11297 Set_Result (Known_Incompatible);
11298 end if;
11300 -- See if Expr is an object with known alignment
11302 elsif Is_Entity_Name (Expr)
11303 and then Known_Alignment (Entity (Expr))
11304 then
11305 Offs := Uint_0;
11306 ExpA := Alignment (Entity (Expr));
11308 -- Otherwise, we can use the alignment of the type of Expr
11309 -- given that we already checked for discombobulating rep
11310 -- clauses for the cases of indexed and selected components
11311 -- above.
11313 elsif Known_Alignment (Etype (Expr)) then
11314 ExpA := Alignment (Etype (Expr));
11316 -- Otherwise the alignment is unknown
11318 else
11319 Set_Result (Default);
11320 end if;
11322 -- If we got an alignment, see if it is acceptable
11324 if Present (ExpA) and then ExpA < ObjA then
11325 Set_Result (Known_Incompatible);
11326 end if;
11328 -- If Expr is a component or an entire object with a known
11329 -- alignment, then we are fine. Otherwise, if its size is
11330 -- known, it must be big enough for the required alignment.
11332 if Present (Offs) then
11333 null;
11335 -- See if Expr is an object with known size
11337 elsif Is_Entity_Name (Expr)
11338 and then Known_Static_Esize (Entity (Expr))
11339 then
11340 SizA := Esize (Entity (Expr));
11342 -- Otherwise, we check the object size of the Expr type
11344 elsif Known_Static_Esize (Etype (Expr)) then
11345 SizA := Esize (Etype (Expr));
11346 end if;
11348 -- If we got a size, see if it is a multiple of the Obj
11349 -- alignment; if not, then the alignment cannot be
11350 -- acceptable, since the size is always a multiple of the
11351 -- alignment.
11353 if Present (SizA) then
11354 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
11355 Set_Result (Known_Incompatible);
11356 end if;
11357 end if;
11358 end if;
11359 end;
11361 -- If we do not know required alignment, any non-zero offset is a
11362 -- potential problem (but certainly may be OK, so result is unknown).
11364 elsif Present (Offs) then
11365 Set_Result (Unknown);
11367 -- If we can't find the result by direct comparison of alignment
11368 -- values, then there is still one case that we can determine known
11369 -- result, and that is when we can determine that the types are the
11370 -- same, and no alignments are specified. Then we known that the
11371 -- alignments are compatible, even if we don't know the alignment
11372 -- value in the front end.
11374 elsif Etype (Obj) = Etype (Expr) then
11376 -- Types are the same, but we have to check for possible size
11377 -- and alignments on the Expr object that may make the alignment
11378 -- different, even though the types are the same.
11380 if Is_Entity_Name (Expr) then
11382 -- First check alignment of the Expr object. Any alignment less
11383 -- than Maximum_Alignment is worrisome since this is the case
11384 -- where we do not know the alignment of Obj.
11386 if Known_Alignment (Entity (Expr))
11387 and then Alignment (Entity (Expr)) < Ttypes.Maximum_Alignment
11388 then
11389 Set_Result (Unknown);
11391 -- Now check size of Expr object. Any size that is not an even
11392 -- multiple of Maximum_Alignment is also worrisome since it
11393 -- may cause the alignment of the object to be less than the
11394 -- alignment of the type.
11396 elsif Known_Static_Esize (Entity (Expr))
11397 and then
11398 Esize (Entity (Expr)) mod
11399 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit)
11400 /= 0
11401 then
11402 Set_Result (Unknown);
11404 -- Otherwise same type is decisive
11406 else
11407 Set_Result (Known_Compatible);
11408 end if;
11409 end if;
11411 -- Another case to deal with is when there is an explicit size or
11412 -- alignment clause when the types are not the same. If so, then the
11413 -- result is Unknown. We don't need to do this test if the Default is
11414 -- Unknown, since that result will be set in any case.
11416 elsif Default /= Unknown
11417 and then (Has_Size_Clause (Etype (Expr))
11418 or else
11419 Has_Alignment_Clause (Etype (Expr)))
11420 then
11421 Set_Result (Unknown);
11423 -- If no indication found, set default
11425 else
11426 Set_Result (Default);
11427 end if;
11429 -- Return worst result found
11431 return Result;
11432 end Has_Compatible_Alignment_Internal;
11434 -- Start of processing for Has_Compatible_Alignment
11436 begin
11437 -- If Obj has no specified alignment, then set alignment from the type
11438 -- alignment. Perhaps we should always do this, but for sure we should
11439 -- do it when there is an address clause since we can do more if the
11440 -- alignment is known.
11442 if not Known_Alignment (Obj) and then Known_Alignment (Etype (Obj)) then
11443 Set_Alignment (Obj, Alignment (Etype (Obj)));
11444 end if;
11446 -- Now do the internal call that does all the work
11448 return
11449 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
11450 end Has_Compatible_Alignment;
11452 ----------------------
11453 -- Has_Declarations --
11454 ----------------------
11456 function Has_Declarations (N : Node_Id) return Boolean is
11457 begin
11458 return Nkind (N) in N_Accept_Statement
11459 | N_Block_Statement
11460 | N_Compilation_Unit_Aux
11461 | N_Entry_Body
11462 | N_Package_Body
11463 | N_Protected_Body
11464 | N_Subprogram_Body
11465 | N_Task_Body
11466 | N_Package_Specification;
11467 end Has_Declarations;
11469 ---------------------------------
11470 -- Has_Defaulted_Discriminants --
11471 ---------------------------------
11473 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
11474 begin
11475 return Has_Discriminants (Typ)
11476 and then Present (Discriminant_Default_Value
11477 (First_Discriminant (Typ)));
11478 end Has_Defaulted_Discriminants;
11480 -------------------
11481 -- Has_Denormals --
11482 -------------------
11484 function Has_Denormals (E : Entity_Id) return Boolean is
11485 begin
11486 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
11487 end Has_Denormals;
11489 -------------------------------------------
11490 -- Has_Discriminant_Dependent_Constraint --
11491 -------------------------------------------
11493 function Has_Discriminant_Dependent_Constraint
11494 (Comp : Entity_Id) return Boolean
11496 Comp_Decl : constant Node_Id := Parent (Comp);
11497 Subt_Indic : Node_Id;
11498 Constr : Node_Id;
11499 Assn : Node_Id;
11501 begin
11502 -- Discriminants can't depend on discriminants
11504 if Ekind (Comp) = E_Discriminant then
11505 return False;
11507 else
11508 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
11510 if Nkind (Subt_Indic) = N_Subtype_Indication then
11511 Constr := Constraint (Subt_Indic);
11513 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
11514 Assn := First (Constraints (Constr));
11515 while Present (Assn) loop
11516 case Nkind (Assn) is
11517 when N_Identifier
11518 | N_Range
11519 | N_Subtype_Indication
11521 if Depends_On_Discriminant (Assn) then
11522 return True;
11523 end if;
11525 when N_Discriminant_Association =>
11526 if Depends_On_Discriminant (Expression (Assn)) then
11527 return True;
11528 end if;
11530 when others =>
11531 null;
11532 end case;
11534 Next (Assn);
11535 end loop;
11536 end if;
11537 end if;
11538 end if;
11540 return False;
11541 end Has_Discriminant_Dependent_Constraint;
11543 --------------------------------------
11544 -- Has_Effectively_Volatile_Profile --
11545 --------------------------------------
11547 function Has_Effectively_Volatile_Profile
11548 (Subp_Id : Entity_Id) return Boolean
11550 Formal : Entity_Id;
11552 begin
11553 -- Inspect the formal parameters looking for an effectively volatile
11554 -- type for reading.
11556 Formal := First_Formal (Subp_Id);
11557 while Present (Formal) loop
11558 if Is_Effectively_Volatile_For_Reading (Etype (Formal)) then
11559 return True;
11560 end if;
11562 Next_Formal (Formal);
11563 end loop;
11565 -- Inspect the return type of functions
11567 if Ekind (Subp_Id) in E_Function | E_Generic_Function
11568 and then Is_Effectively_Volatile_For_Reading (Etype (Subp_Id))
11569 then
11570 return True;
11571 end if;
11573 return False;
11574 end Has_Effectively_Volatile_Profile;
11576 --------------------------
11577 -- Has_Enabled_Property --
11578 --------------------------
11580 function Has_Enabled_Property
11581 (Item_Id : Entity_Id;
11582 Property : Name_Id) return Boolean
11584 function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean;
11585 -- Determine whether a protected type or variable denoted by Item_Id
11586 -- has the property enabled.
11588 function State_Has_Enabled_Property return Boolean;
11589 -- Determine whether a state denoted by Item_Id has the property enabled
11591 function Type_Or_Variable_Has_Enabled_Property
11592 (Item_Id : Entity_Id) return Boolean;
11593 -- Determine whether type or variable denoted by Item_Id has the
11594 -- property enabled.
11596 -----------------------------------------------------
11597 -- Protected_Type_Or_Variable_Has_Enabled_Property --
11598 -----------------------------------------------------
11600 function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean
11602 begin
11603 -- Protected entities always have the properties Async_Readers and
11604 -- Async_Writers (SPARK RM 7.1.2(16)).
11606 if Property = Name_Async_Readers
11607 or else Property = Name_Async_Writers
11608 then
11609 return True;
11611 -- Protected objects that have Part_Of components also inherit their
11612 -- properties Effective_Reads and Effective_Writes
11613 -- (SPARK RM 7.1.2(16)).
11615 elsif Is_Single_Protected_Object (Item_Id) then
11616 declare
11617 Constit_Elmt : Elmt_Id;
11618 Constit_Id : Entity_Id;
11619 Constits : constant Elist_Id :=
11620 Part_Of_Constituents (Item_Id);
11621 begin
11622 if Present (Constits) then
11623 Constit_Elmt := First_Elmt (Constits);
11624 while Present (Constit_Elmt) loop
11625 Constit_Id := Node (Constit_Elmt);
11627 if Has_Enabled_Property (Constit_Id, Property) then
11628 return True;
11629 end if;
11631 Next_Elmt (Constit_Elmt);
11632 end loop;
11633 end if;
11634 end;
11635 end if;
11637 return False;
11638 end Protected_Type_Or_Variable_Has_Enabled_Property;
11640 --------------------------------
11641 -- State_Has_Enabled_Property --
11642 --------------------------------
11644 function State_Has_Enabled_Property return Boolean is
11645 Decl : constant Node_Id := Parent (Item_Id);
11647 procedure Find_Simple_Properties
11648 (Has_External : out Boolean;
11649 Has_Synchronous : out Boolean);
11650 -- Extract the simple properties associated with declaration Decl
11652 function Is_Enabled_External_Property return Boolean;
11653 -- Determine whether property Property appears within the external
11654 -- property list of declaration Decl, and return its status.
11656 ----------------------------
11657 -- Find_Simple_Properties --
11658 ----------------------------
11660 procedure Find_Simple_Properties
11661 (Has_External : out Boolean;
11662 Has_Synchronous : out Boolean)
11664 Opt : Node_Id;
11666 begin
11667 -- Assume that none of the properties are available
11669 Has_External := False;
11670 Has_Synchronous := False;
11672 Opt := First (Expressions (Decl));
11673 while Present (Opt) loop
11674 if Nkind (Opt) = N_Identifier then
11675 if Chars (Opt) = Name_External then
11676 Has_External := True;
11678 elsif Chars (Opt) = Name_Synchronous then
11679 Has_Synchronous := True;
11680 end if;
11681 end if;
11683 Next (Opt);
11684 end loop;
11685 end Find_Simple_Properties;
11687 ----------------------------------
11688 -- Is_Enabled_External_Property --
11689 ----------------------------------
11691 function Is_Enabled_External_Property return Boolean is
11692 Opt : Node_Id;
11693 Opt_Nam : Node_Id;
11694 Prop : Node_Id;
11695 Prop_Nam : Node_Id;
11696 Props : Node_Id;
11698 begin
11699 Opt := First (Component_Associations (Decl));
11700 while Present (Opt) loop
11701 Opt_Nam := First (Choices (Opt));
11703 if Nkind (Opt_Nam) = N_Identifier
11704 and then Chars (Opt_Nam) = Name_External
11705 then
11706 Props := Expression (Opt);
11708 -- Multiple properties appear as an aggregate
11710 if Nkind (Props) = N_Aggregate then
11712 -- Simple property form
11714 Prop := First (Expressions (Props));
11715 while Present (Prop) loop
11716 if Chars (Prop) = Property then
11717 return True;
11718 end if;
11720 Next (Prop);
11721 end loop;
11723 -- Property with expression form
11725 Prop := First (Component_Associations (Props));
11726 while Present (Prop) loop
11727 Prop_Nam := First (Choices (Prop));
11729 -- The property can be represented in two ways:
11730 -- others => <value>
11731 -- <property> => <value>
11733 if Nkind (Prop_Nam) = N_Others_Choice
11734 or else (Nkind (Prop_Nam) = N_Identifier
11735 and then Chars (Prop_Nam) = Property)
11736 then
11737 return Is_True (Expr_Value (Expression (Prop)));
11738 end if;
11740 Next (Prop);
11741 end loop;
11743 -- Single property
11745 else
11746 return Chars (Props) = Property;
11747 end if;
11748 end if;
11750 Next (Opt);
11751 end loop;
11753 return False;
11754 end Is_Enabled_External_Property;
11756 -- Local variables
11758 Has_External : Boolean;
11759 Has_Synchronous : Boolean;
11761 -- Start of processing for State_Has_Enabled_Property
11763 begin
11764 -- The declaration of an external abstract state appears as an
11765 -- extension aggregate. If this is not the case, properties can
11766 -- never be set.
11768 if Nkind (Decl) /= N_Extension_Aggregate then
11769 return False;
11770 end if;
11772 Find_Simple_Properties (Has_External, Has_Synchronous);
11774 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
11776 if Has_External then
11777 return True;
11779 -- Option External may enable or disable specific properties
11781 elsif Is_Enabled_External_Property then
11782 return True;
11784 -- Simple option Synchronous
11786 -- enables disables
11787 -- Async_Readers Effective_Reads
11788 -- Async_Writers Effective_Writes
11790 -- Note that both forms of External have higher precedence than
11791 -- Synchronous (SPARK RM 7.1.4(9)).
11793 elsif Has_Synchronous then
11794 return Property in Name_Async_Readers | Name_Async_Writers;
11795 end if;
11797 return False;
11798 end State_Has_Enabled_Property;
11800 -------------------------------------------
11801 -- Type_Or_Variable_Has_Enabled_Property --
11802 -------------------------------------------
11804 function Type_Or_Variable_Has_Enabled_Property
11805 (Item_Id : Entity_Id) return Boolean
11807 AR : constant Node_Id :=
11808 Get_Pragma (Item_Id, Pragma_Async_Readers);
11809 AW : constant Node_Id :=
11810 Get_Pragma (Item_Id, Pragma_Async_Writers);
11811 ER : constant Node_Id :=
11812 Get_Pragma (Item_Id, Pragma_Effective_Reads);
11813 EW : constant Node_Id :=
11814 Get_Pragma (Item_Id, Pragma_Effective_Writes);
11816 Is_Derived_Type_With_Volatile_Parent_Type : constant Boolean :=
11817 Is_Derived_Type (Item_Id)
11818 and then Is_Effectively_Volatile (Etype (Base_Type (Item_Id)));
11820 begin
11821 -- A non-effectively volatile object can never possess external
11822 -- properties.
11824 if not Is_Effectively_Volatile (Item_Id) then
11825 return False;
11827 -- External properties related to variables come in two flavors -
11828 -- explicit and implicit. The explicit case is characterized by the
11829 -- presence of a property pragma with an optional Boolean flag. The
11830 -- property is enabled when the flag evaluates to True or the flag is
11831 -- missing altogether.
11833 elsif Property = Name_Async_Readers and then Present (AR) then
11834 return Is_Enabled_Pragma (AR);
11836 elsif Property = Name_Async_Writers and then Present (AW) then
11837 return Is_Enabled_Pragma (AW);
11839 elsif Property = Name_Effective_Reads and then Present (ER) then
11840 return Is_Enabled_Pragma (ER);
11842 elsif Property = Name_Effective_Writes and then Present (EW) then
11843 return Is_Enabled_Pragma (EW);
11845 -- If other properties are set explicitly, then this one is set
11846 -- implicitly to False, except in the case of a derived type
11847 -- whose parent type is volatile (in that case, we will inherit
11848 -- from the parent type, below).
11850 elsif (Present (AR)
11851 or else Present (AW)
11852 or else Present (ER)
11853 or else Present (EW))
11854 and then not Is_Derived_Type_With_Volatile_Parent_Type
11855 then
11856 return False;
11858 -- For a private type (including subtype of a private types), look at
11859 -- the full view.
11861 elsif Is_Private_Type (Item_Id) and then Present (Full_View (Item_Id))
11862 then
11863 return Type_Or_Variable_Has_Enabled_Property (Full_View (Item_Id));
11865 -- For a derived type whose parent type is volatile, the
11866 -- property may be inherited (but ignore a non-volatile parent).
11868 elsif Is_Derived_Type_With_Volatile_Parent_Type then
11869 return Type_Or_Variable_Has_Enabled_Property
11870 (First_Subtype (Etype (Base_Type (Item_Id))));
11872 -- For a subtype, the property will be inherited from its base type.
11874 elsif Is_Type (Item_Id)
11875 and then not Is_Base_Type (Item_Id)
11876 then
11877 return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id));
11879 -- If not specified explicitly for an object and its type
11880 -- is effectively volatile, then take result from the type.
11882 elsif Is_Object (Item_Id)
11883 and then Is_Effectively_Volatile (Etype (Item_Id))
11884 then
11885 return Has_Enabled_Property (Etype (Item_Id), Property);
11887 -- The implicit case lacks all property pragmas
11889 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
11890 if Is_Protected_Type (Etype (Item_Id)) then
11891 return Protected_Type_Or_Variable_Has_Enabled_Property;
11892 else
11893 return True;
11894 end if;
11896 else
11897 return False;
11898 end if;
11899 end Type_Or_Variable_Has_Enabled_Property;
11901 -- Start of processing for Has_Enabled_Property
11903 begin
11904 -- Abstract states and variables have a flexible scheme of specifying
11905 -- external properties.
11907 if Ekind (Item_Id) = E_Abstract_State then
11908 return State_Has_Enabled_Property;
11910 elsif Ekind (Item_Id) in E_Variable | E_Constant then
11911 return Type_Or_Variable_Has_Enabled_Property (Item_Id);
11913 -- Other objects can only inherit properties through their type. We
11914 -- cannot call directly Type_Or_Variable_Has_Enabled_Property on
11915 -- these as they don't have contracts attached, which is expected by
11916 -- this function.
11918 elsif Is_Object (Item_Id) then
11919 return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id));
11921 elsif Is_Type (Item_Id) then
11922 return Type_Or_Variable_Has_Enabled_Property
11923 (Item_Id => First_Subtype (Item_Id));
11925 -- Otherwise a property is enabled when the related item is effectively
11926 -- volatile.
11928 else
11929 return Is_Effectively_Volatile (Item_Id);
11930 end if;
11931 end Has_Enabled_Property;
11933 -------------------------------------
11934 -- Has_Full_Default_Initialization --
11935 -------------------------------------
11937 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
11938 Comp : Entity_Id;
11940 begin
11941 -- A type subject to pragma Default_Initial_Condition may be fully
11942 -- default initialized depending on inheritance and the argument of
11943 -- the pragma. Since any type may act as the full view of a private
11944 -- type, this check must be performed prior to the specialized tests
11945 -- below.
11947 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
11948 return True;
11949 end if;
11951 -- A scalar type is fully default initialized if it is subject to aspect
11952 -- Default_Value.
11954 if Is_Scalar_Type (Typ) then
11955 return Has_Default_Aspect (Typ);
11957 -- An access type is fully default initialized by default
11959 elsif Is_Access_Type (Typ) then
11960 return True;
11962 -- An array type is fully default initialized if its element type is
11963 -- scalar and the array type carries aspect Default_Component_Value or
11964 -- the element type is fully default initialized.
11966 elsif Is_Array_Type (Typ) then
11967 return
11968 Has_Default_Aspect (Typ)
11969 or else Has_Full_Default_Initialization (Component_Type (Typ));
11971 -- A protected type, record type, or type extension is fully default
11972 -- initialized if all its components either carry an initialization
11973 -- expression or have a type that is fully default initialized. The
11974 -- parent type of a type extension must be fully default initialized.
11976 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
11978 -- Inspect all entities defined in the scope of the type, looking for
11979 -- uninitialized components.
11981 Comp := First_Component (Typ);
11982 while Present (Comp) loop
11983 if Comes_From_Source (Comp)
11984 and then No (Expression (Parent (Comp)))
11985 and then not Has_Full_Default_Initialization (Etype (Comp))
11986 then
11987 return False;
11988 end if;
11990 Next_Component (Comp);
11991 end loop;
11993 -- Ensure that the parent type of a type extension is fully default
11994 -- initialized.
11996 if Etype (Typ) /= Typ
11997 and then not Has_Full_Default_Initialization (Etype (Typ))
11998 then
11999 return False;
12000 end if;
12002 -- If we get here, then all components and parent portion are fully
12003 -- default initialized.
12005 return True;
12007 -- A task type is fully default initialized by default
12009 elsif Is_Task_Type (Typ) then
12010 return True;
12012 -- Otherwise the type is not fully default initialized
12014 else
12015 return False;
12016 end if;
12017 end Has_Full_Default_Initialization;
12019 -----------------------------------------------
12020 -- Has_Fully_Default_Initializing_DIC_Pragma --
12021 -----------------------------------------------
12023 function Has_Fully_Default_Initializing_DIC_Pragma
12024 (Typ : Entity_Id) return Boolean
12026 Args : List_Id;
12027 Prag : Node_Id;
12029 begin
12030 -- A type that inherits pragma Default_Initial_Condition from a parent
12031 -- type is automatically fully default initialized.
12033 if Has_Inherited_DIC (Typ) then
12034 return True;
12036 -- Otherwise the type is fully default initialized only when the pragma
12037 -- appears without an argument, or the argument is non-null.
12039 elsif Has_Own_DIC (Typ) then
12040 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
12041 pragma Assert (Present (Prag));
12042 Args := Pragma_Argument_Associations (Prag);
12044 -- The pragma appears without an argument in which case it defaults
12045 -- to True.
12047 if No (Args) then
12048 return True;
12050 -- The pragma appears with a non-null expression
12052 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
12053 return True;
12054 end if;
12055 end if;
12057 return False;
12058 end Has_Fully_Default_Initializing_DIC_Pragma;
12060 ---------------------------------
12061 -- Has_Inferable_Discriminants --
12062 ---------------------------------
12064 function Has_Inferable_Discriminants (N : Node_Id) return Boolean is
12066 function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean;
12067 -- Determines whether the left-most prefix of a selected component is a
12068 -- formal parameter in a subprogram. Assumes N is a selected component.
12070 --------------------------------
12071 -- Prefix_Is_Formal_Parameter --
12072 --------------------------------
12074 function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean is
12075 Sel_Comp : Node_Id;
12077 begin
12078 -- Move to the left-most prefix by climbing up the tree
12080 Sel_Comp := N;
12081 while Present (Parent (Sel_Comp))
12082 and then Nkind (Parent (Sel_Comp)) = N_Selected_Component
12083 loop
12084 Sel_Comp := Parent (Sel_Comp);
12085 end loop;
12087 return Is_Formal (Entity (Prefix (Sel_Comp)));
12088 end Prefix_Is_Formal_Parameter;
12090 -- Start of processing for Has_Inferable_Discriminants
12092 begin
12093 -- For selected components, the subtype of the selector must be a
12094 -- constrained Unchecked_Union. If the component is subject to a
12095 -- per-object constraint, then the enclosing object must either be
12096 -- a regular discriminated type or must have inferable discriminants.
12098 if Nkind (N) = N_Selected_Component then
12099 -- The call to Has_Inferable_Discriminants will determine whether
12100 -- the selector has a constrained Unchecked_Union nominal type.
12102 if not Has_Inferable_Discriminants (Selector_Name (N)) then
12103 return False;
12104 end if;
12106 -- A small hack. If we have a per-object constrained selected
12107 -- component of a formal parameter, return True since we do not
12108 -- know the actual parameter association yet.
12110 return not Has_Per_Object_Constraint (Entity (Selector_Name (N)))
12111 or else not Is_Unchecked_Union (Etype (Prefix (N)))
12112 or else Has_Inferable_Discriminants (Prefix (N))
12113 or else Prefix_Is_Formal_Parameter (N);
12115 -- A qualified expression has inferable discriminants if its subtype
12116 -- mark is a constrained Unchecked_Union subtype.
12118 elsif Nkind (N) = N_Qualified_Expression then
12119 return Is_Unchecked_Union (Etype (Subtype_Mark (N)))
12120 and then Is_Constrained (Etype (Subtype_Mark (N)));
12122 -- For all other names, it is sufficient to have a constrained
12123 -- Unchecked_Union nominal subtype, unless it is incomplete or
12124 -- private because it cannot have a known discriminant part in
12125 -- this case (RM B.3.3 (11/2)).
12127 else
12128 return Is_Unchecked_Union (Etype (N))
12129 and then Is_Constrained (Etype (N))
12130 and then not Is_Incomplete_Or_Private_Type (Etype (N));
12131 end if;
12132 end Has_Inferable_Discriminants;
12134 --------------------
12135 -- Has_Infinities --
12136 --------------------
12138 function Has_Infinities (E : Entity_Id) return Boolean is
12139 begin
12140 return
12141 Is_Floating_Point_Type (E)
12142 and then Nkind (Scalar_Range (E)) = N_Range
12143 and then Includes_Infinities (Scalar_Range (E));
12144 end Has_Infinities;
12146 --------------------
12147 -- Has_Interfaces --
12148 --------------------
12150 function Has_Interfaces
12151 (T : Entity_Id;
12152 Use_Full_View : Boolean := True) return Boolean
12154 Typ : Entity_Id := Base_Type (T);
12156 begin
12157 -- Handle concurrent types
12159 if Is_Concurrent_Type (Typ) then
12160 Typ := Corresponding_Record_Type (Typ);
12161 end if;
12163 if No (Typ)
12164 or else not Is_Record_Type (Typ)
12165 or else not Is_Tagged_Type (Typ)
12166 then
12167 return False;
12168 end if;
12170 -- Handle private types
12172 if Use_Full_View and then Present (Full_View (Typ)) then
12173 Typ := Full_View (Typ);
12174 end if;
12176 -- Handle concurrent record types
12178 if Is_Concurrent_Record_Type (Typ)
12179 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
12180 then
12181 return True;
12182 end if;
12184 loop
12185 if Is_Interface (Typ)
12186 or else
12187 (Is_Record_Type (Typ)
12188 and then Present (Interfaces (Typ))
12189 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
12190 then
12191 return True;
12192 end if;
12194 exit when Etype (Typ) = Typ
12196 -- Handle private types
12198 or else (Present (Full_View (Etype (Typ)))
12199 and then Full_View (Etype (Typ)) = Typ)
12201 -- Protect frontend against wrong sources with cyclic derivations
12203 or else Etype (Typ) = T;
12205 -- Climb to the ancestor type handling private types
12207 if Present (Full_View (Etype (Typ))) then
12208 Typ := Full_View (Etype (Typ));
12209 else
12210 Typ := Etype (Typ);
12211 end if;
12212 end loop;
12214 return False;
12215 end Has_Interfaces;
12217 --------------------------
12218 -- Has_Max_Queue_Length --
12219 --------------------------
12221 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
12222 begin
12223 return
12224 Ekind (Id) = E_Entry
12225 and then
12226 (Present (Get_Pragma (Id, Pragma_Max_Queue_Length))
12227 or else
12228 Present (Get_Pragma (Id, Pragma_Max_Entry_Queue_Length)));
12229 end Has_Max_Queue_Length;
12231 ---------------------------------
12232 -- Has_No_Obvious_Side_Effects --
12233 ---------------------------------
12235 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
12236 begin
12237 -- For now handle literals, constants, and non-volatile variables and
12238 -- expressions combining these with operators or short circuit forms.
12240 if Nkind (N) in N_Numeric_Or_String_Literal then
12241 return True;
12243 elsif Nkind (N) = N_Character_Literal then
12244 return True;
12246 elsif Nkind (N) in N_Unary_Op then
12247 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
12249 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
12250 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
12251 and then
12252 Has_No_Obvious_Side_Effects (Right_Opnd (N));
12254 elsif Nkind (N) = N_Expression_With_Actions
12255 and then Is_Empty_List (Actions (N))
12256 then
12257 return Has_No_Obvious_Side_Effects (Expression (N));
12259 elsif Nkind (N) in N_Has_Entity then
12260 return Present (Entity (N))
12261 and then
12262 Ekind (Entity (N)) in
12263 E_Variable | E_Constant | E_Enumeration_Literal |
12264 E_In_Parameter | E_Out_Parameter | E_In_Out_Parameter
12265 and then not Is_Volatile (Entity (N));
12267 else
12268 return False;
12269 end if;
12270 end Has_No_Obvious_Side_Effects;
12272 -----------------------------
12273 -- Has_Non_Null_Refinement --
12274 -----------------------------
12276 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
12277 Constits : Elist_Id;
12279 begin
12280 pragma Assert (Ekind (Id) = E_Abstract_State);
12281 Constits := Refinement_Constituents (Id);
12283 -- For a refinement to be non-null, the first constituent must be
12284 -- anything other than null.
12286 return
12287 Present (Constits)
12288 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
12289 end Has_Non_Null_Refinement;
12291 -----------------------------
12292 -- Has_Non_Null_Statements --
12293 -----------------------------
12295 function Has_Non_Null_Statements (L : List_Id) return Boolean is
12296 Node : Node_Id;
12298 begin
12299 Node := First (L);
12301 while Present (Node) loop
12302 if Nkind (Node) not in N_Null_Statement | N_Call_Marker then
12303 return True;
12304 end if;
12306 Next (Node);
12307 end loop;
12309 return False;
12310 end Has_Non_Null_Statements;
12312 ----------------------------------
12313 -- Is_Access_Subprogram_Wrapper --
12314 ----------------------------------
12316 function Is_Access_Subprogram_Wrapper (E : Entity_Id) return Boolean is
12317 Formal : constant Entity_Id := Last_Formal (E);
12318 begin
12319 return Present (Formal)
12320 and then Ekind (Etype (Formal)) in Access_Subprogram_Kind
12321 and then Access_Subprogram_Wrapper
12322 (Directly_Designated_Type (Etype (Formal))) = E;
12323 end Is_Access_Subprogram_Wrapper;
12325 ---------------------------
12326 -- Is_Explicitly_Aliased --
12327 ---------------------------
12329 function Is_Explicitly_Aliased (N : Node_Id) return Boolean is
12330 begin
12331 return Is_Formal (N)
12332 and then Present (Parent (N))
12333 and then Nkind (Parent (N)) = N_Parameter_Specification
12334 and then Aliased_Present (Parent (N));
12335 end Is_Explicitly_Aliased;
12337 ----------------------------
12338 -- Is_Container_Aggregate --
12339 ----------------------------
12341 function Is_Container_Aggregate (Exp : Node_Id) return Boolean is
12343 function Is_Record_Aggregate return Boolean is
12344 (Is_Parenthesis_Aggregate (Exp));
12345 -- Given an aggregate whose type is a record type with specified
12346 -- Aggregate aspect, we determine whether it is a record aggregate or
12347 -- a container aggregate by ckecking whether it uses parentheses () or
12348 -- square brackets []. If the code where the aggregate occurs can see
12349 -- only a partial view of the aggregate's type then the aggregate cannot
12350 -- be a record type and must then use []; an aggregate of a private type
12351 -- has to be a container aggregate and must then use [].
12353 begin
12354 return Nkind (Exp) = N_Aggregate
12355 and then Has_Aspect (Etype (Exp), Aspect_Aggregate)
12356 and then not Is_Record_Aggregate;
12357 end Is_Container_Aggregate;
12359 ---------------------------------
12360 -- Side_Effect_Free_Statements --
12361 ---------------------------------
12363 function Side_Effect_Free_Statements (L : List_Id) return Boolean is
12364 Node : Node_Id;
12366 begin
12367 Node := First (L);
12369 while Present (Node) loop
12370 case Nkind (Node) is
12371 when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error =>
12372 null;
12374 when N_Object_Declaration =>
12375 if Present (Expression (Node))
12376 and then not Side_Effect_Free (Expression (Node))
12377 then
12378 return False;
12379 end if;
12381 when others =>
12382 return False;
12383 end case;
12385 Next (Node);
12386 end loop;
12388 return True;
12389 end Side_Effect_Free_Statements;
12391 ---------------------------
12392 -- Side_Effect_Free_Loop --
12393 ---------------------------
12395 function Side_Effect_Free_Loop (N : Node_Id) return Boolean is
12396 Scheme : Node_Id;
12397 Spec : Node_Id;
12398 Subt : Node_Id;
12400 begin
12401 -- If this is not a loop (e.g. because the loop has been rewritten),
12402 -- then return false.
12404 if Nkind (N) /= N_Loop_Statement then
12405 return False;
12406 end if;
12408 -- First check the statements
12410 if Side_Effect_Free_Statements (Statements (N)) then
12412 -- Then check the loop condition/indexes
12414 if Present (Iteration_Scheme (N)) then
12415 Scheme := Iteration_Scheme (N);
12417 if Present (Condition (Scheme))
12418 or else Present (Iterator_Specification (Scheme))
12419 then
12420 return False;
12421 elsif Present (Loop_Parameter_Specification (Scheme)) then
12422 Spec := Loop_Parameter_Specification (Scheme);
12423 Subt := Discrete_Subtype_Definition (Spec);
12425 if Present (Subt) then
12426 if Nkind (Subt) = N_Range then
12427 return Side_Effect_Free (Low_Bound (Subt))
12428 and then Side_Effect_Free (High_Bound (Subt));
12429 else
12430 -- subtype indication
12432 return True;
12433 end if;
12434 end if;
12435 end if;
12436 end if;
12437 end if;
12439 return False;
12440 end Side_Effect_Free_Loop;
12442 ----------------------------------
12443 -- Has_Non_Trivial_Precondition --
12444 ----------------------------------
12446 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
12447 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre,
12448 Class_Present => True);
12449 begin
12450 return
12451 Present (Pre)
12452 and then not Is_Entity_Name (Expression (Pre));
12453 end Has_Non_Trivial_Precondition;
12455 -------------------
12456 -- Has_Null_Body --
12457 -------------------
12459 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
12460 Body_Id : Entity_Id;
12461 Decl : Node_Id;
12462 Spec : Node_Id;
12463 Stmt1 : Node_Id;
12464 Stmt2 : Node_Id;
12466 begin
12467 Spec := Parent (Proc_Id);
12468 Decl := Parent (Spec);
12470 -- Retrieve the entity of the procedure body (e.g. invariant proc).
12472 if Nkind (Spec) = N_Procedure_Specification
12473 and then Nkind (Decl) = N_Subprogram_Declaration
12474 then
12475 Body_Id := Corresponding_Body (Decl);
12477 -- The body acts as a spec
12479 else
12480 Body_Id := Proc_Id;
12481 end if;
12483 -- The body will be generated later
12485 if No (Body_Id) then
12486 return False;
12487 end if;
12489 Spec := Parent (Body_Id);
12490 Decl := Parent (Spec);
12492 pragma Assert
12493 (Nkind (Spec) = N_Procedure_Specification
12494 and then Nkind (Decl) = N_Subprogram_Body);
12496 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
12498 -- Look for a null statement followed by an optional return
12499 -- statement.
12501 if Nkind (Stmt1) = N_Null_Statement then
12502 Stmt2 := Next (Stmt1);
12504 if Present (Stmt2) then
12505 return Nkind (Stmt2) = N_Simple_Return_Statement;
12506 else
12507 return True;
12508 end if;
12509 end if;
12511 return False;
12512 end Has_Null_Body;
12514 ------------------------
12515 -- Has_Null_Exclusion --
12516 ------------------------
12518 function Has_Null_Exclusion (N : Node_Id) return Boolean is
12519 begin
12520 case Nkind (N) is
12521 when N_Access_Definition
12522 | N_Access_Function_Definition
12523 | N_Access_Procedure_Definition
12524 | N_Access_To_Object_Definition
12525 | N_Allocator
12526 | N_Derived_Type_Definition
12527 | N_Function_Specification
12528 | N_Subtype_Declaration
12530 return Null_Exclusion_Present (N);
12532 when N_Component_Definition
12533 | N_Formal_Object_Declaration
12535 if Present (Subtype_Mark (N)) then
12536 return Null_Exclusion_Present (N);
12537 else pragma Assert (Present (Access_Definition (N)));
12538 return Null_Exclusion_Present (Access_Definition (N));
12539 end if;
12541 when N_Object_Renaming_Declaration =>
12542 if Present (Subtype_Mark (N)) then
12543 return Null_Exclusion_Present (N);
12544 elsif Present (Access_Definition (N)) then
12545 return Null_Exclusion_Present (Access_Definition (N));
12546 else
12547 return False; -- Case of no subtype in renaming (AI12-0275)
12548 end if;
12550 when N_Discriminant_Specification =>
12551 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
12552 return Null_Exclusion_Present (Discriminant_Type (N));
12553 else
12554 return Null_Exclusion_Present (N);
12555 end if;
12557 when N_Object_Declaration =>
12558 if Nkind (Object_Definition (N)) = N_Access_Definition then
12559 return Null_Exclusion_Present (Object_Definition (N));
12560 else
12561 return Null_Exclusion_Present (N);
12562 end if;
12564 when N_Parameter_Specification =>
12565 if Nkind (Parameter_Type (N)) = N_Access_Definition then
12566 return Null_Exclusion_Present (Parameter_Type (N))
12567 or else Null_Exclusion_Present (N);
12568 else
12569 return Null_Exclusion_Present (N);
12570 end if;
12572 when others =>
12573 return False;
12574 end case;
12575 end Has_Null_Exclusion;
12577 ------------------------
12578 -- Has_Null_Extension --
12579 ------------------------
12581 function Has_Null_Extension (T : Entity_Id) return Boolean is
12582 B : constant Entity_Id := Base_Type (T);
12583 Comps : Node_Id;
12584 Ext : Node_Id;
12586 begin
12587 if Nkind (Parent (B)) = N_Full_Type_Declaration
12588 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
12589 then
12590 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
12592 if Present (Ext) then
12593 if Null_Present (Ext) then
12594 return True;
12595 else
12596 Comps := Component_List (Ext);
12598 -- The null component list is rewritten during analysis to
12599 -- include the parent component. Any other component indicates
12600 -- that the extension was not originally null.
12602 return Null_Present (Comps)
12603 or else No (Next (First (Component_Items (Comps))));
12604 end if;
12605 else
12606 return False;
12607 end if;
12609 else
12610 return False;
12611 end if;
12612 end Has_Null_Extension;
12614 -------------------------
12615 -- Has_Null_Refinement --
12616 -------------------------
12618 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
12619 Constits : Elist_Id;
12621 begin
12622 pragma Assert (Ekind (Id) = E_Abstract_State);
12623 Constits := Refinement_Constituents (Id);
12625 -- For a refinement to be null, the state's sole constituent must be a
12626 -- null.
12628 return
12629 Present (Constits)
12630 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
12631 end Has_Null_Refinement;
12633 ------------------------------------------
12634 -- Has_Nonstatic_Class_Wide_Pre_Or_Post --
12635 ------------------------------------------
12637 function Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post
12638 (Subp : Entity_Id) return Boolean
12640 Disp_Type : constant Entity_Id := Find_Dispatching_Type (Subp);
12641 Prag : Node_Id;
12642 Pragma_Arg : Node_Id;
12644 begin
12645 if Present (Disp_Type)
12646 and then Is_Abstract_Type (Disp_Type)
12647 and then Present (Contract (Subp))
12648 then
12649 Prag := Pre_Post_Conditions (Contract (Subp));
12651 while Present (Prag) loop
12652 if Pragma_Name (Prag) in Name_Precondition | Name_Postcondition
12653 and then Class_Present (Prag)
12654 then
12655 Pragma_Arg :=
12656 Nlists.First
12657 (Pragma_Argument_Associations (Prag));
12659 if not Is_Static_Expression (Expression (Pragma_Arg)) then
12660 return True;
12661 end if;
12662 end if;
12664 Prag := Next_Pragma (Prag);
12665 end loop;
12666 end if;
12668 return False;
12669 end Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post;
12671 -------------------------------
12672 -- Has_Overriding_Initialize --
12673 -------------------------------
12675 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
12676 BT : constant Entity_Id := Base_Type (T);
12677 P : Elmt_Id;
12679 begin
12680 if Is_Controlled (BT) then
12681 if Is_RTU (Scope (BT), Ada_Finalization) then
12682 return False;
12684 elsif Present (Primitive_Operations (BT)) then
12685 P := First_Elmt (Primitive_Operations (BT));
12686 while Present (P) loop
12687 declare
12688 Init : constant Entity_Id := Node (P);
12689 Formal : constant Entity_Id := First_Formal (Init);
12690 begin
12691 if Ekind (Init) = E_Procedure
12692 and then Chars (Init) = Name_Initialize
12693 and then Comes_From_Source (Init)
12694 and then Present (Formal)
12695 and then Etype (Formal) = BT
12696 and then No (Next_Formal (Formal))
12697 and then (Ada_Version < Ada_2012
12698 or else not Null_Present (Parent (Init)))
12699 then
12700 return True;
12701 end if;
12702 end;
12704 Next_Elmt (P);
12705 end loop;
12706 end if;
12708 -- Here if type itself does not have a non-null Initialize operation:
12709 -- check immediate ancestor.
12711 if Is_Derived_Type (BT)
12712 and then Has_Overriding_Initialize (Etype (BT))
12713 then
12714 return True;
12715 end if;
12716 end if;
12718 return False;
12719 end Has_Overriding_Initialize;
12721 --------------------------------------
12722 -- Has_Preelaborable_Initialization --
12723 --------------------------------------
12725 function Has_Preelaborable_Initialization
12726 (E : Entity_Id;
12727 Preelab_Init_Expr : Node_Id := Empty) return Boolean
12729 Has_PE : Boolean;
12731 procedure Check_Components (E : Entity_Id);
12732 -- Check component/discriminant chain, sets Has_PE False if a component
12733 -- or discriminant does not meet the preelaborable initialization rules.
12735 function Type_Named_In_Preelab_Init_Expression
12736 (Typ : Entity_Id;
12737 Expr : Node_Id) return Boolean;
12738 -- Returns True iff Typ'Preelaborable_Initialization occurs in Expr
12739 -- (where Expr may be a conjunction of one or more P_I attributes).
12741 ----------------------
12742 -- Check_Components --
12743 ----------------------
12745 procedure Check_Components (E : Entity_Id) is
12746 Ent : Entity_Id;
12747 Exp : Node_Id;
12749 begin
12750 -- Loop through components and discriminants of record or protected
12751 -- type.
12753 Ent := First_Component_Or_Discriminant (E);
12754 while Present (Ent) loop
12756 case Ekind (Ent) is
12757 when E_Component =>
12759 -- Get default expression if any. If there is no declaration
12760 -- node, it means we have an internal entity. The parent and
12761 -- tag fields are examples of such entities. For such cases,
12762 -- we just test the type of the entity.
12764 if Present (Declaration_Node (Ent)) then
12765 Exp := Expression (Declaration_Node (Ent));
12766 else
12767 Exp := Empty;
12768 end if;
12770 when E_Discriminant =>
12772 -- Note: for a renamed discriminant, the Declaration_Node
12773 -- may point to the one from the ancestor, and have a
12774 -- different expression, so use the proper attribute to
12775 -- retrieve the expression from the derived constraint.
12777 Exp := Discriminant_Default_Value (Ent);
12779 when others =>
12780 raise Program_Error;
12781 end case;
12783 -- A component has PI if it has no default expression and the
12784 -- component type has PI.
12786 if No (Exp) then
12787 if not Has_Preelaborable_Initialization
12788 (Etype (Ent), Preelab_Init_Expr)
12789 then
12790 Has_PE := False;
12791 exit;
12792 end if;
12794 -- Require the default expression to be preelaborable
12796 elsif not Is_Preelaborable_Construct (Exp) then
12797 Has_PE := False;
12798 exit;
12799 end if;
12801 Next_Component_Or_Discriminant (Ent);
12802 end loop;
12803 end Check_Components;
12805 --------------------------------------
12806 -- Type_Named_In_Preelab_Expression --
12807 --------------------------------------
12809 function Type_Named_In_Preelab_Init_Expression
12810 (Typ : Entity_Id;
12811 Expr : Node_Id) return Boolean
12813 begin
12814 -- Return True if Expr is a Preelaborable_Initialization attribute
12815 -- and the prefix is a subtype that has the same type as Typ.
12817 if Nkind (Expr) = N_Attribute_Reference
12818 and then Attribute_Name (Expr) = Name_Preelaborable_Initialization
12819 and then Is_Entity_Name (Prefix (Expr))
12820 and then Base_Type (Entity (Prefix (Expr))) = Base_Type (Typ)
12821 then
12822 return True;
12824 -- In the case where Expr is a conjunction, test whether either
12825 -- operand is a Preelaborable_Initialization attribute whose prefix
12826 -- has the same type as Typ, and return True if so.
12828 elsif Nkind (Expr) = N_Op_And
12829 and then
12830 (Type_Named_In_Preelab_Init_Expression (Typ, Left_Opnd (Expr))
12831 or else
12832 Type_Named_In_Preelab_Init_Expression (Typ, Right_Opnd (Expr)))
12833 then
12834 return True;
12836 -- Typ not named in a Preelaborable_Initialization attribute of Expr
12838 else
12839 return False;
12840 end if;
12841 end Type_Named_In_Preelab_Init_Expression;
12843 -- Start of processing for Has_Preelaborable_Initialization
12845 begin
12846 -- Immediate return if already marked as known preelaborable init. This
12847 -- covers types for which this function has already been called once
12848 -- and returned True (in which case the result is cached), and also
12849 -- types to which a pragma Preelaborable_Initialization applies.
12851 if Known_To_Have_Preelab_Init (E) then
12852 return True;
12853 end if;
12855 -- If the type is a subtype representing a generic actual type, then
12856 -- test whether its base type has preelaborable initialization since
12857 -- the subtype representing the actual does not inherit this attribute
12858 -- from the actual or formal. (but maybe it should???)
12860 if Is_Generic_Actual_Type (E) then
12861 return Has_Preelaborable_Initialization (Base_Type (E));
12862 end if;
12864 -- All elementary types have preelaborable initialization
12866 if Is_Elementary_Type (E) then
12867 Has_PE := True;
12869 -- Array types have PI if the component type has PI
12871 elsif Is_Array_Type (E) then
12872 Has_PE := Has_Preelaborable_Initialization
12873 (Component_Type (E), Preelab_Init_Expr);
12875 -- A derived type has preelaborable initialization if its parent type
12876 -- has preelaborable initialization and (in the case of a derived record
12877 -- extension) if the non-inherited components all have preelaborable
12878 -- initialization. However, a user-defined controlled type with an
12879 -- overriding Initialize procedure does not have preelaborable
12880 -- initialization.
12882 elsif Is_Derived_Type (E) then
12884 -- When the rule of RM 10.2.1(11.8/5) applies, we presume a component
12885 -- of a generic formal derived type has preelaborable initialization.
12886 -- (See comment on spec of Has_Preelaborable_Initialization.)
12888 if Is_Generic_Type (E)
12889 and then Present (Preelab_Init_Expr)
12890 and then
12891 Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr)
12892 then
12893 return True;
12894 end if;
12896 -- If the derived type is a private extension then it doesn't have
12897 -- preelaborable initialization.
12899 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
12900 return False;
12901 end if;
12903 -- First check whether ancestor type has preelaborable initialization
12905 Has_PE := Has_Preelaborable_Initialization
12906 (Etype (Base_Type (E)), Preelab_Init_Expr);
12908 -- If OK, check extension components (if any)
12910 if Has_PE and then Is_Record_Type (E) then
12911 Check_Components (E);
12912 end if;
12914 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
12915 -- with a user defined Initialize procedure does not have PI. If
12916 -- the type is untagged, the control primitives come from a component
12917 -- that has already been checked.
12919 if Has_PE
12920 and then Is_Controlled (E)
12921 and then Is_Tagged_Type (E)
12922 and then Has_Overriding_Initialize (E)
12923 then
12924 Has_PE := False;
12925 end if;
12927 -- Private types not derived from a type having preelaborable init and
12928 -- that are not marked with pragma Preelaborable_Initialization do not
12929 -- have preelaborable initialization.
12931 elsif Is_Private_Type (E) then
12933 -- When the rule of RM 10.2.1(11.8/5) applies, we presume a component
12934 -- of a generic formal private type has preelaborable initialization.
12935 -- (See comment on spec of Has_Preelaborable_Initialization.)
12937 if Is_Generic_Type (E)
12938 and then Present (Preelab_Init_Expr)
12939 and then
12940 Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr)
12941 then
12942 return True;
12943 else
12944 return False;
12945 end if;
12947 -- Record type has PI if it is non private and all components have PI
12949 elsif Is_Record_Type (E) then
12950 Has_PE := True;
12951 Check_Components (E);
12953 -- Protected types must not have entries, and components must meet
12954 -- same set of rules as for record components.
12956 elsif Is_Protected_Type (E) then
12957 if Has_Entries (E) then
12958 Has_PE := False;
12959 else
12960 Has_PE := True;
12961 Check_Components (E);
12962 end if;
12964 -- Type System.Address always has preelaborable initialization
12966 elsif Is_RTE (E, RE_Address) then
12967 Has_PE := True;
12969 -- In all other cases, type does not have preelaborable initialization
12971 else
12972 return False;
12973 end if;
12975 -- If type has preelaborable initialization, cache result
12977 if Has_PE then
12978 Set_Known_To_Have_Preelab_Init (E);
12979 end if;
12981 return Has_PE;
12982 end Has_Preelaborable_Initialization;
12984 ----------------
12985 -- Has_Prefix --
12986 ----------------
12988 function Has_Prefix (N : Node_Id) return Boolean is
12989 begin
12990 return Nkind (N) in
12991 N_Attribute_Reference | N_Expanded_Name | N_Explicit_Dereference |
12992 N_Indexed_Component | N_Reference | N_Selected_Component |
12993 N_Slice;
12994 end Has_Prefix;
12996 ---------------------------
12997 -- Has_Private_Component --
12998 ---------------------------
13000 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
13001 Btype : Entity_Id := Base_Type (Type_Id);
13002 Component : Entity_Id;
13004 begin
13005 if Error_Posted (Type_Id)
13006 or else Error_Posted (Btype)
13007 then
13008 return False;
13009 end if;
13011 if Is_Class_Wide_Type (Btype) then
13012 Btype := Root_Type (Btype);
13013 end if;
13015 if Is_Private_Type (Btype) then
13016 declare
13017 UT : constant Entity_Id := Underlying_Type (Btype);
13018 begin
13019 if No (UT) then
13020 if No (Full_View (Btype)) then
13021 return not Is_Generic_Type (Btype)
13022 and then
13023 not Is_Generic_Type (Root_Type (Btype));
13024 else
13025 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
13026 end if;
13027 else
13028 return not Is_Frozen (UT) and then Has_Private_Component (UT);
13029 end if;
13030 end;
13032 elsif Is_Array_Type (Btype) then
13033 return Has_Private_Component (Component_Type (Btype));
13035 elsif Is_Record_Type (Btype) then
13036 Component := First_Component (Btype);
13037 while Present (Component) loop
13038 if Has_Private_Component (Etype (Component)) then
13039 return True;
13040 end if;
13042 Next_Component (Component);
13043 end loop;
13045 return False;
13047 elsif Is_Protected_Type (Btype)
13048 and then Present (Corresponding_Record_Type (Btype))
13049 then
13050 return Has_Private_Component (Corresponding_Record_Type (Btype));
13052 else
13053 return False;
13054 end if;
13055 end Has_Private_Component;
13057 --------------------------------
13058 -- Has_Relaxed_Initialization --
13059 --------------------------------
13061 function Has_Relaxed_Initialization (E : Entity_Id) return Boolean is
13063 function Denotes_Relaxed_Parameter
13064 (Expr : Node_Id;
13065 Param : Entity_Id)
13066 return Boolean;
13067 -- Returns True iff expression Expr denotes a formal parameter or
13068 -- function Param (through its attribute Result).
13070 -------------------------------
13071 -- Denotes_Relaxed_Parameter --
13072 -------------------------------
13074 function Denotes_Relaxed_Parameter
13075 (Expr : Node_Id;
13076 Param : Entity_Id) return Boolean is
13077 begin
13078 if Nkind (Expr) in N_Identifier | N_Expanded_Name then
13079 return Entity (Expr) = Param;
13080 else
13081 pragma Assert (Is_Attribute_Result (Expr));
13082 return Entity (Prefix (Expr)) = Param;
13083 end if;
13084 end Denotes_Relaxed_Parameter;
13086 -- Start of processing for Has_Relaxed_Initialization
13088 begin
13089 -- When analyzing, we checked all syntax legality rules for the aspect
13090 -- Relaxed_Initialization, but didn't store the property anywhere (e.g.
13091 -- as an Einfo flag). To query the property we look directly at the AST,
13092 -- but now without any syntactic checks.
13094 case Ekind (E) is
13095 -- Constants have this aspect attached directly; for deferred
13096 -- constants, the aspect is attached to the partial view.
13098 when E_Constant =>
13099 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13101 -- Variables have this aspect attached directly
13103 when E_Variable =>
13104 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13106 -- Types have this aspect attached directly (though we only allow it
13107 -- to be specified for the first subtype). For private types, the
13108 -- aspect is attached to the partial view.
13110 when Type_Kind =>
13111 pragma Assert (Is_First_Subtype (E));
13112 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13114 -- Formal parameters and functions have the Relaxed_Initialization
13115 -- aspect attached to the subprogram entity and must be listed in
13116 -- the aspect expression.
13118 when Formal_Kind
13119 | E_Function
13121 declare
13122 Subp_Id : Entity_Id;
13123 Aspect_Expr : Node_Id;
13124 Param_Expr : Node_Id;
13125 Assoc : Node_Id;
13127 begin
13128 if Is_Formal (E) then
13129 Subp_Id := Scope (E);
13130 else
13131 Subp_Id := E;
13132 end if;
13134 if Has_Aspect (Subp_Id, Aspect_Relaxed_Initialization) then
13135 Aspect_Expr :=
13136 Find_Value_Of_Aspect
13137 (Subp_Id, Aspect_Relaxed_Initialization);
13139 -- Aspect expression is either an aggregate with an optional
13140 -- Boolean expression (which defaults to True), e.g.:
13142 -- function F (X : Integer) return Integer
13143 -- with Relaxed_Initialization => (X => True, F'Result);
13145 if Nkind (Aspect_Expr) = N_Aggregate then
13147 if Present (Component_Associations (Aspect_Expr)) then
13148 Assoc := First (Component_Associations (Aspect_Expr));
13150 while Present (Assoc) loop
13151 if Denotes_Relaxed_Parameter
13152 (First (Choices (Assoc)), E)
13153 then
13154 return
13155 Is_True
13156 (Static_Boolean (Expression (Assoc)));
13157 end if;
13159 Next (Assoc);
13160 end loop;
13161 end if;
13163 Param_Expr := First (Expressions (Aspect_Expr));
13165 while Present (Param_Expr) loop
13166 if Denotes_Relaxed_Parameter (Param_Expr, E) then
13167 return True;
13168 end if;
13170 Next (Param_Expr);
13171 end loop;
13173 return False;
13175 -- or it is a single identifier, e.g.:
13177 -- function F (X : Integer) return Integer
13178 -- with Relaxed_Initialization => X;
13180 else
13181 return Denotes_Relaxed_Parameter (Aspect_Expr, E);
13182 end if;
13183 else
13184 return False;
13185 end if;
13186 end;
13188 when others =>
13189 raise Program_Error;
13190 end case;
13191 end Has_Relaxed_Initialization;
13193 ----------------------
13194 -- Has_Signed_Zeros --
13195 ----------------------
13197 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
13198 begin
13199 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
13200 end Has_Signed_Zeros;
13202 ------------------------------
13203 -- Has_Significant_Contract --
13204 ------------------------------
13206 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
13207 Subp_Nam : constant Name_Id := Chars (Subp_Id);
13209 begin
13210 -- _Finalizer procedure
13212 if Subp_Nam = Name_uFinalizer then
13213 return False;
13215 -- _Wrapped_Statements procedure which gets generated as part of the
13216 -- expansion of postconditions.
13218 elsif Subp_Nam = Name_uWrapped_Statements then
13219 return False;
13221 -- Predicate function
13223 elsif Ekind (Subp_Id) = E_Function
13224 and then Is_Predicate_Function (Subp_Id)
13225 then
13226 return False;
13228 -- TSS subprogram
13230 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
13231 return False;
13233 else
13234 return True;
13235 end if;
13236 end Has_Significant_Contract;
13238 -----------------------------
13239 -- Has_Static_Array_Bounds --
13240 -----------------------------
13242 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
13243 All_Static : Boolean;
13244 Dummy : Boolean;
13246 begin
13247 Examine_Array_Bounds (Typ, All_Static, Dummy);
13249 return All_Static;
13250 end Has_Static_Array_Bounds;
13252 -----------------------------------
13253 -- Has_Static_Empty_Array_Bounds --
13254 -----------------------------------
13256 function Has_Static_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
13257 All_Static : Boolean;
13258 Has_Empty : Boolean;
13260 begin
13261 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
13263 return Has_Empty;
13264 end Has_Static_Empty_Array_Bounds;
13266 ---------------------------------------
13267 -- Has_Static_Non_Empty_Array_Bounds --
13268 ---------------------------------------
13270 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
13271 All_Static : Boolean;
13272 Has_Empty : Boolean;
13274 begin
13275 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
13277 return All_Static and not Has_Empty;
13278 end Has_Static_Non_Empty_Array_Bounds;
13280 ----------------
13281 -- Has_Stream --
13282 ----------------
13284 function Has_Stream (T : Entity_Id) return Boolean is
13285 E : Entity_Id;
13287 begin
13288 if No (T) then
13289 return False;
13291 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
13292 return True;
13294 elsif Is_Array_Type (T) then
13295 return Has_Stream (Component_Type (T));
13297 elsif Is_Record_Type (T) then
13298 E := First_Component (T);
13299 while Present (E) loop
13300 if Has_Stream (Etype (E)) then
13301 return True;
13302 else
13303 Next_Component (E);
13304 end if;
13305 end loop;
13307 return False;
13309 elsif Is_Private_Type (T) then
13310 return Has_Stream (Underlying_Type (T));
13312 else
13313 return False;
13314 end if;
13315 end Has_Stream;
13317 ----------------
13318 -- Has_Suffix --
13319 ----------------
13321 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
13322 begin
13323 Get_Name_String (Chars (E));
13324 return Name_Buffer (Name_Len) = Suffix;
13325 end Has_Suffix;
13327 ----------------
13328 -- Add_Suffix --
13329 ----------------
13331 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
13332 begin
13333 Get_Name_String (Chars (E));
13334 Add_Char_To_Name_Buffer (Suffix);
13335 return Name_Find;
13336 end Add_Suffix;
13338 -------------------
13339 -- Remove_Suffix --
13340 -------------------
13342 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
13343 begin
13344 pragma Assert (Has_Suffix (E, Suffix));
13345 Get_Name_String (Chars (E));
13346 Name_Len := Name_Len - 1;
13347 return Name_Find;
13348 end Remove_Suffix;
13350 ----------------------------------
13351 -- Replace_Null_By_Null_Address --
13352 ----------------------------------
13354 procedure Replace_Null_By_Null_Address (N : Node_Id) is
13355 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
13356 -- Replace operand Op with a reference to Null_Address when the operand
13357 -- denotes a null Address. Other_Op denotes the other operand.
13359 --------------------------
13360 -- Replace_Null_Operand --
13361 --------------------------
13363 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
13364 begin
13365 -- Check the type of the complementary operand since the N_Null node
13366 -- has not been decorated yet.
13368 if Nkind (Op) = N_Null
13369 and then Is_Descendant_Of_Address (Etype (Other_Op))
13370 then
13371 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
13372 end if;
13373 end Replace_Null_Operand;
13375 -- Start of processing for Replace_Null_By_Null_Address
13377 begin
13378 pragma Assert (Relaxed_RM_Semantics);
13379 pragma Assert (Nkind (N) in N_Null | N_Op_Compare);
13381 if Nkind (N) = N_Null then
13382 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
13384 else
13385 declare
13386 L : constant Node_Id := Left_Opnd (N);
13387 R : constant Node_Id := Right_Opnd (N);
13389 begin
13390 Replace_Null_Operand (L, Other_Op => R);
13391 Replace_Null_Operand (R, Other_Op => L);
13392 end;
13393 end if;
13394 end Replace_Null_By_Null_Address;
13396 --------------------------
13397 -- Has_Tagged_Component --
13398 --------------------------
13400 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
13401 Comp : Entity_Id;
13403 begin
13404 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
13405 return Has_Tagged_Component (Underlying_Type (Typ));
13407 elsif Is_Array_Type (Typ) then
13408 return Has_Tagged_Component (Component_Type (Typ));
13410 elsif Is_Tagged_Type (Typ) then
13411 return True;
13413 elsif Is_Record_Type (Typ) then
13414 Comp := First_Component (Typ);
13415 while Present (Comp) loop
13416 if Has_Tagged_Component (Etype (Comp)) then
13417 return True;
13418 end if;
13420 Next_Component (Comp);
13421 end loop;
13423 return False;
13425 else
13426 return False;
13427 end if;
13428 end Has_Tagged_Component;
13430 -----------------------------
13431 -- Has_Undefined_Reference --
13432 -----------------------------
13434 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
13435 Has_Undef_Ref : Boolean := False;
13436 -- Flag set when expression Expr contains at least one undefined
13437 -- reference.
13439 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
13440 -- Determine whether N denotes a reference and if it does, whether it is
13441 -- undefined.
13443 ----------------------------
13444 -- Is_Undefined_Reference --
13445 ----------------------------
13447 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
13448 begin
13449 if Is_Entity_Name (N)
13450 and then Present (Entity (N))
13451 and then Entity (N) = Any_Id
13452 then
13453 Has_Undef_Ref := True;
13454 return Abandon;
13455 end if;
13457 return OK;
13458 end Is_Undefined_Reference;
13460 procedure Find_Undefined_References is
13461 new Traverse_Proc (Is_Undefined_Reference);
13463 -- Start of processing for Has_Undefined_Reference
13465 begin
13466 Find_Undefined_References (Expr);
13468 return Has_Undef_Ref;
13469 end Has_Undefined_Reference;
13471 ----------------------------------------
13472 -- Has_Effectively_Volatile_Component --
13473 ----------------------------------------
13475 function Has_Effectively_Volatile_Component
13476 (Typ : Entity_Id) return Boolean
13478 Comp : Entity_Id;
13480 begin
13481 if Has_Volatile_Components (Typ) then
13482 return True;
13484 elsif Is_Array_Type (Typ) then
13485 return Is_Effectively_Volatile (Component_Type (Typ));
13487 elsif Is_Record_Type (Typ) then
13488 Comp := First_Component (Typ);
13489 while Present (Comp) loop
13490 if Is_Effectively_Volatile (Etype (Comp)) then
13491 return True;
13492 end if;
13494 Next_Component (Comp);
13495 end loop;
13496 end if;
13498 return False;
13499 end Has_Effectively_Volatile_Component;
13501 ------------------------
13502 -- Has_Enabled_Aspect --
13503 ------------------------
13505 function Has_Enabled_Aspect
13506 (Id : Entity_Id;
13507 A : Aspect_Id)
13508 return Boolean
13510 Asp : constant Node_Id := Find_Aspect (Id, A);
13511 begin
13512 if Present (Asp) then
13513 if Present (Expression (Asp)) then
13514 return Is_True (Static_Boolean (Expression (Asp)));
13515 else
13516 return True;
13517 end if;
13518 else
13519 return False;
13520 end if;
13521 end Has_Enabled_Aspect;
13523 ----------------------------
13524 -- Has_Volatile_Component --
13525 ----------------------------
13527 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
13528 Comp : Entity_Id;
13530 begin
13531 if Has_Volatile_Components (Typ) then
13532 return True;
13534 elsif Is_Array_Type (Typ) then
13535 return Is_Volatile (Component_Type (Typ));
13537 elsif Is_Record_Type (Typ) then
13538 Comp := First_Component (Typ);
13539 while Present (Comp) loop
13540 if Is_Volatile_Object_Ref (Comp) then
13541 return True;
13542 end if;
13544 Next_Component (Comp);
13545 end loop;
13546 end if;
13548 return False;
13549 end Has_Volatile_Component;
13551 -------------------------
13552 -- Implementation_Kind --
13553 -------------------------
13555 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
13556 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
13557 Arg : Node_Id;
13558 begin
13559 pragma Assert (Present (Impl_Prag));
13560 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
13561 return Chars (Get_Pragma_Arg (Arg));
13562 end Implementation_Kind;
13564 --------------------------
13565 -- Implements_Interface --
13566 --------------------------
13568 function Implements_Interface
13569 (Typ_Ent : Entity_Id;
13570 Iface_Ent : Entity_Id;
13571 Exclude_Parents : Boolean := False) return Boolean
13573 Ifaces_List : Elist_Id;
13574 Elmt : Elmt_Id;
13575 Iface : Entity_Id := Base_Type (Iface_Ent);
13576 Typ : Entity_Id := Base_Type (Typ_Ent);
13578 begin
13579 if Is_Class_Wide_Type (Typ) then
13580 Typ := Root_Type (Typ);
13581 end if;
13583 if not Has_Interfaces (Typ) then
13584 return False;
13585 end if;
13587 if Is_Class_Wide_Type (Iface) then
13588 Iface := Root_Type (Iface);
13589 end if;
13591 Collect_Interfaces (Typ, Ifaces_List);
13593 Elmt := First_Elmt (Ifaces_List);
13594 while Present (Elmt) loop
13595 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
13596 and then Exclude_Parents
13597 then
13598 null;
13600 elsif Node (Elmt) = Iface then
13601 return True;
13602 end if;
13604 Next_Elmt (Elmt);
13605 end loop;
13607 return False;
13608 end Implements_Interface;
13610 --------------------------------
13611 -- Implicitly_Designated_Type --
13612 --------------------------------
13614 function Implicitly_Designated_Type (Typ : Entity_Id) return Entity_Id is
13615 Desig : constant Entity_Id := Designated_Type (Typ);
13617 begin
13618 -- An implicit dereference is a legal occurrence of an incomplete type
13619 -- imported through a limited_with clause, if the full view is visible.
13621 if Is_Incomplete_Type (Desig)
13622 and then From_Limited_With (Desig)
13623 and then not From_Limited_With (Scope (Desig))
13624 and then
13625 (Is_Immediately_Visible (Scope (Desig))
13626 or else
13627 (Is_Child_Unit (Scope (Desig))
13628 and then Is_Visible_Lib_Unit (Scope (Desig))))
13629 then
13630 return Available_View (Desig);
13631 else
13632 return Desig;
13633 end if;
13634 end Implicitly_Designated_Type;
13636 ------------------------------------
13637 -- In_Assertion_Expression_Pragma --
13638 ------------------------------------
13640 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
13641 Par : Node_Id;
13642 Prag : Node_Id := Empty;
13644 begin
13645 -- Climb the parent chain looking for an enclosing pragma
13647 Par := N;
13648 while Present (Par) loop
13649 if Nkind (Par) = N_Pragma then
13650 Prag := Par;
13651 exit;
13653 -- Precondition-like pragmas are expanded into if statements, check
13654 -- the original node instead.
13656 elsif Nkind (Original_Node (Par)) = N_Pragma then
13657 Prag := Original_Node (Par);
13658 exit;
13660 -- The expansion of attribute 'Old generates a constant to capture
13661 -- the result of the prefix. If the parent traversal reaches
13662 -- one of these constants, then the node technically came from a
13663 -- postcondition-like pragma. Note that the Ekind is not tested here
13664 -- because N may be the expression of an object declaration which is
13665 -- currently being analyzed. Such objects carry Ekind of E_Void.
13667 elsif Nkind (Par) = N_Object_Declaration
13668 and then Constant_Present (Par)
13669 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
13670 then
13671 return True;
13673 -- Prevent the search from going too far
13675 elsif Is_Body_Or_Package_Declaration (Par) then
13676 return False;
13677 end if;
13679 Par := Parent (Par);
13680 end loop;
13682 return
13683 Present (Prag)
13684 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
13685 end In_Assertion_Expression_Pragma;
13687 -------------------
13688 -- In_Check_Node --
13689 -------------------
13691 function In_Check_Node (N : Node_Id) return Boolean is
13692 Par : Node_Id := Parent (N);
13693 begin
13694 while Present (Par) loop
13695 if Nkind (Par) in N_Raise_xxx_Error then
13696 return True;
13698 -- Prevent the search from going too far
13700 elsif Is_Body_Or_Package_Declaration (Par) then
13701 return False;
13703 else
13704 Par := Parent (Par);
13705 end if;
13706 end loop;
13708 return False;
13709 end In_Check_Node;
13711 -------------------------------
13712 -- In_Generic_Formal_Package --
13713 -------------------------------
13715 function In_Generic_Formal_Package (E : Entity_Id) return Boolean is
13716 Par : Node_Id;
13718 begin
13719 Par := Parent (E);
13720 while Present (Par) loop
13721 if Nkind (Par) = N_Formal_Package_Declaration
13722 or else Nkind (Original_Node (Par)) = N_Formal_Package_Declaration
13723 then
13724 return True;
13725 end if;
13727 Par := Parent (Par);
13728 end loop;
13730 return False;
13731 end In_Generic_Formal_Package;
13733 ----------------------
13734 -- In_Generic_Scope --
13735 ----------------------
13737 function In_Generic_Scope (E : Entity_Id) return Boolean is
13738 S : Entity_Id;
13740 begin
13741 S := Scope (E);
13742 while Present (S) and then S /= Standard_Standard loop
13743 if Is_Generic_Unit (S) then
13744 return True;
13745 end if;
13747 S := Scope (S);
13748 end loop;
13750 return False;
13751 end In_Generic_Scope;
13753 -----------------
13754 -- In_Instance --
13755 -----------------
13757 function In_Instance return Boolean is
13758 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
13759 S : Entity_Id;
13761 begin
13762 S := Current_Scope;
13763 while Present (S) and then S /= Standard_Standard loop
13764 if Is_Generic_Instance (S) then
13766 -- A child instance is always compiled in the context of a parent
13767 -- instance. Nevertheless, its actuals must not be analyzed in an
13768 -- instance context. We detect this case by examining the current
13769 -- compilation unit, which must be a child instance, and checking
13770 -- that it has not been analyzed yet.
13772 if Is_Child_Unit (Curr_Unit)
13773 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
13774 N_Package_Instantiation
13775 and then Ekind (Curr_Unit) = E_Void
13776 then
13777 return False;
13778 else
13779 return True;
13780 end if;
13781 end if;
13783 S := Scope (S);
13784 end loop;
13786 return False;
13787 end In_Instance;
13789 ----------------------
13790 -- In_Instance_Body --
13791 ----------------------
13793 function In_Instance_Body return Boolean is
13794 S : Entity_Id;
13796 begin
13797 S := Current_Scope;
13798 while Present (S) and then S /= Standard_Standard loop
13799 if Ekind (S) in E_Function | E_Procedure
13800 and then Is_Generic_Instance (S)
13801 then
13802 return True;
13804 elsif Ekind (S) = E_Package
13805 and then In_Package_Body (S)
13806 and then Is_Generic_Instance (S)
13807 then
13808 return True;
13809 end if;
13811 S := Scope (S);
13812 end loop;
13814 return False;
13815 end In_Instance_Body;
13817 -----------------------------
13818 -- In_Instance_Not_Visible --
13819 -----------------------------
13821 function In_Instance_Not_Visible return Boolean is
13822 S : Entity_Id;
13824 begin
13825 S := Current_Scope;
13826 while Present (S) and then S /= Standard_Standard loop
13827 if Ekind (S) in E_Function | E_Procedure
13828 and then Is_Generic_Instance (S)
13829 then
13830 return True;
13832 elsif Ekind (S) = E_Package
13833 and then (In_Package_Body (S) or else In_Private_Part (S))
13834 and then Is_Generic_Instance (S)
13835 then
13836 return True;
13837 end if;
13839 S := Scope (S);
13840 end loop;
13842 return False;
13843 end In_Instance_Not_Visible;
13845 ------------------------------
13846 -- In_Instance_Visible_Part --
13847 ------------------------------
13849 function In_Instance_Visible_Part
13850 (Id : Entity_Id := Current_Scope) return Boolean
13852 Inst : Entity_Id;
13854 begin
13855 Inst := Id;
13856 while Present (Inst) and then Inst /= Standard_Standard loop
13857 if Ekind (Inst) = E_Package
13858 and then Is_Generic_Instance (Inst)
13859 and then not In_Package_Body (Inst)
13860 and then not In_Private_Part (Inst)
13861 then
13862 return True;
13863 end if;
13865 Inst := Scope (Inst);
13866 end loop;
13868 return False;
13869 end In_Instance_Visible_Part;
13871 ---------------------
13872 -- In_Package_Body --
13873 ---------------------
13875 function In_Package_Body return Boolean is
13876 S : Entity_Id;
13878 begin
13879 S := Current_Scope;
13880 while Present (S) and then S /= Standard_Standard loop
13881 if Ekind (S) = E_Package and then In_Package_Body (S) then
13882 return True;
13883 else
13884 S := Scope (S);
13885 end if;
13886 end loop;
13888 return False;
13889 end In_Package_Body;
13891 --------------------------
13892 -- In_Pragma_Expression --
13893 --------------------------
13895 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
13896 P : Node_Id;
13897 begin
13898 P := Parent (N);
13899 loop
13900 if No (P) then
13901 return False;
13903 -- Prevent the search from going too far
13905 elsif Is_Body_Or_Package_Declaration (P) then
13906 return False;
13908 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
13909 return True;
13911 else
13912 P := Parent (P);
13913 end if;
13914 end loop;
13915 end In_Pragma_Expression;
13917 ---------------------------
13918 -- In_Pre_Post_Condition --
13919 ---------------------------
13921 function In_Pre_Post_Condition
13922 (N : Node_Id; Class_Wide_Only : Boolean := False) return Boolean
13924 Par : Node_Id;
13925 Prag : Node_Id := Empty;
13926 Prag_Id : Pragma_Id;
13928 begin
13929 -- Climb the parent chain looking for an enclosing pragma
13931 Par := N;
13932 while Present (Par) loop
13933 if Nkind (Par) = N_Pragma then
13934 Prag := Par;
13935 exit;
13937 -- Prevent the search from going too far
13939 elsif Is_Body_Or_Package_Declaration (Par) then
13940 exit;
13941 end if;
13943 Par := Parent (Par);
13944 end loop;
13946 if Present (Prag) then
13947 Prag_Id := Get_Pragma_Id (Prag);
13949 if Class_Wide_Only then
13950 return
13951 Prag_Id = Pragma_Post_Class
13952 or else Prag_Id = Pragma_Pre_Class
13953 or else (Class_Present (Prag)
13954 and then (Prag_Id = Pragma_Post
13955 or else Prag_Id = Pragma_Postcondition
13956 or else Prag_Id = Pragma_Pre
13957 or else Prag_Id = Pragma_Precondition));
13958 else
13959 return
13960 Prag_Id = Pragma_Post
13961 or else Prag_Id = Pragma_Post_Class
13962 or else Prag_Id = Pragma_Postcondition
13963 or else Prag_Id = Pragma_Pre
13964 or else Prag_Id = Pragma_Pre_Class
13965 or else Prag_Id = Pragma_Precondition;
13966 end if;
13968 -- Otherwise the node is not enclosed by a pre/postcondition pragma
13970 else
13971 return False;
13972 end if;
13973 end In_Pre_Post_Condition;
13975 ------------------------------
13976 -- In_Quantified_Expression --
13977 ------------------------------
13979 function In_Quantified_Expression (N : Node_Id) return Boolean is
13980 P : Node_Id;
13981 begin
13982 P := Parent (N);
13983 loop
13984 if No (P) then
13985 return False;
13987 -- Prevent the search from going too far
13989 elsif Is_Body_Or_Package_Declaration (P) then
13990 return False;
13992 elsif Nkind (P) = N_Quantified_Expression then
13993 return True;
13994 else
13995 P := Parent (P);
13996 end if;
13997 end loop;
13998 end In_Quantified_Expression;
14000 -------------------------------------
14001 -- In_Reverse_Storage_Order_Object --
14002 -------------------------------------
14004 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
14005 Pref : Node_Id;
14006 Btyp : Entity_Id := Empty;
14008 begin
14009 -- Climb up indexed components
14011 Pref := N;
14012 loop
14013 case Nkind (Pref) is
14014 when N_Selected_Component =>
14015 Pref := Prefix (Pref);
14016 exit;
14018 when N_Indexed_Component =>
14019 Pref := Prefix (Pref);
14021 when others =>
14022 Pref := Empty;
14023 exit;
14024 end case;
14025 end loop;
14027 if Present (Pref) then
14028 Btyp := Base_Type (Etype (Pref));
14029 end if;
14031 return Present (Btyp)
14032 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
14033 and then Reverse_Storage_Order (Btyp);
14034 end In_Reverse_Storage_Order_Object;
14036 ------------------------------
14037 -- In_Same_Declarative_Part --
14038 ------------------------------
14040 function In_Same_Declarative_Part
14041 (Context : Node_Id;
14042 N : Node_Id) return Boolean
14044 Cont : Node_Id := Context;
14045 Nod : Node_Id;
14047 begin
14048 if Nkind (Cont) = N_Compilation_Unit_Aux then
14049 Cont := Parent (Cont);
14050 end if;
14052 Nod := Parent (N);
14053 while Present (Nod) loop
14054 if Nod = Cont then
14055 return True;
14057 elsif Nkind (Nod) in N_Accept_Statement
14058 | N_Block_Statement
14059 | N_Compilation_Unit
14060 | N_Entry_Body
14061 | N_Package_Body
14062 | N_Package_Declaration
14063 | N_Protected_Body
14064 | N_Subprogram_Body
14065 | N_Task_Body
14066 then
14067 return False;
14069 elsif Nkind (Nod) = N_Subunit then
14070 Nod := Corresponding_Stub (Nod);
14072 else
14073 Nod := Parent (Nod);
14074 end if;
14075 end loop;
14077 return False;
14078 end In_Same_Declarative_Part;
14080 --------------------------------------
14081 -- In_Subprogram_Or_Concurrent_Unit --
14082 --------------------------------------
14084 function In_Subprogram_Or_Concurrent_Unit return Boolean is
14085 E : Entity_Id;
14086 K : Entity_Kind;
14088 begin
14089 -- Use scope chain to check successively outer scopes
14091 E := Current_Scope;
14092 loop
14093 K := Ekind (E);
14095 if K in Subprogram_Kind
14096 or else K in Concurrent_Kind
14097 or else K in Generic_Subprogram_Kind
14098 then
14099 return True;
14101 elsif E = Standard_Standard then
14102 return False;
14103 end if;
14105 E := Scope (E);
14106 end loop;
14107 end In_Subprogram_Or_Concurrent_Unit;
14109 ----------------
14110 -- In_Subtree --
14111 ----------------
14113 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
14114 Curr : Node_Id;
14116 begin
14117 Curr := N;
14118 while Present (Curr) loop
14119 if Curr = Root then
14120 return True;
14121 end if;
14123 Curr := Parent (Curr);
14124 end loop;
14126 return False;
14127 end In_Subtree;
14129 ----------------
14130 -- In_Subtree --
14131 ----------------
14133 function In_Subtree
14134 (N : Node_Id;
14135 Root1 : Node_Id;
14136 Root2 : Node_Id) return Boolean
14138 Curr : Node_Id;
14140 begin
14141 Curr := N;
14142 while Present (Curr) loop
14143 if Curr = Root1 or else Curr = Root2 then
14144 return True;
14145 end if;
14147 Curr := Parent (Curr);
14148 end loop;
14150 return False;
14151 end In_Subtree;
14153 ---------------------
14154 -- In_Return_Value --
14155 ---------------------
14157 function In_Return_Value (Expr : Node_Id) return Boolean is
14158 Par : Node_Id;
14159 Prev_Par : Node_Id;
14160 Pre : Node_Id;
14161 In_Function_Call : Boolean := False;
14163 begin
14164 -- Move through parent nodes to determine if Expr contributes to the
14165 -- return value of the current subprogram.
14167 Par := Expr;
14168 Prev_Par := Empty;
14169 while Present (Par) loop
14171 case Nkind (Par) is
14172 -- Ignore ranges and they don't contribute to the result
14174 when N_Range =>
14175 return False;
14177 -- An object declaration whose parent is an extended return
14178 -- statement is a return object.
14180 when N_Object_Declaration =>
14181 if Present (Parent (Par))
14182 and then Nkind (Parent (Par)) = N_Extended_Return_Statement
14183 then
14184 return True;
14185 end if;
14187 -- We hit a simple return statement, so we know we are in one
14189 when N_Simple_Return_Statement =>
14190 return True;
14192 -- Only include one nexting level of function calls
14194 when N_Function_Call =>
14195 if not In_Function_Call then
14196 In_Function_Call := True;
14198 -- When the function return type has implicit dereference
14199 -- specified we know it cannot directly contribute to the
14200 -- return value.
14202 if Present (Etype (Par))
14203 and then Has_Implicit_Dereference
14204 (Get_Full_View (Etype (Par)))
14205 then
14206 return False;
14207 end if;
14208 else
14209 return False;
14210 end if;
14212 -- Check if we are on the right-hand side of an assignment
14213 -- statement to a return object.
14215 -- This is not specified in the RM ???
14217 when N_Assignment_Statement =>
14218 if Prev_Par = Name (Par) then
14219 return False;
14220 end if;
14222 Pre := Name (Par);
14223 while Present (Pre) loop
14224 if Is_Entity_Name (Pre)
14225 and then Is_Return_Object (Entity (Pre))
14226 then
14227 return True;
14228 end if;
14230 exit when Nkind (Pre) not in N_Selected_Component
14231 | N_Indexed_Component
14232 | N_Slice;
14234 Pre := Prefix (Pre);
14235 end loop;
14237 -- Otherwise, we hit a master which was not relevant
14239 when others =>
14240 if Is_Master (Par) then
14241 return False;
14242 end if;
14243 end case;
14245 -- Iterate up to the next parent, keeping track of the previous one
14247 Prev_Par := Par;
14248 Par := Parent (Par);
14249 end loop;
14251 return False;
14252 end In_Return_Value;
14254 -----------------------------------------
14255 -- In_Statement_Condition_With_Actions --
14256 -----------------------------------------
14258 function In_Statement_Condition_With_Actions (N : Node_Id) return Boolean is
14259 Prev : Node_Id := N;
14260 P : Node_Id := Parent (N);
14261 -- P and Prev will be used for traversing the AST, while maintaining an
14262 -- invariant that P = Parent (Prev).
14263 begin
14264 while Present (P) loop
14265 if Nkind (P) = N_Iteration_Scheme
14266 and then Prev = Condition (P)
14267 then
14268 return True;
14270 elsif Nkind (P) = N_Elsif_Part
14271 and then Prev = Condition (P)
14272 then
14273 return True;
14275 -- No point in going beyond statements
14277 elsif Nkind (N) in N_Statement_Other_Than_Procedure_Call
14278 | N_Procedure_Call_Statement
14279 then
14280 exit;
14282 -- Prevent the search from going too far
14284 elsif Is_Body_Or_Package_Declaration (P) then
14285 exit;
14286 end if;
14288 Prev := P;
14289 P := Parent (P);
14290 end loop;
14292 return False;
14293 end In_Statement_Condition_With_Actions;
14295 ---------------------
14296 -- In_Visible_Part --
14297 ---------------------
14299 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
14300 begin
14301 return Is_Package_Or_Generic_Package (Scope_Id)
14302 and then In_Open_Scopes (Scope_Id)
14303 and then not In_Package_Body (Scope_Id)
14304 and then not In_Private_Part (Scope_Id);
14305 end In_Visible_Part;
14307 --------------------------------
14308 -- Incomplete_Or_Partial_View --
14309 --------------------------------
14311 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
14312 S : constant Entity_Id := Scope (Id);
14314 function Inspect_Decls
14315 (Decls : List_Id;
14316 Taft : Boolean := False) return Entity_Id;
14317 -- Check whether a declarative region contains the incomplete or partial
14318 -- view of Id.
14320 -------------------
14321 -- Inspect_Decls --
14322 -------------------
14324 function Inspect_Decls
14325 (Decls : List_Id;
14326 Taft : Boolean := False) return Entity_Id
14328 Decl : Node_Id;
14329 Match : Node_Id;
14331 begin
14332 Decl := First (Decls);
14333 while Present (Decl) loop
14334 Match := Empty;
14336 -- The partial view of a Taft-amendment type is an incomplete
14337 -- type.
14339 if Taft then
14340 if Nkind (Decl) = N_Incomplete_Type_Declaration then
14341 Match := Defining_Identifier (Decl);
14342 end if;
14344 -- Otherwise look for a private type whose full view matches the
14345 -- input type. Note that this checks full_type_declaration nodes
14346 -- to account for derivations from a private type where the type
14347 -- declaration hold the partial view and the full view is an
14348 -- itype.
14350 elsif Nkind (Decl) in N_Full_Type_Declaration
14351 | N_Private_Extension_Declaration
14352 | N_Private_Type_Declaration
14353 then
14354 Match := Defining_Identifier (Decl);
14355 end if;
14357 -- Guard against unanalyzed entities
14359 if Present (Match)
14360 and then Is_Type (Match)
14361 and then Present (Full_View (Match))
14362 and then Full_View (Match) = Id
14363 then
14364 return Match;
14365 end if;
14367 Next (Decl);
14368 end loop;
14370 return Empty;
14371 end Inspect_Decls;
14373 -- Local variables
14375 Prev : Entity_Id;
14377 -- Start of processing for Incomplete_Or_Partial_View
14379 begin
14380 -- Deferred constant or incomplete type case
14382 Prev := Current_Entity (Id);
14384 while Present (Prev) loop
14385 exit when Scope (Prev) = S;
14387 Prev := Homonym (Prev);
14388 end loop;
14390 if Present (Prev)
14391 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
14392 and then Present (Full_View (Prev))
14393 and then Full_View (Prev) = Id
14394 then
14395 return Prev;
14396 end if;
14398 -- Private or Taft amendment type case
14400 if Present (S) and then Is_Package_Or_Generic_Package (S) then
14401 declare
14402 Pkg_Decl : constant Node_Id := Package_Specification (S);
14404 begin
14405 -- It is knows that Typ has a private view, look for it in the
14406 -- visible declarations of the enclosing scope. A special case
14407 -- of this is when the two views have been exchanged - the full
14408 -- appears earlier than the private.
14410 if Has_Private_Declaration (Id) then
14411 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
14413 -- Exchanged view case, look in the private declarations
14415 if No (Prev) then
14416 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
14417 end if;
14419 return Prev;
14421 -- Otherwise if this is the package body, then Typ is a potential
14422 -- Taft amendment type. The incomplete view should be located in
14423 -- the private declarations of the enclosing scope.
14425 elsif In_Package_Body (S) then
14426 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
14427 end if;
14428 end;
14429 end if;
14431 -- The type has no incomplete or private view
14433 return Empty;
14434 end Incomplete_Or_Partial_View;
14436 ---------------------------------------
14437 -- Incomplete_View_From_Limited_With --
14438 ---------------------------------------
14440 function Incomplete_View_From_Limited_With
14441 (Typ : Entity_Id) return Entity_Id
14443 begin
14444 -- It might make sense to make this an attribute in Einfo, and set it
14445 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
14446 -- slots for new attributes, and it seems a bit simpler to just search
14447 -- the Limited_View (if it exists) for an incomplete type whose
14448 -- Non_Limited_View is Typ.
14450 if Ekind (Scope (Typ)) = E_Package
14451 and then Present (Limited_View (Scope (Typ)))
14452 then
14453 declare
14454 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
14455 begin
14456 while Present (Ent) loop
14457 if Is_Incomplete_Type (Ent)
14458 and then Non_Limited_View (Ent) = Typ
14459 then
14460 return Ent;
14461 end if;
14463 Next_Entity (Ent);
14464 end loop;
14465 end;
14466 end if;
14468 return Typ;
14469 end Incomplete_View_From_Limited_With;
14471 ----------------------------------
14472 -- Indexed_Component_Bit_Offset --
14473 ----------------------------------
14475 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
14476 Exp : constant Node_Id := First (Expressions (N));
14477 Typ : constant Entity_Id := Etype (Prefix (N));
14478 Off : constant Uint := Component_Size (Typ);
14479 Ind : Node_Id;
14481 begin
14482 -- Return early if the component size is not known or variable
14484 if No (Off) or else Off < Uint_0 then
14485 return No_Uint;
14486 end if;
14488 -- Deal with the degenerate case of an empty component
14490 if Off = Uint_0 then
14491 return Off;
14492 end if;
14494 -- Check that both the index value and the low bound are known
14496 if not Compile_Time_Known_Value (Exp) then
14497 return No_Uint;
14498 end if;
14500 Ind := First_Index (Typ);
14501 if No (Ind) then
14502 return No_Uint;
14503 end if;
14505 -- Do not attempt to compute offsets within multi-dimensional arrays
14507 if Present (Next_Index (Ind)) then
14508 return No_Uint;
14509 end if;
14511 if Nkind (Ind) = N_Subtype_Indication then
14512 Ind := Constraint (Ind);
14514 if Nkind (Ind) = N_Range_Constraint then
14515 Ind := Range_Expression (Ind);
14516 end if;
14517 end if;
14519 if Nkind (Ind) /= N_Range
14520 or else not Compile_Time_Known_Value (Low_Bound (Ind))
14521 then
14522 return No_Uint;
14523 end if;
14525 -- Return the scaled offset
14527 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound (Ind)));
14528 end Indexed_Component_Bit_Offset;
14530 -----------------------------
14531 -- Inherit_Predicate_Flags --
14532 -----------------------------
14534 procedure Inherit_Predicate_Flags
14535 (Subt, Par : Entity_Id;
14536 Only_Flags : Boolean := False)
14538 begin
14539 if Ada_Version < Ada_2012
14540 or else Present (Predicate_Function (Subt))
14541 then
14542 return;
14543 end if;
14545 Set_Has_Predicates (Subt, Has_Predicates (Par));
14546 Set_Has_Static_Predicate_Aspect
14547 (Subt, Has_Static_Predicate_Aspect (Par));
14548 Set_Has_Dynamic_Predicate_Aspect
14549 (Subt, Has_Dynamic_Predicate_Aspect (Par));
14550 Set_Has_Ghost_Predicate_Aspect
14551 (Subt, Has_Ghost_Predicate_Aspect (Par));
14553 -- A named subtype does not inherit the predicate function of its
14554 -- parent but an itype declared for a loop index needs the discrete
14555 -- predicate information of its parent to execute the loop properly.
14556 -- Moreover, a named private subtype whose full view is an itype also
14557 -- needs to inherit a predicate function because it will not be frozen.
14558 -- A non-discrete type may has a static predicate (for example True)
14559 -- but has no static_discrete_predicate.
14561 if not Only_Flags
14562 and then (Is_Itype (Subt)
14563 or else (Ekind (Subt) = E_Private_Subtype
14564 and then Present (Full_View (Subt))
14565 and then Is_Itype (Full_View (Subt))))
14566 and then Present (Predicate_Function (Par))
14567 then
14568 Set_Subprograms_For_Type (Subt, Subprograms_For_Type (Par));
14570 if Has_Static_Predicate (Par) and then Is_Discrete_Type (Par) then
14571 Set_Static_Discrete_Predicate
14572 (Subt, Static_Discrete_Predicate (Par));
14573 end if;
14574 end if;
14575 end Inherit_Predicate_Flags;
14577 ----------------------------
14578 -- Inherit_Rep_Item_Chain --
14579 ----------------------------
14581 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
14582 Item : Node_Id;
14583 Next_Item : Node_Id;
14585 begin
14586 -- There are several inheritance scenarios to consider depending on
14587 -- whether both types have rep item chains and whether the destination
14588 -- type already inherits part of the source type's rep item chain.
14590 -- 1) The source type lacks a rep item chain
14591 -- From_Typ ---> Empty
14593 -- Typ --------> Item (or Empty)
14595 -- In this case inheritance cannot take place because there are no items
14596 -- to inherit.
14598 -- 2) The destination type lacks a rep item chain
14599 -- From_Typ ---> Item ---> ...
14601 -- Typ --------> Empty
14603 -- Inheritance takes place by setting the First_Rep_Item of the
14604 -- destination type to the First_Rep_Item of the source type.
14605 -- From_Typ ---> Item ---> ...
14606 -- ^
14607 -- Typ -----------+
14609 -- 3.1) Both source and destination types have at least one rep item.
14610 -- The destination type does NOT inherit a rep item from the source
14611 -- type.
14612 -- From_Typ ---> Item ---> Item
14614 -- Typ --------> Item ---> Item
14616 -- Inheritance takes place by setting the Next_Rep_Item of the last item
14617 -- of the destination type to the First_Rep_Item of the source type.
14618 -- From_Typ -------------------> Item ---> Item
14619 -- ^
14620 -- Typ --------> Item ---> Item --+
14622 -- 3.2) Both source and destination types have at least one rep item.
14623 -- The destination type DOES inherit part of the rep item chain of the
14624 -- source type.
14625 -- From_Typ ---> Item ---> Item ---> Item
14626 -- ^
14627 -- Typ --------> Item ------+
14629 -- This rare case arises when the full view of a private extension must
14630 -- inherit the rep item chain from the full view of its parent type and
14631 -- the full view of the parent type contains extra rep items. Currently
14632 -- only invariants may lead to such form of inheritance.
14634 -- type From_Typ is tagged private
14635 -- with Type_Invariant'Class => Item_2;
14637 -- type Typ is new From_Typ with private
14638 -- with Type_Invariant => Item_4;
14640 -- At this point the rep item chains contain the following items
14642 -- From_Typ -----------> Item_2 ---> Item_3
14643 -- ^
14644 -- Typ --------> Item_4 --+
14646 -- The full views of both types may introduce extra invariants
14648 -- type From_Typ is tagged null record
14649 -- with Type_Invariant => Item_1;
14651 -- type Typ is new From_Typ with null record;
14653 -- The full view of Typ would have to inherit any new rep items added to
14654 -- the full view of From_Typ.
14656 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
14657 -- ^
14658 -- Typ --------> Item_4 --+
14660 -- To achieve this form of inheritance, the destination type must first
14661 -- sever the link between its own rep chain and that of the source type,
14662 -- then inheritance 3.1 takes place.
14664 -- Case 1: The source type lacks a rep item chain
14666 if No (First_Rep_Item (From_Typ)) then
14667 return;
14669 -- Case 2: The destination type lacks a rep item chain
14671 elsif No (First_Rep_Item (Typ)) then
14672 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
14674 -- Case 3: Both the source and destination types have at least one rep
14675 -- item. Traverse the rep item chain of the destination type to find the
14676 -- last rep item.
14678 else
14679 Item := Empty;
14680 Next_Item := First_Rep_Item (Typ);
14681 while Present (Next_Item) loop
14683 -- Detect a link between the destination type's rep chain and that
14684 -- of the source type. There are two possibilities:
14686 -- Variant 1
14687 -- Next_Item
14688 -- V
14689 -- From_Typ ---> Item_1 --->
14690 -- ^
14691 -- Typ -----------+
14693 -- Item is Empty
14695 -- Variant 2
14696 -- Next_Item
14697 -- V
14698 -- From_Typ ---> Item_1 ---> Item_2 --->
14699 -- ^
14700 -- Typ --------> Item_3 ------+
14701 -- ^
14702 -- Item
14704 if Present_In_Rep_Item (From_Typ, Next_Item) then
14705 exit;
14706 end if;
14708 Item := Next_Item;
14709 Next_Item := Next_Rep_Item (Next_Item);
14710 end loop;
14712 -- Inherit the source type's rep item chain
14714 if Present (Item) then
14715 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
14716 else
14717 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
14718 end if;
14719 end if;
14720 end Inherit_Rep_Item_Chain;
14722 ------------------------------------
14723 -- Inherits_From_Tagged_Full_View --
14724 ------------------------------------
14726 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
14727 begin
14728 return Is_Private_Type (Typ)
14729 and then Present (Full_View (Typ))
14730 and then Is_Private_Type (Full_View (Typ))
14731 and then not Is_Tagged_Type (Full_View (Typ))
14732 and then Present (Underlying_Type (Full_View (Typ)))
14733 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
14734 end Inherits_From_Tagged_Full_View;
14736 ---------------------------------
14737 -- Insert_Explicit_Dereference --
14738 ---------------------------------
14740 procedure Insert_Explicit_Dereference (N : Node_Id) is
14741 New_Prefix : constant Node_Id := Relocate_Node (N);
14742 Ent : Entity_Id := Empty;
14743 Pref : Node_Id := Empty;
14744 I : Interp_Index;
14745 It : Interp;
14746 T : Entity_Id;
14748 begin
14749 Save_Interps (N, New_Prefix);
14751 Rewrite (N,
14752 Make_Explicit_Dereference (Sloc (Parent (N)),
14753 Prefix => New_Prefix));
14755 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
14757 if Is_Overloaded (New_Prefix) then
14759 -- The dereference is also overloaded, and its interpretations are
14760 -- the designated types of the interpretations of the original node.
14762 Set_Etype (N, Any_Type);
14764 Get_First_Interp (New_Prefix, I, It);
14765 while Present (It.Nam) loop
14766 T := It.Typ;
14768 if Is_Access_Type (T) then
14769 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
14770 end if;
14772 Get_Next_Interp (I, It);
14773 end loop;
14775 else
14776 -- Prefix is unambiguous: mark the original prefix (which might
14777 -- Come_From_Source) as a reference, since the new (relocated) one
14778 -- won't be taken into account.
14780 if Is_Entity_Name (New_Prefix) then
14781 Ent := Entity (New_Prefix);
14782 Pref := New_Prefix;
14784 -- For a retrieval of a subcomponent of some composite object,
14785 -- retrieve the ultimate entity if there is one.
14787 elsif Nkind (New_Prefix) in N_Selected_Component | N_Indexed_Component
14788 then
14789 Pref := Prefix (New_Prefix);
14790 while Present (Pref)
14791 and then Nkind (Pref) in
14792 N_Selected_Component | N_Indexed_Component
14793 loop
14794 Pref := Prefix (Pref);
14795 end loop;
14797 if Present (Pref) and then Is_Entity_Name (Pref) then
14798 Ent := Entity (Pref);
14799 end if;
14800 end if;
14802 -- Place the reference on the entity node
14804 if Present (Ent) then
14805 Generate_Reference (Ent, Pref);
14806 end if;
14807 end if;
14808 end Insert_Explicit_Dereference;
14810 ------------------------------------------
14811 -- Inspect_Deferred_Constant_Completion --
14812 ------------------------------------------
14814 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
14815 Decl : Node_Id;
14817 begin
14818 Decl := First (Decls);
14819 while Present (Decl) loop
14821 -- Deferred constant signature
14823 if Nkind (Decl) = N_Object_Declaration
14824 and then Constant_Present (Decl)
14825 and then No (Expression (Decl))
14827 -- No need to check internally generated constants
14829 and then Comes_From_Source (Decl)
14831 -- The constant is not completed. A full object declaration or a
14832 -- pragma Import complete a deferred constant.
14834 and then not Has_Completion (Defining_Identifier (Decl))
14835 then
14836 Error_Msg_N
14837 ("constant declaration requires initialization expression",
14838 Defining_Identifier (Decl));
14839 end if;
14841 Next (Decl);
14842 end loop;
14843 end Inspect_Deferred_Constant_Completion;
14845 -------------------------------
14846 -- Install_Elaboration_Model --
14847 -------------------------------
14849 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
14850 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
14851 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
14852 -- Empty if there is no such pragma.
14854 ------------------------------------
14855 -- Find_Elaboration_Checks_Pragma --
14856 ------------------------------------
14858 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
14859 Item : Node_Id;
14861 begin
14862 Item := First (L);
14863 while Present (Item) loop
14864 if Nkind (Item) = N_Pragma
14865 and then Pragma_Name (Item) = Name_Elaboration_Checks
14866 then
14867 return Item;
14868 end if;
14870 Next (Item);
14871 end loop;
14873 return Empty;
14874 end Find_Elaboration_Checks_Pragma;
14876 -- Local variables
14878 Args : List_Id;
14879 Model : Node_Id;
14880 Prag : Node_Id;
14881 Unit : Node_Id;
14883 -- Start of processing for Install_Elaboration_Model
14885 begin
14886 -- Nothing to do when the unit does not exist
14888 if No (Unit_Id) then
14889 return;
14890 end if;
14892 Unit := Parent (Unit_Declaration_Node (Unit_Id));
14894 -- Nothing to do when the unit is not a library unit
14896 if Nkind (Unit) /= N_Compilation_Unit then
14897 return;
14898 end if;
14900 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
14902 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
14903 -- elaboration model as specified by the pragma.
14905 if Present (Prag) then
14906 Args := Pragma_Argument_Associations (Prag);
14908 -- Guard against an illegal pragma. The sole argument must be an
14909 -- identifier which specifies either Dynamic or Static model.
14911 if Present (Args) then
14912 Model := Get_Pragma_Arg (First (Args));
14914 if Nkind (Model) = N_Identifier then
14915 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
14916 end if;
14917 end if;
14918 end if;
14919 end Install_Elaboration_Model;
14921 -----------------------------
14922 -- Install_Generic_Formals --
14923 -----------------------------
14925 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
14926 E : Entity_Id;
14928 begin
14929 pragma Assert (Is_Generic_Subprogram (Subp_Id));
14931 E := First_Entity (Subp_Id);
14932 while Present (E) loop
14933 Install_Entity (E);
14934 Next_Entity (E);
14935 end loop;
14936 end Install_Generic_Formals;
14938 ------------------------
14939 -- Install_SPARK_Mode --
14940 ------------------------
14942 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
14943 begin
14944 SPARK_Mode := Mode;
14945 SPARK_Mode_Pragma := Prag;
14946 end Install_SPARK_Mode;
14948 --------------------------
14949 -- Invalid_Scalar_Value --
14950 --------------------------
14952 function Invalid_Scalar_Value
14953 (Loc : Source_Ptr;
14954 Scal_Typ : Scalar_Id) return Node_Id
14956 function Invalid_Binder_Value return Node_Id;
14957 -- Return a reference to the corresponding invalid value for type
14958 -- Scal_Typ as defined in unit System.Scalar_Values.
14960 function Invalid_Float_Value return Node_Id;
14961 -- Return the invalid value of float type Scal_Typ
14963 function Invalid_Integer_Value return Node_Id;
14964 -- Return the invalid value of integer type Scal_Typ
14966 procedure Set_Invalid_Binder_Values;
14967 -- Set the contents of collection Invalid_Binder_Values
14969 --------------------------
14970 -- Invalid_Binder_Value --
14971 --------------------------
14973 function Invalid_Binder_Value return Node_Id is
14974 Val_Id : Entity_Id;
14976 begin
14977 -- Initialize the collection of invalid binder values the first time
14978 -- around.
14980 Set_Invalid_Binder_Values;
14982 -- Obtain the corresponding variable from System.Scalar_Values which
14983 -- holds the invalid value for this type.
14985 Val_Id := Invalid_Binder_Values (Scal_Typ);
14986 pragma Assert (Present (Val_Id));
14988 return New_Occurrence_Of (Val_Id, Loc);
14989 end Invalid_Binder_Value;
14991 -------------------------
14992 -- Invalid_Float_Value --
14993 -------------------------
14995 function Invalid_Float_Value return Node_Id is
14996 Value : constant Ureal := Invalid_Floats (Scal_Typ);
14998 begin
14999 -- Pragma Invalid_Scalars did not specify an invalid value for this
15000 -- type. Fall back to the value provided by the binder.
15002 if Value = No_Ureal then
15003 return Invalid_Binder_Value;
15004 else
15005 return Make_Real_Literal (Loc, Realval => Value);
15006 end if;
15007 end Invalid_Float_Value;
15009 ---------------------------
15010 -- Invalid_Integer_Value --
15011 ---------------------------
15013 function Invalid_Integer_Value return Node_Id is
15014 Value : constant Uint := Invalid_Integers (Scal_Typ);
15016 begin
15017 -- Pragma Invalid_Scalars did not specify an invalid value for this
15018 -- type. Fall back to the value provided by the binder.
15020 if No (Value) then
15021 return Invalid_Binder_Value;
15022 else
15023 return Make_Integer_Literal (Loc, Intval => Value);
15024 end if;
15025 end Invalid_Integer_Value;
15027 -------------------------------
15028 -- Set_Invalid_Binder_Values --
15029 -------------------------------
15031 procedure Set_Invalid_Binder_Values is
15032 begin
15033 if not Invalid_Binder_Values_Set then
15034 Invalid_Binder_Values_Set := True;
15036 -- Initialize the contents of the collection once since RTE calls
15037 -- are not cheap.
15039 Invalid_Binder_Values :=
15040 (Name_Short_Float => RTE (RE_IS_Isf),
15041 Name_Float => RTE (RE_IS_Ifl),
15042 Name_Long_Float => RTE (RE_IS_Ilf),
15043 Name_Long_Long_Float => RTE (RE_IS_Ill),
15044 Name_Signed_8 => RTE (RE_IS_Is1),
15045 Name_Signed_16 => RTE (RE_IS_Is2),
15046 Name_Signed_32 => RTE (RE_IS_Is4),
15047 Name_Signed_64 => RTE (RE_IS_Is8),
15048 Name_Signed_128 => Empty,
15049 Name_Unsigned_8 => RTE (RE_IS_Iu1),
15050 Name_Unsigned_16 => RTE (RE_IS_Iu2),
15051 Name_Unsigned_32 => RTE (RE_IS_Iu4),
15052 Name_Unsigned_64 => RTE (RE_IS_Iu8),
15053 Name_Unsigned_128 => Empty);
15055 if System_Max_Integer_Size < 128 then
15056 Invalid_Binder_Values (Name_Signed_128) := RTE (RE_IS_Is8);
15057 Invalid_Binder_Values (Name_Unsigned_128) := RTE (RE_IS_Iu8);
15058 else
15059 Invalid_Binder_Values (Name_Signed_128) := RTE (RE_IS_Is16);
15060 Invalid_Binder_Values (Name_Unsigned_128) := RTE (RE_IS_Iu16);
15061 end if;
15062 end if;
15063 end Set_Invalid_Binder_Values;
15065 -- Start of processing for Invalid_Scalar_Value
15067 begin
15068 if Scal_Typ in Float_Scalar_Id then
15069 return Invalid_Float_Value;
15071 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
15072 return Invalid_Integer_Value;
15073 end if;
15074 end Invalid_Scalar_Value;
15076 ------------------------
15077 -- Is_Access_Variable --
15078 ------------------------
15080 function Is_Access_Variable (E : Entity_Id) return Boolean is
15081 begin
15082 return Is_Access_Type (E)
15083 and then not Is_Access_Constant (E)
15084 and then Ekind (Directly_Designated_Type (E)) /= E_Subprogram_Type;
15085 end Is_Access_Variable;
15087 -----------------------------
15088 -- Is_Actual_Out_Parameter --
15089 -----------------------------
15091 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
15092 Formal : Entity_Id;
15093 Call : Node_Id;
15094 begin
15095 Find_Actual (N, Formal, Call);
15096 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
15097 end Is_Actual_Out_Parameter;
15099 --------------------------------
15100 -- Is_Actual_In_Out_Parameter --
15101 --------------------------------
15103 function Is_Actual_In_Out_Parameter (N : Node_Id) return Boolean is
15104 Formal : Entity_Id;
15105 Call : Node_Id;
15106 begin
15107 Find_Actual (N, Formal, Call);
15108 return Present (Formal) and then Ekind (Formal) = E_In_Out_Parameter;
15109 end Is_Actual_In_Out_Parameter;
15111 ---------------------------------------
15112 -- Is_Actual_Out_Or_In_Out_Parameter --
15113 ---------------------------------------
15115 function Is_Actual_Out_Or_In_Out_Parameter (N : Node_Id) return Boolean is
15116 Formal : Entity_Id;
15117 Call : Node_Id;
15118 begin
15119 Find_Actual (N, Formal, Call);
15120 return Present (Formal)
15121 and then Ekind (Formal) in E_Out_Parameter | E_In_Out_Parameter;
15122 end Is_Actual_Out_Or_In_Out_Parameter;
15124 -------------------------
15125 -- Is_Actual_Parameter --
15126 -------------------------
15128 function Is_Actual_Parameter (N : Node_Id) return Boolean is
15129 PK : constant Node_Kind := Nkind (Parent (N));
15131 begin
15132 case PK is
15133 when N_Parameter_Association =>
15134 return N = Explicit_Actual_Parameter (Parent (N));
15136 when N_Entry_Call_Statement
15137 | N_Subprogram_Call
15139 return Is_List_Member (N)
15140 and then
15141 List_Containing (N) = Parameter_Associations (Parent (N));
15143 when others =>
15144 return False;
15145 end case;
15146 end Is_Actual_Parameter;
15148 ---------------------
15149 -- Is_Aliased_View --
15150 ---------------------
15152 function Is_Aliased_View (Obj : Node_Id) return Boolean is
15153 E : Entity_Id;
15155 begin
15156 if Is_Entity_Name (Obj) then
15157 E := Entity (Obj);
15159 return
15160 (Is_Object (E)
15161 and then
15162 (Is_Aliased (E)
15163 or else (Present (Renamed_Object (E))
15164 and then Is_Aliased_View (Renamed_Object (E)))))
15166 or else ((Is_Formal (E) or else Is_Formal_Object (E))
15167 and then Is_Tagged_Type (Etype (E)))
15169 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
15171 -- Current instance of type, either directly or as rewritten
15172 -- reference to the current object.
15174 or else (Is_Entity_Name (Original_Node (Obj))
15175 and then Present (Entity (Original_Node (Obj)))
15176 and then Is_Type (Entity (Original_Node (Obj))))
15178 or else (Is_Type (E) and then E = Current_Scope)
15180 or else (Is_Incomplete_Or_Private_Type (E)
15181 and then Full_View (E) = Current_Scope)
15183 -- Ada 2012 AI05-0053: the return object of an extended return
15184 -- statement is aliased if its type is immutably limited.
15186 or else (Is_Return_Object (E)
15187 and then Is_Inherently_Limited_Type (Etype (E)))
15189 -- The current instance of a limited type is aliased, so
15190 -- we want to allow uses of T'Access in the init proc for
15191 -- a limited type T. However, we don't want to mark the formal
15192 -- parameter as being aliased since that could impact callers.
15194 or else (Is_Formal (E)
15195 and then Chars (E) = Name_uInit
15196 and then Is_Inherently_Limited_Type (Etype (E)));
15198 elsif Nkind (Obj) = N_Selected_Component then
15199 return Is_Aliased (Entity (Selector_Name (Obj)));
15201 elsif Nkind (Obj) = N_Indexed_Component then
15202 return Has_Aliased_Components (Etype (Prefix (Obj)))
15203 or else
15204 (Is_Access_Type (Etype (Prefix (Obj)))
15205 and then Has_Aliased_Components
15206 (Designated_Type (Etype (Prefix (Obj)))));
15208 -- Handle a 'Super view conversion
15210 elsif Nkind (Obj) = N_Attribute_Reference
15211 and then Attribute_Name (Obj) = Name_Super
15212 then
15213 return Is_Aliased_View (Prefix (Obj));
15215 elsif Nkind (Obj) in N_Unchecked_Type_Conversion | N_Type_Conversion then
15216 return Is_Tagged_Type (Etype (Obj))
15217 and then Is_Aliased_View (Expression (Obj));
15219 -- Ada 2022 AI12-0228
15221 elsif Nkind (Obj) = N_Qualified_Expression
15222 and then Ada_Version >= Ada_2012
15223 then
15224 return Is_Aliased_View (Expression (Obj));
15226 elsif Is_Expanded_Class_Wide_Interface_Object_Decl (Parent (Obj)) then
15227 return Is_Aliased
15228 (Defining_Identifier (Original_Node (Parent (Obj))));
15230 -- The dereference of an access-to-object value denotes an aliased view,
15231 -- but this routine uses the rules of the language so we need to exclude
15232 -- rewritten constructs that introduce artificial dereferences.
15234 elsif Nkind (Obj) = N_Explicit_Dereference then
15235 return not Is_Captured_Function_Call (Obj)
15236 and then not
15237 (Nkind (Parent (Obj)) = N_Object_Renaming_Declaration
15238 and then Is_Return_Object (Defining_Entity (Parent (Obj))));
15240 else
15241 return False;
15242 end if;
15243 end Is_Aliased_View;
15245 -------------------------
15246 -- Is_Ancestor_Package --
15247 -------------------------
15249 function Is_Ancestor_Package
15250 (E1 : Entity_Id;
15251 E2 : Entity_Id) return Boolean
15253 Par : Entity_Id;
15255 begin
15256 Par := E2;
15257 while Present (Par) and then Par /= Standard_Standard loop
15258 if Par = E1 then
15259 return True;
15260 end if;
15262 Par := Scope (Par);
15263 end loop;
15265 return False;
15266 end Is_Ancestor_Package;
15268 ----------------------
15269 -- Is_Atomic_Object --
15270 ----------------------
15272 function Is_Atomic_Object (N : Node_Id) return Boolean is
15273 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean;
15274 -- Determine whether prefix P has atomic components. This requires the
15275 -- presence of an Atomic_Components aspect/pragma.
15277 ---------------------------------
15278 -- Prefix_Has_Atomic_Components --
15279 ---------------------------------
15281 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean is
15282 Typ : constant Entity_Id := Etype (P);
15284 begin
15285 if Is_Access_Type (Typ) then
15286 return Has_Atomic_Components (Designated_Type (Typ));
15288 elsif Has_Atomic_Components (Typ) then
15289 return True;
15291 elsif Is_Entity_Name (P)
15292 and then Has_Atomic_Components (Entity (P))
15293 then
15294 return True;
15296 else
15297 return False;
15298 end if;
15299 end Prefix_Has_Atomic_Components;
15301 -- Start of processing for Is_Atomic_Object
15303 begin
15304 if Is_Entity_Name (N) then
15305 return Is_Atomic_Object_Entity (Entity (N));
15307 elsif Is_Atomic (Etype (N)) then
15308 return True;
15310 elsif Nkind (N) = N_Indexed_Component then
15311 return Prefix_Has_Atomic_Components (Prefix (N));
15313 elsif Nkind (N) = N_Selected_Component then
15314 return Is_Atomic (Entity (Selector_Name (N)));
15316 else
15317 return False;
15318 end if;
15319 end Is_Atomic_Object;
15321 -----------------------------
15322 -- Is_Atomic_Object_Entity --
15323 -----------------------------
15325 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
15326 begin
15327 return
15328 Is_Object (Id)
15329 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
15330 end Is_Atomic_Object_Entity;
15332 -----------------------------
15333 -- Is_Attribute_Loop_Entry --
15334 -----------------------------
15336 function Is_Attribute_Loop_Entry (N : Node_Id) return Boolean is
15337 begin
15338 return Nkind (N) = N_Attribute_Reference
15339 and then Attribute_Name (N) = Name_Loop_Entry;
15340 end Is_Attribute_Loop_Entry;
15342 ----------------------
15343 -- Is_Attribute_Old --
15344 ----------------------
15346 function Is_Attribute_Old (N : Node_Id) return Boolean is
15347 begin
15348 return Nkind (N) = N_Attribute_Reference
15349 and then Attribute_Name (N) = Name_Old;
15350 end Is_Attribute_Old;
15352 -------------------------
15353 -- Is_Attribute_Result --
15354 -------------------------
15356 function Is_Attribute_Result (N : Node_Id) return Boolean is
15357 begin
15358 return Nkind (N) = N_Attribute_Reference
15359 and then Attribute_Name (N) = Name_Result;
15360 end Is_Attribute_Result;
15362 -------------------------
15363 -- Is_Attribute_Update --
15364 -------------------------
15366 function Is_Attribute_Update (N : Node_Id) return Boolean is
15367 begin
15368 return Nkind (N) = N_Attribute_Reference
15369 and then Attribute_Name (N) = Name_Update;
15370 end Is_Attribute_Update;
15372 ------------------------------------
15373 -- Is_Body_Or_Package_Declaration --
15374 ------------------------------------
15376 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
15377 begin
15378 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
15379 end Is_Body_Or_Package_Declaration;
15381 -----------------------
15382 -- Is_Bounded_String --
15383 -----------------------
15385 function Is_Bounded_String (T : Entity_Id) return Boolean is
15386 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
15388 begin
15389 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
15390 -- Super_String, or one of the [Wide_]Wide_ versions. This will
15391 -- be True for all the Bounded_String types in instances of the
15392 -- Generic_Bounded_Length generics, and for types derived from those.
15394 return Present (Under)
15395 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
15396 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
15397 Is_RTE (Root_Type (Under), RO_WW_Super_String));
15398 end Is_Bounded_String;
15400 -------------------------------
15401 -- Is_By_Protected_Procedure --
15402 -------------------------------
15404 function Is_By_Protected_Procedure (Id : Entity_Id) return Boolean is
15405 begin
15406 return Ekind (Id) = E_Procedure
15407 and then Present (Get_Rep_Pragma (Id, Name_Implemented))
15408 and then Implementation_Kind (Id) = Name_By_Protected_Procedure;
15409 end Is_By_Protected_Procedure;
15411 ---------------------
15412 -- Is_CCT_Instance --
15413 ---------------------
15415 function Is_CCT_Instance
15416 (Ref_Id : Entity_Id;
15417 Context_Id : Entity_Id) return Boolean
15419 begin
15420 pragma Assert (Ekind (Ref_Id) in E_Protected_Type | E_Task_Type);
15422 if Is_Single_Task_Object (Context_Id) then
15423 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
15425 else
15426 pragma Assert
15427 (Ekind (Context_Id) in
15428 E_Entry | E_Entry_Family | E_Function | E_Package |
15429 E_Procedure | E_Protected_Type | E_Task_Type
15430 or else Is_Record_Type (Context_Id));
15431 return Scope_Within_Or_Same (Context_Id, Ref_Id);
15432 end if;
15433 end Is_CCT_Instance;
15435 -------------------------
15436 -- Is_Child_Or_Sibling --
15437 -------------------------
15439 function Is_Child_Or_Sibling
15440 (Pack_1 : Entity_Id;
15441 Pack_2 : Entity_Id) return Boolean
15443 function Distance_From_Standard (Pack : Entity_Id) return Nat;
15444 -- Given an arbitrary package, return the number of "climbs" necessary
15445 -- to reach scope Standard_Standard.
15447 procedure Equalize_Depths
15448 (Pack : in out Entity_Id;
15449 Depth : in out Nat;
15450 Depth_To_Reach : Nat);
15451 -- Given an arbitrary package, its depth and a target depth to reach,
15452 -- climb the scope chain until the said depth is reached. The pointer
15453 -- to the package and its depth a modified during the climb.
15455 ----------------------------
15456 -- Distance_From_Standard --
15457 ----------------------------
15459 function Distance_From_Standard (Pack : Entity_Id) return Nat is
15460 Dist : Nat;
15461 Scop : Entity_Id;
15463 begin
15464 Dist := 0;
15465 Scop := Pack;
15466 while Present (Scop) and then Scop /= Standard_Standard loop
15467 Dist := Dist + 1;
15468 Scop := Scope (Scop);
15469 end loop;
15471 return Dist;
15472 end Distance_From_Standard;
15474 ---------------------
15475 -- Equalize_Depths --
15476 ---------------------
15478 procedure Equalize_Depths
15479 (Pack : in out Entity_Id;
15480 Depth : in out Nat;
15481 Depth_To_Reach : Nat)
15483 begin
15484 -- The package must be at a greater or equal depth
15486 if Depth < Depth_To_Reach then
15487 raise Program_Error;
15488 end if;
15490 -- Climb the scope chain until the desired depth is reached
15492 while Present (Pack) and then Depth /= Depth_To_Reach loop
15493 Pack := Scope (Pack);
15494 Depth := Depth - 1;
15495 end loop;
15496 end Equalize_Depths;
15498 -- Local variables
15500 P_1 : Entity_Id := Pack_1;
15501 P_1_Child : Boolean := False;
15502 P_1_Depth : Nat := Distance_From_Standard (P_1);
15503 P_2 : Entity_Id := Pack_2;
15504 P_2_Child : Boolean := False;
15505 P_2_Depth : Nat := Distance_From_Standard (P_2);
15507 -- Start of processing for Is_Child_Or_Sibling
15509 begin
15510 pragma Assert
15511 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
15513 -- Both packages denote the same entity, therefore they cannot be
15514 -- children or siblings.
15516 if P_1 = P_2 then
15517 return False;
15519 -- One of the packages is at a deeper level than the other. Note that
15520 -- both may still come from different hierarchies.
15522 -- (root) P_2
15523 -- / \ :
15524 -- X P_2 or X
15525 -- : :
15526 -- P_1 P_1
15528 elsif P_1_Depth > P_2_Depth then
15529 Equalize_Depths
15530 (Pack => P_1,
15531 Depth => P_1_Depth,
15532 Depth_To_Reach => P_2_Depth);
15533 P_1_Child := True;
15535 -- (root) P_1
15536 -- / \ :
15537 -- P_1 X or X
15538 -- : :
15539 -- P_2 P_2
15541 elsif P_2_Depth > P_1_Depth then
15542 Equalize_Depths
15543 (Pack => P_2,
15544 Depth => P_2_Depth,
15545 Depth_To_Reach => P_1_Depth);
15546 P_2_Child := True;
15547 end if;
15549 -- At this stage the package pointers have been elevated to the same
15550 -- depth. If the related entities are the same, then one package is a
15551 -- potential child of the other:
15553 -- P_1
15554 -- :
15555 -- X became P_1 P_2 or vice versa
15556 -- :
15557 -- P_2
15559 if P_1 = P_2 then
15560 if P_1_Child then
15561 return Is_Child_Unit (Pack_1);
15563 else pragma Assert (P_2_Child);
15564 return Is_Child_Unit (Pack_2);
15565 end if;
15567 -- The packages may come from the same package chain or from entirely
15568 -- different hierarchies. To determine this, climb the scope stack until
15569 -- a common root is found.
15571 -- (root) (root 1) (root 2)
15572 -- / \ | |
15573 -- P_1 P_2 P_1 P_2
15575 else
15576 while Present (P_1) and then Present (P_2) loop
15578 -- The two packages may be siblings
15580 if P_1 = P_2 then
15581 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
15582 end if;
15584 P_1 := Scope (P_1);
15585 P_2 := Scope (P_2);
15586 end loop;
15587 end if;
15589 return False;
15590 end Is_Child_Or_Sibling;
15592 -------------------
15593 -- Is_Confirming --
15594 -------------------
15596 function Is_Confirming (Aspect : Nonoverridable_Aspect_Id;
15597 Aspect_Spec_1, Aspect_Spec_2 : Node_Id)
15598 return Boolean is
15599 function Names_Match (Nm1, Nm2 : Node_Id) return Boolean;
15601 -----------------
15602 -- Names_Match --
15603 -----------------
15605 function Names_Match (Nm1, Nm2 : Node_Id) return Boolean is
15606 begin
15607 if Nkind (Nm1) /= Nkind (Nm2) then
15608 return False;
15609 -- This may be too restrictive given that visibility
15610 -- may allow an identifier in one case and an expanded
15611 -- name in the other.
15612 end if;
15613 case Nkind (Nm1) is
15614 when N_Identifier =>
15615 return Name_Equals (Chars (Nm1), Chars (Nm2));
15617 when N_Expanded_Name =>
15618 -- An inherited operation has the same name as its
15619 -- ancestor, but they may have different scopes.
15620 -- This may be too permissive for Iterator_Element, which
15621 -- is intended to be identical in parent and derived type.
15623 return Names_Match (Selector_Name (Nm1),
15624 Selector_Name (Nm2));
15626 when N_Empty =>
15627 return True; -- needed for Aggregate aspect checking
15629 when others =>
15630 -- e.g., 'Class attribute references
15631 if Is_Entity_Name (Nm1) and Is_Entity_Name (Nm2) then
15632 return Entity (Nm1) = Entity (Nm2);
15633 end if;
15635 raise Program_Error;
15636 end case;
15637 end Names_Match;
15638 begin
15639 -- allow users to disable "shall be confirming" check, at least for now
15640 if Relaxed_RM_Semantics then
15641 return True;
15642 end if;
15644 -- ??? Type conversion here (along with "when others =>" below) is a
15645 -- workaround for a bootstrapping problem related to casing on a
15646 -- static-predicate-bearing subtype.
15648 case Aspect_Id (Aspect) is
15649 -- name-valued aspects; compare text of names, not resolution.
15650 when Aspect_Default_Iterator
15651 | Aspect_Iterator_Element
15652 | Aspect_Constant_Indexing
15653 | Aspect_Variable_Indexing =>
15654 declare
15655 Item_1 : constant Node_Id := Aspect_Rep_Item (Aspect_Spec_1);
15656 Item_2 : constant Node_Id := Aspect_Rep_Item (Aspect_Spec_2);
15657 begin
15658 if Nkind (Item_1) /= N_Attribute_Definition_Clause
15659 or Nkind (Item_2) /= N_Attribute_Definition_Clause
15660 then
15661 pragma Assert (Serious_Errors_Detected > 0);
15662 return True;
15663 end if;
15665 return Names_Match (Expression (Item_1),
15666 Expression (Item_2));
15667 end;
15669 -- A confirming aspect for Implicit_Derenfence on a derived type
15670 -- has already been checked in Analyze_Aspect_Implicit_Dereference,
15671 -- including the presence of renamed discriminants.
15673 when Aspect_Implicit_Dereference =>
15674 return True;
15676 -- one of a kind
15677 when Aspect_Aggregate =>
15678 declare
15679 Empty_1,
15680 Add_Named_1,
15681 Add_Unnamed_1,
15682 New_Indexed_1,
15683 Assign_Indexed_1,
15684 Empty_2,
15685 Add_Named_2,
15686 Add_Unnamed_2,
15687 New_Indexed_2,
15688 Assign_Indexed_2 : Node_Id := Empty;
15689 begin
15690 Parse_Aspect_Aggregate
15691 (N => Expression (Aspect_Spec_1),
15692 Empty_Subp => Empty_1,
15693 Add_Named_Subp => Add_Named_1,
15694 Add_Unnamed_Subp => Add_Unnamed_1,
15695 New_Indexed_Subp => New_Indexed_1,
15696 Assign_Indexed_Subp => Assign_Indexed_1);
15697 Parse_Aspect_Aggregate
15698 (N => Expression (Aspect_Spec_2),
15699 Empty_Subp => Empty_2,
15700 Add_Named_Subp => Add_Named_2,
15701 Add_Unnamed_Subp => Add_Unnamed_2,
15702 New_Indexed_Subp => New_Indexed_2,
15703 Assign_Indexed_Subp => Assign_Indexed_2);
15704 return
15705 Names_Match (Empty_1, Empty_2) and then
15706 Names_Match (Add_Named_1, Add_Named_2) and then
15707 Names_Match (Add_Unnamed_1, Add_Unnamed_2) and then
15708 Names_Match (New_Indexed_1, New_Indexed_2) and then
15709 Names_Match (Assign_Indexed_1, Assign_Indexed_2);
15710 end;
15712 -- Checking for this aspect is performed elsewhere during freezing
15713 when Aspect_No_Controlled_Parts =>
15714 return True;
15716 -- scalar-valued aspects; compare (static) values.
15717 when Aspect_Max_Entry_Queue_Length =>
15718 -- This should be unreachable. Max_Entry_Queue_Length is
15719 -- supported only for protected entries, not for types.
15720 pragma Assert (Serious_Errors_Detected /= 0);
15721 return True;
15723 when others =>
15724 raise Program_Error;
15725 end case;
15726 end Is_Confirming;
15728 -----------------------------
15729 -- Is_Concurrent_Interface --
15730 -----------------------------
15732 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
15733 begin
15734 return Is_Protected_Interface (T)
15735 or else Is_Synchronized_Interface (T)
15736 or else Is_Task_Interface (T);
15737 end Is_Concurrent_Interface;
15739 ------------------------------------------------------
15740 -- Is_Conjunction_Of_Formal_Preelab_Init_Attributes --
15741 ------------------------------------------------------
15743 function Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15744 (Expr : Node_Id) return Boolean
15747 function Is_Formal_Preelab_Init_Attribute
15748 (N : Node_Id) return Boolean;
15749 -- Returns True if N is a Preelaborable_Initialization attribute
15750 -- applied to a generic formal type, or N's Original_Node is such
15751 -- an attribute.
15753 --------------------------------------
15754 -- Is_Formal_Preelab_Init_Attribute --
15755 --------------------------------------
15757 function Is_Formal_Preelab_Init_Attribute
15758 (N : Node_Id) return Boolean
15760 Orig_N : constant Node_Id := Original_Node (N);
15762 begin
15763 return Nkind (Orig_N) = N_Attribute_Reference
15764 and then Attribute_Name (Orig_N) = Name_Preelaborable_Initialization
15765 and then Is_Entity_Name (Prefix (Orig_N))
15766 and then Is_Generic_Type (Entity (Prefix (Orig_N)));
15767 end Is_Formal_Preelab_Init_Attribute;
15769 -- Start of Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15771 begin
15772 return Is_Formal_Preelab_Init_Attribute (Expr)
15773 or else (Nkind (Expr) = N_Op_And
15774 and then
15775 Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15776 (Left_Opnd (Expr))
15777 and then
15778 Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15779 (Right_Opnd (Expr)));
15780 end Is_Conjunction_Of_Formal_Preelab_Init_Attributes;
15782 -----------------------
15783 -- Is_Constant_Bound --
15784 -----------------------
15786 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
15787 begin
15788 if Compile_Time_Known_Value (Exp) then
15789 return True;
15791 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
15792 return Is_Constant_Object (Entity (Exp))
15793 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
15795 elsif Nkind (Exp) in N_Binary_Op then
15796 return Is_Constant_Bound (Left_Opnd (Exp))
15797 and then Is_Constant_Bound (Right_Opnd (Exp))
15798 and then Scope (Entity (Exp)) = Standard_Standard;
15800 else
15801 return False;
15802 end if;
15803 end Is_Constant_Bound;
15805 ---------------------------
15806 -- Is_Container_Element --
15807 ---------------------------
15809 function Is_Container_Element (Exp : Node_Id) return Boolean is
15810 Loc : constant Source_Ptr := Sloc (Exp);
15811 Pref : constant Node_Id := Prefix (Exp);
15813 Call : Node_Id;
15814 -- Call to an indexing aspect
15816 Cont_Typ : Entity_Id;
15817 -- The type of the container being accessed
15819 Elem_Typ : Entity_Id;
15820 -- Its element type
15822 Indexing : Entity_Id;
15823 Is_Const : Boolean;
15824 -- Indicates that constant indexing is used, and the element is thus
15825 -- a constant.
15827 Ref_Typ : Entity_Id;
15828 -- The reference type returned by the indexing operation
15830 begin
15831 -- If C is a container, in a context that imposes the element type of
15832 -- that container, the indexing notation C (X) is rewritten as:
15834 -- Indexing (C, X).Discr.all
15836 -- where Indexing is one of the indexing aspects of the container.
15837 -- If the context does not require a reference, the construct can be
15838 -- rewritten as
15840 -- Element (C, X)
15842 -- First, verify that the construct has the proper form
15844 if not Expander_Active then
15845 return False;
15847 elsif Nkind (Pref) /= N_Selected_Component then
15848 return False;
15850 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
15851 return False;
15853 else
15854 Call := Prefix (Pref);
15855 Ref_Typ := Etype (Call);
15856 end if;
15858 if not Has_Implicit_Dereference (Ref_Typ)
15859 or else No (First (Parameter_Associations (Call)))
15860 or else not Is_Entity_Name (Name (Call))
15861 then
15862 return False;
15863 end if;
15865 -- Retrieve type of container object, and its iterator aspects
15867 Cont_Typ := Etype (First (Parameter_Associations (Call)));
15868 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
15869 Is_Const := False;
15871 if No (Indexing) then
15873 -- Container should have at least one indexing operation
15875 return False;
15877 elsif Entity (Name (Call)) /= Entity (Indexing) then
15879 -- This may be a variable indexing operation
15881 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
15883 if No (Indexing)
15884 or else Entity (Name (Call)) /= Entity (Indexing)
15885 then
15886 return False;
15887 end if;
15889 else
15890 Is_Const := True;
15891 end if;
15893 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
15895 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
15896 return False;
15897 end if;
15899 -- Check that the expression is not the target of an assignment, in
15900 -- which case the rewriting is not possible.
15902 if not Is_Const then
15903 declare
15904 Par : Node_Id;
15906 begin
15907 Par := Exp;
15908 while Present (Par)
15909 loop
15910 if Nkind (Parent (Par)) = N_Assignment_Statement
15911 and then Par = Name (Parent (Par))
15912 then
15913 return False;
15915 -- A renaming produces a reference, and the transformation
15916 -- does not apply.
15918 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
15919 return False;
15921 elsif Nkind (Parent (Par)) in N_Entry_Call_Statement
15922 | N_Subprogram_Call
15923 then
15924 -- Check that the element is not part of an actual for an
15925 -- in-out parameter.
15927 declare
15928 F : Entity_Id;
15929 A : Node_Id;
15931 begin
15932 F := First_Formal (Entity (Name (Parent (Par))));
15933 A := First_Actual (Parent (Par));
15934 while Present (F) loop
15935 if A = Par and then Ekind (F) /= E_In_Parameter then
15936 return False;
15937 end if;
15939 Next_Formal (F);
15940 Next_Actual (A);
15941 end loop;
15942 end;
15944 -- E_In_Parameter in a call: element is not modified.
15946 exit;
15947 end if;
15949 Par := Parent (Par);
15950 end loop;
15951 end;
15952 end if;
15954 -- The expression has the proper form and the context requires the
15955 -- element type. Retrieve the Element function of the container and
15956 -- rewrite the construct as a call to it.
15958 declare
15959 Op : Elmt_Id;
15961 begin
15962 Op := First_Elmt (Primitive_Operations (Cont_Typ));
15963 while Present (Op) loop
15964 exit when Chars (Node (Op)) = Name_Element;
15965 Next_Elmt (Op);
15966 end loop;
15968 if No (Op) then
15969 return False;
15971 else
15972 Rewrite (Exp,
15973 Make_Function_Call (Loc,
15974 Name => New_Occurrence_Of (Node (Op), Loc),
15975 Parameter_Associations => Parameter_Associations (Call)));
15976 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
15977 return True;
15978 end if;
15979 end;
15980 end Is_Container_Element;
15982 ----------------------------
15983 -- Is_Contract_Annotation --
15984 ----------------------------
15986 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
15987 begin
15988 return Is_Package_Contract_Annotation (Item)
15989 or else
15990 Is_Subprogram_Contract_Annotation (Item);
15991 end Is_Contract_Annotation;
15993 --------------------------------------
15994 -- Is_Controlling_Limited_Procedure --
15995 --------------------------------------
15997 function Is_Controlling_Limited_Procedure
15998 (Proc_Nam : Entity_Id) return Boolean
16000 Param : Node_Id;
16001 Param_Typ : Entity_Id := Empty;
16003 begin
16004 if Ekind (Proc_Nam) = E_Procedure
16005 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
16006 then
16007 Param :=
16008 Parameter_Type
16009 (First (Parameter_Specifications (Parent (Proc_Nam))));
16011 -- The formal may be an anonymous access type
16013 if Nkind (Param) = N_Access_Definition then
16014 Param_Typ := Entity (Subtype_Mark (Param));
16015 else
16016 Param_Typ := Etype (Param);
16017 end if;
16019 -- In the case where an Itype was created for a dispatching call, the
16020 -- procedure call has been rewritten. The actual may be an access to
16021 -- interface type in which case it is the designated type that is the
16022 -- controlling type.
16024 elsif Present (Associated_Node_For_Itype (Proc_Nam))
16025 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
16026 and then
16027 Present (Parameter_Associations
16028 (Associated_Node_For_Itype (Proc_Nam)))
16029 then
16030 Param_Typ :=
16031 Etype (First (Parameter_Associations
16032 (Associated_Node_For_Itype (Proc_Nam))));
16034 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
16035 Param_Typ := Directly_Designated_Type (Param_Typ);
16036 end if;
16037 end if;
16039 if Present (Param_Typ) then
16040 return
16041 Is_Interface (Param_Typ)
16042 and then Is_Limited_Record (Param_Typ);
16043 end if;
16045 return False;
16046 end Is_Controlling_Limited_Procedure;
16048 -----------------------------
16049 -- Is_CPP_Constructor_Call --
16050 -----------------------------
16052 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
16053 Ret_Typ : Entity_Id;
16055 begin
16056 if Nkind (N) /= N_Function_Call then
16057 return False;
16058 end if;
16060 Ret_Typ := Base_Type (Etype (N));
16062 if Is_Class_Wide_Type (Ret_Typ) then
16063 Ret_Typ := Root_Type (Ret_Typ);
16064 end if;
16066 if Is_Private_Type (Ret_Typ) then
16067 Ret_Typ := Underlying_Type (Ret_Typ);
16068 end if;
16070 return Present (Ret_Typ)
16071 and then Is_CPP_Class (Ret_Typ)
16072 and then Is_Constructor (Entity (Name (N)))
16073 and then Is_Imported (Entity (Name (N)));
16074 end Is_CPP_Constructor_Call;
16076 -------------------------
16077 -- Is_Current_Instance --
16078 -------------------------
16080 function Is_Current_Instance (N : Node_Id) return Boolean is
16081 Typ : constant Entity_Id := Entity (N);
16082 P : Node_Id;
16084 begin
16085 -- Since Ada 2005, the "current instance" rule does not apply
16086 -- to a type_mark in an access_definition (RM 8.6),
16087 -- although it does apply in an access_to_object definition.
16088 -- So the rule does not apply in the definition of an anonymous
16089 -- access type, but it does apply in the definition of a named
16090 -- access-to-object type.
16091 -- The rule also does not apply in a designated subprogram profile.
16093 if Ada_Version >= Ada_2005 then
16094 case Nkind (Parent (N)) is
16095 when N_Access_Definition | N_Access_Function_Definition =>
16096 return False;
16097 when N_Parameter_Specification =>
16098 if Nkind (Parent (Parent (N))) in
16099 N_Access_To_Subprogram_Definition
16100 then
16101 return False;
16102 end if;
16103 when others =>
16104 null;
16105 end case;
16106 end if;
16108 -- Simplest case: entity is a concurrent type and we are currently
16109 -- inside the body. This will eventually be expanded into a call to
16110 -- Self (for tasks) or _object (for protected objects).
16112 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
16113 return True;
16115 else
16116 -- Check whether the context is a (sub)type declaration for the
16117 -- type entity.
16119 P := Parent (N);
16120 while Present (P) loop
16121 if Nkind (P) in N_Full_Type_Declaration
16122 | N_Private_Type_Declaration
16123 | N_Subtype_Declaration
16124 and then Comes_From_Source (P)
16126 -- If the type has a previous incomplete declaration, the
16127 -- reference in the type definition may have the incomplete
16128 -- view. So, here we detect if this incomplete view is a current
16129 -- instance by checking if its full view is the entity of the
16130 -- full declaration begin analyzed.
16132 and then
16133 (Defining_Entity (P) = Typ
16134 or else
16135 (Ekind (Typ) = E_Incomplete_Type
16136 and then Full_View (Typ) = Defining_Entity (P)))
16137 then
16138 return True;
16140 -- A subtype name may appear in an aspect specification for a
16141 -- Predicate_Failure aspect, for which we do not construct a
16142 -- wrapper procedure. The subtype will be replaced by the
16143 -- expression being tested when the corresponding predicate
16144 -- check is expanded. It may also appear in the pragma Predicate
16145 -- expression during legality checking.
16147 elsif Nkind (P) = N_Aspect_Specification
16148 and then Nkind (Parent (P)) = N_Subtype_Declaration
16149 and then Underlying_Type (Defining_Identifier (Parent (P))) =
16150 Underlying_Type (Typ)
16151 then
16152 return True;
16154 elsif Nkind (P) = N_Pragma
16155 and then Get_Pragma_Id (P) in Pragma_Predicate
16156 | Pragma_Predicate_Failure
16158 -- For "pragma Predicate (T, Is_OK (T))", return False for the
16159 -- first use of T and True for the second.
16161 and then
16162 N /= Expression (First (Pragma_Argument_Associations (P)))
16163 then
16164 declare
16165 Arg : constant Entity_Id :=
16166 Entity (Expression (Get_Argument (P)));
16167 begin
16168 if Underlying_Type (Arg) = Underlying_Type (Typ) then
16169 return True;
16170 end if;
16171 end;
16172 end if;
16174 P := Parent (P);
16175 end loop;
16176 end if;
16178 -- In any other context this is not a current instance reference.
16180 return False;
16181 end Is_Current_Instance;
16183 --------------------------------------------------
16184 -- Is_Current_Instance_Reference_In_Type_Aspect --
16185 --------------------------------------------------
16187 function Is_Current_Instance_Reference_In_Type_Aspect
16188 (N : Node_Id) return Boolean
16190 begin
16191 -- When a current_instance is referenced within an aspect_specification
16192 -- of a type or subtype, it will show up as a reference to the formal
16193 -- parameter of the aspect's associated subprogram rather than as a
16194 -- reference to the type or subtype itself (in fact, the original name
16195 -- is never even analyzed). We check for predicate, invariant, and
16196 -- Default_Initial_Condition subprograms (in theory there could be
16197 -- other cases added, in which case this function will need updating).
16199 if Is_Entity_Name (N) then
16200 return Present (Entity (N))
16201 and then Ekind (Entity (N)) = E_In_Parameter
16202 and then Ekind (Scope (Entity (N))) in E_Function | E_Procedure
16203 and then
16204 (Is_Predicate_Function (Scope (Entity (N)))
16205 or else Is_Invariant_Procedure (Scope (Entity (N)))
16206 or else Is_Partial_Invariant_Procedure (Scope (Entity (N)))
16207 or else Is_DIC_Procedure (Scope (Entity (N))));
16209 else
16210 case Nkind (N) is
16211 when N_Indexed_Component
16212 | N_Slice
16214 return
16215 Is_Current_Instance_Reference_In_Type_Aspect (Prefix (N));
16217 when N_Selected_Component =>
16218 return
16219 Is_Current_Instance_Reference_In_Type_Aspect (Prefix (N));
16221 when N_Type_Conversion =>
16222 return Is_Current_Instance_Reference_In_Type_Aspect
16223 (Expression (N));
16225 when N_Qualified_Expression =>
16226 return Is_Current_Instance_Reference_In_Type_Aspect
16227 (Expression (N));
16229 when others =>
16230 return False;
16231 end case;
16232 end if;
16233 end Is_Current_Instance_Reference_In_Type_Aspect;
16235 --------------------
16236 -- Is_Declaration --
16237 --------------------
16239 function Is_Declaration
16240 (N : Node_Id;
16241 Body_OK : Boolean := True;
16242 Concurrent_OK : Boolean := True;
16243 Formal_OK : Boolean := True;
16244 Generic_OK : Boolean := True;
16245 Instantiation_OK : Boolean := True;
16246 Renaming_OK : Boolean := True;
16247 Stub_OK : Boolean := True;
16248 Subprogram_OK : Boolean := True;
16249 Type_OK : Boolean := True) return Boolean
16251 begin
16252 case Nkind (N) is
16254 -- Body declarations
16256 when N_Proper_Body =>
16257 return Body_OK;
16259 -- Concurrent type declarations
16261 when N_Protected_Type_Declaration
16262 | N_Single_Protected_Declaration
16263 | N_Single_Task_Declaration
16264 | N_Task_Type_Declaration
16266 return Concurrent_OK or Type_OK;
16268 -- Formal declarations
16270 when N_Formal_Abstract_Subprogram_Declaration
16271 | N_Formal_Concrete_Subprogram_Declaration
16272 | N_Formal_Object_Declaration
16273 | N_Formal_Package_Declaration
16274 | N_Formal_Type_Declaration
16276 return Formal_OK;
16278 -- Generic declarations
16280 when N_Generic_Package_Declaration
16281 | N_Generic_Subprogram_Declaration
16283 return Generic_OK;
16285 -- Generic instantiations
16287 when N_Function_Instantiation
16288 | N_Package_Instantiation
16289 | N_Procedure_Instantiation
16291 return Instantiation_OK;
16293 -- Generic renaming declarations
16295 when N_Generic_Renaming_Declaration =>
16296 return Generic_OK or Renaming_OK;
16298 -- Renaming declarations
16300 when N_Exception_Renaming_Declaration
16301 | N_Object_Renaming_Declaration
16302 | N_Package_Renaming_Declaration
16303 | N_Subprogram_Renaming_Declaration
16305 return Renaming_OK;
16307 -- Stub declarations
16309 when N_Body_Stub =>
16310 return Stub_OK;
16312 -- Subprogram declarations
16314 when N_Abstract_Subprogram_Declaration
16315 | N_Entry_Declaration
16316 | N_Expression_Function
16317 | N_Subprogram_Declaration
16319 return Subprogram_OK;
16321 -- Type declarations
16323 when N_Full_Type_Declaration
16324 | N_Incomplete_Type_Declaration
16325 | N_Private_Extension_Declaration
16326 | N_Private_Type_Declaration
16327 | N_Subtype_Declaration
16329 return Type_OK;
16331 -- Miscellaneous
16333 when N_Component_Declaration
16334 | N_Exception_Declaration
16335 | N_Implicit_Label_Declaration
16336 | N_Number_Declaration
16337 | N_Object_Declaration
16338 | N_Package_Declaration
16340 return True;
16342 when others =>
16343 return False;
16344 end case;
16345 end Is_Declaration;
16347 --------------------------------
16348 -- Is_Declared_Within_Variant --
16349 --------------------------------
16351 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
16352 Comp_Decl : constant Node_Id := Parent (Comp);
16353 Comp_List : constant Node_Id := Parent (Comp_Decl);
16354 begin
16355 return Nkind (Parent (Comp_List)) = N_Variant;
16356 end Is_Declared_Within_Variant;
16358 ----------------------------------------------
16359 -- Is_Dependent_Component_Of_Mutable_Object --
16360 ----------------------------------------------
16362 function Is_Dependent_Component_Of_Mutable_Object
16363 (Object : Node_Id) return Boolean
16365 P : Node_Id;
16366 Prefix_Type : Entity_Id;
16367 P_Aliased : Boolean := False;
16368 Comp : Entity_Id;
16370 Deref : Node_Id := Original_Node (Object);
16371 -- Dereference node, in something like X.all.Y(2)
16373 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
16375 begin
16376 -- Find the dereference node if any
16378 while Nkind (Deref) in
16379 N_Indexed_Component | N_Selected_Component | N_Slice
16380 loop
16381 Deref := Original_Node (Prefix (Deref));
16382 end loop;
16384 -- If the prefix is a qualified expression of a variable, then function
16385 -- Is_Variable will return False for that because a qualified expression
16386 -- denotes a constant view, so we need to get the name being qualified
16387 -- so we can test below whether that's a variable (or a dereference).
16389 if Nkind (Deref) = N_Qualified_Expression then
16390 Deref := Expression (Deref);
16391 end if;
16393 -- Ada 2005: If we have a component or slice of a dereference, something
16394 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
16395 -- will return False, because it is indeed a constant view. But it might
16396 -- be a view of a variable object, so we want the following condition to
16397 -- be True in that case.
16399 if Is_Variable (Object)
16400 or else Is_Variable (Deref)
16401 or else
16402 (Ada_Version >= Ada_2005
16403 and then (Nkind (Deref) = N_Explicit_Dereference
16404 or else (Present (Etype (Deref))
16405 and then Is_Access_Type (Etype (Deref)))))
16406 then
16407 if Nkind (Object) = N_Selected_Component then
16409 -- If the selector is not a component, then we definitely return
16410 -- False (it could be a function selector in a prefix form call
16411 -- occurring in an iterator specification).
16413 if (Present (Entity (Selector_Name (Object)))
16414 and then Ekind (Entity (Selector_Name (Object))) not in
16415 E_Component | E_Discriminant)
16416 or else
16417 (Inside_A_Generic
16418 and then Nkind (Parent (Selector_Name (Object)))
16419 = N_Function_Call)
16420 then
16421 return False;
16422 end if;
16424 -- Get the original node of the prefix in case it has been
16425 -- rewritten, which can occur, for example, in qualified
16426 -- expression cases. Also, a discriminant check on a selected
16427 -- component may be expanded into a dereference when removing
16428 -- side effects, and the subtype of the original node may be
16429 -- unconstrained.
16431 P := Original_Node (Prefix (Object));
16432 Prefix_Type := Etype (P);
16434 -- If the prefix is a qualified expression, we want to look at its
16435 -- operand.
16437 if Nkind (P) = N_Qualified_Expression then
16438 P := Expression (P);
16439 Prefix_Type := Etype (P);
16440 end if;
16442 if Is_Entity_Name (P) then
16443 -- The Etype may not be set on P (which is wrong) in certain
16444 -- corner cases involving the deprecated front-end inlining of
16445 -- subprograms (via -gnatN), so use the Etype set on the
16446 -- the entity for these instances since we know it is present.
16448 if No (Prefix_Type) then
16449 Prefix_Type := Etype (Entity (P));
16450 end if;
16452 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
16453 Prefix_Type := Base_Type (Prefix_Type);
16454 end if;
16456 if Is_Aliased (Entity (P)) then
16457 P_Aliased := True;
16458 end if;
16460 -- For explicit dereferences we get the access prefix so we can
16461 -- treat this similarly to implicit dereferences and examine the
16462 -- kind of the access type and its designated subtype further
16463 -- below.
16465 elsif Nkind (P) = N_Explicit_Dereference then
16466 P := Prefix (P);
16467 Prefix_Type := Etype (P);
16469 else
16470 -- Check for prefix being an aliased component???
16472 null;
16473 end if;
16475 -- A heap object is constrained by its initial value
16477 -- Ada 2005 (AI-363): Always assume the object could be mutable in
16478 -- the dereferenced case, since the access value might denote an
16479 -- unconstrained aliased object, whereas in Ada 95 the designated
16480 -- object is guaranteed to be constrained. A worst-case assumption
16481 -- has to apply in Ada 2005 because we can't tell at compile
16482 -- time whether the object is "constrained by its initial value",
16483 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
16484 -- rules (these rules are acknowledged to need fixing). We don't
16485 -- impose this more stringent checking for earlier Ada versions or
16486 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
16487 -- benefit, though it's unclear on why using -gnat95 would not be
16488 -- sufficient???).
16490 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
16491 if Is_Access_Type (Prefix_Type)
16492 or else Nkind (P) = N_Explicit_Dereference
16493 then
16494 return False;
16495 end if;
16497 else pragma Assert (Ada_Version >= Ada_2005);
16498 if Is_Access_Type (Prefix_Type) then
16499 -- We need to make sure we have the base subtype, in case
16500 -- this is actually an access subtype (whose Ekind will be
16501 -- E_Access_Subtype).
16503 Prefix_Type := Etype (Prefix_Type);
16505 -- If the access type is pool-specific, and there is no
16506 -- constrained partial view of the designated type, then the
16507 -- designated object is known to be constrained. If it's a
16508 -- formal access type and the renaming is in the generic
16509 -- spec, we also treat it as pool-specific (known to be
16510 -- constrained), but assume the worst if in the generic body
16511 -- (see RM 3.3(23.3/3)).
16513 if Ekind (Prefix_Type) = E_Access_Type
16514 and then (not Is_Generic_Type (Prefix_Type)
16515 or else not In_Generic_Body (Current_Scope))
16516 and then not Object_Type_Has_Constrained_Partial_View
16517 (Typ => Designated_Type (Prefix_Type),
16518 Scop => Current_Scope)
16519 then
16520 return False;
16522 -- Otherwise (general access type, or there is a constrained
16523 -- partial view of the designated type), we need to check
16524 -- based on the designated type.
16526 else
16527 Prefix_Type := Designated_Type (Prefix_Type);
16528 end if;
16529 end if;
16530 end if;
16532 Comp :=
16533 Original_Record_Component (Entity (Selector_Name (Object)));
16535 -- As per AI-0017, the renaming is illegal in a generic body, even
16536 -- if the subtype is indefinite (only applies to prefixes of an
16537 -- untagged formal type, see RM 3.3 (23.11/3)).
16539 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
16541 if not Is_Constrained (Prefix_Type)
16542 and then (Is_Definite_Subtype (Prefix_Type)
16543 or else
16544 (not Is_Tagged_Type (Prefix_Type)
16545 and then Is_Generic_Type (Prefix_Type)
16546 and then In_Generic_Body (Current_Scope)))
16548 and then (Is_Declared_Within_Variant (Comp)
16549 or else Has_Discriminant_Dependent_Constraint (Comp))
16550 and then (not P_Aliased or else Ada_Version >= Ada_2005)
16551 then
16552 return True;
16554 -- If the prefix is of an access type at this point, then we want
16555 -- to return False, rather than calling this function recursively
16556 -- on the access object (which itself might be a discriminant-
16557 -- dependent component of some other object, but that isn't
16558 -- relevant to checking the object passed to us). This avoids
16559 -- issuing wrong errors when compiling with -gnatc, where there
16560 -- can be implicit dereferences that have not been expanded.
16562 elsif Is_Access_Type (Etype (Prefix (Object))) then
16563 return False;
16565 else
16566 return
16567 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
16568 end if;
16570 elsif Nkind (Object) = N_Indexed_Component
16571 or else Nkind (Object) = N_Slice
16572 then
16573 return Is_Dependent_Component_Of_Mutable_Object
16574 (Original_Node (Prefix (Object)));
16576 -- A type conversion that Is_Variable is a view conversion:
16577 -- go back to the denoted object.
16579 elsif Nkind (Object) = N_Type_Conversion then
16580 return
16581 Is_Dependent_Component_Of_Mutable_Object
16582 (Original_Node (Expression (Object)));
16583 end if;
16584 end if;
16586 return False;
16587 end Is_Dependent_Component_Of_Mutable_Object;
16589 ---------------------
16590 -- Is_Dereferenced --
16591 ---------------------
16593 function Is_Dereferenced (N : Node_Id) return Boolean is
16594 P : constant Node_Id := Parent (N);
16595 begin
16596 return Nkind (P) in N_Selected_Component
16597 | N_Explicit_Dereference
16598 | N_Indexed_Component
16599 | N_Slice
16600 and then Prefix (P) = N;
16601 end Is_Dereferenced;
16603 ----------------------
16604 -- Is_Descendant_Of --
16605 ----------------------
16607 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
16608 T : Entity_Id;
16609 Etyp : Entity_Id;
16611 begin
16612 pragma Assert (Nkind (T1) in N_Entity);
16613 pragma Assert (Nkind (T2) in N_Entity);
16615 T := Base_Type (T1);
16617 -- Immediate return if the types match
16619 if T = T2 then
16620 return True;
16622 -- Comment needed here ???
16624 elsif Ekind (T) = E_Class_Wide_Type then
16625 return Etype (T) = T2;
16627 -- All other cases
16629 else
16630 loop
16631 Etyp := Etype (T);
16633 -- Done if we found the type we are looking for
16635 if Etyp = T2 then
16636 return True;
16638 -- Done if no more derivations to check
16640 elsif T = T1
16641 or else T = Etyp
16642 then
16643 return False;
16645 -- Following test catches error cases resulting from prev errors
16647 elsif No (Etyp) then
16648 return False;
16650 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
16651 return False;
16653 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
16654 return False;
16655 end if;
16657 T := Base_Type (Etyp);
16658 end loop;
16659 end if;
16660 end Is_Descendant_Of;
16662 ----------------------------------------
16663 -- Is_Descendant_Of_Suspension_Object --
16664 ----------------------------------------
16666 function Is_Descendant_Of_Suspension_Object
16667 (Typ : Entity_Id) return Boolean
16669 Cur_Typ : Entity_Id;
16670 Par_Typ : Entity_Id;
16672 begin
16673 -- Climb the type derivation chain checking each parent type against
16674 -- Suspension_Object.
16676 Cur_Typ := Base_Type (Typ);
16677 while Present (Cur_Typ) loop
16678 Par_Typ := Etype (Cur_Typ);
16680 -- The current type is a match
16682 if Is_RTE (Cur_Typ, RE_Suspension_Object) then
16683 return True;
16685 -- Stop the traversal once the root of the derivation chain has been
16686 -- reached. In that case the current type is its own base type.
16688 elsif Cur_Typ = Par_Typ then
16689 exit;
16690 end if;
16692 Cur_Typ := Base_Type (Par_Typ);
16693 end loop;
16695 return False;
16696 end Is_Descendant_Of_Suspension_Object;
16698 ---------------------------------------------
16699 -- Is_Double_Precision_Floating_Point_Type --
16700 ---------------------------------------------
16702 function Is_Double_Precision_Floating_Point_Type
16703 (E : Entity_Id) return Boolean is
16704 begin
16705 return Is_Floating_Point_Type (E)
16706 and then Machine_Radix_Value (E) = Uint_2
16707 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
16708 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
16709 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
16710 end Is_Double_Precision_Floating_Point_Type;
16712 -----------------------------
16713 -- Is_Effectively_Volatile --
16714 -----------------------------
16716 function Is_Effectively_Volatile
16717 (Id : Entity_Id;
16718 Ignore_Protected : Boolean := False) return Boolean is
16719 begin
16720 if Is_Type (Id) then
16722 -- An arbitrary type is effectively volatile when it is subject to
16723 -- pragma Atomic or Volatile, unless No_Caching is enabled.
16725 if Is_Volatile (Id)
16726 and then not No_Caching_Enabled (Id)
16727 then
16728 return True;
16730 -- An array type is effectively volatile when it is subject to pragma
16731 -- Atomic_Components or Volatile_Components or its component type is
16732 -- effectively volatile.
16734 elsif Is_Array_Type (Id) then
16735 if Has_Volatile_Components (Id) then
16736 return True;
16737 else
16738 declare
16739 Anc : Entity_Id := Base_Type (Id);
16740 begin
16741 if Is_Private_Type (Anc) then
16742 Anc := Full_View (Anc);
16743 end if;
16745 -- Test for presence of ancestor, as the full view of a
16746 -- private type may be missing in case of error.
16748 return Present (Anc)
16749 and then Is_Effectively_Volatile
16750 (Component_Type (Anc), Ignore_Protected);
16751 end;
16752 end if;
16754 -- A protected type is always volatile unless Ignore_Protected is
16755 -- True.
16757 elsif Is_Protected_Type (Id) and then not Ignore_Protected then
16758 return True;
16760 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
16761 -- automatically volatile.
16763 elsif Is_Descendant_Of_Suspension_Object (Id) then
16764 return True;
16766 -- Otherwise the type is not effectively volatile
16768 else
16769 return False;
16770 end if;
16772 -- Otherwise Id denotes an object
16774 else pragma Assert (Is_Object (Id));
16775 -- A volatile object for which No_Caching is enabled is not
16776 -- effectively volatile.
16778 return
16779 (Is_Volatile (Id)
16780 and then not
16781 (Ekind (Id) = E_Variable and then No_Caching_Enabled (Id)))
16782 or else Has_Volatile_Components (Id)
16783 or else Is_Effectively_Volatile (Etype (Id), Ignore_Protected);
16784 end if;
16785 end Is_Effectively_Volatile;
16787 -----------------------------------------
16788 -- Is_Effectively_Volatile_For_Reading --
16789 -----------------------------------------
16791 function Is_Effectively_Volatile_For_Reading
16792 (Id : Entity_Id;
16793 Ignore_Protected : Boolean := False) return Boolean
16795 begin
16796 -- A concurrent type is effectively volatile for reading, except for a
16797 -- protected type when Ignore_Protected is True.
16799 if Is_Task_Type (Id)
16800 or else (Is_Protected_Type (Id) and then not Ignore_Protected)
16801 then
16802 return True;
16804 elsif Is_Effectively_Volatile (Id, Ignore_Protected) then
16806 -- Other volatile types and objects are effectively volatile for
16807 -- reading when they have property Async_Writers or Effective_Reads
16808 -- set to True. This includes the case of an array type whose
16809 -- Volatile_Components aspect is True (hence it is effectively
16810 -- volatile) which does not have the properties Async_Writers
16811 -- and Effective_Reads set to False.
16813 if Async_Writers_Enabled (Id)
16814 or else Effective_Reads_Enabled (Id)
16815 then
16816 return True;
16818 -- In addition, an array type is effectively volatile for reading
16819 -- when its component type is effectively volatile for reading.
16821 elsif Is_Array_Type (Id) then
16822 declare
16823 Anc : Entity_Id := Base_Type (Id);
16824 begin
16825 if Is_Private_Type (Anc) then
16826 Anc := Full_View (Anc);
16827 end if;
16829 -- Test for presence of ancestor, as the full view of a
16830 -- private type may be missing in case of error.
16832 return Present (Anc)
16833 and then Is_Effectively_Volatile_For_Reading
16834 (Component_Type (Anc), Ignore_Protected);
16835 end;
16836 end if;
16837 end if;
16839 return False;
16841 end Is_Effectively_Volatile_For_Reading;
16843 ------------------------------------
16844 -- Is_Effectively_Volatile_Object --
16845 ------------------------------------
16847 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
16848 function Is_Effectively_Volatile (E : Entity_Id) return Boolean is
16849 (Is_Effectively_Volatile (E, Ignore_Protected => False));
16851 function Is_Effectively_Volatile_Object_Inst
16852 is new Is_Effectively_Volatile_Object_Shared (Is_Effectively_Volatile);
16853 begin
16854 return Is_Effectively_Volatile_Object_Inst (N);
16855 end Is_Effectively_Volatile_Object;
16857 ------------------------------------------------
16858 -- Is_Effectively_Volatile_Object_For_Reading --
16859 ------------------------------------------------
16861 function Is_Effectively_Volatile_Object_For_Reading
16862 (N : Node_Id) return Boolean
16864 function Is_Effectively_Volatile_For_Reading
16865 (E : Entity_Id) return Boolean
16866 is (Is_Effectively_Volatile_For_Reading (E, Ignore_Protected => False));
16868 function Is_Effectively_Volatile_Object_For_Reading_Inst
16869 is new Is_Effectively_Volatile_Object_Shared
16870 (Is_Effectively_Volatile_For_Reading);
16871 begin
16872 return Is_Effectively_Volatile_Object_For_Reading_Inst (N);
16873 end Is_Effectively_Volatile_Object_For_Reading;
16875 -------------------------------------------
16876 -- Is_Effectively_Volatile_Object_Shared --
16877 -------------------------------------------
16879 function Is_Effectively_Volatile_Object_Shared
16880 (N : Node_Id) return Boolean
16882 begin
16883 if Is_Entity_Name (N) then
16884 return Is_Object (Entity (N))
16885 and then Is_Effectively_Volatile_Entity (Entity (N));
16887 elsif Nkind (N) in N_Indexed_Component | N_Slice then
16888 return Is_Effectively_Volatile_Object_Shared (Prefix (N));
16890 elsif Nkind (N) = N_Selected_Component then
16891 return
16892 Is_Effectively_Volatile_Object_Shared (Prefix (N))
16893 or else
16894 Is_Effectively_Volatile_Object_Shared (Selector_Name (N));
16896 elsif Nkind (N) in N_Qualified_Expression
16897 | N_Unchecked_Type_Conversion
16898 | N_Type_Conversion
16899 then
16900 return Is_Effectively_Volatile_Object_Shared (Expression (N));
16902 else
16903 return False;
16904 end if;
16905 end Is_Effectively_Volatile_Object_Shared;
16907 ----------------------------------------
16908 -- Is_Entity_Of_Quantified_Expression --
16909 ----------------------------------------
16911 function Is_Entity_Of_Quantified_Expression (Id : Entity_Id) return Boolean
16913 Par : constant Node_Id := Parent (Id);
16915 begin
16916 return (Nkind (Par) = N_Loop_Parameter_Specification
16917 or else Nkind (Par) = N_Iterator_Specification)
16918 and then Defining_Identifier (Par) = Id
16919 and then Nkind (Parent (Par)) = N_Quantified_Expression;
16920 end Is_Entity_Of_Quantified_Expression;
16922 -------------------
16923 -- Is_Entry_Body --
16924 -------------------
16926 function Is_Entry_Body (Id : Entity_Id) return Boolean is
16927 begin
16928 return
16929 Is_Entry (Id)
16930 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
16931 end Is_Entry_Body;
16933 --------------------------
16934 -- Is_Entry_Declaration --
16935 --------------------------
16937 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
16938 begin
16939 return
16940 Is_Entry (Id)
16941 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
16942 end Is_Entry_Declaration;
16944 ------------------------------------
16945 -- Is_Expanded_Priority_Attribute --
16946 ------------------------------------
16948 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
16949 begin
16950 return
16951 Nkind (E) = N_Function_Call
16952 and then not Configurable_Run_Time_Mode
16953 and then Nkind (Original_Node (E)) = N_Attribute_Reference
16954 and then (Is_RTE (Entity (Name (E)), RE_Get_Ceiling)
16955 or else Is_RTE (Entity (Name (E)), RO_PE_Get_Ceiling));
16956 end Is_Expanded_Priority_Attribute;
16958 ----------------------------
16959 -- Is_Expression_Function --
16960 ----------------------------
16962 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
16963 begin
16964 if Ekind (Subp) in E_Function | E_Subprogram_Body then
16965 return
16966 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
16967 N_Expression_Function;
16968 else
16969 return False;
16970 end if;
16971 end Is_Expression_Function;
16973 ------------------------------------------
16974 -- Is_Expression_Function_Or_Completion --
16975 ------------------------------------------
16977 function Is_Expression_Function_Or_Completion
16978 (Subp : Entity_Id) return Boolean
16980 Subp_Decl : Node_Id;
16982 begin
16983 if Ekind (Subp) = E_Function then
16984 Subp_Decl := Unit_Declaration_Node (Subp);
16986 -- The function declaration is either an expression function or is
16987 -- completed by an expression function body.
16989 return
16990 Is_Expression_Function (Subp)
16991 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
16992 and then Present (Corresponding_Body (Subp_Decl))
16993 and then Is_Expression_Function
16994 (Corresponding_Body (Subp_Decl)));
16996 elsif Ekind (Subp) = E_Subprogram_Body then
16997 return Is_Expression_Function (Subp);
16999 else
17000 return False;
17001 end if;
17002 end Is_Expression_Function_Or_Completion;
17004 -----------------------------------------------
17005 -- Is_Extended_Precision_Floating_Point_Type --
17006 -----------------------------------------------
17008 function Is_Extended_Precision_Floating_Point_Type
17009 (E : Entity_Id) return Boolean is
17010 begin
17011 return Is_Floating_Point_Type (E)
17012 and then Machine_Radix_Value (E) = Uint_2
17013 and then Machine_Mantissa_Value (E) = Uint_64
17014 and then Machine_Emax_Value (E) = Uint_2 ** Uint_14
17015 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_14);
17016 end Is_Extended_Precision_Floating_Point_Type;
17018 -----------------------
17019 -- Is_EVF_Expression --
17020 -----------------------
17022 function Is_EVF_Expression (N : Node_Id) return Boolean is
17023 Orig_N : constant Node_Id := Original_Node (N);
17024 Alt : Node_Id;
17025 Expr : Node_Id;
17026 Id : Entity_Id;
17028 begin
17029 -- Detect a reference to a formal parameter of a specific tagged type
17030 -- whose related subprogram is subject to pragma Expresions_Visible with
17031 -- value "False".
17033 if Is_Entity_Name (N) and then Present (Entity (N)) then
17034 Id := Entity (N);
17036 return
17037 Is_Formal (Id)
17038 and then Is_Specific_Tagged_Type (Etype (Id))
17039 and then Extensions_Visible_Status (Id) =
17040 Extensions_Visible_False;
17042 -- A case expression is an EVF expression when it contains at least one
17043 -- EVF dependent_expression. Note that a case expression may have been
17044 -- expanded, hence the use of Original_Node.
17046 elsif Nkind (Orig_N) = N_Case_Expression then
17047 Alt := First (Alternatives (Orig_N));
17048 while Present (Alt) loop
17049 if Is_EVF_Expression (Expression (Alt)) then
17050 return True;
17051 end if;
17053 Next (Alt);
17054 end loop;
17056 -- An if expression is an EVF expression when it contains at least one
17057 -- EVF dependent_expression. Note that an if expression may have been
17058 -- expanded, hence the use of Original_Node.
17060 elsif Nkind (Orig_N) = N_If_Expression then
17061 Expr := Next (First (Expressions (Orig_N)));
17062 while Present (Expr) loop
17063 if Is_EVF_Expression (Expr) then
17064 return True;
17065 end if;
17067 Next (Expr);
17068 end loop;
17070 -- A qualified expression or a type conversion is an EVF expression when
17071 -- its operand is an EVF expression.
17073 elsif Nkind (N) in N_Qualified_Expression
17074 | N_Unchecked_Type_Conversion
17075 | N_Type_Conversion
17076 then
17077 return Is_EVF_Expression (Expression (N));
17079 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
17080 -- their prefix denotes an EVF expression.
17082 elsif Nkind (N) = N_Attribute_Reference
17083 and then Attribute_Name (N) in Name_Loop_Entry
17084 | Name_Old
17085 | Name_Update
17086 then
17087 return Is_EVF_Expression (Prefix (N));
17088 end if;
17090 return False;
17091 end Is_EVF_Expression;
17093 --------------
17094 -- Is_False --
17095 --------------
17097 function Is_False (U : Opt_Ubool) return Boolean is
17098 begin
17099 return not Is_True (U);
17100 end Is_False;
17102 ---------------------------
17103 -- Is_Fixed_Model_Number --
17104 ---------------------------
17106 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
17107 S : constant Ureal := Small_Value (T);
17108 M : Urealp.Save_Mark;
17109 R : Boolean;
17111 begin
17112 M := Urealp.Mark;
17113 R := (U = UR_Trunc (U / S) * S);
17114 Urealp.Release (M);
17115 return R;
17116 end Is_Fixed_Model_Number;
17118 -----------------------------
17119 -- Is_Full_Access_Object --
17120 -----------------------------
17122 function Is_Full_Access_Object (N : Node_Id) return Boolean is
17123 begin
17124 return Is_Atomic_Object (N)
17125 or else Is_Volatile_Full_Access_Object_Ref (N);
17126 end Is_Full_Access_Object;
17128 -------------------------------
17129 -- Is_Fully_Initialized_Type --
17130 -------------------------------
17132 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
17133 begin
17134 -- Scalar types
17136 if Is_Scalar_Type (Typ) then
17138 -- A scalar type with an aspect Default_Value is fully initialized
17140 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
17141 -- of a scalar type, but we don't take that into account here, since
17142 -- we don't want these to affect warnings.
17144 return Has_Default_Aspect (Typ);
17146 elsif Is_Access_Type (Typ) then
17147 return True;
17149 elsif Is_Array_Type (Typ) then
17150 if Is_Fully_Initialized_Type (Component_Type (Typ))
17151 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
17152 then
17153 return True;
17154 end if;
17156 -- An interesting case, if we have a constrained type one of whose
17157 -- bounds is known to be null, then there are no elements to be
17158 -- initialized, so all the elements are initialized.
17160 if Is_Constrained (Typ) then
17161 declare
17162 Indx : Node_Id;
17163 Indx_Typ : Entity_Id;
17164 Lbd, Hbd : Node_Id;
17166 begin
17167 Indx := First_Index (Typ);
17168 while Present (Indx) loop
17169 if Etype (Indx) = Any_Type then
17170 return False;
17172 -- If index is a range, use directly
17174 elsif Nkind (Indx) = N_Range then
17175 Lbd := Low_Bound (Indx);
17176 Hbd := High_Bound (Indx);
17178 else
17179 Indx_Typ := Etype (Indx);
17181 if Is_Private_Type (Indx_Typ) then
17182 Indx_Typ := Full_View (Indx_Typ);
17183 end if;
17185 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
17186 return False;
17187 else
17188 Lbd := Type_Low_Bound (Indx_Typ);
17189 Hbd := Type_High_Bound (Indx_Typ);
17190 end if;
17191 end if;
17193 if Compile_Time_Known_Value (Lbd)
17194 and then
17195 Compile_Time_Known_Value (Hbd)
17196 then
17197 if Expr_Value (Hbd) < Expr_Value (Lbd) then
17198 return True;
17199 end if;
17200 end if;
17202 Next_Index (Indx);
17203 end loop;
17204 end;
17205 end if;
17207 -- If no null indexes, then type is not fully initialized
17209 return False;
17211 -- Record types
17213 elsif Is_Record_Type (Typ) then
17214 -- Mutably tagged types get default initialized to their parent
17215 -- subtype's default values.
17217 if Is_Mutably_Tagged_CW_Equivalent_Type (Typ) then
17218 return True;
17219 end if;
17221 if Has_Defaulted_Discriminants (Typ)
17222 and then Is_Fully_Initialized_Variant (Typ)
17223 then
17224 return True;
17225 end if;
17227 -- We consider bounded string types to be fully initialized, because
17228 -- otherwise we get false alarms when the Data component is not
17229 -- default-initialized.
17231 if Is_Bounded_String (Typ) then
17232 return True;
17233 end if;
17235 -- Controlled records are considered to be fully initialized if
17236 -- there is a user defined Initialize routine. This may not be
17237 -- entirely correct, but as the spec notes, we are guessing here
17238 -- what is best from the point of view of issuing warnings.
17240 if Is_Controlled (Typ) then
17241 declare
17242 Utyp : constant Entity_Id := Underlying_Type (Typ);
17244 begin
17245 if Present (Utyp) then
17246 declare
17247 Init : constant Entity_Id :=
17248 Find_Controlled_Prim_Op (Utyp, Name_Initialize);
17250 begin
17251 if Present (Init)
17252 and then Comes_From_Source (Init)
17253 and then not In_Predefined_Unit (Init)
17254 then
17255 return True;
17257 elsif Is_Tagged_Type (Typ)
17258 and then Is_Derived_Type (Typ)
17259 and then Has_Null_Extension (Typ)
17260 and then
17261 Is_Fully_Initialized_Type (Etype (Base_Type (Typ)))
17262 then
17263 return True;
17264 end if;
17265 end;
17266 end if;
17267 end;
17268 end if;
17270 -- Otherwise see if all record components are initialized
17272 declare
17273 Comp : Entity_Id;
17275 begin
17276 Comp := First_Component (Typ);
17277 while Present (Comp) loop
17278 if (No (Parent (Comp))
17279 or else No (Expression (Parent (Comp))))
17280 and then not Is_Fully_Initialized_Type (Etype (Comp))
17282 -- Special VM case for tag components, which need to be
17283 -- defined in this case, but are never initialized as VMs
17284 -- are using other dispatching mechanisms. Ignore this
17285 -- uninitialized case. Note that this applies both to the
17286 -- uTag entry and the main vtable pointer (CPP_Class case).
17288 and then (Tagged_Type_Expansion or else not Is_Tag (Comp))
17289 then
17290 return False;
17291 end if;
17293 Next_Component (Comp);
17294 end loop;
17295 end;
17297 -- No uninitialized components, so type is fully initialized.
17298 -- Note that this catches the case of no components as well.
17300 return True;
17302 elsif Is_Concurrent_Type (Typ) then
17303 return True;
17305 elsif Is_Private_Type (Typ) then
17306 declare
17307 U : constant Entity_Id := Underlying_Type (Typ);
17309 begin
17310 if No (U) then
17311 return False;
17312 else
17313 return Is_Fully_Initialized_Type (U);
17314 end if;
17315 end;
17317 else
17318 return False;
17319 end if;
17320 end Is_Fully_Initialized_Type;
17322 ----------------------------------
17323 -- Is_Fully_Initialized_Variant --
17324 ----------------------------------
17326 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
17327 Loc : constant Source_Ptr := Sloc (Typ);
17328 Constraints : constant List_Id := New_List;
17329 Components : constant Elist_Id := New_Elmt_List;
17330 Comp_Elmt : Elmt_Id;
17331 Comp_Id : Node_Id;
17332 Comp_List : Node_Id;
17333 Discr : Entity_Id;
17334 Discr_Val : Node_Id;
17336 Report_Errors : Boolean;
17337 pragma Warnings (Off, Report_Errors);
17339 begin
17340 if Serious_Errors_Detected > 0 then
17341 return False;
17342 end if;
17344 if Is_Record_Type (Typ)
17345 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
17346 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
17347 then
17348 Comp_List := Component_List (Type_Definition (Parent (Typ)));
17350 Discr := First_Discriminant (Typ);
17351 while Present (Discr) loop
17352 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
17353 Discr_Val := Expression (Parent (Discr));
17355 if Present (Discr_Val)
17356 and then Is_OK_Static_Expression (Discr_Val)
17357 then
17358 Append_To (Constraints,
17359 Make_Component_Association (Loc,
17360 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
17361 Expression => New_Copy (Discr_Val)));
17362 else
17363 return False;
17364 end if;
17365 else
17366 return False;
17367 end if;
17369 Next_Discriminant (Discr);
17370 end loop;
17372 Gather_Components
17373 (Typ => Typ,
17374 Comp_List => Comp_List,
17375 Governed_By => Constraints,
17376 Into => Components,
17377 Report_Errors => Report_Errors);
17379 -- Check that each component present is fully initialized
17381 Comp_Elmt := First_Elmt (Components);
17382 while Present (Comp_Elmt) loop
17383 Comp_Id := Node (Comp_Elmt);
17385 if Ekind (Comp_Id) = E_Component
17386 and then (No (Parent (Comp_Id))
17387 or else No (Expression (Parent (Comp_Id))))
17388 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
17389 then
17390 return False;
17391 end if;
17393 Next_Elmt (Comp_Elmt);
17394 end loop;
17396 return True;
17398 elsif Is_Private_Type (Typ) then
17399 declare
17400 U : constant Entity_Id := Underlying_Type (Typ);
17402 begin
17403 if No (U) then
17404 return False;
17405 else
17406 return Is_Fully_Initialized_Variant (U);
17407 end if;
17408 end;
17410 else
17411 return False;
17412 end if;
17413 end Is_Fully_Initialized_Variant;
17415 -----------------------------------
17416 -- Is_Function_With_Side_Effects --
17417 -----------------------------------
17419 function Is_Function_With_Side_Effects (Subp : Entity_Id) return Boolean is
17420 Arg : Node_Id;
17421 Expr : Node_Id;
17422 Prag : constant Node_Id := Get_Pragma (Subp, Pragma_Side_Effects);
17424 begin
17425 -- Extract the value from the Boolean expression (if any)
17427 if Present (Prag) then
17428 Arg := First (Pragma_Argument_Associations (Prag));
17430 if Present (Arg) then
17431 Expr := Get_Pragma_Arg (Arg);
17433 return Is_True (Expr_Value (Expr));
17435 -- Otherwise the aspect or pragma defaults to True
17437 else
17438 return True;
17439 end if;
17440 end if;
17442 return False;
17443 end Is_Function_With_Side_Effects;
17445 ------------------------------------
17446 -- Is_Generic_Declaration_Or_Body --
17447 ------------------------------------
17449 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
17450 Spec_Decl : Node_Id;
17452 begin
17453 -- Package/subprogram body
17455 if Nkind (Decl) in N_Package_Body | N_Subprogram_Body
17456 and then Present (Corresponding_Spec (Decl))
17457 then
17458 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
17460 -- Package/subprogram body stub
17462 elsif Nkind (Decl) in N_Package_Body_Stub | N_Subprogram_Body_Stub
17463 and then Present (Corresponding_Spec_Of_Stub (Decl))
17464 then
17465 Spec_Decl :=
17466 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
17468 -- All other cases
17470 else
17471 Spec_Decl := Decl;
17472 end if;
17474 -- Rather than inspecting the defining entity of the spec declaration,
17475 -- look at its Nkind. This takes care of the case where the analysis of
17476 -- a generic body modifies the Ekind of its spec to allow for recursive
17477 -- calls.
17479 return Nkind (Spec_Decl) in N_Generic_Declaration;
17480 end Is_Generic_Declaration_Or_Body;
17482 ---------------------------
17483 -- Is_Independent_Object --
17484 ---------------------------
17486 function Is_Independent_Object (N : Node_Id) return Boolean is
17487 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean;
17488 -- Determine whether arbitrary entity Id denotes an object that is
17489 -- Independent.
17491 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean;
17492 -- Determine whether prefix P has independent components. This requires
17493 -- the presence of an Independent_Components aspect/pragma.
17495 ------------------------------------
17496 -- Is_Independent_Object_Entity --
17497 ------------------------------------
17499 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean is
17500 begin
17501 return
17502 Is_Object (Id)
17503 and then (Is_Independent (Id)
17504 or else
17505 Is_Independent (Etype (Id)));
17506 end Is_Independent_Object_Entity;
17508 -------------------------------------
17509 -- Prefix_Has_Independent_Components --
17510 -------------------------------------
17512 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean
17514 Typ : constant Entity_Id := Etype (P);
17516 begin
17517 if Is_Access_Type (Typ) then
17518 return Has_Independent_Components (Designated_Type (Typ));
17520 elsif Has_Independent_Components (Typ) then
17521 return True;
17523 elsif Is_Entity_Name (P)
17524 and then Has_Independent_Components (Entity (P))
17525 then
17526 return True;
17528 else
17529 return False;
17530 end if;
17531 end Prefix_Has_Independent_Components;
17533 -- Start of processing for Is_Independent_Object
17535 begin
17536 if Is_Entity_Name (N) then
17537 return Is_Independent_Object_Entity (Entity (N));
17539 elsif Is_Independent (Etype (N)) then
17540 return True;
17542 elsif Nkind (N) = N_Indexed_Component then
17543 return Prefix_Has_Independent_Components (Prefix (N));
17545 elsif Nkind (N) = N_Selected_Component then
17546 return Prefix_Has_Independent_Components (Prefix (N))
17547 or else Is_Independent (Entity (Selector_Name (N)));
17549 else
17550 return False;
17551 end if;
17552 end Is_Independent_Object;
17554 ----------------------------
17555 -- Is_Inherited_Operation --
17556 ----------------------------
17558 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
17559 pragma Assert (Is_Overloadable (E));
17560 Kind : constant Node_Kind := Nkind (Parent (E));
17561 begin
17562 return Kind = N_Full_Type_Declaration
17563 or else Kind = N_Private_Extension_Declaration
17564 or else Kind = N_Subtype_Declaration
17565 or else (Ekind (E) = E_Enumeration_Literal
17566 and then Is_Derived_Type (Etype (E)));
17567 end Is_Inherited_Operation;
17569 --------------------------------------
17570 -- Is_Inlinable_Expression_Function --
17571 --------------------------------------
17573 function Is_Inlinable_Expression_Function
17574 (Subp : Entity_Id) return Boolean
17576 Return_Expr : Node_Id;
17578 begin
17579 if Is_Expression_Function_Or_Completion (Subp)
17580 and then Has_Pragma_Inline_Always (Subp)
17581 and then Needs_No_Actuals (Subp)
17582 and then No (Contract (Subp))
17583 and then not Is_Dispatching_Operation (Subp)
17584 and then Needs_Finalization (Etype (Subp))
17585 and then not Is_Class_Wide_Type (Etype (Subp))
17586 and then not Has_Invariants (Etype (Subp))
17587 and then Present (Subprogram_Body (Subp))
17588 and then Was_Expression_Function (Subprogram_Body (Subp))
17589 then
17590 Return_Expr := Expression_Of_Expression_Function (Subp);
17592 -- The returned object must not have a qualified expression and its
17593 -- nominal subtype must be statically compatible with the result
17594 -- subtype of the expression function.
17596 return
17597 Nkind (Return_Expr) = N_Identifier
17598 and then Etype (Return_Expr) = Etype (Subp);
17599 end if;
17601 return False;
17602 end Is_Inlinable_Expression_Function;
17604 -----------------------
17605 -- Is_Internal_Block --
17606 -----------------------
17608 function Is_Internal_Block (N : Node_Id) return Boolean is
17609 begin
17610 return Nkind (N) = N_Block_Statement
17611 and then Is_Internal (Entity (Identifier (N)));
17612 end Is_Internal_Block;
17614 -----------------
17615 -- Is_Iterator --
17616 -----------------
17618 function Is_Iterator (Typ : Entity_Id) return Boolean is
17619 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
17620 -- Determine whether type Iter_Typ is a predefined forward or reversible
17621 -- iterator.
17623 ----------------------
17624 -- Denotes_Iterator --
17625 ----------------------
17627 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
17628 begin
17629 -- Check that the name matches, and that the ultimate ancestor is in
17630 -- a predefined unit, i.e the one that declares iterator interfaces.
17632 return
17633 Chars (Iter_Typ) in Name_Forward_Iterator | Name_Reversible_Iterator
17634 and then In_Predefined_Unit (Root_Type (Iter_Typ));
17635 end Denotes_Iterator;
17637 -- Local variables
17639 Iface_Elmt : Elmt_Id;
17640 Ifaces : Elist_Id;
17642 -- Start of processing for Is_Iterator
17644 begin
17645 -- The type may be a subtype of a descendant of the proper instance of
17646 -- the predefined interface type, so we must use the root type of the
17647 -- given type. The same is done for Is_Reversible_Iterator.
17649 if Is_Class_Wide_Type (Typ)
17650 and then Denotes_Iterator (Root_Type (Typ))
17651 then
17652 return True;
17654 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17655 return False;
17657 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
17658 return True;
17660 else
17661 Collect_Interfaces (Typ, Ifaces);
17663 Iface_Elmt := First_Elmt (Ifaces);
17664 while Present (Iface_Elmt) loop
17665 if Denotes_Iterator (Node (Iface_Elmt)) then
17666 return True;
17667 end if;
17669 Next_Elmt (Iface_Elmt);
17670 end loop;
17672 return False;
17673 end if;
17674 end Is_Iterator;
17676 ----------------------------
17677 -- Is_Iterator_Over_Array --
17678 ----------------------------
17680 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
17681 Container : constant Node_Id := Name (N);
17682 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
17683 begin
17684 return Is_Array_Type (Container_Typ);
17685 end Is_Iterator_Over_Array;
17687 --------------------------
17688 -- Known_To_Be_Assigned --
17689 --------------------------
17691 function Known_To_Be_Assigned
17692 (N : Node_Id;
17693 Only_LHS : Boolean := False) return Boolean
17695 function Known_Assn (N : Node_Id) return Boolean is
17696 (Known_To_Be_Assigned (N, Only_LHS));
17697 -- Local function to simplify the passing of parameters for recursive
17698 -- calls.
17700 P : constant Node_Id := Parent (N);
17701 Form : Entity_Id := Empty;
17702 Call : Node_Id := Empty;
17704 -- Start of processing for Known_To_Be_Assigned
17706 begin
17707 -- Check for out parameters
17709 Find_Actual (N, Form, Call);
17711 if Present (Form) then
17712 return Ekind (Form) /= E_In_Parameter and then not Only_LHS;
17713 end if;
17715 -- Otherwise look at the parent
17717 case Nkind (P) is
17719 -- Test left side of assignment
17721 when N_Assignment_Statement =>
17722 return N = Name (P);
17724 -- Test prefix of component or attribute. Note that the prefix of an
17725 -- explicit or implicit dereference cannot be an l-value. In the case
17726 -- of a 'Read attribute, the reference can be an actual in the
17727 -- argument list of the attribute.
17729 when N_Attribute_Reference =>
17730 return
17731 not Only_LHS and then
17732 ((N = Prefix (P)
17733 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
17734 or else
17735 Attribute_Name (P) = Name_Read);
17737 -- For an expanded name, the name is an lvalue if the expanded name
17738 -- is an lvalue, but the prefix is never an lvalue, since it is just
17739 -- the scope where the name is found.
17741 when N_Expanded_Name =>
17742 if N = Prefix (P) then
17743 return Known_Assn (P);
17744 else
17745 return False;
17746 end if;
17748 -- For a selected component A.B, A is certainly an lvalue if A.B is.
17749 -- B is a little interesting, if we have A.B := 3, there is some
17750 -- discussion as to whether B is an lvalue or not, we choose to say
17751 -- it is. Note however that A is not an lvalue if it is of an access
17752 -- type since this is an implicit dereference.
17754 when N_Selected_Component =>
17755 if N = Prefix (P)
17756 and then Present (Etype (N))
17757 and then Is_Access_Type (Etype (N))
17758 then
17759 return False;
17760 else
17761 return Known_Assn (P);
17762 end if;
17764 -- For an indexed component or slice, the index or slice bounds is
17765 -- never an lvalue. The prefix is an lvalue if the indexed component
17766 -- or slice is an lvalue, except if it is an access type, where we
17767 -- have an implicit dereference.
17769 when N_Indexed_Component | N_Slice =>
17770 if N /= Prefix (P)
17771 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
17772 then
17773 return False;
17774 else
17775 return Known_Assn (P);
17776 end if;
17778 -- Prefix of a reference is an lvalue if the reference is an lvalue
17780 when N_Reference =>
17781 return Known_Assn (P);
17783 -- Prefix of explicit dereference is never an lvalue
17785 when N_Explicit_Dereference =>
17786 return False;
17788 -- Test for appearing in a conversion that itself appears in an
17789 -- lvalue context, since this should be an lvalue.
17791 when N_Type_Conversion =>
17792 return Known_Assn (P);
17794 -- Test for appearance in object renaming declaration
17796 when N_Object_Renaming_Declaration =>
17797 return not Only_LHS;
17799 -- All other references are definitely not lvalues
17801 when others =>
17802 return False;
17803 end case;
17804 end Known_To_Be_Assigned;
17806 -----------------------------
17807 -- Is_Library_Level_Entity --
17808 -----------------------------
17810 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
17811 begin
17812 -- The following is a small optimization, and it also properly handles
17813 -- discriminals, which in task bodies might appear in expressions before
17814 -- the corresponding procedure has been created, and which therefore do
17815 -- not have an assigned scope.
17817 if Is_Formal (E) then
17818 return False;
17820 -- If we somehow got an empty value for Scope, the tree must be
17821 -- malformed. Rather than blow up we return True in this case.
17823 elsif No (Scope (E)) then
17824 return True;
17826 -- Handle loops since Enclosing_Dynamic_Scope skips them; required to
17827 -- properly handle entities local to quantified expressions in library
17828 -- level specifications.
17830 elsif Ekind (Scope (E)) = E_Loop then
17831 return False;
17832 end if;
17834 -- Normal test is simply that the enclosing dynamic scope is Standard
17836 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
17837 end Is_Library_Level_Entity;
17839 --------------------------------
17840 -- Is_Limited_Class_Wide_Type --
17841 --------------------------------
17843 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
17844 begin
17845 return
17846 Is_Class_Wide_Type (Typ)
17847 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
17848 end Is_Limited_Class_Wide_Type;
17850 ---------------------------------
17851 -- Is_Local_Variable_Reference --
17852 ---------------------------------
17854 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
17855 begin
17856 if not Is_Entity_Name (Expr) then
17857 return False;
17859 else
17860 declare
17861 Ent : constant Entity_Id := Entity (Expr);
17862 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
17863 begin
17864 if Ekind (Ent)
17865 not in E_Variable | E_In_Out_Parameter | E_Out_Parameter
17866 then
17867 return False;
17868 else
17869 return Present (Sub) and then Sub = Current_Subprogram;
17870 end if;
17871 end;
17872 end if;
17873 end Is_Local_Variable_Reference;
17875 ---------------
17876 -- Is_Master --
17877 ---------------
17879 function Is_Master (N : Node_Id) return Boolean is
17880 Disable_Subexpression_Masters : constant Boolean := True;
17882 begin
17883 if Nkind (N) in N_Subprogram_Body | N_Task_Body | N_Entry_Body
17884 or else Is_Statement (N)
17885 then
17886 return True;
17887 end if;
17889 -- We avoid returning True when the master is a subexpression described
17890 -- in RM 7.6.1(3/2) for the proposes of accessibility level calculation
17891 -- in Accessibility_Level_Helper.Innermost_Master_Scope_Depth ???
17893 if not Disable_Subexpression_Masters
17894 and then Nkind (N) in N_Subexpr
17895 then
17896 declare
17897 Par : Node_Id := N;
17899 subtype N_Simple_Statement_Other_Than_Simple_Return
17900 is Node_Kind with Static_Predicate =>
17901 N_Simple_Statement_Other_Than_Simple_Return
17902 in N_Abort_Statement
17903 | N_Assignment_Statement
17904 | N_Code_Statement
17905 | N_Delay_Statement
17906 | N_Entry_Call_Statement
17907 | N_Free_Statement
17908 | N_Goto_Statement
17909 | N_Null_Statement
17910 | N_Raise_Statement
17911 | N_Requeue_Statement
17912 | N_Exit_Statement
17913 | N_Procedure_Call_Statement;
17914 begin
17915 while Present (Par) loop
17916 Par := Parent (Par);
17917 if Nkind (Par) in N_Subexpr |
17918 N_Simple_Statement_Other_Than_Simple_Return
17919 then
17920 return False;
17921 end if;
17922 end loop;
17924 return True;
17925 end;
17926 end if;
17928 return False;
17929 end Is_Master;
17931 -----------------------
17932 -- Is_Name_Reference --
17933 -----------------------
17935 function Is_Name_Reference (N : Node_Id) return Boolean is
17936 begin
17937 if Is_Entity_Name (N) then
17938 return Present (Entity (N)) and then Is_Object (Entity (N));
17939 end if;
17941 case Nkind (N) is
17942 when N_Indexed_Component
17943 | N_Slice
17945 return
17946 Is_Name_Reference (Prefix (N))
17947 or else Is_Access_Type (Etype (Prefix (N)));
17949 -- Attributes 'Input, 'Old and 'Result produce objects
17951 when N_Attribute_Reference =>
17952 return Attribute_Name (N) in Name_Input | Name_Old | Name_Result;
17954 when N_Selected_Component =>
17955 return
17956 Is_Name_Reference (Selector_Name (N))
17957 and then
17958 (Is_Name_Reference (Prefix (N))
17959 or else Is_Access_Type (Etype (Prefix (N))));
17961 when N_Explicit_Dereference =>
17962 return True;
17964 -- A view conversion of a tagged name is a name reference
17966 when N_Type_Conversion =>
17967 return
17968 Is_Tagged_Type (Etype (Subtype_Mark (N)))
17969 and then Is_Tagged_Type (Etype (Expression (N)))
17970 and then Is_Name_Reference (Expression (N));
17972 -- An unchecked type conversion is considered to be a name if the
17973 -- operand is a name (this construction arises only as a result of
17974 -- expansion activities).
17976 when N_Unchecked_Type_Conversion =>
17977 return Is_Name_Reference (Expression (N));
17979 when others =>
17980 return False;
17981 end case;
17982 end Is_Name_Reference;
17984 --------------------------
17985 -- Is_Newly_Constructed --
17986 --------------------------
17988 function Is_Newly_Constructed
17989 (Exp : Node_Id; Context_Requires_NC : Boolean) return Boolean
17991 Original_Exp : constant Node_Id := Original_Node (Exp);
17993 function Is_NC (Exp : Node_Id) return Boolean is
17994 (Is_Newly_Constructed (Exp, Context_Requires_NC));
17996 -- If the context requires that the expression shall be newly
17997 -- constructed, then "True" is a good result in the sense that the
17998 -- expression satisfies the requirements of the context (and "False"
17999 -- is analogously a bad result). If the context requires that the
18000 -- expression shall *not* be newly constructed, then things are
18001 -- reversed: "False" is the good value and "True" is the bad value.
18003 Good_Result : constant Boolean := Context_Requires_NC;
18004 Bad_Result : constant Boolean := not Good_Result;
18005 begin
18006 case Nkind (Original_Exp) is
18007 when N_Aggregate
18008 | N_Extension_Aggregate
18009 | N_Function_Call
18010 | N_Op
18012 return True;
18014 when N_Identifier =>
18015 return Present (Entity (Original_Exp))
18016 and then Ekind (Entity (Original_Exp)) = E_Function;
18018 when N_Qualified_Expression =>
18019 return Is_NC (Expression (Original_Exp));
18021 when N_Type_Conversion
18022 | N_Unchecked_Type_Conversion
18024 if Is_View_Conversion (Original_Exp) then
18025 return Is_NC (Expression (Original_Exp));
18026 elsif not Comes_From_Source (Exp) then
18027 if Exp /= Original_Exp then
18028 return Is_NC (Original_Exp);
18029 else
18030 return Is_NC (Expression (Original_Exp));
18031 end if;
18032 else
18033 return False;
18034 end if;
18036 when N_Explicit_Dereference
18037 | N_Indexed_Component
18038 | N_Selected_Component
18040 return Nkind (Exp) = N_Function_Call;
18042 -- A use of 'Input is a function call, hence allowed. Normally the
18043 -- attribute will be changed to a call, but the attribute by itself
18044 -- can occur with -gnatc.
18046 when N_Attribute_Reference =>
18047 return Attribute_Name (Original_Exp) = Name_Input;
18049 -- "return raise ..." is OK
18051 when N_Raise_Expression =>
18052 return Good_Result;
18054 -- For a case expression, all dependent expressions must be legal
18056 when N_Case_Expression =>
18057 declare
18058 Alt : Node_Id;
18060 begin
18061 Alt := First (Alternatives (Original_Exp));
18062 while Present (Alt) loop
18063 if Is_NC (Expression (Alt)) = Bad_Result then
18064 return Bad_Result;
18065 end if;
18067 Next (Alt);
18068 end loop;
18070 return Good_Result;
18071 end;
18073 -- For an if expression, all dependent expressions must be legal
18075 when N_If_Expression =>
18076 declare
18077 Then_Expr : constant Node_Id :=
18078 Next (First (Expressions (Original_Exp)));
18079 Else_Expr : constant Node_Id := Next (Then_Expr);
18080 begin
18081 if Is_NC (Then_Expr) = Bad_Result
18082 or else Is_NC (Else_Expr) = Bad_Result
18083 then
18084 return Bad_Result;
18085 else
18086 return Good_Result;
18087 end if;
18088 end;
18090 when others =>
18091 return False;
18092 end case;
18093 end Is_Newly_Constructed;
18095 ------------------------------------
18096 -- Is_Non_Preelaborable_Construct --
18097 ------------------------------------
18099 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
18101 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
18102 -- intentionally unnested to avoid deep indentation of code.
18104 Non_Preelaborable : exception;
18105 -- This exception is raised when the construct violates preelaborability
18106 -- to terminate the recursion.
18108 procedure Visit (Nod : Node_Id);
18109 -- Semantically inspect construct Nod to determine whether it violates
18110 -- preelaborability. This routine raises Non_Preelaborable.
18112 procedure Visit_List (List : List_Id);
18113 pragma Inline (Visit_List);
18114 -- Invoke Visit on each element of list List. This routine raises
18115 -- Non_Preelaborable.
18117 procedure Visit_Pragma (Prag : Node_Id);
18118 pragma Inline (Visit_Pragma);
18119 -- Semantically inspect pragma Prag to determine whether it violates
18120 -- preelaborability. This routine raises Non_Preelaborable.
18122 procedure Visit_Subexpression (Expr : Node_Id);
18123 pragma Inline (Visit_Subexpression);
18124 -- Semantically inspect expression Expr to determine whether it violates
18125 -- preelaborability. This routine raises Non_Preelaborable.
18127 -----------
18128 -- Visit --
18129 -----------
18131 procedure Visit (Nod : Node_Id) is
18132 begin
18133 case Nkind (Nod) is
18135 -- Declarations
18137 when N_Component_Declaration =>
18139 -- Defining_Identifier is left out because it is not relevant
18140 -- for preelaborability.
18142 Visit (Component_Definition (Nod));
18143 Visit (Expression (Nod));
18145 when N_Derived_Type_Definition =>
18147 -- Interface_List is left out because it is not relevant for
18148 -- preelaborability.
18150 Visit (Record_Extension_Part (Nod));
18151 Visit (Subtype_Indication (Nod));
18153 when N_Entry_Declaration =>
18155 -- A protected type with at leat one entry is not preelaborable
18156 -- while task types are never preelaborable. This renders entry
18157 -- declarations non-preelaborable.
18159 raise Non_Preelaborable;
18161 when N_Full_Type_Declaration =>
18163 -- Defining_Identifier and Discriminant_Specifications are left
18164 -- out because they are not relevant for preelaborability.
18166 Visit (Type_Definition (Nod));
18168 when N_Function_Instantiation
18169 | N_Package_Instantiation
18170 | N_Procedure_Instantiation
18172 -- Defining_Unit_Name and Name are left out because they are
18173 -- not relevant for preelaborability.
18175 Visit_List (Generic_Associations (Nod));
18177 when N_Object_Declaration =>
18179 -- Defining_Identifier is left out because it is not relevant
18180 -- for preelaborability.
18182 Visit (Object_Definition (Nod));
18184 if Has_Init_Expression (Nod) then
18185 Visit (Expression (Nod));
18187 elsif not Constant_Present (Nod)
18188 and then not Has_Preelaborable_Initialization
18189 (Etype (Defining_Entity (Nod)))
18190 then
18191 raise Non_Preelaborable;
18192 end if;
18194 when N_Private_Extension_Declaration
18195 | N_Subtype_Declaration
18197 -- Defining_Identifier, Discriminant_Specifications, and
18198 -- Interface_List are left out because they are not relevant
18199 -- for preelaborability.
18201 Visit (Subtype_Indication (Nod));
18203 when N_Protected_Type_Declaration
18204 | N_Single_Protected_Declaration
18206 -- Defining_Identifier, Discriminant_Specifications, and
18207 -- Interface_List are left out because they are not relevant
18208 -- for preelaborability.
18210 Visit (Protected_Definition (Nod));
18212 -- A [single] task type is never preelaborable
18214 when N_Single_Task_Declaration
18215 | N_Task_Type_Declaration
18217 raise Non_Preelaborable;
18219 -- Pragmas
18221 when N_Pragma =>
18222 Visit_Pragma (Nod);
18224 -- Statements
18226 when N_Statement_Other_Than_Procedure_Call =>
18227 if Nkind (Nod) /= N_Null_Statement then
18228 raise Non_Preelaborable;
18229 end if;
18231 -- Subexpressions
18233 when N_Subexpr =>
18234 Visit_Subexpression (Nod);
18236 -- Special
18238 when N_Access_To_Object_Definition =>
18239 Visit (Subtype_Indication (Nod));
18241 when N_Case_Expression_Alternative =>
18242 Visit (Expression (Nod));
18243 Visit_List (Discrete_Choices (Nod));
18245 when N_Component_Definition =>
18246 Visit (Access_Definition (Nod));
18247 Visit (Subtype_Indication (Nod));
18249 when N_Component_List =>
18250 Visit_List (Component_Items (Nod));
18251 Visit (Variant_Part (Nod));
18253 when N_Constrained_Array_Definition =>
18254 Visit_List (Discrete_Subtype_Definitions (Nod));
18255 Visit (Component_Definition (Nod));
18257 when N_Delta_Constraint
18258 | N_Digits_Constraint
18260 -- Delta_Expression and Digits_Expression are left out because
18261 -- they are not relevant for preelaborability.
18263 Visit (Range_Constraint (Nod));
18265 when N_Discriminant_Specification =>
18267 -- Defining_Identifier and Expression are left out because they
18268 -- are not relevant for preelaborability.
18270 Visit (Discriminant_Type (Nod));
18272 when N_Generic_Association =>
18274 -- Selector_Name is left out because it is not relevant for
18275 -- preelaborability.
18277 Visit (Explicit_Generic_Actual_Parameter (Nod));
18279 when N_Index_Or_Discriminant_Constraint =>
18280 Visit_List (Constraints (Nod));
18282 when N_Iterator_Specification =>
18284 -- Defining_Identifier is left out because it is not relevant
18285 -- for preelaborability.
18287 Visit (Name (Nod));
18288 Visit (Subtype_Indication (Nod));
18290 when N_Loop_Parameter_Specification =>
18292 -- Defining_Identifier is left out because it is not relevant
18293 -- for preelaborability.
18295 Visit (Discrete_Subtype_Definition (Nod));
18297 when N_Parameter_Association =>
18298 Visit (Explicit_Actual_Parameter (N));
18300 when N_Protected_Definition =>
18302 -- End_Label is left out because it is not relevant for
18303 -- preelaborability.
18305 Visit_List (Private_Declarations (Nod));
18306 Visit_List (Visible_Declarations (Nod));
18308 when N_Range_Constraint =>
18309 Visit (Range_Expression (Nod));
18311 when N_Record_Definition
18312 | N_Variant
18314 -- End_Label, Discrete_Choices, and Interface_List are left out
18315 -- because they are not relevant for preelaborability.
18317 Visit (Component_List (Nod));
18319 when N_Subtype_Indication =>
18321 -- Subtype_Mark is left out because it is not relevant for
18322 -- preelaborability.
18324 Visit (Constraint (Nod));
18326 when N_Unconstrained_Array_Definition =>
18328 -- Subtype_Marks is left out because it is not relevant for
18329 -- preelaborability.
18331 Visit (Component_Definition (Nod));
18333 when N_Variant_Part =>
18335 -- Name is left out because it is not relevant for
18336 -- preelaborability.
18338 Visit_List (Variants (Nod));
18340 -- Default
18342 when others =>
18343 null;
18344 end case;
18345 end Visit;
18347 ----------------
18348 -- Visit_List --
18349 ----------------
18351 procedure Visit_List (List : List_Id) is
18352 Nod : Node_Id;
18354 begin
18355 Nod := First (List);
18356 while Present (Nod) loop
18357 Visit (Nod);
18358 Next (Nod);
18359 end loop;
18360 end Visit_List;
18362 ------------------
18363 -- Visit_Pragma --
18364 ------------------
18366 procedure Visit_Pragma (Prag : Node_Id) is
18367 begin
18368 case Get_Pragma_Id (Prag) is
18369 when Pragma_Assert
18370 | Pragma_Assert_And_Cut
18371 | Pragma_Assume
18372 | Pragma_Async_Readers
18373 | Pragma_Async_Writers
18374 | Pragma_Attribute_Definition
18375 | Pragma_Check
18376 | Pragma_Constant_After_Elaboration
18377 | Pragma_CPU
18378 | Pragma_Deadline_Floor
18379 | Pragma_Dispatching_Domain
18380 | Pragma_Effective_Reads
18381 | Pragma_Effective_Writes
18382 | Pragma_Extensions_Visible
18383 | Pragma_Ghost
18384 | Pragma_Secondary_Stack_Size
18385 | Pragma_Task_Name
18386 | Pragma_Volatile_Function
18388 Visit_List (Pragma_Argument_Associations (Prag));
18390 -- Default
18392 when others =>
18393 null;
18394 end case;
18395 end Visit_Pragma;
18397 -------------------------
18398 -- Visit_Subexpression --
18399 -------------------------
18401 procedure Visit_Subexpression (Expr : Node_Id) is
18402 procedure Visit_Aggregate (Aggr : Node_Id);
18403 pragma Inline (Visit_Aggregate);
18404 -- Semantically inspect aggregate Aggr to determine whether it
18405 -- violates preelaborability.
18407 ---------------------
18408 -- Visit_Aggregate --
18409 ---------------------
18411 procedure Visit_Aggregate (Aggr : Node_Id) is
18412 begin
18413 if not Is_Preelaborable_Aggregate (Aggr) then
18414 raise Non_Preelaborable;
18415 end if;
18416 end Visit_Aggregate;
18418 -- Start of processing for Visit_Subexpression
18420 begin
18421 case Nkind (Expr) is
18422 when N_Allocator
18423 | N_Qualified_Expression
18424 | N_Type_Conversion
18425 | N_Unchecked_Expression
18426 | N_Unchecked_Type_Conversion
18428 -- Subpool_Handle_Name and Subtype_Mark are left out because
18429 -- they are not relevant for preelaborability.
18431 Visit (Expression (Expr));
18433 when N_Aggregate
18434 | N_Extension_Aggregate
18436 Visit_Aggregate (Expr);
18438 when N_Attribute_Reference
18439 | N_Explicit_Dereference
18440 | N_Reference
18442 -- Attribute_Name and Expressions are left out because they are
18443 -- not relevant for preelaborability.
18445 Visit (Prefix (Expr));
18447 when N_Case_Expression =>
18449 -- End_Span is left out because it is not relevant for
18450 -- preelaborability.
18452 Visit_List (Alternatives (Expr));
18453 Visit (Expression (Expr));
18455 when N_Delta_Aggregate =>
18456 Visit_Aggregate (Expr);
18457 Visit (Expression (Expr));
18459 when N_Expression_With_Actions =>
18460 Visit_List (Actions (Expr));
18461 Visit (Expression (Expr));
18463 when N_Function_Call =>
18465 -- Ada 2022 (AI12-0175): Calls to certain functions that are
18466 -- essentially unchecked conversions are preelaborable.
18468 if Ada_Version >= Ada_2022
18469 and then Nkind (Expr) = N_Function_Call
18470 and then Is_Entity_Name (Name (Expr))
18471 and then Is_Preelaborable_Function (Entity (Name (Expr)))
18472 then
18473 Visit_List (Parameter_Associations (Expr));
18474 else
18475 raise Non_Preelaborable;
18476 end if;
18478 when N_If_Expression =>
18479 Visit_List (Expressions (Expr));
18481 when N_Quantified_Expression =>
18482 Visit (Condition (Expr));
18483 Visit (Iterator_Specification (Expr));
18484 Visit (Loop_Parameter_Specification (Expr));
18486 when N_Range =>
18487 Visit (High_Bound (Expr));
18488 Visit (Low_Bound (Expr));
18490 when N_Slice =>
18491 Visit (Discrete_Range (Expr));
18492 Visit (Prefix (Expr));
18494 -- Default
18496 when others =>
18498 -- The evaluation of an object name is not preelaborable,
18499 -- unless the name is a static expression (checked further
18500 -- below), or statically denotes a discriminant.
18502 if Is_Entity_Name (Expr) then
18503 Object_Name : declare
18504 Id : constant Entity_Id := Entity (Expr);
18506 begin
18507 if Is_Object (Id) then
18508 if Ekind (Id) = E_Discriminant then
18509 null;
18511 elsif Ekind (Id) in E_Constant | E_In_Parameter
18512 and then Present (Discriminal_Link (Id))
18513 then
18514 null;
18516 else
18517 raise Non_Preelaborable;
18518 end if;
18519 end if;
18520 end Object_Name;
18522 -- A non-static expression is not preelaborable
18524 elsif not Is_OK_Static_Expression (Expr) then
18525 raise Non_Preelaborable;
18526 end if;
18527 end case;
18528 end Visit_Subexpression;
18530 -- Start of processing for Is_Non_Preelaborable_Construct
18532 begin
18533 Visit (N);
18535 -- At this point it is known that the construct is preelaborable
18537 return False;
18539 exception
18541 -- The elaboration of the construct performs an action which violates
18542 -- preelaborability.
18544 when Non_Preelaborable =>
18545 return True;
18546 end Is_Non_Preelaborable_Construct;
18548 ---------------------------------
18549 -- Is_Nontrivial_DIC_Procedure --
18550 ---------------------------------
18552 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
18553 Body_Decl : Node_Id;
18554 Stmt : Node_Id;
18556 begin
18557 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
18558 Body_Decl :=
18559 Unit_Declaration_Node
18560 (Corresponding_Body (Unit_Declaration_Node (Id)));
18562 -- The body of the Default_Initial_Condition procedure must contain
18563 -- at least one statement, otherwise the generation of the subprogram
18564 -- body failed.
18566 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
18568 -- To qualify as nontrivial, the first statement of the procedure
18569 -- must be a check in the form of an if statement. If the original
18570 -- Default_Initial_Condition expression was folded, then the first
18571 -- statement is not a check.
18573 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
18575 return
18576 Nkind (Stmt) = N_If_Statement
18577 and then Nkind (Original_Node (Stmt)) = N_Pragma;
18578 end if;
18580 return False;
18581 end Is_Nontrivial_DIC_Procedure;
18583 -----------------------
18584 -- Is_Null_Extension --
18585 -----------------------
18587 function Is_Null_Extension
18588 (T : Entity_Id; Ignore_Privacy : Boolean := False) return Boolean
18590 Type_Decl : Node_Id;
18591 Type_Def : Node_Id;
18592 begin
18593 pragma Assert (not Is_Class_Wide_Type (T));
18595 if Ignore_Privacy then
18596 Type_Decl := Parent (Underlying_Type (Base_Type (T)));
18597 else
18598 Type_Decl := Parent (Base_Type (T));
18599 if Nkind (Type_Decl) /= N_Full_Type_Declaration then
18600 return False;
18601 end if;
18602 end if;
18603 pragma Assert (Nkind (Type_Decl) = N_Full_Type_Declaration);
18604 Type_Def := Type_Definition (Type_Decl);
18605 if Present (Discriminant_Specifications (Type_Decl))
18606 or else Nkind (Type_Def) /= N_Derived_Type_Definition
18607 or else not Is_Tagged_Type (T)
18608 or else No (Record_Extension_Part (Type_Def))
18609 then
18610 return False;
18611 end if;
18613 return Is_Null_Record_Definition (Record_Extension_Part (Type_Def));
18614 end Is_Null_Extension;
18616 --------------------------
18617 -- Is_Null_Extension_Of --
18618 --------------------------
18620 function Is_Null_Extension_Of
18621 (Descendant, Ancestor : Entity_Id) return Boolean
18623 Ancestor_Type : constant Entity_Id :=
18624 Underlying_Type (Base_Type (Ancestor));
18625 Descendant_Type : Entity_Id := Underlying_Type (Base_Type (Descendant));
18626 begin
18627 pragma Assert (not Is_Class_Wide_Type (Descendant));
18628 pragma Assert (not Is_Class_Wide_Type (Ancestor));
18629 pragma Assert (Descendant_Type /= Ancestor_Type);
18631 while Descendant_Type /= Ancestor_Type loop
18632 if not Is_Null_Extension
18633 (Descendant_Type, Ignore_Privacy => True)
18634 then
18635 return False;
18636 end if;
18637 Descendant_Type := Etype (Subtype_Indication
18638 (Type_Definition (Parent (Descendant_Type))));
18639 Descendant_Type := Underlying_Type (Base_Type (Descendant_Type));
18640 end loop;
18641 return True;
18642 end Is_Null_Extension_Of;
18644 -------------------------------
18645 -- Is_Null_Record_Definition --
18646 -------------------------------
18648 function Is_Null_Record_Definition (Record_Def : Node_Id) return Boolean is
18649 Item : Node_Id;
18650 begin
18651 -- Testing Null_Present is just an optimization, not required.
18653 if Null_Present (Record_Def) then
18654 return True;
18655 elsif Present (Variant_Part (Component_List (Record_Def))) then
18656 return False;
18657 elsif No (Component_List (Record_Def)) then
18658 return True;
18659 end if;
18661 Item := First_Non_Pragma (Component_Items (Component_List (Record_Def)));
18663 while Present (Item) loop
18664 if Nkind (Item) = N_Component_Declaration
18665 and then Is_Internal_Name (Chars (Defining_Identifier (Item)))
18666 then
18667 null;
18668 else
18669 return False;
18670 end if;
18671 Next_Non_Pragma (Item);
18672 end loop;
18674 return True;
18675 end Is_Null_Record_Definition;
18677 -------------------------
18678 -- Is_Null_Record_Type --
18679 -------------------------
18681 function Is_Null_Record_Type
18682 (T : Entity_Id; Ignore_Privacy : Boolean := False) return Boolean
18684 Decl : Node_Id;
18685 Type_Def : Node_Id;
18686 begin
18687 if not Is_Record_Type (T) then
18688 return False;
18689 end if;
18691 if Ignore_Privacy then
18692 Decl := Parent (Underlying_Type (Base_Type (T)));
18693 else
18694 Decl := Parent (Base_Type (T));
18695 if Nkind (Decl) /= N_Full_Type_Declaration then
18696 return False;
18697 end if;
18698 end if;
18699 pragma Assert (Nkind (Decl) = N_Full_Type_Declaration);
18700 Type_Def := Type_Definition (Decl);
18702 if Has_Discriminants (Defining_Identifier (Decl)) then
18703 return False;
18704 end if;
18706 case Nkind (Type_Def) is
18707 when N_Record_Definition =>
18708 return Is_Null_Record_Definition (Type_Def);
18709 when N_Derived_Type_Definition =>
18710 if not Is_Null_Record_Type
18711 (Etype (Subtype_Indication (Type_Def)),
18712 Ignore_Privacy => Ignore_Privacy)
18713 then
18714 return False;
18715 elsif not Is_Tagged_Type (T) then
18716 return True;
18717 else
18718 return Is_Null_Extension (T, Ignore_Privacy => Ignore_Privacy);
18719 end if;
18720 when others =>
18721 return False;
18722 end case;
18723 end Is_Null_Record_Type;
18725 ---------------------
18726 -- Is_Object_Image --
18727 ---------------------
18729 function Is_Object_Image (Prefix : Node_Id) return Boolean is
18730 begin
18731 -- Here we test for the case that the prefix is not a type and assume
18732 -- if it is not then it must be a named value or an object reference.
18733 -- This is because the parser always checks that prefixes of attributes
18734 -- are named.
18736 return not (Is_Entity_Name (Prefix)
18737 and then Is_Type (Entity (Prefix))
18738 and then not Is_Current_Instance (Prefix));
18739 end Is_Object_Image;
18741 -------------------------
18742 -- Is_Object_Reference --
18743 -------------------------
18745 function Is_Object_Reference (N : Node_Id) return Boolean is
18746 function Safe_Prefix (N : Node_Id) return Node_Id;
18747 -- Return Prefix (N) unless it has been rewritten as an
18748 -- N_Raise_xxx_Error node, in which case return its original node.
18750 -----------------
18751 -- Safe_Prefix --
18752 -----------------
18754 function Safe_Prefix (N : Node_Id) return Node_Id is
18755 begin
18756 if Nkind (Prefix (N)) in N_Raise_xxx_Error then
18757 return Original_Node (Prefix (N));
18758 else
18759 return Prefix (N);
18760 end if;
18761 end Safe_Prefix;
18763 begin
18764 -- AI12-0068: Note that a current instance reference in a type or
18765 -- subtype's aspect_specification is considered a value, not an object
18766 -- (see RM 8.6(18/5)).
18768 if Is_Entity_Name (N) then
18769 return Present (Entity (N)) and then Is_Object (Entity (N))
18770 and then not Is_Current_Instance_Reference_In_Type_Aspect (N);
18772 else
18773 case Nkind (N) is
18774 when N_Indexed_Component
18775 | N_Slice
18777 return
18778 Is_Object_Reference (Safe_Prefix (N))
18779 or else Is_Access_Type (Etype (Safe_Prefix (N)));
18781 -- In Ada 95, a function call is a constant object; a procedure
18782 -- call is not.
18784 -- Note that predefined operators are functions as well, and so
18785 -- are attributes that are (can be renamed as) functions.
18787 when N_Function_Call
18788 | N_Op
18790 return Etype (N) /= Standard_Void_Type;
18792 -- Attributes references 'Loop_Entry, 'Old, 'Priority and 'Result
18793 -- yield objects, even though they are not functions.
18795 when N_Attribute_Reference =>
18796 return
18797 Attribute_Name (N) in Name_Loop_Entry
18798 | Name_Old
18799 | Name_Priority
18800 | Name_Result
18801 or else Is_Function_Attribute_Name (Attribute_Name (N));
18803 when N_Selected_Component =>
18804 return
18805 Is_Object_Reference (Selector_Name (N))
18806 and then
18807 (Is_Object_Reference (Safe_Prefix (N))
18808 or else Is_Access_Type (Etype (Safe_Prefix (N))));
18810 -- An explicit dereference denotes an object, except that a
18811 -- conditional expression gets turned into an explicit dereference
18812 -- in some cases, and conditional expressions are not object
18813 -- names.
18815 when N_Explicit_Dereference =>
18816 return Nkind (Original_Node (N)) not in
18817 N_Case_Expression | N_If_Expression;
18819 -- A view conversion of a tagged object is an object reference
18821 when N_Type_Conversion =>
18822 if Ada_Version <= Ada_2012 then
18823 -- A view conversion of a tagged object is an object
18824 -- reference.
18825 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
18826 and then Is_Tagged_Type (Etype (Expression (N)))
18827 and then Is_Object_Reference (Expression (N));
18829 else
18830 -- AI12-0226: In Ada 2022 a value conversion of an object is
18831 -- an object.
18833 return Is_Object_Reference (Expression (N));
18834 end if;
18836 -- An unchecked type conversion is considered to be an object if
18837 -- the operand is an object (this construction arises only as a
18838 -- result of expansion activities).
18840 when N_Unchecked_Type_Conversion =>
18841 return True;
18843 -- AI05-0003: In Ada 2012 a qualified expression is a name.
18844 -- This allows disambiguation of function calls and the use
18845 -- of aggregates in more contexts.
18847 when N_Qualified_Expression =>
18848 return Ada_Version >= Ada_2012
18849 and then Is_Object_Reference (Expression (N));
18851 -- In Ada 95 an aggregate is an object reference
18853 when N_Aggregate
18854 | N_Delta_Aggregate
18855 | N_Extension_Aggregate
18857 return Ada_Version >= Ada_95;
18859 -- A string literal is not an object reference, but it might come
18860 -- from rewriting of an object reference, e.g. from folding of an
18861 -- aggregate.
18863 when N_String_Literal =>
18864 return Is_Rewrite_Substitution (N)
18865 and then Is_Object_Reference (Original_Node (N));
18867 -- AI12-0125: Target name represents a constant object
18869 when N_Target_Name =>
18870 return True;
18872 when others =>
18873 return False;
18874 end case;
18875 end if;
18876 end Is_Object_Reference;
18878 -----------------------------------
18879 -- Is_OK_Variable_For_Out_Formal --
18880 -----------------------------------
18882 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
18883 begin
18884 Note_Possible_Modification (AV, Sure => True);
18886 -- We must reject parenthesized variable names. Comes_From_Source is
18887 -- checked because there are currently cases where the compiler violates
18888 -- this rule (e.g. passing a task object to its controlled Initialize
18889 -- routine). This should be properly documented in sinfo???
18891 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
18892 return False;
18894 -- A variable is always allowed
18896 elsif Is_Variable (AV) then
18897 return True;
18899 -- Generalized indexing operations are rewritten as explicit
18900 -- dereferences, and it is only during resolution that we can
18901 -- check whether the context requires an access_to_variable type.
18903 elsif Nkind (AV) = N_Explicit_Dereference
18904 and then Present (Etype (Original_Node (AV)))
18905 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
18906 and then Ada_Version >= Ada_2012
18907 then
18908 return not Is_Access_Constant (Etype (Prefix (AV)));
18910 -- Unchecked conversions are allowed only if they come from the
18911 -- generated code, which sometimes uses unchecked conversions for out
18912 -- parameters in cases where code generation is unaffected. We tell
18913 -- source unchecked conversions by seeing if they are rewrites of
18914 -- an original Unchecked_Conversion function call, or of an explicit
18915 -- conversion of a function call or an aggregate (as may happen in the
18916 -- expansion of a packed array aggregate).
18918 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
18919 if Nkind (Original_Node (AV)) in N_Function_Call | N_Aggregate then
18920 return False;
18922 elsif Nkind (Original_Node (Expression (AV))) = N_Function_Call then
18923 return False;
18925 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
18926 return Is_OK_Variable_For_Out_Formal (Expression (AV));
18928 else
18929 return True;
18930 end if;
18932 -- Normal type conversions are allowed if argument is a variable
18934 elsif Nkind (AV) = N_Type_Conversion then
18935 if Is_Variable (Expression (AV))
18936 and then Paren_Count (Expression (AV)) = 0
18937 then
18938 Note_Possible_Modification (Expression (AV), Sure => True);
18939 return True;
18941 -- We also allow a non-parenthesized expression that raises
18942 -- constraint error if it rewrites what used to be a variable
18944 elsif Raises_Constraint_Error (Expression (AV))
18945 and then Paren_Count (Expression (AV)) = 0
18946 and then Is_Variable (Original_Node (Expression (AV)))
18947 then
18948 return True;
18950 -- Type conversion of something other than a variable
18952 else
18953 return False;
18954 end if;
18956 -- If this node is rewritten, then test the original form, if that is
18957 -- OK, then we consider the rewritten node OK (for example, if the
18958 -- original node is a conversion, then Is_Variable will not be true
18959 -- but we still want to allow the conversion if it converts a variable).
18961 elsif Is_Rewrite_Substitution (AV) then
18962 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
18964 -- All other non-variables are rejected
18966 else
18967 return False;
18968 end if;
18969 end Is_OK_Variable_For_Out_Formal;
18971 ----------------------------
18972 -- Is_OK_Volatile_Context --
18973 ----------------------------
18975 function Is_OK_Volatile_Context
18976 (Context : Node_Id;
18977 Obj_Ref : Node_Id;
18978 Check_Actuals : Boolean) return Boolean
18980 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
18981 -- Determine whether an arbitrary node denotes a call to a protected
18982 -- entry, function, or procedure in prefixed form where the prefix is
18983 -- Obj_Ref.
18985 function Within_Check (Nod : Node_Id) return Boolean;
18986 -- Determine whether an arbitrary node appears in a check node
18988 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
18989 -- Determine whether an arbitrary entity appears in a volatile function
18991 ---------------------------------
18992 -- Is_Protected_Operation_Call --
18993 ---------------------------------
18995 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
18996 Pref : Node_Id;
18997 Subp : Node_Id;
18999 begin
19000 -- A call to a protected operations retains its selected component
19001 -- form as opposed to other prefixed calls that are transformed in
19002 -- expanded names.
19004 if Nkind (Nod) = N_Selected_Component then
19005 Pref := Prefix (Nod);
19006 Subp := Selector_Name (Nod);
19008 return
19009 Pref = Obj_Ref
19010 and then Present (Etype (Pref))
19011 and then Is_Protected_Type (Etype (Pref))
19012 and then Is_Entity_Name (Subp)
19013 and then Present (Entity (Subp))
19014 and then Ekind (Entity (Subp)) in
19015 E_Entry | E_Entry_Family | E_Function | E_Procedure;
19016 else
19017 return False;
19018 end if;
19019 end Is_Protected_Operation_Call;
19021 ------------------
19022 -- Within_Check --
19023 ------------------
19025 function Within_Check (Nod : Node_Id) return Boolean is
19026 Par : Node_Id;
19028 begin
19029 -- Climb the parent chain looking for a check node
19031 Par := Nod;
19032 while Present (Par) loop
19033 if Nkind (Par) in N_Raise_xxx_Error then
19034 return True;
19036 -- Prevent the search from going too far
19038 elsif Is_Body_Or_Package_Declaration (Par) then
19039 exit;
19040 end if;
19042 Par := Parent (Par);
19043 end loop;
19045 return False;
19046 end Within_Check;
19048 ------------------------------
19049 -- Within_Volatile_Function --
19050 ------------------------------
19052 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
19053 pragma Assert (Ekind (Id) = E_Return_Statement);
19055 Func_Id : constant Entity_Id := Return_Applies_To (Id);
19057 begin
19058 pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function);
19060 return Is_Volatile_Function (Func_Id);
19061 end Within_Volatile_Function;
19063 -- Local variables
19065 Obj_Id : Entity_Id;
19067 -- Start of processing for Is_OK_Volatile_Context
19069 begin
19070 -- Ignore context restriction when doing preanalysis, e.g. on a copy of
19071 -- an expression function, because this copy is not fully decorated and
19072 -- it is not possible to reliably decide the legality of the context.
19073 -- Any violations will be reported anyway when doing the full analysis.
19075 if not Full_Analysis then
19076 return True;
19077 end if;
19079 -- For actual parameters within explicit parameter associations switch
19080 -- the context to the corresponding subprogram call.
19082 if Nkind (Context) = N_Parameter_Association then
19083 return Is_OK_Volatile_Context (Context => Parent (Context),
19084 Obj_Ref => Obj_Ref,
19085 Check_Actuals => Check_Actuals);
19087 -- The volatile object appears on either side of an assignment
19089 elsif Nkind (Context) = N_Assignment_Statement then
19090 return True;
19092 -- The volatile object is part of the initialization expression of
19093 -- another object.
19095 elsif Nkind (Context) = N_Object_Declaration
19096 and then Present (Expression (Context))
19097 and then Expression (Context) = Obj_Ref
19098 and then Nkind (Parent (Context)) /= N_Expression_With_Actions
19099 then
19100 Obj_Id := Defining_Entity (Context);
19102 -- The volatile object acts as the initialization expression of an
19103 -- extended return statement. This is valid context as long as the
19104 -- function is volatile.
19106 if Is_Return_Object (Obj_Id) then
19107 return Within_Volatile_Function (Scope (Obj_Id));
19109 -- Otherwise this is a normal object initialization
19111 else
19112 return True;
19113 end if;
19115 -- The volatile object acts as the name of a renaming declaration
19117 elsif Nkind (Context) = N_Object_Renaming_Declaration
19118 and then Name (Context) = Obj_Ref
19119 then
19120 return True;
19122 -- The volatile object appears as an actual parameter in a call to an
19123 -- instance of Unchecked_Conversion whose result is renamed.
19125 elsif Nkind (Context) = N_Function_Call
19126 and then Is_Entity_Name (Name (Context))
19127 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
19128 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
19129 then
19130 return True;
19132 -- The volatile object is actually the prefix in a protected entry,
19133 -- function, or procedure call.
19135 elsif Is_Protected_Operation_Call (Context) then
19136 return True;
19138 -- The volatile object appears as the expression of a simple return
19139 -- statement that applies to a volatile function.
19141 elsif Nkind (Context) = N_Simple_Return_Statement
19142 and then Expression (Context) = Obj_Ref
19143 then
19144 return
19145 Within_Volatile_Function (Return_Statement_Entity (Context));
19147 -- The volatile object appears as the prefix of a name occurring in a
19148 -- non-interfering context.
19150 elsif Nkind (Context) in
19151 N_Attribute_Reference |
19152 N_Explicit_Dereference |
19153 N_Indexed_Component |
19154 N_Selected_Component |
19155 N_Slice
19156 and then Prefix (Context) = Obj_Ref
19157 and then Is_OK_Volatile_Context
19158 (Context => Parent (Context),
19159 Obj_Ref => Context,
19160 Check_Actuals => Check_Actuals)
19161 then
19162 return True;
19164 -- The volatile object appears as the prefix of attributes Address,
19165 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
19166 -- Position, Size, Storage_Size.
19168 elsif Nkind (Context) = N_Attribute_Reference
19169 and then Prefix (Context) = Obj_Ref
19170 and then Attribute_Name (Context) in Name_Address
19171 | Name_Alignment
19172 | Name_Component_Size
19173 | Name_First
19174 | Name_First_Bit
19175 | Name_Last
19176 | Name_Last_Bit
19177 | Name_Length
19178 | Name_Position
19179 | Name_Size
19180 | Name_Storage_Size
19181 then
19182 return True;
19184 -- The volatile object appears as the expression of a type conversion
19185 -- occurring in a non-interfering context.
19187 elsif Nkind (Context) in N_Qualified_Expression
19188 | N_Type_Conversion
19189 | N_Unchecked_Type_Conversion
19190 and then Expression (Context) = Obj_Ref
19191 and then Is_OK_Volatile_Context
19192 (Context => Parent (Context),
19193 Obj_Ref => Context,
19194 Check_Actuals => Check_Actuals)
19195 then
19196 return True;
19198 -- The volatile object appears as the expression in a delay statement
19200 elsif Nkind (Context) in N_Delay_Statement then
19201 return True;
19203 -- Allow references to volatile objects in various checks. This is not a
19204 -- direct SPARK 2014 requirement.
19206 elsif Within_Check (Context) then
19207 return True;
19209 -- References to effectively volatile objects that appear as actual
19210 -- parameters in subprogram calls can be examined only after call itself
19211 -- has been resolved. Before that, assume such references to be legal.
19213 elsif Nkind (Context) in N_Subprogram_Call | N_Entry_Call_Statement then
19214 if Check_Actuals then
19215 declare
19216 Call : Node_Id;
19217 Formal : Entity_Id;
19218 Subp : constant Entity_Id := Get_Called_Entity (Context);
19219 begin
19220 Find_Actual (Obj_Ref, Formal, Call);
19221 pragma Assert (Call = Context);
19223 -- An effectively volatile object may act as an actual when the
19224 -- corresponding formal is of a non-scalar effectively volatile
19225 -- type (SPARK RM 7.1.3(9)).
19227 if not Is_Scalar_Type (Etype (Formal))
19228 and then Is_Effectively_Volatile_For_Reading (Etype (Formal))
19229 then
19230 return True;
19232 -- An effectively volatile object may act as an actual in a
19233 -- call to an instance of Unchecked_Conversion. (SPARK RM
19234 -- 7.1.3(9)).
19236 elsif Is_Unchecked_Conversion_Instance (Subp) then
19237 return True;
19239 else
19240 return False;
19241 end if;
19242 end;
19243 else
19244 return True;
19245 end if;
19246 else
19247 return False;
19248 end if;
19249 end Is_OK_Volatile_Context;
19251 ------------------------------------
19252 -- Is_Package_Contract_Annotation --
19253 ------------------------------------
19255 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
19256 Nam : Name_Id;
19258 begin
19259 if Nkind (Item) = N_Aspect_Specification then
19260 Nam := Chars (Identifier (Item));
19262 else pragma Assert (Nkind (Item) = N_Pragma);
19263 Nam := Pragma_Name (Item);
19264 end if;
19266 return Nam = Name_Abstract_State
19267 or else Nam = Name_Initial_Condition
19268 or else Nam = Name_Initializes
19269 or else Nam = Name_Refined_State;
19270 end Is_Package_Contract_Annotation;
19272 -----------------------------------
19273 -- Is_Partially_Initialized_Type --
19274 -----------------------------------
19276 function Is_Partially_Initialized_Type
19277 (Typ : Entity_Id;
19278 Include_Implicit : Boolean := True) return Boolean
19280 begin
19281 if Is_Scalar_Type (Typ) then
19282 return Has_Default_Aspect (Base_Type (Typ));
19284 elsif Is_Access_Type (Typ) then
19285 return Include_Implicit;
19287 elsif Is_Array_Type (Typ) then
19289 -- If component type is partially initialized, so is array type
19291 if Has_Default_Aspect (Base_Type (Typ))
19292 or else Is_Partially_Initialized_Type
19293 (Component_Type (Typ), Include_Implicit)
19294 then
19295 return True;
19297 -- Otherwise we are only partially initialized if we are fully
19298 -- initialized (this is the empty array case, no point in us
19299 -- duplicating that code here).
19301 else
19302 return Is_Fully_Initialized_Type (Typ);
19303 end if;
19305 elsif Is_Record_Type (Typ) then
19307 -- A discriminated type is always partially initialized if in
19308 -- all mode
19310 if Has_Discriminants (Typ) and then Include_Implicit then
19311 return True;
19313 -- A tagged type is always partially initialized
19315 elsif Is_Tagged_Type (Typ) then
19316 return True;
19318 -- Case of nondiscriminated record
19320 else
19321 declare
19322 Comp : Entity_Id;
19324 Component_Present : Boolean := False;
19325 -- Set True if at least one component is present. If no
19326 -- components are present, then record type is fully
19327 -- initialized (another odd case, like the null array).
19329 begin
19330 -- Loop through components
19332 Comp := First_Component (Typ);
19333 while Present (Comp) loop
19334 Component_Present := True;
19336 -- If a component has an initialization expression then the
19337 -- enclosing record type is partially initialized
19339 if Present (Parent (Comp))
19340 and then Present (Expression (Parent (Comp)))
19341 then
19342 return True;
19344 -- If a component is of a type which is itself partially
19345 -- initialized, then the enclosing record type is also.
19347 elsif Is_Partially_Initialized_Type
19348 (Etype (Comp), Include_Implicit)
19349 then
19350 return True;
19351 end if;
19353 Next_Component (Comp);
19354 end loop;
19356 -- No initialized components found. If we found any components
19357 -- they were all uninitialized so the result is false.
19359 if Component_Present then
19360 return False;
19362 -- But if we found no components, then all the components are
19363 -- initialized so we consider the type to be initialized.
19365 else
19366 return True;
19367 end if;
19368 end;
19369 end if;
19371 -- Concurrent types are always fully initialized
19373 elsif Is_Concurrent_Type (Typ) then
19374 return True;
19376 -- For a private type, go to underlying type. If there is no underlying
19377 -- type then just assume this partially initialized. Not clear if this
19378 -- can happen in a non-error case, but no harm in testing for this.
19380 elsif Is_Private_Type (Typ) then
19381 declare
19382 U : constant Entity_Id := Underlying_Type (Typ);
19383 begin
19384 if No (U) then
19385 return True;
19386 else
19387 return Is_Partially_Initialized_Type (U, Include_Implicit);
19388 end if;
19389 end;
19391 -- For any other type (are there any?) assume partially initialized
19393 else
19394 return True;
19395 end if;
19396 end Is_Partially_Initialized_Type;
19398 ------------------------------------
19399 -- Is_Potentially_Persistent_Type --
19400 ------------------------------------
19402 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
19403 Comp : Entity_Id;
19404 Indx : Node_Id;
19406 begin
19407 -- For private type, test corresponding full type
19409 if Is_Private_Type (T) then
19410 return Is_Potentially_Persistent_Type (Full_View (T));
19412 -- Scalar types are potentially persistent
19414 elsif Is_Scalar_Type (T) then
19415 return True;
19417 -- Record type is potentially persistent if not tagged and the types of
19418 -- all it components are potentially persistent, and no component has
19419 -- an initialization expression.
19421 elsif Is_Record_Type (T)
19422 and then not Is_Tagged_Type (T)
19423 and then not Is_Partially_Initialized_Type (T)
19424 then
19425 Comp := First_Component (T);
19426 while Present (Comp) loop
19427 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
19428 return False;
19429 else
19430 Next_Entity (Comp);
19431 end if;
19432 end loop;
19434 return True;
19436 -- Array type is potentially persistent if its component type is
19437 -- potentially persistent and if all its constraints are static.
19439 elsif Is_Array_Type (T) then
19440 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
19441 return False;
19442 end if;
19444 Indx := First_Index (T);
19445 while Present (Indx) loop
19446 if not Is_OK_Static_Subtype (Etype (Indx)) then
19447 return False;
19448 else
19449 Next_Index (Indx);
19450 end if;
19451 end loop;
19453 return True;
19455 -- All other types are not potentially persistent
19457 else
19458 return False;
19459 end if;
19460 end Is_Potentially_Persistent_Type;
19462 --------------------------------
19463 -- Is_Potentially_Unevaluated --
19464 --------------------------------
19466 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
19467 function Has_Null_Others_Choice (Aggr : Node_Id) return Boolean;
19468 -- Aggr is an array aggregate with static bounds and an others clause;
19469 -- return True if the others choice of the given array aggregate does
19470 -- not cover any component (i.e. is null).
19472 function Immediate_Context_Implies_Is_Potentially_Unevaluated
19473 (Expr : Node_Id) return Boolean;
19474 -- Return True if the *immediate* context of this expression tells us
19475 -- that it is potentially unevaluated; return False if the *immediate*
19476 -- context doesn't provide an answer to this question and we need to
19477 -- keep looking.
19479 function Non_Static_Or_Null_Range (N : Node_Id) return Boolean;
19480 -- Return True if the given range is nonstatic or null
19482 ----------------------------
19483 -- Has_Null_Others_Choice --
19484 ----------------------------
19486 function Has_Null_Others_Choice (Aggr : Node_Id) return Boolean is
19487 Idx : constant Node_Id := First_Index (Etype (Aggr));
19488 Hiv : constant Uint := Expr_Value (Type_High_Bound (Etype (Idx)));
19489 Lov : constant Uint := Expr_Value (Type_Low_Bound (Etype (Idx)));
19491 begin
19492 declare
19493 Intervals : constant Interval_Lists.Discrete_Interval_List :=
19494 Interval_Lists.Aggregate_Intervals (Aggr);
19496 begin
19497 -- The others choice is null if, after normalization, we
19498 -- have a single interval covering the whole aggregate.
19500 return Intervals'Length = 1
19501 and then
19502 Intervals (Intervals'First).Low = Lov
19503 and then
19504 Intervals (Intervals'First).High = Hiv;
19505 end;
19507 -- If the aggregate is malformed (that is, indexes are not disjoint)
19508 -- then no action is needed at this stage; the error will be reported
19509 -- later by the frontend.
19511 exception
19512 when Interval_Lists.Intervals_Error =>
19513 return False;
19514 end Has_Null_Others_Choice;
19516 ----------------------------------------------------------
19517 -- Immediate_Context_Implies_Is_Potentially_Unevaluated --
19518 ----------------------------------------------------------
19520 function Immediate_Context_Implies_Is_Potentially_Unevaluated
19521 (Expr : Node_Id) return Boolean
19523 Par : constant Node_Id := Parent (Expr);
19525 function Aggregate_Type return Node_Id is (Etype (Parent (Par)));
19526 begin
19527 if Nkind (Par) = N_If_Expression then
19528 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
19530 elsif Nkind (Par) = N_Case_Expression then
19531 return Expr /= Expression (Par);
19533 elsif Nkind (Par) in N_Short_Circuit then
19534 return Expr = Right_Opnd (Par);
19536 elsif Nkind (Par) in N_Membership_Test then
19538 -- If the membership includes several alternatives, only the first
19539 -- is definitely evaluated.
19541 if Present (Alternatives (Par)) then
19542 return Expr /= First (Alternatives (Par));
19544 -- If this is a range membership both bounds are evaluated
19546 else
19547 return False;
19548 end if;
19550 elsif Nkind (Par) = N_Quantified_Expression then
19551 return Expr = Condition (Par);
19553 elsif Nkind (Par) in N_Component_Association
19554 | N_Iterated_Component_Association
19555 and then Expr = Expression (Par)
19556 and then Nkind (Parent (Par))
19557 in N_Aggregate | N_Delta_Aggregate | N_Extension_Aggregate
19558 and then Present (Aggregate_Type)
19559 and then Aggregate_Type /= Any_Composite
19560 then
19561 if Is_Array_Type (Aggregate_Type) then
19562 if Ada_Version >= Ada_2022 then
19563 -- For Ada 2022, this predicate returns True for
19564 -- any "repeatedly evaluated" expression.
19565 return True;
19566 end if;
19568 declare
19569 Choice : Node_Id;
19570 In_Others_Choice : Boolean := False;
19571 Array_Agg : constant Node_Id := Parent (Par);
19572 begin
19573 -- The expression of an array_component_association is
19574 -- potentially unevaluated if the associated choice is a
19575 -- subtype_indication or range that defines a nonstatic or
19576 -- null range.
19578 Choice := First (Choices (Par));
19579 while Present (Choice) loop
19580 if Nkind (Choice) = N_Range
19581 and then Non_Static_Or_Null_Range (Choice)
19582 then
19583 return True;
19585 elsif Nkind (Choice) = N_Identifier
19586 and then Present (Scalar_Range (Etype (Choice)))
19587 and then
19588 Non_Static_Or_Null_Range
19589 (Scalar_Range (Etype (Choice)))
19590 then
19591 return True;
19593 elsif Nkind (Choice) = N_Others_Choice then
19594 In_Others_Choice := True;
19595 end if;
19597 Next (Choice);
19598 end loop;
19600 -- It is also potentially unevaluated if the associated
19601 -- choice is an others choice and the applicable index
19602 -- constraint is nonstatic or null.
19604 if In_Others_Choice then
19605 if not Compile_Time_Known_Bounds (Aggregate_Type) then
19606 return True;
19607 else
19608 return Has_Null_Others_Choice (Array_Agg);
19609 end if;
19610 end if;
19611 end;
19613 elsif Is_Container_Aggregate (Parent (Par)) then
19614 -- a component of a container aggregate
19615 return True;
19616 end if;
19618 return False;
19620 else
19621 return False;
19622 end if;
19623 end Immediate_Context_Implies_Is_Potentially_Unevaluated;
19625 ------------------------------
19626 -- Non_Static_Or_Null_Range --
19627 ------------------------------
19629 function Non_Static_Or_Null_Range (N : Node_Id) return Boolean is
19630 Low, High : Node_Id;
19632 begin
19633 Get_Index_Bounds (N, Low, High);
19635 -- Check static bounds
19637 if not Compile_Time_Known_Value (Low)
19638 or else not Compile_Time_Known_Value (High)
19639 then
19640 return True;
19642 -- Check null range
19644 elsif Expr_Value (High) < Expr_Value (Low) then
19645 return True;
19646 end if;
19648 return False;
19649 end Non_Static_Or_Null_Range;
19651 -- Local variables
19653 Expr : Node_Id;
19654 Par : Node_Id;
19656 -- Start of processing for Is_Potentially_Unevaluated
19658 begin
19659 Expr := N;
19660 Par := Parent (Expr);
19662 while Present (Par)
19663 and then Nkind (Par) /= N_Pragma_Argument_Association
19664 loop
19665 if Comes_From_Source (Par)
19666 and then
19667 Immediate_Context_Implies_Is_Potentially_Unevaluated (Expr)
19668 then
19669 return True;
19671 -- For component associations continue climbing; it may be part of an
19672 -- array aggregate. For iterated component association we know that
19673 -- it belongs to an array aggreate, but only its expression is
19674 -- potentially unevaluated, not discrete choice list or iterator
19675 -- specification.
19677 elsif Nkind (Par) in N_Component_Association
19678 | N_Iterated_Component_Association
19679 then
19680 null;
19682 -- If the context is not an expression, or if is the result of
19683 -- expansion of an enclosing construct (such as another attribute)
19684 -- the predicate does not apply.
19686 elsif Nkind (Par) = N_Case_Expression_Alternative then
19687 null;
19689 elsif Nkind (Par) not in N_Subexpr
19690 or else not Comes_From_Source (Par)
19691 then
19692 return False;
19693 end if;
19695 Expr := Par;
19696 Par := Parent (Par);
19697 end loop;
19699 return False;
19700 end Is_Potentially_Unevaluated;
19702 -----------------------------------------
19703 -- Is_Predefined_Dispatching_Operation --
19704 -----------------------------------------
19706 function Is_Predefined_Dispatching_Operation
19707 (E : Entity_Id) return Boolean
19709 TSS_Name : TSS_Name_Type;
19711 begin
19712 if not Is_Dispatching_Operation (E) then
19713 return False;
19714 end if;
19716 Get_Name_String (Chars (E));
19718 -- Most predefined primitives have internally generated names. Equality
19719 -- must be treated differently; the predefined operation is recognized
19720 -- as a homogeneous binary operator that returns Boolean.
19722 if Name_Len > TSS_Name_Type'Last then
19723 TSS_Name :=
19724 TSS_Name_Type
19725 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
19727 if Chars (E) in Name_uAssign | Name_uSize
19728 or else
19729 (Chars (E) = Name_Op_Eq
19730 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
19731 or else TSS_Name = TSS_Deep_Adjust
19732 or else TSS_Name = TSS_Deep_Finalize
19733 or else TSS_Name = TSS_Stream_Input
19734 or else TSS_Name = TSS_Stream_Output
19735 or else TSS_Name = TSS_Stream_Read
19736 or else TSS_Name = TSS_Stream_Write
19737 or else TSS_Name = TSS_Put_Image
19738 or else Is_Predefined_Interface_Primitive (E)
19739 then
19740 return True;
19741 end if;
19742 end if;
19744 return False;
19745 end Is_Predefined_Dispatching_Operation;
19747 ---------------------------------------
19748 -- Is_Predefined_Interface_Primitive --
19749 ---------------------------------------
19751 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
19752 begin
19753 -- In VM targets we don't restrict the functionality of this test to
19754 -- compiling in Ada 2005 mode since in VM targets any tagged type has
19755 -- these primitives.
19757 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
19758 and then Chars (E) in Name_uDisp_Asynchronous_Select
19759 | Name_uDisp_Conditional_Select
19760 | Name_uDisp_Get_Prim_Op_Kind
19761 | Name_uDisp_Get_Task_Id
19762 | Name_uDisp_Requeue
19763 | Name_uDisp_Timed_Select;
19764 end Is_Predefined_Interface_Primitive;
19766 ---------------------------------------
19767 -- Is_Predefined_Internal_Operation --
19768 ---------------------------------------
19770 function Is_Predefined_Internal_Operation
19771 (E : Entity_Id) return Boolean
19773 TSS_Name : TSS_Name_Type;
19775 begin
19776 if not Is_Dispatching_Operation (E) then
19777 return False;
19778 end if;
19780 Get_Name_String (Chars (E));
19782 -- Most predefined primitives have internally generated names. Equality
19783 -- must be treated differently; the predefined operation is recognized
19784 -- as a homogeneous binary operator that returns Boolean.
19786 if Name_Len > TSS_Name_Type'Last then
19787 TSS_Name :=
19788 TSS_Name_Type
19789 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
19791 if Chars (E) in Name_uSize | Name_uAssign
19792 or else
19793 (Chars (E) = Name_Op_Eq
19794 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
19795 or else TSS_Name = TSS_Deep_Adjust
19796 or else TSS_Name = TSS_Deep_Finalize
19797 or else Is_Predefined_Interface_Primitive (E)
19798 then
19799 return True;
19800 end if;
19801 end if;
19803 return False;
19804 end Is_Predefined_Internal_Operation;
19806 --------------------------------
19807 -- Is_Preelaborable_Aggregate --
19808 --------------------------------
19810 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
19811 Aggr_Typ : constant Entity_Id := Etype (Aggr);
19812 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
19814 Anc_Part : Node_Id;
19815 Assoc : Node_Id;
19816 Choice : Node_Id;
19817 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
19818 Expr : Node_Id;
19820 begin
19821 if Array_Aggr then
19822 Comp_Typ := Component_Type (Aggr_Typ);
19823 end if;
19825 -- Inspect the ancestor part
19827 if Nkind (Aggr) = N_Extension_Aggregate then
19828 Anc_Part := Ancestor_Part (Aggr);
19830 -- The ancestor denotes a subtype mark
19832 if Is_Entity_Name (Anc_Part)
19833 and then Is_Type (Entity (Anc_Part))
19834 then
19835 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
19836 return False;
19837 end if;
19839 -- Otherwise the ancestor denotes an expression
19841 elsif not Is_Preelaborable_Construct (Anc_Part) then
19842 return False;
19843 end if;
19844 end if;
19846 -- Inspect the positional associations
19848 Expr := First (Expressions (Aggr));
19849 while Present (Expr) loop
19850 if not Is_Preelaborable_Construct (Expr) then
19851 return False;
19852 end if;
19854 Next (Expr);
19855 end loop;
19857 -- Inspect the named associations
19859 Assoc := First (Component_Associations (Aggr));
19860 while Present (Assoc) loop
19862 -- Inspect the choices of the current named association
19864 Choice := First (Choices (Assoc));
19865 while Present (Choice) loop
19866 if Array_Aggr then
19868 -- For a choice to be preelaborable, it must denote either a
19869 -- static range or a static expression.
19871 if Nkind (Choice) = N_Others_Choice then
19872 null;
19874 elsif Nkind (Choice) = N_Range then
19875 if not Is_OK_Static_Range (Choice) then
19876 return False;
19877 end if;
19879 elsif not Is_OK_Static_Expression (Choice) then
19880 return False;
19881 end if;
19883 else
19884 Comp_Typ := Etype (Choice);
19885 end if;
19887 Next (Choice);
19888 end loop;
19890 -- The type of the choice must have preelaborable initialization if
19891 -- the association carries a <>.
19893 pragma Assert (Present (Comp_Typ));
19894 if Box_Present (Assoc) then
19895 if not Has_Preelaborable_Initialization (Comp_Typ) then
19896 return False;
19897 end if;
19899 -- The type of the expression must have preelaborable initialization
19901 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
19902 return False;
19903 end if;
19905 Next (Assoc);
19906 end loop;
19908 -- At this point the aggregate is preelaborable
19910 return True;
19911 end Is_Preelaborable_Aggregate;
19913 --------------------------------
19914 -- Is_Preelaborable_Construct --
19915 --------------------------------
19917 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
19918 begin
19919 -- Aggregates
19921 if Nkind (N) in N_Aggregate | N_Extension_Aggregate then
19922 return Is_Preelaborable_Aggregate (N);
19924 -- Attributes are allowed in general, even if their prefix is a formal
19925 -- type. It seems that certain attributes known not to be static might
19926 -- not be allowed, but there are no rules to prevent them.
19928 elsif Nkind (N) = N_Attribute_Reference then
19929 return True;
19931 -- Expressions
19933 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
19934 return True;
19936 elsif Nkind (N) = N_Qualified_Expression then
19937 return Is_Preelaborable_Construct (Expression (N));
19939 -- Names are preelaborable when they denote a discriminant of an
19940 -- enclosing type. Discriminals are also considered for this check.
19942 elsif Is_Entity_Name (N)
19943 and then Present (Entity (N))
19944 and then
19945 (Ekind (Entity (N)) = E_Discriminant
19946 or else (Ekind (Entity (N)) in E_Constant | E_In_Parameter
19947 and then Present (Discriminal_Link (Entity (N)))))
19948 then
19949 return True;
19951 -- Statements
19953 elsif Nkind (N) = N_Null then
19954 return True;
19956 -- Ada 2022 (AI12-0175): Calls to certain functions that are essentially
19957 -- unchecked conversions are preelaborable.
19959 elsif Ada_Version >= Ada_2022
19960 and then Nkind (N) = N_Function_Call
19961 and then Is_Entity_Name (Name (N))
19962 and then Is_Preelaborable_Function (Entity (Name (N)))
19963 then
19964 declare
19965 A : Node_Id;
19966 begin
19967 A := First_Actual (N);
19969 while Present (A) loop
19970 if not Is_Preelaborable_Construct (A) then
19971 return False;
19972 end if;
19974 Next_Actual (A);
19975 end loop;
19976 end;
19978 return True;
19980 -- Otherwise the construct is not preelaborable
19982 else
19983 return False;
19984 end if;
19985 end Is_Preelaborable_Construct;
19987 -------------------------------
19988 -- Is_Preelaborable_Function --
19989 -------------------------------
19991 function Is_Preelaborable_Function (Id : Entity_Id) return Boolean is
19992 SATAC : constant Rtsfind.RTU_Id := System_Address_To_Access_Conversions;
19993 Scop : constant Entity_Id := Scope (Id);
19995 begin
19996 -- Small optimization: every allowed function has convention Intrinsic
19997 -- (see Analyze_Subprogram_Instantiation for the subtlety in the test).
19999 if not Is_Intrinsic_Subprogram (Id)
20000 and then Convention (Id) /= Convention_Intrinsic
20001 then
20002 return False;
20003 end if;
20005 -- An instance of Unchecked_Conversion
20007 if Is_Unchecked_Conversion_Instance (Id) then
20008 return True;
20009 end if;
20011 -- A function declared in System.Storage_Elements
20013 if Is_RTU (Scop, System_Storage_Elements) then
20014 return True;
20015 end if;
20017 -- The functions To_Pointer and To_Address declared in an instance of
20018 -- System.Address_To_Access_Conversions (they are the only ones).
20020 if Ekind (Scop) = E_Package
20021 and then Nkind (Parent (Scop)) = N_Package_Specification
20022 and then Present (Generic_Parent (Parent (Scop)))
20023 and then Is_RTU (Generic_Parent (Parent (Scop)), SATAC)
20024 then
20025 return True;
20026 end if;
20028 return False;
20029 end Is_Preelaborable_Function;
20031 -----------------------------
20032 -- Is_Private_Library_Unit --
20033 -----------------------------
20035 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
20036 Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
20037 begin
20038 return Nkind (Comp_Unit) = N_Compilation_Unit
20039 and then Private_Present (Comp_Unit);
20040 end Is_Private_Library_Unit;
20042 ---------------------------------
20043 -- Is_Protected_Self_Reference --
20044 ---------------------------------
20046 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
20048 function In_Access_Definition (N : Node_Id) return Boolean;
20049 -- Returns true if N belongs to an access definition
20051 --------------------------
20052 -- In_Access_Definition --
20053 --------------------------
20055 function In_Access_Definition (N : Node_Id) return Boolean is
20056 P : Node_Id;
20058 begin
20059 P := Parent (N);
20060 while Present (P) loop
20061 if Nkind (P) = N_Access_Definition then
20062 return True;
20063 end if;
20065 P := Parent (P);
20066 end loop;
20068 return False;
20069 end In_Access_Definition;
20071 -- Start of processing for Is_Protected_Self_Reference
20073 begin
20074 -- Verify that prefix is analyzed and has the proper form. Note that
20075 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
20076 -- produce the address of an entity, do not analyze their prefix
20077 -- because they denote entities that are not necessarily visible.
20078 -- Neither of them can apply to a protected type.
20080 return Ada_Version >= Ada_2005
20081 and then Is_Entity_Name (N)
20082 and then Present (Entity (N))
20083 and then Is_Protected_Type (Entity (N))
20084 and then In_Open_Scopes (Entity (N))
20085 and then not In_Access_Definition (N);
20086 end Is_Protected_Self_Reference;
20088 -----------------------------
20089 -- Is_RCI_Pkg_Spec_Or_Body --
20090 -----------------------------
20092 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
20094 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
20095 -- Return True if the unit of Cunit is an RCI package declaration
20097 ---------------------------
20098 -- Is_RCI_Pkg_Decl_Cunit --
20099 ---------------------------
20101 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
20102 The_Unit : constant Node_Id := Unit (Cunit);
20104 begin
20105 if Nkind (The_Unit) /= N_Package_Declaration then
20106 return False;
20107 end if;
20109 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
20110 end Is_RCI_Pkg_Decl_Cunit;
20112 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
20114 begin
20115 return Is_RCI_Pkg_Decl_Cunit (Cunit)
20116 or else
20117 (Nkind (Unit (Cunit)) = N_Package_Body
20118 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
20119 end Is_RCI_Pkg_Spec_Or_Body;
20121 -----------------------------------------
20122 -- Is_Remote_Access_To_Class_Wide_Type --
20123 -----------------------------------------
20125 function Is_Remote_Access_To_Class_Wide_Type
20126 (E : Entity_Id) return Boolean
20128 begin
20129 -- A remote access to class-wide type is a general access to object type
20130 -- declared in the visible part of a Remote_Types or Remote_Call_
20131 -- Interface unit.
20133 return Ekind (E) = E_General_Access_Type
20134 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
20135 end Is_Remote_Access_To_Class_Wide_Type;
20137 -----------------------------------------
20138 -- Is_Remote_Access_To_Subprogram_Type --
20139 -----------------------------------------
20141 function Is_Remote_Access_To_Subprogram_Type
20142 (E : Entity_Id) return Boolean
20144 begin
20145 return (Ekind (E) = E_Access_Subprogram_Type
20146 or else (Ekind (E) = E_Record_Type
20147 and then Present (Corresponding_Remote_Type (E))))
20148 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
20149 end Is_Remote_Access_To_Subprogram_Type;
20151 --------------------
20152 -- Is_Remote_Call --
20153 --------------------
20155 function Is_Remote_Call (N : Node_Id) return Boolean is
20156 begin
20157 if Nkind (N) not in N_Subprogram_Call then
20159 -- An entry call cannot be remote
20161 return False;
20163 elsif Nkind (Name (N)) in N_Has_Entity
20164 and then Is_Remote_Call_Interface (Entity (Name (N)))
20165 then
20166 -- A subprogram declared in the spec of a RCI package is remote
20168 return True;
20170 elsif Nkind (Name (N)) = N_Explicit_Dereference
20171 and then Is_Remote_Access_To_Subprogram_Type
20172 (Etype (Prefix (Name (N))))
20173 then
20174 -- The dereference of a RAS is a remote call
20176 return True;
20178 elsif Present (Controlling_Argument (N))
20179 and then Is_Remote_Access_To_Class_Wide_Type
20180 (Etype (Controlling_Argument (N)))
20181 then
20182 -- Any primitive operation call with a controlling argument of
20183 -- a RACW type is a remote call.
20185 return True;
20186 end if;
20188 -- All other calls are local calls
20190 return False;
20191 end Is_Remote_Call;
20193 ----------------------
20194 -- Is_Renamed_Entry --
20195 ----------------------
20197 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
20198 Orig_Node : Node_Id := Empty;
20199 Subp_Decl : Node_Id :=
20200 (if No (Parent (Proc_Nam)) then Empty else Parent (Parent (Proc_Nam)));
20202 function Is_Entry (Nam : Node_Id) return Boolean;
20203 -- Determine whether Nam is an entry. Traverse selectors if there are
20204 -- nested selected components.
20206 --------------
20207 -- Is_Entry --
20208 --------------
20210 function Is_Entry (Nam : Node_Id) return Boolean is
20211 begin
20212 if Nkind (Nam) = N_Selected_Component then
20213 return Is_Entry (Selector_Name (Nam));
20214 end if;
20216 return Ekind (Entity (Nam)) = E_Entry;
20217 end Is_Entry;
20219 -- Start of processing for Is_Renamed_Entry
20221 begin
20222 if Present (Alias (Proc_Nam)) then
20223 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
20224 end if;
20226 -- Look for a rewritten subprogram renaming declaration
20228 if Nkind (Subp_Decl) = N_Subprogram_Declaration
20229 and then Present (Original_Node (Subp_Decl))
20230 then
20231 Orig_Node := Original_Node (Subp_Decl);
20232 end if;
20234 -- The rewritten subprogram is actually an entry
20236 if Present (Orig_Node)
20237 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
20238 and then Is_Entry (Name (Orig_Node))
20239 then
20240 return True;
20241 end if;
20243 return False;
20244 end Is_Renamed_Entry;
20246 ----------------------------
20247 -- Is_Reversible_Iterator --
20248 ----------------------------
20250 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
20251 Ifaces_List : Elist_Id;
20252 Iface_Elmt : Elmt_Id;
20253 Iface : Entity_Id;
20255 begin
20256 if Is_Class_Wide_Type (Typ)
20257 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
20258 and then In_Predefined_Unit (Root_Type (Typ))
20259 then
20260 return True;
20262 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
20263 return False;
20265 else
20266 Collect_Interfaces (Typ, Ifaces_List);
20268 Iface_Elmt := First_Elmt (Ifaces_List);
20269 while Present (Iface_Elmt) loop
20270 Iface := Node (Iface_Elmt);
20271 if Chars (Iface) = Name_Reversible_Iterator
20272 and then In_Predefined_Unit (Iface)
20273 then
20274 return True;
20275 end if;
20277 Next_Elmt (Iface_Elmt);
20278 end loop;
20279 end if;
20281 return False;
20282 end Is_Reversible_Iterator;
20284 ---------------------------------
20285 -- Is_Single_Concurrent_Object --
20286 ---------------------------------
20288 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
20289 begin
20290 return
20291 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
20292 end Is_Single_Concurrent_Object;
20294 -------------------------------
20295 -- Is_Single_Concurrent_Type --
20296 -------------------------------
20298 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
20299 begin
20300 return
20301 Ekind (Id) in E_Protected_Type | E_Task_Type
20302 and then Is_Single_Concurrent_Type_Declaration
20303 (Declaration_Node (Id));
20304 end Is_Single_Concurrent_Type;
20306 -------------------------------------------
20307 -- Is_Single_Concurrent_Type_Declaration --
20308 -------------------------------------------
20310 function Is_Single_Concurrent_Type_Declaration
20311 (N : Node_Id) return Boolean
20313 begin
20314 return Nkind (Original_Node (N)) in
20315 N_Single_Protected_Declaration | N_Single_Task_Declaration;
20316 end Is_Single_Concurrent_Type_Declaration;
20318 ---------------------------------------------
20319 -- Is_Single_Precision_Floating_Point_Type --
20320 ---------------------------------------------
20322 function Is_Single_Precision_Floating_Point_Type
20323 (E : Entity_Id) return Boolean is
20324 begin
20325 return Is_Floating_Point_Type (E)
20326 and then Machine_Radix_Value (E) = Uint_2
20327 and then Machine_Mantissa_Value (E) = Uint_24
20328 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
20329 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
20330 end Is_Single_Precision_Floating_Point_Type;
20332 --------------------------------
20333 -- Is_Single_Protected_Object --
20334 --------------------------------
20336 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
20337 begin
20338 return
20339 Ekind (Id) = E_Variable
20340 and then Ekind (Etype (Id)) = E_Protected_Type
20341 and then Is_Single_Concurrent_Type (Etype (Id));
20342 end Is_Single_Protected_Object;
20344 ---------------------------
20345 -- Is_Single_Task_Object --
20346 ---------------------------
20348 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
20349 begin
20350 return
20351 Ekind (Id) = E_Variable
20352 and then Ekind (Etype (Id)) = E_Task_Type
20353 and then Is_Single_Concurrent_Type (Etype (Id));
20354 end Is_Single_Task_Object;
20356 -----------------------------
20357 -- Is_Specific_Tagged_Type --
20358 -----------------------------
20360 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
20361 Full_Typ : Entity_Id;
20363 begin
20364 -- Handle private types
20366 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
20367 Full_Typ := Full_View (Typ);
20368 else
20369 Full_Typ := Typ;
20370 end if;
20372 -- A specific tagged type is a non-class-wide tagged type
20374 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
20375 end Is_Specific_Tagged_Type;
20377 ------------------
20378 -- Is_Statement --
20379 ------------------
20381 function Is_Statement (N : Node_Id) return Boolean is
20382 begin
20383 return
20384 Nkind (N) in N_Statement_Other_Than_Procedure_Call
20385 or else Nkind (N) = N_Procedure_Call_Statement;
20386 end Is_Statement;
20388 --------------------------------------
20389 -- Is_Static_Discriminant_Component --
20390 --------------------------------------
20392 function Is_Static_Discriminant_Component (N : Node_Id) return Boolean is
20393 begin
20394 return Nkind (N) = N_Selected_Component
20395 and then not Is_In_Discriminant_Check (N)
20396 and then Present (Etype (Prefix (N)))
20397 and then Ekind (Etype (Prefix (N))) = E_Record_Subtype
20398 and then Has_Static_Discriminants (Etype (Prefix (N)))
20399 and then Present (Entity (Selector_Name (N)))
20400 and then Ekind (Entity (Selector_Name (N))) = E_Discriminant
20401 and then not In_Check_Node (N);
20402 end Is_Static_Discriminant_Component;
20404 ------------------------
20405 -- Is_Static_Function --
20406 ------------------------
20408 function Is_Static_Function (Subp : Entity_Id) return Boolean is
20409 begin
20410 -- Always return False for pre Ada 2022 to e.g. ignore the Static
20411 -- aspect in package Interfaces for Ada_Version < 2022 and also
20412 -- for efficiency.
20414 return Ada_Version >= Ada_2022
20415 and then Has_Enabled_Aspect (Subp, Aspect_Static);
20416 end Is_Static_Function;
20418 -----------------------------
20419 -- Is_Static_Function_Call --
20420 -----------------------------
20422 function Is_Static_Function_Call (Call : Node_Id) return Boolean is
20423 function Has_All_Static_Actuals (Call : Node_Id) return Boolean;
20424 -- Return whether all actual parameters of Call are static expressions
20426 ----------------------------
20427 -- Has_All_Static_Actuals --
20428 ----------------------------
20430 function Has_All_Static_Actuals (Call : Node_Id) return Boolean is
20431 Actual : Node_Id := First_Actual (Call);
20432 String_Result : constant Boolean :=
20433 Is_String_Type (Etype (Entity (Name (Call))));
20435 begin
20436 while Present (Actual) loop
20437 if not Is_Static_Expression (Actual) then
20439 -- ??? In the string-returning case we want to avoid a call
20440 -- being made to Establish_Transient_Scope in Resolve_Call,
20441 -- but at the point where that's tested for (which now includes
20442 -- a call to test Is_Static_Function_Call), the actuals of the
20443 -- call haven't been resolved, so expressions of the actuals
20444 -- may not have been marked Is_Static_Expression yet, so we
20445 -- force them to be resolved here, so we can tell if they're
20446 -- static. Calling Resolve here is admittedly a kludge, and we
20447 -- limit this call to string-returning cases.
20449 if String_Result then
20450 Resolve (Actual);
20451 end if;
20453 -- Test flag again in case it's now True due to above Resolve
20455 if not Is_Static_Expression (Actual) then
20456 return False;
20457 end if;
20458 end if;
20460 Next_Actual (Actual);
20461 end loop;
20463 return True;
20464 end Has_All_Static_Actuals;
20466 begin
20467 return Nkind (Call) = N_Function_Call
20468 and then Is_Entity_Name (Name (Call))
20469 and then Is_Static_Function (Entity (Name (Call)))
20470 and then Has_All_Static_Actuals (Call);
20471 end Is_Static_Function_Call;
20473 -------------------------------------------
20474 -- Is_Subcomponent_Of_Full_Access_Object --
20475 -------------------------------------------
20477 function Is_Subcomponent_Of_Full_Access_Object (N : Node_Id) return Boolean
20479 R : Node_Id;
20481 begin
20482 R := Get_Referenced_Object (N);
20484 while Nkind (R) in N_Indexed_Component | N_Selected_Component | N_Slice
20485 loop
20486 R := Get_Referenced_Object (Prefix (R));
20488 -- If the prefix is an access value, only the designated type matters
20490 if Is_Access_Type (Etype (R)) then
20491 if Is_Full_Access (Designated_Type (Etype (R))) then
20492 return True;
20493 end if;
20495 else
20496 if Is_Full_Access_Object (R) then
20497 return True;
20498 end if;
20499 end if;
20500 end loop;
20502 return False;
20503 end Is_Subcomponent_Of_Full_Access_Object;
20505 ---------------------------------------
20506 -- Is_Subprogram_Contract_Annotation --
20507 ---------------------------------------
20509 function Is_Subprogram_Contract_Annotation
20510 (Item : Node_Id) return Boolean
20512 Nam : Name_Id;
20514 begin
20515 if Nkind (Item) = N_Aspect_Specification then
20516 Nam := Chars (Identifier (Item));
20518 else pragma Assert (Nkind (Item) = N_Pragma);
20519 Nam := Pragma_Name (Item);
20520 end if;
20522 return Nam = Name_Always_Terminates
20523 or else Nam = Name_Contract_Cases
20524 or else Nam = Name_Depends
20525 or else Nam = Name_Exceptional_Cases
20526 or else Nam = Name_Extensions_Visible
20527 or else Nam = Name_Global
20528 or else Nam = Name_Post
20529 or else Nam = Name_Post_Class
20530 or else Nam = Name_Postcondition
20531 or else Nam = Name_Pre
20532 or else Nam = Name_Pre_Class
20533 or else Nam = Name_Precondition
20534 or else Nam = Name_Refined_Depends
20535 or else Nam = Name_Refined_Global
20536 or else Nam = Name_Refined_Post
20537 or else Nam = Name_Subprogram_Variant
20538 or else Nam = Name_Test_Case;
20539 end Is_Subprogram_Contract_Annotation;
20541 --------------------------------------------------
20542 -- Is_Subprogram_Stub_Without_Prior_Declaration --
20543 --------------------------------------------------
20545 function Is_Subprogram_Stub_Without_Prior_Declaration
20546 (N : Node_Id) return Boolean
20548 begin
20549 pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
20551 case Ekind (Defining_Entity (N)) is
20553 -- A subprogram stub without prior declaration serves as declaration
20554 -- for the actual subprogram body. As such, it has an attached
20555 -- defining entity of E_Function or E_Procedure.
20557 when E_Function
20558 | E_Procedure
20560 return True;
20562 -- Otherwise, it is completes a [generic] subprogram declaration
20564 when E_Generic_Function
20565 | E_Generic_Procedure
20566 | E_Subprogram_Body
20568 return False;
20570 when others =>
20571 raise Program_Error;
20572 end case;
20573 end Is_Subprogram_Stub_Without_Prior_Declaration;
20575 ---------------------------
20576 -- Is_Suitable_Primitive --
20577 ---------------------------
20579 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
20580 begin
20581 -- The Default_Initial_Condition and invariant procedures must not be
20582 -- treated as primitive operations even when they apply to a tagged
20583 -- type. These routines must not act as targets of dispatching calls
20584 -- because they already utilize class-wide-precondition semantics to
20585 -- handle inheritance and overriding.
20587 if Ekind (Subp_Id) = E_Procedure
20588 and then (Is_DIC_Procedure (Subp_Id)
20589 or else
20590 Is_Invariant_Procedure (Subp_Id))
20591 then
20592 return False;
20593 end if;
20595 return True;
20596 end Is_Suitable_Primitive;
20598 ----------------------------
20599 -- Is_Synchronized_Object --
20600 ----------------------------
20602 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
20603 Prag : Node_Id;
20605 begin
20606 if Is_Object (Id) then
20608 -- The object is synchronized if it is of a type that yields a
20609 -- synchronized object.
20611 if Yields_Synchronized_Object (Etype (Id)) then
20612 return True;
20614 -- The object is synchronized if it is atomic and Async_Writers is
20615 -- enabled.
20617 elsif Is_Atomic_Object_Entity (Id)
20618 and then Async_Writers_Enabled (Id)
20619 then
20620 return True;
20622 -- A constant is a synchronized object by default, unless its type is
20623 -- access-to-variable type.
20625 elsif Ekind (Id) = E_Constant
20626 and then not Is_Access_Variable (Etype (Id))
20627 then
20628 return True;
20630 -- A variable is a synchronized object if it is subject to pragma
20631 -- Constant_After_Elaboration.
20633 elsif Ekind (Id) = E_Variable then
20634 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
20636 return Present (Prag) and then Is_Enabled_Pragma (Prag);
20637 end if;
20638 end if;
20640 -- Otherwise the input is not an object or it does not qualify as a
20641 -- synchronized object.
20643 return False;
20644 end Is_Synchronized_Object;
20646 ---------------------------------
20647 -- Is_Synchronized_Tagged_Type --
20648 ---------------------------------
20650 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
20651 Kind : constant Entity_Kind := Ekind (Base_Type (E));
20653 begin
20654 -- A task or protected type derived from an interface is a tagged type.
20655 -- Such a tagged type is called a synchronized tagged type, as are
20656 -- synchronized interfaces and private extensions whose declaration
20657 -- includes the reserved word synchronized.
20659 return (Is_Tagged_Type (E)
20660 and then (Kind = E_Task_Type
20661 or else
20662 Kind = E_Protected_Type))
20663 or else
20664 (Is_Interface (E)
20665 and then Is_Synchronized_Interface (E))
20666 or else
20667 (Ekind (E) = E_Record_Type_With_Private
20668 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
20669 and then (Synchronized_Present (Parent (E))
20670 or else Is_Synchronized_Interface (Etype (E))));
20671 end Is_Synchronized_Tagged_Type;
20673 -----------------
20674 -- Is_Transfer --
20675 -----------------
20677 function Is_Transfer (N : Node_Id) return Boolean is
20678 Kind : constant Node_Kind := Nkind (N);
20680 begin
20681 if Kind in N_Simple_Return_Statement
20682 | N_Extended_Return_Statement
20683 | N_Goto_Statement
20684 | N_Raise_Statement
20685 | N_Requeue_Statement
20686 then
20687 return True;
20689 elsif Kind in N_Exit_Statement | N_Raise_xxx_Error
20690 and then No (Condition (N))
20691 then
20692 return True;
20694 elsif Kind = N_Procedure_Call_Statement
20695 and then Is_Entity_Name (Name (N))
20696 and then Present (Entity (Name (N)))
20697 and then No_Return (Entity (Name (N)))
20698 then
20699 return True;
20701 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
20702 return True;
20704 else
20705 return False;
20706 end if;
20707 end Is_Transfer;
20709 -------------
20710 -- Is_True --
20711 -------------
20713 function Is_True (U : Opt_Ubool) return Boolean is
20714 begin
20715 return No (U) or else U = Uint_1;
20716 end Is_True;
20718 ------------------------
20719 -- Is_Trivial_Boolean --
20720 ------------------------
20722 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
20723 begin
20724 return Comes_From_Source (N)
20725 and then Nkind (N) in N_Identifier | N_Expanded_Name
20726 and then Entity (N) in Standard_True | Standard_False;
20727 end Is_Trivial_Boolean;
20729 --------------------------------------
20730 -- Is_Unchecked_Conversion_Instance --
20731 --------------------------------------
20733 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
20734 Par : Node_Id;
20736 begin
20737 -- Look for a function whose generic parent is the predefined intrinsic
20738 -- function Unchecked_Conversion, or for one that renames such an
20739 -- instance.
20741 if Ekind (Id) = E_Function then
20742 Par := Parent (Id);
20744 if Nkind (Par) = N_Function_Specification then
20745 Par := Generic_Parent (Par);
20747 if Present (Par) then
20748 return
20749 Chars (Par) = Name_Unchecked_Conversion
20750 and then Is_Intrinsic_Subprogram (Par)
20751 and then In_Predefined_Unit (Par);
20752 else
20753 return
20754 Present (Alias (Id))
20755 and then Is_Unchecked_Conversion_Instance (Alias (Id));
20756 end if;
20757 end if;
20758 end if;
20760 return False;
20761 end Is_Unchecked_Conversion_Instance;
20763 -------------------------------
20764 -- Is_Universal_Numeric_Type --
20765 -------------------------------
20767 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
20768 begin
20769 return T = Universal_Integer or else T = Universal_Real;
20770 end Is_Universal_Numeric_Type;
20772 -------------------------------------
20773 -- Is_Unconstrained_Or_Tagged_Item --
20774 -------------------------------------
20776 function Is_Unconstrained_Or_Tagged_Item
20777 (Item : Entity_Id) return Boolean
20779 Typ : constant Entity_Id := Etype (Item);
20780 begin
20781 if Is_Tagged_Type (Typ) then
20782 return True;
20784 elsif Is_Array_Type (Typ)
20785 or else Is_Record_Type (Typ)
20786 or else Is_Private_Type (Typ)
20787 then
20788 return not Is_Constrained (Typ);
20790 else
20791 return False;
20792 end if;
20793 end Is_Unconstrained_Or_Tagged_Item;
20795 ------------------------------
20796 -- Is_User_Defined_Equality --
20797 ------------------------------
20799 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
20800 F1, F2 : Entity_Id;
20802 begin
20803 -- An equality operator is a function that carries the name "=", returns
20804 -- Boolean, and has exactly two formal parameters of an identical type.
20806 if Ekind (Id) = E_Function
20807 and then Chars (Id) = Name_Op_Eq
20808 and then Base_Type (Etype (Id)) = Standard_Boolean
20809 then
20810 F1 := First_Formal (Id);
20812 if No (F1) then
20813 return False;
20814 end if;
20816 F2 := Next_Formal (F1);
20818 return Present (F2)
20819 and then No (Next_Formal (F2))
20820 and then Base_Type (Etype (F1)) = Base_Type (Etype (F2));
20822 else
20823 return False;
20824 end if;
20825 end Is_User_Defined_Equality;
20827 -----------------------------
20828 -- Is_User_Defined_Literal --
20829 -----------------------------
20831 function Is_User_Defined_Literal
20832 (N : Node_Id;
20833 Typ : Entity_Id) return Boolean
20835 Literal_Aspect_Map :
20836 constant array (N_Numeric_Or_String_Literal) of Aspect_Id :=
20837 (N_Integer_Literal => Aspect_Integer_Literal,
20838 N_Interpolated_String_Literal => No_Aspect,
20839 N_Real_Literal => Aspect_Real_Literal,
20840 N_String_Literal => Aspect_String_Literal);
20842 begin
20843 -- Return True when N is either a literal or a named number and the
20844 -- type has the appropriate user-defined literal aspect.
20846 return (Nkind (N) in N_Numeric_Or_String_Literal
20847 and then Has_Aspect (Typ, Literal_Aspect_Map (Nkind (N))))
20848 or else
20849 (Is_Entity_Name (N)
20850 and then Present (Entity (N))
20851 and then
20852 ((Ekind (Entity (N)) = E_Named_Integer
20853 and then Has_Aspect (Typ, Aspect_Integer_Literal))
20854 or else
20855 (Ekind (Entity (N)) = E_Named_Real
20856 and then Has_Aspect (Typ, Aspect_Real_Literal))));
20857 end Is_User_Defined_Literal;
20859 --------------------------------------
20860 -- Is_Validation_Variable_Reference --
20861 --------------------------------------
20863 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
20864 Var : constant Node_Id := Unqual_Conv (N);
20865 Var_Id : Entity_Id;
20867 begin
20868 Var_Id := Empty;
20870 if Is_Entity_Name (Var) then
20871 Var_Id := Entity (Var);
20872 end if;
20874 return
20875 Present (Var_Id)
20876 and then Ekind (Var_Id) = E_Variable
20877 and then Present (Validated_Object (Var_Id));
20878 end Is_Validation_Variable_Reference;
20880 ----------------------------
20881 -- Is_Variable_Size_Array --
20882 ----------------------------
20884 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
20885 Idx : Node_Id;
20887 begin
20888 pragma Assert (Is_Array_Type (E));
20890 -- Check if some index is initialized with a non-constant value
20892 Idx := First_Index (E);
20893 while Present (Idx) loop
20894 if Nkind (Idx) = N_Range then
20895 if not Is_Constant_Bound (Low_Bound (Idx))
20896 or else not Is_Constant_Bound (High_Bound (Idx))
20897 then
20898 return True;
20899 end if;
20900 end if;
20902 Next_Index (Idx);
20903 end loop;
20905 return False;
20906 end Is_Variable_Size_Array;
20908 -----------------------------
20909 -- Is_Variable_Size_Record --
20910 -----------------------------
20912 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
20913 Comp : Entity_Id;
20914 Comp_Typ : Entity_Id;
20916 begin
20917 pragma Assert (Is_Record_Type (E));
20919 Comp := First_Component (E);
20920 while Present (Comp) loop
20921 Comp_Typ := Underlying_Type (Etype (Comp));
20923 -- Recursive call if the record type has discriminants
20925 if Is_Record_Type (Comp_Typ)
20926 and then Has_Discriminants (Comp_Typ)
20927 and then Is_Variable_Size_Record (Comp_Typ)
20928 then
20929 return True;
20931 elsif Is_Array_Type (Comp_Typ)
20932 and then Is_Variable_Size_Array (Comp_Typ)
20933 then
20934 return True;
20935 end if;
20937 Next_Component (Comp);
20938 end loop;
20940 return False;
20941 end Is_Variable_Size_Record;
20943 -----------------
20944 -- Is_Variable --
20945 -----------------
20947 -- Should Is_Variable be refactored to better handle dereferences and
20948 -- technical debt ???
20950 function Is_Variable
20951 (N : Node_Id;
20952 Use_Original_Node : Boolean := True) return Boolean
20954 Orig_Node : Node_Id;
20956 function In_Protected_Function (E : Entity_Id) return Boolean;
20957 -- Within a protected function, the private components of the enclosing
20958 -- protected type are constants. A function nested within a (protected)
20959 -- procedure is not itself protected. Within the body of a protected
20960 -- function the current instance of the protected type is a constant.
20962 function Is_Variable_Prefix (P : Node_Id) return Boolean;
20963 -- Prefixes can involve implicit dereferences, in which case we must
20964 -- test for the case of a reference of a constant access type, which can
20965 -- can never be a variable.
20967 ---------------------------
20968 -- In_Protected_Function --
20969 ---------------------------
20971 function In_Protected_Function (E : Entity_Id) return Boolean is
20972 Prot : Entity_Id;
20973 S : Entity_Id;
20975 begin
20976 -- E is the current instance of a type
20978 if Is_Type (E) then
20979 Prot := E;
20981 -- E is an object
20983 else
20984 Prot := Scope (E);
20985 end if;
20987 if not Is_Protected_Type (Prot) then
20988 return False;
20990 else
20991 S := Current_Scope;
20992 while Present (S) and then S /= Prot loop
20993 if Ekind (S) = E_Function and then Scope (S) = Prot then
20994 return True;
20995 end if;
20997 S := Scope (S);
20998 end loop;
21000 return False;
21001 end if;
21002 end In_Protected_Function;
21004 ------------------------
21005 -- Is_Variable_Prefix --
21006 ------------------------
21008 function Is_Variable_Prefix (P : Node_Id) return Boolean is
21009 begin
21010 if Is_Access_Type (Etype (P)) then
21011 return not Is_Access_Constant (Root_Type (Etype (P)));
21013 -- For the case of an indexed component whose prefix has a packed
21014 -- array type, the prefix has been rewritten into a type conversion.
21015 -- Determine variable-ness from the converted expression.
21017 elsif Nkind (P) = N_Type_Conversion
21018 and then not Comes_From_Source (P)
21019 and then Is_Packed_Array (Etype (P))
21020 then
21021 return Is_Variable (Expression (P));
21023 else
21024 return Is_Variable (P);
21025 end if;
21026 end Is_Variable_Prefix;
21028 -- Start of processing for Is_Variable
21030 begin
21031 -- Special check, allow x'Deref(expr) as a variable
21033 if Nkind (N) = N_Attribute_Reference
21034 and then Attribute_Name (N) = Name_Deref
21035 then
21036 return True;
21037 end if;
21039 -- Check if we perform the test on the original node since this may be a
21040 -- test of syntactic categories which must not be disturbed by whatever
21041 -- rewriting might have occurred. For example, an aggregate, which is
21042 -- certainly NOT a variable, could be turned into a variable by
21043 -- expansion.
21045 if Use_Original_Node then
21046 Orig_Node := Original_Node (N);
21047 else
21048 Orig_Node := N;
21049 end if;
21051 -- Definitely OK if Assignment_OK is set. Since this is something that
21052 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
21054 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
21055 return True;
21057 -- It is possible that N is a selected component of a view conversion,
21058 -- and in that case get the expression of the conversion and test
21059 -- whether it is indeed a variable.
21061 elsif Nkind (N) = N_Selected_Component
21062 and then Is_View_Conversion (Ultimate_Prefix (N))
21063 and then Is_Variable (Expression (Ultimate_Prefix (N)))
21064 then
21065 return True;
21067 -- Normally we go to the original node, but there is one exception where
21068 -- we use the rewritten node, namely when it is an explicit dereference.
21069 -- The generated code may rewrite a prefix which is an access type with
21070 -- an explicit dereference. The dereference is a variable, even though
21071 -- the original node may not be (since it could be a constant of the
21072 -- access type).
21074 -- In Ada 2005 we have a further case to consider: the prefix may be a
21075 -- function call given in prefix notation. The original node appears to
21076 -- be a selected component, but we need to examine the call.
21078 elsif Nkind (N) = N_Explicit_Dereference
21079 and then Nkind (Orig_Node) /= N_Explicit_Dereference
21080 and then Present (Etype (Orig_Node))
21081 and then Is_Access_Type (Etype (Orig_Node))
21082 then
21083 -- Note that if the prefix is an explicit dereference that does not
21084 -- come from source, we must check for a rewritten function call in
21085 -- prefixed notation before other forms of rewriting, to prevent a
21086 -- compiler crash.
21088 return
21089 (Nkind (Orig_Node) = N_Function_Call
21090 and then not Is_Access_Constant (Etype (Prefix (N))))
21091 or else
21092 Is_Variable_Prefix (Original_Node (Prefix (N)));
21094 -- Generalized indexing operations are rewritten as explicit
21095 -- dereferences, and it is only during resolution that we can
21096 -- check whether the context requires an access_to_variable type.
21098 elsif Nkind (N) = N_Explicit_Dereference
21099 and then Present (Etype (Orig_Node))
21100 and then Has_Implicit_Dereference (Etype (Orig_Node))
21101 and then Ada_Version >= Ada_2012
21102 then
21103 return not Is_Access_Constant (Etype (Prefix (N)));
21105 -- A function call is never a variable
21107 elsif Nkind (N) = N_Function_Call then
21108 return False;
21110 -- All remaining checks use the original node
21112 elsif Is_Entity_Name (Orig_Node)
21113 and then Present (Entity (Orig_Node))
21114 then
21115 declare
21116 E : constant Entity_Id := Entity (Orig_Node);
21117 K : constant Entity_Kind := Ekind (E);
21119 begin
21120 if Is_Loop_Parameter (E) then
21121 return False;
21122 end if;
21124 return (K = E_Variable
21125 and then Nkind (Parent (E)) /= N_Exception_Handler)
21126 or else (K = E_Component
21127 and then not In_Protected_Function (E))
21128 or else (Present (Etype (E))
21129 and then Is_Access_Variable (Etype (E))
21130 and then Is_Dereferenced (N))
21131 or else K = E_Out_Parameter
21132 or else K = E_In_Out_Parameter
21133 or else K = E_Generic_In_Out_Parameter
21135 -- Current instance of type. If this is a protected type, check
21136 -- we are not within the body of one of its protected functions.
21138 or else (Is_Type (E)
21139 and then In_Open_Scopes (E)
21140 and then not In_Protected_Function (E))
21142 or else (Is_Incomplete_Or_Private_Type (E)
21143 and then In_Open_Scopes (Full_View (E)));
21144 end;
21146 else
21147 case Nkind (Orig_Node) is
21148 when N_Indexed_Component
21149 | N_Slice
21151 return Is_Variable_Prefix (Prefix (Orig_Node));
21153 when N_Selected_Component =>
21154 return Is_Variable (Selector_Name (Orig_Node))
21155 and then Is_Variable_Prefix (Prefix (Orig_Node));
21157 -- For an explicit dereference, the type of the prefix cannot
21158 -- be an access to constant or an access to subprogram.
21160 when N_Explicit_Dereference =>
21161 declare
21162 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
21163 begin
21164 return Is_Access_Type (Typ)
21165 and then not Is_Access_Constant (Root_Type (Typ))
21166 and then Ekind (Typ) /= E_Access_Subprogram_Type;
21167 end;
21169 -- Handle the case where 'Super is present - representing a view
21170 -- conversion.
21172 when N_Attribute_Reference =>
21173 if Attribute_Name (Orig_Node) = Name_Super then
21174 return Is_Variable (Prefix (Orig_Node));
21175 end if;
21177 return False;
21179 -- The type conversion is the case where we do not deal with the
21180 -- context dependent special case of an actual parameter. Thus
21181 -- the type conversion is only considered a variable for the
21182 -- purposes of this routine if the target type is tagged. However,
21183 -- a type conversion is considered to be a variable if it does not
21184 -- come from source (this deals for example with the conversions
21185 -- of expressions to their actual subtypes).
21187 when N_Type_Conversion =>
21188 return Is_Variable (Expression (Orig_Node))
21189 and then
21190 (not Comes_From_Source (Orig_Node)
21191 or else
21192 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
21193 and then
21194 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
21196 -- GNAT allows an unchecked type conversion as a variable. This
21197 -- only affects the generation of internal expanded code, since
21198 -- calls to instantiations of Unchecked_Conversion are never
21199 -- considered variables (since they are function calls).
21201 when N_Unchecked_Type_Conversion =>
21202 return Is_Variable (Expression (Orig_Node));
21204 when others =>
21205 return False;
21206 end case;
21207 end if;
21208 end Is_Variable;
21210 ------------------------
21211 -- Is_View_Conversion --
21212 ------------------------
21214 function Is_View_Conversion (N : Node_Id) return Boolean is
21215 begin
21216 if Nkind (N) = N_Type_Conversion
21217 and then Nkind (Unqual_Conv (N)) in N_Has_Etype
21218 then
21219 if Is_Tagged_Type (Etype (N))
21220 and then (Is_Tagged_Type (Etype (Unqual_Conv (N)))
21221 or else Is_Class_Wide_Equivalent_Type
21222 (Etype (Unqual_Conv (N))))
21223 then
21224 return True;
21226 elsif Is_Actual_Parameter (N)
21227 and then (Is_Actual_Out_Parameter (N)
21228 or else Is_Actual_In_Out_Parameter (N))
21229 then
21230 return True;
21231 end if;
21232 end if;
21234 return False;
21235 end Is_View_Conversion;
21237 ---------------------------
21238 -- Is_Visibly_Controlled --
21239 ---------------------------
21241 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
21242 Root : constant Entity_Id := Root_Type (T);
21243 begin
21244 return Chars (Scope (Root)) = Name_Finalization
21245 and then Chars (Scope (Scope (Root))) = Name_Ada
21246 and then Scope (Scope (Scope (Root))) = Standard_Standard;
21247 end Is_Visibly_Controlled;
21249 ----------------------------------------
21250 -- Is_Volatile_Full_Access_Object_Ref --
21251 ----------------------------------------
21253 function Is_Volatile_Full_Access_Object_Ref (N : Node_Id) return Boolean is
21254 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean;
21255 -- Determine whether arbitrary entity Id denotes an object that is
21256 -- Volatile_Full_Access.
21258 ----------------------------
21259 -- Is_VFA_Object_Entity --
21260 ----------------------------
21262 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean is
21263 begin
21264 return
21265 Is_Object (Id)
21266 and then (Is_Volatile_Full_Access (Id)
21267 or else
21268 Is_Volatile_Full_Access (Etype (Id)));
21269 end Is_VFA_Object_Entity;
21271 -- Start of processing for Is_Volatile_Full_Access_Object_Ref
21273 begin
21274 if Is_Entity_Name (N) then
21275 return Is_VFA_Object_Entity (Entity (N));
21277 elsif Is_Volatile_Full_Access (Etype (N)) then
21278 return True;
21280 elsif Nkind (N) = N_Selected_Component then
21281 return Is_Volatile_Full_Access (Entity (Selector_Name (N)));
21283 else
21284 return False;
21285 end if;
21286 end Is_Volatile_Full_Access_Object_Ref;
21288 --------------------------
21289 -- Is_Volatile_Function --
21290 --------------------------
21292 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
21293 begin
21294 pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function);
21296 -- A protected function is volatile
21298 if Nkind (Parent (Unit_Declaration_Node (Func_Id))) =
21299 N_Protected_Definition
21300 then
21301 return True;
21303 -- An instance of Ada.Unchecked_Conversion is a volatile function if
21304 -- either the source or the target are effectively volatile.
21306 elsif Is_Unchecked_Conversion_Instance (Func_Id)
21307 and then Has_Effectively_Volatile_Profile (Func_Id)
21308 then
21309 return True;
21311 -- A function with side-effects is volatile
21313 elsif Is_Function_With_Side_Effects (Func_Id) then
21314 return True;
21316 -- Otherwise the function is treated as volatile if it is subject to
21317 -- enabled pragma Volatile_Function.
21319 else
21320 return
21321 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
21322 end if;
21323 end Is_Volatile_Function;
21325 ----------------------------
21326 -- Is_Volatile_Object_Ref --
21327 ----------------------------
21329 function Is_Volatile_Object_Ref (N : Node_Id) return Boolean is
21330 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean;
21331 -- Determine whether arbitrary entity Id denotes an object that is
21332 -- Volatile.
21334 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean;
21335 -- Determine whether prefix P has volatile components. This requires
21336 -- the presence of a Volatile_Components aspect/pragma or that P be
21337 -- itself a volatile object as per RM C.6(8).
21339 ---------------------------------
21340 -- Is_Volatile_Object_Entity --
21341 ---------------------------------
21343 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean is
21344 begin
21345 return
21346 Is_Object (Id)
21347 and then (Is_Volatile (Id) or else Is_Volatile (Etype (Id)));
21348 end Is_Volatile_Object_Entity;
21350 ------------------------------------
21351 -- Prefix_Has_Volatile_Components --
21352 ------------------------------------
21354 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean is
21355 Typ : constant Entity_Id := Etype (P);
21357 begin
21358 if Is_Access_Type (Typ) then
21359 declare
21360 Dtyp : constant Entity_Id := Designated_Type (Typ);
21362 begin
21363 return Has_Volatile_Components (Dtyp)
21364 or else Is_Volatile (Dtyp);
21365 end;
21367 elsif Has_Volatile_Components (Typ) then
21368 return True;
21370 elsif Is_Entity_Name (P)
21371 and then Has_Volatile_Component (Entity (P))
21372 then
21373 return True;
21375 elsif Is_Volatile_Object_Ref (P) then
21376 return True;
21378 else
21379 return False;
21380 end if;
21381 end Prefix_Has_Volatile_Components;
21383 -- Start of processing for Is_Volatile_Object_Ref
21385 begin
21386 if Is_Entity_Name (N) then
21387 return Is_Volatile_Object_Entity (Entity (N));
21389 elsif Is_Volatile (Etype (N)) then
21390 return True;
21392 elsif Nkind (N) = N_Indexed_Component then
21393 return Prefix_Has_Volatile_Components (Prefix (N));
21395 elsif Nkind (N) = N_Selected_Component then
21396 return Prefix_Has_Volatile_Components (Prefix (N))
21397 or else Is_Volatile (Entity (Selector_Name (N)));
21399 else
21400 return False;
21401 end if;
21402 end Is_Volatile_Object_Ref;
21404 -----------------------------
21405 -- Iterate_Call_Parameters --
21406 -----------------------------
21408 procedure Iterate_Call_Parameters (Call : Node_Id) is
21409 Actual : Node_Id := First_Actual (Call);
21410 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
21412 begin
21413 while Present (Formal) and then Present (Actual) loop
21414 Handle_Parameter (Formal, Actual);
21416 Next_Formal (Formal);
21417 Next_Actual (Actual);
21418 end loop;
21420 pragma Assert (No (Formal));
21421 pragma Assert (No (Actual));
21422 end Iterate_Call_Parameters;
21424 --------------------------------
21425 -- Iterate_Interface_Ancestor --
21426 --------------------------------
21428 function Iterator_Interface_Ancestor (Typ : Entity_Id) return Entity_Id is
21429 begin
21430 if Has_Interfaces (Typ) then
21431 declare
21432 Iface_Elmt : Elmt_Id;
21433 Ifaces : Elist_Id;
21434 Root_Iface : Entity_Id;
21436 begin
21437 Collect_Interfaces (Typ, Ifaces);
21439 Iface_Elmt := First_Elmt (Ifaces);
21440 while Present (Iface_Elmt) loop
21441 Root_Iface := Root_Type (Node (Iface_Elmt));
21443 if Chars (Root_Iface)
21444 in Name_Forward_Iterator | Name_Reversible_Iterator
21445 and then In_Predefined_Unit (Root_Iface)
21446 then
21447 return Root_Iface;
21448 end if;
21450 Next_Elmt (Iface_Elmt);
21451 end loop;
21452 end;
21453 end if;
21455 return Empty;
21456 end Iterator_Interface_Ancestor;
21458 -------------------------
21459 -- Kill_Current_Values --
21460 -------------------------
21462 procedure Kill_Current_Values
21463 (Ent : Entity_Id;
21464 Last_Assignment_Only : Boolean := False)
21466 begin
21467 if Is_Assignable (Ent) then
21468 Set_Last_Assignment (Ent, Empty);
21469 end if;
21471 if Is_Object (Ent) then
21472 if not Last_Assignment_Only then
21473 Kill_Checks (Ent);
21474 Set_Current_Value (Ent, Empty);
21476 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
21477 -- for a constant. Once the constant is elaborated, its value is
21478 -- not changed, therefore the associated flags that describe the
21479 -- value should not be modified either.
21481 if Ekind (Ent) = E_Constant then
21482 null;
21484 -- Non-constant entities
21486 else
21487 if not Can_Never_Be_Null (Ent) then
21488 Set_Is_Known_Non_Null (Ent, False);
21489 end if;
21491 Set_Is_Known_Null (Ent, False);
21493 -- Reset the Is_Known_Valid flag unless the type is always
21494 -- valid. This does not apply to a loop parameter because its
21495 -- bounds are defined by the loop header and therefore always
21496 -- valid.
21498 if not Is_Known_Valid (Etype (Ent))
21499 and then Ekind (Ent) /= E_Loop_Parameter
21500 then
21501 Set_Is_Known_Valid (Ent, False);
21502 end if;
21503 end if;
21504 end if;
21505 end if;
21506 end Kill_Current_Values;
21508 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
21509 S : Entity_Id;
21511 begin
21512 -- Kill all saved checks, a special case of killing saved values
21514 if not Last_Assignment_Only then
21515 Kill_All_Checks;
21516 end if;
21518 -- Loop through relevant scopes, which includes the current scope and
21519 -- any parent scopes if the current scope is a block or a package.
21521 S := Current_Scope;
21522 Scope_Loop : loop
21524 -- Clear current values of all entities in current scope
21526 declare
21527 Ent : Entity_Id;
21528 begin
21529 Ent := First_Entity (S);
21530 while Present (Ent) loop
21531 Kill_Current_Values (Ent, Last_Assignment_Only);
21532 Next_Entity (Ent);
21533 end loop;
21534 end;
21536 -- If this is a not a subprogram, deal with parents
21538 if not Is_Subprogram (S) then
21539 S := Scope (S);
21540 exit Scope_Loop when S = Standard_Standard;
21541 else
21542 exit Scope_Loop;
21543 end if;
21544 end loop Scope_Loop;
21545 end Kill_Current_Values;
21547 --------------------------
21548 -- Kill_Size_Check_Code --
21549 --------------------------
21551 procedure Kill_Size_Check_Code (E : Entity_Id) is
21552 begin
21553 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
21554 and then Present (Size_Check_Code (E))
21555 then
21556 Remove (Size_Check_Code (E));
21557 Set_Size_Check_Code (E, Empty);
21558 end if;
21559 end Kill_Size_Check_Code;
21561 --------------------
21562 -- Known_Non_Null --
21563 --------------------
21565 function Known_Non_Null (N : Node_Id) return Boolean is
21566 Status : constant Null_Status_Kind := Null_Status (N);
21568 Id : Entity_Id;
21569 Op : Node_Kind;
21570 Val : Node_Id;
21572 begin
21573 -- The expression yields a non-null value ignoring simple flow analysis
21575 if Status = Is_Non_Null then
21576 return True;
21578 -- Otherwise check whether N is a reference to an entity that appears
21579 -- within a conditional construct.
21581 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21583 -- First check if we are in decisive conditional
21585 Get_Current_Value_Condition (N, Op, Val);
21587 if Known_Null (Val) then
21588 if Op = N_Op_Eq then
21589 return False;
21590 elsif Op = N_Op_Ne then
21591 return True;
21592 end if;
21593 end if;
21595 -- If OK to do replacement, test Is_Known_Non_Null flag
21597 Id := Entity (N);
21599 if OK_To_Do_Constant_Replacement (Id) then
21600 return Is_Known_Non_Null (Id);
21601 end if;
21602 end if;
21604 -- Otherwise it is not possible to determine whether N yields a non-null
21605 -- value.
21607 return False;
21608 end Known_Non_Null;
21610 ----------------
21611 -- Known_Null --
21612 ----------------
21614 function Known_Null (N : Node_Id) return Boolean is
21615 Status : constant Null_Status_Kind := Null_Status (N);
21617 Id : Entity_Id;
21618 Op : Node_Kind;
21619 Val : Node_Id;
21621 begin
21622 -- The expression yields a null value ignoring simple flow analysis
21624 if Status = Is_Null then
21625 return True;
21627 -- Otherwise check whether N is a reference to an entity that appears
21628 -- within a conditional construct.
21630 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21632 -- First check if we are in decisive conditional
21634 Get_Current_Value_Condition (N, Op, Val);
21636 -- If Get_Current_Value_Condition were to return Val = N, then the
21637 -- recursion below could be infinite.
21639 if Val = N then
21640 raise Program_Error;
21641 end if;
21643 if Known_Null (Val) then
21644 if Op = N_Op_Eq then
21645 return True;
21646 elsif Op = N_Op_Ne then
21647 return False;
21648 end if;
21649 end if;
21651 -- If OK to do replacement, test Is_Known_Null flag
21653 Id := Entity (N);
21655 if OK_To_Do_Constant_Replacement (Id) then
21656 return Is_Known_Null (Id);
21657 end if;
21658 end if;
21660 -- Otherwise it is not possible to determine whether N yields a null
21661 -- value.
21663 return False;
21664 end Known_Null;
21666 ---------------------------
21667 -- Last_Source_Statement --
21668 ---------------------------
21670 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
21671 N : Node_Id;
21673 begin
21674 N := Last (Statements (HSS));
21675 while Present (N) loop
21676 exit when Comes_From_Source (N);
21677 Prev (N);
21678 end loop;
21680 return N;
21681 end Last_Source_Statement;
21683 -----------------------
21684 -- Mark_Coextensions --
21685 -----------------------
21687 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
21688 Is_Dynamic : Boolean;
21689 -- Indicates whether the context causes nested coextensions to be
21690 -- dynamic or static
21692 function Mark_Allocator (N : Node_Id) return Traverse_Result;
21693 -- Recognize an allocator node and label it as a dynamic coextension
21695 --------------------
21696 -- Mark_Allocator --
21697 --------------------
21699 function Mark_Allocator (N : Node_Id) return Traverse_Result is
21700 begin
21701 if Nkind (N) = N_Allocator then
21702 if Is_Dynamic then
21703 Set_Is_Static_Coextension (N, False);
21704 Set_Is_Dynamic_Coextension (N);
21706 -- If the allocator expression is potentially dynamic, it may
21707 -- be expanded out of order and require dynamic allocation
21708 -- anyway, so we treat the coextension itself as dynamic.
21709 -- Potential optimization ???
21711 elsif Nkind (Expression (N)) = N_Qualified_Expression
21712 and then Nkind (Expression (Expression (N))) = N_Op_Concat
21713 then
21714 Set_Is_Static_Coextension (N, False);
21715 Set_Is_Dynamic_Coextension (N);
21716 else
21717 Set_Is_Dynamic_Coextension (N, False);
21718 Set_Is_Static_Coextension (N);
21719 end if;
21720 end if;
21722 return OK;
21723 end Mark_Allocator;
21725 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
21727 -- Start of processing for Mark_Coextensions
21729 begin
21730 -- An allocator that appears on the right-hand side of an assignment is
21731 -- treated as a potentially dynamic coextension when the right-hand side
21732 -- is an allocator or a qualified expression.
21734 -- Obj := new ...'(new Coextension ...);
21736 if Nkind (Context_Nod) = N_Assignment_Statement then
21737 Is_Dynamic := Nkind (Expression (Context_Nod)) in
21738 N_Allocator | N_Qualified_Expression;
21740 -- An allocator that appears within the expression of a simple return
21741 -- statement is treated as a potentially dynamic coextension when the
21742 -- expression is either aggregate, allocator, or qualified expression.
21744 -- return (new Coextension ...);
21745 -- return new ...'(new Coextension ...);
21747 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
21748 Is_Dynamic := Nkind (Expression (Context_Nod)) in
21749 N_Aggregate | N_Allocator | N_Qualified_Expression;
21751 -- An alloctor that appears within the initialization expression of an
21752 -- object declaration is considered a potentially dynamic coextension
21753 -- when the initialization expression is an allocator or a qualified
21754 -- expression.
21756 -- Obj : ... := new ...'(new Coextension ...);
21758 -- A similar case arises when the object declaration is part of an
21759 -- extended return statement.
21761 -- return Obj : ... := new ...'(new Coextension ...);
21762 -- return Obj : ... := (new Coextension ...);
21764 elsif Nkind (Context_Nod) = N_Object_Declaration then
21765 Is_Dynamic := Nkind (Root_Nod) in N_Allocator | N_Qualified_Expression
21766 or else Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
21768 -- This routine should not be called with constructs that cannot contain
21769 -- coextensions.
21771 else
21772 raise Program_Error;
21773 end if;
21775 Mark_Allocators (Root_Nod);
21776 end Mark_Coextensions;
21778 ---------------------------------
21779 -- Mark_Elaboration_Attributes --
21780 ---------------------------------
21782 procedure Mark_Elaboration_Attributes
21783 (N_Id : Node_Or_Entity_Id;
21784 Checks : Boolean := False;
21785 Level : Boolean := False;
21786 Modes : Boolean := False;
21787 Warnings : Boolean := False)
21789 function Elaboration_Checks_OK
21790 (Target_Id : Entity_Id;
21791 Context_Id : Entity_Id) return Boolean;
21792 -- Determine whether elaboration checks are enabled for target Target_Id
21793 -- which resides within context Context_Id.
21795 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
21796 -- Preserve relevant attributes of the context in arbitrary entity Id
21798 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
21799 -- Preserve relevant attributes of the context in arbitrary node N
21801 ---------------------------
21802 -- Elaboration_Checks_OK --
21803 ---------------------------
21805 function Elaboration_Checks_OK
21806 (Target_Id : Entity_Id;
21807 Context_Id : Entity_Id) return Boolean
21809 Encl_Scop : Entity_Id;
21811 begin
21812 -- Elaboration checks are suppressed for the target
21814 if Elaboration_Checks_Suppressed (Target_Id) then
21815 return False;
21816 end if;
21818 -- Otherwise elaboration checks are OK for the target, but may be
21819 -- suppressed for the context where the target is declared.
21821 Encl_Scop := Context_Id;
21822 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
21823 if Elaboration_Checks_Suppressed (Encl_Scop) then
21824 return False;
21825 end if;
21827 Encl_Scop := Scope (Encl_Scop);
21828 end loop;
21830 -- Neither the target nor its declarative context have elaboration
21831 -- checks suppressed.
21833 return True;
21834 end Elaboration_Checks_OK;
21836 ------------------------------------
21837 -- Mark_Elaboration_Attributes_Id --
21838 ------------------------------------
21840 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
21841 begin
21842 -- Mark the status of elaboration checks in effect. Do not reset the
21843 -- status in case the entity is reanalyzed with checks suppressed.
21845 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
21846 Set_Is_Elaboration_Checks_OK_Id (Id,
21847 Elaboration_Checks_OK
21848 (Target_Id => Id,
21849 Context_Id => Scope (Id)));
21850 end if;
21852 -- Mark the status of elaboration warnings in effect. Do not reset
21853 -- the status in case the entity is reanalyzed with warnings off.
21855 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
21856 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
21857 end if;
21858 end Mark_Elaboration_Attributes_Id;
21860 --------------------------------------
21861 -- Mark_Elaboration_Attributes_Node --
21862 --------------------------------------
21864 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
21865 function Extract_Name (N : Node_Id) return Node_Id;
21866 -- Obtain the Name attribute of call or instantiation N
21868 ------------------
21869 -- Extract_Name --
21870 ------------------
21872 function Extract_Name (N : Node_Id) return Node_Id is
21873 Nam : Node_Id;
21875 begin
21876 Nam := Name (N);
21878 -- A call to an entry family appears in indexed form
21880 if Nkind (Nam) = N_Indexed_Component then
21881 Nam := Prefix (Nam);
21882 end if;
21884 -- The name may also appear in qualified form
21886 if Nkind (Nam) = N_Selected_Component then
21887 Nam := Selector_Name (Nam);
21888 end if;
21890 return Nam;
21891 end Extract_Name;
21893 -- Local variables
21895 Context_Id : Entity_Id;
21896 Nam : Node_Id;
21898 -- Start of processing for Mark_Elaboration_Attributes_Node
21900 begin
21901 -- Mark the status of elaboration checks in effect. Do not reset the
21902 -- status in case the node is reanalyzed with checks suppressed.
21904 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
21906 -- Assignments, attribute references, and variable references do
21907 -- not have a "declarative" context.
21909 Context_Id := Empty;
21911 -- The status of elaboration checks for calls and instantiations
21912 -- depends on the most recent pragma Suppress/Unsuppress, as well
21913 -- as the suppression status of the context where the target is
21914 -- defined.
21916 -- package Pack is
21917 -- function Func ...;
21918 -- end Pack;
21920 -- with Pack;
21921 -- procedure Main is
21922 -- pragma Suppress (Elaboration_Checks, Pack);
21923 -- X : ... := Pack.Func;
21924 -- ...
21926 -- In the example above, the call to Func has elaboration checks
21927 -- enabled because there is no active general purpose suppression
21928 -- pragma, however the elaboration checks of Pack are explicitly
21929 -- suppressed. As a result the elaboration checks of the call must
21930 -- be disabled in order to preserve this dependency.
21932 if Nkind (N) in N_Entry_Call_Statement
21933 | N_Function_Call
21934 | N_Function_Instantiation
21935 | N_Package_Instantiation
21936 | N_Procedure_Call_Statement
21937 | N_Procedure_Instantiation
21938 then
21939 Nam := Extract_Name (N);
21941 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
21942 Context_Id := Scope (Entity (Nam));
21943 end if;
21944 end if;
21946 Set_Is_Elaboration_Checks_OK_Node (N,
21947 Elaboration_Checks_OK
21948 (Target_Id => Empty,
21949 Context_Id => Context_Id));
21950 end if;
21952 -- Mark the enclosing level of the node. Do not reset the status in
21953 -- case the node is relocated and reanalyzed.
21955 if Level and then not Is_Declaration_Level_Node (N) then
21956 Set_Is_Declaration_Level_Node (N,
21957 Find_Enclosing_Level (N) = Declaration_Level);
21958 end if;
21960 -- Mark the Ghost and SPARK mode in effect
21962 if Modes then
21963 if Ghost_Mode = Ignore then
21964 Set_Is_Ignored_Ghost_Node (N);
21965 end if;
21967 if SPARK_Mode = On then
21968 Set_Is_SPARK_Mode_On_Node (N);
21969 end if;
21970 end if;
21972 -- Mark the status of elaboration warnings in effect. Do not reset
21973 -- the status in case the node is reanalyzed with warnings off.
21975 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
21976 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
21977 end if;
21978 end Mark_Elaboration_Attributes_Node;
21980 -- Start of processing for Mark_Elaboration_Attributes
21982 begin
21983 -- Do not capture any elaboration-related attributes when switch -gnatH
21984 -- (legacy elaboration checking mode enabled) is in effect because the
21985 -- attributes are useless to the legacy model.
21987 if Legacy_Elaboration_Checks then
21988 return;
21989 end if;
21991 if Nkind (N_Id) in N_Entity then
21992 Mark_Elaboration_Attributes_Id (N_Id);
21993 else
21994 Mark_Elaboration_Attributes_Node (N_Id);
21995 end if;
21996 end Mark_Elaboration_Attributes;
21998 ----------------------------------------
21999 -- Mark_Save_Invocation_Graph_Of_Body --
22000 ----------------------------------------
22002 procedure Mark_Save_Invocation_Graph_Of_Body is
22003 Main : constant Node_Id := Cunit (Main_Unit);
22004 Main_Unit : constant Node_Id := Unit (Main);
22005 Aux_Id : Entity_Id;
22007 begin
22008 Set_Save_Invocation_Graph_Of_Body (Main);
22010 -- Assume that the main unit does not have a complimentary unit
22012 Aux_Id := Empty;
22014 -- Obtain the complimentary unit of the main unit
22016 if Nkind (Main_Unit) in N_Generic_Package_Declaration
22017 | N_Generic_Subprogram_Declaration
22018 | N_Package_Declaration
22019 | N_Subprogram_Declaration
22020 then
22021 Aux_Id := Corresponding_Body (Main_Unit);
22023 elsif Nkind (Main_Unit) in N_Package_Body
22024 | N_Subprogram_Body
22025 | N_Subprogram_Renaming_Declaration
22026 then
22027 Aux_Id := Corresponding_Spec (Main_Unit);
22028 end if;
22030 if Present (Aux_Id) then
22031 Set_Save_Invocation_Graph_Of_Body
22032 (Parent (Unit_Declaration_Node (Aux_Id)));
22033 end if;
22034 end Mark_Save_Invocation_Graph_Of_Body;
22036 ----------------------------------
22037 -- Matching_Static_Array_Bounds --
22038 ----------------------------------
22040 function Matching_Static_Array_Bounds
22041 (L_Typ : Node_Id;
22042 R_Typ : Node_Id) return Boolean
22044 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
22045 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
22047 L_Index : Node_Id := Empty; -- init to ...
22048 R_Index : Node_Id := Empty; -- ...avoid warnings
22049 L_Low : Node_Id;
22050 L_High : Node_Id;
22051 L_Len : Uint;
22052 R_Low : Node_Id;
22053 R_High : Node_Id;
22054 R_Len : Uint;
22056 begin
22057 if L_Ndims /= R_Ndims then
22058 return False;
22059 end if;
22061 -- Unconstrained types do not have static bounds
22063 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
22064 return False;
22065 end if;
22067 -- First treat specially the first dimension, as the lower bound and
22068 -- length of string literals are not stored like those of arrays.
22070 if Ekind (L_Typ) = E_String_Literal_Subtype then
22071 L_Low := String_Literal_Low_Bound (L_Typ);
22072 L_Len := String_Literal_Length (L_Typ);
22073 else
22074 L_Index := First_Index (L_Typ);
22075 Get_Index_Bounds (L_Index, L_Low, L_High);
22077 if Is_OK_Static_Expression (L_Low)
22078 and then
22079 Is_OK_Static_Expression (L_High)
22080 then
22081 if Expr_Value (L_High) < Expr_Value (L_Low) then
22082 L_Len := Uint_0;
22083 else
22084 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
22085 end if;
22086 else
22087 return False;
22088 end if;
22089 end if;
22091 if Ekind (R_Typ) = E_String_Literal_Subtype then
22092 R_Low := String_Literal_Low_Bound (R_Typ);
22093 R_Len := String_Literal_Length (R_Typ);
22094 else
22095 R_Index := First_Index (R_Typ);
22096 Get_Index_Bounds (R_Index, R_Low, R_High);
22098 if Is_OK_Static_Expression (R_Low)
22099 and then
22100 Is_OK_Static_Expression (R_High)
22101 then
22102 if Expr_Value (R_High) < Expr_Value (R_Low) then
22103 R_Len := Uint_0;
22104 else
22105 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
22106 end if;
22107 else
22108 return False;
22109 end if;
22110 end if;
22112 if (Is_OK_Static_Expression (L_Low)
22113 and then
22114 Is_OK_Static_Expression (R_Low))
22115 and then Expr_Value (L_Low) = Expr_Value (R_Low)
22116 and then L_Len = R_Len
22117 then
22118 null;
22119 else
22120 return False;
22121 end if;
22123 -- Then treat all other dimensions
22125 for Indx in 2 .. L_Ndims loop
22126 Next (L_Index);
22127 Next (R_Index);
22129 Get_Index_Bounds (L_Index, L_Low, L_High);
22130 Get_Index_Bounds (R_Index, R_Low, R_High);
22132 if (Is_OK_Static_Expression (L_Low) and then
22133 Is_OK_Static_Expression (L_High) and then
22134 Is_OK_Static_Expression (R_Low) and then
22135 Is_OK_Static_Expression (R_High))
22136 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
22137 and then
22138 Expr_Value (L_High) = Expr_Value (R_High))
22139 then
22140 null;
22141 else
22142 return False;
22143 end if;
22144 end loop;
22146 -- If we fall through the loop, all indexes matched
22148 return True;
22149 end Matching_Static_Array_Bounds;
22151 -----------------
22152 -- Might_Raise --
22153 -----------------
22155 function Might_Raise (N : Node_Id) return Boolean is
22156 Result : Boolean := False;
22158 function Process (N : Node_Id) return Traverse_Result;
22159 -- Set Result to True if we find something that could raise an exception
22161 -------------
22162 -- Process --
22163 -------------
22165 function Process (N : Node_Id) return Traverse_Result is
22166 begin
22167 if Nkind (N) in N_Procedure_Call_Statement
22168 | N_Function_Call
22169 | N_Raise_Statement
22170 | N_Raise_xxx_Error
22171 | N_Raise_Expression
22172 then
22173 Result := True;
22174 return Abandon;
22175 else
22176 return OK;
22177 end if;
22178 end Process;
22180 procedure Set_Result is new Traverse_Proc (Process);
22182 -- Start of processing for Might_Raise
22184 begin
22185 -- False if exceptions can't be propagated
22187 if No_Exception_Handlers_Set then
22188 return False;
22189 end if;
22191 -- If the checks handled by the back end are not disabled, we cannot
22192 -- ensure that no exception will be raised.
22194 if not Access_Checks_Suppressed (Empty)
22195 or else not Discriminant_Checks_Suppressed (Empty)
22196 or else not Range_Checks_Suppressed (Empty)
22197 or else not Index_Checks_Suppressed (Empty)
22198 or else Opt.Stack_Checking_Enabled
22199 then
22200 return True;
22201 end if;
22203 Set_Result (N);
22204 return Result;
22205 end Might_Raise;
22207 ----------------------------------------
22208 -- Nearest_Class_Condition_Subprogram --
22209 ----------------------------------------
22211 function Nearest_Class_Condition_Subprogram
22212 (Kind : Condition_Kind;
22213 Spec_Id : Entity_Id) return Entity_Id
22215 Subp_Id : constant Entity_Id := Ultimate_Alias (Spec_Id);
22217 begin
22218 -- Prevent cascaded errors
22220 if not Is_Dispatching_Operation (Subp_Id) then
22221 return Empty;
22223 -- No need to search if this subprogram has class-wide postconditions
22225 elsif Present (Class_Condition (Kind, Subp_Id)) then
22226 return Subp_Id;
22227 end if;
22229 -- Process the contracts of inherited subprograms, looking for
22230 -- class-wide pre/postconditions.
22232 declare
22233 Subps : constant Subprogram_List := Inherited_Subprograms (Subp_Id);
22234 Subp_Id : Entity_Id;
22236 begin
22237 for Index in Subps'Range loop
22238 Subp_Id := Subps (Index);
22240 if Present (Alias (Subp_Id)) then
22241 Subp_Id := Ultimate_Alias (Subp_Id);
22242 end if;
22244 -- Wrappers of class-wide pre/postconditions reference the
22245 -- parent primitive that has the inherited contract.
22247 if Is_Wrapper (Subp_Id)
22248 and then Present (LSP_Subprogram (Subp_Id))
22249 then
22250 Subp_Id := LSP_Subprogram (Subp_Id);
22251 end if;
22253 if Present (Class_Condition (Kind, Subp_Id)) then
22254 return Subp_Id;
22255 end if;
22256 end loop;
22257 end;
22259 return Empty;
22260 end Nearest_Class_Condition_Subprogram;
22262 --------------------------------
22263 -- Nearest_Enclosing_Instance --
22264 --------------------------------
22266 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
22267 Inst : Entity_Id;
22269 begin
22270 Inst := Scope (E);
22271 while Present (Inst) and then Inst /= Standard_Standard loop
22272 if Is_Generic_Instance (Inst) then
22273 return Inst;
22274 end if;
22276 Inst := Scope (Inst);
22277 end loop;
22279 return Empty;
22280 end Nearest_Enclosing_Instance;
22282 ------------------------
22283 -- Needs_Finalization --
22284 ------------------------
22286 function Needs_Finalization (Typ : Entity_Id) return Boolean is
22287 function Has_Some_Controlled_Component
22288 (Input_Typ : Entity_Id) return Boolean;
22289 -- Determine whether type Input_Typ has at least one controlled
22290 -- component.
22292 -----------------------------------
22293 -- Has_Some_Controlled_Component --
22294 -----------------------------------
22296 function Has_Some_Controlled_Component
22297 (Input_Typ : Entity_Id) return Boolean
22299 Comp : Entity_Id;
22301 begin
22302 -- When a type is already frozen and has at least one controlled
22303 -- component, or is manually decorated, it is sufficient to inspect
22304 -- flag Has_Controlled_Component.
22306 if Has_Controlled_Component (Input_Typ) then
22307 return True;
22309 -- Otherwise inspect the internals of the type
22311 elsif not Is_Frozen (Input_Typ) then
22312 if Is_Array_Type (Input_Typ) then
22313 return Needs_Finalization (Component_Type (Input_Typ));
22315 elsif Is_Record_Type (Input_Typ) then
22316 Comp := First_Component (Input_Typ);
22317 while Present (Comp) loop
22318 -- Skip _Parent component like Record_Type_Definition
22320 if Chars (Comp) /= Name_uParent
22321 and then Needs_Finalization (Etype (Comp))
22322 then
22323 return True;
22324 end if;
22326 Next_Component (Comp);
22327 end loop;
22328 end if;
22329 end if;
22331 return False;
22332 end Has_Some_Controlled_Component;
22334 -- Start of processing for Needs_Finalization
22336 begin
22337 -- Certain run-time configurations and targets do not provide support
22338 -- for controlled types.
22340 if Restriction_Active (No_Finalization) then
22341 return False;
22343 -- C++ types are not considered controlled. It is assumed that the non-
22344 -- Ada side will handle their clean up.
22346 elsif Convention (Typ) = Convention_CPP then
22347 return False;
22349 -- Class-wide types are treated as controlled because derivations from
22350 -- the root type may introduce controlled components.
22352 elsif Is_Class_Wide_Type (Typ) then
22353 return True;
22355 -- Concurrent types are controlled as long as their corresponding record
22356 -- is controlled.
22358 elsif Is_Concurrent_Type (Typ)
22359 and then Present (Corresponding_Record_Type (Typ))
22360 and then Needs_Finalization (Corresponding_Record_Type (Typ))
22361 then
22362 return True;
22364 -- Otherwise the type is controlled when it is either derived from type
22365 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
22366 -- contains at least one controlled component.
22368 else
22369 return
22370 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
22371 end if;
22372 end Needs_Finalization;
22374 ----------------------
22375 -- Needs_One_Actual --
22376 ----------------------
22378 function Needs_One_Actual (E : Entity_Id) return Boolean is
22379 Formal : Entity_Id;
22381 begin
22382 -- Ada 2005 or later, and formals present. The first formal must be
22383 -- of a type that supports prefix notation: a controlling argument,
22384 -- a class-wide type, or an access to such.
22386 if Ada_Version >= Ada_2005
22387 and then Present (First_Formal (E))
22388 and then No (Default_Value (First_Formal (E)))
22389 and then
22390 (Is_Controlling_Formal (First_Formal (E))
22391 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
22392 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
22393 then
22394 Formal := Next_Formal (First_Formal (E));
22395 while Present (Formal) loop
22396 if No (Default_Value (Formal)) then
22397 return False;
22398 end if;
22400 Next_Formal (Formal);
22401 end loop;
22403 return True;
22405 -- Ada 83/95 or no formals
22407 else
22408 return False;
22409 end if;
22410 end Needs_One_Actual;
22412 ----------------------------
22413 -- Needs_Secondary_Stack --
22414 ----------------------------
22416 function Needs_Secondary_Stack (Id : Entity_Id) return Boolean is
22417 pragma Assert (if Present (Id) then Ekind (Id) in E_Void | Type_Kind);
22419 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
22420 -- Called for untagged record and protected types. Return True if the
22421 -- size of function results is known in the caller for Typ.
22423 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
22424 -- Returns True if Typ is a nonlimited record with defaulted
22425 -- discriminants whose max size makes it unsuitable for allocating on
22426 -- the primary stack.
22428 ------------------------------
22429 -- Caller_Known_Size_Record --
22430 ------------------------------
22432 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
22433 pragma Assert (if Present (Typ) then Typ = Underlying_Type (Typ));
22435 function Depends_On_Discriminant (Typ : Entity_Id) return Boolean;
22436 -- Called for untagged record and protected types. Return True if Typ
22437 -- depends on discriminants, either directly when it is unconstrained
22438 -- or indirectly when it is constrained by uplevel discriminants.
22440 -----------------------------
22441 -- Depends_On_Discriminant --
22442 -----------------------------
22444 function Depends_On_Discriminant (Typ : Entity_Id) return Boolean is
22445 Cons : Elmt_Id;
22447 begin
22448 if Has_Discriminants (Typ) then
22449 if not Is_Constrained (Typ) then
22450 return True;
22452 else
22453 Cons := First_Elmt (Discriminant_Constraint (Typ));
22454 while Present (Cons) loop
22455 if Nkind (Node (Cons)) = N_Identifier
22456 and then Ekind (Entity (Node (Cons))) = E_Discriminant
22457 then
22458 return True;
22459 end if;
22461 Next_Elmt (Cons);
22462 end loop;
22463 end if;
22464 end if;
22466 return False;
22467 end Depends_On_Discriminant;
22469 -- Start of processing for Caller_Known_Size_Record
22471 begin
22472 -- This is a protected type without Corresponding_Record_Type set,
22473 -- typically because expansion is disabled. The safe thing to do is
22474 -- to return True, so Needs_Secondary_Stack returns False.
22476 if No (Typ) then
22477 return True;
22478 end if;
22480 -- If either size is specified for the type, then it's known in the
22481 -- caller in particular. Note that, even if the clause is confirming,
22482 -- this does not change the outcome since the size was already known.
22484 if Has_Size_Clause (First_Subtype (Typ))
22485 or else Has_Object_Size_Clause (First_Subtype (Typ))
22486 then
22487 return True;
22488 end if;
22490 -- First see if we have a variant part and return False if it depends
22491 -- on discriminants.
22493 if Has_Variant_Part (Typ) and then Depends_On_Discriminant (Typ) then
22494 return False;
22495 end if;
22497 -- Then loop over components and return False if their subtype has a
22498 -- caller-unknown size, possibly recursively.
22500 -- ??? This is overly conservative, an array could be nested inside
22501 -- some other record that is constrained by nondiscriminants. That
22502 -- is, the recursive calls are too conservative.
22504 declare
22505 Comp : Entity_Id;
22507 begin
22508 Comp := First_Component (Typ);
22509 while Present (Comp) loop
22510 declare
22511 Comp_Type : constant Entity_Id :=
22512 Underlying_Type (Etype (Comp));
22514 begin
22515 if Is_Record_Type (Comp_Type) then
22516 if not Caller_Known_Size_Record (Comp_Type) then
22517 return False;
22518 end if;
22520 elsif Is_Protected_Type (Comp_Type) then
22521 if not Caller_Known_Size_Record
22522 (Corresponding_Record_Type (Comp_Type))
22523 then
22524 return False;
22525 end if;
22527 elsif Is_Array_Type (Comp_Type) then
22528 if Size_Depends_On_Discriminant (Comp_Type) then
22529 return False;
22530 end if;
22531 end if;
22532 end;
22534 Next_Component (Comp);
22535 end loop;
22536 end;
22538 return True;
22539 end Caller_Known_Size_Record;
22541 ------------------------------
22542 -- Large_Max_Size_Mutable --
22543 ------------------------------
22545 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
22546 pragma Assert (Typ = Underlying_Type (Typ));
22548 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
22549 -- Returns true if the discrete type T has a large range
22551 ----------------------------
22552 -- Is_Large_Discrete_Type --
22553 ----------------------------
22555 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
22556 Threshold : constant Int := 16;
22557 -- Arbitrary threshold above which we consider it "large". We want
22558 -- a fairly large threshold, because these large types really
22559 -- shouldn't have default discriminants in the first place, in
22560 -- most cases.
22562 begin
22563 return UI_To_Int (RM_Size (T)) > Threshold;
22564 end Is_Large_Discrete_Type;
22566 -- Start of processing for Large_Max_Size_Mutable
22568 begin
22569 if Is_Record_Type (Typ)
22570 and then not Is_Inherently_Limited_Type (Typ)
22571 and then Has_Defaulted_Discriminants (Typ)
22572 then
22573 -- Loop through the components, looking for an array whose upper
22574 -- bound(s) depends on discriminants, where both the subtype of
22575 -- the discriminant and the index subtype are too large.
22577 declare
22578 Comp : Entity_Id;
22580 begin
22581 Comp := First_Component (Typ);
22582 while Present (Comp) loop
22583 declare
22584 Comp_Type : constant Entity_Id :=
22585 Underlying_Type (Etype (Comp));
22587 Hi : Node_Id;
22588 Indx : Node_Id;
22589 Ityp : Entity_Id;
22591 begin
22592 if Present (Comp_Type)
22593 and then Is_Array_Type (Comp_Type)
22594 then
22595 Indx := First_Index (Comp_Type);
22597 while Present (Indx) loop
22598 Ityp := Etype (Indx);
22599 Hi := Type_High_Bound (Ityp);
22601 if Nkind (Hi) = N_Identifier
22602 and then Ekind (Entity (Hi)) = E_Discriminant
22603 and then Is_Large_Discrete_Type (Ityp)
22604 and then Is_Large_Discrete_Type
22605 (Etype (Entity (Hi)))
22606 then
22607 return True;
22608 end if;
22610 Next_Index (Indx);
22611 end loop;
22612 end if;
22613 end;
22615 Next_Component (Comp);
22616 end loop;
22617 end;
22618 end if;
22620 return False;
22621 end Large_Max_Size_Mutable;
22623 -- Local declarations
22625 Typ : constant Entity_Id := Underlying_Type (Id);
22627 -- Start of processing for Needs_Secondary_Stack
22629 begin
22630 -- This is a private type which is not completed yet. This can only
22631 -- happen in a default expression (of a formal parameter or of a
22632 -- record component). The safe thing to do is to return False.
22634 if No (Typ) then
22635 return False;
22636 end if;
22638 -- Do not expand transient scope for non-existent procedure return or
22639 -- string literal types.
22641 if Typ = Standard_Void_Type
22642 or else Ekind (Typ) = E_String_Literal_Subtype
22643 then
22644 return False;
22646 -- If Typ is a generic formal incomplete type, then we want to look at
22647 -- the actual type.
22649 elsif Ekind (Typ) = E_Record_Subtype
22650 and then Present (Cloned_Subtype (Typ))
22651 then
22652 return Needs_Secondary_Stack (Cloned_Subtype (Typ));
22654 -- Class-wide types obviously have an unknown size. For specific tagged
22655 -- types, if a call returning one of them is dispatching on result, and
22656 -- this type is not returned on the secondary stack, then the call goes
22657 -- through a thunk that only moves the result from the primary onto the
22658 -- secondary stack, because the computation of the size of the result is
22659 -- possible but complex from the outside.
22661 elsif Is_Class_Wide_Type (Typ) then
22662 return True;
22664 -- If the return slot of the back end cannot be accessed, then there
22665 -- is no way to call Adjust at the right time for the return object if
22666 -- the type needs finalization, so the return object must be allocated
22667 -- on the secondary stack.
22669 elsif not Back_End_Return_Slot and then Needs_Finalization (Typ) then
22670 return True;
22672 -- Definite subtypes have a known size. This includes all elementary
22673 -- types. Tasks have a known size even if they have discriminants, so
22674 -- we return False here, with one exception:
22675 -- For a type like:
22676 -- type T (Last : Natural := 0) is
22677 -- X : String (1 .. Last);
22678 -- end record;
22679 -- we return True. That's because for "P(F(...));", where F returns T,
22680 -- we don't know the size of the result at the call site, so if we
22681 -- allocated it on the primary stack, we would have to allocate the
22682 -- maximum size, which is way too big.
22684 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
22685 return Large_Max_Size_Mutable (Typ);
22687 -- Indefinite (discriminated) record type
22689 elsif Is_Record_Type (Typ) then
22690 return not Caller_Known_Size_Record (Typ);
22692 -- Indefinite (discriminated) protected type
22694 elsif Is_Protected_Type (Typ) then
22695 return not Caller_Known_Size_Record (Corresponding_Record_Type (Typ));
22697 -- Unconstrained array type
22699 else
22700 pragma Assert (Is_Array_Type (Typ) and then not Is_Constrained (Typ));
22701 return True;
22702 end if;
22703 end Needs_Secondary_Stack;
22705 ---------------------------------
22706 -- Needs_Simple_Initialization --
22707 ---------------------------------
22709 function Needs_Simple_Initialization
22710 (Typ : Entity_Id;
22711 Consider_IS : Boolean := True) return Boolean
22713 Consider_IS_NS : constant Boolean :=
22714 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
22716 begin
22717 -- Never need initialization if it is suppressed
22719 if Initialization_Suppressed (Typ) then
22720 return False;
22721 end if;
22723 -- Check for private type, in which case test applies to the underlying
22724 -- type of the private type.
22726 if Is_Private_Type (Typ) then
22727 declare
22728 RT : constant Entity_Id := Underlying_Type (Typ);
22729 begin
22730 if Present (RT) then
22731 return Needs_Simple_Initialization (RT);
22732 else
22733 return False;
22734 end if;
22735 end;
22737 -- Scalar type with Default_Value aspect requires initialization
22739 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
22740 return True;
22742 -- Cases needing simple initialization are access types, and, if pragma
22743 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
22744 -- types.
22746 elsif Is_Access_Type (Typ)
22747 or else (Consider_IS_NS and then Is_Scalar_Type (Typ))
22748 then
22749 return True;
22751 -- Mutably tagged types require default initialization
22753 elsif Is_Mutably_Tagged_CW_Equivalent_Type (Typ) then
22754 return True;
22756 -- If Initialize/Normalize_Scalars is in effect, string objects also
22757 -- need initialization, unless they are created in the course of
22758 -- expanding an aggregate (since in the latter case they will be
22759 -- filled with appropriate initializing values before they are used).
22761 elsif Consider_IS_NS
22762 and then Is_Standard_String_Type (Typ)
22763 and then
22764 (not Is_Itype (Typ)
22765 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
22766 then
22767 return True;
22769 else
22770 return False;
22771 end if;
22772 end Needs_Simple_Initialization;
22774 -------------------------------------
22775 -- Needs_Variable_Reference_Marker --
22776 -------------------------------------
22778 function Needs_Variable_Reference_Marker
22779 (N : Node_Id;
22780 Calls_OK : Boolean) return Boolean
22782 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
22783 -- Deteremine whether variable reference Ref appears within a suitable
22784 -- context that allows the creation of a marker.
22786 -----------------------------
22787 -- Within_Suitable_Context --
22788 -----------------------------
22790 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
22791 Par : Node_Id;
22793 begin
22794 Par := Ref;
22795 while Present (Par) loop
22797 -- The context is not suitable when the reference appears within
22798 -- the formal part of an instantiation which acts as compilation
22799 -- unit because there is no proper list for the insertion of the
22800 -- marker.
22802 if Nkind (Par) = N_Generic_Association
22803 and then Nkind (Parent (Par)) in N_Generic_Instantiation
22804 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
22805 then
22806 return False;
22808 -- The context is not suitable when the reference appears within
22809 -- a pragma. If the pragma has run-time semantics, the reference
22810 -- will be reconsidered once the pragma is expanded.
22812 elsif Nkind (Par) = N_Pragma then
22813 return False;
22815 -- The context is not suitable when the reference appears within a
22816 -- subprogram call, and the caller requests this behavior.
22818 elsif not Calls_OK
22819 and then Nkind (Par) in N_Entry_Call_Statement
22820 | N_Function_Call
22821 | N_Procedure_Call_Statement
22822 then
22823 return False;
22825 -- Prevent the search from going too far
22827 elsif Is_Body_Or_Package_Declaration (Par) then
22828 exit;
22829 end if;
22831 Par := Parent (Par);
22832 end loop;
22834 return True;
22835 end Within_Suitable_Context;
22837 -- Local variables
22839 Prag : Node_Id;
22840 Var_Id : Entity_Id;
22842 -- Start of processing for Needs_Variable_Reference_Marker
22844 begin
22845 -- No marker needs to be created when switch -gnatH (legacy elaboration
22846 -- checking mode enabled) is in effect because the legacy ABE mechanism
22847 -- does not use markers.
22849 if Legacy_Elaboration_Checks then
22850 return False;
22852 -- No marker needs to be created when the reference is preanalyzed
22853 -- because the marker will be inserted in the wrong place.
22855 elsif Preanalysis_Active then
22856 return False;
22858 -- Only references warrant a marker
22860 elsif Nkind (N) not in N_Expanded_Name | N_Identifier then
22861 return False;
22863 -- Only source references warrant a marker
22865 elsif not Comes_From_Source (N) then
22866 return False;
22868 -- No marker needs to be created when the reference is erroneous, left
22869 -- in a bad state, or does not denote a variable.
22871 elsif not (Present (Entity (N))
22872 and then Ekind (Entity (N)) = E_Variable
22873 and then Entity (N) /= Any_Id)
22874 then
22875 return False;
22876 end if;
22878 Var_Id := Entity (N);
22879 Prag := SPARK_Pragma (Var_Id);
22881 -- Both the variable and reference must appear in SPARK_Mode On regions
22882 -- because this elaboration scenario falls under the SPARK rules.
22884 if not (Comes_From_Source (Var_Id)
22885 and then Present (Prag)
22886 and then Get_SPARK_Mode_From_Annotation (Prag) = On
22887 and then Is_SPARK_Mode_On_Node (N))
22888 then
22889 return False;
22891 -- No marker needs to be created when the reference does not appear
22892 -- within a suitable context (see body for details).
22894 -- Performance note: parent traversal
22896 elsif not Within_Suitable_Context (N) then
22897 return False;
22898 end if;
22900 -- At this point it is known that the variable reference will play a
22901 -- role in ABE diagnostics and requires a marker.
22903 return True;
22904 end Needs_Variable_Reference_Marker;
22906 ------------------------
22907 -- New_Copy_List_Tree --
22908 ------------------------
22910 function New_Copy_List_Tree (List : List_Id) return List_Id is
22911 NL : List_Id;
22912 E : Node_Id;
22914 begin
22915 if List = No_List then
22916 return No_List;
22918 else
22919 NL := New_List;
22920 E := First (List);
22922 while Present (E) loop
22923 Append (New_Copy_Tree (E), NL);
22924 Next (E);
22925 end loop;
22927 return NL;
22928 end if;
22929 end New_Copy_List_Tree;
22931 -------------------
22932 -- New_Copy_Tree --
22933 -------------------
22935 -- The following tables play a key role in replicating entities and Itypes.
22936 -- They are intentionally declared at the library level rather than within
22937 -- New_Copy_Tree to avoid elaborating them on each call. This performance
22938 -- optimization saves up to 2% of the entire compilation time spent in the
22939 -- front end. Care should be taken to reset the tables on each new call to
22940 -- New_Copy_Tree.
22942 NCT_Table_Max : constant := 511;
22944 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
22946 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
22947 -- Obtain the hash value of node or entity Key
22949 --------------------
22950 -- NCT_Table_Hash --
22951 --------------------
22953 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
22954 begin
22955 return NCT_Table_Index (Key mod NCT_Table_Max);
22956 end NCT_Table_Hash;
22958 ----------------------
22959 -- NCT_New_Entities --
22960 ----------------------
22962 -- The following table maps old entities and Itypes to their corresponding
22963 -- new entities and Itypes.
22965 -- Aaa -> Xxx
22967 package NCT_New_Entities is new Simple_HTable (
22968 Header_Num => NCT_Table_Index,
22969 Element => Entity_Id,
22970 No_Element => Empty,
22971 Key => Entity_Id,
22972 Hash => NCT_Table_Hash,
22973 Equal => "=");
22975 ------------------------
22976 -- NCT_Pending_Itypes --
22977 ------------------------
22979 -- The following table maps old Associated_Node_For_Itype nodes to a set of
22980 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
22981 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
22982 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
22984 -- Ppp -> (Xxx, Yyy, Zzz)
22986 -- The set is expressed as an Elist
22988 package NCT_Pending_Itypes is new Simple_HTable (
22989 Header_Num => NCT_Table_Index,
22990 Element => Elist_Id,
22991 No_Element => No_Elist,
22992 Key => Node_Id,
22993 Hash => NCT_Table_Hash,
22994 Equal => "=");
22996 NCT_Tables_In_Use : Boolean := False;
22997 -- This flag keeps track of whether the two tables NCT_New_Entities and
22998 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
22999 -- where certain operations are not performed if the tables are not in
23000 -- use. This saves up to 8% of the entire compilation time spent in the
23001 -- front end.
23003 -------------------
23004 -- New_Copy_Tree --
23005 -------------------
23007 function New_Copy_Tree
23008 (Source : Node_Id;
23009 Map : Elist_Id := No_Elist;
23010 New_Sloc : Source_Ptr := No_Location;
23011 New_Scope : Entity_Id := Empty) return Node_Id
23013 -- This routine performs low-level tree manipulations and needs access
23014 -- to the internals of the tree.
23016 EWA_Level : Nat := 0;
23017 -- This counter keeps track of how many N_Expression_With_Actions nodes
23018 -- are encountered during a depth-first traversal of the subtree. These
23019 -- nodes may define new entities in their Actions lists and thus require
23020 -- special processing.
23022 EWA_Inner_Scope_Level : Nat := 0;
23023 -- This counter keeps track of how many scoping constructs appear within
23024 -- an N_Expression_With_Actions node.
23026 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
23027 pragma Inline (Add_New_Entity);
23028 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
23029 -- value New_Id. Old_Id is an entity which appears within the Actions
23030 -- list of an N_Expression_With_Actions node, or within an entity map.
23031 -- New_Id is the corresponding new entity generated during Phase 1.
23033 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
23034 pragma Inline (Add_Pending_Itype);
23035 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
23036 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
23037 -- an itype.
23039 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
23040 pragma Inline (Build_NCT_Tables);
23041 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
23042 -- information supplied in entity map Entity_Map. The format of the
23043 -- entity map must be as follows:
23045 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
23047 function Copy_Any_Node_With_Replacement
23048 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
23049 pragma Inline (Copy_Any_Node_With_Replacement);
23050 -- Replicate entity or node N by invoking one of the following routines:
23052 -- Copy_Node_With_Replacement
23053 -- Corresponding_Entity
23055 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
23056 -- Replicate the elements of entity list List
23058 function Copy_Field_With_Replacement
23059 (Field : Union_Id;
23060 Old_Par : Node_Id := Empty;
23061 New_Par : Node_Id := Empty;
23062 Semantic : Boolean := False) return Union_Id;
23063 -- Replicate field Field by invoking one of the following routines:
23065 -- Copy_Elist_With_Replacement
23066 -- Copy_List_With_Replacement
23067 -- Copy_Node_With_Replacement
23068 -- Corresponding_Entity
23070 -- If the field is not an entity list, entity, itype, syntactic list,
23071 -- or node, then the field is returned unchanged. The routine always
23072 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
23073 -- the expected parent of a syntactic field. New_Par is the new parent
23074 -- associated with a replicated syntactic field. Flag Semantic should
23075 -- be set when the input is a semantic field.
23077 function Copy_List_With_Replacement (List : List_Id) return List_Id;
23078 -- Replicate the elements of syntactic list List
23080 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
23081 -- Replicate node N
23083 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
23084 pragma Inline (Corresponding_Entity);
23085 -- Return the corresponding new entity of Id generated during Phase 1.
23086 -- If there is no such entity, return Id.
23088 function In_Entity_Map
23089 (Id : Entity_Id;
23090 Entity_Map : Elist_Id) return Boolean;
23091 pragma Inline (In_Entity_Map);
23092 -- Determine whether entity Id is one of the old ids specified in entity
23093 -- map Entity_Map. The format of the entity map must be as follows:
23095 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
23097 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
23098 pragma Inline (Update_CFS_Sloc);
23099 -- Update the Comes_From_Source and Sloc attributes of node or entity N
23101 procedure Update_Controlling_Argument
23102 (Old_Call : Node_Id;
23103 New_Call : Node_Id);
23104 pragma Inline (Update_Controlling_Argument);
23105 -- Update Controlling_Argument of New_Call base on Old_Call to make it
23106 -- points to the corresponding newly copied actual parameter.
23108 procedure Update_Named_Associations
23109 (Old_Call : Node_Id;
23110 New_Call : Node_Id);
23111 pragma Inline (Update_Named_Associations);
23112 -- Update semantic chain First/Next_Named_Association of call New_call
23113 -- based on call Old_Call.
23115 procedure Update_New_Entities (Entity_Map : Elist_Id);
23116 pragma Inline (Update_New_Entities);
23117 -- Update the semantic attributes of all new entities generated during
23118 -- Phase 1 that do not appear in entity map Entity_Map. The format of
23119 -- the entity map must be as follows:
23121 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
23123 procedure Update_Pending_Itypes
23124 (Old_Assoc : Node_Id;
23125 New_Assoc : Node_Id);
23126 pragma Inline (Update_Pending_Itypes);
23127 -- Update semantic attribute Associated_Node_For_Itype to refer to node
23128 -- New_Assoc for all itypes whose associated node is Old_Assoc.
23130 procedure Update_Semantic_Fields (Id : Entity_Id);
23131 pragma Inline (Update_Semantic_Fields);
23132 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
23133 -- or itype Id.
23135 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
23136 pragma Inline (Visit_Any_Node);
23137 -- Visit entity of node N by invoking one of the following routines:
23139 -- Visit_Entity
23140 -- Visit_Itype
23141 -- Visit_Node
23143 procedure Visit_Elist (List : Elist_Id);
23144 -- Visit the elements of entity list List
23146 procedure Visit_Entity (Id : Entity_Id);
23147 -- Visit entity Id. This action may create a new entity of Id and save
23148 -- it in table NCT_New_Entities.
23150 procedure Visit_Field
23151 (Field : Union_Id;
23152 Par_Nod : Node_Id := Empty;
23153 Semantic : Boolean := False);
23154 -- Visit field Field by invoking one of the following routines:
23156 -- Visit_Elist
23157 -- Visit_Entity
23158 -- Visit_Itype
23159 -- Visit_List
23160 -- Visit_Node
23162 -- If the field is not an entity list, entity, itype, syntactic list,
23163 -- or node, then the field is not visited. The routine always visits
23164 -- valid syntactic fields. Par_Nod is the expected parent of the
23165 -- syntactic field. Flag Semantic should be set when the input is a
23166 -- semantic field.
23168 procedure Visit_Itype (Itype : Entity_Id);
23169 -- Visit itype Itype. This action may create a new entity for Itype and
23170 -- save it in table NCT_New_Entities. In addition, the routine may map
23171 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
23173 procedure Visit_List (List : List_Id);
23174 -- Visit the elements of syntactic list List
23176 procedure Visit_Node (N : Node_Id);
23177 -- Visit node N
23179 procedure Visit_Semantic_Fields (Id : Entity_Id);
23180 pragma Inline (Visit_Semantic_Fields);
23181 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
23182 -- fields of entity or itype Id.
23184 --------------------
23185 -- Add_New_Entity --
23186 --------------------
23188 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
23189 begin
23190 pragma Assert (Present (Old_Id));
23191 pragma Assert (Present (New_Id));
23192 pragma Assert (Nkind (Old_Id) in N_Entity);
23193 pragma Assert (Nkind (New_Id) in N_Entity);
23195 NCT_Tables_In_Use := True;
23197 -- Sanity check the NCT_New_Entities table. No previous mapping with
23198 -- key Old_Id should exist.
23200 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
23202 -- Establish the mapping
23204 -- Old_Id -> New_Id
23206 NCT_New_Entities.Set (Old_Id, New_Id);
23207 end Add_New_Entity;
23209 -----------------------
23210 -- Add_Pending_Itype --
23211 -----------------------
23213 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
23214 Itypes : Elist_Id;
23216 begin
23217 pragma Assert (Present (Assoc_Nod));
23218 pragma Assert (Present (Itype));
23219 pragma Assert (Nkind (Itype) in N_Entity);
23220 pragma Assert (Is_Itype (Itype));
23222 NCT_Tables_In_Use := True;
23224 -- It is not possible to sanity check the NCT_Pendint_Itypes table
23225 -- directly because a single node may act as the associated node for
23226 -- multiple itypes.
23228 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
23230 if No (Itypes) then
23231 Itypes := New_Elmt_List;
23232 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
23233 end if;
23235 -- Establish the mapping
23237 -- Assoc_Nod -> (Itype, ...)
23239 -- Avoid inserting the same itype multiple times. This involves a
23240 -- linear search, however the set of itypes with the same associated
23241 -- node is very small.
23243 Append_Unique_Elmt (Itype, Itypes);
23244 end Add_Pending_Itype;
23246 ----------------------
23247 -- Build_NCT_Tables --
23248 ----------------------
23250 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
23251 Elmt : Elmt_Id;
23252 Old_Id : Entity_Id;
23253 New_Id : Entity_Id;
23255 begin
23256 -- Nothing to do when there is no entity map
23258 if No (Entity_Map) then
23259 return;
23260 end if;
23262 Elmt := First_Elmt (Entity_Map);
23263 while Present (Elmt) loop
23265 -- Extract the (Old_Id, New_Id) pair from the entity map
23267 Old_Id := Node (Elmt);
23268 Next_Elmt (Elmt);
23270 New_Id := Node (Elmt);
23271 Next_Elmt (Elmt);
23273 -- Establish the following mapping within table NCT_New_Entities
23275 -- Old_Id -> New_Id
23277 Add_New_Entity (Old_Id, New_Id);
23279 -- Establish the following mapping within table NCT_Pending_Itypes
23280 -- when the new entity is an itype.
23282 -- Assoc_Nod -> (New_Id, ...)
23284 -- IMPORTANT: the associated node is that of the old itype because
23285 -- the node will be replicated in Phase 2.
23287 if Is_Itype (Old_Id) then
23288 Add_Pending_Itype
23289 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
23290 Itype => New_Id);
23291 end if;
23292 end loop;
23293 end Build_NCT_Tables;
23295 ------------------------------------
23296 -- Copy_Any_Node_With_Replacement --
23297 ------------------------------------
23299 function Copy_Any_Node_With_Replacement
23300 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
23302 begin
23303 if Nkind (N) in N_Entity then
23304 return Corresponding_Entity (N);
23305 else
23306 return Copy_Node_With_Replacement (N);
23307 end if;
23308 end Copy_Any_Node_With_Replacement;
23310 ---------------------------------
23311 -- Copy_Elist_With_Replacement --
23312 ---------------------------------
23314 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
23315 Elmt : Elmt_Id;
23316 Result : Elist_Id;
23318 begin
23319 -- Copy the contents of the old list. Note that the list itself may
23320 -- be empty, in which case the routine returns a new empty list. This
23321 -- avoids sharing lists between subtrees. The element of an entity
23322 -- list could be an entity or a node, hence the invocation of routine
23323 -- Copy_Any_Node_With_Replacement.
23325 if Present (List) then
23326 Result := New_Elmt_List;
23328 Elmt := First_Elmt (List);
23329 while Present (Elmt) loop
23330 Append_Elmt
23331 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
23333 Next_Elmt (Elmt);
23334 end loop;
23336 -- Otherwise the list does not exist
23338 else
23339 Result := No_Elist;
23340 end if;
23342 return Result;
23343 end Copy_Elist_With_Replacement;
23345 ---------------------------------
23346 -- Copy_Field_With_Replacement --
23347 ---------------------------------
23349 function Copy_Field_With_Replacement
23350 (Field : Union_Id;
23351 Old_Par : Node_Id := Empty;
23352 New_Par : Node_Id := Empty;
23353 Semantic : Boolean := False) return Union_Id
23355 begin
23356 -- The field is empty
23358 if Field = Union_Id (Empty) then
23359 return Field;
23361 -- The field is an entity/itype/node
23363 elsif Field in Node_Range then
23364 declare
23365 Old_N : constant Node_Id := Node_Id (Field);
23366 Syntactic : constant Boolean :=
23367 Is_Syntactic_Node (Source => Old_Par, Field => Old_N);
23369 New_N : Node_Id;
23371 begin
23372 -- The field is an entity/itype
23374 if Nkind (Old_N) in N_Entity then
23376 -- An entity/itype is always replicated
23378 New_N := Corresponding_Entity (Old_N);
23380 -- Update the parent pointer when the entity is a syntactic
23381 -- field. Note that itypes do not have parent pointers.
23383 if Syntactic and then New_N /= Old_N then
23384 Set_Parent (New_N, New_Par);
23385 end if;
23387 -- The field is a node
23389 else
23390 -- A node is replicated when it is either a syntactic field
23391 -- or when the caller treats it as a semantic attribute.
23393 if Syntactic or else Semantic then
23394 New_N := Copy_Node_With_Replacement (Old_N);
23396 -- Update the parent pointer when the node is a syntactic
23397 -- field.
23399 if Syntactic and then New_N /= Old_N then
23400 Set_Parent (New_N, New_Par);
23401 end if;
23403 -- Otherwise the node is returned unchanged
23405 else
23406 New_N := Old_N;
23407 end if;
23408 end if;
23410 return Union_Id (New_N);
23411 end;
23413 -- The field is an entity list
23415 elsif Field in Elist_Range then
23416 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
23418 -- The field is a syntactic list
23420 elsif Field in List_Range then
23421 declare
23422 Old_List : constant List_Id := List_Id (Field);
23423 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
23425 New_List : List_Id;
23427 begin
23428 -- A list is replicated when it is either a syntactic field or
23429 -- when the caller treats it as a semantic attribute.
23431 if Syntactic or else Semantic then
23432 New_List := Copy_List_With_Replacement (Old_List);
23434 -- Update the parent pointer when the list is a syntactic
23435 -- field.
23437 if Syntactic and then New_List /= Old_List then
23438 Set_Parent (New_List, New_Par);
23439 end if;
23441 -- Otherwise the list is returned unchanged
23443 else
23444 New_List := Old_List;
23445 end if;
23447 return Union_Id (New_List);
23448 end;
23450 -- Otherwise the field denotes an attribute that does not need to be
23451 -- replicated (Chars, literals, etc).
23453 else
23454 return Field;
23455 end if;
23456 end Copy_Field_With_Replacement;
23458 --------------------------------
23459 -- Copy_List_With_Replacement --
23460 --------------------------------
23462 function Copy_List_With_Replacement (List : List_Id) return List_Id is
23463 Elmt : Node_Id;
23464 Result : List_Id;
23466 begin
23467 -- Copy the contents of the old list. Note that the list itself may
23468 -- be empty, in which case the routine returns a new empty list. This
23469 -- avoids sharing lists between subtrees. The element of a syntactic
23470 -- list is always a node, never an entity or itype, hence the call to
23471 -- routine Copy_Node_With_Replacement.
23473 if Present (List) then
23474 Result := New_List;
23476 Elmt := First (List);
23477 while Present (Elmt) loop
23478 Append (Copy_Node_With_Replacement (Elmt), Result);
23480 Next (Elmt);
23481 end loop;
23483 -- Otherwise the list does not exist
23485 else
23486 Result := No_List;
23487 end if;
23489 return Result;
23490 end Copy_List_With_Replacement;
23492 --------------------------------
23493 -- Copy_Node_With_Replacement --
23494 --------------------------------
23496 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
23497 Result : Node_Id;
23499 function Transform (U : Union_Id) return Union_Id;
23500 -- Copies one field, replacing N with Result
23502 ---------------
23503 -- Transform --
23504 ---------------
23506 function Transform (U : Union_Id) return Union_Id is
23507 begin
23508 return Copy_Field_With_Replacement
23509 (Field => U,
23510 Old_Par => N,
23511 New_Par => Result);
23512 end Transform;
23514 procedure Walk is new Walk_Sinfo_Fields_Pairwise (Transform);
23516 -- Start of processing for Copy_Node_With_Replacement
23518 begin
23519 -- Assume that the node must be returned unchanged
23521 Result := N;
23523 if N > Empty_Or_Error then
23524 pragma Assert (Nkind (N) not in N_Entity);
23526 Result := New_Copy (N);
23528 Walk (Result, Result);
23530 -- Update the Comes_From_Source and Sloc attributes of the node
23531 -- in case the caller has supplied new values.
23533 Update_CFS_Sloc (Result);
23535 -- Update the Associated_Node_For_Itype attribute of all itypes
23536 -- created during Phase 1 whose associated node is N. As a result
23537 -- the Associated_Node_For_Itype refers to the replicated node.
23538 -- No action needs to be taken when the Associated_Node_For_Itype
23539 -- refers to an entity because this was already handled during
23540 -- Phase 1, in Visit_Itype.
23542 Update_Pending_Itypes
23543 (Old_Assoc => N,
23544 New_Assoc => Result);
23546 -- Update the First/Next_Named_Association chain and the
23547 -- Controlling_Argument for a replicated call.
23549 if Nkind (N) in N_Entry_Call_Statement
23550 | N_Subprogram_Call
23551 then
23552 Update_Named_Associations
23553 (Old_Call => N,
23554 New_Call => Result);
23556 if Nkind (N) in N_Subprogram_Call then
23557 Update_Controlling_Argument
23558 (Old_Call => N,
23559 New_Call => Result);
23560 end if;
23562 -- Update the Renamed_Object attribute of a replicated object
23563 -- declaration.
23565 elsif Nkind (N) = N_Object_Renaming_Declaration then
23566 Set_Renamed_Object_Of_Possibly_Void
23567 (Defining_Entity (Result), Name (Result));
23569 -- Update the Chars attribute of identifiers
23571 elsif Nkind (N) = N_Identifier then
23573 -- The Entity field of identifiers that denote aspects is used
23574 -- to store arbitrary expressions (and hence we must check that
23575 -- they reference an actual entity before copying their Chars
23576 -- value).
23578 if Present (Entity (Result))
23579 and then Nkind (Entity (Result)) in N_Entity
23580 then
23581 Set_Chars (Result, Chars (Entity (Result)));
23582 end if;
23583 end if;
23585 Copy_Dimensions (From => N, To => Result);
23586 end if;
23588 return Result;
23589 end Copy_Node_With_Replacement;
23591 --------------------------
23592 -- Corresponding_Entity --
23593 --------------------------
23595 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
23596 New_Id : Entity_Id;
23597 Result : Entity_Id;
23599 begin
23600 -- Assume that the entity must be returned unchanged
23602 Result := Id;
23604 if Id > Empty_Or_Error then
23605 pragma Assert (Nkind (Id) in N_Entity);
23607 -- Determine whether the entity has a corresponding new entity
23608 -- generated during Phase 1 and if it does, use it.
23610 if NCT_Tables_In_Use then
23611 New_Id := NCT_New_Entities.Get (Id);
23613 if Present (New_Id) then
23614 Result := New_Id;
23615 end if;
23616 end if;
23617 end if;
23619 return Result;
23620 end Corresponding_Entity;
23622 -------------------
23623 -- In_Entity_Map --
23624 -------------------
23626 function In_Entity_Map
23627 (Id : Entity_Id;
23628 Entity_Map : Elist_Id) return Boolean
23630 Elmt : Elmt_Id;
23631 Old_Id : Entity_Id;
23633 begin
23634 -- The entity map contains pairs (Old_Id, New_Id). The advancement
23635 -- step always skips the New_Id portion of the pair.
23637 if Present (Entity_Map) then
23638 Elmt := First_Elmt (Entity_Map);
23639 while Present (Elmt) loop
23640 Old_Id := Node (Elmt);
23642 if Old_Id = Id then
23643 return True;
23644 end if;
23646 Next_Elmt (Elmt);
23647 Next_Elmt (Elmt);
23648 end loop;
23649 end if;
23651 return False;
23652 end In_Entity_Map;
23654 ---------------------
23655 -- Update_CFS_Sloc --
23656 ---------------------
23658 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
23659 begin
23660 -- A new source location defaults the Comes_From_Source attribute
23662 if New_Sloc /= No_Location then
23663 Set_Comes_From_Source (N, Get_Comes_From_Source_Default);
23664 Set_Sloc (N, New_Sloc);
23665 end if;
23666 end Update_CFS_Sloc;
23668 ---------------------------------
23669 -- Update_Controlling_Argument --
23670 ---------------------------------
23672 procedure Update_Controlling_Argument
23673 (Old_Call : Node_Id;
23674 New_Call : Node_Id)
23676 New_Act : Node_Id;
23677 Old_Act : Node_Id;
23679 Old_Ctrl_Arg : constant Node_Id := Controlling_Argument (Old_Call);
23680 -- Controlling argument of the old call node
23682 Replaced : Boolean := False;
23683 -- Flag to make sure that replacement works as expected
23685 begin
23686 if No (Old_Ctrl_Arg) then
23687 return;
23688 end if;
23690 -- Recreate the Controlling_Argument of a call by traversing both the
23691 -- old and new actual parameters in parallel.
23693 New_Act := First (Parameter_Associations (New_Call));
23694 Old_Act := First (Parameter_Associations (Old_Call));
23695 while Present (Old_Act) loop
23697 -- Actual parameter appears either in a named parameter
23698 -- association or directly.
23700 if Nkind (Old_Act) = N_Parameter_Association then
23701 if Explicit_Actual_Parameter (Old_Act) = Old_Ctrl_Arg then
23702 Set_Controlling_Argument
23703 (New_Call, Explicit_Actual_Parameter (New_Act));
23704 Replaced := True;
23705 exit;
23706 end if;
23708 elsif Old_Act = Old_Ctrl_Arg then
23709 Set_Controlling_Argument (New_Call, New_Act);
23710 Replaced := True;
23711 exit;
23712 end if;
23714 Next (New_Act);
23715 Next (Old_Act);
23716 end loop;
23718 pragma Assert (Replaced);
23719 end Update_Controlling_Argument;
23721 -------------------------------
23722 -- Update_Named_Associations --
23723 -------------------------------
23725 procedure Update_Named_Associations
23726 (Old_Call : Node_Id;
23727 New_Call : Node_Id)
23729 New_Act : Node_Id;
23730 New_Next : Node_Id;
23731 Old_Act : Node_Id;
23732 Old_Next : Node_Id;
23734 begin
23735 if No (First_Named_Actual (Old_Call)) then
23736 return;
23737 end if;
23739 -- Recreate the First/Next_Named_Actual chain of a call by traversing
23740 -- the chains of both the old and new calls in parallel.
23742 New_Act := First (Parameter_Associations (New_Call));
23743 Old_Act := First (Parameter_Associations (Old_Call));
23744 while Present (Old_Act) loop
23745 if Nkind (Old_Act) = N_Parameter_Association
23746 and then Explicit_Actual_Parameter (Old_Act)
23747 = First_Named_Actual (Old_Call)
23748 then
23749 Set_First_Named_Actual (New_Call,
23750 Explicit_Actual_Parameter (New_Act));
23751 end if;
23753 if Nkind (Old_Act) = N_Parameter_Association
23754 and then Present (Next_Named_Actual (Old_Act))
23755 then
23756 -- Scan the actual parameter list to find the next suitable
23757 -- named actual. Note that the list may be out of order.
23759 New_Next := First (Parameter_Associations (New_Call));
23760 Old_Next := First (Parameter_Associations (Old_Call));
23761 while Nkind (Old_Next) /= N_Parameter_Association
23762 or else Explicit_Actual_Parameter (Old_Next) /=
23763 Next_Named_Actual (Old_Act)
23764 loop
23765 Next (New_Next);
23766 Next (Old_Next);
23767 end loop;
23769 Set_Next_Named_Actual (New_Act,
23770 Explicit_Actual_Parameter (New_Next));
23771 end if;
23773 Next (New_Act);
23774 Next (Old_Act);
23775 end loop;
23776 end Update_Named_Associations;
23778 -------------------------
23779 -- Update_New_Entities --
23780 -------------------------
23782 procedure Update_New_Entities (Entity_Map : Elist_Id) is
23783 New_Id : Entity_Id := Empty;
23784 Old_Id : Entity_Id := Empty;
23786 begin
23787 if NCT_Tables_In_Use then
23788 NCT_New_Entities.Get_First (Old_Id, New_Id);
23790 -- Update the semantic fields of all new entities created during
23791 -- Phase 1 which were not supplied via an entity map.
23792 -- ??? Is there a better way of distinguishing those?
23794 while Present (Old_Id) and then Present (New_Id) loop
23795 if not In_Entity_Map (Old_Id, Entity_Map) then
23796 Update_Semantic_Fields (New_Id);
23797 end if;
23799 NCT_New_Entities.Get_Next (Old_Id, New_Id);
23800 end loop;
23801 end if;
23802 end Update_New_Entities;
23804 ---------------------------
23805 -- Update_Pending_Itypes --
23806 ---------------------------
23808 procedure Update_Pending_Itypes
23809 (Old_Assoc : Node_Id;
23810 New_Assoc : Node_Id)
23812 Item : Elmt_Id;
23813 Itypes : Elist_Id;
23815 begin
23816 if NCT_Tables_In_Use then
23817 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
23819 -- Update the Associated_Node_For_Itype attribute for all itypes
23820 -- which originally refer to Old_Assoc to designate New_Assoc.
23822 if Present (Itypes) then
23823 Item := First_Elmt (Itypes);
23824 while Present (Item) loop
23825 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
23827 Next_Elmt (Item);
23828 end loop;
23829 end if;
23830 end if;
23831 end Update_Pending_Itypes;
23833 ----------------------------
23834 -- Update_Semantic_Fields --
23835 ----------------------------
23837 procedure Update_Semantic_Fields (Id : Entity_Id) is
23838 begin
23839 -- Discriminant_Constraint
23841 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
23842 Set_Discriminant_Constraint (Id, Elist_Id (
23843 Copy_Field_With_Replacement
23844 (Field => Union_Id (Discriminant_Constraint (Id)),
23845 Semantic => True)));
23846 end if;
23848 -- Etype
23850 Set_Etype (Id, Node_Id (
23851 Copy_Field_With_Replacement
23852 (Field => Union_Id (Etype (Id)),
23853 Semantic => True)));
23855 -- First_Index
23856 -- Packed_Array_Impl_Type
23858 if Is_Array_Type (Id) then
23859 if Present (First_Index (Id)) then
23860 Set_First_Index (Id, First (List_Id (
23861 Copy_Field_With_Replacement
23862 (Field => Union_Id (List_Containing (First_Index (Id))),
23863 Semantic => True))));
23864 end if;
23866 if Is_Packed (Id) then
23867 Set_Packed_Array_Impl_Type (Id, Node_Id (
23868 Copy_Field_With_Replacement
23869 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
23870 Semantic => True)));
23871 end if;
23872 end if;
23874 -- Prev_Entity
23876 Set_Prev_Entity (Id, Node_Id (
23877 Copy_Field_With_Replacement
23878 (Field => Union_Id (Prev_Entity (Id)),
23879 Semantic => True)));
23881 -- Next_Entity
23883 Set_Next_Entity (Id, Node_Id (
23884 Copy_Field_With_Replacement
23885 (Field => Union_Id (Next_Entity (Id)),
23886 Semantic => True)));
23888 -- Scalar_Range
23890 if Is_Discrete_Type (Id) then
23891 Set_Scalar_Range (Id, Node_Id (
23892 Copy_Field_With_Replacement
23893 (Field => Union_Id (Scalar_Range (Id)),
23894 Semantic => True)));
23895 end if;
23897 -- Scope
23899 -- Update the scope when the caller specified an explicit one
23901 if Present (New_Scope) then
23902 Set_Scope (Id, New_Scope);
23903 else
23904 Set_Scope (Id, Node_Id (
23905 Copy_Field_With_Replacement
23906 (Field => Union_Id (Scope (Id)),
23907 Semantic => True)));
23908 end if;
23909 end Update_Semantic_Fields;
23911 --------------------
23912 -- Visit_Any_Node --
23913 --------------------
23915 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
23916 begin
23917 if Nkind (N) in N_Entity then
23918 if Is_Itype (N) then
23919 Visit_Itype (N);
23920 else
23921 Visit_Entity (N);
23922 end if;
23923 else
23924 Visit_Node (N);
23925 end if;
23926 end Visit_Any_Node;
23928 -----------------
23929 -- Visit_Elist --
23930 -----------------
23932 procedure Visit_Elist (List : Elist_Id) is
23933 Elmt : Elmt_Id;
23935 begin
23936 -- The element of an entity list could be an entity, itype, or a
23937 -- node, hence the call to Visit_Any_Node.
23939 if Present (List) then
23940 Elmt := First_Elmt (List);
23941 while Present (Elmt) loop
23942 Visit_Any_Node (Node (Elmt));
23944 Next_Elmt (Elmt);
23945 end loop;
23946 end if;
23947 end Visit_Elist;
23949 ------------------
23950 -- Visit_Entity --
23951 ------------------
23953 procedure Visit_Entity (Id : Entity_Id) is
23954 New_Id : Entity_Id;
23956 begin
23957 pragma Assert (Nkind (Id) in N_Entity);
23958 pragma Assert (not Is_Itype (Id));
23960 -- Nothing to do when the entity is not defined in the Actions list
23961 -- of an N_Expression_With_Actions node.
23963 if EWA_Level = 0 then
23964 return;
23966 -- Nothing to do when the entity is defined in a scoping construct
23967 -- within an N_Expression_With_Actions node.
23969 elsif EWA_Inner_Scope_Level > 0 then
23970 return;
23972 -- Nothing to do when the entity was already visited
23974 elsif NCT_Tables_In_Use
23975 and then Present (NCT_New_Entities.Get (Id))
23976 then
23977 return;
23979 -- Nothing to do when the declaration node of the entity is not in
23980 -- the subtree being replicated.
23982 elsif not In_Subtree
23983 (N => Declaration_Node (Id),
23984 Root => Source)
23985 then
23986 return;
23987 end if;
23989 -- Create a new entity by directly copying the old entity. This
23990 -- action causes all attributes of the old entity to be inherited.
23992 New_Id := New_Copy (Id);
23994 -- Create a new name for the new entity because the back end needs
23995 -- distinct names for debugging purposes, provided that the entity
23996 -- has already been analyzed.
23998 if Ekind (Id) /= E_Void then
23999 Set_Chars (New_Id, New_Internal_Name ('T'));
24000 end if;
24002 -- Update the Comes_From_Source and Sloc attributes of the entity in
24003 -- case the caller has supplied new values.
24005 Update_CFS_Sloc (New_Id);
24007 -- Establish the following mapping within table NCT_New_Entities:
24009 -- Id -> New_Id
24011 Add_New_Entity (Id, New_Id);
24013 -- Deal with the semantic fields of entities. The fields are visited
24014 -- because they may mention entities which reside within the subtree
24015 -- being copied.
24017 Visit_Semantic_Fields (Id);
24018 end Visit_Entity;
24020 -----------------
24021 -- Visit_Field --
24022 -----------------
24024 procedure Visit_Field
24025 (Field : Union_Id;
24026 Par_Nod : Node_Id := Empty;
24027 Semantic : Boolean := False)
24029 begin
24030 -- The field is empty
24032 if Field = Union_Id (Empty) then
24033 return;
24035 -- The field is an entity/itype/node
24037 elsif Field in Node_Range then
24038 declare
24039 N : constant Node_Id := Node_Id (Field);
24041 begin
24042 -- The field is an entity/itype
24044 if Nkind (N) in N_Entity then
24046 -- Itypes are always visited
24048 if Is_Itype (N) then
24049 Visit_Itype (N);
24051 -- An entity is visited when it is either a syntactic field
24052 -- or when the caller treats it as a semantic attribute.
24054 elsif Parent (N) = Par_Nod or else Semantic then
24055 Visit_Entity (N);
24056 end if;
24058 -- The field is a node
24060 else
24061 -- A node is visited when it is either a syntactic field or
24062 -- when the caller treats it as a semantic attribute.
24064 if Parent (N) = Par_Nod or else Semantic then
24065 Visit_Node (N);
24066 end if;
24067 end if;
24068 end;
24070 -- The field is an entity list
24072 elsif Field in Elist_Range then
24073 Visit_Elist (Elist_Id (Field));
24075 -- The field is a syntax list
24077 elsif Field in List_Range then
24078 declare
24079 List : constant List_Id := List_Id (Field);
24081 begin
24082 -- A syntax list is visited when it is either a syntactic field
24083 -- or when the caller treats it as a semantic attribute.
24085 if Parent (List) = Par_Nod or else Semantic then
24086 Visit_List (List);
24087 end if;
24088 end;
24090 -- Otherwise the field denotes information which does not need to be
24091 -- visited (chars, literals, etc.).
24093 else
24094 null;
24095 end if;
24096 end Visit_Field;
24098 -----------------
24099 -- Visit_Itype --
24100 -----------------
24102 procedure Visit_Itype (Itype : Entity_Id) is
24103 New_Assoc : Node_Id;
24104 New_Itype : Entity_Id;
24105 Old_Assoc : Node_Id;
24107 begin
24108 pragma Assert (Nkind (Itype) in N_Entity);
24109 pragma Assert (Is_Itype (Itype));
24111 -- Itypes that describe the designated type of access to subprograms
24112 -- have the structure of subprogram declarations, with signatures,
24113 -- etc. Either we duplicate the signatures completely, or choose to
24114 -- share such itypes, which is fine because their elaboration will
24115 -- have no side effects.
24117 if Ekind (Itype) = E_Subprogram_Type then
24118 return;
24120 -- Nothing to do if the itype was already visited
24122 elsif NCT_Tables_In_Use
24123 and then Present (NCT_New_Entities.Get (Itype))
24124 then
24125 return;
24127 -- Nothing to do if the associated node of the itype is not within
24128 -- the subtree being replicated.
24130 elsif not In_Subtree
24131 (N => Associated_Node_For_Itype (Itype),
24132 Root => Source)
24133 then
24134 return;
24135 end if;
24137 -- Create a new itype by directly copying the old itype. This action
24138 -- causes all attributes of the old itype to be inherited.
24140 New_Itype := New_Copy (Itype);
24142 -- Create a new name for the new itype because the back end requires
24143 -- distinct names for debugging purposes.
24145 Set_Chars (New_Itype, New_Internal_Name ('T'));
24147 -- Update the Comes_From_Source and Sloc attributes of the itype in
24148 -- case the caller has supplied new values.
24150 Update_CFS_Sloc (New_Itype);
24152 -- Establish the following mapping within table NCT_New_Entities:
24154 -- Itype -> New_Itype
24156 Add_New_Entity (Itype, New_Itype);
24158 -- The new itype must be unfrozen because the resulting subtree may
24159 -- be inserted anywhere and cause an earlier or later freezing.
24161 if Present (Freeze_Node (New_Itype)) then
24162 Set_Freeze_Node (New_Itype, Empty);
24163 Set_Is_Frozen (New_Itype, False);
24164 end if;
24166 -- If a record subtype is simply copied, the entity list will be
24167 -- shared, so Cloned_Subtype must be set to indicate this.
24169 if Ekind (Itype) in E_Class_Wide_Subtype | E_Record_Subtype then
24170 Set_Cloned_Subtype (New_Itype, Itype);
24171 end if;
24173 -- The associated node may denote an entity, in which case it may
24174 -- already have a new corresponding entity created during a prior
24175 -- call to Visit_Entity or Visit_Itype for the same subtree.
24177 -- Given
24178 -- Old_Assoc ---------> New_Assoc
24180 -- Created by Visit_Itype
24181 -- Itype -------------> New_Itype
24182 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
24184 -- In the example above, Old_Assoc is an arbitrary entity that was
24185 -- already visited for the same subtree and has a corresponding new
24186 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
24187 -- of copying entities, however it must be updated to New_Assoc.
24189 Old_Assoc := Associated_Node_For_Itype (Itype);
24191 if Nkind (Old_Assoc) in N_Entity then
24192 if NCT_Tables_In_Use then
24193 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
24195 if Present (New_Assoc) then
24196 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
24197 end if;
24198 end if;
24200 -- Otherwise the associated node denotes a node. Postpone the update
24201 -- until Phase 2 when the node is replicated. Establish the following
24202 -- mapping within table NCT_Pending_Itypes:
24204 -- Old_Assoc -> (New_Type, ...)
24206 else
24207 Add_Pending_Itype (Old_Assoc, New_Itype);
24208 end if;
24210 -- Deal with the semantic fields of itypes. The fields are visited
24211 -- because they may mention entities that reside within the subtree
24212 -- being copied.
24214 Visit_Semantic_Fields (Itype);
24215 end Visit_Itype;
24217 ----------------
24218 -- Visit_List --
24219 ----------------
24221 procedure Visit_List (List : List_Id) is
24222 Elmt : Node_Id;
24224 begin
24225 -- Note that the element of a syntactic list is always a node, never
24226 -- an entity or itype, hence the call to Visit_Node.
24228 Elmt := First (List);
24229 while Present (Elmt) loop
24230 Visit_Node (Elmt);
24232 Next (Elmt);
24233 end loop;
24234 end Visit_List;
24236 ----------------
24237 -- Visit_Node --
24238 ----------------
24240 procedure Visit_Node (N : Node_Id) is
24241 begin
24242 pragma Assert (Nkind (N) not in N_Entity);
24244 -- If the node is a quantified expression and expander is active,
24245 -- it contains an implicit declaration that may require a new entity
24246 -- when the condition has already been (pre)analyzed.
24248 if Nkind (N) = N_Expression_With_Actions
24249 or else
24250 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
24251 then
24252 EWA_Level := EWA_Level + 1;
24254 elsif EWA_Level > 0
24255 and then Nkind (N) in N_Block_Statement
24256 | N_Subprogram_Body
24257 | N_Subprogram_Declaration
24258 then
24259 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
24260 end if;
24262 -- If the node is a block, we need to process all declarations
24263 -- in the block and make new entities for each.
24265 if Nkind (N) = N_Block_Statement then
24266 declare
24267 Decl : Node_Id := First (Declarations (N));
24269 begin
24270 while Present (Decl) loop
24271 if Nkind (Decl) = N_Object_Declaration then
24272 Add_New_Entity (Defining_Identifier (Decl),
24273 New_Copy (Defining_Identifier (Decl)));
24274 end if;
24276 Next (Decl);
24277 end loop;
24278 end;
24279 end if;
24281 declare
24282 procedure Action (U : Union_Id);
24283 procedure Action (U : Union_Id) is
24284 begin
24285 Visit_Field (Field => U, Par_Nod => N);
24286 end Action;
24288 procedure Walk is new Walk_Sinfo_Fields (Action);
24289 begin
24290 Walk (N);
24291 end;
24293 if EWA_Level > 0
24294 and then Nkind (N) in N_Block_Statement
24295 | N_Subprogram_Body
24296 | N_Subprogram_Declaration
24297 then
24298 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
24300 elsif Nkind (N) = N_Expression_With_Actions
24301 or else
24302 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
24303 then
24304 EWA_Level := EWA_Level - 1;
24305 end if;
24306 end Visit_Node;
24308 ---------------------------
24309 -- Visit_Semantic_Fields --
24310 ---------------------------
24312 procedure Visit_Semantic_Fields (Id : Entity_Id) is
24313 begin
24314 pragma Assert (Nkind (Id) in N_Entity);
24316 -- Discriminant_Constraint
24318 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
24319 Visit_Field
24320 (Field => Union_Id (Discriminant_Constraint (Id)),
24321 Semantic => True);
24322 end if;
24324 -- Etype
24326 Visit_Field
24327 (Field => Union_Id (Etype (Id)),
24328 Semantic => True);
24330 -- First_Index
24331 -- Packed_Array_Impl_Type
24333 if Is_Array_Type (Id) then
24334 if Present (First_Index (Id)) then
24335 Visit_Field
24336 (Field => Union_Id (List_Containing (First_Index (Id))),
24337 Semantic => True);
24338 end if;
24340 if Is_Packed (Id) then
24341 Visit_Field
24342 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
24343 Semantic => True);
24344 end if;
24345 end if;
24347 -- Scalar_Range
24349 if Is_Discrete_Type (Id) then
24350 Visit_Field
24351 (Field => Union_Id (Scalar_Range (Id)),
24352 Semantic => True);
24353 end if;
24354 end Visit_Semantic_Fields;
24356 -- Start of processing for New_Copy_Tree
24358 begin
24359 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
24360 -- shallow copies for each node within, and then updating the child and
24361 -- parent pointers accordingly. This process is straightforward, however
24362 -- the routine must deal with the following complications:
24364 -- * Entities defined within N_Expression_With_Actions nodes must be
24365 -- replicated rather than shared to avoid introducing two identical
24366 -- symbols within the same scope. Note that no other expression can
24367 -- currently define entities.
24369 -- do
24370 -- Source_Low : ...;
24371 -- Source_High : ...;
24373 -- <reference to Source_Low>
24374 -- <reference to Source_High>
24375 -- in ... end;
24377 -- New_Copy_Tree handles this case by first creating new entities
24378 -- and then updating all existing references to point to these new
24379 -- entities.
24381 -- do
24382 -- New_Low : ...;
24383 -- New_High : ...;
24385 -- <reference to New_Low>
24386 -- <reference to New_High>
24387 -- in ... end;
24389 -- * Itypes defined within the subtree must be replicated to avoid any
24390 -- dependencies on invalid or inaccessible data.
24392 -- subtype Source_Itype is ... range Source_Low .. Source_High;
24394 -- New_Copy_Tree handles this case by first creating a new itype in
24395 -- the same fashion as entities, and then updating various relevant
24396 -- constraints.
24398 -- subtype New_Itype is ... range New_Low .. New_High;
24400 -- * The Associated_Node_For_Itype field of itypes must be updated to
24401 -- reference the proper replicated entity or node.
24403 -- * Semantic fields of entities such as Etype and Scope must be
24404 -- updated to reference the proper replicated entities.
24406 -- * Some semantic fields of nodes must be updated to reference
24407 -- the proper replicated nodes.
24409 -- Finally, quantified expressions contain an implicit declaration for
24410 -- the bound variable. Given that quantified expressions appearing
24411 -- in contracts are copied to create pragmas and eventually checking
24412 -- procedures, a new bound variable must be created for each copy, to
24413 -- prevent multiple declarations of the same symbol.
24415 -- To meet all these demands, routine New_Copy_Tree is split into two
24416 -- phases.
24418 -- Phase 1 traverses the tree in order to locate entities and itypes
24419 -- defined within the subtree. New entities are generated and saved in
24420 -- table NCT_New_Entities. The semantic fields of all new entities and
24421 -- itypes are then updated accordingly.
24423 -- Phase 2 traverses the tree in order to replicate each node. Various
24424 -- semantic fields of nodes and entities are updated accordingly.
24426 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
24427 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
24428 -- data inside.
24430 if NCT_Tables_In_Use then
24431 NCT_Tables_In_Use := False;
24433 NCT_New_Entities.Reset;
24434 NCT_Pending_Itypes.Reset;
24435 end if;
24437 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
24438 -- supplied by a linear entity map. The tables offer faster access to
24439 -- the same data.
24441 Build_NCT_Tables (Map);
24443 -- Execute Phase 1. Traverse the subtree and generate new entities for
24444 -- the following cases:
24446 -- * An entity defined within an N_Expression_With_Actions node
24448 -- * An itype referenced within the subtree where the associated node
24449 -- is also in the subtree.
24451 -- All new entities are accessible via table NCT_New_Entities, which
24452 -- contains mappings of the form:
24454 -- Old_Entity -> New_Entity
24455 -- Old_Itype -> New_Itype
24457 -- In addition, the associated nodes of all new itypes are mapped in
24458 -- table NCT_Pending_Itypes:
24460 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
24462 Visit_Any_Node (Source);
24464 -- Update the semantic attributes of all new entities generated during
24465 -- Phase 1 before starting Phase 2. The updates could be performed in
24466 -- routine Corresponding_Entity, however this may cause the same entity
24467 -- to be updated multiple times, effectively generating useless nodes.
24468 -- Keeping the updates separates from Phase 2 ensures that only one set
24469 -- of attributes is generated for an entity at any one time.
24471 Update_New_Entities (Map);
24473 -- Execute Phase 2. Replicate the source subtree one node at a time.
24474 -- The following transformations take place:
24476 -- * References to entities and itypes are updated to refer to the
24477 -- new entities and itypes generated during Phase 1.
24479 -- * All Associated_Node_For_Itype attributes of itypes are updated
24480 -- to refer to the new replicated Associated_Node_For_Itype.
24482 return Copy_Node_With_Replacement (Source);
24483 end New_Copy_Tree;
24485 -------------------------
24486 -- New_External_Entity --
24487 -------------------------
24489 function New_External_Entity
24490 (Kind : Entity_Kind;
24491 Scope_Id : Entity_Id;
24492 Sloc_Value : Source_Ptr;
24493 Related_Id : Entity_Id;
24494 Suffix : Character;
24495 Suffix_Index : Int := 0;
24496 Prefix : Character := ' ') return Entity_Id
24498 N : constant Entity_Id :=
24499 Make_Defining_Identifier (Sloc_Value,
24500 New_External_Name
24501 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
24503 begin
24504 Mutate_Ekind (N, Kind);
24505 Set_Is_Internal (N, True);
24506 Append_Entity (N, Scope_Id);
24507 Set_Public_Status (N);
24509 if Kind in Type_Kind then
24510 Reinit_Size_Align (N);
24511 end if;
24513 return N;
24514 end New_External_Entity;
24516 -------------------------
24517 -- New_Internal_Entity --
24518 -------------------------
24520 function New_Internal_Entity
24521 (Kind : Entity_Kind;
24522 Scope_Id : Entity_Id;
24523 Sloc_Value : Source_Ptr;
24524 Id_Char : Character) return Entity_Id
24526 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
24528 begin
24529 Mutate_Ekind (N, Kind);
24530 Set_Is_Internal (N, True);
24531 Append_Entity (N, Scope_Id);
24533 if Kind in Type_Kind then
24534 Reinit_Size_Align (N);
24535 end if;
24537 return N;
24538 end New_Internal_Entity;
24540 -----------------
24541 -- Next_Actual --
24542 -----------------
24544 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
24545 Par : constant Node_Id := Parent (Actual_Id);
24546 N : Node_Id;
24548 begin
24549 -- If we are pointing at a positional parameter, it is a member of a
24550 -- node list (the list of parameters), and the next parameter is the
24551 -- next node on the list, unless we hit a parameter association, then
24552 -- we shift to using the chain whose head is the First_Named_Actual in
24553 -- the parent, and then is threaded using the Next_Named_Actual of the
24554 -- Parameter_Association. All this fiddling is because the original node
24555 -- list is in the textual call order, and what we need is the
24556 -- declaration order.
24558 if Is_List_Member (Actual_Id) then
24559 N := Next (Actual_Id);
24561 if Nkind (N) = N_Parameter_Association then
24563 -- In case of a build-in-place call, the call will no longer be a
24564 -- call; it will have been rewritten.
24566 if Nkind (Par) in N_Entry_Call_Statement
24567 | N_Function_Call
24568 | N_Procedure_Call_Statement
24569 then
24570 return First_Named_Actual (Par);
24572 -- In case of a call rewritten in GNATprove mode while "inlining
24573 -- for proof" go to the original call.
24575 elsif Nkind (Par) = N_Null_Statement then
24576 pragma Assert
24577 (GNATprove_Mode
24578 and then
24579 Nkind (Original_Node (Par)) in N_Subprogram_Call);
24581 return First_Named_Actual (Original_Node (Par));
24582 else
24583 return Empty;
24584 end if;
24585 else
24586 return N;
24587 end if;
24589 else
24590 return Next_Named_Actual (Parent (Actual_Id));
24591 end if;
24592 end Next_Actual;
24594 procedure Next_Actual (Actual_Id : in out Node_Id) is
24595 begin
24596 Actual_Id := Next_Actual (Actual_Id);
24597 end Next_Actual;
24599 -----------------
24600 -- Next_Global --
24601 -----------------
24603 function Next_Global (Node : Node_Id) return Node_Id is
24604 begin
24605 -- The global item may either be in a list, or by itself, in which case
24606 -- there is no next global item with the same mode.
24608 if Is_List_Member (Node) then
24609 return Next (Node);
24610 else
24611 return Empty;
24612 end if;
24613 end Next_Global;
24615 procedure Next_Global (Node : in out Node_Id) is
24616 begin
24617 Node := Next_Global (Node);
24618 end Next_Global;
24620 ------------------------
24621 -- No_Caching_Enabled --
24622 ------------------------
24624 function No_Caching_Enabled (Id : Entity_Id) return Boolean is
24625 Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching);
24626 Arg1 : Node_Id;
24628 begin
24629 if Present (Prag) then
24630 Arg1 := First (Pragma_Argument_Associations (Prag));
24632 -- The pragma has an optional Boolean expression, the related
24633 -- property is enabled only when the expression evaluates to True.
24635 if Present (Arg1) then
24636 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
24638 -- Otherwise the lack of expression enables the property by
24639 -- default.
24641 else
24642 return True;
24643 end if;
24645 -- The property was never set in the first place
24647 else
24648 return False;
24649 end if;
24650 end No_Caching_Enabled;
24652 --------------------------
24653 -- No_Heap_Finalization --
24654 --------------------------
24656 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
24657 begin
24658 if Ekind (Typ) in E_Access_Type | E_General_Access_Type
24659 and then Is_Library_Level_Entity (Typ)
24660 then
24661 -- A global No_Heap_Finalization pragma applies to all library-level
24662 -- named access-to-object types.
24664 if Present (No_Heap_Finalization_Pragma) then
24665 return True;
24667 -- The library-level named access-to-object type itself is subject to
24668 -- pragma No_Heap_Finalization.
24670 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
24671 return True;
24672 end if;
24673 end if;
24675 return False;
24676 end No_Heap_Finalization;
24678 -----------------------
24679 -- Normalize_Actuals --
24680 -----------------------
24682 -- Chain actuals according to formals of subprogram. If there are no named
24683 -- associations, the chain is simply the list of Parameter Associations,
24684 -- since the order is the same as the declaration order. If there are named
24685 -- associations, then the First_Named_Actual field in the N_Function_Call
24686 -- or N_Procedure_Call_Statement node points to the Parameter_Association
24687 -- node for the parameter that comes first in declaration order. The
24688 -- remaining named parameters are then chained in declaration order using
24689 -- Next_Named_Actual.
24691 -- This routine also verifies that the number of actuals is compatible with
24692 -- the number and default values of formals, but performs no type checking
24693 -- (type checking is done by the caller).
24695 -- If the matching succeeds, Success is set to True and the caller proceeds
24696 -- with type-checking. If the match is unsuccessful, then Success is set to
24697 -- False, and the caller attempts a different interpretation, if there is
24698 -- one.
24700 -- If the flag Report is on, the call is not overloaded, and a failure to
24701 -- match can be reported here, rather than in the caller.
24703 procedure Normalize_Actuals
24704 (N : Node_Id;
24705 S : Entity_Id;
24706 Report : Boolean;
24707 Success : out Boolean)
24709 Actuals : constant List_Id := Parameter_Associations (N);
24710 Actual : Node_Id := Empty;
24711 Formal : Entity_Id;
24712 Last : Node_Id := Empty;
24713 First_Named : Node_Id := Empty;
24714 Found : Boolean;
24716 Formals_To_Match : Integer := 0;
24717 Actuals_To_Match : Integer := 0;
24719 procedure Chain (A : Node_Id);
24720 -- Add named actual at the proper place in the list, using the
24721 -- Next_Named_Actual link.
24723 function Reporting return Boolean;
24724 -- Determines if an error is to be reported. To report an error, we
24725 -- need Report to be True, and also we do not report errors caused
24726 -- by calls to init procs that occur within other init procs. Such
24727 -- errors must always be cascaded errors, since if all the types are
24728 -- declared correctly, the compiler will certainly build decent calls.
24730 -----------
24731 -- Chain --
24732 -----------
24734 procedure Chain (A : Node_Id) is
24735 begin
24736 if No (Last) then
24738 -- Call node points to first actual in list
24740 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
24742 else
24743 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
24744 end if;
24746 Last := A;
24747 Set_Next_Named_Actual (Last, Empty);
24748 end Chain;
24750 ---------------
24751 -- Reporting --
24752 ---------------
24754 function Reporting return Boolean is
24755 begin
24756 if not Report then
24757 return False;
24759 elsif not Within_Init_Proc then
24760 return True;
24762 elsif Is_Init_Proc (Entity (Name (N))) then
24763 return False;
24765 else
24766 return True;
24767 end if;
24768 end Reporting;
24770 -- Start of processing for Normalize_Actuals
24772 begin
24773 if Is_Access_Type (S) then
24775 -- The name in the call is a function call that returns an access
24776 -- to subprogram. The designated type has the list of formals.
24778 Formal := First_Formal (Designated_Type (S));
24779 else
24780 Formal := First_Formal (S);
24781 end if;
24783 while Present (Formal) loop
24784 Formals_To_Match := Formals_To_Match + 1;
24785 Next_Formal (Formal);
24786 end loop;
24788 -- Find if there is a named association, and verify that no positional
24789 -- associations appear after named ones.
24791 if Present (Actuals) then
24792 Actual := First (Actuals);
24793 end if;
24795 while Present (Actual)
24796 and then Nkind (Actual) /= N_Parameter_Association
24797 loop
24798 Actuals_To_Match := Actuals_To_Match + 1;
24799 Next (Actual);
24800 end loop;
24802 if No (Actual) and Actuals_To_Match = Formals_To_Match then
24804 -- Most common case: positional notation, no defaults
24806 Success := True;
24807 return;
24809 elsif Actuals_To_Match > Formals_To_Match then
24811 -- Too many actuals: will not work
24813 if Reporting then
24814 if Is_Entity_Name (Name (N)) then
24815 Error_Msg_N ("too many arguments in call to&", Name (N));
24816 else
24817 Error_Msg_N ("too many arguments in call", N);
24818 end if;
24819 end if;
24821 Success := False;
24822 return;
24823 end if;
24825 First_Named := Actual;
24827 while Present (Actual) loop
24828 if Nkind (Actual) /= N_Parameter_Association then
24829 Error_Msg_N
24830 ("positional parameters not allowed after named ones", Actual);
24831 Success := False;
24832 return;
24834 else
24835 Actuals_To_Match := Actuals_To_Match + 1;
24836 end if;
24838 Next (Actual);
24839 end loop;
24841 if Present (Actuals) then
24842 Actual := First (Actuals);
24843 end if;
24845 Formal := First_Formal (S);
24846 while Present (Formal) loop
24848 -- Match the formals in order. If the corresponding actual is
24849 -- positional, nothing to do. Else scan the list of named actuals
24850 -- to find the one with the right name.
24852 if Present (Actual)
24853 and then Nkind (Actual) /= N_Parameter_Association
24854 then
24855 Next (Actual);
24856 Actuals_To_Match := Actuals_To_Match - 1;
24857 Formals_To_Match := Formals_To_Match - 1;
24859 else
24860 -- For named parameters, search the list of actuals to find
24861 -- one that matches the next formal name.
24863 Actual := First_Named;
24864 Found := False;
24865 while Present (Actual) loop
24866 if Chars (Selector_Name (Actual)) = Chars (Formal) then
24867 Found := True;
24868 Chain (Actual);
24869 Actuals_To_Match := Actuals_To_Match - 1;
24870 Formals_To_Match := Formals_To_Match - 1;
24871 exit;
24872 end if;
24874 Next (Actual);
24875 end loop;
24877 if not Found then
24878 if Ekind (Formal) /= E_In_Parameter
24879 or else No (Default_Value (Formal))
24880 then
24881 if Reporting then
24882 if (Comes_From_Source (S)
24883 or else Sloc (S) = Standard_Location)
24884 and then Is_Overloadable (S)
24885 then
24886 if No (Actuals)
24887 and then
24888 Nkind (Parent (N)) in N_Procedure_Call_Statement
24889 | N_Function_Call
24890 | N_Parameter_Association
24891 and then Ekind (S) /= E_Function
24892 then
24893 Set_Etype (N, Etype (S));
24895 else
24896 Error_Msg_Name_1 := Chars (S);
24897 Error_Msg_Sloc := Sloc (S);
24898 Error_Msg_NE
24899 ("missing argument for parameter & "
24900 & "in call to % declared #", N, Formal);
24901 end if;
24903 elsif Is_Overloadable (S) then
24904 Error_Msg_Name_1 := Chars (S);
24906 -- Point to type derivation that generated the
24907 -- operation.
24909 Error_Msg_Sloc := Sloc (Parent (S));
24911 Error_Msg_NE
24912 ("missing argument for parameter & "
24913 & "in call to % (inherited) #", N, Formal);
24915 else
24916 Error_Msg_NE
24917 ("missing argument for parameter &", N, Formal);
24918 end if;
24919 end if;
24921 Success := False;
24922 return;
24924 else
24925 Formals_To_Match := Formals_To_Match - 1;
24926 end if;
24927 end if;
24928 end if;
24930 Next_Formal (Formal);
24931 end loop;
24933 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
24934 Success := True;
24935 return;
24937 else
24938 if Reporting then
24940 -- Find some superfluous named actual that did not get
24941 -- attached to the list of associations.
24943 Actual := First (Actuals);
24944 while Present (Actual) loop
24945 if Nkind (Actual) = N_Parameter_Association
24946 and then Actual /= Last
24947 and then No (Next_Named_Actual (Actual))
24948 then
24949 -- A validity check may introduce a copy of a call that
24950 -- includes an extra actual (for example for an unrelated
24951 -- accessibility check). Check that the extra actual matches
24952 -- some extra formal, which must exist already because
24953 -- subprogram must be frozen at this point.
24955 if Present (Extra_Formals (S))
24956 and then not Comes_From_Source (Actual)
24957 and then Nkind (Actual) = N_Parameter_Association
24958 and then Chars (Extra_Formals (S)) =
24959 Chars (Selector_Name (Actual))
24960 then
24961 null;
24962 else
24963 Error_Msg_N
24964 ("unmatched actual & in call", Selector_Name (Actual));
24965 exit;
24966 end if;
24967 end if;
24969 Next (Actual);
24970 end loop;
24971 end if;
24973 Success := False;
24974 return;
24975 end if;
24976 end Normalize_Actuals;
24978 --------------------------------
24979 -- Note_Possible_Modification --
24980 --------------------------------
24982 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
24983 Modification_Comes_From_Source : constant Boolean :=
24984 Comes_From_Source (Parent (N));
24986 Ent : Entity_Id;
24987 Exp : Node_Id;
24989 begin
24990 -- Loop to find referenced entity, if there is one
24992 Exp := N;
24993 loop
24994 Ent := Empty;
24996 if Is_Entity_Name (Exp) then
24997 Ent := Entity (Exp);
24999 -- If the entity is missing, it is an undeclared identifier,
25000 -- and there is nothing to annotate.
25002 if No (Ent) then
25003 return;
25004 end if;
25006 elsif Nkind (Exp) = N_Explicit_Dereference then
25007 declare
25008 P : constant Node_Id := Prefix (Exp);
25010 begin
25011 -- In formal verification mode, keep track of all reads and
25012 -- writes through explicit dereferences.
25014 if GNATprove_Mode then
25015 SPARK_Specific.Generate_Dereference (N, 'm');
25016 end if;
25018 if Nkind (P) = N_Selected_Component
25019 and then Present (Entry_Formal (Entity (Selector_Name (P))))
25020 then
25021 -- Case of a reference to an entry formal
25023 Ent := Entry_Formal (Entity (Selector_Name (P)));
25025 elsif Nkind (P) = N_Identifier
25026 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
25027 and then Present (Expression (Parent (Entity (P))))
25028 and then Nkind (Expression (Parent (Entity (P)))) =
25029 N_Reference
25030 then
25031 -- Case of a reference to a value on which side effects have
25032 -- been removed.
25034 Exp := Prefix (Expression (Parent (Entity (P))));
25035 goto Continue;
25037 else
25038 return;
25039 end if;
25040 end;
25042 elsif Nkind (Exp) in N_Type_Conversion | N_Unchecked_Type_Conversion
25043 then
25044 Exp := Expression (Exp);
25045 goto Continue;
25047 elsif Nkind (Exp) in
25048 N_Slice | N_Indexed_Component | N_Selected_Component
25049 then
25050 -- Special check, if the prefix is an access type, then return
25051 -- since we are modifying the thing pointed to, not the prefix.
25052 -- When we are expanding, most usually the prefix is replaced
25053 -- by an explicit dereference, and this test is not needed, but
25054 -- in some cases (notably -gnatc mode and generics) when we do
25055 -- not do full expansion, we need this special test.
25057 if Is_Access_Type (Etype (Prefix (Exp))) then
25058 return;
25060 -- Otherwise go to prefix and keep going
25062 else
25063 Exp := Prefix (Exp);
25064 goto Continue;
25065 end if;
25067 -- All other cases, not a modification
25069 else
25070 return;
25071 end if;
25073 -- Now look for entity being referenced
25075 if Present (Ent) then
25076 if Is_Object (Ent) then
25077 if Comes_From_Source (Exp)
25078 or else Modification_Comes_From_Source
25079 then
25080 -- Give warning if pragma unmodified is given and we are
25081 -- sure this is a modification.
25083 if Has_Pragma_Unmodified (Ent) and then Sure then
25085 -- Note that the entity may be present only as a result
25086 -- of pragma Unused.
25088 if Has_Pragma_Unused (Ent) then
25089 Error_Msg_NE
25090 ("??aspect Unused specified for &!", N, Ent);
25091 else
25092 Error_Msg_NE
25093 ("??aspect Unmodified specified for &!", N, Ent);
25094 end if;
25095 end if;
25097 Set_Never_Set_In_Source (Ent, False);
25098 end if;
25100 Set_Is_True_Constant (Ent, False);
25101 Set_Current_Value (Ent, Empty);
25102 Set_Is_Known_Null (Ent, False);
25104 if not Can_Never_Be_Null (Ent) then
25105 Set_Is_Known_Non_Null (Ent, False);
25106 end if;
25108 -- Follow renaming chain
25110 if Ekind (Ent) in E_Variable | E_Constant
25111 and then Present (Renamed_Object (Ent))
25112 then
25113 Exp := Renamed_Object (Ent);
25115 -- If the entity is the loop variable in an iteration over
25116 -- a container, retrieve container expression to indicate
25117 -- possible modification.
25119 if Present (Related_Expression (Ent))
25120 and then Nkind (Parent (Related_Expression (Ent))) =
25121 N_Iterator_Specification
25122 then
25123 Exp := Original_Node (Related_Expression (Ent));
25124 end if;
25126 goto Continue;
25128 -- The expression may be the renaming of a subcomponent of an
25129 -- array or container. The assignment to the subcomponent is
25130 -- a modification of the container.
25132 elsif Comes_From_Source (Original_Node (Exp))
25133 and then Nkind (Original_Node (Exp)) in
25134 N_Selected_Component | N_Indexed_Component
25135 then
25136 Exp := Prefix (Original_Node (Exp));
25137 goto Continue;
25138 end if;
25140 -- Generate a reference only if the assignment comes from
25141 -- source. This excludes, for example, calls to a dispatching
25142 -- assignment operation when the left-hand side is tagged. In
25143 -- GNATprove mode, we need those references also on generated
25144 -- code, as these are used to compute the local effects of
25145 -- subprograms.
25147 if Modification_Comes_From_Source or GNATprove_Mode then
25148 Generate_Reference (Ent, Exp, 'm');
25150 -- If the target of the assignment is the bound variable
25151 -- in an iterator, indicate that the corresponding array
25152 -- or container is also modified.
25154 if Ada_Version >= Ada_2012
25155 and then Nkind (Parent (Ent)) = N_Iterator_Specification
25156 then
25157 declare
25158 Domain : constant Node_Id := Name (Parent (Ent));
25160 begin
25161 -- ??? In the full version of the construct, the
25162 -- domain of iteration can be given by an expression.
25164 if Is_Entity_Name (Domain) then
25165 Generate_Reference (Entity (Domain), Exp, 'm');
25166 Set_Is_True_Constant (Entity (Domain), False);
25167 Set_Never_Set_In_Source (Entity (Domain), False);
25168 end if;
25169 end;
25170 end if;
25171 end if;
25172 end if;
25174 Kill_Checks (Ent);
25176 -- If we are sure this is a modification from source, and we know
25177 -- this modifies a constant, then give an appropriate warning.
25179 if Sure
25180 and then Modification_Comes_From_Source
25181 and then Overlays_Constant (Ent)
25182 and then Address_Clause_Overlay_Warnings
25183 then
25184 declare
25185 Addr : constant Node_Id := Address_Clause (Ent);
25186 O_Ent : Entity_Id;
25187 Off : Boolean;
25189 begin
25190 Find_Overlaid_Entity (Addr, O_Ent, Off);
25192 Error_Msg_Sloc := Sloc (Addr);
25193 Error_Msg_NE
25194 ("?o?constant& may be modified via address clause#",
25195 N, O_Ent);
25196 end;
25197 end if;
25199 return;
25200 end if;
25202 <<Continue>>
25203 null;
25204 end loop;
25205 end Note_Possible_Modification;
25207 -----------------
25208 -- Null_Status --
25209 -----------------
25211 function Null_Status (N : Node_Id) return Null_Status_Kind is
25212 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
25213 -- Determine whether definition Def carries a null exclusion
25215 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
25216 -- Determine the null status of arbitrary entity Id
25218 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
25219 -- Determine the null status of type Typ
25221 ---------------------------
25222 -- Is_Null_Excluding_Def --
25223 ---------------------------
25225 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
25226 begin
25227 return Nkind (Def) in N_Access_Definition
25228 | N_Access_Function_Definition
25229 | N_Access_Procedure_Definition
25230 | N_Access_To_Object_Definition
25231 | N_Component_Definition
25232 | N_Derived_Type_Definition
25233 and then Null_Exclusion_Present (Def);
25234 end Is_Null_Excluding_Def;
25236 ---------------------------
25237 -- Null_Status_Of_Entity --
25238 ---------------------------
25240 function Null_Status_Of_Entity
25241 (Id : Entity_Id) return Null_Status_Kind
25243 Decl : constant Node_Id := Declaration_Node (Id);
25244 Def : Node_Id;
25246 begin
25247 -- The value of an imported or exported entity may be set externally
25248 -- regardless of a null exclusion. As a result, the value cannot be
25249 -- determined statically.
25251 if Is_Imported (Id) or else Is_Exported (Id) then
25252 return Unknown;
25254 elsif Nkind (Decl) in N_Component_Declaration
25255 | N_Discriminant_Specification
25256 | N_Formal_Object_Declaration
25257 | N_Object_Declaration
25258 | N_Object_Renaming_Declaration
25259 | N_Parameter_Specification
25260 then
25261 -- A component declaration yields a non-null value when either
25262 -- its component definition or access definition carries a null
25263 -- exclusion.
25265 if Nkind (Decl) = N_Component_Declaration then
25266 Def := Component_Definition (Decl);
25268 if Is_Null_Excluding_Def (Def) then
25269 return Is_Non_Null;
25270 end if;
25272 Def := Access_Definition (Def);
25274 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25275 return Is_Non_Null;
25276 end if;
25278 -- A formal object declaration yields a non-null value if its
25279 -- access definition carries a null exclusion. If the object is
25280 -- default initialized, then the value depends on the expression.
25282 elsif Nkind (Decl) = N_Formal_Object_Declaration then
25283 Def := Access_Definition (Decl);
25285 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25286 return Is_Non_Null;
25287 end if;
25289 -- A constant may yield a null or non-null value depending on its
25290 -- initialization expression.
25292 elsif Ekind (Id) = E_Constant then
25293 return Null_Status (Constant_Value (Id));
25295 -- The construct yields a non-null value when it has a null
25296 -- exclusion.
25298 elsif Null_Exclusion_Present (Decl) then
25299 return Is_Non_Null;
25301 -- An object renaming declaration yields a non-null value if its
25302 -- access definition carries a null exclusion. Otherwise the value
25303 -- depends on the renamed name.
25305 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
25306 Def := Access_Definition (Decl);
25308 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25309 return Is_Non_Null;
25311 else
25312 return Null_Status (Name (Decl));
25313 end if;
25314 end if;
25315 end if;
25317 -- At this point the declaration of the entity does not carry a null
25318 -- exclusion and lacks an initialization expression. Check the status
25319 -- of its type.
25321 return Null_Status_Of_Type (Etype (Id));
25322 end Null_Status_Of_Entity;
25324 -------------------------
25325 -- Null_Status_Of_Type --
25326 -------------------------
25328 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
25329 Curr : Entity_Id;
25330 Decl : Node_Id;
25332 begin
25333 -- Traverse the type chain looking for types with null exclusion
25335 Curr := Typ;
25336 while Present (Curr) and then Etype (Curr) /= Curr loop
25337 Decl := Parent (Curr);
25339 -- Guard against itypes which do not always have declarations. A
25340 -- type yields a non-null value if it carries a null exclusion.
25342 if Present (Decl) then
25343 if Nkind (Decl) = N_Full_Type_Declaration
25344 and then Is_Null_Excluding_Def (Type_Definition (Decl))
25345 then
25346 return Is_Non_Null;
25348 elsif Nkind (Decl) = N_Subtype_Declaration
25349 and then Null_Exclusion_Present (Decl)
25350 then
25351 return Is_Non_Null;
25352 end if;
25353 end if;
25355 Curr := Etype (Curr);
25356 end loop;
25358 -- The type chain does not contain any null excluding types
25360 return Unknown;
25361 end Null_Status_Of_Type;
25363 -- Start of processing for Null_Status
25365 begin
25366 -- Prevent cascaded errors or infinite loops when trying to determine
25367 -- the null status of an erroneous construct.
25369 if Error_Posted (N) then
25370 return Unknown;
25372 -- An allocator always creates a non-null value
25374 elsif Nkind (N) = N_Allocator then
25375 return Is_Non_Null;
25377 -- Taking the 'Access of something yields a non-null value
25379 elsif Nkind (N) = N_Attribute_Reference
25380 and then Attribute_Name (N) in Name_Access
25381 | Name_Unchecked_Access
25382 | Name_Unrestricted_Access
25383 then
25384 return Is_Non_Null;
25386 -- "null" yields null
25388 elsif Nkind (N) = N_Null then
25389 return Is_Null;
25391 -- Check the status of the operand of a type conversion
25393 elsif Nkind (N) in N_Type_Conversion | N_Unchecked_Type_Conversion then
25394 return Null_Status (Expression (N));
25396 -- The input denotes a reference to an entity. Determine whether the
25397 -- entity or its type yields a null or non-null value.
25399 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
25400 return Null_Status_Of_Entity (Entity (N));
25401 end if;
25403 -- Otherwise it is not possible to determine the null status of the
25404 -- subexpression at compile time without resorting to simple flow
25405 -- analysis.
25407 return Unknown;
25408 end Null_Status;
25410 --------------------------------------
25411 -- Null_To_Null_Address_Convert_OK --
25412 --------------------------------------
25414 function Null_To_Null_Address_Convert_OK
25415 (N : Node_Id;
25416 Typ : Entity_Id := Empty) return Boolean
25418 begin
25419 if not Relaxed_RM_Semantics then
25420 return False;
25421 end if;
25423 if Nkind (N) = N_Null then
25424 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
25426 elsif Nkind (N) in N_Op_Compare then
25427 declare
25428 L : constant Node_Id := Left_Opnd (N);
25429 R : constant Node_Id := Right_Opnd (N);
25431 begin
25432 -- We check the Etype of the complementary operand since the
25433 -- N_Null node is not decorated at this stage.
25435 return
25436 ((Nkind (L) = N_Null
25437 and then Is_Descendant_Of_Address (Etype (R)))
25438 or else
25439 (Nkind (R) = N_Null
25440 and then Is_Descendant_Of_Address (Etype (L))));
25441 end;
25442 end if;
25444 return False;
25445 end Null_To_Null_Address_Convert_OK;
25447 ---------------------------------
25448 -- Number_Of_Elements_In_Array --
25449 ---------------------------------
25451 function Number_Of_Elements_In_Array (T : Entity_Id) return Nat is
25452 Indx : Node_Id;
25453 Typ : Entity_Id;
25454 Low : Node_Id;
25455 High : Node_Id;
25456 Num : Nat := 1;
25458 begin
25459 pragma Assert (Is_Array_Type (T));
25461 Indx := First_Index (T);
25462 while Present (Indx) loop
25463 Typ := Underlying_Type (Etype (Indx));
25465 -- Never look at junk bounds of a generic type
25467 if Is_Generic_Type (Typ) then
25468 return 0;
25469 end if;
25471 -- Check the array bounds are known at compile time and return zero
25472 -- if they are not.
25474 Low := Type_Low_Bound (Typ);
25475 High := Type_High_Bound (Typ);
25477 if not Compile_Time_Known_Value (Low) then
25478 return 0;
25479 elsif not Compile_Time_Known_Value (High) then
25480 return 0;
25481 else
25482 Num :=
25483 Num * Int'Max
25484 (0, UI_To_Int (Expr_Value (High) - Expr_Value (Low) + Uint_1));
25485 end if;
25487 Next_Index (Indx);
25488 end loop;
25490 return Num;
25491 end Number_Of_Elements_In_Array;
25493 ---------------------------------
25494 -- Original_Aspect_Pragma_Name --
25495 ---------------------------------
25497 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
25498 Item : Node_Id;
25499 Item_Nam : Name_Id;
25501 begin
25502 pragma Assert (Nkind (N) in N_Aspect_Specification | N_Pragma);
25504 Item := N;
25506 -- The pragma was generated to emulate an aspect, use the original
25507 -- aspect specification.
25509 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
25510 Item := Corresponding_Aspect (Item);
25511 end if;
25513 -- Retrieve the name of the aspect/pragma. As assertion pragmas from
25514 -- a generic instantiation might have been rewritten into pragma Check,
25515 -- we look at the original node for Item. Note also that Pre, Pre_Class,
25516 -- Post and Post_Class rewrite their pragma identifier to preserve the
25517 -- original name, so we look at the original node for the identifier.
25518 -- ??? this is kludgey
25520 if Nkind (Item) = N_Pragma then
25521 Item_Nam :=
25522 Chars (Original_Node (Pragma_Identifier (Original_Node (Item))));
25524 if Item_Nam = Name_Check then
25525 -- Pragma "Check" preserves the original pragma name as its first
25526 -- argument.
25527 Item_Nam :=
25528 Chars (Expression (First (Pragma_Argument_Associations
25529 (Original_Node (Item)))));
25530 end if;
25532 else
25533 pragma Assert (Nkind (Item) = N_Aspect_Specification);
25534 Item_Nam := Chars (Identifier (Item));
25535 end if;
25537 -- Deal with 'Class by converting the name to its _XXX form
25539 if Class_Present (Item) then
25540 if Item_Nam = Name_Invariant then
25541 Item_Nam := Name_uInvariant;
25543 elsif Item_Nam = Name_Post then
25544 Item_Nam := Name_uPost;
25546 elsif Item_Nam = Name_Pre then
25547 Item_Nam := Name_uPre;
25549 elsif Item_Nam in Name_Type_Invariant | Name_Type_Invariant_Class
25550 then
25551 Item_Nam := Name_uType_Invariant;
25553 -- Nothing to do for other cases (e.g. a Check that derived from
25554 -- Pre_Class and has the flag set). Also we do nothing if the name
25555 -- is already in special _xxx form.
25557 end if;
25558 end if;
25560 return Item_Nam;
25561 end Original_Aspect_Pragma_Name;
25563 --------------------------------------
25564 -- Original_Corresponding_Operation --
25565 --------------------------------------
25567 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
25569 Typ : constant Entity_Id := Find_Dispatching_Type (S);
25571 begin
25572 -- If S is an inherited primitive S2 the original corresponding
25573 -- operation of S is the original corresponding operation of S2
25575 if Present (Alias (S))
25576 and then Find_Dispatching_Type (Alias (S)) /= Typ
25577 then
25578 return Original_Corresponding_Operation (Alias (S));
25580 -- If S overrides an inherited subprogram S2 the original corresponding
25581 -- operation of S is the original corresponding operation of S2
25583 elsif Present (Overridden_Operation (S)) then
25584 return Original_Corresponding_Operation (Overridden_Operation (S));
25586 -- otherwise it is S itself
25588 else
25589 return S;
25590 end if;
25591 end Original_Corresponding_Operation;
25593 -----------------------------------
25594 -- Original_View_In_Visible_Part --
25595 -----------------------------------
25597 function Original_View_In_Visible_Part
25598 (Typ : Entity_Id) return Boolean
25600 Scop : constant Entity_Id := Scope (Typ);
25602 begin
25603 -- The scope must be a package
25605 if not Is_Package_Or_Generic_Package (Scop) then
25606 return False;
25607 end if;
25609 -- A type with a private declaration has a private view declared in
25610 -- the visible part.
25612 if Has_Private_Declaration (Typ) then
25613 return True;
25614 end if;
25616 return List_Containing (Parent (Typ)) =
25617 Visible_Declarations (Package_Specification (Scop));
25618 end Original_View_In_Visible_Part;
25620 -------------------
25621 -- Output_Entity --
25622 -------------------
25624 procedure Output_Entity (Id : Entity_Id) is
25625 Scop : Entity_Id;
25627 begin
25628 Scop := Scope (Id);
25630 -- The entity may lack a scope when it is in the process of being
25631 -- analyzed. Use the current scope as an approximation.
25633 if No (Scop) then
25634 Scop := Current_Scope;
25635 end if;
25637 Output_Name (Chars (Id), Scop);
25638 end Output_Entity;
25640 -----------------
25641 -- Output_Name --
25642 -----------------
25644 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
25645 begin
25646 Write_Str
25647 (Get_Name_String
25648 (Get_Qualified_Name
25649 (Nam => Nam,
25650 Suffix => No_Name,
25651 Scop => Scop)));
25652 Write_Eol;
25653 end Output_Name;
25655 ------------------
25656 -- Param_Entity --
25657 ------------------
25659 -- This would be trivial, simply a test for an identifier that was a
25660 -- reference to a formal, if it were not for the fact that a previous call
25661 -- to Expand_Entry_Parameter will have modified the reference to the
25662 -- identifier. A formal of a protected entity is rewritten as
25664 -- typ!(recobj).rec.all'Constrained
25666 -- where rec is a selector whose Entry_Formal link points to the formal
25668 -- If the type of the entry parameter has a representation clause, then an
25669 -- extra temp is involved (see below).
25671 -- For a formal of a task entity, the formal is rewritten as a local
25672 -- renaming.
25674 -- In addition, a formal that is marked volatile because it is aliased
25675 -- through an address clause is rewritten as dereference as well.
25677 function Param_Entity (N : Node_Id) return Entity_Id is
25678 Renamed_Obj : Node_Id;
25680 begin
25681 -- Simple reference case
25683 if Nkind (N) in N_Identifier | N_Expanded_Name then
25684 if Is_Formal (Entity (N)) then
25685 return Entity (N);
25687 -- Handle renamings of formal parameters and formals of tasks that
25688 -- are rewritten as renamings.
25690 elsif Nkind (Parent (Entity (N))) = N_Object_Renaming_Declaration then
25691 Renamed_Obj := Get_Referenced_Object (Renamed_Object (Entity (N)));
25693 if Is_Entity_Name (Renamed_Obj)
25694 and then Is_Formal (Entity (Renamed_Obj))
25695 then
25696 return Entity (Renamed_Obj);
25698 elsif
25699 Nkind (Parent (Parent (Entity (N)))) = N_Accept_Statement
25700 then
25701 return Entity (N);
25702 end if;
25703 end if;
25705 else
25706 if Nkind (N) = N_Explicit_Dereference then
25707 declare
25708 P : Node_Id := Prefix (N);
25709 S : Node_Id;
25710 E : Entity_Id;
25711 Decl : Node_Id;
25713 begin
25714 -- If the type of an entry parameter has a representation
25715 -- clause, then the prefix is not a selected component, but
25716 -- instead a reference to a temp pointing at the selected
25717 -- component. In this case, set P to be the initial value of
25718 -- that temp.
25720 if Nkind (P) = N_Identifier then
25721 E := Entity (P);
25723 if Ekind (E) = E_Constant then
25724 Decl := Parent (E);
25726 if Nkind (Decl) = N_Object_Declaration then
25727 P := Expression (Decl);
25728 end if;
25729 end if;
25730 end if;
25732 if Nkind (P) = N_Selected_Component then
25733 S := Selector_Name (P);
25735 if Present (Entry_Formal (Entity (S))) then
25736 return Entry_Formal (Entity (S));
25737 end if;
25739 elsif Nkind (Original_Node (N)) = N_Identifier then
25740 return Param_Entity (Original_Node (N));
25741 end if;
25742 end;
25743 end if;
25744 end if;
25746 return Empty;
25747 end Param_Entity;
25749 ----------------------
25750 -- Policy_In_Effect --
25751 ----------------------
25753 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
25754 function Policy_In_List (List : Node_Id) return Name_Id;
25755 -- Determine the mode of a policy in a N_Pragma list
25757 --------------------
25758 -- Policy_In_List --
25759 --------------------
25761 function Policy_In_List (List : Node_Id) return Name_Id is
25762 Arg1 : Node_Id;
25763 Arg2 : Node_Id;
25764 Prag : Node_Id;
25766 begin
25767 Prag := List;
25768 while Present (Prag) loop
25769 Arg1 := First (Pragma_Argument_Associations (Prag));
25770 Arg2 := Next (Arg1);
25772 Arg1 := Get_Pragma_Arg (Arg1);
25773 Arg2 := Get_Pragma_Arg (Arg2);
25775 -- The current Check_Policy pragma matches the requested policy or
25776 -- appears in the single argument form (Assertion, policy_id).
25778 if Chars (Arg1) in Name_Assertion | Policy then
25779 return Chars (Arg2);
25780 end if;
25782 Prag := Next_Pragma (Prag);
25783 end loop;
25785 return No_Name;
25786 end Policy_In_List;
25788 -- Local variables
25790 Kind : Name_Id;
25792 -- Start of processing for Policy_In_Effect
25794 begin
25795 if not Is_Valid_Assertion_Kind (Policy) then
25796 raise Program_Error;
25797 end if;
25799 -- Inspect all policy pragmas that appear within scopes (if any)
25801 Kind := Policy_In_List (Check_Policy_List);
25803 -- Inspect all configuration policy pragmas (if any)
25805 if Kind = No_Name then
25806 Kind := Policy_In_List (Check_Policy_List_Config);
25807 end if;
25809 -- The context lacks policy pragmas, determine the mode based on whether
25810 -- assertions are enabled at the configuration level. This ensures that
25811 -- the policy is preserved when analyzing generics.
25813 if Kind = No_Name then
25814 if Assertions_Enabled_Config then
25815 Kind := Name_Check;
25816 else
25817 Kind := Name_Ignore;
25818 end if;
25819 end if;
25821 -- In CodePeer mode and GNATprove mode, we need to consider all
25822 -- assertions, unless they are disabled. Force Name_Check on
25823 -- ignored assertions.
25825 if Kind in Name_Ignore | Name_Off
25826 and then (CodePeer_Mode or GNATprove_Mode)
25827 then
25828 Kind := Name_Check;
25829 end if;
25831 return Kind;
25832 end Policy_In_Effect;
25834 -------------------------------------------
25835 -- Preanalyze_And_Resolve_Without_Errors --
25836 -------------------------------------------
25838 procedure Preanalyze_And_Resolve_Without_Errors (N : Node_Id) is
25839 Status : constant Boolean := Get_Ignore_Errors;
25840 begin
25841 Set_Ignore_Errors (True);
25842 Preanalyze_And_Resolve (N);
25843 Set_Ignore_Errors (Status);
25844 end Preanalyze_And_Resolve_Without_Errors;
25846 -------------------------------
25847 -- Preanalyze_Without_Errors --
25848 -------------------------------
25850 procedure Preanalyze_Without_Errors (N : Node_Id) is
25851 Status : constant Boolean := Get_Ignore_Errors;
25852 begin
25853 Set_Ignore_Errors (True);
25854 Preanalyze (N);
25855 Set_Ignore_Errors (Status);
25856 end Preanalyze_Without_Errors;
25858 -----------------------
25859 -- Predicate_Enabled --
25860 -----------------------
25862 function Predicate_Enabled (Typ : Entity_Id) return Boolean is
25863 begin
25864 return Present (Predicate_Function (Typ))
25865 and then not Predicates_Ignored (Typ)
25866 and then not Predicate_Checks_Suppressed (Empty);
25867 end Predicate_Enabled;
25869 ----------------------------------
25870 -- Predicate_Failure_Expression --
25871 ----------------------------------
25873 function Predicate_Failure_Expression
25874 (Typ : Entity_Id; Inherited_OK : Boolean) return Node_Id
25876 PF_Aspect : constant Node_Id :=
25877 Find_Aspect (Typ, Aspect_Predicate_Failure);
25878 begin
25879 -- Check for Predicate_Failure aspect specification via an
25880 -- aspect_specification (as opposed to via a pragma).
25882 if Present (PF_Aspect) then
25883 if Inherited_OK or else Entity (PF_Aspect) = Typ then
25884 return Expression (PF_Aspect);
25885 else
25886 return Empty;
25887 end if;
25888 end if;
25890 -- Check for Predicate_Failure aspect specification via a pragma.
25892 declare
25893 Rep_Item : Node_Id := First_Rep_Item (Typ);
25894 begin
25895 while Present (Rep_Item) loop
25896 if Nkind (Rep_Item) = N_Pragma
25897 and then Get_Pragma_Id (Rep_Item) = Pragma_Predicate_Failure
25898 then
25899 declare
25900 Arg1 : constant Node_Id :=
25901 Get_Pragma_Arg
25902 (First (Pragma_Argument_Associations (Rep_Item)));
25903 Arg2 : constant Node_Id :=
25904 Get_Pragma_Arg
25905 (Next (First (Pragma_Argument_Associations (Rep_Item))));
25906 begin
25907 if Inherited_OK or else
25908 (Nkind (Arg1) in N_Has_Entity
25909 and then Entity (Arg1) = Typ)
25910 then
25911 return Arg2;
25912 end if;
25913 end;
25914 end if;
25916 Next_Rep_Item (Rep_Item);
25917 end loop;
25918 end;
25920 -- If we are interested in an inherited Predicate_Failure aspect
25921 -- and we have an ancestor to inherit from, then recursively check
25922 -- for that case.
25924 if Inherited_OK and then Present (Nearest_Ancestor (Typ)) then
25925 return Predicate_Failure_Expression (Nearest_Ancestor (Typ),
25926 Inherited_OK => True);
25927 end if;
25929 return Empty;
25930 end Predicate_Failure_Expression;
25932 ----------------------------------
25933 -- Predicate_Tests_On_Arguments --
25934 ----------------------------------
25936 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
25937 begin
25938 -- Always test predicates on indirect call
25940 if Ekind (Subp) = E_Subprogram_Type then
25941 return True;
25943 -- Do not test predicates on call to generated default Finalize, since
25944 -- we are not interested in whether something we are finalizing (and
25945 -- typically destroying) satisfies its predicates.
25947 elsif Chars (Subp) = Name_Finalize
25948 and then not Comes_From_Source (Subp)
25949 then
25950 return False;
25952 -- Do not test predicates on any internally generated routines
25954 elsif Is_Internal_Name (Chars (Subp)) then
25955 return False;
25957 -- Do not test predicates on call to Init_Proc, since if needed the
25958 -- predicate test will occur at some other point.
25960 elsif Is_Init_Proc (Subp) then
25961 return False;
25963 -- Do not test predicates on call to predicate function, since this
25964 -- would cause infinite recursion.
25966 elsif Ekind (Subp) = E_Function
25967 and then Is_Predicate_Function (Subp)
25968 then
25969 return False;
25971 -- For now, no other exceptions
25973 else
25974 return True;
25975 end if;
25976 end Predicate_Tests_On_Arguments;
25978 -----------------------
25979 -- Private_Component --
25980 -----------------------
25982 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
25983 Ancestor : constant Entity_Id := Base_Type (Type_Id);
25985 function Trace_Components
25986 (T : Entity_Id;
25987 Check : Boolean) return Entity_Id;
25988 -- Recursive function that does the work, and checks against circular
25989 -- definition for each subcomponent type.
25991 ----------------------
25992 -- Trace_Components --
25993 ----------------------
25995 function Trace_Components
25996 (T : Entity_Id;
25997 Check : Boolean) return Entity_Id
25999 Btype : constant Entity_Id := Base_Type (T);
26000 Component : Entity_Id;
26001 P : Entity_Id;
26002 Candidate : Entity_Id := Empty;
26004 begin
26005 if Check and then Btype = Ancestor then
26006 Error_Msg_N ("circular type definition", Type_Id);
26007 return Any_Type;
26008 end if;
26010 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
26011 if Present (Full_View (Btype))
26012 and then Is_Record_Type (Full_View (Btype))
26013 and then not Is_Frozen (Btype)
26014 then
26015 -- To indicate that the ancestor depends on a private type, the
26016 -- current Btype is sufficient. However, to check for circular
26017 -- definition we must recurse on the full view.
26019 Candidate := Trace_Components (Full_View (Btype), True);
26021 if Candidate = Any_Type then
26022 return Any_Type;
26023 else
26024 return Btype;
26025 end if;
26027 else
26028 return Btype;
26029 end if;
26031 elsif Is_Array_Type (Btype) then
26032 return Trace_Components (Component_Type (Btype), True);
26034 elsif Is_Record_Type (Btype) then
26035 Component := First_Entity (Btype);
26036 while Present (Component)
26037 and then Comes_From_Source (Component)
26038 loop
26039 -- Skip anonymous types generated by constrained components
26041 if not Is_Type (Component) then
26042 P := Trace_Components (Etype (Component), True);
26044 if Present (P) then
26045 if P = Any_Type then
26046 return P;
26047 else
26048 Candidate := P;
26049 end if;
26050 end if;
26051 end if;
26053 Next_Entity (Component);
26054 end loop;
26056 return Candidate;
26058 else
26059 return Empty;
26060 end if;
26061 end Trace_Components;
26063 -- Start of processing for Private_Component
26065 begin
26066 return Trace_Components (Type_Id, False);
26067 end Private_Component;
26069 ---------------------------
26070 -- Primitive_Names_Match --
26071 ---------------------------
26073 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
26074 function Non_Internal_Name (E : Entity_Id) return Name_Id;
26075 -- Given an internal name, returns the corresponding non-internal name
26077 ------------------------
26078 -- Non_Internal_Name --
26079 ------------------------
26081 function Non_Internal_Name (E : Entity_Id) return Name_Id is
26082 begin
26083 Get_Name_String (Chars (E));
26084 Name_Len := Name_Len - 1;
26085 return Name_Find;
26086 end Non_Internal_Name;
26088 -- Start of processing for Primitive_Names_Match
26090 begin
26091 pragma Assert (Present (E1) and then Present (E2));
26093 return Chars (E1) = Chars (E2)
26094 or else
26095 (not Is_Internal_Name (Chars (E1))
26096 and then Is_Internal_Name (Chars (E2))
26097 and then Non_Internal_Name (E2) = Chars (E1))
26098 or else
26099 (not Is_Internal_Name (Chars (E2))
26100 and then Is_Internal_Name (Chars (E1))
26101 and then Non_Internal_Name (E1) = Chars (E2))
26102 or else
26103 (Is_Predefined_Dispatching_Operation (E1)
26104 and then Is_Predefined_Dispatching_Operation (E2)
26105 and then Same_TSS (E1, E2))
26106 or else
26107 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
26108 end Primitive_Names_Match;
26110 -----------------------
26111 -- Process_End_Label --
26112 -----------------------
26114 procedure Process_End_Label
26115 (N : Node_Id;
26116 Typ : Character;
26117 Ent : Entity_Id)
26119 Loc : Source_Ptr;
26120 Nam : Node_Id;
26121 Scop : Entity_Id;
26123 Label_Ref : Boolean;
26124 -- Set True if reference to end label itself is required
26126 Endl : Node_Id;
26127 -- Gets set to the operator symbol or identifier that references the
26128 -- entity Ent. For the child unit case, this is the identifier from the
26129 -- designator. For other cases, this is simply Endl.
26131 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
26132 -- N is an identifier node that appears as a parent unit reference in
26133 -- the case where Ent is a child unit. This procedure generates an
26134 -- appropriate cross-reference entry. E is the corresponding entity.
26136 -------------------------
26137 -- Generate_Parent_Ref --
26138 -------------------------
26140 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
26141 begin
26142 -- If names do not match, something weird, skip reference
26144 if Chars (E) = Chars (N) then
26146 -- Generate the reference. We do NOT consider this as a reference
26147 -- for unreferenced symbol purposes.
26149 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
26151 if Style_Check then
26152 Style.Check_Identifier (N, E);
26153 end if;
26154 end if;
26155 end Generate_Parent_Ref;
26157 -- Start of processing for Process_End_Label
26159 begin
26160 -- If no node, ignore. This happens in some error situations, and
26161 -- also for some internally generated structures where no end label
26162 -- references are required in any case.
26164 if No (N) then
26165 return;
26166 end if;
26168 -- Nothing to do if no End_Label, happens for internally generated
26169 -- constructs where we don't want an end label reference anyway. Also
26170 -- nothing to do if Endl is a string literal, which means there was
26171 -- some prior error (bad operator symbol)
26173 Endl := End_Label (N);
26175 if No (Endl) or else Nkind (Endl) = N_String_Literal then
26176 return;
26177 end if;
26179 -- Reference node is not in extended main source unit
26181 if not In_Extended_Main_Source_Unit (N) then
26183 -- Generally we do not collect references except for the extended
26184 -- main source unit. The one exception is the 'e' entry for a
26185 -- package spec, where it is useful for a client to have the
26186 -- ending information to define scopes.
26188 if Typ /= 'e' then
26189 return;
26191 else
26192 Label_Ref := False;
26194 -- For this case, we can ignore any parent references, but we
26195 -- need the package name itself for the 'e' entry.
26197 if Nkind (Endl) = N_Designator then
26198 Endl := Identifier (Endl);
26199 end if;
26200 end if;
26202 -- Reference is in extended main source unit
26204 else
26205 Label_Ref := True;
26207 -- For designator, generate references for the parent entries
26209 if Nkind (Endl) = N_Designator then
26211 -- Generate references for the prefix if the END line comes from
26212 -- source (otherwise we do not need these references) We climb the
26213 -- scope stack to find the expected entities.
26215 if Comes_From_Source (Endl) then
26216 Nam := Name (Endl);
26217 Scop := Current_Scope;
26218 while Nkind (Nam) = N_Selected_Component loop
26219 Scop := Scope (Scop);
26220 exit when No (Scop);
26221 Generate_Parent_Ref (Selector_Name (Nam), Scop);
26222 Nam := Prefix (Nam);
26223 end loop;
26225 if Present (Scop) then
26226 Generate_Parent_Ref (Nam, Scope (Scop));
26227 end if;
26228 end if;
26230 Endl := Identifier (Endl);
26231 end if;
26232 end if;
26234 -- If the end label is not for the given entity, then either we have
26235 -- some previous error, or this is a generic instantiation for which
26236 -- we do not need to make a cross-reference in this case anyway. In
26237 -- either case we simply ignore the call.
26239 if Chars (Ent) /= Chars (Endl) then
26240 return;
26241 end if;
26243 -- If label was really there, then generate a normal reference and then
26244 -- adjust the location in the end label to point past the name (which
26245 -- should almost always be the semicolon).
26247 Loc := Sloc (Endl);
26249 if Comes_From_Source (Endl) then
26251 -- If a label reference is required, then do the style check and
26252 -- generate an l-type cross-reference entry for the label
26254 if Label_Ref then
26255 if Style_Check then
26256 Style.Check_Identifier (Endl, Ent);
26257 end if;
26259 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
26260 end if;
26262 -- Set the location to point past the label (normally this will
26263 -- mean the semicolon immediately following the label). This is
26264 -- done for the sake of the 'e' or 't' entry generated below.
26266 Get_Decoded_Name_String (Chars (Endl));
26267 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
26268 end if;
26270 -- Now generate the e/t reference
26272 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
26274 -- Restore Sloc, in case modified above, since we have an identifier
26275 -- and the normal Sloc should be left set in the tree.
26277 Set_Sloc (Endl, Loc);
26278 end Process_End_Label;
26280 --------------------------------
26281 -- Propagate_Concurrent_Flags --
26282 --------------------------------
26284 procedure Propagate_Concurrent_Flags
26285 (Typ : Entity_Id;
26286 Comp_Typ : Entity_Id)
26288 begin
26289 if Has_Task (Comp_Typ) then
26290 Set_Has_Task (Typ);
26291 end if;
26293 if Has_Protected (Comp_Typ) then
26294 Set_Has_Protected (Typ);
26295 end if;
26297 if Has_Timing_Event (Comp_Typ) then
26298 Set_Has_Timing_Event (Typ);
26299 end if;
26300 end Propagate_Concurrent_Flags;
26302 --------------------------------
26303 -- Propagate_Controlled_Flags --
26304 --------------------------------
26306 procedure Propagate_Controlled_Flags
26307 (Typ : Entity_Id;
26308 From_Typ : Entity_Id;
26309 Comp : Boolean := False;
26310 Deriv : Boolean := False)
26312 begin
26313 -- It does not make sense to have both Comp and Deriv set True
26315 pragma Assert (not Comp or else not Deriv);
26317 -- This implementation only supports array types for the component case.
26318 -- Disregard Is_Controlled_Active and Disable_Controlled in this case.
26320 if Comp then
26321 pragma Assert (Is_Array_Type (Typ));
26323 else
26324 if Is_Controlled_Active (From_Typ) then
26325 Set_Is_Controlled_Active (Typ);
26326 end if;
26328 if Disable_Controlled (From_Typ) then
26329 Set_Disable_Controlled (Typ);
26330 end if;
26331 end if;
26333 -- Direct controlled types do not inherit Finalize_Storage_Only
26335 if not (Deriv and then Is_Controlled (From_Typ)) then
26336 if Finalize_Storage_Only (From_Typ) then
26337 Set_Finalize_Storage_Only (Typ);
26338 end if;
26339 end if;
26341 -- Is_Controlled yields Has_Controlled_Component for component
26343 if Has_Controlled_Component (From_Typ)
26344 or else (Comp and then Is_Controlled (From_Typ))
26345 then
26346 Set_Has_Controlled_Component (Typ);
26347 end if;
26349 if Has_Relaxed_Finalization (From_Typ) then
26350 Set_Has_Relaxed_Finalization (Typ);
26351 end if;
26352 end Propagate_Controlled_Flags;
26354 ------------------------------
26355 -- Propagate_DIC_Attributes --
26356 ------------------------------
26358 procedure Propagate_DIC_Attributes
26359 (Typ : Entity_Id;
26360 From_Typ : Entity_Id)
26362 DIC_Proc : Entity_Id;
26363 Partial_DIC_Proc : Entity_Id;
26365 begin
26366 if Present (Typ) and then Present (From_Typ) then
26367 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26369 -- Nothing to do if both the source and the destination denote the
26370 -- same type.
26372 if From_Typ = Typ then
26373 return;
26375 -- Nothing to do when the destination denotes an incomplete type
26376 -- because the DIC is associated with the current instance of a
26377 -- private type, thus it can never apply to an incomplete type.
26379 elsif Is_Incomplete_Type (Typ) then
26380 return;
26381 end if;
26383 DIC_Proc := DIC_Procedure (From_Typ);
26384 Partial_DIC_Proc := Partial_DIC_Procedure (From_Typ);
26386 -- The setting of the attributes is intentionally conservative. This
26387 -- prevents accidental clobbering of enabled attributes. We need to
26388 -- call Base_Type twice, because it is sometimes not set to an actual
26389 -- base type???
26391 if Has_Inherited_DIC (From_Typ) then
26392 Set_Has_Inherited_DIC (Base_Type (Base_Type (Typ)));
26393 end if;
26395 if Has_Own_DIC (From_Typ) then
26396 Set_Has_Own_DIC (Base_Type (Base_Type (Typ)));
26397 end if;
26399 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
26400 Set_DIC_Procedure (Typ, DIC_Proc);
26401 end if;
26403 if Present (Partial_DIC_Proc)
26404 and then No (Partial_DIC_Procedure (Typ))
26405 then
26406 Set_Partial_DIC_Procedure (Typ, Partial_DIC_Proc);
26407 end if;
26408 end if;
26409 end Propagate_DIC_Attributes;
26411 ------------------------------------
26412 -- Propagate_Invariant_Attributes --
26413 ------------------------------------
26415 procedure Propagate_Invariant_Attributes
26416 (Typ : Entity_Id;
26417 From_Typ : Entity_Id)
26419 Full_IP : Entity_Id;
26420 Part_IP : Entity_Id;
26422 begin
26423 if Present (Typ) and then Present (From_Typ) then
26424 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26426 -- Nothing to do if both the source and the destination denote the
26427 -- same type.
26429 if From_Typ = Typ then
26430 return;
26431 end if;
26433 Full_IP := Invariant_Procedure (From_Typ);
26434 Part_IP := Partial_Invariant_Procedure (From_Typ);
26436 -- The setting of the attributes is intentionally conservative. This
26437 -- prevents accidental clobbering of enabled attributes. We need to
26438 -- call Base_Type twice, because it is sometimes not set to an actual
26439 -- base type???
26441 if Has_Inheritable_Invariants (From_Typ) then
26442 Set_Has_Inheritable_Invariants (Base_Type (Base_Type (Typ)));
26443 end if;
26445 if Has_Inherited_Invariants (From_Typ) then
26446 Set_Has_Inherited_Invariants (Base_Type (Base_Type (Typ)));
26447 end if;
26449 if Has_Own_Invariants (From_Typ) then
26450 Set_Has_Own_Invariants (Base_Type (Base_Type (Typ)));
26451 end if;
26453 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
26454 Set_Invariant_Procedure (Typ, Full_IP);
26455 end if;
26457 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
26458 then
26459 Set_Partial_Invariant_Procedure (Typ, Part_IP);
26460 end if;
26461 end if;
26462 end Propagate_Invariant_Attributes;
26464 ------------------------------------
26465 -- Propagate_Predicate_Attributes --
26466 ------------------------------------
26468 procedure Propagate_Predicate_Attributes
26469 (Typ : Entity_Id;
26470 From_Typ : Entity_Id)
26472 Pred_Func : Entity_Id;
26473 begin
26474 if Present (Typ) and then Present (From_Typ) then
26475 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26477 -- Nothing to do if both the source and the destination denote the
26478 -- same type.
26480 if From_Typ = Typ then
26481 return;
26482 end if;
26484 Pred_Func := Predicate_Function (From_Typ);
26486 -- The setting of the attributes is intentionally conservative. This
26487 -- prevents accidental clobbering of enabled attributes.
26489 if Has_Predicates (From_Typ) then
26490 Set_Has_Predicates (Typ);
26491 end if;
26493 if Present (Pred_Func) and then No (Predicate_Function (Typ)) then
26494 Set_Predicate_Function (Typ, Pred_Func);
26495 end if;
26496 end if;
26497 end Propagate_Predicate_Attributes;
26499 ---------------------------------------
26500 -- Record_Possible_Part_Of_Reference --
26501 ---------------------------------------
26503 procedure Record_Possible_Part_Of_Reference
26504 (Var_Id : Entity_Id;
26505 Ref : Node_Id)
26507 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
26508 Refs : Elist_Id;
26510 begin
26511 -- The variable is a constituent of a single protected/task type. Such
26512 -- a variable acts as a component of the type and must appear within a
26513 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
26514 -- verify its legality now.
26516 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
26517 Check_Part_Of_Reference (Var_Id, Ref);
26519 -- The variable is subject to pragma Part_Of and may eventually become a
26520 -- constituent of a single protected/task type. Record the reference to
26521 -- verify its placement when the contract of the variable is analyzed.
26523 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
26524 Refs := Part_Of_References (Var_Id);
26526 if No (Refs) then
26527 Refs := New_Elmt_List;
26528 Set_Part_Of_References (Var_Id, Refs);
26529 end if;
26531 Append_Elmt (Ref, Refs);
26532 end if;
26533 end Record_Possible_Part_Of_Reference;
26535 ----------------
26536 -- Referenced --
26537 ----------------
26539 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
26540 Seen : Boolean := False;
26542 function Is_Reference (N : Node_Id) return Traverse_Result;
26543 -- Determine whether node N denotes a reference to Id. If this is the
26544 -- case, set global flag Seen to True and stop the traversal.
26546 ------------------
26547 -- Is_Reference --
26548 ------------------
26550 function Is_Reference (N : Node_Id) return Traverse_Result is
26551 begin
26552 if Is_Entity_Name (N)
26553 and then Present (Entity (N))
26554 and then Entity (N) = Id
26555 then
26556 Seen := True;
26557 return Abandon;
26558 else
26559 return OK;
26560 end if;
26561 end Is_Reference;
26563 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
26565 -- Start of processing for Referenced
26567 begin
26568 Inspect_Expression (Expr);
26569 return Seen;
26570 end Referenced;
26572 ------------------------------------
26573 -- References_Generic_Formal_Type --
26574 ------------------------------------
26576 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
26578 function Process (N : Node_Id) return Traverse_Result;
26579 -- Process one node in search for generic formal type
26581 -------------
26582 -- Process --
26583 -------------
26585 function Process (N : Node_Id) return Traverse_Result is
26586 begin
26587 if Nkind (N) in N_Has_Entity then
26588 declare
26589 E : constant Entity_Id := Entity (N);
26590 begin
26591 if Present (E) then
26592 if Is_Generic_Type (E) then
26593 return Abandon;
26594 elsif Present (Etype (E))
26595 and then Is_Generic_Type (Etype (E))
26596 then
26597 return Abandon;
26598 end if;
26599 end if;
26600 end;
26601 end if;
26603 return Atree.OK;
26604 end Process;
26606 function Traverse is new Traverse_Func (Process);
26607 -- Traverse tree to look for generic type
26609 begin
26610 if Inside_A_Generic then
26611 return Traverse (N) = Abandon;
26612 else
26613 return False;
26614 end if;
26615 end References_Generic_Formal_Type;
26617 -------------------------------
26618 -- Remove_Entity_And_Homonym --
26619 -------------------------------
26621 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
26622 begin
26623 Remove_Entity (Id);
26624 Remove_Homonym (Id);
26625 end Remove_Entity_And_Homonym;
26627 --------------------
26628 -- Remove_Homonym --
26629 --------------------
26631 procedure Remove_Homonym (Id : Entity_Id) is
26632 Hom : Entity_Id;
26633 Prev : Entity_Id := Empty;
26635 begin
26636 if Id = Current_Entity (Id) then
26637 if Present (Homonym (Id)) then
26638 Set_Current_Entity (Homonym (Id));
26639 else
26640 Set_Name_Entity_Id (Chars (Id), Empty);
26641 end if;
26643 else
26644 Hom := Current_Entity (Id);
26645 while Present (Hom) and then Hom /= Id loop
26646 Prev := Hom;
26647 Hom := Homonym (Hom);
26648 end loop;
26650 -- If Id is not on the homonym chain, nothing to do
26652 if Present (Hom) then
26653 Set_Homonym (Prev, Homonym (Id));
26654 end if;
26655 end if;
26656 end Remove_Homonym;
26658 ------------------------------
26659 -- Remove_Overloaded_Entity --
26660 ------------------------------
26662 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
26663 procedure Remove_Primitive_Of (Typ : Entity_Id);
26664 -- Remove primitive subprogram Id from the list of primitives that
26665 -- belong to type Typ.
26667 -------------------------
26668 -- Remove_Primitive_Of --
26669 -------------------------
26671 procedure Remove_Primitive_Of (Typ : Entity_Id) is
26672 Prims : Elist_Id;
26674 begin
26675 if Is_Tagged_Type (Typ) then
26676 Prims := Direct_Primitive_Operations (Typ);
26678 if Present (Prims) then
26679 Remove (Prims, Id);
26680 end if;
26681 end if;
26682 end Remove_Primitive_Of;
26684 -- Local variables
26686 Formal : Entity_Id;
26688 -- Start of processing for Remove_Overloaded_Entity
26690 begin
26691 Remove_Entity_And_Homonym (Id);
26693 -- The entity denotes a primitive subprogram. Remove it from the list of
26694 -- primitives of the associated controlling type.
26696 if Ekind (Id) in E_Function | E_Procedure and then Is_Primitive (Id) then
26697 Formal := First_Formal (Id);
26698 while Present (Formal) loop
26699 if Is_Controlling_Formal (Formal) then
26700 Remove_Primitive_Of (Etype (Formal));
26701 exit;
26702 end if;
26704 Next_Formal (Formal);
26705 end loop;
26707 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
26708 Remove_Primitive_Of (Etype (Id));
26709 end if;
26710 end if;
26711 end Remove_Overloaded_Entity;
26713 ---------------------
26714 -- Rep_To_Pos_Flag --
26715 ---------------------
26717 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
26718 begin
26719 return New_Occurrence_Of
26720 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
26721 end Rep_To_Pos_Flag;
26723 --------------------
26724 -- Require_Entity --
26725 --------------------
26727 procedure Require_Entity (N : Node_Id) is
26728 begin
26729 if Is_Entity_Name (N) and then No (Entity (N)) then
26730 if Total_Errors_Detected /= 0 then
26731 Set_Entity (N, Any_Id);
26732 else
26733 raise Program_Error;
26734 end if;
26735 end if;
26736 end Require_Entity;
26738 ------------------------------
26739 -- Requires_Transient_Scope --
26740 ------------------------------
26742 function Requires_Transient_Scope (Typ : Entity_Id) return Boolean is
26743 begin
26744 return Needs_Secondary_Stack (Typ) or else Needs_Finalization (Typ);
26745 end Requires_Transient_Scope;
26747 --------------------------
26748 -- Reset_Analyzed_Flags --
26749 --------------------------
26751 procedure Reset_Analyzed_Flags (N : Node_Id) is
26752 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
26753 -- Function used to reset Analyzed flags in tree. Note that we do
26754 -- not reset Analyzed flags in entities, since there is no need to
26755 -- reanalyze entities, and indeed, it is wrong to do so, since it
26756 -- can result in generating auxiliary stuff more than once.
26758 --------------------
26759 -- Clear_Analyzed --
26760 --------------------
26762 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
26763 begin
26764 if Nkind (N) not in N_Entity then
26765 Set_Analyzed (N, False);
26766 end if;
26768 return OK;
26769 end Clear_Analyzed;
26771 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
26773 -- Start of processing for Reset_Analyzed_Flags
26775 begin
26776 Reset_Analyzed (N);
26777 end Reset_Analyzed_Flags;
26779 ------------------------
26780 -- Restore_SPARK_Mode --
26781 ------------------------
26783 procedure Restore_SPARK_Mode
26784 (Mode : SPARK_Mode_Type;
26785 Prag : Node_Id)
26787 begin
26788 SPARK_Mode := Mode;
26789 SPARK_Mode_Pragma := Prag;
26790 end Restore_SPARK_Mode;
26792 --------------------------------
26793 -- Returns_Unconstrained_Type --
26794 --------------------------------
26796 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
26797 begin
26798 return Ekind (Subp) = E_Function
26799 and then not Is_Scalar_Type (Etype (Subp))
26800 and then not Is_Access_Type (Etype (Subp))
26801 and then not Is_Constrained (Etype (Subp));
26802 end Returns_Unconstrained_Type;
26804 ----------------------------
26805 -- Root_Type_Of_Full_View --
26806 ----------------------------
26808 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
26809 Rtyp : constant Entity_Id := Root_Type (T);
26811 begin
26812 -- The root type of the full view may itself be a private type. Keep
26813 -- looking for the ultimate derivation parent.
26815 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
26816 return Root_Type_Of_Full_View (Full_View (Rtyp));
26817 else
26818 return Rtyp;
26819 end if;
26820 end Root_Type_Of_Full_View;
26822 ---------------------------
26823 -- Safe_To_Capture_Value --
26824 ---------------------------
26826 function Safe_To_Capture_Value
26827 (N : Node_Id;
26828 Ent : Entity_Id;
26829 Cond : Boolean := False) return Boolean
26831 begin
26832 -- The only entities for which we track constant values are variables
26833 -- that are not renamings, constants and formal parameters, so check
26834 -- if we have this case.
26836 -- Note: it may seem odd to track constant values for constants, but in
26837 -- fact this routine is used for other purposes than simply capturing
26838 -- the value. In particular, the setting of Known[_Non]_Null and
26839 -- Is_Known_Valid.
26841 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
26842 or else
26843 Ekind (Ent) = E_Constant
26844 or else
26845 Is_Formal (Ent)
26846 then
26847 null;
26849 -- For conditionals, we also allow loop parameters
26851 elsif Cond and then Ekind (Ent) = E_Loop_Parameter then
26852 null;
26854 -- For all other cases, not just unsafe, but impossible to capture
26855 -- Current_Value, since the above are the only entities which have
26856 -- Current_Value fields.
26858 else
26859 return False;
26860 end if;
26862 -- Skip if volatile or aliased, since funny things might be going on in
26863 -- these cases which we cannot necessarily track. Also skip any variable
26864 -- for which an address clause is given, or whose address is taken. Also
26865 -- never capture value of library level variables (an attempt to do so
26866 -- can occur in the case of package elaboration code).
26868 if Treat_As_Volatile (Ent)
26869 or else Is_Aliased (Ent)
26870 or else Present (Address_Clause (Ent))
26871 or else Address_Taken (Ent)
26872 or else (Is_Library_Level_Entity (Ent)
26873 and then Ekind (Ent) = E_Variable)
26874 then
26875 return False;
26876 end if;
26878 -- OK, all above conditions are met. We also require that the scope of
26879 -- the reference be the same as the scope of the entity, not counting
26880 -- packages and blocks and loops.
26882 declare
26883 E_Scope : constant Entity_Id := Scope (Ent);
26884 R_Scope : Entity_Id;
26886 begin
26887 R_Scope := Current_Scope;
26888 while R_Scope /= Standard_Standard loop
26889 exit when R_Scope = E_Scope;
26891 if Ekind (R_Scope) not in E_Package | E_Block | E_Loop then
26892 return False;
26893 else
26894 R_Scope := Scope (R_Scope);
26895 end if;
26896 end loop;
26897 end;
26899 -- We also require that the reference does not appear in a context
26900 -- where it is not sure to be executed (i.e. a conditional context
26901 -- or an exception handler). We skip this if Cond is True, since the
26902 -- capturing of values from conditional tests handles this ok.
26904 if Cond or else No (N) then
26905 return True;
26906 end if;
26908 declare
26909 Desc : Node_Id;
26910 P : Node_Id;
26912 begin
26913 Desc := N;
26915 -- Seems dubious that case expressions are not handled here ???
26917 P := Parent (N);
26918 while Present (P) loop
26919 if Is_Body (P) then
26920 return True;
26922 elsif Nkind (P) = N_If_Statement
26923 or else Nkind (P) = N_Case_Statement
26924 or else (Nkind (P) in N_Short_Circuit
26925 and then Desc = Right_Opnd (P))
26926 or else (Nkind (P) = N_If_Expression
26927 and then Desc /= First (Expressions (P)))
26928 or else Nkind (P) = N_Exception_Handler
26929 or else Nkind (P) = N_Selective_Accept
26930 or else Nkind (P) = N_Conditional_Entry_Call
26931 or else Nkind (P) = N_Timed_Entry_Call
26932 or else Nkind (P) = N_Asynchronous_Select
26933 then
26934 return False;
26936 else
26937 Desc := P;
26938 P := Parent (P);
26940 -- A special Ada 2012 case: the original node may be part
26941 -- of the else_actions of a conditional expression, in which
26942 -- case it might not have been expanded yet, and appears in
26943 -- a non-syntactic list of actions. In that case it is clearly
26944 -- not safe to save a value.
26946 if No (P)
26947 and then Is_List_Member (Desc)
26948 and then No (Parent (List_Containing (Desc)))
26949 then
26950 return False;
26951 end if;
26952 end if;
26953 end loop;
26954 end;
26956 -- OK, looks safe to set value
26958 return True;
26959 end Safe_To_Capture_Value;
26961 ---------------
26962 -- Same_Name --
26963 ---------------
26965 function Same_Name (N1, N2 : Node_Id) return Boolean is
26966 K1 : constant Node_Kind := Nkind (N1);
26967 K2 : constant Node_Kind := Nkind (N2);
26969 begin
26970 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
26971 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
26972 then
26973 return Chars (N1) = Chars (N2);
26975 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
26976 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
26977 then
26978 return Same_Name (Selector_Name (N1), Selector_Name (N2))
26979 and then Same_Name (Prefix (N1), Prefix (N2));
26981 else
26982 return False;
26983 end if;
26984 end Same_Name;
26986 -----------------
26987 -- Same_Object --
26988 -----------------
26990 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
26991 N1 : constant Node_Id := Original_Node (Node1);
26992 N2 : constant Node_Id := Original_Node (Node2);
26993 -- We do the tests on original nodes, since we are most interested
26994 -- in the original source, not any expansion that got in the way.
26996 K1 : constant Node_Kind := Nkind (N1);
26997 K2 : constant Node_Kind := Nkind (N2);
26999 begin
27000 -- First case, both are entities with same entity
27002 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
27003 declare
27004 EN1 : constant Entity_Id := Entity (N1);
27005 EN2 : constant Entity_Id := Entity (N2);
27006 begin
27007 if Present (EN1) and then Present (EN2)
27008 and then (Ekind (EN1) in E_Variable | E_Constant
27009 or else Is_Formal (EN1))
27010 and then EN1 = EN2
27011 then
27012 return True;
27013 end if;
27014 end;
27015 end if;
27017 -- Second case, selected component with same selector, same record
27019 if K1 = N_Selected_Component
27020 and then K2 = N_Selected_Component
27021 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
27022 then
27023 return Same_Object (Prefix (N1), Prefix (N2));
27025 -- Third case, indexed component with same subscripts, same array
27027 elsif K1 = N_Indexed_Component
27028 and then K2 = N_Indexed_Component
27029 and then Same_Object (Prefix (N1), Prefix (N2))
27030 then
27031 declare
27032 E1, E2 : Node_Id;
27033 begin
27034 E1 := First (Expressions (N1));
27035 E2 := First (Expressions (N2));
27036 while Present (E1) loop
27037 if not Same_Value (E1, E2) then
27038 return False;
27039 else
27040 Next (E1);
27041 Next (E2);
27042 end if;
27043 end loop;
27045 return True;
27046 end;
27048 -- Fourth case, slice of same array with same bounds
27050 elsif K1 = N_Slice
27051 and then K2 = N_Slice
27052 and then Nkind (Discrete_Range (N1)) = N_Range
27053 and then Nkind (Discrete_Range (N2)) = N_Range
27054 and then Same_Value (Low_Bound (Discrete_Range (N1)),
27055 Low_Bound (Discrete_Range (N2)))
27056 and then Same_Value (High_Bound (Discrete_Range (N1)),
27057 High_Bound (Discrete_Range (N2)))
27058 then
27059 return Same_Name (Prefix (N1), Prefix (N2));
27061 -- All other cases, not clearly the same object
27063 else
27064 return False;
27065 end if;
27066 end Same_Object;
27068 ---------------------------------
27069 -- Same_Or_Aliased_Subprograms --
27070 ---------------------------------
27072 function Same_Or_Aliased_Subprograms
27073 (S : Entity_Id;
27074 E : Entity_Id) return Boolean
27076 Subp_Alias : constant Entity_Id := Alias (S);
27077 Subp : Entity_Id := E;
27078 begin
27079 -- During expansion of subprograms with postconditions the original
27080 -- subprogram's declarations and statements get wrapped into a local
27081 -- _Wrapped_Statements subprogram.
27083 if Chars (Subp) = Name_uWrapped_Statements then
27084 Subp := Enclosing_Subprogram (Subp);
27085 end if;
27087 return S = Subp
27088 or else (Present (Subp_Alias) and then Subp_Alias = Subp);
27089 end Same_Or_Aliased_Subprograms;
27091 ---------------
27092 -- Same_Type --
27093 ---------------
27095 function Same_Type (T1, T2 : Entity_Id) return Boolean is
27096 begin
27097 if T1 = T2 then
27098 return True;
27100 elsif not Is_Constrained (T1)
27101 and then not Is_Constrained (T2)
27102 and then Base_Type (T1) = Base_Type (T2)
27103 then
27104 return True;
27106 -- For now don't bother with case of identical constraints, to be
27107 -- fiddled with later on perhaps (this is only used for optimization
27108 -- purposes, so it is not critical to do a best possible job)
27110 else
27111 return False;
27112 end if;
27113 end Same_Type;
27115 ----------------
27116 -- Same_Value --
27117 ----------------
27119 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
27120 begin
27121 if Compile_Time_Known_Value (Node1)
27122 and then Compile_Time_Known_Value (Node2)
27123 then
27124 -- Handle properly compile-time expressions that are not
27125 -- scalar.
27127 if Is_String_Type (Etype (Node1)) then
27128 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
27130 else
27131 return Expr_Value (Node1) = Expr_Value (Node2);
27132 end if;
27134 elsif Same_Object (Node1, Node2) then
27135 return True;
27136 else
27137 return False;
27138 end if;
27139 end Same_Value;
27141 --------------------
27142 -- Set_SPARK_Mode --
27143 --------------------
27145 procedure Set_SPARK_Mode (Context : Entity_Id) is
27146 begin
27147 -- Do not consider illegal or partially decorated constructs
27149 if Ekind (Context) = E_Void or else Error_Posted (Context) then
27150 null;
27152 elsif Present (SPARK_Pragma (Context)) then
27153 Install_SPARK_Mode
27154 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
27155 Prag => SPARK_Pragma (Context));
27156 end if;
27157 end Set_SPARK_Mode;
27159 -------------------------
27160 -- Scalar_Part_Present --
27161 -------------------------
27163 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
27164 Val_Typ : constant Entity_Id := Validated_View (Typ);
27165 Field : Entity_Id;
27167 begin
27168 if Is_Scalar_Type (Val_Typ) then
27169 return True;
27171 elsif Is_Array_Type (Val_Typ) then
27172 return Scalar_Part_Present (Component_Type (Val_Typ));
27174 elsif Is_Record_Type (Val_Typ) then
27175 Field := First_Component_Or_Discriminant (Val_Typ);
27176 while Present (Field) loop
27177 if Scalar_Part_Present (Etype (Field)) then
27178 return True;
27179 end if;
27181 Next_Component_Or_Discriminant (Field);
27182 end loop;
27183 end if;
27185 return False;
27186 end Scalar_Part_Present;
27188 ------------------------
27189 -- Scope_Is_Transient --
27190 ------------------------
27192 function Scope_Is_Transient return Boolean is
27193 begin
27194 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
27195 end Scope_Is_Transient;
27197 ------------------
27198 -- Scope_Within --
27199 ------------------
27201 function Scope_Within
27202 (Inner : Entity_Id;
27203 Outer : Entity_Id) return Boolean
27205 Curr : Entity_Id;
27207 begin
27208 Curr := Inner;
27209 while Present (Curr) and then Curr /= Standard_Standard loop
27210 Curr := Scope (Curr);
27212 if Curr = Outer then
27213 return True;
27215 -- A selective accept body appears within a task type, but the
27216 -- enclosing subprogram is the procedure of the task body.
27218 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
27219 and then
27220 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
27221 then
27222 return True;
27224 -- Ditto for the body of a protected operation
27226 elsif Is_Subprogram (Curr)
27227 and then Outer = Protected_Body_Subprogram (Curr)
27228 then
27229 return True;
27231 -- The body of a protected operation is within the protected type
27233 elsif Is_Subprogram (Curr)
27234 and then Present (Protected_Subprogram (Curr))
27235 and then Is_Protected_Type (Outer)
27236 and then Scope (Protected_Subprogram (Curr)) = Outer
27237 then
27238 return True;
27240 -- Outside of its scope, a synchronized type may just be private
27242 elsif Is_Private_Type (Curr)
27243 and then Present (Full_View (Curr))
27244 and then Is_Concurrent_Type (Full_View (Curr))
27245 then
27246 return Scope_Within (Full_View (Curr), Outer);
27247 end if;
27248 end loop;
27250 return False;
27251 end Scope_Within;
27253 --------------------------
27254 -- Scope_Within_Or_Same --
27255 --------------------------
27257 function Scope_Within_Or_Same
27258 (Inner : Entity_Id;
27259 Outer : Entity_Id) return Boolean
27261 Curr : Entity_Id := Inner;
27263 begin
27264 -- Similar to the above, but check for scope identity first
27266 while Present (Curr) and then Curr /= Standard_Standard loop
27267 if Curr = Outer then
27268 return True;
27270 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
27271 and then
27272 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
27273 then
27274 return True;
27276 elsif Is_Subprogram (Curr)
27277 and then Outer = Protected_Body_Subprogram (Curr)
27278 then
27279 return True;
27281 elsif Is_Subprogram (Curr)
27282 and then Present (Protected_Subprogram (Curr))
27283 and then Is_Protected_Type (Outer)
27284 and then Scope (Protected_Subprogram (Curr)) = Outer
27285 then
27286 return True;
27288 elsif Is_Private_Type (Curr)
27289 and then Present (Full_View (Curr))
27290 then
27291 if Full_View (Curr) = Outer then
27292 return True;
27293 else
27294 return Scope_Within (Full_View (Curr), Outer);
27295 end if;
27296 end if;
27298 Curr := Scope (Curr);
27299 end loop;
27301 return False;
27302 end Scope_Within_Or_Same;
27304 ------------------------
27305 -- Set_Current_Entity --
27306 ------------------------
27308 -- The given entity is to be set as the currently visible definition of its
27309 -- associated name (i.e. the Node_Id associated with its name). All we have
27310 -- to do is to get the name from the identifier, and then set the
27311 -- associated Node_Id to point to the given entity.
27313 procedure Set_Current_Entity (E : Entity_Id) is
27314 begin
27315 Set_Name_Entity_Id (Chars (E), E);
27316 end Set_Current_Entity;
27318 ---------------------------
27319 -- Set_Debug_Info_Needed --
27320 ---------------------------
27322 procedure Set_Debug_Info_Needed (T : Entity_Id) is
27324 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
27325 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
27326 -- Used to set debug info in a related node if not set already
27328 --------------------------------------
27329 -- Set_Debug_Info_Needed_If_Not_Set --
27330 --------------------------------------
27332 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
27333 begin
27334 if Present (E) and then not Needs_Debug_Info (E) then
27335 Set_Debug_Info_Needed (E);
27337 -- For a private type, indicate that the full view also needs
27338 -- debug information.
27340 if Is_Type (E)
27341 and then Is_Private_Type (E)
27342 and then Present (Full_View (E))
27343 then
27344 Set_Debug_Info_Needed (Full_View (E));
27345 end if;
27346 end if;
27347 end Set_Debug_Info_Needed_If_Not_Set;
27349 -- Start of processing for Set_Debug_Info_Needed
27351 begin
27352 -- Nothing to do if there is no available entity
27354 if No (T) then
27355 return;
27357 -- Nothing to do for an entity with suppressed debug information
27359 elsif Debug_Info_Off (T) then
27360 return;
27362 -- Nothing to do for an ignored Ghost entity because the entity will be
27363 -- eliminated from the tree.
27365 elsif Is_Ignored_Ghost_Entity (T) then
27366 return;
27368 -- Nothing to do if entity comes from a predefined file. Library files
27369 -- are compiled without debug information, but inlined bodies of these
27370 -- routines may appear in user code, and debug information on them ends
27371 -- up complicating debugging the user code.
27373 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
27374 Set_Needs_Debug_Info (T, False);
27375 end if;
27377 -- Set flag in entity itself. Note that we will go through the following
27378 -- circuitry even if the flag is already set on T. That's intentional,
27379 -- it makes sure that the flag will be set in subsidiary entities.
27381 Set_Needs_Debug_Info (T);
27383 -- Set flag on subsidiary entities if not set already
27385 if Is_Object (T) then
27386 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
27388 elsif Is_Type (T) then
27389 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
27391 if Is_Record_Type (T) then
27392 declare
27393 Ent : Entity_Id := First_Entity (T);
27394 begin
27395 while Present (Ent) loop
27396 Set_Debug_Info_Needed_If_Not_Set (Ent);
27397 Next_Entity (Ent);
27398 end loop;
27399 end;
27401 -- For a class wide subtype, we also need debug information
27402 -- for the equivalent type.
27404 if Ekind (T) = E_Class_Wide_Subtype then
27405 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
27406 end if;
27408 elsif Is_Array_Type (T) then
27409 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
27411 declare
27412 Indx : Node_Id := First_Index (T);
27413 begin
27414 while Present (Indx) loop
27415 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
27416 Next_Index (Indx);
27417 end loop;
27418 end;
27420 -- For a packed array type, we also need debug information for
27421 -- the type used to represent the packed array. Conversely, we
27422 -- also need it for the former if we need it for the latter.
27424 if Is_Packed (T) then
27425 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
27426 end if;
27428 if Is_Packed_Array_Impl_Type (T) then
27429 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
27430 end if;
27432 elsif Is_Access_Type (T) then
27433 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
27435 elsif Is_Private_Type (T) then
27436 declare
27437 FV : constant Entity_Id := Full_View (T);
27439 begin
27440 Set_Debug_Info_Needed_If_Not_Set (FV);
27442 -- If the full view is itself a derived private type, we need
27443 -- debug information on its underlying type.
27445 if Present (FV)
27446 and then Is_Private_Type (FV)
27447 and then Present (Underlying_Full_View (FV))
27448 then
27449 Set_Needs_Debug_Info (Underlying_Full_View (FV));
27450 end if;
27451 end;
27453 elsif Is_Protected_Type (T) then
27454 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
27456 elsif Is_Scalar_Type (T) then
27458 -- If the subrange bounds are materialized by dedicated constant
27459 -- objects, also include them in the debug info to make sure the
27460 -- debugger can properly use them.
27462 if Present (Scalar_Range (T))
27463 and then Nkind (Scalar_Range (T)) = N_Range
27464 then
27465 declare
27466 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
27467 High_Bnd : constant Node_Id := Type_High_Bound (T);
27469 begin
27470 if Is_Entity_Name (Low_Bnd) then
27471 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
27472 end if;
27474 if Is_Entity_Name (High_Bnd) then
27475 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
27476 end if;
27477 end;
27478 end if;
27479 end if;
27480 end if;
27481 end Set_Debug_Info_Needed;
27483 --------------------------------
27484 -- Set_Debug_Info_Defining_Id --
27485 --------------------------------
27487 procedure Set_Debug_Info_Defining_Id (N : Node_Id) is
27488 begin
27489 if Comes_From_Source (Defining_Identifier (N))
27490 or else Debug_Generated_Code
27491 then
27492 Set_Debug_Info_Needed (Defining_Identifier (N));
27493 end if;
27494 end Set_Debug_Info_Defining_Id;
27496 ----------------------------
27497 -- Set_Entity_With_Checks --
27498 ----------------------------
27500 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
27501 Val_Actual : Entity_Id;
27502 Nod : Node_Id;
27503 Post_Node : Node_Id;
27505 begin
27506 -- Unconditionally set the entity
27508 Set_Entity (N, Val);
27510 -- The node to post on is the selector in the case of an expanded name,
27511 -- and otherwise the node itself.
27513 if Nkind (N) = N_Expanded_Name then
27514 Post_Node := Selector_Name (N);
27515 else
27516 Post_Node := N;
27517 end if;
27519 -- Check for violation of No_Fixed_IO
27521 if Restriction_Check_Required (No_Fixed_IO)
27522 and then
27523 ((RTU_Loaded (Ada_Text_IO)
27524 and then (Is_RTE (Val, RE_Decimal_IO)
27525 or else
27526 Is_RTE (Val, RE_Fixed_IO)))
27528 or else
27529 (RTU_Loaded (Ada_Wide_Text_IO)
27530 and then (Is_RTE (Val, RO_WT_Decimal_IO)
27531 or else
27532 Is_RTE (Val, RO_WT_Fixed_IO)))
27534 or else
27535 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
27536 and then (Is_RTE (Val, RO_WW_Decimal_IO)
27537 or else
27538 Is_RTE (Val, RO_WW_Fixed_IO))))
27540 -- A special extra check, don't complain about a reference from within
27541 -- the Ada.Interrupts package itself!
27543 and then not In_Same_Extended_Unit (N, Val)
27544 then
27545 Check_Restriction (No_Fixed_IO, Post_Node);
27546 end if;
27548 -- Remaining checks are only done on source nodes. Note that we test
27549 -- for violation of No_Fixed_IO even on non-source nodes, because the
27550 -- cases for checking violations of this restriction are instantiations
27551 -- where the reference in the instance has Comes_From_Source False.
27553 if not Comes_From_Source (N) then
27554 return;
27555 end if;
27557 -- Check for violation of No_Abort_Statements, which is triggered by
27558 -- call to Ada.Task_Identification.Abort_Task.
27560 if Restriction_Check_Required (No_Abort_Statements)
27561 and then Is_RTE (Val, RE_Abort_Task)
27563 -- A special extra check, don't complain about a reference from within
27564 -- the Ada.Task_Identification package itself!
27566 and then not In_Same_Extended_Unit (N, Val)
27567 then
27568 Check_Restriction (No_Abort_Statements, Post_Node);
27569 end if;
27571 if Val = Standard_Long_Long_Integer then
27572 Check_Restriction (No_Long_Long_Integers, Post_Node);
27573 end if;
27575 -- Check for violation of No_Dynamic_Attachment
27577 if Restriction_Check_Required (No_Dynamic_Attachment)
27578 and then RTU_Loaded (Ada_Interrupts)
27579 and then (Is_RTE (Val, RE_Is_Reserved) or else
27580 Is_RTE (Val, RE_Is_Attached) or else
27581 Is_RTE (Val, RE_Current_Handler) or else
27582 Is_RTE (Val, RE_Attach_Handler) or else
27583 Is_RTE (Val, RE_Exchange_Handler) or else
27584 Is_RTE (Val, RE_Detach_Handler) or else
27585 Is_RTE (Val, RE_Reference))
27587 -- A special extra check, don't complain about a reference from within
27588 -- the Ada.Interrupts package itself!
27590 and then not In_Same_Extended_Unit (N, Val)
27591 then
27592 Check_Restriction (No_Dynamic_Attachment, Post_Node);
27593 end if;
27595 -- Check for No_Implementation_Identifiers
27597 if Restriction_Check_Required (No_Implementation_Identifiers) then
27599 -- We have an implementation defined entity if it is marked as
27600 -- implementation defined, or is defined in a package marked as
27601 -- implementation defined. However, library packages themselves
27602 -- are excluded (we don't want to flag Interfaces itself, just
27603 -- the entities within it).
27605 if (Is_Implementation_Defined (Val)
27606 or else
27607 (Present (Scope (Val))
27608 and then Is_Implementation_Defined (Scope (Val))))
27609 and then not (Is_Package_Or_Generic_Package (Val)
27610 and then Is_Library_Level_Entity (Val))
27611 then
27612 Check_Restriction (No_Implementation_Identifiers, Post_Node);
27613 end if;
27614 end if;
27616 -- Do the style check
27618 if Style_Check
27619 and then not Suppress_Style_Checks (Val)
27620 and then not In_Instance
27621 then
27622 if Nkind (N) = N_Identifier then
27623 Nod := N;
27624 elsif Nkind (N) = N_Expanded_Name then
27625 Nod := Selector_Name (N);
27626 else
27627 return;
27628 end if;
27630 -- A special situation arises for derived operations, where we want
27631 -- to do the check against the parent (since the Sloc of the derived
27632 -- operation points to the derived type declaration itself).
27634 Val_Actual := Val;
27635 while not Comes_From_Source (Val_Actual)
27636 and then Nkind (Val_Actual) in N_Entity
27637 and then (Ekind (Val_Actual) = E_Enumeration_Literal
27638 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
27639 and then Present (Alias (Val_Actual))
27640 loop
27641 Val_Actual := Alias (Val_Actual);
27642 end loop;
27644 -- Renaming declarations for generic actuals do not come from source,
27645 -- and have a different name from that of the entity they rename, so
27646 -- there is no style check to perform here.
27648 if Chars (Nod) = Chars (Val_Actual) then
27649 Style.Check_Identifier (Nod, Val_Actual);
27650 end if;
27651 end if;
27652 end Set_Entity_With_Checks;
27654 ------------------------------
27655 -- Set_Invalid_Scalar_Value --
27656 ------------------------------
27658 procedure Set_Invalid_Scalar_Value
27659 (Scal_Typ : Float_Scalar_Id;
27660 Value : Ureal)
27662 Slot : Ureal renames Invalid_Floats (Scal_Typ);
27664 begin
27665 -- Detect an attempt to set a different value for the same scalar type
27667 pragma Assert (Slot = No_Ureal);
27668 Slot := Value;
27669 end Set_Invalid_Scalar_Value;
27671 ------------------------------
27672 -- Set_Invalid_Scalar_Value --
27673 ------------------------------
27675 procedure Set_Invalid_Scalar_Value
27676 (Scal_Typ : Integer_Scalar_Id;
27677 Value : Uint)
27679 Slot : Uint renames Invalid_Integers (Scal_Typ);
27681 begin
27682 -- Detect an attempt to set a different value for the same scalar type
27684 pragma Assert (No (Slot));
27685 Slot := Value;
27686 end Set_Invalid_Scalar_Value;
27688 ------------------------
27689 -- Set_Name_Entity_Id --
27690 ------------------------
27692 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
27693 begin
27694 Set_Name_Table_Int (Id, Int (Val));
27695 end Set_Name_Entity_Id;
27697 ---------------------
27698 -- Set_Next_Actual --
27699 ---------------------
27701 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
27702 begin
27703 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
27704 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
27705 end if;
27706 end Set_Next_Actual;
27708 ----------------------------------
27709 -- Set_Optimize_Alignment_Flags --
27710 ----------------------------------
27712 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
27713 begin
27714 if Optimize_Alignment = 'S' then
27715 Set_Optimize_Alignment_Space (E);
27716 elsif Optimize_Alignment = 'T' then
27717 Set_Optimize_Alignment_Time (E);
27718 end if;
27719 end Set_Optimize_Alignment_Flags;
27721 -----------------------
27722 -- Set_Public_Status --
27723 -----------------------
27725 procedure Set_Public_Status (Id : Entity_Id) is
27726 S : constant Entity_Id := Current_Scope;
27728 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
27729 -- Determines if E is defined within handled statement sequence or
27730 -- an if statement, returns True if so, False otherwise.
27732 ----------------------
27733 -- Within_HSS_Or_If --
27734 ----------------------
27736 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
27737 N : Node_Id;
27738 begin
27739 N := Declaration_Node (E);
27740 loop
27741 N := Parent (N);
27743 if No (N) then
27744 return False;
27746 elsif Nkind (N) in
27747 N_Handled_Sequence_Of_Statements | N_If_Statement
27748 then
27749 return True;
27750 end if;
27751 end loop;
27752 end Within_HSS_Or_If;
27754 -- Start of processing for Set_Public_Status
27756 begin
27757 -- Everything in the scope of Standard is public
27759 if S = Standard_Standard then
27760 Set_Is_Public (Id);
27762 -- Entity is definitely not public if enclosing scope is not public
27764 elsif not Is_Public (S) then
27765 return;
27767 -- An object or function declaration that occurs in a handled sequence
27768 -- of statements or within an if statement is the declaration for a
27769 -- temporary object or local subprogram generated by the expander. It
27770 -- never needs to be made public and furthermore, making it public can
27771 -- cause back end problems.
27773 elsif Nkind (Parent (Id)) in
27774 N_Object_Declaration | N_Function_Specification
27775 and then Within_HSS_Or_If (Id)
27776 then
27777 return;
27779 -- Entities in public packages or records are public
27781 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
27782 Set_Is_Public (Id);
27784 -- The bounds of an entry family declaration can generate object
27785 -- declarations that are visible to the back-end, e.g. in the
27786 -- the declaration of a composite type that contains tasks.
27788 elsif Is_Concurrent_Type (S)
27789 and then not Has_Completion (S)
27790 and then Nkind (Parent (Id)) = N_Object_Declaration
27791 then
27792 Set_Is_Public (Id);
27793 end if;
27794 end Set_Public_Status;
27796 -----------------------------
27797 -- Set_Referenced_Modified --
27798 -----------------------------
27800 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
27801 Pref : Node_Id;
27803 begin
27804 -- Deal with indexed components, selected components, or slices where
27805 -- the prefix is modified.
27807 if Nkind (N) in N_Indexed_Component | N_Selected_Component | N_Slice then
27809 -- Grab the original node to avoid looking at internally generated
27810 -- objects.
27812 Pref := Original_Node (Prefix (N));
27814 -- If prefix is access type, then it is the designated object that is
27815 -- being modified, which means we have no entity to set the flag on.
27817 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
27818 return;
27820 -- Otherwise chase the prefix
27822 else
27823 Set_Referenced_Modified (Pref, Out_Param);
27824 end if;
27826 -- Otherwise see if we have an entity name (only other case to process)
27828 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
27829 Set_Referenced_As_LHS (Entity (N), not Out_Param);
27830 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
27831 end if;
27832 end Set_Referenced_Modified;
27834 ------------------
27835 -- Set_Rep_Info --
27836 ------------------
27838 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
27839 begin
27840 Set_Is_Atomic (T1, Is_Atomic (T2));
27841 Set_Is_Independent (T1, Is_Independent (T2));
27842 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
27844 if Is_Base_Type (T1) then
27845 Set_Is_Volatile (T1, Is_Volatile (T2));
27846 end if;
27847 end Set_Rep_Info;
27849 -------------------
27850 -- Set_Size_Info --
27851 -------------------
27853 procedure Set_Size_Info (T1, T2 : Entity_Id) is
27854 begin
27855 -- We copy Esize, but not RM_Size, since in general RM_Size is
27856 -- subtype specific and does not get inherited by all subtypes.
27858 Copy_Esize (To => T1, From => T2);
27859 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
27861 if Is_Discrete_Or_Fixed_Point_Type (T1)
27862 and then
27863 Is_Discrete_Or_Fixed_Point_Type (T2)
27864 then
27865 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
27866 end if;
27868 Copy_Alignment (To => T1, From => T2);
27869 end Set_Size_Info;
27871 ------------------------------
27872 -- Should_Ignore_Pragma_Par --
27873 ------------------------------
27875 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
27876 pragma Assert (Compiler_State = Parsing);
27877 -- This one can't work during semantic analysis, because we don't have a
27878 -- correct Current_Source_File.
27880 Result : constant Boolean :=
27881 Get_Name_Table_Boolean3 (Prag_Name)
27882 and then not Is_Internal_File_Name
27883 (File_Name (Current_Source_File));
27884 begin
27885 return Result;
27886 end Should_Ignore_Pragma_Par;
27888 ------------------------------
27889 -- Should_Ignore_Pragma_Sem --
27890 ------------------------------
27892 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
27893 pragma Assert (Compiler_State = Analyzing);
27894 Prag_Name : constant Name_Id := Pragma_Name (N);
27895 Result : constant Boolean :=
27896 Get_Name_Table_Boolean3 (Prag_Name)
27897 and then not In_Internal_Unit (N);
27899 begin
27900 return Result;
27901 end Should_Ignore_Pragma_Sem;
27903 --------------------
27904 -- Static_Boolean --
27905 --------------------
27907 function Static_Boolean (N : Node_Id) return Opt_Ubool is
27908 begin
27909 Analyze_And_Resolve (N, Standard_Boolean);
27911 if N = Error
27912 or else Error_Posted (N)
27913 or else Etype (N) = Any_Type
27914 then
27915 return No_Uint;
27916 end if;
27918 if Is_OK_Static_Expression (N) then
27919 if not Raises_Constraint_Error (N) then
27920 return Expr_Value (N);
27921 else
27922 return No_Uint;
27923 end if;
27925 elsif Etype (N) = Any_Type then
27926 return No_Uint;
27928 else
27929 Flag_Non_Static_Expr
27930 ("static boolean expression required here", N);
27931 return No_Uint;
27932 end if;
27933 end Static_Boolean;
27935 --------------------
27936 -- Static_Integer --
27937 --------------------
27939 function Static_Integer (N : Node_Id) return Uint is
27940 begin
27941 Analyze_And_Resolve (N, Any_Integer);
27943 if N = Error
27944 or else Error_Posted (N)
27945 or else Etype (N) = Any_Type
27946 then
27947 return No_Uint;
27948 end if;
27950 if Is_OK_Static_Expression (N) then
27951 if not Raises_Constraint_Error (N) then
27952 return Expr_Value (N);
27953 else
27954 return No_Uint;
27955 end if;
27957 elsif Etype (N) = Any_Type then
27958 return No_Uint;
27960 else
27961 Flag_Non_Static_Expr
27962 ("static integer expression required here", N);
27963 return No_Uint;
27964 end if;
27965 end Static_Integer;
27967 -------------------------------
27968 -- Statically_Denotes_Entity --
27969 -------------------------------
27971 function Statically_Denotes_Entity (N : Node_Id) return Boolean is
27972 E : Entity_Id;
27973 begin
27974 if not Is_Entity_Name (N) then
27975 return False;
27976 else
27977 E := Entity (N);
27978 end if;
27980 return
27981 Nkind (Parent (E)) /= N_Object_Renaming_Declaration
27982 or else Is_Prival (E)
27983 or else Statically_Denotes_Entity (Renamed_Object (E));
27984 end Statically_Denotes_Entity;
27986 -------------------------------
27987 -- Statically_Denotes_Object --
27988 -------------------------------
27990 function Statically_Denotes_Object (N : Node_Id) return Boolean is
27991 begin
27992 return Statically_Denotes_Entity (N)
27993 and then Is_Object_Reference (N);
27994 end Statically_Denotes_Object;
27996 --------------------------
27997 -- Statically_Different --
27998 --------------------------
28000 function Statically_Different (E1, E2 : Node_Id) return Boolean is
28001 R1 : constant Node_Id := Get_Referenced_Object (E1);
28002 R2 : constant Node_Id := Get_Referenced_Object (E2);
28003 begin
28004 return Is_Entity_Name (R1)
28005 and then Is_Entity_Name (R2)
28006 and then Entity (R1) /= Entity (R2)
28007 and then not Is_Formal (Entity (R1))
28008 and then not Is_Formal (Entity (R2));
28009 end Statically_Different;
28011 -----------------------------
28012 -- Statically_Names_Object --
28013 -----------------------------
28015 function Statically_Names_Object (N : Node_Id) return Boolean is
28016 begin
28017 if Statically_Denotes_Object (N) then
28018 return True;
28019 elsif Is_Entity_Name (N) then
28020 declare
28021 E : constant Entity_Id := Entity (N);
28022 begin
28023 return Nkind (Parent (E)) = N_Object_Renaming_Declaration
28024 and then Statically_Names_Object (Renamed_Object (E));
28025 end;
28026 end if;
28028 case Nkind (N) is
28029 when N_Indexed_Component =>
28030 if Is_Access_Type (Etype (Prefix (N))) then
28031 -- treat implicit dereference same as explicit
28032 return False;
28033 end if;
28035 if not Is_Constrained (Etype (Prefix (N))) then
28036 return False;
28037 end if;
28039 declare
28040 Indx : Node_Id := First_Index (Etype (Prefix (N)));
28041 Expr : Node_Id := First (Expressions (N));
28042 Index_Subtype : Node_Id;
28043 begin
28044 loop
28045 Index_Subtype := Etype (Indx);
28047 if not Is_Static_Subtype (Index_Subtype) then
28048 return False;
28049 end if;
28050 if not Is_OK_Static_Expression (Expr) then
28051 return False;
28052 end if;
28054 declare
28055 Index_Value : constant Uint := Expr_Value (Expr);
28056 Low_Value : constant Uint :=
28057 Expr_Value (Type_Low_Bound (Index_Subtype));
28058 High_Value : constant Uint :=
28059 Expr_Value (Type_High_Bound (Index_Subtype));
28060 begin
28061 if Index_Value < Low_Value
28062 or Index_Value > High_Value
28063 then
28064 return False;
28065 end if;
28066 end;
28068 Next_Index (Indx);
28069 Expr := Next (Expr);
28070 pragma Assert (Present (Indx) = Present (Expr)
28071 or else Serious_Errors_Detected > 0);
28072 exit when not (Present (Indx) and Present (Expr));
28073 end loop;
28074 end;
28076 when N_Selected_Component =>
28077 if Is_Access_Type (Etype (Prefix (N))) then
28078 -- treat implicit dereference same as explicit
28079 return False;
28080 end if;
28082 if Ekind (Entity (Selector_Name (N))) not in
28083 E_Component | E_Discriminant
28084 then
28085 return False;
28086 end if;
28088 declare
28089 Comp : constant Entity_Id :=
28090 Original_Record_Component (Entity (Selector_Name (N)));
28091 begin
28092 -- AI12-0373 confirms that we should not call
28093 -- Has_Discriminant_Dependent_Constraint here which would be
28094 -- too strong.
28096 if Is_Declared_Within_Variant (Comp) then
28097 return False;
28098 end if;
28099 end;
28101 when others => -- includes N_Slice, N_Explicit_Dereference
28102 return False;
28103 end case;
28105 pragma Assert (Present (Prefix (N)));
28107 return Statically_Names_Object (Prefix (N));
28108 end Statically_Names_Object;
28110 ---------------------------------
28111 -- String_From_Numeric_Literal --
28112 ---------------------------------
28114 function String_From_Numeric_Literal (N : Node_Id) return String_Id is
28115 Loc : constant Source_Ptr := Sloc (N);
28116 Sbuffer : constant Source_Buffer_Ptr :=
28117 Source_Text (Get_Source_File_Index (Loc));
28118 Src_Ptr : Source_Ptr := Loc;
28120 C : Character := Sbuffer (Src_Ptr);
28121 -- Current source program character
28123 function Belongs_To_Numeric_Literal (C : Character) return Boolean;
28124 -- Return True if C belongs to the numeric literal
28126 --------------------------------
28127 -- Belongs_To_Numeric_Literal --
28128 --------------------------------
28130 function Belongs_To_Numeric_Literal (C : Character) return Boolean is
28131 begin
28132 case C is
28133 when '0' .. '9' | '_' | '.' | 'e' | '#' | 'A' .. 'F' =>
28134 return True;
28136 -- Make sure '+' or '-' is part of an exponent
28138 when '+' | '-' =>
28139 declare
28140 Prev_C : constant Character := Sbuffer (Src_Ptr - 1);
28141 begin
28142 return Prev_C in 'e' | 'E';
28143 end;
28145 -- Other characters cannot belong to a numeric literal
28147 when others =>
28148 return False;
28149 end case;
28150 end Belongs_To_Numeric_Literal;
28152 -- Start of processing for String_From_Numeric_Literal
28154 begin
28155 Start_String;
28156 while Belongs_To_Numeric_Literal (C) loop
28157 Store_String_Char (C);
28158 Src_Ptr := Src_Ptr + 1;
28159 C := Sbuffer (Src_Ptr);
28160 end loop;
28162 return End_String;
28163 end String_From_Numeric_Literal;
28165 --------------------------------------
28166 -- Subject_To_Loop_Entry_Attributes --
28167 --------------------------------------
28169 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
28170 Stmt : Node_Id;
28172 begin
28173 Stmt := N;
28175 -- The expansion mechanism transform a loop subject to at least one
28176 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
28177 -- the conditional part.
28179 if Nkind (Stmt) in N_Block_Statement | N_If_Statement
28180 and then Nkind (Original_Node (N)) = N_Loop_Statement
28181 then
28182 Stmt := Original_Node (N);
28183 end if;
28185 return
28186 Nkind (Stmt) = N_Loop_Statement
28187 and then Present (Identifier (Stmt))
28188 and then Present (Entity (Identifier (Stmt)))
28189 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
28190 end Subject_To_Loop_Entry_Attributes;
28192 -------------------------------
28193 -- Support_Atomic_Primitives --
28194 -------------------------------
28196 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
28197 Size : Int;
28199 begin
28200 -- Verify the alignment of Typ is known
28202 if not Known_Alignment (Typ) then
28203 return False;
28204 end if;
28206 if Known_Static_Esize (Typ) then
28207 Size := UI_To_Int (Esize (Typ));
28209 -- If the Esize (Object_Size) is unknown at compile time, look at the
28210 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
28212 elsif Known_Static_RM_Size (Typ) then
28213 Size := UI_To_Int (RM_Size (Typ));
28215 -- Otherwise, the size is considered to be unknown.
28217 else
28218 return False;
28219 end if;
28221 -- Check that the size of the component is 8, 16, 32, or 64 bits and
28222 -- that Typ is properly aligned.
28224 case Size is
28225 when 8 | 16 | 32 | 64 =>
28226 return Size = UI_To_Int (Alignment (Typ)) * 8;
28228 when others =>
28229 return False;
28230 end case;
28231 end Support_Atomic_Primitives;
28233 -----------------
28234 -- Trace_Scope --
28235 -----------------
28237 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
28238 begin
28239 if Debug_Flag_W then
28240 for J in 0 .. Scope_Stack.Last loop
28241 Write_Str (" ");
28242 end loop;
28244 Write_Str (Msg);
28245 Write_Name (Chars (E));
28246 Write_Str (" from ");
28247 Write_Location (Sloc (N));
28248 Write_Eol;
28249 end if;
28250 end Trace_Scope;
28252 -----------------------
28253 -- Transfer_Entities --
28254 -----------------------
28256 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
28257 procedure Set_Public_Status_Of (Id : Entity_Id);
28258 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
28259 -- Set_Public_Status. If successful and Id denotes a record type, set
28260 -- the Is_Public attribute of its fields.
28262 --------------------------
28263 -- Set_Public_Status_Of --
28264 --------------------------
28266 procedure Set_Public_Status_Of (Id : Entity_Id) is
28267 Field : Entity_Id;
28269 begin
28270 if not Is_Public (Id) then
28271 Set_Public_Status (Id);
28273 -- When the input entity is a public record type, ensure that all
28274 -- its internal fields are also exposed to the linker. The fields
28275 -- of a class-wide type are never made public.
28277 if Is_Public (Id)
28278 and then Is_Record_Type (Id)
28279 and then not Is_Class_Wide_Type (Id)
28280 then
28281 Field := First_Entity (Id);
28282 while Present (Field) loop
28283 Set_Is_Public (Field);
28284 Next_Entity (Field);
28285 end loop;
28286 end if;
28287 end if;
28288 end Set_Public_Status_Of;
28290 -- Local variables
28292 Full_Id : Entity_Id;
28293 Id : Entity_Id;
28295 -- Start of processing for Transfer_Entities
28297 begin
28298 Id := First_Entity (From);
28300 if Present (Id) then
28302 -- Merge the entity chain of the source scope with that of the
28303 -- destination scope.
28305 if Present (Last_Entity (To)) then
28306 Link_Entities (Last_Entity (To), Id);
28307 else
28308 Set_First_Entity (To, Id);
28309 end if;
28311 Set_Last_Entity (To, Last_Entity (From));
28313 -- Inspect the entities of the source scope and update their Scope
28314 -- attribute.
28316 while Present (Id) loop
28317 Set_Scope (Id, To);
28318 Set_Public_Status_Of (Id);
28320 -- Handle an internally generated full view for a private type
28322 if Is_Private_Type (Id)
28323 and then Present (Full_View (Id))
28324 and then Is_Itype (Full_View (Id))
28325 then
28326 Full_Id := Full_View (Id);
28328 Set_Scope (Full_Id, To);
28329 Set_Public_Status_Of (Full_Id);
28330 end if;
28332 Next_Entity (Id);
28333 end loop;
28335 Set_First_Entity (From, Empty);
28336 Set_Last_Entity (From, Empty);
28337 end if;
28338 end Transfer_Entities;
28340 ------------------------
28341 -- Traverse_More_Func --
28342 ------------------------
28344 function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is
28346 Processing_Itype : Boolean := False;
28347 -- Set to True while traversing the nodes under an Itype, to prevent
28348 -- looping on Itype handling during that traversal.
28350 function Process_More (N : Node_Id) return Traverse_Result;
28351 -- Wrapper over the Process callback to handle parts of the AST that
28352 -- are not normally traversed as syntactic children.
28354 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result;
28355 -- Main recursive traversal implemented as an instantiation of
28356 -- Traverse_Func over a modified Process callback.
28358 ------------------
28359 -- Process_More --
28360 ------------------
28362 function Process_More (N : Node_Id) return Traverse_Result is
28364 procedure Traverse_More (N : Node_Id;
28365 Res : in out Traverse_Result);
28366 procedure Traverse_More (L : List_Id;
28367 Res : in out Traverse_Result);
28368 -- Traverse a node or list and update the traversal result to value
28369 -- Abandon when needed.
28371 -------------------
28372 -- Traverse_More --
28373 -------------------
28375 procedure Traverse_More (N : Node_Id;
28376 Res : in out Traverse_Result)
28378 begin
28379 -- Do not process any more nodes if Abandon was reached
28381 if Res = Abandon then
28382 return;
28383 end if;
28385 if Traverse_Rec (N) = Abandon then
28386 Res := Abandon;
28387 end if;
28388 end Traverse_More;
28390 procedure Traverse_More (L : List_Id;
28391 Res : in out Traverse_Result)
28393 N : Node_Id := First (L);
28395 begin
28396 -- Do not process any more nodes if Abandon was reached
28398 if Res = Abandon then
28399 return;
28400 end if;
28402 while Present (N) loop
28403 Traverse_More (N, Res);
28404 Next (N);
28405 end loop;
28406 end Traverse_More;
28408 -- Local variables
28410 Node : Node_Id;
28411 Result : Traverse_Result;
28413 -- Start of processing for Process_More
28415 begin
28416 -- Initial callback to Process. Return immediately on Skip/Abandon.
28417 -- Otherwise update the value of Node for further processing of
28418 -- non-syntactic children.
28420 Result := Process (N);
28422 case Result is
28423 when OK => Node := N;
28424 when OK_Orig => Node := Original_Node (N);
28425 when Skip => return Skip;
28426 when Abandon => return Abandon;
28427 end case;
28429 -- Process the relevant semantic children which are a logical part of
28430 -- the AST under this node before returning for the processing of
28431 -- syntactic children.
28433 -- Start with all non-syntactic lists of action nodes
28435 case Nkind (Node) is
28436 when N_Component_Association =>
28437 Traverse_More (Loop_Actions (Node), Result);
28439 when N_Elsif_Part =>
28440 Traverse_More (Condition_Actions (Node), Result);
28442 when N_Short_Circuit =>
28443 Traverse_More (Actions (Node), Result);
28445 when N_Case_Expression_Alternative =>
28446 Traverse_More (Actions (Node), Result);
28448 when N_Iterated_Component_Association =>
28449 Traverse_More (Loop_Actions (Node), Result);
28451 when N_Iterated_Element_Association =>
28452 Traverse_More (Loop_Actions (Node), Result);
28454 when N_Iteration_Scheme =>
28455 Traverse_More (Condition_Actions (Node), Result);
28457 when N_If_Expression =>
28458 Traverse_More (Then_Actions (Node), Result);
28459 Traverse_More (Else_Actions (Node), Result);
28461 -- Various nodes have a field Actions as a syntactic node,
28462 -- so it will be traversed in the regular syntactic traversal.
28464 when N_Compilation_Unit_Aux
28465 | N_Compound_Statement
28466 | N_Expression_With_Actions
28467 | N_Freeze_Entity
28469 null;
28471 when others =>
28472 null;
28473 end case;
28475 -- If Process_Itypes is True, process unattached nodes which come
28476 -- from Itypes. This only concerns currently ranges of scalar
28477 -- (possibly as index) types. This traversal is protected against
28478 -- looping with Processing_Itype.
28480 if Process_Itypes
28481 and then not Processing_Itype
28482 and then Nkind (Node) in N_Has_Etype
28483 and then Present (Etype (Node))
28484 and then Is_Itype (Etype (Node))
28485 then
28486 declare
28487 Typ : constant Entity_Id := Etype (Node);
28488 begin
28489 Processing_Itype := True;
28491 case Ekind (Typ) is
28492 when Scalar_Kind =>
28493 Traverse_More (Scalar_Range (Typ), Result);
28495 when Array_Kind =>
28496 declare
28497 Index : Node_Id := First_Index (Typ);
28498 Rng : Node_Id;
28499 begin
28500 while Present (Index) loop
28501 if Nkind (Index) in N_Has_Entity then
28502 Rng := Scalar_Range (Entity (Index));
28503 else
28504 Rng := Index;
28505 end if;
28507 Traverse_More (Rng, Result);
28508 Next_Index (Index);
28509 end loop;
28510 end;
28511 when others =>
28512 null;
28513 end case;
28515 Processing_Itype := False;
28516 end;
28517 end if;
28519 return Result;
28520 end Process_More;
28522 -- Define Traverse_Rec as a renaming of the instantiation, as an
28523 -- instantiation cannot complete a previous spec.
28525 function Traverse_Recursive is new Traverse_Func (Process_More);
28526 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result
28527 renames Traverse_Recursive;
28529 -- Start of processing for Traverse_More_Func
28531 begin
28532 return Traverse_Rec (Node);
28533 end Traverse_More_Func;
28535 ------------------------
28536 -- Traverse_More_Proc --
28537 ------------------------
28539 procedure Traverse_More_Proc (Node : Node_Id) is
28540 function Traverse is new Traverse_More_Func (Process, Process_Itypes);
28541 Discard : Traverse_Final_Result;
28542 pragma Warnings (Off, Discard);
28543 begin
28544 Discard := Traverse (Node);
28545 end Traverse_More_Proc;
28547 ------------------------------------
28548 -- Type_Without_Stream_Operation --
28549 ------------------------------------
28551 function Type_Without_Stream_Operation
28552 (T : Entity_Id;
28553 Op : TSS_Name_Type := TSS_Null) return Entity_Id
28555 BT : constant Entity_Id := Base_Type (T);
28556 Op_Missing : Boolean;
28558 begin
28559 if Is_Elementary_Type (T) then
28560 if Op = TSS_Null then
28561 Op_Missing :=
28562 No (TSS (BT, TSS_Stream_Read))
28563 or else No (TSS (BT, TSS_Stream_Write));
28565 else
28566 Op_Missing := No (TSS (BT, Op));
28567 end if;
28569 if Op_Missing then
28570 return T;
28571 else
28572 return Empty;
28573 end if;
28575 elsif Is_Array_Type (T) then
28576 return Type_Without_Stream_Operation (Component_Type (T), Op);
28578 elsif Is_Record_Type (T) then
28579 declare
28580 Comp : Entity_Id;
28581 C_Typ : Entity_Id;
28583 begin
28584 Comp := First_Component (T);
28585 while Present (Comp) loop
28586 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
28588 if Present (C_Typ) then
28589 return C_Typ;
28590 end if;
28592 Next_Component (Comp);
28593 end loop;
28595 return Empty;
28596 end;
28598 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
28599 return Type_Without_Stream_Operation (Full_View (T), Op);
28600 else
28601 return Empty;
28602 end if;
28603 end Type_Without_Stream_Operation;
28605 ------------------------------
28606 -- Ultimate_Overlaid_Entity --
28607 ------------------------------
28609 function Ultimate_Overlaid_Entity (E : Entity_Id) return Entity_Id is
28610 Address : Node_Id;
28611 Alias : Entity_Id := E;
28612 Offset : Boolean;
28614 begin
28615 -- Currently this routine is only called for stand-alone objects that
28616 -- have been analysed, since the analysis of the Address aspect is often
28617 -- delayed.
28619 pragma Assert (Ekind (E) in E_Constant | E_Variable);
28621 loop
28622 Address := Address_Clause (Alias);
28623 if Present (Address) then
28624 Find_Overlaid_Entity (Address, Alias, Offset);
28625 if Present (Alias) then
28626 null;
28627 else
28628 return Empty;
28629 end if;
28630 elsif Alias = E then
28631 return Empty;
28632 else
28633 return Alias;
28634 end if;
28635 end loop;
28636 end Ultimate_Overlaid_Entity;
28638 ---------------------
28639 -- Ultimate_Prefix --
28640 ---------------------
28642 function Ultimate_Prefix (N : Node_Id) return Node_Id is
28643 Pref : Node_Id;
28645 begin
28646 Pref := N;
28647 while Nkind (Pref) in N_Explicit_Dereference
28648 | N_Indexed_Component
28649 | N_Selected_Component
28650 | N_Slice
28651 loop
28652 Pref := Prefix (Pref);
28653 end loop;
28655 return Pref;
28656 end Ultimate_Prefix;
28658 ----------------------------
28659 -- Unique_Defining_Entity --
28660 ----------------------------
28662 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
28663 begin
28664 return Unique_Entity (Defining_Entity (N));
28665 end Unique_Defining_Entity;
28667 -------------------
28668 -- Unique_Entity --
28669 -------------------
28671 function Unique_Entity (E : Entity_Id) return Entity_Id is
28672 U : Entity_Id := E;
28673 P : Node_Id;
28675 begin
28676 case Ekind (E) is
28677 when E_Constant =>
28678 if Present (Full_View (E)) then
28679 U := Full_View (E);
28680 end if;
28682 when Entry_Kind =>
28683 if Nkind (Parent (E)) = N_Entry_Body then
28684 declare
28685 Prot_Item : Entity_Id;
28686 Prot_Type : Entity_Id;
28688 begin
28689 if Ekind (E) = E_Entry then
28690 Prot_Type := Scope (E);
28692 -- Bodies of entry families are nested within an extra scope
28693 -- that contains an entry index declaration.
28695 else
28696 Prot_Type := Scope (Scope (E));
28697 end if;
28699 -- A protected type may be declared as a private type, in
28700 -- which case we need to get its full view.
28702 if Is_Private_Type (Prot_Type) then
28703 Prot_Type := Full_View (Prot_Type);
28704 end if;
28706 -- Full view may not be present on error, in which case
28707 -- return E by default.
28709 if Present (Prot_Type) then
28710 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
28712 -- Traverse the entity list of the protected type and
28713 -- locate an entry declaration which matches the entry
28714 -- body.
28716 Prot_Item := First_Entity (Prot_Type);
28717 while Present (Prot_Item) loop
28718 if Ekind (Prot_Item) in Entry_Kind
28719 and then Corresponding_Body (Parent (Prot_Item)) = E
28720 then
28721 U := Prot_Item;
28722 exit;
28723 end if;
28725 Next_Entity (Prot_Item);
28726 end loop;
28727 end if;
28728 end;
28729 end if;
28731 when Formal_Kind =>
28732 if Present (Spec_Entity (E)) then
28733 U := Spec_Entity (E);
28734 end if;
28736 when E_Package_Body =>
28737 P := Parent (E);
28739 if Nkind (P) = N_Defining_Program_Unit_Name then
28740 P := Parent (P);
28741 end if;
28743 if Nkind (P) = N_Package_Body
28744 and then Present (Corresponding_Spec (P))
28745 then
28746 U := Corresponding_Spec (P);
28748 elsif Nkind (P) = N_Package_Body_Stub
28749 and then Present (Corresponding_Spec_Of_Stub (P))
28750 then
28751 U := Corresponding_Spec_Of_Stub (P);
28752 end if;
28754 when E_Protected_Body =>
28755 P := Parent (E);
28757 if Nkind (P) = N_Protected_Body
28758 and then Present (Corresponding_Spec (P))
28759 then
28760 U := Corresponding_Spec (P);
28762 elsif Nkind (P) = N_Protected_Body_Stub
28763 and then Present (Corresponding_Spec_Of_Stub (P))
28764 then
28765 U := Corresponding_Spec_Of_Stub (P);
28767 if Is_Single_Protected_Object (U) then
28768 U := Etype (U);
28769 end if;
28770 end if;
28772 if Is_Private_Type (U) then
28773 U := Full_View (U);
28774 end if;
28776 when E_Subprogram_Body =>
28777 P := Parent (E);
28779 if Nkind (P) = N_Defining_Program_Unit_Name then
28780 P := Parent (P);
28781 end if;
28783 P := Parent (P);
28785 if Nkind (P) = N_Subprogram_Body
28786 and then Present (Corresponding_Spec (P))
28787 then
28788 U := Corresponding_Spec (P);
28790 elsif Nkind (P) = N_Subprogram_Body_Stub
28791 and then Present (Corresponding_Spec_Of_Stub (P))
28792 then
28793 U := Corresponding_Spec_Of_Stub (P);
28795 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
28796 U := Corresponding_Spec (P);
28797 end if;
28799 when E_Task_Body =>
28800 P := Parent (E);
28802 if Nkind (P) = N_Task_Body
28803 and then Present (Corresponding_Spec (P))
28804 then
28805 U := Corresponding_Spec (P);
28807 elsif Nkind (P) = N_Task_Body_Stub
28808 and then Present (Corresponding_Spec_Of_Stub (P))
28809 then
28810 U := Corresponding_Spec_Of_Stub (P);
28812 if Is_Single_Task_Object (U) then
28813 U := Etype (U);
28814 end if;
28815 end if;
28817 if Is_Private_Type (U) then
28818 U := Full_View (U);
28819 end if;
28821 when Type_Kind =>
28822 if Present (Full_View (E)) then
28823 U := Full_View (E);
28824 end if;
28826 when others =>
28827 null;
28828 end case;
28830 return U;
28831 end Unique_Entity;
28833 -----------------
28834 -- Unique_Name --
28835 -----------------
28837 function Unique_Name (E : Entity_Id) return String is
28839 -- Local subprograms
28841 function Add_Homonym_Suffix (E : Entity_Id) return String;
28843 function This_Name return String;
28845 ------------------------
28846 -- Add_Homonym_Suffix --
28847 ------------------------
28849 function Add_Homonym_Suffix (E : Entity_Id) return String is
28851 -- Names in E_Subprogram_Body or E_Package_Body entities are not
28852 -- reliable, as they may not include the overloading suffix.
28853 -- Instead, when looking for the name of E or one of its enclosing
28854 -- scope, we get the name of the corresponding Unique_Entity.
28856 U : constant Entity_Id := Unique_Entity (E);
28857 Nam : constant String := Get_Name_String (Chars (U));
28859 begin
28860 -- If E has homonyms but is not fully qualified, as done in
28861 -- GNATprove mode, append the homonym number on the fly. Strip the
28862 -- leading space character in the image of natural numbers. Also do
28863 -- not print the homonym value of 1.
28865 if Has_Homonym (U) then
28866 declare
28867 N : constant Pos := Homonym_Number (U);
28868 S : constant String := N'Img;
28869 begin
28870 if N > 1 then
28871 return Nam & "__" & S (2 .. S'Last);
28872 end if;
28873 end;
28874 end if;
28876 return Nam;
28877 end Add_Homonym_Suffix;
28879 ---------------
28880 -- This_Name --
28881 ---------------
28883 function This_Name return String is
28884 begin
28885 return Add_Homonym_Suffix (E);
28886 end This_Name;
28888 -- Local variables
28890 U : constant Entity_Id := Unique_Entity (E);
28892 -- Start of processing for Unique_Name
28894 begin
28895 if E = Standard_Standard
28896 or else Has_Fully_Qualified_Name (E)
28897 then
28898 return This_Name;
28900 elsif Ekind (E) = E_Enumeration_Literal then
28901 return Unique_Name (Etype (E)) & "__" & This_Name;
28903 else
28904 declare
28905 S : constant Entity_Id := Scope (U);
28906 pragma Assert (Present (S));
28908 begin
28909 -- Prefix names of predefined types with standard__, but leave
28910 -- names of user-defined packages and subprograms without prefix
28911 -- (even if technically they are nested in the Standard package).
28913 if S = Standard_Standard then
28914 if Ekind (U) = E_Package or else Is_Subprogram (U) then
28915 return This_Name;
28916 else
28917 return Unique_Name (S) & "__" & This_Name;
28918 end if;
28920 -- For intances of generic subprograms use the name of the related
28921 -- instance and skip the scope of its wrapper package.
28923 elsif Is_Wrapper_Package (S) then
28924 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
28925 -- Wrapper package and the instantiation are in the same scope
28927 declare
28928 Related_Name : constant String :=
28929 Add_Homonym_Suffix (Related_Instance (S));
28930 Enclosing_Name : constant String :=
28931 Unique_Name (Scope (S)) & "__" & Related_Name;
28933 begin
28934 if Is_Subprogram (U)
28935 and then not Is_Generic_Actual_Subprogram (U)
28936 then
28937 return Enclosing_Name;
28938 else
28939 return Enclosing_Name & "__" & This_Name;
28940 end if;
28941 end;
28943 elsif Is_Child_Unit (U) then
28944 return Child_Prefix & Unique_Name (S) & "__" & This_Name;
28945 else
28946 return Unique_Name (S) & "__" & This_Name;
28947 end if;
28948 end;
28949 end if;
28950 end Unique_Name;
28952 ---------------------
28953 -- Unit_Is_Visible --
28954 ---------------------
28956 function Unit_Is_Visible (U : Entity_Id) return Boolean is
28957 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
28958 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
28960 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
28961 -- For a child unit, check whether unit appears in a with_clause
28962 -- of a parent.
28964 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
28965 -- Scan the context clause of one compilation unit looking for a
28966 -- with_clause for the unit in question.
28968 ----------------------------
28969 -- Unit_In_Parent_Context --
28970 ----------------------------
28972 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
28973 begin
28974 if Unit_In_Context (Par_Unit) then
28975 return True;
28977 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
28978 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
28980 else
28981 return False;
28982 end if;
28983 end Unit_In_Parent_Context;
28985 ---------------------
28986 -- Unit_In_Context --
28987 ---------------------
28989 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
28990 Clause : Node_Id;
28992 begin
28993 Clause := First (Context_Items (Comp_Unit));
28994 while Present (Clause) loop
28995 if Nkind (Clause) = N_With_Clause then
28996 if Library_Unit (Clause) = U then
28997 return True;
28999 -- The with_clause may denote a renaming of the unit we are
29000 -- looking for, eg. Text_IO which renames Ada.Text_IO.
29002 elsif
29003 Renamed_Entity (Entity (Name (Clause))) =
29004 Defining_Entity (Unit (U))
29005 then
29006 return True;
29007 end if;
29008 end if;
29010 Next (Clause);
29011 end loop;
29013 return False;
29014 end Unit_In_Context;
29016 -- Start of processing for Unit_Is_Visible
29018 begin
29019 -- The currrent unit is directly visible
29021 if Curr = U then
29022 return True;
29024 elsif Unit_In_Context (Curr) then
29025 return True;
29027 -- If the current unit is a body, check the context of the spec
29029 elsif Nkind (Unit (Curr)) = N_Package_Body
29030 or else
29031 (Nkind (Unit (Curr)) = N_Subprogram_Body
29032 and then not Acts_As_Spec (Unit (Curr)))
29033 then
29034 if Unit_In_Context (Library_Unit (Curr)) then
29035 return True;
29036 end if;
29037 end if;
29039 -- If the spec is a child unit, examine the parents
29041 if Is_Child_Unit (Curr_Entity) then
29042 if Nkind (Unit (Curr)) in N_Unit_Body then
29043 return
29044 Unit_In_Parent_Context
29045 (Parent_Spec (Unit (Library_Unit (Curr))));
29046 else
29047 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
29048 end if;
29050 else
29051 return False;
29052 end if;
29053 end Unit_Is_Visible;
29055 ------------------------------
29056 -- Universal_Interpretation --
29057 ------------------------------
29059 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
29060 Index : Interp_Index;
29061 It : Interp;
29063 begin
29064 -- The argument may be a formal parameter of an operator or subprogram
29065 -- with multiple interpretations, or else an expression for an actual.
29067 if Nkind (Opnd) = N_Defining_Identifier
29068 or else not Is_Overloaded (Opnd)
29069 then
29070 if Is_Universal_Numeric_Type (Etype (Opnd)) then
29071 return Etype (Opnd);
29072 else
29073 return Empty;
29074 end if;
29076 else
29077 Get_First_Interp (Opnd, Index, It);
29078 while Present (It.Typ) loop
29079 if Is_Universal_Numeric_Type (It.Typ) then
29080 return It.Typ;
29081 end if;
29083 Get_Next_Interp (Index, It);
29084 end loop;
29086 return Empty;
29087 end if;
29088 end Universal_Interpretation;
29090 ---------------
29091 -- Unqualify --
29092 ---------------
29094 function Unqualify (Expr : Node_Id) return Node_Id is
29095 begin
29096 -- Recurse to handle unlikely case of multiple levels of qualification
29098 if Nkind (Expr) = N_Qualified_Expression then
29099 return Unqualify (Expression (Expr));
29101 -- Normal case, not a qualified expression
29103 else
29104 return Expr;
29105 end if;
29106 end Unqualify;
29108 -----------------
29109 -- Unqual_Conv --
29110 -----------------
29112 function Unqual_Conv (Expr : Node_Id) return Node_Id is
29113 begin
29114 -- Recurse to handle unlikely case of multiple levels of qualification
29115 -- and/or conversion.
29117 if Nkind (Expr) in N_Qualified_Expression
29118 | N_Type_Conversion
29119 | N_Unchecked_Type_Conversion
29120 then
29121 return Unqual_Conv (Expression (Expr));
29123 -- Normal case, not a qualified expression
29125 else
29126 return Expr;
29127 end if;
29128 end Unqual_Conv;
29130 --------------------
29131 -- Validated_View --
29132 --------------------
29134 function Validated_View (Typ : Entity_Id) return Entity_Id is
29135 begin
29136 -- Scalar types can be always validated. In fast, switiching to the base
29137 -- type would drop the range constraints and force validation to use a
29138 -- larger type than necessary.
29140 if Is_Scalar_Type (Typ) then
29141 return Typ;
29143 -- Array types can be validated even when they are derived, because
29144 -- validation only requires their bounds and component types to be
29145 -- accessible. In fact, switching to the parent type would pollute
29146 -- expansion of attribute Valid_Scalars with unnecessary conversion
29147 -- that might not be eliminated by the frontend.
29149 elsif Is_Array_Type (Typ) then
29150 return Typ;
29152 -- For other types, in particular for record subtypes, we switch to the
29153 -- base type.
29155 elsif not Is_Base_Type (Typ) then
29156 return Validated_View (Base_Type (Typ));
29158 -- Obtain the full view of the input type by stripping away concurrency,
29159 -- derivations, and privacy.
29161 elsif Is_Concurrent_Type (Typ) then
29162 if Present (Corresponding_Record_Type (Typ)) then
29163 return Corresponding_Record_Type (Typ);
29164 else
29165 return Typ;
29166 end if;
29168 elsif Is_Derived_Type (Typ) then
29169 return Validated_View (Etype (Typ));
29171 elsif Is_Private_Type (Typ) then
29172 if Present (Underlying_Full_View (Typ)) then
29173 return Validated_View (Underlying_Full_View (Typ));
29175 elsif Present (Full_View (Typ)) then
29176 return Validated_View (Full_View (Typ));
29177 else
29178 return Typ;
29179 end if;
29181 elsif From_Limited_With (Typ) then
29182 if Has_Non_Limited_View (Typ) then
29183 return Validated_View (Non_Limited_View (Typ));
29184 else
29185 return Typ;
29186 end if;
29188 else
29189 return Typ;
29190 end if;
29191 end Validated_View;
29193 -----------------------
29194 -- Visible_Ancestors --
29195 -----------------------
29197 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
29198 List_1 : Elist_Id;
29199 List_2 : Elist_Id;
29200 Elmt : Elmt_Id;
29202 begin
29203 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
29205 -- Collect all the parents and progenitors of Typ. If the full-view of
29206 -- private parents and progenitors is available then it is used to
29207 -- generate the list of visible ancestors; otherwise their partial
29208 -- view is added to the resulting list.
29210 Collect_Parents
29211 (T => Typ,
29212 List => List_1,
29213 Use_Full_View => True);
29215 Collect_Interfaces
29216 (T => Typ,
29217 Ifaces_List => List_2,
29218 Exclude_Parents => True,
29219 Use_Full_View => True);
29221 -- Join the two lists. Avoid duplications because an interface may
29222 -- simultaneously be parent and progenitor of a type.
29224 Elmt := First_Elmt (List_2);
29225 while Present (Elmt) loop
29226 Append_Unique_Elmt (Node (Elmt), List_1);
29227 Next_Elmt (Elmt);
29228 end loop;
29230 return List_1;
29231 end Visible_Ancestors;
29233 ---------------------------
29234 -- Warn_On_Hiding_Entity --
29235 ---------------------------
29237 procedure Warn_On_Hiding_Entity
29238 (N : Node_Id;
29239 Hidden, Visible : Entity_Id;
29240 On_Use_Clause : Boolean)
29242 begin
29243 -- Don't warn for record components since they always have a well
29244 -- defined scope which does not confuse other uses. Note that in
29245 -- some cases, Ekind has not been set yet.
29247 if Ekind (Hidden) /= E_Component
29248 and then Ekind (Hidden) /= E_Discriminant
29249 and then Nkind (Parent (Hidden)) /= N_Component_Declaration
29250 and then Ekind (Visible) /= E_Component
29251 and then Ekind (Visible) /= E_Discriminant
29252 and then Nkind (Parent (Visible)) /= N_Component_Declaration
29254 -- Don't warn for one character variables. It is too common to use
29255 -- such variables as locals and will just cause too many false hits.
29257 and then Length_Of_Name (Chars (Hidden)) /= 1
29259 -- Don't warn for non-source entities
29261 and then Comes_From_Source (Hidden)
29262 and then Comes_From_Source (Visible)
29264 -- Don't warn within a generic instantiation
29266 and then not In_Instance
29268 -- Don't warn unless entity in question is in extended main source
29270 and then In_Extended_Main_Source_Unit (Visible)
29272 -- Finally, in the case of a declaration, the hidden entity must
29273 -- be either immediately visible or use visible (i.e. from a used
29274 -- package). In the case of a use clause, the visible entity must
29275 -- be immediately visible.
29277 and then
29278 (if On_Use_Clause then
29279 Is_Immediately_Visible (Visible)
29280 else
29281 (Is_Immediately_Visible (Hidden)
29282 or else
29283 Is_Potentially_Use_Visible (Hidden)))
29284 then
29285 if On_Use_Clause then
29286 Error_Msg_Sloc := Sloc (Visible);
29287 Error_Msg_NE ("visible declaration of&# hides homonym "
29288 & "from use clause?h?", N, Hidden);
29289 else
29290 Error_Msg_Sloc := Sloc (Hidden);
29291 Error_Msg_NE ("declaration hides &#?h?", N, Visible);
29292 end if;
29293 end if;
29294 end Warn_On_Hiding_Entity;
29296 ----------------------
29297 -- Within_Init_Proc --
29298 ----------------------
29300 function Within_Init_Proc return Boolean is
29301 S : Entity_Id;
29303 begin
29304 S := Current_Scope;
29305 while not Is_Overloadable (S) loop
29306 if S = Standard_Standard then
29307 return False;
29308 else
29309 S := Scope (S);
29310 end if;
29311 end loop;
29313 return Is_Init_Proc (S);
29314 end Within_Init_Proc;
29316 ---------------------------
29317 -- Within_Protected_Type --
29318 ---------------------------
29320 function Within_Protected_Type (E : Entity_Id) return Boolean is
29321 Scop : Entity_Id := Scope (E);
29323 begin
29324 while Present (Scop) loop
29325 if Ekind (Scop) = E_Protected_Type then
29326 return True;
29327 end if;
29329 Scop := Scope (Scop);
29330 end loop;
29332 return False;
29333 end Within_Protected_Type;
29335 ------------------
29336 -- Within_Scope --
29337 ------------------
29339 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
29340 begin
29341 return Scope_Within_Or_Same (Scope (E), S);
29342 end Within_Scope;
29344 ----------------
29345 -- Wrong_Type --
29346 ----------------
29348 procedure Wrong_Type
29349 (Expr : Node_Id;
29350 Expected_Type : Entity_Id;
29351 Multiple : Boolean := False)
29353 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
29354 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
29356 Err_Msg_Exp_Typ : Entity_Id := Expected_Type;
29357 -- Type entity used when printing errors concerning the expected type
29359 Matching_Field : Entity_Id;
29360 -- Entity to give a more precise suggestion on how to write a one-
29361 -- element positional aggregate.
29363 function Has_One_Matching_Field return Boolean;
29364 -- Determines if Expec_Type is a record type with a single component or
29365 -- discriminant whose type matches the found type or is one dimensional
29366 -- array whose component type matches the found type. In the case of
29367 -- one discriminant, we ignore the variant parts. That's not accurate,
29368 -- but good enough for the warning.
29370 ----------------------------
29371 -- Has_One_Matching_Field --
29372 ----------------------------
29374 function Has_One_Matching_Field return Boolean is
29375 E : Entity_Id;
29377 begin
29378 Matching_Field := Empty;
29380 if Is_Array_Type (Expec_Type)
29381 and then Number_Dimensions (Expec_Type) = 1
29382 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
29383 then
29384 -- Use type name if available. This excludes multidimensional
29385 -- arrays and anonymous arrays.
29387 if Comes_From_Source (Expec_Type) then
29388 Matching_Field := Expec_Type;
29390 -- For an assignment, use name of target
29392 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
29393 and then Is_Entity_Name (Name (Parent (Expr)))
29394 then
29395 Matching_Field := Entity (Name (Parent (Expr)));
29396 end if;
29398 return True;
29400 elsif not Is_Record_Type (Expec_Type) then
29401 return False;
29403 else
29404 E := First_Entity (Expec_Type);
29405 loop
29406 if No (E) then
29407 return False;
29409 elsif Ekind (E) not in E_Discriminant | E_Component
29410 or else Chars (E) in Name_uTag | Name_uParent
29411 then
29412 Next_Entity (E);
29414 else
29415 exit;
29416 end if;
29417 end loop;
29419 if not Covers (Etype (E), Found_Type) then
29420 return False;
29422 elsif Present (Next_Entity (E))
29423 and then (Ekind (E) = E_Component
29424 or else Ekind (Next_Entity (E)) = E_Discriminant)
29425 then
29426 return False;
29428 else
29429 Matching_Field := E;
29430 return True;
29431 end if;
29432 end if;
29433 end Has_One_Matching_Field;
29435 -- Start of processing for Wrong_Type
29437 begin
29438 -- Don't output message if either type is Any_Type, or if a message
29439 -- has already been posted for this node and we do not want multiple
29440 -- error messages. We need to do the latter check explicitly (it is
29441 -- ordinarily done in Errout) because we are using '!' to force the
29442 -- output of the error messages.
29444 if Expec_Type = Any_Type
29445 or else Found_Type = Any_Type
29446 or else (Error_Posted (Expr) and then not Multiple)
29447 then
29448 return;
29450 -- If one of the types is a Taft-Amendment type and the other it its
29451 -- completion, it must be an illegal use of a TAT in the spec, for
29452 -- which an error was already emitted. Avoid cascaded errors.
29454 elsif Is_Incomplete_Type (Expec_Type)
29455 and then Has_Completion_In_Body (Expec_Type)
29456 and then Full_View (Expec_Type) = Etype (Expr)
29457 then
29458 return;
29460 elsif Is_Incomplete_Type (Etype (Expr))
29461 and then Has_Completion_In_Body (Etype (Expr))
29462 and then Full_View (Etype (Expr)) = Expec_Type
29463 then
29464 return;
29465 end if;
29467 -- Avoid printing internally generated subtypes in error messages and
29468 -- instead use the corresponding first subtype in such cases.
29470 if not Comes_From_Source (Err_Msg_Exp_Typ)
29471 or else not Comes_From_Source (Declaration_Node (Err_Msg_Exp_Typ))
29472 then
29473 Err_Msg_Exp_Typ := First_Subtype (Err_Msg_Exp_Typ);
29474 end if;
29476 -- An interesting special check. If the expression is parenthesized
29477 -- and its type corresponds to the type of the sole component of the
29478 -- expected record type, or to the component type of the expected one
29479 -- dimensional array type, then assume we have a bad aggregate attempt.
29481 if Nkind (Expr) in N_Subexpr
29482 and then Paren_Count (Expr) /= 0
29483 and then Has_One_Matching_Field
29484 then
29485 Error_Msg_N ("positional aggregate cannot have one component", Expr);
29487 if Present (Matching_Field) then
29488 if Is_Array_Type (Expec_Type) then
29489 Error_Msg_NE
29490 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
29491 else
29492 Error_Msg_NE
29493 ("\write instead `& ='> ...`", Expr, Matching_Field);
29494 end if;
29495 end if;
29497 -- Another special check, if we are looking for a pool-specific access
29498 -- type and we found an E_Access_Attribute_Type, then we have the case
29499 -- of an Access attribute being used in a context which needs a pool-
29500 -- specific type, which is never allowed. The one extra check we make
29501 -- is that the expected designated type covers the Found_Type.
29503 elsif Is_Access_Type (Expec_Type)
29504 and then Ekind (Found_Type) = E_Access_Attribute_Type
29505 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
29506 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
29507 and then Covers
29508 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
29509 then
29510 Error_Msg_N
29511 ("result must be general access type!", Expr);
29512 Error_Msg_NE -- CODEFIX
29513 ("\add ALL to }!", Expr, Err_Msg_Exp_Typ);
29515 -- Another special check, if the expected type is an integer type,
29516 -- but the expression is of type System.Address, and the parent is
29517 -- an addition or subtraction operation whose left operand is the
29518 -- expression in question and whose right operand is of an integral
29519 -- type, then this is an attempt at address arithmetic, so give
29520 -- appropriate message.
29522 elsif Is_Integer_Type (Expec_Type)
29523 and then Is_RTE (Found_Type, RE_Address)
29524 and then Nkind (Parent (Expr)) in N_Op_Add | N_Op_Subtract
29525 and then Expr = Left_Opnd (Parent (Expr))
29526 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
29527 then
29528 Error_Msg_N
29529 ("address arithmetic not predefined in package System",
29530 Parent (Expr));
29531 Error_Msg_N
29532 ("\possible missing with/use of System.Storage_Elements",
29533 Parent (Expr));
29534 return;
29536 -- If the expected type is an anonymous access type, as for access
29537 -- parameters and discriminants, the error is on the designated types.
29539 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
29540 if Comes_From_Source (Expec_Type) then
29541 Error_Msg_NE ("expected}!", Expr, Expec_Type);
29542 else
29543 Error_Msg_NE
29544 ("expected an access type with designated}",
29545 Expr, Designated_Type (Expec_Type));
29546 end if;
29548 if Is_Access_Type (Found_Type)
29549 and then not Comes_From_Source (Found_Type)
29550 then
29551 Error_Msg_NE
29552 ("\\found an access type with designated}!",
29553 Expr, Designated_Type (Found_Type));
29554 else
29555 if From_Limited_With (Found_Type) then
29556 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
29557 Error_Msg_Qual_Level := 99;
29558 Error_Msg_NE -- CODEFIX
29559 ("\\missing `WITH &;", Expr, Scope (Found_Type));
29560 Error_Msg_Qual_Level := 0;
29561 else
29562 Error_Msg_NE ("found}!", Expr, Found_Type);
29563 end if;
29564 end if;
29566 -- Normal case of one type found, some other type expected
29568 else
29569 -- If the names of the two types are the same, see if some number
29570 -- of levels of qualification will help. Don't try more than three
29571 -- levels, and if we get to standard, it's no use (and probably
29572 -- represents an error in the compiler) Also do not bother with
29573 -- internal scope names.
29575 declare
29576 Expec_Scope : Entity_Id;
29577 Found_Scope : Entity_Id;
29579 begin
29580 Expec_Scope := Expec_Type;
29581 Found_Scope := Found_Type;
29583 for Levels in Nat range 0 .. 3 loop
29584 if Chars (Expec_Scope) /= Chars (Found_Scope) then
29585 Error_Msg_Qual_Level := Levels;
29586 exit;
29587 end if;
29589 Expec_Scope := Scope (Expec_Scope);
29590 Found_Scope := Scope (Found_Scope);
29592 exit when Expec_Scope = Standard_Standard
29593 or else Found_Scope = Standard_Standard
29594 or else not Comes_From_Source (Expec_Scope)
29595 or else not Comes_From_Source (Found_Scope);
29596 end loop;
29597 end;
29599 if Is_Record_Type (Expec_Type)
29600 and then Present (Corresponding_Remote_Type (Expec_Type))
29601 then
29602 Error_Msg_NE ("expected}!", Expr,
29603 Corresponding_Remote_Type (Expec_Type));
29604 else
29605 Error_Msg_NE ("expected}!", Expr, Err_Msg_Exp_Typ);
29606 end if;
29608 if Is_Entity_Name (Expr)
29609 and then Is_Package_Or_Generic_Package (Entity (Expr))
29610 then
29611 Error_Msg_N ("\\found package name!", Expr);
29613 elsif Is_Entity_Name (Expr)
29614 and then Ekind (Entity (Expr)) in E_Procedure | E_Generic_Procedure
29615 then
29616 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
29617 Error_Msg_N
29618 ("found procedure name, possibly missing Access attribute!",
29619 Expr);
29620 else
29621 Error_Msg_N
29622 ("\\found procedure name instead of function!", Expr);
29623 end if;
29625 elsif Nkind (Expr) = N_Function_Call
29626 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
29627 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
29628 and then No (Parameter_Associations (Expr))
29629 then
29630 Error_Msg_N
29631 ("found function name, possibly missing Access attribute!",
29632 Expr);
29634 -- Catch common error: a prefix or infix operator which is not
29635 -- directly visible because the type isn't.
29637 elsif Nkind (Expr) in N_Op
29638 and then Is_Overloaded (Expr)
29639 and then not Is_Immediately_Visible (Expec_Type)
29640 and then not Is_Potentially_Use_Visible (Expec_Type)
29641 and then not In_Use (Expec_Type)
29642 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
29643 then
29644 Error_Msg_N
29645 ("operator of the type is not directly visible!", Expr);
29647 elsif Ekind (Found_Type) = E_Void
29648 and then Present (Parent (Found_Type))
29649 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
29650 then
29651 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
29653 else
29654 Error_Msg_NE ("\\found}!", Expr, Found_Type);
29655 end if;
29657 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
29658 -- of the same modular type, and (M1 and M2) = 0 was intended.
29660 if Expec_Type = Standard_Boolean
29661 and then Is_Modular_Integer_Type (Found_Type)
29662 and then Nkind (Parent (Expr)) in N_Op_And | N_Op_Or | N_Op_Xor
29663 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
29664 then
29665 declare
29666 Op : constant Node_Id := Right_Opnd (Parent (Expr));
29667 L : constant Node_Id := Left_Opnd (Op);
29668 R : constant Node_Id := Right_Opnd (Op);
29670 begin
29671 -- The case for the message is when the left operand of the
29672 -- comparison is the same modular type, or when it is an
29673 -- integer literal (or other universal integer expression),
29674 -- which would have been typed as the modular type if the
29675 -- parens had been there.
29677 if (Etype (L) = Found_Type
29678 or else
29679 Etype (L) = Universal_Integer)
29680 and then Is_Integer_Type (Etype (R))
29681 then
29682 Error_Msg_N
29683 ("\\possible missing parens for modular operation", Expr);
29684 end if;
29685 end;
29686 end if;
29688 -- Reset error message qualification indication
29690 Error_Msg_Qual_Level := 0;
29691 end if;
29692 end Wrong_Type;
29694 --------------------------------
29695 -- Yields_Synchronized_Object --
29696 --------------------------------
29698 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
29699 Has_Sync_Comp : Boolean := False;
29700 Id : Entity_Id;
29702 begin
29703 -- An array type yields a synchronized object if its component type
29704 -- yields a synchronized object.
29706 if Is_Array_Type (Typ) then
29707 return Yields_Synchronized_Object (Component_Type (Typ));
29709 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
29710 -- yields a synchronized object by default.
29712 elsif Is_Descendant_Of_Suspension_Object (Typ) then
29713 return True;
29715 -- A protected type yields a synchronized object by default
29717 elsif Is_Protected_Type (Typ) then
29718 return True;
29720 -- A record type or type extension yields a synchronized object when its
29721 -- discriminants (if any) lack default values and all components are of
29722 -- a type that yields a synchronized object.
29724 elsif Is_Record_Type (Typ) then
29726 -- Inspect all entities defined in the scope of the type, looking for
29727 -- components of a type that does not yield a synchronized object or
29728 -- for discriminants with default values.
29730 Id := First_Entity (Typ);
29731 while Present (Id) loop
29732 if Comes_From_Source (Id) then
29733 if Ekind (Id) = E_Component then
29734 if Yields_Synchronized_Object (Etype (Id)) then
29735 Has_Sync_Comp := True;
29737 -- The component does not yield a synchronized object
29739 else
29740 return False;
29741 end if;
29743 elsif Ekind (Id) = E_Discriminant
29744 and then Present (Expression (Parent (Id)))
29745 then
29746 return False;
29747 end if;
29748 end if;
29750 Next_Entity (Id);
29751 end loop;
29753 -- Ensure that the parent type of a type extension yields a
29754 -- synchronized object.
29756 if Etype (Typ) /= Typ
29757 and then not Is_Private_Type (Etype (Typ))
29758 and then not Yields_Synchronized_Object (Etype (Typ))
29759 then
29760 return False;
29761 end if;
29763 -- If we get here, then all discriminants lack default values and all
29764 -- components are of a type that yields a synchronized object.
29766 return Has_Sync_Comp;
29768 -- A synchronized interface type yields a synchronized object by default
29770 elsif Is_Synchronized_Interface (Typ) then
29771 return True;
29773 -- A task type yields a synchronized object by default
29775 elsif Is_Task_Type (Typ) then
29776 return True;
29778 -- A private type yields a synchronized object if its underlying type
29779 -- does.
29781 elsif Is_Private_Type (Typ)
29782 and then Present (Underlying_Type (Typ))
29783 then
29784 return Yields_Synchronized_Object (Underlying_Type (Typ));
29786 -- Otherwise the type does not yield a synchronized object
29788 else
29789 return False;
29790 end if;
29791 end Yields_Synchronized_Object;
29793 ---------------------------
29794 -- Yields_Universal_Type --
29795 ---------------------------
29797 function Yields_Universal_Type (N : Node_Id) return Boolean is
29798 begin
29799 -- Integer and real literals are of a universal type
29801 if Nkind (N) in N_Integer_Literal | N_Real_Literal then
29802 return True;
29804 -- The values of certain attributes are of a universal type
29806 elsif Nkind (N) = N_Attribute_Reference then
29807 return
29808 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
29810 -- ??? There are possibly other cases to consider
29812 else
29813 return False;
29814 end if;
29815 end Yields_Universal_Type;
29817 package body Interval_Lists is
29819 procedure Check_Consistency (Intervals : Discrete_Interval_List);
29820 -- Check that list is sorted, lacks null intervals, and has gaps
29821 -- between intervals.
29823 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval;
29824 -- Given an element of a Discrete_Choices list, a
29825 -- Static_Discrete_Predicate list, or an Others_Discrete_Choices
29826 -- list (but not an N_Others_Choice node) return the corresponding
29827 -- interval. If an element that does not represent a single
29828 -- contiguous interval due to a static predicate (or which
29829 -- represents a single contiguous interval whose bounds depend on
29830 -- a static predicate) is encountered, then that is an error on the
29831 -- part of whoever built the list in question.
29833 function In_Interval
29834 (Value : Uint; Interval : Discrete_Interval) return Boolean;
29835 -- Does the given value lie within the given interval?
29837 procedure Normalize_Interval_List
29838 (List : in out Discrete_Interval_List; Last : out Nat);
29839 -- Perform sorting and merging as required by Check_Consistency
29841 -------------------------
29842 -- Aggregate_Intervals --
29843 -------------------------
29845 function Aggregate_Intervals (N : Node_Id) return Discrete_Interval_List
29847 pragma Assert (Nkind (N) = N_Aggregate
29848 and then Is_Array_Type (Etype (N)));
29850 function Unmerged_Intervals_Count return Nat;
29851 -- Count the number of intervals given in the aggregate N; the others
29852 -- choice (if present) is not taken into account.
29854 ------------------------------
29855 -- Unmerged_Intervals_Count --
29856 ------------------------------
29858 function Unmerged_Intervals_Count return Nat is
29859 Count : Nat := 0;
29860 Choice : Node_Id;
29861 Comp : Node_Id;
29862 begin
29863 Comp := First (Component_Associations (N));
29864 while Present (Comp) loop
29865 Choice := First (Choices (Comp));
29867 while Present (Choice) loop
29868 if Nkind (Choice) /= N_Others_Choice then
29869 Count := Count + 1;
29870 end if;
29872 Next (Choice);
29873 end loop;
29875 Next (Comp);
29876 end loop;
29878 return Count;
29879 end Unmerged_Intervals_Count;
29881 -- Local variables
29883 Comp : Node_Id;
29884 Max_I : constant Nat := Unmerged_Intervals_Count;
29885 Intervals : Discrete_Interval_List (1 .. Max_I);
29886 Num_I : Nat := 0;
29888 -- Start of processing for Aggregate_Intervals
29890 begin
29891 -- No action needed if there are no intervals
29893 if Max_I = 0 then
29894 return Intervals;
29895 end if;
29897 -- Internally store all the unsorted intervals
29899 Comp := First (Component_Associations (N));
29900 while Present (Comp) loop
29901 declare
29902 Choice_Intervals : constant Discrete_Interval_List :=
29903 Choice_List_Intervals (Choices (Comp));
29904 begin
29905 for J in Choice_Intervals'Range loop
29906 Num_I := Num_I + 1;
29907 Intervals (Num_I) := Choice_Intervals (J);
29908 end loop;
29909 end;
29911 Next (Comp);
29912 end loop;
29914 -- Normalize the lists sorting and merging the intervals
29916 declare
29917 Aggr_Intervals : Discrete_Interval_List (1 .. Num_I) :=
29918 Intervals (1 .. Num_I);
29919 begin
29920 Normalize_Interval_List (Aggr_Intervals, Num_I);
29921 Check_Consistency (Aggr_Intervals (1 .. Num_I));
29922 return Aggr_Intervals (1 .. Num_I);
29923 end;
29924 end Aggregate_Intervals;
29926 ------------------------
29927 -- Check_Consistency --
29928 ------------------------
29930 procedure Check_Consistency (Intervals : Discrete_Interval_List) is
29931 begin
29932 if Serious_Errors_Detected > 0 then
29933 return;
29934 end if;
29936 -- low bound is 1 and high bound equals length
29937 pragma Assert (Intervals'First = 1 and Intervals'Last >= 0);
29938 for Idx in Intervals'Range loop
29939 -- each interval is non-null
29940 pragma Assert (Intervals (Idx).Low <= Intervals (Idx).High);
29941 if Idx /= Intervals'First then
29942 -- intervals are sorted with non-empty gaps between them
29943 pragma Assert
29944 (Intervals (Idx - 1).High < (Intervals (Idx).Low - 1));
29945 null;
29946 end if;
29947 end loop;
29948 end Check_Consistency;
29950 ---------------------------
29951 -- Choice_List_Intervals --
29952 ---------------------------
29954 function Choice_List_Intervals
29955 (Discrete_Choices : List_Id) return Discrete_Interval_List
29957 function Unmerged_Choice_Count return Nat;
29958 -- The number of intervals before adjacent intervals are merged
29960 ---------------------------
29961 -- Unmerged_Choice_Count --
29962 ---------------------------
29964 function Unmerged_Choice_Count return Nat is
29965 Choice : Node_Id := First (Discrete_Choices);
29966 Count : Nat := 0;
29967 begin
29968 while Present (Choice) loop
29969 -- Non-contiguous choices involving static predicates
29970 -- have already been normalized away.
29972 if Nkind (Choice) = N_Others_Choice then
29973 Count :=
29974 Count + List_Length (Others_Discrete_Choices (Choice));
29975 else
29976 Count := Count + 1; -- an ordinary expression or range
29977 end if;
29979 Next (Choice);
29980 end loop;
29981 return Count;
29982 end Unmerged_Choice_Count;
29984 -- Local variables
29986 Choice : Node_Id := First (Discrete_Choices);
29987 Result : Discrete_Interval_List (1 .. Unmerged_Choice_Count);
29988 Count : Nat := 0;
29990 -- Start of processing for Choice_List_Intervals
29992 begin
29993 while Present (Choice) loop
29994 if Nkind (Choice) = N_Others_Choice then
29995 declare
29996 Others_Choice : Node_Id :=
29997 First (Others_Discrete_Choices (Choice));
29998 begin
29999 while Present (Others_Choice) loop
30000 Count := Count + 1;
30001 Result (Count) := Chosen_Interval (Others_Choice);
30002 Next (Others_Choice);
30003 end loop;
30004 end;
30005 else
30006 Count := Count + 1;
30007 Result (Count) := Chosen_Interval (Choice);
30008 end if;
30010 Next (Choice);
30011 end loop;
30013 pragma Assert (Count = Result'Last);
30014 Normalize_Interval_List (Result, Count);
30015 Check_Consistency (Result (1 .. Count));
30016 return Result (1 .. Count);
30017 end Choice_List_Intervals;
30019 ---------------------
30020 -- Chosen_Interval --
30021 ---------------------
30023 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval is
30024 begin
30025 case Nkind (Choice) is
30026 when N_Range =>
30027 return (Low => Expr_Value (Low_Bound (Choice)),
30028 High => Expr_Value (High_Bound (Choice)));
30030 when N_Subtype_Indication =>
30031 declare
30032 Range_Exp : constant Node_Id :=
30033 Range_Expression (Constraint (Choice));
30034 begin
30035 return (Low => Expr_Value (Low_Bound (Range_Exp)),
30036 High => Expr_Value (High_Bound (Range_Exp)));
30037 end;
30039 when N_Others_Choice =>
30040 raise Program_Error;
30042 when others =>
30043 if Is_Entity_Name (Choice) and then Is_Type (Entity (Choice))
30044 then
30045 return
30046 (Low => Expr_Value (Type_Low_Bound (Entity (Choice))),
30047 High => Expr_Value (Type_High_Bound (Entity (Choice))));
30048 else
30049 -- an expression
30050 return (Low | High => Expr_Value (Choice));
30051 end if;
30052 end case;
30053 end Chosen_Interval;
30055 -----------------
30056 -- In_Interval --
30057 -----------------
30059 function In_Interval
30060 (Value : Uint; Interval : Discrete_Interval) return Boolean is
30061 begin
30062 return Value >= Interval.Low and then Value <= Interval.High;
30063 end In_Interval;
30065 ---------------
30066 -- Is_Subset --
30067 ---------------
30069 function Is_Subset
30070 (Subset, Of_Set : Discrete_Interval_List) return Boolean
30072 -- Returns True iff for each interval of Subset we can find
30073 -- a single interval of Of_Set which contains the Subset interval.
30074 begin
30075 if Of_Set'Length = 0 then
30076 return Subset'Length = 0;
30077 end if;
30079 declare
30080 Set_Index : Pos range Of_Set'Range := Of_Set'First;
30082 begin
30083 for Ss_Idx in Subset'Range loop
30084 while not In_Interval
30085 (Value => Subset (Ss_Idx).Low,
30086 Interval => Of_Set (Set_Index))
30087 loop
30088 if Set_Index = Of_Set'Last then
30089 return False;
30090 end if;
30092 Set_Index := Set_Index + 1;
30093 end loop;
30095 if not In_Interval
30096 (Value => Subset (Ss_Idx).High,
30097 Interval => Of_Set (Set_Index))
30098 then
30099 return False;
30100 end if;
30101 end loop;
30102 end;
30104 return True;
30105 end Is_Subset;
30107 -----------------------------
30108 -- Normalize_Interval_List --
30109 -----------------------------
30111 procedure Normalize_Interval_List
30112 (List : in out Discrete_Interval_List; Last : out Nat)
30114 Temp_0 : Discrete_Interval := (others => Uint_0);
30115 -- Cope with Heap_Sort_G idiosyncrasies.
30117 function Is_Null (Idx : Pos) return Boolean;
30118 -- True iff List (Idx) defines a null range
30120 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean;
30121 -- Compare two list elements
30123 procedure Merge_Intervals (Null_Interval_Count : out Nat);
30124 -- Merge contiguous ranges by replacing one with merged range and
30125 -- the other with a null value. Return a count of the null intervals,
30126 -- both preexisting and those introduced by merging.
30128 procedure Move_Interval (From, To : Natural);
30129 -- Copy interval from one location to another
30131 function Read_Interval (From : Natural) return Discrete_Interval;
30132 -- Normal array indexing unless From = 0
30134 ----------------------
30135 -- Interval_Sorting --
30136 ----------------------
30138 package Interval_Sorting is
30139 new Gnat.Heap_Sort_G (Move_Interval, Lt_Interval);
30141 -------------
30142 -- Is_Null --
30143 -------------
30145 function Is_Null (Idx : Pos) return Boolean is
30146 begin
30147 return List (Idx).Low > List (Idx).High;
30148 end Is_Null;
30150 -----------------
30151 -- Lt_Interval --
30152 -----------------
30154 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean is
30155 Elem1 : constant Discrete_Interval := Read_Interval (Idx1);
30156 Elem2 : constant Discrete_Interval := Read_Interval (Idx2);
30157 Null_1 : constant Boolean := Elem1.Low > Elem1.High;
30158 Null_2 : constant Boolean := Elem2.Low > Elem2.High;
30159 begin
30160 if Null_1 /= Null_2 then
30161 -- So that sorting moves null intervals to high end
30162 return Null_2;
30164 elsif Elem1.Low /= Elem2.Low then
30165 return Elem1.Low < Elem2.Low;
30167 else
30168 return Elem1.High < Elem2.High;
30169 end if;
30170 end Lt_Interval;
30172 ---------------------
30173 -- Merge_Intervals --
30174 ---------------------
30176 procedure Merge_Intervals (Null_Interval_Count : out Nat) is
30177 Not_Null : Pos range List'Range;
30178 -- Index of the most recently examined non-null interval
30180 Null_Interval : constant Discrete_Interval :=
30181 (Low => Uint_1, High => Uint_0); -- any null range ok here
30182 begin
30183 if List'Length = 0 or else Is_Null (List'First) then
30184 Null_Interval_Count := List'Length;
30185 -- no non-null elements, so no merge candidates
30186 return;
30187 end if;
30189 Null_Interval_Count := 0;
30190 Not_Null := List'First;
30192 for Idx in List'First + 1 .. List'Last loop
30193 if Is_Null (Idx) then
30195 -- all remaining elements are null
30197 Null_Interval_Count :=
30198 Null_Interval_Count + List (Idx .. List'Last)'Length;
30199 return;
30201 elsif List (Idx).Low = List (Not_Null).High + 1 then
30203 -- Merge the two intervals into one; discard the other
30205 List (Not_Null).High := List (Idx).High;
30206 List (Idx) := Null_Interval;
30207 Null_Interval_Count := Null_Interval_Count + 1;
30209 else
30210 if List (Idx).Low <= List (Not_Null).High then
30211 raise Intervals_Error;
30212 end if;
30214 pragma Assert (List (Idx).Low > List (Not_Null).High);
30215 Not_Null := Idx;
30216 end if;
30217 end loop;
30218 end Merge_Intervals;
30220 -------------------
30221 -- Move_Interval --
30222 -------------------
30224 procedure Move_Interval (From, To : Natural) is
30225 Rhs : constant Discrete_Interval := Read_Interval (From);
30226 begin
30227 if To = 0 then
30228 Temp_0 := Rhs;
30229 else
30230 List (Pos (To)) := Rhs;
30231 end if;
30232 end Move_Interval;
30234 -------------------
30235 -- Read_Interval --
30236 -------------------
30238 function Read_Interval (From : Natural) return Discrete_Interval is
30239 begin
30240 if From = 0 then
30241 return Temp_0;
30242 else
30243 return List (Pos (From));
30244 end if;
30245 end Read_Interval;
30247 -- Start of processing for Normalize_Interval_Lists
30249 begin
30250 Interval_Sorting.Sort (Natural (List'Last));
30252 declare
30253 Null_Interval_Count : Nat;
30255 begin
30256 Merge_Intervals (Null_Interval_Count);
30257 Last := List'Last - Null_Interval_Count;
30259 if Null_Interval_Count /= 0 then
30260 -- Move null intervals introduced during merging to high end
30261 Interval_Sorting.Sort (Natural (List'Last));
30262 end if;
30263 end;
30264 end Normalize_Interval_List;
30266 --------------------
30267 -- Type_Intervals --
30268 --------------------
30270 function Type_Intervals (Typ : Entity_Id) return Discrete_Interval_List
30272 begin
30273 if Has_Static_Predicate (Typ) then
30274 declare
30275 -- No sorting or merging needed
30276 SDP_List : constant List_Id := Static_Discrete_Predicate (Typ);
30277 Range_Or_Expr : Node_Id := First (SDP_List);
30278 Result : Discrete_Interval_List (1 .. List_Length (SDP_List));
30280 begin
30281 for Idx in Result'Range loop
30282 Result (Idx) := Chosen_Interval (Range_Or_Expr);
30283 Next (Range_Or_Expr);
30284 end loop;
30286 pragma Assert (No (Range_Or_Expr));
30287 Check_Consistency (Result);
30288 return Result;
30289 end;
30290 else
30291 declare
30292 Low : constant Uint := Expr_Value (Type_Low_Bound (Typ));
30293 High : constant Uint := Expr_Value (Type_High_Bound (Typ));
30294 begin
30295 if Low > High then
30296 declare
30297 Null_Array : Discrete_Interval_List (1 .. 0);
30298 begin
30299 return Null_Array;
30300 end;
30301 else
30302 return (1 => (Low => Low, High => High));
30303 end if;
30304 end;
30305 end if;
30306 end Type_Intervals;
30308 end Interval_Lists;
30310 package body Old_Attr_Util is
30311 package body Conditional_Evaluation is
30312 type Determining_Expr_Context is
30313 (No_Context, If_Expr, Case_Expr, Short_Circuit_Op, Membership_Test);
30315 -- Determining_Expr_Context enumeration elements (except for
30316 -- No_Context) correspond to the list items in RM 6.1.1 definition
30317 -- of "determining expression".
30319 type Determining_Expr
30320 (Context : Determining_Expr_Context := No_Context)
30321 is record
30322 Expr : Node_Id := Empty;
30323 case Context is
30324 when Short_Circuit_Op =>
30325 Is_And_Then : Boolean;
30326 when If_Expr =>
30327 Is_Then_Part : Boolean;
30328 when Case_Expr =>
30329 Alternatives : Node_Id;
30330 when Membership_Test =>
30331 -- Given a subexpression of <exp4> in a membership test
30332 -- <exp1> in <exp2> | <exp3> | <exp4> | <exp5>
30333 -- the corresponding determining expression value would
30334 -- have First_Non_Preceding = <exp4> (See RM 6.1.1).
30335 First_Non_Preceding : Node_Id;
30336 when No_Context =>
30337 null;
30338 end case;
30339 end record;
30341 type Determining_Expression_List is
30342 array (Positive range <>) of Determining_Expr;
30344 function Determining_Condition (Det : Determining_Expr)
30345 return Node_Id;
30346 -- Given a determining expression, build a Boolean-valued
30347 -- condition that incorporates that expression into condition
30348 -- suitable for deciding whether to initialize a 'Old constant.
30349 -- Polarity is "True => initialize the constant".
30351 function Determining_Expressions
30352 (Expr : Node_Id; Expr_Trailer : Node_Id := Empty)
30353 return Determining_Expression_List;
30354 -- Given a conditionally evaluated expression, return its
30355 -- determining expressions.
30356 -- See RM 6.1.1 for definition of term "determining expressions".
30357 -- Tests should be performed in the order they occur in the
30358 -- array, with short circuiting.
30359 -- A determining expression need not be of a boolean type (e.g.,
30360 -- it might be the determining expression of a case expression).
30361 -- The Expr_Trailer parameter should be defaulted for nonrecursive
30362 -- calls.
30364 function Is_Conditionally_Evaluated (Expr : Node_Id) return Boolean;
30365 -- See RM 6.1.1 for definition of term "conditionally evaluated".
30367 function Is_Known_On_Entry (Expr : Node_Id) return Boolean;
30368 -- See RM 6.1.1 for definition of term "known on entry".
30370 --------------------------------------
30371 -- Conditional_Evaluation_Condition --
30372 --------------------------------------
30374 function Conditional_Evaluation_Condition
30375 (Expr : Node_Id) return Node_Id
30377 Determiners : constant Determining_Expression_List :=
30378 Determining_Expressions (Expr);
30379 Loc : constant Source_Ptr := Sloc (Expr);
30380 Result : Node_Id :=
30381 New_Occurrence_Of (Standard_True, Loc);
30382 begin
30383 pragma Assert (Determiners'Length > 0 or else
30384 Is_Anonymous_Access_Type (Etype (Expr)));
30386 for I in Determiners'Range loop
30387 Result := Make_And_Then
30388 (Loc,
30389 Left_Opnd => Result,
30390 Right_Opnd =>
30391 Determining_Condition (Determiners (I)));
30392 end loop;
30393 return Result;
30394 end Conditional_Evaluation_Condition;
30396 ---------------------------
30397 -- Determining_Condition --
30398 ---------------------------
30400 function Determining_Condition (Det : Determining_Expr) return Node_Id
30402 Loc : constant Source_Ptr := Sloc (Det.Expr);
30403 begin
30404 case Det.Context is
30405 when Short_Circuit_Op =>
30406 if Det.Is_And_Then then
30407 return New_Copy_Tree (Det.Expr);
30408 else
30409 return Make_Op_Not (Loc, New_Copy_Tree (Det.Expr));
30410 end if;
30412 when If_Expr =>
30413 if Det.Is_Then_Part then
30414 return New_Copy_Tree (Det.Expr);
30415 else
30416 return Make_Op_Not (Loc, New_Copy_Tree (Det.Expr));
30417 end if;
30419 when Case_Expr =>
30420 declare
30421 Alts : List_Id := Discrete_Choices (Det.Alternatives);
30422 begin
30423 if Nkind (First (Alts)) = N_Others_Choice then
30424 Alts := Others_Discrete_Choices (First (Alts));
30425 end if;
30427 return Make_In (Loc,
30428 Left_Opnd => New_Copy_Tree (Det.Expr),
30429 Right_Opnd => Empty,
30430 Alternatives => New_Copy_List (Alts));
30431 end;
30433 when Membership_Test =>
30434 declare
30435 function Copy_Prefix
30436 (List : List_Id; Suffix_Start : Node_Id)
30437 return List_Id;
30438 -- Given a list and a member of that list, returns
30439 -- a copy (similar to Nlists.New_Copy_List) of the
30440 -- prefix of the list up to but not including
30441 -- Suffix_Start.
30443 -----------------
30444 -- Copy_Prefix --
30445 -----------------
30447 function Copy_Prefix
30448 (List : List_Id; Suffix_Start : Node_Id)
30449 return List_Id
30451 Result : constant List_Id := New_List;
30452 Elem : Node_Id := First (List);
30453 begin
30454 while Elem /= Suffix_Start loop
30455 Append (New_Copy (Elem), Result);
30456 Next (Elem);
30457 pragma Assert (Present (Elem));
30458 end loop;
30459 return Result;
30460 end Copy_Prefix;
30462 begin
30463 return Make_In (Loc,
30464 Left_Opnd => New_Copy_Tree (Left_Opnd (Det.Expr)),
30465 Right_Opnd => Empty,
30466 Alternatives => Copy_Prefix
30467 (Alternatives (Det.Expr),
30468 Det.First_Non_Preceding));
30469 end;
30471 when No_Context =>
30472 raise Program_Error;
30473 end case;
30474 end Determining_Condition;
30476 -----------------------------
30477 -- Determining_Expressions --
30478 -----------------------------
30480 function Determining_Expressions
30481 (Expr : Node_Id; Expr_Trailer : Node_Id := Empty)
30482 return Determining_Expression_List
30484 Par : Node_Id := Expr;
30485 Trailer : Node_Id := Expr_Trailer;
30486 Next_Element : Determining_Expr;
30487 begin
30488 -- We want to stop climbing up the tree when we reach the
30489 -- postcondition expression. An aspect_specification is
30490 -- transformed into a pragma, so reaching a pragma is our
30491 -- termination condition. This relies on the fact that
30492 -- pragmas are not allowed in declare expressions (or any
30493 -- other kind of expression).
30495 loop
30496 Next_Element.Expr := Empty;
30498 case Nkind (Par) is
30499 when N_Short_Circuit =>
30500 if Trailer = Right_Opnd (Par) then
30501 Next_Element :=
30502 (Expr => Left_Opnd (Par),
30503 Context => Short_Circuit_Op,
30504 Is_And_Then => Nkind (Par) = N_And_Then);
30505 end if;
30507 when N_If_Expression =>
30508 -- For an expression like
30509 -- (if C1 then ... elsif C2 then ... else Foo'Old)
30510 -- the RM says are two determining expressions,
30511 -- C1 and C2. Our treatment here (where we only add
30512 -- one determining expression to the list) is ok because
30513 -- we will see two if-expressions, one within the other.
30515 if Trailer /= First (Expressions (Par)) then
30516 Next_Element :=
30517 (Expr => First (Expressions (Par)),
30518 Context => If_Expr,
30519 Is_Then_Part =>
30520 Trailer = Next (First (Expressions (Par))));
30521 end if;
30523 when N_Case_Expression_Alternative =>
30524 pragma Assert (Nkind (Parent (Par)) = N_Case_Expression);
30526 Next_Element :=
30527 (Expr => Expression (Parent (Par)),
30528 Context => Case_Expr,
30529 Alternatives => Par);
30531 when N_Membership_Test =>
30532 if Trailer /= Left_Opnd (Par)
30533 and then Is_Non_Empty_List (Alternatives (Par))
30534 and then Trailer /= First (Alternatives (Par))
30535 then
30536 pragma Assert (No (Right_Opnd (Par)));
30537 pragma Assert
30538 (Is_List_Member (Trailer)
30539 and then List_Containing (Trailer)
30540 = Alternatives (Par));
30542 -- This one is different than the others
30543 -- because one element in the array result
30544 -- may represent multiple determining
30545 -- expressions (i.e. every member of the list
30546 -- Alternatives (Par)
30547 -- up to but not including Trailer).
30549 Next_Element :=
30550 (Expr => Par,
30551 Context => Membership_Test,
30552 First_Non_Preceding => Trailer);
30553 end if;
30555 when N_Pragma =>
30556 pragma Assert
30557 (Get_Pragma_Id (Pragma_Name (Par)) in
30558 Pragma_Check
30559 | Pragma_Contract_Cases
30560 | Pragma_Exceptional_Cases
30561 | Pragma_Post
30562 | Pragma_Postcondition
30563 | Pragma_Post_Class
30564 | Pragma_Refined_Post
30565 | Pragma_Test_Case);
30567 return (1 .. 0 => <>); -- recursion terminates here
30569 when N_Empty =>
30570 -- This case should be impossible, but if it does
30571 -- happen somehow then we don't want an infinite loop.
30572 raise Program_Error;
30574 when others =>
30575 null;
30576 end case;
30578 Trailer := Par;
30579 Par := Parent (Par);
30581 if Present (Next_Element.Expr) then
30582 return Determining_Expressions
30583 (Expr => Par, Expr_Trailer => Trailer)
30584 & Next_Element;
30585 end if;
30586 end loop;
30587 end Determining_Expressions;
30589 -----------------------------------------
30590 -- Eligible_For_Conditional_Evaluation --
30591 -----------------------------------------
30593 function Eligible_For_Conditional_Evaluation
30594 (Expr : Node_Id) return Boolean
30596 begin
30597 if Is_Anonymous_Access_Type (Etype (Expr)) then
30598 -- The code in exp_attr.adb that also builds declarations
30599 -- for 'Old constants doesn't handle the anonymous access
30600 -- type case correctly, so we avoid that problem by
30601 -- returning True here.
30602 return True;
30604 elsif Ada_Version < Ada_2022 then
30605 return False;
30607 elsif Inside_Class_Condition_Preanalysis then
30608 -- No need to evaluate it during preanalysis of a class-wide
30609 -- pre/postcondition since the expression is not installed yet
30610 -- on its definite context.
30611 return False;
30613 elsif not Is_Conditionally_Evaluated (Expr) then
30614 return False;
30615 else
30616 declare
30617 Determiners : constant Determining_Expression_List :=
30618 Determining_Expressions (Expr);
30619 begin
30620 pragma Assert (if Serious_Errors_Detected = 0 then
30621 Determiners'Length > 0);
30623 for Idx in Determiners'Range loop
30624 if not Is_Known_On_Entry (Determiners (Idx).Expr) then
30625 return False;
30626 end if;
30627 end loop;
30628 end;
30629 return True;
30630 end if;
30631 end Eligible_For_Conditional_Evaluation;
30633 --------------------------------
30634 -- Is_Conditionally_Evaluated --
30635 --------------------------------
30637 function Is_Conditionally_Evaluated (Expr : Node_Id) return Boolean
30639 -- There are three possibilities - the expression is
30640 -- unconditionally evaluated, repeatedly evaluated, or
30641 -- conditionally evaluated (see RM 6.1.1). So we implement
30642 -- this test by testing for the other two.
30644 function Is_Repeatedly_Evaluated (Expr : Node_Id) return Boolean;
30645 -- See RM 6.1.1 for definition of "repeatedly evaluated".
30647 -----------------------------
30648 -- Is_Repeatedly_Evaluated --
30649 -----------------------------
30651 function Is_Repeatedly_Evaluated (Expr : Node_Id) return Boolean is
30652 Par : Node_Id := Expr;
30653 Trailer : Node_Id := Empty;
30655 -- There are three ways that an expression can be repeatedly
30656 -- evaluated.
30657 begin
30658 -- An aspect_specification is transformed into a pragma, so
30659 -- reaching a pragma is our termination condition. We want to
30660 -- stop when we reach the postcondition expression.
30662 while Nkind (Par) /= N_Pragma loop
30663 pragma Assert (Present (Par));
30665 -- test for case 1:
30666 -- A subexpression of a predicate of a
30667 -- quantified_expression.
30669 if Nkind (Par) = N_Quantified_Expression
30670 and then Trailer = Condition (Par)
30671 then
30672 return True;
30673 elsif Nkind (Par) = N_Expression_With_Actions
30674 and then
30675 Nkind (Original_Node (Par)) = N_Quantified_Expression
30676 then
30677 return True;
30678 end if;
30680 -- test for cases 2 and 3:
30681 -- A subexpression of the expression of an
30682 -- array_component_association or of
30683 -- a container_element_associatiation.
30685 if Nkind (Par) in N_Component_Association
30686 | N_Iterated_Component_Association
30687 and then Trailer = Expression (Par)
30688 then
30689 -- determine whether Par is part of an array aggregate
30690 -- or a container aggregate
30691 declare
30692 Rover : Node_Id := Par;
30693 begin
30694 while Nkind (Rover) not in N_Has_Etype loop
30695 pragma Assert (Present (Rover));
30696 Rover := Parent (Rover);
30697 end loop;
30698 if Present (Etype (Rover)) then
30699 if Is_Array_Type (Etype (Rover))
30700 or else Is_Container_Aggregate (Rover)
30701 then
30702 return True;
30703 end if;
30704 end if;
30705 end;
30706 end if;
30708 Trailer := Par;
30709 Par := Parent (Par);
30710 end loop;
30712 return False;
30713 end Is_Repeatedly_Evaluated;
30715 begin
30716 if not Is_Potentially_Unevaluated (Expr) then
30717 -- the expression is unconditionally evaluated
30718 return False;
30719 elsif Is_Repeatedly_Evaluated (Expr) then
30720 return False;
30721 end if;
30723 return True;
30724 end Is_Conditionally_Evaluated;
30726 -----------------------
30727 -- Is_Known_On_Entry --
30728 -----------------------
30730 function Is_Known_On_Entry (Expr : Node_Id) return Boolean is
30731 -- ??? This implementation is incomplete. See RM 6.1.1
30732 -- for details. In particular, this function *should* return
30733 -- True for a function call (or a user-defined literal, which
30734 -- is equivalent to a function call) if all actual parameters
30735 -- (including defaulted params) are known on entry and the
30736 -- function has "Globals => null" specified; the current
30737 -- implementation will incorrectly return False in this case.
30739 function All_Exps_Known_On_Entry
30740 (Expr_List : List_Id) return Boolean;
30741 -- Given a list of expressions, returns False iff
30742 -- Is_Known_On_Entry is False for at least one list element.
30744 -----------------------------
30745 -- All_Exps_Known_On_Entry --
30746 -----------------------------
30748 function All_Exps_Known_On_Entry
30749 (Expr_List : List_Id) return Boolean
30751 Expr : Node_Id := First (Expr_List);
30752 begin
30753 while Present (Expr) loop
30754 if not Is_Known_On_Entry (Expr) then
30755 return False;
30756 end if;
30757 Next (Expr);
30758 end loop;
30759 return True;
30760 end All_Exps_Known_On_Entry;
30762 begin
30763 if Is_Static_Expression (Expr) then
30764 return True;
30765 end if;
30767 if Is_Attribute_Old (Expr) then
30768 return True;
30769 end if;
30771 declare
30772 Pref : Node_Id := Expr;
30773 begin
30774 loop
30775 case Nkind (Pref) is
30776 when N_Selected_Component =>
30777 null;
30779 when N_Indexed_Component =>
30780 if not All_Exps_Known_On_Entry (Expressions (Pref))
30781 then
30782 return False;
30783 end if;
30785 when N_Slice =>
30786 return False; -- just to be clear about this case
30788 when others =>
30789 exit;
30790 end case;
30792 Pref := Prefix (Pref);
30793 end loop;
30795 if Is_Entity_Name (Pref)
30796 and then Is_Constant_Object (Entity (Pref))
30797 then
30798 declare
30799 Obj : constant Entity_Id := Entity (Pref);
30800 Obj_Typ : constant Entity_Id := Etype (Obj);
30801 begin
30802 case Ekind (Obj) is
30803 when E_In_Parameter =>
30804 if not Is_Elementary_Type (Obj_Typ) then
30805 return False;
30806 elsif Is_Aliased (Obj) then
30807 return False;
30808 end if;
30810 when E_Constant =>
30811 -- return False for a deferred constant
30812 if Present (Full_View (Obj)) then
30813 return False;
30814 end if;
30816 -- Handle constants introduced by side-effect
30817 -- removal, e.g. by validity checks.
30819 if not Comes_From_Source (Obj) then
30820 return
30821 Is_Known_On_Entry (Expression (Parent (Obj)));
30822 end if;
30824 -- return False if not "all views are constant".
30825 if Is_Immutably_Limited_Type (Obj_Typ)
30826 or Needs_Finalization (Obj_Typ)
30827 then
30828 return False;
30829 end if;
30831 when others =>
30832 null;
30833 end case;
30834 end;
30836 return True;
30837 end if;
30839 -- ??? Cope with a malformed tree. Code to cope with a
30840 -- nonstatic use of an enumeration literal should not be
30841 -- necessary.
30842 if Is_Entity_Name (Pref)
30843 and then Ekind (Entity (Pref)) = E_Enumeration_Literal
30844 then
30845 return True;
30846 end if;
30847 end;
30849 case Nkind (Expr) is
30850 when N_Unary_Op =>
30851 return Is_Known_On_Entry (Right_Opnd (Expr));
30853 when N_Binary_Op =>
30854 return Is_Known_On_Entry (Left_Opnd (Expr))
30855 and then Is_Known_On_Entry (Right_Opnd (Expr));
30857 when N_Type_Conversion | N_Qualified_Expression =>
30858 return Is_Known_On_Entry (Expression (Expr));
30860 when N_If_Expression =>
30861 return All_Exps_Known_On_Entry (Expressions (Expr));
30863 when N_Case_Expression =>
30864 if not Is_Known_On_Entry (Expression (Expr)) then
30865 return False;
30866 end if;
30868 declare
30869 Alt : Node_Id := First (Alternatives (Expr));
30870 begin
30871 while Present (Alt) loop
30872 if not Is_Known_On_Entry (Expression (Alt)) then
30873 return False;
30874 end if;
30875 Next (Alt);
30876 end loop;
30877 end;
30879 return True;
30881 when others =>
30882 return False;
30883 end case;
30884 end Is_Known_On_Entry;
30886 end Conditional_Evaluation;
30888 package body Indirect_Temps is
30890 Indirect_Temp_Access_Type_Char : constant Character := 'K';
30891 -- The character passed to Make_Temporary when declaring
30892 -- the access type that is used in the implementation of an
30893 -- indirect temporary.
30895 --------------------------
30896 -- Indirect_Temp_Needed --
30897 --------------------------
30899 function Indirect_Temp_Needed (Typ : Entity_Id) return Boolean is
30900 begin
30901 -- There should be no correctness issues if the only cases where
30902 -- this function returns False are cases where Typ is an
30903 -- anonymous access type and we need to generate a saooaaat (a
30904 -- stand-alone object of an anonymous access type) in order get
30905 -- accessibility right. In other cases where this function
30906 -- returns False, there would be no correctness problems with
30907 -- returning True instead; however, returning False when we can
30908 -- generally results in simpler code.
30910 return False
30912 -- If Typ is not definite, then we cannot generate
30913 -- Temp : Typ;
30915 or else not Is_Definite_Subtype (Typ)
30917 -- If Typ is tagged, then generating
30918 -- Temp : Typ;
30919 -- might generate an object with the wrong tag. If we had
30920 -- a predicate that indicated whether the nominal tag is
30921 -- trustworthy, we could use that predicate here.
30923 or else Is_Tagged_Type (Typ)
30925 -- If Typ needs finalization, then generating an implicit
30926 -- Temp : Typ;
30927 -- declaration could have user-visible side effects.
30929 or else Needs_Finalization (Typ)
30931 -- In the anonymous access type case, we need to
30932 -- generate a saooaaat. We don't want the code in
30933 -- in exp_attr.adb that deals with the case where this
30934 -- function returns False to have to deal with that case
30935 -- (just to avoid code duplication). So we cheat a little
30936 -- bit and return True here for an anonymous access type.
30938 or else Is_Anonymous_Access_Type (Typ);
30940 -- ??? Unimplemented - spec description says:
30941 -- For an unconstrained-but-definite discriminated subtype,
30942 -- returns True if the potential difference in size between an
30943 -- unconstrained object and a constrained object is large.
30945 -- For example,
30946 -- type Typ (Len : Natural := 0) is
30947 -- record F : String (1 .. Len); end record;
30949 -- See Large_Max_Size_Mutable function elsewhere in this file,
30950 -- currently declared inside of Needs_Secondary_Stack, so it
30951 -- would have to be moved if we want it to be callable from here.
30953 end Indirect_Temp_Needed;
30955 ---------------------------
30956 -- Declare_Indirect_Temp --
30957 ---------------------------
30959 procedure Declare_Indirect_Temp
30960 (Attr_Prefix : Node_Id; Indirect_Temp : out Entity_Id)
30962 Loc : constant Source_Ptr := Sloc (Attr_Prefix);
30963 Prefix_Type : constant Entity_Id := Etype (Attr_Prefix);
30964 Temp_Id : constant Entity_Id :=
30965 Make_Temporary (Loc, 'P', Attr_Prefix);
30967 procedure Declare_Indirect_Temp_Via_Allocation;
30968 -- Handle the usual case.
30970 -------------------------------------------
30971 -- Declare_Indirect_Temp_Via_Allocation --
30972 -------------------------------------------
30974 procedure Declare_Indirect_Temp_Via_Allocation is
30975 Access_Type_Id : constant Entity_Id :=
30976 Make_Temporary
30977 (Loc, Indirect_Temp_Access_Type_Char, Attr_Prefix);
30979 Temp_Decl : constant Node_Id :=
30980 Make_Object_Declaration (Loc,
30981 Defining_Identifier => Temp_Id,
30982 Object_Definition =>
30983 New_Occurrence_Of (Access_Type_Id, Loc));
30985 Allocate_Class_Wide : constant Boolean :=
30986 Is_Specific_Tagged_Type (Prefix_Type);
30987 -- If True then access type designates the class-wide type in
30988 -- order to preserve (at run time) the value of the underlying
30989 -- tag.
30990 -- ??? We could do better here (in the case where Prefix_Type
30991 -- is tagged and specific) if we had a predicate which takes an
30992 -- expression and returns True iff the expression is of
30993 -- a specific tagged type and the underlying tag (at run time)
30994 -- is statically known to match that of the specific type.
30995 -- In that case, Allocate_Class_Wide could safely be False.
30997 function Designated_Subtype_Mark return Node_Id;
30998 -- Usually, a subtype mark indicating the subtype of the
30999 -- attribute prefix. If that subtype is a specific tagged
31000 -- type, then returns the corresponding class-wide type.
31001 -- If the prefix is of an anonymous access type, then returns
31002 -- the designated type of that type.
31004 -----------------------------
31005 -- Designated_Subtype_Mark --
31006 -----------------------------
31008 function Designated_Subtype_Mark return Node_Id is
31009 Typ : Entity_Id := Prefix_Type;
31010 begin
31011 if Allocate_Class_Wide then
31012 if Is_Private_Type (Typ)
31013 and then Present (Full_View (Typ))
31014 then
31015 Typ := Full_View (Typ);
31016 end if;
31017 Typ := Class_Wide_Type (Typ);
31018 end if;
31020 return New_Occurrence_Of (Typ, Loc);
31021 end Designated_Subtype_Mark;
31023 Access_Type_Def : constant Node_Id :=
31024 Make_Access_To_Object_Definition
31025 (Loc, Subtype_Indication => Designated_Subtype_Mark);
31027 Access_Type_Decl : constant Node_Id :=
31028 Make_Full_Type_Declaration
31029 (Loc, Access_Type_Id,
31030 Type_Definition => Access_Type_Def);
31031 begin
31032 Mutate_Ekind (Temp_Id, E_Variable);
31033 Set_Etype (Temp_Id, Access_Type_Id);
31034 Mutate_Ekind (Access_Type_Id, E_Access_Type);
31036 if Append_Decls_In_Reverse_Order then
31037 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31038 Append_Item (Access_Type_Decl, Is_Eval_Stmt => False);
31039 else
31040 Append_Item (Access_Type_Decl, Is_Eval_Stmt => False);
31041 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31042 end if;
31044 -- When a type associated with an indirect temporary gets
31045 -- created for a 'Old attribute reference we need to mark
31046 -- the type as such. This allows, for example, finalization
31047 -- collections associated with them to be finalized in the
31048 -- correct order after postcondition checks.
31050 if Attribute_Name (Parent (Attr_Prefix)) = Name_Old then
31051 Set_Stores_Attribute_Old_Prefix (Access_Type_Id);
31052 end if;
31054 Analyze (Access_Type_Decl);
31055 Analyze (Temp_Decl);
31057 pragma Assert
31058 (Is_Access_Type_For_Indirect_Temp (Access_Type_Id));
31060 declare
31061 Expression : Node_Id := Attr_Prefix;
31062 Allocator : Node_Id;
31063 begin
31064 if Allocate_Class_Wide then
31065 -- generate T'Class'(T'Class (<prefix>))
31066 Expression :=
31067 Make_Type_Conversion (Loc,
31068 Subtype_Mark => Designated_Subtype_Mark,
31069 Expression => Expression);
31070 end if;
31072 Allocator :=
31073 Make_Allocator (Loc,
31074 Make_Qualified_Expression
31075 (Loc,
31076 Subtype_Mark => Designated_Subtype_Mark,
31077 Expression => Expression));
31079 -- Allocate saved prefix value on the secondary stack
31080 -- in order to avoid introducing a storage leak. This
31081 -- allocated object is never explicitly reclaimed.
31083 -- ??? Emit storage leak warning if RE_SS_Pool
31084 -- unavailable?
31086 if RTE_Available (RE_SS_Pool) then
31087 Set_Storage_Pool (Allocator, RTE (RE_SS_Pool));
31088 Set_Procedure_To_Call
31089 (Allocator, RTE (RE_SS_Allocate));
31090 Set_Uses_Sec_Stack (Current_Scope);
31091 end if;
31093 Append_Item
31094 (Make_Assignment_Statement (Loc,
31095 Name => New_Occurrence_Of (Temp_Id, Loc),
31096 Expression => Allocator),
31097 Is_Eval_Stmt => True);
31098 end;
31099 end Declare_Indirect_Temp_Via_Allocation;
31101 begin
31102 Indirect_Temp := Temp_Id;
31104 if Is_Anonymous_Access_Type (Prefix_Type) then
31105 -- In the anonymous access type case, we do not want a level
31106 -- indirection (which would result in declaring an
31107 -- access-to-access type); that would result in correctness
31108 -- problems - the accessibility level of the type of the
31109 -- 'Old constant would be wrong (See 6.1.1.). So in that case,
31110 -- we do not generate an allocator. Instead we generate
31111 -- Temp : access Designated := null;
31112 -- which is unconditionally elaborated and then
31113 -- Temp := <attribute prefix>;
31114 -- which is conditionally executed.
31116 declare
31117 Temp_Decl : constant Node_Id :=
31118 Make_Object_Declaration (Loc,
31119 Defining_Identifier => Temp_Id,
31120 Object_Definition =>
31121 Make_Access_Definition
31122 (Loc,
31123 Constant_Present =>
31124 Is_Access_Constant (Prefix_Type),
31125 Subtype_Mark =>
31126 New_Occurrence_Of
31127 (Designated_Type (Prefix_Type), Loc)));
31128 begin
31129 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31130 Analyze (Temp_Decl);
31131 Append_Item
31132 (Make_Assignment_Statement (Loc,
31133 Name => New_Occurrence_Of (Temp_Id, Loc),
31134 Expression => Attr_Prefix),
31135 Is_Eval_Stmt => True);
31136 end;
31137 else
31138 -- the usual case
31139 Declare_Indirect_Temp_Via_Allocation;
31140 end if;
31141 end Declare_Indirect_Temp;
31143 -------------------------
31144 -- Indirect_Temp_Value --
31145 -------------------------
31147 function Indirect_Temp_Value
31148 (Temp : Entity_Id;
31149 Typ : Entity_Id;
31150 Loc : Source_Ptr) return Node_Id
31152 Result : Node_Id;
31153 begin
31154 if Is_Anonymous_Access_Type (Typ) then
31155 -- No indirection in this case; just evaluate the temp.
31156 return New_Occurrence_Of (Temp, Loc);
31158 else
31159 Result := Make_Explicit_Dereference (Loc,
31160 New_Occurrence_Of (Temp, Loc));
31162 Set_Etype (Result, Designated_Type (Etype (Temp)));
31164 if Is_Specific_Tagged_Type (Typ) then
31165 -- The designated type of the access type is class-wide, so
31166 -- convert to the specific type.
31168 Result :=
31169 Make_Type_Conversion (Loc,
31170 Subtype_Mark => New_Occurrence_Of (Typ, Loc),
31171 Expression => Result);
31173 Set_Etype (Result, Typ);
31174 end if;
31176 return Result;
31177 end if;
31178 end Indirect_Temp_Value;
31180 --------------------------------------
31181 -- Is_Access_Type_For_Indirect_Temp --
31182 --------------------------------------
31184 function Is_Access_Type_For_Indirect_Temp
31185 (T : Entity_Id) return Boolean is
31186 begin
31187 if Is_Access_Type (T)
31188 and then not Comes_From_Source (T)
31189 and then Is_Internal_Name (Chars (T))
31190 and then Nkind (Scope (T)) in N_Entity
31191 and then Ekind (Scope (T))
31192 in E_Entry | E_Entry_Family | E_Function | E_Procedure
31193 and then
31194 (Present (Wrapped_Statements (Scope (T)))
31195 or else Present (Contract (Scope (T))))
31196 then
31197 -- ??? Should define a flag for this. We could incorrectly
31198 -- return True if other clients of Make_Temporary happen to
31199 -- pass in the same character.
31200 declare
31201 Name : constant String := Get_Name_String (Chars (T));
31202 begin
31203 if Name (Name'First) = Indirect_Temp_Access_Type_Char then
31204 return True;
31205 end if;
31206 end;
31207 end if;
31209 return False;
31210 end Is_Access_Type_For_Indirect_Temp;
31212 end Indirect_Temps;
31213 end Old_Attr_Util;
31215 package body Storage_Model_Support is
31217 -----------------------------------------
31218 -- Has_Designated_Storage_Model_Aspect --
31219 -----------------------------------------
31221 function Has_Designated_Storage_Model_Aspect
31222 (Typ : Entity_Id) return Boolean
31224 begin
31225 return Has_Aspect (Typ, Aspect_Designated_Storage_Model);
31226 end Has_Designated_Storage_Model_Aspect;
31228 -----------------------------------
31229 -- Has_Storage_Model_Type_Aspect --
31230 -----------------------------------
31232 function Has_Storage_Model_Type_Aspect (Typ : Entity_Id) return Boolean
31234 begin
31235 return Has_Aspect (Typ, Aspect_Storage_Model_Type);
31236 end Has_Storage_Model_Type_Aspect;
31238 --------------------------
31239 -- Storage_Model_Object --
31240 --------------------------
31242 function Storage_Model_Object (Typ : Entity_Id) return Entity_Id is
31243 begin
31244 pragma Assert (Has_Designated_Storage_Model_Aspect (Typ));
31246 return
31247 Entity
31248 (Find_Value_Of_Aspect (Typ, Aspect_Designated_Storage_Model));
31249 end Storage_Model_Object;
31251 ------------------------
31252 -- Storage_Model_Type --
31253 ------------------------
31255 function Storage_Model_Type (Obj : Entity_Id) return Entity_Id is
31256 begin
31257 pragma Assert (Has_Storage_Model_Type_Aspect (Etype (Obj)));
31259 return Etype (Obj);
31260 end Storage_Model_Type;
31262 -----------------------------------
31263 -- Get_Storage_Model_Type_Entity --
31264 -----------------------------------
31266 function Get_Storage_Model_Type_Entity
31267 (SM_Obj_Or_Type : Entity_Id;
31268 Nam : Name_Id) return Entity_Id
31270 Typ : constant Entity_Id := (if Is_Object (SM_Obj_Or_Type) then
31271 Storage_Model_Type (SM_Obj_Or_Type)
31272 else
31273 SM_Obj_Or_Type);
31274 pragma Assert
31275 (Is_Type (Typ)
31276 and then
31277 Nam in Name_Address_Type
31278 | Name_Null_Address
31279 | Name_Allocate
31280 | Name_Deallocate
31281 | Name_Copy_From
31282 | Name_Copy_To
31283 | Name_Storage_Size);
31285 Assoc : Node_Id;
31286 SMT_Aspect_Value : constant Node_Id :=
31287 Find_Value_Of_Aspect (Typ, Aspect_Storage_Model_Type);
31289 begin
31290 -- When the aspect has an aggregate expression, search through it
31291 -- to locate a match for the name of the given "subaspect" and return
31292 -- the entity of the aggregate association's expression.
31294 if Present (SMT_Aspect_Value) then
31295 Assoc := First (Component_Associations (SMT_Aspect_Value));
31296 while Present (Assoc) loop
31297 if Chars (First (Choices (Assoc))) = Nam then
31298 return Entity (Expression (Assoc));
31299 end if;
31301 Next (Assoc);
31302 end loop;
31303 end if;
31305 -- The aggregate argument of Storage_Model_Type is optional, and when
31306 -- not present the aspect defaults to the native storage model, where
31307 -- the address type is System.Address. In that case, we return
31308 -- System.Address for Name_Address_Type and System.Null_Address for
31309 -- Name_Null_Address, but return Empty for other cases, and leave it
31310 -- to the back end to map those to the appropriate native operations.
31312 if Nam = Name_Address_Type then
31313 return RTE (RE_Address);
31315 elsif Nam = Name_Null_Address then
31316 return RTE (RE_Null_Address);
31318 else
31319 return Empty;
31320 end if;
31321 end Get_Storage_Model_Type_Entity;
31323 --------------------------------
31324 -- Storage_Model_Address_Type --
31325 --------------------------------
31327 function Storage_Model_Address_Type
31328 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31330 begin
31331 return
31332 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Address_Type);
31333 end Storage_Model_Address_Type;
31335 --------------------------------
31336 -- Storage_Model_Null_Address --
31337 --------------------------------
31339 function Storage_Model_Null_Address
31340 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31342 begin
31343 return
31344 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Null_Address);
31345 end Storage_Model_Null_Address;
31347 ----------------------------
31348 -- Storage_Model_Allocate --
31349 ----------------------------
31351 function Storage_Model_Allocate
31352 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31354 begin
31355 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Allocate);
31356 end Storage_Model_Allocate;
31358 ------------------------------
31359 -- Storage_Model_Deallocate --
31360 ------------------------------
31362 function Storage_Model_Deallocate
31363 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31365 begin
31366 return
31367 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Deallocate);
31368 end Storage_Model_Deallocate;
31370 -----------------------------
31371 -- Storage_Model_Copy_From --
31372 -----------------------------
31374 function Storage_Model_Copy_From
31375 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31377 begin
31378 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Copy_From);
31379 end Storage_Model_Copy_From;
31381 ---------------------------
31382 -- Storage_Model_Copy_To --
31383 ---------------------------
31385 function Storage_Model_Copy_To
31386 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31388 begin
31389 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Copy_To);
31390 end Storage_Model_Copy_To;
31392 --------------------------------
31393 -- Storage_Model_Storage_Size --
31394 --------------------------------
31396 function Storage_Model_Storage_Size
31397 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31399 begin
31400 return
31401 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Storage_Size);
31402 end Storage_Model_Storage_Size;
31404 end Storage_Model_Support;
31406 end Sem_Util;