ada: Rename Is_Constr_Subt_For_UN_Aliased flag
[official-gcc.git] / gcc / ada / sem_util.adb
blobf8922fed322f03f7453561dee402200f8ad32777
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-2023, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Accessibility; use Accessibility;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo.Utils; use Einfo.Utils;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Erroutc; use Erroutc;
34 with Exp_Ch6; use Exp_Ch6;
35 with Exp_Ch11; use Exp_Ch11;
36 with Exp_Util; use Exp_Util;
37 with Fname; use Fname;
38 with Freeze; use Freeze;
39 with Itypes; use Itypes;
40 with Lib; use Lib;
41 with Lib.Xref; use Lib.Xref;
42 with Namet.Sp; use Namet.Sp;
43 with Nlists; use Nlists;
44 with Nmake; use Nmake;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
49 with Sem; use Sem;
50 with Sem_Aux; use Sem_Aux;
51 with Sem_Attr; use Sem_Attr;
52 with Sem_Cat; use Sem_Cat;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Ch13; use Sem_Ch13;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Elab; use Sem_Elab;
58 with Sem_Eval; use Sem_Eval;
59 with Sem_Prag; use Sem_Prag;
60 with Sem_Res; use Sem_Res;
61 with Sem_Warn; use Sem_Warn;
62 with Sem_Type; use Sem_Type;
63 with Sinfo; use Sinfo;
64 with Sinfo.Nodes; use Sinfo.Nodes;
65 with Sinfo.Utils; use Sinfo.Utils;
66 with Sinput; use Sinput;
67 with Stand; use Stand;
68 with Style;
69 with Stringt; use Stringt;
70 with Targparm; use Targparm;
71 with Tbuild; use Tbuild;
72 with Ttypes; use Ttypes;
73 with Uname; use Uname;
74 with Warnsw; use Warnsw;
76 with GNAT.Heap_Sort_G;
77 with GNAT.HTable; use GNAT.HTable;
79 package body Sem_Util is
81 ---------------------------
82 -- Local Data Structures --
83 ---------------------------
85 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
86 -- A collection to hold the entities of the variables declared in package
87 -- System.Scalar_Values which describe the invalid values of scalar types.
89 Invalid_Binder_Values_Set : Boolean := False;
90 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
92 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
93 -- A collection to hold the invalid values of float types as specified by
94 -- pragma Initialize_Scalars.
96 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
97 -- A collection to hold the invalid values of integer types as specified
98 -- by pragma Initialize_Scalars.
100 -----------------------
101 -- Local Subprograms --
102 -----------------------
104 function Build_Component_Subtype
105 (C : List_Id;
106 Loc : Source_Ptr;
107 T : Entity_Id) return Node_Id;
108 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
109 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
110 -- Loc is the source location, T is the original subtype.
112 procedure Examine_Array_Bounds
113 (Typ : Entity_Id;
114 All_Static : out Boolean;
115 Has_Empty : out Boolean);
116 -- Inspect the index constraints of array type Typ. Flag All_Static is set
117 -- when all ranges are static. Flag Has_Empty is set only when All_Static
118 -- is set and indicates that at least one range is empty.
120 function Has_Enabled_Property
121 (Item_Id : Entity_Id;
122 Property : Name_Id) return Boolean;
123 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
124 -- Determine whether the state abstraction, object, or type denoted by
125 -- entity Item_Id has enabled property Property.
127 function Has_Null_Extension (T : Entity_Id) return Boolean;
128 -- T is a derived tagged type. Check whether the type extension is null.
129 -- If the parent type is fully initialized, T can be treated as such.
131 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean;
132 -- Determine whether arbitrary entity Id denotes an atomic object as per
133 -- RM C.6(7).
135 generic
136 with function Is_Effectively_Volatile_Entity
137 (Id : Entity_Id) return Boolean;
138 -- Function to use on object and type entities
139 function Is_Effectively_Volatile_Object_Shared
140 (N : Node_Id) return Boolean;
141 -- Shared function used to detect effectively volatile objects and
142 -- effectively volatile objects for reading.
144 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
145 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
146 -- with discriminants whose default values are static, examine only the
147 -- components in the selected variant to determine whether all of them
148 -- have a default.
150 function Is_Preelaborable_Function (Id : Entity_Id) return Boolean;
151 -- Ada 2022: Determine whether the specified function is suitable as the
152 -- name of a call in a preelaborable construct (RM 10.2.1(7/5)).
154 type Null_Status_Kind is
155 (Is_Null,
156 -- This value indicates that a subexpression is known to have a null
157 -- value at compile time.
159 Is_Non_Null,
160 -- This value indicates that a subexpression is known to have a non-null
161 -- value at compile time.
163 Unknown);
164 -- This value indicates that it cannot be determined at compile time
165 -- whether a subexpression yields a null or non-null value.
167 function Null_Status (N : Node_Id) return Null_Status_Kind;
168 -- Determine whether subexpression N of an access type yields a null value,
169 -- a non-null value, or the value cannot be determined at compile time. The
170 -- routine does not take simple flow diagnostics into account, it relies on
171 -- static facts such as the presence of null exclusions.
173 function Subprogram_Name (N : Node_Id) return String;
174 -- Return the fully qualified name of the enclosing subprogram for the
175 -- given node N, with file:line:col information appended, e.g.
176 -- "subp:file:line:col", corresponding to the source location of the
177 -- body of the subprogram.
179 -----------------------------
180 -- Abstract_Interface_List --
181 -----------------------------
183 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
184 Nod : Node_Id;
186 begin
187 if Is_Concurrent_Type (Typ) then
189 -- If we are dealing with a synchronized subtype, go to the base
190 -- type, whose declaration has the interface list.
192 Nod := Declaration_Node (Base_Type (Typ));
194 if Nkind (Nod) in N_Full_Type_Declaration | N_Private_Type_Declaration
195 then
196 return Empty_List;
197 end if;
199 elsif Ekind (Typ) = E_Record_Type_With_Private then
200 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
201 Nod := Type_Definition (Parent (Typ));
203 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
204 if Present (Full_View (Typ))
205 and then
206 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
207 then
208 Nod := Type_Definition (Parent (Full_View (Typ)));
210 -- If the full-view is not available we cannot do anything else
211 -- here (the source has errors).
213 else
214 return Empty_List;
215 end if;
217 -- Support for generic formals with interfaces is still missing ???
219 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
220 return Empty_List;
222 else
223 pragma Assert
224 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
225 Nod := Parent (Typ);
226 end if;
228 elsif Ekind (Typ) = E_Record_Subtype then
229 Nod := Type_Definition (Parent (Etype (Typ)));
231 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
233 -- Recurse, because parent may still be a private extension. Also
234 -- note that the full view of the subtype or the full view of its
235 -- base type may (both) be unavailable.
237 return Abstract_Interface_List (Etype (Typ));
239 elsif Ekind (Typ) = E_Record_Type then
240 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
241 Nod := Formal_Type_Definition (Parent (Typ));
242 else
243 Nod := Type_Definition (Parent (Typ));
244 end if;
246 -- Otherwise the type is of a kind which does not implement interfaces
248 else
249 return Empty_List;
250 end if;
252 return Interface_List (Nod);
253 end Abstract_Interface_List;
255 ----------------------------------
256 -- Acquire_Warning_Match_String --
257 ----------------------------------
259 function Acquire_Warning_Match_String (Str_Lit : Node_Id) return String is
260 S : constant String := To_String (Strval (Str_Lit));
261 begin
262 if S = "" then
263 return "";
264 else
265 -- Put "*" before or after or both, if it's not already there
267 declare
268 F : constant Boolean := S (S'First) = '*';
269 L : constant Boolean := S (S'Last) = '*';
270 begin
271 if F then
272 if L then
273 return S;
274 else
275 return S & "*";
276 end if;
277 else
278 if L then
279 return "*" & S;
280 else
281 return "*" & S & "*";
282 end if;
283 end if;
284 end;
285 end if;
286 end Acquire_Warning_Match_String;
288 --------------------------------
289 -- Add_Access_Type_To_Process --
290 --------------------------------
292 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
293 L : Elist_Id;
295 begin
296 Ensure_Freeze_Node (E);
297 L := Access_Types_To_Process (Freeze_Node (E));
299 if No (L) then
300 L := New_Elmt_List;
301 Set_Access_Types_To_Process (Freeze_Node (E), L);
302 end if;
304 Append_Elmt (A, L);
305 end Add_Access_Type_To_Process;
307 --------------------------
308 -- Add_Block_Identifier --
309 --------------------------
311 procedure Add_Block_Identifier
312 (N : Node_Id;
313 Id : out Entity_Id;
314 Scope : Entity_Id := Current_Scope)
316 Loc : constant Source_Ptr := Sloc (N);
318 begin
319 pragma Assert (Nkind (N) = N_Block_Statement);
321 -- The block already has a label, return its entity
323 if Present (Identifier (N)) then
324 Id := Entity (Identifier (N));
326 -- Create a new block label and set its attributes
328 else
329 Id := New_Internal_Entity (E_Block, Scope, Loc, 'B');
330 Set_Etype (Id, Standard_Void_Type);
331 Set_Parent (Id, N);
332 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
333 Set_Block_Node (Id, Identifier (N));
334 end if;
335 end Add_Block_Identifier;
337 ----------------------------
338 -- Add_Global_Declaration --
339 ----------------------------
341 procedure Add_Global_Declaration (N : Node_Id) is
342 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
344 begin
345 if No (Declarations (Aux_Node)) then
346 Set_Declarations (Aux_Node, New_List);
347 end if;
349 Append_To (Declarations (Aux_Node), N);
350 Analyze (N);
351 end Add_Global_Declaration;
353 --------------------------------
354 -- Address_Integer_Convert_OK --
355 --------------------------------
357 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
358 begin
359 if Allow_Integer_Address
360 and then ((Is_Descendant_Of_Address (T1)
361 and then Is_Private_Type (T1)
362 and then Is_Integer_Type (T2))
363 or else
364 (Is_Descendant_Of_Address (T2)
365 and then Is_Private_Type (T2)
366 and then Is_Integer_Type (T1)))
367 then
368 return True;
369 else
370 return False;
371 end if;
372 end Address_Integer_Convert_OK;
374 -------------------
375 -- Address_Value --
376 -------------------
378 function Address_Value (N : Node_Id) return Node_Id is
379 Expr : Node_Id := N;
381 begin
382 loop
383 -- For constant, get constant expression
385 if Is_Entity_Name (Expr)
386 and then Ekind (Entity (Expr)) = E_Constant
387 then
388 Expr := Constant_Value (Entity (Expr));
390 -- For unchecked conversion, get result to convert
392 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
393 Expr := Expression (Expr);
395 -- For (common case) of To_Address call, get argument
397 elsif Nkind (Expr) = N_Function_Call
398 and then Is_Entity_Name (Name (Expr))
399 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
400 then
401 Expr := First_Actual (Expr);
403 -- We finally have the real expression
405 else
406 exit;
407 end if;
408 end loop;
410 return Expr;
411 end Address_Value;
413 -----------------
414 -- Addressable --
415 -----------------
417 function Addressable (V : Uint) return Boolean is
418 begin
419 if No (V) then
420 return False;
421 end if;
423 return V = Uint_8 or else
424 V = Uint_16 or else
425 V = Uint_32 or else
426 V = Uint_64 or else
427 (V = Uint_128 and then System_Max_Integer_Size = 128);
428 end Addressable;
430 function Addressable (V : Int) return Boolean is
431 begin
432 return V = 8 or else
433 V = 16 or else
434 V = 32 or else
435 V = 64 or else
436 V = System_Max_Integer_Size;
437 end Addressable;
439 ---------------------------------
440 -- Aggregate_Constraint_Checks --
441 ---------------------------------
443 procedure Aggregate_Constraint_Checks
444 (Exp : Node_Id;
445 Check_Typ : Entity_Id)
447 Exp_Typ : constant Entity_Id := Etype (Exp);
449 begin
450 if Raises_Constraint_Error (Exp) then
451 return;
452 end if;
454 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
455 -- component's type to force the appropriate accessibility checks.
457 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
458 -- force the corresponding run-time check
460 if Is_Access_Type (Check_Typ)
461 and then Is_Local_Anonymous_Access (Check_Typ)
462 then
463 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
464 Analyze_And_Resolve (Exp, Check_Typ);
465 Check_Unset_Reference (Exp);
466 end if;
468 -- What follows is really expansion activity, so check that expansion
469 -- is on and is allowed. In GNATprove mode, we also want check flags to
470 -- be added in the tree, so that the formal verification can rely on
471 -- those to be present. In GNATprove mode for formal verification, some
472 -- treatment typically only done during expansion needs to be performed
473 -- on the tree, but it should not be applied inside generics. Otherwise,
474 -- this breaks the name resolution mechanism for generic instances.
476 if not Expander_Active
477 and not (GNATprove_Mode and not Inside_A_Generic)
478 then
479 return;
480 end if;
482 if Is_Access_Type (Check_Typ)
483 and then Can_Never_Be_Null (Check_Typ)
484 and then not Can_Never_Be_Null (Exp_Typ)
485 then
486 Install_Null_Excluding_Check (Exp);
487 end if;
489 -- First check if we have to insert discriminant checks
491 if Has_Discriminants (Exp_Typ) then
492 Apply_Discriminant_Check (Exp, Check_Typ);
494 -- Next emit length checks for array aggregates
496 elsif Is_Array_Type (Exp_Typ) then
497 Apply_Length_Check (Exp, Check_Typ);
499 -- Finally emit scalar and string checks. If we are dealing with a
500 -- scalar literal we need to check by hand because the Etype of
501 -- literals is not necessarily correct.
503 elsif Is_Scalar_Type (Exp_Typ)
504 and then Compile_Time_Known_Value (Exp)
505 then
506 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
507 Apply_Compile_Time_Constraint_Error
508 (Exp, "value not in range of}??", CE_Range_Check_Failed,
509 Ent => Base_Type (Check_Typ),
510 Typ => Base_Type (Check_Typ));
512 elsif Is_Out_Of_Range (Exp, Check_Typ) then
513 Apply_Compile_Time_Constraint_Error
514 (Exp, "value not in range of}??", CE_Range_Check_Failed,
515 Ent => Check_Typ,
516 Typ => Check_Typ);
518 elsif not Range_Checks_Suppressed (Check_Typ) then
519 Apply_Scalar_Range_Check (Exp, Check_Typ);
520 end if;
522 -- Verify that target type is also scalar, to prevent view anomalies
523 -- in instantiations.
525 elsif (Is_Scalar_Type (Exp_Typ)
526 or else Nkind (Exp) = N_String_Literal)
527 and then Is_Scalar_Type (Check_Typ)
528 and then Exp_Typ /= Check_Typ
529 then
530 -- If expression is a constant, it is worthwhile checking whether it
531 -- is a bound of the type.
533 if Is_Entity_Name (Exp)
534 and then Ekind (Entity (Exp)) = E_Constant
535 then
536 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
537 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
538 or else
539 (Is_Entity_Name (Type_High_Bound (Check_Typ))
540 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
541 then
542 return;
543 end if;
544 end if;
546 -- Change Exp into Check_Typ'(Exp) to ensure that range checks are
547 -- performed at run time.
549 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
550 Analyze_And_Resolve (Exp, Check_Typ);
551 Check_Unset_Reference (Exp);
553 end if;
554 end Aggregate_Constraint_Checks;
556 -----------------------
557 -- Alignment_In_Bits --
558 -----------------------
560 function Alignment_In_Bits (E : Entity_Id) return Uint is
561 begin
562 return Alignment (E) * System_Storage_Unit;
563 end Alignment_In_Bits;
565 --------------------------------------
566 -- All_Composite_Constraints_Static --
567 --------------------------------------
569 function All_Composite_Constraints_Static
570 (Constr : Node_Id) return Boolean
572 begin
573 if No (Constr) or else Error_Posted (Constr) then
574 return True;
575 end if;
577 case Nkind (Constr) is
578 when N_Subexpr =>
579 if Nkind (Constr) in N_Has_Entity
580 and then Present (Entity (Constr))
581 then
582 if Is_Type (Entity (Constr)) then
583 return
584 not Is_Discrete_Type (Entity (Constr))
585 or else Is_OK_Static_Subtype (Entity (Constr));
586 end if;
588 elsif Nkind (Constr) = N_Range then
589 return
590 Is_OK_Static_Expression (Low_Bound (Constr))
591 and then
592 Is_OK_Static_Expression (High_Bound (Constr));
594 elsif Nkind (Constr) = N_Attribute_Reference
595 and then Attribute_Name (Constr) = Name_Range
596 then
597 return
598 Is_OK_Static_Expression
599 (Type_Low_Bound (Etype (Prefix (Constr))))
600 and then
601 Is_OK_Static_Expression
602 (Type_High_Bound (Etype (Prefix (Constr))));
603 end if;
605 return
606 No (Etype (Constr)) -- previous error
607 or else not Is_Discrete_Type (Etype (Constr))
608 or else Is_OK_Static_Expression (Constr);
610 when N_Discriminant_Association =>
611 return All_Composite_Constraints_Static (Expression (Constr));
613 when N_Range_Constraint =>
614 return
615 All_Composite_Constraints_Static (Range_Expression (Constr));
617 when N_Index_Or_Discriminant_Constraint =>
618 declare
619 One_Cstr : Entity_Id;
620 begin
621 One_Cstr := First (Constraints (Constr));
622 while Present (One_Cstr) loop
623 if not All_Composite_Constraints_Static (One_Cstr) then
624 return False;
625 end if;
627 Next (One_Cstr);
628 end loop;
629 end;
631 return True;
633 when N_Subtype_Indication =>
634 return
635 All_Composite_Constraints_Static (Subtype_Mark (Constr))
636 and then
637 All_Composite_Constraints_Static (Constraint (Constr));
639 when others =>
640 raise Program_Error;
641 end case;
642 end All_Composite_Constraints_Static;
644 ------------------------
645 -- Append_Entity_Name --
646 ------------------------
648 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
649 Temp : Bounded_String;
651 procedure Inner (E : Entity_Id);
652 -- Inner recursive routine, keep outer routine nonrecursive to ease
653 -- debugging when we get strange results from this routine.
655 -----------
656 -- Inner --
657 -----------
659 procedure Inner (E : Entity_Id) is
660 Scop : Node_Id;
662 begin
663 -- If entity has an internal name, skip by it, and print its scope.
664 -- Note that we strip a final R from the name before the test; this
665 -- is needed for some cases of instantiations.
667 declare
668 E_Name : Bounded_String;
670 begin
671 Append (E_Name, Chars (E));
673 if E_Name.Chars (E_Name.Length) = 'R' then
674 E_Name.Length := E_Name.Length - 1;
675 end if;
677 if Is_Internal_Name (E_Name) then
678 Inner (Scope (E));
679 return;
680 end if;
681 end;
683 Scop := Scope (E);
685 -- Just print entity name if its scope is at the outer level
687 if Scop = Standard_Standard then
688 null;
690 -- If scope comes from source, write scope and entity
692 elsif Comes_From_Source (Scop) then
693 Append_Entity_Name (Temp, Scop);
694 Append (Temp, '.');
696 -- If in wrapper package skip past it
698 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
699 Append_Entity_Name (Temp, Scope (Scop));
700 Append (Temp, '.');
702 -- Otherwise nothing to output (happens in unnamed block statements)
704 else
705 null;
706 end if;
708 -- Output the name
710 declare
711 E_Name : Bounded_String;
713 begin
714 Append_Unqualified_Decoded (E_Name, Chars (E));
716 -- Remove trailing upper-case letters from the name (useful for
717 -- dealing with some cases of internal names generated in the case
718 -- of references from within a generic).
720 while E_Name.Length > 1
721 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
722 loop
723 E_Name.Length := E_Name.Length - 1;
724 end loop;
726 -- Adjust casing appropriately (gets name from source if possible)
728 Adjust_Name_Case (E_Name, Sloc (E));
729 Append (Temp, E_Name);
730 end;
731 end Inner;
733 -- Start of processing for Append_Entity_Name
735 begin
736 Inner (E);
737 Append (Buf, Temp);
738 end Append_Entity_Name;
740 ---------------------------------
741 -- Append_Inherited_Subprogram --
742 ---------------------------------
744 procedure Append_Inherited_Subprogram (S : Entity_Id) is
745 Par : constant Entity_Id := Alias (S);
746 -- The parent subprogram
748 Scop : constant Entity_Id := Scope (Par);
749 -- The scope of definition of the parent subprogram
751 Typ : constant Entity_Id := Defining_Entity (Parent (S));
752 -- The derived type of which S is a primitive operation
754 Decl : Node_Id;
755 Next_E : Entity_Id;
757 begin
758 if Ekind (Current_Scope) = E_Package
759 and then In_Private_Part (Current_Scope)
760 and then Has_Private_Declaration (Typ)
761 and then Is_Tagged_Type (Typ)
762 and then Scop = Current_Scope
763 then
764 -- The inherited operation is available at the earliest place after
765 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
766 -- relevant for type extensions. If the parent operation appears
767 -- after the type extension, the operation is not visible.
769 Decl := First
770 (Visible_Declarations
771 (Package_Specification (Current_Scope)));
772 while Present (Decl) loop
773 if Nkind (Decl) = N_Private_Extension_Declaration
774 and then Defining_Entity (Decl) = Typ
775 then
776 if Sloc (Decl) > Sloc (Par) then
777 Next_E := Next_Entity (Par);
778 Link_Entities (Par, S);
779 Link_Entities (S, Next_E);
780 return;
782 else
783 exit;
784 end if;
785 end if;
787 Next (Decl);
788 end loop;
789 end if;
791 -- If partial view is not a type extension, or it appears before the
792 -- subprogram declaration, insert normally at end of entity list.
794 Append_Entity (S, Current_Scope);
795 end Append_Inherited_Subprogram;
797 -----------------------------------------
798 -- Apply_Compile_Time_Constraint_Error --
799 -----------------------------------------
801 procedure Apply_Compile_Time_Constraint_Error
802 (N : Node_Id;
803 Msg : String;
804 Reason : RT_Exception_Code;
805 Ent : Entity_Id := Empty;
806 Typ : Entity_Id := Empty;
807 Loc : Source_Ptr := No_Location;
808 Warn : Boolean := False;
809 Emit_Message : Boolean := True)
811 Stat : constant Boolean := Is_Static_Expression (N);
812 R_Stat : constant Node_Id :=
813 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
814 Rtyp : Entity_Id;
816 begin
817 if No (Typ) then
818 Rtyp := Etype (N);
819 else
820 Rtyp := Typ;
821 end if;
823 if Emit_Message then
824 Discard_Node
825 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
826 end if;
828 -- Now we replace the node by an N_Raise_Constraint_Error node
829 -- This does not need reanalyzing, so set it as analyzed now.
831 Rewrite (N, R_Stat);
832 Set_Analyzed (N, True);
834 Set_Etype (N, Rtyp);
835 Set_Raises_Constraint_Error (N);
837 -- Now deal with possible local raise handling
839 Possible_Local_Raise (N, Standard_Constraint_Error);
841 -- If the original expression was marked as static, the result is
842 -- still marked as static, but the Raises_Constraint_Error flag is
843 -- always set so that further static evaluation is not attempted.
845 if Stat then
846 Set_Is_Static_Expression (N);
847 end if;
848 end Apply_Compile_Time_Constraint_Error;
850 ---------------------------
851 -- Async_Readers_Enabled --
852 ---------------------------
854 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
855 begin
856 return Has_Enabled_Property (Id, Name_Async_Readers);
857 end Async_Readers_Enabled;
859 ---------------------------
860 -- Async_Writers_Enabled --
861 ---------------------------
863 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
864 begin
865 return Has_Enabled_Property (Id, Name_Async_Writers);
866 end Async_Writers_Enabled;
868 --------------------------------------
869 -- Available_Full_View_Of_Component --
870 --------------------------------------
872 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
873 ST : constant Entity_Id := Scope (T);
874 SCT : constant Entity_Id := Scope (Component_Type (T));
875 begin
876 return In_Open_Scopes (ST)
877 and then In_Open_Scopes (SCT)
878 and then Scope_Depth (ST) >= Scope_Depth (SCT);
879 end Available_Full_View_Of_Component;
881 ----------------
882 -- Bad_Aspect --
883 ----------------
885 procedure Bad_Aspect
886 (N : Node_Id;
887 Nam : Name_Id;
888 Warn : Boolean := False)
890 begin
891 Error_Msg_Warn := Warn;
892 Error_Msg_N ("<<& is not a valid aspect identifier", N);
894 -- Check bad spelling
895 Error_Msg_Name_1 := Aspect_Spell_Check (Nam);
896 if Error_Msg_Name_1 /= No_Name then
897 Error_Msg_N -- CODEFIX
898 ("\<<possible misspelling of %", N);
899 end if;
900 end Bad_Aspect;
902 -------------------
903 -- Bad_Attribute --
904 -------------------
906 procedure Bad_Attribute
907 (N : Node_Id;
908 Nam : Name_Id;
909 Warn : Boolean := False)
911 begin
912 Error_Msg_Warn := Warn;
913 Error_Msg_N ("<<unrecognized attribute&", N);
915 -- Check for possible misspelling
917 Error_Msg_Name_1 := Attribute_Spell_Check (Nam);
918 if Error_Msg_Name_1 /= No_Name then
919 Error_Msg_N -- CODEFIX
920 ("\<<possible misspelling of %", N);
921 end if;
922 end Bad_Attribute;
924 --------------------------------
925 -- Bad_Predicated_Subtype_Use --
926 --------------------------------
928 procedure Bad_Predicated_Subtype_Use
929 (Msg : String;
930 N : Node_Id;
931 Typ : Entity_Id;
932 Suggest_Static : Boolean := False)
934 Gen : Entity_Id;
936 begin
937 -- Avoid cascaded errors
939 if Error_Posted (N) then
940 return;
941 end if;
943 if Inside_A_Generic then
944 Gen := Current_Scope;
945 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
946 Gen := Scope (Gen);
947 end loop;
949 if No (Gen) then
950 return;
951 end if;
953 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
954 Set_No_Predicate_On_Actual (Typ);
955 end if;
957 elsif Has_Predicates (Typ) then
958 if Is_Generic_Actual_Type (Typ) then
960 -- The restriction on loop parameters is only that the type
961 -- should only have static predicates.
963 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
964 and then not Has_Dynamic_Predicate_Aspect (Typ)
965 and then not Has_Ghost_Predicate_Aspect (Typ)
966 and then Is_OK_Static_Subtype (Typ)
967 then
968 return;
969 end if;
971 Gen := Current_Scope;
972 while not Is_Generic_Instance (Gen) loop
973 Gen := Scope (Gen);
974 end loop;
976 pragma Assert (Present (Gen));
978 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
979 Error_Msg_Warn := SPARK_Mode /= On;
980 Error_Msg_FE (Msg & "<<", N, Typ);
981 Error_Msg_F ("\Program_Error [<<", N);
983 Insert_Action (N,
984 Make_Raise_Program_Error (Sloc (N),
985 Reason => PE_Bad_Predicated_Generic_Type));
987 else
988 Error_Msg_FE (Msg, N, Typ);
989 end if;
991 else
992 Error_Msg_FE (Msg, N, Typ);
993 end if;
995 -- Suggest to use First_Valid/Last_Valid instead of First/Last/Range
996 -- if the predicate is static.
998 if not Has_Dynamic_Predicate_Aspect (Typ)
999 and then not Has_Ghost_Predicate_Aspect (Typ)
1000 and then Has_Static_Predicate (Typ)
1001 and then Nkind (N) = N_Attribute_Reference
1002 then
1003 declare
1004 Aname : constant Name_Id := Attribute_Name (N);
1005 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
1006 begin
1007 case Attr_Id is
1008 when Attribute_First =>
1009 Error_Msg_F ("\use attribute First_Valid instead", N);
1010 when Attribute_Last =>
1011 Error_Msg_F ("\use attribute Last_Valid instead", N);
1012 when Attribute_Range =>
1013 Error_Msg_F ("\use attributes First_Valid and "
1014 & "Last_Valid instead", N);
1015 when others =>
1016 null;
1017 end case;
1018 end;
1019 end if;
1021 -- Emit an optional suggestion on how to remedy the error if the
1022 -- context warrants it.
1024 if Suggest_Static and then Has_Static_Predicate (Typ) then
1025 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
1026 end if;
1027 end if;
1028 end Bad_Predicated_Subtype_Use;
1030 -----------------------------------------
1031 -- Bad_Unordered_Enumeration_Reference --
1032 -----------------------------------------
1034 function Bad_Unordered_Enumeration_Reference
1035 (N : Node_Id;
1036 T : Entity_Id) return Boolean
1038 begin
1039 return Is_Enumeration_Type (T)
1040 and then Warn_On_Unordered_Enumeration_Type
1041 and then not Is_Generic_Type (T)
1042 and then Comes_From_Source (N)
1043 and then not Has_Pragma_Ordered (T)
1044 and then not In_Same_Extended_Unit (N, T);
1045 end Bad_Unordered_Enumeration_Reference;
1047 ----------------------------
1048 -- Begin_Keyword_Location --
1049 ----------------------------
1051 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
1052 HSS : Node_Id;
1054 begin
1055 pragma Assert
1056 (Nkind (N) in
1057 N_Block_Statement |
1058 N_Entry_Body |
1059 N_Package_Body |
1060 N_Subprogram_Body |
1061 N_Task_Body);
1063 HSS := Handled_Statement_Sequence (N);
1065 -- When the handled sequence of statements comes from source, the
1066 -- location of the "begin" keyword is that of the sequence itself.
1067 -- Note that an internal construct may inherit a source sequence.
1069 if Comes_From_Source (HSS) then
1070 return Sloc (HSS);
1072 -- The parser generates an internal handled sequence of statements to
1073 -- capture the location of the "begin" keyword if present in the source.
1074 -- Since there are no source statements, the location of the "begin"
1075 -- keyword is effectively that of the "end" keyword.
1077 elsif Comes_From_Source (N) then
1078 return Sloc (HSS);
1080 -- Otherwise the construct is internal and should carry the location of
1081 -- the original construct which prompted its creation.
1083 else
1084 return Sloc (N);
1085 end if;
1086 end Begin_Keyword_Location;
1088 --------------------------
1089 -- Build_Actual_Subtype --
1090 --------------------------
1092 function Build_Actual_Subtype
1093 (T : Entity_Id;
1094 N : Node_Or_Entity_Id) return Node_Id
1096 Loc : Source_Ptr;
1097 -- Normally Sloc (N), but may point to corresponding body in some cases
1099 Constraints : List_Id;
1100 Decl : Node_Id;
1101 Discr : Entity_Id;
1102 Hi : Node_Id;
1103 Lo : Node_Id;
1104 Subt : Entity_Id;
1105 Disc_Type : Entity_Id;
1106 Obj : Node_Id;
1107 Index : Node_Id;
1109 begin
1110 Loc := Sloc (N);
1112 if Nkind (N) = N_Defining_Identifier then
1113 Obj := New_Occurrence_Of (N, Loc);
1115 -- If this is a formal parameter of a subprogram declaration, and
1116 -- we are compiling the body, we want the declaration for the
1117 -- actual subtype to carry the source position of the body, to
1118 -- prevent anomalies in gdb when stepping through the code.
1120 if Is_Formal (N) then
1121 declare
1122 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1123 begin
1124 if Nkind (Decl) = N_Subprogram_Declaration
1125 and then Present (Corresponding_Body (Decl))
1126 then
1127 Loc := Sloc (Corresponding_Body (Decl));
1128 end if;
1129 end;
1130 end if;
1132 else
1133 Obj := N;
1134 end if;
1136 if Is_Array_Type (T) then
1137 Constraints := New_List;
1138 Index := First_Index (T);
1140 for J in 1 .. Number_Dimensions (T) loop
1142 -- Build an array subtype declaration with the nominal subtype and
1143 -- the bounds of the actual. Add the declaration in front of the
1144 -- local declarations for the subprogram, for analysis before any
1145 -- reference to the formal in the body.
1147 -- If this is for an index with a fixed lower bound, then use
1148 -- the fixed lower bound as the lower bound of the actual
1149 -- subtype's corresponding index.
1151 if not Is_Constrained (T)
1152 and then Is_Fixed_Lower_Bound_Index_Subtype (Etype (Index))
1153 then
1154 Lo := New_Copy_Tree (Type_Low_Bound (Etype (Index)));
1156 else
1157 Lo :=
1158 Make_Attribute_Reference (Loc,
1159 Prefix =>
1160 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1161 Attribute_Name => Name_First,
1162 Expressions => New_List (
1163 Make_Integer_Literal (Loc, J)));
1164 end if;
1166 Hi :=
1167 Make_Attribute_Reference (Loc,
1168 Prefix =>
1169 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1170 Attribute_Name => Name_Last,
1171 Expressions => New_List (
1172 Make_Integer_Literal (Loc, J)));
1174 Append (Make_Range (Loc, Lo, Hi), Constraints);
1176 Next_Index (Index);
1177 end loop;
1179 -- If the type has unknown discriminants there is no constrained
1180 -- subtype to build. This is never called for a formal or for a
1181 -- lhs, so returning the type is ok ???
1183 elsif Has_Unknown_Discriminants (T) then
1184 return T;
1186 else
1187 Constraints := New_List;
1189 -- Type T is a generic derived type, inherit the discriminants from
1190 -- the parent type.
1192 if Is_Private_Type (T)
1193 and then No (Full_View (T))
1195 -- T was flagged as an error if it was declared as a formal
1196 -- derived type with known discriminants. In this case there
1197 -- is no need to look at the parent type since T already carries
1198 -- its own discriminants.
1200 and then not Error_Posted (T)
1201 then
1202 Disc_Type := Etype (Base_Type (T));
1203 else
1204 Disc_Type := T;
1205 end if;
1207 Discr := First_Discriminant (Disc_Type);
1208 while Present (Discr) loop
1209 Append_To (Constraints,
1210 Make_Selected_Component (Loc,
1211 Prefix =>
1212 Duplicate_Subexpr_No_Checks (Obj),
1213 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1214 Next_Discriminant (Discr);
1215 end loop;
1216 end if;
1218 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1219 Set_Is_Internal (Subt);
1221 Decl :=
1222 Make_Subtype_Declaration (Loc,
1223 Defining_Identifier => Subt,
1224 Subtype_Indication =>
1225 Make_Subtype_Indication (Loc,
1226 Subtype_Mark => New_Occurrence_Of (T, Loc),
1227 Constraint =>
1228 Make_Index_Or_Discriminant_Constraint (Loc,
1229 Constraints => Constraints)));
1231 Mark_Rewrite_Insertion (Decl);
1232 return Decl;
1233 end Build_Actual_Subtype;
1235 ---------------------------------------
1236 -- Build_Actual_Subtype_Of_Component --
1237 ---------------------------------------
1239 function Build_Actual_Subtype_Of_Component
1240 (T : Entity_Id;
1241 N : Node_Id) return Node_Id
1243 Loc : constant Source_Ptr := Sloc (N);
1244 P : constant Node_Id := Prefix (N);
1246 D : Elmt_Id;
1247 Id : Node_Id;
1248 Index_Typ : Entity_Id;
1249 Sel : Entity_Id := Empty;
1251 Desig_Typ : Entity_Id;
1252 -- This is either a copy of T, or if T is an access type, then it is
1253 -- the directly designated type of this access type.
1255 function Build_Access_Record_Constraint (C : List_Id) return List_Id;
1256 -- If the record component is a constrained access to the current
1257 -- record, the subtype has not been constructed during analysis of
1258 -- the enclosing record type (see Analyze_Access). In that case, build
1259 -- a constrained access subtype after replacing references to the
1260 -- enclosing discriminants with the corresponding discriminant values
1261 -- of the prefix.
1263 function Build_Actual_Array_Constraint return List_Id;
1264 -- If one or more of the bounds of the component depends on
1265 -- discriminants, build actual constraint using the discriminants
1266 -- of the prefix, as above.
1268 function Build_Actual_Record_Constraint return List_Id;
1269 -- Similar to previous one, for discriminated components constrained
1270 -- by the discriminant of the enclosing object.
1272 function Build_Discriminant_Reference
1273 (Discrim_Name : Node_Id; Obj : Node_Id := P) return Node_Id;
1274 -- Build a reference to the discriminant denoted by Discrim_Name.
1275 -- The prefix of the result is usually Obj, but it could be
1276 -- a prefix of Obj in some corner cases.
1278 function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id;
1279 -- Copy the subtree rooted at N and insert an explicit dereference if it
1280 -- is of an access type.
1282 -----------------------------------
1283 -- Build_Actual_Array_Constraint --
1284 -----------------------------------
1286 function Build_Actual_Array_Constraint return List_Id is
1287 Constraints : constant List_Id := New_List;
1288 Indx : Node_Id;
1289 Hi : Node_Id;
1290 Lo : Node_Id;
1291 Old_Hi : Node_Id;
1292 Old_Lo : Node_Id;
1294 begin
1295 Indx := First_Index (Desig_Typ);
1296 while Present (Indx) loop
1297 Old_Lo := Type_Low_Bound (Etype (Indx));
1298 Old_Hi := Type_High_Bound (Etype (Indx));
1300 if Denotes_Discriminant (Old_Lo) then
1301 Lo := Build_Discriminant_Reference (Old_Lo);
1302 else
1303 Lo := New_Copy_Tree (Old_Lo);
1305 -- The new bound will be reanalyzed in the enclosing
1306 -- declaration. For literal bounds that come from a type
1307 -- declaration, the type of the context must be imposed, so
1308 -- insure that analysis will take place. For non-universal
1309 -- types this is not strictly necessary.
1311 Set_Analyzed (Lo, False);
1312 end if;
1314 if Denotes_Discriminant (Old_Hi) then
1315 Hi := Build_Discriminant_Reference (Old_Hi);
1316 else
1317 Hi := New_Copy_Tree (Old_Hi);
1318 Set_Analyzed (Hi, False);
1319 end if;
1321 Append (Make_Range (Loc, Lo, Hi), Constraints);
1322 Next_Index (Indx);
1323 end loop;
1325 return Constraints;
1326 end Build_Actual_Array_Constraint;
1328 ------------------------------------
1329 -- Build_Actual_Record_Constraint --
1330 ------------------------------------
1332 function Build_Actual_Record_Constraint return List_Id is
1333 Constraints : constant List_Id := New_List;
1334 D : Elmt_Id;
1335 D_Val : Node_Id;
1337 begin
1338 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1339 while Present (D) loop
1340 if Denotes_Discriminant (Node (D)) then
1341 D_Val := Build_Discriminant_Reference (Node (D));
1342 else
1343 D_Val := New_Copy_Tree (Node (D));
1344 end if;
1346 Append (D_Val, Constraints);
1347 Next_Elmt (D);
1348 end loop;
1350 return Constraints;
1351 end Build_Actual_Record_Constraint;
1353 ----------------------------------
1354 -- Build_Discriminant_Reference --
1355 ----------------------------------
1357 function Build_Discriminant_Reference
1358 (Discrim_Name : Node_Id; Obj : Node_Id := P) return Node_Id
1360 Discrim : constant Entity_Id := Entity (Discrim_Name);
1362 function Obj_Is_Good_Prefix return Boolean;
1363 -- Returns True if Obj.Discrim makes sense; that is, if
1364 -- Obj has Discrim as one of its discriminants (or is an
1365 -- access value that designates such an object).
1367 ------------------------
1368 -- Obj_Is_Good_Prefix --
1369 ------------------------
1371 function Obj_Is_Good_Prefix return Boolean is
1372 Obj_Type : Entity_Id :=
1373 Implementation_Base_Type (Etype (Obj));
1375 Discriminated_Type : constant Entity_Id :=
1376 Implementation_Base_Type
1377 (Scope (Original_Record_Component (Discrim)));
1378 begin
1379 -- The order of the following two tests matters in the
1380 -- access-to-class-wide case.
1382 if Is_Access_Type (Obj_Type) then
1383 Obj_Type := Implementation_Base_Type
1384 (Designated_Type (Obj_Type));
1385 end if;
1387 if Is_Class_Wide_Type (Obj_Type) then
1388 Obj_Type := Implementation_Base_Type
1389 (Find_Specific_Type (Obj_Type));
1390 end if;
1392 -- If a type T1 defines a discriminant D1, then Obj.D1 is ok (for
1393 -- our purposes here) if T1 is an ancestor of the type of Obj.
1394 -- So that's what we would like to test for here.
1395 -- The bad news: Is_Ancestor is only defined in the tagged case.
1396 -- The good news: in the untagged case, Implementation_Base_Type
1397 -- looks through derived types so we can use a simpler test.
1399 if Is_Tagged_Type (Discriminated_Type) then
1400 return Is_Ancestor (Discriminated_Type, Obj_Type);
1401 else
1402 return Discriminated_Type = Obj_Type;
1403 end if;
1404 end Obj_Is_Good_Prefix;
1406 -- Start of processing for Build_Discriminant_Reference
1408 begin
1409 if not Obj_Is_Good_Prefix then
1410 -- If the given discriminant is not a component of the given
1411 -- object, then try the enclosing object.
1413 if Nkind (Obj) = N_Selected_Component then
1414 return Build_Discriminant_Reference
1415 (Discrim_Name => Discrim_Name,
1416 Obj => Prefix (Obj));
1417 elsif Nkind (Obj) in N_Has_Entity
1418 and then Nkind (Parent (Entity (Obj))) =
1419 N_Object_Renaming_Declaration
1420 then
1421 -- Look through a renaming (a corner case of a corner case).
1422 return Build_Discriminant_Reference
1423 (Discrim_Name => Discrim_Name,
1424 Obj => Name (Parent (Entity (Obj))));
1425 else
1426 -- We are in some unexpected case here, so revert to the
1427 -- old behavior (by falling through to it).
1428 null;
1429 end if;
1430 end if;
1432 return Make_Selected_Component (Loc,
1433 Prefix => Copy_And_Maybe_Dereference (Obj),
1434 Selector_Name => New_Occurrence_Of (Discrim, Loc));
1435 end Build_Discriminant_Reference;
1437 ------------------------------------
1438 -- Build_Access_Record_Constraint --
1439 ------------------------------------
1441 function Build_Access_Record_Constraint (C : List_Id) return List_Id is
1442 Constraints : constant List_Id := New_List;
1443 D : Node_Id;
1444 D_Val : Node_Id;
1446 begin
1447 -- Retrieve the constraint from the component declaration, because
1448 -- the component subtype has not been constructed and the component
1449 -- type is an unconstrained access.
1451 D := First (C);
1452 while Present (D) loop
1453 if Nkind (D) = N_Discriminant_Association
1454 and then Denotes_Discriminant (Expression (D))
1455 then
1456 D_Val := New_Copy_Tree (D);
1457 Set_Expression (D_Val,
1458 Make_Selected_Component (Loc,
1459 Prefix => Copy_And_Maybe_Dereference (P),
1460 Selector_Name =>
1461 New_Occurrence_Of (Entity (Expression (D)), Loc)));
1463 elsif Denotes_Discriminant (D) then
1464 D_Val := Make_Selected_Component (Loc,
1465 Prefix => Copy_And_Maybe_Dereference (P),
1466 Selector_Name => New_Occurrence_Of (Entity (D), Loc));
1468 else
1469 D_Val := New_Copy_Tree (D);
1470 end if;
1472 Append (D_Val, Constraints);
1473 Next (D);
1474 end loop;
1476 return Constraints;
1477 end Build_Access_Record_Constraint;
1479 --------------------------------
1480 -- Copy_And_Maybe_Dereference --
1481 --------------------------------
1483 function Copy_And_Maybe_Dereference (N : Node_Id) return Node_Id is
1484 New_N : constant Node_Id := New_Copy_Tree (N);
1486 begin
1487 if Is_Access_Type (Etype (N)) then
1488 return Make_Explicit_Dereference (Sloc (Parent (N)), New_N);
1490 else
1491 return New_N;
1492 end if;
1493 end Copy_And_Maybe_Dereference;
1495 -- Start of processing for Build_Actual_Subtype_Of_Component
1497 begin
1498 -- The subtype does not need to be created for a selected component
1499 -- in a Spec_Expression.
1501 if In_Spec_Expression then
1502 return Empty;
1504 -- More comments for the rest of this body would be good ???
1506 elsif Nkind (N) = N_Explicit_Dereference then
1507 if Is_Composite_Type (T)
1508 and then not Is_Constrained (T)
1509 and then not (Is_Class_Wide_Type (T)
1510 and then Is_Constrained (Root_Type (T)))
1511 and then not Has_Unknown_Discriminants (T)
1512 then
1513 -- If the type of the dereference is already constrained, it is an
1514 -- actual subtype.
1516 if Is_Array_Type (Etype (N))
1517 and then Is_Constrained (Etype (N))
1518 then
1519 return Empty;
1520 else
1521 Remove_Side_Effects (P);
1522 return Build_Actual_Subtype (T, N);
1523 end if;
1525 else
1526 return Empty;
1527 end if;
1529 elsif Nkind (N) = N_Selected_Component then
1530 -- The entity of the selected component allows us to retrieve
1531 -- the original constraint from its component declaration.
1533 Sel := Entity (Selector_Name (N));
1534 if Parent_Kind (Sel) /= N_Component_Declaration then
1535 return Empty;
1536 end if;
1537 end if;
1539 if Is_Access_Type (T) then
1540 Desig_Typ := Designated_Type (T);
1542 else
1543 Desig_Typ := T;
1544 end if;
1546 if Ekind (Desig_Typ) = E_Array_Subtype then
1547 Id := First_Index (Desig_Typ);
1549 -- Check whether an index bound is constrained by a discriminant
1551 while Present (Id) loop
1552 Index_Typ := Underlying_Type (Etype (Id));
1554 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1555 or else
1556 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1557 then
1558 Remove_Side_Effects (P);
1559 return
1560 Build_Component_Subtype
1561 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1562 end if;
1564 Next_Index (Id);
1565 end loop;
1567 elsif Is_Composite_Type (Desig_Typ)
1568 and then Has_Discriminants (Desig_Typ)
1569 and then not Is_Empty_Elmt_List (Discriminant_Constraint (Desig_Typ))
1570 and then not Has_Unknown_Discriminants (Desig_Typ)
1571 then
1572 if Is_Private_Type (Desig_Typ)
1573 and then No (Discriminant_Constraint (Desig_Typ))
1574 then
1575 Desig_Typ := Full_View (Desig_Typ);
1576 end if;
1578 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1579 while Present (D) loop
1580 if Denotes_Discriminant (Node (D)) then
1581 Remove_Side_Effects (P);
1582 return
1583 Build_Component_Subtype (
1584 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1585 end if;
1587 Next_Elmt (D);
1588 end loop;
1590 -- Special processing for an access record component that is
1591 -- the target of an assignment. If the designated type is an
1592 -- unconstrained discriminated record we create its actual
1593 -- subtype now.
1595 elsif Ekind (T) = E_Access_Type
1596 and then Present (Sel)
1597 and then Has_Per_Object_Constraint (Sel)
1598 and then Nkind (Parent (N)) = N_Assignment_Statement
1599 and then N = Name (Parent (N))
1600 -- and then not Inside_Init_Proc
1601 -- and then Has_Discriminants (Desig_Typ)
1602 -- and then not Is_Constrained (Desig_Typ)
1603 then
1604 declare
1605 S_Indic : constant Node_Id :=
1606 (Subtype_Indication
1607 (Component_Definition (Parent (Sel))));
1608 Discs : List_Id;
1609 begin
1610 if Nkind (S_Indic) = N_Subtype_Indication then
1611 Discs := Constraints (Constraint (S_Indic));
1613 Remove_Side_Effects (P);
1614 return Build_Component_Subtype
1615 (Build_Access_Record_Constraint (Discs), Loc, T);
1616 else
1617 return Empty;
1618 end if;
1619 end;
1620 end if;
1622 -- If none of the above, the actual and nominal subtypes are the same
1624 return Empty;
1625 end Build_Actual_Subtype_Of_Component;
1627 -----------------------------
1628 -- Build_Component_Subtype --
1629 -----------------------------
1631 function Build_Component_Subtype
1632 (C : List_Id;
1633 Loc : Source_Ptr;
1634 T : Entity_Id) return Node_Id
1636 Subt : Entity_Id;
1637 Decl : Node_Id;
1639 begin
1640 -- Unchecked_Union components do not require component subtypes
1642 if Is_Unchecked_Union (T) then
1643 return Empty;
1644 end if;
1646 Subt := Make_Temporary (Loc, 'S');
1647 Set_Is_Internal (Subt);
1649 Decl :=
1650 Make_Subtype_Declaration (Loc,
1651 Defining_Identifier => Subt,
1652 Subtype_Indication =>
1653 Make_Subtype_Indication (Loc,
1654 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1655 Constraint =>
1656 Make_Index_Or_Discriminant_Constraint (Loc,
1657 Constraints => C)));
1659 Mark_Rewrite_Insertion (Decl);
1660 return Decl;
1661 end Build_Component_Subtype;
1663 -----------------------------
1664 -- Build_Constrained_Itype --
1665 -----------------------------
1667 procedure Build_Constrained_Itype
1668 (N : Node_Id;
1669 Typ : Entity_Id;
1670 New_Assoc_List : List_Id)
1672 Constrs : constant List_Id := New_List;
1673 Loc : constant Source_Ptr := Sloc (N);
1674 Def_Id : Entity_Id;
1675 Indic : Node_Id;
1676 New_Assoc : Node_Id;
1677 Subtyp_Decl : Node_Id;
1679 begin
1680 New_Assoc := First (New_Assoc_List);
1681 while Present (New_Assoc) loop
1683 -- There is exactly one choice in the component association (and
1684 -- it is either a discriminant, a component or the others clause).
1685 pragma Assert (List_Length (Choices (New_Assoc)) = 1);
1687 -- Duplicate expression for the discriminant and put it on the
1688 -- list of constraints for the itype declaration.
1690 if Is_Entity_Name (First (Choices (New_Assoc)))
1691 and then
1692 Ekind (Entity (First (Choices (New_Assoc)))) = E_Discriminant
1693 then
1694 Append_To (Constrs, Duplicate_Subexpr (Expression (New_Assoc)));
1695 end if;
1697 Next (New_Assoc);
1698 end loop;
1700 if Has_Unknown_Discriminants (Typ)
1701 and then Present (Underlying_Record_View (Typ))
1702 then
1703 Indic :=
1704 Make_Subtype_Indication (Loc,
1705 Subtype_Mark =>
1706 New_Occurrence_Of (Underlying_Record_View (Typ), Loc),
1707 Constraint =>
1708 Make_Index_Or_Discriminant_Constraint (Loc,
1709 Constraints => Constrs));
1710 else
1711 Indic :=
1712 Make_Subtype_Indication (Loc,
1713 Subtype_Mark =>
1714 New_Occurrence_Of (Base_Type (Typ), Loc),
1715 Constraint =>
1716 Make_Index_Or_Discriminant_Constraint (Loc,
1717 Constraints => Constrs));
1718 end if;
1720 Def_Id := Create_Itype (Ekind (Typ), N);
1722 Subtyp_Decl :=
1723 Make_Subtype_Declaration (Loc,
1724 Defining_Identifier => Def_Id,
1725 Subtype_Indication => Indic);
1726 Set_Parent (Subtyp_Decl, Parent (N));
1728 -- Itypes must be analyzed with checks off (see itypes.ads)
1730 Analyze (Subtyp_Decl, Suppress => All_Checks);
1732 Set_Etype (N, Def_Id);
1733 end Build_Constrained_Itype;
1735 ---------------------------
1736 -- Build_Default_Subtype --
1737 ---------------------------
1739 function Build_Default_Subtype
1740 (T : Entity_Id;
1741 N : Node_Id) return Entity_Id
1743 Loc : constant Source_Ptr := Sloc (N);
1744 Disc : Entity_Id;
1746 Bas : Entity_Id;
1747 -- The base type that is to be constrained by the defaults
1749 begin
1750 if not Has_Discriminants (T) or else Is_Constrained (T) then
1751 return T;
1752 end if;
1754 Bas := Base_Type (T);
1756 -- If T is non-private but its base type is private, this is the
1757 -- completion of a subtype declaration whose parent type is private
1758 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1759 -- are to be found in the full view of the base. Check that the private
1760 -- status of T and its base differ.
1762 if Is_Private_Type (Bas)
1763 and then not Is_Private_Type (T)
1764 and then Present (Full_View (Bas))
1765 then
1766 Bas := Full_View (Bas);
1767 end if;
1769 Disc := First_Discriminant (T);
1771 if No (Discriminant_Default_Value (Disc)) then
1772 return T;
1773 end if;
1775 declare
1776 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1777 Constraints : constant List_Id := New_List;
1778 Decl : Node_Id;
1780 begin
1781 while Present (Disc) loop
1782 Append_To (Constraints,
1783 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1784 Next_Discriminant (Disc);
1785 end loop;
1787 Decl :=
1788 Make_Subtype_Declaration (Loc,
1789 Defining_Identifier => Act,
1790 Subtype_Indication =>
1791 Make_Subtype_Indication (Loc,
1792 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1793 Constraint =>
1794 Make_Index_Or_Discriminant_Constraint (Loc,
1795 Constraints => Constraints)));
1797 Insert_Action (N, Decl);
1799 -- If the context is a component declaration the subtype declaration
1800 -- will be analyzed when the enclosing type is frozen, otherwise do
1801 -- it now.
1803 if Ekind (Current_Scope) /= E_Record_Type then
1804 Analyze (Decl);
1805 end if;
1807 return Act;
1808 end;
1809 end Build_Default_Subtype;
1811 ------------------------------
1812 -- Build_Default_Subtype_OK --
1813 ------------------------------
1815 function Build_Default_Subtype_OK (T : Entity_Id) return Boolean is
1816 begin
1818 if Is_Constrained (T) then
1820 -- We won't build a new subtype if T is constrained
1822 return False;
1823 end if;
1825 return Is_Definite_Subtype (T) and then Is_Inherently_Limited_Type (T);
1826 end Build_Default_Subtype_OK;
1828 --------------------------------------------
1829 -- Build_Discriminal_Subtype_Of_Component --
1830 --------------------------------------------
1832 function Build_Discriminal_Subtype_Of_Component
1833 (T : Entity_Id) return Node_Id
1835 Loc : constant Source_Ptr := Sloc (T);
1836 D : Elmt_Id;
1837 Id : Node_Id;
1839 function Build_Discriminal_Array_Constraint return List_Id;
1840 -- If one or more of the bounds of the component depends on
1841 -- discriminants, build actual constraint using the discriminants
1842 -- of the prefix.
1844 function Build_Discriminal_Record_Constraint return List_Id;
1845 -- Similar to previous one, for discriminated components constrained by
1846 -- the discriminant of the enclosing object.
1848 ----------------------------------------
1849 -- Build_Discriminal_Array_Constraint --
1850 ----------------------------------------
1852 function Build_Discriminal_Array_Constraint return List_Id is
1853 Constraints : constant List_Id := New_List;
1854 Indx : Node_Id;
1855 Hi : Node_Id;
1856 Lo : Node_Id;
1857 Old_Hi : Node_Id;
1858 Old_Lo : Node_Id;
1860 begin
1861 Indx := First_Index (T);
1862 while Present (Indx) loop
1863 Old_Lo := Type_Low_Bound (Etype (Indx));
1864 Old_Hi := Type_High_Bound (Etype (Indx));
1866 if Denotes_Discriminant (Old_Lo) then
1867 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1869 else
1870 Lo := New_Copy_Tree (Old_Lo);
1871 end if;
1873 if Denotes_Discriminant (Old_Hi) then
1874 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1876 else
1877 Hi := New_Copy_Tree (Old_Hi);
1878 end if;
1880 Append (Make_Range (Loc, Lo, Hi), Constraints);
1881 Next_Index (Indx);
1882 end loop;
1884 return Constraints;
1885 end Build_Discriminal_Array_Constraint;
1887 -----------------------------------------
1888 -- Build_Discriminal_Record_Constraint --
1889 -----------------------------------------
1891 function Build_Discriminal_Record_Constraint return List_Id is
1892 Constraints : constant List_Id := New_List;
1893 D : Elmt_Id;
1894 D_Val : Node_Id;
1896 begin
1897 D := First_Elmt (Discriminant_Constraint (T));
1898 while Present (D) loop
1899 if Denotes_Discriminant (Node (D)) then
1900 D_Val :=
1901 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1902 else
1903 D_Val := New_Copy_Tree (Node (D));
1904 end if;
1906 Append (D_Val, Constraints);
1907 Next_Elmt (D);
1908 end loop;
1910 return Constraints;
1911 end Build_Discriminal_Record_Constraint;
1913 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1915 begin
1916 if Ekind (T) = E_Array_Subtype then
1917 Id := First_Index (T);
1918 while Present (Id) loop
1919 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1920 or else
1921 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1922 then
1923 return Build_Component_Subtype
1924 (Build_Discriminal_Array_Constraint, Loc, T);
1925 end if;
1927 Next_Index (Id);
1928 end loop;
1930 elsif Ekind (T) = E_Record_Subtype
1931 and then Has_Discriminants (T)
1932 and then not Has_Unknown_Discriminants (T)
1933 then
1934 D := First_Elmt (Discriminant_Constraint (T));
1935 while Present (D) loop
1936 if Denotes_Discriminant (Node (D)) then
1937 return Build_Component_Subtype
1938 (Build_Discriminal_Record_Constraint, Loc, T);
1939 end if;
1941 Next_Elmt (D);
1942 end loop;
1943 end if;
1945 -- If none of the above, the actual and nominal subtypes are the same
1947 return Empty;
1948 end Build_Discriminal_Subtype_Of_Component;
1950 ------------------------------
1951 -- Build_Elaboration_Entity --
1952 ------------------------------
1954 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1955 Loc : constant Source_Ptr := Sloc (N);
1956 Decl : Node_Id;
1957 Elab_Ent : Entity_Id;
1959 procedure Set_Package_Name (Ent : Entity_Id);
1960 -- Given an entity, sets the fully qualified name of the entity in
1961 -- Name_Buffer, with components separated by double underscores. This
1962 -- is a recursive routine that climbs the scope chain to Standard.
1964 ----------------------
1965 -- Set_Package_Name --
1966 ----------------------
1968 procedure Set_Package_Name (Ent : Entity_Id) is
1969 begin
1970 if Scope (Ent) /= Standard_Standard then
1971 Set_Package_Name (Scope (Ent));
1973 declare
1974 Nam : constant String := Get_Name_String (Chars (Ent));
1975 begin
1976 Name_Buffer (Name_Len + 1) := '_';
1977 Name_Buffer (Name_Len + 2) := '_';
1978 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1979 Name_Len := Name_Len + Nam'Length + 2;
1980 end;
1982 else
1983 Get_Name_String (Chars (Ent));
1984 end if;
1985 end Set_Package_Name;
1987 -- Start of processing for Build_Elaboration_Entity
1989 begin
1990 -- Ignore call if already constructed
1992 if Present (Elaboration_Entity (Spec_Id)) then
1993 return;
1995 -- Do not generate an elaboration entity in GNATprove move because the
1996 -- elaboration counter is a form of expansion.
1998 elsif GNATprove_Mode then
1999 return;
2001 -- See if we need elaboration entity
2003 -- We always need an elaboration entity when preserving control flow, as
2004 -- we want to remain explicit about the unit's elaboration order.
2006 elsif Opt.Suppress_Control_Flow_Optimizations then
2007 null;
2009 -- We always need an elaboration entity for the dynamic elaboration
2010 -- model, since it is needed to properly generate the PE exception for
2011 -- access before elaboration.
2013 elsif Dynamic_Elaboration_Checks then
2014 null;
2016 -- For the static model, we don't need the elaboration counter if this
2017 -- unit is sure to have no elaboration code, since that means there
2018 -- is no elaboration unit to be called. Note that we can't just decide
2019 -- after the fact by looking to see whether there was elaboration code,
2020 -- because that's too late to make this decision.
2022 elsif Restriction_Active (No_Elaboration_Code) then
2023 return;
2025 -- Similarly, for the static model, we can skip the elaboration counter
2026 -- if we have the No_Multiple_Elaboration restriction, since for the
2027 -- static model, that's the only purpose of the counter (to avoid
2028 -- multiple elaboration).
2030 elsif Restriction_Active (No_Multiple_Elaboration) then
2031 return;
2032 end if;
2034 -- Here we need the elaboration entity
2036 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
2037 -- name with dots replaced by double underscore. We have to manually
2038 -- construct this name, since it will be elaborated in the outer scope,
2039 -- and thus will not have the unit name automatically prepended.
2041 Set_Package_Name (Spec_Id);
2042 Add_Str_To_Name_Buffer ("_E");
2044 -- Create elaboration counter
2046 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
2047 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
2049 Decl :=
2050 Make_Object_Declaration (Loc,
2051 Defining_Identifier => Elab_Ent,
2052 Object_Definition =>
2053 New_Occurrence_Of (Standard_Short_Integer, Loc),
2054 Expression => Make_Integer_Literal (Loc, Uint_0));
2056 Push_Scope (Standard_Standard);
2057 Add_Global_Declaration (Decl);
2058 Pop_Scope;
2060 -- Reset True_Constant indication, since we will indeed assign a value
2061 -- to the variable in the binder main. We also kill the Current_Value
2062 -- and Last_Assignment fields for the same reason.
2064 Set_Is_True_Constant (Elab_Ent, False);
2065 Set_Current_Value (Elab_Ent, Empty);
2066 Set_Last_Assignment (Elab_Ent, Empty);
2068 -- We do not want any further qualification of the name (if we did not
2069 -- do this, we would pick up the name of the generic package in the case
2070 -- of a library level generic instantiation).
2072 Set_Has_Qualified_Name (Elab_Ent);
2073 Set_Has_Fully_Qualified_Name (Elab_Ent);
2074 end Build_Elaboration_Entity;
2076 --------------------------------
2077 -- Build_Explicit_Dereference --
2078 --------------------------------
2080 procedure Build_Explicit_Dereference
2081 (Expr : Node_Id;
2082 Disc : Entity_Id)
2084 Loc : constant Source_Ptr := Sloc (Expr);
2085 I : Interp_Index;
2086 It : Interp;
2088 begin
2089 -- An entity of a type with a reference aspect is overloaded with
2090 -- both interpretations: with and without the dereference. Now that
2091 -- the dereference is made explicit, set the type of the node properly,
2092 -- to prevent anomalies in the backend. Same if the expression is an
2093 -- overloaded function call whose return type has a reference aspect.
2095 if Is_Entity_Name (Expr) then
2096 Set_Etype (Expr, Etype (Entity (Expr)));
2098 -- The designated entity will not be examined again when resolving
2099 -- the dereference, so generate a reference to it now.
2101 Generate_Reference (Entity (Expr), Expr);
2103 elsif Nkind (Expr) = N_Function_Call then
2105 -- If the name of the indexing function is overloaded, locate the one
2106 -- whose return type has an implicit dereference on the desired
2107 -- discriminant, and set entity and type of function call.
2109 if Is_Overloaded (Name (Expr)) then
2110 Get_First_Interp (Name (Expr), I, It);
2112 while Present (It.Nam) loop
2113 if Ekind ((It.Typ)) = E_Record_Type
2114 and then First_Entity ((It.Typ)) = Disc
2115 then
2116 Set_Entity (Name (Expr), It.Nam);
2117 Set_Etype (Name (Expr), Etype (It.Nam));
2118 exit;
2119 end if;
2121 Get_Next_Interp (I, It);
2122 end loop;
2123 end if;
2125 -- Set type of call from resolved function name.
2127 Set_Etype (Expr, Etype (Name (Expr)));
2128 end if;
2130 Set_Is_Overloaded (Expr, False);
2132 -- The expression will often be a generalized indexing that yields a
2133 -- container element that is then dereferenced, in which case the
2134 -- generalized indexing call is also non-overloaded.
2136 if Nkind (Expr) = N_Indexed_Component
2137 and then Present (Generalized_Indexing (Expr))
2138 then
2139 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
2140 end if;
2142 Rewrite (Expr,
2143 Make_Explicit_Dereference (Loc,
2144 Prefix =>
2145 Make_Selected_Component (Loc,
2146 Prefix => Relocate_Node (Expr),
2147 Selector_Name => New_Occurrence_Of (Disc, Loc))));
2148 Set_Etype (Prefix (Expr), Etype (Disc));
2149 Set_Etype (Expr, Designated_Type (Etype (Disc)));
2150 end Build_Explicit_Dereference;
2152 ---------------------------
2153 -- Build_Overriding_Spec --
2154 ---------------------------
2156 function Build_Overriding_Spec
2157 (Op : Entity_Id;
2158 Typ : Entity_Id) return Node_Id
2160 Loc : constant Source_Ptr := Sloc (Typ);
2161 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
2162 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
2164 Formal_Spec : Node_Id;
2165 Formal_Type : Node_Id;
2166 New_Spec : Node_Id;
2168 begin
2169 New_Spec := Copy_Subprogram_Spec (Spec);
2171 Formal_Spec := First (Parameter_Specifications (New_Spec));
2172 while Present (Formal_Spec) loop
2173 Formal_Type := Parameter_Type (Formal_Spec);
2175 if Is_Entity_Name (Formal_Type)
2176 and then Entity (Formal_Type) = Par_Typ
2177 then
2178 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
2180 elsif Nkind (Formal_Type) = N_Access_Definition
2181 and then Entity (Subtype_Mark (Formal_Type)) = Par_Typ
2182 then
2183 Rewrite (Subtype_Mark (Formal_Type), New_Occurrence_Of (Typ, Loc));
2184 end if;
2186 Next (Formal_Spec);
2187 end loop;
2189 return New_Spec;
2190 end Build_Overriding_Spec;
2192 -------------------
2193 -- Build_Subtype --
2194 -------------------
2196 function Build_Subtype
2197 (Related_Node : Node_Id;
2198 Loc : Source_Ptr;
2199 Typ : Entity_Id;
2200 Constraints : List_Id)
2201 return Entity_Id
2203 Indic : Node_Id;
2204 Subtyp_Decl : Node_Id;
2205 Def_Id : Entity_Id;
2206 Btyp : Entity_Id := Base_Type (Typ);
2208 begin
2209 -- The Related_Node better be here or else we won't be able to
2210 -- attach new itypes to a node in the tree.
2212 pragma Assert (Present (Related_Node));
2214 -- If the view of the component's type is incomplete or private
2215 -- with unknown discriminants, then the constraint must be applied
2216 -- to the full type.
2218 if Has_Unknown_Discriminants (Btyp)
2219 and then Present (Underlying_Type (Btyp))
2220 then
2221 Btyp := Underlying_Type (Btyp);
2222 end if;
2224 Indic :=
2225 Make_Subtype_Indication (Loc,
2226 Subtype_Mark => New_Occurrence_Of (Btyp, Loc),
2227 Constraint =>
2228 Make_Index_Or_Discriminant_Constraint (Loc, Constraints));
2230 Def_Id := Create_Itype (Ekind (Typ), Related_Node);
2232 Subtyp_Decl :=
2233 Make_Subtype_Declaration (Loc,
2234 Defining_Identifier => Def_Id,
2235 Subtype_Indication => Indic);
2237 Set_Parent (Subtyp_Decl, Parent (Related_Node));
2239 -- Itypes must be analyzed with checks off (see package Itypes)
2241 Analyze (Subtyp_Decl, Suppress => All_Checks);
2243 if Is_Itype (Def_Id) and then Has_Predicates (Typ) then
2244 Inherit_Predicate_Flags (Def_Id, Typ);
2246 -- Indicate where the predicate function may be found
2248 if Is_Itype (Typ) then
2249 if Present (Predicate_Function (Def_Id)) then
2250 null;
2252 elsif Present (Predicate_Function (Typ)) then
2253 Set_Predicate_Function (Def_Id, Predicate_Function (Typ));
2255 else
2256 Set_Predicated_Parent (Def_Id, Predicated_Parent (Typ));
2257 end if;
2259 elsif No (Predicate_Function (Def_Id)) then
2260 Set_Predicated_Parent (Def_Id, Typ);
2261 end if;
2262 end if;
2264 return Def_Id;
2265 end Build_Subtype;
2267 -----------------------------------
2268 -- Cannot_Raise_Constraint_Error --
2269 -----------------------------------
2271 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
2273 function List_Cannot_Raise_CE (L : List_Id) return Boolean;
2274 -- Returns True if none of the list members cannot possibly raise
2275 -- Constraint_Error.
2277 --------------------------
2278 -- List_Cannot_Raise_CE --
2279 --------------------------
2281 function List_Cannot_Raise_CE (L : List_Id) return Boolean is
2282 N : Node_Id;
2283 begin
2284 N := First (L);
2285 while Present (N) loop
2286 if Cannot_Raise_Constraint_Error (N) then
2287 Next (N);
2288 else
2289 return False;
2290 end if;
2291 end loop;
2293 return True;
2294 end List_Cannot_Raise_CE;
2296 -- Start of processing for Cannot_Raise_Constraint_Error
2298 begin
2299 if Compile_Time_Known_Value (Expr) then
2300 return True;
2302 elsif Do_Range_Check (Expr) then
2303 return False;
2305 elsif Raises_Constraint_Error (Expr) then
2306 return False;
2308 else
2309 case Nkind (Expr) is
2310 when N_Identifier =>
2311 return True;
2313 when N_Expanded_Name =>
2314 return True;
2316 when N_Indexed_Component =>
2317 return not Do_Range_Check (Expr)
2318 and then Cannot_Raise_Constraint_Error (Prefix (Expr))
2319 and then List_Cannot_Raise_CE (Expressions (Expr));
2321 when N_Selected_Component =>
2322 return not Do_Discriminant_Check (Expr)
2323 and then Cannot_Raise_Constraint_Error (Prefix (Expr));
2325 when N_Attribute_Reference =>
2326 if Do_Overflow_Check (Expr) then
2327 return False;
2329 elsif No (Expressions (Expr)) then
2330 return True;
2332 else
2333 return List_Cannot_Raise_CE (Expressions (Expr));
2334 end if;
2336 when N_Type_Conversion =>
2337 if Do_Overflow_Check (Expr)
2338 or else Do_Length_Check (Expr)
2339 then
2340 return False;
2341 else
2342 return Cannot_Raise_Constraint_Error (Expression (Expr));
2343 end if;
2345 when N_Unchecked_Type_Conversion =>
2346 return Cannot_Raise_Constraint_Error (Expression (Expr));
2348 when N_Unary_Op =>
2349 if Do_Overflow_Check (Expr) then
2350 return False;
2351 else
2352 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2353 end if;
2355 when N_Op_Divide
2356 | N_Op_Mod
2357 | N_Op_Rem
2359 if Do_Division_Check (Expr)
2360 or else
2361 Do_Overflow_Check (Expr)
2362 then
2363 return False;
2364 else
2365 return
2366 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2367 and then
2368 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2369 end if;
2371 when N_Op_Add
2372 | N_Op_And
2373 | N_Op_Concat
2374 | N_Op_Eq
2375 | N_Op_Expon
2376 | N_Op_Ge
2377 | N_Op_Gt
2378 | N_Op_Le
2379 | N_Op_Lt
2380 | N_Op_Multiply
2381 | N_Op_Ne
2382 | N_Op_Or
2383 | N_Op_Rotate_Left
2384 | N_Op_Rotate_Right
2385 | N_Op_Shift_Left
2386 | N_Op_Shift_Right
2387 | N_Op_Shift_Right_Arithmetic
2388 | N_Op_Subtract
2389 | N_Op_Xor
2391 if Do_Overflow_Check (Expr) then
2392 return False;
2393 else
2394 return
2395 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2396 and then
2397 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2398 end if;
2400 when others =>
2401 return False;
2402 end case;
2403 end if;
2404 end Cannot_Raise_Constraint_Error;
2406 -------------------------------
2407 -- Check_Ambiguous_Aggregate --
2408 -------------------------------
2410 procedure Check_Ambiguous_Aggregate (Call : Node_Id) is
2411 Actual : Node_Id;
2413 begin
2414 if All_Extensions_Allowed then
2415 Actual := First_Actual (Call);
2416 while Present (Actual) loop
2417 if Nkind (Actual) = N_Aggregate then
2418 Error_Msg_N
2419 ("\add type qualification to aggregate actual", Actual);
2420 exit;
2421 end if;
2422 Next_Actual (Actual);
2423 end loop;
2424 end if;
2425 end Check_Ambiguous_Aggregate;
2427 -----------------------------------------
2428 -- Check_Dynamically_Tagged_Expression --
2429 -----------------------------------------
2431 procedure Check_Dynamically_Tagged_Expression
2432 (Expr : Node_Id;
2433 Typ : Entity_Id;
2434 Related_Nod : Node_Id)
2436 begin
2437 pragma Assert (Is_Tagged_Type (Typ));
2439 -- In order to avoid spurious errors when analyzing the expanded code,
2440 -- this check is done only for nodes that come from source and for
2441 -- actuals of generic instantiations.
2443 if (Comes_From_Source (Related_Nod)
2444 or else In_Generic_Actual (Expr))
2445 and then (Is_Class_Wide_Type (Etype (Expr))
2446 or else Is_Dynamically_Tagged (Expr))
2447 and then not Is_Class_Wide_Type (Typ)
2448 then
2449 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2450 end if;
2451 end Check_Dynamically_Tagged_Expression;
2453 --------------------------
2454 -- Check_Fully_Declared --
2455 --------------------------
2457 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2458 begin
2459 if Ekind (T) = E_Incomplete_Type then
2461 -- Ada 2005 (AI-50217): If the type is available through a limited
2462 -- with_clause, verify that its full view has been analyzed.
2464 if From_Limited_With (T)
2465 and then Present (Non_Limited_View (T))
2466 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2467 then
2468 -- The non-limited view is fully declared
2470 null;
2472 else
2473 Error_Msg_NE
2474 ("premature usage of incomplete}", N, First_Subtype (T));
2475 end if;
2477 -- Need comments for these tests ???
2479 elsif Has_Private_Component (T)
2480 and then not Is_Generic_Type (Root_Type (T))
2481 and then not In_Spec_Expression
2482 then
2483 -- Special case: if T is the anonymous type created for a single
2484 -- task or protected object, use the name of the source object.
2486 if Is_Concurrent_Type (T)
2487 and then not Comes_From_Source (T)
2488 and then Nkind (N) = N_Object_Declaration
2489 then
2490 Error_Msg_NE
2491 ("type of& has incomplete component",
2492 N, Defining_Identifier (N));
2493 else
2494 Error_Msg_NE
2495 ("premature usage of incomplete}",
2496 N, First_Subtype (T));
2497 end if;
2498 end if;
2499 end Check_Fully_Declared;
2501 -------------------------------------------
2502 -- Check_Function_With_Address_Parameter --
2503 -------------------------------------------
2505 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2506 F : Entity_Id;
2507 T : Entity_Id;
2509 begin
2510 F := First_Formal (Subp_Id);
2511 while Present (F) loop
2512 T := Etype (F);
2514 if Is_Private_Type (T) and then Present (Full_View (T)) then
2515 T := Full_View (T);
2516 end if;
2518 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2519 Set_Is_Pure (Subp_Id, False);
2520 exit;
2521 end if;
2523 Next_Formal (F);
2524 end loop;
2525 end Check_Function_With_Address_Parameter;
2527 -------------------------------------
2528 -- Check_Function_Writable_Actuals --
2529 -------------------------------------
2531 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2532 Writable_Actuals_List : Elist_Id := No_Elist;
2533 Identifiers_List : Elist_Id := No_Elist;
2534 Aggr_Error_Node : Node_Id := Empty;
2535 Error_Node : Node_Id := Empty;
2537 procedure Collect_Identifiers (N : Node_Id);
2538 -- In a single traversal of subtree N collect in Writable_Actuals_List
2539 -- all the actuals of functions with writable actuals, and in the list
2540 -- Identifiers_List collect all the identifiers that are not actuals of
2541 -- functions with writable actuals. If a writable actual is referenced
2542 -- twice as writable actual then Error_Node is set to reference its
2543 -- second occurrence, the error is reported, and the tree traversal
2544 -- is abandoned.
2546 -------------------------
2547 -- Collect_Identifiers --
2548 -------------------------
2550 procedure Collect_Identifiers (N : Node_Id) is
2552 function Check_Node (N : Node_Id) return Traverse_Result;
2553 -- Process a single node during the tree traversal to collect the
2554 -- writable actuals of functions and all the identifiers which are
2555 -- not writable actuals of functions.
2557 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2558 -- Returns True if List has a node whose Entity is Entity (N)
2560 ----------------
2561 -- Check_Node --
2562 ----------------
2564 function Check_Node (N : Node_Id) return Traverse_Result is
2565 Is_Writable_Actual : Boolean := False;
2566 Id : Entity_Id := Empty;
2567 -- Default init of Id for CodePeer
2569 begin
2570 if Nkind (N) = N_Identifier then
2572 -- No analysis possible if the entity is not decorated
2574 if No (Entity (N)) then
2575 return Skip;
2577 -- Don't collect identifiers of packages, called functions, etc
2579 elsif Ekind (Entity (N)) in
2580 E_Package | E_Function | E_Procedure | E_Entry
2581 then
2582 return Skip;
2584 -- For rewritten nodes, continue the traversal in the original
2585 -- subtree. Needed to handle aggregates in original expressions
2586 -- extracted from the tree by Remove_Side_Effects.
2588 elsif Is_Rewrite_Substitution (N) then
2589 Collect_Identifiers (Original_Node (N));
2590 return Skip;
2592 -- For now we skip aggregate discriminants, since they require
2593 -- performing the analysis in two phases to identify conflicts:
2594 -- first one analyzing discriminants and second one analyzing
2595 -- the rest of components (since at run time, discriminants are
2596 -- evaluated prior to components): too much computation cost
2597 -- to identify a corner case???
2599 elsif Nkind (Parent (N)) = N_Component_Association
2600 and then Nkind (Parent (Parent (N))) in
2601 N_Aggregate | N_Extension_Aggregate
2602 then
2603 declare
2604 Choice : constant Node_Id := First (Choices (Parent (N)));
2606 begin
2607 if Ekind (Entity (N)) = E_Discriminant then
2608 return Skip;
2610 elsif Expression (Parent (N)) = N
2611 and then Nkind (Choice) = N_Identifier
2612 and then Ekind (Entity (Choice)) = E_Discriminant
2613 then
2614 return Skip;
2615 end if;
2616 end;
2618 -- Analyze if N is a writable actual of a function
2620 elsif Nkind (Parent (N)) = N_Function_Call then
2621 declare
2622 Call : constant Node_Id := Parent (N);
2623 Actual : Node_Id;
2624 Formal : Node_Id;
2626 begin
2627 Id := Get_Called_Entity (Call);
2629 -- In case of previous error, no check is possible
2631 if No (Id) then
2632 return Abandon;
2633 end if;
2635 if Ekind (Id) in E_Function | E_Generic_Function
2636 and then Has_Out_Or_In_Out_Parameter (Id)
2637 then
2638 Formal := First_Formal (Id);
2639 Actual := First_Actual (Call);
2640 while Present (Actual) and then Present (Formal) loop
2641 if Actual = N then
2642 if Ekind (Formal) in E_Out_Parameter
2643 | E_In_Out_Parameter
2644 then
2645 Is_Writable_Actual := True;
2646 end if;
2648 exit;
2649 end if;
2651 Next_Formal (Formal);
2652 Next_Actual (Actual);
2653 end loop;
2654 end if;
2655 end;
2656 end if;
2658 if Is_Writable_Actual then
2660 -- Skip checking the error in non-elementary types since
2661 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2662 -- store this actual in Writable_Actuals_List since it is
2663 -- needed to perform checks on other constructs that have
2664 -- arbitrary order of evaluation (for example, aggregates).
2666 if not Is_Elementary_Type (Etype (N)) then
2667 if not Contains (Writable_Actuals_List, N) then
2668 Append_New_Elmt (N, To => Writable_Actuals_List);
2669 end if;
2671 -- Second occurrence of an elementary type writable actual
2673 elsif Contains (Writable_Actuals_List, N) then
2675 -- Report the error on the second occurrence of the
2676 -- identifier. We cannot assume that N is the second
2677 -- occurrence (according to their location in the
2678 -- sources), since Traverse_Func walks through Field2
2679 -- last (see comment in the body of Traverse_Func).
2681 declare
2682 Elmt : Elmt_Id;
2684 begin
2685 Elmt := First_Elmt (Writable_Actuals_List);
2686 while Present (Elmt)
2687 and then Entity (Node (Elmt)) /= Entity (N)
2688 loop
2689 Next_Elmt (Elmt);
2690 end loop;
2692 if Sloc (N) > Sloc (Node (Elmt)) then
2693 Error_Node := N;
2694 else
2695 Error_Node := Node (Elmt);
2696 end if;
2698 Error_Msg_NE
2699 ("value may be affected by call to & "
2700 & "because order of evaluation is arbitrary",
2701 Error_Node, Id);
2702 return Abandon;
2703 end;
2705 -- First occurrence of a elementary type writable actual
2707 else
2708 Append_New_Elmt (N, To => Writable_Actuals_List);
2709 end if;
2711 else
2712 if No (Identifiers_List) then
2713 Identifiers_List := New_Elmt_List;
2714 end if;
2716 Append_Unique_Elmt (N, Identifiers_List);
2717 end if;
2718 end if;
2720 return OK;
2721 end Check_Node;
2723 --------------
2724 -- Contains --
2725 --------------
2727 function Contains
2728 (List : Elist_Id;
2729 N : Node_Id) return Boolean
2731 pragma Assert (Nkind (N) in N_Has_Entity);
2733 Elmt : Elmt_Id;
2735 begin
2736 if No (List) then
2737 return False;
2738 end if;
2740 Elmt := First_Elmt (List);
2741 while Present (Elmt) loop
2742 if Entity (Node (Elmt)) = Entity (N) then
2743 return True;
2744 else
2745 Next_Elmt (Elmt);
2746 end if;
2747 end loop;
2749 return False;
2750 end Contains;
2752 ------------------
2753 -- Do_Traversal --
2754 ------------------
2756 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2757 -- The traversal procedure
2759 -- Start of processing for Collect_Identifiers
2761 begin
2762 if Present (Error_Node) then
2763 return;
2764 end if;
2766 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2767 return;
2768 end if;
2770 Do_Traversal (N);
2771 end Collect_Identifiers;
2773 -- Start of processing for Check_Function_Writable_Actuals
2775 begin
2776 -- The check only applies to Ada 2012 code on which Check_Actuals has
2777 -- been set, and only to constructs that have multiple constituents
2778 -- whose order of evaluation is not specified by the language.
2780 if Ada_Version < Ada_2012
2781 or else not Check_Actuals (N)
2782 or else Nkind (N) not in N_Op
2783 | N_Membership_Test
2784 | N_Range
2785 | N_Aggregate
2786 | N_Extension_Aggregate
2787 | N_Full_Type_Declaration
2788 | N_Function_Call
2789 | N_Procedure_Call_Statement
2790 | N_Entry_Call_Statement
2791 or else (Nkind (N) = N_Full_Type_Declaration
2792 and then not Is_Record_Type (Defining_Identifier (N)))
2794 -- In addition, this check only applies to source code, not to code
2795 -- generated by constraint checks.
2797 or else not Comes_From_Source (N)
2798 then
2799 return;
2800 end if;
2802 -- If a construct C has two or more direct constituents that are names
2803 -- or expressions whose evaluation may occur in an arbitrary order, at
2804 -- least one of which contains a function call with an in out or out
2805 -- parameter, then the construct is legal only if: for each name N that
2806 -- is passed as a parameter of mode in out or out to some inner function
2807 -- call C2 (not including the construct C itself), there is no other
2808 -- name anywhere within a direct constituent of the construct C other
2809 -- than the one containing C2, that is known to refer to the same
2810 -- object (RM 6.4.1(6.17/3)).
2812 case Nkind (N) is
2813 when N_Range =>
2814 Collect_Identifiers (Low_Bound (N));
2815 Collect_Identifiers (High_Bound (N));
2817 when N_Membership_Test
2818 | N_Op
2820 declare
2821 Expr : Node_Id;
2823 begin
2824 Collect_Identifiers (Left_Opnd (N));
2826 if Present (Right_Opnd (N)) then
2827 Collect_Identifiers (Right_Opnd (N));
2828 end if;
2830 if Nkind (N) in N_Membership_Test then
2831 Expr := First (Alternatives (N));
2832 while Present (Expr) loop
2833 Collect_Identifiers (Expr);
2835 Next (Expr);
2836 end loop;
2837 end if;
2838 end;
2840 when N_Full_Type_Declaration =>
2841 declare
2842 function Get_Record_Part (N : Node_Id) return Node_Id;
2843 -- Return the record part of this record type definition
2845 ---------------------
2846 -- Get_Record_Part --
2847 ---------------------
2849 function Get_Record_Part (N : Node_Id) return Node_Id is
2850 Type_Def : constant Node_Id := Type_Definition (N);
2851 begin
2852 if Nkind (Type_Def) = N_Derived_Type_Definition then
2853 return Record_Extension_Part (Type_Def);
2854 else
2855 return Type_Def;
2856 end if;
2857 end Get_Record_Part;
2859 Comp : Node_Id;
2860 Def_Id : Entity_Id := Defining_Identifier (N);
2861 Rec : Node_Id := Get_Record_Part (N);
2863 begin
2864 -- No need to perform any analysis if the record has no
2865 -- components
2867 if No (Rec) or else No (Component_List (Rec)) then
2868 return;
2869 end if;
2871 -- Collect the identifiers starting from the deepest
2872 -- derivation. Done to report the error in the deepest
2873 -- derivation.
2875 loop
2876 if Present (Component_List (Rec)) then
2877 Comp := First (Component_Items (Component_List (Rec)));
2878 while Present (Comp) loop
2879 if Nkind (Comp) = N_Component_Declaration
2880 and then Present (Expression (Comp))
2881 then
2882 Collect_Identifiers (Expression (Comp));
2883 end if;
2885 Next (Comp);
2886 end loop;
2887 end if;
2889 exit when No (Underlying_Type (Etype (Def_Id)))
2890 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2891 = Def_Id;
2893 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2894 Rec := Get_Record_Part (Parent (Def_Id));
2895 end loop;
2896 end;
2898 when N_Entry_Call_Statement
2899 | N_Subprogram_Call
2901 declare
2902 Id : constant Entity_Id := Get_Called_Entity (N);
2903 Formal : Node_Id;
2904 Actual : Node_Id;
2906 begin
2907 Formal := First_Formal (Id);
2908 Actual := First_Actual (N);
2909 while Present (Actual) and then Present (Formal) loop
2910 if Ekind (Formal) in E_Out_Parameter | E_In_Out_Parameter
2911 then
2912 Collect_Identifiers (Actual);
2913 end if;
2915 Next_Formal (Formal);
2916 Next_Actual (Actual);
2917 end loop;
2918 end;
2920 when N_Aggregate
2921 | N_Extension_Aggregate
2923 declare
2924 Assoc : Node_Id;
2925 Choice : Node_Id;
2926 Comp_Expr : Node_Id;
2928 begin
2929 -- Handle the N_Others_Choice of array aggregates with static
2930 -- bounds. There is no need to perform this analysis in
2931 -- aggregates without static bounds since we cannot evaluate
2932 -- if the N_Others_Choice covers several elements. There is
2933 -- no need to handle the N_Others choice of record aggregates
2934 -- since at this stage it has been already expanded by
2935 -- Resolve_Record_Aggregate.
2937 if Is_Array_Type (Etype (N))
2938 and then Nkind (N) = N_Aggregate
2939 and then Present (Aggregate_Bounds (N))
2940 and then Compile_Time_Known_Bounds (Etype (N))
2941 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2943 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2944 then
2945 declare
2946 Count_Components : Uint := Uint_0;
2947 Num_Components : Uint;
2948 Others_Assoc : Node_Id := Empty;
2949 Others_Choice : Node_Id := Empty;
2950 Others_Box_Present : Boolean := False;
2952 begin
2953 -- Count positional associations
2955 if Present (Expressions (N)) then
2956 Comp_Expr := First (Expressions (N));
2957 while Present (Comp_Expr) loop
2958 Count_Components := Count_Components + 1;
2959 Next (Comp_Expr);
2960 end loop;
2961 end if;
2963 -- Count the rest of elements and locate the N_Others
2964 -- choice (if any)
2966 Assoc := First (Component_Associations (N));
2967 while Present (Assoc) loop
2968 Choice := First (Choices (Assoc));
2969 while Present (Choice) loop
2970 if Nkind (Choice) = N_Others_Choice then
2971 Others_Assoc := Assoc;
2972 Others_Choice := Choice;
2973 Others_Box_Present := Box_Present (Assoc);
2975 -- Count several components
2977 elsif Nkind (Choice) in
2978 N_Range | N_Subtype_Indication
2979 or else (Is_Entity_Name (Choice)
2980 and then Is_Type (Entity (Choice)))
2981 then
2982 declare
2983 L, H : Node_Id;
2984 begin
2985 Get_Index_Bounds (Choice, L, H);
2986 pragma Assert
2987 (Compile_Time_Known_Value (L)
2988 and then Compile_Time_Known_Value (H));
2989 Count_Components :=
2990 Count_Components
2991 + Expr_Value (H) - Expr_Value (L) + 1;
2992 end;
2994 -- Count single component. No other case available
2995 -- since we are handling an aggregate with static
2996 -- bounds.
2998 else
2999 pragma Assert (Is_OK_Static_Expression (Choice)
3000 or else Nkind (Choice) = N_Identifier
3001 or else Nkind (Choice) = N_Integer_Literal);
3003 Count_Components := Count_Components + 1;
3004 end if;
3006 Next (Choice);
3007 end loop;
3009 Next (Assoc);
3010 end loop;
3012 Num_Components :=
3013 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
3014 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
3016 pragma Assert (Count_Components <= Num_Components);
3018 -- Handle the N_Others choice if it covers several
3019 -- components
3021 if Present (Others_Choice)
3022 and then (Num_Components - Count_Components) > 1
3023 then
3024 if not Others_Box_Present then
3026 -- At this stage, if expansion is active, the
3027 -- expression of the others choice has not been
3028 -- analyzed. Hence we generate a duplicate and
3029 -- we analyze it silently to have available the
3030 -- minimum decoration required to collect the
3031 -- identifiers.
3033 pragma Assert (Present (Others_Assoc));
3035 if not Expander_Active then
3036 Comp_Expr := Expression (Others_Assoc);
3037 else
3038 Comp_Expr :=
3039 New_Copy_Tree (Expression (Others_Assoc));
3040 Preanalyze_Without_Errors (Comp_Expr);
3041 end if;
3043 Collect_Identifiers (Comp_Expr);
3045 if Present (Writable_Actuals_List) then
3047 -- As suggested by Robert, at current stage we
3048 -- report occurrences of this case as warnings.
3050 Error_Msg_N
3051 ("writable function parameter may affect "
3052 & "value in other component because order "
3053 & "of evaluation is unspecified??",
3054 Node (First_Elmt (Writable_Actuals_List)));
3055 end if;
3056 end if;
3057 end if;
3058 end;
3060 -- For an array aggregate, a discrete_choice_list that has
3061 -- a nonstatic range is considered as two or more separate
3062 -- occurrences of the expression (RM 6.4.1(20/3)).
3064 elsif Is_Array_Type (Etype (N))
3065 and then Nkind (N) = N_Aggregate
3066 and then Present (Aggregate_Bounds (N))
3067 and then not Compile_Time_Known_Bounds (Etype (N))
3068 then
3069 -- Collect identifiers found in the dynamic bounds
3071 declare
3072 Count_Components : Natural := 0;
3073 Low, High : Node_Id;
3075 begin
3076 Assoc := First (Component_Associations (N));
3077 while Present (Assoc) loop
3078 Choice := First (Choices (Assoc));
3079 while Present (Choice) loop
3080 if Nkind (Choice) in
3081 N_Range | N_Subtype_Indication
3082 or else (Is_Entity_Name (Choice)
3083 and then Is_Type (Entity (Choice)))
3084 then
3085 Get_Index_Bounds (Choice, Low, High);
3087 if not Compile_Time_Known_Value (Low) then
3088 Collect_Identifiers (Low);
3090 if No (Aggr_Error_Node) then
3091 Aggr_Error_Node := Low;
3092 end if;
3093 end if;
3095 if not Compile_Time_Known_Value (High) then
3096 Collect_Identifiers (High);
3098 if No (Aggr_Error_Node) then
3099 Aggr_Error_Node := High;
3100 end if;
3101 end if;
3103 -- The RM rule is violated if there is more than
3104 -- a single choice in a component association.
3106 else
3107 Count_Components := Count_Components + 1;
3109 if No (Aggr_Error_Node)
3110 and then Count_Components > 1
3111 then
3112 Aggr_Error_Node := Choice;
3113 end if;
3115 if not Compile_Time_Known_Value (Choice) then
3116 Collect_Identifiers (Choice);
3117 end if;
3118 end if;
3120 Next (Choice);
3121 end loop;
3123 Next (Assoc);
3124 end loop;
3125 end;
3126 end if;
3128 -- Handle ancestor part of extension aggregates
3130 if Nkind (N) = N_Extension_Aggregate then
3131 Collect_Identifiers (Ancestor_Part (N));
3132 end if;
3134 -- Handle positional associations
3136 if Present (Expressions (N)) then
3137 Comp_Expr := First (Expressions (N));
3138 while Present (Comp_Expr) loop
3139 if not Is_OK_Static_Expression (Comp_Expr) then
3140 Collect_Identifiers (Comp_Expr);
3141 end if;
3143 Next (Comp_Expr);
3144 end loop;
3145 end if;
3147 -- Handle discrete associations
3149 if Present (Component_Associations (N)) then
3150 Assoc := First (Component_Associations (N));
3151 while Present (Assoc) loop
3153 if not Box_Present (Assoc) then
3154 Choice := First (Choices (Assoc));
3155 while Present (Choice) loop
3157 -- For now we skip discriminants since it requires
3158 -- performing the analysis in two phases: first one
3159 -- analyzing discriminants and second one analyzing
3160 -- the rest of components since discriminants are
3161 -- evaluated prior to components: too much extra
3162 -- work to detect a corner case???
3164 if Nkind (Choice) in N_Has_Entity
3165 and then Present (Entity (Choice))
3166 and then Ekind (Entity (Choice)) = E_Discriminant
3167 then
3168 null;
3170 elsif Box_Present (Assoc) then
3171 null;
3173 else
3174 if not Analyzed (Expression (Assoc)) then
3175 Comp_Expr :=
3176 New_Copy_Tree (Expression (Assoc));
3177 Set_Parent (Comp_Expr, Parent (N));
3178 Preanalyze_Without_Errors (Comp_Expr);
3179 else
3180 Comp_Expr := Expression (Assoc);
3181 end if;
3183 Collect_Identifiers (Comp_Expr);
3184 end if;
3186 Next (Choice);
3187 end loop;
3188 end if;
3190 Next (Assoc);
3191 end loop;
3192 end if;
3193 end;
3195 when others =>
3196 return;
3197 end case;
3199 -- No further action needed if we already reported an error
3201 if Present (Error_Node) then
3202 return;
3203 end if;
3205 -- Check violation of RM 6.20/3 in aggregates
3207 if Present (Aggr_Error_Node)
3208 and then Present (Writable_Actuals_List)
3209 then
3210 Error_Msg_N
3211 ("value may be affected by call in other component because they "
3212 & "are evaluated in unspecified order",
3213 Node (First_Elmt (Writable_Actuals_List)));
3214 return;
3215 end if;
3217 -- Check if some writable argument of a function is referenced
3219 if Present (Writable_Actuals_List)
3220 and then Present (Identifiers_List)
3221 then
3222 declare
3223 Elmt_1 : Elmt_Id;
3224 Elmt_2 : Elmt_Id;
3226 begin
3227 Elmt_1 := First_Elmt (Writable_Actuals_List);
3228 while Present (Elmt_1) loop
3229 Elmt_2 := First_Elmt (Identifiers_List);
3230 while Present (Elmt_2) loop
3231 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
3232 case Nkind (Parent (Node (Elmt_2))) is
3233 when N_Aggregate
3234 | N_Component_Association
3235 | N_Component_Declaration
3237 Error_Msg_N
3238 ("value may be affected by call in other "
3239 & "component because they are evaluated "
3240 & "in unspecified order",
3241 Node (Elmt_2));
3243 when N_Membership_Test =>
3244 Error_Msg_N
3245 ("value may be affected by call in other "
3246 & "alternative because they are evaluated "
3247 & "in unspecified order",
3248 Node (Elmt_2));
3250 when others =>
3251 Error_Msg_N
3252 ("value of actual may be affected by call in "
3253 & "other actual because they are evaluated "
3254 & "in unspecified order",
3255 Node (Elmt_2));
3256 end case;
3257 end if;
3259 Next_Elmt (Elmt_2);
3260 end loop;
3262 Next_Elmt (Elmt_1);
3263 end loop;
3264 end;
3265 end if;
3266 end Check_Function_Writable_Actuals;
3268 --------------------------------
3269 -- Check_Implicit_Dereference --
3270 --------------------------------
3272 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
3273 Disc : Entity_Id;
3274 Desig : Entity_Id;
3275 Nam : Node_Id;
3277 begin
3278 if Nkind (N) = N_Indexed_Component
3279 and then Present (Generalized_Indexing (N))
3280 then
3281 Nam := Generalized_Indexing (N);
3282 else
3283 Nam := N;
3284 end if;
3286 if Ada_Version < Ada_2012
3287 or else not Has_Implicit_Dereference (Base_Type (Typ))
3288 then
3289 return;
3291 elsif not Comes_From_Source (N)
3292 and then Nkind (N) /= N_Indexed_Component
3293 then
3294 return;
3296 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
3297 null;
3299 else
3300 Disc := First_Discriminant (Typ);
3301 while Present (Disc) loop
3302 if Has_Implicit_Dereference (Disc) then
3303 Desig := Designated_Type (Etype (Disc));
3304 Add_One_Interp (Nam, Disc, Desig);
3306 -- If the node is a generalized indexing, add interpretation
3307 -- to that node as well, for subsequent resolution.
3309 if Nkind (N) = N_Indexed_Component then
3310 Add_One_Interp (N, Disc, Desig);
3311 end if;
3313 -- If the operation comes from a generic unit and the context
3314 -- is a selected component, the selector name may be global
3315 -- and set in the instance already. Remove the entity to
3316 -- force resolution of the selected component, and the
3317 -- generation of an explicit dereference if needed.
3319 if In_Instance
3320 and then Nkind (Parent (Nam)) = N_Selected_Component
3321 then
3322 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3323 end if;
3325 exit;
3326 end if;
3328 Next_Discriminant (Disc);
3329 end loop;
3330 end if;
3331 end Check_Implicit_Dereference;
3333 ----------------------------------
3334 -- Check_Internal_Protected_Use --
3335 ----------------------------------
3337 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3338 S : Entity_Id;
3339 Prot : Entity_Id;
3341 begin
3342 Prot := Empty;
3344 S := Current_Scope;
3345 while Present (S) loop
3346 if S = Standard_Standard then
3347 exit;
3349 elsif Ekind (S) = E_Function
3350 and then Ekind (Scope (S)) = E_Protected_Type
3351 then
3352 Prot := Scope (S);
3353 exit;
3354 end if;
3356 S := Scope (S);
3357 end loop;
3359 if Present (Prot)
3360 and then Scope (Nam) = Prot
3361 and then Ekind (Nam) /= E_Function
3362 then
3363 -- An indirect function call (e.g. a callback within a protected
3364 -- function body) is not statically illegal. If the access type is
3365 -- anonymous and is the type of an access parameter, the scope of Nam
3366 -- will be the protected type, but it is not a protected operation.
3368 if Ekind (Nam) = E_Subprogram_Type
3369 and then Nkind (Associated_Node_For_Itype (Nam)) =
3370 N_Function_Specification
3371 then
3372 null;
3374 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3375 Error_Msg_N
3376 ("within protected function cannot use protected procedure in "
3377 & "renaming or as generic actual", N);
3379 elsif Nkind (N) = N_Attribute_Reference then
3380 Error_Msg_N
3381 ("within protected function cannot take access of protected "
3382 & "procedure", N);
3384 else
3385 Error_Msg_N
3386 ("within protected function, protected object is constant", N);
3387 Error_Msg_N
3388 ("\cannot call operation that may modify it", N);
3389 end if;
3390 end if;
3392 -- Verify that an internal call does not appear within a precondition
3393 -- of a protected operation. This implements AI12-0166.
3394 -- The precondition aspect has been rewritten as a pragma Precondition
3395 -- and we check whether the scope of the called subprogram is the same
3396 -- as that of the entity to which the aspect applies.
3398 if Convention (Nam) = Convention_Protected then
3399 declare
3400 P : Node_Id;
3402 begin
3403 P := Parent (N);
3404 while Present (P) loop
3405 if Nkind (P) = N_Pragma
3406 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3407 and then From_Aspect_Specification (P)
3408 and then
3409 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3410 then
3411 Error_Msg_N
3412 ("internal call cannot appear in precondition of "
3413 & "protected operation", N);
3414 return;
3416 elsif Nkind (P) = N_Pragma
3417 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3418 then
3419 -- Check whether call is in a case guard. It is legal in a
3420 -- consequence.
3422 P := N;
3423 while Present (P) loop
3424 if Nkind (Parent (P)) = N_Component_Association
3425 and then P /= Expression (Parent (P))
3426 then
3427 Error_Msg_N
3428 ("internal call cannot appear in case guard in a "
3429 & "contract case", N);
3430 end if;
3432 P := Parent (P);
3433 end loop;
3435 return;
3437 elsif Nkind (P) = N_Parameter_Specification
3438 and then Scope (Current_Scope) = Scope (Nam)
3439 and then Nkind (Parent (P)) in
3440 N_Entry_Declaration | N_Subprogram_Declaration
3441 then
3442 Error_Msg_N
3443 ("internal call cannot appear in default for formal of "
3444 & "protected operation", N);
3445 return;
3447 -- Prevent the search from going too far
3449 elsif Is_Body_Or_Package_Declaration (P) then
3450 exit;
3451 end if;
3453 P := Parent (P);
3454 end loop;
3455 end;
3456 end if;
3457 end Check_Internal_Protected_Use;
3459 ---------------------------------------
3460 -- Check_Later_Vs_Basic_Declarations --
3461 ---------------------------------------
3463 procedure Check_Later_Vs_Basic_Declarations
3464 (Decls : List_Id;
3465 During_Parsing : Boolean)
3467 Body_Sloc : Source_Ptr;
3468 Decl : Node_Id;
3470 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3471 -- Return whether Decl is considered as a declarative item.
3472 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3473 -- When During_Parsing is False, the semantics of SPARK is followed.
3475 -------------------------------
3476 -- Is_Later_Declarative_Item --
3477 -------------------------------
3479 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3480 begin
3481 if Nkind (Decl) in N_Later_Decl_Item then
3482 return True;
3484 elsif Nkind (Decl) = N_Pragma then
3485 return True;
3487 elsif During_Parsing then
3488 return False;
3490 -- In SPARK, a package declaration is not considered as a later
3491 -- declarative item.
3493 elsif Nkind (Decl) = N_Package_Declaration then
3494 return False;
3496 -- In SPARK, a renaming is considered as a later declarative item
3498 elsif Nkind (Decl) in N_Renaming_Declaration then
3499 return True;
3501 else
3502 return False;
3503 end if;
3504 end Is_Later_Declarative_Item;
3506 -- Start of processing for Check_Later_Vs_Basic_Declarations
3508 begin
3509 Decl := First (Decls);
3511 -- Loop through sequence of basic declarative items
3513 Outer : while Present (Decl) loop
3514 if Nkind (Decl) not in
3515 N_Subprogram_Body | N_Package_Body | N_Task_Body
3516 and then Nkind (Decl) not in N_Body_Stub
3517 then
3518 Next (Decl);
3520 -- Once a body is encountered, we only allow later declarative
3521 -- items. The inner loop checks the rest of the list.
3523 else
3524 Body_Sloc := Sloc (Decl);
3526 Inner : while Present (Decl) loop
3527 if not Is_Later_Declarative_Item (Decl) then
3528 if During_Parsing then
3529 if Ada_Version = Ada_83 then
3530 Error_Msg_Sloc := Body_Sloc;
3531 Error_Msg_N
3532 ("(Ada 83) decl cannot appear after body#", Decl);
3533 end if;
3534 end if;
3535 end if;
3537 Next (Decl);
3538 end loop Inner;
3539 end if;
3540 end loop Outer;
3541 end Check_Later_Vs_Basic_Declarations;
3543 ---------------------------
3544 -- Check_No_Hidden_State --
3545 ---------------------------
3547 procedure Check_No_Hidden_State (Id : Entity_Id) is
3548 Context : Entity_Id := Empty;
3549 Not_Visible : Boolean := False;
3550 Scop : Entity_Id;
3552 begin
3553 pragma Assert (Ekind (Id) in E_Abstract_State | E_Variable);
3555 -- Nothing to do for internally-generated abstract states and variables
3556 -- because they do not represent the hidden state of the source unit.
3558 if not Comes_From_Source (Id) then
3559 return;
3560 end if;
3562 -- Find the proper context where the object or state appears
3564 Scop := Scope (Id);
3565 while Present (Scop) loop
3566 Context := Scop;
3568 -- Keep track of the context's visibility
3570 Not_Visible := Not_Visible or else In_Private_Part (Context);
3572 -- Prevent the search from going too far
3574 if Context = Standard_Standard then
3575 return;
3577 -- Objects and states that appear immediately within a subprogram or
3578 -- entry inside a construct nested within a subprogram do not
3579 -- introduce a hidden state. They behave as local variable
3580 -- declarations. The same is true for elaboration code inside a block
3581 -- or a task.
3583 elsif Is_Subprogram_Or_Entry (Context)
3584 or else Ekind (Context) in E_Block | E_Task_Type
3585 then
3586 return;
3587 end if;
3589 -- Stop the traversal when a package subject to a null abstract state
3590 -- has been found.
3592 if Is_Package_Or_Generic_Package (Context)
3593 and then Has_Null_Abstract_State (Context)
3594 then
3595 exit;
3596 end if;
3598 Scop := Scope (Scop);
3599 end loop;
3601 -- At this point we know that there is at least one package with a null
3602 -- abstract state in visibility. Emit an error message unconditionally
3603 -- if the entity being processed is a state because the placement of the
3604 -- related package is irrelevant. This is not the case for objects as
3605 -- the intermediate context matters.
3607 if Present (Context)
3608 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3609 then
3610 Error_Msg_N ("cannot introduce hidden state &", Id);
3611 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3612 end if;
3613 end Check_No_Hidden_State;
3615 ---------------------------------------------
3616 -- Check_Nonoverridable_Aspect_Consistency --
3617 ---------------------------------------------
3619 procedure Check_Inherited_Nonoverridable_Aspects
3620 (Inheritor : Entity_Id;
3621 Interface_List : List_Id;
3622 Parent_Type : Entity_Id) is
3624 -- array needed for iterating over subtype values
3625 Nonoverridable_Aspects : constant array (Positive range <>) of
3626 Nonoverridable_Aspect_Id :=
3627 (Aspect_Default_Iterator,
3628 Aspect_Iterator_Element,
3629 Aspect_Implicit_Dereference,
3630 Aspect_Constant_Indexing,
3631 Aspect_Variable_Indexing,
3632 Aspect_Aggregate,
3633 Aspect_Max_Entry_Queue_Length
3634 -- , Aspect_No_Controlled_Parts
3637 -- Note that none of these 8 aspects can be specified (for a type)
3638 -- via a pragma. For 7 of them, the corresponding pragma does not
3639 -- exist. The Pragma_Id enumeration type does include
3640 -- Pragma_Max_Entry_Queue_Length, but that pragma is only use to
3641 -- specify the aspect for a protected entry or entry family, not for
3642 -- a type, and therefore cannot introduce the sorts of inheritance
3643 -- issues that we are concerned with in this procedure.
3645 type Entity_Array is array (Nat range <>) of Entity_Id;
3647 function Ancestor_Entities return Entity_Array;
3648 -- Returns all progenitors (including parent type, if present)
3650 procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3651 (Aspect : Nonoverridable_Aspect_Id;
3652 Ancestor_1 : Entity_Id;
3653 Aspect_Spec_1 : Node_Id;
3654 Ancestor_2 : Entity_Id;
3655 Aspect_Spec_2 : Node_Id);
3656 -- A given aspect has been specified for each of two ancestors;
3657 -- check that the two aspect specifications are compatible (see
3658 -- RM 13.1.1(18.5) and AI12-0211).
3660 -----------------------
3661 -- Ancestor_Entities --
3662 -----------------------
3664 function Ancestor_Entities return Entity_Array is
3665 Ifc_Count : constant Nat := List_Length (Interface_List);
3666 Ifc_Ancestors : Entity_Array (1 .. Ifc_Count);
3667 Ifc : Node_Id := First (Interface_List);
3668 begin
3669 for Idx in Ifc_Ancestors'Range loop
3670 Ifc_Ancestors (Idx) := Entity (Ifc);
3671 pragma Assert (Present (Ifc_Ancestors (Idx)));
3672 Ifc := Next (Ifc);
3673 end loop;
3674 pragma Assert (No (Ifc));
3675 if Present (Parent_Type) then
3676 return Parent_Type & Ifc_Ancestors;
3677 else
3678 return Ifc_Ancestors;
3679 end if;
3680 end Ancestor_Entities;
3682 -------------------------------------------------------
3683 -- Check_Consistency_For_One_Aspect_Of_Two_Ancestors --
3684 -------------------------------------------------------
3686 procedure Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3687 (Aspect : Nonoverridable_Aspect_Id;
3688 Ancestor_1 : Entity_Id;
3689 Aspect_Spec_1 : Node_Id;
3690 Ancestor_2 : Entity_Id;
3691 Aspect_Spec_2 : Node_Id) is
3692 begin
3693 if not Is_Confirming (Aspect, Aspect_Spec_1, Aspect_Spec_2) then
3694 Error_Msg_Name_1 := Aspect_Names (Aspect);
3695 Error_Msg_Name_2 := Chars (Ancestor_1);
3696 Error_Msg_Name_3 := Chars (Ancestor_2);
3698 Error_Msg (
3699 "incompatible % aspects inherited from ancestors % and %",
3700 Sloc (Inheritor));
3701 end if;
3702 end Check_Consistency_For_One_Aspect_Of_Two_Ancestors;
3704 Ancestors : constant Entity_Array := Ancestor_Entities;
3706 -- start of processing for Check_Inherited_Nonoverridable_Aspects
3707 begin
3708 -- No Ada_Version check here; AI12-0211 is a binding interpretation.
3710 if Ancestors'Length < 2 then
3711 return; -- Inconsistency impossible; it takes 2 to disagree.
3712 elsif In_Instance_Body then
3713 return; -- No legality checking in an instance body.
3714 end if;
3716 for Aspect of Nonoverridable_Aspects loop
3717 declare
3718 First_Ancestor_With_Aspect : Entity_Id := Empty;
3719 First_Aspect_Spec, Current_Aspect_Spec : Node_Id := Empty;
3720 begin
3721 for Ancestor of Ancestors loop
3722 Current_Aspect_Spec := Find_Aspect (Ancestor, Aspect);
3723 if Present (Current_Aspect_Spec) then
3724 if Present (First_Ancestor_With_Aspect) then
3725 Check_Consistency_For_One_Aspect_Of_Two_Ancestors
3726 (Aspect => Aspect,
3727 Ancestor_1 => First_Ancestor_With_Aspect,
3728 Aspect_Spec_1 => First_Aspect_Spec,
3729 Ancestor_2 => Ancestor,
3730 Aspect_Spec_2 => Current_Aspect_Spec);
3731 else
3732 First_Ancestor_With_Aspect := Ancestor;
3733 First_Aspect_Spec := Current_Aspect_Spec;
3734 end if;
3735 end if;
3736 end loop;
3737 end;
3738 end loop;
3739 end Check_Inherited_Nonoverridable_Aspects;
3741 -------------------
3742 -- Check_Parents --
3743 -------------------
3745 function Check_Parents (N : Node_Id; List : Elist_Id) return Boolean is
3747 function Check_Node
3748 (Parent_Node : Node_Id;
3749 N : Node_Id) return Traverse_Result;
3750 -- Process a single node.
3752 ----------------
3753 -- Check_Node --
3754 ----------------
3756 function Check_Node
3757 (Parent_Node : Node_Id;
3758 N : Node_Id) return Traverse_Result is
3759 begin
3760 if Nkind (N) = N_Identifier
3761 and then Parent (N) /= Parent_Node
3762 and then Present (Entity (N))
3763 and then Contains (List, Entity (N))
3764 then
3765 return Abandon;
3766 end if;
3768 return OK;
3769 end Check_Node;
3771 function Traverse is new Traverse_Func_With_Parent (Check_Node);
3773 -- Start of processing for Check_Parents
3775 begin
3776 return Traverse (N) = OK;
3777 end Check_Parents;
3779 -----------------------------
3780 -- Check_Part_Of_Reference --
3781 -----------------------------
3783 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3784 function Is_Enclosing_Package_Body
3785 (Body_Decl : Node_Id;
3786 Obj_Id : Entity_Id) return Boolean;
3787 pragma Inline (Is_Enclosing_Package_Body);
3788 -- Determine whether package body Body_Decl or its corresponding spec
3789 -- immediately encloses the declaration of object Obj_Id.
3791 function Is_Internal_Declaration_Or_Body
3792 (Decl : Node_Id) return Boolean;
3793 pragma Inline (Is_Internal_Declaration_Or_Body);
3794 -- Determine whether declaration or body denoted by Decl is internal
3796 function Is_Single_Declaration_Or_Body
3797 (Decl : Node_Id;
3798 Conc_Typ : Entity_Id) return Boolean;
3799 pragma Inline (Is_Single_Declaration_Or_Body);
3800 -- Determine whether protected/task declaration or body denoted by Decl
3801 -- belongs to single concurrent type Conc_Typ.
3803 function Is_Single_Task_Pragma
3804 (Prag : Node_Id;
3805 Task_Typ : Entity_Id) return Boolean;
3806 pragma Inline (Is_Single_Task_Pragma);
3807 -- Determine whether pragma Prag belongs to single task type Task_Typ
3809 -------------------------------
3810 -- Is_Enclosing_Package_Body --
3811 -------------------------------
3813 function Is_Enclosing_Package_Body
3814 (Body_Decl : Node_Id;
3815 Obj_Id : Entity_Id) return Boolean
3817 Obj_Context : Node_Id;
3819 begin
3820 -- Find the context of the object declaration
3822 Obj_Context := Parent (Declaration_Node (Obj_Id));
3824 if Nkind (Obj_Context) = N_Package_Specification then
3825 Obj_Context := Parent (Obj_Context);
3826 end if;
3828 -- The object appears immediately within the package body
3830 if Obj_Context = Body_Decl then
3831 return True;
3833 -- The object appears immediately within the corresponding spec
3835 elsif Nkind (Obj_Context) = N_Package_Declaration
3836 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3837 Obj_Context
3838 then
3839 return True;
3840 end if;
3842 return False;
3843 end Is_Enclosing_Package_Body;
3845 -------------------------------------
3846 -- Is_Internal_Declaration_Or_Body --
3847 -------------------------------------
3849 function Is_Internal_Declaration_Or_Body
3850 (Decl : Node_Id) return Boolean
3852 begin
3853 if Comes_From_Source (Decl) then
3854 return False;
3856 -- A body generated for an expression function which has not been
3857 -- inserted into the tree yet (In_Spec_Expression is True) is not
3858 -- considered internal.
3860 elsif Nkind (Decl) = N_Subprogram_Body
3861 and then Was_Expression_Function (Decl)
3862 and then not In_Spec_Expression
3863 then
3864 return False;
3865 end if;
3867 return True;
3868 end Is_Internal_Declaration_Or_Body;
3870 -----------------------------------
3871 -- Is_Single_Declaration_Or_Body --
3872 -----------------------------------
3874 function Is_Single_Declaration_Or_Body
3875 (Decl : Node_Id;
3876 Conc_Typ : Entity_Id) return Boolean
3878 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3880 begin
3881 return
3882 Present (Anonymous_Object (Spec_Id))
3883 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3884 end Is_Single_Declaration_Or_Body;
3886 ---------------------------
3887 -- Is_Single_Task_Pragma --
3888 ---------------------------
3890 function Is_Single_Task_Pragma
3891 (Prag : Node_Id;
3892 Task_Typ : Entity_Id) return Boolean
3894 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3896 begin
3897 -- To qualify, the pragma must be associated with single task type
3898 -- Task_Typ.
3900 return
3901 Is_Single_Task_Object (Task_Typ)
3902 and then Nkind (Decl) = N_Object_Declaration
3903 and then Defining_Entity (Decl) = Task_Typ;
3904 end Is_Single_Task_Pragma;
3906 -- Local variables
3908 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3909 Par : Node_Id;
3910 Prag_Nam : Name_Id;
3911 Prev : Node_Id;
3913 -- Start of processing for Check_Part_Of_Reference
3915 begin
3916 -- Nothing to do when the variable was recorded, but did not become a
3917 -- constituent of a single concurrent type.
3919 if No (Conc_Obj) then
3920 return;
3921 end if;
3923 -- Traverse the parent chain looking for a suitable context for the
3924 -- reference to the concurrent constituent.
3926 Prev := Ref;
3927 Par := Parent (Prev);
3928 while Present (Par) loop
3929 if Nkind (Par) = N_Pragma then
3930 Prag_Nam := Pragma_Name (Par);
3932 -- A concurrent constituent is allowed to appear in pragmas
3933 -- Initial_Condition and Initializes as this is part of the
3934 -- elaboration checks for the constituent (SPARK RM 9(3)).
3936 if Prag_Nam in Name_Initial_Condition | Name_Initializes then
3937 return;
3939 -- When the reference appears within pragma Depends or Global,
3940 -- check whether the pragma applies to a single task type. Note
3941 -- that the pragma may not encapsulated by the type definition,
3942 -- but this is still a valid context.
3944 elsif Prag_Nam in Name_Depends | Name_Global
3945 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3946 then
3947 return;
3948 end if;
3950 -- The reference appears somewhere in the definition of a single
3951 -- concurrent type (SPARK RM 9(3)).
3953 elsif Nkind (Par) in
3954 N_Single_Protected_Declaration | N_Single_Task_Declaration
3955 and then Defining_Entity (Par) = Conc_Obj
3956 then
3957 return;
3959 -- The reference appears within the declaration or body of a single
3960 -- concurrent type (SPARK RM 9(3)).
3962 elsif Nkind (Par) in N_Protected_Body
3963 | N_Protected_Type_Declaration
3964 | N_Task_Body
3965 | N_Task_Type_Declaration
3966 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3967 then
3968 return;
3970 -- The reference appears within the statement list of the object's
3971 -- immediately enclosing package (SPARK RM 9(3)).
3973 elsif Nkind (Par) = N_Package_Body
3974 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3975 and then Is_Enclosing_Package_Body (Par, Var_Id)
3976 then
3977 return;
3979 -- The reference has been relocated within an internally generated
3980 -- package or subprogram. Assume that the reference is legal as the
3981 -- real check was already performed in the original context of the
3982 -- reference.
3984 elsif Nkind (Par) in N_Package_Body
3985 | N_Package_Declaration
3986 | N_Subprogram_Body
3987 | N_Subprogram_Declaration
3988 and then Is_Internal_Declaration_Or_Body (Par)
3989 then
3990 return;
3992 -- The reference has been relocated to an inlined body for GNATprove.
3993 -- Assume that the reference is legal as the real check was already
3994 -- performed in the original context of the reference.
3996 elsif GNATprove_Mode
3997 and then Nkind (Par) = N_Subprogram_Body
3998 and then Chars (Defining_Entity (Par)) = Name_uParent
3999 then
4000 return;
4001 end if;
4003 Prev := Par;
4004 Par := Parent (Prev);
4005 end loop;
4007 -- At this point it is known that the reference does not appear within a
4008 -- legal context.
4010 Error_Msg_NE
4011 ("reference to variable & cannot appear in this context", Ref, Var_Id);
4012 Error_Msg_Name_1 := Chars (Var_Id);
4014 if Is_Single_Protected_Object (Conc_Obj) then
4015 Error_Msg_NE
4016 ("\% is constituent of single protected type &", Ref, Conc_Obj);
4018 else
4019 Error_Msg_NE
4020 ("\% is constituent of single task type &", Ref, Conc_Obj);
4021 end if;
4022 end Check_Part_Of_Reference;
4024 ------------------------------------------
4025 -- Check_Potentially_Blocking_Operation --
4026 ------------------------------------------
4028 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
4029 S : Entity_Id;
4031 begin
4032 -- N is one of the potentially blocking operations listed in 9.5.1(8).
4033 -- When pragma Detect_Blocking is active, the run time will raise
4034 -- Program_Error. Here we only issue a warning, since we generally
4035 -- support the use of potentially blocking operations in the absence
4036 -- of the pragma.
4038 -- Indirect blocking through a subprogram call cannot be diagnosed
4039 -- statically without interprocedural analysis, so we do not attempt
4040 -- to do it here.
4042 S := Scope (Current_Scope);
4043 while Present (S) and then S /= Standard_Standard loop
4044 if Is_Protected_Type (S) then
4045 Error_Msg_N
4046 ("potentially blocking operation in protected operation??", N);
4047 return;
4048 end if;
4050 S := Scope (S);
4051 end loop;
4052 end Check_Potentially_Blocking_Operation;
4054 ------------------------------------
4055 -- Check_Previous_Null_Procedure --
4056 ------------------------------------
4058 procedure Check_Previous_Null_Procedure
4059 (Decl : Node_Id;
4060 Prev : Entity_Id)
4062 begin
4063 if Ekind (Prev) = E_Procedure
4064 and then Nkind (Parent (Prev)) = N_Procedure_Specification
4065 and then Null_Present (Parent (Prev))
4066 then
4067 Error_Msg_Sloc := Sloc (Prev);
4068 Error_Msg_N
4069 ("declaration cannot complete previous null procedure#", Decl);
4070 end if;
4071 end Check_Previous_Null_Procedure;
4073 ---------------------------------
4074 -- Check_Result_And_Post_State --
4075 ---------------------------------
4077 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
4078 procedure Check_Result_And_Post_State_In_Pragma
4079 (Prag : Node_Id;
4080 Result_Seen : in out Boolean);
4081 -- Determine whether pragma Prag mentions attribute 'Result and whether
4082 -- the pragma contains an expression that evaluates differently in pre-
4083 -- and post-state. Prag is a [refined] postcondition or a contract-cases
4084 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
4086 -------------------------------------------
4087 -- Check_Result_And_Post_State_In_Pragma --
4088 -------------------------------------------
4090 procedure Check_Result_And_Post_State_In_Pragma
4091 (Prag : Node_Id;
4092 Result_Seen : in out Boolean)
4094 procedure Check_Conjunct (Expr : Node_Id);
4095 -- Check an individual conjunct in a conjunction of Boolean
4096 -- expressions, connected by "and" or "and then" operators.
4098 procedure Check_Conjuncts (Expr : Node_Id);
4099 -- Apply the post-state check to every conjunct in an expression, in
4100 -- case this is a conjunction of Boolean expressions. Otherwise apply
4101 -- it to the expression as a whole.
4103 procedure Check_Expression (Expr : Node_Id);
4104 -- Perform the 'Result and post-state checks on a given expression
4106 function Is_Function_Result (N : Node_Id) return Traverse_Result;
4107 -- Attempt to find attribute 'Result in a subtree denoted by N
4109 function Mentions_Post_State (N : Node_Id) return Boolean;
4110 -- Determine whether a subtree denoted by N mentions any construct
4111 -- that denotes a post-state.
4113 procedure Check_Function_Result is
4114 new Traverse_Proc (Is_Function_Result);
4116 --------------------
4117 -- Check_Conjunct --
4118 --------------------
4120 procedure Check_Conjunct (Expr : Node_Id) is
4121 function Adjust_Message (Msg : String) return String;
4122 -- Prepend a prefix to the input message Msg denoting that the
4123 -- message applies to a conjunct in the expression, when this
4124 -- is the case.
4126 function Applied_On_Conjunct return Boolean;
4127 -- Returns True if the message applies to a conjunct in the
4128 -- expression, instead of the whole expression.
4130 function Has_Global_Output (Subp : Entity_Id) return Boolean;
4131 -- Returns True if Subp has an output in its Global contract
4133 function Has_No_Output (Subp : Entity_Id) return Boolean;
4134 -- Returns True if Subp has no declared output: no function
4135 -- result, no output parameter, and no output in its Global
4136 -- contract.
4138 --------------------
4139 -- Adjust_Message --
4140 --------------------
4142 function Adjust_Message (Msg : String) return String is
4143 begin
4144 if Applied_On_Conjunct then
4145 return "conjunct in " & Msg;
4146 else
4147 return Msg;
4148 end if;
4149 end Adjust_Message;
4151 -------------------------
4152 -- Applied_On_Conjunct --
4153 -------------------------
4155 function Applied_On_Conjunct return Boolean is
4156 begin
4157 -- Expr is the conjunct of an enclosing "and" expression
4159 return Nkind (Parent (Expr)) in N_Subexpr
4161 -- or Expr is a conjunct of an enclosing "and then"
4162 -- expression in a postcondition aspect that was split into
4163 -- multiple pragmas. The first conjunct has the "and then"
4164 -- expression as Original_Node, and other conjuncts have
4165 -- Split_PCC set to True.
4167 or else Nkind (Original_Node (Expr)) = N_And_Then
4168 or else Split_PPC (Prag);
4169 end Applied_On_Conjunct;
4171 -----------------------
4172 -- Has_Global_Output --
4173 -----------------------
4175 function Has_Global_Output (Subp : Entity_Id) return Boolean is
4176 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
4177 List : Node_Id;
4178 Assoc : Node_Id;
4180 begin
4181 if No (Global) then
4182 return False;
4183 end if;
4185 List := Expression (Get_Argument (Global, Subp));
4187 -- Empty list (no global items) or single global item
4188 -- declaration (only input items).
4190 if Nkind (List) in N_Null
4191 | N_Expanded_Name
4192 | N_Identifier
4193 | N_Selected_Component
4194 then
4195 return False;
4197 -- Simple global list (only input items) or moded global list
4198 -- declaration.
4200 elsif Nkind (List) = N_Aggregate then
4201 if Present (Expressions (List)) then
4202 return False;
4204 else
4205 Assoc := First (Component_Associations (List));
4206 while Present (Assoc) loop
4207 if Chars (First (Choices (Assoc))) /= Name_Input then
4208 return True;
4209 end if;
4211 Next (Assoc);
4212 end loop;
4214 return False;
4215 end if;
4217 -- To accommodate partial decoration of disabled SPARK
4218 -- features, this routine may be called with illegal input.
4219 -- If this is the case, do not raise Program_Error.
4221 else
4222 return False;
4223 end if;
4224 end Has_Global_Output;
4226 -------------------
4227 -- Has_No_Output --
4228 -------------------
4230 function Has_No_Output (Subp : Entity_Id) return Boolean is
4231 Param : Node_Id;
4233 begin
4234 -- A function has its result as output
4236 if Ekind (Subp) = E_Function then
4237 return False;
4238 end if;
4240 -- An OUT or IN OUT parameter is an output
4242 Param := First_Formal (Subp);
4243 while Present (Param) loop
4244 if Ekind (Param) in E_Out_Parameter | E_In_Out_Parameter then
4245 return False;
4246 end if;
4248 Next_Formal (Param);
4249 end loop;
4251 -- An item of mode Output or In_Out in the Global contract is
4252 -- an output.
4254 if Has_Global_Output (Subp) then
4255 return False;
4256 end if;
4258 return True;
4259 end Has_No_Output;
4261 -- Local variables
4263 Err_Node : Node_Id;
4264 -- Error node when reporting a warning on a (refined)
4265 -- postcondition.
4267 -- Start of processing for Check_Conjunct
4269 begin
4270 if Applied_On_Conjunct then
4271 Err_Node := Expr;
4272 else
4273 Err_Node := Prag;
4274 end if;
4276 -- Do not report missing reference to outcome in postcondition if
4277 -- either the postcondition is trivially True or False, or if the
4278 -- subprogram is ghost and has no declared output.
4280 if not Is_Trivial_Boolean (Expr)
4281 and then not Mentions_Post_State (Expr)
4282 and then not (Is_Ghost_Entity (Subp_Id)
4283 and then Has_No_Output (Subp_Id))
4284 and then not Is_Wrapper (Subp_Id)
4285 then
4286 case Pragma_Name (Prag) is
4287 when Name_Contract_Cases =>
4288 Error_Msg_NE (Adjust_Message
4289 ("contract case does not check the outcome of calling "
4290 & "&?.t?"), Expr, Subp_Id);
4292 when Name_Refined_Post =>
4293 Error_Msg_NE (Adjust_Message
4294 ("refined postcondition does not check the outcome of "
4295 & "calling &?.t?"), Err_Node, Subp_Id);
4297 when Name_Postcondition =>
4298 Error_Msg_NE (Adjust_Message
4299 ("postcondition does not check the outcome of calling "
4300 & "&?.t?"), Err_Node, Subp_Id);
4302 when others => pragma Assert (False);
4303 end case;
4304 end if;
4305 end Check_Conjunct;
4307 ---------------------
4308 -- Check_Conjuncts --
4309 ---------------------
4311 procedure Check_Conjuncts (Expr : Node_Id) is
4312 begin
4313 if Nkind (Expr) in N_Op_And | N_And_Then then
4314 Check_Conjuncts (Left_Opnd (Expr));
4315 Check_Conjuncts (Right_Opnd (Expr));
4316 else
4317 Check_Conjunct (Expr);
4318 end if;
4319 end Check_Conjuncts;
4321 ----------------------
4322 -- Check_Expression --
4323 ----------------------
4325 procedure Check_Expression (Expr : Node_Id) is
4326 begin
4327 if not Is_Trivial_Boolean (Expr) then
4328 Check_Function_Result (Expr);
4329 Check_Conjuncts (Expr);
4330 end if;
4331 end Check_Expression;
4333 ------------------------
4334 -- Is_Function_Result --
4335 ------------------------
4337 function Is_Function_Result (N : Node_Id) return Traverse_Result is
4338 begin
4339 if Is_Attribute_Result (N) then
4340 Result_Seen := True;
4341 return Abandon;
4343 -- Warn on infinite recursion if call is to current function
4345 elsif Nkind (N) = N_Function_Call
4346 and then Is_Entity_Name (Name (N))
4347 and then Entity (Name (N)) = Subp_Id
4348 and then not Is_Potentially_Unevaluated (N)
4349 then
4350 Error_Msg_NE
4351 ("call to & within its postcondition will lead to infinite "
4352 & "recursion?", N, Subp_Id);
4353 return OK;
4355 -- Continue the traversal
4357 else
4358 return OK;
4359 end if;
4360 end Is_Function_Result;
4362 -------------------------
4363 -- Mentions_Post_State --
4364 -------------------------
4366 function Mentions_Post_State (N : Node_Id) return Boolean is
4367 Post_State_Seen : Boolean := False;
4369 function Is_Post_State (N : Node_Id) return Traverse_Result;
4370 -- Attempt to find a construct that denotes a post-state. If this
4371 -- is the case, set flag Post_State_Seen.
4373 -------------------
4374 -- Is_Post_State --
4375 -------------------
4377 function Is_Post_State (N : Node_Id) return Traverse_Result is
4378 Ent : Entity_Id;
4380 begin
4381 if Nkind (N) in N_Explicit_Dereference | N_Function_Call then
4382 Post_State_Seen := True;
4383 return Abandon;
4385 elsif Nkind (N) in N_Expanded_Name | N_Identifier then
4386 Ent := Entity (N);
4388 -- Treat an undecorated reference as OK
4390 if No (Ent)
4392 -- A reference to an assignable entity is considered a
4393 -- change in the post-state of a subprogram.
4395 or else Ekind (Ent) in E_Generic_In_Out_Parameter
4396 | E_In_Out_Parameter
4397 | E_Out_Parameter
4398 | E_Variable
4400 -- The reference may be modified through a dereference
4402 or else (Is_Access_Type (Etype (Ent))
4403 and then Nkind (Parent (N)) =
4404 N_Selected_Component)
4405 then
4406 Post_State_Seen := True;
4407 return Abandon;
4408 end if;
4410 elsif Nkind (N) = N_Attribute_Reference then
4411 if Attribute_Name (N) = Name_Old then
4412 return Skip;
4414 elsif Attribute_Name (N) = Name_Result then
4415 Post_State_Seen := True;
4416 return Abandon;
4417 end if;
4418 end if;
4420 return OK;
4421 end Is_Post_State;
4423 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
4425 -- Start of processing for Mentions_Post_State
4427 begin
4428 Find_Post_State (N);
4430 return Post_State_Seen;
4431 end Mentions_Post_State;
4433 -- Local variables
4435 Expr : constant Node_Id :=
4436 Get_Pragma_Arg
4437 (First (Pragma_Argument_Associations (Prag)));
4438 Nam : constant Name_Id := Pragma_Name (Prag);
4439 CCase : Node_Id;
4441 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4443 begin
4444 -- Examine all consequences
4446 if Nam = Name_Contract_Cases then
4447 CCase := First (Component_Associations (Expr));
4448 while Present (CCase) loop
4449 Check_Expression (Expression (CCase));
4451 Next (CCase);
4452 end loop;
4454 -- Examine the expression of a postcondition
4456 else pragma Assert (Nam in Name_Postcondition | Name_Refined_Post);
4457 Check_Expression (Expr);
4458 end if;
4459 end Check_Result_And_Post_State_In_Pragma;
4461 -- Local variables
4463 Items : constant Node_Id := Contract (Subp_Id);
4464 Case_Prag : Node_Id := Empty;
4465 Post_Prag : Node_Id := Empty;
4466 Prag : Node_Id;
4467 Seen_In_Case : Boolean := False;
4468 Seen_In_Post : Boolean := False;
4469 Spec_Id : constant Entity_Id := Unique_Entity (Subp_Id);
4471 -- Start of processing for Check_Result_And_Post_State
4473 begin
4474 -- Do not check in instances, because we already checked the generic
4476 if In_Instance then
4477 return;
4479 -- The lack of attribute 'Result or a post-state is classified as a
4480 -- suspicious contract. Do not perform the check if the corresponding
4481 -- switch is not set.
4483 elsif not Warn_On_Suspicious_Contract then
4484 return;
4486 -- Nothing to do if there is no contract
4488 elsif No (Items) then
4489 return;
4491 -- If the subprogram has a contract Exceptional_Cases, it is often
4492 -- useful to refer only to the pre-state in the postcondition, to
4493 -- indicate when the subprogram might terminate normally.
4495 elsif Present (Get_Pragma (Subp_Id, Pragma_Exceptional_Cases)) then
4496 return;
4498 -- Same if the subprogram has a contract Always_Terminates => Cond,
4499 -- where Cond is not syntactically True.
4501 else
4502 declare
4503 Prag : constant Node_Id :=
4504 Get_Pragma (Subp_Id, Pragma_Always_Terminates);
4505 begin
4506 if Present (Prag)
4507 and then Present (Pragma_Argument_Associations (Prag))
4508 then
4509 declare
4510 Cond : constant Node_Id :=
4511 Get_Pragma_Arg
4512 (First (Pragma_Argument_Associations (Prag)));
4513 begin
4514 if not Compile_Time_Known_Value (Cond)
4515 or else not Is_True (Expr_Value (Cond))
4516 then
4517 return;
4518 end if;
4519 end;
4520 end if;
4521 end;
4522 end if;
4524 -- Examine all postconditions for attribute 'Result and a post-state
4526 Prag := Pre_Post_Conditions (Items);
4527 while Present (Prag) loop
4528 if Pragma_Name_Unmapped (Prag)
4529 in Name_Postcondition | Name_Refined_Post
4530 and then not Error_Posted (Prag)
4531 then
4532 Post_Prag := Prag;
4533 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4534 end if;
4536 Prag := Next_Pragma (Prag);
4537 end loop;
4539 -- Examine the contract cases of the subprogram for attribute 'Result
4540 -- and a post-state.
4542 Prag := Contract_Test_Cases (Items);
4543 while Present (Prag) loop
4544 if Pragma_Name (Prag) = Name_Contract_Cases
4545 and then not Error_Posted (Prag)
4546 then
4547 Case_Prag := Prag;
4548 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4549 end if;
4551 Prag := Next_Pragma (Prag);
4552 end loop;
4554 -- Do not emit any errors if the subprogram is not a function
4556 if Ekind (Spec_Id) not in E_Function | E_Generic_Function then
4557 null;
4559 -- Regardless of whether the function has postconditions or contract
4560 -- cases, or whether they mention attribute 'Result, an [IN] OUT formal
4561 -- parameter is always treated as a result.
4563 elsif Has_Out_Or_In_Out_Parameter (Spec_Id) then
4564 null;
4566 -- The function has both a postcondition and contract cases and they do
4567 -- not mention attribute 'Result.
4569 elsif Present (Case_Prag)
4570 and then not Seen_In_Case
4571 and then Present (Post_Prag)
4572 and then not Seen_In_Post
4573 then
4574 Error_Msg_N
4575 ("neither postcondition nor contract cases mention function "
4576 & "result?.t?", Post_Prag);
4578 -- The function has contract cases only and they do not mention
4579 -- attribute 'Result.
4581 elsif Present (Case_Prag) and then not Seen_In_Case then
4582 Error_Msg_N
4583 ("contract cases do not mention function result?.t?", Case_Prag);
4585 -- The function has non-trivial postconditions only and they do not
4586 -- mention attribute 'Result.
4588 elsif Present (Post_Prag)
4589 and then not Seen_In_Post
4590 and then not Is_Trivial_Boolean
4591 (Get_Pragma_Arg (First (Pragma_Argument_Associations (Post_Prag))))
4592 then
4593 Error_Msg_N
4594 ("postcondition does not mention function result?.t?", Post_Prag);
4595 end if;
4596 end Check_Result_And_Post_State;
4598 -----------------------------
4599 -- Check_State_Refinements --
4600 -----------------------------
4602 procedure Check_State_Refinements
4603 (Context : Node_Id;
4604 Is_Main_Unit : Boolean := False)
4606 procedure Check_Package (Pack : Node_Id);
4607 -- Verify that all abstract states of a [generic] package denoted by its
4608 -- declarative node Pack have proper refinement. Recursively verify the
4609 -- visible and private declarations of the [generic] package for other
4610 -- nested packages.
4612 procedure Check_Packages_In (Decls : List_Id);
4613 -- Seek out [generic] package declarations within declarative list Decls
4614 -- and verify the status of their abstract state refinement.
4616 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4617 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4619 -------------------
4620 -- Check_Package --
4621 -------------------
4623 procedure Check_Package (Pack : Node_Id) is
4624 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4625 Spec : constant Node_Id := Specification (Pack);
4626 States : constant Elist_Id :=
4627 Abstract_States (Defining_Entity (Pack));
4629 State_Elmt : Elmt_Id;
4630 State_Id : Entity_Id;
4632 begin
4633 -- Do not verify proper state refinement when the package is subject
4634 -- to pragma SPARK_Mode Off because this disables the requirement for
4635 -- state refinement.
4637 if SPARK_Mode_Is_Off (Pack) then
4638 null;
4640 -- State refinement can only occur in a completing package body. Do
4641 -- not verify proper state refinement when the body is subject to
4642 -- pragma SPARK_Mode Off because this disables the requirement for
4643 -- state refinement.
4645 elsif Present (Body_Id)
4646 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4647 then
4648 null;
4650 -- Do not verify proper state refinement when the package is an
4651 -- instance as this check was already performed in the generic.
4653 elsif Present (Generic_Parent (Spec)) then
4654 null;
4656 -- Otherwise examine the contents of the package
4658 else
4659 if Present (States) then
4660 State_Elmt := First_Elmt (States);
4661 while Present (State_Elmt) loop
4662 State_Id := Node (State_Elmt);
4664 -- Emit an error when a non-null state lacks refinement,
4665 -- but has Part_Of constituents or there is a package
4666 -- body (SPARK RM 7.1.4(4)). Constituents in private
4667 -- child packages, which are not known at this stage,
4668 -- independently require the existence of a package body.
4670 if not Is_Null_State (State_Id)
4671 and then No (Refinement_Constituents (State_Id))
4672 and then
4673 (Present (Part_Of_Constituents (State_Id))
4674 or else
4675 Present (Body_Id))
4676 then
4677 Error_Msg_N ("state & requires refinement", State_Id);
4678 Error_Msg_N ("\package body should have Refined_State "
4679 & "for state & with constituents", State_Id);
4680 end if;
4682 Next_Elmt (State_Elmt);
4683 end loop;
4684 end if;
4686 Check_Packages_In (Visible_Declarations (Spec));
4687 Check_Packages_In (Private_Declarations (Spec));
4688 end if;
4689 end Check_Package;
4691 -----------------------
4692 -- Check_Packages_In --
4693 -----------------------
4695 procedure Check_Packages_In (Decls : List_Id) is
4696 Decl : Node_Id;
4698 begin
4699 if Present (Decls) then
4700 Decl := First (Decls);
4701 while Present (Decl) loop
4702 if Nkind (Decl) in N_Generic_Package_Declaration
4703 | N_Package_Declaration
4704 then
4705 Check_Package (Decl);
4706 end if;
4708 Next (Decl);
4709 end loop;
4710 end if;
4711 end Check_Packages_In;
4713 -----------------------
4714 -- SPARK_Mode_Is_Off --
4715 -----------------------
4717 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4718 Id : constant Entity_Id := Defining_Entity (N);
4719 Prag : constant Node_Id := SPARK_Pragma (Id);
4721 begin
4722 -- Default the mode to "off" when the context is an instance and all
4723 -- SPARK_Mode pragmas found within are to be ignored.
4725 if Ignore_SPARK_Mode_Pragmas (Id) then
4726 return True;
4728 else
4729 return
4730 Present (Prag)
4731 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4732 end if;
4733 end SPARK_Mode_Is_Off;
4735 -- Start of processing for Check_State_Refinements
4737 begin
4738 -- A block may declare a nested package
4740 if Nkind (Context) = N_Block_Statement then
4741 Check_Packages_In (Declarations (Context));
4743 -- An entry, protected, subprogram, or task body may declare a nested
4744 -- package.
4746 elsif Nkind (Context) in N_Entry_Body
4747 | N_Protected_Body
4748 | N_Subprogram_Body
4749 | N_Task_Body
4750 then
4751 -- Do not verify proper state refinement when the body is subject to
4752 -- pragma SPARK_Mode Off because this disables the requirement for
4753 -- state refinement.
4755 if not SPARK_Mode_Is_Off (Context) then
4756 Check_Packages_In (Declarations (Context));
4757 end if;
4759 -- A package body may declare a nested package
4761 elsif Nkind (Context) = N_Package_Body then
4762 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4764 -- Do not verify proper state refinement when the body is subject to
4765 -- pragma SPARK_Mode Off because this disables the requirement for
4766 -- state refinement.
4768 if not SPARK_Mode_Is_Off (Context) then
4769 Check_Packages_In (Declarations (Context));
4770 end if;
4772 -- A library level [generic] package may declare a nested package
4774 elsif Nkind (Context) in
4775 N_Generic_Package_Declaration | N_Package_Declaration
4776 and then Is_Main_Unit
4777 then
4778 Check_Package (Context);
4779 end if;
4780 end Check_State_Refinements;
4782 ------------------------------
4783 -- Check_Unprotected_Access --
4784 ------------------------------
4786 procedure Check_Unprotected_Access
4787 (Context : Node_Id;
4788 Expr : Node_Id)
4790 Cont_Encl_Typ : Entity_Id;
4791 Pref_Encl_Typ : Entity_Id;
4793 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4794 -- Check whether Obj is a private component of a protected object.
4795 -- Return the protected type where the component resides, Empty
4796 -- otherwise.
4798 function Is_Public_Operation return Boolean;
4799 -- Verify that the enclosing operation is callable from outside the
4800 -- protected object, to minimize false positives.
4802 ------------------------------
4803 -- Enclosing_Protected_Type --
4804 ------------------------------
4806 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4807 begin
4808 if Is_Entity_Name (Obj) then
4809 declare
4810 Ent : Entity_Id := Entity (Obj);
4812 begin
4813 -- The object can be a renaming of a private component, use
4814 -- the original record component.
4816 if Is_Prival (Ent) then
4817 Ent := Prival_Link (Ent);
4818 end if;
4820 if Is_Protected_Type (Scope (Ent)) then
4821 return Scope (Ent);
4822 end if;
4823 end;
4824 end if;
4826 -- For indexed and selected components, recursively check the prefix
4828 if Nkind (Obj) in N_Indexed_Component | N_Selected_Component then
4829 return Enclosing_Protected_Type (Prefix (Obj));
4831 -- The object does not denote a protected component
4833 else
4834 return Empty;
4835 end if;
4836 end Enclosing_Protected_Type;
4838 -------------------------
4839 -- Is_Public_Operation --
4840 -------------------------
4842 function Is_Public_Operation return Boolean is
4843 S : Entity_Id;
4844 E : Entity_Id;
4846 begin
4847 S := Current_Scope;
4848 while Present (S) and then S /= Pref_Encl_Typ loop
4849 if Scope (S) = Pref_Encl_Typ then
4850 E := First_Entity (Pref_Encl_Typ);
4851 while Present (E)
4852 and then E /= First_Private_Entity (Pref_Encl_Typ)
4853 loop
4854 if E = S then
4855 return True;
4856 end if;
4858 Next_Entity (E);
4859 end loop;
4860 end if;
4862 S := Scope (S);
4863 end loop;
4865 return False;
4866 end Is_Public_Operation;
4868 -- Start of processing for Check_Unprotected_Access
4870 begin
4871 if Nkind (Expr) = N_Attribute_Reference
4872 and then Attribute_Name (Expr) = Name_Unchecked_Access
4873 then
4874 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4875 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4877 -- Check whether we are trying to export a protected component to a
4878 -- context with an equal or lower access level.
4880 if Present (Pref_Encl_Typ)
4881 and then No (Cont_Encl_Typ)
4882 and then Is_Public_Operation
4883 and then Scope_Depth (Pref_Encl_Typ)
4884 >= Static_Accessibility_Level
4885 (Context, Object_Decl_Level)
4886 then
4887 Error_Msg_N
4888 ("??possible unprotected access to protected data", Expr);
4889 end if;
4890 end if;
4891 end Check_Unprotected_Access;
4893 ------------------------------
4894 -- Check_Unused_Body_States --
4895 ------------------------------
4897 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4898 procedure Process_Refinement_Clause
4899 (Clause : Node_Id;
4900 States : Elist_Id);
4901 -- Inspect all constituents of refinement clause Clause and remove any
4902 -- matches from body state list States.
4904 procedure Report_Unused_Body_States (States : Elist_Id);
4905 -- Emit errors for each abstract state or object found in list States
4907 -------------------------------
4908 -- Process_Refinement_Clause --
4909 -------------------------------
4911 procedure Process_Refinement_Clause
4912 (Clause : Node_Id;
4913 States : Elist_Id)
4915 procedure Process_Constituent (Constit : Node_Id);
4916 -- Remove constituent Constit from body state list States
4918 -------------------------
4919 -- Process_Constituent --
4920 -------------------------
4922 procedure Process_Constituent (Constit : Node_Id) is
4923 Constit_Id : Entity_Id;
4925 begin
4926 -- Guard against illegal constituents. Only abstract states and
4927 -- objects can appear on the right hand side of a refinement.
4929 if Is_Entity_Name (Constit) then
4930 Constit_Id := Entity_Of (Constit);
4932 if Present (Constit_Id)
4933 and then Ekind (Constit_Id) in
4934 E_Abstract_State | E_Constant | E_Variable
4935 then
4936 Remove (States, Constit_Id);
4937 end if;
4938 end if;
4939 end Process_Constituent;
4941 -- Local variables
4943 Constit : Node_Id;
4945 -- Start of processing for Process_Refinement_Clause
4947 begin
4948 if Nkind (Clause) = N_Component_Association then
4949 Constit := Expression (Clause);
4951 -- Multiple constituents appear as an aggregate
4953 if Nkind (Constit) = N_Aggregate then
4954 Constit := First (Expressions (Constit));
4955 while Present (Constit) loop
4956 Process_Constituent (Constit);
4957 Next (Constit);
4958 end loop;
4960 -- Various forms of a single constituent
4962 else
4963 Process_Constituent (Constit);
4964 end if;
4965 end if;
4966 end Process_Refinement_Clause;
4968 -------------------------------
4969 -- Report_Unused_Body_States --
4970 -------------------------------
4972 procedure Report_Unused_Body_States (States : Elist_Id) is
4973 Posted : Boolean := False;
4974 State_Elmt : Elmt_Id;
4975 State_Id : Entity_Id;
4977 begin
4978 if Present (States) then
4979 State_Elmt := First_Elmt (States);
4980 while Present (State_Elmt) loop
4981 State_Id := Node (State_Elmt);
4983 -- Constants are part of the hidden state of a package, but the
4984 -- compiler cannot determine whether they have variable input
4985 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4986 -- hidden state. Do not emit an error when a constant does not
4987 -- participate in a state refinement, even though it acts as a
4988 -- hidden state.
4990 if Ekind (State_Id) = E_Constant then
4991 null;
4993 -- Overlays do not contribute to package state
4995 elsif Ekind (State_Id) = E_Variable
4996 and then Present (Ultimate_Overlaid_Entity (State_Id))
4997 then
4998 null;
5000 -- Generate an error message of the form:
5002 -- body of package ... has unused hidden states
5003 -- abstract state ... defined at ...
5004 -- variable ... defined at ...
5006 else
5007 if not Posted then
5008 Posted := True;
5009 SPARK_Msg_N
5010 ("body of package & has unused hidden states", Body_Id);
5011 end if;
5013 Error_Msg_Sloc := Sloc (State_Id);
5015 if Ekind (State_Id) = E_Abstract_State then
5016 SPARK_Msg_NE
5017 ("\abstract state & defined #", Body_Id, State_Id);
5019 else
5020 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
5021 end if;
5022 end if;
5024 Next_Elmt (State_Elmt);
5025 end loop;
5026 end if;
5027 end Report_Unused_Body_States;
5029 -- Local variables
5031 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
5032 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
5033 Clause : Node_Id;
5034 States : Elist_Id;
5036 -- Start of processing for Check_Unused_Body_States
5038 begin
5039 -- Inspect the clauses of pragma Refined_State and determine whether all
5040 -- visible states declared within the package body participate in the
5041 -- refinement.
5043 if Present (Prag) then
5044 Clause := Expression (Get_Argument (Prag, Spec_Id));
5045 States := Collect_Body_States (Body_Id);
5047 -- Multiple non-null state refinements appear as an aggregate
5049 if Nkind (Clause) = N_Aggregate then
5050 Clause := First (Component_Associations (Clause));
5051 while Present (Clause) loop
5052 Process_Refinement_Clause (Clause, States);
5053 Next (Clause);
5054 end loop;
5056 -- Various forms of a single state refinement
5058 else
5059 Process_Refinement_Clause (Clause, States);
5060 end if;
5062 -- Ensure that all abstract states and objects declared in the
5063 -- package body state space are utilized as constituents.
5065 Report_Unused_Body_States (States);
5066 end if;
5067 end Check_Unused_Body_States;
5069 -----------------
5070 -- Choice_List --
5071 -----------------
5073 function Choice_List (N : Node_Id) return List_Id is
5074 begin
5075 if Nkind (N) = N_Iterated_Component_Association then
5076 return Discrete_Choices (N);
5077 else
5078 return Choices (N);
5079 end if;
5080 end Choice_List;
5082 ---------------------
5083 -- Class_Condition --
5084 ---------------------
5086 function Class_Condition
5087 (Kind : Condition_Kind;
5088 Subp : Entity_Id) return Node_Id is
5090 begin
5091 case Kind is
5092 when Class_Postcondition =>
5093 return Class_Postconditions (Subp);
5095 when Class_Precondition =>
5096 return Class_Preconditions (Subp);
5098 when Ignored_Class_Postcondition =>
5099 return Ignored_Class_Postconditions (Subp);
5101 when Ignored_Class_Precondition =>
5102 return Ignored_Class_Preconditions (Subp);
5103 end case;
5104 end Class_Condition;
5106 -------------------------
5107 -- Collect_Body_States --
5108 -------------------------
5110 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
5111 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
5112 -- Determine whether object Obj_Id is a suitable visible state of a
5113 -- package body.
5115 procedure Collect_Visible_States
5116 (Pack_Id : Entity_Id;
5117 States : in out Elist_Id);
5118 -- Gather the entities of all abstract states and objects declared in
5119 -- the visible state space of package Pack_Id.
5121 ----------------------------
5122 -- Collect_Visible_States --
5123 ----------------------------
5125 procedure Collect_Visible_States
5126 (Pack_Id : Entity_Id;
5127 States : in out Elist_Id)
5129 Item_Id : Entity_Id;
5131 begin
5132 -- Traverse the entity chain of the package and inspect all visible
5133 -- items.
5135 Item_Id := First_Entity (Pack_Id);
5136 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
5138 -- Do not consider internally generated items as those cannot be
5139 -- named and participate in refinement.
5141 if not Comes_From_Source (Item_Id) then
5142 null;
5144 elsif Ekind (Item_Id) = E_Abstract_State then
5145 Append_New_Elmt (Item_Id, States);
5147 elsif Ekind (Item_Id) in E_Constant | E_Variable
5148 and then Is_Visible_Object (Item_Id)
5149 then
5150 Append_New_Elmt (Item_Id, States);
5152 -- Recursively gather the visible states of a nested package
5153 -- except for nested package renamings.
5155 elsif Ekind (Item_Id) = E_Package
5156 and then No (Renamed_Entity (Item_Id))
5157 then
5158 Collect_Visible_States (Item_Id, States);
5159 end if;
5161 Next_Entity (Item_Id);
5162 end loop;
5163 end Collect_Visible_States;
5165 -----------------------
5166 -- Is_Visible_Object --
5167 -----------------------
5169 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
5170 begin
5171 -- Objects that map generic formals to their actuals are not visible
5172 -- from outside the generic instantiation.
5174 if Present (Corresponding_Generic_Association
5175 (Declaration_Node (Obj_Id)))
5176 then
5177 return False;
5179 -- Constituents of a single protected/task type act as components of
5180 -- the type and are not visible from outside the type.
5182 elsif Ekind (Obj_Id) = E_Variable
5183 and then Present (Encapsulating_State (Obj_Id))
5184 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
5185 then
5186 return False;
5188 else
5189 return True;
5190 end if;
5191 end Is_Visible_Object;
5193 -- Local variables
5195 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
5196 Decl : Node_Id;
5197 Item_Id : Entity_Id;
5198 States : Elist_Id := No_Elist;
5200 -- Start of processing for Collect_Body_States
5202 begin
5203 -- Inspect the declarations of the body looking for source objects,
5204 -- packages and package instantiations. Note that even though this
5205 -- processing is very similar to Collect_Visible_States, a package
5206 -- body does not have a First/Next_Entity list.
5208 Decl := First (Declarations (Body_Decl));
5209 while Present (Decl) loop
5211 -- Capture source objects as internally generated temporaries cannot
5212 -- be named and participate in refinement.
5214 if Nkind (Decl) = N_Object_Declaration then
5215 Item_Id := Defining_Entity (Decl);
5217 if Comes_From_Source (Item_Id)
5218 and then Is_Visible_Object (Item_Id)
5219 then
5220 Append_New_Elmt (Item_Id, States);
5221 end if;
5223 -- Capture the visible abstract states and objects of a source
5224 -- package [instantiation].
5226 elsif Nkind (Decl) = N_Package_Declaration then
5227 Item_Id := Defining_Entity (Decl);
5229 if Comes_From_Source (Item_Id) then
5230 Collect_Visible_States (Item_Id, States);
5231 end if;
5232 end if;
5234 Next (Decl);
5235 end loop;
5237 return States;
5238 end Collect_Body_States;
5240 ------------------------
5241 -- Collect_Interfaces --
5242 ------------------------
5244 procedure Collect_Interfaces
5245 (T : Entity_Id;
5246 Ifaces_List : out Elist_Id;
5247 Exclude_Parents : Boolean := False;
5248 Use_Full_View : Boolean := True)
5250 procedure Collect (Typ : Entity_Id);
5251 -- Subsidiary subprogram used to traverse the whole list
5252 -- of directly and indirectly implemented interfaces
5254 -------------
5255 -- Collect --
5256 -------------
5258 procedure Collect (Typ : Entity_Id) is
5259 Ancestor : Entity_Id;
5260 Full_T : Entity_Id;
5261 Id : Node_Id;
5262 Iface : Entity_Id;
5264 begin
5265 Full_T := Typ;
5267 -- Handle private types and subtypes
5269 if Use_Full_View
5270 and then Is_Private_Type (Typ)
5271 and then Present (Full_View (Typ))
5272 then
5273 Full_T := Full_View (Typ);
5275 if Ekind (Full_T) = E_Record_Subtype then
5276 Full_T := Etype (Typ);
5278 if Present (Full_View (Full_T)) then
5279 Full_T := Full_View (Full_T);
5280 end if;
5281 end if;
5282 end if;
5284 -- Include the ancestor if we are generating the whole list of
5285 -- abstract interfaces.
5287 if Etype (Full_T) /= Typ
5289 -- Protect the frontend against wrong sources. For example:
5291 -- package P is
5292 -- type A is tagged null record;
5293 -- type B is new A with private;
5294 -- type C is new A with private;
5295 -- private
5296 -- type B is new C with null record;
5297 -- type C is new B with null record;
5298 -- end P;
5300 and then Etype (Full_T) /= T
5301 then
5302 Ancestor := Etype (Full_T);
5303 Collect (Ancestor);
5305 if Is_Interface (Ancestor) and then not Exclude_Parents then
5306 Append_Unique_Elmt (Ancestor, Ifaces_List);
5307 end if;
5308 end if;
5310 -- Traverse the graph of ancestor interfaces
5312 Id := First (Abstract_Interface_List (Full_T));
5313 while Present (Id) loop
5314 Iface := Etype (Id);
5316 -- Protect against wrong uses. For example:
5317 -- type I is interface;
5318 -- type O is tagged null record;
5319 -- type Wrong is new I and O with null record; -- ERROR
5321 if Is_Interface (Iface) then
5322 if Exclude_Parents
5323 and then Etype (T) /= T
5324 and then Interface_Present_In_Ancestor (Etype (T), Iface)
5325 then
5326 null;
5327 else
5328 Collect (Iface);
5329 Append_Unique_Elmt (Iface, Ifaces_List);
5330 end if;
5331 end if;
5333 Next (Id);
5334 end loop;
5335 end Collect;
5337 -- Start of processing for Collect_Interfaces
5339 begin
5340 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
5341 Ifaces_List := New_Elmt_List;
5342 Collect (T);
5343 end Collect_Interfaces;
5345 ----------------------------------
5346 -- Collect_Interface_Components --
5347 ----------------------------------
5349 procedure Collect_Interface_Components
5350 (Tagged_Type : Entity_Id;
5351 Components_List : out Elist_Id)
5353 procedure Collect (Typ : Entity_Id);
5354 -- Subsidiary subprogram used to climb to the parents
5356 -------------
5357 -- Collect --
5358 -------------
5360 procedure Collect (Typ : Entity_Id) is
5361 Tag_Comp : Entity_Id;
5362 Parent_Typ : Entity_Id;
5364 begin
5365 -- Handle private types
5367 if Present (Full_View (Etype (Typ))) then
5368 Parent_Typ := Full_View (Etype (Typ));
5369 else
5370 Parent_Typ := Etype (Typ);
5371 end if;
5373 if Parent_Typ /= Typ
5375 -- Protect the frontend against wrong sources. For example:
5377 -- package P is
5378 -- type A is tagged null record;
5379 -- type B is new A with private;
5380 -- type C is new A with private;
5381 -- private
5382 -- type B is new C with null record;
5383 -- type C is new B with null record;
5384 -- end P;
5386 and then Parent_Typ /= Tagged_Type
5387 then
5388 Collect (Parent_Typ);
5389 end if;
5391 -- Collect the components containing tags of secondary dispatch
5392 -- tables.
5394 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
5395 while Present (Tag_Comp) loop
5396 pragma Assert (Present (Related_Type (Tag_Comp)));
5397 Append_Elmt (Tag_Comp, Components_List);
5399 Tag_Comp := Next_Tag_Component (Tag_Comp);
5400 end loop;
5401 end Collect;
5403 -- Start of processing for Collect_Interface_Components
5405 begin
5406 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
5407 and then Is_Tagged_Type (Tagged_Type));
5409 Components_List := New_Elmt_List;
5410 Collect (Tagged_Type);
5411 end Collect_Interface_Components;
5413 -----------------------------
5414 -- Collect_Interfaces_Info --
5415 -----------------------------
5417 procedure Collect_Interfaces_Info
5418 (T : Entity_Id;
5419 Ifaces_List : out Elist_Id;
5420 Components_List : out Elist_Id;
5421 Tags_List : out Elist_Id)
5423 Comps_List : Elist_Id;
5424 Comp_Elmt : Elmt_Id;
5425 Comp_Iface : Entity_Id;
5426 Iface_Elmt : Elmt_Id;
5427 Iface : Entity_Id;
5429 function Search_Tag (Iface : Entity_Id) return Entity_Id;
5430 -- Search for the secondary tag associated with the interface type
5431 -- Iface that is implemented by T.
5433 ----------------
5434 -- Search_Tag --
5435 ----------------
5437 function Search_Tag (Iface : Entity_Id) return Entity_Id is
5438 ADT : Elmt_Id;
5439 begin
5440 if not Is_CPP_Class (T) then
5441 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
5442 else
5443 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
5444 end if;
5446 while Present (ADT)
5447 and then Is_Tag (Node (ADT))
5448 and then Related_Type (Node (ADT)) /= Iface
5449 loop
5450 -- Skip secondary dispatch table referencing thunks to user
5451 -- defined primitives covered by this interface.
5453 pragma Assert (Has_Suffix (Node (ADT), 'P'));
5454 Next_Elmt (ADT);
5456 -- Skip secondary dispatch tables of Ada types
5458 if not Is_CPP_Class (T) then
5460 -- Skip secondary dispatch table referencing thunks to
5461 -- predefined primitives.
5463 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
5464 Next_Elmt (ADT);
5466 -- Skip secondary dispatch table referencing user-defined
5467 -- primitives covered by this interface.
5469 pragma Assert (Has_Suffix (Node (ADT), 'D'));
5470 Next_Elmt (ADT);
5472 -- Skip secondary dispatch table referencing predefined
5473 -- primitives.
5475 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
5476 Next_Elmt (ADT);
5477 end if;
5478 end loop;
5480 pragma Assert (Is_Tag (Node (ADT)));
5481 return Node (ADT);
5482 end Search_Tag;
5484 -- Start of processing for Collect_Interfaces_Info
5486 begin
5487 Collect_Interfaces (T, Ifaces_List);
5488 Collect_Interface_Components (T, Comps_List);
5490 -- Search for the record component and tag associated with each
5491 -- interface type of T.
5493 Components_List := New_Elmt_List;
5494 Tags_List := New_Elmt_List;
5496 Iface_Elmt := First_Elmt (Ifaces_List);
5497 while Present (Iface_Elmt) loop
5498 Iface := Node (Iface_Elmt);
5500 -- Associate the primary tag component and the primary dispatch table
5501 -- with all the interfaces that are parents of T
5503 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5504 Append_Elmt (First_Tag_Component (T), Components_List);
5505 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5507 -- Otherwise search for the tag component and secondary dispatch
5508 -- table of Iface
5510 else
5511 Comp_Elmt := First_Elmt (Comps_List);
5512 while Present (Comp_Elmt) loop
5513 Comp_Iface := Related_Type (Node (Comp_Elmt));
5515 if Comp_Iface = Iface
5516 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5517 then
5518 Append_Elmt (Node (Comp_Elmt), Components_List);
5519 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5520 exit;
5521 end if;
5523 Next_Elmt (Comp_Elmt);
5524 end loop;
5525 pragma Assert (Present (Comp_Elmt));
5526 end if;
5528 Next_Elmt (Iface_Elmt);
5529 end loop;
5530 end Collect_Interfaces_Info;
5532 ---------------------
5533 -- Collect_Parents --
5534 ---------------------
5536 procedure Collect_Parents
5537 (T : Entity_Id;
5538 List : out Elist_Id;
5539 Use_Full_View : Boolean := True)
5541 Current_Typ : Entity_Id := T;
5542 Parent_Typ : Entity_Id;
5544 begin
5545 List := New_Elmt_List;
5547 -- No action if the if the type has no parents
5549 if T = Etype (T) then
5550 return;
5551 end if;
5553 loop
5554 Parent_Typ := Etype (Current_Typ);
5556 if Is_Private_Type (Parent_Typ)
5557 and then Present (Full_View (Parent_Typ))
5558 and then Use_Full_View
5559 then
5560 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5561 end if;
5563 Append_Elmt (Parent_Typ, List);
5565 exit when Parent_Typ = Current_Typ;
5566 Current_Typ := Parent_Typ;
5567 end loop;
5568 end Collect_Parents;
5570 ----------------------------------
5571 -- Collect_Primitive_Operations --
5572 ----------------------------------
5574 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5575 B_Type : constant Entity_Id := Base_Type (T);
5577 function Match (E : Entity_Id) return Boolean;
5578 -- True if E's base type is B_Type, or E is of an anonymous access type
5579 -- and the base type of its designated type is B_Type.
5581 -----------
5582 -- Match --
5583 -----------
5585 function Match (E : Entity_Id) return Boolean is
5586 Etyp : Entity_Id := Etype (E);
5588 begin
5589 if Ekind (Etyp) = E_Anonymous_Access_Type then
5590 Etyp := Designated_Type (Etyp);
5591 end if;
5593 -- In Ada 2012 a primitive operation may have a formal of an
5594 -- incomplete view of the parent type.
5596 return Base_Type (Etyp) = B_Type
5597 or else
5598 (Ada_Version >= Ada_2012
5599 and then Ekind (Etyp) = E_Incomplete_Type
5600 and then Full_View (Etyp) = B_Type);
5601 end Match;
5603 -- Local variables
5605 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5606 B_Scope : Entity_Id := Scope (B_Type);
5607 Op_List : Elist_Id;
5608 Eq_Prims_List : Elist_Id := No_Elist;
5609 Formal : Entity_Id;
5610 Is_Prim : Boolean;
5611 Is_Type_In_Pkg : Boolean;
5612 Formal_Derived : Boolean := False;
5613 Id : Entity_Id;
5615 -- Start of processing for Collect_Primitive_Operations
5617 begin
5618 -- For tagged types, the primitive operations are collected as they
5619 -- are declared, and held in an explicit list which is simply returned.
5621 if Is_Tagged_Type (B_Type) then
5622 return Primitive_Operations (B_Type);
5624 -- An untagged generic type that is a derived type inherits the
5625 -- primitive operations of its parent type. Other formal types only
5626 -- have predefined operators, which are not explicitly represented.
5628 elsif Is_Generic_Type (B_Type) then
5629 if Nkind (B_Decl) = N_Formal_Type_Declaration
5630 and then Nkind (Formal_Type_Definition (B_Decl)) =
5631 N_Formal_Derived_Type_Definition
5632 then
5633 Formal_Derived := True;
5634 else
5635 return New_Elmt_List;
5636 end if;
5637 end if;
5639 Op_List := New_Elmt_List;
5641 if B_Scope = Standard_Standard then
5642 if B_Type = Standard_String then
5643 Append_Elmt (Standard_Op_Concat, Op_List);
5645 elsif B_Type = Standard_Wide_String then
5646 Append_Elmt (Standard_Op_Concatw, Op_List);
5648 else
5649 null;
5650 end if;
5652 -- Locate the primitive subprograms of the type
5654 else
5655 -- The primitive operations appear after the base type, except if the
5656 -- derivation happens within the private part of B_Scope and the type
5657 -- is a private type, in which case both the type and some primitive
5658 -- operations may appear before the base type, and the list of
5659 -- candidates starts after the type.
5661 if In_Open_Scopes (B_Scope)
5662 and then Scope (T) = B_Scope
5663 and then In_Private_Part (B_Scope)
5664 then
5665 Id := Next_Entity (T);
5667 -- In Ada 2012, If the type has an incomplete partial view, there may
5668 -- be primitive operations declared before the full view, so we need
5669 -- to start scanning from the incomplete view, which is earlier on
5670 -- the entity chain.
5672 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5673 and then Present (Incomplete_View (Parent (B_Type)))
5674 then
5675 Id := Incomplete_View (Parent (B_Type));
5677 -- If T is a derived from a type with an incomplete view declared
5678 -- elsewhere, that incomplete view is irrelevant, we want the
5679 -- operations in the scope of T.
5681 if Scope (Id) /= Scope (B_Type) then
5682 Id := Next_Entity (B_Type);
5683 end if;
5685 else
5686 Id := Next_Entity (B_Type);
5687 end if;
5689 -- Set flag if this is a type in a package spec
5691 Is_Type_In_Pkg :=
5692 Is_Package_Or_Generic_Package (B_Scope)
5693 and then
5694 Parent_Kind (Declaration_Node (First_Subtype (T))) /=
5695 N_Package_Body;
5697 while Present (Id) loop
5699 -- Test whether the result type or any of the parameter types of
5700 -- each subprogram following the type match that type when the
5701 -- type is declared in a package spec, is a derived type, or the
5702 -- subprogram is marked as primitive. (The Is_Primitive test is
5703 -- needed to find primitives of nonderived types in declarative
5704 -- parts that happen to override the predefined "=" operator.)
5706 -- Note that generic formal subprograms are not considered to be
5707 -- primitive operations and thus are never inherited.
5709 if Is_Overloadable (Id)
5710 and then (Is_Type_In_Pkg
5711 or else Is_Derived_Type (B_Type)
5712 or else Is_Primitive (Id))
5713 and then Parent_Kind (Parent (Id))
5714 not in N_Formal_Subprogram_Declaration
5715 then
5716 Is_Prim := False;
5718 if Match (Id) then
5719 Is_Prim := True;
5721 else
5722 Formal := First_Formal (Id);
5723 while Present (Formal) loop
5724 if Match (Formal) then
5725 Is_Prim := True;
5726 exit;
5727 end if;
5729 Next_Formal (Formal);
5730 end loop;
5731 end if;
5733 -- For a formal derived type, the only primitives are the ones
5734 -- inherited from the parent type. Operations appearing in the
5735 -- package declaration are not primitive for it.
5737 if Is_Prim
5738 and then (not Formal_Derived or else Present (Alias (Id)))
5739 then
5740 -- In the special case of an equality operator aliased to
5741 -- an overriding dispatching equality belonging to the same
5742 -- type, we don't include it in the list of primitives.
5743 -- This avoids inheriting multiple equality operators when
5744 -- deriving from untagged private types whose full type is
5745 -- tagged, which can otherwise cause ambiguities. Note that
5746 -- this should only happen for this kind of untagged parent
5747 -- type, since normally dispatching operations are inherited
5748 -- using the type's Primitive_Operations list.
5750 if Chars (Id) = Name_Op_Eq
5751 and then Is_Dispatching_Operation (Id)
5752 and then Present (Alias (Id))
5753 and then Present (Overridden_Operation (Alias (Id)))
5754 and then Base_Type (Etype (First_Entity (Id))) =
5755 Base_Type (Etype (First_Entity (Alias (Id))))
5756 then
5757 null;
5759 -- Include the subprogram in the list of primitives
5761 else
5762 Append_Elmt (Id, Op_List);
5764 -- Save collected equality primitives for later filtering
5765 -- (if we are processing a private type for which we can
5766 -- collect several candidates).
5768 if Inherits_From_Tagged_Full_View (T)
5769 and then Chars (Id) = Name_Op_Eq
5770 and then Etype (First_Formal (Id)) =
5771 Etype (Next_Formal (First_Formal (Id)))
5772 then
5773 Append_New_Elmt (Id, Eq_Prims_List);
5774 end if;
5775 end if;
5776 end if;
5777 end if;
5779 Next_Entity (Id);
5781 -- For a type declared in System, some of its operations may
5782 -- appear in the target-specific extension to System.
5784 if No (Id)
5785 and then Is_RTU (B_Scope, System)
5786 and then Present_System_Aux
5787 then
5788 B_Scope := System_Aux_Id;
5789 Id := First_Entity (System_Aux_Id);
5790 end if;
5791 end loop;
5793 -- Filter collected equality primitives
5795 if Inherits_From_Tagged_Full_View (T)
5796 and then Present (Eq_Prims_List)
5797 then
5798 declare
5799 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5800 Second : Elmt_Id;
5802 begin
5803 pragma Assert (No (Next_Elmt (First))
5804 or else No (Next_Elmt (Next_Elmt (First))));
5806 -- No action needed if we have collected a single equality
5807 -- primitive
5809 if Present (Next_Elmt (First)) then
5810 Second := Next_Elmt (First);
5812 if Is_Dispatching_Operation
5813 (Ultimate_Alias (Node (First)))
5814 then
5815 Remove (Op_List, Node (First));
5817 elsif Is_Dispatching_Operation
5818 (Ultimate_Alias (Node (Second)))
5819 then
5820 Remove (Op_List, Node (Second));
5822 else
5823 raise Program_Error;
5824 end if;
5825 end if;
5826 end;
5827 end if;
5828 end if;
5830 return Op_List;
5831 end Collect_Primitive_Operations;
5833 -----------------------------------
5834 -- Compile_Time_Constraint_Error --
5835 -----------------------------------
5837 function Compile_Time_Constraint_Error
5838 (N : Node_Id;
5839 Msg : String;
5840 Ent : Entity_Id := Empty;
5841 Loc : Source_Ptr := No_Location;
5842 Warn : Boolean := False;
5843 Extra_Msg : String := "") return Node_Id
5845 Msgc : String (1 .. Msg'Length + 3);
5846 -- Copy of message, with room for possible ?? or << and ! at end
5848 Msgl : Natural;
5849 Wmsg : Boolean;
5850 Eloc : Source_Ptr;
5852 begin
5853 -- If this is a warning, convert it into an error if we are in code
5854 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5855 -- warning. The rationale is that a compile-time constraint error should
5856 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5857 -- a few cases we prefer to issue a warning and generate both a suitable
5858 -- run-time error in GNAT and a suitable check message in GNATprove.
5859 -- Those cases are those that likely correspond to deactivated SPARK
5860 -- code, so that this kind of code can be compiled and analyzed instead
5861 -- of being rejected.
5863 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5865 -- A static constraint error in an instance body is not a fatal error.
5866 -- We choose to inhibit the message altogether, because there is no
5867 -- obvious node (for now) on which to post it. On the other hand the
5868 -- offending node must be replaced with a constraint_error in any case.
5870 -- No messages are generated if we already posted an error on this node
5872 if not Error_Posted (N) then
5873 if Loc /= No_Location then
5874 Eloc := Loc;
5875 else
5876 Eloc := Sloc (N);
5877 end if;
5879 -- Copy message to Msgc, converting any ? in the message into <
5880 -- instead, so that we have an error in GNATprove mode.
5882 Msgl := Msg'Length;
5884 for J in 1 .. Msgl loop
5885 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5886 Msgc (J) := '<';
5887 else
5888 Msgc (J) := Msg (J);
5889 end if;
5890 end loop;
5892 -- Message is a warning, even in Ada 95 case
5894 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5895 Wmsg := True;
5897 -- In Ada 83, all messages are warnings. In the private part and the
5898 -- body of an instance, constraint_checks are only warnings. We also
5899 -- make this a warning if the Warn parameter is set.
5901 elsif Warn
5902 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5903 or else In_Instance_Not_Visible
5904 then
5905 Msgl := Msgl + 1;
5906 Msgc (Msgl) := '<';
5907 Msgl := Msgl + 1;
5908 Msgc (Msgl) := '<';
5909 Wmsg := True;
5911 -- Otherwise we have a real error message (Ada 95 static case) and we
5912 -- make this an unconditional message. Note that in the warning case
5913 -- we do not make the message unconditional, it seems reasonable to
5914 -- delete messages like this (about exceptions that will be raised)
5915 -- in dead code.
5917 else
5918 Wmsg := False;
5919 Msgl := Msgl + 1;
5920 Msgc (Msgl) := '!';
5921 end if;
5923 -- One more test, skip the warning if the related expression is
5924 -- statically unevaluated, since we don't want to warn about what
5925 -- will happen when something is evaluated if it never will be
5926 -- evaluated.
5928 -- Suppress error reporting when checking that the expression of a
5929 -- static expression function is a potentially static expression,
5930 -- because we don't want additional errors being reported during the
5931 -- preanalysis of the expression (see Analyze_Expression_Function).
5933 if not Is_Statically_Unevaluated (N)
5934 and then not Checking_Potentially_Static_Expression
5935 then
5936 if Present (Ent) then
5937 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5938 else
5939 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5940 end if;
5942 -- Emit any extra message as a continuation
5944 if Extra_Msg /= "" then
5945 Error_Msg_N ('\' & Extra_Msg, N);
5946 end if;
5948 if Wmsg then
5950 -- Check whether the context is an Init_Proc
5952 if Inside_Init_Proc then
5953 declare
5954 Init_Proc_Type : constant Entity_Id :=
5955 Etype (First_Formal (Current_Scope_No_Loops));
5957 Conc_Typ : constant Entity_Id :=
5958 (if Present (Init_Proc_Type)
5959 and then Ekind (Init_Proc_Type) = E_Record_Type
5960 then Corresponding_Concurrent_Type (Init_Proc_Type)
5961 else Empty);
5963 begin
5964 -- Don't complain if the corresponding concurrent type
5965 -- doesn't come from source (i.e. a single task/protected
5966 -- object).
5968 if Present (Conc_Typ)
5969 and then not Comes_From_Source (Conc_Typ)
5970 then
5971 Error_Msg ("\& [<<", Eloc, N);
5973 else
5974 if GNATprove_Mode then
5975 Error_Msg
5976 ("\Constraint_Error would have been raised"
5977 & " for objects of this type", Eloc, N);
5978 else
5979 Error_Msg
5980 ("\Constraint_Error will be raised"
5981 & " for objects of this type??", Eloc, N);
5982 end if;
5983 end if;
5984 end;
5986 else
5987 Error_Msg ("\Constraint_Error [<<", Eloc, N);
5988 end if;
5990 else
5991 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5992 Set_Error_Posted (N);
5993 end if;
5994 end if;
5995 end if;
5997 return N;
5998 end Compile_Time_Constraint_Error;
6000 ----------------------------
6001 -- Compute_Returns_By_Ref --
6002 ----------------------------
6004 procedure Compute_Returns_By_Ref (Func : Entity_Id) is
6005 Kind : constant Entity_Kind := Ekind (Func);
6006 Typ : constant Entity_Id := Etype (Func);
6008 begin
6009 -- Nothing to do for procedures
6011 if Kind in E_Procedure | E_Generic_Procedure
6012 or else (Kind = E_Subprogram_Type and then Typ = Standard_Void_Type)
6013 then
6014 null;
6016 -- The build-in-place protocols return a reference to the result
6018 elsif Is_Build_In_Place_Function (Func) then
6019 Set_Returns_By_Ref (Func);
6021 -- In Ada 95, limited types are returned by reference, but not if the
6022 -- convention is other than Ada.
6024 elsif Is_Inherently_Limited_Type (Typ)
6025 and then not Has_Foreign_Convention (Func)
6026 then
6027 Set_Returns_By_Ref (Func);
6028 end if;
6029 end Compute_Returns_By_Ref;
6031 --------------------------------
6032 -- Collect_Types_In_Hierarchy --
6033 --------------------------------
6035 function Collect_Types_In_Hierarchy
6036 (Typ : Entity_Id;
6037 Examine_Components : Boolean := False) return Elist_Id
6039 Results : Elist_Id;
6041 procedure Process_Type (Typ : Entity_Id);
6042 -- Collect type Typ if it satisfies function Predicate. Do so for its
6043 -- parent type, base type, progenitor types, and any component types.
6045 ------------------
6046 -- Process_Type --
6047 ------------------
6049 procedure Process_Type (Typ : Entity_Id) is
6050 Comp : Entity_Id;
6051 Iface_Elmt : Elmt_Id;
6053 begin
6054 if not Is_Type (Typ) or else Error_Posted (Typ) then
6055 return;
6056 end if;
6058 -- Collect the current type if it satisfies the predicate
6060 if Predicate (Typ) then
6061 Append_Elmt (Typ, Results);
6062 end if;
6064 -- Process component types
6066 if Examine_Components then
6068 -- Examine components and discriminants
6070 if Is_Concurrent_Type (Typ)
6071 or else Is_Incomplete_Or_Private_Type (Typ)
6072 or else Is_Record_Type (Typ)
6073 or else Has_Discriminants (Typ)
6074 then
6075 Comp := First_Component_Or_Discriminant (Typ);
6077 while Present (Comp) loop
6078 Process_Type (Etype (Comp));
6080 Next_Component_Or_Discriminant (Comp);
6081 end loop;
6083 -- Examine array components
6085 elsif Ekind (Typ) = E_Array_Type then
6086 Process_Type (Component_Type (Typ));
6087 end if;
6088 end if;
6090 -- Examine parent type
6092 if Etype (Typ) /= Typ then
6093 -- Prevent infinite recursion, which can happen in illegal
6094 -- programs. Silently return if illegal. For now, just deal
6095 -- with the 2-type cycle case. Larger cycles will get
6096 -- SIGSEGV at compile time from running out of stack.
6098 if Etype (Etype (Typ)) = Typ then
6099 if Total_Errors_Detected = 0 then
6100 raise Program_Error;
6101 else
6102 return;
6103 end if;
6104 end if;
6106 Process_Type (Etype (Typ));
6107 end if;
6109 -- Examine base type
6111 if Base_Type (Typ) /= Typ then
6112 Process_Type (Base_Type (Typ));
6113 end if;
6115 -- Examine interfaces
6117 if Is_Record_Type (Typ)
6118 and then Present (Interfaces (Typ))
6119 then
6120 Iface_Elmt := First_Elmt (Interfaces (Typ));
6121 while Present (Iface_Elmt) loop
6122 Process_Type (Node (Iface_Elmt));
6124 Next_Elmt (Iface_Elmt);
6125 end loop;
6126 end if;
6127 end Process_Type;
6129 -- Start of processing for Collect_Types_In_Hierarchy
6131 begin
6132 Results := New_Elmt_List;
6133 Process_Type (Typ);
6134 return Results;
6135 end Collect_Types_In_Hierarchy;
6137 -----------------------
6138 -- Conditional_Delay --
6139 -----------------------
6141 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
6142 begin
6143 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
6144 Set_Has_Delayed_Freeze (New_Ent);
6145 end if;
6146 end Conditional_Delay;
6148 -------------------------
6149 -- Copy_Component_List --
6150 -------------------------
6152 function Copy_Component_List
6153 (R_Typ : Entity_Id;
6154 Loc : Source_Ptr) return List_Id
6156 Comp : Node_Id;
6157 Comps : constant List_Id := New_List;
6159 begin
6160 Comp := First_Component (Underlying_Type (R_Typ));
6161 while Present (Comp) loop
6162 if Comes_From_Source (Comp) then
6163 declare
6164 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
6165 begin
6166 Append_To (Comps,
6167 Make_Component_Declaration (Loc,
6168 Defining_Identifier =>
6169 Make_Defining_Identifier (Loc, Chars (Comp)),
6170 Component_Definition =>
6171 New_Copy_Tree
6172 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
6173 end;
6174 end if;
6176 Next_Component (Comp);
6177 end loop;
6179 return Comps;
6180 end Copy_Component_List;
6182 -----------------------
6183 -- Copy_Ghost_Aspect --
6184 -----------------------
6186 procedure Copy_Ghost_Aspect (From : Node_Id; To : Node_Id) is
6187 pragma Assert (not Has_Aspects (To));
6188 Asp : Node_Id;
6190 begin
6191 if Has_Aspects (From) then
6192 Asp := Find_Aspect (Defining_Entity (From), Aspect_Ghost);
6194 if Present (Asp) then
6195 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
6196 end if;
6197 end if;
6198 end Copy_Ghost_Aspect;
6200 -------------------------
6201 -- Copy_Parameter_List --
6202 -------------------------
6204 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
6205 Loc : constant Source_Ptr := Sloc (Subp_Id);
6206 Plist : List_Id;
6207 Formal : Entity_Id := First_Formal (Subp_Id);
6209 begin
6210 if Present (Formal) then
6211 Plist := New_List;
6212 while Present (Formal) loop
6213 Append_To (Plist,
6214 Make_Parameter_Specification (Loc,
6215 Defining_Identifier =>
6216 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
6217 In_Present => In_Present (Parent (Formal)),
6218 Out_Present => Out_Present (Parent (Formal)),
6219 Parameter_Type =>
6220 New_Occurrence_Of (Etype (Formal), Loc),
6221 Expression =>
6222 New_Copy_Tree (Expression (Parent (Formal)))));
6224 Next_Formal (Formal);
6225 end loop;
6226 else
6227 Plist := No_List;
6228 end if;
6230 return Plist;
6231 end Copy_Parameter_List;
6233 ----------------------------
6234 -- Copy_SPARK_Mode_Aspect --
6235 ----------------------------
6237 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
6238 pragma Assert (not Has_Aspects (To));
6239 Asp : Node_Id;
6241 begin
6242 if Has_Aspects (From) then
6243 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
6245 if Present (Asp) then
6246 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
6247 end if;
6248 end if;
6249 end Copy_SPARK_Mode_Aspect;
6251 --------------------------
6252 -- Copy_Subprogram_Spec --
6253 --------------------------
6255 function Copy_Subprogram_Spec
6256 (Spec : Node_Id;
6257 New_Sloc : Source_Ptr := No_Location) return Node_Id
6259 Def_Id : Node_Id;
6260 Formal_Spec : Node_Id;
6261 Result : Node_Id;
6263 begin
6264 -- The structure of the original tree must be replicated without any
6265 -- alterations. Use New_Copy_Tree for this purpose.
6267 Result := New_Copy_Tree (Spec, New_Sloc => New_Sloc);
6269 -- However, the spec of a null procedure carries the corresponding null
6270 -- statement of the body (created by the parser), and this cannot be
6271 -- shared with the new subprogram spec.
6273 if Nkind (Result) = N_Procedure_Specification then
6274 Set_Null_Statement (Result, Empty);
6275 end if;
6277 -- Create a new entity for the defining unit name
6279 Def_Id := Defining_Unit_Name (Result);
6280 Set_Defining_Unit_Name (Result,
6281 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
6283 -- Create new entities for the formal parameters
6285 Formal_Spec := First (Parameter_Specifications (Result));
6286 while Present (Formal_Spec) loop
6287 Def_Id := Defining_Identifier (Formal_Spec);
6288 Set_Defining_Identifier (Formal_Spec,
6289 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
6291 Next (Formal_Spec);
6292 end loop;
6294 return Result;
6295 end Copy_Subprogram_Spec;
6297 --------------------------------
6298 -- Corresponding_Generic_Type --
6299 --------------------------------
6301 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
6302 Inst : Entity_Id;
6303 Gen : Entity_Id;
6304 Typ : Entity_Id;
6306 begin
6307 if not Is_Generic_Actual_Type (T) then
6308 return Any_Type;
6310 -- If the actual is the actual of an enclosing instance, resolution
6311 -- was correct in the generic.
6313 elsif Nkind (Parent (T)) = N_Subtype_Declaration
6314 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
6315 and then
6316 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
6317 then
6318 return Any_Type;
6320 else
6321 Inst := Scope (T);
6323 if Is_Wrapper_Package (Inst) then
6324 Inst := Related_Instance (Inst);
6325 end if;
6327 Gen :=
6328 Generic_Parent
6329 (Specification (Unit_Declaration_Node (Inst)));
6331 -- Generic actual has the same name as the corresponding formal
6333 Typ := First_Entity (Gen);
6334 while Present (Typ) loop
6335 if Chars (Typ) = Chars (T) then
6336 return Typ;
6337 end if;
6339 Next_Entity (Typ);
6340 end loop;
6342 return Any_Type;
6343 end if;
6344 end Corresponding_Generic_Type;
6346 --------------------------------
6347 -- Corresponding_Primitive_Op --
6348 --------------------------------
6350 function Corresponding_Primitive_Op
6351 (Ancestor_Op : Entity_Id;
6352 Descendant_Type : Entity_Id) return Entity_Id
6354 function Find_Untagged_Type_Of (Prim : Entity_Id) return Entity_Id;
6355 -- Search for the untagged type of the primitive operation Prim.
6357 function Profile_Matches_Ancestor (S : Entity_Id) return Boolean;
6358 -- Returns True if subprogram S has the proper profile for an
6359 -- overriding of Ancestor_Op (that is, corresponding formals either
6360 -- have the same type, or are corresponding controlling formals,
6361 -- and similarly for result types).
6363 ---------------------------
6364 -- Find_Untagged_Type_Of --
6365 ---------------------------
6367 function Find_Untagged_Type_Of (Prim : Entity_Id) return Entity_Id is
6368 E : Entity_Id := First_Entity (Scope (Prim));
6370 begin
6371 while Present (E) and then E /= Prim loop
6372 if not Is_Tagged_Type (E)
6373 and then Contains (Direct_Primitive_Operations (E), Prim)
6374 then
6375 return E;
6376 end if;
6378 Next_Entity (E);
6379 end loop;
6381 pragma Assert (False);
6382 return Empty;
6383 end Find_Untagged_Type_Of;
6385 Typ : constant Entity_Id :=
6386 (if Is_Dispatching_Operation (Ancestor_Op)
6387 then Find_Dispatching_Type (Ancestor_Op)
6388 else Find_Untagged_Type_Of (Ancestor_Op));
6390 ------------------------------
6391 -- Profile_Matches_Ancestor --
6392 ------------------------------
6394 function Profile_Matches_Ancestor (S : Entity_Id) return Boolean is
6395 F1 : Entity_Id := First_Formal (Ancestor_Op);
6396 F2 : Entity_Id := First_Formal (S);
6398 begin
6399 if Ekind (Ancestor_Op) /= Ekind (S) then
6400 return False;
6401 end if;
6403 -- ??? This should probably account for anonymous access formals,
6404 -- but the parent function (Corresponding_Primitive_Op) is currently
6405 -- only called for user-defined literal functions, which can't have
6406 -- such formals. But if this is ever used in a more general context
6407 -- it should be extended to handle such formals (and result types).
6409 while Present (F1) and then Present (F2) loop
6410 if Etype (F1) = Etype (F2)
6411 or else Is_Ancestor (Typ, Etype (F2))
6412 then
6413 Next_Formal (F1);
6414 Next_Formal (F2);
6415 else
6416 return False;
6417 end if;
6418 end loop;
6420 return No (F1)
6421 and then No (F2)
6422 and then (Etype (Ancestor_Op) = Etype (S)
6423 or else Is_Ancestor (Typ, Etype (S)));
6424 end Profile_Matches_Ancestor;
6426 -- Local variables
6428 Elmt : Elmt_Id;
6429 Subp : Entity_Id;
6431 -- Start of processing for Corresponding_Primitive_Op
6433 begin
6434 pragma Assert (Is_Ancestor (Typ, Descendant_Type)
6435 or else Is_Progenitor (Typ, Descendant_Type));
6437 Elmt := First_Elmt (Primitive_Operations (Descendant_Type));
6439 while Present (Elmt) loop
6440 Subp := Node (Elmt);
6442 -- For regular primitives we need to check the profile against
6443 -- the ancestor when the name matches the name of Ancestor_Op,
6444 -- but for predefined dispatching operations we cannot rely on
6445 -- the name of the primitive to identify a candidate since their
6446 -- name is internally built by adding a suffix to the name of the
6447 -- tagged type.
6449 if Chars (Subp) = Chars (Ancestor_Op)
6450 or else Is_Predefined_Dispatching_Operation (Subp)
6451 then
6452 -- Handle case where Ancestor_Op is a primitive of a progenitor.
6453 -- We rely on internal entities that map interface primitives:
6454 -- their attribute Interface_Alias references the interface
6455 -- primitive, and their Alias attribute references the primitive
6456 -- of Descendant_Type implementing that interface primitive.
6458 if Present (Interface_Alias (Subp)) then
6459 if Interface_Alias (Subp) = Ancestor_Op then
6460 return Alias (Subp);
6461 end if;
6463 -- Otherwise, return subprogram when profile matches its ancestor
6465 elsif Profile_Matches_Ancestor (Subp) then
6466 return Subp;
6467 end if;
6468 end if;
6470 Next_Elmt (Elmt);
6471 end loop;
6473 pragma Assert (False);
6474 return Empty;
6475 end Corresponding_Primitive_Op;
6477 --------------------
6478 -- Current_Entity --
6479 --------------------
6481 -- The currently visible definition for a given identifier is the
6482 -- one most chained at the start of the visibility chain, i.e. the
6483 -- one that is referenced by the Node_Id value of the name of the
6484 -- given identifier.
6486 function Current_Entity (N : Node_Id) return Entity_Id is
6487 begin
6488 return Get_Name_Entity_Id (Chars (N));
6489 end Current_Entity;
6491 -----------------------------
6492 -- Current_Entity_In_Scope --
6493 -----------------------------
6495 function Current_Entity_In_Scope (N : Name_Id) return Entity_Id is
6496 CS : constant Entity_Id := Current_Scope;
6498 E : Entity_Id;
6500 begin
6501 E := Get_Name_Entity_Id (N);
6503 if No (E) then
6504 null;
6506 elsif Scope_Is_Transient then
6507 while Present (E) loop
6508 exit when Scope (E) = CS or else Scope (E) = Scope (CS);
6510 E := Homonym (E);
6511 end loop;
6513 else
6514 while Present (E) loop
6515 exit when Scope (E) = CS;
6517 E := Homonym (E);
6518 end loop;
6519 end if;
6521 return E;
6522 end Current_Entity_In_Scope;
6524 -----------------------------
6525 -- Current_Entity_In_Scope --
6526 -----------------------------
6528 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
6529 begin
6530 return Current_Entity_In_Scope (Chars (N));
6531 end Current_Entity_In_Scope;
6533 -------------------
6534 -- Current_Scope --
6535 -------------------
6537 function Current_Scope return Entity_Id is
6538 begin
6539 if Scope_Stack.Last = -1 then
6540 return Standard_Standard;
6541 else
6542 declare
6543 C : constant Entity_Id :=
6544 Scope_Stack.Table (Scope_Stack.Last).Entity;
6545 begin
6546 if Present (C) then
6547 return C;
6548 else
6549 return Standard_Standard;
6550 end if;
6551 end;
6552 end if;
6553 end Current_Scope;
6555 ----------------------------
6556 -- Current_Scope_No_Loops --
6557 ----------------------------
6559 function Current_Scope_No_Loops return Entity_Id is
6560 S : Entity_Id;
6562 begin
6563 -- Examine the scope stack starting from the current scope and skip any
6564 -- internally generated loops.
6566 S := Current_Scope;
6567 while Present (S) and then S /= Standard_Standard loop
6568 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
6569 S := Scope (S);
6570 else
6571 exit;
6572 end if;
6573 end loop;
6575 return S;
6576 end Current_Scope_No_Loops;
6578 ------------------------
6579 -- Current_Subprogram --
6580 ------------------------
6582 function Current_Subprogram return Entity_Id is
6583 Scop : constant Entity_Id := Current_Scope;
6584 begin
6585 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
6586 return Scop;
6587 else
6588 return Enclosing_Subprogram (Scop);
6589 end if;
6590 end Current_Subprogram;
6592 ------------------------------
6593 -- CW_Or_Needs_Finalization --
6594 ------------------------------
6596 function CW_Or_Needs_Finalization (Typ : Entity_Id) return Boolean is
6597 begin
6598 return Is_Class_Wide_Type (Typ) or else Needs_Finalization (Typ);
6599 end CW_Or_Needs_Finalization;
6601 ---------------------
6602 -- Defining_Entity --
6603 ---------------------
6605 function Defining_Entity (N : Node_Id) return Entity_Id is
6606 Ent : constant Entity_Id := Defining_Entity_Or_Empty (N);
6608 begin
6609 if Present (Ent) then
6610 return Ent;
6612 else
6613 raise Program_Error;
6614 end if;
6615 end Defining_Entity;
6617 ------------------------------
6618 -- Defining_Entity_Or_Empty --
6619 ------------------------------
6621 function Defining_Entity_Or_Empty (N : Node_Id) return Entity_Id is
6622 begin
6623 case Nkind (N) is
6624 when N_Abstract_Subprogram_Declaration
6625 | N_Expression_Function
6626 | N_Formal_Subprogram_Declaration
6627 | N_Generic_Package_Declaration
6628 | N_Generic_Subprogram_Declaration
6629 | N_Package_Declaration
6630 | N_Subprogram_Body
6631 | N_Subprogram_Body_Stub
6632 | N_Subprogram_Declaration
6633 | N_Subprogram_Renaming_Declaration
6635 return Defining_Entity (Specification (N));
6637 when N_Component_Declaration
6638 | N_Defining_Program_Unit_Name
6639 | N_Discriminant_Specification
6640 | N_Entry_Body
6641 | N_Entry_Declaration
6642 | N_Entry_Index_Specification
6643 | N_Exception_Declaration
6644 | N_Exception_Renaming_Declaration
6645 | N_Formal_Object_Declaration
6646 | N_Formal_Package_Declaration
6647 | N_Formal_Type_Declaration
6648 | N_Full_Type_Declaration
6649 | N_Implicit_Label_Declaration
6650 | N_Incomplete_Type_Declaration
6651 | N_Iterator_Specification
6652 | N_Loop_Parameter_Specification
6653 | N_Number_Declaration
6654 | N_Object_Declaration
6655 | N_Object_Renaming_Declaration
6656 | N_Package_Body_Stub
6657 | N_Parameter_Specification
6658 | N_Private_Extension_Declaration
6659 | N_Private_Type_Declaration
6660 | N_Protected_Body
6661 | N_Protected_Body_Stub
6662 | N_Protected_Type_Declaration
6663 | N_Single_Protected_Declaration
6664 | N_Single_Task_Declaration
6665 | N_Subtype_Declaration
6666 | N_Task_Body
6667 | N_Task_Body_Stub
6668 | N_Task_Type_Declaration
6670 return Defining_Identifier (N);
6672 when N_Compilation_Unit =>
6673 return Defining_Entity (Unit (N));
6675 when N_Subunit =>
6676 return Defining_Entity (Proper_Body (N));
6678 when N_Function_Instantiation
6679 | N_Function_Specification
6680 | N_Generic_Function_Renaming_Declaration
6681 | N_Generic_Package_Renaming_Declaration
6682 | N_Generic_Procedure_Renaming_Declaration
6683 | N_Package_Body
6684 | N_Package_Instantiation
6685 | N_Package_Renaming_Declaration
6686 | N_Package_Specification
6687 | N_Procedure_Instantiation
6688 | N_Procedure_Specification
6690 declare
6691 Nam : constant Node_Id := Defining_Unit_Name (N);
6692 Err : Entity_Id := Empty;
6694 begin
6695 if Nkind (Nam) in N_Entity then
6696 return Nam;
6698 -- For Error, make up a name and attach to declaration so we
6699 -- can continue semantic analysis.
6701 elsif Nam = Error then
6702 Err := Make_Temporary (Sloc (N), 'T');
6703 Set_Defining_Unit_Name (N, Err);
6705 return Err;
6707 -- If not an entity, get defining identifier
6709 else
6710 return Defining_Identifier (Nam);
6711 end if;
6712 end;
6714 when N_Block_Statement
6715 | N_Loop_Statement
6717 return Entity (Identifier (N));
6719 when others =>
6720 return Empty;
6721 end case;
6722 end Defining_Entity_Or_Empty;
6724 --------------------------
6725 -- Denotes_Discriminant --
6726 --------------------------
6728 function Denotes_Discriminant
6729 (N : Node_Id;
6730 Check_Concurrent : Boolean := False) return Boolean
6732 E : Entity_Id;
6734 begin
6735 if not Is_Entity_Name (N) or else No (Entity (N)) then
6736 return False;
6737 else
6738 E := Entity (N);
6739 end if;
6741 -- If we are checking for a protected type, the discriminant may have
6742 -- been rewritten as the corresponding discriminal of the original type
6743 -- or of the corresponding concurrent record, depending on whether we
6744 -- are in the spec or body of the protected type.
6746 return Ekind (E) = E_Discriminant
6747 or else
6748 (Check_Concurrent
6749 and then Ekind (E) = E_In_Parameter
6750 and then Present (Discriminal_Link (E))
6751 and then
6752 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
6753 or else
6754 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
6755 end Denotes_Discriminant;
6757 -------------------------
6758 -- Denotes_Same_Object --
6759 -------------------------
6761 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
6762 function Is_Object_Renaming (N : Node_Id) return Boolean;
6763 -- Return true if N names an object renaming entity
6765 function Is_Valid_Renaming (N : Node_Id) return Boolean;
6766 -- For renamings, return False if the prefix of any dereference within
6767 -- the renamed object_name is a variable, or any expression within the
6768 -- renamed object_name contains references to variables or calls on
6769 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6771 ------------------------
6772 -- Is_Object_Renaming --
6773 ------------------------
6775 function Is_Object_Renaming (N : Node_Id) return Boolean is
6776 begin
6777 return Is_Entity_Name (N)
6778 and then Ekind (Entity (N)) in E_Variable | E_Constant
6779 and then Present (Renamed_Object (Entity (N)));
6780 end Is_Object_Renaming;
6782 -----------------------
6783 -- Is_Valid_Renaming --
6784 -----------------------
6786 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6787 begin
6788 if Is_Object_Renaming (N)
6789 and then not Is_Valid_Renaming (Renamed_Object (Entity (N)))
6790 then
6791 return False;
6792 end if;
6794 -- Check if any expression within the renamed object_name contains no
6795 -- references to variables nor calls on nonstatic functions.
6797 if Nkind (N) = N_Indexed_Component then
6798 declare
6799 Indx : Node_Id;
6801 begin
6802 Indx := First (Expressions (N));
6803 while Present (Indx) loop
6804 if not Is_OK_Static_Expression (Indx) then
6805 return False;
6806 end if;
6808 Next (Indx);
6809 end loop;
6810 end;
6812 elsif Nkind (N) = N_Slice then
6813 declare
6814 Rng : constant Node_Id := Discrete_Range (N);
6815 begin
6816 -- Bounds specified as a range
6818 if Nkind (Rng) = N_Range then
6819 if not Is_OK_Static_Range (Rng) then
6820 return False;
6821 end if;
6823 -- Bounds specified as a constrained subtype indication
6825 elsif Nkind (Rng) = N_Subtype_Indication then
6826 if not Is_OK_Static_Range
6827 (Range_Expression (Constraint (Rng)))
6828 then
6829 return False;
6830 end if;
6832 -- Bounds specified as a subtype name
6834 elsif not Is_OK_Static_Expression (Rng) then
6835 return False;
6836 end if;
6837 end;
6838 end if;
6840 if Has_Prefix (N) then
6841 declare
6842 P : constant Node_Id := Prefix (N);
6844 begin
6845 if Nkind (N) = N_Explicit_Dereference
6846 and then Is_Variable (P)
6847 then
6848 return False;
6850 elsif Is_Entity_Name (P)
6851 and then Ekind (Entity (P)) = E_Function
6852 then
6853 return False;
6855 elsif Nkind (P) = N_Function_Call then
6856 return False;
6857 end if;
6859 -- Recursion to continue traversing the prefix of the
6860 -- renaming expression
6862 return Is_Valid_Renaming (P);
6863 end;
6864 end if;
6866 return True;
6867 end Is_Valid_Renaming;
6869 -- Start of processing for Denotes_Same_Object
6871 begin
6872 -- Both names statically denote the same stand-alone object or
6873 -- parameter (RM 6.4.1(6.6/3)).
6875 if Is_Entity_Name (A1)
6876 and then Is_Entity_Name (A2)
6877 and then Entity (A1) = Entity (A2)
6878 then
6879 return True;
6881 -- Both names are selected_components, their prefixes are known to
6882 -- denote the same object, and their selector_names denote the same
6883 -- component (RM 6.4.1(6.7/3)).
6885 elsif Nkind (A1) = N_Selected_Component
6886 and then Nkind (A2) = N_Selected_Component
6887 then
6888 return Denotes_Same_Object (Prefix (A1), Prefix (A2))
6889 and then
6890 Entity (Selector_Name (A1)) = Entity (Selector_Name (A2));
6892 -- Both names are dereferences and the dereferenced names are known to
6893 -- denote the same object (RM 6.4.1(6.8/3)).
6895 elsif Nkind (A1) = N_Explicit_Dereference
6896 and then Nkind (A2) = N_Explicit_Dereference
6897 then
6898 return Denotes_Same_Object (Prefix (A1), Prefix (A2));
6900 -- Both names are indexed_components, their prefixes are known to denote
6901 -- the same object, and each of the pairs of corresponding index values
6902 -- are either both static expressions with the same static value or both
6903 -- names that are known to denote the same object (RM 6.4.1(6.9/3)).
6905 elsif Nkind (A1) = N_Indexed_Component
6906 and then Nkind (A2) = N_Indexed_Component
6907 then
6908 if not Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
6909 return False;
6910 else
6911 declare
6912 Indx1 : Node_Id;
6913 Indx2 : Node_Id;
6915 begin
6916 Indx1 := First (Expressions (A1));
6917 Indx2 := First (Expressions (A2));
6918 while Present (Indx1) loop
6920 -- Indexes must denote the same static value or same object
6922 if Is_OK_Static_Expression (Indx1) then
6923 if not Is_OK_Static_Expression (Indx2) then
6924 return False;
6926 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6927 return False;
6928 end if;
6930 elsif not Denotes_Same_Object (Indx1, Indx2) then
6931 return False;
6932 end if;
6934 Next (Indx1);
6935 Next (Indx2);
6936 end loop;
6938 return True;
6939 end;
6940 end if;
6942 -- Both names are slices, their prefixes are known to denote the same
6943 -- object, and the two slices have statically matching index constraints
6944 -- (RM 6.4.1(6.10/3)).
6946 elsif Nkind (A1) = N_Slice
6947 and then Nkind (A2) = N_Slice
6948 then
6949 if not Denotes_Same_Object (Prefix (A1), Prefix (A2)) then
6950 return False;
6951 else
6952 declare
6953 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6955 begin
6956 Get_Index_Bounds (Discrete_Range (A1), Lo1, Hi1);
6957 Get_Index_Bounds (Discrete_Range (A2), Lo2, Hi2);
6959 -- Check whether bounds are statically identical. There is no
6960 -- attempt to detect partial overlap of slices.
6962 return Is_OK_Static_Expression (Lo1)
6963 and then Is_OK_Static_Expression (Lo2)
6964 and then Is_OK_Static_Expression (Hi1)
6965 and then Is_OK_Static_Expression (Hi2)
6966 and then Expr_Value (Lo1) = Expr_Value (Lo2)
6967 and then Expr_Value (Hi1) = Expr_Value (Hi2);
6968 end;
6969 end if;
6971 -- One of the two names statically denotes a renaming declaration whose
6972 -- renamed object_name is known to denote the same object as the other;
6973 -- the prefix of any dereference within the renamed object_name is not a
6974 -- variable, and any expression within the renamed object_name contains
6975 -- no references to variables nor calls on nonstatic functions (RM
6976 -- 6.4.1(6.11/3)).
6978 elsif Is_Object_Renaming (A1)
6979 and then Is_Valid_Renaming (A1)
6980 then
6981 return Denotes_Same_Object (Renamed_Object (Entity (A1)), A2);
6983 elsif Is_Object_Renaming (A2)
6984 and then Is_Valid_Renaming (A2)
6985 then
6986 return Denotes_Same_Object (A1, Renamed_Object (Entity (A2)));
6988 else
6989 return False;
6990 end if;
6991 end Denotes_Same_Object;
6993 -------------------------
6994 -- Denotes_Same_Prefix --
6995 -------------------------
6997 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6998 begin
6999 if Is_Entity_Name (A1) then
7000 if Nkind (A2) in N_Selected_Component | N_Indexed_Component
7001 and then not Is_Access_Type (Etype (A1))
7002 then
7003 return Denotes_Same_Object (A1, Prefix (A2))
7004 or else Denotes_Same_Prefix (A1, Prefix (A2));
7005 else
7006 return False;
7007 end if;
7009 elsif Is_Entity_Name (A2) then
7010 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
7012 elsif Nkind (A1) in N_Selected_Component | N_Indexed_Component | N_Slice
7013 and then
7014 Nkind (A2) in N_Selected_Component | N_Indexed_Component | N_Slice
7015 then
7016 declare
7017 Root1, Root2 : Node_Id;
7018 Depth1, Depth2 : Nat := 0;
7020 begin
7021 Root1 := Prefix (A1);
7022 while not Is_Entity_Name (Root1) loop
7023 if Nkind (Root1) not in
7024 N_Selected_Component | N_Indexed_Component
7025 then
7026 return False;
7027 else
7028 Root1 := Prefix (Root1);
7029 end if;
7031 Depth1 := Depth1 + 1;
7032 end loop;
7034 Root2 := Prefix (A2);
7035 while not Is_Entity_Name (Root2) loop
7036 if Nkind (Root2) not in
7037 N_Selected_Component | N_Indexed_Component
7038 then
7039 return False;
7040 else
7041 Root2 := Prefix (Root2);
7042 end if;
7044 Depth2 := Depth2 + 1;
7045 end loop;
7047 -- If both have the same depth and they do not denote the same
7048 -- object, they are disjoint and no warning is needed.
7050 if Depth1 = Depth2 then
7051 return False;
7053 elsif Depth1 > Depth2 then
7054 Root1 := Prefix (A1);
7055 for J in 1 .. Depth1 - Depth2 - 1 loop
7056 Root1 := Prefix (Root1);
7057 end loop;
7059 return Denotes_Same_Object (Root1, A2);
7061 else
7062 Root2 := Prefix (A2);
7063 for J in 1 .. Depth2 - Depth1 - 1 loop
7064 Root2 := Prefix (Root2);
7065 end loop;
7067 return Denotes_Same_Object (A1, Root2);
7068 end if;
7069 end;
7071 else
7072 return False;
7073 end if;
7074 end Denotes_Same_Prefix;
7076 ----------------------
7077 -- Denotes_Variable --
7078 ----------------------
7080 function Denotes_Variable (N : Node_Id) return Boolean is
7081 begin
7082 return Is_Variable (N) and then Paren_Count (N) = 0;
7083 end Denotes_Variable;
7085 -----------------------------
7086 -- Depends_On_Discriminant --
7087 -----------------------------
7089 function Depends_On_Discriminant (N : Node_Id) return Boolean is
7090 L : Node_Id;
7091 H : Node_Id;
7093 begin
7094 Get_Index_Bounds (N, L, H);
7095 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
7096 end Depends_On_Discriminant;
7098 -------------------------------------
7099 -- Derivation_Too_Early_To_Inherit --
7100 -------------------------------------
7102 function Derivation_Too_Early_To_Inherit
7103 (Typ : Entity_Id; Streaming_Op : TSS_Name_Type) return Boolean is
7105 Btyp : constant Entity_Id := Implementation_Base_Type (Typ);
7106 Parent_Type : Entity_Id;
7108 Real_Rep : Node_Id;
7110 -- Start of processing for Derivation_Too_Early_To_Inherit
7112 begin
7113 if Is_Derived_Type (Btyp) then
7114 Parent_Type := Implementation_Base_Type (Etype (Btyp));
7115 pragma Assert (Parent_Type /= Btyp);
7117 if Has_Stream_Attribute_Definition
7118 (Parent_Type, Streaming_Op, Real_Rep => Real_Rep)
7120 and then In_Same_Extended_Unit (Btyp, Parent_Type)
7121 and then Instantiation (Get_Source_File_Index (Sloc (Btyp))) =
7122 Instantiation (Get_Source_File_Index (Sloc (Parent_Type)))
7123 then
7124 return Earlier_In_Extended_Unit (Btyp, Real_Rep);
7125 end if;
7126 end if;
7128 return False;
7129 end Derivation_Too_Early_To_Inherit;
7131 -------------------------
7132 -- Designate_Same_Unit --
7133 -------------------------
7135 function Designate_Same_Unit
7136 (Name1 : Node_Id;
7137 Name2 : Node_Id) return Boolean
7139 K1 : constant Node_Kind := Nkind (Name1);
7140 K2 : constant Node_Kind := Nkind (Name2);
7142 function Prefix_Node (N : Node_Id) return Node_Id;
7143 -- Returns the parent unit name node of a defining program unit name
7144 -- or the prefix if N is a selected component or an expanded name.
7146 function Select_Node (N : Node_Id) return Node_Id;
7147 -- Returns the defining identifier node of a defining program unit
7148 -- name or the selector node if N is a selected component or an
7149 -- expanded name.
7151 -----------------
7152 -- Prefix_Node --
7153 -----------------
7155 function Prefix_Node (N : Node_Id) return Node_Id is
7156 begin
7157 if Nkind (N) = N_Defining_Program_Unit_Name then
7158 return Name (N);
7159 else
7160 return Prefix (N);
7161 end if;
7162 end Prefix_Node;
7164 -----------------
7165 -- Select_Node --
7166 -----------------
7168 function Select_Node (N : Node_Id) return Node_Id is
7169 begin
7170 if Nkind (N) = N_Defining_Program_Unit_Name then
7171 return Defining_Identifier (N);
7172 else
7173 return Selector_Name (N);
7174 end if;
7175 end Select_Node;
7177 -- Start of processing for Designate_Same_Unit
7179 begin
7180 if K1 in N_Identifier | N_Defining_Identifier
7181 and then
7182 K2 in N_Identifier | N_Defining_Identifier
7183 then
7184 return Chars (Name1) = Chars (Name2);
7186 elsif K1 in N_Expanded_Name
7187 | N_Selected_Component
7188 | N_Defining_Program_Unit_Name
7189 and then
7190 K2 in N_Expanded_Name
7191 | N_Selected_Component
7192 | N_Defining_Program_Unit_Name
7193 then
7194 return
7195 Chars (Select_Node (Name1)) = Chars (Select_Node (Name2))
7196 and then
7197 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
7199 else
7200 return False;
7201 end if;
7202 end Designate_Same_Unit;
7204 ---------------------------------------------
7205 -- Diagnose_Iterated_Component_Association --
7206 ---------------------------------------------
7208 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
7209 Def_Id : constant Entity_Id := Defining_Identifier (N);
7210 Aggr : Node_Id;
7212 begin
7213 -- Determine whether the iterated component association appears within
7214 -- an aggregate. If this is the case, raise Program_Error because the
7215 -- iterated component association cannot be left in the tree as is and
7216 -- must always be processed by the related aggregate.
7218 Aggr := N;
7219 while Present (Aggr) loop
7220 if Nkind (Aggr) = N_Aggregate then
7221 raise Program_Error;
7223 -- Prevent the search from going too far
7225 elsif Is_Body_Or_Package_Declaration (Aggr) then
7226 exit;
7227 end if;
7229 Aggr := Parent (Aggr);
7230 end loop;
7232 -- At this point it is known that the iterated component association is
7233 -- not within an aggregate. This is really a quantified expression with
7234 -- a missing "all" or "some" quantifier.
7236 Error_Msg_N ("missing quantifier", Def_Id);
7238 -- Rewrite the iterated component association as True to prevent any
7239 -- cascaded errors.
7241 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
7242 Analyze (N);
7243 end Diagnose_Iterated_Component_Association;
7245 ------------------------
7246 -- Discriminated_Size --
7247 ------------------------
7249 function Discriminated_Size (Comp : Entity_Id) return Boolean is
7250 function Non_Static_Bound (Bound : Node_Id) return Boolean;
7251 -- Check whether the bound of an index is non-static and does denote
7252 -- a discriminant, in which case any object of the type (protected or
7253 -- otherwise) will have a non-static size.
7255 ----------------------
7256 -- Non_Static_Bound --
7257 ----------------------
7259 function Non_Static_Bound (Bound : Node_Id) return Boolean is
7260 begin
7261 if Is_OK_Static_Expression (Bound) then
7262 return False;
7264 -- If the bound is given by a discriminant it is non-static
7265 -- (A static constraint replaces the reference with the value).
7266 -- In an protected object the discriminant has been replaced by
7267 -- the corresponding discriminal within the protected operation.
7269 elsif Is_Entity_Name (Bound)
7270 and then
7271 (Ekind (Entity (Bound)) = E_Discriminant
7272 or else Present (Discriminal_Link (Entity (Bound))))
7273 then
7274 return False;
7276 else
7277 return True;
7278 end if;
7279 end Non_Static_Bound;
7281 -- Local variables
7283 Typ : constant Entity_Id := Etype (Comp);
7284 Index : Node_Id;
7286 -- Start of processing for Discriminated_Size
7288 begin
7289 if not Is_Array_Type (Typ) then
7290 return False;
7291 end if;
7293 if Ekind (Typ) = E_Array_Subtype then
7294 Index := First_Index (Typ);
7295 while Present (Index) loop
7296 if Non_Static_Bound (Low_Bound (Index))
7297 or else Non_Static_Bound (High_Bound (Index))
7298 then
7299 return False;
7300 end if;
7302 Next_Index (Index);
7303 end loop;
7305 return True;
7306 end if;
7308 return False;
7309 end Discriminated_Size;
7311 -----------------------------
7312 -- Effective_Reads_Enabled --
7313 -----------------------------
7315 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
7316 begin
7317 return Has_Enabled_Property (Id, Name_Effective_Reads);
7318 end Effective_Reads_Enabled;
7320 ------------------------------
7321 -- Effective_Writes_Enabled --
7322 ------------------------------
7324 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
7325 begin
7326 return Has_Enabled_Property (Id, Name_Effective_Writes);
7327 end Effective_Writes_Enabled;
7329 ------------------------------
7330 -- Enclosing_Comp_Unit_Node --
7331 ------------------------------
7333 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
7334 Current_Node : Node_Id;
7336 begin
7337 Current_Node := N;
7338 while Present (Current_Node)
7339 and then Nkind (Current_Node) /= N_Compilation_Unit
7340 loop
7341 Current_Node := Parent (Current_Node);
7342 end loop;
7344 return Current_Node;
7345 end Enclosing_Comp_Unit_Node;
7347 --------------------------
7348 -- Enclosing_CPP_Parent --
7349 --------------------------
7351 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
7352 Parent_Typ : Entity_Id := Typ;
7354 begin
7355 while not Is_CPP_Class (Parent_Typ)
7356 and then Etype (Parent_Typ) /= Parent_Typ
7357 loop
7358 Parent_Typ := Etype (Parent_Typ);
7360 if Is_Private_Type (Parent_Typ) then
7361 Parent_Typ := Full_View (Base_Type (Parent_Typ));
7362 end if;
7363 end loop;
7365 pragma Assert (Is_CPP_Class (Parent_Typ));
7366 return Parent_Typ;
7367 end Enclosing_CPP_Parent;
7369 ---------------------------
7370 -- Enclosing_Declaration --
7371 ---------------------------
7373 function Enclosing_Declaration (N : Node_Id) return Node_Id is
7374 Decl : Node_Id := N;
7376 begin
7377 while Present (Decl)
7378 and then not (Nkind (Decl) in N_Declaration
7379 or else
7380 Nkind (Decl) in N_Later_Decl_Item
7381 or else
7382 Nkind (Decl) in N_Renaming_Declaration
7383 or else
7384 Nkind (Decl) = N_Number_Declaration)
7385 loop
7386 Decl := Parent (Decl);
7387 end loop;
7389 return Decl;
7390 end Enclosing_Declaration;
7392 ----------------------------------------
7393 -- Enclosing_Declaration_Or_Statement --
7394 ----------------------------------------
7396 function Enclosing_Declaration_Or_Statement
7397 (N : Node_Id) return Node_Id
7399 Par : Node_Id;
7401 begin
7402 Par := N;
7403 while Present (Par) loop
7404 if Is_Declaration (Par) or else Is_Statement (Par) then
7405 return Par;
7407 -- Prevent the search from going too far
7409 elsif Is_Body_Or_Package_Declaration (Par) then
7410 exit;
7411 end if;
7413 Par := Parent (Par);
7414 end loop;
7416 return N;
7417 end Enclosing_Declaration_Or_Statement;
7419 ----------------------------
7420 -- Enclosing_Generic_Body --
7421 ----------------------------
7423 function Enclosing_Generic_Body (N : Node_Id) return Node_Id is
7424 Par : Node_Id;
7425 Spec_Id : Entity_Id;
7427 begin
7428 Par := Parent (N);
7429 while Present (Par) loop
7430 if Nkind (Par) in N_Package_Body | N_Subprogram_Body then
7431 Spec_Id := Corresponding_Spec (Par);
7433 if Present (Spec_Id)
7434 and then Nkind (Unit_Declaration_Node (Spec_Id)) in
7435 N_Generic_Declaration
7436 then
7437 return Par;
7438 end if;
7439 end if;
7441 Par := Parent (Par);
7442 end loop;
7444 return Empty;
7445 end Enclosing_Generic_Body;
7447 ----------------------------
7448 -- Enclosing_Generic_Unit --
7449 ----------------------------
7451 function Enclosing_Generic_Unit (N : Node_Id) return Node_Id is
7452 Par : Node_Id;
7453 Spec_Decl : Node_Id;
7454 Spec_Id : Entity_Id;
7456 begin
7457 Par := Parent (N);
7458 while Present (Par) loop
7459 if Nkind (Par) in N_Generic_Declaration then
7460 return Par;
7462 elsif Nkind (Par) in N_Package_Body | N_Subprogram_Body then
7463 Spec_Id := Corresponding_Spec (Par);
7465 if Present (Spec_Id) then
7466 Spec_Decl := Unit_Declaration_Node (Spec_Id);
7468 if Nkind (Spec_Decl) in N_Generic_Declaration then
7469 return Spec_Decl;
7470 end if;
7471 end if;
7472 end if;
7474 Par := Parent (Par);
7475 end loop;
7477 return Empty;
7478 end Enclosing_Generic_Unit;
7480 -------------------
7481 -- Enclosing_HSS --
7482 -------------------
7484 function Enclosing_HSS (Stmt : Node_Id) return Node_Id is
7485 Par : Node_Id;
7486 begin
7487 pragma Assert (Is_Statement (Stmt));
7489 Par := Parent (Stmt);
7490 while Present (Par) loop
7492 if Nkind (Par) = N_Handled_Sequence_Of_Statements then
7493 return Par;
7495 -- Prevent the search from going too far
7497 elsif Is_Body_Or_Package_Declaration (Par) then
7498 return Empty;
7500 end if;
7502 Par := Parent (Par);
7503 end loop;
7505 return Par;
7506 end Enclosing_HSS;
7508 -------------------------------
7509 -- Enclosing_Lib_Unit_Entity --
7510 -------------------------------
7512 function Enclosing_Lib_Unit_Entity
7513 (E : Entity_Id := Current_Scope) return Entity_Id
7515 Unit_Entity : Entity_Id;
7517 begin
7518 -- Look for enclosing library unit entity by following scope links.
7519 -- Equivalent to, but faster than indexing through the scope stack.
7521 Unit_Entity := E;
7522 while (Present (Scope (Unit_Entity))
7523 and then Scope (Unit_Entity) /= Standard_Standard)
7524 and not Is_Child_Unit (Unit_Entity)
7525 loop
7526 Unit_Entity := Scope (Unit_Entity);
7527 end loop;
7529 return Unit_Entity;
7530 end Enclosing_Lib_Unit_Entity;
7532 -----------------------------
7533 -- Enclosing_Lib_Unit_Node --
7534 -----------------------------
7536 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
7537 Encl_Unit : Node_Id;
7539 begin
7540 Encl_Unit := Enclosing_Comp_Unit_Node (N);
7541 while Present (Encl_Unit)
7542 and then Nkind (Unit (Encl_Unit)) = N_Subunit
7543 loop
7544 Encl_Unit := Library_Unit (Encl_Unit);
7545 end loop;
7547 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
7548 return Encl_Unit;
7549 end Enclosing_Lib_Unit_Node;
7551 -----------------------
7552 -- Enclosing_Package --
7553 -----------------------
7555 function Enclosing_Package (N : Node_Or_Entity_Id) return Entity_Id is
7556 Dynamic_Scope : Entity_Id;
7558 begin
7559 -- Obtain the enclosing scope when N is a Node_Id - taking care to
7560 -- handle the case when the enclosing scope is already a package.
7562 if Nkind (N) not in N_Entity then
7563 declare
7564 Encl_Scop : constant Entity_Id := Find_Enclosing_Scope (N);
7565 begin
7566 if No (Encl_Scop) then
7567 return Empty;
7568 elsif Ekind (Encl_Scop) in
7569 E_Generic_Package | E_Package | E_Package_Body
7570 then
7571 return Encl_Scop;
7572 end if;
7574 return Enclosing_Package (Encl_Scop);
7575 end;
7576 end if;
7578 -- When N is already an Entity_Id proceed
7580 Dynamic_Scope := Enclosing_Dynamic_Scope (N);
7581 if Dynamic_Scope = Standard_Standard then
7582 return Standard_Standard;
7584 elsif Dynamic_Scope = Empty then
7585 return Empty;
7587 elsif Ekind (Dynamic_Scope) in
7588 E_Generic_Package | E_Package | E_Package_Body
7589 then
7590 return Dynamic_Scope;
7592 else
7593 return Enclosing_Package (Dynamic_Scope);
7594 end if;
7595 end Enclosing_Package;
7597 -------------------------------------
7598 -- Enclosing_Package_Or_Subprogram --
7599 -------------------------------------
7601 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
7602 S : Entity_Id;
7604 begin
7605 S := Scope (E);
7606 while Present (S) loop
7607 if Is_Package_Or_Generic_Package (S)
7608 or else Is_Subprogram_Or_Generic_Subprogram (S)
7609 then
7610 return S;
7612 else
7613 S := Scope (S);
7614 end if;
7615 end loop;
7617 return Empty;
7618 end Enclosing_Package_Or_Subprogram;
7620 --------------------------
7621 -- Enclosing_Subprogram --
7622 --------------------------
7624 function Enclosing_Subprogram (N : Node_Or_Entity_Id) return Entity_Id is
7625 Dyn_Scop : Entity_Id;
7626 Encl_Scop : Entity_Id;
7628 begin
7629 -- Obtain the enclosing scope when N is a Node_Id - taking care to
7630 -- handle the case when the enclosing scope is already a subprogram.
7632 if Nkind (N) not in N_Entity then
7633 Encl_Scop := Find_Enclosing_Scope (N);
7635 if No (Encl_Scop) then
7636 return Empty;
7637 elsif Ekind (Encl_Scop) in Subprogram_Kind then
7638 return Encl_Scop;
7639 end if;
7641 return Enclosing_Subprogram (Encl_Scop);
7642 end if;
7644 -- When N is already an Entity_Id proceed
7646 Dyn_Scop := Enclosing_Dynamic_Scope (N);
7647 if Dyn_Scop = Standard_Standard then
7648 return Empty;
7650 elsif Dyn_Scop = Empty then
7651 return Empty;
7653 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
7654 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
7656 elsif Ekind (Dyn_Scop) in E_Block | E_Loop | E_Return_Statement then
7657 return Enclosing_Subprogram (Dyn_Scop);
7659 elsif Ekind (Dyn_Scop) in E_Entry | E_Entry_Family then
7661 -- For a task entry or entry family, return the enclosing subprogram
7662 -- of the task itself.
7664 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
7665 return Enclosing_Subprogram (Dyn_Scop);
7667 -- A protected entry or entry family is rewritten as a protected
7668 -- procedure which is the desired enclosing subprogram. This is
7669 -- relevant when unnesting a procedure local to an entry body.
7671 else
7672 return Protected_Body_Subprogram (Dyn_Scop);
7673 end if;
7675 elsif Ekind (Dyn_Scop) = E_Task_Type then
7676 return Get_Task_Body_Procedure (Dyn_Scop);
7678 -- The scope may appear as a private type or as a private extension
7679 -- whose completion is a task or protected type.
7681 elsif Ekind (Dyn_Scop) in
7682 E_Limited_Private_Type | E_Record_Type_With_Private
7683 and then Present (Full_View (Dyn_Scop))
7684 and then Ekind (Full_View (Dyn_Scop)) in E_Task_Type | E_Protected_Type
7685 then
7686 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
7688 -- No body is generated if the protected operation is eliminated
7690 elsif not Is_Eliminated (Dyn_Scop)
7691 and then Present (Protected_Body_Subprogram (Dyn_Scop))
7692 then
7693 return Protected_Body_Subprogram (Dyn_Scop);
7695 else
7696 return Dyn_Scop;
7697 end if;
7698 end Enclosing_Subprogram;
7700 --------------------------
7701 -- End_Keyword_Location --
7702 --------------------------
7704 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
7705 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
7706 -- Return the source location of Nod's end label according to the
7707 -- following precedence rules:
7709 -- 1) If the end label exists, return its location
7710 -- 2) If Nod exists, return its location
7711 -- 3) Return the location of N
7713 -------------------
7714 -- End_Label_Loc --
7715 -------------------
7717 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
7718 Label : Node_Id;
7720 begin
7721 if Present (Nod) then
7722 Label := End_Label (Nod);
7724 if Present (Label) then
7725 return Sloc (Label);
7726 else
7727 return Sloc (Nod);
7728 end if;
7730 else
7731 return Sloc (N);
7732 end if;
7733 end End_Label_Loc;
7735 -- Local variables
7737 Owner : Node_Id := Empty;
7739 -- Start of processing for End_Keyword_Location
7741 begin
7742 if Nkind (N) in N_Block_Statement
7743 | N_Entry_Body
7744 | N_Package_Body
7745 | N_Subprogram_Body
7746 | N_Task_Body
7747 then
7748 Owner := Handled_Statement_Sequence (N);
7750 elsif Nkind (N) = N_Package_Declaration then
7751 Owner := Specification (N);
7753 elsif Nkind (N) = N_Protected_Body then
7754 Owner := N;
7756 elsif Nkind (N) in N_Protected_Type_Declaration
7757 | N_Single_Protected_Declaration
7758 then
7759 Owner := Protected_Definition (N);
7761 elsif Nkind (N) in N_Single_Task_Declaration | N_Task_Type_Declaration
7762 then
7763 Owner := Task_Definition (N);
7765 -- This routine should not be called with other contexts
7767 else
7768 pragma Assert (False);
7769 null;
7770 end if;
7772 return End_Label_Loc (Owner);
7773 end End_Keyword_Location;
7775 ------------------------
7776 -- Ensure_Freeze_Node --
7777 ------------------------
7779 procedure Ensure_Freeze_Node (E : Entity_Id) is
7780 FN : Node_Id;
7781 begin
7782 if No (Freeze_Node (E)) then
7783 FN := Make_Freeze_Entity (Sloc (E));
7784 Set_Has_Delayed_Freeze (E);
7785 Set_Freeze_Node (E, FN);
7786 Set_Access_Types_To_Process (FN, No_Elist);
7787 Set_TSS_Elist (FN, No_Elist);
7788 Set_Entity (FN, E);
7789 end if;
7790 end Ensure_Freeze_Node;
7792 ----------------
7793 -- Enter_Name --
7794 ----------------
7796 procedure Enter_Name (Def_Id : Entity_Id) is
7797 C : constant Entity_Id := Current_Entity (Def_Id);
7798 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7799 S : constant Entity_Id := Current_Scope;
7801 begin
7802 Generate_Definition (Def_Id);
7804 -- Add new name to current scope declarations. Check for duplicate
7805 -- declaration, which may or may not be a genuine error.
7807 if Present (E) then
7809 -- Case of previous entity entered because of a missing declaration
7810 -- or else a bad subtype indication. Best is to use the new entity,
7811 -- and make the previous one invisible.
7813 if Etype (E) = Any_Type then
7814 Set_Is_Immediately_Visible (E, False);
7816 -- Case of renaming declaration constructed for package instances.
7817 -- if there is an explicit declaration with the same identifier,
7818 -- the renaming is not immediately visible any longer, but remains
7819 -- visible through selected component notation.
7821 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7822 and then not Comes_From_Source (E)
7823 then
7824 Set_Is_Immediately_Visible (E, False);
7826 -- The new entity may be the package renaming, which has the same
7827 -- same name as a generic formal which has been seen already.
7829 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7830 and then not Comes_From_Source (Def_Id)
7831 then
7832 Set_Is_Immediately_Visible (E, False);
7834 -- For a fat pointer corresponding to a remote access to subprogram,
7835 -- we use the same identifier as the RAS type, so that the proper
7836 -- name appears in the stub. This type is only retrieved through
7837 -- the RAS type and never by visibility, and is not added to the
7838 -- visibility list (see below).
7840 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7841 and then Ekind (Def_Id) = E_Record_Type
7842 and then Present (Corresponding_Remote_Type (Def_Id))
7843 then
7844 null;
7846 -- Case of an implicit operation or derived literal. The new entity
7847 -- hides the implicit one, which is removed from all visibility,
7848 -- i.e. the entity list of its scope, and homonym chain of its name.
7850 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7851 or else Is_Internal (E)
7852 then
7853 declare
7854 Decl : constant Node_Id := Parent (E);
7855 Prev : Entity_Id;
7856 Prev_Vis : Entity_Id;
7858 begin
7859 -- If E is an implicit declaration, it cannot be the first
7860 -- entity in the scope.
7862 Prev := First_Entity (Current_Scope);
7863 while Present (Prev) and then Next_Entity (Prev) /= E loop
7864 Next_Entity (Prev);
7865 end loop;
7867 if No (Prev) then
7869 -- If E is not on the entity chain of the current scope,
7870 -- it is an implicit declaration in the generic formal
7871 -- part of a generic subprogram. When analyzing the body,
7872 -- the generic formals are visible but not on the entity
7873 -- chain of the subprogram. The new entity will become
7874 -- the visible one in the body.
7876 pragma Assert
7877 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7878 null;
7880 else
7881 Link_Entities (Prev, Next_Entity (E));
7883 if No (Next_Entity (Prev)) then
7884 Set_Last_Entity (Current_Scope, Prev);
7885 end if;
7887 if E = Current_Entity (E) then
7888 Prev_Vis := Empty;
7890 else
7891 Prev_Vis := Current_Entity (E);
7892 while Homonym (Prev_Vis) /= E loop
7893 Prev_Vis := Homonym (Prev_Vis);
7894 end loop;
7895 end if;
7897 if Present (Prev_Vis) then
7899 -- Skip E in the visibility chain
7901 Set_Homonym (Prev_Vis, Homonym (E));
7903 else
7904 Set_Name_Entity_Id (Chars (E), Homonym (E));
7905 end if;
7907 -- The inherited operation cannot be retrieved
7908 -- by name, even though it may remain accesssible
7909 -- in some cases involving subprogram bodies without
7910 -- specs appearing in with_clauses..
7912 Set_Is_Immediately_Visible (E, False);
7913 end if;
7914 end;
7916 -- This section of code could use a comment ???
7918 elsif Present (Etype (E))
7919 and then Is_Concurrent_Type (Etype (E))
7920 and then E = Def_Id
7921 then
7922 return;
7924 -- If the homograph is a protected component renaming, it should not
7925 -- be hiding the current entity. Such renamings are treated as weak
7926 -- declarations.
7928 elsif Is_Prival (E) then
7929 Set_Is_Immediately_Visible (E, False);
7931 -- In this case the current entity is a protected component renaming.
7932 -- Perform minimal decoration by setting the scope and return since
7933 -- the prival should not be hiding other visible entities.
7935 elsif Is_Prival (Def_Id) then
7936 Set_Scope (Def_Id, Current_Scope);
7937 return;
7939 -- Analogous to privals, the discriminal generated for an entry index
7940 -- parameter acts as a weak declaration. Perform minimal decoration
7941 -- to avoid bogus errors.
7943 elsif Is_Discriminal (Def_Id)
7944 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7945 then
7946 Set_Scope (Def_Id, Current_Scope);
7947 return;
7949 -- In the body or private part of an instance, a type extension may
7950 -- introduce a component with the same name as that of an actual. The
7951 -- legality rule is not enforced, but the semantics of the full type
7952 -- with two components of same name are not clear at this point???
7954 elsif In_Instance_Not_Visible then
7955 null;
7957 -- When compiling a package body, some child units may have become
7958 -- visible. They cannot conflict with local entities that hide them.
7960 elsif Is_Child_Unit (E)
7961 and then In_Open_Scopes (Scope (E))
7962 and then not Is_Immediately_Visible (E)
7963 then
7964 null;
7966 -- Conversely, with front-end inlining we may compile the parent body
7967 -- first, and a child unit subsequently. The context is now the
7968 -- parent spec, and body entities are not visible.
7970 elsif Is_Child_Unit (Def_Id)
7971 and then Is_Package_Body_Entity (E)
7972 and then not In_Package_Body (Current_Scope)
7973 then
7974 null;
7976 -- Case of genuine duplicate declaration
7978 else
7979 Error_Msg_Sloc := Sloc (E);
7981 -- If the previous declaration is an incomplete type declaration
7982 -- this may be an attempt to complete it with a private type. The
7983 -- following avoids confusing cascaded errors.
7985 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7986 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7987 then
7988 Error_Msg_N
7989 ("incomplete type cannot be completed with a private " &
7990 "declaration", Parent (Def_Id));
7991 Set_Is_Immediately_Visible (E, False);
7992 Set_Full_View (E, Def_Id);
7994 -- An inherited component of a record conflicts with a new
7995 -- discriminant. The discriminant is inserted first in the scope,
7996 -- but the error should be posted on it, not on the component.
7998 elsif Ekind (E) = E_Discriminant
7999 and then Present (Scope (Def_Id))
8000 and then Scope (Def_Id) /= Current_Scope
8001 then
8002 Error_Msg_Sloc := Sloc (Def_Id);
8003 Error_Msg_N ("& conflicts with declaration#", E);
8004 return;
8006 -- If the name of the unit appears in its own context clause, a
8007 -- dummy package with the name has already been created, and the
8008 -- error emitted. Try to continue quietly.
8010 elsif Error_Posted (E)
8011 and then Sloc (E) = No_Location
8012 and then Nkind (Parent (E)) = N_Package_Specification
8013 and then Current_Scope = Standard_Standard
8014 then
8015 Set_Scope (Def_Id, Current_Scope);
8016 return;
8018 else
8019 Error_Msg_N ("& conflicts with declaration#", Def_Id);
8021 -- Avoid cascaded messages with duplicate components in
8022 -- derived types.
8024 if Ekind (E) in E_Component | E_Discriminant then
8025 return;
8026 end if;
8027 end if;
8029 if Nkind (Parent (Parent (Def_Id))) =
8030 N_Generic_Subprogram_Declaration
8031 and then Def_Id =
8032 Defining_Entity (Specification (Parent (Parent (Def_Id))))
8033 then
8034 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
8035 end if;
8037 -- If entity is in standard, then we are in trouble, because it
8038 -- means that we have a library package with a duplicated name.
8039 -- That's hard to recover from, so abort.
8041 if S = Standard_Standard then
8042 raise Unrecoverable_Error;
8044 -- Otherwise we continue with the declaration. Having two
8045 -- identical declarations should not cause us too much trouble.
8047 else
8048 null;
8049 end if;
8050 end if;
8051 end if;
8053 -- If we fall through, declaration is OK, at least OK enough to continue
8055 -- If Def_Id is a discriminant or a record component we are in the midst
8056 -- of inheriting components in a derived record definition. Preserve
8057 -- their Ekind and Etype.
8059 if Ekind (Def_Id) in E_Discriminant | E_Component then
8060 null;
8062 -- If a type is already set, leave it alone (happens when a type
8063 -- declaration is reanalyzed following a call to the optimizer).
8065 elsif Present (Etype (Def_Id)) then
8066 null;
8068 else
8069 Set_Etype (Def_Id, Any_Type); -- avoid cascaded errors
8070 end if;
8072 -- All entities except Itypes are immediately visible
8074 if not Is_Itype (Def_Id) then
8075 Set_Is_Immediately_Visible (Def_Id);
8076 Set_Current_Entity (Def_Id);
8077 end if;
8079 Set_Homonym (Def_Id, C);
8080 Append_Entity (Def_Id, S);
8081 Set_Public_Status (Def_Id);
8083 -- Warn if new entity hides an old one
8085 if Warn_On_Hiding and then Present (C) then
8086 Warn_On_Hiding_Entity (Def_Id, Hidden => C, Visible => Def_Id,
8087 On_Use_Clause => False);
8088 end if;
8089 end Enter_Name;
8091 ---------------
8092 -- Entity_Of --
8093 ---------------
8095 function Entity_Of (N : Node_Id) return Entity_Id is
8096 Id : Entity_Id;
8097 Ren : Node_Id;
8099 begin
8100 -- Assume that the arbitrary node does not have an entity
8102 Id := Empty;
8104 if Is_Entity_Name (N) then
8105 Id := Entity (N);
8107 -- Follow a possible chain of renamings to reach the earliest renamed
8108 -- source object.
8110 while Present (Id)
8111 and then Is_Object (Id)
8112 and then Present (Renamed_Object (Id))
8113 loop
8114 Ren := Renamed_Object (Id);
8116 -- The reference renames an abstract state or a whole object
8118 -- Obj : ...;
8119 -- Ren : ... renames Obj;
8121 if Is_Entity_Name (Ren) then
8123 -- Do not follow a renaming that goes through a generic formal,
8124 -- because these entities are hidden and must not be referenced
8125 -- from outside the generic.
8127 if Is_Hidden (Entity (Ren)) then
8128 exit;
8130 else
8131 Id := Entity (Ren);
8132 end if;
8134 -- The reference renames a function result. Check the original
8135 -- node in case expansion relocates the function call.
8137 -- Ren : ... renames Func_Call;
8139 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
8140 exit;
8142 -- Otherwise the reference renames something which does not yield
8143 -- an abstract state or a whole object. Treat the reference as not
8144 -- having a proper entity for SPARK legality purposes.
8146 else
8147 Id := Empty;
8148 exit;
8149 end if;
8150 end loop;
8151 end if;
8153 return Id;
8154 end Entity_Of;
8156 --------------------------
8157 -- Examine_Array_Bounds --
8158 --------------------------
8160 procedure Examine_Array_Bounds
8161 (Typ : Entity_Id;
8162 All_Static : out Boolean;
8163 Has_Empty : out Boolean)
8165 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
8166 -- Determine whether bound Bound is a suitable static bound
8168 ------------------------
8169 -- Is_OK_Static_Bound --
8170 ------------------------
8172 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
8173 begin
8174 return
8175 not Error_Posted (Bound)
8176 and then Is_OK_Static_Expression (Bound);
8177 end Is_OK_Static_Bound;
8179 -- Local variables
8181 Hi_Bound : Node_Id;
8182 Index : Node_Id;
8183 Lo_Bound : Node_Id;
8185 -- Start of processing for Examine_Array_Bounds
8187 begin
8188 -- An unconstrained array type does not have static bounds, and it is
8189 -- not known whether they are empty or not.
8191 if not Is_Constrained (Typ) then
8192 All_Static := False;
8193 Has_Empty := False;
8195 -- A string literal has static bounds, and is not empty as long as it
8196 -- contains at least one character.
8198 elsif Ekind (Typ) = E_String_Literal_Subtype then
8199 All_Static := True;
8200 Has_Empty := String_Literal_Length (Typ) > 0;
8201 end if;
8203 -- Assume that all bounds are static and not empty
8205 All_Static := True;
8206 Has_Empty := False;
8208 -- Examine each index
8210 Index := First_Index (Typ);
8211 while Present (Index) loop
8212 if Is_Discrete_Type (Etype (Index)) then
8213 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
8215 if Is_OK_Static_Bound (Lo_Bound)
8216 and then
8217 Is_OK_Static_Bound (Hi_Bound)
8218 then
8219 -- The static bounds produce an empty range
8221 if Is_Null_Range (Lo_Bound, Hi_Bound) then
8222 Has_Empty := True;
8223 end if;
8225 -- Otherwise at least one of the bounds is not static
8227 else
8228 All_Static := False;
8229 end if;
8231 -- Otherwise the index is non-discrete, therefore not static
8233 else
8234 All_Static := False;
8235 end if;
8237 Next_Index (Index);
8238 end loop;
8239 end Examine_Array_Bounds;
8241 -------------------
8242 -- Exceptions_OK --
8243 -------------------
8245 function Exceptions_OK return Boolean is
8246 begin
8247 return
8248 not (Restriction_Active (No_Exception_Handlers) or else
8249 Restriction_Active (No_Exception_Propagation) or else
8250 Restriction_Active (No_Exceptions));
8251 end Exceptions_OK;
8253 --------------------------
8254 -- Explain_Limited_Type --
8255 --------------------------
8257 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
8258 C : Entity_Id;
8260 begin
8261 -- For array, component type must be limited
8263 if Is_Array_Type (T) then
8264 Error_Msg_Node_2 := T;
8265 Error_Msg_NE
8266 ("\component type& of type& is limited", N, Component_Type (T));
8267 Explain_Limited_Type (Component_Type (T), N);
8269 elsif Is_Record_Type (T) then
8271 -- No need for extra messages if explicit limited record
8273 if Is_Limited_Record (Base_Type (T)) then
8274 return;
8275 end if;
8277 -- Otherwise find a limited component. Check only components that
8278 -- come from source, or inherited components that appear in the
8279 -- source of the ancestor.
8281 C := First_Component (T);
8282 while Present (C) loop
8283 if Is_Limited_Type (Etype (C))
8284 and then
8285 (Comes_From_Source (C)
8286 or else
8287 (Present (Original_Record_Component (C))
8288 and then
8289 Comes_From_Source (Original_Record_Component (C))))
8290 then
8291 Error_Msg_Node_2 := T;
8292 Error_Msg_NE ("\component& of type& has limited type", N, C);
8293 Explain_Limited_Type (Etype (C), N);
8294 return;
8295 end if;
8297 Next_Component (C);
8298 end loop;
8300 -- The type may be declared explicitly limited, even if no component
8301 -- of it is limited, in which case we fall out of the loop.
8302 return;
8303 end if;
8304 end Explain_Limited_Type;
8306 ---------------------------------------
8307 -- Expression_Of_Expression_Function --
8308 ---------------------------------------
8310 function Expression_Of_Expression_Function
8311 (Subp : Entity_Id) return Node_Id
8313 Expr_Func : Node_Id := Empty;
8315 begin
8316 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
8318 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
8319 N_Expression_Function
8320 then
8321 Expr_Func := Original_Node (Subprogram_Spec (Subp));
8323 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
8324 N_Expression_Function
8325 then
8326 Expr_Func := Original_Node (Subprogram_Body (Subp));
8328 else
8329 pragma Assert (False);
8330 null;
8331 end if;
8333 return Original_Node (Expression (Expr_Func));
8334 end Expression_Of_Expression_Function;
8336 -------------------------------
8337 -- Extensions_Visible_Status --
8338 -------------------------------
8340 function Extensions_Visible_Status
8341 (Id : Entity_Id) return Extensions_Visible_Mode
8343 Arg : Node_Id;
8344 Decl : Node_Id;
8345 Expr : Node_Id;
8346 Prag : Node_Id;
8347 Subp : Entity_Id;
8349 begin
8350 -- When a formal parameter is subject to Extensions_Visible, the pragma
8351 -- is stored in the contract of related subprogram.
8353 if Is_Formal (Id) then
8354 Subp := Scope (Id);
8356 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
8357 Subp := Id;
8359 -- No other construct carries this pragma
8361 else
8362 return Extensions_Visible_None;
8363 end if;
8365 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
8367 -- In certain cases analysis may request the Extensions_Visible status
8368 -- of an expression function before the pragma has been analyzed yet.
8369 -- Inspect the declarative items after the expression function looking
8370 -- for the pragma (if any).
8372 if No (Prag) and then Is_Expression_Function (Subp) then
8373 Decl := Next (Unit_Declaration_Node (Subp));
8374 while Present (Decl) loop
8375 if Nkind (Decl) = N_Pragma
8376 and then Pragma_Name (Decl) = Name_Extensions_Visible
8377 then
8378 Prag := Decl;
8379 exit;
8381 -- A source construct ends the region where Extensions_Visible may
8382 -- appear, stop the traversal. An expanded expression function is
8383 -- no longer a source construct, but it must still be recognized.
8385 elsif Comes_From_Source (Decl)
8386 or else
8387 (Nkind (Decl) in N_Subprogram_Body | N_Subprogram_Declaration
8388 and then Is_Expression_Function (Defining_Entity (Decl)))
8389 then
8390 exit;
8391 end if;
8393 Next (Decl);
8394 end loop;
8395 end if;
8397 -- Extract the value from the Boolean expression (if any)
8399 if Present (Prag) then
8400 Arg := First (Pragma_Argument_Associations (Prag));
8402 if Present (Arg) then
8403 Expr := Get_Pragma_Arg (Arg);
8405 -- When the associated subprogram is an expression function, the
8406 -- argument of the pragma may not have been analyzed.
8408 if not Analyzed (Expr) then
8409 Preanalyze_And_Resolve (Expr, Standard_Boolean);
8410 end if;
8412 -- Guard against cascading errors when the argument of pragma
8413 -- Extensions_Visible is not a valid static Boolean expression.
8415 if Error_Posted (Expr) then
8416 return Extensions_Visible_None;
8418 elsif Is_True (Expr_Value (Expr)) then
8419 return Extensions_Visible_True;
8421 else
8422 return Extensions_Visible_False;
8423 end if;
8425 -- Otherwise the aspect or pragma defaults to True
8427 else
8428 return Extensions_Visible_True;
8429 end if;
8431 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
8432 -- directly specified. In SPARK code, its value defaults to "False".
8434 elsif SPARK_Mode = On then
8435 return Extensions_Visible_False;
8437 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
8438 -- "True".
8440 else
8441 return Extensions_Visible_True;
8442 end if;
8443 end Extensions_Visible_Status;
8445 -----------------
8446 -- Find_Actual --
8447 -----------------
8449 procedure Find_Actual
8450 (N : Node_Id;
8451 Formal : out Entity_Id;
8452 Call : out Node_Id)
8454 Context : constant Node_Id := Parent (N);
8455 Actual : Node_Id;
8456 Call_Nam : Node_Id;
8457 Call_Ent : Node_Id := Empty;
8459 begin
8460 if Nkind (Context) in N_Indexed_Component | N_Selected_Component
8461 and then N = Prefix (Context)
8462 then
8463 Find_Actual (Context, Formal, Call);
8464 return;
8466 elsif Nkind (Context) = N_Parameter_Association
8467 and then N = Explicit_Actual_Parameter (Context)
8468 then
8469 Call := Parent (Context);
8471 elsif Nkind (Context) in N_Entry_Call_Statement
8472 | N_Function_Call
8473 | N_Procedure_Call_Statement
8474 then
8475 Call := Context;
8477 else
8478 Formal := Empty;
8479 Call := Empty;
8480 return;
8481 end if;
8483 -- If we have a call to a subprogram look for the parameter. Note that
8484 -- we exclude overloaded calls, since we don't know enough to be sure
8485 -- of giving the right answer in this case.
8487 if Nkind (Call) in N_Entry_Call_Statement
8488 | N_Function_Call
8489 | N_Procedure_Call_Statement
8490 then
8491 Call_Nam := Name (Call);
8493 -- A call to an entry family may appear as an indexed component
8495 if Nkind (Call_Nam) = N_Indexed_Component then
8496 Call_Nam := Prefix (Call_Nam);
8497 end if;
8499 -- A call to a protected or task entry appears as a selected
8500 -- component rather than an expanded name.
8502 if Nkind (Call_Nam) = N_Selected_Component then
8503 Call_Nam := Selector_Name (Call_Nam);
8504 end if;
8506 -- If Call_Nam is an entity name, get its entity
8508 if Is_Entity_Name (Call_Nam) then
8509 Call_Ent := Entity (Call_Nam);
8511 -- If it is a dereference, get the designated subprogram type
8513 elsif Nkind (Call_Nam) = N_Explicit_Dereference then
8514 declare
8515 Typ : Entity_Id := Etype (Prefix (Call_Nam));
8516 begin
8517 if Present (Full_View (Typ)) then
8518 Typ := Full_View (Typ);
8519 elsif Is_Private_Type (Typ)
8520 and then Present (Underlying_Full_View (Typ))
8521 then
8522 Typ := Underlying_Full_View (Typ);
8523 end if;
8525 if Is_Access_Type (Typ) then
8526 Call_Ent := Directly_Designated_Type (Typ);
8527 else
8528 pragma Assert (Has_Implicit_Dereference (Typ));
8529 Formal := Empty;
8530 Call := Empty;
8531 return;
8532 end if;
8533 end;
8534 end if;
8536 if Present (Call_Ent)
8537 and then (Is_Generic_Subprogram (Call_Ent)
8538 or else Is_Overloadable (Call_Ent)
8539 or else Ekind (Call_Ent) in E_Entry_Family
8540 | E_Subprogram_Body
8541 | E_Subprogram_Type)
8542 and then not Is_Overloaded (Call_Nam)
8543 then
8544 -- If node is name in call it is not an actual
8546 if N = Call_Nam then
8547 Formal := Empty;
8548 Call := Empty;
8549 return;
8550 end if;
8552 -- Fall here if we are definitely a parameter
8554 Actual := First_Actual (Call);
8555 Formal := First_Formal (Call_Ent);
8556 while Present (Formal) and then Present (Actual) loop
8557 if Actual = N then
8558 return;
8560 -- An actual that is the prefix in a prefixed call may have
8561 -- been rewritten in the call. Check if sloc and kinds and
8562 -- names match.
8564 elsif Sloc (Actual) = Sloc (N)
8565 and then Nkind (Actual) = N_Identifier
8566 and then Nkind (Actual) = Nkind (N)
8567 and then Chars (Actual) = Chars (N)
8568 then
8569 return;
8571 else
8572 Next_Actual (Actual);
8573 Next_Formal (Formal);
8574 end if;
8575 end loop;
8576 end if;
8577 end if;
8579 -- Fall through here if we did not find matching actual
8581 Formal := Empty;
8582 Call := Empty;
8583 end Find_Actual;
8585 ---------------------------
8586 -- Find_Body_Discriminal --
8587 ---------------------------
8589 function Find_Body_Discriminal
8590 (Spec_Discriminant : Entity_Id) return Entity_Id
8592 Tsk : Entity_Id;
8593 Disc : Entity_Id;
8595 begin
8596 -- If expansion is suppressed, then the scope can be the concurrent type
8597 -- itself rather than a corresponding concurrent record type.
8599 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
8600 Tsk := Scope (Spec_Discriminant);
8602 else
8603 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
8605 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
8606 end if;
8608 -- Find discriminant of original concurrent type, and use its current
8609 -- discriminal, which is the renaming within the task/protected body.
8611 Disc := First_Discriminant (Tsk);
8612 while Present (Disc) loop
8613 if Chars (Disc) = Chars (Spec_Discriminant) then
8614 return Discriminal (Disc);
8615 end if;
8617 Next_Discriminant (Disc);
8618 end loop;
8620 -- That loop should always succeed in finding a matching entry and
8621 -- returning. Fatal error if not.
8623 raise Program_Error;
8624 end Find_Body_Discriminal;
8626 -------------------------------------
8627 -- Find_Corresponding_Discriminant --
8628 -------------------------------------
8630 function Find_Corresponding_Discriminant
8631 (Id : Node_Id;
8632 Typ : Entity_Id) return Entity_Id
8634 Par_Disc : Entity_Id;
8635 Old_Disc : Entity_Id;
8636 New_Disc : Entity_Id;
8638 begin
8639 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
8641 -- The original type may currently be private, and the discriminant
8642 -- only appear on its full view.
8644 if Is_Private_Type (Scope (Par_Disc))
8645 and then not Has_Discriminants (Scope (Par_Disc))
8646 and then Present (Full_View (Scope (Par_Disc)))
8647 then
8648 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
8649 else
8650 Old_Disc := First_Discriminant (Scope (Par_Disc));
8651 end if;
8653 if Is_Class_Wide_Type (Typ) then
8654 New_Disc := First_Discriminant (Root_Type (Typ));
8655 else
8656 New_Disc := First_Discriminant (Typ);
8657 end if;
8659 while Present (Old_Disc) and then Present (New_Disc) loop
8660 if Old_Disc = Par_Disc then
8661 return New_Disc;
8662 end if;
8664 Next_Discriminant (Old_Disc);
8665 Next_Discriminant (New_Disc);
8666 end loop;
8668 -- Should always find it
8670 raise Program_Error;
8671 end Find_Corresponding_Discriminant;
8673 -------------------
8674 -- Find_DIC_Type --
8675 -------------------
8677 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
8678 Curr_Typ : Entity_Id;
8679 -- The current type being examined in the parent hierarchy traversal
8681 DIC_Typ : Entity_Id;
8682 -- The type which carries the DIC pragma. This variable denotes the
8683 -- partial view when private types are involved.
8685 Par_Typ : Entity_Id;
8686 -- The parent type of the current type. This variable denotes the full
8687 -- view when private types are involved.
8689 begin
8690 -- The input type defines its own DIC pragma, therefore it is the owner
8692 if Has_Own_DIC (Typ) then
8693 DIC_Typ := Typ;
8695 -- Otherwise the DIC pragma is inherited from a parent type
8697 else
8698 pragma Assert (Has_Inherited_DIC (Typ));
8700 -- Climb the parent chain
8702 Curr_Typ := Typ;
8703 loop
8704 -- Inspect the parent type. Do not consider subtypes as they
8705 -- inherit the DIC attributes from their base types.
8707 DIC_Typ := Base_Type (Etype (Curr_Typ));
8709 -- Look at the full view of a private type because the type may
8710 -- have a hidden parent introduced in the full view.
8712 Par_Typ := DIC_Typ;
8714 if Is_Private_Type (Par_Typ)
8715 and then Present (Full_View (Par_Typ))
8716 then
8717 Par_Typ := Full_View (Par_Typ);
8718 end if;
8720 -- Stop the climb once the nearest parent type which defines a DIC
8721 -- pragma of its own is encountered or when the root of the parent
8722 -- chain is reached.
8724 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8726 Curr_Typ := Par_Typ;
8727 end loop;
8728 end if;
8730 return DIC_Typ;
8731 end Find_DIC_Type;
8733 ----------------------------------
8734 -- Find_Enclosing_Iterator_Loop --
8735 ----------------------------------
8737 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8738 Constr : Node_Id;
8739 S : Entity_Id;
8741 begin
8742 -- Traverse the scope chain looking for an iterator loop. Such loops are
8743 -- usually transformed into blocks, hence the use of Original_Node.
8745 S := Id;
8746 while Present (S) and then S /= Standard_Standard loop
8747 if Ekind (S) = E_Loop
8748 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8749 then
8750 Constr := Original_Node (Label_Construct (Parent (S)));
8752 if Nkind (Constr) = N_Loop_Statement
8753 and then Present (Iteration_Scheme (Constr))
8754 and then Nkind (Iterator_Specification
8755 (Iteration_Scheme (Constr))) =
8756 N_Iterator_Specification
8757 then
8758 return S;
8759 end if;
8760 end if;
8762 S := Scope (S);
8763 end loop;
8765 return Empty;
8766 end Find_Enclosing_Iterator_Loop;
8768 --------------------------
8769 -- Find_Enclosing_Scope --
8770 --------------------------
8772 function Find_Enclosing_Scope (N : Node_Id) return Scope_Kind_Id is
8773 Par : Node_Id;
8775 begin
8776 -- If N is an entity, simply return its Scope
8778 if Nkind (N) in N_Entity then
8779 return Scope (N);
8780 end if;
8782 -- Examine the parent chain looking for a construct which defines a
8783 -- scope.
8785 Par := Parent (N);
8786 while Present (Par) loop
8787 case Nkind (Par) is
8789 -- The construct denotes a declaration, the proper scope is its
8790 -- entity.
8792 when N_Entry_Declaration
8793 | N_Expression_Function
8794 | N_Full_Type_Declaration
8795 | N_Generic_Package_Declaration
8796 | N_Generic_Subprogram_Declaration
8797 | N_Package_Declaration
8798 | N_Private_Extension_Declaration
8799 | N_Protected_Type_Declaration
8800 | N_Single_Protected_Declaration
8801 | N_Single_Task_Declaration
8802 | N_Subprogram_Declaration
8803 | N_Task_Type_Declaration
8805 return Defining_Entity (Par);
8807 -- The construct denotes a body, the proper scope is the entity of
8808 -- the corresponding spec or that of the body if the body does not
8809 -- complete a previous declaration.
8811 when N_Entry_Body
8812 | N_Package_Body
8813 | N_Protected_Body
8814 | N_Subprogram_Body
8815 | N_Task_Body
8817 return Unique_Defining_Entity (Par);
8819 -- Special cases
8821 -- Blocks carry either a source or an internally-generated scope,
8822 -- unless the block is a byproduct of exception handling.
8824 when N_Block_Statement =>
8825 if not Exception_Junk (Par) then
8826 return Entity (Identifier (Par));
8827 end if;
8829 -- Loops carry an internally-generated scope
8831 when N_Loop_Statement =>
8832 return Entity (Identifier (Par));
8834 -- Extended return statements carry an internally-generated scope
8836 when N_Extended_Return_Statement =>
8837 return Return_Statement_Entity (Par);
8839 -- A traversal from a subunit continues via the corresponding stub
8841 when N_Subunit =>
8842 Par := Corresponding_Stub (Par);
8844 when others =>
8845 null;
8846 end case;
8848 Par := Parent (Par);
8849 end loop;
8851 return Standard_Standard;
8852 end Find_Enclosing_Scope;
8854 ------------------------------------
8855 -- Find_Loop_In_Conditional_Block --
8856 ------------------------------------
8858 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8859 Stmt : Node_Id;
8861 begin
8862 Stmt := N;
8864 if Nkind (Stmt) = N_If_Statement then
8865 Stmt := First (Then_Statements (Stmt));
8866 end if;
8868 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8870 -- Inspect the statements of the conditional block. In general the loop
8871 -- should be the first statement in the statement sequence of the block,
8872 -- but the finalization machinery may have introduced extra object
8873 -- declarations.
8875 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8876 while Present (Stmt) loop
8877 if Nkind (Stmt) = N_Loop_Statement then
8878 return Stmt;
8879 end if;
8881 Next (Stmt);
8882 end loop;
8884 -- The expansion of attribute 'Loop_Entry produced a malformed block
8886 raise Program_Error;
8887 end Find_Loop_In_Conditional_Block;
8889 --------------------------
8890 -- Find_Overlaid_Entity --
8891 --------------------------
8893 procedure Find_Overlaid_Entity
8894 (N : Node_Id;
8895 Ent : out Entity_Id;
8896 Off : out Boolean)
8898 pragma Assert
8899 (Nkind (N) = N_Attribute_Definition_Clause
8900 and then Chars (N) = Name_Address);
8902 Expr : Node_Id;
8904 begin
8905 -- We are looking for one of the two following forms:
8907 -- for X'Address use Y'Address
8909 -- or
8911 -- Const : constant Address := expr;
8912 -- ...
8913 -- for X'Address use Const;
8915 -- In the second case, the expr is either Y'Address, or recursively a
8916 -- constant that eventually references Y'Address.
8918 Ent := Empty;
8919 Off := False;
8921 Expr := Expression (N);
8923 -- This loop checks the form of the expression for Y'Address, using
8924 -- recursion to deal with intermediate constants.
8926 loop
8927 -- Check for Y'Address
8929 if Nkind (Expr) = N_Attribute_Reference
8930 and then Attribute_Name (Expr) = Name_Address
8931 then
8932 Expr := Prefix (Expr);
8933 exit;
8935 -- Check for Const where Const is a constant entity
8937 elsif Is_Entity_Name (Expr)
8938 and then Ekind (Entity (Expr)) = E_Constant
8939 then
8940 Expr := Constant_Value (Entity (Expr));
8942 -- Anything else does not need checking
8944 else
8945 return;
8946 end if;
8947 end loop;
8949 -- This loop checks the form of the prefix for an entity, using
8950 -- recursion to deal with intermediate components.
8952 loop
8953 -- Check for Y where Y is an entity
8955 if Is_Entity_Name (Expr) then
8956 Ent := Entity (Expr);
8958 -- If expansion is disabled, then we might see an entity of a
8959 -- protected component or of a discriminant of a concurrent unit.
8960 -- Ignore such entities, because further warnings for overlays
8961 -- expect this routine to only collect entities of entire objects.
8963 if Ekind (Ent) in E_Component | E_Discriminant then
8964 pragma Assert
8965 (not Expander_Active
8966 and then Is_Concurrent_Type (Scope (Ent)));
8967 Ent := Empty;
8968 end if;
8969 return;
8971 -- Check for components
8973 elsif Nkind (Expr) in N_Selected_Component | N_Indexed_Component then
8974 Expr := Prefix (Expr);
8975 Off := True;
8977 -- Anything else does not need checking
8979 else
8980 return;
8981 end if;
8982 end loop;
8983 end Find_Overlaid_Entity;
8985 -------------------------
8986 -- Find_Parameter_Type --
8987 -------------------------
8989 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8990 begin
8991 if Nkind (Param) /= N_Parameter_Specification then
8992 return Empty;
8994 -- For an access parameter, obtain the type from the formal entity
8995 -- itself, because access to subprogram nodes do not carry a type.
8996 -- Shouldn't we always use the formal entity ???
8998 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8999 return Etype (Defining_Identifier (Param));
9001 else
9002 return Etype (Parameter_Type (Param));
9003 end if;
9004 end Find_Parameter_Type;
9006 -----------------------------------
9007 -- Find_Placement_In_State_Space --
9008 -----------------------------------
9010 procedure Find_Placement_In_State_Space
9011 (Item_Id : Entity_Id;
9012 Placement : out State_Space_Kind;
9013 Pack_Id : out Entity_Id)
9015 function Inside_Package_Body (Id : Entity_Id) return Boolean;
9016 function Inside_Private_Part (Id : Entity_Id) return Boolean;
9017 -- Return True if Id is declared directly within the package body
9018 -- and the package private parts, respectively. We cannot use
9019 -- In_Private_Part/In_Body_Part flags, as these are only set during the
9020 -- analysis of the package itself, while Find_Placement_In_State_Space
9021 -- can be called on an entity of another package.
9023 ------------------------
9024 -- Inside_Package_Body --
9025 ------------------------
9027 function Inside_Package_Body (Id : Entity_Id) return Boolean is
9028 Spec_Id : constant Entity_Id := Scope (Id);
9029 Body_Decl : constant Opt_N_Package_Body_Id := Package_Body (Spec_Id);
9030 Decl : constant Node_Id := Enclosing_Declaration (Id);
9031 begin
9032 if Present (Body_Decl)
9033 and then Is_List_Member (Decl)
9034 and then List_Containing (Decl) = Declarations (Body_Decl)
9035 then
9036 return True;
9037 else
9038 return False;
9039 end if;
9040 end Inside_Package_Body;
9042 -------------------------
9043 -- Inside_Private_Part --
9044 -------------------------
9046 function Inside_Private_Part (Id : Entity_Id) return Boolean is
9047 Spec_Id : constant Entity_Id := Scope (Id);
9048 Private_Decls : constant List_Id :=
9049 Private_Declarations (Package_Specification (Spec_Id));
9050 Decl : constant Node_Id := Enclosing_Declaration (Id);
9051 begin
9052 if Is_List_Member (Decl)
9053 and then List_Containing (Decl) = Private_Decls
9054 then
9055 return True;
9057 elsif Ekind (Id) = E_Package
9058 and then Is_Private_Library_Unit (Id)
9059 then
9060 return True;
9062 else
9063 return False;
9064 end if;
9065 end Inside_Private_Part;
9067 -- Local variables
9069 Context : Entity_Id;
9071 -- Start of processing for Find_Placement_In_State_Space
9073 begin
9074 -- Assume that the item does not appear in the state space of a package
9076 Placement := Not_In_Package;
9078 -- Climb the scope stack and examine the enclosing context
9080 Context := Item_Id;
9081 Pack_Id := Scope (Context);
9082 while Present (Pack_Id) and then Pack_Id /= Standard_Standard loop
9083 if Is_Package_Or_Generic_Package (Pack_Id) then
9085 -- A package body is a cut off point for the traversal as the
9086 -- item cannot be visible to the outside from this point on.
9088 if Inside_Package_Body (Context) then
9089 Placement := Body_State_Space;
9090 return;
9092 -- The private part of a package is a cut off point for the
9093 -- traversal as the item cannot be visible to the outside
9094 -- from this point on.
9096 elsif Inside_Private_Part (Context) then
9097 Placement := Private_State_Space;
9098 return;
9100 -- When the item appears in the visible state space of a package,
9101 -- continue to climb the scope stack as this may not be the final
9102 -- state space.
9104 else
9105 Placement := Visible_State_Space;
9107 -- The visible state space of a child unit acts as the proper
9108 -- placement of an item, unless this is a private child unit.
9110 if Is_Child_Unit (Pack_Id)
9111 and then not Is_Private_Library_Unit (Pack_Id)
9112 then
9113 return;
9114 end if;
9115 end if;
9117 -- The item or its enclosing package appear in a construct that has
9118 -- no state space.
9120 else
9121 Placement := Not_In_Package;
9122 Pack_Id := Empty;
9123 return;
9124 end if;
9126 Context := Scope (Context);
9127 Pack_Id := Scope (Context);
9128 end loop;
9129 end Find_Placement_In_State_Space;
9131 -----------------------
9132 -- Find_Primitive_Eq --
9133 -----------------------
9135 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
9136 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
9137 -- Search for the equality primitive; return Empty if the primitive is
9138 -- not found.
9140 ------------------
9141 -- Find_Eq_Prim --
9142 ------------------
9144 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
9145 Prim : Entity_Id;
9146 Prim_Elmt : Elmt_Id;
9148 begin
9149 Prim_Elmt := First_Elmt (Prims_List);
9150 while Present (Prim_Elmt) loop
9151 Prim := Node (Prim_Elmt);
9153 -- Locate primitive equality with the right signature
9155 if Chars (Prim) = Name_Op_Eq
9156 and then Etype (First_Formal (Prim)) =
9157 Etype (Next_Formal (First_Formal (Prim)))
9158 and then Base_Type (Etype (Prim)) = Standard_Boolean
9159 then
9160 return Prim;
9161 end if;
9163 Next_Elmt (Prim_Elmt);
9164 end loop;
9166 return Empty;
9167 end Find_Eq_Prim;
9169 -- Local Variables
9171 Eq_Prim : Entity_Id;
9172 Full_Type : Entity_Id;
9174 -- Start of processing for Find_Primitive_Eq
9176 begin
9177 if Is_Private_Type (Typ) then
9178 Full_Type := Underlying_Type (Typ);
9179 else
9180 Full_Type := Typ;
9181 end if;
9183 if No (Full_Type) then
9184 return Empty;
9185 end if;
9187 Full_Type := Base_Type (Full_Type);
9189 -- When the base type itself is private, use the full view
9191 if Is_Private_Type (Full_Type) then
9192 Full_Type := Underlying_Type (Full_Type);
9193 end if;
9195 if Is_Class_Wide_Type (Full_Type) then
9196 Full_Type := Root_Type (Full_Type);
9197 end if;
9199 if not Is_Tagged_Type (Full_Type) then
9200 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
9202 -- If this is an untagged private type completed with a derivation of
9203 -- an untagged private type whose full view is a tagged type, we use
9204 -- the primitive operations of the private parent type (since it does
9205 -- not have a full view, and also because its equality primitive may
9206 -- have been overridden in its untagged full view). If no equality was
9207 -- defined for it then take its dispatching equality primitive.
9209 elsif Inherits_From_Tagged_Full_View (Typ) then
9210 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
9212 if No (Eq_Prim) then
9213 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
9214 end if;
9216 else
9217 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
9218 end if;
9220 return Eq_Prim;
9221 end Find_Primitive_Eq;
9223 ------------------------
9224 -- Find_Specific_Type --
9225 ------------------------
9227 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
9228 Typ : Entity_Id := Root_Type (CW);
9230 begin
9231 if Ekind (Typ) = E_Incomplete_Type then
9232 if From_Limited_With (Typ) then
9233 Typ := Non_Limited_View (Typ);
9234 else
9235 Typ := Full_View (Typ);
9236 end if;
9237 end if;
9239 if Is_Private_Type (Typ)
9240 and then not Is_Tagged_Type (Typ)
9241 and then Present (Full_View (Typ))
9242 then
9243 return Full_View (Typ);
9244 else
9245 return Typ;
9246 end if;
9247 end Find_Specific_Type;
9249 -----------------------------
9250 -- Find_Static_Alternative --
9251 -----------------------------
9253 function Find_Static_Alternative (N : Node_Id) return Node_Id is
9254 Expr : constant Node_Id := Expression (N);
9255 Val : constant Uint := Expr_Value (Expr);
9256 Alt : Node_Id;
9257 Choice : Node_Id;
9259 begin
9260 Alt := First (Alternatives (N));
9262 Search : loop
9263 if Nkind (Alt) /= N_Pragma then
9264 Choice := First (Discrete_Choices (Alt));
9265 while Present (Choice) loop
9267 -- Others choice, always matches
9269 if Nkind (Choice) = N_Others_Choice then
9270 exit Search;
9272 -- Range, check if value is in the range
9274 elsif Nkind (Choice) = N_Range then
9275 exit Search when
9276 Val >= Expr_Value (Low_Bound (Choice))
9277 and then
9278 Val <= Expr_Value (High_Bound (Choice));
9280 -- Choice is a subtype name. Note that we know it must
9281 -- be a static subtype, since otherwise it would have
9282 -- been diagnosed as illegal.
9284 elsif Is_Entity_Name (Choice)
9285 and then Is_Type (Entity (Choice))
9286 then
9287 exit Search when Is_In_Range (Expr, Etype (Choice),
9288 Assume_Valid => False);
9290 -- Choice is a subtype indication
9292 elsif Nkind (Choice) = N_Subtype_Indication then
9293 declare
9294 C : constant Node_Id := Constraint (Choice);
9295 R : constant Node_Id := Range_Expression (C);
9297 begin
9298 exit Search when
9299 Val >= Expr_Value (Low_Bound (R))
9300 and then
9301 Val <= Expr_Value (High_Bound (R));
9302 end;
9304 -- Choice is a simple expression
9306 else
9307 exit Search when Val = Expr_Value (Choice);
9308 end if;
9310 Next (Choice);
9311 end loop;
9312 end if;
9314 Next (Alt);
9315 pragma Assert (Present (Alt));
9316 end loop Search;
9318 -- The above loop *must* terminate by finding a match, since we know the
9319 -- case statement is valid, and the value of the expression is known at
9320 -- compile time. When we fall out of the loop, Alt points to the
9321 -- alternative that we know will be selected at run time.
9323 return Alt;
9324 end Find_Static_Alternative;
9326 ------------------
9327 -- First_Actual --
9328 ------------------
9330 function First_Actual (Node : Node_Id) return Node_Id is
9331 N : Node_Id;
9333 begin
9334 if No (Parameter_Associations (Node)) then
9335 return Empty;
9336 end if;
9338 N := First (Parameter_Associations (Node));
9340 if Nkind (N) = N_Parameter_Association then
9341 return First_Named_Actual (Node);
9342 else
9343 return N;
9344 end if;
9345 end First_Actual;
9347 ------------------
9348 -- First_Global --
9349 ------------------
9351 function First_Global
9352 (Subp : Entity_Id;
9353 Global_Mode : Name_Id;
9354 Refined : Boolean := False) return Node_Id
9356 function First_From_Global_List
9357 (List : Node_Id;
9358 Global_Mode : Name_Id := Name_Input) return Entity_Id;
9359 -- Get the first item with suitable mode from List
9361 ----------------------------
9362 -- First_From_Global_List --
9363 ----------------------------
9365 function First_From_Global_List
9366 (List : Node_Id;
9367 Global_Mode : Name_Id := Name_Input) return Entity_Id
9369 Assoc : Node_Id;
9371 begin
9372 -- Empty list (no global items)
9374 if Nkind (List) = N_Null then
9375 return Empty;
9377 -- Single global item declaration (only input items)
9379 elsif Nkind (List) in N_Expanded_Name | N_Identifier then
9380 if Global_Mode = Name_Input then
9381 return List;
9382 else
9383 return Empty;
9384 end if;
9386 -- Simple global list (only input items) or moded global list
9387 -- declaration.
9389 elsif Nkind (List) = N_Aggregate then
9390 if Present (Expressions (List)) then
9391 if Global_Mode = Name_Input then
9392 return First (Expressions (List));
9393 else
9394 return Empty;
9395 end if;
9397 else
9398 Assoc := First (Component_Associations (List));
9399 while Present (Assoc) loop
9401 -- When we find the desired mode in an association, call
9402 -- recursively First_From_Global_List as if the mode was
9403 -- Name_Input, in order to reuse the existing machinery
9404 -- for the other cases.
9406 if Chars (First (Choices (Assoc))) = Global_Mode then
9407 return First_From_Global_List (Expression (Assoc));
9408 end if;
9410 Next (Assoc);
9411 end loop;
9413 return Empty;
9414 end if;
9416 -- To accommodate partial decoration of disabled SPARK features,
9417 -- this routine may be called with illegal input. If this is the
9418 -- case, do not raise Program_Error.
9420 else
9421 return Empty;
9422 end if;
9423 end First_From_Global_List;
9425 -- Local variables
9427 Global : Node_Id := Empty;
9428 Body_Id : Entity_Id;
9430 -- Start of processing for First_Global
9432 begin
9433 pragma Assert (Global_Mode in Name_In_Out
9434 | Name_Input
9435 | Name_Output
9436 | Name_Proof_In);
9438 -- Retrieve the suitable pragma Global or Refined_Global. In the second
9439 -- case, it can only be located on the body entity.
9441 if Refined then
9442 if Is_Subprogram_Or_Generic_Subprogram (Subp) then
9443 Body_Id := Subprogram_Body_Entity (Subp);
9445 elsif Is_Entry (Subp) or else Is_Task_Type (Subp) then
9446 Body_Id := Corresponding_Body (Parent (Subp));
9448 -- ??? It should be possible to retrieve the Refined_Global on the
9449 -- task body associated to the task object. This is not yet possible.
9451 elsif Is_Single_Task_Object (Subp) then
9452 Body_Id := Empty;
9454 else
9455 Body_Id := Empty;
9456 end if;
9458 if Present (Body_Id) then
9459 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
9460 end if;
9461 else
9462 Global := Get_Pragma (Subp, Pragma_Global);
9463 end if;
9465 -- No corresponding global if pragma is not present
9467 if No (Global) then
9468 return Empty;
9470 -- Otherwise retrieve the corresponding list of items depending on the
9471 -- Global_Mode.
9473 else
9474 return First_From_Global_List
9475 (Expression (Get_Argument (Global, Subp)), Global_Mode);
9476 end if;
9477 end First_Global;
9479 -------------
9480 -- Fix_Msg --
9481 -------------
9483 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
9484 Is_Task : constant Boolean :=
9485 Ekind (Id) in E_Task_Body | E_Task_Type
9486 or else Is_Single_Task_Object (Id);
9487 Msg_Last : constant Natural := Msg'Last;
9488 Msg_Index : Natural;
9489 Res : String (Msg'Range) := (others => ' ');
9490 Res_Index : Natural;
9492 begin
9493 -- Copy all characters from the input message Msg to result Res with
9494 -- suitable replacements.
9496 Msg_Index := Msg'First;
9497 Res_Index := Res'First;
9498 while Msg_Index <= Msg_Last loop
9500 -- Replace "subprogram" with a different word
9502 if Msg_Index <= Msg_Last - 10
9503 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
9504 then
9505 if Is_Entry (Id) then
9506 Res (Res_Index .. Res_Index + 4) := "entry";
9507 Res_Index := Res_Index + 5;
9509 elsif Is_Task then
9510 Res (Res_Index .. Res_Index + 8) := "task type";
9511 Res_Index := Res_Index + 9;
9513 else
9514 Res (Res_Index .. Res_Index + 9) := "subprogram";
9515 Res_Index := Res_Index + 10;
9516 end if;
9518 Msg_Index := Msg_Index + 10;
9520 -- Replace "protected" with a different word
9522 elsif Msg_Index <= Msg_Last - 9
9523 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
9524 and then Is_Task
9525 then
9526 Res (Res_Index .. Res_Index + 3) := "task";
9527 Res_Index := Res_Index + 4;
9528 Msg_Index := Msg_Index + 9;
9530 -- Otherwise copy the character
9532 else
9533 Res (Res_Index) := Msg (Msg_Index);
9534 Msg_Index := Msg_Index + 1;
9535 Res_Index := Res_Index + 1;
9536 end if;
9537 end loop;
9539 return Res (Res'First .. Res_Index - 1);
9540 end Fix_Msg;
9542 -------------------------
9543 -- From_Nested_Package --
9544 -------------------------
9546 function From_Nested_Package (T : Entity_Id) return Boolean is
9547 Pack : constant Entity_Id := Scope (T);
9549 begin
9550 return
9551 Ekind (Pack) = E_Package
9552 and then not Is_Frozen (Pack)
9553 and then not Scope_Within_Or_Same (Current_Scope, Pack)
9554 and then In_Open_Scopes (Scope (Pack));
9555 end From_Nested_Package;
9557 -----------------------
9558 -- Gather_Components --
9559 -----------------------
9561 procedure Gather_Components
9562 (Typ : Entity_Id;
9563 Comp_List : Node_Id;
9564 Governed_By : List_Id;
9565 Into : Elist_Id;
9566 Report_Errors : out Boolean;
9567 Allow_Compile_Time : Boolean := False;
9568 Include_Interface_Tag : Boolean := False)
9570 Assoc : Node_Id;
9571 Variant : Node_Id;
9572 Discrete_Choice : Node_Id;
9573 Comp_Item : Node_Id;
9574 Discrim : Entity_Id;
9575 Discrim_Name : Node_Id;
9577 type Discriminant_Value_Status is
9578 (Static_Expr, Static_Subtype, Bad);
9579 subtype Good_Discrim_Value_Status is Discriminant_Value_Status
9580 range Static_Expr .. Static_Subtype; -- range excludes Bad
9582 Discrim_Value : Node_Id;
9583 Discrim_Value_Subtype : Node_Id;
9584 Discrim_Value_Status : Discriminant_Value_Status := Bad;
9586 function OK_Scope_For_Discrim_Value_Error_Messages return Boolean is
9587 (Scope (Original_Record_Component
9588 (Entity (First (Choices (Assoc))))) = Typ);
9589 -- Used to avoid generating error messages having a source position
9590 -- which refers to somewhere (e.g., a discriminant value in a derived
9591 -- tagged type declaration) unrelated to the offending construct. This
9592 -- is required for correctness - clients of Gather_Components such as
9593 -- Sem_Ch3.Create_Constrained_Components depend on this function
9594 -- returning True while processing semantically correct examples;
9595 -- generating an error message in this case would be wrong.
9597 begin
9598 Report_Errors := False;
9600 if No (Comp_List) or else Null_Present (Comp_List) then
9601 return;
9602 end if;
9604 Comp_Item := First (Component_Items (Comp_List));
9605 while Present (Comp_Item) loop
9607 -- Skip the tag of a tagged record, as well as all items that are not
9608 -- user components (anonymous types, rep clauses, Parent field,
9609 -- controller field).
9611 if Nkind (Comp_Item) = N_Component_Declaration then
9612 declare
9613 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
9614 begin
9615 if not (Is_Tag (Comp)
9616 and then not
9617 (Include_Interface_Tag
9618 and then Etype (Comp) = RTE (RE_Interface_Tag)))
9619 and then Chars (Comp) /= Name_uParent
9620 then
9621 Append_Elmt (Comp, Into);
9622 end if;
9623 end;
9624 end if;
9626 Next (Comp_Item);
9627 end loop;
9629 if No (Variant_Part (Comp_List)) then
9630 return;
9631 else
9632 Discrim_Name := Name (Variant_Part (Comp_List));
9633 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
9634 end if;
9636 -- Look for the discriminant that governs this variant part.
9637 -- The discriminant *must* be in the Governed_By List
9639 Assoc := First (Governed_By);
9640 Find_Constraint : loop
9641 Discrim := First (Choices (Assoc));
9642 pragma Assert (No (Next (Discrim)));
9644 exit Find_Constraint when
9645 Chars (Discrim_Name) = Chars (Discrim)
9646 or else
9647 (Present (Corresponding_Discriminant (Entity (Discrim)))
9648 and then Chars (Corresponding_Discriminant
9649 (Entity (Discrim))) = Chars (Discrim_Name))
9650 or else
9651 Chars (Original_Record_Component (Entity (Discrim))) =
9652 Chars (Discrim_Name);
9654 if No (Next (Assoc)) then
9655 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
9657 -- If the type is a tagged type with inherited discriminants,
9658 -- use the stored constraint on the parent in order to find
9659 -- the values of discriminants that are otherwise hidden by an
9660 -- explicit constraint. Renamed discriminants are handled in
9661 -- the code above.
9663 -- If several parent discriminants are renamed by a single
9664 -- discriminant of the derived type, the call to obtain the
9665 -- Corresponding_Discriminant field only retrieves the last
9666 -- of them. We recover the constraint on the others from the
9667 -- Stored_Constraint as well.
9669 -- An inherited discriminant may have been constrained in a
9670 -- later ancestor (not the immediate parent) so we must examine
9671 -- the stored constraint of all of them to locate the inherited
9672 -- value.
9674 declare
9675 C : Elmt_Id;
9676 D : Entity_Id;
9677 T : Entity_Id := Typ;
9679 begin
9680 while Is_Derived_Type (T) loop
9681 if Present (Stored_Constraint (T)) then
9682 D := First_Discriminant (Etype (T));
9683 C := First_Elmt (Stored_Constraint (T));
9684 while Present (D) and then Present (C) loop
9685 if Chars (Discrim_Name) = Chars (D) then
9686 if Is_Entity_Name (Node (C))
9687 and then Entity (Node (C)) = Entity (Discrim)
9688 then
9689 -- D is renamed by Discrim, whose value is
9690 -- given in Assoc.
9692 null;
9694 else
9695 Assoc :=
9696 Make_Component_Association (Sloc (Typ),
9697 New_List
9698 (New_Occurrence_Of (D, Sloc (Typ))),
9699 Duplicate_Subexpr_No_Checks (Node (C)));
9700 end if;
9702 exit Find_Constraint;
9703 end if;
9705 Next_Discriminant (D);
9706 Next_Elmt (C);
9707 end loop;
9708 end if;
9710 -- Discriminant may be inherited from ancestor
9712 T := Etype (T);
9713 end loop;
9714 end;
9715 end if;
9716 end if;
9718 Next (Assoc);
9720 if No (Assoc) then
9721 Error_Msg_NE
9722 ("missing value for discriminant&",
9723 First (Governed_By), Discrim_Name);
9725 Report_Errors := True;
9726 return;
9727 end if;
9728 end loop Find_Constraint;
9730 Discrim_Value := Expression (Assoc);
9732 if Is_OK_Static_Expression (Discrim_Value)
9733 or else (Allow_Compile_Time
9734 and then Compile_Time_Known_Value (Discrim_Value))
9735 then
9736 Discrim_Value_Status := Static_Expr;
9737 else
9738 if Ada_Version >= Ada_2022 then
9739 if Is_Rewrite_Substitution (Discrim_Value)
9740 and then Nkind (Discrim_Value) = N_Type_Conversion
9741 and then Etype (Original_Node (Discrim_Value))
9742 = Etype (Expression (Discrim_Value))
9743 then
9744 Discrim_Value_Subtype := Etype (Original_Node (Discrim_Value));
9745 -- An unhelpful (for this code) type conversion may be
9746 -- introduced in some cases; deal with it.
9747 else
9748 Discrim_Value_Subtype := Etype (Discrim_Value);
9749 end if;
9751 if Is_OK_Static_Subtype (Discrim_Value_Subtype) and then
9752 not Is_Null_Range (Type_Low_Bound (Discrim_Value_Subtype),
9753 Type_High_Bound (Discrim_Value_Subtype))
9754 then
9755 -- Is_Null_Range test doesn't account for predicates, as in
9756 -- subtype Null_By_Predicate is Natural
9757 -- with Static_Predicate => Null_By_Predicate < 0;
9758 -- so test for that null case separately.
9760 if not Has_Static_Predicate (Discrim_Value_Subtype)
9761 or else Present (First (Static_Discrete_Predicate
9762 (Discrim_Value_Subtype)))
9763 then
9764 Discrim_Value_Status := Static_Subtype;
9765 end if;
9766 end if;
9767 end if;
9769 if Discrim_Value_Status = Bad then
9771 -- If the variant part is governed by a discriminant of the type
9772 -- this is an error. If the variant part and the discriminant are
9773 -- inherited from an ancestor this is legal (AI05-220) unless the
9774 -- components are being gathered for an aggregate, in which case
9775 -- the caller must check Report_Errors.
9777 -- In Ada 2022 the above rules are relaxed. A nonstatic governing
9778 -- discriminant is OK as long as it has a static subtype and
9779 -- every value of that subtype (and there must be at least one)
9780 -- selects the same variant.
9782 if OK_Scope_For_Discrim_Value_Error_Messages then
9783 if Ada_Version >= Ada_2022 then
9784 Error_Msg_FE
9785 ("value for discriminant & must be static or " &
9786 "discriminant's nominal subtype must be static " &
9787 "and non-null!",
9788 Discrim_Value, Discrim);
9789 else
9790 Error_Msg_FE
9791 ("value for discriminant & must be static!",
9792 Discrim_Value, Discrim);
9793 end if;
9794 Why_Not_Static (Discrim_Value);
9795 end if;
9797 Report_Errors := True;
9798 return;
9799 end if;
9800 end if;
9802 Search_For_Discriminant_Value : declare
9803 Low : Node_Id;
9804 High : Node_Id;
9806 UI_High : Uint;
9807 UI_Low : Uint;
9808 UI_Discrim_Value : Uint;
9810 begin
9811 case Good_Discrim_Value_Status'(Discrim_Value_Status) is
9812 when Static_Expr =>
9813 UI_Discrim_Value := Expr_Value (Discrim_Value);
9814 when Static_Subtype =>
9815 -- Arbitrarily pick one value of the subtype and look
9816 -- for the variant associated with that value; we will
9817 -- check later that the same variant is associated with
9818 -- all of the other values of the subtype.
9819 if Has_Static_Predicate (Discrim_Value_Subtype) then
9820 declare
9821 Range_Or_Expr : constant Node_Id :=
9822 First (Static_Discrete_Predicate
9823 (Discrim_Value_Subtype));
9824 begin
9825 if Nkind (Range_Or_Expr) = N_Range then
9826 UI_Discrim_Value :=
9827 Expr_Value (Low_Bound (Range_Or_Expr));
9828 else
9829 UI_Discrim_Value := Expr_Value (Range_Or_Expr);
9830 end if;
9831 end;
9832 else
9833 UI_Discrim_Value
9834 := Expr_Value (Type_Low_Bound (Discrim_Value_Subtype));
9835 end if;
9836 end case;
9838 Find_Discrete_Value : while Present (Variant) loop
9840 -- If a choice is a subtype with a static predicate, it must
9841 -- be rewritten as an explicit list of non-predicated choices.
9843 Expand_Static_Predicates_In_Choices (Variant);
9845 Discrete_Choice := First (Discrete_Choices (Variant));
9846 while Present (Discrete_Choice) loop
9847 exit Find_Discrete_Value when
9848 Nkind (Discrete_Choice) = N_Others_Choice;
9850 Get_Index_Bounds (Discrete_Choice, Low, High);
9852 UI_Low := Expr_Value (Low);
9853 UI_High := Expr_Value (High);
9855 exit Find_Discrete_Value when
9856 UI_Low <= UI_Discrim_Value
9857 and then
9858 UI_High >= UI_Discrim_Value;
9860 Next (Discrete_Choice);
9861 end loop;
9863 Next_Non_Pragma (Variant);
9864 end loop Find_Discrete_Value;
9865 end Search_For_Discriminant_Value;
9867 -- The case statement must include a variant that corresponds to the
9868 -- value of the discriminant, unless the discriminant type has a
9869 -- static predicate. In that case the absence of an others_choice that
9870 -- would cover this value becomes a run-time error (3.8.1 (21.1/2)).
9872 if No (Variant)
9873 and then not Has_Static_Predicate (Etype (Discrim_Name))
9874 then
9875 Error_Msg_NE
9876 ("value of discriminant & is out of range", Discrim_Value, Discrim);
9877 Report_Errors := True;
9878 return;
9879 end if;
9881 -- If we have found the corresponding choice, recursively add its
9882 -- components to the Into list. The nested components are part of
9883 -- the same record type.
9885 if Present (Variant) then
9886 if Discrim_Value_Status = Static_Subtype then
9887 declare
9888 Discrim_Value_Subtype_Intervals
9889 : constant Interval_Lists.Discrete_Interval_List
9890 := Interval_Lists.Type_Intervals (Discrim_Value_Subtype);
9892 Variant_Intervals
9893 : constant Interval_Lists.Discrete_Interval_List
9894 := Interval_Lists.Choice_List_Intervals
9895 (Discrete_Choices => Discrete_Choices (Variant));
9896 begin
9897 if not Interval_Lists.Is_Subset
9898 (Subset => Discrim_Value_Subtype_Intervals,
9899 Of_Set => Variant_Intervals)
9900 then
9901 if OK_Scope_For_Discrim_Value_Error_Messages then
9902 Error_Msg_NE
9903 ("no single variant is associated with all values of " &
9904 "the subtype of discriminant value &",
9905 Discrim_Value, Discrim);
9906 end if;
9907 Report_Errors := True;
9908 return;
9909 end if;
9910 end;
9911 end if;
9913 Gather_Components
9914 (Typ, Component_List (Variant), Governed_By, Into,
9915 Report_Errors, Allow_Compile_Time);
9916 end if;
9917 end Gather_Components;
9919 ------------------------
9920 -- Get_Actual_Subtype --
9921 ------------------------
9923 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
9924 Typ : constant Entity_Id := Etype (N);
9925 Utyp : Entity_Id := Underlying_Type (Typ);
9926 Decl : Node_Id;
9927 Atyp : Entity_Id;
9929 begin
9930 if No (Utyp) then
9931 Utyp := Typ;
9932 end if;
9934 -- If what we have is an identifier that references a subprogram
9935 -- formal, or a variable or constant object, then we get the actual
9936 -- subtype from the referenced entity if one has been built.
9938 if Nkind (N) in N_Identifier | N_Expanded_Name
9939 and then
9940 (Is_Formal (Entity (N))
9941 or else Ekind (Entity (N)) = E_Constant
9942 or else Ekind (Entity (N)) = E_Variable)
9943 and then Present (Actual_Subtype (Entity (N)))
9944 then
9945 return Actual_Subtype (Entity (N));
9947 -- Similarly, if we have an explicit dereference, then we get the
9948 -- actual subtype from the node itself if one has been built.
9950 elsif Nkind (N) = N_Explicit_Dereference
9951 and then Present (Actual_Designated_Subtype (N))
9952 then
9953 return Actual_Designated_Subtype (N);
9955 -- Actual subtype of unchecked union is always itself. We never need
9956 -- the "real" actual subtype. If we did, we couldn't get it anyway
9957 -- because the discriminant is not available. The restrictions on
9958 -- Unchecked_Union are designed to make sure that this is OK.
9960 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9961 return Typ;
9963 -- Here for the unconstrained case, we must find actual subtype
9964 -- No actual subtype is available, so we must build it on the fly.
9966 -- Checking the type, not the underlying type, for constrainedness
9967 -- seems to be necessary. Maybe all the tests should be on the type???
9969 elsif not Is_Constrained (Typ)
9970 and then (Is_Array_Type (Utyp)
9971 or else (Is_Record_Type (Utyp)
9972 and then Has_Discriminants (Utyp)))
9973 and then not Has_Unknown_Discriminants (Utyp)
9974 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9975 then
9976 -- Nothing to do if in spec expression (why not???)
9978 if In_Spec_Expression then
9979 return Typ;
9981 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9983 -- If the type has no discriminants, there is no subtype to
9984 -- build, even if the underlying type is discriminated.
9986 return Typ;
9988 -- Else build the actual subtype
9990 else
9991 Decl := Build_Actual_Subtype (Typ, N);
9993 -- The call may yield a declaration, or just return the entity
9995 if Decl = Typ then
9996 return Typ;
9997 end if;
9999 Atyp := Defining_Identifier (Decl);
10001 -- If Build_Actual_Subtype generated a new declaration then use it
10003 if Atyp /= Typ then
10005 -- The actual subtype is an Itype, so analyze the declaration,
10006 -- but do not attach it to the tree, to get the type defined.
10008 Set_Parent (Decl, N);
10009 Set_Is_Itype (Atyp);
10010 Analyze (Decl, Suppress => All_Checks);
10011 Set_Associated_Node_For_Itype (Atyp, N);
10012 if Expander_Active then
10013 Set_Has_Delayed_Freeze (Atyp, False);
10015 -- We need to freeze the actual subtype immediately. This is
10016 -- needed because otherwise this Itype will not get frozen
10017 -- at all; it is always safe to freeze on creation because
10018 -- any associated types must be frozen at this point.
10020 -- On the other hand, if we are performing preanalysis on
10021 -- a conjured-up copy of a name (see calls to
10022 -- Preanalyze_Range in sem_ch5.adb) then we don't want
10023 -- to freeze Atyp, now or ever. In this case, the tree
10024 -- we eventually pass to the back end should contain no
10025 -- references to Atyp (and a freeze node would contain
10026 -- such a reference). That's why Expander_Active is tested.
10028 Freeze_Itype (Atyp, N);
10029 end if;
10030 return Atyp;
10032 -- Otherwise we did not build a declaration, so return original
10034 else
10035 return Typ;
10036 end if;
10037 end if;
10039 -- For all remaining cases, the actual subtype is the same as
10040 -- the nominal type.
10042 else
10043 return Typ;
10044 end if;
10045 end Get_Actual_Subtype;
10047 -------------------------------------
10048 -- Get_Actual_Subtype_If_Available --
10049 -------------------------------------
10051 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
10052 begin
10053 -- If what we have is an identifier that references a subprogram
10054 -- formal, or a variable or constant object, then we get the actual
10055 -- subtype from the referenced entity if one has been built.
10057 if Nkind (N) in N_Identifier | N_Expanded_Name
10058 and then
10059 (Is_Formal (Entity (N))
10060 or else Ekind (Entity (N)) = E_Constant
10061 or else Ekind (Entity (N)) = E_Variable)
10062 and then Present (Actual_Subtype (Entity (N)))
10063 then
10064 return Actual_Subtype (Entity (N));
10066 -- Similarly, if we have an explicit dereference, then we get the
10067 -- actual subtype from the node itself if one has been built.
10069 elsif Nkind (N) = N_Explicit_Dereference
10070 and then Present (Actual_Designated_Subtype (N))
10071 then
10072 return Actual_Designated_Subtype (N);
10074 -- Otherwise the Etype of N is returned unchanged
10076 else
10077 return Etype (N);
10078 end if;
10079 end Get_Actual_Subtype_If_Available;
10081 ------------------------
10082 -- Get_Body_From_Stub --
10083 ------------------------
10085 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
10086 begin
10087 return Proper_Body (Unit (Library_Unit (N)));
10088 end Get_Body_From_Stub;
10090 ---------------------
10091 -- Get_Cursor_Type --
10092 ---------------------
10094 function Get_Cursor_Type
10095 (Aspect : Node_Id;
10096 Typ : Entity_Id) return Entity_Id
10098 Assoc : Node_Id;
10099 Func : Entity_Id;
10100 First_Op : Entity_Id;
10101 Cursor : Entity_Id;
10103 begin
10104 -- If error already detected, return
10106 if Error_Posted (Aspect) then
10107 return Any_Type;
10108 end if;
10110 -- The cursor type for an Iterable aspect is the return type of a
10111 -- non-overloaded First primitive operation. Locate association for
10112 -- First.
10114 Assoc := First (Component_Associations (Expression (Aspect)));
10115 First_Op := Any_Id;
10116 while Present (Assoc) loop
10117 if Chars (First (Choices (Assoc))) = Name_First then
10118 First_Op := Expression (Assoc);
10119 exit;
10120 end if;
10122 Next (Assoc);
10123 end loop;
10125 if First_Op = Any_Id then
10126 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
10127 return Any_Type;
10129 elsif not Analyzed (First_Op) then
10130 Analyze (First_Op);
10131 end if;
10133 Cursor := Any_Type;
10135 -- Locate function with desired name and profile in scope of type
10136 -- In the rare case where the type is an integer type, a base type
10137 -- is created for it, check that the base type of the first formal
10138 -- of First matches the base type of the domain.
10140 Func := First_Entity (Scope (Typ));
10141 while Present (Func) loop
10142 if Chars (Func) = Chars (First_Op)
10143 and then Ekind (Func) = E_Function
10144 and then Present (First_Formal (Func))
10145 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
10146 and then No (Next_Formal (First_Formal (Func)))
10147 then
10148 if Cursor /= Any_Type then
10149 Error_Msg_N
10150 ("operation First for iterable type must be unique", Aspect);
10151 return Any_Type;
10152 else
10153 Cursor := Etype (Func);
10154 end if;
10155 end if;
10157 Next_Entity (Func);
10158 end loop;
10160 -- If not found, no way to resolve remaining primitives
10162 if Cursor = Any_Type then
10163 Error_Msg_N
10164 ("primitive operation for Iterable type must appear in the same "
10165 & "list of declarations as the type", Aspect);
10166 end if;
10168 return Cursor;
10169 end Get_Cursor_Type;
10171 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
10172 begin
10173 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
10174 end Get_Cursor_Type;
10176 -------------------------------
10177 -- Get_Default_External_Name --
10178 -------------------------------
10180 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
10181 begin
10182 Get_Decoded_Name_String (Chars (E));
10184 if Opt.External_Name_Imp_Casing = Uppercase then
10185 Set_Casing (All_Upper_Case);
10186 else
10187 Set_Casing (All_Lower_Case);
10188 end if;
10190 return
10191 Make_String_Literal (Sloc (E),
10192 Strval => String_From_Name_Buffer);
10193 end Get_Default_External_Name;
10195 --------------------------
10196 -- Get_Enclosing_Object --
10197 --------------------------
10199 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
10200 begin
10201 if Is_Entity_Name (N) then
10202 return Entity (N);
10203 else
10204 case Nkind (N) is
10205 when N_Indexed_Component
10206 | N_Selected_Component
10207 | N_Slice
10209 -- If not generating code, a dereference may be left implicit.
10210 -- In thoses cases, return Empty.
10212 if Is_Access_Type (Etype (Prefix (N))) then
10213 return Empty;
10214 else
10215 return Get_Enclosing_Object (Prefix (N));
10216 end if;
10218 when N_Type_Conversion =>
10219 return Get_Enclosing_Object (Expression (N));
10221 when others =>
10222 return Empty;
10223 end case;
10224 end if;
10225 end Get_Enclosing_Object;
10227 -------------------------------
10228 -- Get_Enclosing_Deep_Object --
10229 -------------------------------
10231 function Get_Enclosing_Deep_Object (N : Node_Id) return Entity_Id is
10232 begin
10233 if Is_Entity_Name (N) then
10234 return Entity (N);
10235 else
10236 case Nkind (N) is
10237 when N_Explicit_Dereference
10238 | N_Indexed_Component
10239 | N_Selected_Component
10240 | N_Slice
10242 return Get_Enclosing_Deep_Object (Prefix (N));
10244 when N_Type_Conversion =>
10245 return Get_Enclosing_Deep_Object (Expression (N));
10247 when others =>
10248 return Empty;
10249 end case;
10250 end if;
10251 end Get_Enclosing_Deep_Object;
10253 ---------------------------
10254 -- Get_Enum_Lit_From_Pos --
10255 ---------------------------
10257 function Get_Enum_Lit_From_Pos
10258 (T : Entity_Id;
10259 Pos : Uint;
10260 Loc : Source_Ptr) return Node_Id
10262 Btyp : Entity_Id := Base_Type (T);
10263 Lit : Node_Id;
10264 LLoc : Source_Ptr;
10266 begin
10267 -- In the case where the literal is of type Character, Wide_Character
10268 -- or Wide_Wide_Character or of a type derived from them, there needs
10269 -- to be some special handling since there is no explicit chain of
10270 -- literals to search. Instead, an N_Character_Literal node is created
10271 -- with the appropriate Char_Code and Chars fields.
10273 if Is_Standard_Character_Type (T) then
10274 Set_Character_Literal_Name (UI_To_CC (Pos));
10276 return
10277 Make_Character_Literal (Loc,
10278 Chars => Name_Find,
10279 Char_Literal_Value => Pos);
10281 -- For all other cases, we have a complete table of literals, and
10282 -- we simply iterate through the chain of literal until the one
10283 -- with the desired position value is found.
10285 else
10286 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
10287 Btyp := Full_View (Btyp);
10288 end if;
10290 Lit := First_Literal (Btyp);
10292 -- Position in the enumeration type starts at 0
10294 if Pos < 0 then
10295 raise Constraint_Error;
10296 end if;
10298 for J in 1 .. UI_To_Int (Pos) loop
10299 Next_Literal (Lit);
10301 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
10302 -- inside the loop to avoid calling Next_Literal on Empty.
10304 if No (Lit) then
10305 raise Constraint_Error;
10306 end if;
10307 end loop;
10309 -- Create a new node from Lit, with source location provided by Loc
10310 -- if not equal to No_Location, or by copying the source location of
10311 -- Lit otherwise.
10313 LLoc := Loc;
10315 if LLoc = No_Location then
10316 LLoc := Sloc (Lit);
10317 end if;
10319 return New_Occurrence_Of (Lit, LLoc);
10320 end if;
10321 end Get_Enum_Lit_From_Pos;
10323 ----------------------
10324 -- Get_Fullest_View --
10325 ----------------------
10327 function Get_Fullest_View
10328 (E : Entity_Id;
10329 Include_PAT : Boolean := True;
10330 Recurse : Boolean := True) return Entity_Id
10332 New_E : Entity_Id := Empty;
10334 begin
10335 -- Prevent cascaded errors
10337 if No (E) then
10338 return E;
10339 end if;
10341 -- Look at each kind of entity to see where we may need to go deeper.
10343 case Ekind (E) is
10344 when Incomplete_Kind =>
10345 if From_Limited_With (E) then
10346 New_E := Non_Limited_View (E);
10347 elsif Present (Full_View (E)) then
10348 New_E := Full_View (E);
10349 elsif Ekind (E) = E_Incomplete_Subtype then
10350 New_E := Etype (E);
10351 end if;
10353 when Private_Kind =>
10354 if Present (Underlying_Full_View (E)) then
10355 New_E := Underlying_Full_View (E);
10356 elsif Present (Full_View (E)) then
10357 New_E := Full_View (E);
10358 elsif Etype (E) /= E then
10359 New_E := Etype (E);
10360 end if;
10362 when Array_Kind =>
10363 if Include_PAT and then Present (Packed_Array_Impl_Type (E)) then
10364 New_E := Packed_Array_Impl_Type (E);
10365 end if;
10367 when E_Record_Subtype =>
10368 if Present (Cloned_Subtype (E)) then
10369 New_E := Cloned_Subtype (E);
10370 end if;
10372 when E_Class_Wide_Type =>
10373 New_E := Root_Type (E);
10375 when E_Class_Wide_Subtype =>
10376 if Present (Equivalent_Type (E)) then
10377 New_E := Equivalent_Type (E);
10378 elsif Present (Cloned_Subtype (E)) then
10379 New_E := Cloned_Subtype (E);
10380 end if;
10382 when E_Protected_Subtype
10383 | E_Protected_Type
10384 | E_Task_Subtype
10385 | E_Task_Type
10387 if Present (Corresponding_Record_Type (E)) then
10388 New_E := Corresponding_Record_Type (E);
10389 end if;
10391 when E_Access_Protected_Subprogram_Type
10392 | E_Anonymous_Access_Protected_Subprogram_Type
10394 if Present (Equivalent_Type (E)) then
10395 New_E := Equivalent_Type (E);
10396 end if;
10398 when E_Access_Subtype =>
10399 New_E := Base_Type (E);
10401 when others =>
10402 null;
10403 end case;
10405 -- If we found a fuller view, either return it or recurse. Otherwise,
10406 -- return our input.
10408 return (if No (New_E) then E
10409 elsif Recurse then Get_Fullest_View (New_E, Include_PAT, Recurse)
10410 else New_E);
10411 end Get_Fullest_View;
10413 ------------------------
10414 -- Get_Generic_Entity --
10415 ------------------------
10417 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
10418 Ent : constant Entity_Id := Entity (Name (N));
10419 begin
10420 if Present (Renamed_Entity (Ent)) then
10421 return Renamed_Entity (Ent);
10422 else
10423 return Ent;
10424 end if;
10425 end Get_Generic_Entity;
10427 -------------------------------------
10428 -- Get_Incomplete_View_Of_Ancestor --
10429 -------------------------------------
10431 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
10432 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10433 Par_Scope : Entity_Id;
10434 Par_Type : Entity_Id;
10436 begin
10437 -- The incomplete view of an ancestor is only relevant for private
10438 -- derived types in child units.
10440 if not Is_Derived_Type (E)
10441 or else not Is_Child_Unit (Cur_Unit)
10442 then
10443 return Empty;
10445 else
10446 Par_Scope := Scope (Cur_Unit);
10447 if No (Par_Scope) then
10448 return Empty;
10449 end if;
10451 Par_Type := Etype (Base_Type (E));
10453 -- Traverse list of ancestor types until we find one declared in
10454 -- a parent or grandparent unit (two levels seem sufficient).
10456 while Present (Par_Type) loop
10457 if Scope (Par_Type) = Par_Scope
10458 or else Scope (Par_Type) = Scope (Par_Scope)
10459 then
10460 return Par_Type;
10462 elsif not Is_Derived_Type (Par_Type) then
10463 return Empty;
10465 else
10466 Par_Type := Etype (Base_Type (Par_Type));
10467 end if;
10468 end loop;
10470 -- If none found, there is no relevant ancestor type.
10472 return Empty;
10473 end if;
10474 end Get_Incomplete_View_Of_Ancestor;
10476 ----------------------
10477 -- Get_Index_Bounds --
10478 ----------------------
10480 procedure Get_Index_Bounds
10481 (N : Node_Id;
10482 L : out Node_Id;
10483 H : out Node_Id;
10484 Use_Full_View : Boolean := False)
10486 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
10487 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
10488 -- Typ qualifies, the scalar range is obtained from the full view of the
10489 -- type.
10491 --------------------------
10492 -- Scalar_Range_Of_Type --
10493 --------------------------
10495 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
10496 T : Entity_Id := Typ;
10498 begin
10499 if Use_Full_View and then Present (Full_View (T)) then
10500 T := Full_View (T);
10501 end if;
10503 return Scalar_Range (T);
10504 end Scalar_Range_Of_Type;
10506 -- Local variables
10508 Kind : constant Node_Kind := Nkind (N);
10509 Rng : Node_Id;
10511 -- Start of processing for Get_Index_Bounds
10513 begin
10514 if Kind = N_Range then
10515 L := Low_Bound (N);
10516 H := High_Bound (N);
10518 elsif Kind = N_Subtype_Indication then
10519 Rng := Range_Expression (Constraint (N));
10521 if Rng = Error then
10522 L := Error;
10523 H := Error;
10524 return;
10526 else
10527 L := Low_Bound (Range_Expression (Constraint (N)));
10528 H := High_Bound (Range_Expression (Constraint (N)));
10529 end if;
10531 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
10532 Rng := Scalar_Range_Of_Type (Entity (N));
10534 if Error_Posted (Rng) then
10535 L := Error;
10536 H := Error;
10538 elsif Nkind (Rng) = N_Subtype_Indication then
10539 Get_Index_Bounds (Rng, L, H);
10541 else
10542 L := Low_Bound (Rng);
10543 H := High_Bound (Rng);
10544 end if;
10546 else
10547 -- N is an expression, indicating a range with one value
10549 L := N;
10550 H := N;
10551 end if;
10552 end Get_Index_Bounds;
10554 function Get_Index_Bounds
10555 (N : Node_Id;
10556 Use_Full_View : Boolean := False) return Range_Nodes is
10557 Result : Range_Nodes;
10558 begin
10559 Get_Index_Bounds (N, Result.First, Result.Last, Use_Full_View);
10560 return Result;
10561 end Get_Index_Bounds;
10563 function Get_Index_Bounds
10564 (N : Node_Id;
10565 Use_Full_View : Boolean := False) return Range_Values is
10566 Nodes : constant Range_Nodes := Get_Index_Bounds (N, Use_Full_View);
10567 begin
10568 return (Expr_Value (Nodes.First), Expr_Value (Nodes.Last));
10569 end Get_Index_Bounds;
10571 -----------------------------
10572 -- Get_Interfacing_Aspects --
10573 -----------------------------
10575 procedure Get_Interfacing_Aspects
10576 (Iface_Asp : Node_Id;
10577 Conv_Asp : out Node_Id;
10578 EN_Asp : out Node_Id;
10579 Expo_Asp : out Node_Id;
10580 Imp_Asp : out Node_Id;
10581 LN_Asp : out Node_Id;
10582 Do_Checks : Boolean := False)
10584 procedure Save_Or_Duplication_Error
10585 (Asp : Node_Id;
10586 To : in out Node_Id);
10587 -- Save the value of aspect Asp in node To. If To already has a value,
10588 -- then this is considered a duplicate use of aspect. Emit an error if
10589 -- flag Do_Checks is set.
10591 -------------------------------
10592 -- Save_Or_Duplication_Error --
10593 -------------------------------
10595 procedure Save_Or_Duplication_Error
10596 (Asp : Node_Id;
10597 To : in out Node_Id)
10599 begin
10600 -- Detect an extra aspect and issue an error
10602 if Present (To) then
10603 if Do_Checks then
10604 Error_Msg_Name_1 := Chars (Identifier (Asp));
10605 Error_Msg_Sloc := Sloc (To);
10606 Error_Msg_N ("aspect % previously given #", Asp);
10607 end if;
10609 -- Otherwise capture the aspect
10611 else
10612 To := Asp;
10613 end if;
10614 end Save_Or_Duplication_Error;
10616 -- Local variables
10618 Asp : Node_Id;
10619 Asp_Id : Aspect_Id;
10621 -- The following variables capture each individual aspect
10623 Conv : Node_Id := Empty;
10624 EN : Node_Id := Empty;
10625 Expo : Node_Id := Empty;
10626 Imp : Node_Id := Empty;
10627 LN : Node_Id := Empty;
10629 -- Start of processing for Get_Interfacing_Aspects
10631 begin
10632 -- The input interfacing aspect should reside in an aspect specification
10633 -- list.
10635 pragma Assert (Is_List_Member (Iface_Asp));
10637 -- Examine the aspect specifications of the related entity. Find and
10638 -- capture all interfacing aspects. Detect duplicates and emit errors
10639 -- if applicable.
10641 Asp := First (List_Containing (Iface_Asp));
10642 while Present (Asp) loop
10643 Asp_Id := Get_Aspect_Id (Asp);
10645 if Asp_Id = Aspect_Convention then
10646 Save_Or_Duplication_Error (Asp, Conv);
10648 elsif Asp_Id = Aspect_External_Name then
10649 Save_Or_Duplication_Error (Asp, EN);
10651 elsif Asp_Id = Aspect_Export then
10652 Save_Or_Duplication_Error (Asp, Expo);
10654 elsif Asp_Id = Aspect_Import then
10655 Save_Or_Duplication_Error (Asp, Imp);
10657 elsif Asp_Id = Aspect_Link_Name then
10658 Save_Or_Duplication_Error (Asp, LN);
10659 end if;
10661 Next (Asp);
10662 end loop;
10664 Conv_Asp := Conv;
10665 EN_Asp := EN;
10666 Expo_Asp := Expo;
10667 Imp_Asp := Imp;
10668 LN_Asp := LN;
10669 end Get_Interfacing_Aspects;
10671 ---------------------------------
10672 -- Get_Iterable_Type_Primitive --
10673 ---------------------------------
10675 function Get_Iterable_Type_Primitive
10676 (Typ : Entity_Id;
10677 Nam : Name_Id) return Entity_Id
10679 pragma Assert
10680 (Is_Type (Typ)
10681 and then
10682 Nam in Name_Element
10683 | Name_First
10684 | Name_Has_Element
10685 | Name_Last
10686 | Name_Next
10687 | Name_Previous);
10689 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
10690 Assoc : Node_Id;
10692 begin
10693 if No (Funcs) then
10694 return Empty;
10696 else
10697 Assoc := First (Component_Associations (Funcs));
10698 while Present (Assoc) loop
10699 if Chars (First (Choices (Assoc))) = Nam then
10700 return Entity (Expression (Assoc));
10701 end if;
10703 Next (Assoc);
10704 end loop;
10706 return Empty;
10707 end if;
10708 end Get_Iterable_Type_Primitive;
10710 ---------------------------
10711 -- Get_Library_Unit_Name --
10712 ---------------------------
10714 function Get_Library_Unit_Name (Decl_Node : Node_Id) return String_Id is
10715 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
10716 Buf : Bounded_String;
10717 begin
10718 Get_Unit_Name_String (Buf, Unit_Name_Id);
10720 -- Remove the last seven characters (" (spec)" or " (body)")
10722 Buf.Length := Buf.Length - 7;
10723 pragma Assert (Buf.Chars (Buf.Length + 1) = ' ');
10725 return String_From_Name_Buffer (Buf);
10726 end Get_Library_Unit_Name;
10728 --------------------------
10729 -- Get_Max_Queue_Length --
10730 --------------------------
10732 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
10733 pragma Assert (Is_Entry (Id));
10734 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
10735 Max : Uint;
10737 begin
10738 -- A value of 0 or -1 represents no maximum specified, and entries and
10739 -- entry families with no Max_Queue_Length aspect or pragma default to
10740 -- it.
10742 if No (Prag) then
10743 return Uint_0;
10744 end if;
10746 Max := Expr_Value
10747 (Expression (First (Pragma_Argument_Associations (Prag))));
10749 -- Since -1 and 0 are equivalent, return 0 for instances of -1 for
10750 -- uniformity.
10752 if Max = -1 then
10753 return Uint_0;
10754 end if;
10756 return Max;
10757 end Get_Max_Queue_Length;
10759 ------------------------
10760 -- Get_Name_Entity_Id --
10761 ------------------------
10763 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
10764 begin
10765 return Entity_Id (Get_Name_Table_Int (Id));
10766 end Get_Name_Entity_Id;
10768 ------------------------------
10769 -- Get_Name_From_CTC_Pragma --
10770 ------------------------------
10772 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
10773 Arg : constant Node_Id :=
10774 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
10775 begin
10776 return Strval (Expr_Value_S (Arg));
10777 end Get_Name_From_CTC_Pragma;
10779 -----------------------
10780 -- Get_Parent_Entity --
10781 -----------------------
10783 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
10784 begin
10785 if Nkind (Unit) = N_Package_Body
10786 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
10787 then
10788 return Defining_Entity
10789 (Specification (Instance_Spec (Original_Node (Unit))));
10790 elsif Nkind (Unit) = N_Package_Instantiation then
10791 return Defining_Entity (Specification (Instance_Spec (Unit)));
10792 else
10793 return Defining_Entity (Unit);
10794 end if;
10795 end Get_Parent_Entity;
10797 -------------------
10798 -- Get_Pragma_Id --
10799 -------------------
10801 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
10802 begin
10803 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
10804 end Get_Pragma_Id;
10806 ------------------------
10807 -- Get_Qualified_Name --
10808 ------------------------
10810 function Get_Qualified_Name
10811 (Id : Entity_Id;
10812 Suffix : Entity_Id := Empty) return Name_Id
10814 Suffix_Nam : Name_Id := No_Name;
10816 begin
10817 if Present (Suffix) then
10818 Suffix_Nam := Chars (Suffix);
10819 end if;
10821 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
10822 end Get_Qualified_Name;
10824 function Get_Qualified_Name
10825 (Nam : Name_Id;
10826 Suffix : Name_Id := No_Name;
10827 Scop : Entity_Id := Current_Scope) return Name_Id
10829 procedure Add_Scope (S : Entity_Id);
10830 -- Add the fully qualified form of scope S to the name buffer. The
10831 -- format is:
10832 -- s-1__s__
10834 ---------------
10835 -- Add_Scope --
10836 ---------------
10838 procedure Add_Scope (S : Entity_Id) is
10839 begin
10840 if S = Empty then
10841 null;
10843 elsif S = Standard_Standard then
10844 null;
10846 else
10847 Add_Scope (Scope (S));
10848 Get_Name_String_And_Append (Chars (S));
10849 Add_Str_To_Name_Buffer ("__");
10850 end if;
10851 end Add_Scope;
10853 -- Start of processing for Get_Qualified_Name
10855 begin
10856 Name_Len := 0;
10857 Add_Scope (Scop);
10859 -- Append the base name after all scopes have been chained
10861 Get_Name_String_And_Append (Nam);
10863 -- Append the suffix (if present)
10865 if Suffix /= No_Name then
10866 Add_Str_To_Name_Buffer ("__");
10867 Get_Name_String_And_Append (Suffix);
10868 end if;
10870 return Name_Find;
10871 end Get_Qualified_Name;
10873 -----------------------
10874 -- Get_Reason_String --
10875 -----------------------
10877 procedure Get_Reason_String (N : Node_Id) is
10878 begin
10879 if Nkind (N) = N_String_Literal then
10880 Store_String_Chars (Strval (N));
10882 elsif Nkind (N) = N_Op_Concat then
10883 Get_Reason_String (Left_Opnd (N));
10884 Get_Reason_String (Right_Opnd (N));
10886 -- If not of required form, error
10888 else
10889 Error_Msg_N
10890 ("Reason for pragma Warnings has wrong form", N);
10891 Error_Msg_N
10892 ("\must be string literal or concatenation of string literals", N);
10893 return;
10894 end if;
10895 end Get_Reason_String;
10897 --------------------------------
10898 -- Get_Reference_Discriminant --
10899 --------------------------------
10901 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
10902 D : Entity_Id;
10904 begin
10905 D := First_Discriminant (Typ);
10906 while Present (D) loop
10907 if Has_Implicit_Dereference (D) then
10908 return D;
10909 end if;
10910 Next_Discriminant (D);
10911 end loop;
10913 return Empty;
10914 end Get_Reference_Discriminant;
10916 ---------------------------
10917 -- Get_Referenced_Object --
10918 ---------------------------
10920 function Get_Referenced_Object (N : Node_Id) return Node_Id is
10921 R : Node_Id;
10923 begin
10924 R := N;
10925 while Is_Entity_Name (R)
10926 and then Is_Object (Entity (R))
10927 and then Present (Renamed_Object (Entity (R)))
10928 loop
10929 R := Renamed_Object (Entity (R));
10930 end loop;
10932 return R;
10933 end Get_Referenced_Object;
10935 ------------------------
10936 -- Get_Renamed_Entity --
10937 ------------------------
10939 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
10940 R : Entity_Id := E;
10941 begin
10942 while Present (Renamed_Entity (R)) loop
10943 R := Renamed_Entity (R);
10944 end loop;
10946 return R;
10947 end Get_Renamed_Entity;
10949 -----------------------
10950 -- Get_Return_Object --
10951 -----------------------
10953 function Get_Return_Object (N : Node_Id) return Entity_Id is
10954 Decl : Node_Id;
10956 begin
10957 Decl := First (Return_Object_Declarations (N));
10958 while Present (Decl) loop
10959 exit when Nkind (Decl) = N_Object_Declaration
10960 and then Is_Return_Object (Defining_Identifier (Decl));
10961 Next (Decl);
10962 end loop;
10964 pragma Assert (Present (Decl));
10965 return Defining_Identifier (Decl);
10966 end Get_Return_Object;
10968 ---------------------------
10969 -- Get_Subprogram_Entity --
10970 ---------------------------
10972 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
10973 Subp : Node_Id;
10974 Subp_Id : Entity_Id;
10976 begin
10977 if Nkind (Nod) = N_Accept_Statement then
10978 Subp := Entry_Direct_Name (Nod);
10980 elsif Nkind (Nod) = N_Slice then
10981 Subp := Prefix (Nod);
10983 else
10984 Subp := Name (Nod);
10985 end if;
10987 -- Strip the subprogram call
10989 loop
10990 if Nkind (Subp) in N_Explicit_Dereference
10991 | N_Indexed_Component
10992 | N_Selected_Component
10993 then
10994 Subp := Prefix (Subp);
10996 elsif Nkind (Subp) in N_Type_Conversion
10997 | N_Unchecked_Type_Conversion
10998 then
10999 Subp := Expression (Subp);
11001 else
11002 exit;
11003 end if;
11004 end loop;
11006 -- Extract the entity of the subprogram call
11008 if Is_Entity_Name (Subp) then
11009 Subp_Id := Entity (Subp);
11011 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
11012 Subp_Id := Directly_Designated_Type (Subp_Id);
11013 end if;
11015 if Is_Subprogram (Subp_Id) then
11016 return Subp_Id;
11017 else
11018 return Empty;
11019 end if;
11021 -- The search did not find a construct that denotes a subprogram
11023 else
11024 return Empty;
11025 end if;
11026 end Get_Subprogram_Entity;
11028 -----------------------------
11029 -- Get_Task_Body_Procedure --
11030 -----------------------------
11032 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
11033 begin
11034 -- Note: A task type may be the completion of a private type with
11035 -- discriminants. When performing elaboration checks on a task
11036 -- declaration, the current view of the type may be the private one,
11037 -- and the procedure that holds the body of the task is held in its
11038 -- underlying type.
11040 -- This is an odd function, why not have Task_Body_Procedure do
11041 -- the following digging???
11043 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
11044 end Get_Task_Body_Procedure;
11046 -------------------------------
11047 -- Get_User_Defined_Equality --
11048 -------------------------------
11050 function Get_User_Defined_Equality (E : Entity_Id) return Entity_Id is
11051 Prim : Elmt_Id;
11053 begin
11054 Prim := First_Elmt (Collect_Primitive_Operations (E));
11055 while Present (Prim) loop
11056 if Is_User_Defined_Equality (Node (Prim)) then
11057 return Node (Prim);
11058 end if;
11060 Next_Elmt (Prim);
11061 end loop;
11063 return Empty;
11064 end Get_User_Defined_Equality;
11066 ---------------
11067 -- Get_Views --
11068 ---------------
11070 procedure Get_Views
11071 (Typ : Entity_Id;
11072 Priv_Typ : out Entity_Id;
11073 Full_Typ : out Entity_Id;
11074 UFull_Typ : out Entity_Id;
11075 CRec_Typ : out Entity_Id)
11077 IP_View : Entity_Id;
11079 begin
11080 -- Assume that none of the views can be recovered
11082 Priv_Typ := Empty;
11083 Full_Typ := Empty;
11084 UFull_Typ := Empty;
11085 CRec_Typ := Empty;
11087 -- The input type is the corresponding record type of a protected or a
11088 -- task type.
11090 if Ekind (Typ) = E_Record_Type
11091 and then Is_Concurrent_Record_Type (Typ)
11092 then
11093 CRec_Typ := Typ;
11094 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
11095 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
11097 -- Otherwise the input type denotes an arbitrary type
11099 else
11100 IP_View := Incomplete_Or_Partial_View (Typ);
11102 -- The input type denotes the full view of a private type
11104 if Present (IP_View) then
11105 Priv_Typ := IP_View;
11106 Full_Typ := Typ;
11108 -- The input type is a private type
11110 elsif Is_Private_Type (Typ) then
11111 Priv_Typ := Typ;
11112 Full_Typ := Full_View (Priv_Typ);
11114 -- Otherwise the input type does not have any views
11116 else
11117 Full_Typ := Typ;
11118 end if;
11120 if Present (Full_Typ) and then Is_Private_Type (Full_Typ) then
11121 UFull_Typ := Underlying_Full_View (Full_Typ);
11123 if Present (UFull_Typ)
11124 and then Ekind (UFull_Typ) in E_Protected_Type | E_Task_Type
11125 then
11126 CRec_Typ := Corresponding_Record_Type (UFull_Typ);
11127 end if;
11129 else
11130 if Present (Full_Typ)
11131 and then Ekind (Full_Typ) in E_Protected_Type | E_Task_Type
11132 then
11133 CRec_Typ := Corresponding_Record_Type (Full_Typ);
11134 end if;
11135 end if;
11136 end if;
11137 end Get_Views;
11139 ------------------------------
11140 -- Has_Compatible_Alignment --
11141 ------------------------------
11143 function Has_Compatible_Alignment
11144 (Obj : Entity_Id;
11145 Expr : Node_Id;
11146 Layout_Done : Boolean) return Alignment_Result
11148 function Has_Compatible_Alignment_Internal
11149 (Obj : Entity_Id;
11150 Expr : Node_Id;
11151 Layout_Done : Boolean;
11152 Default : Alignment_Result) return Alignment_Result;
11153 -- This is the internal recursive function that actually does the work.
11154 -- There is one additional parameter, which says what the result should
11155 -- be if no alignment information is found, and there is no definite
11156 -- indication of compatible alignments. At the outer level, this is set
11157 -- to Unknown, but for internal recursive calls in the case where types
11158 -- are known to be correct, it is set to Known_Compatible.
11160 ---------------------------------------
11161 -- Has_Compatible_Alignment_Internal --
11162 ---------------------------------------
11164 function Has_Compatible_Alignment_Internal
11165 (Obj : Entity_Id;
11166 Expr : Node_Id;
11167 Layout_Done : Boolean;
11168 Default : Alignment_Result) return Alignment_Result
11170 Result : Alignment_Result := Known_Compatible;
11171 -- Holds the current status of the result. Note that once a value of
11172 -- Known_Incompatible is set, it is sticky and does not get changed
11173 -- to Unknown (the value in Result only gets worse as we go along,
11174 -- never better).
11176 Offs : Uint := No_Uint;
11177 -- Set to a factor of the offset from the base object when Expr is a
11178 -- selected or indexed component, based on Component_Bit_Offset and
11179 -- Component_Size respectively. A negative value is used to represent
11180 -- a value that is not known at compile time.
11182 procedure Check_Prefix;
11183 -- Checks the prefix recursively in the case where the expression
11184 -- is an indexed or selected component.
11186 procedure Set_Result (R : Alignment_Result);
11187 -- If R represents a worse outcome (unknown instead of known
11188 -- compatible, or known incompatible), then set Result to R.
11190 ------------------
11191 -- Check_Prefix --
11192 ------------------
11194 procedure Check_Prefix is
11195 begin
11196 -- The subtlety here is that in doing a recursive call to check
11197 -- the prefix, we have to decide what to do in the case where we
11198 -- don't find any specific indication of an alignment problem.
11200 -- At the outer level, we normally set Unknown as the result in
11201 -- this case, since we can only set Known_Compatible if we really
11202 -- know that the alignment value is OK, but for the recursive
11203 -- call, in the case where the types match, and we have not
11204 -- specified a peculiar alignment for the object, we are only
11205 -- concerned about suspicious rep clauses, the default case does
11206 -- not affect us, since the compiler will, in the absence of such
11207 -- rep clauses, ensure that the alignment is correct.
11209 if Default = Known_Compatible
11210 or else
11211 (Etype (Obj) = Etype (Expr)
11212 and then (not Known_Alignment (Obj)
11213 or else
11214 Alignment (Obj) = Alignment (Etype (Obj))))
11215 then
11216 Set_Result
11217 (Has_Compatible_Alignment_Internal
11218 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
11220 -- In all other cases, we need a full check on the prefix
11222 else
11223 Set_Result
11224 (Has_Compatible_Alignment_Internal
11225 (Obj, Prefix (Expr), Layout_Done, Unknown));
11226 end if;
11227 end Check_Prefix;
11229 ----------------
11230 -- Set_Result --
11231 ----------------
11233 procedure Set_Result (R : Alignment_Result) is
11234 begin
11235 if R > Result then
11236 Result := R;
11237 end if;
11238 end Set_Result;
11240 -- Start of processing for Has_Compatible_Alignment_Internal
11242 begin
11243 -- If Expr is a selected component, we must make sure there is no
11244 -- potentially troublesome component clause and that the record is
11245 -- not packed if the layout is not done.
11247 if Nkind (Expr) = N_Selected_Component then
11249 -- Packing generates unknown alignment if layout is not done
11251 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
11252 Set_Result (Unknown);
11253 end if;
11255 -- Check prefix and component offset
11257 Check_Prefix;
11258 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
11260 -- If Expr is an indexed component, we must make sure there is no
11261 -- potentially troublesome Component_Size clause and that the array
11262 -- is not bit-packed if the layout is not done.
11264 elsif Nkind (Expr) = N_Indexed_Component then
11265 declare
11266 Typ : constant Entity_Id := Etype (Prefix (Expr));
11268 begin
11269 -- Packing generates unknown alignment if layout is not done
11271 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
11272 Set_Result (Unknown);
11273 end if;
11275 -- Check prefix and component offset (or at least size)
11277 Check_Prefix;
11278 Offs := Indexed_Component_Bit_Offset (Expr);
11279 if No (Offs) then
11280 Offs := Component_Size (Typ);
11281 end if;
11282 end;
11283 end if;
11285 -- If we have a null offset, the result is entirely determined by
11286 -- the base object and has already been computed recursively.
11288 if Present (Offs) and then Offs = Uint_0 then
11289 null;
11291 -- Case where we know the alignment of the object
11293 elsif Known_Alignment (Obj) then
11294 declare
11295 ObjA : constant Uint := Alignment (Obj);
11296 ExpA : Uint := No_Uint;
11297 SizA : Uint := No_Uint;
11299 begin
11300 -- If alignment of Obj is 1, then we are always OK
11302 if ObjA = 1 then
11303 Set_Result (Known_Compatible);
11305 -- Alignment of Obj is greater than 1, so we need to check
11307 else
11308 -- If we have an offset, see if it is compatible
11310 if Present (Offs) and then Offs > Uint_0 then
11311 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
11312 Set_Result (Known_Incompatible);
11313 end if;
11315 -- See if Expr is an object with known alignment
11317 elsif Is_Entity_Name (Expr)
11318 and then Known_Alignment (Entity (Expr))
11319 then
11320 Offs := Uint_0;
11321 ExpA := Alignment (Entity (Expr));
11323 -- Otherwise, we can use the alignment of the type of Expr
11324 -- given that we already checked for discombobulating rep
11325 -- clauses for the cases of indexed and selected components
11326 -- above.
11328 elsif Known_Alignment (Etype (Expr)) then
11329 ExpA := Alignment (Etype (Expr));
11331 -- Otherwise the alignment is unknown
11333 else
11334 Set_Result (Default);
11335 end if;
11337 -- If we got an alignment, see if it is acceptable
11339 if Present (ExpA) and then ExpA < ObjA then
11340 Set_Result (Known_Incompatible);
11341 end if;
11343 -- If Expr is a component or an entire object with a known
11344 -- alignment, then we are fine. Otherwise, if its size is
11345 -- known, it must be big enough for the required alignment.
11347 if Present (Offs) then
11348 null;
11350 -- See if Expr is an object with known size
11352 elsif Is_Entity_Name (Expr)
11353 and then Known_Static_Esize (Entity (Expr))
11354 then
11355 SizA := Esize (Entity (Expr));
11357 -- Otherwise, we check the object size of the Expr type
11359 elsif Known_Static_Esize (Etype (Expr)) then
11360 SizA := Esize (Etype (Expr));
11361 end if;
11363 -- If we got a size, see if it is a multiple of the Obj
11364 -- alignment; if not, then the alignment cannot be
11365 -- acceptable, since the size is always a multiple of the
11366 -- alignment.
11368 if Present (SizA) then
11369 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
11370 Set_Result (Known_Incompatible);
11371 end if;
11372 end if;
11373 end if;
11374 end;
11376 -- If we do not know required alignment, any non-zero offset is a
11377 -- potential problem (but certainly may be OK, so result is unknown).
11379 elsif Present (Offs) then
11380 Set_Result (Unknown);
11382 -- If we can't find the result by direct comparison of alignment
11383 -- values, then there is still one case that we can determine known
11384 -- result, and that is when we can determine that the types are the
11385 -- same, and no alignments are specified. Then we known that the
11386 -- alignments are compatible, even if we don't know the alignment
11387 -- value in the front end.
11389 elsif Etype (Obj) = Etype (Expr) then
11391 -- Types are the same, but we have to check for possible size
11392 -- and alignments on the Expr object that may make the alignment
11393 -- different, even though the types are the same.
11395 if Is_Entity_Name (Expr) then
11397 -- First check alignment of the Expr object. Any alignment less
11398 -- than Maximum_Alignment is worrisome since this is the case
11399 -- where we do not know the alignment of Obj.
11401 if Known_Alignment (Entity (Expr))
11402 and then Alignment (Entity (Expr)) < Ttypes.Maximum_Alignment
11403 then
11404 Set_Result (Unknown);
11406 -- Now check size of Expr object. Any size that is not an even
11407 -- multiple of Maximum_Alignment is also worrisome since it
11408 -- may cause the alignment of the object to be less than the
11409 -- alignment of the type.
11411 elsif Known_Static_Esize (Entity (Expr))
11412 and then
11413 Esize (Entity (Expr)) mod
11414 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit)
11415 /= 0
11416 then
11417 Set_Result (Unknown);
11419 -- Otherwise same type is decisive
11421 else
11422 Set_Result (Known_Compatible);
11423 end if;
11424 end if;
11426 -- Another case to deal with is when there is an explicit size or
11427 -- alignment clause when the types are not the same. If so, then the
11428 -- result is Unknown. We don't need to do this test if the Default is
11429 -- Unknown, since that result will be set in any case.
11431 elsif Default /= Unknown
11432 and then (Has_Size_Clause (Etype (Expr))
11433 or else
11434 Has_Alignment_Clause (Etype (Expr)))
11435 then
11436 Set_Result (Unknown);
11438 -- If no indication found, set default
11440 else
11441 Set_Result (Default);
11442 end if;
11444 -- Return worst result found
11446 return Result;
11447 end Has_Compatible_Alignment_Internal;
11449 -- Start of processing for Has_Compatible_Alignment
11451 begin
11452 -- If Obj has no specified alignment, then set alignment from the type
11453 -- alignment. Perhaps we should always do this, but for sure we should
11454 -- do it when there is an address clause since we can do more if the
11455 -- alignment is known.
11457 if not Known_Alignment (Obj) and then Known_Alignment (Etype (Obj)) then
11458 Set_Alignment (Obj, Alignment (Etype (Obj)));
11459 end if;
11461 -- Now do the internal call that does all the work
11463 return
11464 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
11465 end Has_Compatible_Alignment;
11467 ----------------------
11468 -- Has_Declarations --
11469 ----------------------
11471 function Has_Declarations (N : Node_Id) return Boolean is
11472 begin
11473 return Nkind (N) in N_Accept_Statement
11474 | N_Block_Statement
11475 | N_Compilation_Unit_Aux
11476 | N_Entry_Body
11477 | N_Package_Body
11478 | N_Protected_Body
11479 | N_Subprogram_Body
11480 | N_Task_Body
11481 | N_Package_Specification;
11482 end Has_Declarations;
11484 ---------------------------------
11485 -- Has_Defaulted_Discriminants --
11486 ---------------------------------
11488 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
11489 begin
11490 return Has_Discriminants (Typ)
11491 and then Present (Discriminant_Default_Value
11492 (First_Discriminant (Typ)));
11493 end Has_Defaulted_Discriminants;
11495 -------------------
11496 -- Has_Denormals --
11497 -------------------
11499 function Has_Denormals (E : Entity_Id) return Boolean is
11500 begin
11501 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
11502 end Has_Denormals;
11504 -------------------------------------------
11505 -- Has_Discriminant_Dependent_Constraint --
11506 -------------------------------------------
11508 function Has_Discriminant_Dependent_Constraint
11509 (Comp : Entity_Id) return Boolean
11511 Comp_Decl : constant Node_Id := Parent (Comp);
11512 Subt_Indic : Node_Id;
11513 Constr : Node_Id;
11514 Assn : Node_Id;
11516 begin
11517 -- Discriminants can't depend on discriminants
11519 if Ekind (Comp) = E_Discriminant then
11520 return False;
11522 else
11523 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
11525 if Nkind (Subt_Indic) = N_Subtype_Indication then
11526 Constr := Constraint (Subt_Indic);
11528 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
11529 Assn := First (Constraints (Constr));
11530 while Present (Assn) loop
11531 case Nkind (Assn) is
11532 when N_Identifier
11533 | N_Range
11534 | N_Subtype_Indication
11536 if Depends_On_Discriminant (Assn) then
11537 return True;
11538 end if;
11540 when N_Discriminant_Association =>
11541 if Depends_On_Discriminant (Expression (Assn)) then
11542 return True;
11543 end if;
11545 when others =>
11546 null;
11547 end case;
11549 Next (Assn);
11550 end loop;
11551 end if;
11552 end if;
11553 end if;
11555 return False;
11556 end Has_Discriminant_Dependent_Constraint;
11558 --------------------------------------
11559 -- Has_Effectively_Volatile_Profile --
11560 --------------------------------------
11562 function Has_Effectively_Volatile_Profile
11563 (Subp_Id : Entity_Id) return Boolean
11565 Formal : Entity_Id;
11567 begin
11568 -- Inspect the formal parameters looking for an effectively volatile
11569 -- type for reading.
11571 Formal := First_Formal (Subp_Id);
11572 while Present (Formal) loop
11573 if Is_Effectively_Volatile_For_Reading (Etype (Formal)) then
11574 return True;
11575 end if;
11577 Next_Formal (Formal);
11578 end loop;
11580 -- Inspect the return type of functions
11582 if Ekind (Subp_Id) in E_Function | E_Generic_Function
11583 and then Is_Effectively_Volatile_For_Reading (Etype (Subp_Id))
11584 then
11585 return True;
11586 end if;
11588 return False;
11589 end Has_Effectively_Volatile_Profile;
11591 --------------------------
11592 -- Has_Enabled_Property --
11593 --------------------------
11595 function Has_Enabled_Property
11596 (Item_Id : Entity_Id;
11597 Property : Name_Id) return Boolean
11599 function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean;
11600 -- Determine whether a protected type or variable denoted by Item_Id
11601 -- has the property enabled.
11603 function State_Has_Enabled_Property return Boolean;
11604 -- Determine whether a state denoted by Item_Id has the property enabled
11606 function Type_Or_Variable_Has_Enabled_Property
11607 (Item_Id : Entity_Id) return Boolean;
11608 -- Determine whether type or variable denoted by Item_Id has the
11609 -- property enabled.
11611 -----------------------------------------------------
11612 -- Protected_Type_Or_Variable_Has_Enabled_Property --
11613 -----------------------------------------------------
11615 function Protected_Type_Or_Variable_Has_Enabled_Property return Boolean
11617 begin
11618 -- Protected entities always have the properties Async_Readers and
11619 -- Async_Writers (SPARK RM 7.1.2(16)).
11621 if Property = Name_Async_Readers
11622 or else Property = Name_Async_Writers
11623 then
11624 return True;
11626 -- Protected objects that have Part_Of components also inherit their
11627 -- properties Effective_Reads and Effective_Writes
11628 -- (SPARK RM 7.1.2(16)).
11630 elsif Is_Single_Protected_Object (Item_Id) then
11631 declare
11632 Constit_Elmt : Elmt_Id;
11633 Constit_Id : Entity_Id;
11634 Constits : constant Elist_Id
11635 := Part_Of_Constituents (Item_Id);
11636 begin
11637 if Present (Constits) then
11638 Constit_Elmt := First_Elmt (Constits);
11639 while Present (Constit_Elmt) loop
11640 Constit_Id := Node (Constit_Elmt);
11642 if Has_Enabled_Property (Constit_Id, Property) then
11643 return True;
11644 end if;
11646 Next_Elmt (Constit_Elmt);
11647 end loop;
11648 end if;
11649 end;
11650 end if;
11652 return False;
11653 end Protected_Type_Or_Variable_Has_Enabled_Property;
11655 --------------------------------
11656 -- State_Has_Enabled_Property --
11657 --------------------------------
11659 function State_Has_Enabled_Property return Boolean is
11660 Decl : constant Node_Id := Parent (Item_Id);
11662 procedure Find_Simple_Properties
11663 (Has_External : out Boolean;
11664 Has_Synchronous : out Boolean);
11665 -- Extract the simple properties associated with declaration Decl
11667 function Is_Enabled_External_Property return Boolean;
11668 -- Determine whether property Property appears within the external
11669 -- property list of declaration Decl, and return its status.
11671 ----------------------------
11672 -- Find_Simple_Properties --
11673 ----------------------------
11675 procedure Find_Simple_Properties
11676 (Has_External : out Boolean;
11677 Has_Synchronous : out Boolean)
11679 Opt : Node_Id;
11681 begin
11682 -- Assume that none of the properties are available
11684 Has_External := False;
11685 Has_Synchronous := False;
11687 Opt := First (Expressions (Decl));
11688 while Present (Opt) loop
11689 if Nkind (Opt) = N_Identifier then
11690 if Chars (Opt) = Name_External then
11691 Has_External := True;
11693 elsif Chars (Opt) = Name_Synchronous then
11694 Has_Synchronous := True;
11695 end if;
11696 end if;
11698 Next (Opt);
11699 end loop;
11700 end Find_Simple_Properties;
11702 ----------------------------------
11703 -- Is_Enabled_External_Property --
11704 ----------------------------------
11706 function Is_Enabled_External_Property return Boolean is
11707 Opt : Node_Id;
11708 Opt_Nam : Node_Id;
11709 Prop : Node_Id;
11710 Prop_Nam : Node_Id;
11711 Props : Node_Id;
11713 begin
11714 Opt := First (Component_Associations (Decl));
11715 while Present (Opt) loop
11716 Opt_Nam := First (Choices (Opt));
11718 if Nkind (Opt_Nam) = N_Identifier
11719 and then Chars (Opt_Nam) = Name_External
11720 then
11721 Props := Expression (Opt);
11723 -- Multiple properties appear as an aggregate
11725 if Nkind (Props) = N_Aggregate then
11727 -- Simple property form
11729 Prop := First (Expressions (Props));
11730 while Present (Prop) loop
11731 if Chars (Prop) = Property then
11732 return True;
11733 end if;
11735 Next (Prop);
11736 end loop;
11738 -- Property with expression form
11740 Prop := First (Component_Associations (Props));
11741 while Present (Prop) loop
11742 Prop_Nam := First (Choices (Prop));
11744 -- The property can be represented in two ways:
11745 -- others => <value>
11746 -- <property> => <value>
11748 if Nkind (Prop_Nam) = N_Others_Choice
11749 or else (Nkind (Prop_Nam) = N_Identifier
11750 and then Chars (Prop_Nam) = Property)
11751 then
11752 return Is_True (Expr_Value (Expression (Prop)));
11753 end if;
11755 Next (Prop);
11756 end loop;
11758 -- Single property
11760 else
11761 return Chars (Props) = Property;
11762 end if;
11763 end if;
11765 Next (Opt);
11766 end loop;
11768 return False;
11769 end Is_Enabled_External_Property;
11771 -- Local variables
11773 Has_External : Boolean;
11774 Has_Synchronous : Boolean;
11776 -- Start of processing for State_Has_Enabled_Property
11778 begin
11779 -- The declaration of an external abstract state appears as an
11780 -- extension aggregate. If this is not the case, properties can
11781 -- never be set.
11783 if Nkind (Decl) /= N_Extension_Aggregate then
11784 return False;
11785 end if;
11787 Find_Simple_Properties (Has_External, Has_Synchronous);
11789 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
11791 if Has_External then
11792 return True;
11794 -- Option External may enable or disable specific properties
11796 elsif Is_Enabled_External_Property then
11797 return True;
11799 -- Simple option Synchronous
11801 -- enables disables
11802 -- Async_Readers Effective_Reads
11803 -- Async_Writers Effective_Writes
11805 -- Note that both forms of External have higher precedence than
11806 -- Synchronous (SPARK RM 7.1.4(9)).
11808 elsif Has_Synchronous then
11809 return Property in Name_Async_Readers | Name_Async_Writers;
11810 end if;
11812 return False;
11813 end State_Has_Enabled_Property;
11815 -------------------------------------------
11816 -- Type_Or_Variable_Has_Enabled_Property --
11817 -------------------------------------------
11819 function Type_Or_Variable_Has_Enabled_Property
11820 (Item_Id : Entity_Id) return Boolean
11822 AR : constant Node_Id :=
11823 Get_Pragma (Item_Id, Pragma_Async_Readers);
11824 AW : constant Node_Id :=
11825 Get_Pragma (Item_Id, Pragma_Async_Writers);
11826 ER : constant Node_Id :=
11827 Get_Pragma (Item_Id, Pragma_Effective_Reads);
11828 EW : constant Node_Id :=
11829 Get_Pragma (Item_Id, Pragma_Effective_Writes);
11831 Is_Derived_Type_With_Volatile_Parent_Type : constant Boolean :=
11832 Is_Derived_Type (Item_Id)
11833 and then Is_Effectively_Volatile (Etype (Base_Type (Item_Id)));
11835 begin
11836 -- A non-effectively volatile object can never possess external
11837 -- properties.
11839 if not Is_Effectively_Volatile (Item_Id) then
11840 return False;
11842 -- External properties related to variables come in two flavors -
11843 -- explicit and implicit. The explicit case is characterized by the
11844 -- presence of a property pragma with an optional Boolean flag. The
11845 -- property is enabled when the flag evaluates to True or the flag is
11846 -- missing altogether.
11848 elsif Property = Name_Async_Readers and then Present (AR) then
11849 return Is_Enabled_Pragma (AR);
11851 elsif Property = Name_Async_Writers and then Present (AW) then
11852 return Is_Enabled_Pragma (AW);
11854 elsif Property = Name_Effective_Reads and then Present (ER) then
11855 return Is_Enabled_Pragma (ER);
11857 elsif Property = Name_Effective_Writes and then Present (EW) then
11858 return Is_Enabled_Pragma (EW);
11860 -- If other properties are set explicitly, then this one is set
11861 -- implicitly to False, except in the case of a derived type
11862 -- whose parent type is volatile (in that case, we will inherit
11863 -- from the parent type, below).
11865 elsif (Present (AR)
11866 or else Present (AW)
11867 or else Present (ER)
11868 or else Present (EW))
11869 and then not Is_Derived_Type_With_Volatile_Parent_Type
11870 then
11871 return False;
11873 -- For a private type (including subtype of a private types), look at
11874 -- the full view.
11876 elsif Is_Private_Type (Item_Id) and then Present (Full_View (Item_Id))
11877 then
11878 return Type_Or_Variable_Has_Enabled_Property (Full_View (Item_Id));
11880 -- For a derived type whose parent type is volatile, the
11881 -- property may be inherited (but ignore a non-volatile parent).
11883 elsif Is_Derived_Type_With_Volatile_Parent_Type then
11884 return Type_Or_Variable_Has_Enabled_Property
11885 (First_Subtype (Etype (Base_Type (Item_Id))));
11887 -- For a subtype, the property will be inherited from its base type.
11889 elsif Is_Type (Item_Id)
11890 and then not Is_Base_Type (Item_Id)
11891 then
11892 return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id));
11894 -- If not specified explicitly for an object and its type
11895 -- is effectively volatile, then take result from the type.
11897 elsif Is_Object (Item_Id)
11898 and then Is_Effectively_Volatile (Etype (Item_Id))
11899 then
11900 return Has_Enabled_Property (Etype (Item_Id), Property);
11902 -- The implicit case lacks all property pragmas
11904 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
11905 if Is_Protected_Type (Etype (Item_Id)) then
11906 return Protected_Type_Or_Variable_Has_Enabled_Property;
11907 else
11908 return True;
11909 end if;
11911 else
11912 return False;
11913 end if;
11914 end Type_Or_Variable_Has_Enabled_Property;
11916 -- Start of processing for Has_Enabled_Property
11918 begin
11919 -- Abstract states and variables have a flexible scheme of specifying
11920 -- external properties.
11922 if Ekind (Item_Id) = E_Abstract_State then
11923 return State_Has_Enabled_Property;
11925 elsif Ekind (Item_Id) in E_Variable | E_Constant then
11926 return Type_Or_Variable_Has_Enabled_Property (Item_Id);
11928 -- Other objects can only inherit properties through their type. We
11929 -- cannot call directly Type_Or_Variable_Has_Enabled_Property on
11930 -- these as they don't have contracts attached, which is expected by
11931 -- this function.
11933 elsif Is_Object (Item_Id) then
11934 return Type_Or_Variable_Has_Enabled_Property (Etype (Item_Id));
11936 elsif Is_Type (Item_Id) then
11937 return Type_Or_Variable_Has_Enabled_Property
11938 (Item_Id => First_Subtype (Item_Id));
11940 -- Otherwise a property is enabled when the related item is effectively
11941 -- volatile.
11943 else
11944 return Is_Effectively_Volatile (Item_Id);
11945 end if;
11946 end Has_Enabled_Property;
11948 -------------------------------------
11949 -- Has_Full_Default_Initialization --
11950 -------------------------------------
11952 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
11953 Comp : Entity_Id;
11955 begin
11956 -- A type subject to pragma Default_Initial_Condition may be fully
11957 -- default initialized depending on inheritance and the argument of
11958 -- the pragma. Since any type may act as the full view of a private
11959 -- type, this check must be performed prior to the specialized tests
11960 -- below.
11962 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
11963 return True;
11964 end if;
11966 -- A scalar type is fully default initialized if it is subject to aspect
11967 -- Default_Value.
11969 if Is_Scalar_Type (Typ) then
11970 return Has_Default_Aspect (Typ);
11972 -- An access type is fully default initialized by default
11974 elsif Is_Access_Type (Typ) then
11975 return True;
11977 -- An array type is fully default initialized if its element type is
11978 -- scalar and the array type carries aspect Default_Component_Value or
11979 -- the element type is fully default initialized.
11981 elsif Is_Array_Type (Typ) then
11982 return
11983 Has_Default_Aspect (Typ)
11984 or else Has_Full_Default_Initialization (Component_Type (Typ));
11986 -- A protected type, record type, or type extension is fully default
11987 -- initialized if all its components either carry an initialization
11988 -- expression or have a type that is fully default initialized. The
11989 -- parent type of a type extension must be fully default initialized.
11991 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
11993 -- Inspect all entities defined in the scope of the type, looking for
11994 -- uninitialized components.
11996 Comp := First_Component (Typ);
11997 while Present (Comp) loop
11998 if Comes_From_Source (Comp)
11999 and then No (Expression (Parent (Comp)))
12000 and then not Has_Full_Default_Initialization (Etype (Comp))
12001 then
12002 return False;
12003 end if;
12005 Next_Component (Comp);
12006 end loop;
12008 -- Ensure that the parent type of a type extension is fully default
12009 -- initialized.
12011 if Etype (Typ) /= Typ
12012 and then not Has_Full_Default_Initialization (Etype (Typ))
12013 then
12014 return False;
12015 end if;
12017 -- If we get here, then all components and parent portion are fully
12018 -- default initialized.
12020 return True;
12022 -- A task type is fully default initialized by default
12024 elsif Is_Task_Type (Typ) then
12025 return True;
12027 -- Otherwise the type is not fully default initialized
12029 else
12030 return False;
12031 end if;
12032 end Has_Full_Default_Initialization;
12034 -----------------------------------------------
12035 -- Has_Fully_Default_Initializing_DIC_Pragma --
12036 -----------------------------------------------
12038 function Has_Fully_Default_Initializing_DIC_Pragma
12039 (Typ : Entity_Id) return Boolean
12041 Args : List_Id;
12042 Prag : Node_Id;
12044 begin
12045 -- A type that inherits pragma Default_Initial_Condition from a parent
12046 -- type is automatically fully default initialized.
12048 if Has_Inherited_DIC (Typ) then
12049 return True;
12051 -- Otherwise the type is fully default initialized only when the pragma
12052 -- appears without an argument, or the argument is non-null.
12054 elsif Has_Own_DIC (Typ) then
12055 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
12056 pragma Assert (Present (Prag));
12057 Args := Pragma_Argument_Associations (Prag);
12059 -- The pragma appears without an argument in which case it defaults
12060 -- to True.
12062 if No (Args) then
12063 return True;
12065 -- The pragma appears with a non-null expression
12067 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
12068 return True;
12069 end if;
12070 end if;
12072 return False;
12073 end Has_Fully_Default_Initializing_DIC_Pragma;
12075 ---------------------------------
12076 -- Has_Inferable_Discriminants --
12077 ---------------------------------
12079 function Has_Inferable_Discriminants (N : Node_Id) return Boolean is
12081 function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean;
12082 -- Determines whether the left-most prefix of a selected component is a
12083 -- formal parameter in a subprogram. Assumes N is a selected component.
12085 --------------------------------
12086 -- Prefix_Is_Formal_Parameter --
12087 --------------------------------
12089 function Prefix_Is_Formal_Parameter (N : Node_Id) return Boolean is
12090 Sel_Comp : Node_Id;
12092 begin
12093 -- Move to the left-most prefix by climbing up the tree
12095 Sel_Comp := N;
12096 while Present (Parent (Sel_Comp))
12097 and then Nkind (Parent (Sel_Comp)) = N_Selected_Component
12098 loop
12099 Sel_Comp := Parent (Sel_Comp);
12100 end loop;
12102 return Is_Formal (Entity (Prefix (Sel_Comp)));
12103 end Prefix_Is_Formal_Parameter;
12105 -- Start of processing for Has_Inferable_Discriminants
12107 begin
12108 -- For selected components, the subtype of the selector must be a
12109 -- constrained Unchecked_Union. If the component is subject to a
12110 -- per-object constraint, then the enclosing object must either be
12111 -- a regular discriminated type or must have inferable discriminants.
12113 if Nkind (N) = N_Selected_Component then
12114 -- The call to Has_Inferable_Discriminants will determine whether
12115 -- the selector has a constrained Unchecked_Union nominal type.
12117 if not Has_Inferable_Discriminants (Selector_Name (N)) then
12118 return False;
12119 end if;
12121 -- A small hack. If we have a per-object constrained selected
12122 -- component of a formal parameter, return True since we do not
12123 -- know the actual parameter association yet.
12125 return not Has_Per_Object_Constraint (Entity (Selector_Name (N)))
12126 or else not Is_Unchecked_Union (Etype (Prefix (N)))
12127 or else Has_Inferable_Discriminants (Prefix (N))
12128 or else Prefix_Is_Formal_Parameter (N);
12130 -- A qualified expression has inferable discriminants if its subtype
12131 -- mark is a constrained Unchecked_Union subtype.
12133 elsif Nkind (N) = N_Qualified_Expression then
12134 return Is_Unchecked_Union (Etype (Subtype_Mark (N)))
12135 and then Is_Constrained (Etype (Subtype_Mark (N)));
12137 -- For all other names, it is sufficient to have a constrained
12138 -- Unchecked_Union nominal subtype.
12140 else
12141 return Is_Unchecked_Union (Etype (N))
12142 and then Is_Constrained (Etype (N));
12143 end if;
12144 end Has_Inferable_Discriminants;
12146 --------------------
12147 -- Has_Infinities --
12148 --------------------
12150 function Has_Infinities (E : Entity_Id) return Boolean is
12151 begin
12152 return
12153 Is_Floating_Point_Type (E)
12154 and then Nkind (Scalar_Range (E)) = N_Range
12155 and then Includes_Infinities (Scalar_Range (E));
12156 end Has_Infinities;
12158 --------------------
12159 -- Has_Interfaces --
12160 --------------------
12162 function Has_Interfaces
12163 (T : Entity_Id;
12164 Use_Full_View : Boolean := True) return Boolean
12166 Typ : Entity_Id := Base_Type (T);
12168 begin
12169 -- Handle concurrent types
12171 if Is_Concurrent_Type (Typ) then
12172 Typ := Corresponding_Record_Type (Typ);
12173 end if;
12175 if No (Typ)
12176 or else not Is_Record_Type (Typ)
12177 or else not Is_Tagged_Type (Typ)
12178 then
12179 return False;
12180 end if;
12182 -- Handle private types
12184 if Use_Full_View and then Present (Full_View (Typ)) then
12185 Typ := Full_View (Typ);
12186 end if;
12188 -- Handle concurrent record types
12190 if Is_Concurrent_Record_Type (Typ)
12191 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
12192 then
12193 return True;
12194 end if;
12196 loop
12197 if Is_Interface (Typ)
12198 or else
12199 (Is_Record_Type (Typ)
12200 and then Present (Interfaces (Typ))
12201 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
12202 then
12203 return True;
12204 end if;
12206 exit when Etype (Typ) = Typ
12208 -- Handle private types
12210 or else (Present (Full_View (Etype (Typ)))
12211 and then Full_View (Etype (Typ)) = Typ)
12213 -- Protect frontend against wrong sources with cyclic derivations
12215 or else Etype (Typ) = T;
12217 -- Climb to the ancestor type handling private types
12219 if Present (Full_View (Etype (Typ))) then
12220 Typ := Full_View (Etype (Typ));
12221 else
12222 Typ := Etype (Typ);
12223 end if;
12224 end loop;
12226 return False;
12227 end Has_Interfaces;
12229 --------------------------
12230 -- Has_Max_Queue_Length --
12231 --------------------------
12233 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
12234 begin
12235 return
12236 Ekind (Id) = E_Entry
12237 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
12238 end Has_Max_Queue_Length;
12240 ---------------------------------
12241 -- Has_No_Obvious_Side_Effects --
12242 ---------------------------------
12244 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
12245 begin
12246 -- For now handle literals, constants, and non-volatile variables and
12247 -- expressions combining these with operators or short circuit forms.
12249 if Nkind (N) in N_Numeric_Or_String_Literal then
12250 return True;
12252 elsif Nkind (N) = N_Character_Literal then
12253 return True;
12255 elsif Nkind (N) in N_Unary_Op then
12256 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
12258 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
12259 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
12260 and then
12261 Has_No_Obvious_Side_Effects (Right_Opnd (N));
12263 elsif Nkind (N) = N_Expression_With_Actions
12264 and then Is_Empty_List (Actions (N))
12265 then
12266 return Has_No_Obvious_Side_Effects (Expression (N));
12268 elsif Nkind (N) in N_Has_Entity then
12269 return Present (Entity (N))
12270 and then
12271 Ekind (Entity (N)) in
12272 E_Variable | E_Constant | E_Enumeration_Literal |
12273 E_In_Parameter | E_Out_Parameter | E_In_Out_Parameter
12274 and then not Is_Volatile (Entity (N));
12276 else
12277 return False;
12278 end if;
12279 end Has_No_Obvious_Side_Effects;
12281 -----------------------------
12282 -- Has_Non_Null_Refinement --
12283 -----------------------------
12285 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
12286 Constits : Elist_Id;
12288 begin
12289 pragma Assert (Ekind (Id) = E_Abstract_State);
12290 Constits := Refinement_Constituents (Id);
12292 -- For a refinement to be non-null, the first constituent must be
12293 -- anything other than null.
12295 return
12296 Present (Constits)
12297 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
12298 end Has_Non_Null_Refinement;
12300 -----------------------------
12301 -- Has_Non_Null_Statements --
12302 -----------------------------
12304 function Has_Non_Null_Statements (L : List_Id) return Boolean is
12305 Node : Node_Id;
12307 begin
12308 Node := First (L);
12310 while Present (Node) loop
12311 if Nkind (Node) not in N_Null_Statement | N_Call_Marker then
12312 return True;
12313 end if;
12315 Next (Node);
12316 end loop;
12318 return False;
12319 end Has_Non_Null_Statements;
12321 ----------------------------------
12322 -- Is_Access_Subprogram_Wrapper --
12323 ----------------------------------
12325 function Is_Access_Subprogram_Wrapper (E : Entity_Id) return Boolean is
12326 Formal : constant Entity_Id := Last_Formal (E);
12327 begin
12328 return Present (Formal)
12329 and then Ekind (Etype (Formal)) in Access_Subprogram_Kind
12330 and then Access_Subprogram_Wrapper
12331 (Directly_Designated_Type (Etype (Formal))) = E;
12332 end Is_Access_Subprogram_Wrapper;
12334 ---------------------------
12335 -- Is_Explicitly_Aliased --
12336 ---------------------------
12338 function Is_Explicitly_Aliased (N : Node_Id) return Boolean is
12339 begin
12340 return Is_Formal (N)
12341 and then Present (Parent (N))
12342 and then Nkind (Parent (N)) = N_Parameter_Specification
12343 and then Aliased_Present (Parent (N));
12344 end Is_Explicitly_Aliased;
12346 ----------------------------
12347 -- Is_Container_Aggregate --
12348 ----------------------------
12350 function Is_Container_Aggregate (Exp : Node_Id) return Boolean is
12352 function Is_Record_Aggregate return Boolean is
12353 (Is_Parenthesis_Aggregate (Exp));
12354 -- Given an aggregate whose type is a record type with specified
12355 -- Aggregate aspect, we determine whether it is a record aggregate or
12356 -- a container aggregate by ckecking whether it uses parentheses () or
12357 -- square brackets []. If the code where the aggregate occurs can see
12358 -- only a partial view of the aggregate's type then the aggregate cannot
12359 -- be a record type and must then use []; an aggregate of a private type
12360 -- has to be a container aggregate and must then use [].
12362 begin
12363 return Nkind (Exp) = N_Aggregate
12364 and then Has_Aspect (Etype (Exp), Aspect_Aggregate)
12365 and then not Is_Record_Aggregate;
12366 end Is_Container_Aggregate;
12368 ---------------------------------
12369 -- Side_Effect_Free_Statements --
12370 ---------------------------------
12372 function Side_Effect_Free_Statements (L : List_Id) return Boolean is
12373 Node : Node_Id;
12375 begin
12376 Node := First (L);
12378 while Present (Node) loop
12379 case Nkind (Node) is
12380 when N_Null_Statement | N_Call_Marker | N_Raise_xxx_Error =>
12381 null;
12383 when N_Object_Declaration =>
12384 if Present (Expression (Node))
12385 and then not Side_Effect_Free (Expression (Node))
12386 then
12387 return False;
12388 end if;
12390 when others =>
12391 return False;
12392 end case;
12394 Next (Node);
12395 end loop;
12397 return True;
12398 end Side_Effect_Free_Statements;
12400 ---------------------------
12401 -- Side_Effect_Free_Loop --
12402 ---------------------------
12404 function Side_Effect_Free_Loop (N : Node_Id) return Boolean is
12405 Scheme : Node_Id;
12406 Spec : Node_Id;
12407 Subt : Node_Id;
12409 begin
12410 -- If this is not a loop (e.g. because the loop has been rewritten),
12411 -- then return false.
12413 if Nkind (N) /= N_Loop_Statement then
12414 return False;
12415 end if;
12417 -- First check the statements
12419 if Side_Effect_Free_Statements (Statements (N)) then
12421 -- Then check the loop condition/indexes
12423 if Present (Iteration_Scheme (N)) then
12424 Scheme := Iteration_Scheme (N);
12426 if Present (Condition (Scheme))
12427 or else Present (Iterator_Specification (Scheme))
12428 then
12429 return False;
12430 elsif Present (Loop_Parameter_Specification (Scheme)) then
12431 Spec := Loop_Parameter_Specification (Scheme);
12432 Subt := Discrete_Subtype_Definition (Spec);
12434 if Present (Subt) then
12435 if Nkind (Subt) = N_Range then
12436 return Side_Effect_Free (Low_Bound (Subt))
12437 and then Side_Effect_Free (High_Bound (Subt));
12438 else
12439 -- subtype indication
12441 return True;
12442 end if;
12443 end if;
12444 end if;
12445 end if;
12446 end if;
12448 return False;
12449 end Side_Effect_Free_Loop;
12451 ----------------------------------
12452 -- Has_Non_Trivial_Precondition --
12453 ----------------------------------
12455 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
12456 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre,
12457 Class_Present => True);
12458 begin
12459 return
12460 Present (Pre)
12461 and then not Is_Entity_Name (Expression (Pre));
12462 end Has_Non_Trivial_Precondition;
12464 -------------------
12465 -- Has_Null_Body --
12466 -------------------
12468 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
12469 Body_Id : Entity_Id;
12470 Decl : Node_Id;
12471 Spec : Node_Id;
12472 Stmt1 : Node_Id;
12473 Stmt2 : Node_Id;
12475 begin
12476 Spec := Parent (Proc_Id);
12477 Decl := Parent (Spec);
12479 -- Retrieve the entity of the procedure body (e.g. invariant proc).
12481 if Nkind (Spec) = N_Procedure_Specification
12482 and then Nkind (Decl) = N_Subprogram_Declaration
12483 then
12484 Body_Id := Corresponding_Body (Decl);
12486 -- The body acts as a spec
12488 else
12489 Body_Id := Proc_Id;
12490 end if;
12492 -- The body will be generated later
12494 if No (Body_Id) then
12495 return False;
12496 end if;
12498 Spec := Parent (Body_Id);
12499 Decl := Parent (Spec);
12501 pragma Assert
12502 (Nkind (Spec) = N_Procedure_Specification
12503 and then Nkind (Decl) = N_Subprogram_Body);
12505 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
12507 -- Look for a null statement followed by an optional return
12508 -- statement.
12510 if Nkind (Stmt1) = N_Null_Statement then
12511 Stmt2 := Next (Stmt1);
12513 if Present (Stmt2) then
12514 return Nkind (Stmt2) = N_Simple_Return_Statement;
12515 else
12516 return True;
12517 end if;
12518 end if;
12520 return False;
12521 end Has_Null_Body;
12523 ------------------------
12524 -- Has_Null_Exclusion --
12525 ------------------------
12527 function Has_Null_Exclusion (N : Node_Id) return Boolean is
12528 begin
12529 case Nkind (N) is
12530 when N_Access_Definition
12531 | N_Access_Function_Definition
12532 | N_Access_Procedure_Definition
12533 | N_Access_To_Object_Definition
12534 | N_Allocator
12535 | N_Derived_Type_Definition
12536 | N_Function_Specification
12537 | N_Subtype_Declaration
12539 return Null_Exclusion_Present (N);
12541 when N_Component_Definition
12542 | N_Formal_Object_Declaration
12544 if Present (Subtype_Mark (N)) then
12545 return Null_Exclusion_Present (N);
12546 else pragma Assert (Present (Access_Definition (N)));
12547 return Null_Exclusion_Present (Access_Definition (N));
12548 end if;
12550 when N_Object_Renaming_Declaration =>
12551 if Present (Subtype_Mark (N)) then
12552 return Null_Exclusion_Present (N);
12553 elsif Present (Access_Definition (N)) then
12554 return Null_Exclusion_Present (Access_Definition (N));
12555 else
12556 return False; -- Case of no subtype in renaming (AI12-0275)
12557 end if;
12559 when N_Discriminant_Specification =>
12560 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
12561 return Null_Exclusion_Present (Discriminant_Type (N));
12562 else
12563 return Null_Exclusion_Present (N);
12564 end if;
12566 when N_Object_Declaration =>
12567 if Nkind (Object_Definition (N)) = N_Access_Definition then
12568 return Null_Exclusion_Present (Object_Definition (N));
12569 else
12570 return Null_Exclusion_Present (N);
12571 end if;
12573 when N_Parameter_Specification =>
12574 if Nkind (Parameter_Type (N)) = N_Access_Definition then
12575 return Null_Exclusion_Present (Parameter_Type (N))
12576 or else Null_Exclusion_Present (N);
12577 else
12578 return Null_Exclusion_Present (N);
12579 end if;
12581 when others =>
12582 return False;
12583 end case;
12584 end Has_Null_Exclusion;
12586 ------------------------
12587 -- Has_Null_Extension --
12588 ------------------------
12590 function Has_Null_Extension (T : Entity_Id) return Boolean is
12591 B : constant Entity_Id := Base_Type (T);
12592 Comps : Node_Id;
12593 Ext : Node_Id;
12595 begin
12596 if Nkind (Parent (B)) = N_Full_Type_Declaration
12597 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
12598 then
12599 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
12601 if Present (Ext) then
12602 if Null_Present (Ext) then
12603 return True;
12604 else
12605 Comps := Component_List (Ext);
12607 -- The null component list is rewritten during analysis to
12608 -- include the parent component. Any other component indicates
12609 -- that the extension was not originally null.
12611 return Null_Present (Comps)
12612 or else No (Next (First (Component_Items (Comps))));
12613 end if;
12614 else
12615 return False;
12616 end if;
12618 else
12619 return False;
12620 end if;
12621 end Has_Null_Extension;
12623 -------------------------
12624 -- Has_Null_Refinement --
12625 -------------------------
12627 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
12628 Constits : Elist_Id;
12630 begin
12631 pragma Assert (Ekind (Id) = E_Abstract_State);
12632 Constits := Refinement_Constituents (Id);
12634 -- For a refinement to be null, the state's sole constituent must be a
12635 -- null.
12637 return
12638 Present (Constits)
12639 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
12640 end Has_Null_Refinement;
12642 ------------------------------------------
12643 -- Has_Nonstatic_Class_Wide_Pre_Or_Post --
12644 ------------------------------------------
12646 function Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post
12647 (Subp : Entity_Id) return Boolean
12649 Disp_Type : constant Entity_Id := Find_Dispatching_Type (Subp);
12650 Prag : Node_Id;
12651 Pragma_Arg : Node_Id;
12653 begin
12654 if Present (Disp_Type)
12655 and then Is_Abstract_Type (Disp_Type)
12656 and then Present (Contract (Subp))
12657 then
12658 Prag := Pre_Post_Conditions (Contract (Subp));
12660 while Present (Prag) loop
12661 if Pragma_Name (Prag) in Name_Precondition | Name_Postcondition
12662 and then Class_Present (Prag)
12663 then
12664 Pragma_Arg :=
12665 Nlists.First
12666 (Pragma_Argument_Associations (Prag));
12668 if not Is_Static_Expression (Expression (Pragma_Arg)) then
12669 return True;
12670 end if;
12671 end if;
12673 Prag := Next_Pragma (Prag);
12674 end loop;
12675 end if;
12677 return False;
12678 end Is_Prim_Of_Abst_Type_With_Nonstatic_CW_Pre_Post;
12680 -------------------------------
12681 -- Has_Overriding_Initialize --
12682 -------------------------------
12684 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
12685 BT : constant Entity_Id := Base_Type (T);
12686 P : Elmt_Id;
12688 begin
12689 if Is_Controlled (BT) then
12690 if Is_RTU (Scope (BT), Ada_Finalization) then
12691 return False;
12693 elsif Present (Primitive_Operations (BT)) then
12694 P := First_Elmt (Primitive_Operations (BT));
12695 while Present (P) loop
12696 declare
12697 Init : constant Entity_Id := Node (P);
12698 Formal : constant Entity_Id := First_Formal (Init);
12699 begin
12700 if Ekind (Init) = E_Procedure
12701 and then Chars (Init) = Name_Initialize
12702 and then Comes_From_Source (Init)
12703 and then Present (Formal)
12704 and then Etype (Formal) = BT
12705 and then No (Next_Formal (Formal))
12706 and then (Ada_Version < Ada_2012
12707 or else not Null_Present (Parent (Init)))
12708 then
12709 return True;
12710 end if;
12711 end;
12713 Next_Elmt (P);
12714 end loop;
12715 end if;
12717 -- Here if type itself does not have a non-null Initialize operation:
12718 -- check immediate ancestor.
12720 if Is_Derived_Type (BT)
12721 and then Has_Overriding_Initialize (Etype (BT))
12722 then
12723 return True;
12724 end if;
12725 end if;
12727 return False;
12728 end Has_Overriding_Initialize;
12730 --------------------------------------
12731 -- Has_Preelaborable_Initialization --
12732 --------------------------------------
12734 function Has_Preelaborable_Initialization
12735 (E : Entity_Id;
12736 Preelab_Init_Expr : Node_Id := Empty) return Boolean
12738 Has_PE : Boolean;
12740 procedure Check_Components (E : Entity_Id);
12741 -- Check component/discriminant chain, sets Has_PE False if a component
12742 -- or discriminant does not meet the preelaborable initialization rules.
12744 function Type_Named_In_Preelab_Init_Expression
12745 (Typ : Entity_Id;
12746 Expr : Node_Id) return Boolean;
12747 -- Returns True iff Typ'Preelaborable_Initialization occurs in Expr
12748 -- (where Expr may be a conjunction of one or more P_I attributes).
12750 ----------------------
12751 -- Check_Components --
12752 ----------------------
12754 procedure Check_Components (E : Entity_Id) is
12755 Ent : Entity_Id;
12756 Exp : Node_Id;
12758 begin
12759 -- Loop through components and discriminants of record or protected
12760 -- type.
12762 Ent := First_Component_Or_Discriminant (E);
12763 while Present (Ent) loop
12765 case Ekind (Ent) is
12766 when E_Component =>
12768 -- Get default expression if any. If there is no declaration
12769 -- node, it means we have an internal entity. The parent and
12770 -- tag fields are examples of such entities. For such cases,
12771 -- we just test the type of the entity.
12773 if Present (Declaration_Node (Ent)) then
12774 Exp := Expression (Declaration_Node (Ent));
12775 else
12776 Exp := Empty;
12777 end if;
12779 when E_Discriminant =>
12781 -- Note: for a renamed discriminant, the Declaration_Node
12782 -- may point to the one from the ancestor, and have a
12783 -- different expression, so use the proper attribute to
12784 -- retrieve the expression from the derived constraint.
12786 Exp := Discriminant_Default_Value (Ent);
12788 when others =>
12789 raise Program_Error;
12790 end case;
12792 -- A component has PI if it has no default expression and the
12793 -- component type has PI.
12795 if No (Exp) then
12796 if not Has_Preelaborable_Initialization
12797 (Etype (Ent), Preelab_Init_Expr)
12798 then
12799 Has_PE := False;
12800 exit;
12801 end if;
12803 -- Require the default expression to be preelaborable
12805 elsif not Is_Preelaborable_Construct (Exp) then
12806 Has_PE := False;
12807 exit;
12808 end if;
12810 Next_Component_Or_Discriminant (Ent);
12811 end loop;
12812 end Check_Components;
12814 --------------------------------------
12815 -- Type_Named_In_Preelab_Expression --
12816 --------------------------------------
12818 function Type_Named_In_Preelab_Init_Expression
12819 (Typ : Entity_Id;
12820 Expr : Node_Id) return Boolean
12822 begin
12823 -- Return True if Expr is a Preelaborable_Initialization attribute
12824 -- and the prefix is a subtype that has the same type as Typ.
12826 if Nkind (Expr) = N_Attribute_Reference
12827 and then Attribute_Name (Expr) = Name_Preelaborable_Initialization
12828 and then Is_Entity_Name (Prefix (Expr))
12829 and then Base_Type (Entity (Prefix (Expr))) = Base_Type (Typ)
12830 then
12831 return True;
12833 -- In the case where Expr is a conjunction, test whether either
12834 -- operand is a Preelaborable_Initialization attribute whose prefix
12835 -- has the same type as Typ, and return True if so.
12837 elsif Nkind (Expr) = N_Op_And
12838 and then
12839 (Type_Named_In_Preelab_Init_Expression (Typ, Left_Opnd (Expr))
12840 or else
12841 Type_Named_In_Preelab_Init_Expression (Typ, Right_Opnd (Expr)))
12842 then
12843 return True;
12845 -- Typ not named in a Preelaborable_Initialization attribute of Expr
12847 else
12848 return False;
12849 end if;
12850 end Type_Named_In_Preelab_Init_Expression;
12852 -- Start of processing for Has_Preelaborable_Initialization
12854 begin
12855 -- Immediate return if already marked as known preelaborable init. This
12856 -- covers types for which this function has already been called once
12857 -- and returned True (in which case the result is cached), and also
12858 -- types to which a pragma Preelaborable_Initialization applies.
12860 if Known_To_Have_Preelab_Init (E) then
12861 return True;
12862 end if;
12864 -- If the type is a subtype representing a generic actual type, then
12865 -- test whether its base type has preelaborable initialization since
12866 -- the subtype representing the actual does not inherit this attribute
12867 -- from the actual or formal. (but maybe it should???)
12869 if Is_Generic_Actual_Type (E) then
12870 return Has_Preelaborable_Initialization (Base_Type (E));
12871 end if;
12873 -- All elementary types have preelaborable initialization
12875 if Is_Elementary_Type (E) then
12876 Has_PE := True;
12878 -- Array types have PI if the component type has PI
12880 elsif Is_Array_Type (E) then
12881 Has_PE := Has_Preelaborable_Initialization
12882 (Component_Type (E), Preelab_Init_Expr);
12884 -- A derived type has preelaborable initialization if its parent type
12885 -- has preelaborable initialization and (in the case of a derived record
12886 -- extension) if the non-inherited components all have preelaborable
12887 -- initialization. However, a user-defined controlled type with an
12888 -- overriding Initialize procedure does not have preelaborable
12889 -- initialization.
12891 elsif Is_Derived_Type (E) then
12893 -- When the rule of RM 10.2.1(11.8/5) applies, we presume a component
12894 -- of a generic formal derived type has preelaborable initialization.
12895 -- (See comment on spec of Has_Preelaborable_Initialization.)
12897 if Is_Generic_Type (E)
12898 and then Present (Preelab_Init_Expr)
12899 and then
12900 Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr)
12901 then
12902 return True;
12903 end if;
12905 -- If the derived type is a private extension then it doesn't have
12906 -- preelaborable initialization.
12908 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
12909 return False;
12910 end if;
12912 -- First check whether ancestor type has preelaborable initialization
12914 Has_PE := Has_Preelaborable_Initialization
12915 (Etype (Base_Type (E)), Preelab_Init_Expr);
12917 -- If OK, check extension components (if any)
12919 if Has_PE and then Is_Record_Type (E) then
12920 Check_Components (E);
12921 end if;
12923 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
12924 -- with a user defined Initialize procedure does not have PI. If
12925 -- the type is untagged, the control primitives come from a component
12926 -- that has already been checked.
12928 if Has_PE
12929 and then Is_Controlled (E)
12930 and then Is_Tagged_Type (E)
12931 and then Has_Overriding_Initialize (E)
12932 then
12933 Has_PE := False;
12934 end if;
12936 -- Private types not derived from a type having preelaborable init and
12937 -- that are not marked with pragma Preelaborable_Initialization do not
12938 -- have preelaborable initialization.
12940 elsif Is_Private_Type (E) then
12942 -- When the rule of RM 10.2.1(11.8/5) applies, we presume a component
12943 -- of a generic formal private type has preelaborable initialization.
12944 -- (See comment on spec of Has_Preelaborable_Initialization.)
12946 if Is_Generic_Type (E)
12947 and then Present (Preelab_Init_Expr)
12948 and then
12949 Type_Named_In_Preelab_Init_Expression (E, Preelab_Init_Expr)
12950 then
12951 return True;
12952 else
12953 return False;
12954 end if;
12956 -- Record type has PI if it is non private and all components have PI
12958 elsif Is_Record_Type (E) then
12959 Has_PE := True;
12960 Check_Components (E);
12962 -- Protected types must not have entries, and components must meet
12963 -- same set of rules as for record components.
12965 elsif Is_Protected_Type (E) then
12966 if Has_Entries (E) then
12967 Has_PE := False;
12968 else
12969 Has_PE := True;
12970 Check_Components (E);
12971 end if;
12973 -- Type System.Address always has preelaborable initialization
12975 elsif Is_RTE (E, RE_Address) then
12976 Has_PE := True;
12978 -- In all other cases, type does not have preelaborable initialization
12980 else
12981 return False;
12982 end if;
12984 -- If type has preelaborable initialization, cache result
12986 if Has_PE then
12987 Set_Known_To_Have_Preelab_Init (E);
12988 end if;
12990 return Has_PE;
12991 end Has_Preelaborable_Initialization;
12993 ----------------
12994 -- Has_Prefix --
12995 ----------------
12997 function Has_Prefix (N : Node_Id) return Boolean is
12998 begin
12999 return Nkind (N) in
13000 N_Attribute_Reference | N_Expanded_Name | N_Explicit_Dereference |
13001 N_Indexed_Component | N_Reference | N_Selected_Component |
13002 N_Slice;
13003 end Has_Prefix;
13005 ---------------------------
13006 -- Has_Private_Component --
13007 ---------------------------
13009 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
13010 Btype : Entity_Id := Base_Type (Type_Id);
13011 Component : Entity_Id;
13013 begin
13014 if Error_Posted (Type_Id)
13015 or else Error_Posted (Btype)
13016 then
13017 return False;
13018 end if;
13020 if Is_Class_Wide_Type (Btype) then
13021 Btype := Root_Type (Btype);
13022 end if;
13024 if Is_Private_Type (Btype) then
13025 declare
13026 UT : constant Entity_Id := Underlying_Type (Btype);
13027 begin
13028 if No (UT) then
13029 if No (Full_View (Btype)) then
13030 return not Is_Generic_Type (Btype)
13031 and then
13032 not Is_Generic_Type (Root_Type (Btype));
13033 else
13034 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
13035 end if;
13036 else
13037 return not Is_Frozen (UT) and then Has_Private_Component (UT);
13038 end if;
13039 end;
13041 elsif Is_Array_Type (Btype) then
13042 return Has_Private_Component (Component_Type (Btype));
13044 elsif Is_Record_Type (Btype) then
13045 Component := First_Component (Btype);
13046 while Present (Component) loop
13047 if Has_Private_Component (Etype (Component)) then
13048 return True;
13049 end if;
13051 Next_Component (Component);
13052 end loop;
13054 return False;
13056 elsif Is_Protected_Type (Btype)
13057 and then Present (Corresponding_Record_Type (Btype))
13058 then
13059 return Has_Private_Component (Corresponding_Record_Type (Btype));
13061 else
13062 return False;
13063 end if;
13064 end Has_Private_Component;
13066 --------------------------------
13067 -- Has_Relaxed_Initialization --
13068 --------------------------------
13070 function Has_Relaxed_Initialization (E : Entity_Id) return Boolean is
13072 function Denotes_Relaxed_Parameter
13073 (Expr : Node_Id;
13074 Param : Entity_Id)
13075 return Boolean;
13076 -- Returns True iff expression Expr denotes a formal parameter or
13077 -- function Param (through its attribute Result).
13079 -------------------------------
13080 -- Denotes_Relaxed_Parameter --
13081 -------------------------------
13083 function Denotes_Relaxed_Parameter
13084 (Expr : Node_Id;
13085 Param : Entity_Id) return Boolean is
13086 begin
13087 if Nkind (Expr) in N_Identifier | N_Expanded_Name then
13088 return Entity (Expr) = Param;
13089 else
13090 pragma Assert (Is_Attribute_Result (Expr));
13091 return Entity (Prefix (Expr)) = Param;
13092 end if;
13093 end Denotes_Relaxed_Parameter;
13095 -- Start of processing for Has_Relaxed_Initialization
13097 begin
13098 -- When analyzing, we checked all syntax legality rules for the aspect
13099 -- Relaxed_Initialization, but didn't store the property anywhere (e.g.
13100 -- as an Einfo flag). To query the property we look directly at the AST,
13101 -- but now without any syntactic checks.
13103 case Ekind (E) is
13104 -- Abstract states have option Relaxed_Initialization
13106 when E_Abstract_State =>
13107 return Is_Relaxed_Initialization_State (E);
13109 -- Constants have this aspect attached directly; for deferred
13110 -- constants, the aspect is attached to the partial view.
13112 when E_Constant =>
13113 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13115 -- Variables have this aspect attached directly
13117 when E_Variable =>
13118 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13120 -- Types have this aspect attached directly (though we only allow it
13121 -- to be specified for the first subtype). For private types, the
13122 -- aspect is attached to the partial view.
13124 when Type_Kind =>
13125 pragma Assert (Is_First_Subtype (E));
13126 return Has_Aspect (E, Aspect_Relaxed_Initialization);
13128 -- Formal parameters and functions have the Relaxed_Initialization
13129 -- aspect attached to the subprogram entity and must be listed in
13130 -- the aspect expression.
13132 when Formal_Kind
13133 | E_Function
13135 declare
13136 Subp_Id : Entity_Id;
13137 Aspect_Expr : Node_Id;
13138 Param_Expr : Node_Id;
13139 Assoc : Node_Id;
13141 begin
13142 if Is_Formal (E) then
13143 Subp_Id := Scope (E);
13144 else
13145 Subp_Id := E;
13146 end if;
13148 if Has_Aspect (Subp_Id, Aspect_Relaxed_Initialization) then
13149 Aspect_Expr :=
13150 Find_Value_Of_Aspect
13151 (Subp_Id, Aspect_Relaxed_Initialization);
13153 -- Aspect expression is either an aggregate with an optional
13154 -- Boolean expression (which defaults to True), e.g.:
13156 -- function F (X : Integer) return Integer
13157 -- with Relaxed_Initialization => (X => True, F'Result);
13159 if Nkind (Aspect_Expr) = N_Aggregate then
13161 if Present (Component_Associations (Aspect_Expr)) then
13162 Assoc := First (Component_Associations (Aspect_Expr));
13164 while Present (Assoc) loop
13165 if Denotes_Relaxed_Parameter
13166 (First (Choices (Assoc)), E)
13167 then
13168 return
13169 Is_True
13170 (Static_Boolean (Expression (Assoc)));
13171 end if;
13173 Next (Assoc);
13174 end loop;
13175 end if;
13177 Param_Expr := First (Expressions (Aspect_Expr));
13179 while Present (Param_Expr) loop
13180 if Denotes_Relaxed_Parameter (Param_Expr, E) then
13181 return True;
13182 end if;
13184 Next (Param_Expr);
13185 end loop;
13187 return False;
13189 -- or it is a single identifier, e.g.:
13191 -- function F (X : Integer) return Integer
13192 -- with Relaxed_Initialization => X;
13194 else
13195 return Denotes_Relaxed_Parameter (Aspect_Expr, E);
13196 end if;
13197 else
13198 return False;
13199 end if;
13200 end;
13202 when others =>
13203 raise Program_Error;
13204 end case;
13205 end Has_Relaxed_Initialization;
13207 ----------------------
13208 -- Has_Signed_Zeros --
13209 ----------------------
13211 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
13212 begin
13213 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
13214 end Has_Signed_Zeros;
13216 ------------------------------
13217 -- Has_Significant_Contract --
13218 ------------------------------
13220 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
13221 Subp_Nam : constant Name_Id := Chars (Subp_Id);
13223 begin
13224 -- _Finalizer procedure
13226 if Subp_Nam = Name_uFinalizer then
13227 return False;
13229 -- _Wrapped_Statements procedure which gets generated as part of the
13230 -- expansion of postconditions.
13232 elsif Subp_Nam = Name_uWrapped_Statements then
13233 return False;
13235 -- Predicate function
13237 elsif Ekind (Subp_Id) = E_Function
13238 and then Is_Predicate_Function (Subp_Id)
13239 then
13240 return False;
13242 -- TSS subprogram
13244 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
13245 return False;
13247 else
13248 return True;
13249 end if;
13250 end Has_Significant_Contract;
13252 -----------------------------
13253 -- Has_Static_Array_Bounds --
13254 -----------------------------
13256 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
13257 All_Static : Boolean;
13258 Dummy : Boolean;
13260 begin
13261 Examine_Array_Bounds (Typ, All_Static, Dummy);
13263 return All_Static;
13264 end Has_Static_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_Volatile_Component --
13503 ----------------------------
13505 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
13506 Comp : Entity_Id;
13508 begin
13509 if Has_Volatile_Components (Typ) then
13510 return True;
13512 elsif Is_Array_Type (Typ) then
13513 return Is_Volatile (Component_Type (Typ));
13515 elsif Is_Record_Type (Typ) then
13516 Comp := First_Component (Typ);
13517 while Present (Comp) loop
13518 if Is_Volatile_Object_Ref (Comp) then
13519 return True;
13520 end if;
13522 Next_Component (Comp);
13523 end loop;
13524 end if;
13526 return False;
13527 end Has_Volatile_Component;
13529 -------------------------
13530 -- Implementation_Kind --
13531 -------------------------
13533 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
13534 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
13535 Arg : Node_Id;
13536 begin
13537 pragma Assert (Present (Impl_Prag));
13538 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
13539 return Chars (Get_Pragma_Arg (Arg));
13540 end Implementation_Kind;
13542 --------------------------
13543 -- Implements_Interface --
13544 --------------------------
13546 function Implements_Interface
13547 (Typ_Ent : Entity_Id;
13548 Iface_Ent : Entity_Id;
13549 Exclude_Parents : Boolean := False) return Boolean
13551 Ifaces_List : Elist_Id;
13552 Elmt : Elmt_Id;
13553 Iface : Entity_Id := Base_Type (Iface_Ent);
13554 Typ : Entity_Id := Base_Type (Typ_Ent);
13556 begin
13557 if Is_Class_Wide_Type (Typ) then
13558 Typ := Root_Type (Typ);
13559 end if;
13561 if not Has_Interfaces (Typ) then
13562 return False;
13563 end if;
13565 if Is_Class_Wide_Type (Iface) then
13566 Iface := Root_Type (Iface);
13567 end if;
13569 Collect_Interfaces (Typ, Ifaces_List);
13571 Elmt := First_Elmt (Ifaces_List);
13572 while Present (Elmt) loop
13573 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
13574 and then Exclude_Parents
13575 then
13576 null;
13578 elsif Node (Elmt) = Iface then
13579 return True;
13580 end if;
13582 Next_Elmt (Elmt);
13583 end loop;
13585 return False;
13586 end Implements_Interface;
13588 --------------------------------
13589 -- Implicitly_Designated_Type --
13590 --------------------------------
13592 function Implicitly_Designated_Type (Typ : Entity_Id) return Entity_Id is
13593 Desig : constant Entity_Id := Designated_Type (Typ);
13595 begin
13596 -- An implicit dereference is a legal occurrence of an incomplete type
13597 -- imported through a limited_with clause, if the full view is visible.
13599 if Is_Incomplete_Type (Desig)
13600 and then From_Limited_With (Desig)
13601 and then not From_Limited_With (Scope (Desig))
13602 and then
13603 (Is_Immediately_Visible (Scope (Desig))
13604 or else
13605 (Is_Child_Unit (Scope (Desig))
13606 and then Is_Visible_Lib_Unit (Scope (Desig))))
13607 then
13608 return Available_View (Desig);
13609 else
13610 return Desig;
13611 end if;
13612 end Implicitly_Designated_Type;
13614 ------------------------------------
13615 -- In_Assertion_Expression_Pragma --
13616 ------------------------------------
13618 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
13619 Par : Node_Id;
13620 Prag : Node_Id := Empty;
13622 begin
13623 -- Climb the parent chain looking for an enclosing pragma
13625 Par := N;
13626 while Present (Par) loop
13627 if Nkind (Par) = N_Pragma then
13628 Prag := Par;
13629 exit;
13631 -- Precondition-like pragmas are expanded into if statements, check
13632 -- the original node instead.
13634 elsif Nkind (Original_Node (Par)) = N_Pragma then
13635 Prag := Original_Node (Par);
13636 exit;
13638 -- The expansion of attribute 'Old generates a constant to capture
13639 -- the result of the prefix. If the parent traversal reaches
13640 -- one of these constants, then the node technically came from a
13641 -- postcondition-like pragma. Note that the Ekind is not tested here
13642 -- because N may be the expression of an object declaration which is
13643 -- currently being analyzed. Such objects carry Ekind of E_Void.
13645 elsif Nkind (Par) = N_Object_Declaration
13646 and then Constant_Present (Par)
13647 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
13648 then
13649 return True;
13651 -- Prevent the search from going too far
13653 elsif Is_Body_Or_Package_Declaration (Par) then
13654 return False;
13655 end if;
13657 Par := Parent (Par);
13658 end loop;
13660 return
13661 Present (Prag)
13662 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
13663 end In_Assertion_Expression_Pragma;
13665 -------------------
13666 -- In_Check_Node --
13667 -------------------
13669 function In_Check_Node (N : Node_Id) return Boolean is
13670 Par : Node_Id := Parent (N);
13671 begin
13672 while Present (Par) loop
13673 if Nkind (Par) in N_Raise_xxx_Error then
13674 return True;
13676 -- Prevent the search from going too far
13678 elsif Is_Body_Or_Package_Declaration (Par) then
13679 return False;
13681 else
13682 Par := Parent (Par);
13683 end if;
13684 end loop;
13686 return False;
13687 end In_Check_Node;
13689 -------------------------------
13690 -- In_Generic_Formal_Package --
13691 -------------------------------
13693 function In_Generic_Formal_Package (E : Entity_Id) return Boolean is
13694 Par : Node_Id;
13696 begin
13697 Par := Parent (E);
13698 while Present (Par) loop
13699 if Nkind (Par) = N_Formal_Package_Declaration
13700 or else Nkind (Original_Node (Par)) = N_Formal_Package_Declaration
13701 then
13702 return True;
13703 end if;
13705 Par := Parent (Par);
13706 end loop;
13708 return False;
13709 end In_Generic_Formal_Package;
13711 ----------------------
13712 -- In_Generic_Scope --
13713 ----------------------
13715 function In_Generic_Scope (E : Entity_Id) return Boolean is
13716 S : Entity_Id;
13718 begin
13719 S := Scope (E);
13720 while Present (S) and then S /= Standard_Standard loop
13721 if Is_Generic_Unit (S) then
13722 return True;
13723 end if;
13725 S := Scope (S);
13726 end loop;
13728 return False;
13729 end In_Generic_Scope;
13731 -----------------
13732 -- In_Instance --
13733 -----------------
13735 function In_Instance return Boolean is
13736 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
13737 S : Entity_Id;
13739 begin
13740 S := Current_Scope;
13741 while Present (S) and then S /= Standard_Standard loop
13742 if Is_Generic_Instance (S) then
13744 -- A child instance is always compiled in the context of a parent
13745 -- instance. Nevertheless, its actuals must not be analyzed in an
13746 -- instance context. We detect this case by examining the current
13747 -- compilation unit, which must be a child instance, and checking
13748 -- that it has not been analyzed yet.
13750 if Is_Child_Unit (Curr_Unit)
13751 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
13752 N_Package_Instantiation
13753 and then Ekind (Curr_Unit) = E_Void
13754 then
13755 return False;
13756 else
13757 return True;
13758 end if;
13759 end if;
13761 S := Scope (S);
13762 end loop;
13764 return False;
13765 end In_Instance;
13767 ----------------------
13768 -- In_Instance_Body --
13769 ----------------------
13771 function In_Instance_Body return Boolean is
13772 S : Entity_Id;
13774 begin
13775 S := Current_Scope;
13776 while Present (S) and then S /= Standard_Standard loop
13777 if Ekind (S) in E_Function | E_Procedure
13778 and then Is_Generic_Instance (S)
13779 then
13780 return True;
13782 elsif Ekind (S) = E_Package
13783 and then In_Package_Body (S)
13784 and then Is_Generic_Instance (S)
13785 then
13786 return True;
13787 end if;
13789 S := Scope (S);
13790 end loop;
13792 return False;
13793 end In_Instance_Body;
13795 -----------------------------
13796 -- In_Instance_Not_Visible --
13797 -----------------------------
13799 function In_Instance_Not_Visible return Boolean is
13800 S : Entity_Id;
13802 begin
13803 S := Current_Scope;
13804 while Present (S) and then S /= Standard_Standard loop
13805 if Ekind (S) in E_Function | E_Procedure
13806 and then Is_Generic_Instance (S)
13807 then
13808 return True;
13810 elsif Ekind (S) = E_Package
13811 and then (In_Package_Body (S) or else In_Private_Part (S))
13812 and then Is_Generic_Instance (S)
13813 then
13814 return True;
13815 end if;
13817 S := Scope (S);
13818 end loop;
13820 return False;
13821 end In_Instance_Not_Visible;
13823 ------------------------------
13824 -- In_Instance_Visible_Part --
13825 ------------------------------
13827 function In_Instance_Visible_Part
13828 (Id : Entity_Id := Current_Scope) return Boolean
13830 Inst : Entity_Id;
13832 begin
13833 Inst := Id;
13834 while Present (Inst) and then Inst /= Standard_Standard loop
13835 if Ekind (Inst) = E_Package
13836 and then Is_Generic_Instance (Inst)
13837 and then not In_Package_Body (Inst)
13838 and then not In_Private_Part (Inst)
13839 then
13840 return True;
13841 end if;
13843 Inst := Scope (Inst);
13844 end loop;
13846 return False;
13847 end In_Instance_Visible_Part;
13849 ---------------------
13850 -- In_Package_Body --
13851 ---------------------
13853 function In_Package_Body return Boolean is
13854 S : Entity_Id;
13856 begin
13857 S := Current_Scope;
13858 while Present (S) and then S /= Standard_Standard loop
13859 if Ekind (S) = E_Package and then In_Package_Body (S) then
13860 return True;
13861 else
13862 S := Scope (S);
13863 end if;
13864 end loop;
13866 return False;
13867 end In_Package_Body;
13869 --------------------------
13870 -- In_Pragma_Expression --
13871 --------------------------
13873 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
13874 P : Node_Id;
13875 begin
13876 P := Parent (N);
13877 loop
13878 if No (P) then
13879 return False;
13881 -- Prevent the search from going too far
13883 elsif Is_Body_Or_Package_Declaration (P) then
13884 return False;
13886 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
13887 return True;
13889 else
13890 P := Parent (P);
13891 end if;
13892 end loop;
13893 end In_Pragma_Expression;
13895 ---------------------------
13896 -- In_Pre_Post_Condition --
13897 ---------------------------
13899 function In_Pre_Post_Condition
13900 (N : Node_Id; Class_Wide_Only : Boolean := False) return Boolean
13902 Par : Node_Id;
13903 Prag : Node_Id := Empty;
13904 Prag_Id : Pragma_Id;
13906 begin
13907 -- Climb the parent chain looking for an enclosing pragma
13909 Par := N;
13910 while Present (Par) loop
13911 if Nkind (Par) = N_Pragma then
13912 Prag := Par;
13913 exit;
13915 -- Prevent the search from going too far
13917 elsif Is_Body_Or_Package_Declaration (Par) then
13918 exit;
13919 end if;
13921 Par := Parent (Par);
13922 end loop;
13924 if Present (Prag) then
13925 Prag_Id := Get_Pragma_Id (Prag);
13927 if Class_Wide_Only then
13928 return
13929 Prag_Id = Pragma_Post_Class
13930 or else Prag_Id = Pragma_Pre_Class
13931 or else (Class_Present (Prag)
13932 and then (Prag_Id = Pragma_Post
13933 or else Prag_Id = Pragma_Postcondition
13934 or else Prag_Id = Pragma_Pre
13935 or else Prag_Id = Pragma_Precondition));
13936 else
13937 return
13938 Prag_Id = Pragma_Post
13939 or else Prag_Id = Pragma_Post_Class
13940 or else Prag_Id = Pragma_Postcondition
13941 or else Prag_Id = Pragma_Pre
13942 or else Prag_Id = Pragma_Pre_Class
13943 or else Prag_Id = Pragma_Precondition;
13944 end if;
13946 -- Otherwise the node is not enclosed by a pre/postcondition pragma
13948 else
13949 return False;
13950 end if;
13951 end In_Pre_Post_Condition;
13953 ------------------------------
13954 -- In_Quantified_Expression --
13955 ------------------------------
13957 function In_Quantified_Expression (N : Node_Id) return Boolean is
13958 P : Node_Id;
13959 begin
13960 P := Parent (N);
13961 loop
13962 if No (P) then
13963 return False;
13965 -- Prevent the search from going too far
13967 elsif Is_Body_Or_Package_Declaration (P) then
13968 return False;
13970 elsif Nkind (P) = N_Quantified_Expression then
13971 return True;
13972 else
13973 P := Parent (P);
13974 end if;
13975 end loop;
13976 end In_Quantified_Expression;
13978 -------------------------------------
13979 -- In_Reverse_Storage_Order_Object --
13980 -------------------------------------
13982 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
13983 Pref : Node_Id;
13984 Btyp : Entity_Id := Empty;
13986 begin
13987 -- Climb up indexed components
13989 Pref := N;
13990 loop
13991 case Nkind (Pref) is
13992 when N_Selected_Component =>
13993 Pref := Prefix (Pref);
13994 exit;
13996 when N_Indexed_Component =>
13997 Pref := Prefix (Pref);
13999 when others =>
14000 Pref := Empty;
14001 exit;
14002 end case;
14003 end loop;
14005 if Present (Pref) then
14006 Btyp := Base_Type (Etype (Pref));
14007 end if;
14009 return Present (Btyp)
14010 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
14011 and then Reverse_Storage_Order (Btyp);
14012 end In_Reverse_Storage_Order_Object;
14014 ------------------------------
14015 -- In_Same_Declarative_Part --
14016 ------------------------------
14018 function In_Same_Declarative_Part
14019 (Context : Node_Id;
14020 N : Node_Id) return Boolean
14022 Cont : Node_Id := Context;
14023 Nod : Node_Id;
14025 begin
14026 if Nkind (Cont) = N_Compilation_Unit_Aux then
14027 Cont := Parent (Cont);
14028 end if;
14030 Nod := Parent (N);
14031 while Present (Nod) loop
14032 if Nod = Cont then
14033 return True;
14035 elsif Nkind (Nod) in N_Accept_Statement
14036 | N_Block_Statement
14037 | N_Compilation_Unit
14038 | N_Entry_Body
14039 | N_Package_Body
14040 | N_Package_Declaration
14041 | N_Protected_Body
14042 | N_Subprogram_Body
14043 | N_Task_Body
14044 then
14045 return False;
14047 elsif Nkind (Nod) = N_Subunit then
14048 Nod := Corresponding_Stub (Nod);
14050 else
14051 Nod := Parent (Nod);
14052 end if;
14053 end loop;
14055 return False;
14056 end In_Same_Declarative_Part;
14058 --------------------------------------
14059 -- In_Subprogram_Or_Concurrent_Unit --
14060 --------------------------------------
14062 function In_Subprogram_Or_Concurrent_Unit return Boolean is
14063 E : Entity_Id;
14064 K : Entity_Kind;
14066 begin
14067 -- Use scope chain to check successively outer scopes
14069 E := Current_Scope;
14070 loop
14071 K := Ekind (E);
14073 if K in Subprogram_Kind
14074 or else K in Concurrent_Kind
14075 or else K in Generic_Subprogram_Kind
14076 then
14077 return True;
14079 elsif E = Standard_Standard then
14080 return False;
14081 end if;
14083 E := Scope (E);
14084 end loop;
14085 end In_Subprogram_Or_Concurrent_Unit;
14087 ----------------
14088 -- In_Subtree --
14089 ----------------
14091 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
14092 Curr : Node_Id;
14094 begin
14095 Curr := N;
14096 while Present (Curr) loop
14097 if Curr = Root then
14098 return True;
14099 end if;
14101 Curr := Parent (Curr);
14102 end loop;
14104 return False;
14105 end In_Subtree;
14107 ----------------
14108 -- In_Subtree --
14109 ----------------
14111 function In_Subtree
14112 (N : Node_Id;
14113 Root1 : Node_Id;
14114 Root2 : Node_Id) return Boolean
14116 Curr : Node_Id;
14118 begin
14119 Curr := N;
14120 while Present (Curr) loop
14121 if Curr = Root1 or else Curr = Root2 then
14122 return True;
14123 end if;
14125 Curr := Parent (Curr);
14126 end loop;
14128 return False;
14129 end In_Subtree;
14131 ---------------------
14132 -- In_Return_Value --
14133 ---------------------
14135 function In_Return_Value (Expr : Node_Id) return Boolean is
14136 Par : Node_Id;
14137 Prev_Par : Node_Id;
14138 Pre : Node_Id;
14139 In_Function_Call : Boolean := False;
14141 begin
14142 -- Move through parent nodes to determine if Expr contributes to the
14143 -- return value of the current subprogram.
14145 Par := Expr;
14146 Prev_Par := Empty;
14147 while Present (Par) loop
14149 case Nkind (Par) is
14150 -- Ignore ranges and they don't contribute to the result
14152 when N_Range =>
14153 return False;
14155 -- An object declaration whose parent is an extended return
14156 -- statement is a return object.
14158 when N_Object_Declaration =>
14159 if Present (Parent (Par))
14160 and then Nkind (Parent (Par)) = N_Extended_Return_Statement
14161 then
14162 return True;
14163 end if;
14165 -- We hit a simple return statement, so we know we are in one
14167 when N_Simple_Return_Statement =>
14168 return True;
14170 -- Only include one nexting level of function calls
14172 when N_Function_Call =>
14173 if not In_Function_Call then
14174 In_Function_Call := True;
14176 -- When the function return type has implicit dereference
14177 -- specified we know it cannot directly contribute to the
14178 -- return value.
14180 if Present (Etype (Par))
14181 and then Has_Implicit_Dereference
14182 (Get_Full_View (Etype (Par)))
14183 then
14184 return False;
14185 end if;
14186 else
14187 return False;
14188 end if;
14190 -- Check if we are on the right-hand side of an assignment
14191 -- statement to a return object.
14193 -- This is not specified in the RM ???
14195 when N_Assignment_Statement =>
14196 if Prev_Par = Name (Par) then
14197 return False;
14198 end if;
14200 Pre := Name (Par);
14201 while Present (Pre) loop
14202 if Is_Entity_Name (Pre)
14203 and then Is_Return_Object (Entity (Pre))
14204 then
14205 return True;
14206 end if;
14208 exit when Nkind (Pre) not in N_Selected_Component
14209 | N_Indexed_Component
14210 | N_Slice;
14212 Pre := Prefix (Pre);
14213 end loop;
14215 -- Otherwise, we hit a master which was not relevant
14217 when others =>
14218 if Is_Master (Par) then
14219 return False;
14220 end if;
14221 end case;
14223 -- Iterate up to the next parent, keeping track of the previous one
14225 Prev_Par := Par;
14226 Par := Parent (Par);
14227 end loop;
14229 return False;
14230 end In_Return_Value;
14232 -----------------------------------------
14233 -- In_Statement_Condition_With_Actions --
14234 -----------------------------------------
14236 function In_Statement_Condition_With_Actions (N : Node_Id) return Boolean is
14237 Prev : Node_Id := N;
14238 P : Node_Id := Parent (N);
14239 -- P and Prev will be used for traversing the AST, while maintaining an
14240 -- invariant that P = Parent (Prev).
14241 begin
14242 while Present (P) loop
14243 if Nkind (P) = N_Iteration_Scheme
14244 and then Prev = Condition (P)
14245 then
14246 return True;
14248 elsif Nkind (P) = N_Elsif_Part
14249 and then Prev = Condition (P)
14250 then
14251 return True;
14253 -- No point in going beyond statements
14255 elsif Nkind (N) in N_Statement_Other_Than_Procedure_Call
14256 | N_Procedure_Call_Statement
14257 then
14258 exit;
14260 -- Prevent the search from going too far
14262 elsif Is_Body_Or_Package_Declaration (P) then
14263 exit;
14264 end if;
14266 Prev := P;
14267 P := Parent (P);
14268 end loop;
14270 return False;
14271 end In_Statement_Condition_With_Actions;
14273 ---------------------
14274 -- In_Visible_Part --
14275 ---------------------
14277 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
14278 begin
14279 return Is_Package_Or_Generic_Package (Scope_Id)
14280 and then In_Open_Scopes (Scope_Id)
14281 and then not In_Package_Body (Scope_Id)
14282 and then not In_Private_Part (Scope_Id);
14283 end In_Visible_Part;
14285 --------------------------------
14286 -- Incomplete_Or_Partial_View --
14287 --------------------------------
14289 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
14290 S : constant Entity_Id := Scope (Id);
14292 function Inspect_Decls
14293 (Decls : List_Id;
14294 Taft : Boolean := False) return Entity_Id;
14295 -- Check whether a declarative region contains the incomplete or partial
14296 -- view of Id.
14298 -------------------
14299 -- Inspect_Decls --
14300 -------------------
14302 function Inspect_Decls
14303 (Decls : List_Id;
14304 Taft : Boolean := False) return Entity_Id
14306 Decl : Node_Id;
14307 Match : Node_Id;
14309 begin
14310 Decl := First (Decls);
14311 while Present (Decl) loop
14312 Match := Empty;
14314 -- The partial view of a Taft-amendment type is an incomplete
14315 -- type.
14317 if Taft then
14318 if Nkind (Decl) = N_Incomplete_Type_Declaration then
14319 Match := Defining_Identifier (Decl);
14320 end if;
14322 -- Otherwise look for a private type whose full view matches the
14323 -- input type. Note that this checks full_type_declaration nodes
14324 -- to account for derivations from a private type where the type
14325 -- declaration hold the partial view and the full view is an
14326 -- itype.
14328 elsif Nkind (Decl) in N_Full_Type_Declaration
14329 | N_Private_Extension_Declaration
14330 | N_Private_Type_Declaration
14331 then
14332 Match := Defining_Identifier (Decl);
14333 end if;
14335 -- Guard against unanalyzed entities
14337 if Present (Match)
14338 and then Is_Type (Match)
14339 and then Present (Full_View (Match))
14340 and then Full_View (Match) = Id
14341 then
14342 return Match;
14343 end if;
14345 Next (Decl);
14346 end loop;
14348 return Empty;
14349 end Inspect_Decls;
14351 -- Local variables
14353 Prev : Entity_Id;
14355 -- Start of processing for Incomplete_Or_Partial_View
14357 begin
14358 -- Deferred constant or incomplete type case
14360 Prev := Current_Entity (Id);
14362 while Present (Prev) loop
14363 exit when Scope (Prev) = S;
14365 Prev := Homonym (Prev);
14366 end loop;
14368 if Present (Prev)
14369 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
14370 and then Present (Full_View (Prev))
14371 and then Full_View (Prev) = Id
14372 then
14373 return Prev;
14374 end if;
14376 -- Private or Taft amendment type case
14378 if Present (S) and then Is_Package_Or_Generic_Package (S) then
14379 declare
14380 Pkg_Decl : constant Node_Id := Package_Specification (S);
14382 begin
14383 -- It is knows that Typ has a private view, look for it in the
14384 -- visible declarations of the enclosing scope. A special case
14385 -- of this is when the two views have been exchanged - the full
14386 -- appears earlier than the private.
14388 if Has_Private_Declaration (Id) then
14389 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
14391 -- Exchanged view case, look in the private declarations
14393 if No (Prev) then
14394 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
14395 end if;
14397 return Prev;
14399 -- Otherwise if this is the package body, then Typ is a potential
14400 -- Taft amendment type. The incomplete view should be located in
14401 -- the private declarations of the enclosing scope.
14403 elsif In_Package_Body (S) then
14404 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
14405 end if;
14406 end;
14407 end if;
14409 -- The type has no incomplete or private view
14411 return Empty;
14412 end Incomplete_Or_Partial_View;
14414 ---------------------------------------
14415 -- Incomplete_View_From_Limited_With --
14416 ---------------------------------------
14418 function Incomplete_View_From_Limited_With
14419 (Typ : Entity_Id) return Entity_Id
14421 begin
14422 -- It might make sense to make this an attribute in Einfo, and set it
14423 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
14424 -- slots for new attributes, and it seems a bit simpler to just search
14425 -- the Limited_View (if it exists) for an incomplete type whose
14426 -- Non_Limited_View is Typ.
14428 if Ekind (Scope (Typ)) = E_Package
14429 and then Present (Limited_View (Scope (Typ)))
14430 then
14431 declare
14432 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
14433 begin
14434 while Present (Ent) loop
14435 if Is_Incomplete_Type (Ent)
14436 and then Non_Limited_View (Ent) = Typ
14437 then
14438 return Ent;
14439 end if;
14441 Next_Entity (Ent);
14442 end loop;
14443 end;
14444 end if;
14446 return Typ;
14447 end Incomplete_View_From_Limited_With;
14449 ----------------------------------
14450 -- Indexed_Component_Bit_Offset --
14451 ----------------------------------
14453 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
14454 Exp : constant Node_Id := First (Expressions (N));
14455 Typ : constant Entity_Id := Etype (Prefix (N));
14456 Off : constant Uint := Component_Size (Typ);
14457 Ind : Node_Id;
14459 begin
14460 -- Return early if the component size is not known or variable
14462 if No (Off) or else Off < Uint_0 then
14463 return No_Uint;
14464 end if;
14466 -- Deal with the degenerate case of an empty component
14468 if Off = Uint_0 then
14469 return Off;
14470 end if;
14472 -- Check that both the index value and the low bound are known
14474 if not Compile_Time_Known_Value (Exp) then
14475 return No_Uint;
14476 end if;
14478 Ind := First_Index (Typ);
14479 if No (Ind) then
14480 return No_Uint;
14481 end if;
14483 -- Do not attempt to compute offsets within multi-dimensional arrays
14485 if Present (Next_Index (Ind)) then
14486 return No_Uint;
14487 end if;
14489 if Nkind (Ind) = N_Subtype_Indication then
14490 Ind := Constraint (Ind);
14492 if Nkind (Ind) = N_Range_Constraint then
14493 Ind := Range_Expression (Ind);
14494 end if;
14495 end if;
14497 if Nkind (Ind) /= N_Range
14498 or else not Compile_Time_Known_Value (Low_Bound (Ind))
14499 then
14500 return No_Uint;
14501 end if;
14503 -- Return the scaled offset
14505 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound (Ind)));
14506 end Indexed_Component_Bit_Offset;
14508 -----------------------------
14509 -- Inherit_Predicate_Flags --
14510 -----------------------------
14512 procedure Inherit_Predicate_Flags
14513 (Subt, Par : Entity_Id;
14514 Only_Flags : Boolean := False)
14516 begin
14517 if Ada_Version < Ada_2012
14518 or else Present (Predicate_Function (Subt))
14519 then
14520 return;
14521 end if;
14523 Set_Has_Predicates (Subt, Has_Predicates (Par));
14524 Set_Has_Static_Predicate_Aspect
14525 (Subt, Has_Static_Predicate_Aspect (Par));
14526 Set_Has_Dynamic_Predicate_Aspect
14527 (Subt, Has_Dynamic_Predicate_Aspect (Par));
14528 Set_Has_Ghost_Predicate_Aspect
14529 (Subt, Has_Ghost_Predicate_Aspect (Par));
14531 -- A named subtype does not inherit the predicate function of its
14532 -- parent but an itype declared for a loop index needs the discrete
14533 -- predicate information of its parent to execute the loop properly.
14534 -- A non-discrete type may has a static predicate (for example True)
14535 -- but has no static_discrete_predicate.
14537 if not Only_Flags
14538 and then Is_Itype (Subt)
14539 and then Present (Predicate_Function (Par))
14540 then
14541 Set_Subprograms_For_Type (Subt, Subprograms_For_Type (Par));
14543 if Has_Static_Predicate (Par) and then Is_Discrete_Type (Par) then
14544 Set_Static_Discrete_Predicate
14545 (Subt, Static_Discrete_Predicate (Par));
14546 end if;
14547 end if;
14548 end Inherit_Predicate_Flags;
14550 ----------------------------
14551 -- Inherit_Rep_Item_Chain --
14552 ----------------------------
14554 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
14555 Item : Node_Id;
14556 Next_Item : Node_Id;
14558 begin
14559 -- There are several inheritance scenarios to consider depending on
14560 -- whether both types have rep item chains and whether the destination
14561 -- type already inherits part of the source type's rep item chain.
14563 -- 1) The source type lacks a rep item chain
14564 -- From_Typ ---> Empty
14566 -- Typ --------> Item (or Empty)
14568 -- In this case inheritance cannot take place because there are no items
14569 -- to inherit.
14571 -- 2) The destination type lacks a rep item chain
14572 -- From_Typ ---> Item ---> ...
14574 -- Typ --------> Empty
14576 -- Inheritance takes place by setting the First_Rep_Item of the
14577 -- destination type to the First_Rep_Item of the source type.
14578 -- From_Typ ---> Item ---> ...
14579 -- ^
14580 -- Typ -----------+
14582 -- 3.1) Both source and destination types have at least one rep item.
14583 -- The destination type does NOT inherit a rep item from the source
14584 -- type.
14585 -- From_Typ ---> Item ---> Item
14587 -- Typ --------> Item ---> Item
14589 -- Inheritance takes place by setting the Next_Rep_Item of the last item
14590 -- of the destination type to the First_Rep_Item of the source type.
14591 -- From_Typ -------------------> Item ---> Item
14592 -- ^
14593 -- Typ --------> Item ---> Item --+
14595 -- 3.2) Both source and destination types have at least one rep item.
14596 -- The destination type DOES inherit part of the rep item chain of the
14597 -- source type.
14598 -- From_Typ ---> Item ---> Item ---> Item
14599 -- ^
14600 -- Typ --------> Item ------+
14602 -- This rare case arises when the full view of a private extension must
14603 -- inherit the rep item chain from the full view of its parent type and
14604 -- the full view of the parent type contains extra rep items. Currently
14605 -- only invariants may lead to such form of inheritance.
14607 -- type From_Typ is tagged private
14608 -- with Type_Invariant'Class => Item_2;
14610 -- type Typ is new From_Typ with private
14611 -- with Type_Invariant => Item_4;
14613 -- At this point the rep item chains contain the following items
14615 -- From_Typ -----------> Item_2 ---> Item_3
14616 -- ^
14617 -- Typ --------> Item_4 --+
14619 -- The full views of both types may introduce extra invariants
14621 -- type From_Typ is tagged null record
14622 -- with Type_Invariant => Item_1;
14624 -- type Typ is new From_Typ with null record;
14626 -- The full view of Typ would have to inherit any new rep items added to
14627 -- the full view of From_Typ.
14629 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
14630 -- ^
14631 -- Typ --------> Item_4 --+
14633 -- To achieve this form of inheritance, the destination type must first
14634 -- sever the link between its own rep chain and that of the source type,
14635 -- then inheritance 3.1 takes place.
14637 -- Case 1: The source type lacks a rep item chain
14639 if No (First_Rep_Item (From_Typ)) then
14640 return;
14642 -- Case 2: The destination type lacks a rep item chain
14644 elsif No (First_Rep_Item (Typ)) then
14645 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
14647 -- Case 3: Both the source and destination types have at least one rep
14648 -- item. Traverse the rep item chain of the destination type to find the
14649 -- last rep item.
14651 else
14652 Item := Empty;
14653 Next_Item := First_Rep_Item (Typ);
14654 while Present (Next_Item) loop
14656 -- Detect a link between the destination type's rep chain and that
14657 -- of the source type. There are two possibilities:
14659 -- Variant 1
14660 -- Next_Item
14661 -- V
14662 -- From_Typ ---> Item_1 --->
14663 -- ^
14664 -- Typ -----------+
14666 -- Item is Empty
14668 -- Variant 2
14669 -- Next_Item
14670 -- V
14671 -- From_Typ ---> Item_1 ---> Item_2 --->
14672 -- ^
14673 -- Typ --------> Item_3 ------+
14674 -- ^
14675 -- Item
14677 if Present_In_Rep_Item (From_Typ, Next_Item) then
14678 exit;
14679 end if;
14681 Item := Next_Item;
14682 Next_Item := Next_Rep_Item (Next_Item);
14683 end loop;
14685 -- Inherit the source type's rep item chain
14687 if Present (Item) then
14688 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
14689 else
14690 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
14691 end if;
14692 end if;
14693 end Inherit_Rep_Item_Chain;
14695 ------------------------------------
14696 -- Inherits_From_Tagged_Full_View --
14697 ------------------------------------
14699 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
14700 begin
14701 return Is_Private_Type (Typ)
14702 and then Present (Full_View (Typ))
14703 and then Is_Private_Type (Full_View (Typ))
14704 and then not Is_Tagged_Type (Full_View (Typ))
14705 and then Present (Underlying_Type (Full_View (Typ)))
14706 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
14707 end Inherits_From_Tagged_Full_View;
14709 ---------------------------------
14710 -- Insert_Explicit_Dereference --
14711 ---------------------------------
14713 procedure Insert_Explicit_Dereference (N : Node_Id) is
14714 New_Prefix : constant Node_Id := Relocate_Node (N);
14715 Ent : Entity_Id := Empty;
14716 Pref : Node_Id := Empty;
14717 I : Interp_Index;
14718 It : Interp;
14719 T : Entity_Id;
14721 begin
14722 Save_Interps (N, New_Prefix);
14724 Rewrite (N,
14725 Make_Explicit_Dereference (Sloc (Parent (N)),
14726 Prefix => New_Prefix));
14728 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
14730 if Is_Overloaded (New_Prefix) then
14732 -- The dereference is also overloaded, and its interpretations are
14733 -- the designated types of the interpretations of the original node.
14735 Set_Etype (N, Any_Type);
14737 Get_First_Interp (New_Prefix, I, It);
14738 while Present (It.Nam) loop
14739 T := It.Typ;
14741 if Is_Access_Type (T) then
14742 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
14743 end if;
14745 Get_Next_Interp (I, It);
14746 end loop;
14748 else
14749 -- Prefix is unambiguous: mark the original prefix (which might
14750 -- Come_From_Source) as a reference, since the new (relocated) one
14751 -- won't be taken into account.
14753 if Is_Entity_Name (New_Prefix) then
14754 Ent := Entity (New_Prefix);
14755 Pref := New_Prefix;
14757 -- For a retrieval of a subcomponent of some composite object,
14758 -- retrieve the ultimate entity if there is one.
14760 elsif Nkind (New_Prefix) in N_Selected_Component | N_Indexed_Component
14761 then
14762 Pref := Prefix (New_Prefix);
14763 while Present (Pref)
14764 and then Nkind (Pref) in
14765 N_Selected_Component | N_Indexed_Component
14766 loop
14767 Pref := Prefix (Pref);
14768 end loop;
14770 if Present (Pref) and then Is_Entity_Name (Pref) then
14771 Ent := Entity (Pref);
14772 end if;
14773 end if;
14775 -- Place the reference on the entity node
14777 if Present (Ent) then
14778 Generate_Reference (Ent, Pref);
14779 end if;
14780 end if;
14781 end Insert_Explicit_Dereference;
14783 ------------------------------------------
14784 -- Inspect_Deferred_Constant_Completion --
14785 ------------------------------------------
14787 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
14788 Decl : Node_Id;
14790 begin
14791 Decl := First (Decls);
14792 while Present (Decl) loop
14794 -- Deferred constant signature
14796 if Nkind (Decl) = N_Object_Declaration
14797 and then Constant_Present (Decl)
14798 and then No (Expression (Decl))
14800 -- No need to check internally generated constants
14802 and then Comes_From_Source (Decl)
14804 -- The constant is not completed. A full object declaration or a
14805 -- pragma Import complete a deferred constant.
14807 and then not Has_Completion (Defining_Identifier (Decl))
14808 then
14809 Error_Msg_N
14810 ("constant declaration requires initialization expression",
14811 Defining_Identifier (Decl));
14812 end if;
14814 Next (Decl);
14815 end loop;
14816 end Inspect_Deferred_Constant_Completion;
14818 -------------------------------
14819 -- Install_Elaboration_Model --
14820 -------------------------------
14822 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
14823 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
14824 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
14825 -- Empty if there is no such pragma.
14827 ------------------------------------
14828 -- Find_Elaboration_Checks_Pragma --
14829 ------------------------------------
14831 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
14832 Item : Node_Id;
14834 begin
14835 Item := First (L);
14836 while Present (Item) loop
14837 if Nkind (Item) = N_Pragma
14838 and then Pragma_Name (Item) = Name_Elaboration_Checks
14839 then
14840 return Item;
14841 end if;
14843 Next (Item);
14844 end loop;
14846 return Empty;
14847 end Find_Elaboration_Checks_Pragma;
14849 -- Local variables
14851 Args : List_Id;
14852 Model : Node_Id;
14853 Prag : Node_Id;
14854 Unit : Node_Id;
14856 -- Start of processing for Install_Elaboration_Model
14858 begin
14859 -- Nothing to do when the unit does not exist
14861 if No (Unit_Id) then
14862 return;
14863 end if;
14865 Unit := Parent (Unit_Declaration_Node (Unit_Id));
14867 -- Nothing to do when the unit is not a library unit
14869 if Nkind (Unit) /= N_Compilation_Unit then
14870 return;
14871 end if;
14873 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
14875 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
14876 -- elaboration model as specified by the pragma.
14878 if Present (Prag) then
14879 Args := Pragma_Argument_Associations (Prag);
14881 -- Guard against an illegal pragma. The sole argument must be an
14882 -- identifier which specifies either Dynamic or Static model.
14884 if Present (Args) then
14885 Model := Get_Pragma_Arg (First (Args));
14887 if Nkind (Model) = N_Identifier then
14888 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
14889 end if;
14890 end if;
14891 end if;
14892 end Install_Elaboration_Model;
14894 -----------------------------
14895 -- Install_Generic_Formals --
14896 -----------------------------
14898 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
14899 E : Entity_Id;
14901 begin
14902 pragma Assert (Is_Generic_Subprogram (Subp_Id));
14904 E := First_Entity (Subp_Id);
14905 while Present (E) loop
14906 Install_Entity (E);
14907 Next_Entity (E);
14908 end loop;
14909 end Install_Generic_Formals;
14911 ------------------------
14912 -- Install_SPARK_Mode --
14913 ------------------------
14915 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
14916 begin
14917 SPARK_Mode := Mode;
14918 SPARK_Mode_Pragma := Prag;
14919 end Install_SPARK_Mode;
14921 --------------------------
14922 -- Invalid_Scalar_Value --
14923 --------------------------
14925 function Invalid_Scalar_Value
14926 (Loc : Source_Ptr;
14927 Scal_Typ : Scalar_Id) return Node_Id
14929 function Invalid_Binder_Value return Node_Id;
14930 -- Return a reference to the corresponding invalid value for type
14931 -- Scal_Typ as defined in unit System.Scalar_Values.
14933 function Invalid_Float_Value return Node_Id;
14934 -- Return the invalid value of float type Scal_Typ
14936 function Invalid_Integer_Value return Node_Id;
14937 -- Return the invalid value of integer type Scal_Typ
14939 procedure Set_Invalid_Binder_Values;
14940 -- Set the contents of collection Invalid_Binder_Values
14942 --------------------------
14943 -- Invalid_Binder_Value --
14944 --------------------------
14946 function Invalid_Binder_Value return Node_Id is
14947 Val_Id : Entity_Id;
14949 begin
14950 -- Initialize the collection of invalid binder values the first time
14951 -- around.
14953 Set_Invalid_Binder_Values;
14955 -- Obtain the corresponding variable from System.Scalar_Values which
14956 -- holds the invalid value for this type.
14958 Val_Id := Invalid_Binder_Values (Scal_Typ);
14959 pragma Assert (Present (Val_Id));
14961 return New_Occurrence_Of (Val_Id, Loc);
14962 end Invalid_Binder_Value;
14964 -------------------------
14965 -- Invalid_Float_Value --
14966 -------------------------
14968 function Invalid_Float_Value return Node_Id is
14969 Value : constant Ureal := Invalid_Floats (Scal_Typ);
14971 begin
14972 -- Pragma Invalid_Scalars did not specify an invalid value for this
14973 -- type. Fall back to the value provided by the binder.
14975 if Value = No_Ureal then
14976 return Invalid_Binder_Value;
14977 else
14978 return Make_Real_Literal (Loc, Realval => Value);
14979 end if;
14980 end Invalid_Float_Value;
14982 ---------------------------
14983 -- Invalid_Integer_Value --
14984 ---------------------------
14986 function Invalid_Integer_Value return Node_Id is
14987 Value : constant Uint := Invalid_Integers (Scal_Typ);
14989 begin
14990 -- Pragma Invalid_Scalars did not specify an invalid value for this
14991 -- type. Fall back to the value provided by the binder.
14993 if No (Value) then
14994 return Invalid_Binder_Value;
14995 else
14996 return Make_Integer_Literal (Loc, Intval => Value);
14997 end if;
14998 end Invalid_Integer_Value;
15000 -------------------------------
15001 -- Set_Invalid_Binder_Values --
15002 -------------------------------
15004 procedure Set_Invalid_Binder_Values is
15005 begin
15006 if not Invalid_Binder_Values_Set then
15007 Invalid_Binder_Values_Set := True;
15009 -- Initialize the contents of the collection once since RTE calls
15010 -- are not cheap.
15012 Invalid_Binder_Values :=
15013 (Name_Short_Float => RTE (RE_IS_Isf),
15014 Name_Float => RTE (RE_IS_Ifl),
15015 Name_Long_Float => RTE (RE_IS_Ilf),
15016 Name_Long_Long_Float => RTE (RE_IS_Ill),
15017 Name_Signed_8 => RTE (RE_IS_Is1),
15018 Name_Signed_16 => RTE (RE_IS_Is2),
15019 Name_Signed_32 => RTE (RE_IS_Is4),
15020 Name_Signed_64 => RTE (RE_IS_Is8),
15021 Name_Signed_128 => Empty,
15022 Name_Unsigned_8 => RTE (RE_IS_Iu1),
15023 Name_Unsigned_16 => RTE (RE_IS_Iu2),
15024 Name_Unsigned_32 => RTE (RE_IS_Iu4),
15025 Name_Unsigned_64 => RTE (RE_IS_Iu8),
15026 Name_Unsigned_128 => Empty);
15028 if System_Max_Integer_Size < 128 then
15029 Invalid_Binder_Values (Name_Signed_128) := RTE (RE_IS_Is8);
15030 Invalid_Binder_Values (Name_Unsigned_128) := RTE (RE_IS_Iu8);
15031 else
15032 Invalid_Binder_Values (Name_Signed_128) := RTE (RE_IS_Is16);
15033 Invalid_Binder_Values (Name_Unsigned_128) := RTE (RE_IS_Iu16);
15034 end if;
15035 end if;
15036 end Set_Invalid_Binder_Values;
15038 -- Start of processing for Invalid_Scalar_Value
15040 begin
15041 if Scal_Typ in Float_Scalar_Id then
15042 return Invalid_Float_Value;
15044 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
15045 return Invalid_Integer_Value;
15046 end if;
15047 end Invalid_Scalar_Value;
15049 ------------------------
15050 -- Is_Access_Variable --
15051 ------------------------
15053 function Is_Access_Variable (E : Entity_Id) return Boolean is
15054 begin
15055 return Is_Access_Type (E)
15056 and then not Is_Access_Constant (E)
15057 and then Ekind (Directly_Designated_Type (E)) /= E_Subprogram_Type;
15058 end Is_Access_Variable;
15060 -----------------------------
15061 -- Is_Actual_Out_Parameter --
15062 -----------------------------
15064 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
15065 Formal : Entity_Id;
15066 Call : Node_Id;
15067 begin
15068 Find_Actual (N, Formal, Call);
15069 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
15070 end Is_Actual_Out_Parameter;
15072 --------------------------------
15073 -- Is_Actual_In_Out_Parameter --
15074 --------------------------------
15076 function Is_Actual_In_Out_Parameter (N : Node_Id) return Boolean is
15077 Formal : Entity_Id;
15078 Call : Node_Id;
15079 begin
15080 Find_Actual (N, Formal, Call);
15081 return Present (Formal) and then Ekind (Formal) = E_In_Out_Parameter;
15082 end Is_Actual_In_Out_Parameter;
15084 ---------------------------------------
15085 -- Is_Actual_Out_Or_In_Out_Parameter --
15086 ---------------------------------------
15088 function Is_Actual_Out_Or_In_Out_Parameter (N : Node_Id) return Boolean is
15089 Formal : Entity_Id;
15090 Call : Node_Id;
15091 begin
15092 Find_Actual (N, Formal, Call);
15093 return Present (Formal)
15094 and then Ekind (Formal) in E_Out_Parameter | E_In_Out_Parameter;
15095 end Is_Actual_Out_Or_In_Out_Parameter;
15097 -------------------------
15098 -- Is_Actual_Parameter --
15099 -------------------------
15101 function Is_Actual_Parameter (N : Node_Id) return Boolean is
15102 PK : constant Node_Kind := Nkind (Parent (N));
15104 begin
15105 case PK is
15106 when N_Parameter_Association =>
15107 return N = Explicit_Actual_Parameter (Parent (N));
15109 when N_Entry_Call_Statement
15110 | N_Subprogram_Call
15112 return Is_List_Member (N)
15113 and then
15114 List_Containing (N) = Parameter_Associations (Parent (N));
15116 when others =>
15117 return False;
15118 end case;
15119 end Is_Actual_Parameter;
15121 ---------------------
15122 -- Is_Aliased_View --
15123 ---------------------
15125 function Is_Aliased_View (Obj : Node_Id) return Boolean is
15126 E : Entity_Id;
15128 begin
15129 if Is_Entity_Name (Obj) then
15130 E := Entity (Obj);
15132 return
15133 (Is_Object (E)
15134 and then
15135 (Is_Aliased (E)
15136 or else (Present (Renamed_Object (E))
15137 and then Is_Aliased_View (Renamed_Object (E)))))
15139 or else ((Is_Formal (E) or else Is_Formal_Object (E))
15140 and then Is_Tagged_Type (Etype (E)))
15142 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
15144 -- Current instance of type, either directly or as rewritten
15145 -- reference to the current object.
15147 or else (Is_Entity_Name (Original_Node (Obj))
15148 and then Present (Entity (Original_Node (Obj)))
15149 and then Is_Type (Entity (Original_Node (Obj))))
15151 or else (Is_Type (E) and then E = Current_Scope)
15153 or else (Is_Incomplete_Or_Private_Type (E)
15154 and then Full_View (E) = Current_Scope)
15156 -- Ada 2012 AI05-0053: the return object of an extended return
15157 -- statement is aliased if its type is immutably limited.
15159 or else (Is_Return_Object (E)
15160 and then Is_Inherently_Limited_Type (Etype (E)))
15162 -- The current instance of a limited type is aliased, so
15163 -- we want to allow uses of T'Access in the init proc for
15164 -- a limited type T. However, we don't want to mark the formal
15165 -- parameter as being aliased since that could impact callers.
15167 or else (Is_Formal (E)
15168 and then Chars (E) = Name_uInit
15169 and then Is_Inherently_Limited_Type (Etype (E)));
15171 elsif Nkind (Obj) = N_Selected_Component then
15172 return Is_Aliased (Entity (Selector_Name (Obj)));
15174 elsif Nkind (Obj) = N_Indexed_Component then
15175 return Has_Aliased_Components (Etype (Prefix (Obj)))
15176 or else
15177 (Is_Access_Type (Etype (Prefix (Obj)))
15178 and then Has_Aliased_Components
15179 (Designated_Type (Etype (Prefix (Obj)))));
15181 elsif Nkind (Obj) in N_Unchecked_Type_Conversion | N_Type_Conversion then
15182 return Is_Tagged_Type (Etype (Obj))
15183 and then Is_Aliased_View (Expression (Obj));
15185 -- Ada 2022 AI12-0228
15187 elsif Nkind (Obj) = N_Qualified_Expression
15188 and then Ada_Version >= Ada_2012
15189 then
15190 return Is_Aliased_View (Expression (Obj));
15192 -- The dereference of an access-to-object value denotes an aliased view,
15193 -- but this routine uses the rules of the language so we need to exclude
15194 -- rewritten constructs that introduce artificial dereferences.
15196 elsif Nkind (Obj) = N_Explicit_Dereference then
15197 return not Is_Captured_Function_Call (Obj)
15198 and then not
15199 (Nkind (Parent (Obj)) = N_Object_Renaming_Declaration
15200 and then Is_Return_Object (Defining_Entity (Parent (Obj))));
15202 else
15203 return False;
15204 end if;
15205 end Is_Aliased_View;
15207 -------------------------
15208 -- Is_Ancestor_Package --
15209 -------------------------
15211 function Is_Ancestor_Package
15212 (E1 : Entity_Id;
15213 E2 : Entity_Id) return Boolean
15215 Par : Entity_Id;
15217 begin
15218 Par := E2;
15219 while Present (Par) and then Par /= Standard_Standard loop
15220 if Par = E1 then
15221 return True;
15222 end if;
15224 Par := Scope (Par);
15225 end loop;
15227 return False;
15228 end Is_Ancestor_Package;
15230 ----------------------
15231 -- Is_Atomic_Object --
15232 ----------------------
15234 function Is_Atomic_Object (N : Node_Id) return Boolean is
15235 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean;
15236 -- Determine whether prefix P has atomic components. This requires the
15237 -- presence of an Atomic_Components aspect/pragma.
15239 ---------------------------------
15240 -- Prefix_Has_Atomic_Components --
15241 ---------------------------------
15243 function Prefix_Has_Atomic_Components (P : Node_Id) return Boolean is
15244 Typ : constant Entity_Id := Etype (P);
15246 begin
15247 if Is_Access_Type (Typ) then
15248 return Has_Atomic_Components (Designated_Type (Typ));
15250 elsif Has_Atomic_Components (Typ) then
15251 return True;
15253 elsif Is_Entity_Name (P)
15254 and then Has_Atomic_Components (Entity (P))
15255 then
15256 return True;
15258 else
15259 return False;
15260 end if;
15261 end Prefix_Has_Atomic_Components;
15263 -- Start of processing for Is_Atomic_Object
15265 begin
15266 if Is_Entity_Name (N) then
15267 return Is_Atomic_Object_Entity (Entity (N));
15269 elsif Is_Atomic (Etype (N)) then
15270 return True;
15272 elsif Nkind (N) = N_Indexed_Component then
15273 return Prefix_Has_Atomic_Components (Prefix (N));
15275 elsif Nkind (N) = N_Selected_Component then
15276 return Is_Atomic (Entity (Selector_Name (N)));
15278 else
15279 return False;
15280 end if;
15281 end Is_Atomic_Object;
15283 -----------------------------
15284 -- Is_Atomic_Object_Entity --
15285 -----------------------------
15287 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
15288 begin
15289 return
15290 Is_Object (Id)
15291 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
15292 end Is_Atomic_Object_Entity;
15294 -----------------------------
15295 -- Is_Attribute_Loop_Entry --
15296 -----------------------------
15298 function Is_Attribute_Loop_Entry (N : Node_Id) return Boolean is
15299 begin
15300 return Nkind (N) = N_Attribute_Reference
15301 and then Attribute_Name (N) = Name_Loop_Entry;
15302 end Is_Attribute_Loop_Entry;
15304 ----------------------
15305 -- Is_Attribute_Old --
15306 ----------------------
15308 function Is_Attribute_Old (N : Node_Id) return Boolean is
15309 begin
15310 return Nkind (N) = N_Attribute_Reference
15311 and then Attribute_Name (N) = Name_Old;
15312 end Is_Attribute_Old;
15314 -------------------------
15315 -- Is_Attribute_Result --
15316 -------------------------
15318 function Is_Attribute_Result (N : Node_Id) return Boolean is
15319 begin
15320 return Nkind (N) = N_Attribute_Reference
15321 and then Attribute_Name (N) = Name_Result;
15322 end Is_Attribute_Result;
15324 -------------------------
15325 -- Is_Attribute_Update --
15326 -------------------------
15328 function Is_Attribute_Update (N : Node_Id) return Boolean is
15329 begin
15330 return Nkind (N) = N_Attribute_Reference
15331 and then Attribute_Name (N) = Name_Update;
15332 end Is_Attribute_Update;
15334 ------------------------------------
15335 -- Is_Body_Or_Package_Declaration --
15336 ------------------------------------
15338 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
15339 begin
15340 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
15341 end Is_Body_Or_Package_Declaration;
15343 -----------------------
15344 -- Is_Bounded_String --
15345 -----------------------
15347 function Is_Bounded_String (T : Entity_Id) return Boolean is
15348 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
15350 begin
15351 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
15352 -- Super_String, or one of the [Wide_]Wide_ versions. This will
15353 -- be True for all the Bounded_String types in instances of the
15354 -- Generic_Bounded_Length generics, and for types derived from those.
15356 return Present (Under)
15357 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
15358 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
15359 Is_RTE (Root_Type (Under), RO_WW_Super_String));
15360 end Is_Bounded_String;
15362 -------------------------------
15363 -- Is_By_Protected_Procedure --
15364 -------------------------------
15366 function Is_By_Protected_Procedure (Id : Entity_Id) return Boolean is
15367 begin
15368 return Ekind (Id) = E_Procedure
15369 and then Present (Get_Rep_Pragma (Id, Name_Implemented))
15370 and then Implementation_Kind (Id) = Name_By_Protected_Procedure;
15371 end Is_By_Protected_Procedure;
15373 ---------------------
15374 -- Is_CCT_Instance --
15375 ---------------------
15377 function Is_CCT_Instance
15378 (Ref_Id : Entity_Id;
15379 Context_Id : Entity_Id) return Boolean
15381 begin
15382 pragma Assert (Ekind (Ref_Id) in E_Protected_Type | E_Task_Type);
15384 if Is_Single_Task_Object (Context_Id) then
15385 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
15387 else
15388 pragma Assert
15389 (Ekind (Context_Id) in
15390 E_Entry | E_Entry_Family | E_Function | E_Package |
15391 E_Procedure | E_Protected_Type | E_Task_Type
15392 or else Is_Record_Type (Context_Id));
15393 return Scope_Within_Or_Same (Context_Id, Ref_Id);
15394 end if;
15395 end Is_CCT_Instance;
15397 -------------------------
15398 -- Is_Child_Or_Sibling --
15399 -------------------------
15401 function Is_Child_Or_Sibling
15402 (Pack_1 : Entity_Id;
15403 Pack_2 : Entity_Id) return Boolean
15405 function Distance_From_Standard (Pack : Entity_Id) return Nat;
15406 -- Given an arbitrary package, return the number of "climbs" necessary
15407 -- to reach scope Standard_Standard.
15409 procedure Equalize_Depths
15410 (Pack : in out Entity_Id;
15411 Depth : in out Nat;
15412 Depth_To_Reach : Nat);
15413 -- Given an arbitrary package, its depth and a target depth to reach,
15414 -- climb the scope chain until the said depth is reached. The pointer
15415 -- to the package and its depth a modified during the climb.
15417 ----------------------------
15418 -- Distance_From_Standard --
15419 ----------------------------
15421 function Distance_From_Standard (Pack : Entity_Id) return Nat is
15422 Dist : Nat;
15423 Scop : Entity_Id;
15425 begin
15426 Dist := 0;
15427 Scop := Pack;
15428 while Present (Scop) and then Scop /= Standard_Standard loop
15429 Dist := Dist + 1;
15430 Scop := Scope (Scop);
15431 end loop;
15433 return Dist;
15434 end Distance_From_Standard;
15436 ---------------------
15437 -- Equalize_Depths --
15438 ---------------------
15440 procedure Equalize_Depths
15441 (Pack : in out Entity_Id;
15442 Depth : in out Nat;
15443 Depth_To_Reach : Nat)
15445 begin
15446 -- The package must be at a greater or equal depth
15448 if Depth < Depth_To_Reach then
15449 raise Program_Error;
15450 end if;
15452 -- Climb the scope chain until the desired depth is reached
15454 while Present (Pack) and then Depth /= Depth_To_Reach loop
15455 Pack := Scope (Pack);
15456 Depth := Depth - 1;
15457 end loop;
15458 end Equalize_Depths;
15460 -- Local variables
15462 P_1 : Entity_Id := Pack_1;
15463 P_1_Child : Boolean := False;
15464 P_1_Depth : Nat := Distance_From_Standard (P_1);
15465 P_2 : Entity_Id := Pack_2;
15466 P_2_Child : Boolean := False;
15467 P_2_Depth : Nat := Distance_From_Standard (P_2);
15469 -- Start of processing for Is_Child_Or_Sibling
15471 begin
15472 pragma Assert
15473 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
15475 -- Both packages denote the same entity, therefore they cannot be
15476 -- children or siblings.
15478 if P_1 = P_2 then
15479 return False;
15481 -- One of the packages is at a deeper level than the other. Note that
15482 -- both may still come from different hierarchies.
15484 -- (root) P_2
15485 -- / \ :
15486 -- X P_2 or X
15487 -- : :
15488 -- P_1 P_1
15490 elsif P_1_Depth > P_2_Depth then
15491 Equalize_Depths
15492 (Pack => P_1,
15493 Depth => P_1_Depth,
15494 Depth_To_Reach => P_2_Depth);
15495 P_1_Child := True;
15497 -- (root) P_1
15498 -- / \ :
15499 -- P_1 X or X
15500 -- : :
15501 -- P_2 P_2
15503 elsif P_2_Depth > P_1_Depth then
15504 Equalize_Depths
15505 (Pack => P_2,
15506 Depth => P_2_Depth,
15507 Depth_To_Reach => P_1_Depth);
15508 P_2_Child := True;
15509 end if;
15511 -- At this stage the package pointers have been elevated to the same
15512 -- depth. If the related entities are the same, then one package is a
15513 -- potential child of the other:
15515 -- P_1
15516 -- :
15517 -- X became P_1 P_2 or vice versa
15518 -- :
15519 -- P_2
15521 if P_1 = P_2 then
15522 if P_1_Child then
15523 return Is_Child_Unit (Pack_1);
15525 else pragma Assert (P_2_Child);
15526 return Is_Child_Unit (Pack_2);
15527 end if;
15529 -- The packages may come from the same package chain or from entirely
15530 -- different hierarchies. To determine this, climb the scope stack until
15531 -- a common root is found.
15533 -- (root) (root 1) (root 2)
15534 -- / \ | |
15535 -- P_1 P_2 P_1 P_2
15537 else
15538 while Present (P_1) and then Present (P_2) loop
15540 -- The two packages may be siblings
15542 if P_1 = P_2 then
15543 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
15544 end if;
15546 P_1 := Scope (P_1);
15547 P_2 := Scope (P_2);
15548 end loop;
15549 end if;
15551 return False;
15552 end Is_Child_Or_Sibling;
15554 -------------------
15555 -- Is_Confirming --
15556 -------------------
15558 function Is_Confirming (Aspect : Nonoverridable_Aspect_Id;
15559 Aspect_Spec_1, Aspect_Spec_2 : Node_Id)
15560 return Boolean is
15561 function Names_Match (Nm1, Nm2 : Node_Id) return Boolean;
15563 -----------------
15564 -- Names_Match --
15565 -----------------
15567 function Names_Match (Nm1, Nm2 : Node_Id) return Boolean is
15568 begin
15569 if Nkind (Nm1) /= Nkind (Nm2) then
15570 return False;
15571 -- This may be too restrictive given that visibility
15572 -- may allow an identifier in one case and an expanded
15573 -- name in the other.
15574 end if;
15575 case Nkind (Nm1) is
15576 when N_Identifier =>
15577 return Name_Equals (Chars (Nm1), Chars (Nm2));
15579 when N_Expanded_Name =>
15580 -- An inherited operation has the same name as its
15581 -- ancestor, but they may have different scopes.
15582 -- This may be too permissive for Iterator_Element, which
15583 -- is intended to be identical in parent and derived type.
15585 return Names_Match (Selector_Name (Nm1),
15586 Selector_Name (Nm2));
15588 when N_Empty =>
15589 return True; -- needed for Aggregate aspect checking
15591 when others =>
15592 -- e.g., 'Class attribute references
15593 if Is_Entity_Name (Nm1) and Is_Entity_Name (Nm2) then
15594 return Entity (Nm1) = Entity (Nm2);
15595 end if;
15597 raise Program_Error;
15598 end case;
15599 end Names_Match;
15600 begin
15601 -- allow users to disable "shall be confirming" check, at least for now
15602 if Relaxed_RM_Semantics then
15603 return True;
15604 end if;
15606 -- ??? Type conversion here (along with "when others =>" below) is a
15607 -- workaround for a bootstrapping problem related to casing on a
15608 -- static-predicate-bearing subtype.
15610 case Aspect_Id (Aspect) is
15611 -- name-valued aspects; compare text of names, not resolution.
15612 when Aspect_Default_Iterator
15613 | Aspect_Iterator_Element
15614 | Aspect_Constant_Indexing
15615 | Aspect_Variable_Indexing =>
15616 declare
15617 Item_1 : constant Node_Id := Aspect_Rep_Item (Aspect_Spec_1);
15618 Item_2 : constant Node_Id := Aspect_Rep_Item (Aspect_Spec_2);
15619 begin
15620 if Nkind (Item_1) /= N_Attribute_Definition_Clause
15621 or Nkind (Item_2) /= N_Attribute_Definition_Clause
15622 then
15623 pragma Assert (Serious_Errors_Detected > 0);
15624 return True;
15625 end if;
15627 return Names_Match (Expression (Item_1),
15628 Expression (Item_2));
15629 end;
15631 -- A confirming aspect for Implicit_Derenfence on a derived type
15632 -- has already been checked in Analyze_Aspect_Implicit_Dereference,
15633 -- including the presence of renamed discriminants.
15635 when Aspect_Implicit_Dereference =>
15636 return True;
15638 -- one of a kind
15639 when Aspect_Aggregate =>
15640 declare
15641 Empty_1,
15642 Add_Named_1,
15643 Add_Unnamed_1,
15644 New_Indexed_1,
15645 Assign_Indexed_1,
15646 Empty_2,
15647 Add_Named_2,
15648 Add_Unnamed_2,
15649 New_Indexed_2,
15650 Assign_Indexed_2 : Node_Id := Empty;
15651 begin
15652 Parse_Aspect_Aggregate
15653 (N => Expression (Aspect_Spec_1),
15654 Empty_Subp => Empty_1,
15655 Add_Named_Subp => Add_Named_1,
15656 Add_Unnamed_Subp => Add_Unnamed_1,
15657 New_Indexed_Subp => New_Indexed_1,
15658 Assign_Indexed_Subp => Assign_Indexed_1);
15659 Parse_Aspect_Aggregate
15660 (N => Expression (Aspect_Spec_2),
15661 Empty_Subp => Empty_2,
15662 Add_Named_Subp => Add_Named_2,
15663 Add_Unnamed_Subp => Add_Unnamed_2,
15664 New_Indexed_Subp => New_Indexed_2,
15665 Assign_Indexed_Subp => Assign_Indexed_2);
15666 return
15667 Names_Match (Empty_1, Empty_2) and then
15668 Names_Match (Add_Named_1, Add_Named_2) and then
15669 Names_Match (Add_Unnamed_1, Add_Unnamed_2) and then
15670 Names_Match (New_Indexed_1, New_Indexed_2) and then
15671 Names_Match (Assign_Indexed_1, Assign_Indexed_2);
15672 end;
15674 -- Checking for this aspect is performed elsewhere during freezing
15675 when Aspect_No_Controlled_Parts =>
15676 return True;
15678 -- scalar-valued aspects; compare (static) values.
15679 when Aspect_Max_Entry_Queue_Length =>
15680 -- This should be unreachable. Max_Entry_Queue_Length is
15681 -- supported only for protected entries, not for types.
15682 pragma Assert (Serious_Errors_Detected /= 0);
15683 return True;
15685 when others =>
15686 raise Program_Error;
15687 end case;
15688 end Is_Confirming;
15690 -----------------------------
15691 -- Is_Concurrent_Interface --
15692 -----------------------------
15694 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
15695 begin
15696 return Is_Protected_Interface (T)
15697 or else Is_Synchronized_Interface (T)
15698 or else Is_Task_Interface (T);
15699 end Is_Concurrent_Interface;
15701 ------------------------------------------------------
15702 -- Is_Conjunction_Of_Formal_Preelab_Init_Attributes --
15703 ------------------------------------------------------
15705 function Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15706 (Expr : Node_Id) return Boolean
15709 function Is_Formal_Preelab_Init_Attribute
15710 (N : Node_Id) return Boolean;
15711 -- Returns True if N is a Preelaborable_Initialization attribute
15712 -- applied to a generic formal type, or N's Original_Node is such
15713 -- an attribute.
15715 --------------------------------------
15716 -- Is_Formal_Preelab_Init_Attribute --
15717 --------------------------------------
15719 function Is_Formal_Preelab_Init_Attribute
15720 (N : Node_Id) return Boolean
15722 Orig_N : constant Node_Id := Original_Node (N);
15724 begin
15725 return Nkind (Orig_N) = N_Attribute_Reference
15726 and then Attribute_Name (Orig_N) = Name_Preelaborable_Initialization
15727 and then Is_Entity_Name (Prefix (Orig_N))
15728 and then Is_Generic_Type (Entity (Prefix (Orig_N)));
15729 end Is_Formal_Preelab_Init_Attribute;
15731 -- Start of Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15733 begin
15734 return Is_Formal_Preelab_Init_Attribute (Expr)
15735 or else (Nkind (Expr) = N_Op_And
15736 and then
15737 Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15738 (Left_Opnd (Expr))
15739 and then
15740 Is_Conjunction_Of_Formal_Preelab_Init_Attributes
15741 (Right_Opnd (Expr)));
15742 end Is_Conjunction_Of_Formal_Preelab_Init_Attributes;
15744 -----------------------
15745 -- Is_Constant_Bound --
15746 -----------------------
15748 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
15749 begin
15750 if Compile_Time_Known_Value (Exp) then
15751 return True;
15753 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
15754 return Is_Constant_Object (Entity (Exp))
15755 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
15757 elsif Nkind (Exp) in N_Binary_Op then
15758 return Is_Constant_Bound (Left_Opnd (Exp))
15759 and then Is_Constant_Bound (Right_Opnd (Exp))
15760 and then Scope (Entity (Exp)) = Standard_Standard;
15762 else
15763 return False;
15764 end if;
15765 end Is_Constant_Bound;
15767 ---------------------------
15768 -- Is_Container_Element --
15769 ---------------------------
15771 function Is_Container_Element (Exp : Node_Id) return Boolean is
15772 Loc : constant Source_Ptr := Sloc (Exp);
15773 Pref : constant Node_Id := Prefix (Exp);
15775 Call : Node_Id;
15776 -- Call to an indexing aspect
15778 Cont_Typ : Entity_Id;
15779 -- The type of the container being accessed
15781 Elem_Typ : Entity_Id;
15782 -- Its element type
15784 Indexing : Entity_Id;
15785 Is_Const : Boolean;
15786 -- Indicates that constant indexing is used, and the element is thus
15787 -- a constant.
15789 Ref_Typ : Entity_Id;
15790 -- The reference type returned by the indexing operation
15792 begin
15793 -- If C is a container, in a context that imposes the element type of
15794 -- that container, the indexing notation C (X) is rewritten as:
15796 -- Indexing (C, X).Discr.all
15798 -- where Indexing is one of the indexing aspects of the container.
15799 -- If the context does not require a reference, the construct can be
15800 -- rewritten as
15802 -- Element (C, X)
15804 -- First, verify that the construct has the proper form
15806 if not Expander_Active then
15807 return False;
15809 elsif Nkind (Pref) /= N_Selected_Component then
15810 return False;
15812 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
15813 return False;
15815 else
15816 Call := Prefix (Pref);
15817 Ref_Typ := Etype (Call);
15818 end if;
15820 if not Has_Implicit_Dereference (Ref_Typ)
15821 or else No (First (Parameter_Associations (Call)))
15822 or else not Is_Entity_Name (Name (Call))
15823 then
15824 return False;
15825 end if;
15827 -- Retrieve type of container object, and its iterator aspects
15829 Cont_Typ := Etype (First (Parameter_Associations (Call)));
15830 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
15831 Is_Const := False;
15833 if No (Indexing) then
15835 -- Container should have at least one indexing operation
15837 return False;
15839 elsif Entity (Name (Call)) /= Entity (Indexing) then
15841 -- This may be a variable indexing operation
15843 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
15845 if No (Indexing)
15846 or else Entity (Name (Call)) /= Entity (Indexing)
15847 then
15848 return False;
15849 end if;
15851 else
15852 Is_Const := True;
15853 end if;
15855 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
15857 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
15858 return False;
15859 end if;
15861 -- Check that the expression is not the target of an assignment, in
15862 -- which case the rewriting is not possible.
15864 if not Is_Const then
15865 declare
15866 Par : Node_Id;
15868 begin
15869 Par := Exp;
15870 while Present (Par)
15871 loop
15872 if Nkind (Parent (Par)) = N_Assignment_Statement
15873 and then Par = Name (Parent (Par))
15874 then
15875 return False;
15877 -- A renaming produces a reference, and the transformation
15878 -- does not apply.
15880 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
15881 return False;
15883 elsif Nkind (Parent (Par)) in
15884 N_Function_Call |
15885 N_Procedure_Call_Statement |
15886 N_Entry_Call_Statement
15887 then
15888 -- Check that the element is not part of an actual for an
15889 -- in-out parameter.
15891 declare
15892 F : Entity_Id;
15893 A : Node_Id;
15895 begin
15896 F := First_Formal (Entity (Name (Parent (Par))));
15897 A := First (Parameter_Associations (Parent (Par)));
15898 while Present (F) loop
15899 if A = Par and then Ekind (F) /= E_In_Parameter then
15900 return False;
15901 end if;
15903 Next_Formal (F);
15904 Next (A);
15905 end loop;
15906 end;
15908 -- E_In_Parameter in a call: element is not modified.
15910 exit;
15911 end if;
15913 Par := Parent (Par);
15914 end loop;
15915 end;
15916 end if;
15918 -- The expression has the proper form and the context requires the
15919 -- element type. Retrieve the Element function of the container and
15920 -- rewrite the construct as a call to it.
15922 declare
15923 Op : Elmt_Id;
15925 begin
15926 Op := First_Elmt (Primitive_Operations (Cont_Typ));
15927 while Present (Op) loop
15928 exit when Chars (Node (Op)) = Name_Element;
15929 Next_Elmt (Op);
15930 end loop;
15932 if No (Op) then
15933 return False;
15935 else
15936 Rewrite (Exp,
15937 Make_Function_Call (Loc,
15938 Name => New_Occurrence_Of (Node (Op), Loc),
15939 Parameter_Associations => Parameter_Associations (Call)));
15940 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
15941 return True;
15942 end if;
15943 end;
15944 end Is_Container_Element;
15946 ----------------------------
15947 -- Is_Contract_Annotation --
15948 ----------------------------
15950 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
15951 begin
15952 return Is_Package_Contract_Annotation (Item)
15953 or else
15954 Is_Subprogram_Contract_Annotation (Item);
15955 end Is_Contract_Annotation;
15957 --------------------------------------
15958 -- Is_Controlling_Limited_Procedure --
15959 --------------------------------------
15961 function Is_Controlling_Limited_Procedure
15962 (Proc_Nam : Entity_Id) return Boolean
15964 Param : Node_Id;
15965 Param_Typ : Entity_Id := Empty;
15967 begin
15968 if Ekind (Proc_Nam) = E_Procedure
15969 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
15970 then
15971 Param :=
15972 Parameter_Type
15973 (First (Parameter_Specifications (Parent (Proc_Nam))));
15975 -- The formal may be an anonymous access type
15977 if Nkind (Param) = N_Access_Definition then
15978 Param_Typ := Entity (Subtype_Mark (Param));
15979 else
15980 Param_Typ := Etype (Param);
15981 end if;
15983 -- In the case where an Itype was created for a dispatchin call, the
15984 -- procedure call has been rewritten. The actual may be an access to
15985 -- interface type in which case it is the designated type that is the
15986 -- controlling type.
15988 elsif Present (Associated_Node_For_Itype (Proc_Nam))
15989 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
15990 and then
15991 Present (Parameter_Associations
15992 (Associated_Node_For_Itype (Proc_Nam)))
15993 then
15994 Param_Typ :=
15995 Etype (First (Parameter_Associations
15996 (Associated_Node_For_Itype (Proc_Nam))));
15998 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
15999 Param_Typ := Directly_Designated_Type (Param_Typ);
16000 end if;
16001 end if;
16003 if Present (Param_Typ) then
16004 return
16005 Is_Interface (Param_Typ)
16006 and then Is_Limited_Record (Param_Typ);
16007 end if;
16009 return False;
16010 end Is_Controlling_Limited_Procedure;
16012 -----------------------------
16013 -- Is_CPP_Constructor_Call --
16014 -----------------------------
16016 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
16017 Ret_Typ : Entity_Id;
16019 begin
16020 if Nkind (N) /= N_Function_Call then
16021 return False;
16022 end if;
16024 Ret_Typ := Base_Type (Etype (N));
16026 if Is_Class_Wide_Type (Ret_Typ) then
16027 Ret_Typ := Root_Type (Ret_Typ);
16028 end if;
16030 if Is_Private_Type (Ret_Typ) then
16031 Ret_Typ := Underlying_Type (Ret_Typ);
16032 end if;
16034 return Present (Ret_Typ)
16035 and then Is_CPP_Class (Ret_Typ)
16036 and then Is_Constructor (Entity (Name (N)))
16037 and then Is_Imported (Entity (Name (N)));
16038 end Is_CPP_Constructor_Call;
16040 -------------------------
16041 -- Is_Current_Instance --
16042 -------------------------
16044 function Is_Current_Instance (N : Node_Id) return Boolean is
16045 Typ : constant Entity_Id := Entity (N);
16046 P : Node_Id;
16048 begin
16049 -- Simplest case: entity is a concurrent type and we are currently
16050 -- inside the body. This will eventually be expanded into a call to
16051 -- Self (for tasks) or _object (for protected objects).
16053 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
16054 return True;
16056 else
16057 -- Check whether the context is a (sub)type declaration for the
16058 -- type entity.
16060 P := Parent (N);
16061 while Present (P) loop
16062 if Nkind (P) in N_Full_Type_Declaration
16063 | N_Private_Type_Declaration
16064 | N_Subtype_Declaration
16065 and then Comes_From_Source (P)
16067 -- If the type has a previous incomplete declaration, the
16068 -- reference in the type definition may have the incomplete
16069 -- view. So, here we detect if this incomplete view is a current
16070 -- instance by checking if its full view is the entity of the
16071 -- full declaration begin analyzed.
16073 and then
16074 (Defining_Entity (P) = Typ
16075 or else
16076 (Ekind (Typ) = E_Incomplete_Type
16077 and then Full_View (Typ) = Defining_Entity (P)))
16078 then
16079 return True;
16081 -- A subtype name may appear in an aspect specification for a
16082 -- Predicate_Failure aspect, for which we do not construct a
16083 -- wrapper procedure. The subtype will be replaced by the
16084 -- expression being tested when the corresponding predicate
16085 -- check is expanded. It may also appear in the pragma Predicate
16086 -- expression during legality checking.
16088 elsif Nkind (P) = N_Aspect_Specification
16089 and then Nkind (Parent (P)) = N_Subtype_Declaration
16090 and then Underlying_Type (Defining_Identifier (Parent (P))) =
16091 Underlying_Type (Typ)
16092 then
16093 return True;
16095 elsif Nkind (P) = N_Pragma
16096 and then Get_Pragma_Id (P) in Pragma_Predicate
16097 | Pragma_Predicate_Failure
16098 then
16099 declare
16100 Arg : constant Entity_Id :=
16101 Entity (Expression (Get_Argument (P)));
16102 begin
16103 if Underlying_Type (Arg) = Underlying_Type (Typ) then
16104 return True;
16105 end if;
16106 end;
16107 end if;
16109 P := Parent (P);
16110 end loop;
16111 end if;
16113 -- In any other context this is not a current occurrence
16115 return False;
16116 end Is_Current_Instance;
16118 --------------------------------------------------
16119 -- Is_Current_Instance_Reference_In_Type_Aspect --
16120 --------------------------------------------------
16122 function Is_Current_Instance_Reference_In_Type_Aspect
16123 (N : Node_Id) return Boolean
16125 begin
16126 -- When a current_instance is referenced within an aspect_specification
16127 -- of a type or subtype, it will show up as a reference to the formal
16128 -- parameter of the aspect's associated subprogram rather than as a
16129 -- reference to the type or subtype itself (in fact, the original name
16130 -- is never even analyzed). We check for predicate, invariant, and
16131 -- Default_Initial_Condition subprograms (in theory there could be
16132 -- other cases added, in which case this function will need updating).
16134 if Is_Entity_Name (N) then
16135 return Present (Entity (N))
16136 and then Ekind (Entity (N)) = E_In_Parameter
16137 and then Ekind (Scope (Entity (N))) in E_Function | E_Procedure
16138 and then
16139 (Is_Predicate_Function (Scope (Entity (N)))
16140 or else Is_Invariant_Procedure (Scope (Entity (N)))
16141 or else Is_Partial_Invariant_Procedure (Scope (Entity (N)))
16142 or else Is_DIC_Procedure (Scope (Entity (N))));
16144 else
16145 case Nkind (N) is
16146 when N_Indexed_Component
16147 | N_Slice
16149 return
16150 Is_Current_Instance_Reference_In_Type_Aspect (Prefix (N));
16152 when N_Selected_Component =>
16153 return
16154 Is_Current_Instance_Reference_In_Type_Aspect (Prefix (N));
16156 when N_Type_Conversion =>
16157 return Is_Current_Instance_Reference_In_Type_Aspect
16158 (Expression (N));
16160 when N_Qualified_Expression =>
16161 return Is_Current_Instance_Reference_In_Type_Aspect
16162 (Expression (N));
16164 when others =>
16165 return False;
16166 end case;
16167 end if;
16168 end Is_Current_Instance_Reference_In_Type_Aspect;
16170 --------------------
16171 -- Is_Declaration --
16172 --------------------
16174 function Is_Declaration
16175 (N : Node_Id;
16176 Body_OK : Boolean := True;
16177 Concurrent_OK : Boolean := True;
16178 Formal_OK : Boolean := True;
16179 Generic_OK : Boolean := True;
16180 Instantiation_OK : Boolean := True;
16181 Renaming_OK : Boolean := True;
16182 Stub_OK : Boolean := True;
16183 Subprogram_OK : Boolean := True;
16184 Type_OK : Boolean := True) return Boolean
16186 begin
16187 case Nkind (N) is
16189 -- Body declarations
16191 when N_Proper_Body =>
16192 return Body_OK;
16194 -- Concurrent type declarations
16196 when N_Protected_Type_Declaration
16197 | N_Single_Protected_Declaration
16198 | N_Single_Task_Declaration
16199 | N_Task_Type_Declaration
16201 return Concurrent_OK or Type_OK;
16203 -- Formal declarations
16205 when N_Formal_Abstract_Subprogram_Declaration
16206 | N_Formal_Concrete_Subprogram_Declaration
16207 | N_Formal_Object_Declaration
16208 | N_Formal_Package_Declaration
16209 | N_Formal_Type_Declaration
16211 return Formal_OK;
16213 -- Generic declarations
16215 when N_Generic_Package_Declaration
16216 | N_Generic_Subprogram_Declaration
16218 return Generic_OK;
16220 -- Generic instantiations
16222 when N_Function_Instantiation
16223 | N_Package_Instantiation
16224 | N_Procedure_Instantiation
16226 return Instantiation_OK;
16228 -- Generic renaming declarations
16230 when N_Generic_Renaming_Declaration =>
16231 return Generic_OK or Renaming_OK;
16233 -- Renaming declarations
16235 when N_Exception_Renaming_Declaration
16236 | N_Object_Renaming_Declaration
16237 | N_Package_Renaming_Declaration
16238 | N_Subprogram_Renaming_Declaration
16240 return Renaming_OK;
16242 -- Stub declarations
16244 when N_Body_Stub =>
16245 return Stub_OK;
16247 -- Subprogram declarations
16249 when N_Abstract_Subprogram_Declaration
16250 | N_Entry_Declaration
16251 | N_Expression_Function
16252 | N_Subprogram_Declaration
16254 return Subprogram_OK;
16256 -- Type declarations
16258 when N_Full_Type_Declaration
16259 | N_Incomplete_Type_Declaration
16260 | N_Private_Extension_Declaration
16261 | N_Private_Type_Declaration
16262 | N_Subtype_Declaration
16264 return Type_OK;
16266 -- Miscellaneous
16268 when N_Component_Declaration
16269 | N_Exception_Declaration
16270 | N_Implicit_Label_Declaration
16271 | N_Number_Declaration
16272 | N_Object_Declaration
16273 | N_Package_Declaration
16275 return True;
16277 when others =>
16278 return False;
16279 end case;
16280 end Is_Declaration;
16282 --------------------------------
16283 -- Is_Declared_Within_Variant --
16284 --------------------------------
16286 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
16287 Comp_Decl : constant Node_Id := Parent (Comp);
16288 Comp_List : constant Node_Id := Parent (Comp_Decl);
16289 begin
16290 return Nkind (Parent (Comp_List)) = N_Variant;
16291 end Is_Declared_Within_Variant;
16293 ----------------------------------------------
16294 -- Is_Dependent_Component_Of_Mutable_Object --
16295 ----------------------------------------------
16297 function Is_Dependent_Component_Of_Mutable_Object
16298 (Object : Node_Id) return Boolean
16300 P : Node_Id;
16301 Prefix_Type : Entity_Id;
16302 P_Aliased : Boolean := False;
16303 Comp : Entity_Id;
16305 Deref : Node_Id := Original_Node (Object);
16306 -- Dereference node, in something like X.all.Y(2)
16308 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
16310 begin
16311 -- Find the dereference node if any
16313 while Nkind (Deref) in
16314 N_Indexed_Component | N_Selected_Component | N_Slice
16315 loop
16316 Deref := Original_Node (Prefix (Deref));
16317 end loop;
16319 -- If the prefix is a qualified expression of a variable, then function
16320 -- Is_Variable will return False for that because a qualified expression
16321 -- denotes a constant view, so we need to get the name being qualified
16322 -- so we can test below whether that's a variable (or a dereference).
16324 if Nkind (Deref) = N_Qualified_Expression then
16325 Deref := Expression (Deref);
16326 end if;
16328 -- Ada 2005: If we have a component or slice of a dereference, something
16329 -- like X.all.Y (2) and the type of X is access-to-constant, Is_Variable
16330 -- will return False, because it is indeed a constant view. But it might
16331 -- be a view of a variable object, so we want the following condition to
16332 -- be True in that case.
16334 if Is_Variable (Object)
16335 or else Is_Variable (Deref)
16336 or else
16337 (Ada_Version >= Ada_2005
16338 and then (Nkind (Deref) = N_Explicit_Dereference
16339 or else (Present (Etype (Deref))
16340 and then Is_Access_Type (Etype (Deref)))))
16341 then
16342 if Nkind (Object) = N_Selected_Component then
16344 -- If the selector is not a component, then we definitely return
16345 -- False (it could be a function selector in a prefix form call
16346 -- occurring in an iterator specification).
16348 if (Present (Entity (Selector_Name (Object)))
16349 and then Ekind (Entity (Selector_Name (Object))) not in
16350 E_Component | E_Discriminant)
16351 or else
16352 (Inside_A_Generic
16353 and then Nkind (Parent (Selector_Name (Object)))
16354 = N_Function_Call)
16355 then
16356 return False;
16357 end if;
16359 -- Get the original node of the prefix in case it has been
16360 -- rewritten, which can occur, for example, in qualified
16361 -- expression cases. Also, a discriminant check on a selected
16362 -- component may be expanded into a dereference when removing
16363 -- side effects, and the subtype of the original node may be
16364 -- unconstrained.
16366 P := Original_Node (Prefix (Object));
16367 Prefix_Type := Etype (P);
16369 -- If the prefix is a qualified expression, we want to look at its
16370 -- operand.
16372 if Nkind (P) = N_Qualified_Expression then
16373 P := Expression (P);
16374 Prefix_Type := Etype (P);
16375 end if;
16377 if Is_Entity_Name (P) then
16378 -- The Etype may not be set on P (which is wrong) in certain
16379 -- corner cases involving the deprecated front-end inlining of
16380 -- subprograms (via -gnatN), so use the Etype set on the
16381 -- the entity for these instances since we know it is present.
16383 if No (Prefix_Type) then
16384 Prefix_Type := Etype (Entity (P));
16385 end if;
16387 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
16388 Prefix_Type := Base_Type (Prefix_Type);
16389 end if;
16391 if Is_Aliased (Entity (P)) then
16392 P_Aliased := True;
16393 end if;
16395 -- For explicit dereferences we get the access prefix so we can
16396 -- treat this similarly to implicit dereferences and examine the
16397 -- kind of the access type and its designated subtype further
16398 -- below.
16400 elsif Nkind (P) = N_Explicit_Dereference then
16401 P := Prefix (P);
16402 Prefix_Type := Etype (P);
16404 else
16405 -- Check for prefix being an aliased component???
16407 null;
16408 end if;
16410 -- A heap object is constrained by its initial value
16412 -- Ada 2005 (AI-363): Always assume the object could be mutable in
16413 -- the dereferenced case, since the access value might denote an
16414 -- unconstrained aliased object, whereas in Ada 95 the designated
16415 -- object is guaranteed to be constrained. A worst-case assumption
16416 -- has to apply in Ada 2005 because we can't tell at compile
16417 -- time whether the object is "constrained by its initial value",
16418 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
16419 -- rules (these rules are acknowledged to need fixing). We don't
16420 -- impose this more stringent checking for earlier Ada versions or
16421 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
16422 -- benefit, though it's unclear on why using -gnat95 would not be
16423 -- sufficient???).
16425 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
16426 if Is_Access_Type (Prefix_Type)
16427 or else Nkind (P) = N_Explicit_Dereference
16428 then
16429 return False;
16430 end if;
16432 else pragma Assert (Ada_Version >= Ada_2005);
16433 if Is_Access_Type (Prefix_Type) then
16434 -- We need to make sure we have the base subtype, in case
16435 -- this is actually an access subtype (whose Ekind will be
16436 -- E_Access_Subtype).
16438 Prefix_Type := Etype (Prefix_Type);
16440 -- If the access type is pool-specific, and there is no
16441 -- constrained partial view of the designated type, then the
16442 -- designated object is known to be constrained. If it's a
16443 -- formal access type and the renaming is in the generic
16444 -- spec, we also treat it as pool-specific (known to be
16445 -- constrained), but assume the worst if in the generic body
16446 -- (see RM 3.3(23.3/3)).
16448 if Ekind (Prefix_Type) = E_Access_Type
16449 and then (not Is_Generic_Type (Prefix_Type)
16450 or else not In_Generic_Body (Current_Scope))
16451 and then not Object_Type_Has_Constrained_Partial_View
16452 (Typ => Designated_Type (Prefix_Type),
16453 Scop => Current_Scope)
16454 then
16455 return False;
16457 -- Otherwise (general access type, or there is a constrained
16458 -- partial view of the designated type), we need to check
16459 -- based on the designated type.
16461 else
16462 Prefix_Type := Designated_Type (Prefix_Type);
16463 end if;
16464 end if;
16465 end if;
16467 Comp :=
16468 Original_Record_Component (Entity (Selector_Name (Object)));
16470 -- As per AI-0017, the renaming is illegal in a generic body, even
16471 -- if the subtype is indefinite (only applies to prefixes of an
16472 -- untagged formal type, see RM 3.3 (23.11/3)).
16474 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
16476 if not Is_Constrained (Prefix_Type)
16477 and then (Is_Definite_Subtype (Prefix_Type)
16478 or else
16479 (not Is_Tagged_Type (Prefix_Type)
16480 and then Is_Generic_Type (Prefix_Type)
16481 and then In_Generic_Body (Current_Scope)))
16483 and then (Is_Declared_Within_Variant (Comp)
16484 or else Has_Discriminant_Dependent_Constraint (Comp))
16485 and then (not P_Aliased or else Ada_Version >= Ada_2005)
16486 then
16487 return True;
16489 -- If the prefix is of an access type at this point, then we want
16490 -- to return False, rather than calling this function recursively
16491 -- on the access object (which itself might be a discriminant-
16492 -- dependent component of some other object, but that isn't
16493 -- relevant to checking the object passed to us). This avoids
16494 -- issuing wrong errors when compiling with -gnatc, where there
16495 -- can be implicit dereferences that have not been expanded.
16497 elsif Is_Access_Type (Etype (Prefix (Object))) then
16498 return False;
16500 else
16501 return
16502 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
16503 end if;
16505 elsif Nkind (Object) = N_Indexed_Component
16506 or else Nkind (Object) = N_Slice
16507 then
16508 return Is_Dependent_Component_Of_Mutable_Object
16509 (Original_Node (Prefix (Object)));
16511 -- A type conversion that Is_Variable is a view conversion:
16512 -- go back to the denoted object.
16514 elsif Nkind (Object) = N_Type_Conversion then
16515 return
16516 Is_Dependent_Component_Of_Mutable_Object
16517 (Original_Node (Expression (Object)));
16518 end if;
16519 end if;
16521 return False;
16522 end Is_Dependent_Component_Of_Mutable_Object;
16524 ---------------------
16525 -- Is_Dereferenced --
16526 ---------------------
16528 function Is_Dereferenced (N : Node_Id) return Boolean is
16529 P : constant Node_Id := Parent (N);
16530 begin
16531 return Nkind (P) in N_Selected_Component
16532 | N_Explicit_Dereference
16533 | N_Indexed_Component
16534 | N_Slice
16535 and then Prefix (P) = N;
16536 end Is_Dereferenced;
16538 ----------------------
16539 -- Is_Descendant_Of --
16540 ----------------------
16542 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
16543 T : Entity_Id;
16544 Etyp : Entity_Id;
16546 begin
16547 pragma Assert (Nkind (T1) in N_Entity);
16548 pragma Assert (Nkind (T2) in N_Entity);
16550 T := Base_Type (T1);
16552 -- Immediate return if the types match
16554 if T = T2 then
16555 return True;
16557 -- Comment needed here ???
16559 elsif Ekind (T) = E_Class_Wide_Type then
16560 return Etype (T) = T2;
16562 -- All other cases
16564 else
16565 loop
16566 Etyp := Etype (T);
16568 -- Done if we found the type we are looking for
16570 if Etyp = T2 then
16571 return True;
16573 -- Done if no more derivations to check
16575 elsif T = T1
16576 or else T = Etyp
16577 then
16578 return False;
16580 -- Following test catches error cases resulting from prev errors
16582 elsif No (Etyp) then
16583 return False;
16585 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
16586 return False;
16588 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
16589 return False;
16590 end if;
16592 T := Base_Type (Etyp);
16593 end loop;
16594 end if;
16595 end Is_Descendant_Of;
16597 ----------------------------------------
16598 -- Is_Descendant_Of_Suspension_Object --
16599 ----------------------------------------
16601 function Is_Descendant_Of_Suspension_Object
16602 (Typ : Entity_Id) return Boolean
16604 Cur_Typ : Entity_Id;
16605 Par_Typ : Entity_Id;
16607 begin
16608 -- Climb the type derivation chain checking each parent type against
16609 -- Suspension_Object.
16611 Cur_Typ := Base_Type (Typ);
16612 while Present (Cur_Typ) loop
16613 Par_Typ := Etype (Cur_Typ);
16615 -- The current type is a match
16617 if Is_RTE (Cur_Typ, RE_Suspension_Object) then
16618 return True;
16620 -- Stop the traversal once the root of the derivation chain has been
16621 -- reached. In that case the current type is its own base type.
16623 elsif Cur_Typ = Par_Typ then
16624 exit;
16625 end if;
16627 Cur_Typ := Base_Type (Par_Typ);
16628 end loop;
16630 return False;
16631 end Is_Descendant_Of_Suspension_Object;
16633 ---------------------------------------------
16634 -- Is_Double_Precision_Floating_Point_Type --
16635 ---------------------------------------------
16637 function Is_Double_Precision_Floating_Point_Type
16638 (E : Entity_Id) return Boolean is
16639 begin
16640 return Is_Floating_Point_Type (E)
16641 and then Machine_Radix_Value (E) = Uint_2
16642 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
16643 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
16644 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
16645 end Is_Double_Precision_Floating_Point_Type;
16647 -----------------------------
16648 -- Is_Effectively_Volatile --
16649 -----------------------------
16651 function Is_Effectively_Volatile
16652 (Id : Entity_Id;
16653 Ignore_Protected : Boolean := False) return Boolean is
16654 begin
16655 if Is_Type (Id) then
16657 -- An arbitrary type is effectively volatile when it is subject to
16658 -- pragma Atomic or Volatile, unless No_Caching is enabled.
16660 if Is_Volatile (Id)
16661 and then not No_Caching_Enabled (Id)
16662 then
16663 return True;
16665 -- An array type is effectively volatile when it is subject to pragma
16666 -- Atomic_Components or Volatile_Components or its component type is
16667 -- effectively volatile.
16669 elsif Is_Array_Type (Id) then
16670 if Has_Volatile_Components (Id) then
16671 return True;
16672 else
16673 declare
16674 Anc : Entity_Id := Base_Type (Id);
16675 begin
16676 if Is_Private_Type (Anc) then
16677 Anc := Full_View (Anc);
16678 end if;
16680 -- Test for presence of ancestor, as the full view of a
16681 -- private type may be missing in case of error.
16683 return Present (Anc)
16684 and then Is_Effectively_Volatile
16685 (Component_Type (Anc), Ignore_Protected);
16686 end;
16687 end if;
16689 -- A protected type is always volatile unless Ignore_Protected is
16690 -- True.
16692 elsif Is_Protected_Type (Id) and then not Ignore_Protected then
16693 return True;
16695 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
16696 -- automatically volatile.
16698 elsif Is_Descendant_Of_Suspension_Object (Id) then
16699 return True;
16701 -- Otherwise the type is not effectively volatile
16703 else
16704 return False;
16705 end if;
16707 -- Otherwise Id denotes an object
16709 else pragma Assert (Is_Object (Id));
16710 -- A volatile object for which No_Caching is enabled is not
16711 -- effectively volatile.
16713 return
16714 (Is_Volatile (Id)
16715 and then not
16716 (Ekind (Id) = E_Variable and then No_Caching_Enabled (Id)))
16717 or else Has_Volatile_Components (Id)
16718 or else Is_Effectively_Volatile (Etype (Id), Ignore_Protected);
16719 end if;
16720 end Is_Effectively_Volatile;
16722 -----------------------------------------
16723 -- Is_Effectively_Volatile_For_Reading --
16724 -----------------------------------------
16726 function Is_Effectively_Volatile_For_Reading
16727 (Id : Entity_Id;
16728 Ignore_Protected : Boolean := False) return Boolean
16730 begin
16731 -- A concurrent type is effectively volatile for reading, except for a
16732 -- protected type when Ignore_Protected is True.
16734 if Is_Task_Type (Id)
16735 or else (Is_Protected_Type (Id) and then not Ignore_Protected)
16736 then
16737 return True;
16739 elsif Is_Effectively_Volatile (Id, Ignore_Protected) then
16741 -- Other volatile types and objects are effectively volatile for
16742 -- reading when they have property Async_Writers or Effective_Reads
16743 -- set to True. This includes the case of an array type whose
16744 -- Volatile_Components aspect is True (hence it is effectively
16745 -- volatile) which does not have the properties Async_Writers
16746 -- and Effective_Reads set to False.
16748 if Async_Writers_Enabled (Id)
16749 or else Effective_Reads_Enabled (Id)
16750 then
16751 return True;
16753 -- In addition, an array type is effectively volatile for reading
16754 -- when its component type is effectively volatile for reading.
16756 elsif Is_Array_Type (Id) then
16757 declare
16758 Anc : Entity_Id := Base_Type (Id);
16759 begin
16760 if Is_Private_Type (Anc) then
16761 Anc := Full_View (Anc);
16762 end if;
16764 -- Test for presence of ancestor, as the full view of a
16765 -- private type may be missing in case of error.
16767 return Present (Anc)
16768 and then Is_Effectively_Volatile_For_Reading
16769 (Component_Type (Anc), Ignore_Protected);
16770 end;
16771 end if;
16772 end if;
16774 return False;
16776 end Is_Effectively_Volatile_For_Reading;
16778 ------------------------------------
16779 -- Is_Effectively_Volatile_Object --
16780 ------------------------------------
16782 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
16783 function Is_Effectively_Volatile (E : Entity_Id) return Boolean is
16784 (Is_Effectively_Volatile (E, Ignore_Protected => False));
16786 function Is_Effectively_Volatile_Object_Inst
16787 is new Is_Effectively_Volatile_Object_Shared (Is_Effectively_Volatile);
16788 begin
16789 return Is_Effectively_Volatile_Object_Inst (N);
16790 end Is_Effectively_Volatile_Object;
16792 ------------------------------------------------
16793 -- Is_Effectively_Volatile_Object_For_Reading --
16794 ------------------------------------------------
16796 function Is_Effectively_Volatile_Object_For_Reading
16797 (N : Node_Id) return Boolean
16799 function Is_Effectively_Volatile_For_Reading
16800 (E : Entity_Id) return Boolean
16801 is (Is_Effectively_Volatile_For_Reading (E, Ignore_Protected => False));
16803 function Is_Effectively_Volatile_Object_For_Reading_Inst
16804 is new Is_Effectively_Volatile_Object_Shared
16805 (Is_Effectively_Volatile_For_Reading);
16806 begin
16807 return Is_Effectively_Volatile_Object_For_Reading_Inst (N);
16808 end Is_Effectively_Volatile_Object_For_Reading;
16810 -------------------------------------------
16811 -- Is_Effectively_Volatile_Object_Shared --
16812 -------------------------------------------
16814 function Is_Effectively_Volatile_Object_Shared
16815 (N : Node_Id) return Boolean
16817 begin
16818 if Is_Entity_Name (N) then
16819 return Is_Object (Entity (N))
16820 and then Is_Effectively_Volatile_Entity (Entity (N));
16822 elsif Nkind (N) in N_Indexed_Component | N_Slice then
16823 return Is_Effectively_Volatile_Object_Shared (Prefix (N));
16825 elsif Nkind (N) = N_Selected_Component then
16826 return
16827 Is_Effectively_Volatile_Object_Shared (Prefix (N))
16828 or else
16829 Is_Effectively_Volatile_Object_Shared (Selector_Name (N));
16831 elsif Nkind (N) in N_Qualified_Expression
16832 | N_Unchecked_Type_Conversion
16833 | N_Type_Conversion
16834 then
16835 return Is_Effectively_Volatile_Object_Shared (Expression (N));
16837 else
16838 return False;
16839 end if;
16840 end Is_Effectively_Volatile_Object_Shared;
16842 ----------------------------------------
16843 -- Is_Entity_Of_Quantified_Expression --
16844 ----------------------------------------
16846 function Is_Entity_Of_Quantified_Expression (Id : Entity_Id) return Boolean
16848 Par : constant Node_Id := Parent (Id);
16850 begin
16851 return (Nkind (Par) = N_Loop_Parameter_Specification
16852 or else Nkind (Par) = N_Iterator_Specification)
16853 and then Defining_Identifier (Par) = Id
16854 and then Nkind (Parent (Par)) = N_Quantified_Expression;
16855 end Is_Entity_Of_Quantified_Expression;
16857 -------------------
16858 -- Is_Entry_Body --
16859 -------------------
16861 function Is_Entry_Body (Id : Entity_Id) return Boolean is
16862 begin
16863 return
16864 Is_Entry (Id)
16865 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
16866 end Is_Entry_Body;
16868 --------------------------
16869 -- Is_Entry_Declaration --
16870 --------------------------
16872 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
16873 begin
16874 return
16875 Is_Entry (Id)
16876 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
16877 end Is_Entry_Declaration;
16879 ------------------------------------
16880 -- Is_Expanded_Priority_Attribute --
16881 ------------------------------------
16883 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
16884 begin
16885 return
16886 Nkind (E) = N_Function_Call
16887 and then not Configurable_Run_Time_Mode
16888 and then Nkind (Original_Node (E)) = N_Attribute_Reference
16889 and then (Is_RTE (Entity (Name (E)), RE_Get_Ceiling)
16890 or else Is_RTE (Entity (Name (E)), RO_PE_Get_Ceiling));
16891 end Is_Expanded_Priority_Attribute;
16893 ----------------------------
16894 -- Is_Expression_Function --
16895 ----------------------------
16897 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
16898 begin
16899 if Ekind (Subp) in E_Function | E_Subprogram_Body then
16900 return
16901 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
16902 N_Expression_Function;
16903 else
16904 return False;
16905 end if;
16906 end Is_Expression_Function;
16908 ------------------------------------------
16909 -- Is_Expression_Function_Or_Completion --
16910 ------------------------------------------
16912 function Is_Expression_Function_Or_Completion
16913 (Subp : Entity_Id) return Boolean
16915 Subp_Decl : Node_Id;
16917 begin
16918 if Ekind (Subp) = E_Function then
16919 Subp_Decl := Unit_Declaration_Node (Subp);
16921 -- The function declaration is either an expression function or is
16922 -- completed by an expression function body.
16924 return
16925 Is_Expression_Function (Subp)
16926 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
16927 and then Present (Corresponding_Body (Subp_Decl))
16928 and then Is_Expression_Function
16929 (Corresponding_Body (Subp_Decl)));
16931 elsif Ekind (Subp) = E_Subprogram_Body then
16932 return Is_Expression_Function (Subp);
16934 else
16935 return False;
16936 end if;
16937 end Is_Expression_Function_Or_Completion;
16939 -----------------------------------------------
16940 -- Is_Extended_Precision_Floating_Point_Type --
16941 -----------------------------------------------
16943 function Is_Extended_Precision_Floating_Point_Type
16944 (E : Entity_Id) return Boolean is
16945 begin
16946 return Is_Floating_Point_Type (E)
16947 and then Machine_Radix_Value (E) = Uint_2
16948 and then Machine_Mantissa_Value (E) = Uint_64
16949 and then Machine_Emax_Value (E) = Uint_2 ** Uint_14
16950 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_14);
16951 end Is_Extended_Precision_Floating_Point_Type;
16953 -----------------------
16954 -- Is_EVF_Expression --
16955 -----------------------
16957 function Is_EVF_Expression (N : Node_Id) return Boolean is
16958 Orig_N : constant Node_Id := Original_Node (N);
16959 Alt : Node_Id;
16960 Expr : Node_Id;
16961 Id : Entity_Id;
16963 begin
16964 -- Detect a reference to a formal parameter of a specific tagged type
16965 -- whose related subprogram is subject to pragma Expresions_Visible with
16966 -- value "False".
16968 if Is_Entity_Name (N) and then Present (Entity (N)) then
16969 Id := Entity (N);
16971 return
16972 Is_Formal (Id)
16973 and then Is_Specific_Tagged_Type (Etype (Id))
16974 and then Extensions_Visible_Status (Id) =
16975 Extensions_Visible_False;
16977 -- A case expression is an EVF expression when it contains at least one
16978 -- EVF dependent_expression. Note that a case expression may have been
16979 -- expanded, hence the use of Original_Node.
16981 elsif Nkind (Orig_N) = N_Case_Expression then
16982 Alt := First (Alternatives (Orig_N));
16983 while Present (Alt) loop
16984 if Is_EVF_Expression (Expression (Alt)) then
16985 return True;
16986 end if;
16988 Next (Alt);
16989 end loop;
16991 -- An if expression is an EVF expression when it contains at least one
16992 -- EVF dependent_expression. Note that an if expression may have been
16993 -- expanded, hence the use of Original_Node.
16995 elsif Nkind (Orig_N) = N_If_Expression then
16996 Expr := Next (First (Expressions (Orig_N)));
16997 while Present (Expr) loop
16998 if Is_EVF_Expression (Expr) then
16999 return True;
17000 end if;
17002 Next (Expr);
17003 end loop;
17005 -- A qualified expression or a type conversion is an EVF expression when
17006 -- its operand is an EVF expression.
17008 elsif Nkind (N) in N_Qualified_Expression
17009 | N_Unchecked_Type_Conversion
17010 | N_Type_Conversion
17011 then
17012 return Is_EVF_Expression (Expression (N));
17014 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
17015 -- their prefix denotes an EVF expression.
17017 elsif Nkind (N) = N_Attribute_Reference
17018 and then Attribute_Name (N) in Name_Loop_Entry
17019 | Name_Old
17020 | Name_Update
17021 then
17022 return Is_EVF_Expression (Prefix (N));
17023 end if;
17025 return False;
17026 end Is_EVF_Expression;
17028 --------------
17029 -- Is_False --
17030 --------------
17032 function Is_False (U : Opt_Ubool) return Boolean is
17033 begin
17034 return not Is_True (U);
17035 end Is_False;
17037 ---------------------------
17038 -- Is_Fixed_Model_Number --
17039 ---------------------------
17041 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
17042 S : constant Ureal := Small_Value (T);
17043 M : Urealp.Save_Mark;
17044 R : Boolean;
17046 begin
17047 M := Urealp.Mark;
17048 R := (U = UR_Trunc (U / S) * S);
17049 Urealp.Release (M);
17050 return R;
17051 end Is_Fixed_Model_Number;
17053 -----------------------------
17054 -- Is_Full_Access_Object --
17055 -----------------------------
17057 function Is_Full_Access_Object (N : Node_Id) return Boolean is
17058 begin
17059 return Is_Atomic_Object (N)
17060 or else Is_Volatile_Full_Access_Object_Ref (N);
17061 end Is_Full_Access_Object;
17063 -------------------------------
17064 -- Is_Fully_Initialized_Type --
17065 -------------------------------
17067 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
17068 begin
17069 -- Scalar types
17071 if Is_Scalar_Type (Typ) then
17073 -- A scalar type with an aspect Default_Value is fully initialized
17075 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
17076 -- of a scalar type, but we don't take that into account here, since
17077 -- we don't want these to affect warnings.
17079 return Has_Default_Aspect (Typ);
17081 elsif Is_Access_Type (Typ) then
17082 return True;
17084 elsif Is_Array_Type (Typ) then
17085 if Is_Fully_Initialized_Type (Component_Type (Typ))
17086 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
17087 then
17088 return True;
17089 end if;
17091 -- An interesting case, if we have a constrained type one of whose
17092 -- bounds is known to be null, then there are no elements to be
17093 -- initialized, so all the elements are initialized.
17095 if Is_Constrained (Typ) then
17096 declare
17097 Indx : Node_Id;
17098 Indx_Typ : Entity_Id;
17099 Lbd, Hbd : Node_Id;
17101 begin
17102 Indx := First_Index (Typ);
17103 while Present (Indx) loop
17104 if Etype (Indx) = Any_Type then
17105 return False;
17107 -- If index is a range, use directly
17109 elsif Nkind (Indx) = N_Range then
17110 Lbd := Low_Bound (Indx);
17111 Hbd := High_Bound (Indx);
17113 else
17114 Indx_Typ := Etype (Indx);
17116 if Is_Private_Type (Indx_Typ) then
17117 Indx_Typ := Full_View (Indx_Typ);
17118 end if;
17120 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
17121 return False;
17122 else
17123 Lbd := Type_Low_Bound (Indx_Typ);
17124 Hbd := Type_High_Bound (Indx_Typ);
17125 end if;
17126 end if;
17128 if Compile_Time_Known_Value (Lbd)
17129 and then
17130 Compile_Time_Known_Value (Hbd)
17131 then
17132 if Expr_Value (Hbd) < Expr_Value (Lbd) then
17133 return True;
17134 end if;
17135 end if;
17137 Next_Index (Indx);
17138 end loop;
17139 end;
17140 end if;
17142 -- If no null indexes, then type is not fully initialized
17144 return False;
17146 -- Record types
17148 elsif Is_Record_Type (Typ) then
17149 if Has_Defaulted_Discriminants (Typ)
17150 and then Is_Fully_Initialized_Variant (Typ)
17151 then
17152 return True;
17153 end if;
17155 -- We consider bounded string types to be fully initialized, because
17156 -- otherwise we get false alarms when the Data component is not
17157 -- default-initialized.
17159 if Is_Bounded_String (Typ) then
17160 return True;
17161 end if;
17163 -- Controlled records are considered to be fully initialized if
17164 -- there is a user defined Initialize routine. This may not be
17165 -- entirely correct, but as the spec notes, we are guessing here
17166 -- what is best from the point of view of issuing warnings.
17168 if Is_Controlled (Typ) then
17169 declare
17170 Utyp : constant Entity_Id := Underlying_Type (Typ);
17172 begin
17173 if Present (Utyp) then
17174 declare
17175 Init : constant Entity_Id :=
17176 (Find_Optional_Prim_Op
17177 (Utyp, Name_Initialize));
17179 begin
17180 if Present (Init)
17181 and then Comes_From_Source (Init)
17182 and then not In_Predefined_Unit (Init)
17183 then
17184 return True;
17186 elsif Has_Null_Extension (Typ)
17187 and then
17188 Is_Fully_Initialized_Type
17189 (Etype (Base_Type (Typ)))
17190 then
17191 return True;
17192 end if;
17193 end;
17194 end if;
17195 end;
17196 end if;
17198 -- Otherwise see if all record components are initialized
17200 declare
17201 Comp : Entity_Id;
17203 begin
17204 Comp := First_Component (Typ);
17205 while Present (Comp) loop
17206 if (No (Parent (Comp))
17207 or else No (Expression (Parent (Comp))))
17208 and then not Is_Fully_Initialized_Type (Etype (Comp))
17210 -- Special VM case for tag components, which need to be
17211 -- defined in this case, but are never initialized as VMs
17212 -- are using other dispatching mechanisms. Ignore this
17213 -- uninitialized case. Note that this applies both to the
17214 -- uTag entry and the main vtable pointer (CPP_Class case).
17216 and then (Tagged_Type_Expansion or else not Is_Tag (Comp))
17217 then
17218 return False;
17219 end if;
17221 Next_Component (Comp);
17222 end loop;
17223 end;
17225 -- No uninitialized components, so type is fully initialized.
17226 -- Note that this catches the case of no components as well.
17228 return True;
17230 elsif Is_Concurrent_Type (Typ) then
17231 return True;
17233 elsif Is_Private_Type (Typ) then
17234 declare
17235 U : constant Entity_Id := Underlying_Type (Typ);
17237 begin
17238 if No (U) then
17239 return False;
17240 else
17241 return Is_Fully_Initialized_Type (U);
17242 end if;
17243 end;
17245 else
17246 return False;
17247 end if;
17248 end Is_Fully_Initialized_Type;
17250 ----------------------------------
17251 -- Is_Fully_Initialized_Variant --
17252 ----------------------------------
17254 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
17255 Loc : constant Source_Ptr := Sloc (Typ);
17256 Constraints : constant List_Id := New_List;
17257 Components : constant Elist_Id := New_Elmt_List;
17258 Comp_Elmt : Elmt_Id;
17259 Comp_Id : Node_Id;
17260 Comp_List : Node_Id;
17261 Discr : Entity_Id;
17262 Discr_Val : Node_Id;
17264 Report_Errors : Boolean;
17265 pragma Warnings (Off, Report_Errors);
17267 begin
17268 if Serious_Errors_Detected > 0 then
17269 return False;
17270 end if;
17272 if Is_Record_Type (Typ)
17273 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
17274 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
17275 then
17276 Comp_List := Component_List (Type_Definition (Parent (Typ)));
17278 Discr := First_Discriminant (Typ);
17279 while Present (Discr) loop
17280 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
17281 Discr_Val := Expression (Parent (Discr));
17283 if Present (Discr_Val)
17284 and then Is_OK_Static_Expression (Discr_Val)
17285 then
17286 Append_To (Constraints,
17287 Make_Component_Association (Loc,
17288 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
17289 Expression => New_Copy (Discr_Val)));
17290 else
17291 return False;
17292 end if;
17293 else
17294 return False;
17295 end if;
17297 Next_Discriminant (Discr);
17298 end loop;
17300 Gather_Components
17301 (Typ => Typ,
17302 Comp_List => Comp_List,
17303 Governed_By => Constraints,
17304 Into => Components,
17305 Report_Errors => Report_Errors);
17307 -- Check that each component present is fully initialized
17309 Comp_Elmt := First_Elmt (Components);
17310 while Present (Comp_Elmt) loop
17311 Comp_Id := Node (Comp_Elmt);
17313 if Ekind (Comp_Id) = E_Component
17314 and then (No (Parent (Comp_Id))
17315 or else No (Expression (Parent (Comp_Id))))
17316 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
17317 then
17318 return False;
17319 end if;
17321 Next_Elmt (Comp_Elmt);
17322 end loop;
17324 return True;
17326 elsif Is_Private_Type (Typ) then
17327 declare
17328 U : constant Entity_Id := Underlying_Type (Typ);
17330 begin
17331 if No (U) then
17332 return False;
17333 else
17334 return Is_Fully_Initialized_Variant (U);
17335 end if;
17336 end;
17338 else
17339 return False;
17340 end if;
17341 end Is_Fully_Initialized_Variant;
17343 -----------------------------------
17344 -- Is_Function_With_Side_Effects --
17345 -----------------------------------
17347 function Is_Function_With_Side_Effects (Subp : Entity_Id) return Boolean is
17348 Arg : Node_Id;
17349 Expr : Node_Id;
17350 Prag : constant Node_Id := Get_Pragma (Subp, Pragma_Side_Effects);
17352 begin
17353 -- Extract the value from the Boolean expression (if any)
17355 if Present (Prag) then
17356 Arg := First (Pragma_Argument_Associations (Prag));
17358 if Present (Arg) then
17359 Expr := Get_Pragma_Arg (Arg);
17361 return Is_True (Expr_Value (Expr));
17363 -- Otherwise the aspect or pragma defaults to True
17365 else
17366 return True;
17367 end if;
17368 end if;
17370 return False;
17371 end Is_Function_With_Side_Effects;
17373 ------------------------------------
17374 -- Is_Generic_Declaration_Or_Body --
17375 ------------------------------------
17377 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
17378 Spec_Decl : Node_Id;
17380 begin
17381 -- Package/subprogram body
17383 if Nkind (Decl) in N_Package_Body | N_Subprogram_Body
17384 and then Present (Corresponding_Spec (Decl))
17385 then
17386 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
17388 -- Package/subprogram body stub
17390 elsif Nkind (Decl) in N_Package_Body_Stub | N_Subprogram_Body_Stub
17391 and then Present (Corresponding_Spec_Of_Stub (Decl))
17392 then
17393 Spec_Decl :=
17394 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
17396 -- All other cases
17398 else
17399 Spec_Decl := Decl;
17400 end if;
17402 -- Rather than inspecting the defining entity of the spec declaration,
17403 -- look at its Nkind. This takes care of the case where the analysis of
17404 -- a generic body modifies the Ekind of its spec to allow for recursive
17405 -- calls.
17407 return Nkind (Spec_Decl) in N_Generic_Declaration;
17408 end Is_Generic_Declaration_Or_Body;
17410 ---------------------------
17411 -- Is_Independent_Object --
17412 ---------------------------
17414 function Is_Independent_Object (N : Node_Id) return Boolean is
17415 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean;
17416 -- Determine whether arbitrary entity Id denotes an object that is
17417 -- Independent.
17419 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean;
17420 -- Determine whether prefix P has independent components. This requires
17421 -- the presence of an Independent_Components aspect/pragma.
17423 ------------------------------------
17424 -- Is_Independent_Object_Entity --
17425 ------------------------------------
17427 function Is_Independent_Object_Entity (Id : Entity_Id) return Boolean is
17428 begin
17429 return
17430 Is_Object (Id)
17431 and then (Is_Independent (Id)
17432 or else
17433 Is_Independent (Etype (Id)));
17434 end Is_Independent_Object_Entity;
17436 -------------------------------------
17437 -- Prefix_Has_Independent_Components --
17438 -------------------------------------
17440 function Prefix_Has_Independent_Components (P : Node_Id) return Boolean
17442 Typ : constant Entity_Id := Etype (P);
17444 begin
17445 if Is_Access_Type (Typ) then
17446 return Has_Independent_Components (Designated_Type (Typ));
17448 elsif Has_Independent_Components (Typ) then
17449 return True;
17451 elsif Is_Entity_Name (P)
17452 and then Has_Independent_Components (Entity (P))
17453 then
17454 return True;
17456 else
17457 return False;
17458 end if;
17459 end Prefix_Has_Independent_Components;
17461 -- Start of processing for Is_Independent_Object
17463 begin
17464 if Is_Entity_Name (N) then
17465 return Is_Independent_Object_Entity (Entity (N));
17467 elsif Is_Independent (Etype (N)) then
17468 return True;
17470 elsif Nkind (N) = N_Indexed_Component then
17471 return Prefix_Has_Independent_Components (Prefix (N));
17473 elsif Nkind (N) = N_Selected_Component then
17474 return Prefix_Has_Independent_Components (Prefix (N))
17475 or else Is_Independent (Entity (Selector_Name (N)));
17477 else
17478 return False;
17479 end if;
17480 end Is_Independent_Object;
17482 ----------------------------
17483 -- Is_Inherited_Operation --
17484 ----------------------------
17486 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
17487 pragma Assert (Is_Overloadable (E));
17488 Kind : constant Node_Kind := Nkind (Parent (E));
17489 begin
17490 return Kind = N_Full_Type_Declaration
17491 or else Kind = N_Private_Extension_Declaration
17492 or else Kind = N_Subtype_Declaration
17493 or else (Ekind (E) = E_Enumeration_Literal
17494 and then Is_Derived_Type (Etype (E)));
17495 end Is_Inherited_Operation;
17497 --------------------------------------
17498 -- Is_Inlinable_Expression_Function --
17499 --------------------------------------
17501 function Is_Inlinable_Expression_Function
17502 (Subp : Entity_Id) return Boolean
17504 Return_Expr : Node_Id;
17506 begin
17507 if Is_Expression_Function_Or_Completion (Subp)
17508 and then Has_Pragma_Inline_Always (Subp)
17509 and then Needs_No_Actuals (Subp)
17510 and then No (Contract (Subp))
17511 and then not Is_Dispatching_Operation (Subp)
17512 and then Needs_Finalization (Etype (Subp))
17513 and then not Is_Class_Wide_Type (Etype (Subp))
17514 and then not Has_Invariants (Etype (Subp))
17515 and then Present (Subprogram_Body (Subp))
17516 and then Was_Expression_Function (Subprogram_Body (Subp))
17517 then
17518 Return_Expr := Expression_Of_Expression_Function (Subp);
17520 -- The returned object must not have a qualified expression and its
17521 -- nominal subtype must be statically compatible with the result
17522 -- subtype of the expression function.
17524 return
17525 Nkind (Return_Expr) = N_Identifier
17526 and then Etype (Return_Expr) = Etype (Subp);
17527 end if;
17529 return False;
17530 end Is_Inlinable_Expression_Function;
17532 -----------------------
17533 -- Is_Internal_Block --
17534 -----------------------
17536 function Is_Internal_Block (N : Node_Id) return Boolean is
17537 begin
17538 return Nkind (N) = N_Block_Statement
17539 and then Is_Internal (Entity (Identifier (N)));
17540 end Is_Internal_Block;
17542 -----------------
17543 -- Is_Iterator --
17544 -----------------
17546 function Is_Iterator (Typ : Entity_Id) return Boolean is
17547 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
17548 -- Determine whether type Iter_Typ is a predefined forward or reversible
17549 -- iterator.
17551 ----------------------
17552 -- Denotes_Iterator --
17553 ----------------------
17555 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
17556 begin
17557 -- Check that the name matches, and that the ultimate ancestor is in
17558 -- a predefined unit, i.e the one that declares iterator interfaces.
17560 return
17561 Chars (Iter_Typ) in Name_Forward_Iterator | Name_Reversible_Iterator
17562 and then In_Predefined_Unit (Root_Type (Iter_Typ));
17563 end Denotes_Iterator;
17565 -- Local variables
17567 Iface_Elmt : Elmt_Id;
17568 Ifaces : Elist_Id;
17570 -- Start of processing for Is_Iterator
17572 begin
17573 -- The type may be a subtype of a descendant of the proper instance of
17574 -- the predefined interface type, so we must use the root type of the
17575 -- given type. The same is done for Is_Reversible_Iterator.
17577 if Is_Class_Wide_Type (Typ)
17578 and then Denotes_Iterator (Root_Type (Typ))
17579 then
17580 return True;
17582 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17583 return False;
17585 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
17586 return True;
17588 else
17589 Collect_Interfaces (Typ, Ifaces);
17591 Iface_Elmt := First_Elmt (Ifaces);
17592 while Present (Iface_Elmt) loop
17593 if Denotes_Iterator (Node (Iface_Elmt)) then
17594 return True;
17595 end if;
17597 Next_Elmt (Iface_Elmt);
17598 end loop;
17600 return False;
17601 end if;
17602 end Is_Iterator;
17604 ----------------------------
17605 -- Is_Iterator_Over_Array --
17606 ----------------------------
17608 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
17609 Container : constant Node_Id := Name (N);
17610 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
17611 begin
17612 return Is_Array_Type (Container_Typ);
17613 end Is_Iterator_Over_Array;
17615 --------------------------
17616 -- Known_To_Be_Assigned --
17617 --------------------------
17619 function Known_To_Be_Assigned
17620 (N : Node_Id;
17621 Only_LHS : Boolean := False) return Boolean
17623 function Known_Assn (N : Node_Id) return Boolean is
17624 (Known_To_Be_Assigned (N, Only_LHS));
17625 -- Local function to simplify the passing of parameters for recursive
17626 -- calls.
17628 P : constant Node_Id := Parent (N);
17629 Form : Entity_Id := Empty;
17630 Call : Node_Id := Empty;
17632 -- Start of processing for Known_To_Be_Assigned
17634 begin
17635 -- Check for out parameters
17637 Find_Actual (N, Form, Call);
17639 if Present (Form) then
17640 return Ekind (Form) /= E_In_Parameter and then not Only_LHS;
17641 end if;
17643 -- Otherwise look at the parent
17645 case Nkind (P) is
17647 -- Test left side of assignment
17649 when N_Assignment_Statement =>
17650 return N = Name (P);
17652 -- Test prefix of component or attribute. Note that the prefix of an
17653 -- explicit or implicit dereference cannot be an l-value. In the case
17654 -- of a 'Read attribute, the reference can be an actual in the
17655 -- argument list of the attribute.
17657 when N_Attribute_Reference =>
17658 return
17659 not Only_LHS and then
17660 ((N = Prefix (P)
17661 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
17662 or else
17663 Attribute_Name (P) = Name_Read);
17665 -- For an expanded name, the name is an lvalue if the expanded name
17666 -- is an lvalue, but the prefix is never an lvalue, since it is just
17667 -- the scope where the name is found.
17669 when N_Expanded_Name =>
17670 if N = Prefix (P) then
17671 return Known_Assn (P);
17672 else
17673 return False;
17674 end if;
17676 -- For a selected component A.B, A is certainly an lvalue if A.B is.
17677 -- B is a little interesting, if we have A.B := 3, there is some
17678 -- discussion as to whether B is an lvalue or not, we choose to say
17679 -- it is. Note however that A is not an lvalue if it is of an access
17680 -- type since this is an implicit dereference.
17682 when N_Selected_Component =>
17683 if N = Prefix (P)
17684 and then Present (Etype (N))
17685 and then Is_Access_Type (Etype (N))
17686 then
17687 return False;
17688 else
17689 return Known_Assn (P);
17690 end if;
17692 -- For an indexed component or slice, the index or slice bounds is
17693 -- never an lvalue. The prefix is an lvalue if the indexed component
17694 -- or slice is an lvalue, except if it is an access type, where we
17695 -- have an implicit dereference.
17697 when N_Indexed_Component | N_Slice =>
17698 if N /= Prefix (P)
17699 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
17700 then
17701 return False;
17702 else
17703 return Known_Assn (P);
17704 end if;
17706 -- Prefix of a reference is an lvalue if the reference is an lvalue
17708 when N_Reference =>
17709 return Known_Assn (P);
17711 -- Prefix of explicit dereference is never an lvalue
17713 when N_Explicit_Dereference =>
17714 return False;
17716 -- Test for appearing in a conversion that itself appears in an
17717 -- lvalue context, since this should be an lvalue.
17719 when N_Type_Conversion =>
17720 return Known_Assn (P);
17722 -- Test for appearance in object renaming declaration
17724 when N_Object_Renaming_Declaration =>
17725 return not Only_LHS;
17727 -- All other references are definitely not lvalues
17729 when others =>
17730 return False;
17731 end case;
17732 end Known_To_Be_Assigned;
17734 -----------------------------
17735 -- Is_Library_Level_Entity --
17736 -----------------------------
17738 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
17739 begin
17740 -- The following is a small optimization, and it also properly handles
17741 -- discriminals, which in task bodies might appear in expressions before
17742 -- the corresponding procedure has been created, and which therefore do
17743 -- not have an assigned scope.
17745 if Is_Formal (E) then
17746 return False;
17748 -- If we somehow got an empty value for Scope, the tree must be
17749 -- malformed. Rather than blow up we return True in this case.
17751 elsif No (Scope (E)) then
17752 return True;
17754 -- Handle loops since Enclosing_Dynamic_Scope skips them; required to
17755 -- properly handle entities local to quantified expressions in library
17756 -- level specifications.
17758 elsif Ekind (Scope (E)) = E_Loop then
17759 return False;
17760 end if;
17762 -- Normal test is simply that the enclosing dynamic scope is Standard
17764 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
17765 end Is_Library_Level_Entity;
17767 --------------------------------
17768 -- Is_Limited_Class_Wide_Type --
17769 --------------------------------
17771 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
17772 begin
17773 return
17774 Is_Class_Wide_Type (Typ)
17775 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
17776 end Is_Limited_Class_Wide_Type;
17778 ---------------------------------
17779 -- Is_Local_Variable_Reference --
17780 ---------------------------------
17782 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
17783 begin
17784 if not Is_Entity_Name (Expr) then
17785 return False;
17787 else
17788 declare
17789 Ent : constant Entity_Id := Entity (Expr);
17790 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
17791 begin
17792 if Ekind (Ent)
17793 not in E_Variable | E_In_Out_Parameter | E_Out_Parameter
17794 then
17795 return False;
17796 else
17797 return Present (Sub) and then Sub = Current_Subprogram;
17798 end if;
17799 end;
17800 end if;
17801 end Is_Local_Variable_Reference;
17803 ---------------
17804 -- Is_Master --
17805 ---------------
17807 function Is_Master (N : Node_Id) return Boolean is
17808 Disable_Subexpression_Masters : constant Boolean := True;
17810 begin
17811 if Nkind (N) in N_Subprogram_Body | N_Task_Body | N_Entry_Body
17812 or else Is_Statement (N)
17813 then
17814 return True;
17815 end if;
17817 -- We avoid returning True when the master is a subexpression described
17818 -- in RM 7.6.1(3/2) for the proposes of accessibility level calculation
17819 -- in Accessibility_Level_Helper.Innermost_Master_Scope_Depth ???
17821 if not Disable_Subexpression_Masters
17822 and then Nkind (N) in N_Subexpr
17823 then
17824 declare
17825 Par : Node_Id := N;
17827 subtype N_Simple_Statement_Other_Than_Simple_Return
17828 is Node_Kind with Static_Predicate =>
17829 N_Simple_Statement_Other_Than_Simple_Return
17830 in N_Abort_Statement
17831 | N_Assignment_Statement
17832 | N_Code_Statement
17833 | N_Delay_Statement
17834 | N_Entry_Call_Statement
17835 | N_Free_Statement
17836 | N_Goto_Statement
17837 | N_Null_Statement
17838 | N_Raise_Statement
17839 | N_Requeue_Statement
17840 | N_Exit_Statement
17841 | N_Procedure_Call_Statement;
17842 begin
17843 while Present (Par) loop
17844 Par := Parent (Par);
17845 if Nkind (Par) in N_Subexpr |
17846 N_Simple_Statement_Other_Than_Simple_Return
17847 then
17848 return False;
17849 end if;
17850 end loop;
17852 return True;
17853 end;
17854 end if;
17856 return False;
17857 end Is_Master;
17859 -----------------------
17860 -- Is_Name_Reference --
17861 -----------------------
17863 function Is_Name_Reference (N : Node_Id) return Boolean is
17864 begin
17865 if Is_Entity_Name (N) then
17866 return Present (Entity (N)) and then Is_Object (Entity (N));
17867 end if;
17869 case Nkind (N) is
17870 when N_Indexed_Component
17871 | N_Slice
17873 return
17874 Is_Name_Reference (Prefix (N))
17875 or else Is_Access_Type (Etype (Prefix (N)));
17877 -- Attributes 'Input, 'Old and 'Result produce objects
17879 when N_Attribute_Reference =>
17880 return Attribute_Name (N) in Name_Input | Name_Old | Name_Result;
17882 when N_Selected_Component =>
17883 return
17884 Is_Name_Reference (Selector_Name (N))
17885 and then
17886 (Is_Name_Reference (Prefix (N))
17887 or else Is_Access_Type (Etype (Prefix (N))));
17889 when N_Explicit_Dereference =>
17890 return True;
17892 -- A view conversion of a tagged name is a name reference
17894 when N_Type_Conversion =>
17895 return
17896 Is_Tagged_Type (Etype (Subtype_Mark (N)))
17897 and then Is_Tagged_Type (Etype (Expression (N)))
17898 and then Is_Name_Reference (Expression (N));
17900 -- An unchecked type conversion is considered to be a name if the
17901 -- operand is a name (this construction arises only as a result of
17902 -- expansion activities).
17904 when N_Unchecked_Type_Conversion =>
17905 return Is_Name_Reference (Expression (N));
17907 when others =>
17908 return False;
17909 end case;
17910 end Is_Name_Reference;
17912 --------------------------
17913 -- Is_Newly_Constructed --
17914 --------------------------
17916 function Is_Newly_Constructed
17917 (Exp : Node_Id; Context_Requires_NC : Boolean) return Boolean
17919 Original_Exp : constant Node_Id := Original_Node (Exp);
17921 function Is_NC (Exp : Node_Id) return Boolean is
17922 (Is_Newly_Constructed (Exp, Context_Requires_NC));
17924 -- If the context requires that the expression shall be newly
17925 -- constructed, then "True" is a good result in the sense that the
17926 -- expression satisfies the requirements of the context (and "False"
17927 -- is analogously a bad result). If the context requires that the
17928 -- expression shall *not* be newly constructed, then things are
17929 -- reversed: "False" is the good value and "True" is the bad value.
17931 Good_Result : constant Boolean := Context_Requires_NC;
17932 Bad_Result : constant Boolean := not Good_Result;
17933 begin
17934 case Nkind (Original_Exp) is
17935 when N_Aggregate
17936 | N_Extension_Aggregate
17937 | N_Function_Call
17938 | N_Op
17940 return True;
17942 when N_Identifier =>
17943 return Present (Entity (Original_Exp))
17944 and then Ekind (Entity (Original_Exp)) = E_Function;
17946 when N_Qualified_Expression =>
17947 return Is_NC (Expression (Original_Exp));
17949 when N_Type_Conversion
17950 | N_Unchecked_Type_Conversion
17952 if Is_View_Conversion (Original_Exp) then
17953 return Is_NC (Expression (Original_Exp));
17954 elsif not Comes_From_Source (Exp) then
17955 if Exp /= Original_Exp then
17956 return Is_NC (Original_Exp);
17957 else
17958 return Is_NC (Expression (Original_Exp));
17959 end if;
17960 else
17961 return False;
17962 end if;
17964 when N_Explicit_Dereference
17965 | N_Indexed_Component
17966 | N_Selected_Component
17968 return Nkind (Exp) = N_Function_Call;
17970 -- A use of 'Input is a function call, hence allowed. Normally the
17971 -- attribute will be changed to a call, but the attribute by itself
17972 -- can occur with -gnatc.
17974 when N_Attribute_Reference =>
17975 return Attribute_Name (Original_Exp) = Name_Input;
17977 -- "return raise ..." is OK
17979 when N_Raise_Expression =>
17980 return Good_Result;
17982 -- For a case expression, all dependent expressions must be legal
17984 when N_Case_Expression =>
17985 declare
17986 Alt : Node_Id;
17988 begin
17989 Alt := First (Alternatives (Original_Exp));
17990 while Present (Alt) loop
17991 if Is_NC (Expression (Alt)) = Bad_Result then
17992 return Bad_Result;
17993 end if;
17995 Next (Alt);
17996 end loop;
17998 return Good_Result;
17999 end;
18001 -- For an if expression, all dependent expressions must be legal
18003 when N_If_Expression =>
18004 declare
18005 Then_Expr : constant Node_Id :=
18006 Next (First (Expressions (Original_Exp)));
18007 Else_Expr : constant Node_Id := Next (Then_Expr);
18008 begin
18009 if Is_NC (Then_Expr) = Bad_Result
18010 or else Is_NC (Else_Expr) = Bad_Result
18011 then
18012 return Bad_Result;
18013 else
18014 return Good_Result;
18015 end if;
18016 end;
18018 when others =>
18019 return False;
18020 end case;
18021 end Is_Newly_Constructed;
18023 ------------------------------------
18024 -- Is_Non_Preelaborable_Construct --
18025 ------------------------------------
18027 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
18029 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
18030 -- intentionally unnested to avoid deep indentation of code.
18032 Non_Preelaborable : exception;
18033 -- This exception is raised when the construct violates preelaborability
18034 -- to terminate the recursion.
18036 procedure Visit (Nod : Node_Id);
18037 -- Semantically inspect construct Nod to determine whether it violates
18038 -- preelaborability. This routine raises Non_Preelaborable.
18040 procedure Visit_List (List : List_Id);
18041 pragma Inline (Visit_List);
18042 -- Invoke Visit on each element of list List. This routine raises
18043 -- Non_Preelaborable.
18045 procedure Visit_Pragma (Prag : Node_Id);
18046 pragma Inline (Visit_Pragma);
18047 -- Semantically inspect pragma Prag to determine whether it violates
18048 -- preelaborability. This routine raises Non_Preelaborable.
18050 procedure Visit_Subexpression (Expr : Node_Id);
18051 pragma Inline (Visit_Subexpression);
18052 -- Semantically inspect expression Expr to determine whether it violates
18053 -- preelaborability. This routine raises Non_Preelaborable.
18055 -----------
18056 -- Visit --
18057 -----------
18059 procedure Visit (Nod : Node_Id) is
18060 begin
18061 case Nkind (Nod) is
18063 -- Declarations
18065 when N_Component_Declaration =>
18067 -- Defining_Identifier is left out because it is not relevant
18068 -- for preelaborability.
18070 Visit (Component_Definition (Nod));
18071 Visit (Expression (Nod));
18073 when N_Derived_Type_Definition =>
18075 -- Interface_List is left out because it is not relevant for
18076 -- preelaborability.
18078 Visit (Record_Extension_Part (Nod));
18079 Visit (Subtype_Indication (Nod));
18081 when N_Entry_Declaration =>
18083 -- A protected type with at leat one entry is not preelaborable
18084 -- while task types are never preelaborable. This renders entry
18085 -- declarations non-preelaborable.
18087 raise Non_Preelaborable;
18089 when N_Full_Type_Declaration =>
18091 -- Defining_Identifier and Discriminant_Specifications are left
18092 -- out because they are not relevant for preelaborability.
18094 Visit (Type_Definition (Nod));
18096 when N_Function_Instantiation
18097 | N_Package_Instantiation
18098 | N_Procedure_Instantiation
18100 -- Defining_Unit_Name and Name are left out because they are
18101 -- not relevant for preelaborability.
18103 Visit_List (Generic_Associations (Nod));
18105 when N_Object_Declaration =>
18107 -- Defining_Identifier is left out because it is not relevant
18108 -- for preelaborability.
18110 Visit (Object_Definition (Nod));
18112 if Has_Init_Expression (Nod) then
18113 Visit (Expression (Nod));
18115 elsif not Constant_Present (Nod)
18116 and then not Has_Preelaborable_Initialization
18117 (Etype (Defining_Entity (Nod)))
18118 then
18119 raise Non_Preelaborable;
18120 end if;
18122 when N_Private_Extension_Declaration
18123 | N_Subtype_Declaration
18125 -- Defining_Identifier, Discriminant_Specifications, and
18126 -- Interface_List are left out because they are not relevant
18127 -- for preelaborability.
18129 Visit (Subtype_Indication (Nod));
18131 when N_Protected_Type_Declaration
18132 | N_Single_Protected_Declaration
18134 -- Defining_Identifier, Discriminant_Specifications, and
18135 -- Interface_List are left out because they are not relevant
18136 -- for preelaborability.
18138 Visit (Protected_Definition (Nod));
18140 -- A [single] task type is never preelaborable
18142 when N_Single_Task_Declaration
18143 | N_Task_Type_Declaration
18145 raise Non_Preelaborable;
18147 -- Pragmas
18149 when N_Pragma =>
18150 Visit_Pragma (Nod);
18152 -- Statements
18154 when N_Statement_Other_Than_Procedure_Call =>
18155 if Nkind (Nod) /= N_Null_Statement then
18156 raise Non_Preelaborable;
18157 end if;
18159 -- Subexpressions
18161 when N_Subexpr =>
18162 Visit_Subexpression (Nod);
18164 -- Special
18166 when N_Access_To_Object_Definition =>
18167 Visit (Subtype_Indication (Nod));
18169 when N_Case_Expression_Alternative =>
18170 Visit (Expression (Nod));
18171 Visit_List (Discrete_Choices (Nod));
18173 when N_Component_Definition =>
18174 Visit (Access_Definition (Nod));
18175 Visit (Subtype_Indication (Nod));
18177 when N_Component_List =>
18178 Visit_List (Component_Items (Nod));
18179 Visit (Variant_Part (Nod));
18181 when N_Constrained_Array_Definition =>
18182 Visit_List (Discrete_Subtype_Definitions (Nod));
18183 Visit (Component_Definition (Nod));
18185 when N_Delta_Constraint
18186 | N_Digits_Constraint
18188 -- Delta_Expression and Digits_Expression are left out because
18189 -- they are not relevant for preelaborability.
18191 Visit (Range_Constraint (Nod));
18193 when N_Discriminant_Specification =>
18195 -- Defining_Identifier and Expression are left out because they
18196 -- are not relevant for preelaborability.
18198 Visit (Discriminant_Type (Nod));
18200 when N_Generic_Association =>
18202 -- Selector_Name is left out because it is not relevant for
18203 -- preelaborability.
18205 Visit (Explicit_Generic_Actual_Parameter (Nod));
18207 when N_Index_Or_Discriminant_Constraint =>
18208 Visit_List (Constraints (Nod));
18210 when N_Iterator_Specification =>
18212 -- Defining_Identifier is left out because it is not relevant
18213 -- for preelaborability.
18215 Visit (Name (Nod));
18216 Visit (Subtype_Indication (Nod));
18218 when N_Loop_Parameter_Specification =>
18220 -- Defining_Identifier is left out because it is not relevant
18221 -- for preelaborability.
18223 Visit (Discrete_Subtype_Definition (Nod));
18225 when N_Parameter_Association =>
18226 Visit (Explicit_Actual_Parameter (N));
18228 when N_Protected_Definition =>
18230 -- End_Label is left out because it is not relevant for
18231 -- preelaborability.
18233 Visit_List (Private_Declarations (Nod));
18234 Visit_List (Visible_Declarations (Nod));
18236 when N_Range_Constraint =>
18237 Visit (Range_Expression (Nod));
18239 when N_Record_Definition
18240 | N_Variant
18242 -- End_Label, Discrete_Choices, and Interface_List are left out
18243 -- because they are not relevant for preelaborability.
18245 Visit (Component_List (Nod));
18247 when N_Subtype_Indication =>
18249 -- Subtype_Mark is left out because it is not relevant for
18250 -- preelaborability.
18252 Visit (Constraint (Nod));
18254 when N_Unconstrained_Array_Definition =>
18256 -- Subtype_Marks is left out because it is not relevant for
18257 -- preelaborability.
18259 Visit (Component_Definition (Nod));
18261 when N_Variant_Part =>
18263 -- Name is left out because it is not relevant for
18264 -- preelaborability.
18266 Visit_List (Variants (Nod));
18268 -- Default
18270 when others =>
18271 null;
18272 end case;
18273 end Visit;
18275 ----------------
18276 -- Visit_List --
18277 ----------------
18279 procedure Visit_List (List : List_Id) is
18280 Nod : Node_Id;
18282 begin
18283 Nod := First (List);
18284 while Present (Nod) loop
18285 Visit (Nod);
18286 Next (Nod);
18287 end loop;
18288 end Visit_List;
18290 ------------------
18291 -- Visit_Pragma --
18292 ------------------
18294 procedure Visit_Pragma (Prag : Node_Id) is
18295 begin
18296 case Get_Pragma_Id (Prag) is
18297 when Pragma_Assert
18298 | Pragma_Assert_And_Cut
18299 | Pragma_Assume
18300 | Pragma_Async_Readers
18301 | Pragma_Async_Writers
18302 | Pragma_Attribute_Definition
18303 | Pragma_Check
18304 | Pragma_Constant_After_Elaboration
18305 | Pragma_CPU
18306 | Pragma_Deadline_Floor
18307 | Pragma_Dispatching_Domain
18308 | Pragma_Effective_Reads
18309 | Pragma_Effective_Writes
18310 | Pragma_Extensions_Visible
18311 | Pragma_Ghost
18312 | Pragma_Secondary_Stack_Size
18313 | Pragma_Task_Name
18314 | Pragma_Volatile_Function
18316 Visit_List (Pragma_Argument_Associations (Prag));
18318 -- Default
18320 when others =>
18321 null;
18322 end case;
18323 end Visit_Pragma;
18325 -------------------------
18326 -- Visit_Subexpression --
18327 -------------------------
18329 procedure Visit_Subexpression (Expr : Node_Id) is
18330 procedure Visit_Aggregate (Aggr : Node_Id);
18331 pragma Inline (Visit_Aggregate);
18332 -- Semantically inspect aggregate Aggr to determine whether it
18333 -- violates preelaborability.
18335 ---------------------
18336 -- Visit_Aggregate --
18337 ---------------------
18339 procedure Visit_Aggregate (Aggr : Node_Id) is
18340 begin
18341 if not Is_Preelaborable_Aggregate (Aggr) then
18342 raise Non_Preelaborable;
18343 end if;
18344 end Visit_Aggregate;
18346 -- Start of processing for Visit_Subexpression
18348 begin
18349 case Nkind (Expr) is
18350 when N_Allocator
18351 | N_Qualified_Expression
18352 | N_Type_Conversion
18353 | N_Unchecked_Expression
18354 | N_Unchecked_Type_Conversion
18356 -- Subpool_Handle_Name and Subtype_Mark are left out because
18357 -- they are not relevant for preelaborability.
18359 Visit (Expression (Expr));
18361 when N_Aggregate
18362 | N_Extension_Aggregate
18364 Visit_Aggregate (Expr);
18366 when N_Attribute_Reference
18367 | N_Explicit_Dereference
18368 | N_Reference
18370 -- Attribute_Name and Expressions are left out because they are
18371 -- not relevant for preelaborability.
18373 Visit (Prefix (Expr));
18375 when N_Case_Expression =>
18377 -- End_Span is left out because it is not relevant for
18378 -- preelaborability.
18380 Visit_List (Alternatives (Expr));
18381 Visit (Expression (Expr));
18383 when N_Delta_Aggregate =>
18384 Visit_Aggregate (Expr);
18385 Visit (Expression (Expr));
18387 when N_Expression_With_Actions =>
18388 Visit_List (Actions (Expr));
18389 Visit (Expression (Expr));
18391 when N_Function_Call =>
18393 -- Ada 2022 (AI12-0175): Calls to certain functions that are
18394 -- essentially unchecked conversions are preelaborable.
18396 if Ada_Version >= Ada_2022
18397 and then Nkind (Expr) = N_Function_Call
18398 and then Is_Entity_Name (Name (Expr))
18399 and then Is_Preelaborable_Function (Entity (Name (Expr)))
18400 then
18401 Visit_List (Parameter_Associations (Expr));
18402 else
18403 raise Non_Preelaborable;
18404 end if;
18406 when N_If_Expression =>
18407 Visit_List (Expressions (Expr));
18409 when N_Quantified_Expression =>
18410 Visit (Condition (Expr));
18411 Visit (Iterator_Specification (Expr));
18412 Visit (Loop_Parameter_Specification (Expr));
18414 when N_Range =>
18415 Visit (High_Bound (Expr));
18416 Visit (Low_Bound (Expr));
18418 when N_Slice =>
18419 Visit (Discrete_Range (Expr));
18420 Visit (Prefix (Expr));
18422 -- Default
18424 when others =>
18426 -- The evaluation of an object name is not preelaborable,
18427 -- unless the name is a static expression (checked further
18428 -- below), or statically denotes a discriminant.
18430 if Is_Entity_Name (Expr) then
18431 Object_Name : declare
18432 Id : constant Entity_Id := Entity (Expr);
18434 begin
18435 if Is_Object (Id) then
18436 if Ekind (Id) = E_Discriminant then
18437 null;
18439 elsif Ekind (Id) in E_Constant | E_In_Parameter
18440 and then Present (Discriminal_Link (Id))
18441 then
18442 null;
18444 else
18445 raise Non_Preelaborable;
18446 end if;
18447 end if;
18448 end Object_Name;
18450 -- A non-static expression is not preelaborable
18452 elsif not Is_OK_Static_Expression (Expr) then
18453 raise Non_Preelaborable;
18454 end if;
18455 end case;
18456 end Visit_Subexpression;
18458 -- Start of processing for Is_Non_Preelaborable_Construct
18460 begin
18461 Visit (N);
18463 -- At this point it is known that the construct is preelaborable
18465 return False;
18467 exception
18469 -- The elaboration of the construct performs an action which violates
18470 -- preelaborability.
18472 when Non_Preelaborable =>
18473 return True;
18474 end Is_Non_Preelaborable_Construct;
18476 ---------------------------------
18477 -- Is_Nontrivial_DIC_Procedure --
18478 ---------------------------------
18480 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
18481 Body_Decl : Node_Id;
18482 Stmt : Node_Id;
18484 begin
18485 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
18486 Body_Decl :=
18487 Unit_Declaration_Node
18488 (Corresponding_Body (Unit_Declaration_Node (Id)));
18490 -- The body of the Default_Initial_Condition procedure must contain
18491 -- at least one statement, otherwise the generation of the subprogram
18492 -- body failed.
18494 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
18496 -- To qualify as nontrivial, the first statement of the procedure
18497 -- must be a check in the form of an if statement. If the original
18498 -- Default_Initial_Condition expression was folded, then the first
18499 -- statement is not a check.
18501 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
18503 return
18504 Nkind (Stmt) = N_If_Statement
18505 and then Nkind (Original_Node (Stmt)) = N_Pragma;
18506 end if;
18508 return False;
18509 end Is_Nontrivial_DIC_Procedure;
18511 -----------------------
18512 -- Is_Null_Extension --
18513 -----------------------
18515 function Is_Null_Extension
18516 (T : Entity_Id; Ignore_Privacy : Boolean := False) return Boolean
18518 Type_Decl : Node_Id;
18519 Type_Def : Node_Id;
18520 begin
18521 pragma Assert (not Is_Class_Wide_Type (T));
18523 if Ignore_Privacy then
18524 Type_Decl := Parent (Underlying_Type (Base_Type (T)));
18525 else
18526 Type_Decl := Parent (Base_Type (T));
18527 if Nkind (Type_Decl) /= N_Full_Type_Declaration then
18528 return False;
18529 end if;
18530 end if;
18531 pragma Assert (Nkind (Type_Decl) = N_Full_Type_Declaration);
18532 Type_Def := Type_Definition (Type_Decl);
18533 if Present (Discriminant_Specifications (Type_Decl))
18534 or else Nkind (Type_Def) /= N_Derived_Type_Definition
18535 or else not Is_Tagged_Type (T)
18536 or else No (Record_Extension_Part (Type_Def))
18537 then
18538 return False;
18539 end if;
18541 return Is_Null_Record_Definition (Record_Extension_Part (Type_Def));
18542 end Is_Null_Extension;
18544 --------------------------
18545 -- Is_Null_Extension_Of --
18546 --------------------------
18548 function Is_Null_Extension_Of
18549 (Descendant, Ancestor : Entity_Id) return Boolean
18551 Ancestor_Type : constant Entity_Id
18552 := Underlying_Type (Base_Type (Ancestor));
18553 Descendant_Type : Entity_Id := Underlying_Type (Base_Type (Descendant));
18554 begin
18555 pragma Assert (not Is_Class_Wide_Type (Descendant));
18556 pragma Assert (not Is_Class_Wide_Type (Ancestor));
18557 pragma Assert (Descendant_Type /= Ancestor_Type);
18559 while Descendant_Type /= Ancestor_Type loop
18560 if not Is_Null_Extension
18561 (Descendant_Type, Ignore_Privacy => True)
18562 then
18563 return False;
18564 end if;
18565 Descendant_Type := Etype (Subtype_Indication
18566 (Type_Definition (Parent (Descendant_Type))));
18567 Descendant_Type := Underlying_Type (Base_Type (Descendant_Type));
18568 end loop;
18569 return True;
18570 end Is_Null_Extension_Of;
18572 -------------------------------
18573 -- Is_Null_Record_Definition --
18574 -------------------------------
18576 function Is_Null_Record_Definition (Record_Def : Node_Id) return Boolean is
18577 Item : Node_Id;
18578 begin
18579 -- Testing Null_Present is just an optimization, not required.
18581 if Null_Present (Record_Def) then
18582 return True;
18583 elsif Present (Variant_Part (Component_List (Record_Def))) then
18584 return False;
18585 elsif No (Component_List (Record_Def)) then
18586 return True;
18587 end if;
18589 Item := First_Non_Pragma (Component_Items (Component_List (Record_Def)));
18591 while Present (Item) loop
18592 if Nkind (Item) = N_Component_Declaration
18593 and then Is_Internal_Name (Chars (Defining_Identifier (Item)))
18594 then
18595 null;
18596 else
18597 return False;
18598 end if;
18599 Next_Non_Pragma (Item);
18600 end loop;
18602 return True;
18603 end Is_Null_Record_Definition;
18605 -------------------------
18606 -- Is_Null_Record_Type --
18607 -------------------------
18609 function Is_Null_Record_Type
18610 (T : Entity_Id; Ignore_Privacy : Boolean := False) return Boolean
18612 Decl : Node_Id;
18613 Type_Def : Node_Id;
18614 begin
18615 if not Is_Record_Type (T) then
18616 return False;
18617 end if;
18619 if Ignore_Privacy then
18620 Decl := Parent (Underlying_Type (Base_Type (T)));
18621 else
18622 Decl := Parent (Base_Type (T));
18623 if Nkind (Decl) /= N_Full_Type_Declaration then
18624 return False;
18625 end if;
18626 end if;
18627 pragma Assert (Nkind (Decl) = N_Full_Type_Declaration);
18628 Type_Def := Type_Definition (Decl);
18630 if Has_Discriminants (Defining_Identifier (Decl)) then
18631 return False;
18632 end if;
18634 case Nkind (Type_Def) is
18635 when N_Record_Definition =>
18636 return Is_Null_Record_Definition (Type_Def);
18637 when N_Derived_Type_Definition =>
18638 if not Is_Null_Record_Type
18639 (Etype (Subtype_Indication (Type_Def)),
18640 Ignore_Privacy => Ignore_Privacy)
18641 then
18642 return False;
18643 elsif not Is_Tagged_Type (T) then
18644 return True;
18645 else
18646 return Is_Null_Extension (T, Ignore_Privacy => Ignore_Privacy);
18647 end if;
18648 when others =>
18649 return False;
18650 end case;
18651 end Is_Null_Record_Type;
18653 ---------------------
18654 -- Is_Object_Image --
18655 ---------------------
18657 function Is_Object_Image (Prefix : Node_Id) return Boolean is
18658 begin
18659 -- Here we test for the case that the prefix is not a type and assume
18660 -- if it is not then it must be a named value or an object reference.
18661 -- This is because the parser always checks that prefixes of attributes
18662 -- are named.
18664 return not (Is_Entity_Name (Prefix)
18665 and then Is_Type (Entity (Prefix))
18666 and then not Is_Current_Instance (Prefix));
18667 end Is_Object_Image;
18669 -------------------------
18670 -- Is_Object_Reference --
18671 -------------------------
18673 function Is_Object_Reference (N : Node_Id) return Boolean is
18674 function Safe_Prefix (N : Node_Id) return Node_Id;
18675 -- Return Prefix (N) unless it has been rewritten as an
18676 -- N_Raise_xxx_Error node, in which case return its original node.
18678 -----------------
18679 -- Safe_Prefix --
18680 -----------------
18682 function Safe_Prefix (N : Node_Id) return Node_Id is
18683 begin
18684 if Nkind (Prefix (N)) in N_Raise_xxx_Error then
18685 return Original_Node (Prefix (N));
18686 else
18687 return Prefix (N);
18688 end if;
18689 end Safe_Prefix;
18691 begin
18692 -- AI12-0068: Note that a current instance reference in a type or
18693 -- subtype's aspect_specification is considered a value, not an object
18694 -- (see RM 8.6(18/5)).
18696 if Is_Entity_Name (N) then
18697 return Present (Entity (N)) and then Is_Object (Entity (N))
18698 and then not Is_Current_Instance_Reference_In_Type_Aspect (N);
18700 else
18701 case Nkind (N) is
18702 when N_Indexed_Component
18703 | N_Slice
18705 return
18706 Is_Object_Reference (Safe_Prefix (N))
18707 or else Is_Access_Type (Etype (Safe_Prefix (N)));
18709 -- In Ada 95, a function call is a constant object; a procedure
18710 -- call is not.
18712 -- Note that predefined operators are functions as well, and so
18713 -- are attributes that are (can be renamed as) functions.
18715 when N_Function_Call
18716 | N_Op
18718 return Etype (N) /= Standard_Void_Type;
18720 -- Attributes references 'Loop_Entry, 'Old, 'Priority and 'Result
18721 -- yield objects, even though they are not functions.
18723 when N_Attribute_Reference =>
18724 return
18725 Attribute_Name (N) in Name_Loop_Entry
18726 | Name_Old
18727 | Name_Priority
18728 | Name_Result
18729 or else Is_Function_Attribute_Name (Attribute_Name (N));
18731 when N_Selected_Component =>
18732 return
18733 Is_Object_Reference (Selector_Name (N))
18734 and then
18735 (Is_Object_Reference (Safe_Prefix (N))
18736 or else Is_Access_Type (Etype (Safe_Prefix (N))));
18738 -- An explicit dereference denotes an object, except that a
18739 -- conditional expression gets turned into an explicit dereference
18740 -- in some cases, and conditional expressions are not object
18741 -- names.
18743 when N_Explicit_Dereference =>
18744 return Nkind (Original_Node (N)) not in
18745 N_Case_Expression | N_If_Expression;
18747 -- A view conversion of a tagged object is an object reference
18749 when N_Type_Conversion =>
18750 if Ada_Version <= Ada_2012 then
18751 -- A view conversion of a tagged object is an object
18752 -- reference.
18753 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
18754 and then Is_Tagged_Type (Etype (Expression (N)))
18755 and then Is_Object_Reference (Expression (N));
18757 else
18758 -- AI12-0226: In Ada 2022 a value conversion of an object is
18759 -- an object.
18761 return Is_Object_Reference (Expression (N));
18762 end if;
18764 -- An unchecked type conversion is considered to be an object if
18765 -- the operand is an object (this construction arises only as a
18766 -- result of expansion activities).
18768 when N_Unchecked_Type_Conversion =>
18769 return True;
18771 -- AI05-0003: In Ada 2012 a qualified expression is a name.
18772 -- This allows disambiguation of function calls and the use
18773 -- of aggregates in more contexts.
18775 when N_Qualified_Expression =>
18776 return Ada_Version >= Ada_2012
18777 and then Is_Object_Reference (Expression (N));
18779 -- In Ada 95 an aggregate is an object reference
18781 when N_Aggregate
18782 | N_Delta_Aggregate
18783 | N_Extension_Aggregate
18785 return Ada_Version >= Ada_95;
18787 -- A string literal is not an object reference, but it might come
18788 -- from rewriting of an object reference, e.g. from folding of an
18789 -- aggregate.
18791 when N_String_Literal =>
18792 return Is_Rewrite_Substitution (N)
18793 and then Is_Object_Reference (Original_Node (N));
18795 -- AI12-0125: Target name represents a constant object
18797 when N_Target_Name =>
18798 return True;
18800 when others =>
18801 return False;
18802 end case;
18803 end if;
18804 end Is_Object_Reference;
18806 -----------------------------------
18807 -- Is_OK_Variable_For_Out_Formal --
18808 -----------------------------------
18810 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
18811 begin
18812 Note_Possible_Modification (AV, Sure => True);
18814 -- We must reject parenthesized variable names. Comes_From_Source is
18815 -- checked because there are currently cases where the compiler violates
18816 -- this rule (e.g. passing a task object to its controlled Initialize
18817 -- routine). This should be properly documented in sinfo???
18819 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
18820 return False;
18822 -- A variable is always allowed
18824 elsif Is_Variable (AV) then
18825 return True;
18827 -- Generalized indexing operations are rewritten as explicit
18828 -- dereferences, and it is only during resolution that we can
18829 -- check whether the context requires an access_to_variable type.
18831 elsif Nkind (AV) = N_Explicit_Dereference
18832 and then Present (Etype (Original_Node (AV)))
18833 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
18834 and then Ada_Version >= Ada_2012
18835 then
18836 return not Is_Access_Constant (Etype (Prefix (AV)));
18838 -- Unchecked conversions are allowed only if they come from the
18839 -- generated code, which sometimes uses unchecked conversions for out
18840 -- parameters in cases where code generation is unaffected. We tell
18841 -- source unchecked conversions by seeing if they are rewrites of
18842 -- an original Unchecked_Conversion function call, or of an explicit
18843 -- conversion of a function call or an aggregate (as may happen in the
18844 -- expansion of a packed array aggregate).
18846 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
18847 if Nkind (Original_Node (AV)) in N_Function_Call | N_Aggregate then
18848 return False;
18850 elsif Nkind (Original_Node (Expression (AV))) = N_Function_Call then
18851 return False;
18853 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
18854 return Is_OK_Variable_For_Out_Formal (Expression (AV));
18856 else
18857 return True;
18858 end if;
18860 -- Normal type conversions are allowed if argument is a variable
18862 elsif Nkind (AV) = N_Type_Conversion then
18863 if Is_Variable (Expression (AV))
18864 and then Paren_Count (Expression (AV)) = 0
18865 then
18866 Note_Possible_Modification (Expression (AV), Sure => True);
18867 return True;
18869 -- We also allow a non-parenthesized expression that raises
18870 -- constraint error if it rewrites what used to be a variable
18872 elsif Raises_Constraint_Error (Expression (AV))
18873 and then Paren_Count (Expression (AV)) = 0
18874 and then Is_Variable (Original_Node (Expression (AV)))
18875 then
18876 return True;
18878 -- Type conversion of something other than a variable
18880 else
18881 return False;
18882 end if;
18884 -- If this node is rewritten, then test the original form, if that is
18885 -- OK, then we consider the rewritten node OK (for example, if the
18886 -- original node is a conversion, then Is_Variable will not be true
18887 -- but we still want to allow the conversion if it converts a variable).
18889 elsif Is_Rewrite_Substitution (AV) then
18890 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
18892 -- All other non-variables are rejected
18894 else
18895 return False;
18896 end if;
18897 end Is_OK_Variable_For_Out_Formal;
18899 ----------------------------
18900 -- Is_OK_Volatile_Context --
18901 ----------------------------
18903 function Is_OK_Volatile_Context
18904 (Context : Node_Id;
18905 Obj_Ref : Node_Id;
18906 Check_Actuals : Boolean) return Boolean
18908 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
18909 -- Determine whether an arbitrary node denotes a call to a protected
18910 -- entry, function, or procedure in prefixed form where the prefix is
18911 -- Obj_Ref.
18913 function Within_Check (Nod : Node_Id) return Boolean;
18914 -- Determine whether an arbitrary node appears in a check node
18916 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
18917 -- Determine whether an arbitrary entity appears in a volatile function
18919 ---------------------------------
18920 -- Is_Protected_Operation_Call --
18921 ---------------------------------
18923 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
18924 Pref : Node_Id;
18925 Subp : Node_Id;
18927 begin
18928 -- A call to a protected operations retains its selected component
18929 -- form as opposed to other prefixed calls that are transformed in
18930 -- expanded names.
18932 if Nkind (Nod) = N_Selected_Component then
18933 Pref := Prefix (Nod);
18934 Subp := Selector_Name (Nod);
18936 return
18937 Pref = Obj_Ref
18938 and then Present (Etype (Pref))
18939 and then Is_Protected_Type (Etype (Pref))
18940 and then Is_Entity_Name (Subp)
18941 and then Present (Entity (Subp))
18942 and then Ekind (Entity (Subp)) in
18943 E_Entry | E_Entry_Family | E_Function | E_Procedure;
18944 else
18945 return False;
18946 end if;
18947 end Is_Protected_Operation_Call;
18949 ------------------
18950 -- Within_Check --
18951 ------------------
18953 function Within_Check (Nod : Node_Id) return Boolean is
18954 Par : Node_Id;
18956 begin
18957 -- Climb the parent chain looking for a check node
18959 Par := Nod;
18960 while Present (Par) loop
18961 if Nkind (Par) in N_Raise_xxx_Error then
18962 return True;
18964 -- Prevent the search from going too far
18966 elsif Is_Body_Or_Package_Declaration (Par) then
18967 exit;
18968 end if;
18970 Par := Parent (Par);
18971 end loop;
18973 return False;
18974 end Within_Check;
18976 ------------------------------
18977 -- Within_Volatile_Function --
18978 ------------------------------
18980 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
18981 pragma Assert (Ekind (Id) = E_Return_Statement);
18983 Func_Id : constant Entity_Id := Return_Applies_To (Id);
18985 begin
18986 pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function);
18988 return Is_Volatile_Function (Func_Id);
18989 end Within_Volatile_Function;
18991 -- Local variables
18993 Obj_Id : Entity_Id;
18995 -- Start of processing for Is_OK_Volatile_Context
18997 begin
18998 -- Ignore context restriction when doing preanalysis, e.g. on a copy of
18999 -- an expression function, because this copy is not fully decorated and
19000 -- it is not possible to reliably decide the legality of the context.
19001 -- Any violations will be reported anyway when doing the full analysis.
19003 if not Full_Analysis then
19004 return True;
19005 end if;
19007 -- For actual parameters within explicit parameter associations switch
19008 -- the context to the corresponding subprogram call.
19010 if Nkind (Context) = N_Parameter_Association then
19011 return Is_OK_Volatile_Context (Context => Parent (Context),
19012 Obj_Ref => Obj_Ref,
19013 Check_Actuals => Check_Actuals);
19015 -- The volatile object appears on either side of an assignment
19017 elsif Nkind (Context) = N_Assignment_Statement then
19018 return True;
19020 -- The volatile object is part of the initialization expression of
19021 -- another object.
19023 elsif Nkind (Context) = N_Object_Declaration
19024 and then Present (Expression (Context))
19025 and then Expression (Context) = Obj_Ref
19026 and then Nkind (Parent (Context)) /= N_Expression_With_Actions
19027 then
19028 Obj_Id := Defining_Entity (Context);
19030 -- The volatile object acts as the initialization expression of an
19031 -- extended return statement. This is valid context as long as the
19032 -- function is volatile.
19034 if Is_Return_Object (Obj_Id) then
19035 return Within_Volatile_Function (Scope (Obj_Id));
19037 -- Otherwise this is a normal object initialization
19039 else
19040 return True;
19041 end if;
19043 -- The volatile object acts as the name of a renaming declaration
19045 elsif Nkind (Context) = N_Object_Renaming_Declaration
19046 and then Name (Context) = Obj_Ref
19047 then
19048 return True;
19050 -- The volatile object appears as an actual parameter in a call to an
19051 -- instance of Unchecked_Conversion whose result is renamed.
19053 elsif Nkind (Context) = N_Function_Call
19054 and then Is_Entity_Name (Name (Context))
19055 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
19056 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
19057 then
19058 return True;
19060 -- The volatile object is actually the prefix in a protected entry,
19061 -- function, or procedure call.
19063 elsif Is_Protected_Operation_Call (Context) then
19064 return True;
19066 -- The volatile object appears as the expression of a simple return
19067 -- statement that applies to a volatile function.
19069 elsif Nkind (Context) = N_Simple_Return_Statement
19070 and then Expression (Context) = Obj_Ref
19071 then
19072 return
19073 Within_Volatile_Function (Return_Statement_Entity (Context));
19075 -- The volatile object appears as the prefix of a name occurring in a
19076 -- non-interfering context.
19078 elsif Nkind (Context) in
19079 N_Attribute_Reference |
19080 N_Explicit_Dereference |
19081 N_Indexed_Component |
19082 N_Selected_Component |
19083 N_Slice
19084 and then Prefix (Context) = Obj_Ref
19085 and then Is_OK_Volatile_Context
19086 (Context => Parent (Context),
19087 Obj_Ref => Context,
19088 Check_Actuals => Check_Actuals)
19089 then
19090 return True;
19092 -- The volatile object appears as the prefix of attributes Address,
19093 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
19094 -- Position, Size, Storage_Size.
19096 elsif Nkind (Context) = N_Attribute_Reference
19097 and then Prefix (Context) = Obj_Ref
19098 and then Attribute_Name (Context) in Name_Address
19099 | Name_Alignment
19100 | Name_Component_Size
19101 | Name_First
19102 | Name_First_Bit
19103 | Name_Last
19104 | Name_Last_Bit
19105 | Name_Length
19106 | Name_Position
19107 | Name_Size
19108 | Name_Storage_Size
19109 then
19110 return True;
19112 -- The volatile object appears as the expression of a type conversion
19113 -- occurring in a non-interfering context.
19115 elsif Nkind (Context) in N_Qualified_Expression
19116 | N_Type_Conversion
19117 | N_Unchecked_Type_Conversion
19118 and then Expression (Context) = Obj_Ref
19119 and then Is_OK_Volatile_Context
19120 (Context => Parent (Context),
19121 Obj_Ref => Context,
19122 Check_Actuals => Check_Actuals)
19123 then
19124 return True;
19126 -- The volatile object appears as the expression in a delay statement
19128 elsif Nkind (Context) in N_Delay_Statement then
19129 return True;
19131 -- Allow references to volatile objects in various checks. This is not a
19132 -- direct SPARK 2014 requirement.
19134 elsif Within_Check (Context) then
19135 return True;
19137 -- References to effectively volatile objects that appear as actual
19138 -- parameters in subprogram calls can be examined only after call itself
19139 -- has been resolved. Before that, assume such references to be legal.
19141 elsif Nkind (Context) in N_Subprogram_Call | N_Entry_Call_Statement then
19142 if Check_Actuals then
19143 declare
19144 Call : Node_Id;
19145 Formal : Entity_Id;
19146 Subp : constant Entity_Id := Get_Called_Entity (Context);
19147 begin
19148 Find_Actual (Obj_Ref, Formal, Call);
19149 pragma Assert (Call = Context);
19151 -- An effectively volatile object may act as an actual when the
19152 -- corresponding formal is of a non-scalar effectively volatile
19153 -- type (SPARK RM 7.1.3(9)).
19155 if not Is_Scalar_Type (Etype (Formal))
19156 and then Is_Effectively_Volatile_For_Reading (Etype (Formal))
19157 then
19158 return True;
19160 -- An effectively volatile object may act as an actual in a
19161 -- call to an instance of Unchecked_Conversion. (SPARK RM
19162 -- 7.1.3(9)).
19164 elsif Is_Unchecked_Conversion_Instance (Subp) then
19165 return True;
19167 else
19168 return False;
19169 end if;
19170 end;
19171 else
19172 return True;
19173 end if;
19174 else
19175 return False;
19176 end if;
19177 end Is_OK_Volatile_Context;
19179 ------------------------------------
19180 -- Is_Package_Contract_Annotation --
19181 ------------------------------------
19183 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
19184 Nam : Name_Id;
19186 begin
19187 if Nkind (Item) = N_Aspect_Specification then
19188 Nam := Chars (Identifier (Item));
19190 else pragma Assert (Nkind (Item) = N_Pragma);
19191 Nam := Pragma_Name (Item);
19192 end if;
19194 return Nam = Name_Abstract_State
19195 or else Nam = Name_Initial_Condition
19196 or else Nam = Name_Initializes
19197 or else Nam = Name_Refined_State;
19198 end Is_Package_Contract_Annotation;
19200 -----------------------------------
19201 -- Is_Partially_Initialized_Type --
19202 -----------------------------------
19204 function Is_Partially_Initialized_Type
19205 (Typ : Entity_Id;
19206 Include_Implicit : Boolean := True) return Boolean
19208 begin
19209 if Is_Scalar_Type (Typ) then
19210 return Has_Default_Aspect (Base_Type (Typ));
19212 elsif Is_Access_Type (Typ) then
19213 return Include_Implicit;
19215 elsif Is_Array_Type (Typ) then
19217 -- If component type is partially initialized, so is array type
19219 if Has_Default_Aspect (Base_Type (Typ))
19220 or else Is_Partially_Initialized_Type
19221 (Component_Type (Typ), Include_Implicit)
19222 then
19223 return True;
19225 -- Otherwise we are only partially initialized if we are fully
19226 -- initialized (this is the empty array case, no point in us
19227 -- duplicating that code here).
19229 else
19230 return Is_Fully_Initialized_Type (Typ);
19231 end if;
19233 elsif Is_Record_Type (Typ) then
19235 -- A discriminated type is always partially initialized if in
19236 -- all mode
19238 if Has_Discriminants (Typ) and then Include_Implicit then
19239 return True;
19241 -- A tagged type is always partially initialized
19243 elsif Is_Tagged_Type (Typ) then
19244 return True;
19246 -- Case of nondiscriminated record
19248 else
19249 declare
19250 Comp : Entity_Id;
19252 Component_Present : Boolean := False;
19253 -- Set True if at least one component is present. If no
19254 -- components are present, then record type is fully
19255 -- initialized (another odd case, like the null array).
19257 begin
19258 -- Loop through components
19260 Comp := First_Component (Typ);
19261 while Present (Comp) loop
19262 Component_Present := True;
19264 -- If a component has an initialization expression then the
19265 -- enclosing record type is partially initialized
19267 if Present (Parent (Comp))
19268 and then Present (Expression (Parent (Comp)))
19269 then
19270 return True;
19272 -- If a component is of a type which is itself partially
19273 -- initialized, then the enclosing record type is also.
19275 elsif Is_Partially_Initialized_Type
19276 (Etype (Comp), Include_Implicit)
19277 then
19278 return True;
19279 end if;
19281 Next_Component (Comp);
19282 end loop;
19284 -- No initialized components found. If we found any components
19285 -- they were all uninitialized so the result is false.
19287 if Component_Present then
19288 return False;
19290 -- But if we found no components, then all the components are
19291 -- initialized so we consider the type to be initialized.
19293 else
19294 return True;
19295 end if;
19296 end;
19297 end if;
19299 -- Concurrent types are always fully initialized
19301 elsif Is_Concurrent_Type (Typ) then
19302 return True;
19304 -- For a private type, go to underlying type. If there is no underlying
19305 -- type then just assume this partially initialized. Not clear if this
19306 -- can happen in a non-error case, but no harm in testing for this.
19308 elsif Is_Private_Type (Typ) then
19309 declare
19310 U : constant Entity_Id := Underlying_Type (Typ);
19311 begin
19312 if No (U) then
19313 return True;
19314 else
19315 return Is_Partially_Initialized_Type (U, Include_Implicit);
19316 end if;
19317 end;
19319 -- For any other type (are there any?) assume partially initialized
19321 else
19322 return True;
19323 end if;
19324 end Is_Partially_Initialized_Type;
19326 ------------------------------------
19327 -- Is_Potentially_Persistent_Type --
19328 ------------------------------------
19330 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
19331 Comp : Entity_Id;
19332 Indx : Node_Id;
19334 begin
19335 -- For private type, test corresponding full type
19337 if Is_Private_Type (T) then
19338 return Is_Potentially_Persistent_Type (Full_View (T));
19340 -- Scalar types are potentially persistent
19342 elsif Is_Scalar_Type (T) then
19343 return True;
19345 -- Record type is potentially persistent if not tagged and the types of
19346 -- all it components are potentially persistent, and no component has
19347 -- an initialization expression.
19349 elsif Is_Record_Type (T)
19350 and then not Is_Tagged_Type (T)
19351 and then not Is_Partially_Initialized_Type (T)
19352 then
19353 Comp := First_Component (T);
19354 while Present (Comp) loop
19355 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
19356 return False;
19357 else
19358 Next_Entity (Comp);
19359 end if;
19360 end loop;
19362 return True;
19364 -- Array type is potentially persistent if its component type is
19365 -- potentially persistent and if all its constraints are static.
19367 elsif Is_Array_Type (T) then
19368 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
19369 return False;
19370 end if;
19372 Indx := First_Index (T);
19373 while Present (Indx) loop
19374 if not Is_OK_Static_Subtype (Etype (Indx)) then
19375 return False;
19376 else
19377 Next_Index (Indx);
19378 end if;
19379 end loop;
19381 return True;
19383 -- All other types are not potentially persistent
19385 else
19386 return False;
19387 end if;
19388 end Is_Potentially_Persistent_Type;
19390 --------------------------------
19391 -- Is_Potentially_Unevaluated --
19392 --------------------------------
19394 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
19395 function Has_Null_Others_Choice (Aggr : Node_Id) return Boolean;
19396 -- Aggr is an array aggregate with static bounds and an others clause;
19397 -- return True if the others choice of the given array aggregate does
19398 -- not cover any component (i.e. is null).
19400 function Immediate_Context_Implies_Is_Potentially_Unevaluated
19401 (Expr : Node_Id) return Boolean;
19402 -- Return True if the *immediate* context of this expression tells us
19403 -- that it is potentially unevaluated; return False if the *immediate*
19404 -- context doesn't provide an answer to this question and we need to
19405 -- keep looking.
19407 function Non_Static_Or_Null_Range (N : Node_Id) return Boolean;
19408 -- Return True if the given range is nonstatic or null
19410 ----------------------------
19411 -- Has_Null_Others_Choice --
19412 ----------------------------
19414 function Has_Null_Others_Choice (Aggr : Node_Id) return Boolean is
19415 Idx : constant Node_Id := First_Index (Etype (Aggr));
19416 Hiv : constant Uint := Expr_Value (Type_High_Bound (Etype (Idx)));
19417 Lov : constant Uint := Expr_Value (Type_Low_Bound (Etype (Idx)));
19419 begin
19420 declare
19421 Intervals : constant Interval_Lists.Discrete_Interval_List :=
19422 Interval_Lists.Aggregate_Intervals (Aggr);
19424 begin
19425 -- The others choice is null if, after normalization, we
19426 -- have a single interval covering the whole aggregate.
19428 return Intervals'Length = 1
19429 and then
19430 Intervals (Intervals'First).Low = Lov
19431 and then
19432 Intervals (Intervals'First).High = Hiv;
19433 end;
19435 -- If the aggregate is malformed (that is, indexes are not disjoint)
19436 -- then no action is needed at this stage; the error will be reported
19437 -- later by the frontend.
19439 exception
19440 when Interval_Lists.Intervals_Error =>
19441 return False;
19442 end Has_Null_Others_Choice;
19444 ----------------------------------------------------------
19445 -- Immediate_Context_Implies_Is_Potentially_Unevaluated --
19446 ----------------------------------------------------------
19448 function Immediate_Context_Implies_Is_Potentially_Unevaluated
19449 (Expr : Node_Id) return Boolean
19451 Par : constant Node_Id := Parent (Expr);
19453 function Aggregate_Type return Node_Id is (Etype (Parent (Par)));
19454 begin
19455 if Nkind (Par) = N_If_Expression then
19456 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
19458 elsif Nkind (Par) = N_Case_Expression then
19459 return Expr /= Expression (Par);
19461 elsif Nkind (Par) in N_And_Then | N_Or_Else then
19462 return Expr = Right_Opnd (Par);
19464 elsif Nkind (Par) in N_In | N_Not_In then
19466 -- If the membership includes several alternatives, only the first
19467 -- is definitely evaluated.
19469 if Present (Alternatives (Par)) then
19470 return Expr /= First (Alternatives (Par));
19472 -- If this is a range membership both bounds are evaluated
19474 else
19475 return False;
19476 end if;
19478 elsif Nkind (Par) = N_Quantified_Expression then
19479 return Expr = Condition (Par);
19481 elsif Nkind (Par) in N_Component_Association
19482 | N_Iterated_Component_Association
19483 and then Expr = Expression (Par)
19484 and then Nkind (Parent (Par))
19485 in N_Aggregate | N_Delta_Aggregate | N_Extension_Aggregate
19486 and then Present (Aggregate_Type)
19487 and then Aggregate_Type /= Any_Composite
19488 then
19489 if Is_Array_Type (Aggregate_Type) then
19490 if Ada_Version >= Ada_2022 then
19491 -- For Ada 2022, this predicate returns True for
19492 -- any "repeatedly evaluated" expression.
19493 return True;
19494 end if;
19496 declare
19497 Choice : Node_Id;
19498 In_Others_Choice : Boolean := False;
19499 Array_Agg : constant Node_Id := Parent (Par);
19500 begin
19501 -- The expression of an array_component_association is
19502 -- potentially unevaluated if the associated choice is a
19503 -- subtype_indication or range that defines a nonstatic or
19504 -- null range.
19506 Choice := First (Choices (Par));
19507 while Present (Choice) loop
19508 if Nkind (Choice) = N_Range
19509 and then Non_Static_Or_Null_Range (Choice)
19510 then
19511 return True;
19513 elsif Nkind (Choice) = N_Identifier
19514 and then Present (Scalar_Range (Etype (Choice)))
19515 and then
19516 Non_Static_Or_Null_Range
19517 (Scalar_Range (Etype (Choice)))
19518 then
19519 return True;
19521 elsif Nkind (Choice) = N_Others_Choice then
19522 In_Others_Choice := True;
19523 end if;
19525 Next (Choice);
19526 end loop;
19528 -- It is also potentially unevaluated if the associated
19529 -- choice is an others choice and the applicable index
19530 -- constraint is nonstatic or null.
19532 if In_Others_Choice then
19533 if not Compile_Time_Known_Bounds (Aggregate_Type) then
19534 return True;
19535 else
19536 return Has_Null_Others_Choice (Array_Agg);
19537 end if;
19538 end if;
19539 end;
19541 elsif Is_Container_Aggregate (Parent (Par)) then
19542 -- a component of a container aggregate
19543 return True;
19544 end if;
19546 return False;
19548 else
19549 return False;
19550 end if;
19551 end Immediate_Context_Implies_Is_Potentially_Unevaluated;
19553 ------------------------------
19554 -- Non_Static_Or_Null_Range --
19555 ------------------------------
19557 function Non_Static_Or_Null_Range (N : Node_Id) return Boolean is
19558 Low, High : Node_Id;
19560 begin
19561 Get_Index_Bounds (N, Low, High);
19563 -- Check static bounds
19565 if not Compile_Time_Known_Value (Low)
19566 or else not Compile_Time_Known_Value (High)
19567 then
19568 return True;
19570 -- Check null range
19572 elsif Expr_Value (High) < Expr_Value (Low) then
19573 return True;
19574 end if;
19576 return False;
19577 end Non_Static_Or_Null_Range;
19579 -- Local variables
19581 Par : Node_Id;
19582 Expr : Node_Id;
19584 -- Start of processing for Is_Potentially_Unevaluated
19586 begin
19587 Expr := N;
19588 Par := N;
19590 -- A postcondition whose expression is a short-circuit is broken down
19591 -- into individual aspects for better exception reporting. The original
19592 -- short-circuit expression is rewritten as the second operand, and an
19593 -- occurrence of 'Old in that operand is potentially unevaluated.
19594 -- See sem_ch13.adb for details of this transformation. The reference
19595 -- to 'Old may appear within an expression, so we must look for the
19596 -- enclosing pragma argument in the tree that contains the reference.
19598 while Present (Par)
19599 and then Nkind (Par) /= N_Pragma_Argument_Association
19600 loop
19601 if Is_Rewrite_Substitution (Par)
19602 and then Nkind (Original_Node (Par)) = N_And_Then
19603 then
19604 return True;
19605 end if;
19607 Par := Parent (Par);
19608 end loop;
19610 -- Other cases; 'Old appears within other expression (not the top-level
19611 -- conjunct in a postcondition) with a potentially unevaluated operand.
19613 Par := Parent (Expr);
19615 while Present (Par)
19616 and then Nkind (Par) /= N_Pragma_Argument_Association
19617 loop
19618 if Comes_From_Source (Par)
19619 and then
19620 Immediate_Context_Implies_Is_Potentially_Unevaluated (Expr)
19621 then
19622 return True;
19624 -- For component associations continue climbing; it may be part of an
19625 -- array aggregate. For iterated component association we know that
19626 -- it belongs to an array aggreate, but only its expression is
19627 -- potentially unevaluated, not discrete choice list or iterator
19628 -- specification.
19630 elsif Nkind (Par) in N_Component_Association
19631 | N_Iterated_Component_Association
19632 then
19633 null;
19635 -- If the context is not an expression, or if is the result of
19636 -- expansion of an enclosing construct (such as another attribute)
19637 -- the predicate does not apply.
19639 elsif Nkind (Par) = N_Case_Expression_Alternative then
19640 null;
19642 elsif Nkind (Par) not in N_Subexpr
19643 or else not Comes_From_Source (Par)
19644 then
19645 return False;
19646 end if;
19648 Expr := Par;
19649 Par := Parent (Par);
19650 end loop;
19652 return False;
19653 end Is_Potentially_Unevaluated;
19655 -----------------------------------------
19656 -- Is_Predefined_Dispatching_Operation --
19657 -----------------------------------------
19659 function Is_Predefined_Dispatching_Operation
19660 (E : Entity_Id) return Boolean
19662 TSS_Name : TSS_Name_Type;
19664 begin
19665 if not Is_Dispatching_Operation (E) then
19666 return False;
19667 end if;
19669 Get_Name_String (Chars (E));
19671 -- Most predefined primitives have internally generated names. Equality
19672 -- must be treated differently; the predefined operation is recognized
19673 -- as a homogeneous binary operator that returns Boolean.
19675 if Name_Len > TSS_Name_Type'Last then
19676 TSS_Name :=
19677 TSS_Name_Type
19678 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
19680 if Chars (E) in Name_uAssign | Name_uSize
19681 or else
19682 (Chars (E) = Name_Op_Eq
19683 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
19684 or else TSS_Name = TSS_Deep_Adjust
19685 or else TSS_Name = TSS_Deep_Finalize
19686 or else TSS_Name = TSS_Stream_Input
19687 or else TSS_Name = TSS_Stream_Output
19688 or else TSS_Name = TSS_Stream_Read
19689 or else TSS_Name = TSS_Stream_Write
19690 or else TSS_Name = TSS_Put_Image
19691 or else Is_Predefined_Interface_Primitive (E)
19692 then
19693 return True;
19694 end if;
19695 end if;
19697 return False;
19698 end Is_Predefined_Dispatching_Operation;
19700 ---------------------------------------
19701 -- Is_Predefined_Interface_Primitive --
19702 ---------------------------------------
19704 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
19705 begin
19706 -- In VM targets we don't restrict the functionality of this test to
19707 -- compiling in Ada 2005 mode since in VM targets any tagged type has
19708 -- these primitives.
19710 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
19711 and then Chars (E) in Name_uDisp_Asynchronous_Select
19712 | Name_uDisp_Conditional_Select
19713 | Name_uDisp_Get_Prim_Op_Kind
19714 | Name_uDisp_Get_Task_Id
19715 | Name_uDisp_Requeue
19716 | Name_uDisp_Timed_Select;
19717 end Is_Predefined_Interface_Primitive;
19719 ---------------------------------------
19720 -- Is_Predefined_Internal_Operation --
19721 ---------------------------------------
19723 function Is_Predefined_Internal_Operation
19724 (E : Entity_Id) return Boolean
19726 TSS_Name : TSS_Name_Type;
19728 begin
19729 if not Is_Dispatching_Operation (E) then
19730 return False;
19731 end if;
19733 Get_Name_String (Chars (E));
19735 -- Most predefined primitives have internally generated names. Equality
19736 -- must be treated differently; the predefined operation is recognized
19737 -- as a homogeneous binary operator that returns Boolean.
19739 if Name_Len > TSS_Name_Type'Last then
19740 TSS_Name :=
19741 TSS_Name_Type
19742 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
19744 if Chars (E) in Name_uSize | Name_uAssign
19745 or else
19746 (Chars (E) = Name_Op_Eq
19747 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
19748 or else TSS_Name = TSS_Deep_Adjust
19749 or else TSS_Name = TSS_Deep_Finalize
19750 or else Is_Predefined_Interface_Primitive (E)
19751 then
19752 return True;
19753 end if;
19754 end if;
19756 return False;
19757 end Is_Predefined_Internal_Operation;
19759 --------------------------------
19760 -- Is_Preelaborable_Aggregate --
19761 --------------------------------
19763 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
19764 Aggr_Typ : constant Entity_Id := Etype (Aggr);
19765 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
19767 Anc_Part : Node_Id;
19768 Assoc : Node_Id;
19769 Choice : Node_Id;
19770 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
19771 Expr : Node_Id;
19773 begin
19774 if Array_Aggr then
19775 Comp_Typ := Component_Type (Aggr_Typ);
19776 end if;
19778 -- Inspect the ancestor part
19780 if Nkind (Aggr) = N_Extension_Aggregate then
19781 Anc_Part := Ancestor_Part (Aggr);
19783 -- The ancestor denotes a subtype mark
19785 if Is_Entity_Name (Anc_Part)
19786 and then Is_Type (Entity (Anc_Part))
19787 then
19788 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
19789 return False;
19790 end if;
19792 -- Otherwise the ancestor denotes an expression
19794 elsif not Is_Preelaborable_Construct (Anc_Part) then
19795 return False;
19796 end if;
19797 end if;
19799 -- Inspect the positional associations
19801 Expr := First (Expressions (Aggr));
19802 while Present (Expr) loop
19803 if not Is_Preelaborable_Construct (Expr) then
19804 return False;
19805 end if;
19807 Next (Expr);
19808 end loop;
19810 -- Inspect the named associations
19812 Assoc := First (Component_Associations (Aggr));
19813 while Present (Assoc) loop
19815 -- Inspect the choices of the current named association
19817 Choice := First (Choices (Assoc));
19818 while Present (Choice) loop
19819 if Array_Aggr then
19821 -- For a choice to be preelaborable, it must denote either a
19822 -- static range or a static expression.
19824 if Nkind (Choice) = N_Others_Choice then
19825 null;
19827 elsif Nkind (Choice) = N_Range then
19828 if not Is_OK_Static_Range (Choice) then
19829 return False;
19830 end if;
19832 elsif not Is_OK_Static_Expression (Choice) then
19833 return False;
19834 end if;
19836 else
19837 Comp_Typ := Etype (Choice);
19838 end if;
19840 Next (Choice);
19841 end loop;
19843 -- The type of the choice must have preelaborable initialization if
19844 -- the association carries a <>.
19846 pragma Assert (Present (Comp_Typ));
19847 if Box_Present (Assoc) then
19848 if not Has_Preelaborable_Initialization (Comp_Typ) then
19849 return False;
19850 end if;
19852 -- The type of the expression must have preelaborable initialization
19854 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
19855 return False;
19856 end if;
19858 Next (Assoc);
19859 end loop;
19861 -- At this point the aggregate is preelaborable
19863 return True;
19864 end Is_Preelaborable_Aggregate;
19866 --------------------------------
19867 -- Is_Preelaborable_Construct --
19868 --------------------------------
19870 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
19871 begin
19872 -- Aggregates
19874 if Nkind (N) in N_Aggregate | N_Extension_Aggregate then
19875 return Is_Preelaborable_Aggregate (N);
19877 -- Attributes are allowed in general, even if their prefix is a formal
19878 -- type. It seems that certain attributes known not to be static might
19879 -- not be allowed, but there are no rules to prevent them.
19881 elsif Nkind (N) = N_Attribute_Reference then
19882 return True;
19884 -- Expressions
19886 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
19887 return True;
19889 elsif Nkind (N) = N_Qualified_Expression then
19890 return Is_Preelaborable_Construct (Expression (N));
19892 -- Names are preelaborable when they denote a discriminant of an
19893 -- enclosing type. Discriminals are also considered for this check.
19895 elsif Is_Entity_Name (N)
19896 and then Present (Entity (N))
19897 and then
19898 (Ekind (Entity (N)) = E_Discriminant
19899 or else (Ekind (Entity (N)) in E_Constant | E_In_Parameter
19900 and then Present (Discriminal_Link (Entity (N)))))
19901 then
19902 return True;
19904 -- Statements
19906 elsif Nkind (N) = N_Null then
19907 return True;
19909 -- Ada 2022 (AI12-0175): Calls to certain functions that are essentially
19910 -- unchecked conversions are preelaborable.
19912 elsif Ada_Version >= Ada_2022
19913 and then Nkind (N) = N_Function_Call
19914 and then Is_Entity_Name (Name (N))
19915 and then Is_Preelaborable_Function (Entity (Name (N)))
19916 then
19917 declare
19918 A : Node_Id;
19919 begin
19920 A := First_Actual (N);
19922 while Present (A) loop
19923 if not Is_Preelaborable_Construct (A) then
19924 return False;
19925 end if;
19927 Next_Actual (A);
19928 end loop;
19929 end;
19931 return True;
19933 -- Otherwise the construct is not preelaborable
19935 else
19936 return False;
19937 end if;
19938 end Is_Preelaborable_Construct;
19940 -------------------------------
19941 -- Is_Preelaborable_Function --
19942 -------------------------------
19944 function Is_Preelaborable_Function (Id : Entity_Id) return Boolean is
19945 SATAC : constant Rtsfind.RTU_Id := System_Address_To_Access_Conversions;
19946 Scop : constant Entity_Id := Scope (Id);
19948 begin
19949 -- Small optimization: every allowed function has convention Intrinsic
19950 -- (see Analyze_Subprogram_Instantiation for the subtlety in the test).
19952 if not Is_Intrinsic_Subprogram (Id)
19953 and then Convention (Id) /= Convention_Intrinsic
19954 then
19955 return False;
19956 end if;
19958 -- An instance of Unchecked_Conversion
19960 if Is_Unchecked_Conversion_Instance (Id) then
19961 return True;
19962 end if;
19964 -- A function declared in System.Storage_Elements
19966 if Is_RTU (Scop, System_Storage_Elements) then
19967 return True;
19968 end if;
19970 -- The functions To_Pointer and To_Address declared in an instance of
19971 -- System.Address_To_Access_Conversions (they are the only ones).
19973 if Ekind (Scop) = E_Package
19974 and then Nkind (Parent (Scop)) = N_Package_Specification
19975 and then Present (Generic_Parent (Parent (Scop)))
19976 and then Is_RTU (Generic_Parent (Parent (Scop)), SATAC)
19977 then
19978 return True;
19979 end if;
19981 return False;
19982 end Is_Preelaborable_Function;
19984 -----------------------------
19985 -- Is_Private_Library_Unit --
19986 -----------------------------
19988 function Is_Private_Library_Unit (Unit : Entity_Id) return Boolean is
19989 Comp_Unit : constant Node_Id := Parent (Unit_Declaration_Node (Unit));
19990 begin
19991 return Nkind (Comp_Unit) = N_Compilation_Unit
19992 and then Private_Present (Comp_Unit);
19993 end Is_Private_Library_Unit;
19995 ---------------------------------
19996 -- Is_Protected_Self_Reference --
19997 ---------------------------------
19999 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
20001 function In_Access_Definition (N : Node_Id) return Boolean;
20002 -- Returns true if N belongs to an access definition
20004 --------------------------
20005 -- In_Access_Definition --
20006 --------------------------
20008 function In_Access_Definition (N : Node_Id) return Boolean is
20009 P : Node_Id;
20011 begin
20012 P := Parent (N);
20013 while Present (P) loop
20014 if Nkind (P) = N_Access_Definition then
20015 return True;
20016 end if;
20018 P := Parent (P);
20019 end loop;
20021 return False;
20022 end In_Access_Definition;
20024 -- Start of processing for Is_Protected_Self_Reference
20026 begin
20027 -- Verify that prefix is analyzed and has the proper form. Note that
20028 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
20029 -- produce the address of an entity, do not analyze their prefix
20030 -- because they denote entities that are not necessarily visible.
20031 -- Neither of them can apply to a protected type.
20033 return Ada_Version >= Ada_2005
20034 and then Is_Entity_Name (N)
20035 and then Present (Entity (N))
20036 and then Is_Protected_Type (Entity (N))
20037 and then In_Open_Scopes (Entity (N))
20038 and then not In_Access_Definition (N);
20039 end Is_Protected_Self_Reference;
20041 -----------------------------
20042 -- Is_RCI_Pkg_Spec_Or_Body --
20043 -----------------------------
20045 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
20047 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
20048 -- Return True if the unit of Cunit is an RCI package declaration
20050 ---------------------------
20051 -- Is_RCI_Pkg_Decl_Cunit --
20052 ---------------------------
20054 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
20055 The_Unit : constant Node_Id := Unit (Cunit);
20057 begin
20058 if Nkind (The_Unit) /= N_Package_Declaration then
20059 return False;
20060 end if;
20062 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
20063 end Is_RCI_Pkg_Decl_Cunit;
20065 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
20067 begin
20068 return Is_RCI_Pkg_Decl_Cunit (Cunit)
20069 or else
20070 (Nkind (Unit (Cunit)) = N_Package_Body
20071 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
20072 end Is_RCI_Pkg_Spec_Or_Body;
20074 -----------------------------------------
20075 -- Is_Remote_Access_To_Class_Wide_Type --
20076 -----------------------------------------
20078 function Is_Remote_Access_To_Class_Wide_Type
20079 (E : Entity_Id) return Boolean
20081 begin
20082 -- A remote access to class-wide type is a general access to object type
20083 -- declared in the visible part of a Remote_Types or Remote_Call_
20084 -- Interface unit.
20086 return Ekind (E) = E_General_Access_Type
20087 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
20088 end Is_Remote_Access_To_Class_Wide_Type;
20090 -----------------------------------------
20091 -- Is_Remote_Access_To_Subprogram_Type --
20092 -----------------------------------------
20094 function Is_Remote_Access_To_Subprogram_Type
20095 (E : Entity_Id) return Boolean
20097 begin
20098 return (Ekind (E) = E_Access_Subprogram_Type
20099 or else (Ekind (E) = E_Record_Type
20100 and then Present (Corresponding_Remote_Type (E))))
20101 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
20102 end Is_Remote_Access_To_Subprogram_Type;
20104 --------------------
20105 -- Is_Remote_Call --
20106 --------------------
20108 function Is_Remote_Call (N : Node_Id) return Boolean is
20109 begin
20110 if Nkind (N) not in N_Subprogram_Call then
20112 -- An entry call cannot be remote
20114 return False;
20116 elsif Nkind (Name (N)) in N_Has_Entity
20117 and then Is_Remote_Call_Interface (Entity (Name (N)))
20118 then
20119 -- A subprogram declared in the spec of a RCI package is remote
20121 return True;
20123 elsif Nkind (Name (N)) = N_Explicit_Dereference
20124 and then Is_Remote_Access_To_Subprogram_Type
20125 (Etype (Prefix (Name (N))))
20126 then
20127 -- The dereference of a RAS is a remote call
20129 return True;
20131 elsif Present (Controlling_Argument (N))
20132 and then Is_Remote_Access_To_Class_Wide_Type
20133 (Etype (Controlling_Argument (N)))
20134 then
20135 -- Any primitive operation call with a controlling argument of
20136 -- a RACW type is a remote call.
20138 return True;
20139 end if;
20141 -- All other calls are local calls
20143 return False;
20144 end Is_Remote_Call;
20146 ----------------------
20147 -- Is_Renamed_Entry --
20148 ----------------------
20150 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
20151 Orig_Node : Node_Id := Empty;
20152 Subp_Decl : Node_Id :=
20153 (if No (Parent (Proc_Nam)) then Empty else Parent (Parent (Proc_Nam)));
20155 function Is_Entry (Nam : Node_Id) return Boolean;
20156 -- Determine whether Nam is an entry. Traverse selectors if there are
20157 -- nested selected components.
20159 --------------
20160 -- Is_Entry --
20161 --------------
20163 function Is_Entry (Nam : Node_Id) return Boolean is
20164 begin
20165 if Nkind (Nam) = N_Selected_Component then
20166 return Is_Entry (Selector_Name (Nam));
20167 end if;
20169 return Ekind (Entity (Nam)) = E_Entry;
20170 end Is_Entry;
20172 -- Start of processing for Is_Renamed_Entry
20174 begin
20175 if Present (Alias (Proc_Nam)) then
20176 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
20177 end if;
20179 -- Look for a rewritten subprogram renaming declaration
20181 if Nkind (Subp_Decl) = N_Subprogram_Declaration
20182 and then Present (Original_Node (Subp_Decl))
20183 then
20184 Orig_Node := Original_Node (Subp_Decl);
20185 end if;
20187 -- The rewritten subprogram is actually an entry
20189 if Present (Orig_Node)
20190 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
20191 and then Is_Entry (Name (Orig_Node))
20192 then
20193 return True;
20194 end if;
20196 return False;
20197 end Is_Renamed_Entry;
20199 ----------------------------
20200 -- Is_Reversible_Iterator --
20201 ----------------------------
20203 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
20204 Ifaces_List : Elist_Id;
20205 Iface_Elmt : Elmt_Id;
20206 Iface : Entity_Id;
20208 begin
20209 if Is_Class_Wide_Type (Typ)
20210 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
20211 and then In_Predefined_Unit (Root_Type (Typ))
20212 then
20213 return True;
20215 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
20216 return False;
20218 else
20219 Collect_Interfaces (Typ, Ifaces_List);
20221 Iface_Elmt := First_Elmt (Ifaces_List);
20222 while Present (Iface_Elmt) loop
20223 Iface := Node (Iface_Elmt);
20224 if Chars (Iface) = Name_Reversible_Iterator
20225 and then In_Predefined_Unit (Iface)
20226 then
20227 return True;
20228 end if;
20230 Next_Elmt (Iface_Elmt);
20231 end loop;
20232 end if;
20234 return False;
20235 end Is_Reversible_Iterator;
20237 ---------------------------------
20238 -- Is_Single_Concurrent_Object --
20239 ---------------------------------
20241 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
20242 begin
20243 return
20244 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
20245 end Is_Single_Concurrent_Object;
20247 -------------------------------
20248 -- Is_Single_Concurrent_Type --
20249 -------------------------------
20251 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
20252 begin
20253 return
20254 Ekind (Id) in E_Protected_Type | E_Task_Type
20255 and then Is_Single_Concurrent_Type_Declaration
20256 (Declaration_Node (Id));
20257 end Is_Single_Concurrent_Type;
20259 -------------------------------------------
20260 -- Is_Single_Concurrent_Type_Declaration --
20261 -------------------------------------------
20263 function Is_Single_Concurrent_Type_Declaration
20264 (N : Node_Id) return Boolean
20266 begin
20267 return Nkind (Original_Node (N)) in
20268 N_Single_Protected_Declaration | N_Single_Task_Declaration;
20269 end Is_Single_Concurrent_Type_Declaration;
20271 ---------------------------------------------
20272 -- Is_Single_Precision_Floating_Point_Type --
20273 ---------------------------------------------
20275 function Is_Single_Precision_Floating_Point_Type
20276 (E : Entity_Id) return Boolean is
20277 begin
20278 return Is_Floating_Point_Type (E)
20279 and then Machine_Radix_Value (E) = Uint_2
20280 and then Machine_Mantissa_Value (E) = Uint_24
20281 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
20282 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
20283 end Is_Single_Precision_Floating_Point_Type;
20285 --------------------------------
20286 -- Is_Single_Protected_Object --
20287 --------------------------------
20289 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
20290 begin
20291 return
20292 Ekind (Id) = E_Variable
20293 and then Ekind (Etype (Id)) = E_Protected_Type
20294 and then Is_Single_Concurrent_Type (Etype (Id));
20295 end Is_Single_Protected_Object;
20297 ---------------------------
20298 -- Is_Single_Task_Object --
20299 ---------------------------
20301 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
20302 begin
20303 return
20304 Ekind (Id) = E_Variable
20305 and then Ekind (Etype (Id)) = E_Task_Type
20306 and then Is_Single_Concurrent_Type (Etype (Id));
20307 end Is_Single_Task_Object;
20309 -----------------------------
20310 -- Is_Specific_Tagged_Type --
20311 -----------------------------
20313 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
20314 Full_Typ : Entity_Id;
20316 begin
20317 -- Handle private types
20319 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
20320 Full_Typ := Full_View (Typ);
20321 else
20322 Full_Typ := Typ;
20323 end if;
20325 -- A specific tagged type is a non-class-wide tagged type
20327 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
20328 end Is_Specific_Tagged_Type;
20330 ------------------
20331 -- Is_Statement --
20332 ------------------
20334 function Is_Statement (N : Node_Id) return Boolean is
20335 begin
20336 return
20337 Nkind (N) in N_Statement_Other_Than_Procedure_Call
20338 or else Nkind (N) = N_Procedure_Call_Statement;
20339 end Is_Statement;
20341 --------------------------------------
20342 -- Is_Static_Discriminant_Component --
20343 --------------------------------------
20345 function Is_Static_Discriminant_Component (N : Node_Id) return Boolean is
20346 begin
20347 return Nkind (N) = N_Selected_Component
20348 and then not Is_In_Discriminant_Check (N)
20349 and then Present (Etype (Prefix (N)))
20350 and then Ekind (Etype (Prefix (N))) = E_Record_Subtype
20351 and then Has_Static_Discriminants (Etype (Prefix (N)))
20352 and then Present (Entity (Selector_Name (N)))
20353 and then Ekind (Entity (Selector_Name (N))) = E_Discriminant
20354 and then not In_Check_Node (N);
20355 end Is_Static_Discriminant_Component;
20357 ------------------------
20358 -- Is_Static_Function --
20359 ------------------------
20361 function Is_Static_Function (Subp : Entity_Id) return Boolean is
20362 begin
20363 -- Always return False for pre Ada 2022 to e.g. ignore the Static
20364 -- aspect in package Interfaces for Ada_Version < 2022 and also
20365 -- for efficiency.
20367 return Ada_Version >= Ada_2022
20368 and then Has_Aspect (Subp, Aspect_Static)
20369 and then
20370 (No (Find_Value_Of_Aspect (Subp, Aspect_Static))
20371 or else Is_True (Static_Boolean
20372 (Find_Value_Of_Aspect (Subp, Aspect_Static))));
20373 end Is_Static_Function;
20375 -----------------------------
20376 -- Is_Static_Function_Call --
20377 -----------------------------
20379 function Is_Static_Function_Call (Call : Node_Id) return Boolean is
20380 function Has_All_Static_Actuals (Call : Node_Id) return Boolean;
20381 -- Return whether all actual parameters of Call are static expressions
20383 ----------------------------
20384 -- Has_All_Static_Actuals --
20385 ----------------------------
20387 function Has_All_Static_Actuals (Call : Node_Id) return Boolean is
20388 Actual : Node_Id := First_Actual (Call);
20389 String_Result : constant Boolean :=
20390 Is_String_Type (Etype (Entity (Name (Call))));
20392 begin
20393 while Present (Actual) loop
20394 if not Is_Static_Expression (Actual) then
20396 -- ??? In the string-returning case we want to avoid a call
20397 -- being made to Establish_Transient_Scope in Resolve_Call,
20398 -- but at the point where that's tested for (which now includes
20399 -- a call to test Is_Static_Function_Call), the actuals of the
20400 -- call haven't been resolved, so expressions of the actuals
20401 -- may not have been marked Is_Static_Expression yet, so we
20402 -- force them to be resolved here, so we can tell if they're
20403 -- static. Calling Resolve here is admittedly a kludge, and we
20404 -- limit this call to string-returning cases.
20406 if String_Result then
20407 Resolve (Actual);
20408 end if;
20410 -- Test flag again in case it's now True due to above Resolve
20412 if not Is_Static_Expression (Actual) then
20413 return False;
20414 end if;
20415 end if;
20417 Next_Actual (Actual);
20418 end loop;
20420 return True;
20421 end Has_All_Static_Actuals;
20423 begin
20424 return Nkind (Call) = N_Function_Call
20425 and then Is_Entity_Name (Name (Call))
20426 and then Is_Static_Function (Entity (Name (Call)))
20427 and then Has_All_Static_Actuals (Call);
20428 end Is_Static_Function_Call;
20430 -------------------------------------------
20431 -- Is_Subcomponent_Of_Full_Access_Object --
20432 -------------------------------------------
20434 function Is_Subcomponent_Of_Full_Access_Object (N : Node_Id) return Boolean
20436 R : Node_Id;
20438 begin
20439 R := Get_Referenced_Object (N);
20441 while Nkind (R) in N_Indexed_Component | N_Selected_Component | N_Slice
20442 loop
20443 R := Get_Referenced_Object (Prefix (R));
20445 -- If the prefix is an access value, only the designated type matters
20447 if Is_Access_Type (Etype (R)) then
20448 if Is_Full_Access (Designated_Type (Etype (R))) then
20449 return True;
20450 end if;
20452 else
20453 if Is_Full_Access_Object (R) then
20454 return True;
20455 end if;
20456 end if;
20457 end loop;
20459 return False;
20460 end Is_Subcomponent_Of_Full_Access_Object;
20462 ---------------------------------------
20463 -- Is_Subprogram_Contract_Annotation --
20464 ---------------------------------------
20466 function Is_Subprogram_Contract_Annotation
20467 (Item : Node_Id) return Boolean
20469 Nam : Name_Id;
20471 begin
20472 if Nkind (Item) = N_Aspect_Specification then
20473 Nam := Chars (Identifier (Item));
20475 else pragma Assert (Nkind (Item) = N_Pragma);
20476 Nam := Pragma_Name (Item);
20477 end if;
20479 return Nam = Name_Always_Terminates
20480 or else Nam = Name_Contract_Cases
20481 or else Nam = Name_Depends
20482 or else Nam = Name_Exceptional_Cases
20483 or else Nam = Name_Extensions_Visible
20484 or else Nam = Name_Global
20485 or else Nam = Name_Post
20486 or else Nam = Name_Post_Class
20487 or else Nam = Name_Postcondition
20488 or else Nam = Name_Pre
20489 or else Nam = Name_Pre_Class
20490 or else Nam = Name_Precondition
20491 or else Nam = Name_Refined_Depends
20492 or else Nam = Name_Refined_Global
20493 or else Nam = Name_Refined_Post
20494 or else Nam = Name_Subprogram_Variant
20495 or else Nam = Name_Test_Case;
20496 end Is_Subprogram_Contract_Annotation;
20498 --------------------------------------------------
20499 -- Is_Subprogram_Stub_Without_Prior_Declaration --
20500 --------------------------------------------------
20502 function Is_Subprogram_Stub_Without_Prior_Declaration
20503 (N : Node_Id) return Boolean
20505 begin
20506 pragma Assert (Nkind (N) = N_Subprogram_Body_Stub);
20508 case Ekind (Defining_Entity (N)) is
20510 -- A subprogram stub without prior declaration serves as declaration
20511 -- for the actual subprogram body. As such, it has an attached
20512 -- defining entity of E_Function or E_Procedure.
20514 when E_Function
20515 | E_Procedure
20517 return True;
20519 -- Otherwise, it is completes a [generic] subprogram declaration
20521 when E_Generic_Function
20522 | E_Generic_Procedure
20523 | E_Subprogram_Body
20525 return False;
20527 when others =>
20528 raise Program_Error;
20529 end case;
20530 end Is_Subprogram_Stub_Without_Prior_Declaration;
20532 ---------------------------
20533 -- Is_Suitable_Primitive --
20534 ---------------------------
20536 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
20537 begin
20538 -- The Default_Initial_Condition and invariant procedures must not be
20539 -- treated as primitive operations even when they apply to a tagged
20540 -- type. These routines must not act as targets of dispatching calls
20541 -- because they already utilize class-wide-precondition semantics to
20542 -- handle inheritance and overriding.
20544 if Ekind (Subp_Id) = E_Procedure
20545 and then (Is_DIC_Procedure (Subp_Id)
20546 or else
20547 Is_Invariant_Procedure (Subp_Id))
20548 then
20549 return False;
20550 end if;
20552 return True;
20553 end Is_Suitable_Primitive;
20555 ----------------------------
20556 -- Is_Synchronized_Object --
20557 ----------------------------
20559 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
20560 Prag : Node_Id;
20562 begin
20563 if Is_Object (Id) then
20565 -- The object is synchronized if it is of a type that yields a
20566 -- synchronized object.
20568 if Yields_Synchronized_Object (Etype (Id)) then
20569 return True;
20571 -- The object is synchronized if it is atomic and Async_Writers is
20572 -- enabled.
20574 elsif Is_Atomic_Object_Entity (Id)
20575 and then Async_Writers_Enabled (Id)
20576 then
20577 return True;
20579 -- A constant is a synchronized object by default, unless its type is
20580 -- access-to-variable type.
20582 elsif Ekind (Id) = E_Constant
20583 and then not Is_Access_Variable (Etype (Id))
20584 then
20585 return True;
20587 -- A variable is a synchronized object if it is subject to pragma
20588 -- Constant_After_Elaboration.
20590 elsif Ekind (Id) = E_Variable then
20591 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
20593 return Present (Prag) and then Is_Enabled_Pragma (Prag);
20594 end if;
20595 end if;
20597 -- Otherwise the input is not an object or it does not qualify as a
20598 -- synchronized object.
20600 return False;
20601 end Is_Synchronized_Object;
20603 ---------------------------------
20604 -- Is_Synchronized_Tagged_Type --
20605 ---------------------------------
20607 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
20608 Kind : constant Entity_Kind := Ekind (Base_Type (E));
20610 begin
20611 -- A task or protected type derived from an interface is a tagged type.
20612 -- Such a tagged type is called a synchronized tagged type, as are
20613 -- synchronized interfaces and private extensions whose declaration
20614 -- includes the reserved word synchronized.
20616 return (Is_Tagged_Type (E)
20617 and then (Kind = E_Task_Type
20618 or else
20619 Kind = E_Protected_Type))
20620 or else
20621 (Is_Interface (E)
20622 and then Is_Synchronized_Interface (E))
20623 or else
20624 (Ekind (E) = E_Record_Type_With_Private
20625 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
20626 and then (Synchronized_Present (Parent (E))
20627 or else Is_Synchronized_Interface (Etype (E))));
20628 end Is_Synchronized_Tagged_Type;
20630 -----------------
20631 -- Is_Transfer --
20632 -----------------
20634 function Is_Transfer (N : Node_Id) return Boolean is
20635 Kind : constant Node_Kind := Nkind (N);
20637 begin
20638 if Kind in N_Simple_Return_Statement
20639 | N_Extended_Return_Statement
20640 | N_Goto_Statement
20641 | N_Raise_Statement
20642 | N_Requeue_Statement
20643 then
20644 return True;
20646 elsif Kind in N_Exit_Statement | N_Raise_xxx_Error
20647 and then No (Condition (N))
20648 then
20649 return True;
20651 elsif Kind = N_Procedure_Call_Statement
20652 and then Is_Entity_Name (Name (N))
20653 and then Present (Entity (Name (N)))
20654 and then No_Return (Entity (Name (N)))
20655 then
20656 return True;
20658 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
20659 return True;
20661 else
20662 return False;
20663 end if;
20664 end Is_Transfer;
20666 -------------
20667 -- Is_True --
20668 -------------
20670 function Is_True (U : Opt_Ubool) return Boolean is
20671 begin
20672 return No (U) or else U = Uint_1;
20673 end Is_True;
20675 ------------------------
20676 -- Is_Trivial_Boolean --
20677 ------------------------
20679 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
20680 begin
20681 return Comes_From_Source (N)
20682 and then Nkind (N) in N_Identifier | N_Expanded_Name
20683 and then Entity (N) in Standard_True | Standard_False;
20684 end Is_Trivial_Boolean;
20686 --------------------------------------
20687 -- Is_Unchecked_Conversion_Instance --
20688 --------------------------------------
20690 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
20691 Par : Node_Id;
20693 begin
20694 -- Look for a function whose generic parent is the predefined intrinsic
20695 -- function Unchecked_Conversion, or for one that renames such an
20696 -- instance.
20698 if Ekind (Id) = E_Function then
20699 Par := Parent (Id);
20701 if Nkind (Par) = N_Function_Specification then
20702 Par := Generic_Parent (Par);
20704 if Present (Par) then
20705 return
20706 Chars (Par) = Name_Unchecked_Conversion
20707 and then Is_Intrinsic_Subprogram (Par)
20708 and then In_Predefined_Unit (Par);
20709 else
20710 return
20711 Present (Alias (Id))
20712 and then Is_Unchecked_Conversion_Instance (Alias (Id));
20713 end if;
20714 end if;
20715 end if;
20717 return False;
20718 end Is_Unchecked_Conversion_Instance;
20720 -------------------------------
20721 -- Is_Universal_Numeric_Type --
20722 -------------------------------
20724 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
20725 begin
20726 return T = Universal_Integer or else T = Universal_Real;
20727 end Is_Universal_Numeric_Type;
20729 ------------------------------
20730 -- Is_User_Defined_Equality --
20731 ------------------------------
20733 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
20734 F1, F2 : Entity_Id;
20736 begin
20737 -- An equality operator is a function that carries the name "=", returns
20738 -- Boolean, and has exactly two formal parameters of an identical type.
20740 if Ekind (Id) = E_Function
20741 and then Chars (Id) = Name_Op_Eq
20742 and then Base_Type (Etype (Id)) = Standard_Boolean
20743 then
20744 F1 := First_Formal (Id);
20746 if No (F1) then
20747 return False;
20748 end if;
20750 F2 := Next_Formal (F1);
20752 return Present (F2)
20753 and then No (Next_Formal (F2))
20754 and then Base_Type (Etype (F1)) = Base_Type (Etype (F2));
20756 else
20757 return False;
20758 end if;
20759 end Is_User_Defined_Equality;
20761 -----------------------------
20762 -- Is_User_Defined_Literal --
20763 -----------------------------
20765 function Is_User_Defined_Literal
20766 (N : Node_Id;
20767 Typ : Entity_Id) return Boolean
20769 Literal_Aspect_Map :
20770 constant array (N_Numeric_Or_String_Literal) of Aspect_Id :=
20771 (N_Integer_Literal => Aspect_Integer_Literal,
20772 N_Interpolated_String_Literal => No_Aspect,
20773 N_Real_Literal => Aspect_Real_Literal,
20774 N_String_Literal => Aspect_String_Literal);
20776 begin
20777 -- Return True when N is either a literal or a named number and the
20778 -- type has the appropriate user-defined literal aspect.
20780 return (Nkind (N) in N_Numeric_Or_String_Literal
20781 and then Has_Aspect (Typ, Literal_Aspect_Map (Nkind (N))))
20782 or else
20783 (Is_Entity_Name (N)
20784 and then Present (Entity (N))
20785 and then
20786 ((Ekind (Entity (N)) = E_Named_Integer
20787 and then Has_Aspect (Typ, Aspect_Integer_Literal))
20788 or else
20789 (Ekind (Entity (N)) = E_Named_Real
20790 and then Has_Aspect (Typ, Aspect_Real_Literal))));
20791 end Is_User_Defined_Literal;
20793 --------------------------------------
20794 -- Is_Validation_Variable_Reference --
20795 --------------------------------------
20797 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
20798 Var : constant Node_Id := Unqual_Conv (N);
20799 Var_Id : Entity_Id;
20801 begin
20802 Var_Id := Empty;
20804 if Is_Entity_Name (Var) then
20805 Var_Id := Entity (Var);
20806 end if;
20808 return
20809 Present (Var_Id)
20810 and then Ekind (Var_Id) = E_Variable
20811 and then Present (Validated_Object (Var_Id));
20812 end Is_Validation_Variable_Reference;
20814 ----------------------------
20815 -- Is_Variable_Size_Array --
20816 ----------------------------
20818 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
20819 Idx : Node_Id;
20821 begin
20822 pragma Assert (Is_Array_Type (E));
20824 -- Check if some index is initialized with a non-constant value
20826 Idx := First_Index (E);
20827 while Present (Idx) loop
20828 if Nkind (Idx) = N_Range then
20829 if not Is_Constant_Bound (Low_Bound (Idx))
20830 or else not Is_Constant_Bound (High_Bound (Idx))
20831 then
20832 return True;
20833 end if;
20834 end if;
20836 Next_Index (Idx);
20837 end loop;
20839 return False;
20840 end Is_Variable_Size_Array;
20842 -----------------------------
20843 -- Is_Variable_Size_Record --
20844 -----------------------------
20846 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
20847 Comp : Entity_Id;
20848 Comp_Typ : Entity_Id;
20850 begin
20851 pragma Assert (Is_Record_Type (E));
20853 Comp := First_Component (E);
20854 while Present (Comp) loop
20855 Comp_Typ := Underlying_Type (Etype (Comp));
20857 -- Recursive call if the record type has discriminants
20859 if Is_Record_Type (Comp_Typ)
20860 and then Has_Discriminants (Comp_Typ)
20861 and then Is_Variable_Size_Record (Comp_Typ)
20862 then
20863 return True;
20865 elsif Is_Array_Type (Comp_Typ)
20866 and then Is_Variable_Size_Array (Comp_Typ)
20867 then
20868 return True;
20869 end if;
20871 Next_Component (Comp);
20872 end loop;
20874 return False;
20875 end Is_Variable_Size_Record;
20877 -----------------
20878 -- Is_Variable --
20879 -----------------
20881 -- Should Is_Variable be refactored to better handle dereferences and
20882 -- technical debt ???
20884 function Is_Variable
20885 (N : Node_Id;
20886 Use_Original_Node : Boolean := True) return Boolean
20888 Orig_Node : Node_Id;
20890 function In_Protected_Function (E : Entity_Id) return Boolean;
20891 -- Within a protected function, the private components of the enclosing
20892 -- protected type are constants. A function nested within a (protected)
20893 -- procedure is not itself protected. Within the body of a protected
20894 -- function the current instance of the protected type is a constant.
20896 function Is_Variable_Prefix (P : Node_Id) return Boolean;
20897 -- Prefixes can involve implicit dereferences, in which case we must
20898 -- test for the case of a reference of a constant access type, which can
20899 -- can never be a variable.
20901 ---------------------------
20902 -- In_Protected_Function --
20903 ---------------------------
20905 function In_Protected_Function (E : Entity_Id) return Boolean is
20906 Prot : Entity_Id;
20907 S : Entity_Id;
20909 begin
20910 -- E is the current instance of a type
20912 if Is_Type (E) then
20913 Prot := E;
20915 -- E is an object
20917 else
20918 Prot := Scope (E);
20919 end if;
20921 if not Is_Protected_Type (Prot) then
20922 return False;
20924 else
20925 S := Current_Scope;
20926 while Present (S) and then S /= Prot loop
20927 if Ekind (S) = E_Function and then Scope (S) = Prot then
20928 return True;
20929 end if;
20931 S := Scope (S);
20932 end loop;
20934 return False;
20935 end if;
20936 end In_Protected_Function;
20938 ------------------------
20939 -- Is_Variable_Prefix --
20940 ------------------------
20942 function Is_Variable_Prefix (P : Node_Id) return Boolean is
20943 begin
20944 if Is_Access_Type (Etype (P)) then
20945 return not Is_Access_Constant (Root_Type (Etype (P)));
20947 -- For the case of an indexed component whose prefix has a packed
20948 -- array type, the prefix has been rewritten into a type conversion.
20949 -- Determine variable-ness from the converted expression.
20951 elsif Nkind (P) = N_Type_Conversion
20952 and then not Comes_From_Source (P)
20953 and then Is_Packed_Array (Etype (P))
20954 then
20955 return Is_Variable (Expression (P));
20957 else
20958 return Is_Variable (P);
20959 end if;
20960 end Is_Variable_Prefix;
20962 -- Start of processing for Is_Variable
20964 begin
20965 -- Special check, allow x'Deref(expr) as a variable
20967 if Nkind (N) = N_Attribute_Reference
20968 and then Attribute_Name (N) = Name_Deref
20969 then
20970 return True;
20971 end if;
20973 -- Check if we perform the test on the original node since this may be a
20974 -- test of syntactic categories which must not be disturbed by whatever
20975 -- rewriting might have occurred. For example, an aggregate, which is
20976 -- certainly NOT a variable, could be turned into a variable by
20977 -- expansion.
20979 if Use_Original_Node then
20980 Orig_Node := Original_Node (N);
20981 else
20982 Orig_Node := N;
20983 end if;
20985 -- Definitely OK if Assignment_OK is set. Since this is something that
20986 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
20988 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
20989 return True;
20991 -- Normally we go to the original node, but there is one exception where
20992 -- we use the rewritten node, namely when it is an explicit dereference.
20993 -- The generated code may rewrite a prefix which is an access type with
20994 -- an explicit dereference. The dereference is a variable, even though
20995 -- the original node may not be (since it could be a constant of the
20996 -- access type).
20998 -- In Ada 2005 we have a further case to consider: the prefix may be a
20999 -- function call given in prefix notation. The original node appears to
21000 -- be a selected component, but we need to examine the call.
21002 elsif Nkind (N) = N_Explicit_Dereference
21003 and then Nkind (Orig_Node) /= N_Explicit_Dereference
21004 and then Present (Etype (Orig_Node))
21005 and then Is_Access_Type (Etype (Orig_Node))
21006 then
21007 -- Note that if the prefix is an explicit dereference that does not
21008 -- come from source, we must check for a rewritten function call in
21009 -- prefixed notation before other forms of rewriting, to prevent a
21010 -- compiler crash.
21012 return
21013 (Nkind (Orig_Node) = N_Function_Call
21014 and then not Is_Access_Constant (Etype (Prefix (N))))
21015 or else
21016 Is_Variable_Prefix (Original_Node (Prefix (N)));
21018 -- Generalized indexing operations are rewritten as explicit
21019 -- dereferences, and it is only during resolution that we can
21020 -- check whether the context requires an access_to_variable type.
21022 elsif Nkind (N) = N_Explicit_Dereference
21023 and then Present (Etype (Orig_Node))
21024 and then Has_Implicit_Dereference (Etype (Orig_Node))
21025 and then Ada_Version >= Ada_2012
21026 then
21027 return not Is_Access_Constant (Etype (Prefix (N)));
21029 -- A function call is never a variable
21031 elsif Nkind (N) = N_Function_Call then
21032 return False;
21034 -- All remaining checks use the original node
21036 elsif Is_Entity_Name (Orig_Node)
21037 and then Present (Entity (Orig_Node))
21038 then
21039 declare
21040 E : constant Entity_Id := Entity (Orig_Node);
21041 K : constant Entity_Kind := Ekind (E);
21043 begin
21044 if Is_Loop_Parameter (E) then
21045 return False;
21046 end if;
21048 return (K = E_Variable
21049 and then Nkind (Parent (E)) /= N_Exception_Handler)
21050 or else (K = E_Component
21051 and then not In_Protected_Function (E))
21052 or else (Present (Etype (E))
21053 and then Is_Access_Variable (Etype (E))
21054 and then Is_Dereferenced (N))
21055 or else K = E_Out_Parameter
21056 or else K = E_In_Out_Parameter
21057 or else K = E_Generic_In_Out_Parameter
21059 -- Current instance of type. If this is a protected type, check
21060 -- we are not within the body of one of its protected functions.
21062 or else (Is_Type (E)
21063 and then In_Open_Scopes (E)
21064 and then not In_Protected_Function (E))
21066 or else (Is_Incomplete_Or_Private_Type (E)
21067 and then In_Open_Scopes (Full_View (E)));
21068 end;
21070 else
21071 case Nkind (Orig_Node) is
21072 when N_Indexed_Component
21073 | N_Slice
21075 return Is_Variable_Prefix (Prefix (Orig_Node));
21077 when N_Selected_Component =>
21078 return Is_Variable (Selector_Name (Orig_Node))
21079 and then Is_Variable_Prefix (Prefix (Orig_Node));
21081 -- For an explicit dereference, the type of the prefix cannot
21082 -- be an access to constant or an access to subprogram.
21084 when N_Explicit_Dereference =>
21085 declare
21086 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
21087 begin
21088 return Is_Access_Type (Typ)
21089 and then not Is_Access_Constant (Root_Type (Typ))
21090 and then Ekind (Typ) /= E_Access_Subprogram_Type;
21091 end;
21093 -- The type conversion is the case where we do not deal with the
21094 -- context dependent special case of an actual parameter. Thus
21095 -- the type conversion is only considered a variable for the
21096 -- purposes of this routine if the target type is tagged. However,
21097 -- a type conversion is considered to be a variable if it does not
21098 -- come from source (this deals for example with the conversions
21099 -- of expressions to their actual subtypes).
21101 when N_Type_Conversion =>
21102 return Is_Variable (Expression (Orig_Node))
21103 and then
21104 (not Comes_From_Source (Orig_Node)
21105 or else
21106 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
21107 and then
21108 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
21110 -- GNAT allows an unchecked type conversion as a variable. This
21111 -- only affects the generation of internal expanded code, since
21112 -- calls to instantiations of Unchecked_Conversion are never
21113 -- considered variables (since they are function calls).
21115 when N_Unchecked_Type_Conversion =>
21116 return Is_Variable (Expression (Orig_Node));
21118 when others =>
21119 return False;
21120 end case;
21121 end if;
21122 end Is_Variable;
21124 ------------------------
21125 -- Is_View_Conversion --
21126 ------------------------
21128 function Is_View_Conversion (N : Node_Id) return Boolean is
21129 begin
21130 if Nkind (N) = N_Type_Conversion
21131 and then Nkind (Unqual_Conv (N)) in N_Has_Etype
21132 then
21133 if Is_Tagged_Type (Etype (N))
21134 and then Is_Tagged_Type (Etype (Unqual_Conv (N)))
21135 then
21136 return True;
21138 elsif Is_Actual_Parameter (N)
21139 and then (Is_Actual_Out_Parameter (N)
21140 or else Is_Actual_In_Out_Parameter (N))
21141 then
21142 return True;
21143 end if;
21144 end if;
21146 return False;
21147 end Is_View_Conversion;
21149 ---------------------------
21150 -- Is_Visibly_Controlled --
21151 ---------------------------
21153 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
21154 Root : constant Entity_Id := Root_Type (T);
21155 begin
21156 return Chars (Scope (Root)) = Name_Finalization
21157 and then Chars (Scope (Scope (Root))) = Name_Ada
21158 and then Scope (Scope (Scope (Root))) = Standard_Standard;
21159 end Is_Visibly_Controlled;
21161 ----------------------------------------
21162 -- Is_Volatile_Full_Access_Object_Ref --
21163 ----------------------------------------
21165 function Is_Volatile_Full_Access_Object_Ref (N : Node_Id) return Boolean is
21166 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean;
21167 -- Determine whether arbitrary entity Id denotes an object that is
21168 -- Volatile_Full_Access.
21170 ----------------------------
21171 -- Is_VFA_Object_Entity --
21172 ----------------------------
21174 function Is_VFA_Object_Entity (Id : Entity_Id) return Boolean is
21175 begin
21176 return
21177 Is_Object (Id)
21178 and then (Is_Volatile_Full_Access (Id)
21179 or else
21180 Is_Volatile_Full_Access (Etype (Id)));
21181 end Is_VFA_Object_Entity;
21183 -- Start of processing for Is_Volatile_Full_Access_Object_Ref
21185 begin
21186 if Is_Entity_Name (N) then
21187 return Is_VFA_Object_Entity (Entity (N));
21189 elsif Is_Volatile_Full_Access (Etype (N)) then
21190 return True;
21192 elsif Nkind (N) = N_Selected_Component then
21193 return Is_Volatile_Full_Access (Entity (Selector_Name (N)));
21195 else
21196 return False;
21197 end if;
21198 end Is_Volatile_Full_Access_Object_Ref;
21200 --------------------------
21201 -- Is_Volatile_Function --
21202 --------------------------
21204 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
21205 begin
21206 pragma Assert (Ekind (Func_Id) in E_Function | E_Generic_Function);
21208 -- A protected function is volatile
21210 if Nkind (Parent (Unit_Declaration_Node (Func_Id))) =
21211 N_Protected_Definition
21212 then
21213 return True;
21215 -- An instance of Ada.Unchecked_Conversion is a volatile function if
21216 -- either the source or the target are effectively volatile.
21218 elsif Is_Unchecked_Conversion_Instance (Func_Id)
21219 and then Has_Effectively_Volatile_Profile (Func_Id)
21220 then
21221 return True;
21223 -- Otherwise the function is treated as volatile if it is subject to
21224 -- enabled pragma Volatile_Function.
21226 else
21227 return
21228 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
21229 end if;
21230 end Is_Volatile_Function;
21232 ----------------------------
21233 -- Is_Volatile_Object_Ref --
21234 ----------------------------
21236 function Is_Volatile_Object_Ref (N : Node_Id) return Boolean is
21237 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean;
21238 -- Determine whether arbitrary entity Id denotes an object that is
21239 -- Volatile.
21241 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean;
21242 -- Determine whether prefix P has volatile components. This requires
21243 -- the presence of a Volatile_Components aspect/pragma or that P be
21244 -- itself a volatile object as per RM C.6(8).
21246 ---------------------------------
21247 -- Is_Volatile_Object_Entity --
21248 ---------------------------------
21250 function Is_Volatile_Object_Entity (Id : Entity_Id) return Boolean is
21251 begin
21252 return
21253 Is_Object (Id)
21254 and then (Is_Volatile (Id) or else Is_Volatile (Etype (Id)));
21255 end Is_Volatile_Object_Entity;
21257 ------------------------------------
21258 -- Prefix_Has_Volatile_Components --
21259 ------------------------------------
21261 function Prefix_Has_Volatile_Components (P : Node_Id) return Boolean is
21262 Typ : constant Entity_Id := Etype (P);
21264 begin
21265 if Is_Access_Type (Typ) then
21266 declare
21267 Dtyp : constant Entity_Id := Designated_Type (Typ);
21269 begin
21270 return Has_Volatile_Components (Dtyp)
21271 or else Is_Volatile (Dtyp);
21272 end;
21274 elsif Has_Volatile_Components (Typ) then
21275 return True;
21277 elsif Is_Entity_Name (P)
21278 and then Has_Volatile_Component (Entity (P))
21279 then
21280 return True;
21282 elsif Is_Volatile_Object_Ref (P) then
21283 return True;
21285 else
21286 return False;
21287 end if;
21288 end Prefix_Has_Volatile_Components;
21290 -- Start of processing for Is_Volatile_Object_Ref
21292 begin
21293 if Is_Entity_Name (N) then
21294 return Is_Volatile_Object_Entity (Entity (N));
21296 elsif Is_Volatile (Etype (N)) then
21297 return True;
21299 elsif Nkind (N) = N_Indexed_Component then
21300 return Prefix_Has_Volatile_Components (Prefix (N));
21302 elsif Nkind (N) = N_Selected_Component then
21303 return Prefix_Has_Volatile_Components (Prefix (N))
21304 or else Is_Volatile (Entity (Selector_Name (N)));
21306 else
21307 return False;
21308 end if;
21309 end Is_Volatile_Object_Ref;
21311 -----------------------------
21312 -- Iterate_Call_Parameters --
21313 -----------------------------
21315 procedure Iterate_Call_Parameters (Call : Node_Id) is
21316 Actual : Node_Id := First_Actual (Call);
21317 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
21319 begin
21320 while Present (Formal) and then Present (Actual) loop
21321 Handle_Parameter (Formal, Actual);
21323 Next_Formal (Formal);
21324 Next_Actual (Actual);
21325 end loop;
21327 pragma Assert (No (Formal));
21328 pragma Assert (No (Actual));
21329 end Iterate_Call_Parameters;
21331 --------------------------------
21332 -- Iterate_Interface_Ancestor --
21333 --------------------------------
21335 function Iterator_Interface_Ancestor (Typ : Entity_Id) return Entity_Id is
21336 begin
21337 if Has_Interfaces (Typ) then
21338 declare
21339 Iface_Elmt : Elmt_Id;
21340 Ifaces : Elist_Id;
21341 Root_Iface : Entity_Id;
21343 begin
21344 Collect_Interfaces (Typ, Ifaces);
21346 Iface_Elmt := First_Elmt (Ifaces);
21347 while Present (Iface_Elmt) loop
21348 Root_Iface := Root_Type (Node (Iface_Elmt));
21350 if Chars (Root_Iface)
21351 in Name_Forward_Iterator | Name_Reversible_Iterator
21352 and then In_Predefined_Unit (Root_Iface)
21353 then
21354 return Root_Iface;
21355 end if;
21357 Next_Elmt (Iface_Elmt);
21358 end loop;
21359 end;
21360 end if;
21362 return Empty;
21363 end Iterator_Interface_Ancestor;
21365 -------------------------
21366 -- Kill_Current_Values --
21367 -------------------------
21369 procedure Kill_Current_Values
21370 (Ent : Entity_Id;
21371 Last_Assignment_Only : Boolean := False)
21373 begin
21374 if Is_Assignable (Ent) then
21375 Set_Last_Assignment (Ent, Empty);
21376 end if;
21378 if Is_Object (Ent) then
21379 if not Last_Assignment_Only then
21380 Kill_Checks (Ent);
21381 Set_Current_Value (Ent, Empty);
21383 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
21384 -- for a constant. Once the constant is elaborated, its value is
21385 -- not changed, therefore the associated flags that describe the
21386 -- value should not be modified either.
21388 if Ekind (Ent) = E_Constant then
21389 null;
21391 -- Non-constant entities
21393 else
21394 if not Can_Never_Be_Null (Ent) then
21395 Set_Is_Known_Non_Null (Ent, False);
21396 end if;
21398 Set_Is_Known_Null (Ent, False);
21400 -- Reset the Is_Known_Valid flag unless the type is always
21401 -- valid. This does not apply to a loop parameter because its
21402 -- bounds are defined by the loop header and therefore always
21403 -- valid.
21405 if not Is_Known_Valid (Etype (Ent))
21406 and then Ekind (Ent) /= E_Loop_Parameter
21407 then
21408 Set_Is_Known_Valid (Ent, False);
21409 end if;
21410 end if;
21411 end if;
21412 end if;
21413 end Kill_Current_Values;
21415 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
21416 S : Entity_Id;
21418 begin
21419 -- Kill all saved checks, a special case of killing saved values
21421 if not Last_Assignment_Only then
21422 Kill_All_Checks;
21423 end if;
21425 -- Loop through relevant scopes, which includes the current scope and
21426 -- any parent scopes if the current scope is a block or a package.
21428 S := Current_Scope;
21429 Scope_Loop : loop
21431 -- Clear current values of all entities in current scope
21433 declare
21434 Ent : Entity_Id;
21435 begin
21436 Ent := First_Entity (S);
21437 while Present (Ent) loop
21438 Kill_Current_Values (Ent, Last_Assignment_Only);
21439 Next_Entity (Ent);
21440 end loop;
21441 end;
21443 -- If this is a not a subprogram, deal with parents
21445 if not Is_Subprogram (S) then
21446 S := Scope (S);
21447 exit Scope_Loop when S = Standard_Standard;
21448 else
21449 exit Scope_Loop;
21450 end if;
21451 end loop Scope_Loop;
21452 end Kill_Current_Values;
21454 --------------------------
21455 -- Kill_Size_Check_Code --
21456 --------------------------
21458 procedure Kill_Size_Check_Code (E : Entity_Id) is
21459 begin
21460 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
21461 and then Present (Size_Check_Code (E))
21462 then
21463 Remove (Size_Check_Code (E));
21464 Set_Size_Check_Code (E, Empty);
21465 end if;
21466 end Kill_Size_Check_Code;
21468 --------------------
21469 -- Known_Non_Null --
21470 --------------------
21472 function Known_Non_Null (N : Node_Id) return Boolean is
21473 Status : constant Null_Status_Kind := Null_Status (N);
21475 Id : Entity_Id;
21476 Op : Node_Kind;
21477 Val : Node_Id;
21479 begin
21480 -- The expression yields a non-null value ignoring simple flow analysis
21482 if Status = Is_Non_Null then
21483 return True;
21485 -- Otherwise check whether N is a reference to an entity that appears
21486 -- within a conditional construct.
21488 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21490 -- First check if we are in decisive conditional
21492 Get_Current_Value_Condition (N, Op, Val);
21494 if Known_Null (Val) then
21495 if Op = N_Op_Eq then
21496 return False;
21497 elsif Op = N_Op_Ne then
21498 return True;
21499 end if;
21500 end if;
21502 -- If OK to do replacement, test Is_Known_Non_Null flag
21504 Id := Entity (N);
21506 if OK_To_Do_Constant_Replacement (Id) then
21507 return Is_Known_Non_Null (Id);
21508 end if;
21509 end if;
21511 -- Otherwise it is not possible to determine whether N yields a non-null
21512 -- value.
21514 return False;
21515 end Known_Non_Null;
21517 ----------------
21518 -- Known_Null --
21519 ----------------
21521 function Known_Null (N : Node_Id) return Boolean is
21522 Status : constant Null_Status_Kind := Null_Status (N);
21524 Id : Entity_Id;
21525 Op : Node_Kind;
21526 Val : Node_Id;
21528 begin
21529 -- The expression yields a null value ignoring simple flow analysis
21531 if Status = Is_Null then
21532 return True;
21534 -- Otherwise check whether N is a reference to an entity that appears
21535 -- within a conditional construct.
21537 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21539 -- First check if we are in decisive conditional
21541 Get_Current_Value_Condition (N, Op, Val);
21543 -- If Get_Current_Value_Condition were to return Val = N, then the
21544 -- recursion below could be infinite.
21546 if Val = N then
21547 raise Program_Error;
21548 end if;
21550 if Known_Null (Val) then
21551 if Op = N_Op_Eq then
21552 return True;
21553 elsif Op = N_Op_Ne then
21554 return False;
21555 end if;
21556 end if;
21558 -- If OK to do replacement, test Is_Known_Null flag
21560 Id := Entity (N);
21562 if OK_To_Do_Constant_Replacement (Id) then
21563 return Is_Known_Null (Id);
21564 end if;
21565 end if;
21567 -- Otherwise it is not possible to determine whether N yields a null
21568 -- value.
21570 return False;
21571 end Known_Null;
21573 ---------------------------
21574 -- Last_Source_Statement --
21575 ---------------------------
21577 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
21578 N : Node_Id;
21580 begin
21581 N := Last (Statements (HSS));
21582 while Present (N) loop
21583 exit when Comes_From_Source (N);
21584 Prev (N);
21585 end loop;
21587 return N;
21588 end Last_Source_Statement;
21590 -----------------------
21591 -- Mark_Coextensions --
21592 -----------------------
21594 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
21595 Is_Dynamic : Boolean;
21596 -- Indicates whether the context causes nested coextensions to be
21597 -- dynamic or static
21599 function Mark_Allocator (N : Node_Id) return Traverse_Result;
21600 -- Recognize an allocator node and label it as a dynamic coextension
21602 --------------------
21603 -- Mark_Allocator --
21604 --------------------
21606 function Mark_Allocator (N : Node_Id) return Traverse_Result is
21607 begin
21608 if Nkind (N) = N_Allocator then
21609 if Is_Dynamic then
21610 Set_Is_Static_Coextension (N, False);
21611 Set_Is_Dynamic_Coextension (N);
21613 -- If the allocator expression is potentially dynamic, it may
21614 -- be expanded out of order and require dynamic allocation
21615 -- anyway, so we treat the coextension itself as dynamic.
21616 -- Potential optimization ???
21618 elsif Nkind (Expression (N)) = N_Qualified_Expression
21619 and then Nkind (Expression (Expression (N))) = N_Op_Concat
21620 then
21621 Set_Is_Static_Coextension (N, False);
21622 Set_Is_Dynamic_Coextension (N);
21623 else
21624 Set_Is_Dynamic_Coextension (N, False);
21625 Set_Is_Static_Coextension (N);
21626 end if;
21627 end if;
21629 return OK;
21630 end Mark_Allocator;
21632 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
21634 -- Start of processing for Mark_Coextensions
21636 begin
21637 -- An allocator that appears on the right-hand side of an assignment is
21638 -- treated as a potentially dynamic coextension when the right-hand side
21639 -- is an allocator or a qualified expression.
21641 -- Obj := new ...'(new Coextension ...);
21643 if Nkind (Context_Nod) = N_Assignment_Statement then
21644 Is_Dynamic := Nkind (Expression (Context_Nod)) in
21645 N_Allocator | N_Qualified_Expression;
21647 -- An allocator that appears within the expression of a simple return
21648 -- statement is treated as a potentially dynamic coextension when the
21649 -- expression is either aggregate, allocator, or qualified expression.
21651 -- return (new Coextension ...);
21652 -- return new ...'(new Coextension ...);
21654 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
21655 Is_Dynamic := Nkind (Expression (Context_Nod)) in
21656 N_Aggregate | N_Allocator | N_Qualified_Expression;
21658 -- An alloctor that appears within the initialization expression of an
21659 -- object declaration is considered a potentially dynamic coextension
21660 -- when the initialization expression is an allocator or a qualified
21661 -- expression.
21663 -- Obj : ... := new ...'(new Coextension ...);
21665 -- A similar case arises when the object declaration is part of an
21666 -- extended return statement.
21668 -- return Obj : ... := new ...'(new Coextension ...);
21669 -- return Obj : ... := (new Coextension ...);
21671 elsif Nkind (Context_Nod) = N_Object_Declaration then
21672 Is_Dynamic := Nkind (Root_Nod) in N_Allocator | N_Qualified_Expression
21673 or else Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
21675 -- This routine should not be called with constructs that cannot contain
21676 -- coextensions.
21678 else
21679 raise Program_Error;
21680 end if;
21682 Mark_Allocators (Root_Nod);
21683 end Mark_Coextensions;
21685 ---------------------------------
21686 -- Mark_Elaboration_Attributes --
21687 ---------------------------------
21689 procedure Mark_Elaboration_Attributes
21690 (N_Id : Node_Or_Entity_Id;
21691 Checks : Boolean := False;
21692 Level : Boolean := False;
21693 Modes : Boolean := False;
21694 Warnings : Boolean := False)
21696 function Elaboration_Checks_OK
21697 (Target_Id : Entity_Id;
21698 Context_Id : Entity_Id) return Boolean;
21699 -- Determine whether elaboration checks are enabled for target Target_Id
21700 -- which resides within context Context_Id.
21702 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
21703 -- Preserve relevant attributes of the context in arbitrary entity Id
21705 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
21706 -- Preserve relevant attributes of the context in arbitrary node N
21708 ---------------------------
21709 -- Elaboration_Checks_OK --
21710 ---------------------------
21712 function Elaboration_Checks_OK
21713 (Target_Id : Entity_Id;
21714 Context_Id : Entity_Id) return Boolean
21716 Encl_Scop : Entity_Id;
21718 begin
21719 -- Elaboration checks are suppressed for the target
21721 if Elaboration_Checks_Suppressed (Target_Id) then
21722 return False;
21723 end if;
21725 -- Otherwise elaboration checks are OK for the target, but may be
21726 -- suppressed for the context where the target is declared.
21728 Encl_Scop := Context_Id;
21729 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
21730 if Elaboration_Checks_Suppressed (Encl_Scop) then
21731 return False;
21732 end if;
21734 Encl_Scop := Scope (Encl_Scop);
21735 end loop;
21737 -- Neither the target nor its declarative context have elaboration
21738 -- checks suppressed.
21740 return True;
21741 end Elaboration_Checks_OK;
21743 ------------------------------------
21744 -- Mark_Elaboration_Attributes_Id --
21745 ------------------------------------
21747 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
21748 begin
21749 -- Mark the status of elaboration checks in effect. Do not reset the
21750 -- status in case the entity is reanalyzed with checks suppressed.
21752 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
21753 Set_Is_Elaboration_Checks_OK_Id (Id,
21754 Elaboration_Checks_OK
21755 (Target_Id => Id,
21756 Context_Id => Scope (Id)));
21757 end if;
21759 -- Mark the status of elaboration warnings in effect. Do not reset
21760 -- the status in case the entity is reanalyzed with warnings off.
21762 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
21763 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
21764 end if;
21765 end Mark_Elaboration_Attributes_Id;
21767 --------------------------------------
21768 -- Mark_Elaboration_Attributes_Node --
21769 --------------------------------------
21771 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
21772 function Extract_Name (N : Node_Id) return Node_Id;
21773 -- Obtain the Name attribute of call or instantiation N
21775 ------------------
21776 -- Extract_Name --
21777 ------------------
21779 function Extract_Name (N : Node_Id) return Node_Id is
21780 Nam : Node_Id;
21782 begin
21783 Nam := Name (N);
21785 -- A call to an entry family appears in indexed form
21787 if Nkind (Nam) = N_Indexed_Component then
21788 Nam := Prefix (Nam);
21789 end if;
21791 -- The name may also appear in qualified form
21793 if Nkind (Nam) = N_Selected_Component then
21794 Nam := Selector_Name (Nam);
21795 end if;
21797 return Nam;
21798 end Extract_Name;
21800 -- Local variables
21802 Context_Id : Entity_Id;
21803 Nam : Node_Id;
21805 -- Start of processing for Mark_Elaboration_Attributes_Node
21807 begin
21808 -- Mark the status of elaboration checks in effect. Do not reset the
21809 -- status in case the node is reanalyzed with checks suppressed.
21811 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
21813 -- Assignments, attribute references, and variable references do
21814 -- not have a "declarative" context.
21816 Context_Id := Empty;
21818 -- The status of elaboration checks for calls and instantiations
21819 -- depends on the most recent pragma Suppress/Unsuppress, as well
21820 -- as the suppression status of the context where the target is
21821 -- defined.
21823 -- package Pack is
21824 -- function Func ...;
21825 -- end Pack;
21827 -- with Pack;
21828 -- procedure Main is
21829 -- pragma Suppress (Elaboration_Checks, Pack);
21830 -- X : ... := Pack.Func;
21831 -- ...
21833 -- In the example above, the call to Func has elaboration checks
21834 -- enabled because there is no active general purpose suppression
21835 -- pragma, however the elaboration checks of Pack are explicitly
21836 -- suppressed. As a result the elaboration checks of the call must
21837 -- be disabled in order to preserve this dependency.
21839 if Nkind (N) in N_Entry_Call_Statement
21840 | N_Function_Call
21841 | N_Function_Instantiation
21842 | N_Package_Instantiation
21843 | N_Procedure_Call_Statement
21844 | N_Procedure_Instantiation
21845 then
21846 Nam := Extract_Name (N);
21848 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
21849 Context_Id := Scope (Entity (Nam));
21850 end if;
21851 end if;
21853 Set_Is_Elaboration_Checks_OK_Node (N,
21854 Elaboration_Checks_OK
21855 (Target_Id => Empty,
21856 Context_Id => Context_Id));
21857 end if;
21859 -- Mark the enclosing level of the node. Do not reset the status in
21860 -- case the node is relocated and reanalyzed.
21862 if Level and then not Is_Declaration_Level_Node (N) then
21863 Set_Is_Declaration_Level_Node (N,
21864 Find_Enclosing_Level (N) = Declaration_Level);
21865 end if;
21867 -- Mark the Ghost and SPARK mode in effect
21869 if Modes then
21870 if Ghost_Mode = Ignore then
21871 Set_Is_Ignored_Ghost_Node (N);
21872 end if;
21874 if SPARK_Mode = On then
21875 Set_Is_SPARK_Mode_On_Node (N);
21876 end if;
21877 end if;
21879 -- Mark the status of elaboration warnings in effect. Do not reset
21880 -- the status in case the node is reanalyzed with warnings off.
21882 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
21883 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
21884 end if;
21885 end Mark_Elaboration_Attributes_Node;
21887 -- Start of processing for Mark_Elaboration_Attributes
21889 begin
21890 -- Do not capture any elaboration-related attributes when switch -gnatH
21891 -- (legacy elaboration checking mode enabled) is in effect because the
21892 -- attributes are useless to the legacy model.
21894 if Legacy_Elaboration_Checks then
21895 return;
21896 end if;
21898 if Nkind (N_Id) in N_Entity then
21899 Mark_Elaboration_Attributes_Id (N_Id);
21900 else
21901 Mark_Elaboration_Attributes_Node (N_Id);
21902 end if;
21903 end Mark_Elaboration_Attributes;
21905 ----------------------------------------
21906 -- Mark_Save_Invocation_Graph_Of_Body --
21907 ----------------------------------------
21909 procedure Mark_Save_Invocation_Graph_Of_Body is
21910 Main : constant Node_Id := Cunit (Main_Unit);
21911 Main_Unit : constant Node_Id := Unit (Main);
21912 Aux_Id : Entity_Id;
21914 begin
21915 Set_Save_Invocation_Graph_Of_Body (Main);
21917 -- Assume that the main unit does not have a complimentary unit
21919 Aux_Id := Empty;
21921 -- Obtain the complimentary unit of the main unit
21923 if Nkind (Main_Unit) in N_Generic_Package_Declaration
21924 | N_Generic_Subprogram_Declaration
21925 | N_Package_Declaration
21926 | N_Subprogram_Declaration
21927 then
21928 Aux_Id := Corresponding_Body (Main_Unit);
21930 elsif Nkind (Main_Unit) in N_Package_Body
21931 | N_Subprogram_Body
21932 | N_Subprogram_Renaming_Declaration
21933 then
21934 Aux_Id := Corresponding_Spec (Main_Unit);
21935 end if;
21937 if Present (Aux_Id) then
21938 Set_Save_Invocation_Graph_Of_Body
21939 (Parent (Unit_Declaration_Node (Aux_Id)));
21940 end if;
21941 end Mark_Save_Invocation_Graph_Of_Body;
21943 ----------------------------------
21944 -- Matching_Static_Array_Bounds --
21945 ----------------------------------
21947 function Matching_Static_Array_Bounds
21948 (L_Typ : Node_Id;
21949 R_Typ : Node_Id) return Boolean
21951 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
21952 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
21954 L_Index : Node_Id := Empty; -- init to ...
21955 R_Index : Node_Id := Empty; -- ...avoid warnings
21956 L_Low : Node_Id;
21957 L_High : Node_Id;
21958 L_Len : Uint;
21959 R_Low : Node_Id;
21960 R_High : Node_Id;
21961 R_Len : Uint;
21963 begin
21964 if L_Ndims /= R_Ndims then
21965 return False;
21966 end if;
21968 -- Unconstrained types do not have static bounds
21970 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
21971 return False;
21972 end if;
21974 -- First treat specially the first dimension, as the lower bound and
21975 -- length of string literals are not stored like those of arrays.
21977 if Ekind (L_Typ) = E_String_Literal_Subtype then
21978 L_Low := String_Literal_Low_Bound (L_Typ);
21979 L_Len := String_Literal_Length (L_Typ);
21980 else
21981 L_Index := First_Index (L_Typ);
21982 Get_Index_Bounds (L_Index, L_Low, L_High);
21984 if Is_OK_Static_Expression (L_Low)
21985 and then
21986 Is_OK_Static_Expression (L_High)
21987 then
21988 if Expr_Value (L_High) < Expr_Value (L_Low) then
21989 L_Len := Uint_0;
21990 else
21991 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
21992 end if;
21993 else
21994 return False;
21995 end if;
21996 end if;
21998 if Ekind (R_Typ) = E_String_Literal_Subtype then
21999 R_Low := String_Literal_Low_Bound (R_Typ);
22000 R_Len := String_Literal_Length (R_Typ);
22001 else
22002 R_Index := First_Index (R_Typ);
22003 Get_Index_Bounds (R_Index, R_Low, R_High);
22005 if Is_OK_Static_Expression (R_Low)
22006 and then
22007 Is_OK_Static_Expression (R_High)
22008 then
22009 if Expr_Value (R_High) < Expr_Value (R_Low) then
22010 R_Len := Uint_0;
22011 else
22012 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
22013 end if;
22014 else
22015 return False;
22016 end if;
22017 end if;
22019 if (Is_OK_Static_Expression (L_Low)
22020 and then
22021 Is_OK_Static_Expression (R_Low))
22022 and then Expr_Value (L_Low) = Expr_Value (R_Low)
22023 and then L_Len = R_Len
22024 then
22025 null;
22026 else
22027 return False;
22028 end if;
22030 -- Then treat all other dimensions
22032 for Indx in 2 .. L_Ndims loop
22033 Next (L_Index);
22034 Next (R_Index);
22036 Get_Index_Bounds (L_Index, L_Low, L_High);
22037 Get_Index_Bounds (R_Index, R_Low, R_High);
22039 if (Is_OK_Static_Expression (L_Low) and then
22040 Is_OK_Static_Expression (L_High) and then
22041 Is_OK_Static_Expression (R_Low) and then
22042 Is_OK_Static_Expression (R_High))
22043 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
22044 and then
22045 Expr_Value (L_High) = Expr_Value (R_High))
22046 then
22047 null;
22048 else
22049 return False;
22050 end if;
22051 end loop;
22053 -- If we fall through the loop, all indexes matched
22055 return True;
22056 end Matching_Static_Array_Bounds;
22058 -----------------
22059 -- Might_Raise --
22060 -----------------
22062 function Might_Raise (N : Node_Id) return Boolean is
22063 Result : Boolean := False;
22065 function Process (N : Node_Id) return Traverse_Result;
22066 -- Set Result to True if we find something that could raise an exception
22068 -------------
22069 -- Process --
22070 -------------
22072 function Process (N : Node_Id) return Traverse_Result is
22073 begin
22074 if Nkind (N) in N_Procedure_Call_Statement
22075 | N_Function_Call
22076 | N_Raise_Statement
22077 | N_Raise_xxx_Error
22078 | N_Raise_Expression
22079 then
22080 Result := True;
22081 return Abandon;
22082 else
22083 return OK;
22084 end if;
22085 end Process;
22087 procedure Set_Result is new Traverse_Proc (Process);
22089 -- Start of processing for Might_Raise
22091 begin
22092 -- False if exceptions can't be propagated
22094 if No_Exception_Handlers_Set then
22095 return False;
22096 end if;
22098 -- If the checks handled by the back end are not disabled, we cannot
22099 -- ensure that no exception will be raised.
22101 if not Access_Checks_Suppressed (Empty)
22102 or else not Discriminant_Checks_Suppressed (Empty)
22103 or else not Range_Checks_Suppressed (Empty)
22104 or else not Index_Checks_Suppressed (Empty)
22105 or else Opt.Stack_Checking_Enabled
22106 then
22107 return True;
22108 end if;
22110 Set_Result (N);
22111 return Result;
22112 end Might_Raise;
22114 ----------------------------------------
22115 -- Nearest_Class_Condition_Subprogram --
22116 ----------------------------------------
22118 function Nearest_Class_Condition_Subprogram
22119 (Kind : Condition_Kind;
22120 Spec_Id : Entity_Id) return Entity_Id
22122 Subp_Id : constant Entity_Id := Ultimate_Alias (Spec_Id);
22124 begin
22125 -- Prevent cascaded errors
22127 if not Is_Dispatching_Operation (Subp_Id) then
22128 return Empty;
22130 -- No need to search if this subprogram has class-wide postconditions
22132 elsif Present (Class_Condition (Kind, Subp_Id)) then
22133 return Subp_Id;
22134 end if;
22136 -- Process the contracts of inherited subprograms, looking for
22137 -- class-wide pre/postconditions.
22139 declare
22140 Subps : constant Subprogram_List := Inherited_Subprograms (Subp_Id);
22141 Subp_Id : Entity_Id;
22143 begin
22144 for Index in Subps'Range loop
22145 Subp_Id := Subps (Index);
22147 if Present (Alias (Subp_Id)) then
22148 Subp_Id := Ultimate_Alias (Subp_Id);
22149 end if;
22151 -- Wrappers of class-wide pre/postconditions reference the
22152 -- parent primitive that has the inherited contract.
22154 if Is_Wrapper (Subp_Id)
22155 and then Present (LSP_Subprogram (Subp_Id))
22156 then
22157 Subp_Id := LSP_Subprogram (Subp_Id);
22158 end if;
22160 if Present (Class_Condition (Kind, Subp_Id)) then
22161 return Subp_Id;
22162 end if;
22163 end loop;
22164 end;
22166 return Empty;
22167 end Nearest_Class_Condition_Subprogram;
22169 --------------------------------
22170 -- Nearest_Enclosing_Instance --
22171 --------------------------------
22173 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
22174 Inst : Entity_Id;
22176 begin
22177 Inst := Scope (E);
22178 while Present (Inst) and then Inst /= Standard_Standard loop
22179 if Is_Generic_Instance (Inst) then
22180 return Inst;
22181 end if;
22183 Inst := Scope (Inst);
22184 end loop;
22186 return Empty;
22187 end Nearest_Enclosing_Instance;
22189 ------------------------
22190 -- Needs_Finalization --
22191 ------------------------
22193 function Needs_Finalization (Typ : Entity_Id) return Boolean is
22194 function Has_Some_Controlled_Component
22195 (Input_Typ : Entity_Id) return Boolean;
22196 -- Determine whether type Input_Typ has at least one controlled
22197 -- component.
22199 -----------------------------------
22200 -- Has_Some_Controlled_Component --
22201 -----------------------------------
22203 function Has_Some_Controlled_Component
22204 (Input_Typ : Entity_Id) return Boolean
22206 Comp : Entity_Id;
22208 begin
22209 -- When a type is already frozen and has at least one controlled
22210 -- component, or is manually decorated, it is sufficient to inspect
22211 -- flag Has_Controlled_Component.
22213 if Has_Controlled_Component (Input_Typ) then
22214 return True;
22216 -- Otherwise inspect the internals of the type
22218 elsif not Is_Frozen (Input_Typ) then
22219 if Is_Array_Type (Input_Typ) then
22220 return Needs_Finalization (Component_Type (Input_Typ));
22222 elsif Is_Record_Type (Input_Typ) then
22223 Comp := First_Component (Input_Typ);
22224 while Present (Comp) loop
22225 if Needs_Finalization (Etype (Comp)) then
22226 return True;
22227 end if;
22229 Next_Component (Comp);
22230 end loop;
22231 end if;
22232 end if;
22234 return False;
22235 end Has_Some_Controlled_Component;
22237 -- Start of processing for Needs_Finalization
22239 begin
22240 -- Certain run-time configurations and targets do not provide support
22241 -- for controlled types.
22243 if Restriction_Active (No_Finalization) then
22244 return False;
22246 -- C++ types are not considered controlled. It is assumed that the non-
22247 -- Ada side will handle their clean up.
22249 elsif Convention (Typ) = Convention_CPP then
22250 return False;
22252 -- Class-wide types are treated as controlled because derivations from
22253 -- the root type may introduce controlled components.
22255 elsif Is_Class_Wide_Type (Typ) then
22256 return True;
22258 -- Concurrent types are controlled as long as their corresponding record
22259 -- is controlled.
22261 elsif Is_Concurrent_Type (Typ)
22262 and then Present (Corresponding_Record_Type (Typ))
22263 and then Needs_Finalization (Corresponding_Record_Type (Typ))
22264 then
22265 return True;
22267 -- Otherwise the type is controlled when it is either derived from type
22268 -- [Limited_]Controlled and not subject to aspect Disable_Controlled, or
22269 -- contains at least one controlled component.
22271 else
22272 return
22273 Is_Controlled (Typ) or else Has_Some_Controlled_Component (Typ);
22274 end if;
22275 end Needs_Finalization;
22277 ----------------------
22278 -- Needs_One_Actual --
22279 ----------------------
22281 function Needs_One_Actual (E : Entity_Id) return Boolean is
22282 Formal : Entity_Id;
22284 begin
22285 -- Ada 2005 or later, and formals present. The first formal must be
22286 -- of a type that supports prefix notation: a controlling argument,
22287 -- a class-wide type, or an access to such.
22289 if Ada_Version >= Ada_2005
22290 and then Present (First_Formal (E))
22291 and then No (Default_Value (First_Formal (E)))
22292 and then
22293 (Is_Controlling_Formal (First_Formal (E))
22294 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
22295 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
22296 then
22297 Formal := Next_Formal (First_Formal (E));
22298 while Present (Formal) loop
22299 if No (Default_Value (Formal)) then
22300 return False;
22301 end if;
22303 Next_Formal (Formal);
22304 end loop;
22306 return True;
22308 -- Ada 83/95 or no formals
22310 else
22311 return False;
22312 end if;
22313 end Needs_One_Actual;
22315 ----------------------------
22316 -- Needs_Secondary_Stack --
22317 ----------------------------
22319 function Needs_Secondary_Stack (Id : Entity_Id) return Boolean is
22320 pragma Assert (if Present (Id) then Ekind (Id) in E_Void | Type_Kind);
22322 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
22323 -- Called for untagged record and protected types. Return True if the
22324 -- size of function results is known in the caller for Typ.
22326 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
22327 -- Returns True if Typ is a nonlimited record with defaulted
22328 -- discriminants whose max size makes it unsuitable for allocating on
22329 -- the primary stack.
22331 ------------------------------
22332 -- Caller_Known_Size_Record --
22333 ------------------------------
22335 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
22336 pragma Assert (if Present (Typ) then Typ = Underlying_Type (Typ));
22338 function Depends_On_Discriminant (Typ : Entity_Id) return Boolean;
22339 -- Called for untagged record and protected types. Return True if Typ
22340 -- depends on discriminants, either directly when it is unconstrained
22341 -- or indirectly when it is constrained by uplevel discriminants.
22343 -----------------------------
22344 -- Depends_On_Discriminant --
22345 -----------------------------
22347 function Depends_On_Discriminant (Typ : Entity_Id) return Boolean is
22348 Cons : Elmt_Id;
22350 begin
22351 if Has_Discriminants (Typ) then
22352 if not Is_Constrained (Typ) then
22353 return True;
22355 else
22356 Cons := First_Elmt (Discriminant_Constraint (Typ));
22357 while Present (Cons) loop
22358 if Nkind (Node (Cons)) = N_Identifier
22359 and then Ekind (Entity (Node (Cons))) = E_Discriminant
22360 then
22361 return True;
22362 end if;
22364 Next_Elmt (Cons);
22365 end loop;
22366 end if;
22367 end if;
22369 return False;
22370 end Depends_On_Discriminant;
22372 begin
22373 -- This is a protected type without Corresponding_Record_Type set,
22374 -- typically because expansion is disabled. The safe thing to do is
22375 -- to return True, so Needs_Secondary_Stack returns False.
22377 if No (Typ) then
22378 return True;
22379 end if;
22381 -- First see if we have a variant part and return False if it depends
22382 -- on discriminants.
22384 if Has_Variant_Part (Typ) and then Depends_On_Discriminant (Typ) then
22385 return False;
22386 end if;
22388 -- Then loop over components and return False if their subtype has a
22389 -- caller-unknown size, possibly recursively.
22391 -- ??? This is overly conservative, an array could be nested inside
22392 -- some other record that is constrained by nondiscriminants. That
22393 -- is, the recursive calls are too conservative.
22395 declare
22396 Comp : Entity_Id;
22398 begin
22399 Comp := First_Component (Typ);
22400 while Present (Comp) loop
22401 declare
22402 Comp_Type : constant Entity_Id :=
22403 Underlying_Type (Etype (Comp));
22405 begin
22406 if Is_Record_Type (Comp_Type) then
22407 if not Caller_Known_Size_Record (Comp_Type) then
22408 return False;
22409 end if;
22411 elsif Is_Protected_Type (Comp_Type) then
22412 if not Caller_Known_Size_Record
22413 (Corresponding_Record_Type (Comp_Type))
22414 then
22415 return False;
22416 end if;
22418 elsif Is_Array_Type (Comp_Type) then
22419 if Size_Depends_On_Discriminant (Comp_Type) then
22420 return False;
22421 end if;
22422 end if;
22423 end;
22425 Next_Component (Comp);
22426 end loop;
22427 end;
22429 return True;
22430 end Caller_Known_Size_Record;
22432 ------------------------------
22433 -- Large_Max_Size_Mutable --
22434 ------------------------------
22436 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
22437 pragma Assert (Typ = Underlying_Type (Typ));
22439 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
22440 -- Returns true if the discrete type T has a large range
22442 ----------------------------
22443 -- Is_Large_Discrete_Type --
22444 ----------------------------
22446 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
22447 Threshold : constant Int := 16;
22448 -- Arbitrary threshold above which we consider it "large". We want
22449 -- a fairly large threshold, because these large types really
22450 -- shouldn't have default discriminants in the first place, in
22451 -- most cases.
22453 begin
22454 return UI_To_Int (RM_Size (T)) > Threshold;
22455 end Is_Large_Discrete_Type;
22457 -- Start of processing for Large_Max_Size_Mutable
22459 begin
22460 if Is_Record_Type (Typ)
22461 and then not Is_Inherently_Limited_Type (Typ)
22462 and then Has_Defaulted_Discriminants (Typ)
22463 then
22464 -- Loop through the components, looking for an array whose upper
22465 -- bound(s) depends on discriminants, where both the subtype of
22466 -- the discriminant and the index subtype are too large.
22468 declare
22469 Comp : Entity_Id;
22471 begin
22472 Comp := First_Component (Typ);
22473 while Present (Comp) loop
22474 declare
22475 Comp_Type : constant Entity_Id :=
22476 Underlying_Type (Etype (Comp));
22478 Hi : Node_Id;
22479 Indx : Node_Id;
22480 Ityp : Entity_Id;
22482 begin
22483 if Present (Comp_Type)
22484 and then Is_Array_Type (Comp_Type)
22485 then
22486 Indx := First_Index (Comp_Type);
22488 while Present (Indx) loop
22489 Ityp := Etype (Indx);
22490 Hi := Type_High_Bound (Ityp);
22492 if Nkind (Hi) = N_Identifier
22493 and then Ekind (Entity (Hi)) = E_Discriminant
22494 and then Is_Large_Discrete_Type (Ityp)
22495 and then Is_Large_Discrete_Type
22496 (Etype (Entity (Hi)))
22497 then
22498 return True;
22499 end if;
22501 Next_Index (Indx);
22502 end loop;
22503 end if;
22504 end;
22506 Next_Component (Comp);
22507 end loop;
22508 end;
22509 end if;
22511 return False;
22512 end Large_Max_Size_Mutable;
22514 -- Local declarations
22516 Typ : constant Entity_Id := Underlying_Type (Id);
22518 -- Start of processing for Needs_Secondary_Stack
22520 begin
22521 -- This is a private type which is not completed yet. This can only
22522 -- happen in a default expression (of a formal parameter or of a
22523 -- record component). The safe thing to do is to return False.
22525 if No (Typ) then
22526 return False;
22527 end if;
22529 -- Do not expand transient scope for non-existent procedure return or
22530 -- string literal types.
22532 if Typ = Standard_Void_Type
22533 or else Ekind (Typ) = E_String_Literal_Subtype
22534 then
22535 return False;
22537 -- If Typ is a generic formal incomplete type, then we want to look at
22538 -- the actual type.
22540 elsif Ekind (Typ) = E_Record_Subtype
22541 and then Present (Cloned_Subtype (Typ))
22542 then
22543 return Needs_Secondary_Stack (Cloned_Subtype (Typ));
22545 -- Class-wide types obviously have an unknown size. For specific tagged
22546 -- types, if a call returning one of them is dispatching on result, and
22547 -- this type is not returned on the secondary stack, then the call goes
22548 -- through a thunk that only moves the result from the primary onto the
22549 -- secondary stack, because the computation of the size of the result is
22550 -- possible but complex from the outside.
22552 elsif Is_Class_Wide_Type (Typ) then
22553 return True;
22555 -- If the return slot of the back end cannot be accessed, then there
22556 -- is no way to call Adjust at the right time for the return object if
22557 -- the type needs finalization, so the return object must be allocated
22558 -- on the secondary stack.
22560 elsif not Back_End_Return_Slot and then Needs_Finalization (Typ) then
22561 return True;
22563 -- Definite subtypes have a known size. This includes all elementary
22564 -- types. Tasks have a known size even if they have discriminants, so
22565 -- we return False here, with one exception:
22566 -- For a type like:
22567 -- type T (Last : Natural := 0) is
22568 -- X : String (1 .. Last);
22569 -- end record;
22570 -- we return True. That's because for "P(F(...));", where F returns T,
22571 -- we don't know the size of the result at the call site, so if we
22572 -- allocated it on the primary stack, we would have to allocate the
22573 -- maximum size, which is way too big.
22575 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
22576 return Large_Max_Size_Mutable (Typ);
22578 -- Indefinite (discriminated) record type
22580 elsif Is_Record_Type (Typ) then
22581 return not Caller_Known_Size_Record (Typ);
22583 -- Indefinite (discriminated) protected type
22585 elsif Is_Protected_Type (Typ) then
22586 return not Caller_Known_Size_Record (Corresponding_Record_Type (Typ));
22588 -- Unconstrained array type
22590 else
22591 pragma Assert (Is_Array_Type (Typ) and then not Is_Constrained (Typ));
22592 return True;
22593 end if;
22594 end Needs_Secondary_Stack;
22596 ---------------------------------
22597 -- Needs_Simple_Initialization --
22598 ---------------------------------
22600 function Needs_Simple_Initialization
22601 (Typ : Entity_Id;
22602 Consider_IS : Boolean := True) return Boolean
22604 Consider_IS_NS : constant Boolean :=
22605 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
22607 begin
22608 -- Never need initialization if it is suppressed
22610 if Initialization_Suppressed (Typ) then
22611 return False;
22612 end if;
22614 -- Check for private type, in which case test applies to the underlying
22615 -- type of the private type.
22617 if Is_Private_Type (Typ) then
22618 declare
22619 RT : constant Entity_Id := Underlying_Type (Typ);
22620 begin
22621 if Present (RT) then
22622 return Needs_Simple_Initialization (RT);
22623 else
22624 return False;
22625 end if;
22626 end;
22628 -- Scalar type with Default_Value aspect requires initialization
22630 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
22631 return True;
22633 -- Cases needing simple initialization are access types, and, if pragma
22634 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
22635 -- types.
22637 elsif Is_Access_Type (Typ)
22638 or else (Consider_IS_NS and then Is_Scalar_Type (Typ))
22639 then
22640 return True;
22642 -- If Initialize/Normalize_Scalars is in effect, string objects also
22643 -- need initialization, unless they are created in the course of
22644 -- expanding an aggregate (since in the latter case they will be
22645 -- filled with appropriate initializing values before they are used).
22647 elsif Consider_IS_NS
22648 and then Is_Standard_String_Type (Typ)
22649 and then
22650 (not Is_Itype (Typ)
22651 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
22652 then
22653 return True;
22655 else
22656 return False;
22657 end if;
22658 end Needs_Simple_Initialization;
22660 -------------------------------------
22661 -- Needs_Variable_Reference_Marker --
22662 -------------------------------------
22664 function Needs_Variable_Reference_Marker
22665 (N : Node_Id;
22666 Calls_OK : Boolean) return Boolean
22668 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
22669 -- Deteremine whether variable reference Ref appears within a suitable
22670 -- context that allows the creation of a marker.
22672 -----------------------------
22673 -- Within_Suitable_Context --
22674 -----------------------------
22676 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
22677 Par : Node_Id;
22679 begin
22680 Par := Ref;
22681 while Present (Par) loop
22683 -- The context is not suitable when the reference appears within
22684 -- the formal part of an instantiation which acts as compilation
22685 -- unit because there is no proper list for the insertion of the
22686 -- marker.
22688 if Nkind (Par) = N_Generic_Association
22689 and then Nkind (Parent (Par)) in N_Generic_Instantiation
22690 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
22691 then
22692 return False;
22694 -- The context is not suitable when the reference appears within
22695 -- a pragma. If the pragma has run-time semantics, the reference
22696 -- will be reconsidered once the pragma is expanded.
22698 elsif Nkind (Par) = N_Pragma then
22699 return False;
22701 -- The context is not suitable when the reference appears within a
22702 -- subprogram call, and the caller requests this behavior.
22704 elsif not Calls_OK
22705 and then Nkind (Par) in N_Entry_Call_Statement
22706 | N_Function_Call
22707 | N_Procedure_Call_Statement
22708 then
22709 return False;
22711 -- Prevent the search from going too far
22713 elsif Is_Body_Or_Package_Declaration (Par) then
22714 exit;
22715 end if;
22717 Par := Parent (Par);
22718 end loop;
22720 return True;
22721 end Within_Suitable_Context;
22723 -- Local variables
22725 Prag : Node_Id;
22726 Var_Id : Entity_Id;
22728 -- Start of processing for Needs_Variable_Reference_Marker
22730 begin
22731 -- No marker needs to be created when switch -gnatH (legacy elaboration
22732 -- checking mode enabled) is in effect because the legacy ABE mechanism
22733 -- does not use markers.
22735 if Legacy_Elaboration_Checks then
22736 return False;
22738 -- No marker needs to be created when the reference is preanalyzed
22739 -- because the marker will be inserted in the wrong place.
22741 elsif Preanalysis_Active then
22742 return False;
22744 -- Only references warrant a marker
22746 elsif Nkind (N) not in N_Expanded_Name | N_Identifier then
22747 return False;
22749 -- Only source references warrant a marker
22751 elsif not Comes_From_Source (N) then
22752 return False;
22754 -- No marker needs to be created when the reference is erroneous, left
22755 -- in a bad state, or does not denote a variable.
22757 elsif not (Present (Entity (N))
22758 and then Ekind (Entity (N)) = E_Variable
22759 and then Entity (N) /= Any_Id)
22760 then
22761 return False;
22762 end if;
22764 Var_Id := Entity (N);
22765 Prag := SPARK_Pragma (Var_Id);
22767 -- Both the variable and reference must appear in SPARK_Mode On regions
22768 -- because this elaboration scenario falls under the SPARK rules.
22770 if not (Comes_From_Source (Var_Id)
22771 and then Present (Prag)
22772 and then Get_SPARK_Mode_From_Annotation (Prag) = On
22773 and then Is_SPARK_Mode_On_Node (N))
22774 then
22775 return False;
22777 -- No marker needs to be created when the reference does not appear
22778 -- within a suitable context (see body for details).
22780 -- Performance note: parent traversal
22782 elsif not Within_Suitable_Context (N) then
22783 return False;
22784 end if;
22786 -- At this point it is known that the variable reference will play a
22787 -- role in ABE diagnostics and requires a marker.
22789 return True;
22790 end Needs_Variable_Reference_Marker;
22792 ------------------------
22793 -- New_Copy_List_Tree --
22794 ------------------------
22796 function New_Copy_List_Tree (List : List_Id) return List_Id is
22797 NL : List_Id;
22798 E : Node_Id;
22800 begin
22801 if List = No_List then
22802 return No_List;
22804 else
22805 NL := New_List;
22806 E := First (List);
22808 while Present (E) loop
22809 Append (New_Copy_Tree (E), NL);
22810 Next (E);
22811 end loop;
22813 return NL;
22814 end if;
22815 end New_Copy_List_Tree;
22817 -------------------
22818 -- New_Copy_Tree --
22819 -------------------
22821 -- The following tables play a key role in replicating entities and Itypes.
22822 -- They are intentionally declared at the library level rather than within
22823 -- New_Copy_Tree to avoid elaborating them on each call. This performance
22824 -- optimization saves up to 2% of the entire compilation time spent in the
22825 -- front end. Care should be taken to reset the tables on each new call to
22826 -- New_Copy_Tree.
22828 NCT_Table_Max : constant := 511;
22830 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
22832 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
22833 -- Obtain the hash value of node or entity Key
22835 --------------------
22836 -- NCT_Table_Hash --
22837 --------------------
22839 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
22840 begin
22841 return NCT_Table_Index (Key mod NCT_Table_Max);
22842 end NCT_Table_Hash;
22844 ----------------------
22845 -- NCT_New_Entities --
22846 ----------------------
22848 -- The following table maps old entities and Itypes to their corresponding
22849 -- new entities and Itypes.
22851 -- Aaa -> Xxx
22853 package NCT_New_Entities is new Simple_HTable (
22854 Header_Num => NCT_Table_Index,
22855 Element => Entity_Id,
22856 No_Element => Empty,
22857 Key => Entity_Id,
22858 Hash => NCT_Table_Hash,
22859 Equal => "=");
22861 ------------------------
22862 -- NCT_Pending_Itypes --
22863 ------------------------
22865 -- The following table maps old Associated_Node_For_Itype nodes to a set of
22866 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
22867 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
22868 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
22870 -- Ppp -> (Xxx, Yyy, Zzz)
22872 -- The set is expressed as an Elist
22874 package NCT_Pending_Itypes is new Simple_HTable (
22875 Header_Num => NCT_Table_Index,
22876 Element => Elist_Id,
22877 No_Element => No_Elist,
22878 Key => Node_Id,
22879 Hash => NCT_Table_Hash,
22880 Equal => "=");
22882 NCT_Tables_In_Use : Boolean := False;
22883 -- This flag keeps track of whether the two tables NCT_New_Entities and
22884 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
22885 -- where certain operations are not performed if the tables are not in
22886 -- use. This saves up to 8% of the entire compilation time spent in the
22887 -- front end.
22889 -------------------
22890 -- New_Copy_Tree --
22891 -------------------
22893 function New_Copy_Tree
22894 (Source : Node_Id;
22895 Map : Elist_Id := No_Elist;
22896 New_Sloc : Source_Ptr := No_Location;
22897 New_Scope : Entity_Id := Empty) return Node_Id
22899 -- This routine performs low-level tree manipulations and needs access
22900 -- to the internals of the tree.
22902 EWA_Level : Nat := 0;
22903 -- This counter keeps track of how many N_Expression_With_Actions nodes
22904 -- are encountered during a depth-first traversal of the subtree. These
22905 -- nodes may define new entities in their Actions lists and thus require
22906 -- special processing.
22908 EWA_Inner_Scope_Level : Nat := 0;
22909 -- This counter keeps track of how many scoping constructs appear within
22910 -- an N_Expression_With_Actions node.
22912 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
22913 pragma Inline (Add_New_Entity);
22914 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
22915 -- value New_Id. Old_Id is an entity which appears within the Actions
22916 -- list of an N_Expression_With_Actions node, or within an entity map.
22917 -- New_Id is the corresponding new entity generated during Phase 1.
22919 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
22920 pragma Inline (Add_Pending_Itype);
22921 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
22922 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
22923 -- an itype.
22925 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
22926 pragma Inline (Build_NCT_Tables);
22927 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
22928 -- information supplied in entity map Entity_Map. The format of the
22929 -- entity map must be as follows:
22931 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
22933 function Copy_Any_Node_With_Replacement
22934 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
22935 pragma Inline (Copy_Any_Node_With_Replacement);
22936 -- Replicate entity or node N by invoking one of the following routines:
22938 -- Copy_Node_With_Replacement
22939 -- Corresponding_Entity
22941 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
22942 -- Replicate the elements of entity list List
22944 function Copy_Field_With_Replacement
22945 (Field : Union_Id;
22946 Old_Par : Node_Id := Empty;
22947 New_Par : Node_Id := Empty;
22948 Semantic : Boolean := False) return Union_Id;
22949 -- Replicate field Field by invoking one of the following routines:
22951 -- Copy_Elist_With_Replacement
22952 -- Copy_List_With_Replacement
22953 -- Copy_Node_With_Replacement
22954 -- Corresponding_Entity
22956 -- If the field is not an entity list, entity, itype, syntactic list,
22957 -- or node, then the field is returned unchanged. The routine always
22958 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
22959 -- the expected parent of a syntactic field. New_Par is the new parent
22960 -- associated with a replicated syntactic field. Flag Semantic should
22961 -- be set when the input is a semantic field.
22963 function Copy_List_With_Replacement (List : List_Id) return List_Id;
22964 -- Replicate the elements of syntactic list List
22966 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
22967 -- Replicate node N
22969 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
22970 pragma Inline (Corresponding_Entity);
22971 -- Return the corresponding new entity of Id generated during Phase 1.
22972 -- If there is no such entity, return Id.
22974 function In_Entity_Map
22975 (Id : Entity_Id;
22976 Entity_Map : Elist_Id) return Boolean;
22977 pragma Inline (In_Entity_Map);
22978 -- Determine whether entity Id is one of the old ids specified in entity
22979 -- map Entity_Map. The format of the entity map must be as follows:
22981 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
22983 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
22984 pragma Inline (Update_CFS_Sloc);
22985 -- Update the Comes_From_Source and Sloc attributes of node or entity N
22987 procedure Update_Controlling_Argument
22988 (Old_Call : Node_Id;
22989 New_Call : Node_Id);
22990 pragma Inline (Update_Controlling_Argument);
22991 -- Update Controlling_Argument of New_Call base on Old_Call to make it
22992 -- points to the corresponding newly copied actual parameter.
22994 procedure Update_Named_Associations
22995 (Old_Call : Node_Id;
22996 New_Call : Node_Id);
22997 pragma Inline (Update_Named_Associations);
22998 -- Update semantic chain First/Next_Named_Association of call New_call
22999 -- based on call Old_Call.
23001 procedure Update_New_Entities (Entity_Map : Elist_Id);
23002 pragma Inline (Update_New_Entities);
23003 -- Update the semantic attributes of all new entities generated during
23004 -- Phase 1 that do not appear in entity map Entity_Map. The format of
23005 -- the entity map must be as follows:
23007 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
23009 procedure Update_Pending_Itypes
23010 (Old_Assoc : Node_Id;
23011 New_Assoc : Node_Id);
23012 pragma Inline (Update_Pending_Itypes);
23013 -- Update semantic attribute Associated_Node_For_Itype to refer to node
23014 -- New_Assoc for all itypes whose associated node is Old_Assoc.
23016 procedure Update_Semantic_Fields (Id : Entity_Id);
23017 pragma Inline (Update_Semantic_Fields);
23018 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
23019 -- or itype Id.
23021 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
23022 pragma Inline (Visit_Any_Node);
23023 -- Visit entity of node N by invoking one of the following routines:
23025 -- Visit_Entity
23026 -- Visit_Itype
23027 -- Visit_Node
23029 procedure Visit_Elist (List : Elist_Id);
23030 -- Visit the elements of entity list List
23032 procedure Visit_Entity (Id : Entity_Id);
23033 -- Visit entity Id. This action may create a new entity of Id and save
23034 -- it in table NCT_New_Entities.
23036 procedure Visit_Field
23037 (Field : Union_Id;
23038 Par_Nod : Node_Id := Empty;
23039 Semantic : Boolean := False);
23040 -- Visit field Field by invoking one of the following routines:
23042 -- Visit_Elist
23043 -- Visit_Entity
23044 -- Visit_Itype
23045 -- Visit_List
23046 -- Visit_Node
23048 -- If the field is not an entity list, entity, itype, syntactic list,
23049 -- or node, then the field is not visited. The routine always visits
23050 -- valid syntactic fields. Par_Nod is the expected parent of the
23051 -- syntactic field. Flag Semantic should be set when the input is a
23052 -- semantic field.
23054 procedure Visit_Itype (Itype : Entity_Id);
23055 -- Visit itype Itype. This action may create a new entity for Itype and
23056 -- save it in table NCT_New_Entities. In addition, the routine may map
23057 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
23059 procedure Visit_List (List : List_Id);
23060 -- Visit the elements of syntactic list List
23062 procedure Visit_Node (N : Node_Id);
23063 -- Visit node N
23065 procedure Visit_Semantic_Fields (Id : Entity_Id);
23066 pragma Inline (Visit_Semantic_Fields);
23067 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
23068 -- fields of entity or itype Id.
23070 --------------------
23071 -- Add_New_Entity --
23072 --------------------
23074 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
23075 begin
23076 pragma Assert (Present (Old_Id));
23077 pragma Assert (Present (New_Id));
23078 pragma Assert (Nkind (Old_Id) in N_Entity);
23079 pragma Assert (Nkind (New_Id) in N_Entity);
23081 NCT_Tables_In_Use := True;
23083 -- Sanity check the NCT_New_Entities table. No previous mapping with
23084 -- key Old_Id should exist.
23086 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
23088 -- Establish the mapping
23090 -- Old_Id -> New_Id
23092 NCT_New_Entities.Set (Old_Id, New_Id);
23093 end Add_New_Entity;
23095 -----------------------
23096 -- Add_Pending_Itype --
23097 -----------------------
23099 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
23100 Itypes : Elist_Id;
23102 begin
23103 pragma Assert (Present (Assoc_Nod));
23104 pragma Assert (Present (Itype));
23105 pragma Assert (Nkind (Itype) in N_Entity);
23106 pragma Assert (Is_Itype (Itype));
23108 NCT_Tables_In_Use := True;
23110 -- It is not possible to sanity check the NCT_Pendint_Itypes table
23111 -- directly because a single node may act as the associated node for
23112 -- multiple itypes.
23114 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
23116 if No (Itypes) then
23117 Itypes := New_Elmt_List;
23118 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
23119 end if;
23121 -- Establish the mapping
23123 -- Assoc_Nod -> (Itype, ...)
23125 -- Avoid inserting the same itype multiple times. This involves a
23126 -- linear search, however the set of itypes with the same associated
23127 -- node is very small.
23129 Append_Unique_Elmt (Itype, Itypes);
23130 end Add_Pending_Itype;
23132 ----------------------
23133 -- Build_NCT_Tables --
23134 ----------------------
23136 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
23137 Elmt : Elmt_Id;
23138 Old_Id : Entity_Id;
23139 New_Id : Entity_Id;
23141 begin
23142 -- Nothing to do when there is no entity map
23144 if No (Entity_Map) then
23145 return;
23146 end if;
23148 Elmt := First_Elmt (Entity_Map);
23149 while Present (Elmt) loop
23151 -- Extract the (Old_Id, New_Id) pair from the entity map
23153 Old_Id := Node (Elmt);
23154 Next_Elmt (Elmt);
23156 New_Id := Node (Elmt);
23157 Next_Elmt (Elmt);
23159 -- Establish the following mapping within table NCT_New_Entities
23161 -- Old_Id -> New_Id
23163 Add_New_Entity (Old_Id, New_Id);
23165 -- Establish the following mapping within table NCT_Pending_Itypes
23166 -- when the new entity is an itype.
23168 -- Assoc_Nod -> (New_Id, ...)
23170 -- IMPORTANT: the associated node is that of the old itype because
23171 -- the node will be replicated in Phase 2.
23173 if Is_Itype (Old_Id) then
23174 Add_Pending_Itype
23175 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
23176 Itype => New_Id);
23177 end if;
23178 end loop;
23179 end Build_NCT_Tables;
23181 ------------------------------------
23182 -- Copy_Any_Node_With_Replacement --
23183 ------------------------------------
23185 function Copy_Any_Node_With_Replacement
23186 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
23188 begin
23189 if Nkind (N) in N_Entity then
23190 return Corresponding_Entity (N);
23191 else
23192 return Copy_Node_With_Replacement (N);
23193 end if;
23194 end Copy_Any_Node_With_Replacement;
23196 ---------------------------------
23197 -- Copy_Elist_With_Replacement --
23198 ---------------------------------
23200 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
23201 Elmt : Elmt_Id;
23202 Result : Elist_Id;
23204 begin
23205 -- Copy the contents of the old list. Note that the list itself may
23206 -- be empty, in which case the routine returns a new empty list. This
23207 -- avoids sharing lists between subtrees. The element of an entity
23208 -- list could be an entity or a node, hence the invocation of routine
23209 -- Copy_Any_Node_With_Replacement.
23211 if Present (List) then
23212 Result := New_Elmt_List;
23214 Elmt := First_Elmt (List);
23215 while Present (Elmt) loop
23216 Append_Elmt
23217 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
23219 Next_Elmt (Elmt);
23220 end loop;
23222 -- Otherwise the list does not exist
23224 else
23225 Result := No_Elist;
23226 end if;
23228 return Result;
23229 end Copy_Elist_With_Replacement;
23231 ---------------------------------
23232 -- Copy_Field_With_Replacement --
23233 ---------------------------------
23235 function Copy_Field_With_Replacement
23236 (Field : Union_Id;
23237 Old_Par : Node_Id := Empty;
23238 New_Par : Node_Id := Empty;
23239 Semantic : Boolean := False) return Union_Id
23241 begin
23242 -- The field is empty
23244 if Field = Union_Id (Empty) then
23245 return Field;
23247 -- The field is an entity/itype/node
23249 elsif Field in Node_Range then
23250 declare
23251 Old_N : constant Node_Id := Node_Id (Field);
23252 Syntactic : constant Boolean :=
23253 Is_Syntactic_Node (Source => Old_Par, Field => Old_N);
23255 New_N : Node_Id;
23257 begin
23258 -- The field is an entity/itype
23260 if Nkind (Old_N) in N_Entity then
23262 -- An entity/itype is always replicated
23264 New_N := Corresponding_Entity (Old_N);
23266 -- Update the parent pointer when the entity is a syntactic
23267 -- field. Note that itypes do not have parent pointers.
23269 if Syntactic and then New_N /= Old_N then
23270 Set_Parent (New_N, New_Par);
23271 end if;
23273 -- The field is a node
23275 else
23276 -- A node is replicated when it is either a syntactic field
23277 -- or when the caller treats it as a semantic attribute.
23279 if Syntactic or else Semantic then
23280 New_N := Copy_Node_With_Replacement (Old_N);
23282 -- Update the parent pointer when the node is a syntactic
23283 -- field.
23285 if Syntactic and then New_N /= Old_N then
23286 Set_Parent (New_N, New_Par);
23287 end if;
23289 -- Otherwise the node is returned unchanged
23291 else
23292 New_N := Old_N;
23293 end if;
23294 end if;
23296 return Union_Id (New_N);
23297 end;
23299 -- The field is an entity list
23301 elsif Field in Elist_Range then
23302 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
23304 -- The field is a syntactic list
23306 elsif Field in List_Range then
23307 declare
23308 Old_List : constant List_Id := List_Id (Field);
23309 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
23311 New_List : List_Id;
23313 begin
23314 -- A list is replicated when it is either a syntactic field or
23315 -- when the caller treats it as a semantic attribute.
23317 if Syntactic or else Semantic then
23318 New_List := Copy_List_With_Replacement (Old_List);
23320 -- Update the parent pointer when the list is a syntactic
23321 -- field.
23323 if Syntactic and then New_List /= Old_List then
23324 Set_Parent (New_List, New_Par);
23325 end if;
23327 -- Otherwise the list is returned unchanged
23329 else
23330 New_List := Old_List;
23331 end if;
23333 return Union_Id (New_List);
23334 end;
23336 -- Otherwise the field denotes an attribute that does not need to be
23337 -- replicated (Chars, literals, etc).
23339 else
23340 return Field;
23341 end if;
23342 end Copy_Field_With_Replacement;
23344 --------------------------------
23345 -- Copy_List_With_Replacement --
23346 --------------------------------
23348 function Copy_List_With_Replacement (List : List_Id) return List_Id is
23349 Elmt : Node_Id;
23350 Result : List_Id;
23352 begin
23353 -- Copy the contents of the old list. Note that the list itself may
23354 -- be empty, in which case the routine returns a new empty list. This
23355 -- avoids sharing lists between subtrees. The element of a syntactic
23356 -- list is always a node, never an entity or itype, hence the call to
23357 -- routine Copy_Node_With_Replacement.
23359 if Present (List) then
23360 Result := New_List;
23362 Elmt := First (List);
23363 while Present (Elmt) loop
23364 Append (Copy_Node_With_Replacement (Elmt), Result);
23366 Next (Elmt);
23367 end loop;
23369 -- Otherwise the list does not exist
23371 else
23372 Result := No_List;
23373 end if;
23375 return Result;
23376 end Copy_List_With_Replacement;
23378 --------------------------------
23379 -- Copy_Node_With_Replacement --
23380 --------------------------------
23382 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
23383 Result : Node_Id;
23385 function Transform (U : Union_Id) return Union_Id;
23386 -- Copies one field, replacing N with Result
23388 ---------------
23389 -- Transform --
23390 ---------------
23392 function Transform (U : Union_Id) return Union_Id is
23393 begin
23394 return Copy_Field_With_Replacement
23395 (Field => U,
23396 Old_Par => N,
23397 New_Par => Result);
23398 end Transform;
23400 procedure Walk is new Walk_Sinfo_Fields_Pairwise (Transform);
23402 -- Start of processing for Copy_Node_With_Replacement
23404 begin
23405 -- Assume that the node must be returned unchanged
23407 Result := N;
23409 if N > Empty_Or_Error then
23410 pragma Assert (Nkind (N) not in N_Entity);
23412 Result := New_Copy (N);
23414 Walk (Result, Result);
23416 -- Update the Comes_From_Source and Sloc attributes of the node
23417 -- in case the caller has supplied new values.
23419 Update_CFS_Sloc (Result);
23421 -- Update the Associated_Node_For_Itype attribute of all itypes
23422 -- created during Phase 1 whose associated node is N. As a result
23423 -- the Associated_Node_For_Itype refers to the replicated node.
23424 -- No action needs to be taken when the Associated_Node_For_Itype
23425 -- refers to an entity because this was already handled during
23426 -- Phase 1, in Visit_Itype.
23428 Update_Pending_Itypes
23429 (Old_Assoc => N,
23430 New_Assoc => Result);
23432 -- Update the First/Next_Named_Association chain and the
23433 -- Controlling_Argument for a replicated call.
23435 if Nkind (N) in N_Entry_Call_Statement
23436 | N_Subprogram_Call
23437 then
23438 Update_Named_Associations
23439 (Old_Call => N,
23440 New_Call => Result);
23442 if Nkind (N) in N_Subprogram_Call then
23443 Update_Controlling_Argument
23444 (Old_Call => N,
23445 New_Call => Result);
23446 end if;
23448 -- Update the Renamed_Object attribute of a replicated object
23449 -- declaration.
23451 elsif Nkind (N) = N_Object_Renaming_Declaration then
23452 Set_Renamed_Object_Of_Possibly_Void
23453 (Defining_Entity (Result), Name (Result));
23455 -- Update the Chars attribute of identifiers
23457 elsif Nkind (N) = N_Identifier then
23459 -- The Entity field of identifiers that denote aspects is used
23460 -- to store arbitrary expressions (and hence we must check that
23461 -- they reference an actual entity before copying their Chars
23462 -- value).
23464 if Present (Entity (Result))
23465 and then Nkind (Entity (Result)) in N_Entity
23466 then
23467 Set_Chars (Result, Chars (Entity (Result)));
23468 end if;
23469 end if;
23470 end if;
23472 return Result;
23473 end Copy_Node_With_Replacement;
23475 --------------------------
23476 -- Corresponding_Entity --
23477 --------------------------
23479 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
23480 New_Id : Entity_Id;
23481 Result : Entity_Id;
23483 begin
23484 -- Assume that the entity must be returned unchanged
23486 Result := Id;
23488 if Id > Empty_Or_Error then
23489 pragma Assert (Nkind (Id) in N_Entity);
23491 -- Determine whether the entity has a corresponding new entity
23492 -- generated during Phase 1 and if it does, use it.
23494 if NCT_Tables_In_Use then
23495 New_Id := NCT_New_Entities.Get (Id);
23497 if Present (New_Id) then
23498 Result := New_Id;
23499 end if;
23500 end if;
23501 end if;
23503 return Result;
23504 end Corresponding_Entity;
23506 -------------------
23507 -- In_Entity_Map --
23508 -------------------
23510 function In_Entity_Map
23511 (Id : Entity_Id;
23512 Entity_Map : Elist_Id) return Boolean
23514 Elmt : Elmt_Id;
23515 Old_Id : Entity_Id;
23517 begin
23518 -- The entity map contains pairs (Old_Id, New_Id). The advancement
23519 -- step always skips the New_Id portion of the pair.
23521 if Present (Entity_Map) then
23522 Elmt := First_Elmt (Entity_Map);
23523 while Present (Elmt) loop
23524 Old_Id := Node (Elmt);
23526 if Old_Id = Id then
23527 return True;
23528 end if;
23530 Next_Elmt (Elmt);
23531 Next_Elmt (Elmt);
23532 end loop;
23533 end if;
23535 return False;
23536 end In_Entity_Map;
23538 ---------------------
23539 -- Update_CFS_Sloc --
23540 ---------------------
23542 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
23543 begin
23544 -- A new source location defaults the Comes_From_Source attribute
23546 if New_Sloc /= No_Location then
23547 Set_Comes_From_Source (N, Get_Comes_From_Source_Default);
23548 Set_Sloc (N, New_Sloc);
23549 end if;
23550 end Update_CFS_Sloc;
23552 ---------------------------------
23553 -- Update_Controlling_Argument --
23554 ---------------------------------
23556 procedure Update_Controlling_Argument
23557 (Old_Call : Node_Id;
23558 New_Call : Node_Id)
23560 New_Act : Node_Id;
23561 Old_Act : Node_Id;
23563 Old_Ctrl_Arg : constant Node_Id := Controlling_Argument (Old_Call);
23564 -- Controlling argument of the old call node
23566 Replaced : Boolean := False;
23567 -- Flag to make sure that replacement works as expected
23569 begin
23570 if No (Old_Ctrl_Arg) then
23571 return;
23572 end if;
23574 -- Recreate the Controlling_Argument of a call by traversing both the
23575 -- old and new actual parameters in parallel.
23577 New_Act := First (Parameter_Associations (New_Call));
23578 Old_Act := First (Parameter_Associations (Old_Call));
23579 while Present (Old_Act) loop
23581 -- Actual parameter appears either in a named parameter
23582 -- association or directly.
23584 if Nkind (Old_Act) = N_Parameter_Association then
23585 if Explicit_Actual_Parameter (Old_Act) = Old_Ctrl_Arg then
23586 Set_Controlling_Argument
23587 (New_Call, Explicit_Actual_Parameter (New_Act));
23588 Replaced := True;
23589 exit;
23590 end if;
23592 elsif Old_Act = Old_Ctrl_Arg then
23593 Set_Controlling_Argument (New_Call, New_Act);
23594 Replaced := True;
23595 exit;
23596 end if;
23598 Next (New_Act);
23599 Next (Old_Act);
23600 end loop;
23602 pragma Assert (Replaced);
23603 end Update_Controlling_Argument;
23605 -------------------------------
23606 -- Update_Named_Associations --
23607 -------------------------------
23609 procedure Update_Named_Associations
23610 (Old_Call : Node_Id;
23611 New_Call : Node_Id)
23613 New_Act : Node_Id;
23614 New_Next : Node_Id;
23615 Old_Act : Node_Id;
23616 Old_Next : Node_Id;
23618 begin
23619 if No (First_Named_Actual (Old_Call)) then
23620 return;
23621 end if;
23623 -- Recreate the First/Next_Named_Actual chain of a call by traversing
23624 -- the chains of both the old and new calls in parallel.
23626 New_Act := First (Parameter_Associations (New_Call));
23627 Old_Act := First (Parameter_Associations (Old_Call));
23628 while Present (Old_Act) loop
23629 if Nkind (Old_Act) = N_Parameter_Association
23630 and then Explicit_Actual_Parameter (Old_Act)
23631 = First_Named_Actual (Old_Call)
23632 then
23633 Set_First_Named_Actual (New_Call,
23634 Explicit_Actual_Parameter (New_Act));
23635 end if;
23637 if Nkind (Old_Act) = N_Parameter_Association
23638 and then Present (Next_Named_Actual (Old_Act))
23639 then
23640 -- Scan the actual parameter list to find the next suitable
23641 -- named actual. Note that the list may be out of order.
23643 New_Next := First (Parameter_Associations (New_Call));
23644 Old_Next := First (Parameter_Associations (Old_Call));
23645 while Nkind (Old_Next) /= N_Parameter_Association
23646 or else Explicit_Actual_Parameter (Old_Next) /=
23647 Next_Named_Actual (Old_Act)
23648 loop
23649 Next (New_Next);
23650 Next (Old_Next);
23651 end loop;
23653 Set_Next_Named_Actual (New_Act,
23654 Explicit_Actual_Parameter (New_Next));
23655 end if;
23657 Next (New_Act);
23658 Next (Old_Act);
23659 end loop;
23660 end Update_Named_Associations;
23662 -------------------------
23663 -- Update_New_Entities --
23664 -------------------------
23666 procedure Update_New_Entities (Entity_Map : Elist_Id) is
23667 New_Id : Entity_Id := Empty;
23668 Old_Id : Entity_Id := Empty;
23670 begin
23671 if NCT_Tables_In_Use then
23672 NCT_New_Entities.Get_First (Old_Id, New_Id);
23674 -- Update the semantic fields of all new entities created during
23675 -- Phase 1 which were not supplied via an entity map.
23676 -- ??? Is there a better way of distinguishing those?
23678 while Present (Old_Id) and then Present (New_Id) loop
23679 if not In_Entity_Map (Old_Id, Entity_Map) then
23680 Update_Semantic_Fields (New_Id);
23681 end if;
23683 NCT_New_Entities.Get_Next (Old_Id, New_Id);
23684 end loop;
23685 end if;
23686 end Update_New_Entities;
23688 ---------------------------
23689 -- Update_Pending_Itypes --
23690 ---------------------------
23692 procedure Update_Pending_Itypes
23693 (Old_Assoc : Node_Id;
23694 New_Assoc : Node_Id)
23696 Item : Elmt_Id;
23697 Itypes : Elist_Id;
23699 begin
23700 if NCT_Tables_In_Use then
23701 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
23703 -- Update the Associated_Node_For_Itype attribute for all itypes
23704 -- which originally refer to Old_Assoc to designate New_Assoc.
23706 if Present (Itypes) then
23707 Item := First_Elmt (Itypes);
23708 while Present (Item) loop
23709 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
23711 Next_Elmt (Item);
23712 end loop;
23713 end if;
23714 end if;
23715 end Update_Pending_Itypes;
23717 ----------------------------
23718 -- Update_Semantic_Fields --
23719 ----------------------------
23721 procedure Update_Semantic_Fields (Id : Entity_Id) is
23722 begin
23723 -- Discriminant_Constraint
23725 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
23726 Set_Discriminant_Constraint (Id, Elist_Id (
23727 Copy_Field_With_Replacement
23728 (Field => Union_Id (Discriminant_Constraint (Id)),
23729 Semantic => True)));
23730 end if;
23732 -- Etype
23734 Set_Etype (Id, Node_Id (
23735 Copy_Field_With_Replacement
23736 (Field => Union_Id (Etype (Id)),
23737 Semantic => True)));
23739 -- First_Index
23740 -- Packed_Array_Impl_Type
23742 if Is_Array_Type (Id) then
23743 if Present (First_Index (Id)) then
23744 Set_First_Index (Id, First (List_Id (
23745 Copy_Field_With_Replacement
23746 (Field => Union_Id (List_Containing (First_Index (Id))),
23747 Semantic => True))));
23748 end if;
23750 if Is_Packed (Id) then
23751 Set_Packed_Array_Impl_Type (Id, Node_Id (
23752 Copy_Field_With_Replacement
23753 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
23754 Semantic => True)));
23755 end if;
23756 end if;
23758 -- Prev_Entity
23760 Set_Prev_Entity (Id, Node_Id (
23761 Copy_Field_With_Replacement
23762 (Field => Union_Id (Prev_Entity (Id)),
23763 Semantic => True)));
23765 -- Next_Entity
23767 Set_Next_Entity (Id, Node_Id (
23768 Copy_Field_With_Replacement
23769 (Field => Union_Id (Next_Entity (Id)),
23770 Semantic => True)));
23772 -- Scalar_Range
23774 if Is_Discrete_Type (Id) then
23775 Set_Scalar_Range (Id, Node_Id (
23776 Copy_Field_With_Replacement
23777 (Field => Union_Id (Scalar_Range (Id)),
23778 Semantic => True)));
23779 end if;
23781 -- Scope
23783 -- Update the scope when the caller specified an explicit one
23785 if Present (New_Scope) then
23786 Set_Scope (Id, New_Scope);
23787 else
23788 Set_Scope (Id, Node_Id (
23789 Copy_Field_With_Replacement
23790 (Field => Union_Id (Scope (Id)),
23791 Semantic => True)));
23792 end if;
23793 end Update_Semantic_Fields;
23795 --------------------
23796 -- Visit_Any_Node --
23797 --------------------
23799 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
23800 begin
23801 if Nkind (N) in N_Entity then
23802 if Is_Itype (N) then
23803 Visit_Itype (N);
23804 else
23805 Visit_Entity (N);
23806 end if;
23807 else
23808 Visit_Node (N);
23809 end if;
23810 end Visit_Any_Node;
23812 -----------------
23813 -- Visit_Elist --
23814 -----------------
23816 procedure Visit_Elist (List : Elist_Id) is
23817 Elmt : Elmt_Id;
23819 begin
23820 -- The element of an entity list could be an entity, itype, or a
23821 -- node, hence the call to Visit_Any_Node.
23823 if Present (List) then
23824 Elmt := First_Elmt (List);
23825 while Present (Elmt) loop
23826 Visit_Any_Node (Node (Elmt));
23828 Next_Elmt (Elmt);
23829 end loop;
23830 end if;
23831 end Visit_Elist;
23833 ------------------
23834 -- Visit_Entity --
23835 ------------------
23837 procedure Visit_Entity (Id : Entity_Id) is
23838 New_Id : Entity_Id;
23840 begin
23841 pragma Assert (Nkind (Id) in N_Entity);
23842 pragma Assert (not Is_Itype (Id));
23844 -- Nothing to do when the entity is not defined in the Actions list
23845 -- of an N_Expression_With_Actions node.
23847 if EWA_Level = 0 then
23848 return;
23850 -- Nothing to do when the entity is defined in a scoping construct
23851 -- within an N_Expression_With_Actions node.
23853 elsif EWA_Inner_Scope_Level > 0 then
23854 return;
23856 -- Nothing to do when the entity does not denote a construct that
23857 -- may appear within an N_Expression_With_Actions node. Relaxing
23858 -- this restriction leads to a performance penalty.
23860 -- ??? this list is flaky, and may hide dormant bugs
23861 -- Should functions be included???
23863 -- Quantified expressions contain an entity declaration that must
23864 -- always be replaced when the expander is active, even if it has
23865 -- not been analyzed yet like e.g. in predicates.
23867 elsif Ekind (Id) not in E_Block
23868 | E_Constant
23869 | E_Label
23870 | E_Procedure
23871 | E_Variable
23872 and then not Is_Entity_Of_Quantified_Expression (Id)
23873 and then not Is_Type (Id)
23874 then
23875 return;
23877 -- Nothing to do when the entity was already visited
23879 elsif NCT_Tables_In_Use
23880 and then Present (NCT_New_Entities.Get (Id))
23881 then
23882 return;
23884 -- Nothing to do when the declaration node of the entity is not in
23885 -- the subtree being replicated.
23887 elsif not In_Subtree
23888 (N => Declaration_Node (Id),
23889 Root => Source)
23890 then
23891 return;
23892 end if;
23894 -- Create a new entity by directly copying the old entity. This
23895 -- action causes all attributes of the old entity to be inherited.
23897 New_Id := New_Copy (Id);
23899 -- Create a new name for the new entity because the back end needs
23900 -- distinct names for debugging purposes, provided that the entity
23901 -- has already been analyzed.
23903 if Ekind (Id) /= E_Void then
23904 Set_Chars (New_Id, New_Internal_Name ('T'));
23905 end if;
23907 -- Update the Comes_From_Source and Sloc attributes of the entity in
23908 -- case the caller has supplied new values.
23910 Update_CFS_Sloc (New_Id);
23912 -- Establish the following mapping within table NCT_New_Entities:
23914 -- Id -> New_Id
23916 Add_New_Entity (Id, New_Id);
23918 -- Deal with the semantic fields of entities. The fields are visited
23919 -- because they may mention entities which reside within the subtree
23920 -- being copied.
23922 Visit_Semantic_Fields (Id);
23923 end Visit_Entity;
23925 -----------------
23926 -- Visit_Field --
23927 -----------------
23929 procedure Visit_Field
23930 (Field : Union_Id;
23931 Par_Nod : Node_Id := Empty;
23932 Semantic : Boolean := False)
23934 begin
23935 -- The field is empty
23937 if Field = Union_Id (Empty) then
23938 return;
23940 -- The field is an entity/itype/node
23942 elsif Field in Node_Range then
23943 declare
23944 N : constant Node_Id := Node_Id (Field);
23946 begin
23947 -- The field is an entity/itype
23949 if Nkind (N) in N_Entity then
23951 -- Itypes are always visited
23953 if Is_Itype (N) then
23954 Visit_Itype (N);
23956 -- An entity is visited when it is either a syntactic field
23957 -- or when the caller treats it as a semantic attribute.
23959 elsif Parent (N) = Par_Nod or else Semantic then
23960 Visit_Entity (N);
23961 end if;
23963 -- The field is a node
23965 else
23966 -- A node is visited when it is either a syntactic field or
23967 -- when the caller treats it as a semantic attribute.
23969 if Parent (N) = Par_Nod or else Semantic then
23970 Visit_Node (N);
23971 end if;
23972 end if;
23973 end;
23975 -- The field is an entity list
23977 elsif Field in Elist_Range then
23978 Visit_Elist (Elist_Id (Field));
23980 -- The field is a syntax list
23982 elsif Field in List_Range then
23983 declare
23984 List : constant List_Id := List_Id (Field);
23986 begin
23987 -- A syntax list is visited when it is either a syntactic field
23988 -- or when the caller treats it as a semantic attribute.
23990 if Parent (List) = Par_Nod or else Semantic then
23991 Visit_List (List);
23992 end if;
23993 end;
23995 -- Otherwise the field denotes information which does not need to be
23996 -- visited (chars, literals, etc.).
23998 else
23999 null;
24000 end if;
24001 end Visit_Field;
24003 -----------------
24004 -- Visit_Itype --
24005 -----------------
24007 procedure Visit_Itype (Itype : Entity_Id) is
24008 New_Assoc : Node_Id;
24009 New_Itype : Entity_Id;
24010 Old_Assoc : Node_Id;
24012 begin
24013 pragma Assert (Nkind (Itype) in N_Entity);
24014 pragma Assert (Is_Itype (Itype));
24016 -- Itypes that describe the designated type of access to subprograms
24017 -- have the structure of subprogram declarations, with signatures,
24018 -- etc. Either we duplicate the signatures completely, or choose to
24019 -- share such itypes, which is fine because their elaboration will
24020 -- have no side effects.
24022 if Ekind (Itype) = E_Subprogram_Type then
24023 return;
24025 -- Nothing to do if the itype was already visited
24027 elsif NCT_Tables_In_Use
24028 and then Present (NCT_New_Entities.Get (Itype))
24029 then
24030 return;
24032 -- Nothing to do if the associated node of the itype is not within
24033 -- the subtree being replicated.
24035 elsif not In_Subtree
24036 (N => Associated_Node_For_Itype (Itype),
24037 Root => Source)
24038 then
24039 return;
24040 end if;
24042 -- Create a new itype by directly copying the old itype. This action
24043 -- causes all attributes of the old itype to be inherited.
24045 New_Itype := New_Copy (Itype);
24047 -- Create a new name for the new itype because the back end requires
24048 -- distinct names for debugging purposes.
24050 Set_Chars (New_Itype, New_Internal_Name ('T'));
24052 -- Update the Comes_From_Source and Sloc attributes of the itype in
24053 -- case the caller has supplied new values.
24055 Update_CFS_Sloc (New_Itype);
24057 -- Establish the following mapping within table NCT_New_Entities:
24059 -- Itype -> New_Itype
24061 Add_New_Entity (Itype, New_Itype);
24063 -- The new itype must be unfrozen because the resulting subtree may
24064 -- be inserted anywhere and cause an earlier or later freezing.
24066 if Present (Freeze_Node (New_Itype)) then
24067 Set_Freeze_Node (New_Itype, Empty);
24068 Set_Is_Frozen (New_Itype, False);
24069 end if;
24071 -- If a record subtype is simply copied, the entity list will be
24072 -- shared, so Cloned_Subtype must be set to indicate this.
24074 if Ekind (Itype) in E_Class_Wide_Subtype | E_Record_Subtype then
24075 Set_Cloned_Subtype (New_Itype, Itype);
24076 end if;
24078 -- The associated node may denote an entity, in which case it may
24079 -- already have a new corresponding entity created during a prior
24080 -- call to Visit_Entity or Visit_Itype for the same subtree.
24082 -- Given
24083 -- Old_Assoc ---------> New_Assoc
24085 -- Created by Visit_Itype
24086 -- Itype -------------> New_Itype
24087 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
24089 -- In the example above, Old_Assoc is an arbitrary entity that was
24090 -- already visited for the same subtree and has a corresponding new
24091 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
24092 -- of copying entities, however it must be updated to New_Assoc.
24094 Old_Assoc := Associated_Node_For_Itype (Itype);
24096 if Nkind (Old_Assoc) in N_Entity then
24097 if NCT_Tables_In_Use then
24098 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
24100 if Present (New_Assoc) then
24101 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
24102 end if;
24103 end if;
24105 -- Otherwise the associated node denotes a node. Postpone the update
24106 -- until Phase 2 when the node is replicated. Establish the following
24107 -- mapping within table NCT_Pending_Itypes:
24109 -- Old_Assoc -> (New_Type, ...)
24111 else
24112 Add_Pending_Itype (Old_Assoc, New_Itype);
24113 end if;
24115 -- Deal with the semantic fields of itypes. The fields are visited
24116 -- because they may mention entities that reside within the subtree
24117 -- being copied.
24119 Visit_Semantic_Fields (Itype);
24120 end Visit_Itype;
24122 ----------------
24123 -- Visit_List --
24124 ----------------
24126 procedure Visit_List (List : List_Id) is
24127 Elmt : Node_Id;
24129 begin
24130 -- Note that the element of a syntactic list is always a node, never
24131 -- an entity or itype, hence the call to Visit_Node.
24133 Elmt := First (List);
24134 while Present (Elmt) loop
24135 Visit_Node (Elmt);
24137 Next (Elmt);
24138 end loop;
24139 end Visit_List;
24141 ----------------
24142 -- Visit_Node --
24143 ----------------
24145 procedure Visit_Node (N : Node_Id) is
24146 begin
24147 pragma Assert (Nkind (N) not in N_Entity);
24149 -- If the node is a quantified expression and expander is active,
24150 -- it contains an implicit declaration that may require a new entity
24151 -- when the condition has already been (pre)analyzed.
24153 if Nkind (N) = N_Expression_With_Actions
24154 or else
24155 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
24156 then
24157 EWA_Level := EWA_Level + 1;
24159 elsif EWA_Level > 0
24160 and then Nkind (N) in N_Block_Statement
24161 | N_Subprogram_Body
24162 | N_Subprogram_Declaration
24163 then
24164 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
24165 end if;
24167 -- If the node is a block, we need to process all declarations
24168 -- in the block and make new entities for each.
24170 if Nkind (N) = N_Block_Statement then
24171 declare
24172 Decl : Node_Id := First (Declarations (N));
24174 begin
24175 while Present (Decl) loop
24176 if Nkind (Decl) = N_Object_Declaration then
24177 Add_New_Entity (Defining_Identifier (Decl),
24178 New_Copy (Defining_Identifier (Decl)));
24179 end if;
24181 Next (Decl);
24182 end loop;
24183 end;
24184 end if;
24186 declare
24187 procedure Action (U : Union_Id);
24188 procedure Action (U : Union_Id) is
24189 begin
24190 Visit_Field (Field => U, Par_Nod => N);
24191 end Action;
24193 procedure Walk is new Walk_Sinfo_Fields (Action);
24194 begin
24195 Walk (N);
24196 end;
24198 if EWA_Level > 0
24199 and then Nkind (N) in N_Block_Statement
24200 | N_Subprogram_Body
24201 | N_Subprogram_Declaration
24202 then
24203 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
24205 elsif Nkind (N) = N_Expression_With_Actions
24206 or else
24207 (Nkind (N) = N_Quantified_Expression and then Expander_Active)
24208 then
24209 EWA_Level := EWA_Level - 1;
24210 end if;
24211 end Visit_Node;
24213 ---------------------------
24214 -- Visit_Semantic_Fields --
24215 ---------------------------
24217 procedure Visit_Semantic_Fields (Id : Entity_Id) is
24218 begin
24219 pragma Assert (Nkind (Id) in N_Entity);
24221 -- Discriminant_Constraint
24223 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
24224 Visit_Field
24225 (Field => Union_Id (Discriminant_Constraint (Id)),
24226 Semantic => True);
24227 end if;
24229 -- Etype
24231 Visit_Field
24232 (Field => Union_Id (Etype (Id)),
24233 Semantic => True);
24235 -- First_Index
24236 -- Packed_Array_Impl_Type
24238 if Is_Array_Type (Id) then
24239 if Present (First_Index (Id)) then
24240 Visit_Field
24241 (Field => Union_Id (List_Containing (First_Index (Id))),
24242 Semantic => True);
24243 end if;
24245 if Is_Packed (Id) then
24246 Visit_Field
24247 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
24248 Semantic => True);
24249 end if;
24250 end if;
24252 -- Scalar_Range
24254 if Is_Discrete_Type (Id) then
24255 Visit_Field
24256 (Field => Union_Id (Scalar_Range (Id)),
24257 Semantic => True);
24258 end if;
24259 end Visit_Semantic_Fields;
24261 -- Start of processing for New_Copy_Tree
24263 begin
24264 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
24265 -- shallow copies for each node within, and then updating the child and
24266 -- parent pointers accordingly. This process is straightforward, however
24267 -- the routine must deal with the following complications:
24269 -- * Entities defined within N_Expression_With_Actions nodes must be
24270 -- replicated rather than shared to avoid introducing two identical
24271 -- symbols within the same scope. Note that no other expression can
24272 -- currently define entities.
24274 -- do
24275 -- Source_Low : ...;
24276 -- Source_High : ...;
24278 -- <reference to Source_Low>
24279 -- <reference to Source_High>
24280 -- in ... end;
24282 -- New_Copy_Tree handles this case by first creating new entities
24283 -- and then updating all existing references to point to these new
24284 -- entities.
24286 -- do
24287 -- New_Low : ...;
24288 -- New_High : ...;
24290 -- <reference to New_Low>
24291 -- <reference to New_High>
24292 -- in ... end;
24294 -- * Itypes defined within the subtree must be replicated to avoid any
24295 -- dependencies on invalid or inaccessible data.
24297 -- subtype Source_Itype is ... range Source_Low .. Source_High;
24299 -- New_Copy_Tree handles this case by first creating a new itype in
24300 -- the same fashion as entities, and then updating various relevant
24301 -- constraints.
24303 -- subtype New_Itype is ... range New_Low .. New_High;
24305 -- * The Associated_Node_For_Itype field of itypes must be updated to
24306 -- reference the proper replicated entity or node.
24308 -- * Semantic fields of entities such as Etype and Scope must be
24309 -- updated to reference the proper replicated entities.
24311 -- * Some semantic fields of nodes must be updated to reference
24312 -- the proper replicated nodes.
24314 -- Finally, quantified expressions contain an implicit declaration for
24315 -- the bound variable. Given that quantified expressions appearing
24316 -- in contracts are copied to create pragmas and eventually checking
24317 -- procedures, a new bound variable must be created for each copy, to
24318 -- prevent multiple declarations of the same symbol.
24320 -- To meet all these demands, routine New_Copy_Tree is split into two
24321 -- phases.
24323 -- Phase 1 traverses the tree in order to locate entities and itypes
24324 -- defined within the subtree. New entities are generated and saved in
24325 -- table NCT_New_Entities. The semantic fields of all new entities and
24326 -- itypes are then updated accordingly.
24328 -- Phase 2 traverses the tree in order to replicate each node. Various
24329 -- semantic fields of nodes and entities are updated accordingly.
24331 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
24332 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
24333 -- data inside.
24335 if NCT_Tables_In_Use then
24336 NCT_Tables_In_Use := False;
24338 NCT_New_Entities.Reset;
24339 NCT_Pending_Itypes.Reset;
24340 end if;
24342 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
24343 -- supplied by a linear entity map. The tables offer faster access to
24344 -- the same data.
24346 Build_NCT_Tables (Map);
24348 -- Execute Phase 1. Traverse the subtree and generate new entities for
24349 -- the following cases:
24351 -- * An entity defined within an N_Expression_With_Actions node
24353 -- * An itype referenced within the subtree where the associated node
24354 -- is also in the subtree.
24356 -- All new entities are accessible via table NCT_New_Entities, which
24357 -- contains mappings of the form:
24359 -- Old_Entity -> New_Entity
24360 -- Old_Itype -> New_Itype
24362 -- In addition, the associated nodes of all new itypes are mapped in
24363 -- table NCT_Pending_Itypes:
24365 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
24367 Visit_Any_Node (Source);
24369 -- Update the semantic attributes of all new entities generated during
24370 -- Phase 1 before starting Phase 2. The updates could be performed in
24371 -- routine Corresponding_Entity, however this may cause the same entity
24372 -- to be updated multiple times, effectively generating useless nodes.
24373 -- Keeping the updates separates from Phase 2 ensures that only one set
24374 -- of attributes is generated for an entity at any one time.
24376 Update_New_Entities (Map);
24378 -- Execute Phase 2. Replicate the source subtree one node at a time.
24379 -- The following transformations take place:
24381 -- * References to entities and itypes are updated to refer to the
24382 -- new entities and itypes generated during Phase 1.
24384 -- * All Associated_Node_For_Itype attributes of itypes are updated
24385 -- to refer to the new replicated Associated_Node_For_Itype.
24387 return Copy_Node_With_Replacement (Source);
24388 end New_Copy_Tree;
24390 -------------------------
24391 -- New_External_Entity --
24392 -------------------------
24394 function New_External_Entity
24395 (Kind : Entity_Kind;
24396 Scope_Id : Entity_Id;
24397 Sloc_Value : Source_Ptr;
24398 Related_Id : Entity_Id;
24399 Suffix : Character;
24400 Suffix_Index : Int := 0;
24401 Prefix : Character := ' ') return Entity_Id
24403 N : constant Entity_Id :=
24404 Make_Defining_Identifier (Sloc_Value,
24405 New_External_Name
24406 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
24408 begin
24409 Mutate_Ekind (N, Kind);
24410 Set_Is_Internal (N, True);
24411 Append_Entity (N, Scope_Id);
24412 Set_Public_Status (N);
24414 if Kind in Type_Kind then
24415 Reinit_Size_Align (N);
24416 end if;
24418 return N;
24419 end New_External_Entity;
24421 -------------------------
24422 -- New_Internal_Entity --
24423 -------------------------
24425 function New_Internal_Entity
24426 (Kind : Entity_Kind;
24427 Scope_Id : Entity_Id;
24428 Sloc_Value : Source_Ptr;
24429 Id_Char : Character) return Entity_Id
24431 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
24433 begin
24434 Mutate_Ekind (N, Kind);
24435 Set_Is_Internal (N, True);
24436 Append_Entity (N, Scope_Id);
24438 if Kind in Type_Kind then
24439 Reinit_Size_Align (N);
24440 end if;
24442 return N;
24443 end New_Internal_Entity;
24445 -----------------
24446 -- Next_Actual --
24447 -----------------
24449 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
24450 Par : constant Node_Id := Parent (Actual_Id);
24451 N : Node_Id;
24453 begin
24454 -- If we are pointing at a positional parameter, it is a member of a
24455 -- node list (the list of parameters), and the next parameter is the
24456 -- next node on the list, unless we hit a parameter association, then
24457 -- we shift to using the chain whose head is the First_Named_Actual in
24458 -- the parent, and then is threaded using the Next_Named_Actual of the
24459 -- Parameter_Association. All this fiddling is because the original node
24460 -- list is in the textual call order, and what we need is the
24461 -- declaration order.
24463 if Is_List_Member (Actual_Id) then
24464 N := Next (Actual_Id);
24466 if Nkind (N) = N_Parameter_Association then
24468 -- In case of a build-in-place call, the call will no longer be a
24469 -- call; it will have been rewritten.
24471 if Nkind (Par) in N_Entry_Call_Statement
24472 | N_Function_Call
24473 | N_Procedure_Call_Statement
24474 then
24475 return First_Named_Actual (Par);
24477 -- In case of a call rewritten in GNATprove mode while "inlining
24478 -- for proof" go to the original call.
24480 elsif Nkind (Par) = N_Null_Statement then
24481 pragma Assert
24482 (GNATprove_Mode
24483 and then
24484 Nkind (Original_Node (Par)) in N_Subprogram_Call);
24486 return First_Named_Actual (Original_Node (Par));
24487 else
24488 return Empty;
24489 end if;
24490 else
24491 return N;
24492 end if;
24494 else
24495 return Next_Named_Actual (Parent (Actual_Id));
24496 end if;
24497 end Next_Actual;
24499 procedure Next_Actual (Actual_Id : in out Node_Id) is
24500 begin
24501 Actual_Id := Next_Actual (Actual_Id);
24502 end Next_Actual;
24504 -----------------
24505 -- Next_Global --
24506 -----------------
24508 function Next_Global (Node : Node_Id) return Node_Id is
24509 begin
24510 -- The global item may either be in a list, or by itself, in which case
24511 -- there is no next global item with the same mode.
24513 if Is_List_Member (Node) then
24514 return Next (Node);
24515 else
24516 return Empty;
24517 end if;
24518 end Next_Global;
24520 procedure Next_Global (Node : in out Node_Id) is
24521 begin
24522 Node := Next_Global (Node);
24523 end Next_Global;
24525 ------------------------
24526 -- No_Caching_Enabled --
24527 ------------------------
24529 function No_Caching_Enabled (Id : Entity_Id) return Boolean is
24530 Prag : constant Node_Id := Get_Pragma (Id, Pragma_No_Caching);
24531 Arg1 : Node_Id;
24533 begin
24534 if Present (Prag) then
24535 Arg1 := First (Pragma_Argument_Associations (Prag));
24537 -- The pragma has an optional Boolean expression, the related
24538 -- property is enabled only when the expression evaluates to True.
24540 if Present (Arg1) then
24541 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
24543 -- Otherwise the lack of expression enables the property by
24544 -- default.
24546 else
24547 return True;
24548 end if;
24550 -- The property was never set in the first place
24552 else
24553 return False;
24554 end if;
24555 end No_Caching_Enabled;
24557 --------------------------
24558 -- No_Heap_Finalization --
24559 --------------------------
24561 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
24562 begin
24563 if Ekind (Typ) in E_Access_Type | E_General_Access_Type
24564 and then Is_Library_Level_Entity (Typ)
24565 then
24566 -- A global No_Heap_Finalization pragma applies to all library-level
24567 -- named access-to-object types.
24569 if Present (No_Heap_Finalization_Pragma) then
24570 return True;
24572 -- The library-level named access-to-object type itself is subject to
24573 -- pragma No_Heap_Finalization.
24575 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
24576 return True;
24577 end if;
24578 end if;
24580 return False;
24581 end No_Heap_Finalization;
24583 -----------------------
24584 -- Normalize_Actuals --
24585 -----------------------
24587 -- Chain actuals according to formals of subprogram. If there are no named
24588 -- associations, the chain is simply the list of Parameter Associations,
24589 -- since the order is the same as the declaration order. If there are named
24590 -- associations, then the First_Named_Actual field in the N_Function_Call
24591 -- or N_Procedure_Call_Statement node points to the Parameter_Association
24592 -- node for the parameter that comes first in declaration order. The
24593 -- remaining named parameters are then chained in declaration order using
24594 -- Next_Named_Actual.
24596 -- This routine also verifies that the number of actuals is compatible with
24597 -- the number and default values of formals, but performs no type checking
24598 -- (type checking is done by the caller).
24600 -- If the matching succeeds, Success is set to True and the caller proceeds
24601 -- with type-checking. If the match is unsuccessful, then Success is set to
24602 -- False, and the caller attempts a different interpretation, if there is
24603 -- one.
24605 -- If the flag Report is on, the call is not overloaded, and a failure to
24606 -- match can be reported here, rather than in the caller.
24608 procedure Normalize_Actuals
24609 (N : Node_Id;
24610 S : Entity_Id;
24611 Report : Boolean;
24612 Success : out Boolean)
24614 Actuals : constant List_Id := Parameter_Associations (N);
24615 Actual : Node_Id := Empty;
24616 Formal : Entity_Id;
24617 Last : Node_Id := Empty;
24618 First_Named : Node_Id := Empty;
24619 Found : Boolean;
24621 Formals_To_Match : Integer := 0;
24622 Actuals_To_Match : Integer := 0;
24624 procedure Chain (A : Node_Id);
24625 -- Add named actual at the proper place in the list, using the
24626 -- Next_Named_Actual link.
24628 function Reporting return Boolean;
24629 -- Determines if an error is to be reported. To report an error, we
24630 -- need Report to be True, and also we do not report errors caused
24631 -- by calls to init procs that occur within other init procs. Such
24632 -- errors must always be cascaded errors, since if all the types are
24633 -- declared correctly, the compiler will certainly build decent calls.
24635 -----------
24636 -- Chain --
24637 -----------
24639 procedure Chain (A : Node_Id) is
24640 begin
24641 if No (Last) then
24643 -- Call node points to first actual in list
24645 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
24647 else
24648 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
24649 end if;
24651 Last := A;
24652 Set_Next_Named_Actual (Last, Empty);
24653 end Chain;
24655 ---------------
24656 -- Reporting --
24657 ---------------
24659 function Reporting return Boolean is
24660 begin
24661 if not Report then
24662 return False;
24664 elsif not Within_Init_Proc then
24665 return True;
24667 elsif Is_Init_Proc (Entity (Name (N))) then
24668 return False;
24670 else
24671 return True;
24672 end if;
24673 end Reporting;
24675 -- Start of processing for Normalize_Actuals
24677 begin
24678 if Is_Access_Type (S) then
24680 -- The name in the call is a function call that returns an access
24681 -- to subprogram. The designated type has the list of formals.
24683 Formal := First_Formal (Designated_Type (S));
24684 else
24685 Formal := First_Formal (S);
24686 end if;
24688 while Present (Formal) loop
24689 Formals_To_Match := Formals_To_Match + 1;
24690 Next_Formal (Formal);
24691 end loop;
24693 -- Find if there is a named association, and verify that no positional
24694 -- associations appear after named ones.
24696 if Present (Actuals) then
24697 Actual := First (Actuals);
24698 end if;
24700 while Present (Actual)
24701 and then Nkind (Actual) /= N_Parameter_Association
24702 loop
24703 Actuals_To_Match := Actuals_To_Match + 1;
24704 Next (Actual);
24705 end loop;
24707 if No (Actual) and Actuals_To_Match = Formals_To_Match then
24709 -- Most common case: positional notation, no defaults
24711 Success := True;
24712 return;
24714 elsif Actuals_To_Match > Formals_To_Match then
24716 -- Too many actuals: will not work
24718 if Reporting then
24719 if Is_Entity_Name (Name (N)) then
24720 Error_Msg_N ("too many arguments in call to&", Name (N));
24721 else
24722 Error_Msg_N ("too many arguments in call", N);
24723 end if;
24724 end if;
24726 Success := False;
24727 return;
24728 end if;
24730 First_Named := Actual;
24732 while Present (Actual) loop
24733 if Nkind (Actual) /= N_Parameter_Association then
24734 Error_Msg_N
24735 ("positional parameters not allowed after named ones", Actual);
24736 Success := False;
24737 return;
24739 else
24740 Actuals_To_Match := Actuals_To_Match + 1;
24741 end if;
24743 Next (Actual);
24744 end loop;
24746 if Present (Actuals) then
24747 Actual := First (Actuals);
24748 end if;
24750 Formal := First_Formal (S);
24751 while Present (Formal) loop
24753 -- Match the formals in order. If the corresponding actual is
24754 -- positional, nothing to do. Else scan the list of named actuals
24755 -- to find the one with the right name.
24757 if Present (Actual)
24758 and then Nkind (Actual) /= N_Parameter_Association
24759 then
24760 Next (Actual);
24761 Actuals_To_Match := Actuals_To_Match - 1;
24762 Formals_To_Match := Formals_To_Match - 1;
24764 else
24765 -- For named parameters, search the list of actuals to find
24766 -- one that matches the next formal name.
24768 Actual := First_Named;
24769 Found := False;
24770 while Present (Actual) loop
24771 if Chars (Selector_Name (Actual)) = Chars (Formal) then
24772 Found := True;
24773 Chain (Actual);
24774 Actuals_To_Match := Actuals_To_Match - 1;
24775 Formals_To_Match := Formals_To_Match - 1;
24776 exit;
24777 end if;
24779 Next (Actual);
24780 end loop;
24782 if not Found then
24783 if Ekind (Formal) /= E_In_Parameter
24784 or else No (Default_Value (Formal))
24785 then
24786 if Reporting then
24787 if (Comes_From_Source (S)
24788 or else Sloc (S) = Standard_Location)
24789 and then Is_Overloadable (S)
24790 then
24791 if No (Actuals)
24792 and then
24793 Nkind (Parent (N)) in N_Procedure_Call_Statement
24794 | N_Function_Call
24795 | N_Parameter_Association
24796 and then Ekind (S) /= E_Function
24797 then
24798 Set_Etype (N, Etype (S));
24800 else
24801 Error_Msg_Name_1 := Chars (S);
24802 Error_Msg_Sloc := Sloc (S);
24803 Error_Msg_NE
24804 ("missing argument for parameter & "
24805 & "in call to % declared #", N, Formal);
24806 end if;
24808 elsif Is_Overloadable (S) then
24809 Error_Msg_Name_1 := Chars (S);
24811 -- Point to type derivation that generated the
24812 -- operation.
24814 Error_Msg_Sloc := Sloc (Parent (S));
24816 Error_Msg_NE
24817 ("missing argument for parameter & "
24818 & "in call to % (inherited) #", N, Formal);
24820 else
24821 Error_Msg_NE
24822 ("missing argument for parameter &", N, Formal);
24823 end if;
24824 end if;
24826 Success := False;
24827 return;
24829 else
24830 Formals_To_Match := Formals_To_Match - 1;
24831 end if;
24832 end if;
24833 end if;
24835 Next_Formal (Formal);
24836 end loop;
24838 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
24839 Success := True;
24840 return;
24842 else
24843 if Reporting then
24845 -- Find some superfluous named actual that did not get
24846 -- attached to the list of associations.
24848 Actual := First (Actuals);
24849 while Present (Actual) loop
24850 if Nkind (Actual) = N_Parameter_Association
24851 and then Actual /= Last
24852 and then No (Next_Named_Actual (Actual))
24853 then
24854 -- A validity check may introduce a copy of a call that
24855 -- includes an extra actual (for example for an unrelated
24856 -- accessibility check). Check that the extra actual matches
24857 -- some extra formal, which must exist already because
24858 -- subprogram must be frozen at this point.
24860 if Present (Extra_Formals (S))
24861 and then not Comes_From_Source (Actual)
24862 and then Nkind (Actual) = N_Parameter_Association
24863 and then Chars (Extra_Formals (S)) =
24864 Chars (Selector_Name (Actual))
24865 then
24866 null;
24867 else
24868 Error_Msg_N
24869 ("unmatched actual & in call", Selector_Name (Actual));
24870 exit;
24871 end if;
24872 end if;
24874 Next (Actual);
24875 end loop;
24876 end if;
24878 Success := False;
24879 return;
24880 end if;
24881 end Normalize_Actuals;
24883 --------------------------------
24884 -- Note_Possible_Modification --
24885 --------------------------------
24887 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
24888 Modification_Comes_From_Source : constant Boolean :=
24889 Comes_From_Source (Parent (N));
24891 Ent : Entity_Id;
24892 Exp : Node_Id;
24894 begin
24895 -- Loop to find referenced entity, if there is one
24897 Exp := N;
24898 loop
24899 Ent := Empty;
24901 if Is_Entity_Name (Exp) then
24902 Ent := Entity (Exp);
24904 -- If the entity is missing, it is an undeclared identifier,
24905 -- and there is nothing to annotate.
24907 if No (Ent) then
24908 return;
24909 end if;
24911 elsif Nkind (Exp) = N_Explicit_Dereference then
24912 declare
24913 P : constant Node_Id := Prefix (Exp);
24915 begin
24916 -- In formal verification mode, keep track of all reads and
24917 -- writes through explicit dereferences.
24919 if GNATprove_Mode then
24920 SPARK_Specific.Generate_Dereference (N, 'm');
24921 end if;
24923 if Nkind (P) = N_Selected_Component
24924 and then Present (Entry_Formal (Entity (Selector_Name (P))))
24925 then
24926 -- Case of a reference to an entry formal
24928 Ent := Entry_Formal (Entity (Selector_Name (P)));
24930 elsif Nkind (P) = N_Identifier
24931 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
24932 and then Present (Expression (Parent (Entity (P))))
24933 and then Nkind (Expression (Parent (Entity (P)))) =
24934 N_Reference
24935 then
24936 -- Case of a reference to a value on which side effects have
24937 -- been removed.
24939 Exp := Prefix (Expression (Parent (Entity (P))));
24940 goto Continue;
24942 else
24943 return;
24944 end if;
24945 end;
24947 elsif Nkind (Exp) in N_Type_Conversion | N_Unchecked_Type_Conversion
24948 then
24949 Exp := Expression (Exp);
24950 goto Continue;
24952 elsif Nkind (Exp) in
24953 N_Slice | N_Indexed_Component | N_Selected_Component
24954 then
24955 -- Special check, if the prefix is an access type, then return
24956 -- since we are modifying the thing pointed to, not the prefix.
24957 -- When we are expanding, most usually the prefix is replaced
24958 -- by an explicit dereference, and this test is not needed, but
24959 -- in some cases (notably -gnatc mode and generics) when we do
24960 -- not do full expansion, we need this special test.
24962 if Is_Access_Type (Etype (Prefix (Exp))) then
24963 return;
24965 -- Otherwise go to prefix and keep going
24967 else
24968 Exp := Prefix (Exp);
24969 goto Continue;
24970 end if;
24972 -- All other cases, not a modification
24974 else
24975 return;
24976 end if;
24978 -- Now look for entity being referenced
24980 if Present (Ent) then
24981 if Is_Object (Ent) then
24982 if Comes_From_Source (Exp)
24983 or else Modification_Comes_From_Source
24984 then
24985 -- Give warning if pragma unmodified is given and we are
24986 -- sure this is a modification.
24988 if Has_Pragma_Unmodified (Ent) and then Sure then
24990 -- Note that the entity may be present only as a result
24991 -- of pragma Unused.
24993 if Has_Pragma_Unused (Ent) then
24994 Error_Msg_NE
24995 ("??aspect Unused specified for &!", N, Ent);
24996 else
24997 Error_Msg_NE
24998 ("??aspect Unmodified specified for &!", N, Ent);
24999 end if;
25000 end if;
25002 Set_Never_Set_In_Source (Ent, False);
25003 end if;
25005 Set_Is_True_Constant (Ent, False);
25006 Set_Current_Value (Ent, Empty);
25007 Set_Is_Known_Null (Ent, False);
25009 if not Can_Never_Be_Null (Ent) then
25010 Set_Is_Known_Non_Null (Ent, False);
25011 end if;
25013 -- Follow renaming chain
25015 if Ekind (Ent) in E_Variable | E_Constant
25016 and then Present (Renamed_Object (Ent))
25017 then
25018 Exp := Renamed_Object (Ent);
25020 -- If the entity is the loop variable in an iteration over
25021 -- a container, retrieve container expression to indicate
25022 -- possible modification.
25024 if Present (Related_Expression (Ent))
25025 and then Nkind (Parent (Related_Expression (Ent))) =
25026 N_Iterator_Specification
25027 then
25028 Exp := Original_Node (Related_Expression (Ent));
25029 end if;
25031 goto Continue;
25033 -- The expression may be the renaming of a subcomponent of an
25034 -- array or container. The assignment to the subcomponent is
25035 -- a modification of the container.
25037 elsif Comes_From_Source (Original_Node (Exp))
25038 and then Nkind (Original_Node (Exp)) in
25039 N_Selected_Component | N_Indexed_Component
25040 then
25041 Exp := Prefix (Original_Node (Exp));
25042 goto Continue;
25043 end if;
25045 -- Generate a reference only if the assignment comes from
25046 -- source. This excludes, for example, calls to a dispatching
25047 -- assignment operation when the left-hand side is tagged. In
25048 -- GNATprove mode, we need those references also on generated
25049 -- code, as these are used to compute the local effects of
25050 -- subprograms.
25052 if Modification_Comes_From_Source or GNATprove_Mode then
25053 Generate_Reference (Ent, Exp, 'm');
25055 -- If the target of the assignment is the bound variable
25056 -- in an iterator, indicate that the corresponding array
25057 -- or container is also modified.
25059 if Ada_Version >= Ada_2012
25060 and then Nkind (Parent (Ent)) = N_Iterator_Specification
25061 then
25062 declare
25063 Domain : constant Node_Id := Name (Parent (Ent));
25065 begin
25066 -- ??? In the full version of the construct, the
25067 -- domain of iteration can be given by an expression.
25069 if Is_Entity_Name (Domain) then
25070 Generate_Reference (Entity (Domain), Exp, 'm');
25071 Set_Is_True_Constant (Entity (Domain), False);
25072 Set_Never_Set_In_Source (Entity (Domain), False);
25073 end if;
25074 end;
25075 end if;
25076 end if;
25077 end if;
25079 Kill_Checks (Ent);
25081 -- If we are sure this is a modification from source, and we know
25082 -- this modifies a constant, then give an appropriate warning.
25084 if Sure
25085 and then Modification_Comes_From_Source
25086 and then Overlays_Constant (Ent)
25087 and then Address_Clause_Overlay_Warnings
25088 then
25089 declare
25090 Addr : constant Node_Id := Address_Clause (Ent);
25091 O_Ent : Entity_Id;
25092 Off : Boolean;
25094 begin
25095 Find_Overlaid_Entity (Addr, O_Ent, Off);
25097 Error_Msg_Sloc := Sloc (Addr);
25098 Error_Msg_NE
25099 ("?o?constant& may be modified via address clause#",
25100 N, O_Ent);
25101 end;
25102 end if;
25104 return;
25105 end if;
25107 <<Continue>>
25108 null;
25109 end loop;
25110 end Note_Possible_Modification;
25112 -----------------
25113 -- Null_Status --
25114 -----------------
25116 function Null_Status (N : Node_Id) return Null_Status_Kind is
25117 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
25118 -- Determine whether definition Def carries a null exclusion
25120 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
25121 -- Determine the null status of arbitrary entity Id
25123 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
25124 -- Determine the null status of type Typ
25126 ---------------------------
25127 -- Is_Null_Excluding_Def --
25128 ---------------------------
25130 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
25131 begin
25132 return Nkind (Def) in N_Access_Definition
25133 | N_Access_Function_Definition
25134 | N_Access_Procedure_Definition
25135 | N_Access_To_Object_Definition
25136 | N_Component_Definition
25137 | N_Derived_Type_Definition
25138 and then Null_Exclusion_Present (Def);
25139 end Is_Null_Excluding_Def;
25141 ---------------------------
25142 -- Null_Status_Of_Entity --
25143 ---------------------------
25145 function Null_Status_Of_Entity
25146 (Id : Entity_Id) return Null_Status_Kind
25148 Decl : constant Node_Id := Declaration_Node (Id);
25149 Def : Node_Id;
25151 begin
25152 -- The value of an imported or exported entity may be set externally
25153 -- regardless of a null exclusion. As a result, the value cannot be
25154 -- determined statically.
25156 if Is_Imported (Id) or else Is_Exported (Id) then
25157 return Unknown;
25159 elsif Nkind (Decl) in N_Component_Declaration
25160 | N_Discriminant_Specification
25161 | N_Formal_Object_Declaration
25162 | N_Object_Declaration
25163 | N_Object_Renaming_Declaration
25164 | N_Parameter_Specification
25165 then
25166 -- A component declaration yields a non-null value when either
25167 -- its component definition or access definition carries a null
25168 -- exclusion.
25170 if Nkind (Decl) = N_Component_Declaration then
25171 Def := Component_Definition (Decl);
25173 if Is_Null_Excluding_Def (Def) then
25174 return Is_Non_Null;
25175 end if;
25177 Def := Access_Definition (Def);
25179 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25180 return Is_Non_Null;
25181 end if;
25183 -- A formal object declaration yields a non-null value if its
25184 -- access definition carries a null exclusion. If the object is
25185 -- default initialized, then the value depends on the expression.
25187 elsif Nkind (Decl) = N_Formal_Object_Declaration then
25188 Def := Access_Definition (Decl);
25190 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25191 return Is_Non_Null;
25192 end if;
25194 -- A constant may yield a null or non-null value depending on its
25195 -- initialization expression.
25197 elsif Ekind (Id) = E_Constant then
25198 return Null_Status (Constant_Value (Id));
25200 -- The construct yields a non-null value when it has a null
25201 -- exclusion.
25203 elsif Null_Exclusion_Present (Decl) then
25204 return Is_Non_Null;
25206 -- An object renaming declaration yields a non-null value if its
25207 -- access definition carries a null exclusion. Otherwise the value
25208 -- depends on the renamed name.
25210 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
25211 Def := Access_Definition (Decl);
25213 if Present (Def) and then Is_Null_Excluding_Def (Def) then
25214 return Is_Non_Null;
25216 else
25217 return Null_Status (Name (Decl));
25218 end if;
25219 end if;
25220 end if;
25222 -- At this point the declaration of the entity does not carry a null
25223 -- exclusion and lacks an initialization expression. Check the status
25224 -- of its type.
25226 return Null_Status_Of_Type (Etype (Id));
25227 end Null_Status_Of_Entity;
25229 -------------------------
25230 -- Null_Status_Of_Type --
25231 -------------------------
25233 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
25234 Curr : Entity_Id;
25235 Decl : Node_Id;
25237 begin
25238 -- Traverse the type chain looking for types with null exclusion
25240 Curr := Typ;
25241 while Present (Curr) and then Etype (Curr) /= Curr loop
25242 Decl := Parent (Curr);
25244 -- Guard against itypes which do not always have declarations. A
25245 -- type yields a non-null value if it carries a null exclusion.
25247 if Present (Decl) then
25248 if Nkind (Decl) = N_Full_Type_Declaration
25249 and then Is_Null_Excluding_Def (Type_Definition (Decl))
25250 then
25251 return Is_Non_Null;
25253 elsif Nkind (Decl) = N_Subtype_Declaration
25254 and then Null_Exclusion_Present (Decl)
25255 then
25256 return Is_Non_Null;
25257 end if;
25258 end if;
25260 Curr := Etype (Curr);
25261 end loop;
25263 -- The type chain does not contain any null excluding types
25265 return Unknown;
25266 end Null_Status_Of_Type;
25268 -- Start of processing for Null_Status
25270 begin
25271 -- Prevent cascaded errors or infinite loops when trying to determine
25272 -- the null status of an erroneous construct.
25274 if Error_Posted (N) then
25275 return Unknown;
25277 -- An allocator always creates a non-null value
25279 elsif Nkind (N) = N_Allocator then
25280 return Is_Non_Null;
25282 -- Taking the 'Access of something yields a non-null value
25284 elsif Nkind (N) = N_Attribute_Reference
25285 and then Attribute_Name (N) in Name_Access
25286 | Name_Unchecked_Access
25287 | Name_Unrestricted_Access
25288 then
25289 return Is_Non_Null;
25291 -- "null" yields null
25293 elsif Nkind (N) = N_Null then
25294 return Is_Null;
25296 -- Check the status of the operand of a type conversion
25298 elsif Nkind (N) in N_Type_Conversion | N_Unchecked_Type_Conversion then
25299 return Null_Status (Expression (N));
25301 -- The input denotes a reference to an entity. Determine whether the
25302 -- entity or its type yields a null or non-null value.
25304 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
25305 return Null_Status_Of_Entity (Entity (N));
25306 end if;
25308 -- Otherwise it is not possible to determine the null status of the
25309 -- subexpression at compile time without resorting to simple flow
25310 -- analysis.
25312 return Unknown;
25313 end Null_Status;
25315 --------------------------------------
25316 -- Null_To_Null_Address_Convert_OK --
25317 --------------------------------------
25319 function Null_To_Null_Address_Convert_OK
25320 (N : Node_Id;
25321 Typ : Entity_Id := Empty) return Boolean
25323 begin
25324 if not Relaxed_RM_Semantics then
25325 return False;
25326 end if;
25328 if Nkind (N) = N_Null then
25329 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
25331 elsif Nkind (N) in N_Op_Compare then
25332 declare
25333 L : constant Node_Id := Left_Opnd (N);
25334 R : constant Node_Id := Right_Opnd (N);
25336 begin
25337 -- We check the Etype of the complementary operand since the
25338 -- N_Null node is not decorated at this stage.
25340 return
25341 ((Nkind (L) = N_Null
25342 and then Is_Descendant_Of_Address (Etype (R)))
25343 or else
25344 (Nkind (R) = N_Null
25345 and then Is_Descendant_Of_Address (Etype (L))));
25346 end;
25347 end if;
25349 return False;
25350 end Null_To_Null_Address_Convert_OK;
25352 ---------------------------------
25353 -- Number_Of_Elements_In_Array --
25354 ---------------------------------
25356 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
25357 Indx : Node_Id;
25358 Typ : Entity_Id;
25359 Low : Node_Id;
25360 High : Node_Id;
25361 Num : Int := 1;
25363 begin
25364 pragma Assert (Is_Array_Type (T));
25366 Indx := First_Index (T);
25367 while Present (Indx) loop
25368 Typ := Underlying_Type (Etype (Indx));
25370 -- Never look at junk bounds of a generic type
25372 if Is_Generic_Type (Typ) then
25373 return 0;
25374 end if;
25376 -- Check the array bounds are known at compile time and return zero
25377 -- if they are not.
25379 Low := Type_Low_Bound (Typ);
25380 High := Type_High_Bound (Typ);
25382 if not Compile_Time_Known_Value (Low) then
25383 return 0;
25384 elsif not Compile_Time_Known_Value (High) then
25385 return 0;
25386 else
25387 Num :=
25388 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
25389 end if;
25391 Next_Index (Indx);
25392 end loop;
25394 return Num;
25395 end Number_Of_Elements_In_Array;
25397 ---------------------------------
25398 -- Original_Aspect_Pragma_Name --
25399 ---------------------------------
25401 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
25402 Item : Node_Id;
25403 Item_Nam : Name_Id;
25405 begin
25406 pragma Assert (Nkind (N) in N_Aspect_Specification | N_Pragma);
25408 Item := N;
25410 -- The pragma was generated to emulate an aspect, use the original
25411 -- aspect specification.
25413 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
25414 Item := Corresponding_Aspect (Item);
25415 end if;
25417 -- Retrieve the name of the aspect/pragma. As assertion pragmas from
25418 -- a generic instantiation might have been rewritten into pragma Check,
25419 -- we look at the original node for Item. Note also that Pre, Pre_Class,
25420 -- Post and Post_Class rewrite their pragma identifier to preserve the
25421 -- original name, so we look at the original node for the identifier.
25422 -- ??? this is kludgey
25424 if Nkind (Item) = N_Pragma then
25425 Item_Nam :=
25426 Chars (Original_Node (Pragma_Identifier (Original_Node (Item))));
25428 if Item_Nam = Name_Check then
25429 -- Pragma "Check" preserves the original pragma name as its first
25430 -- argument.
25431 Item_Nam :=
25432 Chars (Expression (First (Pragma_Argument_Associations
25433 (Original_Node (Item)))));
25434 end if;
25436 else
25437 pragma Assert (Nkind (Item) = N_Aspect_Specification);
25438 Item_Nam := Chars (Identifier (Item));
25439 end if;
25441 -- Deal with 'Class by converting the name to its _XXX form
25443 if Class_Present (Item) then
25444 if Item_Nam = Name_Invariant then
25445 Item_Nam := Name_uInvariant;
25447 elsif Item_Nam = Name_Post then
25448 Item_Nam := Name_uPost;
25450 elsif Item_Nam = Name_Pre then
25451 Item_Nam := Name_uPre;
25453 elsif Item_Nam in Name_Type_Invariant | Name_Type_Invariant_Class
25454 then
25455 Item_Nam := Name_uType_Invariant;
25457 -- Nothing to do for other cases (e.g. a Check that derived from
25458 -- Pre_Class and has the flag set). Also we do nothing if the name
25459 -- is already in special _xxx form.
25461 end if;
25462 end if;
25464 return Item_Nam;
25465 end Original_Aspect_Pragma_Name;
25467 --------------------------------------
25468 -- Original_Corresponding_Operation --
25469 --------------------------------------
25471 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
25473 Typ : constant Entity_Id := Find_Dispatching_Type (S);
25475 begin
25476 -- If S is an inherited primitive S2 the original corresponding
25477 -- operation of S is the original corresponding operation of S2
25479 if Present (Alias (S))
25480 and then Find_Dispatching_Type (Alias (S)) /= Typ
25481 then
25482 return Original_Corresponding_Operation (Alias (S));
25484 -- If S overrides an inherited subprogram S2 the original corresponding
25485 -- operation of S is the original corresponding operation of S2
25487 elsif Present (Overridden_Operation (S)) then
25488 return Original_Corresponding_Operation (Overridden_Operation (S));
25490 -- otherwise it is S itself
25492 else
25493 return S;
25494 end if;
25495 end Original_Corresponding_Operation;
25497 -----------------------------------
25498 -- Original_View_In_Visible_Part --
25499 -----------------------------------
25501 function Original_View_In_Visible_Part
25502 (Typ : Entity_Id) return Boolean
25504 Scop : constant Entity_Id := Scope (Typ);
25506 begin
25507 -- The scope must be a package
25509 if not Is_Package_Or_Generic_Package (Scop) then
25510 return False;
25511 end if;
25513 -- A type with a private declaration has a private view declared in
25514 -- the visible part.
25516 if Has_Private_Declaration (Typ) then
25517 return True;
25518 end if;
25520 return List_Containing (Parent (Typ)) =
25521 Visible_Declarations (Package_Specification (Scop));
25522 end Original_View_In_Visible_Part;
25524 -------------------
25525 -- Output_Entity --
25526 -------------------
25528 procedure Output_Entity (Id : Entity_Id) is
25529 Scop : Entity_Id;
25531 begin
25532 Scop := Scope (Id);
25534 -- The entity may lack a scope when it is in the process of being
25535 -- analyzed. Use the current scope as an approximation.
25537 if No (Scop) then
25538 Scop := Current_Scope;
25539 end if;
25541 Output_Name (Chars (Id), Scop);
25542 end Output_Entity;
25544 -----------------
25545 -- Output_Name --
25546 -----------------
25548 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
25549 begin
25550 Write_Str
25551 (Get_Name_String
25552 (Get_Qualified_Name
25553 (Nam => Nam,
25554 Suffix => No_Name,
25555 Scop => Scop)));
25556 Write_Eol;
25557 end Output_Name;
25559 ------------------
25560 -- Param_Entity --
25561 ------------------
25563 -- This would be trivial, simply a test for an identifier that was a
25564 -- reference to a formal, if it were not for the fact that a previous call
25565 -- to Expand_Entry_Parameter will have modified the reference to the
25566 -- identifier. A formal of a protected entity is rewritten as
25568 -- typ!(recobj).rec.all'Constrained
25570 -- where rec is a selector whose Entry_Formal link points to the formal
25572 -- If the type of the entry parameter has a representation clause, then an
25573 -- extra temp is involved (see below).
25575 -- For a formal of a task entity, the formal is rewritten as a local
25576 -- renaming.
25578 -- In addition, a formal that is marked volatile because it is aliased
25579 -- through an address clause is rewritten as dereference as well.
25581 function Param_Entity (N : Node_Id) return Entity_Id is
25582 Renamed_Obj : Node_Id;
25584 begin
25585 -- Simple reference case
25587 if Nkind (N) in N_Identifier | N_Expanded_Name then
25588 if Is_Formal (Entity (N)) then
25589 return Entity (N);
25591 -- Handle renamings of formal parameters and formals of tasks that
25592 -- are rewritten as renamings.
25594 elsif Nkind (Parent (Entity (N))) = N_Object_Renaming_Declaration then
25595 Renamed_Obj := Get_Referenced_Object (Renamed_Object (Entity (N)));
25597 if Is_Entity_Name (Renamed_Obj)
25598 and then Is_Formal (Entity (Renamed_Obj))
25599 then
25600 return Entity (Renamed_Obj);
25602 elsif
25603 Nkind (Parent (Parent (Entity (N)))) = N_Accept_Statement
25604 then
25605 return Entity (N);
25606 end if;
25607 end if;
25609 else
25610 if Nkind (N) = N_Explicit_Dereference then
25611 declare
25612 P : Node_Id := Prefix (N);
25613 S : Node_Id;
25614 E : Entity_Id;
25615 Decl : Node_Id;
25617 begin
25618 -- If the type of an entry parameter has a representation
25619 -- clause, then the prefix is not a selected component, but
25620 -- instead a reference to a temp pointing at the selected
25621 -- component. In this case, set P to be the initial value of
25622 -- that temp.
25624 if Nkind (P) = N_Identifier then
25625 E := Entity (P);
25627 if Ekind (E) = E_Constant then
25628 Decl := Parent (E);
25630 if Nkind (Decl) = N_Object_Declaration then
25631 P := Expression (Decl);
25632 end if;
25633 end if;
25634 end if;
25636 if Nkind (P) = N_Selected_Component then
25637 S := Selector_Name (P);
25639 if Present (Entry_Formal (Entity (S))) then
25640 return Entry_Formal (Entity (S));
25641 end if;
25643 elsif Nkind (Original_Node (N)) = N_Identifier then
25644 return Param_Entity (Original_Node (N));
25645 end if;
25646 end;
25647 end if;
25648 end if;
25650 return Empty;
25651 end Param_Entity;
25653 ----------------------
25654 -- Policy_In_Effect --
25655 ----------------------
25657 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
25658 function Policy_In_List (List : Node_Id) return Name_Id;
25659 -- Determine the mode of a policy in a N_Pragma list
25661 --------------------
25662 -- Policy_In_List --
25663 --------------------
25665 function Policy_In_List (List : Node_Id) return Name_Id is
25666 Arg1 : Node_Id;
25667 Arg2 : Node_Id;
25668 Prag : Node_Id;
25670 begin
25671 Prag := List;
25672 while Present (Prag) loop
25673 Arg1 := First (Pragma_Argument_Associations (Prag));
25674 Arg2 := Next (Arg1);
25676 Arg1 := Get_Pragma_Arg (Arg1);
25677 Arg2 := Get_Pragma_Arg (Arg2);
25679 -- The current Check_Policy pragma matches the requested policy or
25680 -- appears in the single argument form (Assertion, policy_id).
25682 if Chars (Arg1) in Name_Assertion | Policy then
25683 return Chars (Arg2);
25684 end if;
25686 Prag := Next_Pragma (Prag);
25687 end loop;
25689 return No_Name;
25690 end Policy_In_List;
25692 -- Local variables
25694 Kind : Name_Id;
25696 -- Start of processing for Policy_In_Effect
25698 begin
25699 if not Is_Valid_Assertion_Kind (Policy) then
25700 raise Program_Error;
25701 end if;
25703 -- Inspect all policy pragmas that appear within scopes (if any)
25705 Kind := Policy_In_List (Check_Policy_List);
25707 -- Inspect all configuration policy pragmas (if any)
25709 if Kind = No_Name then
25710 Kind := Policy_In_List (Check_Policy_List_Config);
25711 end if;
25713 -- The context lacks policy pragmas, determine the mode based on whether
25714 -- assertions are enabled at the configuration level. This ensures that
25715 -- the policy is preserved when analyzing generics.
25717 if Kind = No_Name then
25718 if Assertions_Enabled_Config then
25719 Kind := Name_Check;
25720 else
25721 Kind := Name_Ignore;
25722 end if;
25723 end if;
25725 -- In CodePeer mode and GNATprove mode, we need to consider all
25726 -- assertions, unless they are disabled. Force Name_Check on
25727 -- ignored assertions.
25729 if Kind in Name_Ignore | Name_Off
25730 and then (CodePeer_Mode or GNATprove_Mode)
25731 then
25732 Kind := Name_Check;
25733 end if;
25735 return Kind;
25736 end Policy_In_Effect;
25738 -------------------------------
25739 -- Preanalyze_Without_Errors --
25740 -------------------------------
25742 procedure Preanalyze_Without_Errors (N : Node_Id) is
25743 Status : constant Boolean := Get_Ignore_Errors;
25744 begin
25745 Set_Ignore_Errors (True);
25746 Preanalyze (N);
25747 Set_Ignore_Errors (Status);
25748 end Preanalyze_Without_Errors;
25750 -----------------------
25751 -- Predicate_Enabled --
25752 -----------------------
25754 function Predicate_Enabled (Typ : Entity_Id) return Boolean is
25755 begin
25756 return Present (Predicate_Function (Typ))
25757 and then not Predicates_Ignored (Typ)
25758 and then not Predicate_Checks_Suppressed (Empty);
25759 end Predicate_Enabled;
25761 ----------------------------------
25762 -- Predicate_Failure_Expression --
25763 ----------------------------------
25765 function Predicate_Failure_Expression
25766 (Typ : Entity_Id; Inherited_OK : Boolean) return Node_Id
25768 PF_Aspect : constant Node_Id :=
25769 Find_Aspect (Typ, Aspect_Predicate_Failure);
25770 begin
25771 -- Check for Predicate_Failure aspect specification via an
25772 -- aspect_specification (as opposed to via a pragma).
25774 if Present (PF_Aspect) then
25775 if Inherited_OK or else Entity (PF_Aspect) = Typ then
25776 return Expression (PF_Aspect);
25777 else
25778 return Empty;
25779 end if;
25780 end if;
25782 -- Check for Predicate_Failure aspect specification via a pragma.
25784 declare
25785 Rep_Item : Node_Id := First_Rep_Item (Typ);
25786 begin
25787 while Present (Rep_Item) loop
25788 if Nkind (Rep_Item) = N_Pragma
25789 and then Get_Pragma_Id (Rep_Item) = Pragma_Predicate_Failure
25790 then
25791 declare
25792 Arg1 : constant Node_Id :=
25793 Get_Pragma_Arg
25794 (First (Pragma_Argument_Associations (Rep_Item)));
25795 Arg2 : constant Node_Id :=
25796 Get_Pragma_Arg
25797 (Next (First (Pragma_Argument_Associations (Rep_Item))));
25798 begin
25799 if Inherited_OK or else
25800 (Nkind (Arg1) in N_Has_Entity
25801 and then Entity (Arg1) = Typ)
25802 then
25803 return Arg2;
25804 end if;
25805 end;
25806 end if;
25808 Next_Rep_Item (Rep_Item);
25809 end loop;
25810 end;
25812 -- If we are interested in an inherited Predicate_Failure aspect
25813 -- and we have an ancestor to inherit from, then recursively check
25814 -- for that case.
25816 if Inherited_OK and then Present (Nearest_Ancestor (Typ)) then
25817 return Predicate_Failure_Expression (Nearest_Ancestor (Typ),
25818 Inherited_OK => True);
25819 end if;
25821 return Empty;
25822 end Predicate_Failure_Expression;
25824 ----------------------------------
25825 -- Predicate_Tests_On_Arguments --
25826 ----------------------------------
25828 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
25829 begin
25830 -- Always test predicates on indirect call
25832 if Ekind (Subp) = E_Subprogram_Type then
25833 return True;
25835 -- Do not test predicates on call to generated default Finalize, since
25836 -- we are not interested in whether something we are finalizing (and
25837 -- typically destroying) satisfies its predicates.
25839 elsif Chars (Subp) = Name_Finalize
25840 and then not Comes_From_Source (Subp)
25841 then
25842 return False;
25844 -- Do not test predicates on any internally generated routines
25846 elsif Is_Internal_Name (Chars (Subp)) then
25847 return False;
25849 -- Do not test predicates on call to Init_Proc, since if needed the
25850 -- predicate test will occur at some other point.
25852 elsif Is_Init_Proc (Subp) then
25853 return False;
25855 -- Do not test predicates on call to predicate function, since this
25856 -- would cause infinite recursion.
25858 elsif Ekind (Subp) = E_Function
25859 and then Is_Predicate_Function (Subp)
25860 then
25861 return False;
25863 -- For now, no other exceptions
25865 else
25866 return True;
25867 end if;
25868 end Predicate_Tests_On_Arguments;
25870 -----------------------
25871 -- Private_Component --
25872 -----------------------
25874 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
25875 Ancestor : constant Entity_Id := Base_Type (Type_Id);
25877 function Trace_Components
25878 (T : Entity_Id;
25879 Check : Boolean) return Entity_Id;
25880 -- Recursive function that does the work, and checks against circular
25881 -- definition for each subcomponent type.
25883 ----------------------
25884 -- Trace_Components --
25885 ----------------------
25887 function Trace_Components
25888 (T : Entity_Id;
25889 Check : Boolean) return Entity_Id
25891 Btype : constant Entity_Id := Base_Type (T);
25892 Component : Entity_Id;
25893 P : Entity_Id;
25894 Candidate : Entity_Id := Empty;
25896 begin
25897 if Check and then Btype = Ancestor then
25898 Error_Msg_N ("circular type definition", Type_Id);
25899 return Any_Type;
25900 end if;
25902 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
25903 if Present (Full_View (Btype))
25904 and then Is_Record_Type (Full_View (Btype))
25905 and then not Is_Frozen (Btype)
25906 then
25907 -- To indicate that the ancestor depends on a private type, the
25908 -- current Btype is sufficient. However, to check for circular
25909 -- definition we must recurse on the full view.
25911 Candidate := Trace_Components (Full_View (Btype), True);
25913 if Candidate = Any_Type then
25914 return Any_Type;
25915 else
25916 return Btype;
25917 end if;
25919 else
25920 return Btype;
25921 end if;
25923 elsif Is_Array_Type (Btype) then
25924 return Trace_Components (Component_Type (Btype), True);
25926 elsif Is_Record_Type (Btype) then
25927 Component := First_Entity (Btype);
25928 while Present (Component)
25929 and then Comes_From_Source (Component)
25930 loop
25931 -- Skip anonymous types generated by constrained components
25933 if not Is_Type (Component) then
25934 P := Trace_Components (Etype (Component), True);
25936 if Present (P) then
25937 if P = Any_Type then
25938 return P;
25939 else
25940 Candidate := P;
25941 end if;
25942 end if;
25943 end if;
25945 Next_Entity (Component);
25946 end loop;
25948 return Candidate;
25950 else
25951 return Empty;
25952 end if;
25953 end Trace_Components;
25955 -- Start of processing for Private_Component
25957 begin
25958 return Trace_Components (Type_Id, False);
25959 end Private_Component;
25961 ---------------------------
25962 -- Primitive_Names_Match --
25963 ---------------------------
25965 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
25966 function Non_Internal_Name (E : Entity_Id) return Name_Id;
25967 -- Given an internal name, returns the corresponding non-internal name
25969 ------------------------
25970 -- Non_Internal_Name --
25971 ------------------------
25973 function Non_Internal_Name (E : Entity_Id) return Name_Id is
25974 begin
25975 Get_Name_String (Chars (E));
25976 Name_Len := Name_Len - 1;
25977 return Name_Find;
25978 end Non_Internal_Name;
25980 -- Start of processing for Primitive_Names_Match
25982 begin
25983 pragma Assert (Present (E1) and then Present (E2));
25985 return Chars (E1) = Chars (E2)
25986 or else
25987 (not Is_Internal_Name (Chars (E1))
25988 and then Is_Internal_Name (Chars (E2))
25989 and then Non_Internal_Name (E2) = Chars (E1))
25990 or else
25991 (not Is_Internal_Name (Chars (E2))
25992 and then Is_Internal_Name (Chars (E1))
25993 and then Non_Internal_Name (E1) = Chars (E2))
25994 or else
25995 (Is_Predefined_Dispatching_Operation (E1)
25996 and then Is_Predefined_Dispatching_Operation (E2)
25997 and then Same_TSS (E1, E2))
25998 or else
25999 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
26000 end Primitive_Names_Match;
26002 -----------------------
26003 -- Process_End_Label --
26004 -----------------------
26006 procedure Process_End_Label
26007 (N : Node_Id;
26008 Typ : Character;
26009 Ent : Entity_Id)
26011 Loc : Source_Ptr;
26012 Nam : Node_Id;
26013 Scop : Entity_Id;
26015 Label_Ref : Boolean;
26016 -- Set True if reference to end label itself is required
26018 Endl : Node_Id;
26019 -- Gets set to the operator symbol or identifier that references the
26020 -- entity Ent. For the child unit case, this is the identifier from the
26021 -- designator. For other cases, this is simply Endl.
26023 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
26024 -- N is an identifier node that appears as a parent unit reference in
26025 -- the case where Ent is a child unit. This procedure generates an
26026 -- appropriate cross-reference entry. E is the corresponding entity.
26028 -------------------------
26029 -- Generate_Parent_Ref --
26030 -------------------------
26032 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
26033 begin
26034 -- If names do not match, something weird, skip reference
26036 if Chars (E) = Chars (N) then
26038 -- Generate the reference. We do NOT consider this as a reference
26039 -- for unreferenced symbol purposes.
26041 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
26043 if Style_Check then
26044 Style.Check_Identifier (N, E);
26045 end if;
26046 end if;
26047 end Generate_Parent_Ref;
26049 -- Start of processing for Process_End_Label
26051 begin
26052 -- If no node, ignore. This happens in some error situations, and
26053 -- also for some internally generated structures where no end label
26054 -- references are required in any case.
26056 if No (N) then
26057 return;
26058 end if;
26060 -- Nothing to do if no End_Label, happens for internally generated
26061 -- constructs where we don't want an end label reference anyway. Also
26062 -- nothing to do if Endl is a string literal, which means there was
26063 -- some prior error (bad operator symbol)
26065 Endl := End_Label (N);
26067 if No (Endl) or else Nkind (Endl) = N_String_Literal then
26068 return;
26069 end if;
26071 -- Reference node is not in extended main source unit
26073 if not In_Extended_Main_Source_Unit (N) then
26075 -- Generally we do not collect references except for the extended
26076 -- main source unit. The one exception is the 'e' entry for a
26077 -- package spec, where it is useful for a client to have the
26078 -- ending information to define scopes.
26080 if Typ /= 'e' then
26081 return;
26083 else
26084 Label_Ref := False;
26086 -- For this case, we can ignore any parent references, but we
26087 -- need the package name itself for the 'e' entry.
26089 if Nkind (Endl) = N_Designator then
26090 Endl := Identifier (Endl);
26091 end if;
26092 end if;
26094 -- Reference is in extended main source unit
26096 else
26097 Label_Ref := True;
26099 -- For designator, generate references for the parent entries
26101 if Nkind (Endl) = N_Designator then
26103 -- Generate references for the prefix if the END line comes from
26104 -- source (otherwise we do not need these references) We climb the
26105 -- scope stack to find the expected entities.
26107 if Comes_From_Source (Endl) then
26108 Nam := Name (Endl);
26109 Scop := Current_Scope;
26110 while Nkind (Nam) = N_Selected_Component loop
26111 Scop := Scope (Scop);
26112 exit when No (Scop);
26113 Generate_Parent_Ref (Selector_Name (Nam), Scop);
26114 Nam := Prefix (Nam);
26115 end loop;
26117 if Present (Scop) then
26118 Generate_Parent_Ref (Nam, Scope (Scop));
26119 end if;
26120 end if;
26122 Endl := Identifier (Endl);
26123 end if;
26124 end if;
26126 -- If the end label is not for the given entity, then either we have
26127 -- some previous error, or this is a generic instantiation for which
26128 -- we do not need to make a cross-reference in this case anyway. In
26129 -- either case we simply ignore the call.
26131 if Chars (Ent) /= Chars (Endl) then
26132 return;
26133 end if;
26135 -- If label was really there, then generate a normal reference and then
26136 -- adjust the location in the end label to point past the name (which
26137 -- should almost always be the semicolon).
26139 Loc := Sloc (Endl);
26141 if Comes_From_Source (Endl) then
26143 -- If a label reference is required, then do the style check and
26144 -- generate an l-type cross-reference entry for the label
26146 if Label_Ref then
26147 if Style_Check then
26148 Style.Check_Identifier (Endl, Ent);
26149 end if;
26151 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
26152 end if;
26154 -- Set the location to point past the label (normally this will
26155 -- mean the semicolon immediately following the label). This is
26156 -- done for the sake of the 'e' or 't' entry generated below.
26158 Get_Decoded_Name_String (Chars (Endl));
26159 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
26160 end if;
26162 -- Now generate the e/t reference
26164 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
26166 -- Restore Sloc, in case modified above, since we have an identifier
26167 -- and the normal Sloc should be left set in the tree.
26169 Set_Sloc (Endl, Loc);
26170 end Process_End_Label;
26172 --------------------------------
26173 -- Propagate_Concurrent_Flags --
26174 --------------------------------
26176 procedure Propagate_Concurrent_Flags
26177 (Typ : Entity_Id;
26178 Comp_Typ : Entity_Id)
26180 begin
26181 if Has_Task (Comp_Typ) then
26182 Set_Has_Task (Typ);
26183 end if;
26185 if Has_Protected (Comp_Typ) then
26186 Set_Has_Protected (Typ);
26187 end if;
26189 if Has_Timing_Event (Comp_Typ) then
26190 Set_Has_Timing_Event (Typ);
26191 end if;
26192 end Propagate_Concurrent_Flags;
26194 ------------------------------
26195 -- Propagate_DIC_Attributes --
26196 ------------------------------
26198 procedure Propagate_DIC_Attributes
26199 (Typ : Entity_Id;
26200 From_Typ : Entity_Id)
26202 DIC_Proc : Entity_Id;
26203 Partial_DIC_Proc : Entity_Id;
26205 begin
26206 if Present (Typ) and then Present (From_Typ) then
26207 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26209 -- Nothing to do if both the source and the destination denote the
26210 -- same type.
26212 if From_Typ = Typ then
26213 return;
26215 -- Nothing to do when the destination denotes an incomplete type
26216 -- because the DIC is associated with the current instance of a
26217 -- private type, thus it can never apply to an incomplete type.
26219 elsif Is_Incomplete_Type (Typ) then
26220 return;
26221 end if;
26223 DIC_Proc := DIC_Procedure (From_Typ);
26224 Partial_DIC_Proc := Partial_DIC_Procedure (From_Typ);
26226 -- The setting of the attributes is intentionally conservative. This
26227 -- prevents accidental clobbering of enabled attributes. We need to
26228 -- call Base_Type twice, because it is sometimes not set to an actual
26229 -- base type???
26231 if Has_Inherited_DIC (From_Typ) then
26232 Set_Has_Inherited_DIC (Base_Type (Base_Type (Typ)));
26233 end if;
26235 if Has_Own_DIC (From_Typ) then
26236 Set_Has_Own_DIC (Base_Type (Base_Type (Typ)));
26237 end if;
26239 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
26240 Set_DIC_Procedure (Typ, DIC_Proc);
26241 end if;
26243 if Present (Partial_DIC_Proc)
26244 and then No (Partial_DIC_Procedure (Typ))
26245 then
26246 Set_Partial_DIC_Procedure (Typ, Partial_DIC_Proc);
26247 end if;
26248 end if;
26249 end Propagate_DIC_Attributes;
26251 ------------------------------------
26252 -- Propagate_Invariant_Attributes --
26253 ------------------------------------
26255 procedure Propagate_Invariant_Attributes
26256 (Typ : Entity_Id;
26257 From_Typ : Entity_Id)
26259 Full_IP : Entity_Id;
26260 Part_IP : Entity_Id;
26262 begin
26263 if Present (Typ) and then Present (From_Typ) then
26264 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26266 -- Nothing to do if both the source and the destination denote the
26267 -- same type.
26269 if From_Typ = Typ then
26270 return;
26271 end if;
26273 Full_IP := Invariant_Procedure (From_Typ);
26274 Part_IP := Partial_Invariant_Procedure (From_Typ);
26276 -- The setting of the attributes is intentionally conservative. This
26277 -- prevents accidental clobbering of enabled attributes. We need to
26278 -- call Base_Type twice, because it is sometimes not set to an actual
26279 -- base type???
26281 if Has_Inheritable_Invariants (From_Typ) then
26282 Set_Has_Inheritable_Invariants (Base_Type (Base_Type (Typ)));
26283 end if;
26285 if Has_Inherited_Invariants (From_Typ) then
26286 Set_Has_Inherited_Invariants (Base_Type (Base_Type (Typ)));
26287 end if;
26289 if Has_Own_Invariants (From_Typ) then
26290 Set_Has_Own_Invariants (Base_Type (Base_Type (Typ)));
26291 end if;
26293 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
26294 Set_Invariant_Procedure (Typ, Full_IP);
26295 end if;
26297 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
26298 then
26299 Set_Partial_Invariant_Procedure (Typ, Part_IP);
26300 end if;
26301 end if;
26302 end Propagate_Invariant_Attributes;
26304 ------------------------------------
26305 -- Propagate_Predicate_Attributes --
26306 ------------------------------------
26308 procedure Propagate_Predicate_Attributes
26309 (Typ : Entity_Id;
26310 From_Typ : Entity_Id)
26312 Pred_Func : Entity_Id;
26313 begin
26314 if Present (Typ) and then Present (From_Typ) then
26315 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
26317 -- Nothing to do if both the source and the destination denote the
26318 -- same type.
26320 if From_Typ = Typ then
26321 return;
26322 end if;
26324 Pred_Func := Predicate_Function (From_Typ);
26326 -- The setting of the attributes is intentionally conservative. This
26327 -- prevents accidental clobbering of enabled attributes.
26329 if Has_Predicates (From_Typ) then
26330 Set_Has_Predicates (Typ);
26331 end if;
26333 if Present (Pred_Func) and then No (Predicate_Function (Typ)) then
26334 Set_Predicate_Function (Typ, Pred_Func);
26335 end if;
26336 end if;
26337 end Propagate_Predicate_Attributes;
26339 ---------------------------------------
26340 -- Record_Possible_Part_Of_Reference --
26341 ---------------------------------------
26343 procedure Record_Possible_Part_Of_Reference
26344 (Var_Id : Entity_Id;
26345 Ref : Node_Id)
26347 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
26348 Refs : Elist_Id;
26350 begin
26351 -- The variable is a constituent of a single protected/task type. Such
26352 -- a variable acts as a component of the type and must appear within a
26353 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
26354 -- verify its legality now.
26356 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
26357 Check_Part_Of_Reference (Var_Id, Ref);
26359 -- The variable is subject to pragma Part_Of and may eventually become a
26360 -- constituent of a single protected/task type. Record the reference to
26361 -- verify its placement when the contract of the variable is analyzed.
26363 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
26364 Refs := Part_Of_References (Var_Id);
26366 if No (Refs) then
26367 Refs := New_Elmt_List;
26368 Set_Part_Of_References (Var_Id, Refs);
26369 end if;
26371 Append_Elmt (Ref, Refs);
26372 end if;
26373 end Record_Possible_Part_Of_Reference;
26375 ----------------
26376 -- Referenced --
26377 ----------------
26379 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
26380 Seen : Boolean := False;
26382 function Is_Reference (N : Node_Id) return Traverse_Result;
26383 -- Determine whether node N denotes a reference to Id. If this is the
26384 -- case, set global flag Seen to True and stop the traversal.
26386 ------------------
26387 -- Is_Reference --
26388 ------------------
26390 function Is_Reference (N : Node_Id) return Traverse_Result is
26391 begin
26392 if Is_Entity_Name (N)
26393 and then Present (Entity (N))
26394 and then Entity (N) = Id
26395 then
26396 Seen := True;
26397 return Abandon;
26398 else
26399 return OK;
26400 end if;
26401 end Is_Reference;
26403 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
26405 -- Start of processing for Referenced
26407 begin
26408 Inspect_Expression (Expr);
26409 return Seen;
26410 end Referenced;
26412 ------------------------------------
26413 -- References_Generic_Formal_Type --
26414 ------------------------------------
26416 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
26418 function Process (N : Node_Id) return Traverse_Result;
26419 -- Process one node in search for generic formal type
26421 -------------
26422 -- Process --
26423 -------------
26425 function Process (N : Node_Id) return Traverse_Result is
26426 begin
26427 if Nkind (N) in N_Has_Entity then
26428 declare
26429 E : constant Entity_Id := Entity (N);
26430 begin
26431 if Present (E) then
26432 if Is_Generic_Type (E) then
26433 return Abandon;
26434 elsif Present (Etype (E))
26435 and then Is_Generic_Type (Etype (E))
26436 then
26437 return Abandon;
26438 end if;
26439 end if;
26440 end;
26441 end if;
26443 return Atree.OK;
26444 end Process;
26446 function Traverse is new Traverse_Func (Process);
26447 -- Traverse tree to look for generic type
26449 begin
26450 if Inside_A_Generic then
26451 return Traverse (N) = Abandon;
26452 else
26453 return False;
26454 end if;
26455 end References_Generic_Formal_Type;
26457 -------------------------------
26458 -- Remove_Entity_And_Homonym --
26459 -------------------------------
26461 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
26462 begin
26463 Remove_Entity (Id);
26464 Remove_Homonym (Id);
26465 end Remove_Entity_And_Homonym;
26467 --------------------
26468 -- Remove_Homonym --
26469 --------------------
26471 procedure Remove_Homonym (Id : Entity_Id) is
26472 Hom : Entity_Id;
26473 Prev : Entity_Id := Empty;
26475 begin
26476 if Id = Current_Entity (Id) then
26477 if Present (Homonym (Id)) then
26478 Set_Current_Entity (Homonym (Id));
26479 else
26480 Set_Name_Entity_Id (Chars (Id), Empty);
26481 end if;
26483 else
26484 Hom := Current_Entity (Id);
26485 while Present (Hom) and then Hom /= Id loop
26486 Prev := Hom;
26487 Hom := Homonym (Hom);
26488 end loop;
26490 -- If Id is not on the homonym chain, nothing to do
26492 if Present (Hom) then
26493 Set_Homonym (Prev, Homonym (Id));
26494 end if;
26495 end if;
26496 end Remove_Homonym;
26498 ------------------------------
26499 -- Remove_Overloaded_Entity --
26500 ------------------------------
26502 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
26503 procedure Remove_Primitive_Of (Typ : Entity_Id);
26504 -- Remove primitive subprogram Id from the list of primitives that
26505 -- belong to type Typ.
26507 -------------------------
26508 -- Remove_Primitive_Of --
26509 -------------------------
26511 procedure Remove_Primitive_Of (Typ : Entity_Id) is
26512 Prims : Elist_Id;
26514 begin
26515 if Is_Tagged_Type (Typ) then
26516 Prims := Direct_Primitive_Operations (Typ);
26518 if Present (Prims) then
26519 Remove (Prims, Id);
26520 end if;
26521 end if;
26522 end Remove_Primitive_Of;
26524 -- Local variables
26526 Formal : Entity_Id;
26528 -- Start of processing for Remove_Overloaded_Entity
26530 begin
26531 Remove_Entity_And_Homonym (Id);
26533 -- The entity denotes a primitive subprogram. Remove it from the list of
26534 -- primitives of the associated controlling type.
26536 if Ekind (Id) in E_Function | E_Procedure and then Is_Primitive (Id) then
26537 Formal := First_Formal (Id);
26538 while Present (Formal) loop
26539 if Is_Controlling_Formal (Formal) then
26540 Remove_Primitive_Of (Etype (Formal));
26541 exit;
26542 end if;
26544 Next_Formal (Formal);
26545 end loop;
26547 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
26548 Remove_Primitive_Of (Etype (Id));
26549 end if;
26550 end if;
26551 end Remove_Overloaded_Entity;
26553 ---------------------
26554 -- Rep_To_Pos_Flag --
26555 ---------------------
26557 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
26558 begin
26559 return New_Occurrence_Of
26560 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
26561 end Rep_To_Pos_Flag;
26563 --------------------
26564 -- Require_Entity --
26565 --------------------
26567 procedure Require_Entity (N : Node_Id) is
26568 begin
26569 if Is_Entity_Name (N) and then No (Entity (N)) then
26570 if Total_Errors_Detected /= 0 then
26571 Set_Entity (N, Any_Id);
26572 else
26573 raise Program_Error;
26574 end if;
26575 end if;
26576 end Require_Entity;
26578 ------------------------------
26579 -- Requires_Transient_Scope --
26580 ------------------------------
26582 function Requires_Transient_Scope (Typ : Entity_Id) return Boolean is
26583 begin
26584 return Needs_Secondary_Stack (Typ) or else Needs_Finalization (Typ);
26585 end Requires_Transient_Scope;
26587 --------------------------
26588 -- Reset_Analyzed_Flags --
26589 --------------------------
26591 procedure Reset_Analyzed_Flags (N : Node_Id) is
26592 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
26593 -- Function used to reset Analyzed flags in tree. Note that we do
26594 -- not reset Analyzed flags in entities, since there is no need to
26595 -- reanalyze entities, and indeed, it is wrong to do so, since it
26596 -- can result in generating auxiliary stuff more than once.
26598 --------------------
26599 -- Clear_Analyzed --
26600 --------------------
26602 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
26603 begin
26604 if Nkind (N) not in N_Entity then
26605 Set_Analyzed (N, False);
26606 end if;
26608 return OK;
26609 end Clear_Analyzed;
26611 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
26613 -- Start of processing for Reset_Analyzed_Flags
26615 begin
26616 Reset_Analyzed (N);
26617 end Reset_Analyzed_Flags;
26619 ------------------------
26620 -- Restore_SPARK_Mode --
26621 ------------------------
26623 procedure Restore_SPARK_Mode
26624 (Mode : SPARK_Mode_Type;
26625 Prag : Node_Id)
26627 begin
26628 SPARK_Mode := Mode;
26629 SPARK_Mode_Pragma := Prag;
26630 end Restore_SPARK_Mode;
26632 --------------------------------
26633 -- Returns_Unconstrained_Type --
26634 --------------------------------
26636 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
26637 begin
26638 return Ekind (Subp) = E_Function
26639 and then not Is_Scalar_Type (Etype (Subp))
26640 and then not Is_Access_Type (Etype (Subp))
26641 and then not Is_Constrained (Etype (Subp));
26642 end Returns_Unconstrained_Type;
26644 ----------------------------
26645 -- Root_Type_Of_Full_View --
26646 ----------------------------
26648 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
26649 Rtyp : constant Entity_Id := Root_Type (T);
26651 begin
26652 -- The root type of the full view may itself be a private type. Keep
26653 -- looking for the ultimate derivation parent.
26655 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
26656 return Root_Type_Of_Full_View (Full_View (Rtyp));
26657 else
26658 return Rtyp;
26659 end if;
26660 end Root_Type_Of_Full_View;
26662 ---------------------------
26663 -- Safe_To_Capture_Value --
26664 ---------------------------
26666 function Safe_To_Capture_Value
26667 (N : Node_Id;
26668 Ent : Entity_Id;
26669 Cond : Boolean := False) return Boolean
26671 begin
26672 -- The only entities for which we track constant values are variables
26673 -- that are not renamings, constants and formal parameters, so check
26674 -- if we have this case.
26676 -- Note: it may seem odd to track constant values for constants, but in
26677 -- fact this routine is used for other purposes than simply capturing
26678 -- the value. In particular, the setting of Known[_Non]_Null and
26679 -- Is_Known_Valid.
26681 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
26682 or else
26683 Ekind (Ent) = E_Constant
26684 or else
26685 Is_Formal (Ent)
26686 then
26687 null;
26689 -- For conditionals, we also allow loop parameters
26691 elsif Cond and then Ekind (Ent) = E_Loop_Parameter then
26692 null;
26694 -- For all other cases, not just unsafe, but impossible to capture
26695 -- Current_Value, since the above are the only entities which have
26696 -- Current_Value fields.
26698 else
26699 return False;
26700 end if;
26702 -- Skip if volatile or aliased, since funny things might be going on in
26703 -- these cases which we cannot necessarily track. Also skip any variable
26704 -- for which an address clause is given, or whose address is taken. Also
26705 -- never capture value of library level variables (an attempt to do so
26706 -- can occur in the case of package elaboration code).
26708 if Treat_As_Volatile (Ent)
26709 or else Is_Aliased (Ent)
26710 or else Present (Address_Clause (Ent))
26711 or else Address_Taken (Ent)
26712 or else (Is_Library_Level_Entity (Ent)
26713 and then Ekind (Ent) = E_Variable)
26714 then
26715 return False;
26716 end if;
26718 -- OK, all above conditions are met. We also require that the scope of
26719 -- the reference be the same as the scope of the entity, not counting
26720 -- packages and blocks and loops.
26722 declare
26723 E_Scope : constant Entity_Id := Scope (Ent);
26724 R_Scope : Entity_Id;
26726 begin
26727 R_Scope := Current_Scope;
26728 while R_Scope /= Standard_Standard loop
26729 exit when R_Scope = E_Scope;
26731 if Ekind (R_Scope) not in E_Package | E_Block | E_Loop then
26732 return False;
26733 else
26734 R_Scope := Scope (R_Scope);
26735 end if;
26736 end loop;
26737 end;
26739 -- We also require that the reference does not appear in a context
26740 -- where it is not sure to be executed (i.e. a conditional context
26741 -- or an exception handler). We skip this if Cond is True, since the
26742 -- capturing of values from conditional tests handles this ok.
26744 if Cond or else No (N) then
26745 return True;
26746 end if;
26748 declare
26749 Desc : Node_Id;
26750 P : Node_Id;
26752 begin
26753 Desc := N;
26755 -- Seems dubious that case expressions are not handled here ???
26757 P := Parent (N);
26758 while Present (P) loop
26759 if Is_Body (P) then
26760 return True;
26762 elsif Nkind (P) = N_If_Statement
26763 or else Nkind (P) = N_Case_Statement
26764 or else (Nkind (P) in N_Short_Circuit
26765 and then Desc = Right_Opnd (P))
26766 or else (Nkind (P) = N_If_Expression
26767 and then Desc /= First (Expressions (P)))
26768 or else Nkind (P) = N_Exception_Handler
26769 or else Nkind (P) = N_Selective_Accept
26770 or else Nkind (P) = N_Conditional_Entry_Call
26771 or else Nkind (P) = N_Timed_Entry_Call
26772 or else Nkind (P) = N_Asynchronous_Select
26773 then
26774 return False;
26776 else
26777 Desc := P;
26778 P := Parent (P);
26780 -- A special Ada 2012 case: the original node may be part
26781 -- of the else_actions of a conditional expression, in which
26782 -- case it might not have been expanded yet, and appears in
26783 -- a non-syntactic list of actions. In that case it is clearly
26784 -- not safe to save a value.
26786 if No (P)
26787 and then Is_List_Member (Desc)
26788 and then No (Parent (List_Containing (Desc)))
26789 then
26790 return False;
26791 end if;
26792 end if;
26793 end loop;
26794 end;
26796 -- OK, looks safe to set value
26798 return True;
26799 end Safe_To_Capture_Value;
26801 ---------------
26802 -- Same_Name --
26803 ---------------
26805 function Same_Name (N1, N2 : Node_Id) return Boolean is
26806 K1 : constant Node_Kind := Nkind (N1);
26807 K2 : constant Node_Kind := Nkind (N2);
26809 begin
26810 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
26811 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
26812 then
26813 return Chars (N1) = Chars (N2);
26815 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
26816 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
26817 then
26818 return Same_Name (Selector_Name (N1), Selector_Name (N2))
26819 and then Same_Name (Prefix (N1), Prefix (N2));
26821 else
26822 return False;
26823 end if;
26824 end Same_Name;
26826 -----------------
26827 -- Same_Object --
26828 -----------------
26830 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
26831 N1 : constant Node_Id := Original_Node (Node1);
26832 N2 : constant Node_Id := Original_Node (Node2);
26833 -- We do the tests on original nodes, since we are most interested
26834 -- in the original source, not any expansion that got in the way.
26836 K1 : constant Node_Kind := Nkind (N1);
26837 K2 : constant Node_Kind := Nkind (N2);
26839 begin
26840 -- First case, both are entities with same entity
26842 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
26843 declare
26844 EN1 : constant Entity_Id := Entity (N1);
26845 EN2 : constant Entity_Id := Entity (N2);
26846 begin
26847 if Present (EN1) and then Present (EN2)
26848 and then (Ekind (EN1) in E_Variable | E_Constant
26849 or else Is_Formal (EN1))
26850 and then EN1 = EN2
26851 then
26852 return True;
26853 end if;
26854 end;
26855 end if;
26857 -- Second case, selected component with same selector, same record
26859 if K1 = N_Selected_Component
26860 and then K2 = N_Selected_Component
26861 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
26862 then
26863 return Same_Object (Prefix (N1), Prefix (N2));
26865 -- Third case, indexed component with same subscripts, same array
26867 elsif K1 = N_Indexed_Component
26868 and then K2 = N_Indexed_Component
26869 and then Same_Object (Prefix (N1), Prefix (N2))
26870 then
26871 declare
26872 E1, E2 : Node_Id;
26873 begin
26874 E1 := First (Expressions (N1));
26875 E2 := First (Expressions (N2));
26876 while Present (E1) loop
26877 if not Same_Value (E1, E2) then
26878 return False;
26879 else
26880 Next (E1);
26881 Next (E2);
26882 end if;
26883 end loop;
26885 return True;
26886 end;
26888 -- Fourth case, slice of same array with same bounds
26890 elsif K1 = N_Slice
26891 and then K2 = N_Slice
26892 and then Nkind (Discrete_Range (N1)) = N_Range
26893 and then Nkind (Discrete_Range (N2)) = N_Range
26894 and then Same_Value (Low_Bound (Discrete_Range (N1)),
26895 Low_Bound (Discrete_Range (N2)))
26896 and then Same_Value (High_Bound (Discrete_Range (N1)),
26897 High_Bound (Discrete_Range (N2)))
26898 then
26899 return Same_Name (Prefix (N1), Prefix (N2));
26901 -- All other cases, not clearly the same object
26903 else
26904 return False;
26905 end if;
26906 end Same_Object;
26908 ---------------------------------
26909 -- Same_Or_Aliased_Subprograms --
26910 ---------------------------------
26912 function Same_Or_Aliased_Subprograms
26913 (S : Entity_Id;
26914 E : Entity_Id) return Boolean
26916 Subp_Alias : constant Entity_Id := Alias (S);
26917 Subp : Entity_Id := E;
26918 begin
26919 -- During expansion of subprograms with postconditions the original
26920 -- subprogram's declarations and statements get wrapped into a local
26921 -- _Wrapped_Statements subprogram.
26923 if Chars (Subp) = Name_uWrapped_Statements then
26924 Subp := Enclosing_Subprogram (Subp);
26925 end if;
26927 return S = Subp
26928 or else (Present (Subp_Alias) and then Subp_Alias = Subp);
26929 end Same_Or_Aliased_Subprograms;
26931 ---------------
26932 -- Same_Type --
26933 ---------------
26935 function Same_Type (T1, T2 : Entity_Id) return Boolean is
26936 begin
26937 if T1 = T2 then
26938 return True;
26940 elsif not Is_Constrained (T1)
26941 and then not Is_Constrained (T2)
26942 and then Base_Type (T1) = Base_Type (T2)
26943 then
26944 return True;
26946 -- For now don't bother with case of identical constraints, to be
26947 -- fiddled with later on perhaps (this is only used for optimization
26948 -- purposes, so it is not critical to do a best possible job)
26950 else
26951 return False;
26952 end if;
26953 end Same_Type;
26955 ----------------
26956 -- Same_Value --
26957 ----------------
26959 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
26960 begin
26961 if Compile_Time_Known_Value (Node1)
26962 and then Compile_Time_Known_Value (Node2)
26963 then
26964 -- Handle properly compile-time expressions that are not
26965 -- scalar.
26967 if Is_String_Type (Etype (Node1)) then
26968 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
26970 else
26971 return Expr_Value (Node1) = Expr_Value (Node2);
26972 end if;
26974 elsif Same_Object (Node1, Node2) then
26975 return True;
26976 else
26977 return False;
26978 end if;
26979 end Same_Value;
26981 --------------------
26982 -- Set_SPARK_Mode --
26983 --------------------
26985 procedure Set_SPARK_Mode (Context : Entity_Id) is
26986 begin
26987 -- Do not consider illegal or partially decorated constructs
26989 if Ekind (Context) = E_Void or else Error_Posted (Context) then
26990 null;
26992 elsif Present (SPARK_Pragma (Context)) then
26993 Install_SPARK_Mode
26994 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
26995 Prag => SPARK_Pragma (Context));
26996 end if;
26997 end Set_SPARK_Mode;
26999 -------------------------
27000 -- Scalar_Part_Present --
27001 -------------------------
27003 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
27004 Val_Typ : constant Entity_Id := Validated_View (Typ);
27005 Field : Entity_Id;
27007 begin
27008 if Is_Scalar_Type (Val_Typ) then
27009 return True;
27011 elsif Is_Array_Type (Val_Typ) then
27012 return Scalar_Part_Present (Component_Type (Val_Typ));
27014 elsif Is_Record_Type (Val_Typ) then
27015 Field := First_Component_Or_Discriminant (Val_Typ);
27016 while Present (Field) loop
27017 if Scalar_Part_Present (Etype (Field)) then
27018 return True;
27019 end if;
27021 Next_Component_Or_Discriminant (Field);
27022 end loop;
27023 end if;
27025 return False;
27026 end Scalar_Part_Present;
27028 ------------------------
27029 -- Scope_Is_Transient --
27030 ------------------------
27032 function Scope_Is_Transient return Boolean is
27033 begin
27034 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
27035 end Scope_Is_Transient;
27037 ------------------
27038 -- Scope_Within --
27039 ------------------
27041 function Scope_Within
27042 (Inner : Entity_Id;
27043 Outer : Entity_Id) return Boolean
27045 Curr : Entity_Id;
27047 begin
27048 Curr := Inner;
27049 while Present (Curr) and then Curr /= Standard_Standard loop
27050 Curr := Scope (Curr);
27052 if Curr = Outer then
27053 return True;
27055 -- A selective accept body appears within a task type, but the
27056 -- enclosing subprogram is the procedure of the task body.
27058 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
27059 and then
27060 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
27061 then
27062 return True;
27064 -- Ditto for the body of a protected operation
27066 elsif Is_Subprogram (Curr)
27067 and then Outer = Protected_Body_Subprogram (Curr)
27068 then
27069 return True;
27071 -- The body of a protected operation is within the protected type
27073 elsif Is_Subprogram (Curr)
27074 and then Present (Protected_Subprogram (Curr))
27075 and then Is_Protected_Type (Outer)
27076 and then Scope (Protected_Subprogram (Curr)) = Outer
27077 then
27078 return True;
27080 -- Outside of its scope, a synchronized type may just be private
27082 elsif Is_Private_Type (Curr)
27083 and then Present (Full_View (Curr))
27084 and then Is_Concurrent_Type (Full_View (Curr))
27085 then
27086 return Scope_Within (Full_View (Curr), Outer);
27087 end if;
27088 end loop;
27090 return False;
27091 end Scope_Within;
27093 --------------------------
27094 -- Scope_Within_Or_Same --
27095 --------------------------
27097 function Scope_Within_Or_Same
27098 (Inner : Entity_Id;
27099 Outer : Entity_Id) return Boolean
27101 Curr : Entity_Id := Inner;
27103 begin
27104 -- Similar to the above, but check for scope identity first
27106 while Present (Curr) and then Curr /= Standard_Standard loop
27107 if Curr = Outer then
27108 return True;
27110 elsif Ekind (Implementation_Base_Type (Curr)) = E_Task_Type
27111 and then
27112 Outer = Task_Body_Procedure (Implementation_Base_Type (Curr))
27113 then
27114 return True;
27116 elsif Is_Subprogram (Curr)
27117 and then Outer = Protected_Body_Subprogram (Curr)
27118 then
27119 return True;
27121 elsif Is_Subprogram (Curr)
27122 and then Present (Protected_Subprogram (Curr))
27123 and then Is_Protected_Type (Outer)
27124 and then Scope (Protected_Subprogram (Curr)) = Outer
27125 then
27126 return True;
27128 elsif Is_Private_Type (Curr)
27129 and then Present (Full_View (Curr))
27130 then
27131 if Full_View (Curr) = Outer then
27132 return True;
27133 else
27134 return Scope_Within (Full_View (Curr), Outer);
27135 end if;
27136 end if;
27138 Curr := Scope (Curr);
27139 end loop;
27141 return False;
27142 end Scope_Within_Or_Same;
27144 ------------------------
27145 -- Set_Current_Entity --
27146 ------------------------
27148 -- The given entity is to be set as the currently visible definition of its
27149 -- associated name (i.e. the Node_Id associated with its name). All we have
27150 -- to do is to get the name from the identifier, and then set the
27151 -- associated Node_Id to point to the given entity.
27153 procedure Set_Current_Entity (E : Entity_Id) is
27154 begin
27155 Set_Name_Entity_Id (Chars (E), E);
27156 end Set_Current_Entity;
27158 ---------------------------
27159 -- Set_Debug_Info_Needed --
27160 ---------------------------
27162 procedure Set_Debug_Info_Needed (T : Entity_Id) is
27164 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
27165 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
27166 -- Used to set debug info in a related node if not set already
27168 --------------------------------------
27169 -- Set_Debug_Info_Needed_If_Not_Set --
27170 --------------------------------------
27172 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
27173 begin
27174 if Present (E) and then not Needs_Debug_Info (E) then
27175 Set_Debug_Info_Needed (E);
27177 -- For a private type, indicate that the full view also needs
27178 -- debug information.
27180 if Is_Type (E)
27181 and then Is_Private_Type (E)
27182 and then Present (Full_View (E))
27183 then
27184 Set_Debug_Info_Needed (Full_View (E));
27185 end if;
27186 end if;
27187 end Set_Debug_Info_Needed_If_Not_Set;
27189 -- Start of processing for Set_Debug_Info_Needed
27191 begin
27192 -- Nothing to do if there is no available entity
27194 if No (T) then
27195 return;
27197 -- Nothing to do for an entity with suppressed debug information
27199 elsif Debug_Info_Off (T) then
27200 return;
27202 -- Nothing to do for an ignored Ghost entity because the entity will be
27203 -- eliminated from the tree.
27205 elsif Is_Ignored_Ghost_Entity (T) then
27206 return;
27208 -- Nothing to do if entity comes from a predefined file. Library files
27209 -- are compiled without debug information, but inlined bodies of these
27210 -- routines may appear in user code, and debug information on them ends
27211 -- up complicating debugging the user code.
27213 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
27214 Set_Needs_Debug_Info (T, False);
27215 end if;
27217 -- Set flag in entity itself. Note that we will go through the following
27218 -- circuitry even if the flag is already set on T. That's intentional,
27219 -- it makes sure that the flag will be set in subsidiary entities.
27221 Set_Needs_Debug_Info (T);
27223 -- Set flag on subsidiary entities if not set already
27225 if Is_Object (T) then
27226 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
27228 elsif Is_Type (T) then
27229 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
27231 if Is_Record_Type (T) then
27232 declare
27233 Ent : Entity_Id := First_Entity (T);
27234 begin
27235 while Present (Ent) loop
27236 Set_Debug_Info_Needed_If_Not_Set (Ent);
27237 Next_Entity (Ent);
27238 end loop;
27239 end;
27241 -- For a class wide subtype, we also need debug information
27242 -- for the equivalent type.
27244 if Ekind (T) = E_Class_Wide_Subtype then
27245 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
27246 end if;
27248 elsif Is_Array_Type (T) then
27249 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
27251 declare
27252 Indx : Node_Id := First_Index (T);
27253 begin
27254 while Present (Indx) loop
27255 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
27256 Next_Index (Indx);
27257 end loop;
27258 end;
27260 -- For a packed array type, we also need debug information for
27261 -- the type used to represent the packed array. Conversely, we
27262 -- also need it for the former if we need it for the latter.
27264 if Is_Packed (T) then
27265 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
27266 end if;
27268 if Is_Packed_Array_Impl_Type (T) then
27269 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
27270 end if;
27272 elsif Is_Access_Type (T) then
27273 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
27275 elsif Is_Private_Type (T) then
27276 declare
27277 FV : constant Entity_Id := Full_View (T);
27279 begin
27280 Set_Debug_Info_Needed_If_Not_Set (FV);
27282 -- If the full view is itself a derived private type, we need
27283 -- debug information on its underlying type.
27285 if Present (FV)
27286 and then Is_Private_Type (FV)
27287 and then Present (Underlying_Full_View (FV))
27288 then
27289 Set_Needs_Debug_Info (Underlying_Full_View (FV));
27290 end if;
27291 end;
27293 elsif Is_Protected_Type (T) then
27294 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
27296 elsif Is_Scalar_Type (T) then
27298 -- If the subrange bounds are materialized by dedicated constant
27299 -- objects, also include them in the debug info to make sure the
27300 -- debugger can properly use them.
27302 if Present (Scalar_Range (T))
27303 and then Nkind (Scalar_Range (T)) = N_Range
27304 then
27305 declare
27306 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
27307 High_Bnd : constant Node_Id := Type_High_Bound (T);
27309 begin
27310 if Is_Entity_Name (Low_Bnd) then
27311 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
27312 end if;
27314 if Is_Entity_Name (High_Bnd) then
27315 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
27316 end if;
27317 end;
27318 end if;
27319 end if;
27320 end if;
27321 end Set_Debug_Info_Needed;
27323 --------------------------------
27324 -- Set_Debug_Info_Defining_Id --
27325 --------------------------------
27327 procedure Set_Debug_Info_Defining_Id (N : Node_Id) is
27328 begin
27329 if Comes_From_Source (Defining_Identifier (N))
27330 or else Debug_Generated_Code
27331 then
27332 Set_Debug_Info_Needed (Defining_Identifier (N));
27333 end if;
27334 end Set_Debug_Info_Defining_Id;
27336 ----------------------------
27337 -- Set_Entity_With_Checks --
27338 ----------------------------
27340 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
27341 Val_Actual : Entity_Id;
27342 Nod : Node_Id;
27343 Post_Node : Node_Id;
27345 begin
27346 -- Unconditionally set the entity
27348 Set_Entity (N, Val);
27350 -- The node to post on is the selector in the case of an expanded name,
27351 -- and otherwise the node itself.
27353 if Nkind (N) = N_Expanded_Name then
27354 Post_Node := Selector_Name (N);
27355 else
27356 Post_Node := N;
27357 end if;
27359 -- Check for violation of No_Fixed_IO
27361 if Restriction_Check_Required (No_Fixed_IO)
27362 and then
27363 ((RTU_Loaded (Ada_Text_IO)
27364 and then (Is_RTE (Val, RE_Decimal_IO)
27365 or else
27366 Is_RTE (Val, RE_Fixed_IO)))
27368 or else
27369 (RTU_Loaded (Ada_Wide_Text_IO)
27370 and then (Is_RTE (Val, RO_WT_Decimal_IO)
27371 or else
27372 Is_RTE (Val, RO_WT_Fixed_IO)))
27374 or else
27375 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
27376 and then (Is_RTE (Val, RO_WW_Decimal_IO)
27377 or else
27378 Is_RTE (Val, RO_WW_Fixed_IO))))
27380 -- A special extra check, don't complain about a reference from within
27381 -- the Ada.Interrupts package itself!
27383 and then not In_Same_Extended_Unit (N, Val)
27384 then
27385 Check_Restriction (No_Fixed_IO, Post_Node);
27386 end if;
27388 -- Remaining checks are only done on source nodes. Note that we test
27389 -- for violation of No_Fixed_IO even on non-source nodes, because the
27390 -- cases for checking violations of this restriction are instantiations
27391 -- where the reference in the instance has Comes_From_Source False.
27393 if not Comes_From_Source (N) then
27394 return;
27395 end if;
27397 -- Check for violation of No_Abort_Statements, which is triggered by
27398 -- call to Ada.Task_Identification.Abort_Task.
27400 if Restriction_Check_Required (No_Abort_Statements)
27401 and then Is_RTE (Val, RE_Abort_Task)
27403 -- A special extra check, don't complain about a reference from within
27404 -- the Ada.Task_Identification package itself!
27406 and then not In_Same_Extended_Unit (N, Val)
27407 then
27408 Check_Restriction (No_Abort_Statements, Post_Node);
27409 end if;
27411 if Val = Standard_Long_Long_Integer then
27412 Check_Restriction (No_Long_Long_Integers, Post_Node);
27413 end if;
27415 -- Check for violation of No_Dynamic_Attachment
27417 if Restriction_Check_Required (No_Dynamic_Attachment)
27418 and then RTU_Loaded (Ada_Interrupts)
27419 and then (Is_RTE (Val, RE_Is_Reserved) or else
27420 Is_RTE (Val, RE_Is_Attached) or else
27421 Is_RTE (Val, RE_Current_Handler) or else
27422 Is_RTE (Val, RE_Attach_Handler) or else
27423 Is_RTE (Val, RE_Exchange_Handler) or else
27424 Is_RTE (Val, RE_Detach_Handler) or else
27425 Is_RTE (Val, RE_Reference))
27427 -- A special extra check, don't complain about a reference from within
27428 -- the Ada.Interrupts package itself!
27430 and then not In_Same_Extended_Unit (N, Val)
27431 then
27432 Check_Restriction (No_Dynamic_Attachment, Post_Node);
27433 end if;
27435 -- Check for No_Implementation_Identifiers
27437 if Restriction_Check_Required (No_Implementation_Identifiers) then
27439 -- We have an implementation defined entity if it is marked as
27440 -- implementation defined, or is defined in a package marked as
27441 -- implementation defined. However, library packages themselves
27442 -- are excluded (we don't want to flag Interfaces itself, just
27443 -- the entities within it).
27445 if (Is_Implementation_Defined (Val)
27446 or else
27447 (Present (Scope (Val))
27448 and then Is_Implementation_Defined (Scope (Val))))
27449 and then not (Is_Package_Or_Generic_Package (Val)
27450 and then Is_Library_Level_Entity (Val))
27451 then
27452 Check_Restriction (No_Implementation_Identifiers, Post_Node);
27453 end if;
27454 end if;
27456 -- Do the style check
27458 if Style_Check
27459 and then not Suppress_Style_Checks (Val)
27460 and then not In_Instance
27461 then
27462 if Nkind (N) = N_Identifier then
27463 Nod := N;
27464 elsif Nkind (N) = N_Expanded_Name then
27465 Nod := Selector_Name (N);
27466 else
27467 return;
27468 end if;
27470 -- A special situation arises for derived operations, where we want
27471 -- to do the check against the parent (since the Sloc of the derived
27472 -- operation points to the derived type declaration itself).
27474 Val_Actual := Val;
27475 while not Comes_From_Source (Val_Actual)
27476 and then Nkind (Val_Actual) in N_Entity
27477 and then (Ekind (Val_Actual) = E_Enumeration_Literal
27478 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
27479 and then Present (Alias (Val_Actual))
27480 loop
27481 Val_Actual := Alias (Val_Actual);
27482 end loop;
27484 -- Renaming declarations for generic actuals do not come from source,
27485 -- and have a different name from that of the entity they rename, so
27486 -- there is no style check to perform here.
27488 if Chars (Nod) = Chars (Val_Actual) then
27489 Style.Check_Identifier (Nod, Val_Actual);
27490 end if;
27491 end if;
27492 end Set_Entity_With_Checks;
27494 ------------------------------
27495 -- Set_Invalid_Scalar_Value --
27496 ------------------------------
27498 procedure Set_Invalid_Scalar_Value
27499 (Scal_Typ : Float_Scalar_Id;
27500 Value : Ureal)
27502 Slot : Ureal renames Invalid_Floats (Scal_Typ);
27504 begin
27505 -- Detect an attempt to set a different value for the same scalar type
27507 pragma Assert (Slot = No_Ureal);
27508 Slot := Value;
27509 end Set_Invalid_Scalar_Value;
27511 ------------------------------
27512 -- Set_Invalid_Scalar_Value --
27513 ------------------------------
27515 procedure Set_Invalid_Scalar_Value
27516 (Scal_Typ : Integer_Scalar_Id;
27517 Value : Uint)
27519 Slot : Uint renames Invalid_Integers (Scal_Typ);
27521 begin
27522 -- Detect an attempt to set a different value for the same scalar type
27524 pragma Assert (No (Slot));
27525 Slot := Value;
27526 end Set_Invalid_Scalar_Value;
27528 ------------------------
27529 -- Set_Name_Entity_Id --
27530 ------------------------
27532 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
27533 begin
27534 Set_Name_Table_Int (Id, Int (Val));
27535 end Set_Name_Entity_Id;
27537 ---------------------
27538 -- Set_Next_Actual --
27539 ---------------------
27541 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
27542 begin
27543 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
27544 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
27545 end if;
27546 end Set_Next_Actual;
27548 ----------------------------------
27549 -- Set_Optimize_Alignment_Flags --
27550 ----------------------------------
27552 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
27553 begin
27554 if Optimize_Alignment = 'S' then
27555 Set_Optimize_Alignment_Space (E);
27556 elsif Optimize_Alignment = 'T' then
27557 Set_Optimize_Alignment_Time (E);
27558 end if;
27559 end Set_Optimize_Alignment_Flags;
27561 -----------------------
27562 -- Set_Public_Status --
27563 -----------------------
27565 procedure Set_Public_Status (Id : Entity_Id) is
27566 S : constant Entity_Id := Current_Scope;
27568 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
27569 -- Determines if E is defined within handled statement sequence or
27570 -- an if statement, returns True if so, False otherwise.
27572 ----------------------
27573 -- Within_HSS_Or_If --
27574 ----------------------
27576 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
27577 N : Node_Id;
27578 begin
27579 N := Declaration_Node (E);
27580 loop
27581 N := Parent (N);
27583 if No (N) then
27584 return False;
27586 elsif Nkind (N) in
27587 N_Handled_Sequence_Of_Statements | N_If_Statement
27588 then
27589 return True;
27590 end if;
27591 end loop;
27592 end Within_HSS_Or_If;
27594 -- Start of processing for Set_Public_Status
27596 begin
27597 -- Everything in the scope of Standard is public
27599 if S = Standard_Standard then
27600 Set_Is_Public (Id);
27602 -- Entity is definitely not public if enclosing scope is not public
27604 elsif not Is_Public (S) then
27605 return;
27607 -- An object or function declaration that occurs in a handled sequence
27608 -- of statements or within an if statement is the declaration for a
27609 -- temporary object or local subprogram generated by the expander. It
27610 -- never needs to be made public and furthermore, making it public can
27611 -- cause back end problems.
27613 elsif Nkind (Parent (Id)) in
27614 N_Object_Declaration | N_Function_Specification
27615 and then Within_HSS_Or_If (Id)
27616 then
27617 return;
27619 -- Entities in public packages or records are public
27621 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
27622 Set_Is_Public (Id);
27624 -- The bounds of an entry family declaration can generate object
27625 -- declarations that are visible to the back-end, e.g. in the
27626 -- the declaration of a composite type that contains tasks.
27628 elsif Is_Concurrent_Type (S)
27629 and then not Has_Completion (S)
27630 and then Nkind (Parent (Id)) = N_Object_Declaration
27631 then
27632 Set_Is_Public (Id);
27633 end if;
27634 end Set_Public_Status;
27636 -----------------------------
27637 -- Set_Referenced_Modified --
27638 -----------------------------
27640 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
27641 Pref : Node_Id;
27643 begin
27644 -- Deal with indexed or selected component where prefix is modified
27646 if Nkind (N) in N_Indexed_Component | N_Selected_Component then
27647 Pref := Prefix (N);
27649 -- If prefix is access type, then it is the designated object that is
27650 -- being modified, which means we have no entity to set the flag on.
27652 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
27653 return;
27655 -- Otherwise chase the prefix
27657 else
27658 Set_Referenced_Modified (Pref, Out_Param);
27659 end if;
27661 -- Otherwise see if we have an entity name (only other case to process)
27663 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
27664 Set_Referenced_As_LHS (Entity (N), not Out_Param);
27665 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
27666 end if;
27667 end Set_Referenced_Modified;
27669 ------------------
27670 -- Set_Rep_Info --
27671 ------------------
27673 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
27674 begin
27675 Set_Is_Atomic (T1, Is_Atomic (T2));
27676 Set_Is_Independent (T1, Is_Independent (T2));
27677 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
27679 if Is_Base_Type (T1) then
27680 Set_Is_Volatile (T1, Is_Volatile (T2));
27681 end if;
27682 end Set_Rep_Info;
27684 -------------------
27685 -- Set_Size_Info --
27686 -------------------
27688 procedure Set_Size_Info (T1, T2 : Entity_Id) is
27689 begin
27690 -- We copy Esize, but not RM_Size, since in general RM_Size is
27691 -- subtype specific and does not get inherited by all subtypes.
27693 Copy_Esize (To => T1, From => T2);
27694 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
27696 if Is_Discrete_Or_Fixed_Point_Type (T1)
27697 and then
27698 Is_Discrete_Or_Fixed_Point_Type (T2)
27699 then
27700 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
27701 end if;
27703 Copy_Alignment (To => T1, From => T2);
27704 end Set_Size_Info;
27706 ------------------------------
27707 -- Should_Ignore_Pragma_Par --
27708 ------------------------------
27710 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
27711 pragma Assert (Compiler_State = Parsing);
27712 -- This one can't work during semantic analysis, because we don't have a
27713 -- correct Current_Source_File.
27715 Result : constant Boolean :=
27716 Get_Name_Table_Boolean3 (Prag_Name)
27717 and then not Is_Internal_File_Name
27718 (File_Name (Current_Source_File));
27719 begin
27720 return Result;
27721 end Should_Ignore_Pragma_Par;
27723 ------------------------------
27724 -- Should_Ignore_Pragma_Sem --
27725 ------------------------------
27727 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
27728 pragma Assert (Compiler_State = Analyzing);
27729 Prag_Name : constant Name_Id := Pragma_Name (N);
27730 Result : constant Boolean :=
27731 Get_Name_Table_Boolean3 (Prag_Name)
27732 and then not In_Internal_Unit (N);
27734 begin
27735 return Result;
27736 end Should_Ignore_Pragma_Sem;
27738 --------------------
27739 -- Static_Boolean --
27740 --------------------
27742 function Static_Boolean (N : Node_Id) return Opt_Ubool is
27743 begin
27744 Analyze_And_Resolve (N, Standard_Boolean);
27746 if N = Error
27747 or else Error_Posted (N)
27748 or else Etype (N) = Any_Type
27749 then
27750 return No_Uint;
27751 end if;
27753 if Is_OK_Static_Expression (N) then
27754 if not Raises_Constraint_Error (N) then
27755 return Expr_Value (N);
27756 else
27757 return No_Uint;
27758 end if;
27760 elsif Etype (N) = Any_Type then
27761 return No_Uint;
27763 else
27764 Flag_Non_Static_Expr
27765 ("static boolean expression required here", N);
27766 return No_Uint;
27767 end if;
27768 end Static_Boolean;
27770 --------------------
27771 -- Static_Integer --
27772 --------------------
27774 function Static_Integer (N : Node_Id) return Uint is
27775 begin
27776 Analyze_And_Resolve (N, Any_Integer);
27778 if N = Error
27779 or else Error_Posted (N)
27780 or else Etype (N) = Any_Type
27781 then
27782 return No_Uint;
27783 end if;
27785 if Is_OK_Static_Expression (N) then
27786 if not Raises_Constraint_Error (N) then
27787 return Expr_Value (N);
27788 else
27789 return No_Uint;
27790 end if;
27792 elsif Etype (N) = Any_Type then
27793 return No_Uint;
27795 else
27796 Flag_Non_Static_Expr
27797 ("static integer expression required here", N);
27798 return No_Uint;
27799 end if;
27800 end Static_Integer;
27802 -------------------------------
27803 -- Statically_Denotes_Entity --
27804 -------------------------------
27806 function Statically_Denotes_Entity (N : Node_Id) return Boolean is
27807 E : Entity_Id;
27808 begin
27809 if not Is_Entity_Name (N) then
27810 return False;
27811 else
27812 E := Entity (N);
27813 end if;
27815 return
27816 Nkind (Parent (E)) /= N_Object_Renaming_Declaration
27817 or else Is_Prival (E)
27818 or else Statically_Denotes_Entity (Renamed_Object (E));
27819 end Statically_Denotes_Entity;
27821 -------------------------------
27822 -- Statically_Denotes_Object --
27823 -------------------------------
27825 function Statically_Denotes_Object (N : Node_Id) return Boolean is
27826 begin
27827 return Statically_Denotes_Entity (N)
27828 and then Is_Object_Reference (N);
27829 end Statically_Denotes_Object;
27831 --------------------------
27832 -- Statically_Different --
27833 --------------------------
27835 function Statically_Different (E1, E2 : Node_Id) return Boolean is
27836 R1 : constant Node_Id := Get_Referenced_Object (E1);
27837 R2 : constant Node_Id := Get_Referenced_Object (E2);
27838 begin
27839 return Is_Entity_Name (R1)
27840 and then Is_Entity_Name (R2)
27841 and then Entity (R1) /= Entity (R2)
27842 and then not Is_Formal (Entity (R1))
27843 and then not Is_Formal (Entity (R2));
27844 end Statically_Different;
27846 -----------------------------
27847 -- Statically_Names_Object --
27848 -----------------------------
27850 function Statically_Names_Object (N : Node_Id) return Boolean is
27851 begin
27852 if Statically_Denotes_Object (N) then
27853 return True;
27854 elsif Is_Entity_Name (N) then
27855 declare
27856 E : constant Entity_Id := Entity (N);
27857 begin
27858 return Nkind (Parent (E)) = N_Object_Renaming_Declaration
27859 and then Statically_Names_Object (Renamed_Object (E));
27860 end;
27861 end if;
27863 case Nkind (N) is
27864 when N_Indexed_Component =>
27865 if Is_Access_Type (Etype (Prefix (N))) then
27866 -- treat implicit dereference same as explicit
27867 return False;
27868 end if;
27870 if not Is_Constrained (Etype (Prefix (N))) then
27871 return False;
27872 end if;
27874 declare
27875 Indx : Node_Id := First_Index (Etype (Prefix (N)));
27876 Expr : Node_Id := First (Expressions (N));
27877 Index_Subtype : Node_Id;
27878 begin
27879 loop
27880 Index_Subtype := Etype (Indx);
27882 if not Is_Static_Subtype (Index_Subtype) then
27883 return False;
27884 end if;
27885 if not Is_OK_Static_Expression (Expr) then
27886 return False;
27887 end if;
27889 declare
27890 Index_Value : constant Uint := Expr_Value (Expr);
27891 Low_Value : constant Uint :=
27892 Expr_Value (Type_Low_Bound (Index_Subtype));
27893 High_Value : constant Uint :=
27894 Expr_Value (Type_High_Bound (Index_Subtype));
27895 begin
27896 if Index_Value < Low_Value
27897 or Index_Value > High_Value
27898 then
27899 return False;
27900 end if;
27901 end;
27903 Next_Index (Indx);
27904 Expr := Next (Expr);
27905 pragma Assert (Present (Indx) = Present (Expr)
27906 or else Serious_Errors_Detected > 0);
27907 exit when not (Present (Indx) and Present (Expr));
27908 end loop;
27909 end;
27911 when N_Selected_Component =>
27912 if Is_Access_Type (Etype (Prefix (N))) then
27913 -- treat implicit dereference same as explicit
27914 return False;
27915 end if;
27917 if Ekind (Entity (Selector_Name (N))) not in
27918 E_Component | E_Discriminant
27919 then
27920 return False;
27921 end if;
27923 declare
27924 Comp : constant Entity_Id :=
27925 Original_Record_Component (Entity (Selector_Name (N)));
27926 begin
27927 -- AI12-0373 confirms that we should not call
27928 -- Has_Discriminant_Dependent_Constraint here which would be
27929 -- too strong.
27931 if Is_Declared_Within_Variant (Comp) then
27932 return False;
27933 end if;
27934 end;
27936 when others => -- includes N_Slice, N_Explicit_Dereference
27937 return False;
27938 end case;
27940 pragma Assert (Present (Prefix (N)));
27942 return Statically_Names_Object (Prefix (N));
27943 end Statically_Names_Object;
27945 ---------------------------------
27946 -- String_From_Numeric_Literal --
27947 ---------------------------------
27949 function String_From_Numeric_Literal (N : Node_Id) return String_Id is
27950 Loc : constant Source_Ptr := Sloc (N);
27951 Sbuffer : constant Source_Buffer_Ptr :=
27952 Source_Text (Get_Source_File_Index (Loc));
27953 Src_Ptr : Source_Ptr := Loc;
27955 C : Character := Sbuffer (Src_Ptr);
27956 -- Current source program character
27958 function Belongs_To_Numeric_Literal (C : Character) return Boolean;
27959 -- Return True if C belongs to the numeric literal
27961 --------------------------------
27962 -- Belongs_To_Numeric_Literal --
27963 --------------------------------
27965 function Belongs_To_Numeric_Literal (C : Character) return Boolean is
27966 begin
27967 case C is
27968 when '0' .. '9' | '_' | '.' | 'e' | '#' | 'A' .. 'F' =>
27969 return True;
27971 -- Make sure '+' or '-' is part of an exponent
27973 when '+' | '-' =>
27974 declare
27975 Prev_C : constant Character := Sbuffer (Src_Ptr - 1);
27976 begin
27977 return Prev_C in 'e' | 'E';
27978 end;
27980 -- Other characters cannot belong to a numeric literal
27982 when others =>
27983 return False;
27984 end case;
27985 end Belongs_To_Numeric_Literal;
27987 -- Start of processing for String_From_Numeric_Literal
27989 begin
27990 Start_String;
27991 while Belongs_To_Numeric_Literal (C) loop
27992 Store_String_Char (C);
27993 Src_Ptr := Src_Ptr + 1;
27994 C := Sbuffer (Src_Ptr);
27995 end loop;
27997 return End_String;
27998 end String_From_Numeric_Literal;
28000 --------------------------------------
28001 -- Subject_To_Loop_Entry_Attributes --
28002 --------------------------------------
28004 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
28005 Stmt : Node_Id;
28007 begin
28008 Stmt := N;
28010 -- The expansion mechanism transform a loop subject to at least one
28011 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
28012 -- the conditional part.
28014 if Nkind (Stmt) in N_Block_Statement | N_If_Statement
28015 and then Nkind (Original_Node (N)) = N_Loop_Statement
28016 then
28017 Stmt := Original_Node (N);
28018 end if;
28020 return
28021 Nkind (Stmt) = N_Loop_Statement
28022 and then Present (Identifier (Stmt))
28023 and then Present (Entity (Identifier (Stmt)))
28024 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
28025 end Subject_To_Loop_Entry_Attributes;
28027 ---------------------
28028 -- Subprogram_Name --
28029 ---------------------
28031 function Subprogram_Name (N : Node_Id) return String is
28032 Buf : Bounded_String;
28033 Ent : Node_Id := N;
28034 Nod : Node_Id;
28036 begin
28037 while Present (Ent) loop
28038 case Nkind (Ent) is
28039 when N_Subprogram_Body =>
28040 Ent := Defining_Unit_Name (Specification (Ent));
28041 exit;
28043 when N_Subprogram_Declaration =>
28044 Nod := Corresponding_Body (Ent);
28046 if Present (Nod) then
28047 Ent := Nod;
28048 else
28049 Ent := Defining_Unit_Name (Specification (Ent));
28050 end if;
28052 exit;
28054 when N_Subprogram_Instantiation
28055 | N_Package_Body
28056 | N_Package_Specification
28058 Ent := Defining_Unit_Name (Ent);
28059 exit;
28061 when N_Protected_Type_Declaration =>
28062 Ent := Corresponding_Body (Ent);
28063 exit;
28065 when N_Protected_Body
28066 | N_Task_Body
28068 Ent := Defining_Identifier (Ent);
28069 exit;
28071 when N_Entity =>
28072 exit;
28074 when others =>
28075 null;
28076 end case;
28078 Ent := Parent (Ent);
28079 end loop;
28081 if No (Ent) then
28082 return "unknown subprogram:unknown file:0:0";
28083 end if;
28085 -- If the subprogram is a child unit, use its simple name to start the
28086 -- construction of the fully qualified name.
28088 if Nkind (Ent) = N_Defining_Program_Unit_Name then
28089 Ent := Defining_Identifier (Ent);
28090 end if;
28092 Append_Entity_Name (Buf, Ent);
28094 -- Append homonym number if needed
28096 if Nkind (N) in N_Entity and then Has_Homonym (N) then
28097 declare
28098 H : Entity_Id := Homonym (N);
28099 Nr : Nat := 1;
28101 begin
28102 while Present (H) loop
28103 if Scope (H) = Scope (N) then
28104 Nr := Nr + 1;
28105 end if;
28107 H := Homonym (H);
28108 end loop;
28110 if Nr > 1 then
28111 Append (Buf, '#');
28112 Append (Buf, Nr);
28113 end if;
28114 end;
28115 end if;
28117 -- Append source location of Ent to Buf so that the string will
28118 -- look like "subp:file:line:col".
28120 declare
28121 Loc : constant Source_Ptr := Sloc (Ent);
28122 begin
28123 Append (Buf, ':');
28124 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
28125 Append (Buf, ':');
28126 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
28127 Append (Buf, ':');
28128 Append (Buf, Nat (Get_Column_Number (Loc)));
28129 end;
28131 return +Buf;
28132 end Subprogram_Name;
28134 -------------------------------
28135 -- Support_Atomic_Primitives --
28136 -------------------------------
28138 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
28139 Size : Int;
28141 begin
28142 -- Verify the alignment of Typ is known
28144 if not Known_Alignment (Typ) then
28145 return False;
28146 end if;
28148 if Known_Static_Esize (Typ) then
28149 Size := UI_To_Int (Esize (Typ));
28151 -- If the Esize (Object_Size) is unknown at compile time, look at the
28152 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
28154 elsif Known_Static_RM_Size (Typ) then
28155 Size := UI_To_Int (RM_Size (Typ));
28157 -- Otherwise, the size is considered to be unknown.
28159 else
28160 return False;
28161 end if;
28163 -- Check that the size of the component is 8, 16, 32, or 64 bits and
28164 -- that Typ is properly aligned.
28166 case Size is
28167 when 8 | 16 | 32 | 64 =>
28168 return Size = UI_To_Int (Alignment (Typ)) * 8;
28170 when others =>
28171 return False;
28172 end case;
28173 end Support_Atomic_Primitives;
28175 -----------------
28176 -- Trace_Scope --
28177 -----------------
28179 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
28180 begin
28181 if Debug_Flag_W then
28182 for J in 0 .. Scope_Stack.Last loop
28183 Write_Str (" ");
28184 end loop;
28186 Write_Str (Msg);
28187 Write_Name (Chars (E));
28188 Write_Str (" from ");
28189 Write_Location (Sloc (N));
28190 Write_Eol;
28191 end if;
28192 end Trace_Scope;
28194 -----------------------
28195 -- Transfer_Entities --
28196 -----------------------
28198 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
28199 procedure Set_Public_Status_Of (Id : Entity_Id);
28200 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
28201 -- Set_Public_Status. If successful and Id denotes a record type, set
28202 -- the Is_Public attribute of its fields.
28204 --------------------------
28205 -- Set_Public_Status_Of --
28206 --------------------------
28208 procedure Set_Public_Status_Of (Id : Entity_Id) is
28209 Field : Entity_Id;
28211 begin
28212 if not Is_Public (Id) then
28213 Set_Public_Status (Id);
28215 -- When the input entity is a public record type, ensure that all
28216 -- its internal fields are also exposed to the linker. The fields
28217 -- of a class-wide type are never made public.
28219 if Is_Public (Id)
28220 and then Is_Record_Type (Id)
28221 and then not Is_Class_Wide_Type (Id)
28222 then
28223 Field := First_Entity (Id);
28224 while Present (Field) loop
28225 Set_Is_Public (Field);
28226 Next_Entity (Field);
28227 end loop;
28228 end if;
28229 end if;
28230 end Set_Public_Status_Of;
28232 -- Local variables
28234 Full_Id : Entity_Id;
28235 Id : Entity_Id;
28237 -- Start of processing for Transfer_Entities
28239 begin
28240 Id := First_Entity (From);
28242 if Present (Id) then
28244 -- Merge the entity chain of the source scope with that of the
28245 -- destination scope.
28247 if Present (Last_Entity (To)) then
28248 Link_Entities (Last_Entity (To), Id);
28249 else
28250 Set_First_Entity (To, Id);
28251 end if;
28253 Set_Last_Entity (To, Last_Entity (From));
28255 -- Inspect the entities of the source scope and update their Scope
28256 -- attribute.
28258 while Present (Id) loop
28259 Set_Scope (Id, To);
28260 Set_Public_Status_Of (Id);
28262 -- Handle an internally generated full view for a private type
28264 if Is_Private_Type (Id)
28265 and then Present (Full_View (Id))
28266 and then Is_Itype (Full_View (Id))
28267 then
28268 Full_Id := Full_View (Id);
28270 Set_Scope (Full_Id, To);
28271 Set_Public_Status_Of (Full_Id);
28272 end if;
28274 Next_Entity (Id);
28275 end loop;
28277 Set_First_Entity (From, Empty);
28278 Set_Last_Entity (From, Empty);
28279 end if;
28280 end Transfer_Entities;
28282 ------------------------
28283 -- Traverse_More_Func --
28284 ------------------------
28286 function Traverse_More_Func (Node : Node_Id) return Traverse_Final_Result is
28288 Processing_Itype : Boolean := False;
28289 -- Set to True while traversing the nodes under an Itype, to prevent
28290 -- looping on Itype handling during that traversal.
28292 function Process_More (N : Node_Id) return Traverse_Result;
28293 -- Wrapper over the Process callback to handle parts of the AST that
28294 -- are not normally traversed as syntactic children.
28296 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result;
28297 -- Main recursive traversal implemented as an instantiation of
28298 -- Traverse_Func over a modified Process callback.
28300 ------------------
28301 -- Process_More --
28302 ------------------
28304 function Process_More (N : Node_Id) return Traverse_Result is
28306 procedure Traverse_More (N : Node_Id;
28307 Res : in out Traverse_Result);
28308 procedure Traverse_More (L : List_Id;
28309 Res : in out Traverse_Result);
28310 -- Traverse a node or list and update the traversal result to value
28311 -- Abandon when needed.
28313 -------------------
28314 -- Traverse_More --
28315 -------------------
28317 procedure Traverse_More (N : Node_Id;
28318 Res : in out Traverse_Result)
28320 begin
28321 -- Do not process any more nodes if Abandon was reached
28323 if Res = Abandon then
28324 return;
28325 end if;
28327 if Traverse_Rec (N) = Abandon then
28328 Res := Abandon;
28329 end if;
28330 end Traverse_More;
28332 procedure Traverse_More (L : List_Id;
28333 Res : in out Traverse_Result)
28335 N : Node_Id := First (L);
28337 begin
28338 -- Do not process any more nodes if Abandon was reached
28340 if Res = Abandon then
28341 return;
28342 end if;
28344 while Present (N) loop
28345 Traverse_More (N, Res);
28346 Next (N);
28347 end loop;
28348 end Traverse_More;
28350 -- Local variables
28352 Node : Node_Id;
28353 Result : Traverse_Result;
28355 -- Start of processing for Process_More
28357 begin
28358 -- Initial callback to Process. Return immediately on Skip/Abandon.
28359 -- Otherwise update the value of Node for further processing of
28360 -- non-syntactic children.
28362 Result := Process (N);
28364 case Result is
28365 when OK => Node := N;
28366 when OK_Orig => Node := Original_Node (N);
28367 when Skip => return Skip;
28368 when Abandon => return Abandon;
28369 end case;
28371 -- Process the relevant semantic children which are a logical part of
28372 -- the AST under this node before returning for the processing of
28373 -- syntactic children.
28375 -- Start with all non-syntactic lists of action nodes
28377 case Nkind (Node) is
28378 when N_Component_Association =>
28379 Traverse_More (Loop_Actions (Node), Result);
28381 when N_Elsif_Part =>
28382 Traverse_More (Condition_Actions (Node), Result);
28384 when N_Short_Circuit =>
28385 Traverse_More (Actions (Node), Result);
28387 when N_Case_Expression_Alternative =>
28388 Traverse_More (Actions (Node), Result);
28390 when N_Iterated_Component_Association =>
28391 Traverse_More (Loop_Actions (Node), Result);
28393 when N_Iterated_Element_Association =>
28394 Traverse_More (Loop_Actions (Node), Result);
28396 when N_Iteration_Scheme =>
28397 Traverse_More (Condition_Actions (Node), Result);
28399 when N_If_Expression =>
28400 Traverse_More (Then_Actions (Node), Result);
28401 Traverse_More (Else_Actions (Node), Result);
28403 -- Various nodes have a field Actions as a syntactic node,
28404 -- so it will be traversed in the regular syntactic traversal.
28406 when N_Compilation_Unit_Aux
28407 | N_Compound_Statement
28408 | N_Expression_With_Actions
28409 | N_Freeze_Entity
28411 null;
28413 when others =>
28414 null;
28415 end case;
28417 -- If Process_Itypes is True, process unattached nodes which come
28418 -- from Itypes. This only concerns currently ranges of scalar
28419 -- (possibly as index) types. This traversal is protected against
28420 -- looping with Processing_Itype.
28422 if Process_Itypes
28423 and then not Processing_Itype
28424 and then Nkind (Node) in N_Has_Etype
28425 and then Present (Etype (Node))
28426 and then Is_Itype (Etype (Node))
28427 then
28428 declare
28429 Typ : constant Entity_Id := Etype (Node);
28430 begin
28431 Processing_Itype := True;
28433 case Ekind (Typ) is
28434 when Scalar_Kind =>
28435 Traverse_More (Scalar_Range (Typ), Result);
28437 when Array_Kind =>
28438 declare
28439 Index : Node_Id := First_Index (Typ);
28440 Rng : Node_Id;
28441 begin
28442 while Present (Index) loop
28443 if Nkind (Index) in N_Has_Entity then
28444 Rng := Scalar_Range (Entity (Index));
28445 else
28446 Rng := Index;
28447 end if;
28449 Traverse_More (Rng, Result);
28450 Next_Index (Index);
28451 end loop;
28452 end;
28453 when others =>
28454 null;
28455 end case;
28457 Processing_Itype := False;
28458 end;
28459 end if;
28461 return Result;
28462 end Process_More;
28464 -- Define Traverse_Rec as a renaming of the instantiation, as an
28465 -- instantiation cannot complete a previous spec.
28467 function Traverse_Recursive is new Traverse_Func (Process_More);
28468 function Traverse_Rec (N : Node_Id) return Traverse_Final_Result
28469 renames Traverse_Recursive;
28471 -- Start of processing for Traverse_More_Func
28473 begin
28474 return Traverse_Rec (Node);
28475 end Traverse_More_Func;
28477 ------------------------
28478 -- Traverse_More_Proc --
28479 ------------------------
28481 procedure Traverse_More_Proc (Node : Node_Id) is
28482 function Traverse is new Traverse_More_Func (Process, Process_Itypes);
28483 Discard : Traverse_Final_Result;
28484 pragma Warnings (Off, Discard);
28485 begin
28486 Discard := Traverse (Node);
28487 end Traverse_More_Proc;
28489 ------------------------------------
28490 -- Type_Without_Stream_Operation --
28491 ------------------------------------
28493 function Type_Without_Stream_Operation
28494 (T : Entity_Id;
28495 Op : TSS_Name_Type := TSS_Null) return Entity_Id
28497 BT : constant Entity_Id := Base_Type (T);
28498 Op_Missing : Boolean;
28500 begin
28501 if not Restriction_Active (No_Default_Stream_Attributes) then
28502 return Empty;
28503 end if;
28505 if Is_Elementary_Type (T) then
28506 if Op = TSS_Null then
28507 Op_Missing :=
28508 No (TSS (BT, TSS_Stream_Read))
28509 or else No (TSS (BT, TSS_Stream_Write));
28511 else
28512 Op_Missing := No (TSS (BT, Op));
28513 end if;
28515 if Op_Missing then
28516 return T;
28517 else
28518 return Empty;
28519 end if;
28521 elsif Is_Array_Type (T) then
28522 return Type_Without_Stream_Operation (Component_Type (T), Op);
28524 elsif Is_Record_Type (T) then
28525 declare
28526 Comp : Entity_Id;
28527 C_Typ : Entity_Id;
28529 begin
28530 Comp := First_Component (T);
28531 while Present (Comp) loop
28532 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
28534 if Present (C_Typ) then
28535 return C_Typ;
28536 end if;
28538 Next_Component (Comp);
28539 end loop;
28541 return Empty;
28542 end;
28544 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
28545 return Type_Without_Stream_Operation (Full_View (T), Op);
28546 else
28547 return Empty;
28548 end if;
28549 end Type_Without_Stream_Operation;
28551 ------------------------------
28552 -- Ultimate_Overlaid_Entity --
28553 ------------------------------
28555 function Ultimate_Overlaid_Entity (E : Entity_Id) return Entity_Id is
28556 Address : Node_Id;
28557 Alias : Entity_Id := E;
28558 Offset : Boolean;
28560 begin
28561 -- Currently this routine is only called for stand-alone objects that
28562 -- have been analysed, since the analysis of the Address aspect is often
28563 -- delayed.
28565 pragma Assert (Ekind (E) in E_Constant | E_Variable);
28567 loop
28568 Address := Address_Clause (Alias);
28569 if Present (Address) then
28570 Find_Overlaid_Entity (Address, Alias, Offset);
28571 if Present (Alias) then
28572 null;
28573 else
28574 return Empty;
28575 end if;
28576 elsif Alias = E then
28577 return Empty;
28578 else
28579 return Alias;
28580 end if;
28581 end loop;
28582 end Ultimate_Overlaid_Entity;
28584 ---------------------
28585 -- Ultimate_Prefix --
28586 ---------------------
28588 function Ultimate_Prefix (N : Node_Id) return Node_Id is
28589 Pref : Node_Id;
28591 begin
28592 Pref := N;
28593 while Nkind (Pref) in N_Explicit_Dereference
28594 | N_Indexed_Component
28595 | N_Selected_Component
28596 | N_Slice
28597 loop
28598 Pref := Prefix (Pref);
28599 end loop;
28601 return Pref;
28602 end Ultimate_Prefix;
28604 ----------------------------
28605 -- Unique_Defining_Entity --
28606 ----------------------------
28608 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
28609 begin
28610 return Unique_Entity (Defining_Entity (N));
28611 end Unique_Defining_Entity;
28613 -------------------
28614 -- Unique_Entity --
28615 -------------------
28617 function Unique_Entity (E : Entity_Id) return Entity_Id is
28618 U : Entity_Id := E;
28619 P : Node_Id;
28621 begin
28622 case Ekind (E) is
28623 when E_Constant =>
28624 if Present (Full_View (E)) then
28625 U := Full_View (E);
28626 end if;
28628 when Entry_Kind =>
28629 if Nkind (Parent (E)) = N_Entry_Body then
28630 declare
28631 Prot_Item : Entity_Id;
28632 Prot_Type : Entity_Id;
28634 begin
28635 if Ekind (E) = E_Entry then
28636 Prot_Type := Scope (E);
28638 -- Bodies of entry families are nested within an extra scope
28639 -- that contains an entry index declaration.
28641 else
28642 Prot_Type := Scope (Scope (E));
28643 end if;
28645 -- A protected type may be declared as a private type, in
28646 -- which case we need to get its full view.
28648 if Is_Private_Type (Prot_Type) then
28649 Prot_Type := Full_View (Prot_Type);
28650 end if;
28652 -- Full view may not be present on error, in which case
28653 -- return E by default.
28655 if Present (Prot_Type) then
28656 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
28658 -- Traverse the entity list of the protected type and
28659 -- locate an entry declaration which matches the entry
28660 -- body.
28662 Prot_Item := First_Entity (Prot_Type);
28663 while Present (Prot_Item) loop
28664 if Ekind (Prot_Item) in Entry_Kind
28665 and then Corresponding_Body (Parent (Prot_Item)) = E
28666 then
28667 U := Prot_Item;
28668 exit;
28669 end if;
28671 Next_Entity (Prot_Item);
28672 end loop;
28673 end if;
28674 end;
28675 end if;
28677 when Formal_Kind =>
28678 if Present (Spec_Entity (E)) then
28679 U := Spec_Entity (E);
28680 end if;
28682 when E_Package_Body =>
28683 P := Parent (E);
28685 if Nkind (P) = N_Defining_Program_Unit_Name then
28686 P := Parent (P);
28687 end if;
28689 if Nkind (P) = N_Package_Body
28690 and then Present (Corresponding_Spec (P))
28691 then
28692 U := Corresponding_Spec (P);
28694 elsif Nkind (P) = N_Package_Body_Stub
28695 and then Present (Corresponding_Spec_Of_Stub (P))
28696 then
28697 U := Corresponding_Spec_Of_Stub (P);
28698 end if;
28700 when E_Protected_Body =>
28701 P := Parent (E);
28703 if Nkind (P) = N_Protected_Body
28704 and then Present (Corresponding_Spec (P))
28705 then
28706 U := Corresponding_Spec (P);
28708 elsif Nkind (P) = N_Protected_Body_Stub
28709 and then Present (Corresponding_Spec_Of_Stub (P))
28710 then
28711 U := Corresponding_Spec_Of_Stub (P);
28713 if Is_Single_Protected_Object (U) then
28714 U := Etype (U);
28715 end if;
28716 end if;
28718 if Is_Private_Type (U) then
28719 U := Full_View (U);
28720 end if;
28722 when E_Subprogram_Body =>
28723 P := Parent (E);
28725 if Nkind (P) = N_Defining_Program_Unit_Name then
28726 P := Parent (P);
28727 end if;
28729 P := Parent (P);
28731 if Nkind (P) = N_Subprogram_Body
28732 and then Present (Corresponding_Spec (P))
28733 then
28734 U := Corresponding_Spec (P);
28736 elsif Nkind (P) = N_Subprogram_Body_Stub
28737 and then Present (Corresponding_Spec_Of_Stub (P))
28738 then
28739 U := Corresponding_Spec_Of_Stub (P);
28741 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
28742 U := Corresponding_Spec (P);
28743 end if;
28745 when E_Task_Body =>
28746 P := Parent (E);
28748 if Nkind (P) = N_Task_Body
28749 and then Present (Corresponding_Spec (P))
28750 then
28751 U := Corresponding_Spec (P);
28753 elsif Nkind (P) = N_Task_Body_Stub
28754 and then Present (Corresponding_Spec_Of_Stub (P))
28755 then
28756 U := Corresponding_Spec_Of_Stub (P);
28758 if Is_Single_Task_Object (U) then
28759 U := Etype (U);
28760 end if;
28761 end if;
28763 if Is_Private_Type (U) then
28764 U := Full_View (U);
28765 end if;
28767 when Type_Kind =>
28768 if Present (Full_View (E)) then
28769 U := Full_View (E);
28770 end if;
28772 when others =>
28773 null;
28774 end case;
28776 return U;
28777 end Unique_Entity;
28779 -----------------
28780 -- Unique_Name --
28781 -----------------
28783 function Unique_Name (E : Entity_Id) return String is
28785 -- Local subprograms
28787 function Add_Homonym_Suffix (E : Entity_Id) return String;
28789 function This_Name return String;
28791 ------------------------
28792 -- Add_Homonym_Suffix --
28793 ------------------------
28795 function Add_Homonym_Suffix (E : Entity_Id) return String is
28797 -- Names in E_Subprogram_Body or E_Package_Body entities are not
28798 -- reliable, as they may not include the overloading suffix.
28799 -- Instead, when looking for the name of E or one of its enclosing
28800 -- scope, we get the name of the corresponding Unique_Entity.
28802 U : constant Entity_Id := Unique_Entity (E);
28803 Nam : constant String := Get_Name_String (Chars (U));
28805 begin
28806 -- If E has homonyms but is not fully qualified, as done in
28807 -- GNATprove mode, append the homonym number on the fly. Strip the
28808 -- leading space character in the image of natural numbers. Also do
28809 -- not print the homonym value of 1.
28811 if Has_Homonym (U) then
28812 declare
28813 N : constant Pos := Homonym_Number (U);
28814 S : constant String := N'Img;
28815 begin
28816 if N > 1 then
28817 return Nam & "__" & S (2 .. S'Last);
28818 end if;
28819 end;
28820 end if;
28822 return Nam;
28823 end Add_Homonym_Suffix;
28825 ---------------
28826 -- This_Name --
28827 ---------------
28829 function This_Name return String is
28830 begin
28831 return Add_Homonym_Suffix (E);
28832 end This_Name;
28834 -- Local variables
28836 U : constant Entity_Id := Unique_Entity (E);
28838 -- Start of processing for Unique_Name
28840 begin
28841 if E = Standard_Standard
28842 or else Has_Fully_Qualified_Name (E)
28843 then
28844 return This_Name;
28846 elsif Ekind (E) = E_Enumeration_Literal then
28847 return Unique_Name (Etype (E)) & "__" & This_Name;
28849 else
28850 declare
28851 S : constant Entity_Id := Scope (U);
28852 pragma Assert (Present (S));
28854 begin
28855 -- Prefix names of predefined types with standard__, but leave
28856 -- names of user-defined packages and subprograms without prefix
28857 -- (even if technically they are nested in the Standard package).
28859 if S = Standard_Standard then
28860 if Ekind (U) = E_Package or else Is_Subprogram (U) then
28861 return This_Name;
28862 else
28863 return Unique_Name (S) & "__" & This_Name;
28864 end if;
28866 -- For intances of generic subprograms use the name of the related
28867 -- instance and skip the scope of its wrapper package.
28869 elsif Is_Wrapper_Package (S) then
28870 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
28871 -- Wrapper package and the instantiation are in the same scope
28873 declare
28874 Related_Name : constant String :=
28875 Add_Homonym_Suffix (Related_Instance (S));
28876 Enclosing_Name : constant String :=
28877 Unique_Name (Scope (S)) & "__" & Related_Name;
28879 begin
28880 if Is_Subprogram (U)
28881 and then not Is_Generic_Actual_Subprogram (U)
28882 then
28883 return Enclosing_Name;
28884 else
28885 return Enclosing_Name & "__" & This_Name;
28886 end if;
28887 end;
28889 elsif Is_Child_Unit (U) then
28890 return Child_Prefix & Unique_Name (S) & "__" & This_Name;
28891 else
28892 return Unique_Name (S) & "__" & This_Name;
28893 end if;
28894 end;
28895 end if;
28896 end Unique_Name;
28898 ---------------------
28899 -- Unit_Is_Visible --
28900 ---------------------
28902 function Unit_Is_Visible (U : Entity_Id) return Boolean is
28903 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
28904 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
28906 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
28907 -- For a child unit, check whether unit appears in a with_clause
28908 -- of a parent.
28910 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
28911 -- Scan the context clause of one compilation unit looking for a
28912 -- with_clause for the unit in question.
28914 ----------------------------
28915 -- Unit_In_Parent_Context --
28916 ----------------------------
28918 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
28919 begin
28920 if Unit_In_Context (Par_Unit) then
28921 return True;
28923 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
28924 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
28926 else
28927 return False;
28928 end if;
28929 end Unit_In_Parent_Context;
28931 ---------------------
28932 -- Unit_In_Context --
28933 ---------------------
28935 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
28936 Clause : Node_Id;
28938 begin
28939 Clause := First (Context_Items (Comp_Unit));
28940 while Present (Clause) loop
28941 if Nkind (Clause) = N_With_Clause then
28942 if Library_Unit (Clause) = U then
28943 return True;
28945 -- The with_clause may denote a renaming of the unit we are
28946 -- looking for, eg. Text_IO which renames Ada.Text_IO.
28948 elsif
28949 Renamed_Entity (Entity (Name (Clause))) =
28950 Defining_Entity (Unit (U))
28951 then
28952 return True;
28953 end if;
28954 end if;
28956 Next (Clause);
28957 end loop;
28959 return False;
28960 end Unit_In_Context;
28962 -- Start of processing for Unit_Is_Visible
28964 begin
28965 -- The currrent unit is directly visible
28967 if Curr = U then
28968 return True;
28970 elsif Unit_In_Context (Curr) then
28971 return True;
28973 -- If the current unit is a body, check the context of the spec
28975 elsif Nkind (Unit (Curr)) = N_Package_Body
28976 or else
28977 (Nkind (Unit (Curr)) = N_Subprogram_Body
28978 and then not Acts_As_Spec (Unit (Curr)))
28979 then
28980 if Unit_In_Context (Library_Unit (Curr)) then
28981 return True;
28982 end if;
28983 end if;
28985 -- If the spec is a child unit, examine the parents
28987 if Is_Child_Unit (Curr_Entity) then
28988 if Nkind (Unit (Curr)) in N_Unit_Body then
28989 return
28990 Unit_In_Parent_Context
28991 (Parent_Spec (Unit (Library_Unit (Curr))));
28992 else
28993 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
28994 end if;
28996 else
28997 return False;
28998 end if;
28999 end Unit_Is_Visible;
29001 ------------------------------
29002 -- Universal_Interpretation --
29003 ------------------------------
29005 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
29006 Index : Interp_Index;
29007 It : Interp;
29009 begin
29010 -- The argument may be a formal parameter of an operator or subprogram
29011 -- with multiple interpretations, or else an expression for an actual.
29013 if Nkind (Opnd) = N_Defining_Identifier
29014 or else not Is_Overloaded (Opnd)
29015 then
29016 if Is_Universal_Numeric_Type (Etype (Opnd)) then
29017 return Etype (Opnd);
29018 else
29019 return Empty;
29020 end if;
29022 else
29023 Get_First_Interp (Opnd, Index, It);
29024 while Present (It.Typ) loop
29025 if Is_Universal_Numeric_Type (It.Typ) then
29026 return It.Typ;
29027 end if;
29029 Get_Next_Interp (Index, It);
29030 end loop;
29032 return Empty;
29033 end if;
29034 end Universal_Interpretation;
29036 ---------------
29037 -- Unqualify --
29038 ---------------
29040 function Unqualify (Expr : Node_Id) return Node_Id is
29041 begin
29042 -- Recurse to handle unlikely case of multiple levels of qualification
29044 if Nkind (Expr) = N_Qualified_Expression then
29045 return Unqualify (Expression (Expr));
29047 -- Normal case, not a qualified expression
29049 else
29050 return Expr;
29051 end if;
29052 end Unqualify;
29054 -----------------
29055 -- Unqual_Conv --
29056 -----------------
29058 function Unqual_Conv (Expr : Node_Id) return Node_Id is
29059 begin
29060 -- Recurse to handle unlikely case of multiple levels of qualification
29061 -- and/or conversion.
29063 if Nkind (Expr) in N_Qualified_Expression
29064 | N_Type_Conversion
29065 | N_Unchecked_Type_Conversion
29066 then
29067 return Unqual_Conv (Expression (Expr));
29069 -- Normal case, not a qualified expression
29071 else
29072 return Expr;
29073 end if;
29074 end Unqual_Conv;
29076 --------------------
29077 -- Validated_View --
29078 --------------------
29080 function Validated_View (Typ : Entity_Id) return Entity_Id is
29081 begin
29082 -- Scalar types can be always validated. In fast, switiching to the base
29083 -- type would drop the range constraints and force validation to use a
29084 -- larger type than necessary.
29086 if Is_Scalar_Type (Typ) then
29087 return Typ;
29089 -- Array types can be validated even when they are derived, because
29090 -- validation only requires their bounds and component types to be
29091 -- accessible. In fact, switching to the parent type would pollute
29092 -- expansion of attribute Valid_Scalars with unnecessary conversion
29093 -- that might not be eliminated by the frontend.
29095 elsif Is_Array_Type (Typ) then
29096 return Typ;
29098 -- For other types, in particular for record subtypes, we switch to the
29099 -- base type.
29101 elsif not Is_Base_Type (Typ) then
29102 return Validated_View (Base_Type (Typ));
29104 -- Obtain the full view of the input type by stripping away concurrency,
29105 -- derivations, and privacy.
29107 elsif Is_Concurrent_Type (Typ) then
29108 if Present (Corresponding_Record_Type (Typ)) then
29109 return Corresponding_Record_Type (Typ);
29110 else
29111 return Typ;
29112 end if;
29114 elsif Is_Derived_Type (Typ) then
29115 return Validated_View (Etype (Typ));
29117 elsif Is_Private_Type (Typ) then
29118 if Present (Underlying_Full_View (Typ)) then
29119 return Validated_View (Underlying_Full_View (Typ));
29121 elsif Present (Full_View (Typ)) then
29122 return Validated_View (Full_View (Typ));
29123 else
29124 return Typ;
29125 end if;
29127 elsif From_Limited_With (Typ) then
29128 if Has_Non_Limited_View (Typ) then
29129 return Validated_View (Non_Limited_View (Typ));
29130 else
29131 return Typ;
29132 end if;
29134 else
29135 return Typ;
29136 end if;
29137 end Validated_View;
29139 -----------------------
29140 -- Visible_Ancestors --
29141 -----------------------
29143 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
29144 List_1 : Elist_Id;
29145 List_2 : Elist_Id;
29146 Elmt : Elmt_Id;
29148 begin
29149 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
29151 -- Collect all the parents and progenitors of Typ. If the full-view of
29152 -- private parents and progenitors is available then it is used to
29153 -- generate the list of visible ancestors; otherwise their partial
29154 -- view is added to the resulting list.
29156 Collect_Parents
29157 (T => Typ,
29158 List => List_1,
29159 Use_Full_View => True);
29161 Collect_Interfaces
29162 (T => Typ,
29163 Ifaces_List => List_2,
29164 Exclude_Parents => True,
29165 Use_Full_View => True);
29167 -- Join the two lists. Avoid duplications because an interface may
29168 -- simultaneously be parent and progenitor of a type.
29170 Elmt := First_Elmt (List_2);
29171 while Present (Elmt) loop
29172 Append_Unique_Elmt (Node (Elmt), List_1);
29173 Next_Elmt (Elmt);
29174 end loop;
29176 return List_1;
29177 end Visible_Ancestors;
29179 ---------------------------
29180 -- Warn_On_Hiding_Entity --
29181 ---------------------------
29183 procedure Warn_On_Hiding_Entity
29184 (N : Node_Id;
29185 Hidden, Visible : Entity_Id;
29186 On_Use_Clause : Boolean)
29188 begin
29189 -- Don't warn for record components since they always have a well
29190 -- defined scope which does not confuse other uses. Note that in
29191 -- some cases, Ekind has not been set yet.
29193 if Ekind (Hidden) /= E_Component
29194 and then Ekind (Hidden) /= E_Discriminant
29195 and then Nkind (Parent (Hidden)) /= N_Component_Declaration
29196 and then Ekind (Visible) /= E_Component
29197 and then Ekind (Visible) /= E_Discriminant
29198 and then Nkind (Parent (Visible)) /= N_Component_Declaration
29200 -- Don't warn for one character variables. It is too common to use
29201 -- such variables as locals and will just cause too many false hits.
29203 and then Length_Of_Name (Chars (Hidden)) /= 1
29205 -- Don't warn for non-source entities
29207 and then Comes_From_Source (Hidden)
29208 and then Comes_From_Source (Visible)
29210 -- Don't warn within a generic instantiation
29212 and then not In_Instance
29214 -- Don't warn unless entity in question is in extended main source
29216 and then In_Extended_Main_Source_Unit (Visible)
29218 -- Finally, in the case of a declaration, the hidden entity must
29219 -- be either immediately visible or use visible (i.e. from a used
29220 -- package). In the case of a use clause, the visible entity must
29221 -- be immediately visible.
29223 and then
29224 (if On_Use_Clause then
29225 Is_Immediately_Visible (Visible)
29226 else
29227 (Is_Immediately_Visible (Hidden)
29228 or else
29229 Is_Potentially_Use_Visible (Hidden)))
29230 then
29231 if On_Use_Clause then
29232 Error_Msg_Sloc := Sloc (Visible);
29233 Error_Msg_NE ("visible declaration of&# hides homonym "
29234 & "from use clause?h?", N, Hidden);
29235 else
29236 Error_Msg_Sloc := Sloc (Hidden);
29237 Error_Msg_NE ("declaration hides &#?h?", N, Visible);
29238 end if;
29239 end if;
29240 end Warn_On_Hiding_Entity;
29242 ----------------------
29243 -- Within_Init_Proc --
29244 ----------------------
29246 function Within_Init_Proc return Boolean is
29247 S : Entity_Id;
29249 begin
29250 S := Current_Scope;
29251 while not Is_Overloadable (S) loop
29252 if S = Standard_Standard then
29253 return False;
29254 else
29255 S := Scope (S);
29256 end if;
29257 end loop;
29259 return Is_Init_Proc (S);
29260 end Within_Init_Proc;
29262 ---------------------------
29263 -- Within_Protected_Type --
29264 ---------------------------
29266 function Within_Protected_Type (E : Entity_Id) return Boolean is
29267 Scop : Entity_Id := Scope (E);
29269 begin
29270 while Present (Scop) loop
29271 if Ekind (Scop) = E_Protected_Type then
29272 return True;
29273 end if;
29275 Scop := Scope (Scop);
29276 end loop;
29278 return False;
29279 end Within_Protected_Type;
29281 ------------------
29282 -- Within_Scope --
29283 ------------------
29285 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
29286 begin
29287 return Scope_Within_Or_Same (Scope (E), S);
29288 end Within_Scope;
29290 ----------------
29291 -- Wrong_Type --
29292 ----------------
29294 procedure Wrong_Type
29295 (Expr : Node_Id;
29296 Expected_Type : Entity_Id;
29297 Multiple : Boolean := False)
29299 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
29300 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
29302 Err_Msg_Exp_Typ : Entity_Id := Expected_Type;
29303 -- Type entity used when printing errors concerning the expected type
29305 Matching_Field : Entity_Id;
29306 -- Entity to give a more precise suggestion on how to write a one-
29307 -- element positional aggregate.
29309 function Has_One_Matching_Field return Boolean;
29310 -- Determines if Expec_Type is a record type with a single component or
29311 -- discriminant whose type matches the found type or is one dimensional
29312 -- array whose component type matches the found type. In the case of
29313 -- one discriminant, we ignore the variant parts. That's not accurate,
29314 -- but good enough for the warning.
29316 ----------------------------
29317 -- Has_One_Matching_Field --
29318 ----------------------------
29320 function Has_One_Matching_Field return Boolean is
29321 E : Entity_Id;
29323 begin
29324 Matching_Field := Empty;
29326 if Is_Array_Type (Expec_Type)
29327 and then Number_Dimensions (Expec_Type) = 1
29328 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
29329 then
29330 -- Use type name if available. This excludes multidimensional
29331 -- arrays and anonymous arrays.
29333 if Comes_From_Source (Expec_Type) then
29334 Matching_Field := Expec_Type;
29336 -- For an assignment, use name of target
29338 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
29339 and then Is_Entity_Name (Name (Parent (Expr)))
29340 then
29341 Matching_Field := Entity (Name (Parent (Expr)));
29342 end if;
29344 return True;
29346 elsif not Is_Record_Type (Expec_Type) then
29347 return False;
29349 else
29350 E := First_Entity (Expec_Type);
29351 loop
29352 if No (E) then
29353 return False;
29355 elsif Ekind (E) not in E_Discriminant | E_Component
29356 or else Chars (E) in Name_uTag | Name_uParent
29357 then
29358 Next_Entity (E);
29360 else
29361 exit;
29362 end if;
29363 end loop;
29365 if not Covers (Etype (E), Found_Type) then
29366 return False;
29368 elsif Present (Next_Entity (E))
29369 and then (Ekind (E) = E_Component
29370 or else Ekind (Next_Entity (E)) = E_Discriminant)
29371 then
29372 return False;
29374 else
29375 Matching_Field := E;
29376 return True;
29377 end if;
29378 end if;
29379 end Has_One_Matching_Field;
29381 -- Start of processing for Wrong_Type
29383 begin
29384 -- Don't output message if either type is Any_Type, or if a message
29385 -- has already been posted for this node and we do not want multiple
29386 -- error messages. We need to do the latter check explicitly (it is
29387 -- ordinarily done in Errout) because we are using '!' to force the
29388 -- output of the error messages.
29390 if Expec_Type = Any_Type
29391 or else Found_Type = Any_Type
29392 or else (Error_Posted (Expr) and then not Multiple)
29393 then
29394 return;
29396 -- If one of the types is a Taft-Amendment type and the other it its
29397 -- completion, it must be an illegal use of a TAT in the spec, for
29398 -- which an error was already emitted. Avoid cascaded errors.
29400 elsif Is_Incomplete_Type (Expec_Type)
29401 and then Has_Completion_In_Body (Expec_Type)
29402 and then Full_View (Expec_Type) = Etype (Expr)
29403 then
29404 return;
29406 elsif Is_Incomplete_Type (Etype (Expr))
29407 and then Has_Completion_In_Body (Etype (Expr))
29408 and then Full_View (Etype (Expr)) = Expec_Type
29409 then
29410 return;
29411 end if;
29413 -- Avoid printing internally generated subtypes in error messages and
29414 -- instead use the corresponding first subtype in such cases.
29416 if not Comes_From_Source (Err_Msg_Exp_Typ)
29417 or else not Comes_From_Source (Declaration_Node (Err_Msg_Exp_Typ))
29418 then
29419 Err_Msg_Exp_Typ := First_Subtype (Err_Msg_Exp_Typ);
29420 end if;
29422 -- An interesting special check. If the expression is parenthesized
29423 -- and its type corresponds to the type of the sole component of the
29424 -- expected record type, or to the component type of the expected one
29425 -- dimensional array type, then assume we have a bad aggregate attempt.
29427 if Nkind (Expr) in N_Subexpr
29428 and then Paren_Count (Expr) /= 0
29429 and then Has_One_Matching_Field
29430 then
29431 Error_Msg_N ("positional aggregate cannot have one component", Expr);
29433 if Present (Matching_Field) then
29434 if Is_Array_Type (Expec_Type) then
29435 Error_Msg_NE
29436 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
29437 else
29438 Error_Msg_NE
29439 ("\write instead `& ='> ...`", Expr, Matching_Field);
29440 end if;
29441 end if;
29443 -- Another special check, if we are looking for a pool-specific access
29444 -- type and we found an E_Access_Attribute_Type, then we have the case
29445 -- of an Access attribute being used in a context which needs a pool-
29446 -- specific type, which is never allowed. The one extra check we make
29447 -- is that the expected designated type covers the Found_Type.
29449 elsif Is_Access_Type (Expec_Type)
29450 and then Ekind (Found_Type) = E_Access_Attribute_Type
29451 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
29452 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
29453 and then Covers
29454 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
29455 then
29456 Error_Msg_N
29457 ("result must be general access type!", Expr);
29458 Error_Msg_NE -- CODEFIX
29459 ("\add ALL to }!", Expr, Err_Msg_Exp_Typ);
29461 -- Another special check, if the expected type is an integer type,
29462 -- but the expression is of type System.Address, and the parent is
29463 -- an addition or subtraction operation whose left operand is the
29464 -- expression in question and whose right operand is of an integral
29465 -- type, then this is an attempt at address arithmetic, so give
29466 -- appropriate message.
29468 elsif Is_Integer_Type (Expec_Type)
29469 and then Is_RTE (Found_Type, RE_Address)
29470 and then Nkind (Parent (Expr)) in N_Op_Add | N_Op_Subtract
29471 and then Expr = Left_Opnd (Parent (Expr))
29472 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
29473 then
29474 Error_Msg_N
29475 ("address arithmetic not predefined in package System",
29476 Parent (Expr));
29477 Error_Msg_N
29478 ("\possible missing with/use of System.Storage_Elements",
29479 Parent (Expr));
29480 return;
29482 -- If the expected type is an anonymous access type, as for access
29483 -- parameters and discriminants, the error is on the designated types.
29485 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
29486 if Comes_From_Source (Expec_Type) then
29487 Error_Msg_NE ("expected}!", Expr, Expec_Type);
29488 else
29489 Error_Msg_NE
29490 ("expected an access type with designated}",
29491 Expr, Designated_Type (Expec_Type));
29492 end if;
29494 if Is_Access_Type (Found_Type)
29495 and then not Comes_From_Source (Found_Type)
29496 then
29497 Error_Msg_NE
29498 ("\\found an access type with designated}!",
29499 Expr, Designated_Type (Found_Type));
29500 else
29501 if From_Limited_With (Found_Type) then
29502 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
29503 Error_Msg_Qual_Level := 99;
29504 Error_Msg_NE -- CODEFIX
29505 ("\\missing `WITH &;", Expr, Scope (Found_Type));
29506 Error_Msg_Qual_Level := 0;
29507 else
29508 Error_Msg_NE ("found}!", Expr, Found_Type);
29509 end if;
29510 end if;
29512 -- Normal case of one type found, some other type expected
29514 else
29515 -- If the names of the two types are the same, see if some number
29516 -- of levels of qualification will help. Don't try more than three
29517 -- levels, and if we get to standard, it's no use (and probably
29518 -- represents an error in the compiler) Also do not bother with
29519 -- internal scope names.
29521 declare
29522 Expec_Scope : Entity_Id;
29523 Found_Scope : Entity_Id;
29525 begin
29526 Expec_Scope := Expec_Type;
29527 Found_Scope := Found_Type;
29529 for Levels in Nat range 0 .. 3 loop
29530 if Chars (Expec_Scope) /= Chars (Found_Scope) then
29531 Error_Msg_Qual_Level := Levels;
29532 exit;
29533 end if;
29535 Expec_Scope := Scope (Expec_Scope);
29536 Found_Scope := Scope (Found_Scope);
29538 exit when Expec_Scope = Standard_Standard
29539 or else Found_Scope = Standard_Standard
29540 or else not Comes_From_Source (Expec_Scope)
29541 or else not Comes_From_Source (Found_Scope);
29542 end loop;
29543 end;
29545 if Is_Record_Type (Expec_Type)
29546 and then Present (Corresponding_Remote_Type (Expec_Type))
29547 then
29548 Error_Msg_NE ("expected}!", Expr,
29549 Corresponding_Remote_Type (Expec_Type));
29550 else
29551 Error_Msg_NE ("expected}!", Expr, Err_Msg_Exp_Typ);
29552 end if;
29554 if Is_Entity_Name (Expr)
29555 and then Is_Package_Or_Generic_Package (Entity (Expr))
29556 then
29557 Error_Msg_N ("\\found package name!", Expr);
29559 elsif Is_Entity_Name (Expr)
29560 and then Ekind (Entity (Expr)) in E_Procedure | E_Generic_Procedure
29561 then
29562 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
29563 Error_Msg_N
29564 ("found procedure name, possibly missing Access attribute!",
29565 Expr);
29566 else
29567 Error_Msg_N
29568 ("\\found procedure name instead of function!", Expr);
29569 end if;
29571 elsif Nkind (Expr) = N_Function_Call
29572 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
29573 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
29574 and then No (Parameter_Associations (Expr))
29575 then
29576 Error_Msg_N
29577 ("found function name, possibly missing Access attribute!",
29578 Expr);
29580 -- Catch common error: a prefix or infix operator which is not
29581 -- directly visible because the type isn't.
29583 elsif Nkind (Expr) in N_Op
29584 and then Is_Overloaded (Expr)
29585 and then not Is_Immediately_Visible (Expec_Type)
29586 and then not Is_Potentially_Use_Visible (Expec_Type)
29587 and then not In_Use (Expec_Type)
29588 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
29589 then
29590 Error_Msg_N
29591 ("operator of the type is not directly visible!", Expr);
29593 elsif Ekind (Found_Type) = E_Void
29594 and then Present (Parent (Found_Type))
29595 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
29596 then
29597 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
29599 else
29600 Error_Msg_NE ("\\found}!", Expr, Found_Type);
29601 end if;
29603 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
29604 -- of the same modular type, and (M1 and M2) = 0 was intended.
29606 if Expec_Type = Standard_Boolean
29607 and then Is_Modular_Integer_Type (Found_Type)
29608 and then Nkind (Parent (Expr)) in N_Op_And | N_Op_Or | N_Op_Xor
29609 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
29610 then
29611 declare
29612 Op : constant Node_Id := Right_Opnd (Parent (Expr));
29613 L : constant Node_Id := Left_Opnd (Op);
29614 R : constant Node_Id := Right_Opnd (Op);
29616 begin
29617 -- The case for the message is when the left operand of the
29618 -- comparison is the same modular type, or when it is an
29619 -- integer literal (or other universal integer expression),
29620 -- which would have been typed as the modular type if the
29621 -- parens had been there.
29623 if (Etype (L) = Found_Type
29624 or else
29625 Etype (L) = Universal_Integer)
29626 and then Is_Integer_Type (Etype (R))
29627 then
29628 Error_Msg_N
29629 ("\\possible missing parens for modular operation", Expr);
29630 end if;
29631 end;
29632 end if;
29634 -- Reset error message qualification indication
29636 Error_Msg_Qual_Level := 0;
29637 end if;
29638 end Wrong_Type;
29640 --------------------------------
29641 -- Yields_Synchronized_Object --
29642 --------------------------------
29644 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
29645 Has_Sync_Comp : Boolean := False;
29646 Id : Entity_Id;
29648 begin
29649 -- An array type yields a synchronized object if its component type
29650 -- yields a synchronized object.
29652 if Is_Array_Type (Typ) then
29653 return Yields_Synchronized_Object (Component_Type (Typ));
29655 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
29656 -- yields a synchronized object by default.
29658 elsif Is_Descendant_Of_Suspension_Object (Typ) then
29659 return True;
29661 -- A protected type yields a synchronized object by default
29663 elsif Is_Protected_Type (Typ) then
29664 return True;
29666 -- A record type or type extension yields a synchronized object when its
29667 -- discriminants (if any) lack default values and all components are of
29668 -- a type that yields a synchronized object.
29670 elsif Is_Record_Type (Typ) then
29672 -- Inspect all entities defined in the scope of the type, looking for
29673 -- components of a type that does not yield a synchronized object or
29674 -- for discriminants with default values.
29676 Id := First_Entity (Typ);
29677 while Present (Id) loop
29678 if Comes_From_Source (Id) then
29679 if Ekind (Id) = E_Component then
29680 if Yields_Synchronized_Object (Etype (Id)) then
29681 Has_Sync_Comp := True;
29683 -- The component does not yield a synchronized object
29685 else
29686 return False;
29687 end if;
29689 elsif Ekind (Id) = E_Discriminant
29690 and then Present (Expression (Parent (Id)))
29691 then
29692 return False;
29693 end if;
29694 end if;
29696 Next_Entity (Id);
29697 end loop;
29699 -- Ensure that the parent type of a type extension yields a
29700 -- synchronized object.
29702 if Etype (Typ) /= Typ
29703 and then not Is_Private_Type (Etype (Typ))
29704 and then not Yields_Synchronized_Object (Etype (Typ))
29705 then
29706 return False;
29707 end if;
29709 -- If we get here, then all discriminants lack default values and all
29710 -- components are of a type that yields a synchronized object.
29712 return Has_Sync_Comp;
29714 -- A synchronized interface type yields a synchronized object by default
29716 elsif Is_Synchronized_Interface (Typ) then
29717 return True;
29719 -- A task type yields a synchronized object by default
29721 elsif Is_Task_Type (Typ) then
29722 return True;
29724 -- A private type yields a synchronized object if its underlying type
29725 -- does.
29727 elsif Is_Private_Type (Typ)
29728 and then Present (Underlying_Type (Typ))
29729 then
29730 return Yields_Synchronized_Object (Underlying_Type (Typ));
29732 -- Otherwise the type does not yield a synchronized object
29734 else
29735 return False;
29736 end if;
29737 end Yields_Synchronized_Object;
29739 ---------------------------
29740 -- Yields_Universal_Type --
29741 ---------------------------
29743 function Yields_Universal_Type (N : Node_Id) return Boolean is
29744 begin
29745 -- Integer and real literals are of a universal type
29747 if Nkind (N) in N_Integer_Literal | N_Real_Literal then
29748 return True;
29750 -- The values of certain attributes are of a universal type
29752 elsif Nkind (N) = N_Attribute_Reference then
29753 return
29754 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
29756 -- ??? There are possibly other cases to consider
29758 else
29759 return False;
29760 end if;
29761 end Yields_Universal_Type;
29763 package body Interval_Lists is
29765 procedure Check_Consistency (Intervals : Discrete_Interval_List);
29766 -- Check that list is sorted, lacks null intervals, and has gaps
29767 -- between intervals.
29769 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval;
29770 -- Given an element of a Discrete_Choices list, a
29771 -- Static_Discrete_Predicate list, or an Others_Discrete_Choices
29772 -- list (but not an N_Others_Choice node) return the corresponding
29773 -- interval. If an element that does not represent a single
29774 -- contiguous interval due to a static predicate (or which
29775 -- represents a single contiguous interval whose bounds depend on
29776 -- a static predicate) is encountered, then that is an error on the
29777 -- part of whoever built the list in question.
29779 function In_Interval
29780 (Value : Uint; Interval : Discrete_Interval) return Boolean;
29781 -- Does the given value lie within the given interval?
29783 procedure Normalize_Interval_List
29784 (List : in out Discrete_Interval_List; Last : out Nat);
29785 -- Perform sorting and merging as required by Check_Consistency
29787 -------------------------
29788 -- Aggregate_Intervals --
29789 -------------------------
29791 function Aggregate_Intervals (N : Node_Id) return Discrete_Interval_List
29793 pragma Assert (Nkind (N) = N_Aggregate
29794 and then Is_Array_Type (Etype (N)));
29796 function Unmerged_Intervals_Count return Nat;
29797 -- Count the number of intervals given in the aggregate N; the others
29798 -- choice (if present) is not taken into account.
29800 ------------------------------
29801 -- Unmerged_Intervals_Count --
29802 ------------------------------
29804 function Unmerged_Intervals_Count return Nat is
29805 Count : Nat := 0;
29806 Choice : Node_Id;
29807 Comp : Node_Id;
29808 begin
29809 Comp := First (Component_Associations (N));
29810 while Present (Comp) loop
29811 Choice := First (Choices (Comp));
29813 while Present (Choice) loop
29814 if Nkind (Choice) /= N_Others_Choice then
29815 Count := Count + 1;
29816 end if;
29818 Next (Choice);
29819 end loop;
29821 Next (Comp);
29822 end loop;
29824 return Count;
29825 end Unmerged_Intervals_Count;
29827 -- Local variables
29829 Comp : Node_Id;
29830 Max_I : constant Nat := Unmerged_Intervals_Count;
29831 Intervals : Discrete_Interval_List (1 .. Max_I);
29832 Num_I : Nat := 0;
29834 -- Start of processing for Aggregate_Intervals
29836 begin
29837 -- No action needed if there are no intervals
29839 if Max_I = 0 then
29840 return Intervals;
29841 end if;
29843 -- Internally store all the unsorted intervals
29845 Comp := First (Component_Associations (N));
29846 while Present (Comp) loop
29847 declare
29848 Choice_Intervals : constant Discrete_Interval_List
29849 := Choice_List_Intervals (Choices (Comp));
29850 begin
29851 for J in Choice_Intervals'Range loop
29852 Num_I := Num_I + 1;
29853 Intervals (Num_I) := Choice_Intervals (J);
29854 end loop;
29855 end;
29857 Next (Comp);
29858 end loop;
29860 -- Normalize the lists sorting and merging the intervals
29862 declare
29863 Aggr_Intervals : Discrete_Interval_List (1 .. Num_I)
29864 := Intervals (1 .. Num_I);
29865 begin
29866 Normalize_Interval_List (Aggr_Intervals, Num_I);
29867 Check_Consistency (Aggr_Intervals (1 .. Num_I));
29868 return Aggr_Intervals (1 .. Num_I);
29869 end;
29870 end Aggregate_Intervals;
29872 ------------------------
29873 -- Check_Consistency --
29874 ------------------------
29876 procedure Check_Consistency (Intervals : Discrete_Interval_List) is
29877 begin
29878 if Serious_Errors_Detected > 0 then
29879 return;
29880 end if;
29882 -- low bound is 1 and high bound equals length
29883 pragma Assert (Intervals'First = 1 and Intervals'Last >= 0);
29884 for Idx in Intervals'Range loop
29885 -- each interval is non-null
29886 pragma Assert (Intervals (Idx).Low <= Intervals (Idx).High);
29887 if Idx /= Intervals'First then
29888 -- intervals are sorted with non-empty gaps between them
29889 pragma Assert
29890 (Intervals (Idx - 1).High < (Intervals (Idx).Low - 1));
29891 null;
29892 end if;
29893 end loop;
29894 end Check_Consistency;
29896 ---------------------------
29897 -- Choice_List_Intervals --
29898 ---------------------------
29900 function Choice_List_Intervals
29901 (Discrete_Choices : List_Id) return Discrete_Interval_List
29903 function Unmerged_Choice_Count return Nat;
29904 -- The number of intervals before adjacent intervals are merged
29906 ---------------------------
29907 -- Unmerged_Choice_Count --
29908 ---------------------------
29910 function Unmerged_Choice_Count return Nat is
29911 Choice : Node_Id := First (Discrete_Choices);
29912 Count : Nat := 0;
29913 begin
29914 while Present (Choice) loop
29915 -- Non-contiguous choices involving static predicates
29916 -- have already been normalized away.
29918 if Nkind (Choice) = N_Others_Choice then
29919 Count :=
29920 Count + List_Length (Others_Discrete_Choices (Choice));
29921 else
29922 Count := Count + 1; -- an ordinary expression or range
29923 end if;
29925 Next (Choice);
29926 end loop;
29927 return Count;
29928 end Unmerged_Choice_Count;
29930 -- Local variables
29932 Choice : Node_Id := First (Discrete_Choices);
29933 Result : Discrete_Interval_List (1 .. Unmerged_Choice_Count);
29934 Count : Nat := 0;
29936 -- Start of processing for Choice_List_Intervals
29938 begin
29939 while Present (Choice) loop
29940 if Nkind (Choice) = N_Others_Choice then
29941 declare
29942 Others_Choice : Node_Id
29943 := First (Others_Discrete_Choices (Choice));
29944 begin
29945 while Present (Others_Choice) loop
29946 Count := Count + 1;
29947 Result (Count) := Chosen_Interval (Others_Choice);
29948 Next (Others_Choice);
29949 end loop;
29950 end;
29951 else
29952 Count := Count + 1;
29953 Result (Count) := Chosen_Interval (Choice);
29954 end if;
29956 Next (Choice);
29957 end loop;
29959 pragma Assert (Count = Result'Last);
29960 Normalize_Interval_List (Result, Count);
29961 Check_Consistency (Result (1 .. Count));
29962 return Result (1 .. Count);
29963 end Choice_List_Intervals;
29965 ---------------------
29966 -- Chosen_Interval --
29967 ---------------------
29969 function Chosen_Interval (Choice : Node_Id) return Discrete_Interval is
29970 begin
29971 case Nkind (Choice) is
29972 when N_Range =>
29973 return (Low => Expr_Value (Low_Bound (Choice)),
29974 High => Expr_Value (High_Bound (Choice)));
29976 when N_Subtype_Indication =>
29977 declare
29978 Range_Exp : constant Node_Id
29979 := Range_Expression (Constraint (Choice));
29980 begin
29981 return (Low => Expr_Value (Low_Bound (Range_Exp)),
29982 High => Expr_Value (High_Bound (Range_Exp)));
29983 end;
29985 when N_Others_Choice =>
29986 raise Program_Error;
29988 when others =>
29989 if Is_Entity_Name (Choice) and then Is_Type (Entity (Choice))
29990 then
29991 return
29992 (Low => Expr_Value (Type_Low_Bound (Entity (Choice))),
29993 High => Expr_Value (Type_High_Bound (Entity (Choice))));
29994 else
29995 -- an expression
29996 return (Low | High => Expr_Value (Choice));
29997 end if;
29998 end case;
29999 end Chosen_Interval;
30001 -----------------
30002 -- In_Interval --
30003 -----------------
30005 function In_Interval
30006 (Value : Uint; Interval : Discrete_Interval) return Boolean is
30007 begin
30008 return Value >= Interval.Low and then Value <= Interval.High;
30009 end In_Interval;
30011 ---------------
30012 -- Is_Subset --
30013 ---------------
30015 function Is_Subset
30016 (Subset, Of_Set : Discrete_Interval_List) return Boolean
30018 -- Returns True iff for each interval of Subset we can find
30019 -- a single interval of Of_Set which contains the Subset interval.
30020 begin
30021 if Of_Set'Length = 0 then
30022 return Subset'Length = 0;
30023 end if;
30025 declare
30026 Set_Index : Pos range Of_Set'Range := Of_Set'First;
30028 begin
30029 for Ss_Idx in Subset'Range loop
30030 while not In_Interval
30031 (Value => Subset (Ss_Idx).Low,
30032 Interval => Of_Set (Set_Index))
30033 loop
30034 if Set_Index = Of_Set'Last then
30035 return False;
30036 end if;
30038 Set_Index := Set_Index + 1;
30039 end loop;
30041 if not In_Interval
30042 (Value => Subset (Ss_Idx).High,
30043 Interval => Of_Set (Set_Index))
30044 then
30045 return False;
30046 end if;
30047 end loop;
30048 end;
30050 return True;
30051 end Is_Subset;
30053 -----------------------------
30054 -- Normalize_Interval_List --
30055 -----------------------------
30057 procedure Normalize_Interval_List
30058 (List : in out Discrete_Interval_List; Last : out Nat)
30060 Temp_0 : Discrete_Interval := (others => Uint_0);
30061 -- Cope with Heap_Sort_G idiosyncrasies.
30063 function Is_Null (Idx : Pos) return Boolean;
30064 -- True iff List (Idx) defines a null range
30066 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean;
30067 -- Compare two list elements
30069 procedure Merge_Intervals (Null_Interval_Count : out Nat);
30070 -- Merge contiguous ranges by replacing one with merged range and
30071 -- the other with a null value. Return a count of the null intervals,
30072 -- both preexisting and those introduced by merging.
30074 procedure Move_Interval (From, To : Natural);
30075 -- Copy interval from one location to another
30077 function Read_Interval (From : Natural) return Discrete_Interval;
30078 -- Normal array indexing unless From = 0
30080 ----------------------
30081 -- Interval_Sorting --
30082 ----------------------
30084 package Interval_Sorting is
30085 new Gnat.Heap_Sort_G (Move_Interval, Lt_Interval);
30087 -------------
30088 -- Is_Null --
30089 -------------
30091 function Is_Null (Idx : Pos) return Boolean is
30092 begin
30093 return List (Idx).Low > List (Idx).High;
30094 end Is_Null;
30096 -----------------
30097 -- Lt_Interval --
30098 -----------------
30100 function Lt_Interval (Idx1, Idx2 : Natural) return Boolean is
30101 Elem1 : constant Discrete_Interval := Read_Interval (Idx1);
30102 Elem2 : constant Discrete_Interval := Read_Interval (Idx2);
30103 Null_1 : constant Boolean := Elem1.Low > Elem1.High;
30104 Null_2 : constant Boolean := Elem2.Low > Elem2.High;
30105 begin
30106 if Null_1 /= Null_2 then
30107 -- So that sorting moves null intervals to high end
30108 return Null_2;
30110 elsif Elem1.Low /= Elem2.Low then
30111 return Elem1.Low < Elem2.Low;
30113 else
30114 return Elem1.High < Elem2.High;
30115 end if;
30116 end Lt_Interval;
30118 ---------------------
30119 -- Merge_Intervals --
30120 ---------------------
30122 procedure Merge_Intervals (Null_Interval_Count : out Nat) is
30123 Not_Null : Pos range List'Range;
30124 -- Index of the most recently examined non-null interval
30126 Null_Interval : constant Discrete_Interval
30127 := (Low => Uint_1, High => Uint_0); -- any null range ok here
30128 begin
30129 if List'Length = 0 or else Is_Null (List'First) then
30130 Null_Interval_Count := List'Length;
30131 -- no non-null elements, so no merge candidates
30132 return;
30133 end if;
30135 Null_Interval_Count := 0;
30136 Not_Null := List'First;
30138 for Idx in List'First + 1 .. List'Last loop
30139 if Is_Null (Idx) then
30141 -- all remaining elements are null
30143 Null_Interval_Count :=
30144 Null_Interval_Count + List (Idx .. List'Last)'Length;
30145 return;
30147 elsif List (Idx).Low = List (Not_Null).High + 1 then
30149 -- Merge the two intervals into one; discard the other
30151 List (Not_Null).High := List (Idx).High;
30152 List (Idx) := Null_Interval;
30153 Null_Interval_Count := Null_Interval_Count + 1;
30155 else
30156 if List (Idx).Low <= List (Not_Null).High then
30157 raise Intervals_Error;
30158 end if;
30160 pragma Assert (List (Idx).Low > List (Not_Null).High);
30161 Not_Null := Idx;
30162 end if;
30163 end loop;
30164 end Merge_Intervals;
30166 -------------------
30167 -- Move_Interval --
30168 -------------------
30170 procedure Move_Interval (From, To : Natural) is
30171 Rhs : constant Discrete_Interval := Read_Interval (From);
30172 begin
30173 if To = 0 then
30174 Temp_0 := Rhs;
30175 else
30176 List (Pos (To)) := Rhs;
30177 end if;
30178 end Move_Interval;
30180 -------------------
30181 -- Read_Interval --
30182 -------------------
30184 function Read_Interval (From : Natural) return Discrete_Interval is
30185 begin
30186 if From = 0 then
30187 return Temp_0;
30188 else
30189 return List (Pos (From));
30190 end if;
30191 end Read_Interval;
30193 -- Start of processing for Normalize_Interval_Lists
30195 begin
30196 Interval_Sorting.Sort (Natural (List'Last));
30198 declare
30199 Null_Interval_Count : Nat;
30201 begin
30202 Merge_Intervals (Null_Interval_Count);
30203 Last := List'Last - Null_Interval_Count;
30205 if Null_Interval_Count /= 0 then
30206 -- Move null intervals introduced during merging to high end
30207 Interval_Sorting.Sort (Natural (List'Last));
30208 end if;
30209 end;
30210 end Normalize_Interval_List;
30212 --------------------
30213 -- Type_Intervals --
30214 --------------------
30216 function Type_Intervals (Typ : Entity_Id) return Discrete_Interval_List
30218 begin
30219 if Has_Static_Predicate (Typ) then
30220 declare
30221 -- No sorting or merging needed
30222 SDP_List : constant List_Id := Static_Discrete_Predicate (Typ);
30223 Range_Or_Expr : Node_Id := First (SDP_List);
30224 Result : Discrete_Interval_List (1 .. List_Length (SDP_List));
30226 begin
30227 for Idx in Result'Range loop
30228 Result (Idx) := Chosen_Interval (Range_Or_Expr);
30229 Next (Range_Or_Expr);
30230 end loop;
30232 pragma Assert (No (Range_Or_Expr));
30233 Check_Consistency (Result);
30234 return Result;
30235 end;
30236 else
30237 declare
30238 Low : constant Uint := Expr_Value (Type_Low_Bound (Typ));
30239 High : constant Uint := Expr_Value (Type_High_Bound (Typ));
30240 begin
30241 if Low > High then
30242 declare
30243 Null_Array : Discrete_Interval_List (1 .. 0);
30244 begin
30245 return Null_Array;
30246 end;
30247 else
30248 return (1 => (Low => Low, High => High));
30249 end if;
30250 end;
30251 end if;
30252 end Type_Intervals;
30254 end Interval_Lists;
30256 package body Old_Attr_Util is
30257 package body Conditional_Evaluation is
30258 type Determining_Expr_Context is
30259 (No_Context, If_Expr, Case_Expr, Short_Circuit_Op, Membership_Test);
30261 -- Determining_Expr_Context enumeration elements (except for
30262 -- No_Context) correspond to the list items in RM 6.1.1 definition
30263 -- of "determining expression".
30265 type Determining_Expr
30266 (Context : Determining_Expr_Context := No_Context)
30267 is record
30268 Expr : Node_Id := Empty;
30269 case Context is
30270 when Short_Circuit_Op =>
30271 Is_And_Then : Boolean;
30272 when If_Expr =>
30273 Is_Then_Part : Boolean;
30274 when Case_Expr =>
30275 Alternatives : Node_Id;
30276 when Membership_Test =>
30277 -- Given a subexpression of <exp4> in a membership test
30278 -- <exp1> in <exp2> | <exp3> | <exp4> | <exp5>
30279 -- the corresponding determining expression value would
30280 -- have First_Non_Preceding = <exp4> (See RM 6.1.1).
30281 First_Non_Preceding : Node_Id;
30282 when No_Context =>
30283 null;
30284 end case;
30285 end record;
30287 type Determining_Expression_List is
30288 array (Positive range <>) of Determining_Expr;
30290 function Determining_Condition (Det : Determining_Expr)
30291 return Node_Id;
30292 -- Given a determining expression, build a Boolean-valued
30293 -- condition that incorporates that expression into condition
30294 -- suitable for deciding whether to initialize a 'Old constant.
30295 -- Polarity is "True => initialize the constant".
30297 function Determining_Expressions
30298 (Expr : Node_Id; Expr_Trailer : Node_Id := Empty)
30299 return Determining_Expression_List;
30300 -- Given a conditionally evaluated expression, return its
30301 -- determining expressions.
30302 -- See RM 6.1.1 for definition of term "determining expressions".
30303 -- Tests should be performed in the order they occur in the
30304 -- array, with short circuiting.
30305 -- A determining expression need not be of a boolean type (e.g.,
30306 -- it might be the determining expression of a case expression).
30307 -- The Expr_Trailer parameter should be defaulted for nonrecursive
30308 -- calls.
30310 function Is_Conditionally_Evaluated (Expr : Node_Id) return Boolean;
30311 -- See RM 6.1.1 for definition of term "conditionally evaluated".
30313 function Is_Known_On_Entry (Expr : Node_Id) return Boolean;
30314 -- See RM 6.1.1 for definition of term "known on entry".
30316 --------------------------------------
30317 -- Conditional_Evaluation_Condition --
30318 --------------------------------------
30320 function Conditional_Evaluation_Condition
30321 (Expr : Node_Id) return Node_Id
30323 Determiners : constant Determining_Expression_List :=
30324 Determining_Expressions (Expr);
30325 Loc : constant Source_Ptr := Sloc (Expr);
30326 Result : Node_Id :=
30327 New_Occurrence_Of (Standard_True, Loc);
30328 begin
30329 pragma Assert (Determiners'Length > 0 or else
30330 Is_Anonymous_Access_Type (Etype (Expr)));
30332 for I in Determiners'Range loop
30333 Result := Make_And_Then
30334 (Loc,
30335 Left_Opnd => Result,
30336 Right_Opnd =>
30337 Determining_Condition (Determiners (I)));
30338 end loop;
30339 return Result;
30340 end Conditional_Evaluation_Condition;
30342 ---------------------------
30343 -- Determining_Condition --
30344 ---------------------------
30346 function Determining_Condition (Det : Determining_Expr) return Node_Id
30348 Loc : constant Source_Ptr := Sloc (Det.Expr);
30349 begin
30350 case Det.Context is
30351 when Short_Circuit_Op =>
30352 if Det.Is_And_Then then
30353 return New_Copy_Tree (Det.Expr);
30354 else
30355 return Make_Op_Not (Loc, New_Copy_Tree (Det.Expr));
30356 end if;
30358 when If_Expr =>
30359 if Det.Is_Then_Part then
30360 return New_Copy_Tree (Det.Expr);
30361 else
30362 return Make_Op_Not (Loc, New_Copy_Tree (Det.Expr));
30363 end if;
30365 when Case_Expr =>
30366 declare
30367 Alts : List_Id := Discrete_Choices (Det.Alternatives);
30368 begin
30369 if Nkind (First (Alts)) = N_Others_Choice then
30370 Alts := Others_Discrete_Choices (First (Alts));
30371 end if;
30373 return Make_In (Loc,
30374 Left_Opnd => New_Copy_Tree (Det.Expr),
30375 Right_Opnd => Empty,
30376 Alternatives => New_Copy_List (Alts));
30377 end;
30379 when Membership_Test =>
30380 declare
30381 function Copy_Prefix
30382 (List : List_Id; Suffix_Start : Node_Id)
30383 return List_Id;
30384 -- Given a list and a member of that list, returns
30385 -- a copy (similar to Nlists.New_Copy_List) of the
30386 -- prefix of the list up to but not including
30387 -- Suffix_Start.
30389 -----------------
30390 -- Copy_Prefix --
30391 -----------------
30393 function Copy_Prefix
30394 (List : List_Id; Suffix_Start : Node_Id)
30395 return List_Id
30397 Result : constant List_Id := New_List;
30398 Elem : Node_Id := First (List);
30399 begin
30400 while Elem /= Suffix_Start loop
30401 Append (New_Copy (Elem), Result);
30402 Next (Elem);
30403 pragma Assert (Present (Elem));
30404 end loop;
30405 return Result;
30406 end Copy_Prefix;
30408 begin
30409 return Make_In (Loc,
30410 Left_Opnd => New_Copy_Tree (Left_Opnd (Det.Expr)),
30411 Right_Opnd => Empty,
30412 Alternatives => Copy_Prefix
30413 (Alternatives (Det.Expr),
30414 Det.First_Non_Preceding));
30415 end;
30417 when No_Context =>
30418 raise Program_Error;
30419 end case;
30420 end Determining_Condition;
30422 -----------------------------
30423 -- Determining_Expressions --
30424 -----------------------------
30426 function Determining_Expressions
30427 (Expr : Node_Id; Expr_Trailer : Node_Id := Empty)
30428 return Determining_Expression_List
30430 Par : Node_Id := Expr;
30431 Trailer : Node_Id := Expr_Trailer;
30432 Next_Element : Determining_Expr;
30433 begin
30434 -- We want to stop climbing up the tree when we reach the
30435 -- postcondition expression. An aspect_specification is
30436 -- transformed into a pragma, so reaching a pragma is our
30437 -- termination condition. This relies on the fact that
30438 -- pragmas are not allowed in declare expressions (or any
30439 -- other kind of expression).
30441 loop
30442 Next_Element.Expr := Empty;
30444 case Nkind (Par) is
30445 when N_Short_Circuit =>
30446 if Trailer = Right_Opnd (Par) then
30447 Next_Element :=
30448 (Expr => Left_Opnd (Par),
30449 Context => Short_Circuit_Op,
30450 Is_And_Then => Nkind (Par) = N_And_Then);
30451 end if;
30453 when N_If_Expression =>
30454 -- For an expression like
30455 -- (if C1 then ... elsif C2 then ... else Foo'Old)
30456 -- the RM says are two determining expressions,
30457 -- C1 and C2. Our treatment here (where we only add
30458 -- one determining expression to the list) is ok because
30459 -- we will see two if-expressions, one within the other.
30461 if Trailer /= First (Expressions (Par)) then
30462 Next_Element :=
30463 (Expr => First (Expressions (Par)),
30464 Context => If_Expr,
30465 Is_Then_Part =>
30466 Trailer = Next (First (Expressions (Par))));
30467 end if;
30469 when N_Case_Expression_Alternative =>
30470 pragma Assert (Nkind (Parent (Par)) = N_Case_Expression);
30472 Next_Element :=
30473 (Expr => Expression (Parent (Par)),
30474 Context => Case_Expr,
30475 Alternatives => Par);
30477 when N_Membership_Test =>
30478 if Trailer /= Left_Opnd (Par)
30479 and then Is_Non_Empty_List (Alternatives (Par))
30480 and then Trailer /= First (Alternatives (Par))
30481 then
30482 pragma Assert (No (Right_Opnd (Par)));
30483 pragma Assert
30484 (Is_List_Member (Trailer)
30485 and then List_Containing (Trailer)
30486 = Alternatives (Par));
30488 -- This one is different than the others
30489 -- because one element in the array result
30490 -- may represent multiple determining
30491 -- expressions (i.e. every member of the list
30492 -- Alternatives (Par)
30493 -- up to but not including Trailer).
30495 Next_Element :=
30496 (Expr => Par,
30497 Context => Membership_Test,
30498 First_Non_Preceding => Trailer);
30499 end if;
30501 when N_Pragma =>
30502 declare
30503 Previous : constant Node_Id := Prev (Par);
30504 Prev_Expr : Node_Id;
30505 begin
30506 if Nkind (Previous) = N_Pragma and then
30507 Split_PPC (Previous)
30508 then
30509 -- A source-level postcondition of
30510 -- A and then B and then C
30511 -- results in
30512 -- pragma Postcondition (A);
30513 -- pragma Postcondition (B);
30514 -- pragma Postcondition (C);
30515 -- with Split_PPC set to True on all but the
30516 -- last pragma. We account for that here.
30518 Prev_Expr :=
30519 Expression (First
30520 (Pragma_Argument_Associations (Previous)));
30522 -- This Analyze call is needed in the case when
30523 -- Sem_Attr.Analyze_Attribute calls
30524 -- Eligible_For_Conditional_Evaluation. Without
30525 -- it, we end up passing an unanalyzed expression
30526 -- to Is_Known_On_Entry and that doesn't work.
30528 Analyze (Prev_Expr);
30530 Next_Element :=
30531 (Expr => Prev_Expr,
30532 Context => Short_Circuit_Op,
30533 Is_And_Then => True);
30535 return Determining_Expressions (Prev_Expr)
30536 & Next_Element;
30537 else
30538 pragma Assert
30539 (Get_Pragma_Id (Pragma_Name (Par)) in
30540 Pragma_Check
30541 | Pragma_Contract_Cases
30542 | Pragma_Exceptional_Cases
30543 | Pragma_Post
30544 | Pragma_Postcondition
30545 | Pragma_Post_Class
30546 | Pragma_Refined_Post);
30548 return (1 .. 0 => <>); -- recursion terminates here
30549 end if;
30550 end;
30552 when N_Empty =>
30553 -- This case should be impossible, but if it does
30554 -- happen somehow then we don't want an infinite loop.
30555 raise Program_Error;
30557 when others =>
30558 null;
30559 end case;
30561 Trailer := Par;
30562 Par := Parent (Par);
30564 if Present (Next_Element.Expr) then
30565 return Determining_Expressions
30566 (Expr => Par, Expr_Trailer => Trailer)
30567 & Next_Element;
30568 end if;
30569 end loop;
30570 end Determining_Expressions;
30572 -----------------------------------------
30573 -- Eligible_For_Conditional_Evaluation --
30574 -----------------------------------------
30576 function Eligible_For_Conditional_Evaluation
30577 (Expr : Node_Id) return Boolean
30579 begin
30580 if Is_Anonymous_Access_Type (Etype (Expr)) then
30581 -- The code in exp_attr.adb that also builds declarations
30582 -- for 'Old constants doesn't handle the anonymous access
30583 -- type case correctly, so we avoid that problem by
30584 -- returning True here.
30585 return True;
30587 elsif Ada_Version < Ada_2022 then
30588 return False;
30590 elsif Inside_Class_Condition_Preanalysis then
30591 -- No need to evaluate it during preanalysis of a class-wide
30592 -- pre/postcondition since the expression is not installed yet
30593 -- on its definite context.
30594 return False;
30596 elsif not Is_Conditionally_Evaluated (Expr) then
30597 return False;
30598 else
30599 declare
30600 Determiners : constant Determining_Expression_List :=
30601 Determining_Expressions (Expr);
30602 begin
30603 pragma Assert (Determiners'Length > 0);
30605 for Idx in Determiners'Range loop
30606 if not Is_Known_On_Entry (Determiners (Idx).Expr) then
30607 return False;
30608 end if;
30609 end loop;
30610 end;
30611 return True;
30612 end if;
30613 end Eligible_For_Conditional_Evaluation;
30615 --------------------------------
30616 -- Is_Conditionally_Evaluated --
30617 --------------------------------
30619 function Is_Conditionally_Evaluated (Expr : Node_Id) return Boolean
30621 -- There are three possibilities - the expression is
30622 -- unconditionally evaluated, repeatedly evaluated, or
30623 -- conditionally evaluated (see RM 6.1.1). So we implement
30624 -- this test by testing for the other two.
30626 function Is_Repeatedly_Evaluated (Expr : Node_Id) return Boolean;
30627 -- See RM 6.1.1 for definition of "repeatedly evaluated".
30629 -----------------------------
30630 -- Is_Repeatedly_Evaluated --
30631 -----------------------------
30633 function Is_Repeatedly_Evaluated (Expr : Node_Id) return Boolean is
30634 Par : Node_Id := Expr;
30635 Trailer : Node_Id := Empty;
30637 -- There are three ways that an expression can be repeatedly
30638 -- evaluated.
30639 begin
30640 -- An aspect_specification is transformed into a pragma, so
30641 -- reaching a pragma is our termination condition. We want to
30642 -- stop when we reach the postcondition expression.
30644 while Nkind (Par) /= N_Pragma loop
30645 pragma Assert (Present (Par));
30647 -- test for case 1:
30648 -- A subexpression of a predicate of a
30649 -- quantified_expression.
30651 if Nkind (Par) = N_Quantified_Expression
30652 and then Trailer = Condition (Par)
30653 then
30654 return True;
30655 elsif Nkind (Par) = N_Expression_With_Actions
30656 and then
30657 Nkind (Original_Node (Par)) = N_Quantified_Expression
30658 then
30659 return True;
30660 end if;
30662 -- test for cases 2 and 3:
30663 -- A subexpression of the expression of an
30664 -- array_component_association or of
30665 -- a container_element_associatiation.
30667 if Nkind (Par) in N_Component_Association
30668 | N_Iterated_Component_Association
30669 and then Trailer = Expression (Par)
30670 then
30671 -- determine whether Par is part of an array aggregate
30672 -- or a container aggregate
30673 declare
30674 Rover : Node_Id := Par;
30675 begin
30676 while Nkind (Rover) not in N_Has_Etype loop
30677 pragma Assert (Present (Rover));
30678 Rover := Parent (Rover);
30679 end loop;
30680 if Present (Etype (Rover)) then
30681 if Is_Array_Type (Etype (Rover))
30682 or else Is_Container_Aggregate (Rover)
30683 then
30684 return True;
30685 end if;
30686 end if;
30687 end;
30688 end if;
30690 Trailer := Par;
30691 Par := Parent (Par);
30692 end loop;
30694 return False;
30695 end Is_Repeatedly_Evaluated;
30697 begin
30698 if not Is_Potentially_Unevaluated (Expr) then
30699 -- the expression is unconditionally evaluated
30700 return False;
30701 elsif Is_Repeatedly_Evaluated (Expr) then
30702 return False;
30703 end if;
30705 return True;
30706 end Is_Conditionally_Evaluated;
30708 -----------------------
30709 -- Is_Known_On_Entry --
30710 -----------------------
30712 function Is_Known_On_Entry (Expr : Node_Id) return Boolean is
30713 -- ??? This implementation is incomplete. See RM 6.1.1
30714 -- for details. In particular, this function *should* return
30715 -- True for a function call (or a user-defined literal, which
30716 -- is equivalent to a function call) if all actual parameters
30717 -- (including defaulted params) are known on entry and the
30718 -- function has "Globals => null" specified; the current
30719 -- implementation will incorrectly return False in this case.
30721 function All_Exps_Known_On_Entry
30722 (Expr_List : List_Id) return Boolean;
30723 -- Given a list of expressions, returns False iff
30724 -- Is_Known_On_Entry is False for at least one list element.
30726 -----------------------------
30727 -- All_Exps_Known_On_Entry --
30728 -----------------------------
30730 function All_Exps_Known_On_Entry
30731 (Expr_List : List_Id) return Boolean
30733 Expr : Node_Id := First (Expr_List);
30734 begin
30735 while Present (Expr) loop
30736 if not Is_Known_On_Entry (Expr) then
30737 return False;
30738 end if;
30739 Next (Expr);
30740 end loop;
30741 return True;
30742 end All_Exps_Known_On_Entry;
30744 begin
30745 if Is_Static_Expression (Expr) then
30746 return True;
30747 end if;
30749 if Is_Attribute_Old (Expr) then
30750 return True;
30751 end if;
30753 declare
30754 Pref : Node_Id := Expr;
30755 begin
30756 loop
30757 case Nkind (Pref) is
30758 when N_Selected_Component =>
30759 null;
30761 when N_Indexed_Component =>
30762 if not All_Exps_Known_On_Entry (Expressions (Pref))
30763 then
30764 return False;
30765 end if;
30767 when N_Slice =>
30768 return False; -- just to be clear about this case
30770 when others =>
30771 exit;
30772 end case;
30774 Pref := Prefix (Pref);
30775 end loop;
30777 if Is_Entity_Name (Pref)
30778 and then Is_Constant_Object (Entity (Pref))
30779 then
30780 declare
30781 Obj : constant Entity_Id := Entity (Pref);
30782 Obj_Typ : constant Entity_Id := Etype (Obj);
30783 begin
30784 case Ekind (Obj) is
30785 when E_In_Parameter =>
30786 if not Is_Elementary_Type (Obj_Typ) then
30787 return False;
30788 elsif Is_Aliased (Obj) then
30789 return False;
30790 end if;
30792 when E_Constant =>
30793 -- return False for a deferred constant
30794 if Present (Full_View (Obj)) then
30795 return False;
30796 end if;
30798 -- return False if not "all views are constant".
30799 if Is_Immutably_Limited_Type (Obj_Typ)
30800 or Needs_Finalization (Obj_Typ)
30801 then
30802 return False;
30803 end if;
30805 when others =>
30806 null;
30807 end case;
30808 end;
30810 return True;
30811 end if;
30813 -- ??? Cope with a malformed tree. Code to cope with a
30814 -- nonstatic use of an enumeration literal should not be
30815 -- necessary.
30816 if Is_Entity_Name (Pref)
30817 and then Ekind (Entity (Pref)) = E_Enumeration_Literal
30818 then
30819 return True;
30820 end if;
30821 end;
30823 case Nkind (Expr) is
30824 when N_Unary_Op =>
30825 return Is_Known_On_Entry (Right_Opnd (Expr));
30827 when N_Binary_Op =>
30828 return Is_Known_On_Entry (Left_Opnd (Expr))
30829 and then Is_Known_On_Entry (Right_Opnd (Expr));
30831 when N_Type_Conversion | N_Qualified_Expression =>
30832 return Is_Known_On_Entry (Expression (Expr));
30834 when N_If_Expression =>
30835 if not All_Exps_Known_On_Entry (Expressions (Expr)) then
30836 return False;
30837 end if;
30839 when N_Case_Expression =>
30840 if not Is_Known_On_Entry (Expression (Expr)) then
30841 return False;
30842 end if;
30844 declare
30845 Alt : Node_Id := First (Alternatives (Expr));
30846 begin
30847 while Present (Alt) loop
30848 if not Is_Known_On_Entry (Expression (Alt)) then
30849 return False;
30850 end if;
30851 Next (Alt);
30852 end loop;
30853 end;
30855 return True;
30857 when others =>
30858 null;
30859 end case;
30861 return False;
30862 end Is_Known_On_Entry;
30864 end Conditional_Evaluation;
30866 package body Indirect_Temps is
30868 Indirect_Temp_Access_Type_Char : constant Character := 'K';
30869 -- The character passed to Make_Temporary when declaring
30870 -- the access type that is used in the implementation of an
30871 -- indirect temporary.
30873 --------------------------
30874 -- Indirect_Temp_Needed --
30875 --------------------------
30877 function Indirect_Temp_Needed (Typ : Entity_Id) return Boolean is
30878 begin
30879 -- There should be no correctness issues if the only cases where
30880 -- this function returns False are cases where Typ is an
30881 -- anonymous access type and we need to generate a saooaaat (a
30882 -- stand-alone object of an anonymous access type) in order get
30883 -- accessibility right. In other cases where this function
30884 -- returns False, there would be no correctness problems with
30885 -- returning True instead; however, returning False when we can
30886 -- generally results in simpler code.
30888 return False
30890 -- If Typ is not definite, then we cannot generate
30891 -- Temp : Typ;
30893 or else not Is_Definite_Subtype (Typ)
30895 -- If Typ is tagged, then generating
30896 -- Temp : Typ;
30897 -- might generate an object with the wrong tag. If we had
30898 -- a predicate that indicated whether the nominal tag is
30899 -- trustworthy, we could use that predicate here.
30901 or else Is_Tagged_Type (Typ)
30903 -- If Typ needs finalization, then generating an implicit
30904 -- Temp : Typ;
30905 -- declaration could have user-visible side effects.
30907 or else Needs_Finalization (Typ)
30909 -- In the anonymous access type case, we need to
30910 -- generate a saooaaat. We don't want the code in
30911 -- in exp_attr.adb that deals with the case where this
30912 -- function returns False to have to deal with that case
30913 -- (just to avoid code duplication). So we cheat a little
30914 -- bit and return True here for an anonymous access type.
30916 or else Is_Anonymous_Access_Type (Typ);
30918 -- ??? Unimplemented - spec description says:
30919 -- For an unconstrained-but-definite discriminated subtype,
30920 -- returns True if the potential difference in size between an
30921 -- unconstrained object and a constrained object is large.
30923 -- For example,
30924 -- type Typ (Len : Natural := 0) is
30925 -- record F : String (1 .. Len); end record;
30927 -- See Large_Max_Size_Mutable function elsewhere in this file,
30928 -- currently declared inside of Needs_Secondary_Stack, so it
30929 -- would have to be moved if we want it to be callable from here.
30931 end Indirect_Temp_Needed;
30933 ---------------------------
30934 -- Declare_Indirect_Temp --
30935 ---------------------------
30937 procedure Declare_Indirect_Temp
30938 (Attr_Prefix : Node_Id; Indirect_Temp : out Entity_Id)
30940 Loc : constant Source_Ptr := Sloc (Attr_Prefix);
30941 Prefix_Type : constant Entity_Id := Etype (Attr_Prefix);
30942 Temp_Id : constant Entity_Id :=
30943 Make_Temporary (Loc, 'P', Attr_Prefix);
30945 procedure Declare_Indirect_Temp_Via_Allocation;
30946 -- Handle the usual case.
30948 -------------------------------------------
30949 -- Declare_Indirect_Temp_Via_Allocation --
30950 -------------------------------------------
30952 procedure Declare_Indirect_Temp_Via_Allocation is
30953 Access_Type_Id : constant Entity_Id
30954 := Make_Temporary
30955 (Loc, Indirect_Temp_Access_Type_Char, Attr_Prefix);
30957 Temp_Decl : constant Node_Id :=
30958 Make_Object_Declaration (Loc,
30959 Defining_Identifier => Temp_Id,
30960 Object_Definition =>
30961 New_Occurrence_Of (Access_Type_Id, Loc));
30963 Allocate_Class_Wide : constant Boolean :=
30964 Is_Specific_Tagged_Type (Prefix_Type);
30965 -- If True then access type designates the class-wide type in
30966 -- order to preserve (at run time) the value of the underlying
30967 -- tag.
30968 -- ??? We could do better here (in the case where Prefix_Type
30969 -- is tagged and specific) if we had a predicate which takes an
30970 -- expression and returns True iff the expression is of
30971 -- a specific tagged type and the underlying tag (at run time)
30972 -- is statically known to match that of the specific type.
30973 -- In that case, Allocate_Class_Wide could safely be False.
30975 function Designated_Subtype_Mark return Node_Id;
30976 -- Usually, a subtype mark indicating the subtype of the
30977 -- attribute prefix. If that subtype is a specific tagged
30978 -- type, then returns the corresponding class-wide type.
30979 -- If the prefix is of an anonymous access type, then returns
30980 -- the designated type of that type.
30982 -----------------------------
30983 -- Designated_Subtype_Mark --
30984 -----------------------------
30986 function Designated_Subtype_Mark return Node_Id is
30987 Typ : Entity_Id := Prefix_Type;
30988 begin
30989 if Allocate_Class_Wide then
30990 if Is_Private_Type (Typ)
30991 and then Present (Full_View (Typ))
30992 then
30993 Typ := Full_View (Typ);
30994 end if;
30995 Typ := Class_Wide_Type (Typ);
30996 end if;
30998 return New_Occurrence_Of (Typ, Loc);
30999 end Designated_Subtype_Mark;
31001 Access_Type_Def : constant Node_Id
31002 := Make_Access_To_Object_Definition
31003 (Loc, Subtype_Indication => Designated_Subtype_Mark);
31005 Access_Type_Decl : constant Node_Id
31006 := Make_Full_Type_Declaration
31007 (Loc, Access_Type_Id,
31008 Type_Definition => Access_Type_Def);
31009 begin
31010 Mutate_Ekind (Temp_Id, E_Variable);
31011 Set_Etype (Temp_Id, Access_Type_Id);
31012 Mutate_Ekind (Access_Type_Id, E_Access_Type);
31014 if Append_Decls_In_Reverse_Order then
31015 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31016 Append_Item (Access_Type_Decl, Is_Eval_Stmt => False);
31017 else
31018 Append_Item (Access_Type_Decl, Is_Eval_Stmt => False);
31019 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31020 end if;
31022 -- When a type associated with an indirect temporary gets
31023 -- created for a 'Old attribute reference we need to mark
31024 -- the type as such. This allows, for example, finalization
31025 -- masters associated with them to be finalized in the correct
31026 -- order after postcondition checks.
31028 if Attribute_Name (Parent (Attr_Prefix)) = Name_Old then
31029 Set_Stores_Attribute_Old_Prefix (Access_Type_Id);
31030 end if;
31032 Analyze (Access_Type_Decl);
31033 Analyze (Temp_Decl);
31035 pragma Assert
31036 (Is_Access_Type_For_Indirect_Temp (Access_Type_Id));
31038 declare
31039 Expression : Node_Id := Attr_Prefix;
31040 Allocator : Node_Id;
31041 begin
31042 if Allocate_Class_Wide then
31043 -- generate T'Class'(T'Class (<prefix>))
31044 Expression :=
31045 Make_Type_Conversion (Loc,
31046 Subtype_Mark => Designated_Subtype_Mark,
31047 Expression => Expression);
31048 end if;
31050 Allocator :=
31051 Make_Allocator (Loc,
31052 Make_Qualified_Expression
31053 (Loc,
31054 Subtype_Mark => Designated_Subtype_Mark,
31055 Expression => Expression));
31057 -- Allocate saved prefix value on the secondary stack
31058 -- in order to avoid introducing a storage leak. This
31059 -- allocated object is never explicitly reclaimed.
31061 -- ??? Emit storage leak warning if RE_SS_Pool
31062 -- unavailable?
31064 if RTE_Available (RE_SS_Pool) then
31065 Set_Storage_Pool (Allocator, RTE (RE_SS_Pool));
31066 Set_Procedure_To_Call
31067 (Allocator, RTE (RE_SS_Allocate));
31068 Set_Uses_Sec_Stack (Current_Scope);
31069 end if;
31071 Append_Item
31072 (Make_Assignment_Statement (Loc,
31073 Name => New_Occurrence_Of (Temp_Id, Loc),
31074 Expression => Allocator),
31075 Is_Eval_Stmt => True);
31076 end;
31077 end Declare_Indirect_Temp_Via_Allocation;
31079 begin
31080 Indirect_Temp := Temp_Id;
31082 if Is_Anonymous_Access_Type (Prefix_Type) then
31083 -- In the anonymous access type case, we do not want a level
31084 -- indirection (which would result in declaring an
31085 -- access-to-access type); that would result in correctness
31086 -- problems - the accessibility level of the type of the
31087 -- 'Old constant would be wrong (See 6.1.1.). So in that case,
31088 -- we do not generate an allocator. Instead we generate
31089 -- Temp : access Designated := null;
31090 -- which is unconditionally elaborated and then
31091 -- Temp := <attribute prefix>;
31092 -- which is conditionally executed.
31094 declare
31095 Temp_Decl : constant Node_Id :=
31096 Make_Object_Declaration (Loc,
31097 Defining_Identifier => Temp_Id,
31098 Object_Definition =>
31099 Make_Access_Definition
31100 (Loc,
31101 Constant_Present =>
31102 Is_Access_Constant (Prefix_Type),
31103 Subtype_Mark =>
31104 New_Occurrence_Of
31105 (Designated_Type (Prefix_Type), Loc)));
31106 begin
31107 Append_Item (Temp_Decl, Is_Eval_Stmt => False);
31108 Analyze (Temp_Decl);
31109 Append_Item
31110 (Make_Assignment_Statement (Loc,
31111 Name => New_Occurrence_Of (Temp_Id, Loc),
31112 Expression => Attr_Prefix),
31113 Is_Eval_Stmt => True);
31114 end;
31115 else
31116 -- the usual case
31117 Declare_Indirect_Temp_Via_Allocation;
31118 end if;
31119 end Declare_Indirect_Temp;
31121 -------------------------
31122 -- Indirect_Temp_Value --
31123 -------------------------
31125 function Indirect_Temp_Value
31126 (Temp : Entity_Id;
31127 Typ : Entity_Id;
31128 Loc : Source_Ptr) return Node_Id
31130 Result : Node_Id;
31131 begin
31132 if Is_Anonymous_Access_Type (Typ) then
31133 -- No indirection in this case; just evaluate the temp.
31134 Result := New_Occurrence_Of (Temp, Loc);
31135 Set_Etype (Result, Etype (Temp));
31137 else
31138 Result := Make_Explicit_Dereference (Loc,
31139 New_Occurrence_Of (Temp, Loc));
31141 Set_Etype (Result, Designated_Type (Etype (Temp)));
31143 if Is_Specific_Tagged_Type (Typ) then
31144 -- The designated type of the access type is class-wide, so
31145 -- convert to the specific type.
31147 Result :=
31148 Make_Type_Conversion (Loc,
31149 Subtype_Mark => New_Occurrence_Of (Typ, Loc),
31150 Expression => Result);
31152 Set_Etype (Result, Typ);
31153 end if;
31154 end if;
31156 return Result;
31157 end Indirect_Temp_Value;
31159 function Is_Access_Type_For_Indirect_Temp
31160 (T : Entity_Id) return Boolean is
31161 begin
31162 if Is_Access_Type (T)
31163 and then not Comes_From_Source (T)
31164 and then Is_Internal_Name (Chars (T))
31165 and then Nkind (Scope (T)) in N_Entity
31166 and then Ekind (Scope (T))
31167 in E_Entry | E_Entry_Family | E_Function | E_Procedure
31168 and then
31169 (Present (Wrapped_Statements (Scope (T)))
31170 or else Present (Contract (Scope (T))))
31171 then
31172 -- ??? Should define a flag for this. We could incorrectly
31173 -- return True if other clients of Make_Temporary happen to
31174 -- pass in the same character.
31175 declare
31176 Name : constant String := Get_Name_String (Chars (T));
31177 begin
31178 if Name (Name'First) = Indirect_Temp_Access_Type_Char then
31179 return True;
31180 end if;
31181 end;
31182 end if;
31184 return False;
31185 end Is_Access_Type_For_Indirect_Temp;
31187 end Indirect_Temps;
31188 end Old_Attr_Util;
31190 package body Storage_Model_Support is
31192 -----------------------------------------
31193 -- Has_Designated_Storage_Model_Aspect --
31194 -----------------------------------------
31196 function Has_Designated_Storage_Model_Aspect
31197 (Typ : Entity_Id) return Boolean
31199 begin
31200 return Has_Aspect (Typ, Aspect_Designated_Storage_Model);
31201 end Has_Designated_Storage_Model_Aspect;
31203 -----------------------------------
31204 -- Has_Storage_Model_Type_Aspect --
31205 -----------------------------------
31207 function Has_Storage_Model_Type_Aspect (Typ : Entity_Id) return Boolean
31209 begin
31210 return Has_Aspect (Typ, Aspect_Storage_Model_Type);
31211 end Has_Storage_Model_Type_Aspect;
31213 --------------------------
31214 -- Storage_Model_Object --
31215 --------------------------
31217 function Storage_Model_Object (Typ : Entity_Id) return Entity_Id is
31218 begin
31219 pragma Assert (Has_Designated_Storage_Model_Aspect (Typ));
31221 return
31222 Entity
31223 (Find_Value_Of_Aspect (Typ, Aspect_Designated_Storage_Model));
31224 end Storage_Model_Object;
31226 ------------------------
31227 -- Storage_Model_Type --
31228 ------------------------
31230 function Storage_Model_Type (Obj : Entity_Id) return Entity_Id is
31231 begin
31232 pragma Assert (Has_Storage_Model_Type_Aspect (Etype (Obj)));
31234 return Etype (Obj);
31235 end Storage_Model_Type;
31237 -----------------------------------
31238 -- Get_Storage_Model_Type_Entity --
31239 -----------------------------------
31241 function Get_Storage_Model_Type_Entity
31242 (SM_Obj_Or_Type : Entity_Id;
31243 Nam : Name_Id) return Entity_Id
31245 Typ : constant Entity_Id := (if Is_Object (SM_Obj_Or_Type) then
31246 Storage_Model_Type (SM_Obj_Or_Type)
31247 else
31248 SM_Obj_Or_Type);
31249 pragma Assert
31250 (Is_Type (Typ)
31251 and then
31252 Nam in Name_Address_Type
31253 | Name_Null_Address
31254 | Name_Allocate
31255 | Name_Deallocate
31256 | Name_Copy_From
31257 | Name_Copy_To
31258 | Name_Storage_Size);
31260 Assoc : Node_Id;
31261 SMT_Aspect_Value : constant Node_Id :=
31262 Find_Value_Of_Aspect (Typ, Aspect_Storage_Model_Type);
31264 begin
31265 -- When the aspect has an aggregate expression, search through it
31266 -- to locate a match for the name of the given "subaspect" and return
31267 -- the entity of the aggregate association's expression.
31269 if Present (SMT_Aspect_Value) then
31270 Assoc := First (Component_Associations (SMT_Aspect_Value));
31271 while Present (Assoc) loop
31272 if Chars (First (Choices (Assoc))) = Nam then
31273 return Entity (Expression (Assoc));
31274 end if;
31276 Next (Assoc);
31277 end loop;
31278 end if;
31280 -- The aggregate argument of Storage_Model_Type is optional, and when
31281 -- not present the aspect defaults to the native storage model, where
31282 -- the address type is System.Address. In that case, we return
31283 -- System.Address for Name_Address_Type and System.Null_Address for
31284 -- Name_Null_Address, but return Empty for other cases, and leave it
31285 -- to the back end to map those to the appropriate native operations.
31287 if Nam = Name_Address_Type then
31288 return RTE (RE_Address);
31290 elsif Nam = Name_Null_Address then
31291 return RTE (RE_Null_Address);
31293 else
31294 return Empty;
31295 end if;
31296 end Get_Storage_Model_Type_Entity;
31298 --------------------------------
31299 -- Storage_Model_Address_Type --
31300 --------------------------------
31302 function Storage_Model_Address_Type
31303 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31305 begin
31306 return
31307 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Address_Type);
31308 end Storage_Model_Address_Type;
31310 --------------------------------
31311 -- Storage_Model_Null_Address --
31312 --------------------------------
31314 function Storage_Model_Null_Address
31315 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31317 begin
31318 return
31319 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Null_Address);
31320 end Storage_Model_Null_Address;
31322 ----------------------------
31323 -- Storage_Model_Allocate --
31324 ----------------------------
31326 function Storage_Model_Allocate
31327 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31329 begin
31330 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Allocate);
31331 end Storage_Model_Allocate;
31333 ------------------------------
31334 -- Storage_Model_Deallocate --
31335 ------------------------------
31337 function Storage_Model_Deallocate
31338 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31340 begin
31341 return
31342 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Deallocate);
31343 end Storage_Model_Deallocate;
31345 -----------------------------
31346 -- Storage_Model_Copy_From --
31347 -----------------------------
31349 function Storage_Model_Copy_From
31350 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31352 begin
31353 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Copy_From);
31354 end Storage_Model_Copy_From;
31356 ---------------------------
31357 -- Storage_Model_Copy_To --
31358 ---------------------------
31360 function Storage_Model_Copy_To
31361 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31363 begin
31364 return Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Copy_To);
31365 end Storage_Model_Copy_To;
31367 --------------------------------
31368 -- Storage_Model_Storage_Size --
31369 --------------------------------
31371 function Storage_Model_Storage_Size
31372 (SM_Obj_Or_Type : Entity_Id) return Entity_Id
31374 begin
31375 return
31376 Get_Storage_Model_Type_Entity (SM_Obj_Or_Type, Name_Storage_Size);
31377 end Storage_Model_Storage_Size;
31379 end Storage_Model_Support;
31381 begin
31382 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
31383 end Sem_Util;