Fix ICE in lto_symtab_merge_symbols_1 (PR lto/88004).
[official-gcc.git] / gcc / ada / sem_util.adb
blobe3d7718a5996e9590f89aeac96e75aff883fd89a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ U T I L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Treepr; -- ???For debugging code below
28 with Aspects; use Aspects;
29 with Atree; use Atree;
30 with Casing; use Casing;
31 with Checks; use Checks;
32 with Debug; use Debug;
33 with Elists; use Elists;
34 with Errout; use Errout;
35 with Erroutc; use Erroutc;
36 with Exp_Ch11; use Exp_Ch11;
37 with Exp_Util; use Exp_Util;
38 with Fname; use Fname;
39 with Freeze; use Freeze;
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_Ch6; use Sem_Ch6;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Elab; use Sem_Elab;
56 with Sem_Eval; use Sem_Eval;
57 with Sem_Prag; use Sem_Prag;
58 with Sem_Res; use Sem_Res;
59 with Sem_Warn; use Sem_Warn;
60 with Sem_Type; use Sem_Type;
61 with Sinfo; use Sinfo;
62 with Sinput; use Sinput;
63 with Stand; use Stand;
64 with Style;
65 with Stringt; use Stringt;
66 with Targparm; use Targparm;
67 with Tbuild; use Tbuild;
68 with Ttypes; use Ttypes;
69 with Uname; use Uname;
71 with GNAT.HTable; use GNAT.HTable;
73 package body Sem_Util is
75 ---------------------------
76 -- Local Data Structures --
77 ---------------------------
79 Invalid_Binder_Values : array (Scalar_Id) of Entity_Id := (others => Empty);
80 -- A collection to hold the entities of the variables declared in package
81 -- System.Scalar_Values which describe the invalid values of scalar types.
83 Invalid_Binder_Values_Set : Boolean := False;
84 -- This flag prevents multiple attempts to initialize Invalid_Binder_Values
86 Invalid_Floats : array (Float_Scalar_Id) of Ureal := (others => No_Ureal);
87 -- A collection to hold the invalid values of float types as specified by
88 -- pragma Initialize_Scalars.
90 Invalid_Integers : array (Integer_Scalar_Id) of Uint := (others => No_Uint);
91 -- A collection to hold the invalid values of integer types as specified
92 -- by pragma Initialize_Scalars.
94 -----------------------
95 -- Local Subprograms --
96 -----------------------
98 function Build_Component_Subtype
99 (C : List_Id;
100 Loc : Source_Ptr;
101 T : Entity_Id) return Node_Id;
102 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
103 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
104 -- Loc is the source location, T is the original subtype.
106 procedure Examine_Array_Bounds
107 (Typ : Entity_Id;
108 All_Static : out Boolean;
109 Has_Empty : out Boolean);
110 -- Inspect the index constraints of array type Typ. Flag All_Static is set
111 -- when all ranges are static. Flag Has_Empty is set only when All_Static
112 -- is set and indicates that at least one range is empty.
114 function Has_Enabled_Property
115 (Item_Id : Entity_Id;
116 Property : Name_Id) return Boolean;
117 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
118 -- Determine whether an abstract state or a variable denoted by entity
119 -- Item_Id has enabled property Property.
121 function Has_Null_Extension (T : Entity_Id) return Boolean;
122 -- T is a derived tagged type. Check whether the type extension is null.
123 -- If the parent type is fully initialized, T can be treated as such.
125 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
126 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
127 -- with discriminants whose default values are static, examine only the
128 -- components in the selected variant to determine whether all of them
129 -- have a default.
131 type Null_Status_Kind is
132 (Is_Null,
133 -- This value indicates that a subexpression is known to have a null
134 -- value at compile time.
136 Is_Non_Null,
137 -- This value indicates that a subexpression is known to have a non-null
138 -- value at compile time.
140 Unknown);
141 -- This value indicates that it cannot be determined at compile time
142 -- whether a subexpression yields a null or non-null value.
144 function Null_Status (N : Node_Id) return Null_Status_Kind;
145 -- Determine whether subexpression N of an access type yields a null value,
146 -- a non-null value, or the value cannot be determined at compile time. The
147 -- routine does not take simple flow diagnostics into account, it relies on
148 -- static facts such as the presence of null exclusions.
150 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
151 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
152 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
153 -- the time being. New_Requires_Transient_Scope is used by default; the
154 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
155 -- instead. The intent is to use this temporarily to measure before/after
156 -- efficiency. Note: when this temporary code is removed, the documentation
157 -- of dQ in debug.adb should be removed.
159 procedure Results_Differ
160 (Id : Entity_Id;
161 Old_Val : Boolean;
162 New_Val : Boolean);
163 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
164 -- routine will be removed eventially when New_Requires_Transient_Scope
165 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
166 -- eliminated.
168 function Subprogram_Name (N : Node_Id) return String;
169 -- Return the fully qualified name of the enclosing subprogram for the
170 -- given node N, with file:line:col information appended, e.g.
171 -- "subp:file:line:col", corresponding to the source location of the
172 -- body of the subprogram.
174 ------------------------------
175 -- Abstract_Interface_List --
176 ------------------------------
178 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
179 Nod : Node_Id;
181 begin
182 if Is_Concurrent_Type (Typ) then
184 -- If we are dealing with a synchronized subtype, go to the base
185 -- type, whose declaration has the interface list.
187 Nod := Declaration_Node (Base_Type (Typ));
189 if Nkind_In (Nod, N_Full_Type_Declaration,
190 N_Private_Type_Declaration)
191 then
192 return Empty_List;
193 end if;
195 elsif Ekind (Typ) = E_Record_Type_With_Private then
196 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
197 Nod := Type_Definition (Parent (Typ));
199 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
200 if Present (Full_View (Typ))
201 and then
202 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
203 then
204 Nod := Type_Definition (Parent (Full_View (Typ)));
206 -- If the full-view is not available we cannot do anything else
207 -- here (the source has errors).
209 else
210 return Empty_List;
211 end if;
213 -- Support for generic formals with interfaces is still missing ???
215 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
216 return Empty_List;
218 else
219 pragma Assert
220 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
221 Nod := Parent (Typ);
222 end if;
224 elsif Ekind (Typ) = E_Record_Subtype then
225 Nod := Type_Definition (Parent (Etype (Typ)));
227 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
229 -- Recurse, because parent may still be a private extension. Also
230 -- note that the full view of the subtype or the full view of its
231 -- base type may (both) be unavailable.
233 return Abstract_Interface_List (Etype (Typ));
235 elsif Ekind (Typ) = E_Record_Type then
236 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
237 Nod := Formal_Type_Definition (Parent (Typ));
238 else
239 Nod := Type_Definition (Parent (Typ));
240 end if;
242 -- Otherwise the type is of a kind which does not implement interfaces
244 else
245 return Empty_List;
246 end if;
248 return Interface_List (Nod);
249 end Abstract_Interface_List;
251 --------------------------------
252 -- Add_Access_Type_To_Process --
253 --------------------------------
255 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
256 L : Elist_Id;
258 begin
259 Ensure_Freeze_Node (E);
260 L := Access_Types_To_Process (Freeze_Node (E));
262 if No (L) then
263 L := New_Elmt_List;
264 Set_Access_Types_To_Process (Freeze_Node (E), L);
265 end if;
267 Append_Elmt (A, L);
268 end Add_Access_Type_To_Process;
270 --------------------------
271 -- Add_Block_Identifier --
272 --------------------------
274 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
275 Loc : constant Source_Ptr := Sloc (N);
277 begin
278 pragma Assert (Nkind (N) = N_Block_Statement);
280 -- The block already has a label, return its entity
282 if Present (Identifier (N)) then
283 Id := Entity (Identifier (N));
285 -- Create a new block label and set its attributes
287 else
288 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
289 Set_Etype (Id, Standard_Void_Type);
290 Set_Parent (Id, N);
292 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
293 Set_Block_Node (Id, Identifier (N));
294 end if;
295 end Add_Block_Identifier;
297 ----------------------------
298 -- Add_Global_Declaration --
299 ----------------------------
301 procedure Add_Global_Declaration (N : Node_Id) is
302 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
304 begin
305 if No (Declarations (Aux_Node)) then
306 Set_Declarations (Aux_Node, New_List);
307 end if;
309 Append_To (Declarations (Aux_Node), N);
310 Analyze (N);
311 end Add_Global_Declaration;
313 --------------------------------
314 -- Address_Integer_Convert_OK --
315 --------------------------------
317 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
318 begin
319 if Allow_Integer_Address
320 and then ((Is_Descendant_Of_Address (T1)
321 and then Is_Private_Type (T1)
322 and then Is_Integer_Type (T2))
323 or else
324 (Is_Descendant_Of_Address (T2)
325 and then Is_Private_Type (T2)
326 and then Is_Integer_Type (T1)))
327 then
328 return True;
329 else
330 return False;
331 end if;
332 end Address_Integer_Convert_OK;
334 -------------------
335 -- Address_Value --
336 -------------------
338 function Address_Value (N : Node_Id) return Node_Id is
339 Expr : Node_Id := N;
341 begin
342 loop
343 -- For constant, get constant expression
345 if Is_Entity_Name (Expr)
346 and then Ekind (Entity (Expr)) = E_Constant
347 then
348 Expr := Constant_Value (Entity (Expr));
350 -- For unchecked conversion, get result to convert
352 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
353 Expr := Expression (Expr);
355 -- For (common case) of To_Address call, get argument
357 elsif Nkind (Expr) = N_Function_Call
358 and then Is_Entity_Name (Name (Expr))
359 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
360 then
361 Expr := First (Parameter_Associations (Expr));
363 if Nkind (Expr) = N_Parameter_Association then
364 Expr := Explicit_Actual_Parameter (Expr);
365 end if;
367 -- We finally have the real expression
369 else
370 exit;
371 end if;
372 end loop;
374 return Expr;
375 end Address_Value;
377 -----------------
378 -- Addressable --
379 -----------------
381 -- For now, just 8/16/32/64
383 function Addressable (V : Uint) return Boolean is
384 begin
385 return V = Uint_8 or else
386 V = Uint_16 or else
387 V = Uint_32 or else
388 V = Uint_64;
389 end Addressable;
391 function Addressable (V : Int) return Boolean is
392 begin
393 return V = 8 or else
394 V = 16 or else
395 V = 32 or else
396 V = 64;
397 end Addressable;
399 ---------------------------------
400 -- Aggregate_Constraint_Checks --
401 ---------------------------------
403 procedure Aggregate_Constraint_Checks
404 (Exp : Node_Id;
405 Check_Typ : Entity_Id)
407 Exp_Typ : constant Entity_Id := Etype (Exp);
409 begin
410 if Raises_Constraint_Error (Exp) then
411 return;
412 end if;
414 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
415 -- component's type to force the appropriate accessibility checks.
417 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
418 -- force the corresponding run-time check
420 if Is_Access_Type (Check_Typ)
421 and then Is_Local_Anonymous_Access (Check_Typ)
422 then
423 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
424 Analyze_And_Resolve (Exp, Check_Typ);
425 Check_Unset_Reference (Exp);
426 end if;
428 -- What follows is really expansion activity, so check that expansion
429 -- is on and is allowed. In GNATprove mode, we also want check flags to
430 -- be added in the tree, so that the formal verification can rely on
431 -- those to be present. In GNATprove mode for formal verification, some
432 -- treatment typically only done during expansion needs to be performed
433 -- on the tree, but it should not be applied inside generics. Otherwise,
434 -- this breaks the name resolution mechanism for generic instances.
436 if not Expander_Active
437 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
438 then
439 return;
440 end if;
442 if Is_Access_Type (Check_Typ)
443 and then Can_Never_Be_Null (Check_Typ)
444 and then not Can_Never_Be_Null (Exp_Typ)
445 then
446 Install_Null_Excluding_Check (Exp);
447 end if;
449 -- First check if we have to insert discriminant checks
451 if Has_Discriminants (Exp_Typ) then
452 Apply_Discriminant_Check (Exp, Check_Typ);
454 -- Next emit length checks for array aggregates
456 elsif Is_Array_Type (Exp_Typ) then
457 Apply_Length_Check (Exp, Check_Typ);
459 -- Finally emit scalar and string checks. If we are dealing with a
460 -- scalar literal we need to check by hand because the Etype of
461 -- literals is not necessarily correct.
463 elsif Is_Scalar_Type (Exp_Typ)
464 and then Compile_Time_Known_Value (Exp)
465 then
466 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
467 Apply_Compile_Time_Constraint_Error
468 (Exp, "value not in range of}??", CE_Range_Check_Failed,
469 Ent => Base_Type (Check_Typ),
470 Typ => Base_Type (Check_Typ));
472 elsif Is_Out_Of_Range (Exp, Check_Typ) then
473 Apply_Compile_Time_Constraint_Error
474 (Exp, "value not in range of}??", CE_Range_Check_Failed,
475 Ent => Check_Typ,
476 Typ => Check_Typ);
478 elsif not Range_Checks_Suppressed (Check_Typ) then
479 Apply_Scalar_Range_Check (Exp, Check_Typ);
480 end if;
482 -- Verify that target type is also scalar, to prevent view anomalies
483 -- in instantiations.
485 elsif (Is_Scalar_Type (Exp_Typ)
486 or else Nkind (Exp) = N_String_Literal)
487 and then Is_Scalar_Type (Check_Typ)
488 and then Exp_Typ /= Check_Typ
489 then
490 if Is_Entity_Name (Exp)
491 and then Ekind (Entity (Exp)) = E_Constant
492 then
493 -- If expression is a constant, it is worthwhile checking whether
494 -- it is a bound of the type.
496 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
497 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
498 or else
499 (Is_Entity_Name (Type_High_Bound (Check_Typ))
500 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
501 then
502 return;
504 else
505 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
506 Analyze_And_Resolve (Exp, Check_Typ);
507 Check_Unset_Reference (Exp);
508 end if;
510 -- Could use a comment on this case ???
512 else
513 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
514 Analyze_And_Resolve (Exp, Check_Typ);
515 Check_Unset_Reference (Exp);
516 end if;
518 end if;
519 end Aggregate_Constraint_Checks;
521 -----------------------
522 -- Alignment_In_Bits --
523 -----------------------
525 function Alignment_In_Bits (E : Entity_Id) return Uint is
526 begin
527 return Alignment (E) * System_Storage_Unit;
528 end Alignment_In_Bits;
530 --------------------------------------
531 -- All_Composite_Constraints_Static --
532 --------------------------------------
534 function All_Composite_Constraints_Static
535 (Constr : Node_Id) return Boolean
537 begin
538 if No (Constr) or else Error_Posted (Constr) then
539 return True;
540 end if;
542 case Nkind (Constr) is
543 when N_Subexpr =>
544 if Nkind (Constr) in N_Has_Entity
545 and then Present (Entity (Constr))
546 then
547 if Is_Type (Entity (Constr)) then
548 return
549 not Is_Discrete_Type (Entity (Constr))
550 or else Is_OK_Static_Subtype (Entity (Constr));
551 end if;
553 elsif Nkind (Constr) = N_Range then
554 return
555 Is_OK_Static_Expression (Low_Bound (Constr))
556 and then
557 Is_OK_Static_Expression (High_Bound (Constr));
559 elsif Nkind (Constr) = N_Attribute_Reference
560 and then Attribute_Name (Constr) = Name_Range
561 then
562 return
563 Is_OK_Static_Expression
564 (Type_Low_Bound (Etype (Prefix (Constr))))
565 and then
566 Is_OK_Static_Expression
567 (Type_High_Bound (Etype (Prefix (Constr))));
568 end if;
570 return
571 not Present (Etype (Constr)) -- previous error
572 or else not Is_Discrete_Type (Etype (Constr))
573 or else Is_OK_Static_Expression (Constr);
575 when N_Discriminant_Association =>
576 return All_Composite_Constraints_Static (Expression (Constr));
578 when N_Range_Constraint =>
579 return
580 All_Composite_Constraints_Static (Range_Expression (Constr));
582 when N_Index_Or_Discriminant_Constraint =>
583 declare
584 One_Cstr : Entity_Id;
585 begin
586 One_Cstr := First (Constraints (Constr));
587 while Present (One_Cstr) loop
588 if not All_Composite_Constraints_Static (One_Cstr) then
589 return False;
590 end if;
592 Next (One_Cstr);
593 end loop;
594 end;
596 return True;
598 when N_Subtype_Indication =>
599 return
600 All_Composite_Constraints_Static (Subtype_Mark (Constr))
601 and then
602 All_Composite_Constraints_Static (Constraint (Constr));
604 when others =>
605 raise Program_Error;
606 end case;
607 end All_Composite_Constraints_Static;
609 ------------------------
610 -- Append_Entity_Name --
611 ------------------------
613 procedure Append_Entity_Name (Buf : in out Bounded_String; E : Entity_Id) is
614 Temp : Bounded_String;
616 procedure Inner (E : Entity_Id);
617 -- Inner recursive routine, keep outer routine nonrecursive to ease
618 -- debugging when we get strange results from this routine.
620 -----------
621 -- Inner --
622 -----------
624 procedure Inner (E : Entity_Id) is
625 Scop : Node_Id;
627 begin
628 -- If entity has an internal name, skip by it, and print its scope.
629 -- Note that we strip a final R from the name before the test; this
630 -- is needed for some cases of instantiations.
632 declare
633 E_Name : Bounded_String;
635 begin
636 Append (E_Name, Chars (E));
638 if E_Name.Chars (E_Name.Length) = 'R' then
639 E_Name.Length := E_Name.Length - 1;
640 end if;
642 if Is_Internal_Name (E_Name) then
643 Inner (Scope (E));
644 return;
645 end if;
646 end;
648 Scop := Scope (E);
650 -- Just print entity name if its scope is at the outer level
652 if Scop = Standard_Standard then
653 null;
655 -- If scope comes from source, write scope and entity
657 elsif Comes_From_Source (Scop) then
658 Append_Entity_Name (Temp, Scop);
659 Append (Temp, '.');
661 -- If in wrapper package skip past it
663 elsif Present (Scop) and then Is_Wrapper_Package (Scop) then
664 Append_Entity_Name (Temp, Scope (Scop));
665 Append (Temp, '.');
667 -- Otherwise nothing to output (happens in unnamed block statements)
669 else
670 null;
671 end if;
673 -- Output the name
675 declare
676 E_Name : Bounded_String;
678 begin
679 Append_Unqualified_Decoded (E_Name, Chars (E));
681 -- Remove trailing upper-case letters from the name (useful for
682 -- dealing with some cases of internal names generated in the case
683 -- of references from within a generic).
685 while E_Name.Length > 1
686 and then E_Name.Chars (E_Name.Length) in 'A' .. 'Z'
687 loop
688 E_Name.Length := E_Name.Length - 1;
689 end loop;
691 -- Adjust casing appropriately (gets name from source if possible)
693 Adjust_Name_Case (E_Name, Sloc (E));
694 Append (Temp, E_Name);
695 end;
696 end Inner;
698 -- Start of processing for Append_Entity_Name
700 begin
701 Inner (E);
702 Append (Buf, Temp);
703 end Append_Entity_Name;
705 ---------------------------------
706 -- Append_Inherited_Subprogram --
707 ---------------------------------
709 procedure Append_Inherited_Subprogram (S : Entity_Id) is
710 Par : constant Entity_Id := Alias (S);
711 -- The parent subprogram
713 Scop : constant Entity_Id := Scope (Par);
714 -- The scope of definition of the parent subprogram
716 Typ : constant Entity_Id := Defining_Entity (Parent (S));
717 -- The derived type of which S is a primitive operation
719 Decl : Node_Id;
720 Next_E : Entity_Id;
722 begin
723 if Ekind (Current_Scope) = E_Package
724 and then In_Private_Part (Current_Scope)
725 and then Has_Private_Declaration (Typ)
726 and then Is_Tagged_Type (Typ)
727 and then Scop = Current_Scope
728 then
729 -- The inherited operation is available at the earliest place after
730 -- the derived type declaration (RM 7.3.1 (6/1)). This is only
731 -- relevant for type extensions. If the parent operation appears
732 -- after the type extension, the operation is not visible.
734 Decl := First
735 (Visible_Declarations
736 (Package_Specification (Current_Scope)));
737 while Present (Decl) loop
738 if Nkind (Decl) = N_Private_Extension_Declaration
739 and then Defining_Entity (Decl) = Typ
740 then
741 if Sloc (Decl) > Sloc (Par) then
742 Next_E := Next_Entity (Par);
743 Link_Entities (Par, S);
744 Link_Entities (S, Next_E);
745 return;
747 else
748 exit;
749 end if;
750 end if;
752 Next (Decl);
753 end loop;
754 end if;
756 -- If partial view is not a type extension, or it appears before the
757 -- subprogram declaration, insert normally at end of entity list.
759 Append_Entity (S, Current_Scope);
760 end Append_Inherited_Subprogram;
762 -----------------------------------------
763 -- Apply_Compile_Time_Constraint_Error --
764 -----------------------------------------
766 procedure Apply_Compile_Time_Constraint_Error
767 (N : Node_Id;
768 Msg : String;
769 Reason : RT_Exception_Code;
770 Ent : Entity_Id := Empty;
771 Typ : Entity_Id := Empty;
772 Loc : Source_Ptr := No_Location;
773 Rep : Boolean := True;
774 Warn : Boolean := False)
776 Stat : constant Boolean := Is_Static_Expression (N);
777 R_Stat : constant Node_Id :=
778 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
779 Rtyp : Entity_Id;
781 begin
782 if No (Typ) then
783 Rtyp := Etype (N);
784 else
785 Rtyp := Typ;
786 end if;
788 Discard_Node
789 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
791 -- In GNATprove mode, do not replace the node with an exception raised.
792 -- In such a case, either the call to Compile_Time_Constraint_Error
793 -- issues an error which stops analysis, or it issues a warning in
794 -- a few cases where a suitable check flag is set for GNATprove to
795 -- generate a check message.
797 if not Rep or GNATprove_Mode then
798 return;
799 end if;
801 -- Now we replace the node by an N_Raise_Constraint_Error node
802 -- This does not need reanalyzing, so set it as analyzed now.
804 Rewrite (N, R_Stat);
805 Set_Analyzed (N, True);
807 Set_Etype (N, Rtyp);
808 Set_Raises_Constraint_Error (N);
810 -- Now deal with possible local raise handling
812 Possible_Local_Raise (N, Standard_Constraint_Error);
814 -- If the original expression was marked as static, the result is
815 -- still marked as static, but the Raises_Constraint_Error flag is
816 -- always set so that further static evaluation is not attempted.
818 if Stat then
819 Set_Is_Static_Expression (N);
820 end if;
821 end Apply_Compile_Time_Constraint_Error;
823 ---------------------------
824 -- Async_Readers_Enabled --
825 ---------------------------
827 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
828 begin
829 return Has_Enabled_Property (Id, Name_Async_Readers);
830 end Async_Readers_Enabled;
832 ---------------------------
833 -- Async_Writers_Enabled --
834 ---------------------------
836 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
837 begin
838 return Has_Enabled_Property (Id, Name_Async_Writers);
839 end Async_Writers_Enabled;
841 --------------------------------------
842 -- Available_Full_View_Of_Component --
843 --------------------------------------
845 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
846 ST : constant Entity_Id := Scope (T);
847 SCT : constant Entity_Id := Scope (Component_Type (T));
848 begin
849 return In_Open_Scopes (ST)
850 and then In_Open_Scopes (SCT)
851 and then Scope_Depth (ST) >= Scope_Depth (SCT);
852 end Available_Full_View_Of_Component;
854 -------------------
855 -- Bad_Attribute --
856 -------------------
858 procedure Bad_Attribute
859 (N : Node_Id;
860 Nam : Name_Id;
861 Warn : Boolean := False)
863 begin
864 Error_Msg_Warn := Warn;
865 Error_Msg_N ("unrecognized attribute&<<", N);
867 -- Check for possible misspelling
869 Error_Msg_Name_1 := First_Attribute_Name;
870 while Error_Msg_Name_1 <= Last_Attribute_Name loop
871 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
872 Error_Msg_N -- CODEFIX
873 ("\possible misspelling of %<<", N);
874 exit;
875 end if;
877 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
878 end loop;
879 end Bad_Attribute;
881 --------------------------------
882 -- Bad_Predicated_Subtype_Use --
883 --------------------------------
885 procedure Bad_Predicated_Subtype_Use
886 (Msg : String;
887 N : Node_Id;
888 Typ : Entity_Id;
889 Suggest_Static : Boolean := False)
891 Gen : Entity_Id;
893 begin
894 -- Avoid cascaded errors
896 if Error_Posted (N) then
897 return;
898 end if;
900 if Inside_A_Generic then
901 Gen := Current_Scope;
902 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
903 Gen := Scope (Gen);
904 end loop;
906 if No (Gen) then
907 return;
908 end if;
910 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
911 Set_No_Predicate_On_Actual (Typ);
912 end if;
914 elsif Has_Predicates (Typ) then
915 if Is_Generic_Actual_Type (Typ) then
917 -- The restriction on loop parameters is only that the type
918 -- should have no dynamic predicates.
920 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
921 and then not Has_Dynamic_Predicate_Aspect (Typ)
922 and then Is_OK_Static_Subtype (Typ)
923 then
924 return;
925 end if;
927 Gen := Current_Scope;
928 while not Is_Generic_Instance (Gen) loop
929 Gen := Scope (Gen);
930 end loop;
932 pragma Assert (Present (Gen));
934 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
935 Error_Msg_Warn := SPARK_Mode /= On;
936 Error_Msg_FE (Msg & "<<", N, Typ);
937 Error_Msg_F ("\Program_Error [<<", N);
939 Insert_Action (N,
940 Make_Raise_Program_Error (Sloc (N),
941 Reason => PE_Bad_Predicated_Generic_Type));
943 else
944 Error_Msg_FE (Msg & "<<", N, Typ);
945 end if;
947 else
948 Error_Msg_FE (Msg, N, Typ);
949 end if;
951 -- Emit an optional suggestion on how to remedy the error if the
952 -- context warrants it.
954 if Suggest_Static and then Has_Static_Predicate (Typ) then
955 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
956 end if;
957 end if;
958 end Bad_Predicated_Subtype_Use;
960 -----------------------------------------
961 -- Bad_Unordered_Enumeration_Reference --
962 -----------------------------------------
964 function Bad_Unordered_Enumeration_Reference
965 (N : Node_Id;
966 T : Entity_Id) return Boolean
968 begin
969 return Is_Enumeration_Type (T)
970 and then Warn_On_Unordered_Enumeration_Type
971 and then not Is_Generic_Type (T)
972 and then Comes_From_Source (N)
973 and then not Has_Pragma_Ordered (T)
974 and then not In_Same_Extended_Unit (N, T);
975 end Bad_Unordered_Enumeration_Reference;
977 ----------------------------
978 -- Begin_Keyword_Location --
979 ----------------------------
981 function Begin_Keyword_Location (N : Node_Id) return Source_Ptr is
982 HSS : Node_Id;
984 begin
985 pragma Assert (Nkind_In (N, N_Block_Statement,
986 N_Entry_Body,
987 N_Package_Body,
988 N_Subprogram_Body,
989 N_Task_Body));
991 HSS := Handled_Statement_Sequence (N);
993 -- When the handled sequence of statements comes from source, the
994 -- location of the "begin" keyword is that of the sequence itself.
995 -- Note that an internal construct may inherit a source sequence.
997 if Comes_From_Source (HSS) then
998 return Sloc (HSS);
1000 -- The parser generates an internal handled sequence of statements to
1001 -- capture the location of the "begin" keyword if present in the source.
1002 -- Since there are no source statements, the location of the "begin"
1003 -- keyword is effectively that of the "end" keyword.
1005 elsif Comes_From_Source (N) then
1006 return Sloc (HSS);
1008 -- Otherwise the construct is internal and should carry the location of
1009 -- the original construct which prompted its creation.
1011 else
1012 return Sloc (N);
1013 end if;
1014 end Begin_Keyword_Location;
1016 --------------------------
1017 -- Build_Actual_Subtype --
1018 --------------------------
1020 function Build_Actual_Subtype
1021 (T : Entity_Id;
1022 N : Node_Or_Entity_Id) return Node_Id
1024 Loc : Source_Ptr;
1025 -- Normally Sloc (N), but may point to corresponding body in some cases
1027 Constraints : List_Id;
1028 Decl : Node_Id;
1029 Discr : Entity_Id;
1030 Hi : Node_Id;
1031 Lo : Node_Id;
1032 Subt : Entity_Id;
1033 Disc_Type : Entity_Id;
1034 Obj : Node_Id;
1036 begin
1037 Loc := Sloc (N);
1039 if Nkind (N) = N_Defining_Identifier then
1040 Obj := New_Occurrence_Of (N, Loc);
1042 -- If this is a formal parameter of a subprogram declaration, and
1043 -- we are compiling the body, we want the declaration for the
1044 -- actual subtype to carry the source position of the body, to
1045 -- prevent anomalies in gdb when stepping through the code.
1047 if Is_Formal (N) then
1048 declare
1049 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
1050 begin
1051 if Nkind (Decl) = N_Subprogram_Declaration
1052 and then Present (Corresponding_Body (Decl))
1053 then
1054 Loc := Sloc (Corresponding_Body (Decl));
1055 end if;
1056 end;
1057 end if;
1059 else
1060 Obj := N;
1061 end if;
1063 if Is_Array_Type (T) then
1064 Constraints := New_List;
1065 for J in 1 .. Number_Dimensions (T) loop
1067 -- Build an array subtype declaration with the nominal subtype and
1068 -- the bounds of the actual. Add the declaration in front of the
1069 -- local declarations for the subprogram, for analysis before any
1070 -- reference to the formal in the body.
1072 Lo :=
1073 Make_Attribute_Reference (Loc,
1074 Prefix =>
1075 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1076 Attribute_Name => Name_First,
1077 Expressions => New_List (
1078 Make_Integer_Literal (Loc, J)));
1080 Hi :=
1081 Make_Attribute_Reference (Loc,
1082 Prefix =>
1083 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
1084 Attribute_Name => Name_Last,
1085 Expressions => New_List (
1086 Make_Integer_Literal (Loc, J)));
1088 Append (Make_Range (Loc, Lo, Hi), Constraints);
1089 end loop;
1091 -- If the type has unknown discriminants there is no constrained
1092 -- subtype to build. This is never called for a formal or for a
1093 -- lhs, so returning the type is ok ???
1095 elsif Has_Unknown_Discriminants (T) then
1096 return T;
1098 else
1099 Constraints := New_List;
1101 -- Type T is a generic derived type, inherit the discriminants from
1102 -- the parent type.
1104 if Is_Private_Type (T)
1105 and then No (Full_View (T))
1107 -- T was flagged as an error if it was declared as a formal
1108 -- derived type with known discriminants. In this case there
1109 -- is no need to look at the parent type since T already carries
1110 -- its own discriminants.
1112 and then not Error_Posted (T)
1113 then
1114 Disc_Type := Etype (Base_Type (T));
1115 else
1116 Disc_Type := T;
1117 end if;
1119 Discr := First_Discriminant (Disc_Type);
1120 while Present (Discr) loop
1121 Append_To (Constraints,
1122 Make_Selected_Component (Loc,
1123 Prefix =>
1124 Duplicate_Subexpr_No_Checks (Obj),
1125 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1126 Next_Discriminant (Discr);
1127 end loop;
1128 end if;
1130 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1131 Set_Is_Internal (Subt);
1133 Decl :=
1134 Make_Subtype_Declaration (Loc,
1135 Defining_Identifier => Subt,
1136 Subtype_Indication =>
1137 Make_Subtype_Indication (Loc,
1138 Subtype_Mark => New_Occurrence_Of (T, Loc),
1139 Constraint =>
1140 Make_Index_Or_Discriminant_Constraint (Loc,
1141 Constraints => Constraints)));
1143 Mark_Rewrite_Insertion (Decl);
1144 return Decl;
1145 end Build_Actual_Subtype;
1147 ---------------------------------------
1148 -- Build_Actual_Subtype_Of_Component --
1149 ---------------------------------------
1151 function Build_Actual_Subtype_Of_Component
1152 (T : Entity_Id;
1153 N : Node_Id) return Node_Id
1155 Loc : constant Source_Ptr := Sloc (N);
1156 P : constant Node_Id := Prefix (N);
1157 D : Elmt_Id;
1158 Id : Node_Id;
1159 Index_Typ : Entity_Id;
1161 Desig_Typ : Entity_Id;
1162 -- This is either a copy of T, or if T is an access type, then it is
1163 -- the directly designated type of this access type.
1165 function Build_Actual_Array_Constraint return List_Id;
1166 -- If one or more of the bounds of the component depends on
1167 -- discriminants, build actual constraint using the discriminants
1168 -- of the prefix.
1170 function Build_Actual_Record_Constraint return List_Id;
1171 -- Similar to previous one, for discriminated components constrained
1172 -- by the discriminant of the enclosing object.
1174 -----------------------------------
1175 -- Build_Actual_Array_Constraint --
1176 -----------------------------------
1178 function Build_Actual_Array_Constraint return List_Id is
1179 Constraints : constant List_Id := New_List;
1180 Indx : Node_Id;
1181 Hi : Node_Id;
1182 Lo : Node_Id;
1183 Old_Hi : Node_Id;
1184 Old_Lo : Node_Id;
1186 begin
1187 Indx := First_Index (Desig_Typ);
1188 while Present (Indx) loop
1189 Old_Lo := Type_Low_Bound (Etype (Indx));
1190 Old_Hi := Type_High_Bound (Etype (Indx));
1192 if Denotes_Discriminant (Old_Lo) then
1193 Lo :=
1194 Make_Selected_Component (Loc,
1195 Prefix => New_Copy_Tree (P),
1196 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1198 else
1199 Lo := New_Copy_Tree (Old_Lo);
1201 -- The new bound will be reanalyzed in the enclosing
1202 -- declaration. For literal bounds that come from a type
1203 -- declaration, the type of the context must be imposed, so
1204 -- insure that analysis will take place. For non-universal
1205 -- types this is not strictly necessary.
1207 Set_Analyzed (Lo, False);
1208 end if;
1210 if Denotes_Discriminant (Old_Hi) then
1211 Hi :=
1212 Make_Selected_Component (Loc,
1213 Prefix => New_Copy_Tree (P),
1214 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1216 else
1217 Hi := New_Copy_Tree (Old_Hi);
1218 Set_Analyzed (Hi, False);
1219 end if;
1221 Append (Make_Range (Loc, Lo, Hi), Constraints);
1222 Next_Index (Indx);
1223 end loop;
1225 return Constraints;
1226 end Build_Actual_Array_Constraint;
1228 ------------------------------------
1229 -- Build_Actual_Record_Constraint --
1230 ------------------------------------
1232 function Build_Actual_Record_Constraint return List_Id is
1233 Constraints : constant List_Id := New_List;
1234 D : Elmt_Id;
1235 D_Val : Node_Id;
1237 begin
1238 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1239 while Present (D) loop
1240 if Denotes_Discriminant (Node (D)) then
1241 D_Val := Make_Selected_Component (Loc,
1242 Prefix => New_Copy_Tree (P),
1243 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1245 else
1246 D_Val := New_Copy_Tree (Node (D));
1247 end if;
1249 Append (D_Val, Constraints);
1250 Next_Elmt (D);
1251 end loop;
1253 return Constraints;
1254 end Build_Actual_Record_Constraint;
1256 -- Start of processing for Build_Actual_Subtype_Of_Component
1258 begin
1259 -- Why the test for Spec_Expression mode here???
1261 if In_Spec_Expression then
1262 return Empty;
1264 -- More comments for the rest of this body would be good ???
1266 elsif Nkind (N) = N_Explicit_Dereference then
1267 if Is_Composite_Type (T)
1268 and then not Is_Constrained (T)
1269 and then not (Is_Class_Wide_Type (T)
1270 and then Is_Constrained (Root_Type (T)))
1271 and then not Has_Unknown_Discriminants (T)
1272 then
1273 -- If the type of the dereference is already constrained, it is an
1274 -- actual subtype.
1276 if Is_Array_Type (Etype (N))
1277 and then Is_Constrained (Etype (N))
1278 then
1279 return Empty;
1280 else
1281 Remove_Side_Effects (P);
1282 return Build_Actual_Subtype (T, N);
1283 end if;
1284 else
1285 return Empty;
1286 end if;
1287 end if;
1289 if Ekind (T) = E_Access_Subtype then
1290 Desig_Typ := Designated_Type (T);
1291 else
1292 Desig_Typ := T;
1293 end if;
1295 if Ekind (Desig_Typ) = E_Array_Subtype then
1296 Id := First_Index (Desig_Typ);
1297 while Present (Id) loop
1298 Index_Typ := Underlying_Type (Etype (Id));
1300 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1301 or else
1302 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1303 then
1304 Remove_Side_Effects (P);
1305 return
1306 Build_Component_Subtype
1307 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1308 end if;
1310 Next_Index (Id);
1311 end loop;
1313 elsif Is_Composite_Type (Desig_Typ)
1314 and then Has_Discriminants (Desig_Typ)
1315 and then not Has_Unknown_Discriminants (Desig_Typ)
1316 then
1317 if Is_Private_Type (Desig_Typ)
1318 and then No (Discriminant_Constraint (Desig_Typ))
1319 then
1320 Desig_Typ := Full_View (Desig_Typ);
1321 end if;
1323 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1324 while Present (D) loop
1325 if Denotes_Discriminant (Node (D)) then
1326 Remove_Side_Effects (P);
1327 return
1328 Build_Component_Subtype (
1329 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1330 end if;
1332 Next_Elmt (D);
1333 end loop;
1334 end if;
1336 -- If none of the above, the actual and nominal subtypes are the same
1338 return Empty;
1339 end Build_Actual_Subtype_Of_Component;
1341 ---------------------------------
1342 -- Build_Class_Wide_Clone_Body --
1343 ---------------------------------
1345 procedure Build_Class_Wide_Clone_Body
1346 (Spec_Id : Entity_Id;
1347 Bod : Node_Id)
1349 Loc : constant Source_Ptr := Sloc (Bod);
1350 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1351 Clone_Body : Node_Id;
1353 begin
1354 -- The declaration of the class-wide clone was created when the
1355 -- corresponding class-wide condition was analyzed.
1357 Clone_Body :=
1358 Make_Subprogram_Body (Loc,
1359 Specification =>
1360 Copy_Subprogram_Spec (Parent (Clone_Id)),
1361 Declarations => Declarations (Bod),
1362 Handled_Statement_Sequence => Handled_Statement_Sequence (Bod));
1364 -- The new operation is internal and overriding indicators do not apply
1365 -- (the original primitive may have carried one).
1367 Set_Must_Override (Specification (Clone_Body), False);
1369 -- If the subprogram body is the proper body of a stub, insert the
1370 -- subprogram after the stub, i.e. the same declarative region as
1371 -- the original sugprogram.
1373 if Nkind (Parent (Bod)) = N_Subunit then
1374 Insert_After (Corresponding_Stub (Parent (Bod)), Clone_Body);
1376 else
1377 Insert_Before (Bod, Clone_Body);
1378 end if;
1380 Analyze (Clone_Body);
1381 end Build_Class_Wide_Clone_Body;
1383 ---------------------------------
1384 -- Build_Class_Wide_Clone_Call --
1385 ---------------------------------
1387 function Build_Class_Wide_Clone_Call
1388 (Loc : Source_Ptr;
1389 Decls : List_Id;
1390 Spec_Id : Entity_Id;
1391 Spec : Node_Id) return Node_Id
1393 Clone_Id : constant Entity_Id := Class_Wide_Clone (Spec_Id);
1394 Par_Type : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
1396 Actuals : List_Id;
1397 Call : Node_Id;
1398 Formal : Entity_Id;
1399 New_Body : Node_Id;
1400 New_F_Spec : Entity_Id;
1401 New_Formal : Entity_Id;
1403 begin
1404 Actuals := Empty_List;
1405 Formal := First_Formal (Spec_Id);
1406 New_F_Spec := First (Parameter_Specifications (Spec));
1408 -- Build parameter association for call to class-wide clone.
1410 while Present (Formal) loop
1411 New_Formal := Defining_Identifier (New_F_Spec);
1413 -- If controlling argument and operation is inherited, add conversion
1414 -- to parent type for the call.
1416 if Etype (Formal) = Par_Type
1417 and then not Is_Empty_List (Decls)
1418 then
1419 Append_To (Actuals,
1420 Make_Type_Conversion (Loc,
1421 New_Occurrence_Of (Par_Type, Loc),
1422 New_Occurrence_Of (New_Formal, Loc)));
1424 else
1425 Append_To (Actuals, New_Occurrence_Of (New_Formal, Loc));
1426 end if;
1428 Next_Formal (Formal);
1429 Next (New_F_Spec);
1430 end loop;
1432 if Ekind (Spec_Id) = E_Procedure then
1433 Call :=
1434 Make_Procedure_Call_Statement (Loc,
1435 Name => New_Occurrence_Of (Clone_Id, Loc),
1436 Parameter_Associations => Actuals);
1437 else
1438 Call :=
1439 Make_Simple_Return_Statement (Loc,
1440 Expression =>
1441 Make_Function_Call (Loc,
1442 Name => New_Occurrence_Of (Clone_Id, Loc),
1443 Parameter_Associations => Actuals));
1444 end if;
1446 New_Body :=
1447 Make_Subprogram_Body (Loc,
1448 Specification =>
1449 Copy_Subprogram_Spec (Spec),
1450 Declarations => Decls,
1451 Handled_Statement_Sequence =>
1452 Make_Handled_Sequence_Of_Statements (Loc,
1453 Statements => New_List (Call),
1454 End_Label => Make_Identifier (Loc, Chars (Spec_Id))));
1456 return New_Body;
1457 end Build_Class_Wide_Clone_Call;
1459 ---------------------------------
1460 -- Build_Class_Wide_Clone_Decl --
1461 ---------------------------------
1463 procedure Build_Class_Wide_Clone_Decl (Spec_Id : Entity_Id) is
1464 Loc : constant Source_Ptr := Sloc (Spec_Id);
1465 Clone_Id : constant Entity_Id :=
1466 Make_Defining_Identifier (Loc,
1467 New_External_Name (Chars (Spec_Id), Suffix => "CL"));
1469 Decl : Node_Id;
1470 Spec : Node_Id;
1472 begin
1473 Spec := Copy_Subprogram_Spec (Parent (Spec_Id));
1474 Set_Must_Override (Spec, False);
1475 Set_Must_Not_Override (Spec, False);
1476 Set_Defining_Unit_Name (Spec, Clone_Id);
1478 Decl := Make_Subprogram_Declaration (Loc, Spec);
1479 Append (Decl, List_Containing (Unit_Declaration_Node (Spec_Id)));
1481 -- Link clone to original subprogram, for use when building body and
1482 -- wrapper call to inherited operation.
1484 Set_Class_Wide_Clone (Spec_Id, Clone_Id);
1485 end Build_Class_Wide_Clone_Decl;
1487 -----------------------------
1488 -- Build_Component_Subtype --
1489 -----------------------------
1491 function Build_Component_Subtype
1492 (C : List_Id;
1493 Loc : Source_Ptr;
1494 T : Entity_Id) return Node_Id
1496 Subt : Entity_Id;
1497 Decl : Node_Id;
1499 begin
1500 -- Unchecked_Union components do not require component subtypes
1502 if Is_Unchecked_Union (T) then
1503 return Empty;
1504 end if;
1506 Subt := Make_Temporary (Loc, 'S');
1507 Set_Is_Internal (Subt);
1509 Decl :=
1510 Make_Subtype_Declaration (Loc,
1511 Defining_Identifier => Subt,
1512 Subtype_Indication =>
1513 Make_Subtype_Indication (Loc,
1514 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1515 Constraint =>
1516 Make_Index_Or_Discriminant_Constraint (Loc,
1517 Constraints => C)));
1519 Mark_Rewrite_Insertion (Decl);
1520 return Decl;
1521 end Build_Component_Subtype;
1523 ---------------------------
1524 -- Build_Default_Subtype --
1525 ---------------------------
1527 function Build_Default_Subtype
1528 (T : Entity_Id;
1529 N : Node_Id) return Entity_Id
1531 Loc : constant Source_Ptr := Sloc (N);
1532 Disc : Entity_Id;
1534 Bas : Entity_Id;
1535 -- The base type that is to be constrained by the defaults
1537 begin
1538 if not Has_Discriminants (T) or else Is_Constrained (T) then
1539 return T;
1540 end if;
1542 Bas := Base_Type (T);
1544 -- If T is non-private but its base type is private, this is the
1545 -- completion of a subtype declaration whose parent type is private
1546 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1547 -- are to be found in the full view of the base. Check that the private
1548 -- status of T and its base differ.
1550 if Is_Private_Type (Bas)
1551 and then not Is_Private_Type (T)
1552 and then Present (Full_View (Bas))
1553 then
1554 Bas := Full_View (Bas);
1555 end if;
1557 Disc := First_Discriminant (T);
1559 if No (Discriminant_Default_Value (Disc)) then
1560 return T;
1561 end if;
1563 declare
1564 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1565 Constraints : constant List_Id := New_List;
1566 Decl : Node_Id;
1568 begin
1569 while Present (Disc) loop
1570 Append_To (Constraints,
1571 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1572 Next_Discriminant (Disc);
1573 end loop;
1575 Decl :=
1576 Make_Subtype_Declaration (Loc,
1577 Defining_Identifier => Act,
1578 Subtype_Indication =>
1579 Make_Subtype_Indication (Loc,
1580 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1581 Constraint =>
1582 Make_Index_Or_Discriminant_Constraint (Loc,
1583 Constraints => Constraints)));
1585 Insert_Action (N, Decl);
1587 -- If the context is a component declaration the subtype declaration
1588 -- will be analyzed when the enclosing type is frozen, otherwise do
1589 -- it now.
1591 if Ekind (Current_Scope) /= E_Record_Type then
1592 Analyze (Decl);
1593 end if;
1595 return Act;
1596 end;
1597 end Build_Default_Subtype;
1599 --------------------------------------------
1600 -- Build_Discriminal_Subtype_Of_Component --
1601 --------------------------------------------
1603 function Build_Discriminal_Subtype_Of_Component
1604 (T : Entity_Id) return Node_Id
1606 Loc : constant Source_Ptr := Sloc (T);
1607 D : Elmt_Id;
1608 Id : Node_Id;
1610 function Build_Discriminal_Array_Constraint return List_Id;
1611 -- If one or more of the bounds of the component depends on
1612 -- discriminants, build actual constraint using the discriminants
1613 -- of the prefix.
1615 function Build_Discriminal_Record_Constraint return List_Id;
1616 -- Similar to previous one, for discriminated components constrained by
1617 -- the discriminant of the enclosing object.
1619 ----------------------------------------
1620 -- Build_Discriminal_Array_Constraint --
1621 ----------------------------------------
1623 function Build_Discriminal_Array_Constraint return List_Id is
1624 Constraints : constant List_Id := New_List;
1625 Indx : Node_Id;
1626 Hi : Node_Id;
1627 Lo : Node_Id;
1628 Old_Hi : Node_Id;
1629 Old_Lo : Node_Id;
1631 begin
1632 Indx := First_Index (T);
1633 while Present (Indx) loop
1634 Old_Lo := Type_Low_Bound (Etype (Indx));
1635 Old_Hi := Type_High_Bound (Etype (Indx));
1637 if Denotes_Discriminant (Old_Lo) then
1638 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1640 else
1641 Lo := New_Copy_Tree (Old_Lo);
1642 end if;
1644 if Denotes_Discriminant (Old_Hi) then
1645 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1647 else
1648 Hi := New_Copy_Tree (Old_Hi);
1649 end if;
1651 Append (Make_Range (Loc, Lo, Hi), Constraints);
1652 Next_Index (Indx);
1653 end loop;
1655 return Constraints;
1656 end Build_Discriminal_Array_Constraint;
1658 -----------------------------------------
1659 -- Build_Discriminal_Record_Constraint --
1660 -----------------------------------------
1662 function Build_Discriminal_Record_Constraint return List_Id is
1663 Constraints : constant List_Id := New_List;
1664 D : Elmt_Id;
1665 D_Val : Node_Id;
1667 begin
1668 D := First_Elmt (Discriminant_Constraint (T));
1669 while Present (D) loop
1670 if Denotes_Discriminant (Node (D)) then
1671 D_Val :=
1672 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1673 else
1674 D_Val := New_Copy_Tree (Node (D));
1675 end if;
1677 Append (D_Val, Constraints);
1678 Next_Elmt (D);
1679 end loop;
1681 return Constraints;
1682 end Build_Discriminal_Record_Constraint;
1684 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1686 begin
1687 if Ekind (T) = E_Array_Subtype then
1688 Id := First_Index (T);
1689 while Present (Id) loop
1690 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1691 or else
1692 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1693 then
1694 return Build_Component_Subtype
1695 (Build_Discriminal_Array_Constraint, Loc, T);
1696 end if;
1698 Next_Index (Id);
1699 end loop;
1701 elsif Ekind (T) = E_Record_Subtype
1702 and then Has_Discriminants (T)
1703 and then not Has_Unknown_Discriminants (T)
1704 then
1705 D := First_Elmt (Discriminant_Constraint (T));
1706 while Present (D) loop
1707 if Denotes_Discriminant (Node (D)) then
1708 return Build_Component_Subtype
1709 (Build_Discriminal_Record_Constraint, Loc, T);
1710 end if;
1712 Next_Elmt (D);
1713 end loop;
1714 end if;
1716 -- If none of the above, the actual and nominal subtypes are the same
1718 return Empty;
1719 end Build_Discriminal_Subtype_Of_Component;
1721 ------------------------------
1722 -- Build_Elaboration_Entity --
1723 ------------------------------
1725 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1726 Loc : constant Source_Ptr := Sloc (N);
1727 Decl : Node_Id;
1728 Elab_Ent : Entity_Id;
1730 procedure Set_Package_Name (Ent : Entity_Id);
1731 -- Given an entity, sets the fully qualified name of the entity in
1732 -- Name_Buffer, with components separated by double underscores. This
1733 -- is a recursive routine that climbs the scope chain to Standard.
1735 ----------------------
1736 -- Set_Package_Name --
1737 ----------------------
1739 procedure Set_Package_Name (Ent : Entity_Id) is
1740 begin
1741 if Scope (Ent) /= Standard_Standard then
1742 Set_Package_Name (Scope (Ent));
1744 declare
1745 Nam : constant String := Get_Name_String (Chars (Ent));
1746 begin
1747 Name_Buffer (Name_Len + 1) := '_';
1748 Name_Buffer (Name_Len + 2) := '_';
1749 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1750 Name_Len := Name_Len + Nam'Length + 2;
1751 end;
1753 else
1754 Get_Name_String (Chars (Ent));
1755 end if;
1756 end Set_Package_Name;
1758 -- Start of processing for Build_Elaboration_Entity
1760 begin
1761 -- Ignore call if already constructed
1763 if Present (Elaboration_Entity (Spec_Id)) then
1764 return;
1766 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1767 -- no role in analysis.
1769 elsif ASIS_Mode then
1770 return;
1772 -- Do not generate an elaboration entity in GNATprove move because the
1773 -- elaboration counter is a form of expansion.
1775 elsif GNATprove_Mode then
1776 return;
1778 -- See if we need elaboration entity
1780 -- We always need an elaboration entity when preserving control flow, as
1781 -- we want to remain explicit about the unit's elaboration order.
1783 elsif Opt.Suppress_Control_Flow_Optimizations then
1784 null;
1786 -- We always need an elaboration entity for the dynamic elaboration
1787 -- model, since it is needed to properly generate the PE exception for
1788 -- access before elaboration.
1790 elsif Dynamic_Elaboration_Checks then
1791 null;
1793 -- For the static model, we don't need the elaboration counter if this
1794 -- unit is sure to have no elaboration code, since that means there
1795 -- is no elaboration unit to be called. Note that we can't just decide
1796 -- after the fact by looking to see whether there was elaboration code,
1797 -- because that's too late to make this decision.
1799 elsif Restriction_Active (No_Elaboration_Code) then
1800 return;
1802 -- Similarly, for the static model, we can skip the elaboration counter
1803 -- if we have the No_Multiple_Elaboration restriction, since for the
1804 -- static model, that's the only purpose of the counter (to avoid
1805 -- multiple elaboration).
1807 elsif Restriction_Active (No_Multiple_Elaboration) then
1808 return;
1809 end if;
1811 -- Here we need the elaboration entity
1813 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1814 -- name with dots replaced by double underscore. We have to manually
1815 -- construct this name, since it will be elaborated in the outer scope,
1816 -- and thus will not have the unit name automatically prepended.
1818 Set_Package_Name (Spec_Id);
1819 Add_Str_To_Name_Buffer ("_E");
1821 -- Create elaboration counter
1823 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1824 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1826 Decl :=
1827 Make_Object_Declaration (Loc,
1828 Defining_Identifier => Elab_Ent,
1829 Object_Definition =>
1830 New_Occurrence_Of (Standard_Short_Integer, Loc),
1831 Expression => Make_Integer_Literal (Loc, Uint_0));
1833 Push_Scope (Standard_Standard);
1834 Add_Global_Declaration (Decl);
1835 Pop_Scope;
1837 -- Reset True_Constant indication, since we will indeed assign a value
1838 -- to the variable in the binder main. We also kill the Current_Value
1839 -- and Last_Assignment fields for the same reason.
1841 Set_Is_True_Constant (Elab_Ent, False);
1842 Set_Current_Value (Elab_Ent, Empty);
1843 Set_Last_Assignment (Elab_Ent, Empty);
1845 -- We do not want any further qualification of the name (if we did not
1846 -- do this, we would pick up the name of the generic package in the case
1847 -- of a library level generic instantiation).
1849 Set_Has_Qualified_Name (Elab_Ent);
1850 Set_Has_Fully_Qualified_Name (Elab_Ent);
1851 end Build_Elaboration_Entity;
1853 --------------------------------
1854 -- Build_Explicit_Dereference --
1855 --------------------------------
1857 procedure Build_Explicit_Dereference
1858 (Expr : Node_Id;
1859 Disc : Entity_Id)
1861 Loc : constant Source_Ptr := Sloc (Expr);
1862 I : Interp_Index;
1863 It : Interp;
1865 begin
1866 -- An entity of a type with a reference aspect is overloaded with
1867 -- both interpretations: with and without the dereference. Now that
1868 -- the dereference is made explicit, set the type of the node properly,
1869 -- to prevent anomalies in the backend. Same if the expression is an
1870 -- overloaded function call whose return type has a reference aspect.
1872 if Is_Entity_Name (Expr) then
1873 Set_Etype (Expr, Etype (Entity (Expr)));
1875 -- The designated entity will not be examined again when resolving
1876 -- the dereference, so generate a reference to it now.
1878 Generate_Reference (Entity (Expr), Expr);
1880 elsif Nkind (Expr) = N_Function_Call then
1882 -- If the name of the indexing function is overloaded, locate the one
1883 -- whose return type has an implicit dereference on the desired
1884 -- discriminant, and set entity and type of function call.
1886 if Is_Overloaded (Name (Expr)) then
1887 Get_First_Interp (Name (Expr), I, It);
1889 while Present (It.Nam) loop
1890 if Ekind ((It.Typ)) = E_Record_Type
1891 and then First_Entity ((It.Typ)) = Disc
1892 then
1893 Set_Entity (Name (Expr), It.Nam);
1894 Set_Etype (Name (Expr), Etype (It.Nam));
1895 exit;
1896 end if;
1898 Get_Next_Interp (I, It);
1899 end loop;
1900 end if;
1902 -- Set type of call from resolved function name.
1904 Set_Etype (Expr, Etype (Name (Expr)));
1905 end if;
1907 Set_Is_Overloaded (Expr, False);
1909 -- The expression will often be a generalized indexing that yields a
1910 -- container element that is then dereferenced, in which case the
1911 -- generalized indexing call is also non-overloaded.
1913 if Nkind (Expr) = N_Indexed_Component
1914 and then Present (Generalized_Indexing (Expr))
1915 then
1916 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1917 end if;
1919 Rewrite (Expr,
1920 Make_Explicit_Dereference (Loc,
1921 Prefix =>
1922 Make_Selected_Component (Loc,
1923 Prefix => Relocate_Node (Expr),
1924 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1925 Set_Etype (Prefix (Expr), Etype (Disc));
1926 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1927 end Build_Explicit_Dereference;
1929 ---------------------------
1930 -- Build_Overriding_Spec --
1931 ---------------------------
1933 function Build_Overriding_Spec
1934 (Op : Entity_Id;
1935 Typ : Entity_Id) return Node_Id
1937 Loc : constant Source_Ptr := Sloc (Typ);
1938 Par_Typ : constant Entity_Id := Find_Dispatching_Type (Op);
1939 Spec : constant Node_Id := Specification (Unit_Declaration_Node (Op));
1941 Formal_Spec : Node_Id;
1942 Formal_Type : Node_Id;
1943 New_Spec : Node_Id;
1945 begin
1946 New_Spec := Copy_Subprogram_Spec (Spec);
1948 Formal_Spec := First (Parameter_Specifications (New_Spec));
1949 while Present (Formal_Spec) loop
1950 Formal_Type := Parameter_Type (Formal_Spec);
1952 if Is_Entity_Name (Formal_Type)
1953 and then Entity (Formal_Type) = Par_Typ
1954 then
1955 Rewrite (Formal_Type, New_Occurrence_Of (Typ, Loc));
1956 end if;
1958 -- Nothing needs to be done for access parameters
1960 Next (Formal_Spec);
1961 end loop;
1963 return New_Spec;
1964 end Build_Overriding_Spec;
1966 -----------------------------------
1967 -- Cannot_Raise_Constraint_Error --
1968 -----------------------------------
1970 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1971 begin
1972 if Compile_Time_Known_Value (Expr) then
1973 return True;
1975 elsif Do_Range_Check (Expr) then
1976 return False;
1978 elsif Raises_Constraint_Error (Expr) then
1979 return False;
1981 else
1982 case Nkind (Expr) is
1983 when N_Identifier =>
1984 return True;
1986 when N_Expanded_Name =>
1987 return True;
1989 when N_Selected_Component =>
1990 return not Do_Discriminant_Check (Expr);
1992 when N_Attribute_Reference =>
1993 if Do_Overflow_Check (Expr) then
1994 return False;
1996 elsif No (Expressions (Expr)) then
1997 return True;
1999 else
2000 declare
2001 N : Node_Id;
2003 begin
2004 N := First (Expressions (Expr));
2005 while Present (N) loop
2006 if Cannot_Raise_Constraint_Error (N) then
2007 Next (N);
2008 else
2009 return False;
2010 end if;
2011 end loop;
2013 return True;
2014 end;
2015 end if;
2017 when N_Type_Conversion =>
2018 if Do_Overflow_Check (Expr)
2019 or else Do_Length_Check (Expr)
2020 or else Do_Tag_Check (Expr)
2021 then
2022 return False;
2023 else
2024 return Cannot_Raise_Constraint_Error (Expression (Expr));
2025 end if;
2027 when N_Unchecked_Type_Conversion =>
2028 return Cannot_Raise_Constraint_Error (Expression (Expr));
2030 when N_Unary_Op =>
2031 if Do_Overflow_Check (Expr) then
2032 return False;
2033 else
2034 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2035 end if;
2037 when N_Op_Divide
2038 | N_Op_Mod
2039 | N_Op_Rem
2041 if Do_Division_Check (Expr)
2042 or else
2043 Do_Overflow_Check (Expr)
2044 then
2045 return False;
2046 else
2047 return
2048 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2049 and then
2050 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2051 end if;
2053 when N_Op_Add
2054 | N_Op_And
2055 | N_Op_Concat
2056 | N_Op_Eq
2057 | N_Op_Expon
2058 | N_Op_Ge
2059 | N_Op_Gt
2060 | N_Op_Le
2061 | N_Op_Lt
2062 | N_Op_Multiply
2063 | N_Op_Ne
2064 | N_Op_Or
2065 | N_Op_Rotate_Left
2066 | N_Op_Rotate_Right
2067 | N_Op_Shift_Left
2068 | N_Op_Shift_Right
2069 | N_Op_Shift_Right_Arithmetic
2070 | N_Op_Subtract
2071 | N_Op_Xor
2073 if Do_Overflow_Check (Expr) then
2074 return False;
2075 else
2076 return
2077 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
2078 and then
2079 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
2080 end if;
2082 when others =>
2083 return False;
2084 end case;
2085 end if;
2086 end Cannot_Raise_Constraint_Error;
2088 -----------------------------------------
2089 -- Check_Dynamically_Tagged_Expression --
2090 -----------------------------------------
2092 procedure Check_Dynamically_Tagged_Expression
2093 (Expr : Node_Id;
2094 Typ : Entity_Id;
2095 Related_Nod : Node_Id)
2097 begin
2098 pragma Assert (Is_Tagged_Type (Typ));
2100 -- In order to avoid spurious errors when analyzing the expanded code,
2101 -- this check is done only for nodes that come from source and for
2102 -- actuals of generic instantiations.
2104 if (Comes_From_Source (Related_Nod)
2105 or else In_Generic_Actual (Expr))
2106 and then (Is_Class_Wide_Type (Etype (Expr))
2107 or else Is_Dynamically_Tagged (Expr))
2108 and then not Is_Class_Wide_Type (Typ)
2109 then
2110 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2111 end if;
2112 end Check_Dynamically_Tagged_Expression;
2114 --------------------------
2115 -- Check_Fully_Declared --
2116 --------------------------
2118 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2119 begin
2120 if Ekind (T) = E_Incomplete_Type then
2122 -- Ada 2005 (AI-50217): If the type is available through a limited
2123 -- with_clause, verify that its full view has been analyzed.
2125 if From_Limited_With (T)
2126 and then Present (Non_Limited_View (T))
2127 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2128 then
2129 -- The non-limited view is fully declared
2131 null;
2133 else
2134 Error_Msg_NE
2135 ("premature usage of incomplete}", N, First_Subtype (T));
2136 end if;
2138 -- Need comments for these tests ???
2140 elsif Has_Private_Component (T)
2141 and then not Is_Generic_Type (Root_Type (T))
2142 and then not In_Spec_Expression
2143 then
2144 -- Special case: if T is the anonymous type created for a single
2145 -- task or protected object, use the name of the source object.
2147 if Is_Concurrent_Type (T)
2148 and then not Comes_From_Source (T)
2149 and then Nkind (N) = N_Object_Declaration
2150 then
2151 Error_Msg_NE
2152 ("type of& has incomplete component",
2153 N, Defining_Identifier (N));
2154 else
2155 Error_Msg_NE
2156 ("premature usage of incomplete}",
2157 N, First_Subtype (T));
2158 end if;
2159 end if;
2160 end Check_Fully_Declared;
2162 -------------------------------------------
2163 -- Check_Function_With_Address_Parameter --
2164 -------------------------------------------
2166 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
2167 F : Entity_Id;
2168 T : Entity_Id;
2170 begin
2171 F := First_Formal (Subp_Id);
2172 while Present (F) loop
2173 T := Etype (F);
2175 if Is_Private_Type (T) and then Present (Full_View (T)) then
2176 T := Full_View (T);
2177 end if;
2179 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
2180 Set_Is_Pure (Subp_Id, False);
2181 exit;
2182 end if;
2184 Next_Formal (F);
2185 end loop;
2186 end Check_Function_With_Address_Parameter;
2188 -------------------------------------
2189 -- Check_Function_Writable_Actuals --
2190 -------------------------------------
2192 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2193 Writable_Actuals_List : Elist_Id := No_Elist;
2194 Identifiers_List : Elist_Id := No_Elist;
2195 Aggr_Error_Node : Node_Id := Empty;
2196 Error_Node : Node_Id := Empty;
2198 procedure Collect_Identifiers (N : Node_Id);
2199 -- In a single traversal of subtree N collect in Writable_Actuals_List
2200 -- all the actuals of functions with writable actuals, and in the list
2201 -- Identifiers_List collect all the identifiers that are not actuals of
2202 -- functions with writable actuals. If a writable actual is referenced
2203 -- twice as writable actual then Error_Node is set to reference its
2204 -- second occurrence, the error is reported, and the tree traversal
2205 -- is abandoned.
2207 procedure Preanalyze_Without_Errors (N : Node_Id);
2208 -- Preanalyze N without reporting errors. Very dubious, you can't just
2209 -- go analyzing things more than once???
2211 -------------------------
2212 -- Collect_Identifiers --
2213 -------------------------
2215 procedure Collect_Identifiers (N : Node_Id) is
2217 function Check_Node (N : Node_Id) return Traverse_Result;
2218 -- Process a single node during the tree traversal to collect the
2219 -- writable actuals of functions and all the identifiers which are
2220 -- not writable actuals of functions.
2222 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2223 -- Returns True if List has a node whose Entity is Entity (N)
2225 ----------------
2226 -- Check_Node --
2227 ----------------
2229 function Check_Node (N : Node_Id) return Traverse_Result is
2230 Is_Writable_Actual : Boolean := False;
2231 Id : Entity_Id;
2233 begin
2234 if Nkind (N) = N_Identifier then
2236 -- No analysis possible if the entity is not decorated
2238 if No (Entity (N)) then
2239 return Skip;
2241 -- Don't collect identifiers of packages, called functions, etc
2243 elsif Ekind_In (Entity (N), E_Package,
2244 E_Function,
2245 E_Procedure,
2246 E_Entry)
2247 then
2248 return Skip;
2250 -- For rewritten nodes, continue the traversal in the original
2251 -- subtree. Needed to handle aggregates in original expressions
2252 -- extracted from the tree by Remove_Side_Effects.
2254 elsif Is_Rewrite_Substitution (N) then
2255 Collect_Identifiers (Original_Node (N));
2256 return Skip;
2258 -- For now we skip aggregate discriminants, since they require
2259 -- performing the analysis in two phases to identify conflicts:
2260 -- first one analyzing discriminants and second one analyzing
2261 -- the rest of components (since at run time, discriminants are
2262 -- evaluated prior to components): too much computation cost
2263 -- to identify a corner case???
2265 elsif Nkind (Parent (N)) = N_Component_Association
2266 and then Nkind_In (Parent (Parent (N)),
2267 N_Aggregate,
2268 N_Extension_Aggregate)
2269 then
2270 declare
2271 Choice : constant Node_Id := First (Choices (Parent (N)));
2273 begin
2274 if Ekind (Entity (N)) = E_Discriminant then
2275 return Skip;
2277 elsif Expression (Parent (N)) = N
2278 and then Nkind (Choice) = N_Identifier
2279 and then Ekind (Entity (Choice)) = E_Discriminant
2280 then
2281 return Skip;
2282 end if;
2283 end;
2285 -- Analyze if N is a writable actual of a function
2287 elsif Nkind (Parent (N)) = N_Function_Call then
2288 declare
2289 Call : constant Node_Id := Parent (N);
2290 Actual : Node_Id;
2291 Formal : Node_Id;
2293 begin
2294 Id := Get_Called_Entity (Call);
2296 -- In case of previous error, no check is possible
2298 if No (Id) then
2299 return Abandon;
2300 end if;
2302 if Ekind_In (Id, E_Function, E_Generic_Function)
2303 and then Has_Out_Or_In_Out_Parameter (Id)
2304 then
2305 Formal := First_Formal (Id);
2306 Actual := First_Actual (Call);
2307 while Present (Actual) and then Present (Formal) loop
2308 if Actual = N then
2309 if Ekind_In (Formal, E_Out_Parameter,
2310 E_In_Out_Parameter)
2311 then
2312 Is_Writable_Actual := True;
2313 end if;
2315 exit;
2316 end if;
2318 Next_Formal (Formal);
2319 Next_Actual (Actual);
2320 end loop;
2321 end if;
2322 end;
2323 end if;
2325 if Is_Writable_Actual then
2327 -- Skip checking the error in non-elementary types since
2328 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2329 -- store this actual in Writable_Actuals_List since it is
2330 -- needed to perform checks on other constructs that have
2331 -- arbitrary order of evaluation (for example, aggregates).
2333 if not Is_Elementary_Type (Etype (N)) then
2334 if not Contains (Writable_Actuals_List, N) then
2335 Append_New_Elmt (N, To => Writable_Actuals_List);
2336 end if;
2338 -- Second occurrence of an elementary type writable actual
2340 elsif Contains (Writable_Actuals_List, N) then
2342 -- Report the error on the second occurrence of the
2343 -- identifier. We cannot assume that N is the second
2344 -- occurrence (according to their location in the
2345 -- sources), since Traverse_Func walks through Field2
2346 -- last (see comment in the body of Traverse_Func).
2348 declare
2349 Elmt : Elmt_Id;
2351 begin
2352 Elmt := First_Elmt (Writable_Actuals_List);
2353 while Present (Elmt)
2354 and then Entity (Node (Elmt)) /= Entity (N)
2355 loop
2356 Next_Elmt (Elmt);
2357 end loop;
2359 if Sloc (N) > Sloc (Node (Elmt)) then
2360 Error_Node := N;
2361 else
2362 Error_Node := Node (Elmt);
2363 end if;
2365 Error_Msg_NE
2366 ("value may be affected by call to & "
2367 & "because order of evaluation is arbitrary",
2368 Error_Node, Id);
2369 return Abandon;
2370 end;
2372 -- First occurrence of a elementary type writable actual
2374 else
2375 Append_New_Elmt (N, To => Writable_Actuals_List);
2376 end if;
2378 else
2379 if Identifiers_List = No_Elist then
2380 Identifiers_List := New_Elmt_List;
2381 end if;
2383 Append_Unique_Elmt (N, Identifiers_List);
2384 end if;
2385 end if;
2387 return OK;
2388 end Check_Node;
2390 --------------
2391 -- Contains --
2392 --------------
2394 function Contains
2395 (List : Elist_Id;
2396 N : Node_Id) return Boolean
2398 pragma Assert (Nkind (N) in N_Has_Entity);
2400 Elmt : Elmt_Id;
2402 begin
2403 if List = No_Elist then
2404 return False;
2405 end if;
2407 Elmt := First_Elmt (List);
2408 while Present (Elmt) loop
2409 if Entity (Node (Elmt)) = Entity (N) then
2410 return True;
2411 else
2412 Next_Elmt (Elmt);
2413 end if;
2414 end loop;
2416 return False;
2417 end Contains;
2419 ------------------
2420 -- Do_Traversal --
2421 ------------------
2423 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2424 -- The traversal procedure
2426 -- Start of processing for Collect_Identifiers
2428 begin
2429 if Present (Error_Node) then
2430 return;
2431 end if;
2433 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2434 return;
2435 end if;
2437 Do_Traversal (N);
2438 end Collect_Identifiers;
2440 -------------------------------
2441 -- Preanalyze_Without_Errors --
2442 -------------------------------
2444 procedure Preanalyze_Without_Errors (N : Node_Id) is
2445 Status : constant Boolean := Get_Ignore_Errors;
2446 begin
2447 Set_Ignore_Errors (True);
2448 Preanalyze (N);
2449 Set_Ignore_Errors (Status);
2450 end Preanalyze_Without_Errors;
2452 -- Start of processing for Check_Function_Writable_Actuals
2454 begin
2455 -- The check only applies to Ada 2012 code on which Check_Actuals has
2456 -- been set, and only to constructs that have multiple constituents
2457 -- whose order of evaluation is not specified by the language.
2459 if Ada_Version < Ada_2012
2460 or else not Check_Actuals (N)
2461 or else (not (Nkind (N) in N_Op)
2462 and then not (Nkind (N) in N_Membership_Test)
2463 and then not Nkind_In (N, N_Range,
2464 N_Aggregate,
2465 N_Extension_Aggregate,
2466 N_Full_Type_Declaration,
2467 N_Function_Call,
2468 N_Procedure_Call_Statement,
2469 N_Entry_Call_Statement))
2470 or else (Nkind (N) = N_Full_Type_Declaration
2471 and then not Is_Record_Type (Defining_Identifier (N)))
2473 -- In addition, this check only applies to source code, not to code
2474 -- generated by constraint checks.
2476 or else not Comes_From_Source (N)
2477 then
2478 return;
2479 end if;
2481 -- If a construct C has two or more direct constituents that are names
2482 -- or expressions whose evaluation may occur in an arbitrary order, at
2483 -- least one of which contains a function call with an in out or out
2484 -- parameter, then the construct is legal only if: for each name N that
2485 -- is passed as a parameter of mode in out or out to some inner function
2486 -- call C2 (not including the construct C itself), there is no other
2487 -- name anywhere within a direct constituent of the construct C other
2488 -- than the one containing C2, that is known to refer to the same
2489 -- object (RM 6.4.1(6.17/3)).
2491 case Nkind (N) is
2492 when N_Range =>
2493 Collect_Identifiers (Low_Bound (N));
2494 Collect_Identifiers (High_Bound (N));
2496 when N_Membership_Test
2497 | N_Op
2499 declare
2500 Expr : Node_Id;
2502 begin
2503 Collect_Identifiers (Left_Opnd (N));
2505 if Present (Right_Opnd (N)) then
2506 Collect_Identifiers (Right_Opnd (N));
2507 end if;
2509 if Nkind_In (N, N_In, N_Not_In)
2510 and then Present (Alternatives (N))
2511 then
2512 Expr := First (Alternatives (N));
2513 while Present (Expr) loop
2514 Collect_Identifiers (Expr);
2516 Next (Expr);
2517 end loop;
2518 end if;
2519 end;
2521 when N_Full_Type_Declaration =>
2522 declare
2523 function Get_Record_Part (N : Node_Id) return Node_Id;
2524 -- Return the record part of this record type definition
2526 function Get_Record_Part (N : Node_Id) return Node_Id is
2527 Type_Def : constant Node_Id := Type_Definition (N);
2528 begin
2529 if Nkind (Type_Def) = N_Derived_Type_Definition then
2530 return Record_Extension_Part (Type_Def);
2531 else
2532 return Type_Def;
2533 end if;
2534 end Get_Record_Part;
2536 Comp : Node_Id;
2537 Def_Id : Entity_Id := Defining_Identifier (N);
2538 Rec : Node_Id := Get_Record_Part (N);
2540 begin
2541 -- No need to perform any analysis if the record has no
2542 -- components
2544 if No (Rec) or else No (Component_List (Rec)) then
2545 return;
2546 end if;
2548 -- Collect the identifiers starting from the deepest
2549 -- derivation. Done to report the error in the deepest
2550 -- derivation.
2552 loop
2553 if Present (Component_List (Rec)) then
2554 Comp := First (Component_Items (Component_List (Rec)));
2555 while Present (Comp) loop
2556 if Nkind (Comp) = N_Component_Declaration
2557 and then Present (Expression (Comp))
2558 then
2559 Collect_Identifiers (Expression (Comp));
2560 end if;
2562 Next (Comp);
2563 end loop;
2564 end if;
2566 exit when No (Underlying_Type (Etype (Def_Id)))
2567 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2568 = Def_Id;
2570 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2571 Rec := Get_Record_Part (Parent (Def_Id));
2572 end loop;
2573 end;
2575 when N_Entry_Call_Statement
2576 | N_Subprogram_Call
2578 declare
2579 Id : constant Entity_Id := Get_Called_Entity (N);
2580 Formal : Node_Id;
2581 Actual : Node_Id;
2583 begin
2584 Formal := First_Formal (Id);
2585 Actual := First_Actual (N);
2586 while Present (Actual) and then Present (Formal) loop
2587 if Ekind_In (Formal, E_Out_Parameter,
2588 E_In_Out_Parameter)
2589 then
2590 Collect_Identifiers (Actual);
2591 end if;
2593 Next_Formal (Formal);
2594 Next_Actual (Actual);
2595 end loop;
2596 end;
2598 when N_Aggregate
2599 | N_Extension_Aggregate
2601 declare
2602 Assoc : Node_Id;
2603 Choice : Node_Id;
2604 Comp_Expr : Node_Id;
2606 begin
2607 -- Handle the N_Others_Choice of array aggregates with static
2608 -- bounds. There is no need to perform this analysis in
2609 -- aggregates without static bounds since we cannot evaluate
2610 -- if the N_Others_Choice covers several elements. There is
2611 -- no need to handle the N_Others choice of record aggregates
2612 -- since at this stage it has been already expanded by
2613 -- Resolve_Record_Aggregate.
2615 if Is_Array_Type (Etype (N))
2616 and then Nkind (N) = N_Aggregate
2617 and then Present (Aggregate_Bounds (N))
2618 and then Compile_Time_Known_Bounds (Etype (N))
2619 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2621 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2622 then
2623 declare
2624 Count_Components : Uint := Uint_0;
2625 Num_Components : Uint;
2626 Others_Assoc : Node_Id;
2627 Others_Choice : Node_Id := Empty;
2628 Others_Box_Present : Boolean := False;
2630 begin
2631 -- Count positional associations
2633 if Present (Expressions (N)) then
2634 Comp_Expr := First (Expressions (N));
2635 while Present (Comp_Expr) loop
2636 Count_Components := Count_Components + 1;
2637 Next (Comp_Expr);
2638 end loop;
2639 end if;
2641 -- Count the rest of elements and locate the N_Others
2642 -- choice (if any)
2644 Assoc := First (Component_Associations (N));
2645 while Present (Assoc) loop
2646 Choice := First (Choices (Assoc));
2647 while Present (Choice) loop
2648 if Nkind (Choice) = N_Others_Choice then
2649 Others_Assoc := Assoc;
2650 Others_Choice := Choice;
2651 Others_Box_Present := Box_Present (Assoc);
2653 -- Count several components
2655 elsif Nkind_In (Choice, N_Range,
2656 N_Subtype_Indication)
2657 or else (Is_Entity_Name (Choice)
2658 and then Is_Type (Entity (Choice)))
2659 then
2660 declare
2661 L, H : Node_Id;
2662 begin
2663 Get_Index_Bounds (Choice, L, H);
2664 pragma Assert
2665 (Compile_Time_Known_Value (L)
2666 and then Compile_Time_Known_Value (H));
2667 Count_Components :=
2668 Count_Components
2669 + Expr_Value (H) - Expr_Value (L) + 1;
2670 end;
2672 -- Count single component. No other case available
2673 -- since we are handling an aggregate with static
2674 -- bounds.
2676 else
2677 pragma Assert (Is_OK_Static_Expression (Choice)
2678 or else Nkind (Choice) = N_Identifier
2679 or else Nkind (Choice) = N_Integer_Literal);
2681 Count_Components := Count_Components + 1;
2682 end if;
2684 Next (Choice);
2685 end loop;
2687 Next (Assoc);
2688 end loop;
2690 Num_Components :=
2691 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2692 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2694 pragma Assert (Count_Components <= Num_Components);
2696 -- Handle the N_Others choice if it covers several
2697 -- components
2699 if Present (Others_Choice)
2700 and then (Num_Components - Count_Components) > 1
2701 then
2702 if not Others_Box_Present then
2704 -- At this stage, if expansion is active, the
2705 -- expression of the others choice has not been
2706 -- analyzed. Hence we generate a duplicate and
2707 -- we analyze it silently to have available the
2708 -- minimum decoration required to collect the
2709 -- identifiers.
2711 if not Expander_Active then
2712 Comp_Expr := Expression (Others_Assoc);
2713 else
2714 Comp_Expr :=
2715 New_Copy_Tree (Expression (Others_Assoc));
2716 Preanalyze_Without_Errors (Comp_Expr);
2717 end if;
2719 Collect_Identifiers (Comp_Expr);
2721 if Writable_Actuals_List /= No_Elist then
2723 -- As suggested by Robert, at current stage we
2724 -- report occurrences of this case as warnings.
2726 Error_Msg_N
2727 ("writable function parameter may affect "
2728 & "value in other component because order "
2729 & "of evaluation is unspecified??",
2730 Node (First_Elmt (Writable_Actuals_List)));
2731 end if;
2732 end if;
2733 end if;
2734 end;
2736 -- For an array aggregate, a discrete_choice_list that has
2737 -- a nonstatic range is considered as two or more separate
2738 -- occurrences of the expression (RM 6.4.1(20/3)).
2740 elsif Is_Array_Type (Etype (N))
2741 and then Nkind (N) = N_Aggregate
2742 and then Present (Aggregate_Bounds (N))
2743 and then not Compile_Time_Known_Bounds (Etype (N))
2744 then
2745 -- Collect identifiers found in the dynamic bounds
2747 declare
2748 Count_Components : Natural := 0;
2749 Low, High : Node_Id;
2751 begin
2752 Assoc := First (Component_Associations (N));
2753 while Present (Assoc) loop
2754 Choice := First (Choices (Assoc));
2755 while Present (Choice) loop
2756 if Nkind_In (Choice, N_Range,
2757 N_Subtype_Indication)
2758 or else (Is_Entity_Name (Choice)
2759 and then Is_Type (Entity (Choice)))
2760 then
2761 Get_Index_Bounds (Choice, Low, High);
2763 if not Compile_Time_Known_Value (Low) then
2764 Collect_Identifiers (Low);
2766 if No (Aggr_Error_Node) then
2767 Aggr_Error_Node := Low;
2768 end if;
2769 end if;
2771 if not Compile_Time_Known_Value (High) then
2772 Collect_Identifiers (High);
2774 if No (Aggr_Error_Node) then
2775 Aggr_Error_Node := High;
2776 end if;
2777 end if;
2779 -- The RM rule is violated if there is more than
2780 -- a single choice in a component association.
2782 else
2783 Count_Components := Count_Components + 1;
2785 if No (Aggr_Error_Node)
2786 and then Count_Components > 1
2787 then
2788 Aggr_Error_Node := Choice;
2789 end if;
2791 if not Compile_Time_Known_Value (Choice) then
2792 Collect_Identifiers (Choice);
2793 end if;
2794 end if;
2796 Next (Choice);
2797 end loop;
2799 Next (Assoc);
2800 end loop;
2801 end;
2802 end if;
2804 -- Handle ancestor part of extension aggregates
2806 if Nkind (N) = N_Extension_Aggregate then
2807 Collect_Identifiers (Ancestor_Part (N));
2808 end if;
2810 -- Handle positional associations
2812 if Present (Expressions (N)) then
2813 Comp_Expr := First (Expressions (N));
2814 while Present (Comp_Expr) loop
2815 if not Is_OK_Static_Expression (Comp_Expr) then
2816 Collect_Identifiers (Comp_Expr);
2817 end if;
2819 Next (Comp_Expr);
2820 end loop;
2821 end if;
2823 -- Handle discrete associations
2825 if Present (Component_Associations (N)) then
2826 Assoc := First (Component_Associations (N));
2827 while Present (Assoc) loop
2829 if not Box_Present (Assoc) then
2830 Choice := First (Choices (Assoc));
2831 while Present (Choice) loop
2833 -- For now we skip discriminants since it requires
2834 -- performing the analysis in two phases: first one
2835 -- analyzing discriminants and second one analyzing
2836 -- the rest of components since discriminants are
2837 -- evaluated prior to components: too much extra
2838 -- work to detect a corner case???
2840 if Nkind (Choice) in N_Has_Entity
2841 and then Present (Entity (Choice))
2842 and then Ekind (Entity (Choice)) = E_Discriminant
2843 then
2844 null;
2846 elsif Box_Present (Assoc) then
2847 null;
2849 else
2850 if not Analyzed (Expression (Assoc)) then
2851 Comp_Expr :=
2852 New_Copy_Tree (Expression (Assoc));
2853 Set_Parent (Comp_Expr, Parent (N));
2854 Preanalyze_Without_Errors (Comp_Expr);
2855 else
2856 Comp_Expr := Expression (Assoc);
2857 end if;
2859 Collect_Identifiers (Comp_Expr);
2860 end if;
2862 Next (Choice);
2863 end loop;
2864 end if;
2866 Next (Assoc);
2867 end loop;
2868 end if;
2869 end;
2871 when others =>
2872 return;
2873 end case;
2875 -- No further action needed if we already reported an error
2877 if Present (Error_Node) then
2878 return;
2879 end if;
2881 -- Check violation of RM 6.20/3 in aggregates
2883 if Present (Aggr_Error_Node)
2884 and then Writable_Actuals_List /= No_Elist
2885 then
2886 Error_Msg_N
2887 ("value may be affected by call in other component because they "
2888 & "are evaluated in unspecified order",
2889 Node (First_Elmt (Writable_Actuals_List)));
2890 return;
2891 end if;
2893 -- Check if some writable argument of a function is referenced
2895 if Writable_Actuals_List /= No_Elist
2896 and then Identifiers_List /= No_Elist
2897 then
2898 declare
2899 Elmt_1 : Elmt_Id;
2900 Elmt_2 : Elmt_Id;
2902 begin
2903 Elmt_1 := First_Elmt (Writable_Actuals_List);
2904 while Present (Elmt_1) loop
2905 Elmt_2 := First_Elmt (Identifiers_List);
2906 while Present (Elmt_2) loop
2907 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2908 case Nkind (Parent (Node (Elmt_2))) is
2909 when N_Aggregate
2910 | N_Component_Association
2911 | N_Component_Declaration
2913 Error_Msg_N
2914 ("value may be affected by call in other "
2915 & "component because they are evaluated "
2916 & "in unspecified order",
2917 Node (Elmt_2));
2919 when N_In
2920 | N_Not_In
2922 Error_Msg_N
2923 ("value may be affected by call in other "
2924 & "alternative because they are evaluated "
2925 & "in unspecified order",
2926 Node (Elmt_2));
2928 when others =>
2929 Error_Msg_N
2930 ("value of actual may be affected by call in "
2931 & "other actual because they are evaluated "
2932 & "in unspecified order",
2933 Node (Elmt_2));
2934 end case;
2935 end if;
2937 Next_Elmt (Elmt_2);
2938 end loop;
2940 Next_Elmt (Elmt_1);
2941 end loop;
2942 end;
2943 end if;
2944 end Check_Function_Writable_Actuals;
2946 --------------------------------
2947 -- Check_Implicit_Dereference --
2948 --------------------------------
2950 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2951 Disc : Entity_Id;
2952 Desig : Entity_Id;
2953 Nam : Node_Id;
2955 begin
2956 if Nkind (N) = N_Indexed_Component
2957 and then Present (Generalized_Indexing (N))
2958 then
2959 Nam := Generalized_Indexing (N);
2960 else
2961 Nam := N;
2962 end if;
2964 if Ada_Version < Ada_2012
2965 or else not Has_Implicit_Dereference (Base_Type (Typ))
2966 then
2967 return;
2969 elsif not Comes_From_Source (N)
2970 and then Nkind (N) /= N_Indexed_Component
2971 then
2972 return;
2974 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2975 null;
2977 else
2978 Disc := First_Discriminant (Typ);
2979 while Present (Disc) loop
2980 if Has_Implicit_Dereference (Disc) then
2981 Desig := Designated_Type (Etype (Disc));
2982 Add_One_Interp (Nam, Disc, Desig);
2984 -- If the node is a generalized indexing, add interpretation
2985 -- to that node as well, for subsequent resolution.
2987 if Nkind (N) = N_Indexed_Component then
2988 Add_One_Interp (N, Disc, Desig);
2989 end if;
2991 -- If the operation comes from a generic unit and the context
2992 -- is a selected component, the selector name may be global
2993 -- and set in the instance already. Remove the entity to
2994 -- force resolution of the selected component, and the
2995 -- generation of an explicit dereference if needed.
2997 if In_Instance
2998 and then Nkind (Parent (Nam)) = N_Selected_Component
2999 then
3000 Set_Entity (Selector_Name (Parent (Nam)), Empty);
3001 end if;
3003 exit;
3004 end if;
3006 Next_Discriminant (Disc);
3007 end loop;
3008 end if;
3009 end Check_Implicit_Dereference;
3011 ----------------------------------
3012 -- Check_Internal_Protected_Use --
3013 ----------------------------------
3015 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
3016 S : Entity_Id;
3017 Prot : Entity_Id;
3019 begin
3020 Prot := Empty;
3022 S := Current_Scope;
3023 while Present (S) loop
3024 if S = Standard_Standard then
3025 exit;
3027 elsif Ekind (S) = E_Function
3028 and then Ekind (Scope (S)) = E_Protected_Type
3029 then
3030 Prot := Scope (S);
3031 exit;
3032 end if;
3034 S := Scope (S);
3035 end loop;
3037 if Present (Prot)
3038 and then Scope (Nam) = Prot
3039 and then Ekind (Nam) /= E_Function
3040 then
3041 -- An indirect function call (e.g. a callback within a protected
3042 -- function body) is not statically illegal. If the access type is
3043 -- anonymous and is the type of an access parameter, the scope of Nam
3044 -- will be the protected type, but it is not a protected operation.
3046 if Ekind (Nam) = E_Subprogram_Type
3047 and then Nkind (Associated_Node_For_Itype (Nam)) =
3048 N_Function_Specification
3049 then
3050 null;
3052 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
3053 Error_Msg_N
3054 ("within protected function cannot use protected procedure in "
3055 & "renaming or as generic actual", N);
3057 elsif Nkind (N) = N_Attribute_Reference then
3058 Error_Msg_N
3059 ("within protected function cannot take access of protected "
3060 & "procedure", N);
3062 else
3063 Error_Msg_N
3064 ("within protected function, protected object is constant", N);
3065 Error_Msg_N
3066 ("\cannot call operation that may modify it", N);
3067 end if;
3068 end if;
3070 -- Verify that an internal call does not appear within a precondition
3071 -- of a protected operation. This implements AI12-0166.
3072 -- The precondition aspect has been rewritten as a pragma Precondition
3073 -- and we check whether the scope of the called subprogram is the same
3074 -- as that of the entity to which the aspect applies.
3076 if Convention (Nam) = Convention_Protected then
3077 declare
3078 P : Node_Id;
3080 begin
3081 P := Parent (N);
3082 while Present (P) loop
3083 if Nkind (P) = N_Pragma
3084 and then Chars (Pragma_Identifier (P)) = Name_Precondition
3085 and then From_Aspect_Specification (P)
3086 and then
3087 Scope (Entity (Corresponding_Aspect (P))) = Scope (Nam)
3088 then
3089 Error_Msg_N
3090 ("internal call cannot appear in precondition of "
3091 & "protected operation", N);
3092 return;
3094 elsif Nkind (P) = N_Pragma
3095 and then Chars (Pragma_Identifier (P)) = Name_Contract_Cases
3096 then
3097 -- Check whether call is in a case guard. It is legal in a
3098 -- consequence.
3100 P := N;
3101 while Present (P) loop
3102 if Nkind (Parent (P)) = N_Component_Association
3103 and then P /= Expression (Parent (P))
3104 then
3105 Error_Msg_N
3106 ("internal call cannot appear in case guard in a "
3107 & "contract case", N);
3108 end if;
3110 P := Parent (P);
3111 end loop;
3113 return;
3115 elsif Nkind (P) = N_Parameter_Specification
3116 and then Scope (Current_Scope) = Scope (Nam)
3117 and then Nkind_In (Parent (P), N_Entry_Declaration,
3118 N_Subprogram_Declaration)
3119 then
3120 Error_Msg_N
3121 ("internal call cannot appear in default for formal of "
3122 & "protected operation", N);
3123 return;
3124 end if;
3126 P := Parent (P);
3127 end loop;
3128 end;
3129 end if;
3130 end Check_Internal_Protected_Use;
3132 ---------------------------------------
3133 -- Check_Later_Vs_Basic_Declarations --
3134 ---------------------------------------
3136 procedure Check_Later_Vs_Basic_Declarations
3137 (Decls : List_Id;
3138 During_Parsing : Boolean)
3140 Body_Sloc : Source_Ptr;
3141 Decl : Node_Id;
3143 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
3144 -- Return whether Decl is considered as a declarative item.
3145 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3146 -- When During_Parsing is False, the semantics of SPARK is followed.
3148 -------------------------------
3149 -- Is_Later_Declarative_Item --
3150 -------------------------------
3152 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
3153 begin
3154 if Nkind (Decl) in N_Later_Decl_Item then
3155 return True;
3157 elsif Nkind (Decl) = N_Pragma then
3158 return True;
3160 elsif During_Parsing then
3161 return False;
3163 -- In SPARK, a package declaration is not considered as a later
3164 -- declarative item.
3166 elsif Nkind (Decl) = N_Package_Declaration then
3167 return False;
3169 -- In SPARK, a renaming is considered as a later declarative item
3171 elsif Nkind (Decl) in N_Renaming_Declaration then
3172 return True;
3174 else
3175 return False;
3176 end if;
3177 end Is_Later_Declarative_Item;
3179 -- Start of processing for Check_Later_Vs_Basic_Declarations
3181 begin
3182 Decl := First (Decls);
3184 -- Loop through sequence of basic declarative items
3186 Outer : while Present (Decl) loop
3187 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
3188 and then Nkind (Decl) not in N_Body_Stub
3189 then
3190 Next (Decl);
3192 -- Once a body is encountered, we only allow later declarative
3193 -- items. The inner loop checks the rest of the list.
3195 else
3196 Body_Sloc := Sloc (Decl);
3198 Inner : while Present (Decl) loop
3199 if not Is_Later_Declarative_Item (Decl) then
3200 if During_Parsing then
3201 if Ada_Version = Ada_83 then
3202 Error_Msg_Sloc := Body_Sloc;
3203 Error_Msg_N
3204 ("(Ada 83) decl cannot appear after body#", Decl);
3205 end if;
3206 else
3207 Error_Msg_Sloc := Body_Sloc;
3208 Check_SPARK_05_Restriction
3209 ("decl cannot appear after body#", Decl);
3210 end if;
3211 end if;
3213 Next (Decl);
3214 end loop Inner;
3215 end if;
3216 end loop Outer;
3217 end Check_Later_Vs_Basic_Declarations;
3219 ---------------------------
3220 -- Check_No_Hidden_State --
3221 ---------------------------
3223 procedure Check_No_Hidden_State (Id : Entity_Id) is
3224 Context : Entity_Id := Empty;
3225 Not_Visible : Boolean := False;
3226 Scop : Entity_Id;
3228 begin
3229 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3231 -- Nothing to do for internally-generated abstract states and variables
3232 -- because they do not represent the hidden state of the source unit.
3234 if not Comes_From_Source (Id) then
3235 return;
3236 end if;
3238 -- Find the proper context where the object or state appears
3240 Scop := Scope (Id);
3241 while Present (Scop) loop
3242 Context := Scop;
3244 -- Keep track of the context's visibility
3246 Not_Visible := Not_Visible or else In_Private_Part (Context);
3248 -- Prevent the search from going too far
3250 if Context = Standard_Standard then
3251 return;
3253 -- Objects and states that appear immediately within a subprogram or
3254 -- inside a construct nested within a subprogram do not introduce a
3255 -- hidden state. They behave as local variable declarations.
3257 elsif Is_Subprogram (Context) then
3258 return;
3260 -- When examining a package body, use the entity of the spec as it
3261 -- carries the abstract state declarations.
3263 elsif Ekind (Context) = E_Package_Body then
3264 Context := Spec_Entity (Context);
3265 end if;
3267 -- Stop the traversal when a package subject to a null abstract state
3268 -- has been found.
3270 if Ekind_In (Context, E_Generic_Package, E_Package)
3271 and then Has_Null_Abstract_State (Context)
3272 then
3273 exit;
3274 end if;
3276 Scop := Scope (Scop);
3277 end loop;
3279 -- At this point we know that there is at least one package with a null
3280 -- abstract state in visibility. Emit an error message unconditionally
3281 -- if the entity being processed is a state because the placement of the
3282 -- related package is irrelevant. This is not the case for objects as
3283 -- the intermediate context matters.
3285 if Present (Context)
3286 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3287 then
3288 Error_Msg_N ("cannot introduce hidden state &", Id);
3289 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3290 end if;
3291 end Check_No_Hidden_State;
3293 ----------------------------------------
3294 -- Check_Nonvolatile_Function_Profile --
3295 ----------------------------------------
3297 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3298 Formal : Entity_Id;
3300 begin
3301 -- Inspect all formal parameters
3303 Formal := First_Formal (Func_Id);
3304 while Present (Formal) loop
3305 if Is_Effectively_Volatile (Etype (Formal)) then
3306 Error_Msg_NE
3307 ("nonvolatile function & cannot have a volatile parameter",
3308 Formal, Func_Id);
3309 end if;
3311 Next_Formal (Formal);
3312 end loop;
3314 -- Inspect the return type
3316 if Is_Effectively_Volatile (Etype (Func_Id)) then
3317 Error_Msg_NE
3318 ("nonvolatile function & cannot have a volatile return type",
3319 Result_Definition (Parent (Func_Id)), Func_Id);
3320 end if;
3321 end Check_Nonvolatile_Function_Profile;
3323 -----------------------------
3324 -- Check_Part_Of_Reference --
3325 -----------------------------
3327 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3328 function Is_Enclosing_Package_Body
3329 (Body_Decl : Node_Id;
3330 Obj_Id : Entity_Id) return Boolean;
3331 pragma Inline (Is_Enclosing_Package_Body);
3332 -- Determine whether package body Body_Decl or its corresponding spec
3333 -- immediately encloses the declaration of object Obj_Id.
3335 function Is_Internal_Declaration_Or_Body
3336 (Decl : Node_Id) return Boolean;
3337 pragma Inline (Is_Internal_Declaration_Or_Body);
3338 -- Determine whether declaration or body denoted by Decl is internal
3340 function Is_Single_Declaration_Or_Body
3341 (Decl : Node_Id;
3342 Conc_Typ : Entity_Id) return Boolean;
3343 pragma Inline (Is_Single_Declaration_Or_Body);
3344 -- Determine whether protected/task declaration or body denoted by Decl
3345 -- belongs to single concurrent type Conc_Typ.
3347 function Is_Single_Task_Pragma
3348 (Prag : Node_Id;
3349 Task_Typ : Entity_Id) return Boolean;
3350 pragma Inline (Is_Single_Task_Pragma);
3351 -- Determine whether pragma Prag belongs to single task type Task_Typ
3353 -------------------------------
3354 -- Is_Enclosing_Package_Body --
3355 -------------------------------
3357 function Is_Enclosing_Package_Body
3358 (Body_Decl : Node_Id;
3359 Obj_Id : Entity_Id) return Boolean
3361 Obj_Context : Node_Id;
3363 begin
3364 -- Find the context of the object declaration
3366 Obj_Context := Parent (Declaration_Node (Obj_Id));
3368 if Nkind (Obj_Context) = N_Package_Specification then
3369 Obj_Context := Parent (Obj_Context);
3370 end if;
3372 -- The object appears immediately within the package body
3374 if Obj_Context = Body_Decl then
3375 return True;
3377 -- The object appears immediately within the corresponding spec
3379 elsif Nkind (Obj_Context) = N_Package_Declaration
3380 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3381 Obj_Context
3382 then
3383 return True;
3384 end if;
3386 return False;
3387 end Is_Enclosing_Package_Body;
3389 -------------------------------------
3390 -- Is_Internal_Declaration_Or_Body --
3391 -------------------------------------
3393 function Is_Internal_Declaration_Or_Body
3394 (Decl : Node_Id) return Boolean
3396 begin
3397 if Comes_From_Source (Decl) then
3398 return False;
3400 -- A body generated for an expression function which has not been
3401 -- inserted into the tree yet (In_Spec_Expression is True) is not
3402 -- considered internal.
3404 elsif Nkind (Decl) = N_Subprogram_Body
3405 and then Was_Expression_Function (Decl)
3406 and then not In_Spec_Expression
3407 then
3408 return False;
3409 end if;
3411 return True;
3412 end Is_Internal_Declaration_Or_Body;
3414 -----------------------------------
3415 -- Is_Single_Declaration_Or_Body --
3416 -----------------------------------
3418 function Is_Single_Declaration_Or_Body
3419 (Decl : Node_Id;
3420 Conc_Typ : Entity_Id) return Boolean
3422 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3424 begin
3425 return
3426 Present (Anonymous_Object (Spec_Id))
3427 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3428 end Is_Single_Declaration_Or_Body;
3430 ---------------------------
3431 -- Is_Single_Task_Pragma --
3432 ---------------------------
3434 function Is_Single_Task_Pragma
3435 (Prag : Node_Id;
3436 Task_Typ : Entity_Id) return Boolean
3438 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3440 begin
3441 -- To qualify, the pragma must be associated with single task type
3442 -- Task_Typ.
3444 return
3445 Is_Single_Task_Object (Task_Typ)
3446 and then Nkind (Decl) = N_Object_Declaration
3447 and then Defining_Entity (Decl) = Task_Typ;
3448 end Is_Single_Task_Pragma;
3450 -- Local variables
3452 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3453 Par : Node_Id;
3454 Prag_Nam : Name_Id;
3455 Prev : Node_Id;
3457 -- Start of processing for Check_Part_Of_Reference
3459 begin
3460 -- Nothing to do when the variable was recorded, but did not become a
3461 -- constituent of a single concurrent type.
3463 if No (Conc_Obj) then
3464 return;
3465 end if;
3467 -- Traverse the parent chain looking for a suitable context for the
3468 -- reference to the concurrent constituent.
3470 Prev := Ref;
3471 Par := Parent (Prev);
3472 while Present (Par) loop
3473 if Nkind (Par) = N_Pragma then
3474 Prag_Nam := Pragma_Name (Par);
3476 -- A concurrent constituent is allowed to appear in pragmas
3477 -- Initial_Condition and Initializes as this is part of the
3478 -- elaboration checks for the constituent (SPARK RM 9(3)).
3480 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3481 return;
3483 -- When the reference appears within pragma Depends or Global,
3484 -- check whether the pragma applies to a single task type. Note
3485 -- that the pragma may not encapsulated by the type definition,
3486 -- but this is still a valid context.
3488 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3489 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3490 then
3491 return;
3492 end if;
3494 -- The reference appears somewhere in the definition of a single
3495 -- concurrent type (SPARK RM 9(3)).
3497 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3498 N_Single_Task_Declaration)
3499 and then Defining_Entity (Par) = Conc_Obj
3500 then
3501 return;
3503 -- The reference appears within the declaration or body of a single
3504 -- concurrent type (SPARK RM 9(3)).
3506 elsif Nkind_In (Par, N_Protected_Body,
3507 N_Protected_Type_Declaration,
3508 N_Task_Body,
3509 N_Task_Type_Declaration)
3510 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3511 then
3512 return;
3514 -- The reference appears within the statement list of the object's
3515 -- immediately enclosing package (SPARK RM 9(3)).
3517 elsif Nkind (Par) = N_Package_Body
3518 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3519 and then Is_Enclosing_Package_Body (Par, Var_Id)
3520 then
3521 return;
3523 -- The reference has been relocated within an internally generated
3524 -- package or subprogram. Assume that the reference is legal as the
3525 -- real check was already performed in the original context of the
3526 -- reference.
3528 elsif Nkind_In (Par, N_Package_Body,
3529 N_Package_Declaration,
3530 N_Subprogram_Body,
3531 N_Subprogram_Declaration)
3532 and then Is_Internal_Declaration_Or_Body (Par)
3533 then
3534 return;
3536 -- The reference has been relocated to an inlined body for GNATprove.
3537 -- Assume that the reference is legal as the real check was already
3538 -- performed in the original context of the reference.
3540 elsif GNATprove_Mode
3541 and then Nkind (Par) = N_Subprogram_Body
3542 and then Chars (Defining_Entity (Par)) = Name_uParent
3543 then
3544 return;
3545 end if;
3547 Prev := Par;
3548 Par := Parent (Prev);
3549 end loop;
3551 -- At this point it is known that the reference does not appear within a
3552 -- legal context.
3554 Error_Msg_NE
3555 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3556 Error_Msg_Name_1 := Chars (Var_Id);
3558 if Is_Single_Protected_Object (Conc_Obj) then
3559 Error_Msg_NE
3560 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3562 else
3563 Error_Msg_NE
3564 ("\% is constituent of single task type &", Ref, Conc_Obj);
3565 end if;
3566 end Check_Part_Of_Reference;
3568 ------------------------------------------
3569 -- Check_Potentially_Blocking_Operation --
3570 ------------------------------------------
3572 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3573 S : Entity_Id;
3575 begin
3576 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3577 -- When pragma Detect_Blocking is active, the run time will raise
3578 -- Program_Error. Here we only issue a warning, since we generally
3579 -- support the use of potentially blocking operations in the absence
3580 -- of the pragma.
3582 -- Indirect blocking through a subprogram call cannot be diagnosed
3583 -- statically without interprocedural analysis, so we do not attempt
3584 -- to do it here.
3586 S := Scope (Current_Scope);
3587 while Present (S) and then S /= Standard_Standard loop
3588 if Is_Protected_Type (S) then
3589 Error_Msg_N
3590 ("potentially blocking operation in protected operation??", N);
3591 return;
3592 end if;
3594 S := Scope (S);
3595 end loop;
3596 end Check_Potentially_Blocking_Operation;
3598 ------------------------------------
3599 -- Check_Previous_Null_Procedure --
3600 ------------------------------------
3602 procedure Check_Previous_Null_Procedure
3603 (Decl : Node_Id;
3604 Prev : Entity_Id)
3606 begin
3607 if Ekind (Prev) = E_Procedure
3608 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3609 and then Null_Present (Parent (Prev))
3610 then
3611 Error_Msg_Sloc := Sloc (Prev);
3612 Error_Msg_N
3613 ("declaration cannot complete previous null procedure#", Decl);
3614 end if;
3615 end Check_Previous_Null_Procedure;
3617 ---------------------------------
3618 -- Check_Result_And_Post_State --
3619 ---------------------------------
3621 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3622 procedure Check_Result_And_Post_State_In_Pragma
3623 (Prag : Node_Id;
3624 Result_Seen : in out Boolean);
3625 -- Determine whether pragma Prag mentions attribute 'Result and whether
3626 -- the pragma contains an expression that evaluates differently in pre-
3627 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3628 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3630 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3631 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3632 -- formal parameter.
3634 -------------------------------------------
3635 -- Check_Result_And_Post_State_In_Pragma --
3636 -------------------------------------------
3638 procedure Check_Result_And_Post_State_In_Pragma
3639 (Prag : Node_Id;
3640 Result_Seen : in out Boolean)
3642 procedure Check_Conjunct (Expr : Node_Id);
3643 -- Check an individual conjunct in a conjunction of Boolean
3644 -- expressions, connected by "and" or "and then" operators.
3646 procedure Check_Conjuncts (Expr : Node_Id);
3647 -- Apply the post-state check to every conjunct in an expression, in
3648 -- case this is a conjunction of Boolean expressions. Otherwise apply
3649 -- it to the expression as a whole.
3651 procedure Check_Expression (Expr : Node_Id);
3652 -- Perform the 'Result and post-state checks on a given expression
3654 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3655 -- Attempt to find attribute 'Result in a subtree denoted by N
3657 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3658 -- Determine whether source node N denotes "True" or "False"
3660 function Mentions_Post_State (N : Node_Id) return Boolean;
3661 -- Determine whether a subtree denoted by N mentions any construct
3662 -- that denotes a post-state.
3664 procedure Check_Function_Result is
3665 new Traverse_Proc (Is_Function_Result);
3667 --------------------
3668 -- Check_Conjunct --
3669 --------------------
3671 procedure Check_Conjunct (Expr : Node_Id) is
3672 function Adjust_Message (Msg : String) return String;
3673 -- Prepend a prefix to the input message Msg denoting that the
3674 -- message applies to a conjunct in the expression, when this
3675 -- is the case.
3677 function Applied_On_Conjunct return Boolean;
3678 -- Returns True if the message applies to a conjunct in the
3679 -- expression, instead of the whole expression.
3681 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3682 -- Returns True if Subp has an output in its Global contract
3684 function Has_No_Output (Subp : Entity_Id) return Boolean;
3685 -- Returns True if Subp has no declared output: no function
3686 -- result, no output parameter, and no output in its Global
3687 -- contract.
3689 --------------------
3690 -- Adjust_Message --
3691 --------------------
3693 function Adjust_Message (Msg : String) return String is
3694 begin
3695 if Applied_On_Conjunct then
3696 return "conjunct in " & Msg;
3697 else
3698 return Msg;
3699 end if;
3700 end Adjust_Message;
3702 -------------------------
3703 -- Applied_On_Conjunct --
3704 -------------------------
3706 function Applied_On_Conjunct return Boolean is
3707 begin
3708 -- Expr is the conjunct of an enclosing "and" expression
3710 return Nkind (Parent (Expr)) in N_Subexpr
3712 -- or Expr is a conjunct of an enclosing "and then"
3713 -- expression in a postcondition aspect that was split into
3714 -- multiple pragmas. The first conjunct has the "and then"
3715 -- expression as Original_Node, and other conjuncts have
3716 -- Split_PCC set to True.
3718 or else Nkind (Original_Node (Expr)) = N_And_Then
3719 or else Split_PPC (Prag);
3720 end Applied_On_Conjunct;
3722 -----------------------
3723 -- Has_Global_Output --
3724 -----------------------
3726 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3727 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3728 List : Node_Id;
3729 Assoc : Node_Id;
3731 begin
3732 if No (Global) then
3733 return False;
3734 end if;
3736 List := Expression (Get_Argument (Global, Subp));
3738 -- Empty list (no global items) or single global item
3739 -- declaration (only input items).
3741 if Nkind_In (List, N_Null,
3742 N_Expanded_Name,
3743 N_Identifier,
3744 N_Selected_Component)
3745 then
3746 return False;
3748 -- Simple global list (only input items) or moded global list
3749 -- declaration.
3751 elsif Nkind (List) = N_Aggregate then
3752 if Present (Expressions (List)) then
3753 return False;
3755 else
3756 Assoc := First (Component_Associations (List));
3757 while Present (Assoc) loop
3758 if Chars (First (Choices (Assoc))) /= Name_Input then
3759 return True;
3760 end if;
3762 Next (Assoc);
3763 end loop;
3765 return False;
3766 end if;
3768 -- To accommodate partial decoration of disabled SPARK
3769 -- features, this routine may be called with illegal input.
3770 -- If this is the case, do not raise Program_Error.
3772 else
3773 return False;
3774 end if;
3775 end Has_Global_Output;
3777 -------------------
3778 -- Has_No_Output --
3779 -------------------
3781 function Has_No_Output (Subp : Entity_Id) return Boolean is
3782 Param : Node_Id;
3784 begin
3785 -- A function has its result as output
3787 if Ekind (Subp) = E_Function then
3788 return False;
3789 end if;
3791 -- An OUT or IN OUT parameter is an output
3793 Param := First_Formal (Subp);
3794 while Present (Param) loop
3795 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3796 return False;
3797 end if;
3799 Next_Formal (Param);
3800 end loop;
3802 -- An item of mode Output or In_Out in the Global contract is
3803 -- an output.
3805 if Has_Global_Output (Subp) then
3806 return False;
3807 end if;
3809 return True;
3810 end Has_No_Output;
3812 -- Local variables
3814 Err_Node : Node_Id;
3815 -- Error node when reporting a warning on a (refined)
3816 -- postcondition.
3818 -- Start of processing for Check_Conjunct
3820 begin
3821 if Applied_On_Conjunct then
3822 Err_Node := Expr;
3823 else
3824 Err_Node := Prag;
3825 end if;
3827 -- Do not report missing reference to outcome in postcondition if
3828 -- either the postcondition is trivially True or False, or if the
3829 -- subprogram is ghost and has no declared output.
3831 if not Is_Trivial_Boolean (Expr)
3832 and then not Mentions_Post_State (Expr)
3833 and then not (Is_Ghost_Entity (Subp_Id)
3834 and then Has_No_Output (Subp_Id))
3835 then
3836 if Pragma_Name (Prag) = Name_Contract_Cases then
3837 Error_Msg_NE (Adjust_Message
3838 ("contract case does not check the outcome of calling "
3839 & "&?T?"), Expr, Subp_Id);
3841 elsif Pragma_Name (Prag) = Name_Refined_Post then
3842 Error_Msg_NE (Adjust_Message
3843 ("refined postcondition does not check the outcome of "
3844 & "calling &?T?"), Err_Node, Subp_Id);
3846 else
3847 Error_Msg_NE (Adjust_Message
3848 ("postcondition does not check the outcome of calling "
3849 & "&?T?"), Err_Node, Subp_Id);
3850 end if;
3851 end if;
3852 end Check_Conjunct;
3854 ---------------------
3855 -- Check_Conjuncts --
3856 ---------------------
3858 procedure Check_Conjuncts (Expr : Node_Id) is
3859 begin
3860 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3861 Check_Conjuncts (Left_Opnd (Expr));
3862 Check_Conjuncts (Right_Opnd (Expr));
3863 else
3864 Check_Conjunct (Expr);
3865 end if;
3866 end Check_Conjuncts;
3868 ----------------------
3869 -- Check_Expression --
3870 ----------------------
3872 procedure Check_Expression (Expr : Node_Id) is
3873 begin
3874 if not Is_Trivial_Boolean (Expr) then
3875 Check_Function_Result (Expr);
3876 Check_Conjuncts (Expr);
3877 end if;
3878 end Check_Expression;
3880 ------------------------
3881 -- Is_Function_Result --
3882 ------------------------
3884 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3885 begin
3886 if Is_Attribute_Result (N) then
3887 Result_Seen := True;
3888 return Abandon;
3890 -- Warn on infinite recursion if call is to current function
3892 elsif Nkind (N) = N_Function_Call
3893 and then Is_Entity_Name (Name (N))
3894 and then Entity (Name (N)) = Subp_Id
3895 and then not Is_Potentially_Unevaluated (N)
3896 then
3897 Error_Msg_NE
3898 ("call to & within its postcondition will lead to infinite "
3899 & "recursion?", N, Subp_Id);
3900 return OK;
3902 -- Continue the traversal
3904 else
3905 return OK;
3906 end if;
3907 end Is_Function_Result;
3909 ------------------------
3910 -- Is_Trivial_Boolean --
3911 ------------------------
3913 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3914 begin
3915 return
3916 Comes_From_Source (N)
3917 and then Is_Entity_Name (N)
3918 and then (Entity (N) = Standard_True
3919 or else
3920 Entity (N) = Standard_False);
3921 end Is_Trivial_Boolean;
3923 -------------------------
3924 -- Mentions_Post_State --
3925 -------------------------
3927 function Mentions_Post_State (N : Node_Id) return Boolean is
3928 Post_State_Seen : Boolean := False;
3930 function Is_Post_State (N : Node_Id) return Traverse_Result;
3931 -- Attempt to find a construct that denotes a post-state. If this
3932 -- is the case, set flag Post_State_Seen.
3934 -------------------
3935 -- Is_Post_State --
3936 -------------------
3938 function Is_Post_State (N : Node_Id) return Traverse_Result is
3939 Ent : Entity_Id;
3941 begin
3942 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3943 Post_State_Seen := True;
3944 return Abandon;
3946 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3947 Ent := Entity (N);
3949 -- Treat an undecorated reference as OK
3951 if No (Ent)
3953 -- A reference to an assignable entity is considered a
3954 -- change in the post-state of a subprogram.
3956 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3957 E_In_Out_Parameter,
3958 E_Out_Parameter,
3959 E_Variable)
3961 -- The reference may be modified through a dereference
3963 or else (Is_Access_Type (Etype (Ent))
3964 and then Nkind (Parent (N)) =
3965 N_Selected_Component)
3966 then
3967 Post_State_Seen := True;
3968 return Abandon;
3969 end if;
3971 elsif Nkind (N) = N_Attribute_Reference then
3972 if Attribute_Name (N) = Name_Old then
3973 return Skip;
3975 elsif Attribute_Name (N) = Name_Result then
3976 Post_State_Seen := True;
3977 return Abandon;
3978 end if;
3979 end if;
3981 return OK;
3982 end Is_Post_State;
3984 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3986 -- Start of processing for Mentions_Post_State
3988 begin
3989 Find_Post_State (N);
3991 return Post_State_Seen;
3992 end Mentions_Post_State;
3994 -- Local variables
3996 Expr : constant Node_Id :=
3997 Get_Pragma_Arg
3998 (First (Pragma_Argument_Associations (Prag)));
3999 Nam : constant Name_Id := Pragma_Name (Prag);
4000 CCase : Node_Id;
4002 -- Start of processing for Check_Result_And_Post_State_In_Pragma
4004 begin
4005 -- Examine all consequences
4007 if Nam = Name_Contract_Cases then
4008 CCase := First (Component_Associations (Expr));
4009 while Present (CCase) loop
4010 Check_Expression (Expression (CCase));
4012 Next (CCase);
4013 end loop;
4015 -- Examine the expression of a postcondition
4017 else pragma Assert (Nam_In (Nam, Name_Postcondition,
4018 Name_Refined_Post));
4019 Check_Expression (Expr);
4020 end if;
4021 end Check_Result_And_Post_State_In_Pragma;
4023 --------------------------
4024 -- Has_In_Out_Parameter --
4025 --------------------------
4027 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
4028 Formal : Entity_Id;
4030 begin
4031 -- Traverse the formals looking for an IN OUT parameter
4033 Formal := First_Formal (Subp_Id);
4034 while Present (Formal) loop
4035 if Ekind (Formal) = E_In_Out_Parameter then
4036 return True;
4037 end if;
4039 Next_Formal (Formal);
4040 end loop;
4042 return False;
4043 end Has_In_Out_Parameter;
4045 -- Local variables
4047 Items : constant Node_Id := Contract (Subp_Id);
4048 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4049 Case_Prag : Node_Id := Empty;
4050 Post_Prag : Node_Id := Empty;
4051 Prag : Node_Id;
4052 Seen_In_Case : Boolean := False;
4053 Seen_In_Post : Boolean := False;
4054 Spec_Id : Entity_Id;
4056 -- Start of processing for Check_Result_And_Post_State
4058 begin
4059 -- The lack of attribute 'Result or a post-state is classified as a
4060 -- suspicious contract. Do not perform the check if the corresponding
4061 -- swich is not set.
4063 if not Warn_On_Suspicious_Contract then
4064 return;
4066 -- Nothing to do if there is no contract
4068 elsif No (Items) then
4069 return;
4070 end if;
4072 -- Retrieve the entity of the subprogram spec (if any)
4074 if Nkind (Subp_Decl) = N_Subprogram_Body
4075 and then Present (Corresponding_Spec (Subp_Decl))
4076 then
4077 Spec_Id := Corresponding_Spec (Subp_Decl);
4079 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4080 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4081 then
4082 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4084 else
4085 Spec_Id := Subp_Id;
4086 end if;
4088 -- Examine all postconditions for attribute 'Result and a post-state
4090 Prag := Pre_Post_Conditions (Items);
4091 while Present (Prag) loop
4092 if Nam_In (Pragma_Name_Unmapped (Prag),
4093 Name_Postcondition, Name_Refined_Post)
4094 and then not Error_Posted (Prag)
4095 then
4096 Post_Prag := Prag;
4097 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4098 end if;
4100 Prag := Next_Pragma (Prag);
4101 end loop;
4103 -- Examine the contract cases of the subprogram for attribute 'Result
4104 -- and a post-state.
4106 Prag := Contract_Test_Cases (Items);
4107 while Present (Prag) loop
4108 if Pragma_Name (Prag) = Name_Contract_Cases
4109 and then not Error_Posted (Prag)
4110 then
4111 Case_Prag := Prag;
4112 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4113 end if;
4115 Prag := Next_Pragma (Prag);
4116 end loop;
4118 -- Do not emit any errors if the subprogram is not a function
4120 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4121 null;
4123 -- Regardless of whether the function has postconditions or contract
4124 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4125 -- parameter is always treated as a result.
4127 elsif Has_In_Out_Parameter (Spec_Id) then
4128 null;
4130 -- The function has both a postcondition and contract cases and they do
4131 -- not mention attribute 'Result.
4133 elsif Present (Case_Prag)
4134 and then not Seen_In_Case
4135 and then Present (Post_Prag)
4136 and then not Seen_In_Post
4137 then
4138 Error_Msg_N
4139 ("neither postcondition nor contract cases mention function "
4140 & "result?T?", Post_Prag);
4142 -- The function has contract cases only and they do not mention
4143 -- attribute 'Result.
4145 elsif Present (Case_Prag) and then not Seen_In_Case then
4146 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4148 -- The function has postconditions only and they do not mention
4149 -- attribute 'Result.
4151 elsif Present (Post_Prag) and then not Seen_In_Post then
4152 Error_Msg_N
4153 ("postcondition does not mention function result?T?", Post_Prag);
4154 end if;
4155 end Check_Result_And_Post_State;
4157 -----------------------------
4158 -- Check_State_Refinements --
4159 -----------------------------
4161 procedure Check_State_Refinements
4162 (Context : Node_Id;
4163 Is_Main_Unit : Boolean := False)
4165 procedure Check_Package (Pack : Node_Id);
4166 -- Verify that all abstract states of a [generic] package denoted by its
4167 -- declarative node Pack have proper refinement. Recursively verify the
4168 -- visible and private declarations of the [generic] package for other
4169 -- nested packages.
4171 procedure Check_Packages_In (Decls : List_Id);
4172 -- Seek out [generic] package declarations within declarative list Decls
4173 -- and verify the status of their abstract state refinement.
4175 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4176 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4178 -------------------
4179 -- Check_Package --
4180 -------------------
4182 procedure Check_Package (Pack : Node_Id) is
4183 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4184 Spec : constant Node_Id := Specification (Pack);
4185 States : constant Elist_Id :=
4186 Abstract_States (Defining_Entity (Pack));
4188 State_Elmt : Elmt_Id;
4189 State_Id : Entity_Id;
4191 begin
4192 -- Do not verify proper state refinement when the package is subject
4193 -- to pragma SPARK_Mode Off because this disables the requirement for
4194 -- state refinement.
4196 if SPARK_Mode_Is_Off (Pack) then
4197 null;
4199 -- State refinement can only occur in a completing package body. Do
4200 -- not verify proper state refinement when the body is subject to
4201 -- pragma SPARK_Mode Off because this disables the requirement for
4202 -- state refinement.
4204 elsif Present (Body_Id)
4205 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4206 then
4207 null;
4209 -- Do not verify proper state refinement when the package is an
4210 -- instance as this check was already performed in the generic.
4212 elsif Present (Generic_Parent (Spec)) then
4213 null;
4215 -- Otherwise examine the contents of the package
4217 else
4218 if Present (States) then
4219 State_Elmt := First_Elmt (States);
4220 while Present (State_Elmt) loop
4221 State_Id := Node (State_Elmt);
4223 -- Emit an error when a non-null state lacks any form of
4224 -- refinement.
4226 if not Is_Null_State (State_Id)
4227 and then not Has_Null_Refinement (State_Id)
4228 and then not Has_Non_Null_Refinement (State_Id)
4229 then
4230 Error_Msg_N ("state & requires refinement", State_Id);
4231 end if;
4233 Next_Elmt (State_Elmt);
4234 end loop;
4235 end if;
4237 Check_Packages_In (Visible_Declarations (Spec));
4238 Check_Packages_In (Private_Declarations (Spec));
4239 end if;
4240 end Check_Package;
4242 -----------------------
4243 -- Check_Packages_In --
4244 -----------------------
4246 procedure Check_Packages_In (Decls : List_Id) is
4247 Decl : Node_Id;
4249 begin
4250 if Present (Decls) then
4251 Decl := First (Decls);
4252 while Present (Decl) loop
4253 if Nkind_In (Decl, N_Generic_Package_Declaration,
4254 N_Package_Declaration)
4255 then
4256 Check_Package (Decl);
4257 end if;
4259 Next (Decl);
4260 end loop;
4261 end if;
4262 end Check_Packages_In;
4264 -----------------------
4265 -- SPARK_Mode_Is_Off --
4266 -----------------------
4268 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4269 Id : constant Entity_Id := Defining_Entity (N);
4270 Prag : constant Node_Id := SPARK_Pragma (Id);
4272 begin
4273 -- Default the mode to "off" when the context is an instance and all
4274 -- SPARK_Mode pragmas found within are to be ignored.
4276 if Ignore_SPARK_Mode_Pragmas (Id) then
4277 return True;
4279 else
4280 return
4281 Present (Prag)
4282 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4283 end if;
4284 end SPARK_Mode_Is_Off;
4286 -- Start of processing for Check_State_Refinements
4288 begin
4289 -- A block may declare a nested package
4291 if Nkind (Context) = N_Block_Statement then
4292 Check_Packages_In (Declarations (Context));
4294 -- An entry, protected, subprogram, or task body may declare a nested
4295 -- package.
4297 elsif Nkind_In (Context, N_Entry_Body,
4298 N_Protected_Body,
4299 N_Subprogram_Body,
4300 N_Task_Body)
4301 then
4302 -- Do not verify proper state refinement when the body is subject to
4303 -- pragma SPARK_Mode Off because this disables the requirement for
4304 -- state refinement.
4306 if not SPARK_Mode_Is_Off (Context) then
4307 Check_Packages_In (Declarations (Context));
4308 end if;
4310 -- A package body may declare a nested package
4312 elsif Nkind (Context) = N_Package_Body then
4313 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4315 -- Do not verify proper state refinement when the body is subject to
4316 -- pragma SPARK_Mode Off because this disables the requirement for
4317 -- state refinement.
4319 if not SPARK_Mode_Is_Off (Context) then
4320 Check_Packages_In (Declarations (Context));
4321 end if;
4323 -- A library level [generic] package may declare a nested package
4325 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4326 N_Package_Declaration)
4327 and then Is_Main_Unit
4328 then
4329 Check_Package (Context);
4330 end if;
4331 end Check_State_Refinements;
4333 ------------------------------
4334 -- Check_Unprotected_Access --
4335 ------------------------------
4337 procedure Check_Unprotected_Access
4338 (Context : Node_Id;
4339 Expr : Node_Id)
4341 Cont_Encl_Typ : Entity_Id;
4342 Pref_Encl_Typ : Entity_Id;
4344 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4345 -- Check whether Obj is a private component of a protected object.
4346 -- Return the protected type where the component resides, Empty
4347 -- otherwise.
4349 function Is_Public_Operation return Boolean;
4350 -- Verify that the enclosing operation is callable from outside the
4351 -- protected object, to minimize false positives.
4353 ------------------------------
4354 -- Enclosing_Protected_Type --
4355 ------------------------------
4357 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4358 begin
4359 if Is_Entity_Name (Obj) then
4360 declare
4361 Ent : Entity_Id := Entity (Obj);
4363 begin
4364 -- The object can be a renaming of a private component, use
4365 -- the original record component.
4367 if Is_Prival (Ent) then
4368 Ent := Prival_Link (Ent);
4369 end if;
4371 if Is_Protected_Type (Scope (Ent)) then
4372 return Scope (Ent);
4373 end if;
4374 end;
4375 end if;
4377 -- For indexed and selected components, recursively check the prefix
4379 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4380 return Enclosing_Protected_Type (Prefix (Obj));
4382 -- The object does not denote a protected component
4384 else
4385 return Empty;
4386 end if;
4387 end Enclosing_Protected_Type;
4389 -------------------------
4390 -- Is_Public_Operation --
4391 -------------------------
4393 function Is_Public_Operation return Boolean is
4394 S : Entity_Id;
4395 E : Entity_Id;
4397 begin
4398 S := Current_Scope;
4399 while Present (S) and then S /= Pref_Encl_Typ loop
4400 if Scope (S) = Pref_Encl_Typ then
4401 E := First_Entity (Pref_Encl_Typ);
4402 while Present (E)
4403 and then E /= First_Private_Entity (Pref_Encl_Typ)
4404 loop
4405 if E = S then
4406 return True;
4407 end if;
4409 Next_Entity (E);
4410 end loop;
4411 end if;
4413 S := Scope (S);
4414 end loop;
4416 return False;
4417 end Is_Public_Operation;
4419 -- Start of processing for Check_Unprotected_Access
4421 begin
4422 if Nkind (Expr) = N_Attribute_Reference
4423 and then Attribute_Name (Expr) = Name_Unchecked_Access
4424 then
4425 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4426 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4428 -- Check whether we are trying to export a protected component to a
4429 -- context with an equal or lower access level.
4431 if Present (Pref_Encl_Typ)
4432 and then No (Cont_Encl_Typ)
4433 and then Is_Public_Operation
4434 and then Scope_Depth (Pref_Encl_Typ) >=
4435 Object_Access_Level (Context)
4436 then
4437 Error_Msg_N
4438 ("??possible unprotected access to protected data", Expr);
4439 end if;
4440 end if;
4441 end Check_Unprotected_Access;
4443 ------------------------------
4444 -- Check_Unused_Body_States --
4445 ------------------------------
4447 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4448 procedure Process_Refinement_Clause
4449 (Clause : Node_Id;
4450 States : Elist_Id);
4451 -- Inspect all constituents of refinement clause Clause and remove any
4452 -- matches from body state list States.
4454 procedure Report_Unused_Body_States (States : Elist_Id);
4455 -- Emit errors for each abstract state or object found in list States
4457 -------------------------------
4458 -- Process_Refinement_Clause --
4459 -------------------------------
4461 procedure Process_Refinement_Clause
4462 (Clause : Node_Id;
4463 States : Elist_Id)
4465 procedure Process_Constituent (Constit : Node_Id);
4466 -- Remove constituent Constit from body state list States
4468 -------------------------
4469 -- Process_Constituent --
4470 -------------------------
4472 procedure Process_Constituent (Constit : Node_Id) is
4473 Constit_Id : Entity_Id;
4475 begin
4476 -- Guard against illegal constituents. Only abstract states and
4477 -- objects can appear on the right hand side of a refinement.
4479 if Is_Entity_Name (Constit) then
4480 Constit_Id := Entity_Of (Constit);
4482 if Present (Constit_Id)
4483 and then Ekind_In (Constit_Id, E_Abstract_State,
4484 E_Constant,
4485 E_Variable)
4486 then
4487 Remove (States, Constit_Id);
4488 end if;
4489 end if;
4490 end Process_Constituent;
4492 -- Local variables
4494 Constit : Node_Id;
4496 -- Start of processing for Process_Refinement_Clause
4498 begin
4499 if Nkind (Clause) = N_Component_Association then
4500 Constit := Expression (Clause);
4502 -- Multiple constituents appear as an aggregate
4504 if Nkind (Constit) = N_Aggregate then
4505 Constit := First (Expressions (Constit));
4506 while Present (Constit) loop
4507 Process_Constituent (Constit);
4508 Next (Constit);
4509 end loop;
4511 -- Various forms of a single constituent
4513 else
4514 Process_Constituent (Constit);
4515 end if;
4516 end if;
4517 end Process_Refinement_Clause;
4519 -------------------------------
4520 -- Report_Unused_Body_States --
4521 -------------------------------
4523 procedure Report_Unused_Body_States (States : Elist_Id) is
4524 Posted : Boolean := False;
4525 State_Elmt : Elmt_Id;
4526 State_Id : Entity_Id;
4528 begin
4529 if Present (States) then
4530 State_Elmt := First_Elmt (States);
4531 while Present (State_Elmt) loop
4532 State_Id := Node (State_Elmt);
4534 -- Constants are part of the hidden state of a package, but the
4535 -- compiler cannot determine whether they have variable input
4536 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4537 -- hidden state. Do not emit an error when a constant does not
4538 -- participate in a state refinement, even though it acts as a
4539 -- hidden state.
4541 if Ekind (State_Id) = E_Constant then
4542 null;
4544 -- Generate an error message of the form:
4546 -- body of package ... has unused hidden states
4547 -- abstract state ... defined at ...
4548 -- variable ... defined at ...
4550 else
4551 if not Posted then
4552 Posted := True;
4553 SPARK_Msg_N
4554 ("body of package & has unused hidden states", Body_Id);
4555 end if;
4557 Error_Msg_Sloc := Sloc (State_Id);
4559 if Ekind (State_Id) = E_Abstract_State then
4560 SPARK_Msg_NE
4561 ("\abstract state & defined #", Body_Id, State_Id);
4563 else
4564 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4565 end if;
4566 end if;
4568 Next_Elmt (State_Elmt);
4569 end loop;
4570 end if;
4571 end Report_Unused_Body_States;
4573 -- Local variables
4575 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4576 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4577 Clause : Node_Id;
4578 States : Elist_Id;
4580 -- Start of processing for Check_Unused_Body_States
4582 begin
4583 -- Inspect the clauses of pragma Refined_State and determine whether all
4584 -- visible states declared within the package body participate in the
4585 -- refinement.
4587 if Present (Prag) then
4588 Clause := Expression (Get_Argument (Prag, Spec_Id));
4589 States := Collect_Body_States (Body_Id);
4591 -- Multiple non-null state refinements appear as an aggregate
4593 if Nkind (Clause) = N_Aggregate then
4594 Clause := First (Component_Associations (Clause));
4595 while Present (Clause) loop
4596 Process_Refinement_Clause (Clause, States);
4597 Next (Clause);
4598 end loop;
4600 -- Various forms of a single state refinement
4602 else
4603 Process_Refinement_Clause (Clause, States);
4604 end if;
4606 -- Ensure that all abstract states and objects declared in the
4607 -- package body state space are utilized as constituents.
4609 Report_Unused_Body_States (States);
4610 end if;
4611 end Check_Unused_Body_States;
4613 -----------------
4614 -- Choice_List --
4615 -----------------
4617 function Choice_List (N : Node_Id) return List_Id is
4618 begin
4619 if Nkind (N) = N_Iterated_Component_Association then
4620 return Discrete_Choices (N);
4621 else
4622 return Choices (N);
4623 end if;
4624 end Choice_List;
4626 -------------------------
4627 -- Collect_Body_States --
4628 -------------------------
4630 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4631 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4632 -- Determine whether object Obj_Id is a suitable visible state of a
4633 -- package body.
4635 procedure Collect_Visible_States
4636 (Pack_Id : Entity_Id;
4637 States : in out Elist_Id);
4638 -- Gather the entities of all abstract states and objects declared in
4639 -- the visible state space of package Pack_Id.
4641 ----------------------------
4642 -- Collect_Visible_States --
4643 ----------------------------
4645 procedure Collect_Visible_States
4646 (Pack_Id : Entity_Id;
4647 States : in out Elist_Id)
4649 Item_Id : Entity_Id;
4651 begin
4652 -- Traverse the entity chain of the package and inspect all visible
4653 -- items.
4655 Item_Id := First_Entity (Pack_Id);
4656 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4658 -- Do not consider internally generated items as those cannot be
4659 -- named and participate in refinement.
4661 if not Comes_From_Source (Item_Id) then
4662 null;
4664 elsif Ekind (Item_Id) = E_Abstract_State then
4665 Append_New_Elmt (Item_Id, States);
4667 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4668 and then Is_Visible_Object (Item_Id)
4669 then
4670 Append_New_Elmt (Item_Id, States);
4672 -- Recursively gather the visible states of a nested package
4674 elsif Ekind (Item_Id) = E_Package then
4675 Collect_Visible_States (Item_Id, States);
4676 end if;
4678 Next_Entity (Item_Id);
4679 end loop;
4680 end Collect_Visible_States;
4682 -----------------------
4683 -- Is_Visible_Object --
4684 -----------------------
4686 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4687 begin
4688 -- Objects that map generic formals to their actuals are not visible
4689 -- from outside the generic instantiation.
4691 if Present (Corresponding_Generic_Association
4692 (Declaration_Node (Obj_Id)))
4693 then
4694 return False;
4696 -- Constituents of a single protected/task type act as components of
4697 -- the type and are not visible from outside the type.
4699 elsif Ekind (Obj_Id) = E_Variable
4700 and then Present (Encapsulating_State (Obj_Id))
4701 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4702 then
4703 return False;
4705 else
4706 return True;
4707 end if;
4708 end Is_Visible_Object;
4710 -- Local variables
4712 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4713 Decl : Node_Id;
4714 Item_Id : Entity_Id;
4715 States : Elist_Id := No_Elist;
4717 -- Start of processing for Collect_Body_States
4719 begin
4720 -- Inspect the declarations of the body looking for source objects,
4721 -- packages and package instantiations. Note that even though this
4722 -- processing is very similar to Collect_Visible_States, a package
4723 -- body does not have a First/Next_Entity list.
4725 Decl := First (Declarations (Body_Decl));
4726 while Present (Decl) loop
4728 -- Capture source objects as internally generated temporaries cannot
4729 -- be named and participate in refinement.
4731 if Nkind (Decl) = N_Object_Declaration then
4732 Item_Id := Defining_Entity (Decl);
4734 if Comes_From_Source (Item_Id)
4735 and then Is_Visible_Object (Item_Id)
4736 then
4737 Append_New_Elmt (Item_Id, States);
4738 end if;
4740 -- Capture the visible abstract states and objects of a source
4741 -- package [instantiation].
4743 elsif Nkind (Decl) = N_Package_Declaration then
4744 Item_Id := Defining_Entity (Decl);
4746 if Comes_From_Source (Item_Id) then
4747 Collect_Visible_States (Item_Id, States);
4748 end if;
4749 end if;
4751 Next (Decl);
4752 end loop;
4754 return States;
4755 end Collect_Body_States;
4757 ------------------------
4758 -- Collect_Interfaces --
4759 ------------------------
4761 procedure Collect_Interfaces
4762 (T : Entity_Id;
4763 Ifaces_List : out Elist_Id;
4764 Exclude_Parents : Boolean := False;
4765 Use_Full_View : Boolean := True)
4767 procedure Collect (Typ : Entity_Id);
4768 -- Subsidiary subprogram used to traverse the whole list
4769 -- of directly and indirectly implemented interfaces
4771 -------------
4772 -- Collect --
4773 -------------
4775 procedure Collect (Typ : Entity_Id) is
4776 Ancestor : Entity_Id;
4777 Full_T : Entity_Id;
4778 Id : Node_Id;
4779 Iface : Entity_Id;
4781 begin
4782 Full_T := Typ;
4784 -- Handle private types and subtypes
4786 if Use_Full_View
4787 and then Is_Private_Type (Typ)
4788 and then Present (Full_View (Typ))
4789 then
4790 Full_T := Full_View (Typ);
4792 if Ekind (Full_T) = E_Record_Subtype then
4793 Full_T := Etype (Typ);
4795 if Present (Full_View (Full_T)) then
4796 Full_T := Full_View (Full_T);
4797 end if;
4798 end if;
4799 end if;
4801 -- Include the ancestor if we are generating the whole list of
4802 -- abstract interfaces.
4804 if Etype (Full_T) /= Typ
4806 -- Protect the frontend against wrong sources. For example:
4808 -- package P is
4809 -- type A is tagged null record;
4810 -- type B is new A with private;
4811 -- type C is new A with private;
4812 -- private
4813 -- type B is new C with null record;
4814 -- type C is new B with null record;
4815 -- end P;
4817 and then Etype (Full_T) /= T
4818 then
4819 Ancestor := Etype (Full_T);
4820 Collect (Ancestor);
4822 if Is_Interface (Ancestor) and then not Exclude_Parents then
4823 Append_Unique_Elmt (Ancestor, Ifaces_List);
4824 end if;
4825 end if;
4827 -- Traverse the graph of ancestor interfaces
4829 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4830 Id := First (Abstract_Interface_List (Full_T));
4831 while Present (Id) loop
4832 Iface := Etype (Id);
4834 -- Protect against wrong uses. For example:
4835 -- type I is interface;
4836 -- type O is tagged null record;
4837 -- type Wrong is new I and O with null record; -- ERROR
4839 if Is_Interface (Iface) then
4840 if Exclude_Parents
4841 and then Etype (T) /= T
4842 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4843 then
4844 null;
4845 else
4846 Collect (Iface);
4847 Append_Unique_Elmt (Iface, Ifaces_List);
4848 end if;
4849 end if;
4851 Next (Id);
4852 end loop;
4853 end if;
4854 end Collect;
4856 -- Start of processing for Collect_Interfaces
4858 begin
4859 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4860 Ifaces_List := New_Elmt_List;
4861 Collect (T);
4862 end Collect_Interfaces;
4864 ----------------------------------
4865 -- Collect_Interface_Components --
4866 ----------------------------------
4868 procedure Collect_Interface_Components
4869 (Tagged_Type : Entity_Id;
4870 Components_List : out Elist_Id)
4872 procedure Collect (Typ : Entity_Id);
4873 -- Subsidiary subprogram used to climb to the parents
4875 -------------
4876 -- Collect --
4877 -------------
4879 procedure Collect (Typ : Entity_Id) is
4880 Tag_Comp : Entity_Id;
4881 Parent_Typ : Entity_Id;
4883 begin
4884 -- Handle private types
4886 if Present (Full_View (Etype (Typ))) then
4887 Parent_Typ := Full_View (Etype (Typ));
4888 else
4889 Parent_Typ := Etype (Typ);
4890 end if;
4892 if Parent_Typ /= Typ
4894 -- Protect the frontend against wrong sources. For example:
4896 -- package P is
4897 -- type A is tagged null record;
4898 -- type B is new A with private;
4899 -- type C is new A with private;
4900 -- private
4901 -- type B is new C with null record;
4902 -- type C is new B with null record;
4903 -- end P;
4905 and then Parent_Typ /= Tagged_Type
4906 then
4907 Collect (Parent_Typ);
4908 end if;
4910 -- Collect the components containing tags of secondary dispatch
4911 -- tables.
4913 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4914 while Present (Tag_Comp) loop
4915 pragma Assert (Present (Related_Type (Tag_Comp)));
4916 Append_Elmt (Tag_Comp, Components_List);
4918 Tag_Comp := Next_Tag_Component (Tag_Comp);
4919 end loop;
4920 end Collect;
4922 -- Start of processing for Collect_Interface_Components
4924 begin
4925 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4926 and then Is_Tagged_Type (Tagged_Type));
4928 Components_List := New_Elmt_List;
4929 Collect (Tagged_Type);
4930 end Collect_Interface_Components;
4932 -----------------------------
4933 -- Collect_Interfaces_Info --
4934 -----------------------------
4936 procedure Collect_Interfaces_Info
4937 (T : Entity_Id;
4938 Ifaces_List : out Elist_Id;
4939 Components_List : out Elist_Id;
4940 Tags_List : out Elist_Id)
4942 Comps_List : Elist_Id;
4943 Comp_Elmt : Elmt_Id;
4944 Comp_Iface : Entity_Id;
4945 Iface_Elmt : Elmt_Id;
4946 Iface : Entity_Id;
4948 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4949 -- Search for the secondary tag associated with the interface type
4950 -- Iface that is implemented by T.
4952 ----------------
4953 -- Search_Tag --
4954 ----------------
4956 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4957 ADT : Elmt_Id;
4958 begin
4959 if not Is_CPP_Class (T) then
4960 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4961 else
4962 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4963 end if;
4965 while Present (ADT)
4966 and then Is_Tag (Node (ADT))
4967 and then Related_Type (Node (ADT)) /= Iface
4968 loop
4969 -- Skip secondary dispatch table referencing thunks to user
4970 -- defined primitives covered by this interface.
4972 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4973 Next_Elmt (ADT);
4975 -- Skip secondary dispatch tables of Ada types
4977 if not Is_CPP_Class (T) then
4979 -- Skip secondary dispatch table referencing thunks to
4980 -- predefined primitives.
4982 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4983 Next_Elmt (ADT);
4985 -- Skip secondary dispatch table referencing user-defined
4986 -- primitives covered by this interface.
4988 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4989 Next_Elmt (ADT);
4991 -- Skip secondary dispatch table referencing predefined
4992 -- primitives.
4994 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4995 Next_Elmt (ADT);
4996 end if;
4997 end loop;
4999 pragma Assert (Is_Tag (Node (ADT)));
5000 return Node (ADT);
5001 end Search_Tag;
5003 -- Start of processing for Collect_Interfaces_Info
5005 begin
5006 Collect_Interfaces (T, Ifaces_List);
5007 Collect_Interface_Components (T, Comps_List);
5009 -- Search for the record component and tag associated with each
5010 -- interface type of T.
5012 Components_List := New_Elmt_List;
5013 Tags_List := New_Elmt_List;
5015 Iface_Elmt := First_Elmt (Ifaces_List);
5016 while Present (Iface_Elmt) loop
5017 Iface := Node (Iface_Elmt);
5019 -- Associate the primary tag component and the primary dispatch table
5020 -- with all the interfaces that are parents of T
5022 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5023 Append_Elmt (First_Tag_Component (T), Components_List);
5024 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5026 -- Otherwise search for the tag component and secondary dispatch
5027 -- table of Iface
5029 else
5030 Comp_Elmt := First_Elmt (Comps_List);
5031 while Present (Comp_Elmt) loop
5032 Comp_Iface := Related_Type (Node (Comp_Elmt));
5034 if Comp_Iface = Iface
5035 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5036 then
5037 Append_Elmt (Node (Comp_Elmt), Components_List);
5038 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5039 exit;
5040 end if;
5042 Next_Elmt (Comp_Elmt);
5043 end loop;
5044 pragma Assert (Present (Comp_Elmt));
5045 end if;
5047 Next_Elmt (Iface_Elmt);
5048 end loop;
5049 end Collect_Interfaces_Info;
5051 ---------------------
5052 -- Collect_Parents --
5053 ---------------------
5055 procedure Collect_Parents
5056 (T : Entity_Id;
5057 List : out Elist_Id;
5058 Use_Full_View : Boolean := True)
5060 Current_Typ : Entity_Id := T;
5061 Parent_Typ : Entity_Id;
5063 begin
5064 List := New_Elmt_List;
5066 -- No action if the if the type has no parents
5068 if T = Etype (T) then
5069 return;
5070 end if;
5072 loop
5073 Parent_Typ := Etype (Current_Typ);
5075 if Is_Private_Type (Parent_Typ)
5076 and then Present (Full_View (Parent_Typ))
5077 and then Use_Full_View
5078 then
5079 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5080 end if;
5082 Append_Elmt (Parent_Typ, List);
5084 exit when Parent_Typ = Current_Typ;
5085 Current_Typ := Parent_Typ;
5086 end loop;
5087 end Collect_Parents;
5089 ----------------------------------
5090 -- Collect_Primitive_Operations --
5091 ----------------------------------
5093 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5094 B_Type : constant Entity_Id := Base_Type (T);
5096 function Match (E : Entity_Id) return Boolean;
5097 -- True if E's base type is B_Type, or E is of an anonymous access type
5098 -- and the base type of its designated type is B_Type.
5100 -----------
5101 -- Match --
5102 -----------
5104 function Match (E : Entity_Id) return Boolean is
5105 Etyp : Entity_Id := Etype (E);
5107 begin
5108 if Ekind (Etyp) = E_Anonymous_Access_Type then
5109 Etyp := Designated_Type (Etyp);
5110 end if;
5112 -- In Ada 2012 a primitive operation may have a formal of an
5113 -- incomplete view of the parent type.
5115 return Base_Type (Etyp) = B_Type
5116 or else
5117 (Ada_Version >= Ada_2012
5118 and then Ekind (Etyp) = E_Incomplete_Type
5119 and then Full_View (Etyp) = B_Type);
5120 end Match;
5122 -- Local variables
5124 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5125 B_Scope : Entity_Id := Scope (B_Type);
5126 Op_List : Elist_Id;
5127 Eq_Prims_List : Elist_Id := No_Elist;
5128 Formal : Entity_Id;
5129 Is_Prim : Boolean;
5130 Is_Type_In_Pkg : Boolean;
5131 Formal_Derived : Boolean := False;
5132 Id : Entity_Id;
5134 -- Start of processing for Collect_Primitive_Operations
5136 begin
5137 -- For tagged types, the primitive operations are collected as they
5138 -- are declared, and held in an explicit list which is simply returned.
5140 if Is_Tagged_Type (B_Type) then
5141 return Primitive_Operations (B_Type);
5143 -- An untagged generic type that is a derived type inherits the
5144 -- primitive operations of its parent type. Other formal types only
5145 -- have predefined operators, which are not explicitly represented.
5147 elsif Is_Generic_Type (B_Type) then
5148 if Nkind (B_Decl) = N_Formal_Type_Declaration
5149 and then Nkind (Formal_Type_Definition (B_Decl)) =
5150 N_Formal_Derived_Type_Definition
5151 then
5152 Formal_Derived := True;
5153 else
5154 return New_Elmt_List;
5155 end if;
5156 end if;
5158 Op_List := New_Elmt_List;
5160 if B_Scope = Standard_Standard then
5161 if B_Type = Standard_String then
5162 Append_Elmt (Standard_Op_Concat, Op_List);
5164 elsif B_Type = Standard_Wide_String then
5165 Append_Elmt (Standard_Op_Concatw, Op_List);
5167 else
5168 null;
5169 end if;
5171 -- Locate the primitive subprograms of the type
5173 else
5174 -- The primitive operations appear after the base type, except if the
5175 -- derivation happens within the private part of B_Scope and the type
5176 -- is a private type, in which case both the type and some primitive
5177 -- operations may appear before the base type, and the list of
5178 -- candidates starts after the type.
5180 if In_Open_Scopes (B_Scope)
5181 and then Scope (T) = B_Scope
5182 and then In_Private_Part (B_Scope)
5183 then
5184 Id := Next_Entity (T);
5186 -- In Ada 2012, If the type has an incomplete partial view, there may
5187 -- be primitive operations declared before the full view, so we need
5188 -- to start scanning from the incomplete view, which is earlier on
5189 -- the entity chain.
5191 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5192 and then Present (Incomplete_View (Parent (B_Type)))
5193 then
5194 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5196 -- If T is a derived from a type with an incomplete view declared
5197 -- elsewhere, that incomplete view is irrelevant, we want the
5198 -- operations in the scope of T.
5200 if Scope (Id) /= Scope (B_Type) then
5201 Id := Next_Entity (B_Type);
5202 end if;
5204 else
5205 Id := Next_Entity (B_Type);
5206 end if;
5208 -- Set flag if this is a type in a package spec
5210 Is_Type_In_Pkg :=
5211 Is_Package_Or_Generic_Package (B_Scope)
5212 and then
5213 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5214 N_Package_Body;
5216 while Present (Id) loop
5218 -- Test whether the result type or any of the parameter types of
5219 -- each subprogram following the type match that type when the
5220 -- type is declared in a package spec, is a derived type, or the
5221 -- subprogram is marked as primitive. (The Is_Primitive test is
5222 -- needed to find primitives of nonderived types in declarative
5223 -- parts that happen to override the predefined "=" operator.)
5225 -- Note that generic formal subprograms are not considered to be
5226 -- primitive operations and thus are never inherited.
5228 if Is_Overloadable (Id)
5229 and then (Is_Type_In_Pkg
5230 or else Is_Derived_Type (B_Type)
5231 or else Is_Primitive (Id))
5232 and then Nkind (Parent (Parent (Id)))
5233 not in N_Formal_Subprogram_Declaration
5234 then
5235 Is_Prim := False;
5237 if Match (Id) then
5238 Is_Prim := True;
5240 else
5241 Formal := First_Formal (Id);
5242 while Present (Formal) loop
5243 if Match (Formal) then
5244 Is_Prim := True;
5245 exit;
5246 end if;
5248 Next_Formal (Formal);
5249 end loop;
5250 end if;
5252 -- For a formal derived type, the only primitives are the ones
5253 -- inherited from the parent type. Operations appearing in the
5254 -- package declaration are not primitive for it.
5256 if Is_Prim
5257 and then (not Formal_Derived or else Present (Alias (Id)))
5258 then
5259 -- In the special case of an equality operator aliased to
5260 -- an overriding dispatching equality belonging to the same
5261 -- type, we don't include it in the list of primitives.
5262 -- This avoids inheriting multiple equality operators when
5263 -- deriving from untagged private types whose full type is
5264 -- tagged, which can otherwise cause ambiguities. Note that
5265 -- this should only happen for this kind of untagged parent
5266 -- type, since normally dispatching operations are inherited
5267 -- using the type's Primitive_Operations list.
5269 if Chars (Id) = Name_Op_Eq
5270 and then Is_Dispatching_Operation (Id)
5271 and then Present (Alias (Id))
5272 and then Present (Overridden_Operation (Alias (Id)))
5273 and then Base_Type (Etype (First_Entity (Id))) =
5274 Base_Type (Etype (First_Entity (Alias (Id))))
5275 then
5276 null;
5278 -- Include the subprogram in the list of primitives
5280 else
5281 Append_Elmt (Id, Op_List);
5283 -- Save collected equality primitives for later filtering
5284 -- (if we are processing a private type for which we can
5285 -- collect several candidates).
5287 if Inherits_From_Tagged_Full_View (T)
5288 and then Chars (Id) = Name_Op_Eq
5289 and then Etype (First_Formal (Id)) =
5290 Etype (Next_Formal (First_Formal (Id)))
5291 then
5292 if No (Eq_Prims_List) then
5293 Eq_Prims_List := New_Elmt_List;
5294 end if;
5296 Append_Elmt (Id, Eq_Prims_List);
5297 end if;
5298 end if;
5299 end if;
5300 end if;
5302 Next_Entity (Id);
5304 -- For a type declared in System, some of its operations may
5305 -- appear in the target-specific extension to System.
5307 if No (Id)
5308 and then B_Scope = RTU_Entity (System)
5309 and then Present_System_Aux
5310 then
5311 B_Scope := System_Aux_Id;
5312 Id := First_Entity (System_Aux_Id);
5313 end if;
5314 end loop;
5316 -- Filter collected equality primitives
5318 if Inherits_From_Tagged_Full_View (T)
5319 and then Present (Eq_Prims_List)
5320 then
5321 declare
5322 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5323 Second : Elmt_Id;
5325 begin
5326 pragma Assert (No (Next_Elmt (First))
5327 or else No (Next_Elmt (Next_Elmt (First))));
5329 -- No action needed if we have collected a single equality
5330 -- primitive
5332 if Present (Next_Elmt (First)) then
5333 Second := Next_Elmt (First);
5335 if Is_Dispatching_Operation
5336 (Ultimate_Alias (Node (First)))
5337 then
5338 Remove (Op_List, Node (First));
5340 elsif Is_Dispatching_Operation
5341 (Ultimate_Alias (Node (Second)))
5342 then
5343 Remove (Op_List, Node (Second));
5345 else
5346 pragma Assert (False);
5347 raise Program_Error;
5348 end if;
5349 end if;
5350 end;
5351 end if;
5352 end if;
5354 return Op_List;
5355 end Collect_Primitive_Operations;
5357 -----------------------------------
5358 -- Compile_Time_Constraint_Error --
5359 -----------------------------------
5361 function Compile_Time_Constraint_Error
5362 (N : Node_Id;
5363 Msg : String;
5364 Ent : Entity_Id := Empty;
5365 Loc : Source_Ptr := No_Location;
5366 Warn : Boolean := False) return Node_Id
5368 Msgc : String (1 .. Msg'Length + 3);
5369 -- Copy of message, with room for possible ?? or << and ! at end
5371 Msgl : Natural;
5372 Wmsg : Boolean;
5373 Eloc : Source_Ptr;
5375 -- Start of processing for Compile_Time_Constraint_Error
5377 begin
5378 -- If this is a warning, convert it into an error if we are in code
5379 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5380 -- warning. The rationale is that a compile-time constraint error should
5381 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5382 -- a few cases we prefer to issue a warning and generate both a suitable
5383 -- run-time error in GNAT and a suitable check message in GNATprove.
5384 -- Those cases are those that likely correspond to deactivated SPARK
5385 -- code, so that this kind of code can be compiled and analyzed instead
5386 -- of being rejected.
5388 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5390 -- A static constraint error in an instance body is not a fatal error.
5391 -- we choose to inhibit the message altogether, because there is no
5392 -- obvious node (for now) on which to post it. On the other hand the
5393 -- offending node must be replaced with a constraint_error in any case.
5395 -- No messages are generated if we already posted an error on this node
5397 if not Error_Posted (N) then
5398 if Loc /= No_Location then
5399 Eloc := Loc;
5400 else
5401 Eloc := Sloc (N);
5402 end if;
5404 -- Copy message to Msgc, converting any ? in the message into <
5405 -- instead, so that we have an error in GNATprove mode.
5407 Msgl := Msg'Length;
5409 for J in 1 .. Msgl loop
5410 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5411 Msgc (J) := '<';
5412 else
5413 Msgc (J) := Msg (J);
5414 end if;
5415 end loop;
5417 -- Message is a warning, even in Ada 95 case
5419 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5420 Wmsg := True;
5422 -- In Ada 83, all messages are warnings. In the private part and the
5423 -- body of an instance, constraint_checks are only warnings. We also
5424 -- make this a warning if the Warn parameter is set.
5426 elsif Warn
5427 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5428 or else In_Instance_Not_Visible
5429 then
5430 Msgl := Msgl + 1;
5431 Msgc (Msgl) := '<';
5432 Msgl := Msgl + 1;
5433 Msgc (Msgl) := '<';
5434 Wmsg := True;
5436 -- Otherwise we have a real error message (Ada 95 static case) and we
5437 -- make this an unconditional message. Note that in the warning case
5438 -- we do not make the message unconditional, it seems reasonable to
5439 -- delete messages like this (about exceptions that will be raised)
5440 -- in dead code.
5442 else
5443 Wmsg := False;
5444 Msgl := Msgl + 1;
5445 Msgc (Msgl) := '!';
5446 end if;
5448 -- One more test, skip the warning if the related expression is
5449 -- statically unevaluated, since we don't want to warn about what
5450 -- will happen when something is evaluated if it never will be
5451 -- evaluated.
5453 if not Is_Statically_Unevaluated (N) then
5454 if Present (Ent) then
5455 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5456 else
5457 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5458 end if;
5460 if Wmsg then
5462 -- Check whether the context is an Init_Proc
5464 if Inside_Init_Proc then
5465 declare
5466 Conc_Typ : constant Entity_Id :=
5467 Corresponding_Concurrent_Type
5468 (Entity (Parameter_Type (First
5469 (Parameter_Specifications
5470 (Parent (Current_Scope))))));
5472 begin
5473 -- Don't complain if the corresponding concurrent type
5474 -- doesn't come from source (i.e. a single task/protected
5475 -- object).
5477 if Present (Conc_Typ)
5478 and then not Comes_From_Source (Conc_Typ)
5479 then
5480 Error_Msg_NEL
5481 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5483 else
5484 if GNATprove_Mode then
5485 Error_Msg_NEL
5486 ("\& would have been raised for objects of this "
5487 & "type", N, Standard_Constraint_Error, Eloc);
5488 else
5489 Error_Msg_NEL
5490 ("\& will be raised for objects of this type??",
5491 N, Standard_Constraint_Error, Eloc);
5492 end if;
5493 end if;
5494 end;
5496 else
5497 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5498 end if;
5500 else
5501 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5502 Set_Error_Posted (N);
5503 end if;
5504 end if;
5505 end if;
5507 return N;
5508 end Compile_Time_Constraint_Error;
5510 -----------------------
5511 -- Conditional_Delay --
5512 -----------------------
5514 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5515 begin
5516 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5517 Set_Has_Delayed_Freeze (New_Ent);
5518 end if;
5519 end Conditional_Delay;
5521 -------------------------
5522 -- Copy_Component_List --
5523 -------------------------
5525 function Copy_Component_List
5526 (R_Typ : Entity_Id;
5527 Loc : Source_Ptr) return List_Id
5529 Comp : Node_Id;
5530 Comps : constant List_Id := New_List;
5532 begin
5533 Comp := First_Component (Underlying_Type (R_Typ));
5534 while Present (Comp) loop
5535 if Comes_From_Source (Comp) then
5536 declare
5537 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5538 begin
5539 Append_To (Comps,
5540 Make_Component_Declaration (Loc,
5541 Defining_Identifier =>
5542 Make_Defining_Identifier (Loc, Chars (Comp)),
5543 Component_Definition =>
5544 New_Copy_Tree
5545 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5546 end;
5547 end if;
5549 Next_Component (Comp);
5550 end loop;
5552 return Comps;
5553 end Copy_Component_List;
5555 -------------------------
5556 -- Copy_Parameter_List --
5557 -------------------------
5559 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5560 Loc : constant Source_Ptr := Sloc (Subp_Id);
5561 Plist : List_Id;
5562 Formal : Entity_Id;
5564 begin
5565 if No (First_Formal (Subp_Id)) then
5566 return No_List;
5567 else
5568 Plist := New_List;
5569 Formal := First_Formal (Subp_Id);
5570 while Present (Formal) loop
5571 Append_To (Plist,
5572 Make_Parameter_Specification (Loc,
5573 Defining_Identifier =>
5574 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5575 In_Present => In_Present (Parent (Formal)),
5576 Out_Present => Out_Present (Parent (Formal)),
5577 Parameter_Type =>
5578 New_Occurrence_Of (Etype (Formal), Loc),
5579 Expression =>
5580 New_Copy_Tree (Expression (Parent (Formal)))));
5582 Next_Formal (Formal);
5583 end loop;
5584 end if;
5586 return Plist;
5587 end Copy_Parameter_List;
5589 ----------------------------
5590 -- Copy_SPARK_Mode_Aspect --
5591 ----------------------------
5593 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5594 pragma Assert (not Has_Aspects (To));
5595 Asp : Node_Id;
5597 begin
5598 if Has_Aspects (From) then
5599 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5601 if Present (Asp) then
5602 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5603 Set_Has_Aspects (To, True);
5604 end if;
5605 end if;
5606 end Copy_SPARK_Mode_Aspect;
5608 --------------------------
5609 -- Copy_Subprogram_Spec --
5610 --------------------------
5612 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5613 Def_Id : Node_Id;
5614 Formal_Spec : Node_Id;
5615 Result : Node_Id;
5617 begin
5618 -- The structure of the original tree must be replicated without any
5619 -- alterations. Use New_Copy_Tree for this purpose.
5621 Result := New_Copy_Tree (Spec);
5623 -- However, the spec of a null procedure carries the corresponding null
5624 -- statement of the body (created by the parser), and this cannot be
5625 -- shared with the new subprogram spec.
5627 if Nkind (Result) = N_Procedure_Specification then
5628 Set_Null_Statement (Result, Empty);
5629 end if;
5631 -- Create a new entity for the defining unit name
5633 Def_Id := Defining_Unit_Name (Result);
5634 Set_Defining_Unit_Name (Result,
5635 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5637 -- Create new entities for the formal parameters
5639 if Present (Parameter_Specifications (Result)) then
5640 Formal_Spec := First (Parameter_Specifications (Result));
5641 while Present (Formal_Spec) loop
5642 Def_Id := Defining_Identifier (Formal_Spec);
5643 Set_Defining_Identifier (Formal_Spec,
5644 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5646 Next (Formal_Spec);
5647 end loop;
5648 end if;
5650 return Result;
5651 end Copy_Subprogram_Spec;
5653 --------------------------------
5654 -- Corresponding_Generic_Type --
5655 --------------------------------
5657 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5658 Inst : Entity_Id;
5659 Gen : Entity_Id;
5660 Typ : Entity_Id;
5662 begin
5663 if not Is_Generic_Actual_Type (T) then
5664 return Any_Type;
5666 -- If the actual is the actual of an enclosing instance, resolution
5667 -- was correct in the generic.
5669 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5670 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5671 and then
5672 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5673 then
5674 return Any_Type;
5676 else
5677 Inst := Scope (T);
5679 if Is_Wrapper_Package (Inst) then
5680 Inst := Related_Instance (Inst);
5681 end if;
5683 Gen :=
5684 Generic_Parent
5685 (Specification (Unit_Declaration_Node (Inst)));
5687 -- Generic actual has the same name as the corresponding formal
5689 Typ := First_Entity (Gen);
5690 while Present (Typ) loop
5691 if Chars (Typ) = Chars (T) then
5692 return Typ;
5693 end if;
5695 Next_Entity (Typ);
5696 end loop;
5698 return Any_Type;
5699 end if;
5700 end Corresponding_Generic_Type;
5702 --------------------
5703 -- Current_Entity --
5704 --------------------
5706 -- The currently visible definition for a given identifier is the
5707 -- one most chained at the start of the visibility chain, i.e. the
5708 -- one that is referenced by the Node_Id value of the name of the
5709 -- given identifier.
5711 function Current_Entity (N : Node_Id) return Entity_Id is
5712 begin
5713 return Get_Name_Entity_Id (Chars (N));
5714 end Current_Entity;
5716 -----------------------------
5717 -- Current_Entity_In_Scope --
5718 -----------------------------
5720 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5721 E : Entity_Id;
5722 CS : constant Entity_Id := Current_Scope;
5724 Transient_Case : constant Boolean := Scope_Is_Transient;
5726 begin
5727 E := Get_Name_Entity_Id (Chars (N));
5728 while Present (E)
5729 and then Scope (E) /= CS
5730 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5731 loop
5732 E := Homonym (E);
5733 end loop;
5735 return E;
5736 end Current_Entity_In_Scope;
5738 -------------------
5739 -- Current_Scope --
5740 -------------------
5742 function Current_Scope return Entity_Id is
5743 begin
5744 if Scope_Stack.Last = -1 then
5745 return Standard_Standard;
5746 else
5747 declare
5748 C : constant Entity_Id :=
5749 Scope_Stack.Table (Scope_Stack.Last).Entity;
5750 begin
5751 if Present (C) then
5752 return C;
5753 else
5754 return Standard_Standard;
5755 end if;
5756 end;
5757 end if;
5758 end Current_Scope;
5760 ----------------------------
5761 -- Current_Scope_No_Loops --
5762 ----------------------------
5764 function Current_Scope_No_Loops return Entity_Id is
5765 S : Entity_Id;
5767 begin
5768 -- Examine the scope stack starting from the current scope and skip any
5769 -- internally generated loops.
5771 S := Current_Scope;
5772 while Present (S) and then S /= Standard_Standard loop
5773 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5774 S := Scope (S);
5775 else
5776 exit;
5777 end if;
5778 end loop;
5780 return S;
5781 end Current_Scope_No_Loops;
5783 ------------------------
5784 -- Current_Subprogram --
5785 ------------------------
5787 function Current_Subprogram return Entity_Id is
5788 Scop : constant Entity_Id := Current_Scope;
5789 begin
5790 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5791 return Scop;
5792 else
5793 return Enclosing_Subprogram (Scop);
5794 end if;
5795 end Current_Subprogram;
5797 ----------------------------------
5798 -- Deepest_Type_Access_Level --
5799 ----------------------------------
5801 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5802 begin
5803 if Ekind (Typ) = E_Anonymous_Access_Type
5804 and then not Is_Local_Anonymous_Access (Typ)
5805 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5806 then
5807 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5808 -- access type.
5810 return
5811 Scope_Depth (Enclosing_Dynamic_Scope
5812 (Defining_Identifier
5813 (Associated_Node_For_Itype (Typ))));
5815 -- For generic formal type, return Int'Last (infinite).
5816 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5818 elsif Is_Generic_Type (Root_Type (Typ)) then
5819 return UI_From_Int (Int'Last);
5821 else
5822 return Type_Access_Level (Typ);
5823 end if;
5824 end Deepest_Type_Access_Level;
5826 ---------------------
5827 -- Defining_Entity --
5828 ---------------------
5830 function Defining_Entity
5831 (N : Node_Id;
5832 Empty_On_Errors : Boolean := False;
5833 Concurrent_Subunit : Boolean := False) return Entity_Id
5835 begin
5836 case Nkind (N) is
5837 when N_Abstract_Subprogram_Declaration
5838 | N_Expression_Function
5839 | N_Formal_Subprogram_Declaration
5840 | N_Generic_Package_Declaration
5841 | N_Generic_Subprogram_Declaration
5842 | N_Package_Declaration
5843 | N_Subprogram_Body
5844 | N_Subprogram_Body_Stub
5845 | N_Subprogram_Declaration
5846 | N_Subprogram_Renaming_Declaration
5848 return Defining_Entity (Specification (N));
5850 when N_Component_Declaration
5851 | N_Defining_Program_Unit_Name
5852 | N_Discriminant_Specification
5853 | N_Entry_Body
5854 | N_Entry_Declaration
5855 | N_Entry_Index_Specification
5856 | N_Exception_Declaration
5857 | N_Exception_Renaming_Declaration
5858 | N_Formal_Object_Declaration
5859 | N_Formal_Package_Declaration
5860 | N_Formal_Type_Declaration
5861 | N_Full_Type_Declaration
5862 | N_Implicit_Label_Declaration
5863 | N_Incomplete_Type_Declaration
5864 | N_Iterator_Specification
5865 | N_Loop_Parameter_Specification
5866 | N_Number_Declaration
5867 | N_Object_Declaration
5868 | N_Object_Renaming_Declaration
5869 | N_Package_Body_Stub
5870 | N_Parameter_Specification
5871 | N_Private_Extension_Declaration
5872 | N_Private_Type_Declaration
5873 | N_Protected_Body
5874 | N_Protected_Body_Stub
5875 | N_Protected_Type_Declaration
5876 | N_Single_Protected_Declaration
5877 | N_Single_Task_Declaration
5878 | N_Subtype_Declaration
5879 | N_Task_Body
5880 | N_Task_Body_Stub
5881 | N_Task_Type_Declaration
5883 return Defining_Identifier (N);
5885 when N_Subunit =>
5886 declare
5887 Bod : constant Node_Id := Proper_Body (N);
5888 Orig_Bod : constant Node_Id := Original_Node (Bod);
5890 begin
5891 -- Retrieve the entity of the original protected or task body
5892 -- if requested by the caller.
5894 if Concurrent_Subunit
5895 and then Nkind (Bod) = N_Null_Statement
5896 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5897 then
5898 return Defining_Entity (Orig_Bod);
5899 else
5900 return Defining_Entity (Bod);
5901 end if;
5902 end;
5904 when N_Function_Instantiation
5905 | N_Function_Specification
5906 | N_Generic_Function_Renaming_Declaration
5907 | N_Generic_Package_Renaming_Declaration
5908 | N_Generic_Procedure_Renaming_Declaration
5909 | N_Package_Body
5910 | N_Package_Instantiation
5911 | N_Package_Renaming_Declaration
5912 | N_Package_Specification
5913 | N_Procedure_Instantiation
5914 | N_Procedure_Specification
5916 declare
5917 Nam : constant Node_Id := Defining_Unit_Name (N);
5918 Err : Entity_Id := Empty;
5920 begin
5921 if Nkind (Nam) in N_Entity then
5922 return Nam;
5924 -- For Error, make up a name and attach to declaration so we
5925 -- can continue semantic analysis.
5927 elsif Nam = Error then
5928 if Empty_On_Errors then
5929 return Empty;
5930 else
5931 Err := Make_Temporary (Sloc (N), 'T');
5932 Set_Defining_Unit_Name (N, Err);
5934 return Err;
5935 end if;
5937 -- If not an entity, get defining identifier
5939 else
5940 return Defining_Identifier (Nam);
5941 end if;
5942 end;
5944 when N_Block_Statement
5945 | N_Loop_Statement
5947 return Entity (Identifier (N));
5949 when others =>
5950 if Empty_On_Errors then
5951 return Empty;
5952 else
5953 raise Program_Error;
5954 end if;
5955 end case;
5956 end Defining_Entity;
5958 --------------------------
5959 -- Denotes_Discriminant --
5960 --------------------------
5962 function Denotes_Discriminant
5963 (N : Node_Id;
5964 Check_Concurrent : Boolean := False) return Boolean
5966 E : Entity_Id;
5968 begin
5969 if not Is_Entity_Name (N) or else No (Entity (N)) then
5970 return False;
5971 else
5972 E := Entity (N);
5973 end if;
5975 -- If we are checking for a protected type, the discriminant may have
5976 -- been rewritten as the corresponding discriminal of the original type
5977 -- or of the corresponding concurrent record, depending on whether we
5978 -- are in the spec or body of the protected type.
5980 return Ekind (E) = E_Discriminant
5981 or else
5982 (Check_Concurrent
5983 and then Ekind (E) = E_In_Parameter
5984 and then Present (Discriminal_Link (E))
5985 and then
5986 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5987 or else
5988 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5989 end Denotes_Discriminant;
5991 -------------------------
5992 -- Denotes_Same_Object --
5993 -------------------------
5995 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5996 function Is_Renaming (N : Node_Id) return Boolean;
5997 -- Return true if N names a renaming entity
5999 function Is_Valid_Renaming (N : Node_Id) return Boolean;
6000 -- For renamings, return False if the prefix of any dereference within
6001 -- the renamed object_name is a variable, or any expression within the
6002 -- renamed object_name contains references to variables or calls on
6003 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6005 -----------------
6006 -- Is_Renaming --
6007 -----------------
6009 function Is_Renaming (N : Node_Id) return Boolean is
6010 begin
6011 return
6012 Is_Entity_Name (N) and then Present (Renamed_Entity (Entity (N)));
6013 end Is_Renaming;
6015 -----------------------
6016 -- Is_Valid_Renaming --
6017 -----------------------
6019 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6020 function Check_Renaming (N : Node_Id) return Boolean;
6021 -- Recursive function used to traverse all the prefixes of N
6023 --------------------
6024 -- Check_Renaming --
6025 --------------------
6027 function Check_Renaming (N : Node_Id) return Boolean is
6028 begin
6029 if Is_Renaming (N)
6030 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6031 then
6032 return False;
6033 end if;
6035 if Nkind (N) = N_Indexed_Component then
6036 declare
6037 Indx : Node_Id;
6039 begin
6040 Indx := First (Expressions (N));
6041 while Present (Indx) loop
6042 if not Is_OK_Static_Expression (Indx) then
6043 return False;
6044 end if;
6046 Next_Index (Indx);
6047 end loop;
6048 end;
6049 end if;
6051 if Has_Prefix (N) then
6052 declare
6053 P : constant Node_Id := Prefix (N);
6055 begin
6056 if Nkind (N) = N_Explicit_Dereference
6057 and then Is_Variable (P)
6058 then
6059 return False;
6061 elsif Is_Entity_Name (P)
6062 and then Ekind (Entity (P)) = E_Function
6063 then
6064 return False;
6066 elsif Nkind (P) = N_Function_Call then
6067 return False;
6068 end if;
6070 -- Recursion to continue traversing the prefix of the
6071 -- renaming expression
6073 return Check_Renaming (P);
6074 end;
6075 end if;
6077 return True;
6078 end Check_Renaming;
6080 -- Start of processing for Is_Valid_Renaming
6082 begin
6083 return Check_Renaming (N);
6084 end Is_Valid_Renaming;
6086 -- Local variables
6088 Obj1 : Node_Id := A1;
6089 Obj2 : Node_Id := A2;
6091 -- Start of processing for Denotes_Same_Object
6093 begin
6094 -- Both names statically denote the same stand-alone object or parameter
6095 -- (RM 6.4.1(6.5/3))
6097 if Is_Entity_Name (Obj1)
6098 and then Is_Entity_Name (Obj2)
6099 and then Entity (Obj1) = Entity (Obj2)
6100 then
6101 return True;
6102 end if;
6104 -- For renamings, the prefix of any dereference within the renamed
6105 -- object_name is not a variable, and any expression within the
6106 -- renamed object_name contains no references to variables nor
6107 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6109 if Is_Renaming (Obj1) then
6110 if Is_Valid_Renaming (Obj1) then
6111 Obj1 := Renamed_Entity (Entity (Obj1));
6112 else
6113 return False;
6114 end if;
6115 end if;
6117 if Is_Renaming (Obj2) then
6118 if Is_Valid_Renaming (Obj2) then
6119 Obj2 := Renamed_Entity (Entity (Obj2));
6120 else
6121 return False;
6122 end if;
6123 end if;
6125 -- No match if not same node kind (such cases are handled by
6126 -- Denotes_Same_Prefix)
6128 if Nkind (Obj1) /= Nkind (Obj2) then
6129 return False;
6131 -- After handling valid renamings, one of the two names statically
6132 -- denoted a renaming declaration whose renamed object_name is known
6133 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6135 elsif Is_Entity_Name (Obj1) then
6136 if Is_Entity_Name (Obj2) then
6137 return Entity (Obj1) = Entity (Obj2);
6138 else
6139 return False;
6140 end if;
6142 -- Both names are selected_components, their prefixes are known to
6143 -- denote the same object, and their selector_names denote the same
6144 -- component (RM 6.4.1(6.6/3)).
6146 elsif Nkind (Obj1) = N_Selected_Component then
6147 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6148 and then
6149 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6151 -- Both names are dereferences and the dereferenced names are known to
6152 -- denote the same object (RM 6.4.1(6.7/3))
6154 elsif Nkind (Obj1) = N_Explicit_Dereference then
6155 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6157 -- Both names are indexed_components, their prefixes are known to denote
6158 -- the same object, and each of the pairs of corresponding index values
6159 -- are either both static expressions with the same static value or both
6160 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6162 elsif Nkind (Obj1) = N_Indexed_Component then
6163 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6164 return False;
6165 else
6166 declare
6167 Indx1 : Node_Id;
6168 Indx2 : Node_Id;
6170 begin
6171 Indx1 := First (Expressions (Obj1));
6172 Indx2 := First (Expressions (Obj2));
6173 while Present (Indx1) loop
6175 -- Indexes must denote the same static value or same object
6177 if Is_OK_Static_Expression (Indx1) then
6178 if not Is_OK_Static_Expression (Indx2) then
6179 return False;
6181 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6182 return False;
6183 end if;
6185 elsif not Denotes_Same_Object (Indx1, Indx2) then
6186 return False;
6187 end if;
6189 Next (Indx1);
6190 Next (Indx2);
6191 end loop;
6193 return True;
6194 end;
6195 end if;
6197 -- Both names are slices, their prefixes are known to denote the same
6198 -- object, and the two slices have statically matching index constraints
6199 -- (RM 6.4.1(6.9/3))
6201 elsif Nkind (Obj1) = N_Slice
6202 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6203 then
6204 declare
6205 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6207 begin
6208 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6209 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6211 -- Check whether bounds are statically identical. There is no
6212 -- attempt to detect partial overlap of slices.
6214 return Denotes_Same_Object (Lo1, Lo2)
6215 and then
6216 Denotes_Same_Object (Hi1, Hi2);
6217 end;
6219 -- In the recursion, literals appear as indexes
6221 elsif Nkind (Obj1) = N_Integer_Literal
6222 and then
6223 Nkind (Obj2) = N_Integer_Literal
6224 then
6225 return Intval (Obj1) = Intval (Obj2);
6227 else
6228 return False;
6229 end if;
6230 end Denotes_Same_Object;
6232 -------------------------
6233 -- Denotes_Same_Prefix --
6234 -------------------------
6236 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6237 begin
6238 if Is_Entity_Name (A1) then
6239 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6240 and then not Is_Access_Type (Etype (A1))
6241 then
6242 return Denotes_Same_Object (A1, Prefix (A2))
6243 or else Denotes_Same_Prefix (A1, Prefix (A2));
6244 else
6245 return False;
6246 end if;
6248 elsif Is_Entity_Name (A2) then
6249 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6251 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6252 and then
6253 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6254 then
6255 declare
6256 Root1, Root2 : Node_Id;
6257 Depth1, Depth2 : Nat := 0;
6259 begin
6260 Root1 := Prefix (A1);
6261 while not Is_Entity_Name (Root1) loop
6262 if not Nkind_In
6263 (Root1, N_Selected_Component, N_Indexed_Component)
6264 then
6265 return False;
6266 else
6267 Root1 := Prefix (Root1);
6268 end if;
6270 Depth1 := Depth1 + 1;
6271 end loop;
6273 Root2 := Prefix (A2);
6274 while not Is_Entity_Name (Root2) loop
6275 if not Nkind_In (Root2, N_Selected_Component,
6276 N_Indexed_Component)
6277 then
6278 return False;
6279 else
6280 Root2 := Prefix (Root2);
6281 end if;
6283 Depth2 := Depth2 + 1;
6284 end loop;
6286 -- If both have the same depth and they do not denote the same
6287 -- object, they are disjoint and no warning is needed.
6289 if Depth1 = Depth2 then
6290 return False;
6292 elsif Depth1 > Depth2 then
6293 Root1 := Prefix (A1);
6294 for J in 1 .. Depth1 - Depth2 - 1 loop
6295 Root1 := Prefix (Root1);
6296 end loop;
6298 return Denotes_Same_Object (Root1, A2);
6300 else
6301 Root2 := Prefix (A2);
6302 for J in 1 .. Depth2 - Depth1 - 1 loop
6303 Root2 := Prefix (Root2);
6304 end loop;
6306 return Denotes_Same_Object (A1, Root2);
6307 end if;
6308 end;
6310 else
6311 return False;
6312 end if;
6313 end Denotes_Same_Prefix;
6315 ----------------------
6316 -- Denotes_Variable --
6317 ----------------------
6319 function Denotes_Variable (N : Node_Id) return Boolean is
6320 begin
6321 return Is_Variable (N) and then Paren_Count (N) = 0;
6322 end Denotes_Variable;
6324 -----------------------------
6325 -- Depends_On_Discriminant --
6326 -----------------------------
6328 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6329 L : Node_Id;
6330 H : Node_Id;
6332 begin
6333 Get_Index_Bounds (N, L, H);
6334 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6335 end Depends_On_Discriminant;
6337 -------------------------
6338 -- Designate_Same_Unit --
6339 -------------------------
6341 function Designate_Same_Unit
6342 (Name1 : Node_Id;
6343 Name2 : Node_Id) return Boolean
6345 K1 : constant Node_Kind := Nkind (Name1);
6346 K2 : constant Node_Kind := Nkind (Name2);
6348 function Prefix_Node (N : Node_Id) return Node_Id;
6349 -- Returns the parent unit name node of a defining program unit name
6350 -- or the prefix if N is a selected component or an expanded name.
6352 function Select_Node (N : Node_Id) return Node_Id;
6353 -- Returns the defining identifier node of a defining program unit
6354 -- name or the selector node if N is a selected component or an
6355 -- expanded name.
6357 -----------------
6358 -- Prefix_Node --
6359 -----------------
6361 function Prefix_Node (N : Node_Id) return Node_Id is
6362 begin
6363 if Nkind (N) = N_Defining_Program_Unit_Name then
6364 return Name (N);
6365 else
6366 return Prefix (N);
6367 end if;
6368 end Prefix_Node;
6370 -----------------
6371 -- Select_Node --
6372 -----------------
6374 function Select_Node (N : Node_Id) return Node_Id is
6375 begin
6376 if Nkind (N) = N_Defining_Program_Unit_Name then
6377 return Defining_Identifier (N);
6378 else
6379 return Selector_Name (N);
6380 end if;
6381 end Select_Node;
6383 -- Start of processing for Designate_Same_Unit
6385 begin
6386 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6387 and then
6388 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6389 then
6390 return Chars (Name1) = Chars (Name2);
6392 elsif Nkind_In (K1, N_Expanded_Name,
6393 N_Selected_Component,
6394 N_Defining_Program_Unit_Name)
6395 and then
6396 Nkind_In (K2, N_Expanded_Name,
6397 N_Selected_Component,
6398 N_Defining_Program_Unit_Name)
6399 then
6400 return
6401 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6402 and then
6403 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6405 else
6406 return False;
6407 end if;
6408 end Designate_Same_Unit;
6410 ---------------------------------------------
6411 -- Diagnose_Iterated_Component_Association --
6412 ---------------------------------------------
6414 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6415 Def_Id : constant Entity_Id := Defining_Identifier (N);
6416 Aggr : Node_Id;
6418 begin
6419 -- Determine whether the iterated component association appears within
6420 -- an aggregate. If this is the case, raise Program_Error because the
6421 -- iterated component association cannot be left in the tree as is and
6422 -- must always be processed by the related aggregate.
6424 Aggr := N;
6425 while Present (Aggr) loop
6426 if Nkind (Aggr) = N_Aggregate then
6427 raise Program_Error;
6429 -- Prevent the search from going too far
6431 elsif Is_Body_Or_Package_Declaration (Aggr) then
6432 exit;
6433 end if;
6435 Aggr := Parent (Aggr);
6436 end loop;
6438 -- At this point it is known that the iterated component association is
6439 -- not within an aggregate. This is really a quantified expression with
6440 -- a missing "all" or "some" quantifier.
6442 Error_Msg_N ("missing quantifier", Def_Id);
6444 -- Rewrite the iterated component association as True to prevent any
6445 -- cascaded errors.
6447 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6448 Analyze (N);
6449 end Diagnose_Iterated_Component_Association;
6451 ---------------------------------
6452 -- Dynamic_Accessibility_Level --
6453 ---------------------------------
6455 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
6456 Loc : constant Source_Ptr := Sloc (Expr);
6458 function Make_Level_Literal (Level : Uint) return Node_Id;
6459 -- Construct an integer literal representing an accessibility level
6460 -- with its type set to Natural.
6462 ------------------------
6463 -- Make_Level_Literal --
6464 ------------------------
6466 function Make_Level_Literal (Level : Uint) return Node_Id is
6467 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6469 begin
6470 Set_Etype (Result, Standard_Natural);
6471 return Result;
6472 end Make_Level_Literal;
6474 -- Local variables
6476 E : Entity_Id;
6478 -- Start of processing for Dynamic_Accessibility_Level
6480 begin
6481 if Is_Entity_Name (Expr) then
6482 E := Entity (Expr);
6484 if Present (Renamed_Object (E)) then
6485 return Dynamic_Accessibility_Level (Renamed_Object (E));
6486 end if;
6488 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6489 if Present (Extra_Accessibility (E)) then
6490 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6491 end if;
6492 end if;
6493 end if;
6495 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6497 case Nkind (Expr) is
6499 -- For access discriminant, the level of the enclosing object
6501 when N_Selected_Component =>
6502 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6503 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6504 E_Anonymous_Access_Type
6505 then
6506 return Make_Level_Literal (Object_Access_Level (Expr));
6507 end if;
6509 when N_Attribute_Reference =>
6510 case Get_Attribute_Id (Attribute_Name (Expr)) is
6512 -- For X'Access, the level of the prefix X
6514 when Attribute_Access =>
6515 return Make_Level_Literal
6516 (Object_Access_Level (Prefix (Expr)));
6518 -- Treat the unchecked attributes as library-level
6520 when Attribute_Unchecked_Access
6521 | Attribute_Unrestricted_Access
6523 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6525 -- No other access-valued attributes
6527 when others =>
6528 raise Program_Error;
6529 end case;
6531 when N_Allocator =>
6533 -- Unimplemented: depends on context. As an actual parameter where
6534 -- formal type is anonymous, use
6535 -- Scope_Depth (Current_Scope) + 1.
6536 -- For other cases, see 3.10.2(14/3) and following. ???
6538 null;
6540 when N_Type_Conversion =>
6541 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6543 -- Handle type conversions introduced for a rename of an
6544 -- Ada 2012 stand-alone object of an anonymous access type.
6546 return Dynamic_Accessibility_Level (Expression (Expr));
6547 end if;
6549 when others =>
6550 null;
6551 end case;
6553 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6554 end Dynamic_Accessibility_Level;
6556 ------------------------
6557 -- Discriminated_Size --
6558 ------------------------
6560 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6561 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6562 -- Check whether the bound of an index is non-static and does denote
6563 -- a discriminant, in which case any object of the type (protected or
6564 -- otherwise) will have a non-static size.
6566 ----------------------
6567 -- Non_Static_Bound --
6568 ----------------------
6570 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6571 begin
6572 if Is_OK_Static_Expression (Bound) then
6573 return False;
6575 -- If the bound is given by a discriminant it is non-static
6576 -- (A static constraint replaces the reference with the value).
6577 -- In an protected object the discriminant has been replaced by
6578 -- the corresponding discriminal within the protected operation.
6580 elsif Is_Entity_Name (Bound)
6581 and then
6582 (Ekind (Entity (Bound)) = E_Discriminant
6583 or else Present (Discriminal_Link (Entity (Bound))))
6584 then
6585 return False;
6587 else
6588 return True;
6589 end if;
6590 end Non_Static_Bound;
6592 -- Local variables
6594 Typ : constant Entity_Id := Etype (Comp);
6595 Index : Node_Id;
6597 -- Start of processing for Discriminated_Size
6599 begin
6600 if not Is_Array_Type (Typ) then
6601 return False;
6602 end if;
6604 if Ekind (Typ) = E_Array_Subtype then
6605 Index := First_Index (Typ);
6606 while Present (Index) loop
6607 if Non_Static_Bound (Low_Bound (Index))
6608 or else Non_Static_Bound (High_Bound (Index))
6609 then
6610 return False;
6611 end if;
6613 Next_Index (Index);
6614 end loop;
6616 return True;
6617 end if;
6619 return False;
6620 end Discriminated_Size;
6622 -----------------------------------
6623 -- Effective_Extra_Accessibility --
6624 -----------------------------------
6626 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6627 begin
6628 if Present (Renamed_Object (Id))
6629 and then Is_Entity_Name (Renamed_Object (Id))
6630 then
6631 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6632 else
6633 return Extra_Accessibility (Id);
6634 end if;
6635 end Effective_Extra_Accessibility;
6637 -----------------------------
6638 -- Effective_Reads_Enabled --
6639 -----------------------------
6641 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6642 begin
6643 return Has_Enabled_Property (Id, Name_Effective_Reads);
6644 end Effective_Reads_Enabled;
6646 ------------------------------
6647 -- Effective_Writes_Enabled --
6648 ------------------------------
6650 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6651 begin
6652 return Has_Enabled_Property (Id, Name_Effective_Writes);
6653 end Effective_Writes_Enabled;
6655 ------------------------------
6656 -- Enclosing_Comp_Unit_Node --
6657 ------------------------------
6659 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6660 Current_Node : Node_Id;
6662 begin
6663 Current_Node := N;
6664 while Present (Current_Node)
6665 and then Nkind (Current_Node) /= N_Compilation_Unit
6666 loop
6667 Current_Node := Parent (Current_Node);
6668 end loop;
6670 if Nkind (Current_Node) /= N_Compilation_Unit then
6671 return Empty;
6672 else
6673 return Current_Node;
6674 end if;
6675 end Enclosing_Comp_Unit_Node;
6677 --------------------------
6678 -- Enclosing_CPP_Parent --
6679 --------------------------
6681 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6682 Parent_Typ : Entity_Id := Typ;
6684 begin
6685 while not Is_CPP_Class (Parent_Typ)
6686 and then Etype (Parent_Typ) /= Parent_Typ
6687 loop
6688 Parent_Typ := Etype (Parent_Typ);
6690 if Is_Private_Type (Parent_Typ) then
6691 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6692 end if;
6693 end loop;
6695 pragma Assert (Is_CPP_Class (Parent_Typ));
6696 return Parent_Typ;
6697 end Enclosing_CPP_Parent;
6699 ---------------------------
6700 -- Enclosing_Declaration --
6701 ---------------------------
6703 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6704 Decl : Node_Id := N;
6706 begin
6707 while Present (Decl)
6708 and then not (Nkind (Decl) in N_Declaration
6709 or else
6710 Nkind (Decl) in N_Later_Decl_Item
6711 or else
6712 Nkind (Decl) = N_Number_Declaration)
6713 loop
6714 Decl := Parent (Decl);
6715 end loop;
6717 return Decl;
6718 end Enclosing_Declaration;
6720 ----------------------------
6721 -- Enclosing_Generic_Body --
6722 ----------------------------
6724 function Enclosing_Generic_Body
6725 (N : Node_Id) return Node_Id
6727 P : Node_Id;
6728 Decl : Node_Id;
6729 Spec : Node_Id;
6731 begin
6732 P := Parent (N);
6733 while Present (P) loop
6734 if Nkind (P) = N_Package_Body
6735 or else Nkind (P) = N_Subprogram_Body
6736 then
6737 Spec := Corresponding_Spec (P);
6739 if Present (Spec) then
6740 Decl := Unit_Declaration_Node (Spec);
6742 if Nkind (Decl) = N_Generic_Package_Declaration
6743 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6744 then
6745 return P;
6746 end if;
6747 end if;
6748 end if;
6750 P := Parent (P);
6751 end loop;
6753 return Empty;
6754 end Enclosing_Generic_Body;
6756 ----------------------------
6757 -- Enclosing_Generic_Unit --
6758 ----------------------------
6760 function Enclosing_Generic_Unit
6761 (N : Node_Id) return Node_Id
6763 P : Node_Id;
6764 Decl : Node_Id;
6765 Spec : Node_Id;
6767 begin
6768 P := Parent (N);
6769 while Present (P) loop
6770 if Nkind (P) = N_Generic_Package_Declaration
6771 or else Nkind (P) = N_Generic_Subprogram_Declaration
6772 then
6773 return P;
6775 elsif Nkind (P) = N_Package_Body
6776 or else Nkind (P) = N_Subprogram_Body
6777 then
6778 Spec := Corresponding_Spec (P);
6780 if Present (Spec) then
6781 Decl := Unit_Declaration_Node (Spec);
6783 if Nkind (Decl) = N_Generic_Package_Declaration
6784 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6785 then
6786 return Decl;
6787 end if;
6788 end if;
6789 end if;
6791 P := Parent (P);
6792 end loop;
6794 return Empty;
6795 end Enclosing_Generic_Unit;
6797 -------------------------------
6798 -- Enclosing_Lib_Unit_Entity --
6799 -------------------------------
6801 function Enclosing_Lib_Unit_Entity
6802 (E : Entity_Id := Current_Scope) return Entity_Id
6804 Unit_Entity : Entity_Id;
6806 begin
6807 -- Look for enclosing library unit entity by following scope links.
6808 -- Equivalent to, but faster than indexing through the scope stack.
6810 Unit_Entity := E;
6811 while (Present (Scope (Unit_Entity))
6812 and then Scope (Unit_Entity) /= Standard_Standard)
6813 and not Is_Child_Unit (Unit_Entity)
6814 loop
6815 Unit_Entity := Scope (Unit_Entity);
6816 end loop;
6818 return Unit_Entity;
6819 end Enclosing_Lib_Unit_Entity;
6821 -----------------------------
6822 -- Enclosing_Lib_Unit_Node --
6823 -----------------------------
6825 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6826 Encl_Unit : Node_Id;
6828 begin
6829 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6830 while Present (Encl_Unit)
6831 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6832 loop
6833 Encl_Unit := Library_Unit (Encl_Unit);
6834 end loop;
6836 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6837 return Encl_Unit;
6838 end Enclosing_Lib_Unit_Node;
6840 -----------------------
6841 -- Enclosing_Package --
6842 -----------------------
6844 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6845 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6847 begin
6848 if Dynamic_Scope = Standard_Standard then
6849 return Standard_Standard;
6851 elsif Dynamic_Scope = Empty then
6852 return Empty;
6854 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6855 E_Generic_Package)
6856 then
6857 return Dynamic_Scope;
6859 else
6860 return Enclosing_Package (Dynamic_Scope);
6861 end if;
6862 end Enclosing_Package;
6864 -------------------------------------
6865 -- Enclosing_Package_Or_Subprogram --
6866 -------------------------------------
6868 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6869 S : Entity_Id;
6871 begin
6872 S := Scope (E);
6873 while Present (S) loop
6874 if Is_Package_Or_Generic_Package (S)
6875 or else Ekind (S) = E_Package_Body
6876 then
6877 return S;
6879 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6880 or else Ekind (S) = E_Subprogram_Body
6881 then
6882 return S;
6884 else
6885 S := Scope (S);
6886 end if;
6887 end loop;
6889 return Empty;
6890 end Enclosing_Package_Or_Subprogram;
6892 --------------------------
6893 -- Enclosing_Subprogram --
6894 --------------------------
6896 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6897 Dyn_Scop : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6899 begin
6900 if Dyn_Scop = Standard_Standard then
6901 return Empty;
6903 elsif Dyn_Scop = Empty then
6904 return Empty;
6906 elsif Ekind (Dyn_Scop) = E_Subprogram_Body then
6907 return Corresponding_Spec (Parent (Parent (Dyn_Scop)));
6909 elsif Ekind_In (Dyn_Scop, E_Block, E_Return_Statement) then
6910 return Enclosing_Subprogram (Dyn_Scop);
6912 elsif Ekind (Dyn_Scop) = E_Entry then
6914 -- For a task entry, return the enclosing subprogram of the
6915 -- task itself.
6917 if Ekind (Scope (Dyn_Scop)) = E_Task_Type then
6918 return Enclosing_Subprogram (Dyn_Scop);
6920 -- A protected entry is rewritten as a protected procedure which is
6921 -- the desired enclosing subprogram. This is relevant when unnesting
6922 -- a procedure local to an entry body.
6924 else
6925 return Protected_Body_Subprogram (Dyn_Scop);
6926 end if;
6928 elsif Ekind (Dyn_Scop) = E_Task_Type then
6929 return Get_Task_Body_Procedure (Dyn_Scop);
6931 -- The scope may appear as a private type or as a private extension
6932 -- whose completion is a task or protected type.
6934 elsif Ekind_In (Dyn_Scop, E_Limited_Private_Type,
6935 E_Record_Type_With_Private)
6936 and then Present (Full_View (Dyn_Scop))
6937 and then Ekind_In (Full_View (Dyn_Scop), E_Task_Type, E_Protected_Type)
6938 then
6939 return Get_Task_Body_Procedure (Full_View (Dyn_Scop));
6941 -- No body is generated if the protected operation is eliminated
6943 elsif Convention (Dyn_Scop) = Convention_Protected
6944 and then not Is_Eliminated (Dyn_Scop)
6945 and then Present (Protected_Body_Subprogram (Dyn_Scop))
6946 then
6947 return Protected_Body_Subprogram (Dyn_Scop);
6949 else
6950 return Dyn_Scop;
6951 end if;
6952 end Enclosing_Subprogram;
6954 --------------------------
6955 -- End_Keyword_Location --
6956 --------------------------
6958 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
6959 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
6960 -- Return the source location of Nod's end label according to the
6961 -- following precedence rules:
6963 -- 1) If the end label exists, return its location
6964 -- 2) If Nod exists, return its location
6965 -- 3) Return the location of N
6967 -------------------
6968 -- End_Label_Loc --
6969 -------------------
6971 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
6972 Label : Node_Id;
6974 begin
6975 if Present (Nod) then
6976 Label := End_Label (Nod);
6978 if Present (Label) then
6979 return Sloc (Label);
6980 else
6981 return Sloc (Nod);
6982 end if;
6984 else
6985 return Sloc (N);
6986 end if;
6987 end End_Label_Loc;
6989 -- Local variables
6991 Owner : Node_Id;
6993 -- Start of processing for End_Keyword_Location
6995 begin
6996 if Nkind_In (N, N_Block_Statement,
6997 N_Entry_Body,
6998 N_Package_Body,
6999 N_Subprogram_Body,
7000 N_Task_Body)
7001 then
7002 Owner := Handled_Statement_Sequence (N);
7004 elsif Nkind (N) = N_Package_Declaration then
7005 Owner := Specification (N);
7007 elsif Nkind (N) = N_Protected_Body then
7008 Owner := N;
7010 elsif Nkind_In (N, N_Protected_Type_Declaration,
7011 N_Single_Protected_Declaration)
7012 then
7013 Owner := Protected_Definition (N);
7015 elsif Nkind_In (N, N_Single_Task_Declaration,
7016 N_Task_Type_Declaration)
7017 then
7018 Owner := Task_Definition (N);
7020 -- This routine should not be called with other contexts
7022 else
7023 pragma Assert (False);
7024 null;
7025 end if;
7027 return End_Label_Loc (Owner);
7028 end End_Keyword_Location;
7030 ------------------------
7031 -- Ensure_Freeze_Node --
7032 ------------------------
7034 procedure Ensure_Freeze_Node (E : Entity_Id) is
7035 FN : Node_Id;
7036 begin
7037 if No (Freeze_Node (E)) then
7038 FN := Make_Freeze_Entity (Sloc (E));
7039 Set_Has_Delayed_Freeze (E);
7040 Set_Freeze_Node (E, FN);
7041 Set_Access_Types_To_Process (FN, No_Elist);
7042 Set_TSS_Elist (FN, No_Elist);
7043 Set_Entity (FN, E);
7044 end if;
7045 end Ensure_Freeze_Node;
7047 ----------------
7048 -- Enter_Name --
7049 ----------------
7051 procedure Enter_Name (Def_Id : Entity_Id) is
7052 C : constant Entity_Id := Current_Entity (Def_Id);
7053 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7054 S : constant Entity_Id := Current_Scope;
7056 begin
7057 Generate_Definition (Def_Id);
7059 -- Add new name to current scope declarations. Check for duplicate
7060 -- declaration, which may or may not be a genuine error.
7062 if Present (E) then
7064 -- Case of previous entity entered because of a missing declaration
7065 -- or else a bad subtype indication. Best is to use the new entity,
7066 -- and make the previous one invisible.
7068 if Etype (E) = Any_Type then
7069 Set_Is_Immediately_Visible (E, False);
7071 -- Case of renaming declaration constructed for package instances.
7072 -- if there is an explicit declaration with the same identifier,
7073 -- the renaming is not immediately visible any longer, but remains
7074 -- visible through selected component notation.
7076 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7077 and then not Comes_From_Source (E)
7078 then
7079 Set_Is_Immediately_Visible (E, False);
7081 -- The new entity may be the package renaming, which has the same
7082 -- same name as a generic formal which has been seen already.
7084 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7085 and then not Comes_From_Source (Def_Id)
7086 then
7087 Set_Is_Immediately_Visible (E, False);
7089 -- For a fat pointer corresponding to a remote access to subprogram,
7090 -- we use the same identifier as the RAS type, so that the proper
7091 -- name appears in the stub. This type is only retrieved through
7092 -- the RAS type and never by visibility, and is not added to the
7093 -- visibility list (see below).
7095 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7096 and then Ekind (Def_Id) = E_Record_Type
7097 and then Present (Corresponding_Remote_Type (Def_Id))
7098 then
7099 null;
7101 -- Case of an implicit operation or derived literal. The new entity
7102 -- hides the implicit one, which is removed from all visibility,
7103 -- i.e. the entity list of its scope, and homonym chain of its name.
7105 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7106 or else Is_Internal (E)
7107 then
7108 declare
7109 Decl : constant Node_Id := Parent (E);
7110 Prev : Entity_Id;
7111 Prev_Vis : Entity_Id;
7113 begin
7114 -- If E is an implicit declaration, it cannot be the first
7115 -- entity in the scope.
7117 Prev := First_Entity (Current_Scope);
7118 while Present (Prev) and then Next_Entity (Prev) /= E loop
7119 Next_Entity (Prev);
7120 end loop;
7122 if No (Prev) then
7124 -- If E is not on the entity chain of the current scope,
7125 -- it is an implicit declaration in the generic formal
7126 -- part of a generic subprogram. When analyzing the body,
7127 -- the generic formals are visible but not on the entity
7128 -- chain of the subprogram. The new entity will become
7129 -- the visible one in the body.
7131 pragma Assert
7132 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7133 null;
7135 else
7136 Link_Entities (Prev, Next_Entity (E));
7138 if No (Next_Entity (Prev)) then
7139 Set_Last_Entity (Current_Scope, Prev);
7140 end if;
7142 if E = Current_Entity (E) then
7143 Prev_Vis := Empty;
7145 else
7146 Prev_Vis := Current_Entity (E);
7147 while Homonym (Prev_Vis) /= E loop
7148 Prev_Vis := Homonym (Prev_Vis);
7149 end loop;
7150 end if;
7152 if Present (Prev_Vis) then
7154 -- Skip E in the visibility chain
7156 Set_Homonym (Prev_Vis, Homonym (E));
7158 else
7159 Set_Name_Entity_Id (Chars (E), Homonym (E));
7160 end if;
7161 end if;
7162 end;
7164 -- This section of code could use a comment ???
7166 elsif Present (Etype (E))
7167 and then Is_Concurrent_Type (Etype (E))
7168 and then E = Def_Id
7169 then
7170 return;
7172 -- If the homograph is a protected component renaming, it should not
7173 -- be hiding the current entity. Such renamings are treated as weak
7174 -- declarations.
7176 elsif Is_Prival (E) then
7177 Set_Is_Immediately_Visible (E, False);
7179 -- In this case the current entity is a protected component renaming.
7180 -- Perform minimal decoration by setting the scope and return since
7181 -- the prival should not be hiding other visible entities.
7183 elsif Is_Prival (Def_Id) then
7184 Set_Scope (Def_Id, Current_Scope);
7185 return;
7187 -- Analogous to privals, the discriminal generated for an entry index
7188 -- parameter acts as a weak declaration. Perform minimal decoration
7189 -- to avoid bogus errors.
7191 elsif Is_Discriminal (Def_Id)
7192 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7193 then
7194 Set_Scope (Def_Id, Current_Scope);
7195 return;
7197 -- In the body or private part of an instance, a type extension may
7198 -- introduce a component with the same name as that of an actual. The
7199 -- legality rule is not enforced, but the semantics of the full type
7200 -- with two components of same name are not clear at this point???
7202 elsif In_Instance_Not_Visible then
7203 null;
7205 -- When compiling a package body, some child units may have become
7206 -- visible. They cannot conflict with local entities that hide them.
7208 elsif Is_Child_Unit (E)
7209 and then In_Open_Scopes (Scope (E))
7210 and then not Is_Immediately_Visible (E)
7211 then
7212 null;
7214 -- Conversely, with front-end inlining we may compile the parent body
7215 -- first, and a child unit subsequently. The context is now the
7216 -- parent spec, and body entities are not visible.
7218 elsif Is_Child_Unit (Def_Id)
7219 and then Is_Package_Body_Entity (E)
7220 and then not In_Package_Body (Current_Scope)
7221 then
7222 null;
7224 -- Case of genuine duplicate declaration
7226 else
7227 Error_Msg_Sloc := Sloc (E);
7229 -- If the previous declaration is an incomplete type declaration
7230 -- this may be an attempt to complete it with a private type. The
7231 -- following avoids confusing cascaded errors.
7233 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7234 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7235 then
7236 Error_Msg_N
7237 ("incomplete type cannot be completed with a private " &
7238 "declaration", Parent (Def_Id));
7239 Set_Is_Immediately_Visible (E, False);
7240 Set_Full_View (E, Def_Id);
7242 -- An inherited component of a record conflicts with a new
7243 -- discriminant. The discriminant is inserted first in the scope,
7244 -- but the error should be posted on it, not on the component.
7246 elsif Ekind (E) = E_Discriminant
7247 and then Present (Scope (Def_Id))
7248 and then Scope (Def_Id) /= Current_Scope
7249 then
7250 Error_Msg_Sloc := Sloc (Def_Id);
7251 Error_Msg_N ("& conflicts with declaration#", E);
7252 return;
7254 -- If the name of the unit appears in its own context clause, a
7255 -- dummy package with the name has already been created, and the
7256 -- error emitted. Try to continue quietly.
7258 elsif Error_Posted (E)
7259 and then Sloc (E) = No_Location
7260 and then Nkind (Parent (E)) = N_Package_Specification
7261 and then Current_Scope = Standard_Standard
7262 then
7263 Set_Scope (Def_Id, Current_Scope);
7264 return;
7266 else
7267 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7269 -- Avoid cascaded messages with duplicate components in
7270 -- derived types.
7272 if Ekind_In (E, E_Component, E_Discriminant) then
7273 return;
7274 end if;
7275 end if;
7277 if Nkind (Parent (Parent (Def_Id))) =
7278 N_Generic_Subprogram_Declaration
7279 and then Def_Id =
7280 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7281 then
7282 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7283 end if;
7285 -- If entity is in standard, then we are in trouble, because it
7286 -- means that we have a library package with a duplicated name.
7287 -- That's hard to recover from, so abort.
7289 if S = Standard_Standard then
7290 raise Unrecoverable_Error;
7292 -- Otherwise we continue with the declaration. Having two
7293 -- identical declarations should not cause us too much trouble.
7295 else
7296 null;
7297 end if;
7298 end if;
7299 end if;
7301 -- If we fall through, declaration is OK, at least OK enough to continue
7303 -- If Def_Id is a discriminant or a record component we are in the midst
7304 -- of inheriting components in a derived record definition. Preserve
7305 -- their Ekind and Etype.
7307 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7308 null;
7310 -- If a type is already set, leave it alone (happens when a type
7311 -- declaration is reanalyzed following a call to the optimizer).
7313 elsif Present (Etype (Def_Id)) then
7314 null;
7316 -- Otherwise, the kind E_Void insures that premature uses of the entity
7317 -- will be detected. Any_Type insures that no cascaded errors will occur
7319 else
7320 Set_Ekind (Def_Id, E_Void);
7321 Set_Etype (Def_Id, Any_Type);
7322 end if;
7324 -- Inherited discriminants and components in derived record types are
7325 -- immediately visible. Itypes are not.
7327 -- Unless the Itype is for a record type with a corresponding remote
7328 -- type (what is that about, it was not commented ???)
7330 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7331 or else
7332 ((not Is_Record_Type (Def_Id)
7333 or else No (Corresponding_Remote_Type (Def_Id)))
7334 and then not Is_Itype (Def_Id))
7335 then
7336 Set_Is_Immediately_Visible (Def_Id);
7337 Set_Current_Entity (Def_Id);
7338 end if;
7340 Set_Homonym (Def_Id, C);
7341 Append_Entity (Def_Id, S);
7342 Set_Public_Status (Def_Id);
7344 -- Declaring a homonym is not allowed in SPARK ...
7346 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7347 declare
7348 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7349 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7350 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7352 begin
7353 -- ... unless the new declaration is in a subprogram, and the
7354 -- visible declaration is a variable declaration or a parameter
7355 -- specification outside that subprogram.
7357 if Present (Enclosing_Subp)
7358 and then Nkind_In (Parent (C), N_Object_Declaration,
7359 N_Parameter_Specification)
7360 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7361 then
7362 null;
7364 -- ... or the new declaration is in a package, and the visible
7365 -- declaration occurs outside that package.
7367 elsif Present (Enclosing_Pack)
7368 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7369 then
7370 null;
7372 -- ... or the new declaration is a component declaration in a
7373 -- record type definition.
7375 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7376 null;
7378 -- Don't issue error for non-source entities
7380 elsif Comes_From_Source (Def_Id)
7381 and then Comes_From_Source (C)
7382 then
7383 Error_Msg_Sloc := Sloc (C);
7384 Check_SPARK_05_Restriction
7385 ("redeclaration of identifier &#", Def_Id);
7386 end if;
7387 end;
7388 end if;
7390 -- Warn if new entity hides an old one
7392 if Warn_On_Hiding and then Present (C)
7394 -- Don't warn for record components since they always have a well
7395 -- defined scope which does not confuse other uses. Note that in
7396 -- some cases, Ekind has not been set yet.
7398 and then Ekind (C) /= E_Component
7399 and then Ekind (C) /= E_Discriminant
7400 and then Nkind (Parent (C)) /= N_Component_Declaration
7401 and then Ekind (Def_Id) /= E_Component
7402 and then Ekind (Def_Id) /= E_Discriminant
7403 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7405 -- Don't warn for one character variables. It is too common to use
7406 -- such variables as locals and will just cause too many false hits.
7408 and then Length_Of_Name (Chars (C)) /= 1
7410 -- Don't warn for non-source entities
7412 and then Comes_From_Source (C)
7413 and then Comes_From_Source (Def_Id)
7415 -- Don't warn unless entity in question is in extended main source
7417 and then In_Extended_Main_Source_Unit (Def_Id)
7419 -- Finally, the hidden entity must be either immediately visible or
7420 -- use visible (i.e. from a used package).
7422 and then
7423 (Is_Immediately_Visible (C)
7424 or else
7425 Is_Potentially_Use_Visible (C))
7426 then
7427 Error_Msg_Sloc := Sloc (C);
7428 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7429 end if;
7430 end Enter_Name;
7432 ---------------
7433 -- Entity_Of --
7434 ---------------
7436 function Entity_Of (N : Node_Id) return Entity_Id is
7437 Id : Entity_Id;
7438 Ren : Node_Id;
7440 begin
7441 -- Assume that the arbitrary node does not have an entity
7443 Id := Empty;
7445 if Is_Entity_Name (N) then
7446 Id := Entity (N);
7448 -- Follow a possible chain of renamings to reach the earliest renamed
7449 -- source object.
7451 while Present (Id)
7452 and then Is_Object (Id)
7453 and then Present (Renamed_Object (Id))
7454 loop
7455 Ren := Renamed_Object (Id);
7457 -- The reference renames an abstract state or a whole object
7459 -- Obj : ...;
7460 -- Ren : ... renames Obj;
7462 if Is_Entity_Name (Ren) then
7464 -- Do not follow a renaming that goes through a generic formal,
7465 -- because these entities are hidden and must not be referenced
7466 -- from outside the generic.
7468 if Is_Hidden (Entity (Ren)) then
7469 exit;
7471 else
7472 Id := Entity (Ren);
7473 end if;
7475 -- The reference renames a function result. Check the original
7476 -- node in case expansion relocates the function call.
7478 -- Ren : ... renames Func_Call;
7480 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7481 exit;
7483 -- Otherwise the reference renames something which does not yield
7484 -- an abstract state or a whole object. Treat the reference as not
7485 -- having a proper entity for SPARK legality purposes.
7487 else
7488 Id := Empty;
7489 exit;
7490 end if;
7491 end loop;
7492 end if;
7494 return Id;
7495 end Entity_Of;
7497 --------------------------
7498 -- Examine_Array_Bounds --
7499 --------------------------
7501 procedure Examine_Array_Bounds
7502 (Typ : Entity_Id;
7503 All_Static : out Boolean;
7504 Has_Empty : out Boolean)
7506 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7507 -- Determine whether bound Bound is a suitable static bound
7509 ------------------------
7510 -- Is_OK_Static_Bound --
7511 ------------------------
7513 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7514 begin
7515 return
7516 not Error_Posted (Bound)
7517 and then Is_OK_Static_Expression (Bound);
7518 end Is_OK_Static_Bound;
7520 -- Local variables
7522 Hi_Bound : Node_Id;
7523 Index : Node_Id;
7524 Lo_Bound : Node_Id;
7526 -- Start of processing for Examine_Array_Bounds
7528 begin
7529 -- An unconstrained array type does not have static bounds, and it is
7530 -- not known whether they are empty or not.
7532 if not Is_Constrained (Typ) then
7533 All_Static := False;
7534 Has_Empty := False;
7536 -- A string literal has static bounds, and is not empty as long as it
7537 -- contains at least one character.
7539 elsif Ekind (Typ) = E_String_Literal_Subtype then
7540 All_Static := True;
7541 Has_Empty := String_Literal_Length (Typ) > 0;
7542 end if;
7544 -- Assume that all bounds are static and not empty
7546 All_Static := True;
7547 Has_Empty := False;
7549 -- Examine each index
7551 Index := First_Index (Typ);
7552 while Present (Index) loop
7553 if Is_Discrete_Type (Etype (Index)) then
7554 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7556 if Is_OK_Static_Bound (Lo_Bound)
7557 and then
7558 Is_OK_Static_Bound (Hi_Bound)
7559 then
7560 -- The static bounds produce an empty range
7562 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7563 Has_Empty := True;
7564 end if;
7566 -- Otherwise at least one of the bounds is not static
7568 else
7569 All_Static := False;
7570 end if;
7572 -- Otherwise the index is non-discrete, therefore not static
7574 else
7575 All_Static := False;
7576 end if;
7578 Next_Index (Index);
7579 end loop;
7580 end Examine_Array_Bounds;
7582 --------------------------
7583 -- Explain_Limited_Type --
7584 --------------------------
7586 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7587 C : Entity_Id;
7589 begin
7590 -- For array, component type must be limited
7592 if Is_Array_Type (T) then
7593 Error_Msg_Node_2 := T;
7594 Error_Msg_NE
7595 ("\component type& of type& is limited", N, Component_Type (T));
7596 Explain_Limited_Type (Component_Type (T), N);
7598 elsif Is_Record_Type (T) then
7600 -- No need for extra messages if explicit limited record
7602 if Is_Limited_Record (Base_Type (T)) then
7603 return;
7604 end if;
7606 -- Otherwise find a limited component. Check only components that
7607 -- come from source, or inherited components that appear in the
7608 -- source of the ancestor.
7610 C := First_Component (T);
7611 while Present (C) loop
7612 if Is_Limited_Type (Etype (C))
7613 and then
7614 (Comes_From_Source (C)
7615 or else
7616 (Present (Original_Record_Component (C))
7617 and then
7618 Comes_From_Source (Original_Record_Component (C))))
7619 then
7620 Error_Msg_Node_2 := T;
7621 Error_Msg_NE ("\component& of type& has limited type", N, C);
7622 Explain_Limited_Type (Etype (C), N);
7623 return;
7624 end if;
7626 Next_Component (C);
7627 end loop;
7629 -- The type may be declared explicitly limited, even if no component
7630 -- of it is limited, in which case we fall out of the loop.
7631 return;
7632 end if;
7633 end Explain_Limited_Type;
7635 ---------------------------------------
7636 -- Expression_Of_Expression_Function --
7637 ---------------------------------------
7639 function Expression_Of_Expression_Function
7640 (Subp : Entity_Id) return Node_Id
7642 Expr_Func : Node_Id;
7644 begin
7645 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7647 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7648 N_Expression_Function
7649 then
7650 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7652 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7653 N_Expression_Function
7654 then
7655 Expr_Func := Original_Node (Subprogram_Body (Subp));
7657 else
7658 pragma Assert (False);
7659 null;
7660 end if;
7662 return Original_Node (Expression (Expr_Func));
7663 end Expression_Of_Expression_Function;
7665 -------------------------------
7666 -- Extensions_Visible_Status --
7667 -------------------------------
7669 function Extensions_Visible_Status
7670 (Id : Entity_Id) return Extensions_Visible_Mode
7672 Arg : Node_Id;
7673 Decl : Node_Id;
7674 Expr : Node_Id;
7675 Prag : Node_Id;
7676 Subp : Entity_Id;
7678 begin
7679 -- When a formal parameter is subject to Extensions_Visible, the pragma
7680 -- is stored in the contract of related subprogram.
7682 if Is_Formal (Id) then
7683 Subp := Scope (Id);
7685 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7686 Subp := Id;
7688 -- No other construct carries this pragma
7690 else
7691 return Extensions_Visible_None;
7692 end if;
7694 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7696 -- In certain cases analysis may request the Extensions_Visible status
7697 -- of an expression function before the pragma has been analyzed yet.
7698 -- Inspect the declarative items after the expression function looking
7699 -- for the pragma (if any).
7701 if No (Prag) and then Is_Expression_Function (Subp) then
7702 Decl := Next (Unit_Declaration_Node (Subp));
7703 while Present (Decl) loop
7704 if Nkind (Decl) = N_Pragma
7705 and then Pragma_Name (Decl) = Name_Extensions_Visible
7706 then
7707 Prag := Decl;
7708 exit;
7710 -- A source construct ends the region where Extensions_Visible may
7711 -- appear, stop the traversal. An expanded expression function is
7712 -- no longer a source construct, but it must still be recognized.
7714 elsif Comes_From_Source (Decl)
7715 or else
7716 (Nkind_In (Decl, N_Subprogram_Body,
7717 N_Subprogram_Declaration)
7718 and then Is_Expression_Function (Defining_Entity (Decl)))
7719 then
7720 exit;
7721 end if;
7723 Next (Decl);
7724 end loop;
7725 end if;
7727 -- Extract the value from the Boolean expression (if any)
7729 if Present (Prag) then
7730 Arg := First (Pragma_Argument_Associations (Prag));
7732 if Present (Arg) then
7733 Expr := Get_Pragma_Arg (Arg);
7735 -- When the associated subprogram is an expression function, the
7736 -- argument of the pragma may not have been analyzed.
7738 if not Analyzed (Expr) then
7739 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7740 end if;
7742 -- Guard against cascading errors when the argument of pragma
7743 -- Extensions_Visible is not a valid static Boolean expression.
7745 if Error_Posted (Expr) then
7746 return Extensions_Visible_None;
7748 elsif Is_True (Expr_Value (Expr)) then
7749 return Extensions_Visible_True;
7751 else
7752 return Extensions_Visible_False;
7753 end if;
7755 -- Otherwise the aspect or pragma defaults to True
7757 else
7758 return Extensions_Visible_True;
7759 end if;
7761 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7762 -- directly specified. In SPARK code, its value defaults to "False".
7764 elsif SPARK_Mode = On then
7765 return Extensions_Visible_False;
7767 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7768 -- "True".
7770 else
7771 return Extensions_Visible_True;
7772 end if;
7773 end Extensions_Visible_Status;
7775 -----------------
7776 -- Find_Actual --
7777 -----------------
7779 procedure Find_Actual
7780 (N : Node_Id;
7781 Formal : out Entity_Id;
7782 Call : out Node_Id)
7784 Context : constant Node_Id := Parent (N);
7785 Actual : Node_Id;
7786 Call_Nam : Node_Id;
7788 begin
7789 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7790 and then N = Prefix (Context)
7791 then
7792 Find_Actual (Context, Formal, Call);
7793 return;
7795 elsif Nkind (Context) = N_Parameter_Association
7796 and then N = Explicit_Actual_Parameter (Context)
7797 then
7798 Call := Parent (Context);
7800 elsif Nkind_In (Context, N_Entry_Call_Statement,
7801 N_Function_Call,
7802 N_Procedure_Call_Statement)
7803 then
7804 Call := Context;
7806 else
7807 Formal := Empty;
7808 Call := Empty;
7809 return;
7810 end if;
7812 -- If we have a call to a subprogram look for the parameter. Note that
7813 -- we exclude overloaded calls, since we don't know enough to be sure
7814 -- of giving the right answer in this case.
7816 if Nkind_In (Call, N_Entry_Call_Statement,
7817 N_Function_Call,
7818 N_Procedure_Call_Statement)
7819 then
7820 Call_Nam := Name (Call);
7822 -- A call to a protected or task entry appears as a selected
7823 -- component rather than an expanded name.
7825 if Nkind (Call_Nam) = N_Selected_Component then
7826 Call_Nam := Selector_Name (Call_Nam);
7827 end if;
7829 if Is_Entity_Name (Call_Nam)
7830 and then Present (Entity (Call_Nam))
7831 and then Is_Overloadable (Entity (Call_Nam))
7832 and then not Is_Overloaded (Call_Nam)
7833 then
7834 -- If node is name in call it is not an actual
7836 if N = Call_Nam then
7837 Formal := Empty;
7838 Call := Empty;
7839 return;
7840 end if;
7842 -- Fall here if we are definitely a parameter
7844 Actual := First_Actual (Call);
7845 Formal := First_Formal (Entity (Call_Nam));
7846 while Present (Formal) and then Present (Actual) loop
7847 if Actual = N then
7848 return;
7850 -- An actual that is the prefix in a prefixed call may have
7851 -- been rewritten in the call, after the deferred reference
7852 -- was collected. Check if sloc and kinds and names match.
7854 elsif Sloc (Actual) = Sloc (N)
7855 and then Nkind (Actual) = N_Identifier
7856 and then Nkind (Actual) = Nkind (N)
7857 and then Chars (Actual) = Chars (N)
7858 then
7859 return;
7861 else
7862 Actual := Next_Actual (Actual);
7863 Formal := Next_Formal (Formal);
7864 end if;
7865 end loop;
7866 end if;
7867 end if;
7869 -- Fall through here if we did not find matching actual
7871 Formal := Empty;
7872 Call := Empty;
7873 end Find_Actual;
7875 ---------------------------
7876 -- Find_Body_Discriminal --
7877 ---------------------------
7879 function Find_Body_Discriminal
7880 (Spec_Discriminant : Entity_Id) return Entity_Id
7882 Tsk : Entity_Id;
7883 Disc : Entity_Id;
7885 begin
7886 -- If expansion is suppressed, then the scope can be the concurrent type
7887 -- itself rather than a corresponding concurrent record type.
7889 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7890 Tsk := Scope (Spec_Discriminant);
7892 else
7893 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7895 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7896 end if;
7898 -- Find discriminant of original concurrent type, and use its current
7899 -- discriminal, which is the renaming within the task/protected body.
7901 Disc := First_Discriminant (Tsk);
7902 while Present (Disc) loop
7903 if Chars (Disc) = Chars (Spec_Discriminant) then
7904 return Discriminal (Disc);
7905 end if;
7907 Next_Discriminant (Disc);
7908 end loop;
7910 -- That loop should always succeed in finding a matching entry and
7911 -- returning. Fatal error if not.
7913 raise Program_Error;
7914 end Find_Body_Discriminal;
7916 -------------------------------------
7917 -- Find_Corresponding_Discriminant --
7918 -------------------------------------
7920 function Find_Corresponding_Discriminant
7921 (Id : Node_Id;
7922 Typ : Entity_Id) return Entity_Id
7924 Par_Disc : Entity_Id;
7925 Old_Disc : Entity_Id;
7926 New_Disc : Entity_Id;
7928 begin
7929 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7931 -- The original type may currently be private, and the discriminant
7932 -- only appear on its full view.
7934 if Is_Private_Type (Scope (Par_Disc))
7935 and then not Has_Discriminants (Scope (Par_Disc))
7936 and then Present (Full_View (Scope (Par_Disc)))
7937 then
7938 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7939 else
7940 Old_Disc := First_Discriminant (Scope (Par_Disc));
7941 end if;
7943 if Is_Class_Wide_Type (Typ) then
7944 New_Disc := First_Discriminant (Root_Type (Typ));
7945 else
7946 New_Disc := First_Discriminant (Typ);
7947 end if;
7949 while Present (Old_Disc) and then Present (New_Disc) loop
7950 if Old_Disc = Par_Disc then
7951 return New_Disc;
7952 end if;
7954 Next_Discriminant (Old_Disc);
7955 Next_Discriminant (New_Disc);
7956 end loop;
7958 -- Should always find it
7960 raise Program_Error;
7961 end Find_Corresponding_Discriminant;
7963 -------------------
7964 -- Find_DIC_Type --
7965 -------------------
7967 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
7968 Curr_Typ : Entity_Id;
7969 -- The current type being examined in the parent hierarchy traversal
7971 DIC_Typ : Entity_Id;
7972 -- The type which carries the DIC pragma. This variable denotes the
7973 -- partial view when private types are involved.
7975 Par_Typ : Entity_Id;
7976 -- The parent type of the current type. This variable denotes the full
7977 -- view when private types are involved.
7979 begin
7980 -- The input type defines its own DIC pragma, therefore it is the owner
7982 if Has_Own_DIC (Typ) then
7983 DIC_Typ := Typ;
7985 -- Otherwise the DIC pragma is inherited from a parent type
7987 else
7988 pragma Assert (Has_Inherited_DIC (Typ));
7990 -- Climb the parent chain
7992 Curr_Typ := Typ;
7993 loop
7994 -- Inspect the parent type. Do not consider subtypes as they
7995 -- inherit the DIC attributes from their base types.
7997 DIC_Typ := Base_Type (Etype (Curr_Typ));
7999 -- Look at the full view of a private type because the type may
8000 -- have a hidden parent introduced in the full view.
8002 Par_Typ := DIC_Typ;
8004 if Is_Private_Type (Par_Typ)
8005 and then Present (Full_View (Par_Typ))
8006 then
8007 Par_Typ := Full_View (Par_Typ);
8008 end if;
8010 -- Stop the climb once the nearest parent type which defines a DIC
8011 -- pragma of its own is encountered or when the root of the parent
8012 -- chain is reached.
8014 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
8016 Curr_Typ := Par_Typ;
8017 end loop;
8018 end if;
8020 return DIC_Typ;
8021 end Find_DIC_Type;
8023 ----------------------------------
8024 -- Find_Enclosing_Iterator_Loop --
8025 ----------------------------------
8027 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8028 Constr : Node_Id;
8029 S : Entity_Id;
8031 begin
8032 -- Traverse the scope chain looking for an iterator loop. Such loops are
8033 -- usually transformed into blocks, hence the use of Original_Node.
8035 S := Id;
8036 while Present (S) and then S /= Standard_Standard loop
8037 if Ekind (S) = E_Loop
8038 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8039 then
8040 Constr := Original_Node (Label_Construct (Parent (S)));
8042 if Nkind (Constr) = N_Loop_Statement
8043 and then Present (Iteration_Scheme (Constr))
8044 and then Nkind (Iterator_Specification
8045 (Iteration_Scheme (Constr))) =
8046 N_Iterator_Specification
8047 then
8048 return S;
8049 end if;
8050 end if;
8052 S := Scope (S);
8053 end loop;
8055 return Empty;
8056 end Find_Enclosing_Iterator_Loop;
8058 --------------------------
8059 -- Find_Enclosing_Scope --
8060 --------------------------
8062 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
8063 Par : Node_Id;
8065 begin
8066 -- Examine the parent chain looking for a construct which defines a
8067 -- scope.
8069 Par := Parent (N);
8070 while Present (Par) loop
8071 case Nkind (Par) is
8073 -- The construct denotes a declaration, the proper scope is its
8074 -- entity.
8076 when N_Entry_Declaration
8077 | N_Expression_Function
8078 | N_Full_Type_Declaration
8079 | N_Generic_Package_Declaration
8080 | N_Generic_Subprogram_Declaration
8081 | N_Package_Declaration
8082 | N_Private_Extension_Declaration
8083 | N_Protected_Type_Declaration
8084 | N_Single_Protected_Declaration
8085 | N_Single_Task_Declaration
8086 | N_Subprogram_Declaration
8087 | N_Task_Type_Declaration
8089 return Defining_Entity (Par);
8091 -- The construct denotes a body, the proper scope is the entity of
8092 -- the corresponding spec or that of the body if the body does not
8093 -- complete a previous declaration.
8095 when N_Entry_Body
8096 | N_Package_Body
8097 | N_Protected_Body
8098 | N_Subprogram_Body
8099 | N_Task_Body
8101 return Unique_Defining_Entity (Par);
8103 -- Special cases
8105 -- Blocks carry either a source or an internally-generated scope,
8106 -- unless the block is a byproduct of exception handling.
8108 when N_Block_Statement =>
8109 if not Exception_Junk (Par) then
8110 return Entity (Identifier (Par));
8111 end if;
8113 -- Loops carry an internally-generated scope
8115 when N_Loop_Statement =>
8116 return Entity (Identifier (Par));
8118 -- Extended return statements carry an internally-generated scope
8120 when N_Extended_Return_Statement =>
8121 return Return_Statement_Entity (Par);
8123 -- A traversal from a subunit continues via the corresponding stub
8125 when N_Subunit =>
8126 Par := Corresponding_Stub (Par);
8128 when others =>
8129 null;
8130 end case;
8132 Par := Parent (Par);
8133 end loop;
8135 return Standard_Standard;
8136 end Find_Enclosing_Scope;
8138 ------------------------------------
8139 -- Find_Loop_In_Conditional_Block --
8140 ------------------------------------
8142 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8143 Stmt : Node_Id;
8145 begin
8146 Stmt := N;
8148 if Nkind (Stmt) = N_If_Statement then
8149 Stmt := First (Then_Statements (Stmt));
8150 end if;
8152 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8154 -- Inspect the statements of the conditional block. In general the loop
8155 -- should be the first statement in the statement sequence of the block,
8156 -- but the finalization machinery may have introduced extra object
8157 -- declarations.
8159 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8160 while Present (Stmt) loop
8161 if Nkind (Stmt) = N_Loop_Statement then
8162 return Stmt;
8163 end if;
8165 Next (Stmt);
8166 end loop;
8168 -- The expansion of attribute 'Loop_Entry produced a malformed block
8170 raise Program_Error;
8171 end Find_Loop_In_Conditional_Block;
8173 --------------------------
8174 -- Find_Overlaid_Entity --
8175 --------------------------
8177 procedure Find_Overlaid_Entity
8178 (N : Node_Id;
8179 Ent : out Entity_Id;
8180 Off : out Boolean)
8182 Expr : Node_Id;
8184 begin
8185 -- We are looking for one of the two following forms:
8187 -- for X'Address use Y'Address
8189 -- or
8191 -- Const : constant Address := expr;
8192 -- ...
8193 -- for X'Address use Const;
8195 -- In the second case, the expr is either Y'Address, or recursively a
8196 -- constant that eventually references Y'Address.
8198 Ent := Empty;
8199 Off := False;
8201 if Nkind (N) = N_Attribute_Definition_Clause
8202 and then Chars (N) = Name_Address
8203 then
8204 Expr := Expression (N);
8206 -- This loop checks the form of the expression for Y'Address,
8207 -- using recursion to deal with intermediate constants.
8209 loop
8210 -- Check for Y'Address
8212 if Nkind (Expr) = N_Attribute_Reference
8213 and then Attribute_Name (Expr) = Name_Address
8214 then
8215 Expr := Prefix (Expr);
8216 exit;
8218 -- Check for Const where Const is a constant entity
8220 elsif Is_Entity_Name (Expr)
8221 and then Ekind (Entity (Expr)) = E_Constant
8222 then
8223 Expr := Constant_Value (Entity (Expr));
8225 -- Anything else does not need checking
8227 else
8228 return;
8229 end if;
8230 end loop;
8232 -- This loop checks the form of the prefix for an entity, using
8233 -- recursion to deal with intermediate components.
8235 loop
8236 -- Check for Y where Y is an entity
8238 if Is_Entity_Name (Expr) then
8239 Ent := Entity (Expr);
8240 return;
8242 -- Check for components
8244 elsif
8245 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8246 then
8247 Expr := Prefix (Expr);
8248 Off := True;
8250 -- Anything else does not need checking
8252 else
8253 return;
8254 end if;
8255 end loop;
8256 end if;
8257 end Find_Overlaid_Entity;
8259 -------------------------
8260 -- Find_Parameter_Type --
8261 -------------------------
8263 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8264 begin
8265 if Nkind (Param) /= N_Parameter_Specification then
8266 return Empty;
8268 -- For an access parameter, obtain the type from the formal entity
8269 -- itself, because access to subprogram nodes do not carry a type.
8270 -- Shouldn't we always use the formal entity ???
8272 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8273 return Etype (Defining_Identifier (Param));
8275 else
8276 return Etype (Parameter_Type (Param));
8277 end if;
8278 end Find_Parameter_Type;
8280 -----------------------------------
8281 -- Find_Placement_In_State_Space --
8282 -----------------------------------
8284 procedure Find_Placement_In_State_Space
8285 (Item_Id : Entity_Id;
8286 Placement : out State_Space_Kind;
8287 Pack_Id : out Entity_Id)
8289 Context : Entity_Id;
8291 begin
8292 -- Assume that the item does not appear in the state space of a package
8294 Placement := Not_In_Package;
8295 Pack_Id := Empty;
8297 -- Climb the scope stack and examine the enclosing context
8299 Context := Scope (Item_Id);
8300 while Present (Context) and then Context /= Standard_Standard loop
8301 if Is_Package_Or_Generic_Package (Context) then
8302 Pack_Id := Context;
8304 -- A package body is a cut off point for the traversal as the item
8305 -- cannot be visible to the outside from this point on. Note that
8306 -- this test must be done first as a body is also classified as a
8307 -- private part.
8309 if In_Package_Body (Context) then
8310 Placement := Body_State_Space;
8311 return;
8313 -- The private part of a package is a cut off point for the
8314 -- traversal as the item cannot be visible to the outside from
8315 -- this point on.
8317 elsif In_Private_Part (Context) then
8318 Placement := Private_State_Space;
8319 return;
8321 -- When the item appears in the visible state space of a package,
8322 -- continue to climb the scope stack as this may not be the final
8323 -- state space.
8325 else
8326 Placement := Visible_State_Space;
8328 -- The visible state space of a child unit acts as the proper
8329 -- placement of an item.
8331 if Is_Child_Unit (Context) then
8332 return;
8333 end if;
8334 end if;
8336 -- The item or its enclosing package appear in a construct that has
8337 -- no state space.
8339 else
8340 Placement := Not_In_Package;
8341 return;
8342 end if;
8344 Context := Scope (Context);
8345 end loop;
8346 end Find_Placement_In_State_Space;
8348 -----------------------
8349 -- Find_Primitive_Eq --
8350 -----------------------
8352 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
8353 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
8354 -- Search for the equality primitive; return Empty if the primitive is
8355 -- not found.
8357 ------------------
8358 -- Find_Eq_Prim --
8359 ------------------
8361 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
8362 Prim : Entity_Id;
8363 Prim_Elmt : Elmt_Id;
8365 begin
8366 Prim_Elmt := First_Elmt (Prims_List);
8367 while Present (Prim_Elmt) loop
8368 Prim := Node (Prim_Elmt);
8370 -- Locate primitive equality with the right signature
8372 if Chars (Prim) = Name_Op_Eq
8373 and then Etype (First_Formal (Prim)) =
8374 Etype (Next_Formal (First_Formal (Prim)))
8375 and then Base_Type (Etype (Prim)) = Standard_Boolean
8376 then
8377 return Prim;
8378 end if;
8380 Next_Elmt (Prim_Elmt);
8381 end loop;
8383 return Empty;
8384 end Find_Eq_Prim;
8386 -- Local Variables
8388 Eq_Prim : Entity_Id;
8389 Full_Type : Entity_Id;
8391 -- Start of processing for Find_Primitive_Eq
8393 begin
8394 if Is_Private_Type (Typ) then
8395 Full_Type := Underlying_Type (Typ);
8396 else
8397 Full_Type := Typ;
8398 end if;
8400 if No (Full_Type) then
8401 return Empty;
8402 end if;
8404 Full_Type := Base_Type (Full_Type);
8406 -- When the base type itself is private, use the full view
8408 if Is_Private_Type (Full_Type) then
8409 Full_Type := Underlying_Type (Full_Type);
8410 end if;
8412 if Is_Class_Wide_Type (Full_Type) then
8413 Full_Type := Root_Type (Full_Type);
8414 end if;
8416 if not Is_Tagged_Type (Full_Type) then
8417 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8419 -- If this is an untagged private type completed with a derivation of
8420 -- an untagged private type whose full view is a tagged type, we use
8421 -- the primitive operations of the private parent type (since it does
8422 -- not have a full view, and also because its equality primitive may
8423 -- have been overridden in its untagged full view). If no equality was
8424 -- defined for it then take its dispatching equality primitive.
8426 elsif Inherits_From_Tagged_Full_View (Typ) then
8427 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8429 if No (Eq_Prim) then
8430 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8431 end if;
8433 else
8434 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8435 end if;
8437 return Eq_Prim;
8438 end Find_Primitive_Eq;
8440 ------------------------
8441 -- Find_Specific_Type --
8442 ------------------------
8444 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8445 Typ : Entity_Id := Root_Type (CW);
8447 begin
8448 if Ekind (Typ) = E_Incomplete_Type then
8449 if From_Limited_With (Typ) then
8450 Typ := Non_Limited_View (Typ);
8451 else
8452 Typ := Full_View (Typ);
8453 end if;
8454 end if;
8456 if Is_Private_Type (Typ)
8457 and then not Is_Tagged_Type (Typ)
8458 and then Present (Full_View (Typ))
8459 then
8460 return Full_View (Typ);
8461 else
8462 return Typ;
8463 end if;
8464 end Find_Specific_Type;
8466 -----------------------------
8467 -- Find_Static_Alternative --
8468 -----------------------------
8470 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8471 Expr : constant Node_Id := Expression (N);
8472 Val : constant Uint := Expr_Value (Expr);
8473 Alt : Node_Id;
8474 Choice : Node_Id;
8476 begin
8477 Alt := First (Alternatives (N));
8479 Search : loop
8480 if Nkind (Alt) /= N_Pragma then
8481 Choice := First (Discrete_Choices (Alt));
8482 while Present (Choice) loop
8484 -- Others choice, always matches
8486 if Nkind (Choice) = N_Others_Choice then
8487 exit Search;
8489 -- Range, check if value is in the range
8491 elsif Nkind (Choice) = N_Range then
8492 exit Search when
8493 Val >= Expr_Value (Low_Bound (Choice))
8494 and then
8495 Val <= Expr_Value (High_Bound (Choice));
8497 -- Choice is a subtype name. Note that we know it must
8498 -- be a static subtype, since otherwise it would have
8499 -- been diagnosed as illegal.
8501 elsif Is_Entity_Name (Choice)
8502 and then Is_Type (Entity (Choice))
8503 then
8504 exit Search when Is_In_Range (Expr, Etype (Choice),
8505 Assume_Valid => False);
8507 -- Choice is a subtype indication
8509 elsif Nkind (Choice) = N_Subtype_Indication then
8510 declare
8511 C : constant Node_Id := Constraint (Choice);
8512 R : constant Node_Id := Range_Expression (C);
8514 begin
8515 exit Search when
8516 Val >= Expr_Value (Low_Bound (R))
8517 and then
8518 Val <= Expr_Value (High_Bound (R));
8519 end;
8521 -- Choice is a simple expression
8523 else
8524 exit Search when Val = Expr_Value (Choice);
8525 end if;
8527 Next (Choice);
8528 end loop;
8529 end if;
8531 Next (Alt);
8532 pragma Assert (Present (Alt));
8533 end loop Search;
8535 -- The above loop *must* terminate by finding a match, since we know the
8536 -- case statement is valid, and the value of the expression is known at
8537 -- compile time. When we fall out of the loop, Alt points to the
8538 -- alternative that we know will be selected at run time.
8540 return Alt;
8541 end Find_Static_Alternative;
8543 ------------------
8544 -- First_Actual --
8545 ------------------
8547 function First_Actual (Node : Node_Id) return Node_Id is
8548 N : Node_Id;
8550 begin
8551 if No (Parameter_Associations (Node)) then
8552 return Empty;
8553 end if;
8555 N := First (Parameter_Associations (Node));
8557 if Nkind (N) = N_Parameter_Association then
8558 return First_Named_Actual (Node);
8559 else
8560 return N;
8561 end if;
8562 end First_Actual;
8564 ------------------
8565 -- First_Global --
8566 ------------------
8568 function First_Global
8569 (Subp : Entity_Id;
8570 Global_Mode : Name_Id;
8571 Refined : Boolean := False) return Node_Id
8573 function First_From_Global_List
8574 (List : Node_Id;
8575 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8576 -- Get the first item with suitable mode from List
8578 ----------------------------
8579 -- First_From_Global_List --
8580 ----------------------------
8582 function First_From_Global_List
8583 (List : Node_Id;
8584 Global_Mode : Name_Id := Name_Input) return Entity_Id
8586 Assoc : Node_Id;
8588 begin
8589 -- Empty list (no global items)
8591 if Nkind (List) = N_Null then
8592 return Empty;
8594 -- Single global item declaration (only input items)
8596 elsif Nkind_In (List, N_Expanded_Name, N_Identifier) then
8597 if Global_Mode = Name_Input then
8598 return List;
8599 else
8600 return Empty;
8601 end if;
8603 -- Simple global list (only input items) or moded global list
8604 -- declaration.
8606 elsif Nkind (List) = N_Aggregate then
8607 if Present (Expressions (List)) then
8608 if Global_Mode = Name_Input then
8609 return First (Expressions (List));
8610 else
8611 return Empty;
8612 end if;
8614 else
8615 Assoc := First (Component_Associations (List));
8616 while Present (Assoc) loop
8618 -- When we find the desired mode in an association, call
8619 -- recursively First_From_Global_List as if the mode was
8620 -- Name_Input, in order to reuse the existing machinery
8621 -- for the other cases.
8623 if Chars (First (Choices (Assoc))) = Global_Mode then
8624 return First_From_Global_List (Expression (Assoc));
8625 end if;
8627 Next (Assoc);
8628 end loop;
8630 return Empty;
8631 end if;
8633 -- To accommodate partial decoration of disabled SPARK features,
8634 -- this routine may be called with illegal input. If this is the
8635 -- case, do not raise Program_Error.
8637 else
8638 return Empty;
8639 end if;
8640 end First_From_Global_List;
8642 -- Local variables
8644 Global : Node_Id := Empty;
8645 Body_Id : Entity_Id;
8647 begin
8648 pragma Assert (Nam_In (Global_Mode, Name_In_Out,
8649 Name_Input,
8650 Name_Output,
8651 Name_Proof_In));
8653 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8654 -- case, it can only be located on the body entity.
8656 if Refined then
8657 Body_Id := Subprogram_Body_Entity (Subp);
8658 if Present (Body_Id) then
8659 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8660 end if;
8661 else
8662 Global := Get_Pragma (Subp, Pragma_Global);
8663 end if;
8665 -- No corresponding global if pragma is not present
8667 if No (Global) then
8668 return Empty;
8670 -- Otherwise retrieve the corresponding list of items depending on the
8671 -- Global_Mode.
8673 else
8674 return First_From_Global_List
8675 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8676 end if;
8677 end First_Global;
8679 -------------
8680 -- Fix_Msg --
8681 -------------
8683 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8684 Is_Task : constant Boolean :=
8685 Ekind_In (Id, E_Task_Body, E_Task_Type)
8686 or else Is_Single_Task_Object (Id);
8687 Msg_Last : constant Natural := Msg'Last;
8688 Msg_Index : Natural;
8689 Res : String (Msg'Range) := (others => ' ');
8690 Res_Index : Natural;
8692 begin
8693 -- Copy all characters from the input message Msg to result Res with
8694 -- suitable replacements.
8696 Msg_Index := Msg'First;
8697 Res_Index := Res'First;
8698 while Msg_Index <= Msg_Last loop
8700 -- Replace "subprogram" with a different word
8702 if Msg_Index <= Msg_Last - 10
8703 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8704 then
8705 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8706 Res (Res_Index .. Res_Index + 4) := "entry";
8707 Res_Index := Res_Index + 5;
8709 elsif Is_Task then
8710 Res (Res_Index .. Res_Index + 8) := "task type";
8711 Res_Index := Res_Index + 9;
8713 else
8714 Res (Res_Index .. Res_Index + 9) := "subprogram";
8715 Res_Index := Res_Index + 10;
8716 end if;
8718 Msg_Index := Msg_Index + 10;
8720 -- Replace "protected" with a different word
8722 elsif Msg_Index <= Msg_Last - 9
8723 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8724 and then Is_Task
8725 then
8726 Res (Res_Index .. Res_Index + 3) := "task";
8727 Res_Index := Res_Index + 4;
8728 Msg_Index := Msg_Index + 9;
8730 -- Otherwise copy the character
8732 else
8733 Res (Res_Index) := Msg (Msg_Index);
8734 Msg_Index := Msg_Index + 1;
8735 Res_Index := Res_Index + 1;
8736 end if;
8737 end loop;
8739 return Res (Res'First .. Res_Index - 1);
8740 end Fix_Msg;
8742 -------------------------
8743 -- From_Nested_Package --
8744 -------------------------
8746 function From_Nested_Package (T : Entity_Id) return Boolean is
8747 Pack : constant Entity_Id := Scope (T);
8749 begin
8750 return
8751 Ekind (Pack) = E_Package
8752 and then not Is_Frozen (Pack)
8753 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8754 and then In_Open_Scopes (Scope (Pack));
8755 end From_Nested_Package;
8757 -----------------------
8758 -- Gather_Components --
8759 -----------------------
8761 procedure Gather_Components
8762 (Typ : Entity_Id;
8763 Comp_List : Node_Id;
8764 Governed_By : List_Id;
8765 Into : Elist_Id;
8766 Report_Errors : out Boolean)
8768 Assoc : Node_Id;
8769 Variant : Node_Id;
8770 Discrete_Choice : Node_Id;
8771 Comp_Item : Node_Id;
8773 Discrim : Entity_Id;
8774 Discrim_Name : Node_Id;
8775 Discrim_Value : Node_Id;
8777 begin
8778 Report_Errors := False;
8780 if No (Comp_List) or else Null_Present (Comp_List) then
8781 return;
8783 elsif Present (Component_Items (Comp_List)) then
8784 Comp_Item := First (Component_Items (Comp_List));
8786 else
8787 Comp_Item := Empty;
8788 end if;
8790 while Present (Comp_Item) loop
8792 -- Skip the tag of a tagged record, the interface tags, as well
8793 -- as all items that are not user components (anonymous types,
8794 -- rep clauses, Parent field, controller field).
8796 if Nkind (Comp_Item) = N_Component_Declaration then
8797 declare
8798 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8799 begin
8800 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8801 Append_Elmt (Comp, Into);
8802 end if;
8803 end;
8804 end if;
8806 Next (Comp_Item);
8807 end loop;
8809 if No (Variant_Part (Comp_List)) then
8810 return;
8811 else
8812 Discrim_Name := Name (Variant_Part (Comp_List));
8813 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8814 end if;
8816 -- Look for the discriminant that governs this variant part.
8817 -- The discriminant *must* be in the Governed_By List
8819 Assoc := First (Governed_By);
8820 Find_Constraint : loop
8821 Discrim := First (Choices (Assoc));
8822 exit Find_Constraint when
8823 Chars (Discrim_Name) = Chars (Discrim)
8824 or else
8825 (Present (Corresponding_Discriminant (Entity (Discrim)))
8826 and then Chars (Corresponding_Discriminant
8827 (Entity (Discrim))) = Chars (Discrim_Name))
8828 or else
8829 Chars (Original_Record_Component (Entity (Discrim))) =
8830 Chars (Discrim_Name);
8832 if No (Next (Assoc)) then
8833 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
8835 -- If the type is a tagged type with inherited discriminants,
8836 -- use the stored constraint on the parent in order to find
8837 -- the values of discriminants that are otherwise hidden by an
8838 -- explicit constraint. Renamed discriminants are handled in
8839 -- the code above.
8841 -- If several parent discriminants are renamed by a single
8842 -- discriminant of the derived type, the call to obtain the
8843 -- Corresponding_Discriminant field only retrieves the last
8844 -- of them. We recover the constraint on the others from the
8845 -- Stored_Constraint as well.
8847 -- An inherited discriminant may have been constrained in a
8848 -- later ancestor (not the immediate parent) so we must examine
8849 -- the stored constraint of all of them to locate the inherited
8850 -- value.
8852 declare
8853 C : Elmt_Id;
8854 D : Entity_Id;
8855 T : Entity_Id := Typ;
8857 begin
8858 while Is_Derived_Type (T) loop
8859 if Present (Stored_Constraint (T)) then
8860 D := First_Discriminant (Etype (T));
8861 C := First_Elmt (Stored_Constraint (T));
8862 while Present (D) and then Present (C) loop
8863 if Chars (Discrim_Name) = Chars (D) then
8864 if Is_Entity_Name (Node (C))
8865 and then Entity (Node (C)) = Entity (Discrim)
8866 then
8867 -- D is renamed by Discrim, whose value is
8868 -- given in Assoc.
8870 null;
8872 else
8873 Assoc :=
8874 Make_Component_Association (Sloc (Typ),
8875 New_List
8876 (New_Occurrence_Of (D, Sloc (Typ))),
8877 Duplicate_Subexpr_No_Checks (Node (C)));
8878 end if;
8880 exit Find_Constraint;
8881 end if;
8883 Next_Discriminant (D);
8884 Next_Elmt (C);
8885 end loop;
8886 end if;
8888 -- Discriminant may be inherited from ancestor
8890 T := Etype (T);
8891 end loop;
8892 end;
8893 end if;
8894 end if;
8896 if No (Next (Assoc)) then
8897 Error_Msg_NE
8898 (" missing value for discriminant&",
8899 First (Governed_By), Discrim_Name);
8901 Report_Errors := True;
8902 return;
8903 end if;
8905 Next (Assoc);
8906 end loop Find_Constraint;
8908 Discrim_Value := Expression (Assoc);
8910 if not Is_OK_Static_Expression (Discrim_Value) then
8912 -- If the variant part is governed by a discriminant of the type
8913 -- this is an error. If the variant part and the discriminant are
8914 -- inherited from an ancestor this is legal (AI05-120) unless the
8915 -- components are being gathered for an aggregate, in which case
8916 -- the caller must check Report_Errors.
8918 if Scope (Original_Record_Component
8919 ((Entity (First (Choices (Assoc)))))) = Typ
8920 then
8921 Error_Msg_FE
8922 ("value for discriminant & must be static!",
8923 Discrim_Value, Discrim);
8924 Why_Not_Static (Discrim_Value);
8925 end if;
8927 Report_Errors := True;
8928 return;
8929 end if;
8931 Search_For_Discriminant_Value : declare
8932 Low : Node_Id;
8933 High : Node_Id;
8935 UI_High : Uint;
8936 UI_Low : Uint;
8937 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8939 begin
8940 Find_Discrete_Value : while Present (Variant) loop
8941 Discrete_Choice := First (Discrete_Choices (Variant));
8942 while Present (Discrete_Choice) loop
8943 exit Find_Discrete_Value when
8944 Nkind (Discrete_Choice) = N_Others_Choice;
8946 Get_Index_Bounds (Discrete_Choice, Low, High);
8948 UI_Low := Expr_Value (Low);
8949 UI_High := Expr_Value (High);
8951 exit Find_Discrete_Value when
8952 UI_Low <= UI_Discrim_Value
8953 and then
8954 UI_High >= UI_Discrim_Value;
8956 Next (Discrete_Choice);
8957 end loop;
8959 Next_Non_Pragma (Variant);
8960 end loop Find_Discrete_Value;
8961 end Search_For_Discriminant_Value;
8963 -- The case statement must include a variant that corresponds to the
8964 -- value of the discriminant, unless the discriminant type has a
8965 -- static predicate. In that case the absence of an others_choice that
8966 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8968 if No (Variant)
8969 and then not Has_Static_Predicate (Etype (Discrim_Name))
8970 then
8971 Error_Msg_NE
8972 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8973 Report_Errors := True;
8974 return;
8975 end if;
8977 -- If we have found the corresponding choice, recursively add its
8978 -- components to the Into list. The nested components are part of
8979 -- the same record type.
8981 if Present (Variant) then
8982 Gather_Components
8983 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8984 end if;
8985 end Gather_Components;
8987 ------------------------
8988 -- Get_Actual_Subtype --
8989 ------------------------
8991 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8992 Typ : constant Entity_Id := Etype (N);
8993 Utyp : Entity_Id := Underlying_Type (Typ);
8994 Decl : Node_Id;
8995 Atyp : Entity_Id;
8997 begin
8998 if No (Utyp) then
8999 Utyp := Typ;
9000 end if;
9002 -- If what we have is an identifier that references a subprogram
9003 -- formal, or a variable or constant object, then we get the actual
9004 -- subtype from the referenced entity if one has been built.
9006 if Nkind (N) = N_Identifier
9007 and then
9008 (Is_Formal (Entity (N))
9009 or else Ekind (Entity (N)) = E_Constant
9010 or else Ekind (Entity (N)) = E_Variable)
9011 and then Present (Actual_Subtype (Entity (N)))
9012 then
9013 return Actual_Subtype (Entity (N));
9015 -- Actual subtype of unchecked union is always itself. We never need
9016 -- the "real" actual subtype. If we did, we couldn't get it anyway
9017 -- because the discriminant is not available. The restrictions on
9018 -- Unchecked_Union are designed to make sure that this is OK.
9020 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9021 return Typ;
9023 -- Here for the unconstrained case, we must find actual subtype
9024 -- No actual subtype is available, so we must build it on the fly.
9026 -- Checking the type, not the underlying type, for constrainedness
9027 -- seems to be necessary. Maybe all the tests should be on the type???
9029 elsif (not Is_Constrained (Typ))
9030 and then (Is_Array_Type (Utyp)
9031 or else (Is_Record_Type (Utyp)
9032 and then Has_Discriminants (Utyp)))
9033 and then not Has_Unknown_Discriminants (Utyp)
9034 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9035 then
9036 -- Nothing to do if in spec expression (why not???)
9038 if In_Spec_Expression then
9039 return Typ;
9041 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9043 -- If the type has no discriminants, there is no subtype to
9044 -- build, even if the underlying type is discriminated.
9046 return Typ;
9048 -- Else build the actual subtype
9050 else
9051 Decl := Build_Actual_Subtype (Typ, N);
9052 Atyp := Defining_Identifier (Decl);
9054 -- If Build_Actual_Subtype generated a new declaration then use it
9056 if Atyp /= Typ then
9058 -- The actual subtype is an Itype, so analyze the declaration,
9059 -- but do not attach it to the tree, to get the type defined.
9061 Set_Parent (Decl, N);
9062 Set_Is_Itype (Atyp);
9063 Analyze (Decl, Suppress => All_Checks);
9064 Set_Associated_Node_For_Itype (Atyp, N);
9065 Set_Has_Delayed_Freeze (Atyp, False);
9067 -- We need to freeze the actual subtype immediately. This is
9068 -- needed, because otherwise this Itype will not get frozen
9069 -- at all, and it is always safe to freeze on creation because
9070 -- any associated types must be frozen at this point.
9072 Freeze_Itype (Atyp, N);
9073 return Atyp;
9075 -- Otherwise we did not build a declaration, so return original
9077 else
9078 return Typ;
9079 end if;
9080 end if;
9082 -- For all remaining cases, the actual subtype is the same as
9083 -- the nominal type.
9085 else
9086 return Typ;
9087 end if;
9088 end Get_Actual_Subtype;
9090 -------------------------------------
9091 -- Get_Actual_Subtype_If_Available --
9092 -------------------------------------
9094 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
9095 Typ : constant Entity_Id := Etype (N);
9097 begin
9098 -- If what we have is an identifier that references a subprogram
9099 -- formal, or a variable or constant object, then we get the actual
9100 -- subtype from the referenced entity if one has been built.
9102 if Nkind (N) = N_Identifier
9103 and then
9104 (Is_Formal (Entity (N))
9105 or else Ekind (Entity (N)) = E_Constant
9106 or else Ekind (Entity (N)) = E_Variable)
9107 and then Present (Actual_Subtype (Entity (N)))
9108 then
9109 return Actual_Subtype (Entity (N));
9111 -- Otherwise the Etype of N is returned unchanged
9113 else
9114 return Typ;
9115 end if;
9116 end Get_Actual_Subtype_If_Available;
9118 ------------------------
9119 -- Get_Body_From_Stub --
9120 ------------------------
9122 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
9123 begin
9124 return Proper_Body (Unit (Library_Unit (N)));
9125 end Get_Body_From_Stub;
9127 ---------------------
9128 -- Get_Cursor_Type --
9129 ---------------------
9131 function Get_Cursor_Type
9132 (Aspect : Node_Id;
9133 Typ : Entity_Id) return Entity_Id
9135 Assoc : Node_Id;
9136 Func : Entity_Id;
9137 First_Op : Entity_Id;
9138 Cursor : Entity_Id;
9140 begin
9141 -- If error already detected, return
9143 if Error_Posted (Aspect) then
9144 return Any_Type;
9145 end if;
9147 -- The cursor type for an Iterable aspect is the return type of a
9148 -- non-overloaded First primitive operation. Locate association for
9149 -- First.
9151 Assoc := First (Component_Associations (Expression (Aspect)));
9152 First_Op := Any_Id;
9153 while Present (Assoc) loop
9154 if Chars (First (Choices (Assoc))) = Name_First then
9155 First_Op := Expression (Assoc);
9156 exit;
9157 end if;
9159 Next (Assoc);
9160 end loop;
9162 if First_Op = Any_Id then
9163 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
9164 return Any_Type;
9165 end if;
9167 Cursor := Any_Type;
9169 -- Locate function with desired name and profile in scope of type
9170 -- In the rare case where the type is an integer type, a base type
9171 -- is created for it, check that the base type of the first formal
9172 -- of First matches the base type of the domain.
9174 Func := First_Entity (Scope (Typ));
9175 while Present (Func) loop
9176 if Chars (Func) = Chars (First_Op)
9177 and then Ekind (Func) = E_Function
9178 and then Present (First_Formal (Func))
9179 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
9180 and then No (Next_Formal (First_Formal (Func)))
9181 then
9182 if Cursor /= Any_Type then
9183 Error_Msg_N
9184 ("Operation First for iterable type must be unique", Aspect);
9185 return Any_Type;
9186 else
9187 Cursor := Etype (Func);
9188 end if;
9189 end if;
9191 Next_Entity (Func);
9192 end loop;
9194 -- If not found, no way to resolve remaining primitives.
9196 if Cursor = Any_Type then
9197 Error_Msg_N
9198 ("No legal primitive operation First for Iterable type", Aspect);
9199 end if;
9201 return Cursor;
9202 end Get_Cursor_Type;
9204 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9205 begin
9206 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9207 end Get_Cursor_Type;
9209 -------------------------------
9210 -- Get_Default_External_Name --
9211 -------------------------------
9213 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9214 begin
9215 Get_Decoded_Name_String (Chars (E));
9217 if Opt.External_Name_Imp_Casing = Uppercase then
9218 Set_Casing (All_Upper_Case);
9219 else
9220 Set_Casing (All_Lower_Case);
9221 end if;
9223 return
9224 Make_String_Literal (Sloc (E),
9225 Strval => String_From_Name_Buffer);
9226 end Get_Default_External_Name;
9228 --------------------------
9229 -- Get_Enclosing_Object --
9230 --------------------------
9232 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9233 begin
9234 if Is_Entity_Name (N) then
9235 return Entity (N);
9236 else
9237 case Nkind (N) is
9238 when N_Indexed_Component
9239 | N_Selected_Component
9240 | N_Slice
9242 -- If not generating code, a dereference may be left implicit.
9243 -- In thoses cases, return Empty.
9245 if Is_Access_Type (Etype (Prefix (N))) then
9246 return Empty;
9247 else
9248 return Get_Enclosing_Object (Prefix (N));
9249 end if;
9251 when N_Type_Conversion =>
9252 return Get_Enclosing_Object (Expression (N));
9254 when others =>
9255 return Empty;
9256 end case;
9257 end if;
9258 end Get_Enclosing_Object;
9260 ---------------------------
9261 -- Get_Enum_Lit_From_Pos --
9262 ---------------------------
9264 function Get_Enum_Lit_From_Pos
9265 (T : Entity_Id;
9266 Pos : Uint;
9267 Loc : Source_Ptr) return Node_Id
9269 Btyp : Entity_Id := Base_Type (T);
9270 Lit : Node_Id;
9271 LLoc : Source_Ptr;
9273 begin
9274 -- In the case where the literal is of type Character, Wide_Character
9275 -- or Wide_Wide_Character or of a type derived from them, there needs
9276 -- to be some special handling since there is no explicit chain of
9277 -- literals to search. Instead, an N_Character_Literal node is created
9278 -- with the appropriate Char_Code and Chars fields.
9280 if Is_Standard_Character_Type (T) then
9281 Set_Character_Literal_Name (UI_To_CC (Pos));
9283 return
9284 Make_Character_Literal (Loc,
9285 Chars => Name_Find,
9286 Char_Literal_Value => Pos);
9288 -- For all other cases, we have a complete table of literals, and
9289 -- we simply iterate through the chain of literal until the one
9290 -- with the desired position value is found.
9292 else
9293 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9294 Btyp := Full_View (Btyp);
9295 end if;
9297 Lit := First_Literal (Btyp);
9299 -- Position in the enumeration type starts at 0
9301 if UI_To_Int (Pos) < 0 then
9302 raise Constraint_Error;
9303 end if;
9305 for J in 1 .. UI_To_Int (Pos) loop
9306 Next_Literal (Lit);
9308 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9309 -- inside the loop to avoid calling Next_Literal on Empty.
9311 if No (Lit) then
9312 raise Constraint_Error;
9313 end if;
9314 end loop;
9316 -- Create a new node from Lit, with source location provided by Loc
9317 -- if not equal to No_Location, or by copying the source location of
9318 -- Lit otherwise.
9320 LLoc := Loc;
9322 if LLoc = No_Location then
9323 LLoc := Sloc (Lit);
9324 end if;
9326 return New_Occurrence_Of (Lit, LLoc);
9327 end if;
9328 end Get_Enum_Lit_From_Pos;
9330 ------------------------
9331 -- Get_Generic_Entity --
9332 ------------------------
9334 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9335 Ent : constant Entity_Id := Entity (Name (N));
9336 begin
9337 if Present (Renamed_Object (Ent)) then
9338 return Renamed_Object (Ent);
9339 else
9340 return Ent;
9341 end if;
9342 end Get_Generic_Entity;
9344 -------------------------------------
9345 -- Get_Incomplete_View_Of_Ancestor --
9346 -------------------------------------
9348 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9349 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9350 Par_Scope : Entity_Id;
9351 Par_Type : Entity_Id;
9353 begin
9354 -- The incomplete view of an ancestor is only relevant for private
9355 -- derived types in child units.
9357 if not Is_Derived_Type (E)
9358 or else not Is_Child_Unit (Cur_Unit)
9359 then
9360 return Empty;
9362 else
9363 Par_Scope := Scope (Cur_Unit);
9364 if No (Par_Scope) then
9365 return Empty;
9366 end if;
9368 Par_Type := Etype (Base_Type (E));
9370 -- Traverse list of ancestor types until we find one declared in
9371 -- a parent or grandparent unit (two levels seem sufficient).
9373 while Present (Par_Type) loop
9374 if Scope (Par_Type) = Par_Scope
9375 or else Scope (Par_Type) = Scope (Par_Scope)
9376 then
9377 return Par_Type;
9379 elsif not Is_Derived_Type (Par_Type) then
9380 return Empty;
9382 else
9383 Par_Type := Etype (Base_Type (Par_Type));
9384 end if;
9385 end loop;
9387 -- If none found, there is no relevant ancestor type.
9389 return Empty;
9390 end if;
9391 end Get_Incomplete_View_Of_Ancestor;
9393 ----------------------
9394 -- Get_Index_Bounds --
9395 ----------------------
9397 procedure Get_Index_Bounds
9398 (N : Node_Id;
9399 L : out Node_Id;
9400 H : out Node_Id;
9401 Use_Full_View : Boolean := False)
9403 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9404 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9405 -- Typ qualifies, the scalar range is obtained from the full view of the
9406 -- type.
9408 --------------------------
9409 -- Scalar_Range_Of_Type --
9410 --------------------------
9412 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9413 T : Entity_Id := Typ;
9415 begin
9416 if Use_Full_View and then Present (Full_View (T)) then
9417 T := Full_View (T);
9418 end if;
9420 return Scalar_Range (T);
9421 end Scalar_Range_Of_Type;
9423 -- Local variables
9425 Kind : constant Node_Kind := Nkind (N);
9426 Rng : Node_Id;
9428 -- Start of processing for Get_Index_Bounds
9430 begin
9431 if Kind = N_Range then
9432 L := Low_Bound (N);
9433 H := High_Bound (N);
9435 elsif Kind = N_Subtype_Indication then
9436 Rng := Range_Expression (Constraint (N));
9438 if Rng = Error then
9439 L := Error;
9440 H := Error;
9441 return;
9443 else
9444 L := Low_Bound (Range_Expression (Constraint (N)));
9445 H := High_Bound (Range_Expression (Constraint (N)));
9446 end if;
9448 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9449 Rng := Scalar_Range_Of_Type (Entity (N));
9451 if Error_Posted (Rng) then
9452 L := Error;
9453 H := Error;
9455 elsif Nkind (Rng) = N_Subtype_Indication then
9456 Get_Index_Bounds (Rng, L, H);
9458 else
9459 L := Low_Bound (Rng);
9460 H := High_Bound (Rng);
9461 end if;
9463 else
9464 -- N is an expression, indicating a range with one value
9466 L := N;
9467 H := N;
9468 end if;
9469 end Get_Index_Bounds;
9471 -----------------------------
9472 -- Get_Interfacing_Aspects --
9473 -----------------------------
9475 procedure Get_Interfacing_Aspects
9476 (Iface_Asp : Node_Id;
9477 Conv_Asp : out Node_Id;
9478 EN_Asp : out Node_Id;
9479 Expo_Asp : out Node_Id;
9480 Imp_Asp : out Node_Id;
9481 LN_Asp : out Node_Id;
9482 Do_Checks : Boolean := False)
9484 procedure Save_Or_Duplication_Error
9485 (Asp : Node_Id;
9486 To : in out Node_Id);
9487 -- Save the value of aspect Asp in node To. If To already has a value,
9488 -- then this is considered a duplicate use of aspect. Emit an error if
9489 -- flag Do_Checks is set.
9491 -------------------------------
9492 -- Save_Or_Duplication_Error --
9493 -------------------------------
9495 procedure Save_Or_Duplication_Error
9496 (Asp : Node_Id;
9497 To : in out Node_Id)
9499 begin
9500 -- Detect an extra aspect and issue an error
9502 if Present (To) then
9503 if Do_Checks then
9504 Error_Msg_Name_1 := Chars (Identifier (Asp));
9505 Error_Msg_Sloc := Sloc (To);
9506 Error_Msg_N ("aspect % previously given #", Asp);
9507 end if;
9509 -- Otherwise capture the aspect
9511 else
9512 To := Asp;
9513 end if;
9514 end Save_Or_Duplication_Error;
9516 -- Local variables
9518 Asp : Node_Id;
9519 Asp_Id : Aspect_Id;
9521 -- The following variables capture each individual aspect
9523 Conv : Node_Id := Empty;
9524 EN : Node_Id := Empty;
9525 Expo : Node_Id := Empty;
9526 Imp : Node_Id := Empty;
9527 LN : Node_Id := Empty;
9529 -- Start of processing for Get_Interfacing_Aspects
9531 begin
9532 -- The input interfacing aspect should reside in an aspect specification
9533 -- list.
9535 pragma Assert (Is_List_Member (Iface_Asp));
9537 -- Examine the aspect specifications of the related entity. Find and
9538 -- capture all interfacing aspects. Detect duplicates and emit errors
9539 -- if applicable.
9541 Asp := First (List_Containing (Iface_Asp));
9542 while Present (Asp) loop
9543 Asp_Id := Get_Aspect_Id (Asp);
9545 if Asp_Id = Aspect_Convention then
9546 Save_Or_Duplication_Error (Asp, Conv);
9548 elsif Asp_Id = Aspect_External_Name then
9549 Save_Or_Duplication_Error (Asp, EN);
9551 elsif Asp_Id = Aspect_Export then
9552 Save_Or_Duplication_Error (Asp, Expo);
9554 elsif Asp_Id = Aspect_Import then
9555 Save_Or_Duplication_Error (Asp, Imp);
9557 elsif Asp_Id = Aspect_Link_Name then
9558 Save_Or_Duplication_Error (Asp, LN);
9559 end if;
9561 Next (Asp);
9562 end loop;
9564 Conv_Asp := Conv;
9565 EN_Asp := EN;
9566 Expo_Asp := Expo;
9567 Imp_Asp := Imp;
9568 LN_Asp := LN;
9569 end Get_Interfacing_Aspects;
9571 ---------------------------------
9572 -- Get_Iterable_Type_Primitive --
9573 ---------------------------------
9575 function Get_Iterable_Type_Primitive
9576 (Typ : Entity_Id;
9577 Nam : Name_Id) return Entity_Id
9579 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9580 Assoc : Node_Id;
9582 begin
9583 if No (Funcs) then
9584 return Empty;
9586 else
9587 Assoc := First (Component_Associations (Funcs));
9588 while Present (Assoc) loop
9589 if Chars (First (Choices (Assoc))) = Nam then
9590 return Entity (Expression (Assoc));
9591 end if;
9593 Assoc := Next (Assoc);
9594 end loop;
9596 return Empty;
9597 end if;
9598 end Get_Iterable_Type_Primitive;
9600 ----------------------------------
9601 -- Get_Library_Unit_Name_String --
9602 ----------------------------------
9604 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9605 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9607 begin
9608 Get_Unit_Name_String (Unit_Name_Id);
9610 -- Remove seven last character (" (spec)" or " (body)")
9612 Name_Len := Name_Len - 7;
9613 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9614 end Get_Library_Unit_Name_String;
9616 --------------------------
9617 -- Get_Max_Queue_Length --
9618 --------------------------
9620 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9621 pragma Assert (Is_Entry (Id));
9622 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9624 begin
9625 -- A value of 0 represents no maximum specified, and entries and entry
9626 -- families with no Max_Queue_Length aspect or pragma default to it.
9628 if not Present (Prag) then
9629 return Uint_0;
9630 end if;
9632 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9633 end Get_Max_Queue_Length;
9635 ------------------------
9636 -- Get_Name_Entity_Id --
9637 ------------------------
9639 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9640 begin
9641 return Entity_Id (Get_Name_Table_Int (Id));
9642 end Get_Name_Entity_Id;
9644 ------------------------------
9645 -- Get_Name_From_CTC_Pragma --
9646 ------------------------------
9648 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9649 Arg : constant Node_Id :=
9650 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9651 begin
9652 return Strval (Expr_Value_S (Arg));
9653 end Get_Name_From_CTC_Pragma;
9655 -----------------------
9656 -- Get_Parent_Entity --
9657 -----------------------
9659 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9660 begin
9661 if Nkind (Unit) = N_Package_Body
9662 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9663 then
9664 return Defining_Entity
9665 (Specification (Instance_Spec (Original_Node (Unit))));
9666 elsif Nkind (Unit) = N_Package_Instantiation then
9667 return Defining_Entity (Specification (Instance_Spec (Unit)));
9668 else
9669 return Defining_Entity (Unit);
9670 end if;
9671 end Get_Parent_Entity;
9673 -------------------
9674 -- Get_Pragma_Id --
9675 -------------------
9677 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9678 begin
9679 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9680 end Get_Pragma_Id;
9682 ------------------------
9683 -- Get_Qualified_Name --
9684 ------------------------
9686 function Get_Qualified_Name
9687 (Id : Entity_Id;
9688 Suffix : Entity_Id := Empty) return Name_Id
9690 Suffix_Nam : Name_Id := No_Name;
9692 begin
9693 if Present (Suffix) then
9694 Suffix_Nam := Chars (Suffix);
9695 end if;
9697 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9698 end Get_Qualified_Name;
9700 function Get_Qualified_Name
9701 (Nam : Name_Id;
9702 Suffix : Name_Id := No_Name;
9703 Scop : Entity_Id := Current_Scope) return Name_Id
9705 procedure Add_Scope (S : Entity_Id);
9706 -- Add the fully qualified form of scope S to the name buffer. The
9707 -- format is:
9708 -- s-1__s__
9710 ---------------
9711 -- Add_Scope --
9712 ---------------
9714 procedure Add_Scope (S : Entity_Id) is
9715 begin
9716 if S = Empty then
9717 null;
9719 elsif S = Standard_Standard then
9720 null;
9722 else
9723 Add_Scope (Scope (S));
9724 Get_Name_String_And_Append (Chars (S));
9725 Add_Str_To_Name_Buffer ("__");
9726 end if;
9727 end Add_Scope;
9729 -- Start of processing for Get_Qualified_Name
9731 begin
9732 Name_Len := 0;
9733 Add_Scope (Scop);
9735 -- Append the base name after all scopes have been chained
9737 Get_Name_String_And_Append (Nam);
9739 -- Append the suffix (if present)
9741 if Suffix /= No_Name then
9742 Add_Str_To_Name_Buffer ("__");
9743 Get_Name_String_And_Append (Suffix);
9744 end if;
9746 return Name_Find;
9747 end Get_Qualified_Name;
9749 -----------------------
9750 -- Get_Reason_String --
9751 -----------------------
9753 procedure Get_Reason_String (N : Node_Id) is
9754 begin
9755 if Nkind (N) = N_String_Literal then
9756 Store_String_Chars (Strval (N));
9758 elsif Nkind (N) = N_Op_Concat then
9759 Get_Reason_String (Left_Opnd (N));
9760 Get_Reason_String (Right_Opnd (N));
9762 -- If not of required form, error
9764 else
9765 Error_Msg_N
9766 ("Reason for pragma Warnings has wrong form", N);
9767 Error_Msg_N
9768 ("\must be string literal or concatenation of string literals", N);
9769 return;
9770 end if;
9771 end Get_Reason_String;
9773 --------------------------------
9774 -- Get_Reference_Discriminant --
9775 --------------------------------
9777 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9778 D : Entity_Id;
9780 begin
9781 D := First_Discriminant (Typ);
9782 while Present (D) loop
9783 if Has_Implicit_Dereference (D) then
9784 return D;
9785 end if;
9786 Next_Discriminant (D);
9787 end loop;
9789 return Empty;
9790 end Get_Reference_Discriminant;
9792 ---------------------------
9793 -- Get_Referenced_Object --
9794 ---------------------------
9796 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9797 R : Node_Id;
9799 begin
9800 R := N;
9801 while Is_Entity_Name (R)
9802 and then Present (Renamed_Object (Entity (R)))
9803 loop
9804 R := Renamed_Object (Entity (R));
9805 end loop;
9807 return R;
9808 end Get_Referenced_Object;
9810 ------------------------
9811 -- Get_Renamed_Entity --
9812 ------------------------
9814 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9815 R : Entity_Id;
9817 begin
9818 R := E;
9819 while Present (Renamed_Entity (R)) loop
9820 R := Renamed_Entity (R);
9821 end loop;
9823 return R;
9824 end Get_Renamed_Entity;
9826 -----------------------
9827 -- Get_Return_Object --
9828 -----------------------
9830 function Get_Return_Object (N : Node_Id) return Entity_Id is
9831 Decl : Node_Id;
9833 begin
9834 Decl := First (Return_Object_Declarations (N));
9835 while Present (Decl) loop
9836 exit when Nkind (Decl) = N_Object_Declaration
9837 and then Is_Return_Object (Defining_Identifier (Decl));
9838 Next (Decl);
9839 end loop;
9841 pragma Assert (Present (Decl));
9842 return Defining_Identifier (Decl);
9843 end Get_Return_Object;
9845 ---------------------------
9846 -- Get_Subprogram_Entity --
9847 ---------------------------
9849 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9850 Subp : Node_Id;
9851 Subp_Id : Entity_Id;
9853 begin
9854 if Nkind (Nod) = N_Accept_Statement then
9855 Subp := Entry_Direct_Name (Nod);
9857 elsif Nkind (Nod) = N_Slice then
9858 Subp := Prefix (Nod);
9860 else
9861 Subp := Name (Nod);
9862 end if;
9864 -- Strip the subprogram call
9866 loop
9867 if Nkind_In (Subp, N_Explicit_Dereference,
9868 N_Indexed_Component,
9869 N_Selected_Component)
9870 then
9871 Subp := Prefix (Subp);
9873 elsif Nkind_In (Subp, N_Type_Conversion,
9874 N_Unchecked_Type_Conversion)
9875 then
9876 Subp := Expression (Subp);
9878 else
9879 exit;
9880 end if;
9881 end loop;
9883 -- Extract the entity of the subprogram call
9885 if Is_Entity_Name (Subp) then
9886 Subp_Id := Entity (Subp);
9888 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9889 Subp_Id := Directly_Designated_Type (Subp_Id);
9890 end if;
9892 if Is_Subprogram (Subp_Id) then
9893 return Subp_Id;
9894 else
9895 return Empty;
9896 end if;
9898 -- The search did not find a construct that denotes a subprogram
9900 else
9901 return Empty;
9902 end if;
9903 end Get_Subprogram_Entity;
9905 -----------------------------
9906 -- Get_Task_Body_Procedure --
9907 -----------------------------
9909 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
9910 begin
9911 -- Note: A task type may be the completion of a private type with
9912 -- discriminants. When performing elaboration checks on a task
9913 -- declaration, the current view of the type may be the private one,
9914 -- and the procedure that holds the body of the task is held in its
9915 -- underlying type.
9917 -- This is an odd function, why not have Task_Body_Procedure do
9918 -- the following digging???
9920 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9921 end Get_Task_Body_Procedure;
9923 -------------------------
9924 -- Get_User_Defined_Eq --
9925 -------------------------
9927 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9928 Prim : Elmt_Id;
9929 Op : Entity_Id;
9931 begin
9932 Prim := First_Elmt (Collect_Primitive_Operations (E));
9933 while Present (Prim) loop
9934 Op := Node (Prim);
9936 if Chars (Op) = Name_Op_Eq
9937 and then Etype (Op) = Standard_Boolean
9938 and then Etype (First_Formal (Op)) = E
9939 and then Etype (Next_Formal (First_Formal (Op))) = E
9940 then
9941 return Op;
9942 end if;
9944 Next_Elmt (Prim);
9945 end loop;
9947 return Empty;
9948 end Get_User_Defined_Eq;
9950 ---------------
9951 -- Get_Views --
9952 ---------------
9954 procedure Get_Views
9955 (Typ : Entity_Id;
9956 Priv_Typ : out Entity_Id;
9957 Full_Typ : out Entity_Id;
9958 Full_Base : out Entity_Id;
9959 CRec_Typ : out Entity_Id)
9961 IP_View : Entity_Id;
9963 begin
9964 -- Assume that none of the views can be recovered
9966 Priv_Typ := Empty;
9967 Full_Typ := Empty;
9968 Full_Base := Empty;
9969 CRec_Typ := Empty;
9971 -- The input type is the corresponding record type of a protected or a
9972 -- task type.
9974 if Ekind (Typ) = E_Record_Type
9975 and then Is_Concurrent_Record_Type (Typ)
9976 then
9977 CRec_Typ := Typ;
9978 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9979 Full_Base := Base_Type (Full_Typ);
9980 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9982 -- Otherwise the input type denotes an arbitrary type
9984 else
9985 IP_View := Incomplete_Or_Partial_View (Typ);
9987 -- The input type denotes the full view of a private type
9989 if Present (IP_View) then
9990 Priv_Typ := IP_View;
9991 Full_Typ := Typ;
9993 -- The input type is a private type
9995 elsif Is_Private_Type (Typ) then
9996 Priv_Typ := Typ;
9997 Full_Typ := Full_View (Priv_Typ);
9999 -- Otherwise the input type does not have any views
10001 else
10002 Full_Typ := Typ;
10003 end if;
10005 if Present (Full_Typ) then
10006 Full_Base := Base_Type (Full_Typ);
10008 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
10009 CRec_Typ := Corresponding_Record_Type (Full_Typ);
10010 end if;
10011 end if;
10012 end if;
10013 end Get_Views;
10015 -----------------------
10016 -- Has_Access_Values --
10017 -----------------------
10019 function Has_Access_Values (T : Entity_Id) return Boolean is
10020 Typ : constant Entity_Id := Underlying_Type (T);
10022 begin
10023 -- Case of a private type which is not completed yet. This can only
10024 -- happen in the case of a generic format type appearing directly, or
10025 -- as a component of the type to which this function is being applied
10026 -- at the top level. Return False in this case, since we certainly do
10027 -- not know that the type contains access types.
10029 if No (Typ) then
10030 return False;
10032 elsif Is_Access_Type (Typ) then
10033 return True;
10035 elsif Is_Array_Type (Typ) then
10036 return Has_Access_Values (Component_Type (Typ));
10038 elsif Is_Record_Type (Typ) then
10039 declare
10040 Comp : Entity_Id;
10042 begin
10043 -- Loop to Check components
10045 Comp := First_Component_Or_Discriminant (Typ);
10046 while Present (Comp) loop
10048 -- Check for access component, tag field does not count, even
10049 -- though it is implemented internally using an access type.
10051 if Has_Access_Values (Etype (Comp))
10052 and then Chars (Comp) /= Name_uTag
10053 then
10054 return True;
10055 end if;
10057 Next_Component_Or_Discriminant (Comp);
10058 end loop;
10059 end;
10061 return False;
10063 else
10064 return False;
10065 end if;
10066 end Has_Access_Values;
10068 ------------------------------
10069 -- Has_Compatible_Alignment --
10070 ------------------------------
10072 function Has_Compatible_Alignment
10073 (Obj : Entity_Id;
10074 Expr : Node_Id;
10075 Layout_Done : Boolean) return Alignment_Result
10077 function Has_Compatible_Alignment_Internal
10078 (Obj : Entity_Id;
10079 Expr : Node_Id;
10080 Layout_Done : Boolean;
10081 Default : Alignment_Result) return Alignment_Result;
10082 -- This is the internal recursive function that actually does the work.
10083 -- There is one additional parameter, which says what the result should
10084 -- be if no alignment information is found, and there is no definite
10085 -- indication of compatible alignments. At the outer level, this is set
10086 -- to Unknown, but for internal recursive calls in the case where types
10087 -- are known to be correct, it is set to Known_Compatible.
10089 ---------------------------------------
10090 -- Has_Compatible_Alignment_Internal --
10091 ---------------------------------------
10093 function Has_Compatible_Alignment_Internal
10094 (Obj : Entity_Id;
10095 Expr : Node_Id;
10096 Layout_Done : Boolean;
10097 Default : Alignment_Result) return Alignment_Result
10099 Result : Alignment_Result := Known_Compatible;
10100 -- Holds the current status of the result. Note that once a value of
10101 -- Known_Incompatible is set, it is sticky and does not get changed
10102 -- to Unknown (the value in Result only gets worse as we go along,
10103 -- never better).
10105 Offs : Uint := No_Uint;
10106 -- Set to a factor of the offset from the base object when Expr is a
10107 -- selected or indexed component, based on Component_Bit_Offset and
10108 -- Component_Size respectively. A negative value is used to represent
10109 -- a value which is not known at compile time.
10111 procedure Check_Prefix;
10112 -- Checks the prefix recursively in the case where the expression
10113 -- is an indexed or selected component.
10115 procedure Set_Result (R : Alignment_Result);
10116 -- If R represents a worse outcome (unknown instead of known
10117 -- compatible, or known incompatible), then set Result to R.
10119 ------------------
10120 -- Check_Prefix --
10121 ------------------
10123 procedure Check_Prefix is
10124 begin
10125 -- The subtlety here is that in doing a recursive call to check
10126 -- the prefix, we have to decide what to do in the case where we
10127 -- don't find any specific indication of an alignment problem.
10129 -- At the outer level, we normally set Unknown as the result in
10130 -- this case, since we can only set Known_Compatible if we really
10131 -- know that the alignment value is OK, but for the recursive
10132 -- call, in the case where the types match, and we have not
10133 -- specified a peculiar alignment for the object, we are only
10134 -- concerned about suspicious rep clauses, the default case does
10135 -- not affect us, since the compiler will, in the absence of such
10136 -- rep clauses, ensure that the alignment is correct.
10138 if Default = Known_Compatible
10139 or else
10140 (Etype (Obj) = Etype (Expr)
10141 and then (Unknown_Alignment (Obj)
10142 or else
10143 Alignment (Obj) = Alignment (Etype (Obj))))
10144 then
10145 Set_Result
10146 (Has_Compatible_Alignment_Internal
10147 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
10149 -- In all other cases, we need a full check on the prefix
10151 else
10152 Set_Result
10153 (Has_Compatible_Alignment_Internal
10154 (Obj, Prefix (Expr), Layout_Done, Unknown));
10155 end if;
10156 end Check_Prefix;
10158 ----------------
10159 -- Set_Result --
10160 ----------------
10162 procedure Set_Result (R : Alignment_Result) is
10163 begin
10164 if R > Result then
10165 Result := R;
10166 end if;
10167 end Set_Result;
10169 -- Start of processing for Has_Compatible_Alignment_Internal
10171 begin
10172 -- If Expr is a selected component, we must make sure there is no
10173 -- potentially troublesome component clause and that the record is
10174 -- not packed if the layout is not done.
10176 if Nkind (Expr) = N_Selected_Component then
10178 -- Packing generates unknown alignment if layout is not done
10180 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
10181 Set_Result (Unknown);
10182 end if;
10184 -- Check prefix and component offset
10186 Check_Prefix;
10187 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
10189 -- If Expr is an indexed component, we must make sure there is no
10190 -- potentially troublesome Component_Size clause and that the array
10191 -- is not bit-packed if the layout is not done.
10193 elsif Nkind (Expr) = N_Indexed_Component then
10194 declare
10195 Typ : constant Entity_Id := Etype (Prefix (Expr));
10197 begin
10198 -- Packing generates unknown alignment if layout is not done
10200 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10201 Set_Result (Unknown);
10202 end if;
10204 -- Check prefix and component offset (or at least size)
10206 Check_Prefix;
10207 Offs := Indexed_Component_Bit_Offset (Expr);
10208 if Offs = No_Uint then
10209 Offs := Component_Size (Typ);
10210 end if;
10211 end;
10212 end if;
10214 -- If we have a null offset, the result is entirely determined by
10215 -- the base object and has already been computed recursively.
10217 if Offs = Uint_0 then
10218 null;
10220 -- Case where we know the alignment of the object
10222 elsif Known_Alignment (Obj) then
10223 declare
10224 ObjA : constant Uint := Alignment (Obj);
10225 ExpA : Uint := No_Uint;
10226 SizA : Uint := No_Uint;
10228 begin
10229 -- If alignment of Obj is 1, then we are always OK
10231 if ObjA = 1 then
10232 Set_Result (Known_Compatible);
10234 -- Alignment of Obj is greater than 1, so we need to check
10236 else
10237 -- If we have an offset, see if it is compatible
10239 if Offs /= No_Uint and Offs > Uint_0 then
10240 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10241 Set_Result (Known_Incompatible);
10242 end if;
10244 -- See if Expr is an object with known alignment
10246 elsif Is_Entity_Name (Expr)
10247 and then Known_Alignment (Entity (Expr))
10248 then
10249 ExpA := Alignment (Entity (Expr));
10251 -- Otherwise, we can use the alignment of the type of
10252 -- Expr given that we already checked for
10253 -- discombobulating rep clauses for the cases of indexed
10254 -- and selected components above.
10256 elsif Known_Alignment (Etype (Expr)) then
10257 ExpA := Alignment (Etype (Expr));
10259 -- Otherwise the alignment is unknown
10261 else
10262 Set_Result (Default);
10263 end if;
10265 -- If we got an alignment, see if it is acceptable
10267 if ExpA /= No_Uint and then ExpA < ObjA then
10268 Set_Result (Known_Incompatible);
10269 end if;
10271 -- If Expr is not a piece of a larger object, see if size
10272 -- is given. If so, check that it is not too small for the
10273 -- required alignment.
10275 if Offs /= No_Uint then
10276 null;
10278 -- See if Expr is an object with known size
10280 elsif Is_Entity_Name (Expr)
10281 and then Known_Static_Esize (Entity (Expr))
10282 then
10283 SizA := Esize (Entity (Expr));
10285 -- Otherwise, we check the object size of the Expr type
10287 elsif Known_Static_Esize (Etype (Expr)) then
10288 SizA := Esize (Etype (Expr));
10289 end if;
10291 -- If we got a size, see if it is a multiple of the Obj
10292 -- alignment, if not, then the alignment cannot be
10293 -- acceptable, since the size is always a multiple of the
10294 -- alignment.
10296 if SizA /= No_Uint then
10297 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10298 Set_Result (Known_Incompatible);
10299 end if;
10300 end if;
10301 end if;
10302 end;
10304 -- If we do not know required alignment, any non-zero offset is a
10305 -- potential problem (but certainly may be OK, so result is unknown).
10307 elsif Offs /= No_Uint then
10308 Set_Result (Unknown);
10310 -- If we can't find the result by direct comparison of alignment
10311 -- values, then there is still one case that we can determine known
10312 -- result, and that is when we can determine that the types are the
10313 -- same, and no alignments are specified. Then we known that the
10314 -- alignments are compatible, even if we don't know the alignment
10315 -- value in the front end.
10317 elsif Etype (Obj) = Etype (Expr) then
10319 -- Types are the same, but we have to check for possible size
10320 -- and alignments on the Expr object that may make the alignment
10321 -- different, even though the types are the same.
10323 if Is_Entity_Name (Expr) then
10325 -- First check alignment of the Expr object. Any alignment less
10326 -- than Maximum_Alignment is worrisome since this is the case
10327 -- where we do not know the alignment of Obj.
10329 if Known_Alignment (Entity (Expr))
10330 and then UI_To_Int (Alignment (Entity (Expr))) <
10331 Ttypes.Maximum_Alignment
10332 then
10333 Set_Result (Unknown);
10335 -- Now check size of Expr object. Any size that is not an
10336 -- even multiple of Maximum_Alignment is also worrisome
10337 -- since it may cause the alignment of the object to be less
10338 -- than the alignment of the type.
10340 elsif Known_Static_Esize (Entity (Expr))
10341 and then
10342 (UI_To_Int (Esize (Entity (Expr))) mod
10343 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10344 /= 0
10345 then
10346 Set_Result (Unknown);
10348 -- Otherwise same type is decisive
10350 else
10351 Set_Result (Known_Compatible);
10352 end if;
10353 end if;
10355 -- Another case to deal with is when there is an explicit size or
10356 -- alignment clause when the types are not the same. If so, then the
10357 -- result is Unknown. We don't need to do this test if the Default is
10358 -- Unknown, since that result will be set in any case.
10360 elsif Default /= Unknown
10361 and then (Has_Size_Clause (Etype (Expr))
10362 or else
10363 Has_Alignment_Clause (Etype (Expr)))
10364 then
10365 Set_Result (Unknown);
10367 -- If no indication found, set default
10369 else
10370 Set_Result (Default);
10371 end if;
10373 -- Return worst result found
10375 return Result;
10376 end Has_Compatible_Alignment_Internal;
10378 -- Start of processing for Has_Compatible_Alignment
10380 begin
10381 -- If Obj has no specified alignment, then set alignment from the type
10382 -- alignment. Perhaps we should always do this, but for sure we should
10383 -- do it when there is an address clause since we can do more if the
10384 -- alignment is known.
10386 if Unknown_Alignment (Obj) then
10387 Set_Alignment (Obj, Alignment (Etype (Obj)));
10388 end if;
10390 -- Now do the internal call that does all the work
10392 return
10393 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10394 end Has_Compatible_Alignment;
10396 ----------------------
10397 -- Has_Declarations --
10398 ----------------------
10400 function Has_Declarations (N : Node_Id) return Boolean is
10401 begin
10402 return Nkind_In (Nkind (N), N_Accept_Statement,
10403 N_Block_Statement,
10404 N_Compilation_Unit_Aux,
10405 N_Entry_Body,
10406 N_Package_Body,
10407 N_Protected_Body,
10408 N_Subprogram_Body,
10409 N_Task_Body,
10410 N_Package_Specification);
10411 end Has_Declarations;
10413 ---------------------------------
10414 -- Has_Defaulted_Discriminants --
10415 ---------------------------------
10417 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10418 begin
10419 return Has_Discriminants (Typ)
10420 and then Present (First_Discriminant (Typ))
10421 and then Present (Discriminant_Default_Value
10422 (First_Discriminant (Typ)));
10423 end Has_Defaulted_Discriminants;
10425 -------------------
10426 -- Has_Denormals --
10427 -------------------
10429 function Has_Denormals (E : Entity_Id) return Boolean is
10430 begin
10431 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10432 end Has_Denormals;
10434 -------------------------------------------
10435 -- Has_Discriminant_Dependent_Constraint --
10436 -------------------------------------------
10438 function Has_Discriminant_Dependent_Constraint
10439 (Comp : Entity_Id) return Boolean
10441 Comp_Decl : constant Node_Id := Parent (Comp);
10442 Subt_Indic : Node_Id;
10443 Constr : Node_Id;
10444 Assn : Node_Id;
10446 begin
10447 -- Discriminants can't depend on discriminants
10449 if Ekind (Comp) = E_Discriminant then
10450 return False;
10452 else
10453 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10455 if Nkind (Subt_Indic) = N_Subtype_Indication then
10456 Constr := Constraint (Subt_Indic);
10458 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10459 Assn := First (Constraints (Constr));
10460 while Present (Assn) loop
10461 case Nkind (Assn) is
10462 when N_Identifier
10463 | N_Range
10464 | N_Subtype_Indication
10466 if Depends_On_Discriminant (Assn) then
10467 return True;
10468 end if;
10470 when N_Discriminant_Association =>
10471 if Depends_On_Discriminant (Expression (Assn)) then
10472 return True;
10473 end if;
10475 when others =>
10476 null;
10477 end case;
10479 Next (Assn);
10480 end loop;
10481 end if;
10482 end if;
10483 end if;
10485 return False;
10486 end Has_Discriminant_Dependent_Constraint;
10488 --------------------------------------
10489 -- Has_Effectively_Volatile_Profile --
10490 --------------------------------------
10492 function Has_Effectively_Volatile_Profile
10493 (Subp_Id : Entity_Id) return Boolean
10495 Formal : Entity_Id;
10497 begin
10498 -- Inspect the formal parameters looking for an effectively volatile
10499 -- type.
10501 Formal := First_Formal (Subp_Id);
10502 while Present (Formal) loop
10503 if Is_Effectively_Volatile (Etype (Formal)) then
10504 return True;
10505 end if;
10507 Next_Formal (Formal);
10508 end loop;
10510 -- Inspect the return type of functions
10512 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10513 and then Is_Effectively_Volatile (Etype (Subp_Id))
10514 then
10515 return True;
10516 end if;
10518 return False;
10519 end Has_Effectively_Volatile_Profile;
10521 --------------------------
10522 -- Has_Enabled_Property --
10523 --------------------------
10525 function Has_Enabled_Property
10526 (Item_Id : Entity_Id;
10527 Property : Name_Id) return Boolean
10529 function Protected_Object_Has_Enabled_Property return Boolean;
10530 -- Determine whether a protected object denoted by Item_Id has the
10531 -- property enabled.
10533 function State_Has_Enabled_Property return Boolean;
10534 -- Determine whether a state denoted by Item_Id has the property enabled
10536 function Variable_Has_Enabled_Property return Boolean;
10537 -- Determine whether a variable denoted by Item_Id has the property
10538 -- enabled.
10540 -------------------------------------------
10541 -- Protected_Object_Has_Enabled_Property --
10542 -------------------------------------------
10544 function Protected_Object_Has_Enabled_Property return Boolean is
10545 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10546 Constit_Elmt : Elmt_Id;
10547 Constit_Id : Entity_Id;
10549 begin
10550 -- Protected objects always have the properties Async_Readers and
10551 -- Async_Writers (SPARK RM 7.1.2(16)).
10553 if Property = Name_Async_Readers
10554 or else Property = Name_Async_Writers
10555 then
10556 return True;
10558 -- Protected objects that have Part_Of components also inherit their
10559 -- properties Effective_Reads and Effective_Writes
10560 -- (SPARK RM 7.1.2(16)).
10562 elsif Present (Constits) then
10563 Constit_Elmt := First_Elmt (Constits);
10564 while Present (Constit_Elmt) loop
10565 Constit_Id := Node (Constit_Elmt);
10567 if Has_Enabled_Property (Constit_Id, Property) then
10568 return True;
10569 end if;
10571 Next_Elmt (Constit_Elmt);
10572 end loop;
10573 end if;
10575 return False;
10576 end Protected_Object_Has_Enabled_Property;
10578 --------------------------------
10579 -- State_Has_Enabled_Property --
10580 --------------------------------
10582 function State_Has_Enabled_Property return Boolean is
10583 Decl : constant Node_Id := Parent (Item_Id);
10585 procedure Find_Simple_Properties
10586 (Has_External : out Boolean;
10587 Has_Synchronous : out Boolean);
10588 -- Extract the simple properties associated with declaration Decl
10590 function Is_Enabled_External_Property return Boolean;
10591 -- Determine whether property Property appears within the external
10592 -- property list of declaration Decl, and return its status.
10594 ----------------------------
10595 -- Find_Simple_Properties --
10596 ----------------------------
10598 procedure Find_Simple_Properties
10599 (Has_External : out Boolean;
10600 Has_Synchronous : out Boolean)
10602 Opt : Node_Id;
10604 begin
10605 -- Assume that none of the properties are available
10607 Has_External := False;
10608 Has_Synchronous := False;
10610 Opt := First (Expressions (Decl));
10611 while Present (Opt) loop
10612 if Nkind (Opt) = N_Identifier then
10613 if Chars (Opt) = Name_External then
10614 Has_External := True;
10616 elsif Chars (Opt) = Name_Synchronous then
10617 Has_Synchronous := True;
10618 end if;
10619 end if;
10621 Next (Opt);
10622 end loop;
10623 end Find_Simple_Properties;
10625 ----------------------------------
10626 -- Is_Enabled_External_Property --
10627 ----------------------------------
10629 function Is_Enabled_External_Property return Boolean is
10630 Opt : Node_Id;
10631 Opt_Nam : Node_Id;
10632 Prop : Node_Id;
10633 Prop_Nam : Node_Id;
10634 Props : Node_Id;
10636 begin
10637 Opt := First (Component_Associations (Decl));
10638 while Present (Opt) loop
10639 Opt_Nam := First (Choices (Opt));
10641 if Nkind (Opt_Nam) = N_Identifier
10642 and then Chars (Opt_Nam) = Name_External
10643 then
10644 Props := Expression (Opt);
10646 -- Multiple properties appear as an aggregate
10648 if Nkind (Props) = N_Aggregate then
10650 -- Simple property form
10652 Prop := First (Expressions (Props));
10653 while Present (Prop) loop
10654 if Chars (Prop) = Property then
10655 return True;
10656 end if;
10658 Next (Prop);
10659 end loop;
10661 -- Property with expression form
10663 Prop := First (Component_Associations (Props));
10664 while Present (Prop) loop
10665 Prop_Nam := First (Choices (Prop));
10667 -- The property can be represented in two ways:
10668 -- others => <value>
10669 -- <property> => <value>
10671 if Nkind (Prop_Nam) = N_Others_Choice
10672 or else (Nkind (Prop_Nam) = N_Identifier
10673 and then Chars (Prop_Nam) = Property)
10674 then
10675 return Is_True (Expr_Value (Expression (Prop)));
10676 end if;
10678 Next (Prop);
10679 end loop;
10681 -- Single property
10683 else
10684 return Chars (Props) = Property;
10685 end if;
10686 end if;
10688 Next (Opt);
10689 end loop;
10691 return False;
10692 end Is_Enabled_External_Property;
10694 -- Local variables
10696 Has_External : Boolean;
10697 Has_Synchronous : Boolean;
10699 -- Start of processing for State_Has_Enabled_Property
10701 begin
10702 -- The declaration of an external abstract state appears as an
10703 -- extension aggregate. If this is not the case, properties can
10704 -- never be set.
10706 if Nkind (Decl) /= N_Extension_Aggregate then
10707 return False;
10708 end if;
10710 Find_Simple_Properties (Has_External, Has_Synchronous);
10712 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10714 if Has_External then
10715 return True;
10717 -- Option External may enable or disable specific properties
10719 elsif Is_Enabled_External_Property then
10720 return True;
10722 -- Simple option Synchronous
10724 -- enables disables
10725 -- Asynch_Readers Effective_Reads
10726 -- Asynch_Writers Effective_Writes
10728 -- Note that both forms of External have higher precedence than
10729 -- Synchronous (SPARK RM 7.1.4(10)).
10731 elsif Has_Synchronous then
10732 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
10733 end if;
10735 return False;
10736 end State_Has_Enabled_Property;
10738 -----------------------------------
10739 -- Variable_Has_Enabled_Property --
10740 -----------------------------------
10742 function Variable_Has_Enabled_Property return Boolean is
10743 function Is_Enabled (Prag : Node_Id) return Boolean;
10744 -- Determine whether property pragma Prag (if present) denotes an
10745 -- enabled property.
10747 ----------------
10748 -- Is_Enabled --
10749 ----------------
10751 function Is_Enabled (Prag : Node_Id) return Boolean is
10752 Arg1 : Node_Id;
10754 begin
10755 if Present (Prag) then
10756 Arg1 := First (Pragma_Argument_Associations (Prag));
10758 -- The pragma has an optional Boolean expression, the related
10759 -- property is enabled only when the expression evaluates to
10760 -- True.
10762 if Present (Arg1) then
10763 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10765 -- Otherwise the lack of expression enables the property by
10766 -- default.
10768 else
10769 return True;
10770 end if;
10772 -- The property was never set in the first place
10774 else
10775 return False;
10776 end if;
10777 end Is_Enabled;
10779 -- Local variables
10781 AR : constant Node_Id :=
10782 Get_Pragma (Item_Id, Pragma_Async_Readers);
10783 AW : constant Node_Id :=
10784 Get_Pragma (Item_Id, Pragma_Async_Writers);
10785 ER : constant Node_Id :=
10786 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10787 EW : constant Node_Id :=
10788 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10790 -- Start of processing for Variable_Has_Enabled_Property
10792 begin
10793 -- A non-effectively volatile object can never possess external
10794 -- properties.
10796 if not Is_Effectively_Volatile (Item_Id) then
10797 return False;
10799 -- External properties related to variables come in two flavors -
10800 -- explicit and implicit. The explicit case is characterized by the
10801 -- presence of a property pragma with an optional Boolean flag. The
10802 -- property is enabled when the flag evaluates to True or the flag is
10803 -- missing altogether.
10805 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10806 return True;
10808 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10809 return True;
10811 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10812 return True;
10814 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10815 return True;
10817 -- The implicit case lacks all property pragmas
10819 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10820 if Is_Protected_Type (Etype (Item_Id)) then
10821 return Protected_Object_Has_Enabled_Property;
10822 else
10823 return True;
10824 end if;
10826 else
10827 return False;
10828 end if;
10829 end Variable_Has_Enabled_Property;
10831 -- Start of processing for Has_Enabled_Property
10833 begin
10834 -- Abstract states and variables have a flexible scheme of specifying
10835 -- external properties.
10837 if Ekind (Item_Id) = E_Abstract_State then
10838 return State_Has_Enabled_Property;
10840 elsif Ekind (Item_Id) = E_Variable then
10841 return Variable_Has_Enabled_Property;
10843 -- By default, protected objects only have the properties Async_Readers
10844 -- and Async_Writers. If they have Part_Of components, they also inherit
10845 -- their properties Effective_Reads and Effective_Writes
10846 -- (SPARK RM 7.1.2(16)).
10848 elsif Ekind (Item_Id) = E_Protected_Object then
10849 return Protected_Object_Has_Enabled_Property;
10851 -- Otherwise a property is enabled when the related item is effectively
10852 -- volatile.
10854 else
10855 return Is_Effectively_Volatile (Item_Id);
10856 end if;
10857 end Has_Enabled_Property;
10859 -------------------------------------
10860 -- Has_Full_Default_Initialization --
10861 -------------------------------------
10863 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10864 Comp : Entity_Id;
10866 begin
10867 -- A type subject to pragma Default_Initial_Condition may be fully
10868 -- default initialized depending on inheritance and the argument of
10869 -- the pragma. Since any type may act as the full view of a private
10870 -- type, this check must be performed prior to the specialized tests
10871 -- below.
10873 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
10874 return True;
10875 end if;
10877 -- A scalar type is fully default initialized if it is subject to aspect
10878 -- Default_Value.
10880 if Is_Scalar_Type (Typ) then
10881 return Has_Default_Aspect (Typ);
10883 -- An array type is fully default initialized if its element type is
10884 -- scalar and the array type carries aspect Default_Component_Value or
10885 -- the element type is fully default initialized.
10887 elsif Is_Array_Type (Typ) then
10888 return
10889 Has_Default_Aspect (Typ)
10890 or else Has_Full_Default_Initialization (Component_Type (Typ));
10892 -- A protected type, record type, or type extension is fully default
10893 -- initialized if all its components either carry an initialization
10894 -- expression or have a type that is fully default initialized. The
10895 -- parent type of a type extension must be fully default initialized.
10897 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10899 -- Inspect all entities defined in the scope of the type, looking for
10900 -- uninitialized components.
10902 Comp := First_Entity (Typ);
10903 while Present (Comp) loop
10904 if Ekind (Comp) = E_Component
10905 and then Comes_From_Source (Comp)
10906 and then No (Expression (Parent (Comp)))
10907 and then not Has_Full_Default_Initialization (Etype (Comp))
10908 then
10909 return False;
10910 end if;
10912 Next_Entity (Comp);
10913 end loop;
10915 -- Ensure that the parent type of a type extension is fully default
10916 -- initialized.
10918 if Etype (Typ) /= Typ
10919 and then not Has_Full_Default_Initialization (Etype (Typ))
10920 then
10921 return False;
10922 end if;
10924 -- If we get here, then all components and parent portion are fully
10925 -- default initialized.
10927 return True;
10929 -- A task type is fully default initialized by default
10931 elsif Is_Task_Type (Typ) then
10932 return True;
10934 -- Otherwise the type is not fully default initialized
10936 else
10937 return False;
10938 end if;
10939 end Has_Full_Default_Initialization;
10941 -----------------------------------------------
10942 -- Has_Fully_Default_Initializing_DIC_Pragma --
10943 -----------------------------------------------
10945 function Has_Fully_Default_Initializing_DIC_Pragma
10946 (Typ : Entity_Id) return Boolean
10948 Args : List_Id;
10949 Prag : Node_Id;
10951 begin
10952 -- A type that inherits pragma Default_Initial_Condition from a parent
10953 -- type is automatically fully default initialized.
10955 if Has_Inherited_DIC (Typ) then
10956 return True;
10958 -- Otherwise the type is fully default initialized only when the pragma
10959 -- appears without an argument, or the argument is non-null.
10961 elsif Has_Own_DIC (Typ) then
10962 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10963 pragma Assert (Present (Prag));
10964 Args := Pragma_Argument_Associations (Prag);
10966 -- The pragma appears without an argument in which case it defaults
10967 -- to True.
10969 if No (Args) then
10970 return True;
10972 -- The pragma appears with a non-null expression
10974 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
10975 return True;
10976 end if;
10977 end if;
10979 return False;
10980 end Has_Fully_Default_Initializing_DIC_Pragma;
10982 --------------------
10983 -- Has_Infinities --
10984 --------------------
10986 function Has_Infinities (E : Entity_Id) return Boolean is
10987 begin
10988 return
10989 Is_Floating_Point_Type (E)
10990 and then Nkind (Scalar_Range (E)) = N_Range
10991 and then Includes_Infinities (Scalar_Range (E));
10992 end Has_Infinities;
10994 --------------------
10995 -- Has_Interfaces --
10996 --------------------
10998 function Has_Interfaces
10999 (T : Entity_Id;
11000 Use_Full_View : Boolean := True) return Boolean
11002 Typ : Entity_Id := Base_Type (T);
11004 begin
11005 -- Handle concurrent types
11007 if Is_Concurrent_Type (Typ) then
11008 Typ := Corresponding_Record_Type (Typ);
11009 end if;
11011 if not Present (Typ)
11012 or else not Is_Record_Type (Typ)
11013 or else not Is_Tagged_Type (Typ)
11014 then
11015 return False;
11016 end if;
11018 -- Handle private types
11020 if Use_Full_View and then Present (Full_View (Typ)) then
11021 Typ := Full_View (Typ);
11022 end if;
11024 -- Handle concurrent record types
11026 if Is_Concurrent_Record_Type (Typ)
11027 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
11028 then
11029 return True;
11030 end if;
11032 loop
11033 if Is_Interface (Typ)
11034 or else
11035 (Is_Record_Type (Typ)
11036 and then Present (Interfaces (Typ))
11037 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
11038 then
11039 return True;
11040 end if;
11042 exit when Etype (Typ) = Typ
11044 -- Handle private types
11046 or else (Present (Full_View (Etype (Typ)))
11047 and then Full_View (Etype (Typ)) = Typ)
11049 -- Protect frontend against wrong sources with cyclic derivations
11051 or else Etype (Typ) = T;
11053 -- Climb to the ancestor type handling private types
11055 if Present (Full_View (Etype (Typ))) then
11056 Typ := Full_View (Etype (Typ));
11057 else
11058 Typ := Etype (Typ);
11059 end if;
11060 end loop;
11062 return False;
11063 end Has_Interfaces;
11065 --------------------------
11066 -- Has_Max_Queue_Length --
11067 --------------------------
11069 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
11070 begin
11071 return
11072 Ekind (Id) = E_Entry
11073 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
11074 end Has_Max_Queue_Length;
11076 ---------------------------------
11077 -- Has_No_Obvious_Side_Effects --
11078 ---------------------------------
11080 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
11081 begin
11082 -- For now handle literals, constants, and non-volatile variables and
11083 -- expressions combining these with operators or short circuit forms.
11085 if Nkind (N) in N_Numeric_Or_String_Literal then
11086 return True;
11088 elsif Nkind (N) = N_Character_Literal then
11089 return True;
11091 elsif Nkind (N) in N_Unary_Op then
11092 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
11094 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
11095 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
11096 and then
11097 Has_No_Obvious_Side_Effects (Right_Opnd (N));
11099 elsif Nkind (N) = N_Expression_With_Actions
11100 and then Is_Empty_List (Actions (N))
11101 then
11102 return Has_No_Obvious_Side_Effects (Expression (N));
11104 elsif Nkind (N) in N_Has_Entity then
11105 return Present (Entity (N))
11106 and then Ekind_In (Entity (N), E_Variable,
11107 E_Constant,
11108 E_Enumeration_Literal,
11109 E_In_Parameter,
11110 E_Out_Parameter,
11111 E_In_Out_Parameter)
11112 and then not Is_Volatile (Entity (N));
11114 else
11115 return False;
11116 end if;
11117 end Has_No_Obvious_Side_Effects;
11119 -----------------------------
11120 -- Has_Non_Null_Refinement --
11121 -----------------------------
11123 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
11124 Constits : Elist_Id;
11126 begin
11127 pragma Assert (Ekind (Id) = E_Abstract_State);
11128 Constits := Refinement_Constituents (Id);
11130 -- For a refinement to be non-null, the first constituent must be
11131 -- anything other than null.
11133 return
11134 Present (Constits)
11135 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
11136 end Has_Non_Null_Refinement;
11138 -----------------------------
11139 -- Has_Non_Null_Statements --
11140 -----------------------------
11142 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11143 Node : Node_Id;
11145 begin
11146 if Is_Non_Empty_List (L) then
11147 Node := First (L);
11149 loop
11150 if Nkind (Node) /= N_Null_Statement then
11151 return True;
11152 end if;
11154 Next (Node);
11155 exit when Node = Empty;
11156 end loop;
11157 end if;
11159 return False;
11160 end Has_Non_Null_Statements;
11162 ----------------------------------
11163 -- Has_Non_Trivial_Precondition --
11164 ----------------------------------
11166 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
11167 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
11169 begin
11170 return
11171 Present (Pre)
11172 and then Class_Present (Pre)
11173 and then not Is_Entity_Name (Expression (Pre));
11174 end Has_Non_Trivial_Precondition;
11176 -------------------
11177 -- Has_Null_Body --
11178 -------------------
11180 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
11181 Body_Id : Entity_Id;
11182 Decl : Node_Id;
11183 Spec : Node_Id;
11184 Stmt1 : Node_Id;
11185 Stmt2 : Node_Id;
11187 begin
11188 Spec := Parent (Proc_Id);
11189 Decl := Parent (Spec);
11191 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11193 if Nkind (Spec) = N_Procedure_Specification
11194 and then Nkind (Decl) = N_Subprogram_Declaration
11195 then
11196 Body_Id := Corresponding_Body (Decl);
11198 -- The body acts as a spec
11200 else
11201 Body_Id := Proc_Id;
11202 end if;
11204 -- The body will be generated later
11206 if No (Body_Id) then
11207 return False;
11208 end if;
11210 Spec := Parent (Body_Id);
11211 Decl := Parent (Spec);
11213 pragma Assert
11214 (Nkind (Spec) = N_Procedure_Specification
11215 and then Nkind (Decl) = N_Subprogram_Body);
11217 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11219 -- Look for a null statement followed by an optional return
11220 -- statement.
11222 if Nkind (Stmt1) = N_Null_Statement then
11223 Stmt2 := Next (Stmt1);
11225 if Present (Stmt2) then
11226 return Nkind (Stmt2) = N_Simple_Return_Statement;
11227 else
11228 return True;
11229 end if;
11230 end if;
11232 return False;
11233 end Has_Null_Body;
11235 ------------------------
11236 -- Has_Null_Exclusion --
11237 ------------------------
11239 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11240 begin
11241 case Nkind (N) is
11242 when N_Access_Definition
11243 | N_Access_Function_Definition
11244 | N_Access_Procedure_Definition
11245 | N_Access_To_Object_Definition
11246 | N_Allocator
11247 | N_Derived_Type_Definition
11248 | N_Function_Specification
11249 | N_Subtype_Declaration
11251 return Null_Exclusion_Present (N);
11253 when N_Component_Definition
11254 | N_Formal_Object_Declaration
11255 | N_Object_Renaming_Declaration
11257 if Present (Subtype_Mark (N)) then
11258 return Null_Exclusion_Present (N);
11259 else pragma Assert (Present (Access_Definition (N)));
11260 return Null_Exclusion_Present (Access_Definition (N));
11261 end if;
11263 when N_Discriminant_Specification =>
11264 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11265 return Null_Exclusion_Present (Discriminant_Type (N));
11266 else
11267 return Null_Exclusion_Present (N);
11268 end if;
11270 when N_Object_Declaration =>
11271 if Nkind (Object_Definition (N)) = N_Access_Definition then
11272 return Null_Exclusion_Present (Object_Definition (N));
11273 else
11274 return Null_Exclusion_Present (N);
11275 end if;
11277 when N_Parameter_Specification =>
11278 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11279 return Null_Exclusion_Present (Parameter_Type (N));
11280 else
11281 return Null_Exclusion_Present (N);
11282 end if;
11284 when others =>
11285 return False;
11286 end case;
11287 end Has_Null_Exclusion;
11289 ------------------------
11290 -- Has_Null_Extension --
11291 ------------------------
11293 function Has_Null_Extension (T : Entity_Id) return Boolean is
11294 B : constant Entity_Id := Base_Type (T);
11295 Comps : Node_Id;
11296 Ext : Node_Id;
11298 begin
11299 if Nkind (Parent (B)) = N_Full_Type_Declaration
11300 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11301 then
11302 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11304 if Present (Ext) then
11305 if Null_Present (Ext) then
11306 return True;
11307 else
11308 Comps := Component_List (Ext);
11310 -- The null component list is rewritten during analysis to
11311 -- include the parent component. Any other component indicates
11312 -- that the extension was not originally null.
11314 return Null_Present (Comps)
11315 or else No (Next (First (Component_Items (Comps))));
11316 end if;
11317 else
11318 return False;
11319 end if;
11321 else
11322 return False;
11323 end if;
11324 end Has_Null_Extension;
11326 -------------------------
11327 -- Has_Null_Refinement --
11328 -------------------------
11330 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11331 Constits : Elist_Id;
11333 begin
11334 pragma Assert (Ekind (Id) = E_Abstract_State);
11335 Constits := Refinement_Constituents (Id);
11337 -- For a refinement to be null, the state's sole constituent must be a
11338 -- null.
11340 return
11341 Present (Constits)
11342 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11343 end Has_Null_Refinement;
11345 -------------------------------
11346 -- Has_Overriding_Initialize --
11347 -------------------------------
11349 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11350 BT : constant Entity_Id := Base_Type (T);
11351 P : Elmt_Id;
11353 begin
11354 if Is_Controlled (BT) then
11355 if Is_RTU (Scope (BT), Ada_Finalization) then
11356 return False;
11358 elsif Present (Primitive_Operations (BT)) then
11359 P := First_Elmt (Primitive_Operations (BT));
11360 while Present (P) loop
11361 declare
11362 Init : constant Entity_Id := Node (P);
11363 Formal : constant Entity_Id := First_Formal (Init);
11364 begin
11365 if Ekind (Init) = E_Procedure
11366 and then Chars (Init) = Name_Initialize
11367 and then Comes_From_Source (Init)
11368 and then Present (Formal)
11369 and then Etype (Formal) = BT
11370 and then No (Next_Formal (Formal))
11371 and then (Ada_Version < Ada_2012
11372 or else not Null_Present (Parent (Init)))
11373 then
11374 return True;
11375 end if;
11376 end;
11378 Next_Elmt (P);
11379 end loop;
11380 end if;
11382 -- Here if type itself does not have a non-null Initialize operation:
11383 -- check immediate ancestor.
11385 if Is_Derived_Type (BT)
11386 and then Has_Overriding_Initialize (Etype (BT))
11387 then
11388 return True;
11389 end if;
11390 end if;
11392 return False;
11393 end Has_Overriding_Initialize;
11395 --------------------------------------
11396 -- Has_Preelaborable_Initialization --
11397 --------------------------------------
11399 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11400 Has_PE : Boolean;
11402 procedure Check_Components (E : Entity_Id);
11403 -- Check component/discriminant chain, sets Has_PE False if a component
11404 -- or discriminant does not meet the preelaborable initialization rules.
11406 ----------------------
11407 -- Check_Components --
11408 ----------------------
11410 procedure Check_Components (E : Entity_Id) is
11411 Ent : Entity_Id;
11412 Exp : Node_Id;
11414 begin
11415 -- Loop through entities of record or protected type
11417 Ent := E;
11418 while Present (Ent) loop
11420 -- We are interested only in components and discriminants
11422 Exp := Empty;
11424 case Ekind (Ent) is
11425 when E_Component =>
11427 -- Get default expression if any. If there is no declaration
11428 -- node, it means we have an internal entity. The parent and
11429 -- tag fields are examples of such entities. For such cases,
11430 -- we just test the type of the entity.
11432 if Present (Declaration_Node (Ent)) then
11433 Exp := Expression (Declaration_Node (Ent));
11434 end if;
11436 when E_Discriminant =>
11438 -- Note: for a renamed discriminant, the Declaration_Node
11439 -- may point to the one from the ancestor, and have a
11440 -- different expression, so use the proper attribute to
11441 -- retrieve the expression from the derived constraint.
11443 Exp := Discriminant_Default_Value (Ent);
11445 when others =>
11446 goto Check_Next_Entity;
11447 end case;
11449 -- A component has PI if it has no default expression and the
11450 -- component type has PI.
11452 if No (Exp) then
11453 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11454 Has_PE := False;
11455 exit;
11456 end if;
11458 -- Require the default expression to be preelaborable
11460 elsif not Is_Preelaborable_Construct (Exp) then
11461 Has_PE := False;
11462 exit;
11463 end if;
11465 <<Check_Next_Entity>>
11466 Next_Entity (Ent);
11467 end loop;
11468 end Check_Components;
11470 -- Start of processing for Has_Preelaborable_Initialization
11472 begin
11473 -- Immediate return if already marked as known preelaborable init. This
11474 -- covers types for which this function has already been called once
11475 -- and returned True (in which case the result is cached), and also
11476 -- types to which a pragma Preelaborable_Initialization applies.
11478 if Known_To_Have_Preelab_Init (E) then
11479 return True;
11480 end if;
11482 -- If the type is a subtype representing a generic actual type, then
11483 -- test whether its base type has preelaborable initialization since
11484 -- the subtype representing the actual does not inherit this attribute
11485 -- from the actual or formal. (but maybe it should???)
11487 if Is_Generic_Actual_Type (E) then
11488 return Has_Preelaborable_Initialization (Base_Type (E));
11489 end if;
11491 -- All elementary types have preelaborable initialization
11493 if Is_Elementary_Type (E) then
11494 Has_PE := True;
11496 -- Array types have PI if the component type has PI
11498 elsif Is_Array_Type (E) then
11499 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11501 -- A derived type has preelaborable initialization if its parent type
11502 -- has preelaborable initialization and (in the case of a derived record
11503 -- extension) if the non-inherited components all have preelaborable
11504 -- initialization. However, a user-defined controlled type with an
11505 -- overriding Initialize procedure does not have preelaborable
11506 -- initialization.
11508 elsif Is_Derived_Type (E) then
11510 -- If the derived type is a private extension then it doesn't have
11511 -- preelaborable initialization.
11513 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11514 return False;
11515 end if;
11517 -- First check whether ancestor type has preelaborable initialization
11519 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11521 -- If OK, check extension components (if any)
11523 if Has_PE and then Is_Record_Type (E) then
11524 Check_Components (First_Entity (E));
11525 end if;
11527 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11528 -- with a user defined Initialize procedure does not have PI. If
11529 -- the type is untagged, the control primitives come from a component
11530 -- that has already been checked.
11532 if Has_PE
11533 and then Is_Controlled (E)
11534 and then Is_Tagged_Type (E)
11535 and then Has_Overriding_Initialize (E)
11536 then
11537 Has_PE := False;
11538 end if;
11540 -- Private types not derived from a type having preelaborable init and
11541 -- that are not marked with pragma Preelaborable_Initialization do not
11542 -- have preelaborable initialization.
11544 elsif Is_Private_Type (E) then
11545 return False;
11547 -- Record type has PI if it is non private and all components have PI
11549 elsif Is_Record_Type (E) then
11550 Has_PE := True;
11551 Check_Components (First_Entity (E));
11553 -- Protected types must not have entries, and components must meet
11554 -- same set of rules as for record components.
11556 elsif Is_Protected_Type (E) then
11557 if Has_Entries (E) then
11558 Has_PE := False;
11559 else
11560 Has_PE := True;
11561 Check_Components (First_Entity (E));
11562 Check_Components (First_Private_Entity (E));
11563 end if;
11565 -- Type System.Address always has preelaborable initialization
11567 elsif Is_RTE (E, RE_Address) then
11568 Has_PE := True;
11570 -- In all other cases, type does not have preelaborable initialization
11572 else
11573 return False;
11574 end if;
11576 -- If type has preelaborable initialization, cache result
11578 if Has_PE then
11579 Set_Known_To_Have_Preelab_Init (E);
11580 end if;
11582 return Has_PE;
11583 end Has_Preelaborable_Initialization;
11585 ----------------
11586 -- Has_Prefix --
11587 ----------------
11589 function Has_Prefix (N : Node_Id) return Boolean is
11590 begin
11591 return
11592 Nkind_In (N, N_Attribute_Reference,
11593 N_Expanded_Name,
11594 N_Explicit_Dereference,
11595 N_Indexed_Component,
11596 N_Reference,
11597 N_Selected_Component,
11598 N_Slice);
11599 end Has_Prefix;
11601 ---------------------------
11602 -- Has_Private_Component --
11603 ---------------------------
11605 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11606 Btype : Entity_Id := Base_Type (Type_Id);
11607 Component : Entity_Id;
11609 begin
11610 if Error_Posted (Type_Id)
11611 or else Error_Posted (Btype)
11612 then
11613 return False;
11614 end if;
11616 if Is_Class_Wide_Type (Btype) then
11617 Btype := Root_Type (Btype);
11618 end if;
11620 if Is_Private_Type (Btype) then
11621 declare
11622 UT : constant Entity_Id := Underlying_Type (Btype);
11623 begin
11624 if No (UT) then
11625 if No (Full_View (Btype)) then
11626 return not Is_Generic_Type (Btype)
11627 and then
11628 not Is_Generic_Type (Root_Type (Btype));
11629 else
11630 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11631 end if;
11632 else
11633 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11634 end if;
11635 end;
11637 elsif Is_Array_Type (Btype) then
11638 return Has_Private_Component (Component_Type (Btype));
11640 elsif Is_Record_Type (Btype) then
11641 Component := First_Component (Btype);
11642 while Present (Component) loop
11643 if Has_Private_Component (Etype (Component)) then
11644 return True;
11645 end if;
11647 Next_Component (Component);
11648 end loop;
11650 return False;
11652 elsif Is_Protected_Type (Btype)
11653 and then Present (Corresponding_Record_Type (Btype))
11654 then
11655 return Has_Private_Component (Corresponding_Record_Type (Btype));
11657 else
11658 return False;
11659 end if;
11660 end Has_Private_Component;
11662 ----------------------
11663 -- Has_Signed_Zeros --
11664 ----------------------
11666 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11667 begin
11668 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11669 end Has_Signed_Zeros;
11671 ------------------------------
11672 -- Has_Significant_Contract --
11673 ------------------------------
11675 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11676 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11678 begin
11679 -- _Finalizer procedure
11681 if Subp_Nam = Name_uFinalizer then
11682 return False;
11684 -- _Postconditions procedure
11686 elsif Subp_Nam = Name_uPostconditions then
11687 return False;
11689 -- Predicate function
11691 elsif Ekind (Subp_Id) = E_Function
11692 and then Is_Predicate_Function (Subp_Id)
11693 then
11694 return False;
11696 -- TSS subprogram
11698 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11699 return False;
11701 else
11702 return True;
11703 end if;
11704 end Has_Significant_Contract;
11706 -----------------------------
11707 -- Has_Static_Array_Bounds --
11708 -----------------------------
11710 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11711 All_Static : Boolean;
11712 Dummy : Boolean;
11714 begin
11715 Examine_Array_Bounds (Typ, All_Static, Dummy);
11717 return All_Static;
11718 end Has_Static_Array_Bounds;
11720 ---------------------------------------
11721 -- Has_Static_Non_Empty_Array_Bounds --
11722 ---------------------------------------
11724 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
11725 All_Static : Boolean;
11726 Has_Empty : Boolean;
11728 begin
11729 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
11731 return All_Static and not Has_Empty;
11732 end Has_Static_Non_Empty_Array_Bounds;
11734 ----------------
11735 -- Has_Stream --
11736 ----------------
11738 function Has_Stream (T : Entity_Id) return Boolean is
11739 E : Entity_Id;
11741 begin
11742 if No (T) then
11743 return False;
11745 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11746 return True;
11748 elsif Is_Array_Type (T) then
11749 return Has_Stream (Component_Type (T));
11751 elsif Is_Record_Type (T) then
11752 E := First_Component (T);
11753 while Present (E) loop
11754 if Has_Stream (Etype (E)) then
11755 return True;
11756 else
11757 Next_Component (E);
11758 end if;
11759 end loop;
11761 return False;
11763 elsif Is_Private_Type (T) then
11764 return Has_Stream (Underlying_Type (T));
11766 else
11767 return False;
11768 end if;
11769 end Has_Stream;
11771 ----------------
11772 -- Has_Suffix --
11773 ----------------
11775 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11776 begin
11777 Get_Name_String (Chars (E));
11778 return Name_Buffer (Name_Len) = Suffix;
11779 end Has_Suffix;
11781 ----------------
11782 -- Add_Suffix --
11783 ----------------
11785 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11786 begin
11787 Get_Name_String (Chars (E));
11788 Add_Char_To_Name_Buffer (Suffix);
11789 return Name_Find;
11790 end Add_Suffix;
11792 -------------------
11793 -- Remove_Suffix --
11794 -------------------
11796 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11797 begin
11798 pragma Assert (Has_Suffix (E, Suffix));
11799 Get_Name_String (Chars (E));
11800 Name_Len := Name_Len - 1;
11801 return Name_Find;
11802 end Remove_Suffix;
11804 ----------------------------------
11805 -- Replace_Null_By_Null_Address --
11806 ----------------------------------
11808 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11809 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11810 -- Replace operand Op with a reference to Null_Address when the operand
11811 -- denotes a null Address. Other_Op denotes the other operand.
11813 --------------------------
11814 -- Replace_Null_Operand --
11815 --------------------------
11817 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11818 begin
11819 -- Check the type of the complementary operand since the N_Null node
11820 -- has not been decorated yet.
11822 if Nkind (Op) = N_Null
11823 and then Is_Descendant_Of_Address (Etype (Other_Op))
11824 then
11825 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11826 end if;
11827 end Replace_Null_Operand;
11829 -- Start of processing for Replace_Null_By_Null_Address
11831 begin
11832 pragma Assert (Relaxed_RM_Semantics);
11833 pragma Assert (Nkind_In (N, N_Null,
11834 N_Op_Eq,
11835 N_Op_Ge,
11836 N_Op_Gt,
11837 N_Op_Le,
11838 N_Op_Lt,
11839 N_Op_Ne));
11841 if Nkind (N) = N_Null then
11842 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11844 else
11845 declare
11846 L : constant Node_Id := Left_Opnd (N);
11847 R : constant Node_Id := Right_Opnd (N);
11849 begin
11850 Replace_Null_Operand (L, Other_Op => R);
11851 Replace_Null_Operand (R, Other_Op => L);
11852 end;
11853 end if;
11854 end Replace_Null_By_Null_Address;
11856 --------------------------
11857 -- Has_Tagged_Component --
11858 --------------------------
11860 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11861 Comp : Entity_Id;
11863 begin
11864 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11865 return Has_Tagged_Component (Underlying_Type (Typ));
11867 elsif Is_Array_Type (Typ) then
11868 return Has_Tagged_Component (Component_Type (Typ));
11870 elsif Is_Tagged_Type (Typ) then
11871 return True;
11873 elsif Is_Record_Type (Typ) then
11874 Comp := First_Component (Typ);
11875 while Present (Comp) loop
11876 if Has_Tagged_Component (Etype (Comp)) then
11877 return True;
11878 end if;
11880 Next_Component (Comp);
11881 end loop;
11883 return False;
11885 else
11886 return False;
11887 end if;
11888 end Has_Tagged_Component;
11890 -----------------------------
11891 -- Has_Undefined_Reference --
11892 -----------------------------
11894 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11895 Has_Undef_Ref : Boolean := False;
11896 -- Flag set when expression Expr contains at least one undefined
11897 -- reference.
11899 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11900 -- Determine whether N denotes a reference and if it does, whether it is
11901 -- undefined.
11903 ----------------------------
11904 -- Is_Undefined_Reference --
11905 ----------------------------
11907 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11908 begin
11909 if Is_Entity_Name (N)
11910 and then Present (Entity (N))
11911 and then Entity (N) = Any_Id
11912 then
11913 Has_Undef_Ref := True;
11914 return Abandon;
11915 end if;
11917 return OK;
11918 end Is_Undefined_Reference;
11920 procedure Find_Undefined_References is
11921 new Traverse_Proc (Is_Undefined_Reference);
11923 -- Start of processing for Has_Undefined_Reference
11925 begin
11926 Find_Undefined_References (Expr);
11928 return Has_Undef_Ref;
11929 end Has_Undefined_Reference;
11931 ----------------------------
11932 -- Has_Volatile_Component --
11933 ----------------------------
11935 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11936 Comp : Entity_Id;
11938 begin
11939 if Has_Volatile_Components (Typ) then
11940 return True;
11942 elsif Is_Array_Type (Typ) then
11943 return Is_Volatile (Component_Type (Typ));
11945 elsif Is_Record_Type (Typ) then
11946 Comp := First_Component (Typ);
11947 while Present (Comp) loop
11948 if Is_Volatile_Object (Comp) then
11949 return True;
11950 end if;
11952 Comp := Next_Component (Comp);
11953 end loop;
11954 end if;
11956 return False;
11957 end Has_Volatile_Component;
11959 -------------------------
11960 -- Implementation_Kind --
11961 -------------------------
11963 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11964 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11965 Arg : Node_Id;
11966 begin
11967 pragma Assert (Present (Impl_Prag));
11968 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11969 return Chars (Get_Pragma_Arg (Arg));
11970 end Implementation_Kind;
11972 --------------------------
11973 -- Implements_Interface --
11974 --------------------------
11976 function Implements_Interface
11977 (Typ_Ent : Entity_Id;
11978 Iface_Ent : Entity_Id;
11979 Exclude_Parents : Boolean := False) return Boolean
11981 Ifaces_List : Elist_Id;
11982 Elmt : Elmt_Id;
11983 Iface : Entity_Id := Base_Type (Iface_Ent);
11984 Typ : Entity_Id := Base_Type (Typ_Ent);
11986 begin
11987 if Is_Class_Wide_Type (Typ) then
11988 Typ := Root_Type (Typ);
11989 end if;
11991 if not Has_Interfaces (Typ) then
11992 return False;
11993 end if;
11995 if Is_Class_Wide_Type (Iface) then
11996 Iface := Root_Type (Iface);
11997 end if;
11999 Collect_Interfaces (Typ, Ifaces_List);
12001 Elmt := First_Elmt (Ifaces_List);
12002 while Present (Elmt) loop
12003 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
12004 and then Exclude_Parents
12005 then
12006 null;
12008 elsif Node (Elmt) = Iface then
12009 return True;
12010 end if;
12012 Next_Elmt (Elmt);
12013 end loop;
12015 return False;
12016 end Implements_Interface;
12018 ------------------------------------
12019 -- In_Assertion_Expression_Pragma --
12020 ------------------------------------
12022 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
12023 Par : Node_Id;
12024 Prag : Node_Id := Empty;
12026 begin
12027 -- Climb the parent chain looking for an enclosing pragma
12029 Par := N;
12030 while Present (Par) loop
12031 if Nkind (Par) = N_Pragma then
12032 Prag := Par;
12033 exit;
12035 -- Precondition-like pragmas are expanded into if statements, check
12036 -- the original node instead.
12038 elsif Nkind (Original_Node (Par)) = N_Pragma then
12039 Prag := Original_Node (Par);
12040 exit;
12042 -- The expansion of attribute 'Old generates a constant to capture
12043 -- the result of the prefix. If the parent traversal reaches
12044 -- one of these constants, then the node technically came from a
12045 -- postcondition-like pragma. Note that the Ekind is not tested here
12046 -- because N may be the expression of an object declaration which is
12047 -- currently being analyzed. Such objects carry Ekind of E_Void.
12049 elsif Nkind (Par) = N_Object_Declaration
12050 and then Constant_Present (Par)
12051 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
12052 then
12053 return True;
12055 -- Prevent the search from going too far
12057 elsif Is_Body_Or_Package_Declaration (Par) then
12058 return False;
12059 end if;
12061 Par := Parent (Par);
12062 end loop;
12064 return
12065 Present (Prag)
12066 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
12067 end In_Assertion_Expression_Pragma;
12069 ----------------------
12070 -- In_Generic_Scope --
12071 ----------------------
12073 function In_Generic_Scope (E : Entity_Id) return Boolean is
12074 S : Entity_Id;
12076 begin
12077 S := Scope (E);
12078 while Present (S) and then S /= Standard_Standard loop
12079 if Is_Generic_Unit (S) then
12080 return True;
12081 end if;
12083 S := Scope (S);
12084 end loop;
12086 return False;
12087 end In_Generic_Scope;
12089 -----------------
12090 -- In_Instance --
12091 -----------------
12093 function In_Instance return Boolean is
12094 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12095 S : Entity_Id;
12097 begin
12098 S := Current_Scope;
12099 while Present (S) and then S /= Standard_Standard loop
12100 if Is_Generic_Instance (S) then
12102 -- A child instance is always compiled in the context of a parent
12103 -- instance. Nevertheless, the actuals are not analyzed in an
12104 -- instance context. We detect this case by examining the current
12105 -- compilation unit, which must be a child instance, and checking
12106 -- that it is not currently on the scope stack.
12108 if Is_Child_Unit (Curr_Unit)
12109 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
12110 N_Package_Instantiation
12111 and then not In_Open_Scopes (Curr_Unit)
12112 then
12113 return False;
12114 else
12115 return True;
12116 end if;
12117 end if;
12119 S := Scope (S);
12120 end loop;
12122 return False;
12123 end In_Instance;
12125 ----------------------
12126 -- In_Instance_Body --
12127 ----------------------
12129 function In_Instance_Body return Boolean is
12130 S : Entity_Id;
12132 begin
12133 S := Current_Scope;
12134 while Present (S) and then S /= Standard_Standard loop
12135 if Ekind_In (S, E_Function, E_Procedure)
12136 and then Is_Generic_Instance (S)
12137 then
12138 return True;
12140 elsif Ekind (S) = E_Package
12141 and then In_Package_Body (S)
12142 and then Is_Generic_Instance (S)
12143 then
12144 return True;
12145 end if;
12147 S := Scope (S);
12148 end loop;
12150 return False;
12151 end In_Instance_Body;
12153 -----------------------------
12154 -- In_Instance_Not_Visible --
12155 -----------------------------
12157 function In_Instance_Not_Visible return Boolean is
12158 S : Entity_Id;
12160 begin
12161 S := Current_Scope;
12162 while Present (S) and then S /= Standard_Standard loop
12163 if Ekind_In (S, E_Function, E_Procedure)
12164 and then Is_Generic_Instance (S)
12165 then
12166 return True;
12168 elsif Ekind (S) = E_Package
12169 and then (In_Package_Body (S) or else In_Private_Part (S))
12170 and then Is_Generic_Instance (S)
12171 then
12172 return True;
12173 end if;
12175 S := Scope (S);
12176 end loop;
12178 return False;
12179 end In_Instance_Not_Visible;
12181 ------------------------------
12182 -- In_Instance_Visible_Part --
12183 ------------------------------
12185 function In_Instance_Visible_Part
12186 (Id : Entity_Id := Current_Scope) return Boolean
12188 Inst : Entity_Id;
12190 begin
12191 Inst := Id;
12192 while Present (Inst) and then Inst /= Standard_Standard loop
12193 if Ekind (Inst) = E_Package
12194 and then Is_Generic_Instance (Inst)
12195 and then not In_Package_Body (Inst)
12196 and then not In_Private_Part (Inst)
12197 then
12198 return True;
12199 end if;
12201 Inst := Scope (Inst);
12202 end loop;
12204 return False;
12205 end In_Instance_Visible_Part;
12207 ---------------------
12208 -- In_Package_Body --
12209 ---------------------
12211 function In_Package_Body return Boolean is
12212 S : Entity_Id;
12214 begin
12215 S := Current_Scope;
12216 while Present (S) and then S /= Standard_Standard loop
12217 if Ekind (S) = E_Package and then In_Package_Body (S) then
12218 return True;
12219 else
12220 S := Scope (S);
12221 end if;
12222 end loop;
12224 return False;
12225 end In_Package_Body;
12227 --------------------------
12228 -- In_Pragma_Expression --
12229 --------------------------
12231 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12232 P : Node_Id;
12233 begin
12234 P := Parent (N);
12235 loop
12236 if No (P) then
12237 return False;
12238 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12239 return True;
12240 else
12241 P := Parent (P);
12242 end if;
12243 end loop;
12244 end In_Pragma_Expression;
12246 ---------------------------
12247 -- In_Pre_Post_Condition --
12248 ---------------------------
12250 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12251 Par : Node_Id;
12252 Prag : Node_Id := Empty;
12253 Prag_Id : Pragma_Id;
12255 begin
12256 -- Climb the parent chain looking for an enclosing pragma
12258 Par := N;
12259 while Present (Par) loop
12260 if Nkind (Par) = N_Pragma then
12261 Prag := Par;
12262 exit;
12264 -- Prevent the search from going too far
12266 elsif Is_Body_Or_Package_Declaration (Par) then
12267 exit;
12268 end if;
12270 Par := Parent (Par);
12271 end loop;
12273 if Present (Prag) then
12274 Prag_Id := Get_Pragma_Id (Prag);
12276 return
12277 Prag_Id = Pragma_Post
12278 or else Prag_Id = Pragma_Post_Class
12279 or else Prag_Id = Pragma_Postcondition
12280 or else Prag_Id = Pragma_Pre
12281 or else Prag_Id = Pragma_Pre_Class
12282 or else Prag_Id = Pragma_Precondition;
12284 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12286 else
12287 return False;
12288 end if;
12289 end In_Pre_Post_Condition;
12291 -------------------------------------
12292 -- In_Reverse_Storage_Order_Object --
12293 -------------------------------------
12295 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12296 Pref : Node_Id;
12297 Btyp : Entity_Id := Empty;
12299 begin
12300 -- Climb up indexed components
12302 Pref := N;
12303 loop
12304 case Nkind (Pref) is
12305 when N_Selected_Component =>
12306 Pref := Prefix (Pref);
12307 exit;
12309 when N_Indexed_Component =>
12310 Pref := Prefix (Pref);
12312 when others =>
12313 Pref := Empty;
12314 exit;
12315 end case;
12316 end loop;
12318 if Present (Pref) then
12319 Btyp := Base_Type (Etype (Pref));
12320 end if;
12322 return Present (Btyp)
12323 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12324 and then Reverse_Storage_Order (Btyp);
12325 end In_Reverse_Storage_Order_Object;
12327 ------------------------------
12328 -- In_Same_Declarative_Part --
12329 ------------------------------
12331 function In_Same_Declarative_Part
12332 (Context : Node_Id;
12333 N : Node_Id) return Boolean
12335 Cont : Node_Id := Context;
12336 Nod : Node_Id;
12338 begin
12339 if Nkind (Cont) = N_Compilation_Unit_Aux then
12340 Cont := Parent (Cont);
12341 end if;
12343 Nod := Parent (N);
12344 while Present (Nod) loop
12345 if Nod = Cont then
12346 return True;
12348 elsif Nkind_In (Nod, N_Accept_Statement,
12349 N_Block_Statement,
12350 N_Compilation_Unit,
12351 N_Entry_Body,
12352 N_Package_Body,
12353 N_Package_Declaration,
12354 N_Protected_Body,
12355 N_Subprogram_Body,
12356 N_Task_Body)
12357 then
12358 return False;
12360 elsif Nkind (Nod) = N_Subunit then
12361 Nod := Corresponding_Stub (Nod);
12363 else
12364 Nod := Parent (Nod);
12365 end if;
12366 end loop;
12368 return False;
12369 end In_Same_Declarative_Part;
12371 --------------------------------------
12372 -- In_Subprogram_Or_Concurrent_Unit --
12373 --------------------------------------
12375 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12376 E : Entity_Id;
12377 K : Entity_Kind;
12379 begin
12380 -- Use scope chain to check successively outer scopes
12382 E := Current_Scope;
12383 loop
12384 K := Ekind (E);
12386 if K in Subprogram_Kind
12387 or else K in Concurrent_Kind
12388 or else K in Generic_Subprogram_Kind
12389 then
12390 return True;
12392 elsif E = Standard_Standard then
12393 return False;
12394 end if;
12396 E := Scope (E);
12397 end loop;
12398 end In_Subprogram_Or_Concurrent_Unit;
12400 ----------------
12401 -- In_Subtree --
12402 ----------------
12404 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12405 Curr : Node_Id;
12407 begin
12408 Curr := N;
12409 while Present (Curr) loop
12410 if Curr = Root then
12411 return True;
12412 end if;
12414 Curr := Parent (Curr);
12415 end loop;
12417 return False;
12418 end In_Subtree;
12420 ----------------
12421 -- In_Subtree --
12422 ----------------
12424 function In_Subtree
12425 (N : Node_Id;
12426 Root1 : Node_Id;
12427 Root2 : Node_Id) return Boolean
12429 Curr : Node_Id;
12431 begin
12432 Curr := N;
12433 while Present (Curr) loop
12434 if Curr = Root1 or else Curr = Root2 then
12435 return True;
12436 end if;
12438 Curr := Parent (Curr);
12439 end loop;
12441 return False;
12442 end In_Subtree;
12444 ---------------------
12445 -- In_Visible_Part --
12446 ---------------------
12448 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12449 begin
12450 return Is_Package_Or_Generic_Package (Scope_Id)
12451 and then In_Open_Scopes (Scope_Id)
12452 and then not In_Package_Body (Scope_Id)
12453 and then not In_Private_Part (Scope_Id);
12454 end In_Visible_Part;
12456 --------------------------------
12457 -- Incomplete_Or_Partial_View --
12458 --------------------------------
12460 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12461 function Inspect_Decls
12462 (Decls : List_Id;
12463 Taft : Boolean := False) return Entity_Id;
12464 -- Check whether a declarative region contains the incomplete or partial
12465 -- view of Id.
12467 -------------------
12468 -- Inspect_Decls --
12469 -------------------
12471 function Inspect_Decls
12472 (Decls : List_Id;
12473 Taft : Boolean := False) return Entity_Id
12475 Decl : Node_Id;
12476 Match : Node_Id;
12478 begin
12479 Decl := First (Decls);
12480 while Present (Decl) loop
12481 Match := Empty;
12483 -- The partial view of a Taft-amendment type is an incomplete
12484 -- type.
12486 if Taft then
12487 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12488 Match := Defining_Identifier (Decl);
12489 end if;
12491 -- Otherwise look for a private type whose full view matches the
12492 -- input type. Note that this checks full_type_declaration nodes
12493 -- to account for derivations from a private type where the type
12494 -- declaration hold the partial view and the full view is an
12495 -- itype.
12497 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12498 N_Private_Extension_Declaration,
12499 N_Private_Type_Declaration)
12500 then
12501 Match := Defining_Identifier (Decl);
12502 end if;
12504 -- Guard against unanalyzed entities
12506 if Present (Match)
12507 and then Is_Type (Match)
12508 and then Present (Full_View (Match))
12509 and then Full_View (Match) = Id
12510 then
12511 return Match;
12512 end if;
12514 Next (Decl);
12515 end loop;
12517 return Empty;
12518 end Inspect_Decls;
12520 -- Local variables
12522 Prev : Entity_Id;
12524 -- Start of processing for Incomplete_Or_Partial_View
12526 begin
12527 -- Deferred constant or incomplete type case
12529 Prev := Current_Entity_In_Scope (Id);
12531 if Present (Prev)
12532 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12533 and then Present (Full_View (Prev))
12534 and then Full_View (Prev) = Id
12535 then
12536 return Prev;
12537 end if;
12539 -- Private or Taft amendment type case
12541 declare
12542 Pkg : constant Entity_Id := Scope (Id);
12543 Pkg_Decl : Node_Id := Pkg;
12545 begin
12546 if Present (Pkg)
12547 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12548 then
12549 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12550 Pkg_Decl := Parent (Pkg_Decl);
12551 end loop;
12553 -- It is knows that Typ has a private view, look for it in the
12554 -- visible declarations of the enclosing scope. A special case
12555 -- of this is when the two views have been exchanged - the full
12556 -- appears earlier than the private.
12558 if Has_Private_Declaration (Id) then
12559 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12561 -- Exchanged view case, look in the private declarations
12563 if No (Prev) then
12564 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12565 end if;
12567 return Prev;
12569 -- Otherwise if this is the package body, then Typ is a potential
12570 -- Taft amendment type. The incomplete view should be located in
12571 -- the private declarations of the enclosing scope.
12573 elsif In_Package_Body (Pkg) then
12574 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12575 end if;
12576 end if;
12577 end;
12579 -- The type has no incomplete or private view
12581 return Empty;
12582 end Incomplete_Or_Partial_View;
12584 ---------------------------------------
12585 -- Incomplete_View_From_Limited_With --
12586 ---------------------------------------
12588 function Incomplete_View_From_Limited_With
12589 (Typ : Entity_Id) return Entity_Id
12591 begin
12592 -- It might make sense to make this an attribute in Einfo, and set it
12593 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12594 -- slots for new attributes, and it seems a bit simpler to just search
12595 -- the Limited_View (if it exists) for an incomplete type whose
12596 -- Non_Limited_View is Typ.
12598 if Ekind (Scope (Typ)) = E_Package
12599 and then Present (Limited_View (Scope (Typ)))
12600 then
12601 declare
12602 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12603 begin
12604 while Present (Ent) loop
12605 if Ekind (Ent) in Incomplete_Kind
12606 and then Non_Limited_View (Ent) = Typ
12607 then
12608 return Ent;
12609 end if;
12611 Ent := Next_Entity (Ent);
12612 end loop;
12613 end;
12614 end if;
12616 return Typ;
12617 end Incomplete_View_From_Limited_With;
12619 ----------------------------------
12620 -- Indexed_Component_Bit_Offset --
12621 ----------------------------------
12623 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12624 Exp : constant Node_Id := First (Expressions (N));
12625 Typ : constant Entity_Id := Etype (Prefix (N));
12626 Off : constant Uint := Component_Size (Typ);
12627 Ind : Node_Id;
12629 begin
12630 -- Return early if the component size is not known or variable
12632 if Off = No_Uint or else Off < Uint_0 then
12633 return No_Uint;
12634 end if;
12636 -- Deal with the degenerate case of an empty component
12638 if Off = Uint_0 then
12639 return Off;
12640 end if;
12642 -- Check that both the index value and the low bound are known
12644 if not Compile_Time_Known_Value (Exp) then
12645 return No_Uint;
12646 end if;
12648 Ind := First_Index (Typ);
12649 if No (Ind) then
12650 return No_Uint;
12651 end if;
12653 if Nkind (Ind) = N_Subtype_Indication then
12654 Ind := Constraint (Ind);
12656 if Nkind (Ind) = N_Range_Constraint then
12657 Ind := Range_Expression (Ind);
12658 end if;
12659 end if;
12661 if Nkind (Ind) /= N_Range
12662 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12663 then
12664 return No_Uint;
12665 end if;
12667 -- Return the scaled offset
12669 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12670 end Indexed_Component_Bit_Offset;
12672 ----------------------------
12673 -- Inherit_Rep_Item_Chain --
12674 ----------------------------
12676 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12677 Item : Node_Id;
12678 Next_Item : Node_Id;
12680 begin
12681 -- There are several inheritance scenarios to consider depending on
12682 -- whether both types have rep item chains and whether the destination
12683 -- type already inherits part of the source type's rep item chain.
12685 -- 1) The source type lacks a rep item chain
12686 -- From_Typ ---> Empty
12688 -- Typ --------> Item (or Empty)
12690 -- In this case inheritance cannot take place because there are no items
12691 -- to inherit.
12693 -- 2) The destination type lacks a rep item chain
12694 -- From_Typ ---> Item ---> ...
12696 -- Typ --------> Empty
12698 -- Inheritance takes place by setting the First_Rep_Item of the
12699 -- destination type to the First_Rep_Item of the source type.
12700 -- From_Typ ---> Item ---> ...
12701 -- ^
12702 -- Typ -----------+
12704 -- 3.1) Both source and destination types have at least one rep item.
12705 -- The destination type does NOT inherit a rep item from the source
12706 -- type.
12707 -- From_Typ ---> Item ---> Item
12709 -- Typ --------> Item ---> Item
12711 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12712 -- of the destination type to the First_Rep_Item of the source type.
12713 -- From_Typ -------------------> Item ---> Item
12714 -- ^
12715 -- Typ --------> Item ---> Item --+
12717 -- 3.2) Both source and destination types have at least one rep item.
12718 -- The destination type DOES inherit part of the rep item chain of the
12719 -- source type.
12720 -- From_Typ ---> Item ---> Item ---> Item
12721 -- ^
12722 -- Typ --------> Item ------+
12724 -- This rare case arises when the full view of a private extension must
12725 -- inherit the rep item chain from the full view of its parent type and
12726 -- the full view of the parent type contains extra rep items. Currently
12727 -- only invariants may lead to such form of inheritance.
12729 -- type From_Typ is tagged private
12730 -- with Type_Invariant'Class => Item_2;
12732 -- type Typ is new From_Typ with private
12733 -- with Type_Invariant => Item_4;
12735 -- At this point the rep item chains contain the following items
12737 -- From_Typ -----------> Item_2 ---> Item_3
12738 -- ^
12739 -- Typ --------> Item_4 --+
12741 -- The full views of both types may introduce extra invariants
12743 -- type From_Typ is tagged null record
12744 -- with Type_Invariant => Item_1;
12746 -- type Typ is new From_Typ with null record;
12748 -- The full view of Typ would have to inherit any new rep items added to
12749 -- the full view of From_Typ.
12751 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12752 -- ^
12753 -- Typ --------> Item_4 --+
12755 -- To achieve this form of inheritance, the destination type must first
12756 -- sever the link between its own rep chain and that of the source type,
12757 -- then inheritance 3.1 takes place.
12759 -- Case 1: The source type lacks a rep item chain
12761 if No (First_Rep_Item (From_Typ)) then
12762 return;
12764 -- Case 2: The destination type lacks a rep item chain
12766 elsif No (First_Rep_Item (Typ)) then
12767 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12769 -- Case 3: Both the source and destination types have at least one rep
12770 -- item. Traverse the rep item chain of the destination type to find the
12771 -- last rep item.
12773 else
12774 Item := Empty;
12775 Next_Item := First_Rep_Item (Typ);
12776 while Present (Next_Item) loop
12778 -- Detect a link between the destination type's rep chain and that
12779 -- of the source type. There are two possibilities:
12781 -- Variant 1
12782 -- Next_Item
12783 -- V
12784 -- From_Typ ---> Item_1 --->
12785 -- ^
12786 -- Typ -----------+
12788 -- Item is Empty
12790 -- Variant 2
12791 -- Next_Item
12792 -- V
12793 -- From_Typ ---> Item_1 ---> Item_2 --->
12794 -- ^
12795 -- Typ --------> Item_3 ------+
12796 -- ^
12797 -- Item
12799 if Has_Rep_Item (From_Typ, Next_Item) then
12800 exit;
12801 end if;
12803 Item := Next_Item;
12804 Next_Item := Next_Rep_Item (Next_Item);
12805 end loop;
12807 -- Inherit the source type's rep item chain
12809 if Present (Item) then
12810 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12811 else
12812 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12813 end if;
12814 end if;
12815 end Inherit_Rep_Item_Chain;
12817 ------------------------------------
12818 -- Inherits_From_Tagged_Full_View --
12819 ------------------------------------
12821 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
12822 begin
12823 return Is_Private_Type (Typ)
12824 and then Present (Full_View (Typ))
12825 and then Is_Private_Type (Full_View (Typ))
12826 and then not Is_Tagged_Type (Full_View (Typ))
12827 and then Present (Underlying_Type (Full_View (Typ)))
12828 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
12829 end Inherits_From_Tagged_Full_View;
12831 ---------------------------------
12832 -- Insert_Explicit_Dereference --
12833 ---------------------------------
12835 procedure Insert_Explicit_Dereference (N : Node_Id) is
12836 New_Prefix : constant Node_Id := Relocate_Node (N);
12837 Ent : Entity_Id := Empty;
12838 Pref : Node_Id;
12839 I : Interp_Index;
12840 It : Interp;
12841 T : Entity_Id;
12843 begin
12844 Save_Interps (N, New_Prefix);
12846 Rewrite (N,
12847 Make_Explicit_Dereference (Sloc (Parent (N)),
12848 Prefix => New_Prefix));
12850 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12852 if Is_Overloaded (New_Prefix) then
12854 -- The dereference is also overloaded, and its interpretations are
12855 -- the designated types of the interpretations of the original node.
12857 Set_Etype (N, Any_Type);
12859 Get_First_Interp (New_Prefix, I, It);
12860 while Present (It.Nam) loop
12861 T := It.Typ;
12863 if Is_Access_Type (T) then
12864 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12865 end if;
12867 Get_Next_Interp (I, It);
12868 end loop;
12870 End_Interp_List;
12872 else
12873 -- Prefix is unambiguous: mark the original prefix (which might
12874 -- Come_From_Source) as a reference, since the new (relocated) one
12875 -- won't be taken into account.
12877 if Is_Entity_Name (New_Prefix) then
12878 Ent := Entity (New_Prefix);
12879 Pref := New_Prefix;
12881 -- For a retrieval of a subcomponent of some composite object,
12882 -- retrieve the ultimate entity if there is one.
12884 elsif Nkind_In (New_Prefix, N_Selected_Component,
12885 N_Indexed_Component)
12886 then
12887 Pref := Prefix (New_Prefix);
12888 while Present (Pref)
12889 and then Nkind_In (Pref, N_Selected_Component,
12890 N_Indexed_Component)
12891 loop
12892 Pref := Prefix (Pref);
12893 end loop;
12895 if Present (Pref) and then Is_Entity_Name (Pref) then
12896 Ent := Entity (Pref);
12897 end if;
12898 end if;
12900 -- Place the reference on the entity node
12902 if Present (Ent) then
12903 Generate_Reference (Ent, Pref);
12904 end if;
12905 end if;
12906 end Insert_Explicit_Dereference;
12908 ------------------------------------------
12909 -- Inspect_Deferred_Constant_Completion --
12910 ------------------------------------------
12912 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12913 Decl : Node_Id;
12915 begin
12916 Decl := First (Decls);
12917 while Present (Decl) loop
12919 -- Deferred constant signature
12921 if Nkind (Decl) = N_Object_Declaration
12922 and then Constant_Present (Decl)
12923 and then No (Expression (Decl))
12925 -- No need to check internally generated constants
12927 and then Comes_From_Source (Decl)
12929 -- The constant is not completed. A full object declaration or a
12930 -- pragma Import complete a deferred constant.
12932 and then not Has_Completion (Defining_Identifier (Decl))
12933 then
12934 Error_Msg_N
12935 ("constant declaration requires initialization expression",
12936 Defining_Identifier (Decl));
12937 end if;
12939 Decl := Next (Decl);
12940 end loop;
12941 end Inspect_Deferred_Constant_Completion;
12943 -------------------------------
12944 -- Install_Elaboration_Model --
12945 -------------------------------
12947 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
12948 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
12949 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
12950 -- Empty if there is no such pragma.
12952 ------------------------------------
12953 -- Find_Elaboration_Checks_Pragma --
12954 ------------------------------------
12956 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
12957 Item : Node_Id;
12959 begin
12960 Item := First (L);
12961 while Present (Item) loop
12962 if Nkind (Item) = N_Pragma
12963 and then Pragma_Name (Item) = Name_Elaboration_Checks
12964 then
12965 return Item;
12966 end if;
12968 Next (Item);
12969 end loop;
12971 return Empty;
12972 end Find_Elaboration_Checks_Pragma;
12974 -- Local variables
12976 Args : List_Id;
12977 Model : Node_Id;
12978 Prag : Node_Id;
12979 Unit : Node_Id;
12981 -- Start of processing for Install_Elaboration_Model
12983 begin
12984 -- Nothing to do when the unit does not exist
12986 if No (Unit_Id) then
12987 return;
12988 end if;
12990 Unit := Parent (Unit_Declaration_Node (Unit_Id));
12992 -- Nothing to do when the unit is not a library unit
12994 if Nkind (Unit) /= N_Compilation_Unit then
12995 return;
12996 end if;
12998 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
13000 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13001 -- elaboration model as specified by the pragma.
13003 if Present (Prag) then
13004 Args := Pragma_Argument_Associations (Prag);
13006 -- Guard against an illegal pragma. The sole argument must be an
13007 -- identifier which specifies either Dynamic or Static model.
13009 if Present (Args) then
13010 Model := Get_Pragma_Arg (First (Args));
13012 if Nkind (Model) = N_Identifier then
13013 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
13014 end if;
13015 end if;
13016 end if;
13017 end Install_Elaboration_Model;
13019 -----------------------------
13020 -- Install_Generic_Formals --
13021 -----------------------------
13023 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
13024 E : Entity_Id;
13026 begin
13027 pragma Assert (Is_Generic_Subprogram (Subp_Id));
13029 E := First_Entity (Subp_Id);
13030 while Present (E) loop
13031 Install_Entity (E);
13032 Next_Entity (E);
13033 end loop;
13034 end Install_Generic_Formals;
13036 ------------------------
13037 -- Install_SPARK_Mode --
13038 ------------------------
13040 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
13041 begin
13042 SPARK_Mode := Mode;
13043 SPARK_Mode_Pragma := Prag;
13044 end Install_SPARK_Mode;
13046 --------------------------
13047 -- Invalid_Scalar_Value --
13048 --------------------------
13050 function Invalid_Scalar_Value
13051 (Loc : Source_Ptr;
13052 Scal_Typ : Scalar_Id) return Node_Id
13054 function Invalid_Binder_Value return Node_Id;
13055 -- Return a reference to the corresponding invalid value for type
13056 -- Scal_Typ as defined in unit System.Scalar_Values.
13058 function Invalid_Float_Value return Node_Id;
13059 -- Return the invalid value of float type Scal_Typ
13061 function Invalid_Integer_Value return Node_Id;
13062 -- Return the invalid value of integer type Scal_Typ
13064 procedure Set_Invalid_Binder_Values;
13065 -- Set the contents of collection Invalid_Binder_Values
13067 --------------------------
13068 -- Invalid_Binder_Value --
13069 --------------------------
13071 function Invalid_Binder_Value return Node_Id is
13072 Val_Id : Entity_Id;
13074 begin
13075 -- Initialize the collection of invalid binder values the first time
13076 -- around.
13078 Set_Invalid_Binder_Values;
13080 -- Obtain the corresponding variable from System.Scalar_Values which
13081 -- holds the invalid value for this type.
13083 Val_Id := Invalid_Binder_Values (Scal_Typ);
13084 pragma Assert (Present (Val_Id));
13086 return New_Occurrence_Of (Val_Id, Loc);
13087 end Invalid_Binder_Value;
13089 -------------------------
13090 -- Invalid_Float_Value --
13091 -------------------------
13093 function Invalid_Float_Value return Node_Id is
13094 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13096 begin
13097 -- Pragma Invalid_Scalars did not specify an invalid value for this
13098 -- type. Fall back to the value provided by the binder.
13100 if Value = No_Ureal then
13101 return Invalid_Binder_Value;
13102 else
13103 return Make_Real_Literal (Loc, Realval => Value);
13104 end if;
13105 end Invalid_Float_Value;
13107 ---------------------------
13108 -- Invalid_Integer_Value --
13109 ---------------------------
13111 function Invalid_Integer_Value return Node_Id is
13112 Value : constant Uint := Invalid_Integers (Scal_Typ);
13114 begin
13115 -- Pragma Invalid_Scalars did not specify an invalid value for this
13116 -- type. Fall back to the value provided by the binder.
13118 if Value = No_Uint then
13119 return Invalid_Binder_Value;
13120 else
13121 return Make_Integer_Literal (Loc, Intval => Value);
13122 end if;
13123 end Invalid_Integer_Value;
13125 -------------------------------
13126 -- Set_Invalid_Binder_Values --
13127 -------------------------------
13129 procedure Set_Invalid_Binder_Values is
13130 begin
13131 if not Invalid_Binder_Values_Set then
13132 Invalid_Binder_Values_Set := True;
13134 -- Initialize the contents of the collection once since RTE calls
13135 -- are not cheap.
13137 Invalid_Binder_Values :=
13138 (Name_Short_Float => RTE (RE_IS_Isf),
13139 Name_Float => RTE (RE_IS_Ifl),
13140 Name_Long_Float => RTE (RE_IS_Ilf),
13141 Name_Long_Long_Float => RTE (RE_IS_Ill),
13142 Name_Signed_8 => RTE (RE_IS_Is1),
13143 Name_Signed_16 => RTE (RE_IS_Is2),
13144 Name_Signed_32 => RTE (RE_IS_Is4),
13145 Name_Signed_64 => RTE (RE_IS_Is8),
13146 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13147 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13148 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13149 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13150 end if;
13151 end Set_Invalid_Binder_Values;
13153 -- Start of processing for Invalid_Scalar_Value
13155 begin
13156 if Scal_Typ in Float_Scalar_Id then
13157 return Invalid_Float_Value;
13159 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13160 return Invalid_Integer_Value;
13161 end if;
13162 end Invalid_Scalar_Value;
13164 -----------------------------
13165 -- Is_Actual_Out_Parameter --
13166 -----------------------------
13168 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
13169 Formal : Entity_Id;
13170 Call : Node_Id;
13171 begin
13172 Find_Actual (N, Formal, Call);
13173 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
13174 end Is_Actual_Out_Parameter;
13176 -------------------------
13177 -- Is_Actual_Parameter --
13178 -------------------------
13180 function Is_Actual_Parameter (N : Node_Id) return Boolean is
13181 PK : constant Node_Kind := Nkind (Parent (N));
13183 begin
13184 case PK is
13185 when N_Parameter_Association =>
13186 return N = Explicit_Actual_Parameter (Parent (N));
13188 when N_Subprogram_Call =>
13189 return Is_List_Member (N)
13190 and then
13191 List_Containing (N) = Parameter_Associations (Parent (N));
13193 when others =>
13194 return False;
13195 end case;
13196 end Is_Actual_Parameter;
13198 --------------------------------
13199 -- Is_Actual_Tagged_Parameter --
13200 --------------------------------
13202 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
13203 Formal : Entity_Id;
13204 Call : Node_Id;
13205 begin
13206 Find_Actual (N, Formal, Call);
13207 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
13208 end Is_Actual_Tagged_Parameter;
13210 ---------------------
13211 -- Is_Aliased_View --
13212 ---------------------
13214 function Is_Aliased_View (Obj : Node_Id) return Boolean is
13215 E : Entity_Id;
13217 begin
13218 if Is_Entity_Name (Obj) then
13219 E := Entity (Obj);
13221 return
13222 (Is_Object (E)
13223 and then
13224 (Is_Aliased (E)
13225 or else (Present (Renamed_Object (E))
13226 and then Is_Aliased_View (Renamed_Object (E)))))
13228 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13229 and then Is_Tagged_Type (Etype (E)))
13231 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13233 -- Current instance of type, either directly or as rewritten
13234 -- reference to the current object.
13236 or else (Is_Entity_Name (Original_Node (Obj))
13237 and then Present (Entity (Original_Node (Obj)))
13238 and then Is_Type (Entity (Original_Node (Obj))))
13240 or else (Is_Type (E) and then E = Current_Scope)
13242 or else (Is_Incomplete_Or_Private_Type (E)
13243 and then Full_View (E) = Current_Scope)
13245 -- Ada 2012 AI05-0053: the return object of an extended return
13246 -- statement is aliased if its type is immutably limited.
13248 or else (Is_Return_Object (E)
13249 and then Is_Limited_View (Etype (E)));
13251 elsif Nkind (Obj) = N_Selected_Component then
13252 return Is_Aliased (Entity (Selector_Name (Obj)));
13254 elsif Nkind (Obj) = N_Indexed_Component then
13255 return Has_Aliased_Components (Etype (Prefix (Obj)))
13256 or else
13257 (Is_Access_Type (Etype (Prefix (Obj)))
13258 and then Has_Aliased_Components
13259 (Designated_Type (Etype (Prefix (Obj)))));
13261 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13262 return Is_Tagged_Type (Etype (Obj))
13263 and then Is_Aliased_View (Expression (Obj));
13265 elsif Nkind (Obj) = N_Explicit_Dereference then
13266 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13268 else
13269 return False;
13270 end if;
13271 end Is_Aliased_View;
13273 -------------------------
13274 -- Is_Ancestor_Package --
13275 -------------------------
13277 function Is_Ancestor_Package
13278 (E1 : Entity_Id;
13279 E2 : Entity_Id) return Boolean
13281 Par : Entity_Id;
13283 begin
13284 Par := E2;
13285 while Present (Par) and then Par /= Standard_Standard loop
13286 if Par = E1 then
13287 return True;
13288 end if;
13290 Par := Scope (Par);
13291 end loop;
13293 return False;
13294 end Is_Ancestor_Package;
13296 ----------------------
13297 -- Is_Atomic_Object --
13298 ----------------------
13300 function Is_Atomic_Object (N : Node_Id) return Boolean is
13301 function Is_Atomic_Entity (Id : Entity_Id) return Boolean;
13302 pragma Inline (Is_Atomic_Entity);
13303 -- Determine whether arbitrary entity Id is either atomic or has atomic
13304 -- components.
13306 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean;
13307 -- Determine whether prefix Pref of an indexed or selected component is
13308 -- an atomic object.
13310 ----------------------
13311 -- Is_Atomic_Entity --
13312 ----------------------
13314 function Is_Atomic_Entity (Id : Entity_Id) return Boolean is
13315 begin
13316 return Is_Atomic (Id) or else Has_Atomic_Components (Id);
13317 end Is_Atomic_Entity;
13319 ----------------------
13320 -- Is_Atomic_Prefix --
13321 ----------------------
13323 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean is
13324 Typ : constant Entity_Id := Etype (Pref);
13326 begin
13327 if Is_Access_Type (Typ) then
13328 return Has_Atomic_Components (Designated_Type (Typ));
13330 elsif Is_Atomic_Entity (Typ) then
13331 return True;
13333 elsif Is_Entity_Name (Pref)
13334 and then Is_Atomic_Entity (Entity (Pref))
13335 then
13336 return True;
13338 elsif Nkind (Pref) = N_Indexed_Component then
13339 return Is_Atomic_Prefix (Prefix (Pref));
13341 elsif Nkind (Pref) = N_Selected_Component then
13342 return
13343 Is_Atomic_Prefix (Prefix (Pref))
13344 or else Is_Atomic (Entity (Selector_Name (Pref)));
13345 end if;
13347 return False;
13348 end Is_Atomic_Prefix;
13350 -- Start of processing for Is_Atomic_Object
13352 begin
13353 if Is_Entity_Name (N) then
13354 return Is_Atomic_Object_Entity (Entity (N));
13356 elsif Nkind (N) = N_Indexed_Component then
13357 return Is_Atomic (Etype (N)) or else Is_Atomic_Prefix (Prefix (N));
13359 elsif Nkind (N) = N_Selected_Component then
13360 return
13361 Is_Atomic (Etype (N))
13362 or else Is_Atomic_Prefix (Prefix (N))
13363 or else Is_Atomic (Entity (Selector_Name (N)));
13364 end if;
13366 return False;
13367 end Is_Atomic_Object;
13369 -----------------------------
13370 -- Is_Atomic_Object_Entity --
13371 -----------------------------
13373 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13374 begin
13375 return
13376 Is_Object (Id)
13377 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13378 end Is_Atomic_Object_Entity;
13380 -----------------------------
13381 -- Is_Atomic_Or_VFA_Object --
13382 -----------------------------
13384 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13385 begin
13386 return Is_Atomic_Object (N)
13387 or else (Is_Object_Reference (N)
13388 and then Is_Entity_Name (N)
13389 and then (Is_Volatile_Full_Access (Entity (N))
13390 or else
13391 Is_Volatile_Full_Access (Etype (Entity (N)))));
13392 end Is_Atomic_Or_VFA_Object;
13394 -------------------------
13395 -- Is_Attribute_Result --
13396 -------------------------
13398 function Is_Attribute_Result (N : Node_Id) return Boolean is
13399 begin
13400 return Nkind (N) = N_Attribute_Reference
13401 and then Attribute_Name (N) = Name_Result;
13402 end Is_Attribute_Result;
13404 -------------------------
13405 -- Is_Attribute_Update --
13406 -------------------------
13408 function Is_Attribute_Update (N : Node_Id) return Boolean is
13409 begin
13410 return Nkind (N) = N_Attribute_Reference
13411 and then Attribute_Name (N) = Name_Update;
13412 end Is_Attribute_Update;
13414 ------------------------------------
13415 -- Is_Body_Or_Package_Declaration --
13416 ------------------------------------
13418 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13419 begin
13420 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
13421 end Is_Body_Or_Package_Declaration;
13423 -----------------------
13424 -- Is_Bounded_String --
13425 -----------------------
13427 function Is_Bounded_String (T : Entity_Id) return Boolean is
13428 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13430 begin
13431 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13432 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13433 -- be True for all the Bounded_String types in instances of the
13434 -- Generic_Bounded_Length generics, and for types derived from those.
13436 return Present (Under)
13437 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13438 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13439 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13440 end Is_Bounded_String;
13442 ---------------------
13443 -- Is_CCT_Instance --
13444 ---------------------
13446 function Is_CCT_Instance
13447 (Ref_Id : Entity_Id;
13448 Context_Id : Entity_Id) return Boolean
13450 begin
13451 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13453 if Is_Single_Task_Object (Context_Id) then
13454 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13456 else
13457 pragma Assert (Ekind_In (Context_Id, E_Entry,
13458 E_Entry_Family,
13459 E_Function,
13460 E_Package,
13461 E_Procedure,
13462 E_Protected_Type,
13463 E_Task_Type)
13464 or else
13465 Is_Record_Type (Context_Id));
13466 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13467 end if;
13468 end Is_CCT_Instance;
13470 -------------------------
13471 -- Is_Child_Or_Sibling --
13472 -------------------------
13474 function Is_Child_Or_Sibling
13475 (Pack_1 : Entity_Id;
13476 Pack_2 : Entity_Id) return Boolean
13478 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13479 -- Given an arbitrary package, return the number of "climbs" necessary
13480 -- to reach scope Standard_Standard.
13482 procedure Equalize_Depths
13483 (Pack : in out Entity_Id;
13484 Depth : in out Nat;
13485 Depth_To_Reach : Nat);
13486 -- Given an arbitrary package, its depth and a target depth to reach,
13487 -- climb the scope chain until the said depth is reached. The pointer
13488 -- to the package and its depth a modified during the climb.
13490 ----------------------------
13491 -- Distance_From_Standard --
13492 ----------------------------
13494 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13495 Dist : Nat;
13496 Scop : Entity_Id;
13498 begin
13499 Dist := 0;
13500 Scop := Pack;
13501 while Present (Scop) and then Scop /= Standard_Standard loop
13502 Dist := Dist + 1;
13503 Scop := Scope (Scop);
13504 end loop;
13506 return Dist;
13507 end Distance_From_Standard;
13509 ---------------------
13510 -- Equalize_Depths --
13511 ---------------------
13513 procedure Equalize_Depths
13514 (Pack : in out Entity_Id;
13515 Depth : in out Nat;
13516 Depth_To_Reach : Nat)
13518 begin
13519 -- The package must be at a greater or equal depth
13521 if Depth < Depth_To_Reach then
13522 raise Program_Error;
13523 end if;
13525 -- Climb the scope chain until the desired depth is reached
13527 while Present (Pack) and then Depth /= Depth_To_Reach loop
13528 Pack := Scope (Pack);
13529 Depth := Depth - 1;
13530 end loop;
13531 end Equalize_Depths;
13533 -- Local variables
13535 P_1 : Entity_Id := Pack_1;
13536 P_1_Child : Boolean := False;
13537 P_1_Depth : Nat := Distance_From_Standard (P_1);
13538 P_2 : Entity_Id := Pack_2;
13539 P_2_Child : Boolean := False;
13540 P_2_Depth : Nat := Distance_From_Standard (P_2);
13542 -- Start of processing for Is_Child_Or_Sibling
13544 begin
13545 pragma Assert
13546 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13548 -- Both packages denote the same entity, therefore they cannot be
13549 -- children or siblings.
13551 if P_1 = P_2 then
13552 return False;
13554 -- One of the packages is at a deeper level than the other. Note that
13555 -- both may still come from different hierarchies.
13557 -- (root) P_2
13558 -- / \ :
13559 -- X P_2 or X
13560 -- : :
13561 -- P_1 P_1
13563 elsif P_1_Depth > P_2_Depth then
13564 Equalize_Depths
13565 (Pack => P_1,
13566 Depth => P_1_Depth,
13567 Depth_To_Reach => P_2_Depth);
13568 P_1_Child := True;
13570 -- (root) P_1
13571 -- / \ :
13572 -- P_1 X or X
13573 -- : :
13574 -- P_2 P_2
13576 elsif P_2_Depth > P_1_Depth then
13577 Equalize_Depths
13578 (Pack => P_2,
13579 Depth => P_2_Depth,
13580 Depth_To_Reach => P_1_Depth);
13581 P_2_Child := True;
13582 end if;
13584 -- At this stage the package pointers have been elevated to the same
13585 -- depth. If the related entities are the same, then one package is a
13586 -- potential child of the other:
13588 -- P_1
13589 -- :
13590 -- X became P_1 P_2 or vice versa
13591 -- :
13592 -- P_2
13594 if P_1 = P_2 then
13595 if P_1_Child then
13596 return Is_Child_Unit (Pack_1);
13598 else pragma Assert (P_2_Child);
13599 return Is_Child_Unit (Pack_2);
13600 end if;
13602 -- The packages may come from the same package chain or from entirely
13603 -- different hierarcies. To determine this, climb the scope stack until
13604 -- a common root is found.
13606 -- (root) (root 1) (root 2)
13607 -- / \ | |
13608 -- P_1 P_2 P_1 P_2
13610 else
13611 while Present (P_1) and then Present (P_2) loop
13613 -- The two packages may be siblings
13615 if P_1 = P_2 then
13616 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13617 end if;
13619 P_1 := Scope (P_1);
13620 P_2 := Scope (P_2);
13621 end loop;
13622 end if;
13624 return False;
13625 end Is_Child_Or_Sibling;
13627 -----------------------------
13628 -- Is_Concurrent_Interface --
13629 -----------------------------
13631 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13632 begin
13633 return Is_Interface (T)
13634 and then
13635 (Is_Protected_Interface (T)
13636 or else Is_Synchronized_Interface (T)
13637 or else Is_Task_Interface (T));
13638 end Is_Concurrent_Interface;
13640 -----------------------
13641 -- Is_Constant_Bound --
13642 -----------------------
13644 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13645 begin
13646 if Compile_Time_Known_Value (Exp) then
13647 return True;
13649 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13650 return Is_Constant_Object (Entity (Exp))
13651 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13653 elsif Nkind (Exp) in N_Binary_Op then
13654 return Is_Constant_Bound (Left_Opnd (Exp))
13655 and then Is_Constant_Bound (Right_Opnd (Exp))
13656 and then Scope (Entity (Exp)) = Standard_Standard;
13658 else
13659 return False;
13660 end if;
13661 end Is_Constant_Bound;
13663 ---------------------------
13664 -- Is_Container_Element --
13665 ---------------------------
13667 function Is_Container_Element (Exp : Node_Id) return Boolean is
13668 Loc : constant Source_Ptr := Sloc (Exp);
13669 Pref : constant Node_Id := Prefix (Exp);
13671 Call : Node_Id;
13672 -- Call to an indexing aspect
13674 Cont_Typ : Entity_Id;
13675 -- The type of the container being accessed
13677 Elem_Typ : Entity_Id;
13678 -- Its element type
13680 Indexing : Entity_Id;
13681 Is_Const : Boolean;
13682 -- Indicates that constant indexing is used, and the element is thus
13683 -- a constant.
13685 Ref_Typ : Entity_Id;
13686 -- The reference type returned by the indexing operation
13688 begin
13689 -- If C is a container, in a context that imposes the element type of
13690 -- that container, the indexing notation C (X) is rewritten as:
13692 -- Indexing (C, X).Discr.all
13694 -- where Indexing is one of the indexing aspects of the container.
13695 -- If the context does not require a reference, the construct can be
13696 -- rewritten as
13698 -- Element (C, X)
13700 -- First, verify that the construct has the proper form
13702 if not Expander_Active then
13703 return False;
13705 elsif Nkind (Pref) /= N_Selected_Component then
13706 return False;
13708 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13709 return False;
13711 else
13712 Call := Prefix (Pref);
13713 Ref_Typ := Etype (Call);
13714 end if;
13716 if not Has_Implicit_Dereference (Ref_Typ)
13717 or else No (First (Parameter_Associations (Call)))
13718 or else not Is_Entity_Name (Name (Call))
13719 then
13720 return False;
13721 end if;
13723 -- Retrieve type of container object, and its iterator aspects
13725 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13726 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13727 Is_Const := False;
13729 if No (Indexing) then
13731 -- Container should have at least one indexing operation
13733 return False;
13735 elsif Entity (Name (Call)) /= Entity (Indexing) then
13737 -- This may be a variable indexing operation
13739 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13741 if No (Indexing)
13742 or else Entity (Name (Call)) /= Entity (Indexing)
13743 then
13744 return False;
13745 end if;
13747 else
13748 Is_Const := True;
13749 end if;
13751 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13753 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13754 return False;
13755 end if;
13757 -- Check that the expression is not the target of an assignment, in
13758 -- which case the rewriting is not possible.
13760 if not Is_Const then
13761 declare
13762 Par : Node_Id;
13764 begin
13765 Par := Exp;
13766 while Present (Par)
13767 loop
13768 if Nkind (Parent (Par)) = N_Assignment_Statement
13769 and then Par = Name (Parent (Par))
13770 then
13771 return False;
13773 -- A renaming produces a reference, and the transformation
13774 -- does not apply.
13776 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13777 return False;
13779 elsif Nkind_In
13780 (Nkind (Parent (Par)), N_Function_Call,
13781 N_Procedure_Call_Statement,
13782 N_Entry_Call_Statement)
13783 then
13784 -- Check that the element is not part of an actual for an
13785 -- in-out parameter.
13787 declare
13788 F : Entity_Id;
13789 A : Node_Id;
13791 begin
13792 F := First_Formal (Entity (Name (Parent (Par))));
13793 A := First (Parameter_Associations (Parent (Par)));
13794 while Present (F) loop
13795 if A = Par and then Ekind (F) /= E_In_Parameter then
13796 return False;
13797 end if;
13799 Next_Formal (F);
13800 Next (A);
13801 end loop;
13802 end;
13804 -- E_In_Parameter in a call: element is not modified.
13806 exit;
13807 end if;
13809 Par := Parent (Par);
13810 end loop;
13811 end;
13812 end if;
13814 -- The expression has the proper form and the context requires the
13815 -- element type. Retrieve the Element function of the container and
13816 -- rewrite the construct as a call to it.
13818 declare
13819 Op : Elmt_Id;
13821 begin
13822 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13823 while Present (Op) loop
13824 exit when Chars (Node (Op)) = Name_Element;
13825 Next_Elmt (Op);
13826 end loop;
13828 if No (Op) then
13829 return False;
13831 else
13832 Rewrite (Exp,
13833 Make_Function_Call (Loc,
13834 Name => New_Occurrence_Of (Node (Op), Loc),
13835 Parameter_Associations => Parameter_Associations (Call)));
13836 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13837 return True;
13838 end if;
13839 end;
13840 end Is_Container_Element;
13842 ----------------------------
13843 -- Is_Contract_Annotation --
13844 ----------------------------
13846 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13847 begin
13848 return Is_Package_Contract_Annotation (Item)
13849 or else
13850 Is_Subprogram_Contract_Annotation (Item);
13851 end Is_Contract_Annotation;
13853 --------------------------------------
13854 -- Is_Controlling_Limited_Procedure --
13855 --------------------------------------
13857 function Is_Controlling_Limited_Procedure
13858 (Proc_Nam : Entity_Id) return Boolean
13860 Param : Node_Id;
13861 Param_Typ : Entity_Id := Empty;
13863 begin
13864 if Ekind (Proc_Nam) = E_Procedure
13865 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13866 then
13867 Param :=
13868 Parameter_Type
13869 (First (Parameter_Specifications (Parent (Proc_Nam))));
13871 -- The formal may be an anonymous access type
13873 if Nkind (Param) = N_Access_Definition then
13874 Param_Typ := Entity (Subtype_Mark (Param));
13875 else
13876 Param_Typ := Etype (Param);
13877 end if;
13879 -- In the case where an Itype was created for a dispatchin call, the
13880 -- procedure call has been rewritten. The actual may be an access to
13881 -- interface type in which case it is the designated type that is the
13882 -- controlling type.
13884 elsif Present (Associated_Node_For_Itype (Proc_Nam))
13885 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
13886 and then
13887 Present (Parameter_Associations
13888 (Associated_Node_For_Itype (Proc_Nam)))
13889 then
13890 Param_Typ :=
13891 Etype (First (Parameter_Associations
13892 (Associated_Node_For_Itype (Proc_Nam))));
13894 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
13895 Param_Typ := Directly_Designated_Type (Param_Typ);
13896 end if;
13897 end if;
13899 if Present (Param_Typ) then
13900 return
13901 Is_Interface (Param_Typ)
13902 and then Is_Limited_Record (Param_Typ);
13903 end if;
13905 return False;
13906 end Is_Controlling_Limited_Procedure;
13908 -----------------------------
13909 -- Is_CPP_Constructor_Call --
13910 -----------------------------
13912 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
13913 begin
13914 return Nkind (N) = N_Function_Call
13915 and then Is_CPP_Class (Etype (Etype (N)))
13916 and then Is_Constructor (Entity (Name (N)))
13917 and then Is_Imported (Entity (Name (N)));
13918 end Is_CPP_Constructor_Call;
13920 -------------------------
13921 -- Is_Current_Instance --
13922 -------------------------
13924 function Is_Current_Instance (N : Node_Id) return Boolean is
13925 Typ : constant Entity_Id := Entity (N);
13926 P : Node_Id;
13928 begin
13929 -- Simplest case: entity is a concurrent type and we are currently
13930 -- inside the body. This will eventually be expanded into a call to
13931 -- Self (for tasks) or _object (for protected objects).
13933 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13934 return True;
13936 else
13937 -- Check whether the context is a (sub)type declaration for the
13938 -- type entity.
13940 P := Parent (N);
13941 while Present (P) loop
13942 if Nkind_In (P, N_Full_Type_Declaration,
13943 N_Private_Type_Declaration,
13944 N_Subtype_Declaration)
13945 and then Comes_From_Source (P)
13946 and then Defining_Entity (P) = Typ
13947 then
13948 return True;
13950 -- A subtype name may appear in an aspect specification for a
13951 -- Predicate_Failure aspect, for which we do not construct a
13952 -- wrapper procedure. The subtype will be replaced by the
13953 -- expression being tested when the corresponding predicate
13954 -- check is expanded.
13956 elsif Nkind (P) = N_Aspect_Specification
13957 and then Nkind (Parent (P)) = N_Subtype_Declaration
13958 then
13959 return True;
13961 elsif Nkind (P) = N_Pragma
13962 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
13963 then
13964 return True;
13965 end if;
13967 P := Parent (P);
13968 end loop;
13969 end if;
13971 -- In any other context this is not a current occurrence
13973 return False;
13974 end Is_Current_Instance;
13976 --------------------
13977 -- Is_Declaration --
13978 --------------------
13980 function Is_Declaration
13981 (N : Node_Id;
13982 Body_OK : Boolean := True;
13983 Concurrent_OK : Boolean := True;
13984 Formal_OK : Boolean := True;
13985 Generic_OK : Boolean := True;
13986 Instantiation_OK : Boolean := True;
13987 Renaming_OK : Boolean := True;
13988 Stub_OK : Boolean := True;
13989 Subprogram_OK : Boolean := True;
13990 Type_OK : Boolean := True) return Boolean
13992 begin
13993 case Nkind (N) is
13995 -- Body declarations
13997 when N_Proper_Body =>
13998 return Body_OK;
14000 -- Concurrent type declarations
14002 when N_Protected_Type_Declaration
14003 | N_Single_Protected_Declaration
14004 | N_Single_Task_Declaration
14005 | N_Task_Type_Declaration
14007 return Concurrent_OK or Type_OK;
14009 -- Formal declarations
14011 when N_Formal_Abstract_Subprogram_Declaration
14012 | N_Formal_Concrete_Subprogram_Declaration
14013 | N_Formal_Object_Declaration
14014 | N_Formal_Package_Declaration
14015 | N_Formal_Type_Declaration
14017 return Formal_OK;
14019 -- Generic declarations
14021 when N_Generic_Package_Declaration
14022 | N_Generic_Subprogram_Declaration
14024 return Generic_OK;
14026 -- Generic instantiations
14028 when N_Function_Instantiation
14029 | N_Package_Instantiation
14030 | N_Procedure_Instantiation
14032 return Instantiation_OK;
14034 -- Generic renaming declarations
14036 when N_Generic_Renaming_Declaration =>
14037 return Generic_OK or Renaming_OK;
14039 -- Renaming declarations
14041 when N_Exception_Renaming_Declaration
14042 | N_Object_Renaming_Declaration
14043 | N_Package_Renaming_Declaration
14044 | N_Subprogram_Renaming_Declaration
14046 return Renaming_OK;
14048 -- Stub declarations
14050 when N_Body_Stub =>
14051 return Stub_OK;
14053 -- Subprogram declarations
14055 when N_Abstract_Subprogram_Declaration
14056 | N_Entry_Declaration
14057 | N_Expression_Function
14058 | N_Subprogram_Declaration
14060 return Subprogram_OK;
14062 -- Type declarations
14064 when N_Full_Type_Declaration
14065 | N_Incomplete_Type_Declaration
14066 | N_Private_Extension_Declaration
14067 | N_Private_Type_Declaration
14068 | N_Subtype_Declaration
14070 return Type_OK;
14072 -- Miscellaneous
14074 when N_Component_Declaration
14075 | N_Exception_Declaration
14076 | N_Implicit_Label_Declaration
14077 | N_Number_Declaration
14078 | N_Object_Declaration
14079 | N_Package_Declaration
14081 return True;
14083 when others =>
14084 return False;
14085 end case;
14086 end Is_Declaration;
14088 --------------------------------
14089 -- Is_Declared_Within_Variant --
14090 --------------------------------
14092 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
14093 Comp_Decl : constant Node_Id := Parent (Comp);
14094 Comp_List : constant Node_Id := Parent (Comp_Decl);
14095 begin
14096 return Nkind (Parent (Comp_List)) = N_Variant;
14097 end Is_Declared_Within_Variant;
14099 ----------------------------------------------
14100 -- Is_Dependent_Component_Of_Mutable_Object --
14101 ----------------------------------------------
14103 function Is_Dependent_Component_Of_Mutable_Object
14104 (Object : Node_Id) return Boolean
14106 P : Node_Id;
14107 Prefix_Type : Entity_Id;
14108 P_Aliased : Boolean := False;
14109 Comp : Entity_Id;
14111 Deref : Node_Id := Object;
14112 -- Dereference node, in something like X.all.Y(2)
14114 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14116 begin
14117 -- Find the dereference node if any
14119 while Nkind_In (Deref, N_Indexed_Component,
14120 N_Selected_Component,
14121 N_Slice)
14122 loop
14123 Deref := Prefix (Deref);
14124 end loop;
14126 -- Ada 2005: If we have a component or slice of a dereference,
14127 -- something like X.all.Y (2), and the type of X is access-to-constant,
14128 -- Is_Variable will return False, because it is indeed a constant
14129 -- view. But it might be a view of a variable object, so we want the
14130 -- following condition to be True in that case.
14132 if Is_Variable (Object)
14133 or else (Ada_Version >= Ada_2005
14134 and then Nkind (Deref) = N_Explicit_Dereference)
14135 then
14136 if Nkind (Object) = N_Selected_Component then
14137 P := Prefix (Object);
14138 Prefix_Type := Etype (P);
14140 if Is_Entity_Name (P) then
14141 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
14142 Prefix_Type := Base_Type (Prefix_Type);
14143 end if;
14145 if Is_Aliased (Entity (P)) then
14146 P_Aliased := True;
14147 end if;
14149 -- A discriminant check on a selected component may be expanded
14150 -- into a dereference when removing side effects. Recover the
14151 -- original node and its type, which may be unconstrained.
14153 elsif Nkind (P) = N_Explicit_Dereference
14154 and then not (Comes_From_Source (P))
14155 then
14156 P := Original_Node (P);
14157 Prefix_Type := Etype (P);
14159 else
14160 -- Check for prefix being an aliased component???
14162 null;
14164 end if;
14166 -- A heap object is constrained by its initial value
14168 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14169 -- the dereferenced case, since the access value might denote an
14170 -- unconstrained aliased object, whereas in Ada 95 the designated
14171 -- object is guaranteed to be constrained. A worst-case assumption
14172 -- has to apply in Ada 2005 because we can't tell at compile
14173 -- time whether the object is "constrained by its initial value",
14174 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14175 -- rules (these rules are acknowledged to need fixing). We don't
14176 -- impose this more stringent checking for earlier Ada versions or
14177 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14178 -- benefit, though it's unclear on why using -gnat95 would not be
14179 -- sufficient???).
14181 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
14182 if Is_Access_Type (Prefix_Type)
14183 or else Nkind (P) = N_Explicit_Dereference
14184 then
14185 return False;
14186 end if;
14188 else pragma Assert (Ada_Version >= Ada_2005);
14189 if Is_Access_Type (Prefix_Type) then
14191 -- If the access type is pool-specific, and there is no
14192 -- constrained partial view of the designated type, then the
14193 -- designated object is known to be constrained.
14195 if Ekind (Prefix_Type) = E_Access_Type
14196 and then not Object_Type_Has_Constrained_Partial_View
14197 (Typ => Designated_Type (Prefix_Type),
14198 Scop => Current_Scope)
14199 then
14200 return False;
14202 -- Otherwise (general access type, or there is a constrained
14203 -- partial view of the designated type), we need to check
14204 -- based on the designated type.
14206 else
14207 Prefix_Type := Designated_Type (Prefix_Type);
14208 end if;
14209 end if;
14210 end if;
14212 Comp :=
14213 Original_Record_Component (Entity (Selector_Name (Object)));
14215 -- As per AI-0017, the renaming is illegal in a generic body, even
14216 -- if the subtype is indefinite.
14218 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14220 if not Is_Constrained (Prefix_Type)
14221 and then (Is_Definite_Subtype (Prefix_Type)
14222 or else
14223 (Is_Generic_Type (Prefix_Type)
14224 and then Ekind (Current_Scope) = E_Generic_Package
14225 and then In_Package_Body (Current_Scope)))
14227 and then (Is_Declared_Within_Variant (Comp)
14228 or else Has_Discriminant_Dependent_Constraint (Comp))
14229 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14230 then
14231 return True;
14233 -- If the prefix is of an access type at this point, then we want
14234 -- to return False, rather than calling this function recursively
14235 -- on the access object (which itself might be a discriminant-
14236 -- dependent component of some other object, but that isn't
14237 -- relevant to checking the object passed to us). This avoids
14238 -- issuing wrong errors when compiling with -gnatc, where there
14239 -- can be implicit dereferences that have not been expanded.
14241 elsif Is_Access_Type (Etype (Prefix (Object))) then
14242 return False;
14244 else
14245 return
14246 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14247 end if;
14249 elsif Nkind (Object) = N_Indexed_Component
14250 or else Nkind (Object) = N_Slice
14251 then
14252 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14254 -- A type conversion that Is_Variable is a view conversion:
14255 -- go back to the denoted object.
14257 elsif Nkind (Object) = N_Type_Conversion then
14258 return
14259 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14260 end if;
14261 end if;
14263 return False;
14264 end Is_Dependent_Component_Of_Mutable_Object;
14266 ---------------------
14267 -- Is_Dereferenced --
14268 ---------------------
14270 function Is_Dereferenced (N : Node_Id) return Boolean is
14271 P : constant Node_Id := Parent (N);
14272 begin
14273 return Nkind_In (P, N_Selected_Component,
14274 N_Explicit_Dereference,
14275 N_Indexed_Component,
14276 N_Slice)
14277 and then Prefix (P) = N;
14278 end Is_Dereferenced;
14280 ----------------------
14281 -- Is_Descendant_Of --
14282 ----------------------
14284 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14285 T : Entity_Id;
14286 Etyp : Entity_Id;
14288 begin
14289 pragma Assert (Nkind (T1) in N_Entity);
14290 pragma Assert (Nkind (T2) in N_Entity);
14292 T := Base_Type (T1);
14294 -- Immediate return if the types match
14296 if T = T2 then
14297 return True;
14299 -- Comment needed here ???
14301 elsif Ekind (T) = E_Class_Wide_Type then
14302 return Etype (T) = T2;
14304 -- All other cases
14306 else
14307 loop
14308 Etyp := Etype (T);
14310 -- Done if we found the type we are looking for
14312 if Etyp = T2 then
14313 return True;
14315 -- Done if no more derivations to check
14317 elsif T = T1
14318 or else T = Etyp
14319 then
14320 return False;
14322 -- Following test catches error cases resulting from prev errors
14324 elsif No (Etyp) then
14325 return False;
14327 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14328 return False;
14330 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14331 return False;
14332 end if;
14334 T := Base_Type (Etyp);
14335 end loop;
14336 end if;
14337 end Is_Descendant_Of;
14339 ----------------------------------------
14340 -- Is_Descendant_Of_Suspension_Object --
14341 ----------------------------------------
14343 function Is_Descendant_Of_Suspension_Object
14344 (Typ : Entity_Id) return Boolean
14346 Cur_Typ : Entity_Id;
14347 Par_Typ : Entity_Id;
14349 begin
14350 -- Climb the type derivation chain checking each parent type against
14351 -- Suspension_Object.
14353 Cur_Typ := Base_Type (Typ);
14354 while Present (Cur_Typ) loop
14355 Par_Typ := Etype (Cur_Typ);
14357 -- The current type is a match
14359 if Is_Suspension_Object (Cur_Typ) then
14360 return True;
14362 -- Stop the traversal once the root of the derivation chain has been
14363 -- reached. In that case the current type is its own base type.
14365 elsif Cur_Typ = Par_Typ then
14366 exit;
14367 end if;
14369 Cur_Typ := Base_Type (Par_Typ);
14370 end loop;
14372 return False;
14373 end Is_Descendant_Of_Suspension_Object;
14375 ---------------------------------------------
14376 -- Is_Double_Precision_Floating_Point_Type --
14377 ---------------------------------------------
14379 function Is_Double_Precision_Floating_Point_Type
14380 (E : Entity_Id) return Boolean is
14381 begin
14382 return Is_Floating_Point_Type (E)
14383 and then Machine_Radix_Value (E) = Uint_2
14384 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14385 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14386 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14387 end Is_Double_Precision_Floating_Point_Type;
14389 -----------------------------
14390 -- Is_Effectively_Volatile --
14391 -----------------------------
14393 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14394 begin
14395 if Is_Type (Id) then
14397 -- An arbitrary type is effectively volatile when it is subject to
14398 -- pragma Atomic or Volatile.
14400 if Is_Volatile (Id) then
14401 return True;
14403 -- An array type is effectively volatile when it is subject to pragma
14404 -- Atomic_Components or Volatile_Components or its component type is
14405 -- effectively volatile.
14407 elsif Is_Array_Type (Id) then
14408 declare
14409 Anc : Entity_Id := Base_Type (Id);
14410 begin
14411 if Is_Private_Type (Anc) then
14412 Anc := Full_View (Anc);
14413 end if;
14415 -- Test for presence of ancestor, as the full view of a private
14416 -- type may be missing in case of error.
14418 return
14419 Has_Volatile_Components (Id)
14420 or else
14421 (Present (Anc)
14422 and then Is_Effectively_Volatile (Component_Type (Anc)));
14423 end;
14425 -- A protected type is always volatile
14427 elsif Is_Protected_Type (Id) then
14428 return True;
14430 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14431 -- automatically volatile.
14433 elsif Is_Descendant_Of_Suspension_Object (Id) then
14434 return True;
14436 -- Otherwise the type is not effectively volatile
14438 else
14439 return False;
14440 end if;
14442 -- Otherwise Id denotes an object
14444 else
14445 return
14446 Is_Volatile (Id)
14447 or else Has_Volatile_Components (Id)
14448 or else Is_Effectively_Volatile (Etype (Id));
14449 end if;
14450 end Is_Effectively_Volatile;
14452 ------------------------------------
14453 -- Is_Effectively_Volatile_Object --
14454 ------------------------------------
14456 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14457 begin
14458 if Is_Entity_Name (N) then
14459 return Is_Effectively_Volatile (Entity (N));
14461 elsif Nkind (N) = N_Indexed_Component then
14462 return Is_Effectively_Volatile_Object (Prefix (N));
14464 elsif Nkind (N) = N_Selected_Component then
14465 return
14466 Is_Effectively_Volatile_Object (Prefix (N))
14467 or else
14468 Is_Effectively_Volatile_Object (Selector_Name (N));
14470 else
14471 return False;
14472 end if;
14473 end Is_Effectively_Volatile_Object;
14475 -------------------
14476 -- Is_Entry_Body --
14477 -------------------
14479 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14480 begin
14481 return
14482 Ekind_In (Id, E_Entry, E_Entry_Family)
14483 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14484 end Is_Entry_Body;
14486 --------------------------
14487 -- Is_Entry_Declaration --
14488 --------------------------
14490 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14491 begin
14492 return
14493 Ekind_In (Id, E_Entry, E_Entry_Family)
14494 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14495 end Is_Entry_Declaration;
14497 ------------------------------------
14498 -- Is_Expanded_Priority_Attribute --
14499 ------------------------------------
14501 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14502 begin
14503 return
14504 Nkind (E) = N_Function_Call
14505 and then not Configurable_Run_Time_Mode
14506 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14507 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14508 end Is_Expanded_Priority_Attribute;
14510 ----------------------------
14511 -- Is_Expression_Function --
14512 ----------------------------
14514 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14515 begin
14516 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14517 return
14518 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14519 N_Expression_Function;
14520 else
14521 return False;
14522 end if;
14523 end Is_Expression_Function;
14525 ------------------------------------------
14526 -- Is_Expression_Function_Or_Completion --
14527 ------------------------------------------
14529 function Is_Expression_Function_Or_Completion
14530 (Subp : Entity_Id) return Boolean
14532 Subp_Decl : Node_Id;
14534 begin
14535 if Ekind (Subp) = E_Function then
14536 Subp_Decl := Unit_Declaration_Node (Subp);
14538 -- The function declaration is either an expression function or is
14539 -- completed by an expression function body.
14541 return
14542 Is_Expression_Function (Subp)
14543 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
14544 and then Present (Corresponding_Body (Subp_Decl))
14545 and then Is_Expression_Function
14546 (Corresponding_Body (Subp_Decl)));
14548 elsif Ekind (Subp) = E_Subprogram_Body then
14549 return Is_Expression_Function (Subp);
14551 else
14552 return False;
14553 end if;
14554 end Is_Expression_Function_Or_Completion;
14556 -----------------------
14557 -- Is_EVF_Expression --
14558 -----------------------
14560 function Is_EVF_Expression (N : Node_Id) return Boolean is
14561 Orig_N : constant Node_Id := Original_Node (N);
14562 Alt : Node_Id;
14563 Expr : Node_Id;
14564 Id : Entity_Id;
14566 begin
14567 -- Detect a reference to a formal parameter of a specific tagged type
14568 -- whose related subprogram is subject to pragma Expresions_Visible with
14569 -- value "False".
14571 if Is_Entity_Name (N) and then Present (Entity (N)) then
14572 Id := Entity (N);
14574 return
14575 Is_Formal (Id)
14576 and then Is_Specific_Tagged_Type (Etype (Id))
14577 and then Extensions_Visible_Status (Id) =
14578 Extensions_Visible_False;
14580 -- A case expression is an EVF expression when it contains at least one
14581 -- EVF dependent_expression. Note that a case expression may have been
14582 -- expanded, hence the use of Original_Node.
14584 elsif Nkind (Orig_N) = N_Case_Expression then
14585 Alt := First (Alternatives (Orig_N));
14586 while Present (Alt) loop
14587 if Is_EVF_Expression (Expression (Alt)) then
14588 return True;
14589 end if;
14591 Next (Alt);
14592 end loop;
14594 -- An if expression is an EVF expression when it contains at least one
14595 -- EVF dependent_expression. Note that an if expression may have been
14596 -- expanded, hence the use of Original_Node.
14598 elsif Nkind (Orig_N) = N_If_Expression then
14599 Expr := Next (First (Expressions (Orig_N)));
14600 while Present (Expr) loop
14601 if Is_EVF_Expression (Expr) then
14602 return True;
14603 end if;
14605 Next (Expr);
14606 end loop;
14608 -- A qualified expression or a type conversion is an EVF expression when
14609 -- its operand is an EVF expression.
14611 elsif Nkind_In (N, N_Qualified_Expression,
14612 N_Unchecked_Type_Conversion,
14613 N_Type_Conversion)
14614 then
14615 return Is_EVF_Expression (Expression (N));
14617 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14618 -- their prefix denotes an EVF expression.
14620 elsif Nkind (N) = N_Attribute_Reference
14621 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
14622 Name_Old,
14623 Name_Update)
14624 then
14625 return Is_EVF_Expression (Prefix (N));
14626 end if;
14628 return False;
14629 end Is_EVF_Expression;
14631 --------------
14632 -- Is_False --
14633 --------------
14635 function Is_False (U : Uint) return Boolean is
14636 begin
14637 return (U = 0);
14638 end Is_False;
14640 ---------------------------
14641 -- Is_Fixed_Model_Number --
14642 ---------------------------
14644 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
14645 S : constant Ureal := Small_Value (T);
14646 M : Urealp.Save_Mark;
14647 R : Boolean;
14649 begin
14650 M := Urealp.Mark;
14651 R := (U = UR_Trunc (U / S) * S);
14652 Urealp.Release (M);
14653 return R;
14654 end Is_Fixed_Model_Number;
14656 -------------------------------
14657 -- Is_Fully_Initialized_Type --
14658 -------------------------------
14660 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
14661 begin
14662 -- Scalar types
14664 if Is_Scalar_Type (Typ) then
14666 -- A scalar type with an aspect Default_Value is fully initialized
14668 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14669 -- of a scalar type, but we don't take that into account here, since
14670 -- we don't want these to affect warnings.
14672 return Has_Default_Aspect (Typ);
14674 elsif Is_Access_Type (Typ) then
14675 return True;
14677 elsif Is_Array_Type (Typ) then
14678 if Is_Fully_Initialized_Type (Component_Type (Typ))
14679 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14680 then
14681 return True;
14682 end if;
14684 -- An interesting case, if we have a constrained type one of whose
14685 -- bounds is known to be null, then there are no elements to be
14686 -- initialized, so all the elements are initialized.
14688 if Is_Constrained (Typ) then
14689 declare
14690 Indx : Node_Id;
14691 Indx_Typ : Entity_Id;
14692 Lbd, Hbd : Node_Id;
14694 begin
14695 Indx := First_Index (Typ);
14696 while Present (Indx) loop
14697 if Etype (Indx) = Any_Type then
14698 return False;
14700 -- If index is a range, use directly
14702 elsif Nkind (Indx) = N_Range then
14703 Lbd := Low_Bound (Indx);
14704 Hbd := High_Bound (Indx);
14706 else
14707 Indx_Typ := Etype (Indx);
14709 if Is_Private_Type (Indx_Typ) then
14710 Indx_Typ := Full_View (Indx_Typ);
14711 end if;
14713 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14714 return False;
14715 else
14716 Lbd := Type_Low_Bound (Indx_Typ);
14717 Hbd := Type_High_Bound (Indx_Typ);
14718 end if;
14719 end if;
14721 if Compile_Time_Known_Value (Lbd)
14722 and then
14723 Compile_Time_Known_Value (Hbd)
14724 then
14725 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14726 return True;
14727 end if;
14728 end if;
14730 Next_Index (Indx);
14731 end loop;
14732 end;
14733 end if;
14735 -- If no null indexes, then type is not fully initialized
14737 return False;
14739 -- Record types
14741 elsif Is_Record_Type (Typ) then
14742 if Has_Discriminants (Typ)
14743 and then
14744 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14745 and then Is_Fully_Initialized_Variant (Typ)
14746 then
14747 return True;
14748 end if;
14750 -- We consider bounded string types to be fully initialized, because
14751 -- otherwise we get false alarms when the Data component is not
14752 -- default-initialized.
14754 if Is_Bounded_String (Typ) then
14755 return True;
14756 end if;
14758 -- Controlled records are considered to be fully initialized if
14759 -- there is a user defined Initialize routine. This may not be
14760 -- entirely correct, but as the spec notes, we are guessing here
14761 -- what is best from the point of view of issuing warnings.
14763 if Is_Controlled (Typ) then
14764 declare
14765 Utyp : constant Entity_Id := Underlying_Type (Typ);
14767 begin
14768 if Present (Utyp) then
14769 declare
14770 Init : constant Entity_Id :=
14771 (Find_Optional_Prim_Op
14772 (Underlying_Type (Typ), Name_Initialize));
14774 begin
14775 if Present (Init)
14776 and then Comes_From_Source (Init)
14777 and then not In_Predefined_Unit (Init)
14778 then
14779 return True;
14781 elsif Has_Null_Extension (Typ)
14782 and then
14783 Is_Fully_Initialized_Type
14784 (Etype (Base_Type (Typ)))
14785 then
14786 return True;
14787 end if;
14788 end;
14789 end if;
14790 end;
14791 end if;
14793 -- Otherwise see if all record components are initialized
14795 declare
14796 Ent : Entity_Id;
14798 begin
14799 Ent := First_Entity (Typ);
14800 while Present (Ent) loop
14801 if Ekind (Ent) = E_Component
14802 and then (No (Parent (Ent))
14803 or else No (Expression (Parent (Ent))))
14804 and then not Is_Fully_Initialized_Type (Etype (Ent))
14806 -- Special VM case for tag components, which need to be
14807 -- defined in this case, but are never initialized as VMs
14808 -- are using other dispatching mechanisms. Ignore this
14809 -- uninitialized case. Note that this applies both to the
14810 -- uTag entry and the main vtable pointer (CPP_Class case).
14812 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14813 then
14814 return False;
14815 end if;
14817 Next_Entity (Ent);
14818 end loop;
14819 end;
14821 -- No uninitialized components, so type is fully initialized.
14822 -- Note that this catches the case of no components as well.
14824 return True;
14826 elsif Is_Concurrent_Type (Typ) then
14827 return True;
14829 elsif Is_Private_Type (Typ) then
14830 declare
14831 U : constant Entity_Id := Underlying_Type (Typ);
14833 begin
14834 if No (U) then
14835 return False;
14836 else
14837 return Is_Fully_Initialized_Type (U);
14838 end if;
14839 end;
14841 else
14842 return False;
14843 end if;
14844 end Is_Fully_Initialized_Type;
14846 ----------------------------------
14847 -- Is_Fully_Initialized_Variant --
14848 ----------------------------------
14850 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
14851 Loc : constant Source_Ptr := Sloc (Typ);
14852 Constraints : constant List_Id := New_List;
14853 Components : constant Elist_Id := New_Elmt_List;
14854 Comp_Elmt : Elmt_Id;
14855 Comp_Id : Node_Id;
14856 Comp_List : Node_Id;
14857 Discr : Entity_Id;
14858 Discr_Val : Node_Id;
14860 Report_Errors : Boolean;
14861 pragma Warnings (Off, Report_Errors);
14863 begin
14864 if Serious_Errors_Detected > 0 then
14865 return False;
14866 end if;
14868 if Is_Record_Type (Typ)
14869 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
14870 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
14871 then
14872 Comp_List := Component_List (Type_Definition (Parent (Typ)));
14874 Discr := First_Discriminant (Typ);
14875 while Present (Discr) loop
14876 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
14877 Discr_Val := Expression (Parent (Discr));
14879 if Present (Discr_Val)
14880 and then Is_OK_Static_Expression (Discr_Val)
14881 then
14882 Append_To (Constraints,
14883 Make_Component_Association (Loc,
14884 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
14885 Expression => New_Copy (Discr_Val)));
14886 else
14887 return False;
14888 end if;
14889 else
14890 return False;
14891 end if;
14893 Next_Discriminant (Discr);
14894 end loop;
14896 Gather_Components
14897 (Typ => Typ,
14898 Comp_List => Comp_List,
14899 Governed_By => Constraints,
14900 Into => Components,
14901 Report_Errors => Report_Errors);
14903 -- Check that each component present is fully initialized
14905 Comp_Elmt := First_Elmt (Components);
14906 while Present (Comp_Elmt) loop
14907 Comp_Id := Node (Comp_Elmt);
14909 if Ekind (Comp_Id) = E_Component
14910 and then (No (Parent (Comp_Id))
14911 or else No (Expression (Parent (Comp_Id))))
14912 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
14913 then
14914 return False;
14915 end if;
14917 Next_Elmt (Comp_Elmt);
14918 end loop;
14920 return True;
14922 elsif Is_Private_Type (Typ) then
14923 declare
14924 U : constant Entity_Id := Underlying_Type (Typ);
14926 begin
14927 if No (U) then
14928 return False;
14929 else
14930 return Is_Fully_Initialized_Variant (U);
14931 end if;
14932 end;
14934 else
14935 return False;
14936 end if;
14937 end Is_Fully_Initialized_Variant;
14939 ------------------------------------
14940 -- Is_Generic_Declaration_Or_Body --
14941 ------------------------------------
14943 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
14944 Spec_Decl : Node_Id;
14946 begin
14947 -- Package/subprogram body
14949 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
14950 and then Present (Corresponding_Spec (Decl))
14951 then
14952 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
14954 -- Package/subprogram body stub
14956 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
14957 and then Present (Corresponding_Spec_Of_Stub (Decl))
14958 then
14959 Spec_Decl :=
14960 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
14962 -- All other cases
14964 else
14965 Spec_Decl := Decl;
14966 end if;
14968 -- Rather than inspecting the defining entity of the spec declaration,
14969 -- look at its Nkind. This takes care of the case where the analysis of
14970 -- a generic body modifies the Ekind of its spec to allow for recursive
14971 -- calls.
14973 return
14974 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
14975 N_Generic_Subprogram_Declaration);
14976 end Is_Generic_Declaration_Or_Body;
14978 ----------------------------
14979 -- Is_Inherited_Operation --
14980 ----------------------------
14982 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
14983 pragma Assert (Is_Overloadable (E));
14984 Kind : constant Node_Kind := Nkind (Parent (E));
14985 begin
14986 return Kind = N_Full_Type_Declaration
14987 or else Kind = N_Private_Extension_Declaration
14988 or else Kind = N_Subtype_Declaration
14989 or else (Ekind (E) = E_Enumeration_Literal
14990 and then Is_Derived_Type (Etype (E)));
14991 end Is_Inherited_Operation;
14993 -------------------------------------
14994 -- Is_Inherited_Operation_For_Type --
14995 -------------------------------------
14997 function Is_Inherited_Operation_For_Type
14998 (E : Entity_Id;
14999 Typ : Entity_Id) return Boolean
15001 begin
15002 -- Check that the operation has been created by the type declaration
15004 return Is_Inherited_Operation (E)
15005 and then Defining_Identifier (Parent (E)) = Typ;
15006 end Is_Inherited_Operation_For_Type;
15008 --------------------------------------
15009 -- Is_Inlinable_Expression_Function --
15010 --------------------------------------
15012 function Is_Inlinable_Expression_Function
15013 (Subp : Entity_Id) return Boolean
15015 Return_Expr : Node_Id;
15017 begin
15018 if Is_Expression_Function_Or_Completion (Subp)
15019 and then Has_Pragma_Inline_Always (Subp)
15020 and then Needs_No_Actuals (Subp)
15021 and then No (Contract (Subp))
15022 and then not Is_Dispatching_Operation (Subp)
15023 and then Needs_Finalization (Etype (Subp))
15024 and then not Is_Class_Wide_Type (Etype (Subp))
15025 and then not (Has_Invariants (Etype (Subp)))
15026 and then Present (Subprogram_Body (Subp))
15027 and then Was_Expression_Function (Subprogram_Body (Subp))
15028 then
15029 Return_Expr := Expression_Of_Expression_Function (Subp);
15031 -- The returned object must not have a qualified expression and its
15032 -- nominal subtype must be statically compatible with the result
15033 -- subtype of the expression function.
15035 return
15036 Nkind (Return_Expr) = N_Identifier
15037 and then Etype (Return_Expr) = Etype (Subp);
15038 end if;
15040 return False;
15041 end Is_Inlinable_Expression_Function;
15043 -----------------
15044 -- Is_Iterator --
15045 -----------------
15047 function Is_Iterator (Typ : Entity_Id) return Boolean is
15048 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
15049 -- Determine whether type Iter_Typ is a predefined forward or reversible
15050 -- iterator.
15052 ----------------------
15053 -- Denotes_Iterator --
15054 ----------------------
15056 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
15057 begin
15058 -- Check that the name matches, and that the ultimate ancestor is in
15059 -- a predefined unit, i.e the one that declares iterator interfaces.
15061 return
15062 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
15063 Name_Reversible_Iterator)
15064 and then In_Predefined_Unit (Root_Type (Iter_Typ));
15065 end Denotes_Iterator;
15067 -- Local variables
15069 Iface_Elmt : Elmt_Id;
15070 Ifaces : Elist_Id;
15072 -- Start of processing for Is_Iterator
15074 begin
15075 -- The type may be a subtype of a descendant of the proper instance of
15076 -- the predefined interface type, so we must use the root type of the
15077 -- given type. The same is done for Is_Reversible_Iterator.
15079 if Is_Class_Wide_Type (Typ)
15080 and then Denotes_Iterator (Root_Type (Typ))
15081 then
15082 return True;
15084 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15085 return False;
15087 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
15088 return True;
15090 else
15091 Collect_Interfaces (Typ, Ifaces);
15093 Iface_Elmt := First_Elmt (Ifaces);
15094 while Present (Iface_Elmt) loop
15095 if Denotes_Iterator (Node (Iface_Elmt)) then
15096 return True;
15097 end if;
15099 Next_Elmt (Iface_Elmt);
15100 end loop;
15102 return False;
15103 end if;
15104 end Is_Iterator;
15106 ----------------------------
15107 -- Is_Iterator_Over_Array --
15108 ----------------------------
15110 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
15111 Container : constant Node_Id := Name (N);
15112 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
15113 begin
15114 return Is_Array_Type (Container_Typ);
15115 end Is_Iterator_Over_Array;
15117 ------------
15118 -- Is_LHS --
15119 ------------
15121 -- We seem to have a lot of overlapping functions that do similar things
15122 -- (testing for left hand sides or lvalues???).
15124 function Is_LHS (N : Node_Id) return Is_LHS_Result is
15125 P : constant Node_Id := Parent (N);
15127 begin
15128 -- Return True if we are the left hand side of an assignment statement
15130 if Nkind (P) = N_Assignment_Statement then
15131 if Name (P) = N then
15132 return Yes;
15133 else
15134 return No;
15135 end if;
15137 -- Case of prefix of indexed or selected component or slice
15139 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
15140 and then N = Prefix (P)
15141 then
15142 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15143 -- If P is an LHS, then N is also effectively an LHS, but there
15144 -- is an important exception. If N is of an access type, then
15145 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15146 -- case this makes N.all a left hand side but not N itself.
15148 -- If we don't know the type yet, this is the case where we return
15149 -- Unknown, since the answer depends on the type which is unknown.
15151 if No (Etype (N)) then
15152 return Unknown;
15154 -- We have an Etype set, so we can check it
15156 elsif Is_Access_Type (Etype (N)) then
15157 return No;
15159 -- OK, not access type case, so just test whole expression
15161 else
15162 return Is_LHS (P);
15163 end if;
15165 -- All other cases are not left hand sides
15167 else
15168 return No;
15169 end if;
15170 end Is_LHS;
15172 -----------------------------
15173 -- Is_Library_Level_Entity --
15174 -----------------------------
15176 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
15177 begin
15178 -- The following is a small optimization, and it also properly handles
15179 -- discriminals, which in task bodies might appear in expressions before
15180 -- the corresponding procedure has been created, and which therefore do
15181 -- not have an assigned scope.
15183 if Is_Formal (E) then
15184 return False;
15185 end if;
15187 -- Normal test is simply that the enclosing dynamic scope is Standard
15189 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
15190 end Is_Library_Level_Entity;
15192 --------------------------------
15193 -- Is_Limited_Class_Wide_Type --
15194 --------------------------------
15196 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
15197 begin
15198 return
15199 Is_Class_Wide_Type (Typ)
15200 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
15201 end Is_Limited_Class_Wide_Type;
15203 ---------------------------------
15204 -- Is_Local_Variable_Reference --
15205 ---------------------------------
15207 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
15208 begin
15209 if not Is_Entity_Name (Expr) then
15210 return False;
15212 else
15213 declare
15214 Ent : constant Entity_Id := Entity (Expr);
15215 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
15216 begin
15217 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15218 return False;
15219 else
15220 return Present (Sub) and then Sub = Current_Subprogram;
15221 end if;
15222 end;
15223 end if;
15224 end Is_Local_Variable_Reference;
15226 -----------------------
15227 -- Is_Name_Reference --
15228 -----------------------
15230 function Is_Name_Reference (N : Node_Id) return Boolean is
15231 begin
15232 if Is_Entity_Name (N) then
15233 return Present (Entity (N)) and then Is_Object (Entity (N));
15234 end if;
15236 case Nkind (N) is
15237 when N_Indexed_Component
15238 | N_Slice
15240 return
15241 Is_Name_Reference (Prefix (N))
15242 or else Is_Access_Type (Etype (Prefix (N)));
15244 -- Attributes 'Input, 'Old and 'Result produce objects
15246 when N_Attribute_Reference =>
15247 return
15248 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15250 when N_Selected_Component =>
15251 return
15252 Is_Name_Reference (Selector_Name (N))
15253 and then
15254 (Is_Name_Reference (Prefix (N))
15255 or else Is_Access_Type (Etype (Prefix (N))));
15257 when N_Explicit_Dereference =>
15258 return True;
15260 -- A view conversion of a tagged name is a name reference
15262 when N_Type_Conversion =>
15263 return
15264 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15265 and then Is_Tagged_Type (Etype (Expression (N)))
15266 and then Is_Name_Reference (Expression (N));
15268 -- An unchecked type conversion is considered to be a name if the
15269 -- operand is a name (this construction arises only as a result of
15270 -- expansion activities).
15272 when N_Unchecked_Type_Conversion =>
15273 return Is_Name_Reference (Expression (N));
15275 when others =>
15276 return False;
15277 end case;
15278 end Is_Name_Reference;
15280 ------------------------------------
15281 -- Is_Non_Preelaborable_Construct --
15282 ------------------------------------
15284 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15286 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15287 -- intentionally unnested to avoid deep indentation of code.
15289 Non_Preelaborable : exception;
15290 -- This exception is raised when the construct violates preelaborability
15291 -- to terminate the recursion.
15293 procedure Visit (Nod : Node_Id);
15294 -- Semantically inspect construct Nod to determine whether it violates
15295 -- preelaborability. This routine raises Non_Preelaborable.
15297 procedure Visit_List (List : List_Id);
15298 pragma Inline (Visit_List);
15299 -- Invoke Visit on each element of list List. This routine raises
15300 -- Non_Preelaborable.
15302 procedure Visit_Pragma (Prag : Node_Id);
15303 pragma Inline (Visit_Pragma);
15304 -- Semantically inspect pragma Prag to determine whether it violates
15305 -- preelaborability. This routine raises Non_Preelaborable.
15307 procedure Visit_Subexpression (Expr : Node_Id);
15308 pragma Inline (Visit_Subexpression);
15309 -- Semantically inspect expression Expr to determine whether it violates
15310 -- preelaborability. This routine raises Non_Preelaborable.
15312 -----------
15313 -- Visit --
15314 -----------
15316 procedure Visit (Nod : Node_Id) is
15317 begin
15318 case Nkind (Nod) is
15320 -- Declarations
15322 when N_Component_Declaration =>
15324 -- Defining_Identifier is left out because it is not relevant
15325 -- for preelaborability.
15327 Visit (Component_Definition (Nod));
15328 Visit (Expression (Nod));
15330 when N_Derived_Type_Definition =>
15332 -- Interface_List is left out because it is not relevant for
15333 -- preelaborability.
15335 Visit (Record_Extension_Part (Nod));
15336 Visit (Subtype_Indication (Nod));
15338 when N_Entry_Declaration =>
15340 -- A protected type with at leat one entry is not preelaborable
15341 -- while task types are never preelaborable. This renders entry
15342 -- declarations non-preelaborable.
15344 raise Non_Preelaborable;
15346 when N_Full_Type_Declaration =>
15348 -- Defining_Identifier and Discriminant_Specifications are left
15349 -- out because they are not relevant for preelaborability.
15351 Visit (Type_Definition (Nod));
15353 when N_Function_Instantiation
15354 | N_Package_Instantiation
15355 | N_Procedure_Instantiation
15357 -- Defining_Unit_Name and Name are left out because they are
15358 -- not relevant for preelaborability.
15360 Visit_List (Generic_Associations (Nod));
15362 when N_Object_Declaration =>
15364 -- Defining_Identifier is left out because it is not relevant
15365 -- for preelaborability.
15367 Visit (Object_Definition (Nod));
15369 if Has_Init_Expression (Nod) then
15370 Visit (Expression (Nod));
15372 elsif not Has_Preelaborable_Initialization
15373 (Etype (Defining_Entity (Nod)))
15374 then
15375 raise Non_Preelaborable;
15376 end if;
15378 when N_Private_Extension_Declaration
15379 | N_Subtype_Declaration
15381 -- Defining_Identifier, Discriminant_Specifications, and
15382 -- Interface_List are left out because they are not relevant
15383 -- for preelaborability.
15385 Visit (Subtype_Indication (Nod));
15387 when N_Protected_Type_Declaration
15388 | N_Single_Protected_Declaration
15390 -- Defining_Identifier, Discriminant_Specifications, and
15391 -- Interface_List are left out because they are not relevant
15392 -- for preelaborability.
15394 Visit (Protected_Definition (Nod));
15396 -- A [single] task type is never preelaborable
15398 when N_Single_Task_Declaration
15399 | N_Task_Type_Declaration
15401 raise Non_Preelaborable;
15403 -- Pragmas
15405 when N_Pragma =>
15406 Visit_Pragma (Nod);
15408 -- Statements
15410 when N_Statement_Other_Than_Procedure_Call =>
15411 if Nkind (Nod) /= N_Null_Statement then
15412 raise Non_Preelaborable;
15413 end if;
15415 -- Subexpressions
15417 when N_Subexpr =>
15418 Visit_Subexpression (Nod);
15420 -- Special
15422 when N_Access_To_Object_Definition =>
15423 Visit (Subtype_Indication (Nod));
15425 when N_Case_Expression_Alternative =>
15426 Visit (Expression (Nod));
15427 Visit_List (Discrete_Choices (Nod));
15429 when N_Component_Definition =>
15430 Visit (Access_Definition (Nod));
15431 Visit (Subtype_Indication (Nod));
15433 when N_Component_List =>
15434 Visit_List (Component_Items (Nod));
15435 Visit (Variant_Part (Nod));
15437 when N_Constrained_Array_Definition =>
15438 Visit_List (Discrete_Subtype_Definitions (Nod));
15439 Visit (Component_Definition (Nod));
15441 when N_Delta_Constraint
15442 | N_Digits_Constraint
15444 -- Delta_Expression and Digits_Expression are left out because
15445 -- they are not relevant for preelaborability.
15447 Visit (Range_Constraint (Nod));
15449 when N_Discriminant_Specification =>
15451 -- Defining_Identifier and Expression are left out because they
15452 -- are not relevant for preelaborability.
15454 Visit (Discriminant_Type (Nod));
15456 when N_Generic_Association =>
15458 -- Selector_Name is left out because it is not relevant for
15459 -- preelaborability.
15461 Visit (Explicit_Generic_Actual_Parameter (Nod));
15463 when N_Index_Or_Discriminant_Constraint =>
15464 Visit_List (Constraints (Nod));
15466 when N_Iterator_Specification =>
15468 -- Defining_Identifier is left out because it is not relevant
15469 -- for preelaborability.
15471 Visit (Name (Nod));
15472 Visit (Subtype_Indication (Nod));
15474 when N_Loop_Parameter_Specification =>
15476 -- Defining_Identifier is left out because it is not relevant
15477 -- for preelaborability.
15479 Visit (Discrete_Subtype_Definition (Nod));
15481 when N_Protected_Definition =>
15483 -- End_Label is left out because it is not relevant for
15484 -- preelaborability.
15486 Visit_List (Private_Declarations (Nod));
15487 Visit_List (Visible_Declarations (Nod));
15489 when N_Range_Constraint =>
15490 Visit (Range_Expression (Nod));
15492 when N_Record_Definition
15493 | N_Variant
15495 -- End_Label, Discrete_Choices, and Interface_List are left out
15496 -- because they are not relevant for preelaborability.
15498 Visit (Component_List (Nod));
15500 when N_Subtype_Indication =>
15502 -- Subtype_Mark is left out because it is not relevant for
15503 -- preelaborability.
15505 Visit (Constraint (Nod));
15507 when N_Unconstrained_Array_Definition =>
15509 -- Subtype_Marks is left out because it is not relevant for
15510 -- preelaborability.
15512 Visit (Component_Definition (Nod));
15514 when N_Variant_Part =>
15516 -- Name is left out because it is not relevant for
15517 -- preelaborability.
15519 Visit_List (Variants (Nod));
15521 -- Default
15523 when others =>
15524 null;
15525 end case;
15526 end Visit;
15528 ----------------
15529 -- Visit_List --
15530 ----------------
15532 procedure Visit_List (List : List_Id) is
15533 Nod : Node_Id;
15535 begin
15536 if Present (List) then
15537 Nod := First (List);
15538 while Present (Nod) loop
15539 Visit (Nod);
15540 Next (Nod);
15541 end loop;
15542 end if;
15543 end Visit_List;
15545 ------------------
15546 -- Visit_Pragma --
15547 ------------------
15549 procedure Visit_Pragma (Prag : Node_Id) is
15550 begin
15551 case Get_Pragma_Id (Prag) is
15552 when Pragma_Assert
15553 | Pragma_Assert_And_Cut
15554 | Pragma_Assume
15555 | Pragma_Async_Readers
15556 | Pragma_Async_Writers
15557 | Pragma_Attribute_Definition
15558 | Pragma_Check
15559 | Pragma_Constant_After_Elaboration
15560 | Pragma_CPU
15561 | Pragma_Deadline_Floor
15562 | Pragma_Dispatching_Domain
15563 | Pragma_Effective_Reads
15564 | Pragma_Effective_Writes
15565 | Pragma_Extensions_Visible
15566 | Pragma_Ghost
15567 | Pragma_Secondary_Stack_Size
15568 | Pragma_Task_Name
15569 | Pragma_Volatile_Function
15571 Visit_List (Pragma_Argument_Associations (Prag));
15573 -- Default
15575 when others =>
15576 null;
15577 end case;
15578 end Visit_Pragma;
15580 -------------------------
15581 -- Visit_Subexpression --
15582 -------------------------
15584 procedure Visit_Subexpression (Expr : Node_Id) is
15585 procedure Visit_Aggregate (Aggr : Node_Id);
15586 pragma Inline (Visit_Aggregate);
15587 -- Semantically inspect aggregate Aggr to determine whether it
15588 -- violates preelaborability.
15590 ---------------------
15591 -- Visit_Aggregate --
15592 ---------------------
15594 procedure Visit_Aggregate (Aggr : Node_Id) is
15595 begin
15596 if not Is_Preelaborable_Aggregate (Aggr) then
15597 raise Non_Preelaborable;
15598 end if;
15599 end Visit_Aggregate;
15601 -- Start of processing for Visit_Subexpression
15603 begin
15604 case Nkind (Expr) is
15605 when N_Allocator
15606 | N_Qualified_Expression
15607 | N_Type_Conversion
15608 | N_Unchecked_Expression
15609 | N_Unchecked_Type_Conversion
15611 -- Subpool_Handle_Name and Subtype_Mark are left out because
15612 -- they are not relevant for preelaborability.
15614 Visit (Expression (Expr));
15616 when N_Aggregate
15617 | N_Extension_Aggregate
15619 Visit_Aggregate (Expr);
15621 when N_Attribute_Reference
15622 | N_Explicit_Dereference
15623 | N_Reference
15625 -- Attribute_Name and Expressions are left out because they are
15626 -- not relevant for preelaborability.
15628 Visit (Prefix (Expr));
15630 when N_Case_Expression =>
15632 -- End_Span is left out because it is not relevant for
15633 -- preelaborability.
15635 Visit_List (Alternatives (Expr));
15636 Visit (Expression (Expr));
15638 when N_Delta_Aggregate =>
15639 Visit_Aggregate (Expr);
15640 Visit (Expression (Expr));
15642 when N_Expression_With_Actions =>
15643 Visit_List (Actions (Expr));
15644 Visit (Expression (Expr));
15646 when N_If_Expression =>
15647 Visit_List (Expressions (Expr));
15649 when N_Quantified_Expression =>
15650 Visit (Condition (Expr));
15651 Visit (Iterator_Specification (Expr));
15652 Visit (Loop_Parameter_Specification (Expr));
15654 when N_Range =>
15655 Visit (High_Bound (Expr));
15656 Visit (Low_Bound (Expr));
15658 when N_Slice =>
15659 Visit (Discrete_Range (Expr));
15660 Visit (Prefix (Expr));
15662 -- Default
15664 when others =>
15666 -- The evaluation of an object name is not preelaborable,
15667 -- unless the name is a static expression (checked further
15668 -- below), or statically denotes a discriminant.
15670 if Is_Entity_Name (Expr) then
15671 Object_Name : declare
15672 Id : constant Entity_Id := Entity (Expr);
15674 begin
15675 if Is_Object (Id) then
15676 if Ekind (Id) = E_Discriminant then
15677 null;
15679 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15680 and then Present (Discriminal_Link (Id))
15681 then
15682 null;
15684 else
15685 raise Non_Preelaborable;
15686 end if;
15687 end if;
15688 end Object_Name;
15690 -- A non-static expression is not preelaborable
15692 elsif not Is_OK_Static_Expression (Expr) then
15693 raise Non_Preelaborable;
15694 end if;
15695 end case;
15696 end Visit_Subexpression;
15698 -- Start of processing for Is_Non_Preelaborable_Construct
15700 begin
15701 Visit (N);
15703 -- At this point it is known that the construct is preelaborable
15705 return False;
15707 exception
15709 -- The elaboration of the construct performs an action which violates
15710 -- preelaborability.
15712 when Non_Preelaborable =>
15713 return True;
15714 end Is_Non_Preelaborable_Construct;
15716 ---------------------------------
15717 -- Is_Nontrivial_DIC_Procedure --
15718 ---------------------------------
15720 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15721 Body_Decl : Node_Id;
15722 Stmt : Node_Id;
15724 begin
15725 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15726 Body_Decl :=
15727 Unit_Declaration_Node
15728 (Corresponding_Body (Unit_Declaration_Node (Id)));
15730 -- The body of the Default_Initial_Condition procedure must contain
15731 -- at least one statement, otherwise the generation of the subprogram
15732 -- body failed.
15734 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15736 -- To qualify as nontrivial, the first statement of the procedure
15737 -- must be a check in the form of an if statement. If the original
15738 -- Default_Initial_Condition expression was folded, then the first
15739 -- statement is not a check.
15741 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15743 return
15744 Nkind (Stmt) = N_If_Statement
15745 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15746 end if;
15748 return False;
15749 end Is_Nontrivial_DIC_Procedure;
15751 -------------------------
15752 -- Is_Null_Record_Type --
15753 -------------------------
15755 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15756 Decl : constant Node_Id := Parent (T);
15757 begin
15758 return Nkind (Decl) = N_Full_Type_Declaration
15759 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15760 and then
15761 (No (Component_List (Type_Definition (Decl)))
15762 or else Null_Present (Component_List (Type_Definition (Decl))));
15763 end Is_Null_Record_Type;
15765 ---------------------
15766 -- Is_Object_Image --
15767 ---------------------
15769 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15770 begin
15771 -- When the type of the prefix is not scalar, then the prefix is not
15772 -- valid in any scenario.
15774 if not Is_Scalar_Type (Etype (Prefix)) then
15775 return False;
15776 end if;
15778 -- Here we test for the case that the prefix is not a type and assume
15779 -- if it is not then it must be a named value or an object reference.
15780 -- This is because the parser always checks that prefixes of attributes
15781 -- are named.
15783 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
15784 end Is_Object_Image;
15786 -------------------------
15787 -- Is_Object_Reference --
15788 -------------------------
15790 function Is_Object_Reference (N : Node_Id) return Boolean is
15791 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
15792 -- Determine whether N is the name of an internally-generated renaming
15794 --------------------------------------
15795 -- Is_Internally_Generated_Renaming --
15796 --------------------------------------
15798 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
15799 P : Node_Id;
15801 begin
15802 P := N;
15803 while Present (P) loop
15804 if Nkind (P) = N_Object_Renaming_Declaration then
15805 return not Comes_From_Source (P);
15806 elsif Is_List_Member (P) then
15807 return False;
15808 end if;
15810 P := Parent (P);
15811 end loop;
15813 return False;
15814 end Is_Internally_Generated_Renaming;
15816 -- Start of processing for Is_Object_Reference
15818 begin
15819 if Is_Entity_Name (N) then
15820 return Present (Entity (N)) and then Is_Object (Entity (N));
15822 else
15823 case Nkind (N) is
15824 when N_Indexed_Component
15825 | N_Slice
15827 return
15828 Is_Object_Reference (Prefix (N))
15829 or else Is_Access_Type (Etype (Prefix (N)));
15831 -- In Ada 95, a function call is a constant object; a procedure
15832 -- call is not.
15834 -- Note that predefined operators are functions as well, and so
15835 -- are attributes that are (can be renamed as) functions.
15837 when N_Binary_Op
15838 | N_Function_Call
15839 | N_Unary_Op
15841 return Etype (N) /= Standard_Void_Type;
15843 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
15844 -- objects, even though they are not functions.
15846 when N_Attribute_Reference =>
15847 return
15848 Nam_In (Attribute_Name (N), Name_Loop_Entry,
15849 Name_Old,
15850 Name_Result)
15851 or else Is_Function_Attribute_Name (Attribute_Name (N));
15853 when N_Selected_Component =>
15854 return
15855 Is_Object_Reference (Selector_Name (N))
15856 and then
15857 (Is_Object_Reference (Prefix (N))
15858 or else Is_Access_Type (Etype (Prefix (N))));
15860 -- An explicit dereference denotes an object, except that a
15861 -- conditional expression gets turned into an explicit dereference
15862 -- in some cases, and conditional expressions are not object
15863 -- names.
15865 when N_Explicit_Dereference =>
15866 return not Nkind_In (Original_Node (N), N_Case_Expression,
15867 N_If_Expression);
15869 -- A view conversion of a tagged object is an object reference
15871 when N_Type_Conversion =>
15872 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
15873 and then Is_Tagged_Type (Etype (Expression (N)))
15874 and then Is_Object_Reference (Expression (N));
15876 -- An unchecked type conversion is considered to be an object if
15877 -- the operand is an object (this construction arises only as a
15878 -- result of expansion activities).
15880 when N_Unchecked_Type_Conversion =>
15881 return True;
15883 -- Allow string literals to act as objects as long as they appear
15884 -- in internally-generated renamings. The expansion of iterators
15885 -- may generate such renamings when the range involves a string
15886 -- literal.
15888 when N_String_Literal =>
15889 return Is_Internally_Generated_Renaming (Parent (N));
15891 -- AI05-0003: In Ada 2012 a qualified expression is a name.
15892 -- This allows disambiguation of function calls and the use
15893 -- of aggregates in more contexts.
15895 when N_Qualified_Expression =>
15896 if Ada_Version < Ada_2012 then
15897 return False;
15898 else
15899 return Is_Object_Reference (Expression (N))
15900 or else Nkind (Expression (N)) = N_Aggregate;
15901 end if;
15903 when others =>
15904 return False;
15905 end case;
15906 end if;
15907 end Is_Object_Reference;
15909 -----------------------------------
15910 -- Is_OK_Variable_For_Out_Formal --
15911 -----------------------------------
15913 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
15914 begin
15915 Note_Possible_Modification (AV, Sure => True);
15917 -- We must reject parenthesized variable names. Comes_From_Source is
15918 -- checked because there are currently cases where the compiler violates
15919 -- this rule (e.g. passing a task object to its controlled Initialize
15920 -- routine). This should be properly documented in sinfo???
15922 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
15923 return False;
15925 -- A variable is always allowed
15927 elsif Is_Variable (AV) then
15928 return True;
15930 -- Generalized indexing operations are rewritten as explicit
15931 -- dereferences, and it is only during resolution that we can
15932 -- check whether the context requires an access_to_variable type.
15934 elsif Nkind (AV) = N_Explicit_Dereference
15935 and then Ada_Version >= Ada_2012
15936 and then Nkind (Original_Node (AV)) = N_Indexed_Component
15937 and then Present (Etype (Original_Node (AV)))
15938 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
15939 then
15940 return not Is_Access_Constant (Etype (Prefix (AV)));
15942 -- Unchecked conversions are allowed only if they come from the
15943 -- generated code, which sometimes uses unchecked conversions for out
15944 -- parameters in cases where code generation is unaffected. We tell
15945 -- source unchecked conversions by seeing if they are rewrites of
15946 -- an original Unchecked_Conversion function call, or of an explicit
15947 -- conversion of a function call or an aggregate (as may happen in the
15948 -- expansion of a packed array aggregate).
15950 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
15951 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
15952 return False;
15954 elsif Comes_From_Source (AV)
15955 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
15956 then
15957 return False;
15959 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
15960 return Is_OK_Variable_For_Out_Formal (Expression (AV));
15962 else
15963 return True;
15964 end if;
15966 -- Normal type conversions are allowed if argument is a variable
15968 elsif Nkind (AV) = N_Type_Conversion then
15969 if Is_Variable (Expression (AV))
15970 and then Paren_Count (Expression (AV)) = 0
15971 then
15972 Note_Possible_Modification (Expression (AV), Sure => True);
15973 return True;
15975 -- We also allow a non-parenthesized expression that raises
15976 -- constraint error if it rewrites what used to be a variable
15978 elsif Raises_Constraint_Error (Expression (AV))
15979 and then Paren_Count (Expression (AV)) = 0
15980 and then Is_Variable (Original_Node (Expression (AV)))
15981 then
15982 return True;
15984 -- Type conversion of something other than a variable
15986 else
15987 return False;
15988 end if;
15990 -- If this node is rewritten, then test the original form, if that is
15991 -- OK, then we consider the rewritten node OK (for example, if the
15992 -- original node is a conversion, then Is_Variable will not be true
15993 -- but we still want to allow the conversion if it converts a variable).
15995 elsif Is_Rewrite_Substitution (AV) then
15997 -- In Ada 2012, the explicit dereference may be a rewritten call to a
15998 -- Reference function.
16000 if Ada_Version >= Ada_2012
16001 and then Nkind (Original_Node (AV)) = N_Function_Call
16002 and then
16003 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
16004 then
16006 -- Check that this is not a constant reference.
16008 return not Is_Access_Constant (Etype (Prefix (AV)));
16010 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
16011 return
16012 not Is_Access_Constant (Etype
16013 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
16015 else
16016 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
16017 end if;
16019 -- All other non-variables are rejected
16021 else
16022 return False;
16023 end if;
16024 end Is_OK_Variable_For_Out_Formal;
16026 ----------------------------
16027 -- Is_OK_Volatile_Context --
16028 ----------------------------
16030 function Is_OK_Volatile_Context
16031 (Context : Node_Id;
16032 Obj_Ref : Node_Id) return Boolean
16034 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
16035 -- Determine whether an arbitrary node denotes a call to a protected
16036 -- entry, function, or procedure in prefixed form where the prefix is
16037 -- Obj_Ref.
16039 function Within_Check (Nod : Node_Id) return Boolean;
16040 -- Determine whether an arbitrary node appears in a check node
16042 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
16043 -- Determine whether an arbitrary entity appears in a volatile function
16045 ---------------------------------
16046 -- Is_Protected_Operation_Call --
16047 ---------------------------------
16049 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
16050 Pref : Node_Id;
16051 Subp : Node_Id;
16053 begin
16054 -- A call to a protected operations retains its selected component
16055 -- form as opposed to other prefixed calls that are transformed in
16056 -- expanded names.
16058 if Nkind (Nod) = N_Selected_Component then
16059 Pref := Prefix (Nod);
16060 Subp := Selector_Name (Nod);
16062 return
16063 Pref = Obj_Ref
16064 and then Present (Etype (Pref))
16065 and then Is_Protected_Type (Etype (Pref))
16066 and then Is_Entity_Name (Subp)
16067 and then Present (Entity (Subp))
16068 and then Ekind_In (Entity (Subp), E_Entry,
16069 E_Entry_Family,
16070 E_Function,
16071 E_Procedure);
16072 else
16073 return False;
16074 end if;
16075 end Is_Protected_Operation_Call;
16077 ------------------
16078 -- Within_Check --
16079 ------------------
16081 function Within_Check (Nod : Node_Id) return Boolean is
16082 Par : Node_Id;
16084 begin
16085 -- Climb the parent chain looking for a check node
16087 Par := Nod;
16088 while Present (Par) loop
16089 if Nkind (Par) in N_Raise_xxx_Error then
16090 return True;
16092 -- Prevent the search from going too far
16094 elsif Is_Body_Or_Package_Declaration (Par) then
16095 exit;
16096 end if;
16098 Par := Parent (Par);
16099 end loop;
16101 return False;
16102 end Within_Check;
16104 ------------------------------
16105 -- Within_Volatile_Function --
16106 ------------------------------
16108 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
16109 Func_Id : Entity_Id;
16111 begin
16112 -- Traverse the scope stack looking for a [generic] function
16114 Func_Id := Id;
16115 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
16116 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
16117 return Is_Volatile_Function (Func_Id);
16118 end if;
16120 Func_Id := Scope (Func_Id);
16121 end loop;
16123 return False;
16124 end Within_Volatile_Function;
16126 -- Local variables
16128 Obj_Id : Entity_Id;
16130 -- Start of processing for Is_OK_Volatile_Context
16132 begin
16133 -- The volatile object appears on either side of an assignment
16135 if Nkind (Context) = N_Assignment_Statement then
16136 return True;
16138 -- The volatile object is part of the initialization expression of
16139 -- another object.
16141 elsif Nkind (Context) = N_Object_Declaration
16142 and then Present (Expression (Context))
16143 and then Expression (Context) = Obj_Ref
16144 then
16145 Obj_Id := Defining_Entity (Context);
16147 -- The volatile object acts as the initialization expression of an
16148 -- extended return statement. This is valid context as long as the
16149 -- function is volatile.
16151 if Is_Return_Object (Obj_Id) then
16152 return Within_Volatile_Function (Obj_Id);
16154 -- Otherwise this is a normal object initialization
16156 else
16157 return True;
16158 end if;
16160 -- The volatile object acts as the name of a renaming declaration
16162 elsif Nkind (Context) = N_Object_Renaming_Declaration
16163 and then Name (Context) = Obj_Ref
16164 then
16165 return True;
16167 -- The volatile object appears as an actual parameter in a call to an
16168 -- instance of Unchecked_Conversion whose result is renamed.
16170 elsif Nkind (Context) = N_Function_Call
16171 and then Is_Entity_Name (Name (Context))
16172 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
16173 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
16174 then
16175 return True;
16177 -- The volatile object is actually the prefix in a protected entry,
16178 -- function, or procedure call.
16180 elsif Is_Protected_Operation_Call (Context) then
16181 return True;
16183 -- The volatile object appears as the expression of a simple return
16184 -- statement that applies to a volatile function.
16186 elsif Nkind (Context) = N_Simple_Return_Statement
16187 and then Expression (Context) = Obj_Ref
16188 then
16189 return
16190 Within_Volatile_Function (Return_Statement_Entity (Context));
16192 -- The volatile object appears as the prefix of a name occurring in a
16193 -- non-interfering context.
16195 elsif Nkind_In (Context, N_Attribute_Reference,
16196 N_Explicit_Dereference,
16197 N_Indexed_Component,
16198 N_Selected_Component,
16199 N_Slice)
16200 and then Prefix (Context) = Obj_Ref
16201 and then Is_OK_Volatile_Context
16202 (Context => Parent (Context),
16203 Obj_Ref => Context)
16204 then
16205 return True;
16207 -- The volatile object appears as the prefix of attributes Address,
16208 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16209 -- Position, Size, Storage_Size.
16211 elsif Nkind (Context) = N_Attribute_Reference
16212 and then Prefix (Context) = Obj_Ref
16213 and then Nam_In (Attribute_Name (Context), Name_Address,
16214 Name_Alignment,
16215 Name_Component_Size,
16216 Name_First,
16217 Name_First_Bit,
16218 Name_Last,
16219 Name_Last_Bit,
16220 Name_Length,
16221 Name_Position,
16222 Name_Size,
16223 Name_Storage_Size)
16224 then
16225 return True;
16227 -- The volatile object appears as the expression of a type conversion
16228 -- occurring in a non-interfering context.
16230 elsif Nkind_In (Context, N_Type_Conversion,
16231 N_Unchecked_Type_Conversion)
16232 and then Expression (Context) = Obj_Ref
16233 and then Is_OK_Volatile_Context
16234 (Context => Parent (Context),
16235 Obj_Ref => Context)
16236 then
16237 return True;
16239 -- The volatile object appears as the expression in a delay statement
16241 elsif Nkind (Context) in N_Delay_Statement then
16242 return True;
16244 -- Allow references to volatile objects in various checks. This is not a
16245 -- direct SPARK 2014 requirement.
16247 elsif Within_Check (Context) then
16248 return True;
16250 -- Assume that references to effectively volatile objects that appear
16251 -- as actual parameters in a subprogram call are always legal. A full
16252 -- legality check is done when the actuals are resolved (see routine
16253 -- Resolve_Actuals).
16255 elsif Within_Subprogram_Call (Context) then
16256 return True;
16258 -- Otherwise the context is not suitable for an effectively volatile
16259 -- object.
16261 else
16262 return False;
16263 end if;
16264 end Is_OK_Volatile_Context;
16266 ------------------------------------
16267 -- Is_Package_Contract_Annotation --
16268 ------------------------------------
16270 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16271 Nam : Name_Id;
16273 begin
16274 if Nkind (Item) = N_Aspect_Specification then
16275 Nam := Chars (Identifier (Item));
16277 else pragma Assert (Nkind (Item) = N_Pragma);
16278 Nam := Pragma_Name (Item);
16279 end if;
16281 return Nam = Name_Abstract_State
16282 or else Nam = Name_Initial_Condition
16283 or else Nam = Name_Initializes
16284 or else Nam = Name_Refined_State;
16285 end Is_Package_Contract_Annotation;
16287 -----------------------------------
16288 -- Is_Partially_Initialized_Type --
16289 -----------------------------------
16291 function Is_Partially_Initialized_Type
16292 (Typ : Entity_Id;
16293 Include_Implicit : Boolean := True) return Boolean
16295 begin
16296 if Is_Scalar_Type (Typ) then
16297 return False;
16299 elsif Is_Access_Type (Typ) then
16300 return Include_Implicit;
16302 elsif Is_Array_Type (Typ) then
16304 -- If component type is partially initialized, so is array type
16306 if Is_Partially_Initialized_Type
16307 (Component_Type (Typ), Include_Implicit)
16308 then
16309 return True;
16311 -- Otherwise we are only partially initialized if we are fully
16312 -- initialized (this is the empty array case, no point in us
16313 -- duplicating that code here).
16315 else
16316 return Is_Fully_Initialized_Type (Typ);
16317 end if;
16319 elsif Is_Record_Type (Typ) then
16321 -- A discriminated type is always partially initialized if in
16322 -- all mode
16324 if Has_Discriminants (Typ) and then Include_Implicit then
16325 return True;
16327 -- A tagged type is always partially initialized
16329 elsif Is_Tagged_Type (Typ) then
16330 return True;
16332 -- Case of non-discriminated record
16334 else
16335 declare
16336 Ent : Entity_Id;
16338 Component_Present : Boolean := False;
16339 -- Set True if at least one component is present. If no
16340 -- components are present, then record type is fully
16341 -- initialized (another odd case, like the null array).
16343 begin
16344 -- Loop through components
16346 Ent := First_Entity (Typ);
16347 while Present (Ent) loop
16348 if Ekind (Ent) = E_Component then
16349 Component_Present := True;
16351 -- If a component has an initialization expression then
16352 -- the enclosing record type is partially initialized
16354 if Present (Parent (Ent))
16355 and then Present (Expression (Parent (Ent)))
16356 then
16357 return True;
16359 -- If a component is of a type which is itself partially
16360 -- initialized, then the enclosing record type is also.
16362 elsif Is_Partially_Initialized_Type
16363 (Etype (Ent), Include_Implicit)
16364 then
16365 return True;
16366 end if;
16367 end if;
16369 Next_Entity (Ent);
16370 end loop;
16372 -- No initialized components found. If we found any components
16373 -- they were all uninitialized so the result is false.
16375 if Component_Present then
16376 return False;
16378 -- But if we found no components, then all the components are
16379 -- initialized so we consider the type to be initialized.
16381 else
16382 return True;
16383 end if;
16384 end;
16385 end if;
16387 -- Concurrent types are always fully initialized
16389 elsif Is_Concurrent_Type (Typ) then
16390 return True;
16392 -- For a private type, go to underlying type. If there is no underlying
16393 -- type then just assume this partially initialized. Not clear if this
16394 -- can happen in a non-error case, but no harm in testing for this.
16396 elsif Is_Private_Type (Typ) then
16397 declare
16398 U : constant Entity_Id := Underlying_Type (Typ);
16399 begin
16400 if No (U) then
16401 return True;
16402 else
16403 return Is_Partially_Initialized_Type (U, Include_Implicit);
16404 end if;
16405 end;
16407 -- For any other type (are there any?) assume partially initialized
16409 else
16410 return True;
16411 end if;
16412 end Is_Partially_Initialized_Type;
16414 ------------------------------------
16415 -- Is_Potentially_Persistent_Type --
16416 ------------------------------------
16418 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16419 Comp : Entity_Id;
16420 Indx : Node_Id;
16422 begin
16423 -- For private type, test corresponding full type
16425 if Is_Private_Type (T) then
16426 return Is_Potentially_Persistent_Type (Full_View (T));
16428 -- Scalar types are potentially persistent
16430 elsif Is_Scalar_Type (T) then
16431 return True;
16433 -- Record type is potentially persistent if not tagged and the types of
16434 -- all it components are potentially persistent, and no component has
16435 -- an initialization expression.
16437 elsif Is_Record_Type (T)
16438 and then not Is_Tagged_Type (T)
16439 and then not Is_Partially_Initialized_Type (T)
16440 then
16441 Comp := First_Component (T);
16442 while Present (Comp) loop
16443 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16444 return False;
16445 else
16446 Next_Entity (Comp);
16447 end if;
16448 end loop;
16450 return True;
16452 -- Array type is potentially persistent if its component type is
16453 -- potentially persistent and if all its constraints are static.
16455 elsif Is_Array_Type (T) then
16456 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
16457 return False;
16458 end if;
16460 Indx := First_Index (T);
16461 while Present (Indx) loop
16462 if not Is_OK_Static_Subtype (Etype (Indx)) then
16463 return False;
16464 else
16465 Next_Index (Indx);
16466 end if;
16467 end loop;
16469 return True;
16471 -- All other types are not potentially persistent
16473 else
16474 return False;
16475 end if;
16476 end Is_Potentially_Persistent_Type;
16478 --------------------------------
16479 -- Is_Potentially_Unevaluated --
16480 --------------------------------
16482 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
16483 Par : Node_Id;
16484 Expr : Node_Id;
16486 begin
16487 Expr := N;
16488 Par := N;
16490 -- A postcondition whose expression is a short-circuit is broken down
16491 -- into individual aspects for better exception reporting. The original
16492 -- short-circuit expression is rewritten as the second operand, and an
16493 -- occurrence of 'Old in that operand is potentially unevaluated.
16494 -- See sem_ch13.adb for details of this transformation. The reference
16495 -- to 'Old may appear within an expression, so we must look for the
16496 -- enclosing pragma argument in the tree that contains the reference.
16498 while Present (Par)
16499 and then Nkind (Par) /= N_Pragma_Argument_Association
16500 loop
16501 if Is_Rewrite_Substitution (Par)
16502 and then Nkind (Original_Node (Par)) = N_And_Then
16503 then
16504 return True;
16505 end if;
16507 Par := Parent (Par);
16508 end loop;
16510 -- Other cases; 'Old appears within other expression (not the top-level
16511 -- conjunct in a postcondition) with a potentially unevaluated operand.
16513 Par := Parent (Expr);
16514 while not Nkind_In (Par, N_And_Then,
16515 N_Case_Expression,
16516 N_If_Expression,
16517 N_In,
16518 N_Not_In,
16519 N_Or_Else,
16520 N_Quantified_Expression)
16521 loop
16522 Expr := Par;
16523 Par := Parent (Par);
16525 -- If the context is not an expression, or if is the result of
16526 -- expansion of an enclosing construct (such as another attribute)
16527 -- the predicate does not apply.
16529 if Nkind (Par) = N_Case_Expression_Alternative then
16530 null;
16532 elsif Nkind (Par) not in N_Subexpr
16533 or else not Comes_From_Source (Par)
16534 then
16535 return False;
16536 end if;
16537 end loop;
16539 if Nkind (Par) = N_If_Expression then
16540 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
16542 elsif Nkind (Par) = N_Case_Expression then
16543 return Expr /= Expression (Par);
16545 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
16546 return Expr = Right_Opnd (Par);
16548 elsif Nkind_In (Par, N_In, N_Not_In) then
16550 -- If the membership includes several alternatives, only the first is
16551 -- definitely evaluated.
16553 if Present (Alternatives (Par)) then
16554 return Expr /= First (Alternatives (Par));
16556 -- If this is a range membership both bounds are evaluated
16558 else
16559 return False;
16560 end if;
16562 elsif Nkind (Par) = N_Quantified_Expression then
16563 return Expr = Condition (Par);
16565 else
16566 return False;
16567 end if;
16568 end Is_Potentially_Unevaluated;
16570 -----------------------------------------
16571 -- Is_Predefined_Dispatching_Operation --
16572 -----------------------------------------
16574 function Is_Predefined_Dispatching_Operation
16575 (E : Entity_Id) return Boolean
16577 TSS_Name : TSS_Name_Type;
16579 begin
16580 if not Is_Dispatching_Operation (E) then
16581 return False;
16582 end if;
16584 Get_Name_String (Chars (E));
16586 -- Most predefined primitives have internally generated names. Equality
16587 -- must be treated differently; the predefined operation is recognized
16588 -- as a homogeneous binary operator that returns Boolean.
16590 if Name_Len > TSS_Name_Type'Last then
16591 TSS_Name :=
16592 TSS_Name_Type
16593 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16595 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
16596 or else
16597 (Chars (E) = Name_Op_Eq
16598 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16599 or else TSS_Name = TSS_Deep_Adjust
16600 or else TSS_Name = TSS_Deep_Finalize
16601 or else TSS_Name = TSS_Stream_Input
16602 or else TSS_Name = TSS_Stream_Output
16603 or else TSS_Name = TSS_Stream_Read
16604 or else TSS_Name = TSS_Stream_Write
16605 or else Is_Predefined_Interface_Primitive (E)
16606 then
16607 return True;
16608 end if;
16609 end if;
16611 return False;
16612 end Is_Predefined_Dispatching_Operation;
16614 ---------------------------------------
16615 -- Is_Predefined_Interface_Primitive --
16616 ---------------------------------------
16618 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
16619 begin
16620 -- In VM targets we don't restrict the functionality of this test to
16621 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16622 -- these primitives.
16624 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
16625 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
16626 Name_uDisp_Conditional_Select,
16627 Name_uDisp_Get_Prim_Op_Kind,
16628 Name_uDisp_Get_Task_Id,
16629 Name_uDisp_Requeue,
16630 Name_uDisp_Timed_Select);
16631 end Is_Predefined_Interface_Primitive;
16633 ---------------------------------------
16634 -- Is_Predefined_Internal_Operation --
16635 ---------------------------------------
16637 function Is_Predefined_Internal_Operation
16638 (E : Entity_Id) return Boolean
16640 TSS_Name : TSS_Name_Type;
16642 begin
16643 if not Is_Dispatching_Operation (E) then
16644 return False;
16645 end if;
16647 Get_Name_String (Chars (E));
16649 -- Most predefined primitives have internally generated names. Equality
16650 -- must be treated differently; the predefined operation is recognized
16651 -- as a homogeneous binary operator that returns Boolean.
16653 if Name_Len > TSS_Name_Type'Last then
16654 TSS_Name :=
16655 TSS_Name_Type
16656 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16658 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
16659 or else
16660 (Chars (E) = Name_Op_Eq
16661 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16662 or else TSS_Name = TSS_Deep_Adjust
16663 or else TSS_Name = TSS_Deep_Finalize
16664 or else Is_Predefined_Interface_Primitive (E)
16665 then
16666 return True;
16667 end if;
16668 end if;
16670 return False;
16671 end Is_Predefined_Internal_Operation;
16673 --------------------------------
16674 -- Is_Preelaborable_Aggregate --
16675 --------------------------------
16677 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
16678 Aggr_Typ : constant Entity_Id := Etype (Aggr);
16679 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
16681 Anc_Part : Node_Id;
16682 Assoc : Node_Id;
16683 Choice : Node_Id;
16684 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
16685 Expr : Node_Id;
16687 begin
16688 if Array_Aggr then
16689 Comp_Typ := Component_Type (Aggr_Typ);
16690 end if;
16692 -- Inspect the ancestor part
16694 if Nkind (Aggr) = N_Extension_Aggregate then
16695 Anc_Part := Ancestor_Part (Aggr);
16697 -- The ancestor denotes a subtype mark
16699 if Is_Entity_Name (Anc_Part)
16700 and then Is_Type (Entity (Anc_Part))
16701 then
16702 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
16703 return False;
16704 end if;
16706 -- Otherwise the ancestor denotes an expression
16708 elsif not Is_Preelaborable_Construct (Anc_Part) then
16709 return False;
16710 end if;
16711 end if;
16713 -- Inspect the positional associations
16715 Expr := First (Expressions (Aggr));
16716 while Present (Expr) loop
16717 if not Is_Preelaborable_Construct (Expr) then
16718 return False;
16719 end if;
16721 Next (Expr);
16722 end loop;
16724 -- Inspect the named associations
16726 Assoc := First (Component_Associations (Aggr));
16727 while Present (Assoc) loop
16729 -- Inspect the choices of the current named association
16731 Choice := First (Choices (Assoc));
16732 while Present (Choice) loop
16733 if Array_Aggr then
16735 -- For a choice to be preelaborable, it must denote either a
16736 -- static range or a static expression.
16738 if Nkind (Choice) = N_Others_Choice then
16739 null;
16741 elsif Nkind (Choice) = N_Range then
16742 if not Is_OK_Static_Range (Choice) then
16743 return False;
16744 end if;
16746 elsif not Is_OK_Static_Expression (Choice) then
16747 return False;
16748 end if;
16750 else
16751 Comp_Typ := Etype (Choice);
16752 end if;
16754 Next (Choice);
16755 end loop;
16757 -- The type of the choice must have preelaborable initialization if
16758 -- the association carries a <>.
16760 pragma Assert (Present (Comp_Typ));
16761 if Box_Present (Assoc) then
16762 if not Has_Preelaborable_Initialization (Comp_Typ) then
16763 return False;
16764 end if;
16766 -- The type of the expression must have preelaborable initialization
16768 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
16769 return False;
16770 end if;
16772 Next (Assoc);
16773 end loop;
16775 -- At this point the aggregate is preelaborable
16777 return True;
16778 end Is_Preelaborable_Aggregate;
16780 --------------------------------
16781 -- Is_Preelaborable_Construct --
16782 --------------------------------
16784 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
16785 begin
16786 -- Aggregates
16788 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
16789 return Is_Preelaborable_Aggregate (N);
16791 -- Attributes are allowed in general, even if their prefix is a formal
16792 -- type. It seems that certain attributes known not to be static might
16793 -- not be allowed, but there are no rules to prevent them.
16795 elsif Nkind (N) = N_Attribute_Reference then
16796 return True;
16798 -- Expressions
16800 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
16801 return True;
16803 elsif Nkind (N) = N_Qualified_Expression then
16804 return Is_Preelaborable_Construct (Expression (N));
16806 -- Names are preelaborable when they denote a discriminant of an
16807 -- enclosing type. Discriminals are also considered for this check.
16809 elsif Is_Entity_Name (N)
16810 and then Present (Entity (N))
16811 and then
16812 (Ekind (Entity (N)) = E_Discriminant
16813 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
16814 and then Present (Discriminal_Link (Entity (N)))))
16815 then
16816 return True;
16818 -- Statements
16820 elsif Nkind (N) = N_Null then
16821 return True;
16823 -- Otherwise the construct is not preelaborable
16825 else
16826 return False;
16827 end if;
16828 end Is_Preelaborable_Construct;
16830 ---------------------------------
16831 -- Is_Protected_Self_Reference --
16832 ---------------------------------
16834 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
16836 function In_Access_Definition (N : Node_Id) return Boolean;
16837 -- Returns true if N belongs to an access definition
16839 --------------------------
16840 -- In_Access_Definition --
16841 --------------------------
16843 function In_Access_Definition (N : Node_Id) return Boolean is
16844 P : Node_Id;
16846 begin
16847 P := Parent (N);
16848 while Present (P) loop
16849 if Nkind (P) = N_Access_Definition then
16850 return True;
16851 end if;
16853 P := Parent (P);
16854 end loop;
16856 return False;
16857 end In_Access_Definition;
16859 -- Start of processing for Is_Protected_Self_Reference
16861 begin
16862 -- Verify that prefix is analyzed and has the proper form. Note that
16863 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
16864 -- produce the address of an entity, do not analyze their prefix
16865 -- because they denote entities that are not necessarily visible.
16866 -- Neither of them can apply to a protected type.
16868 return Ada_Version >= Ada_2005
16869 and then Is_Entity_Name (N)
16870 and then Present (Entity (N))
16871 and then Is_Protected_Type (Entity (N))
16872 and then In_Open_Scopes (Entity (N))
16873 and then not In_Access_Definition (N);
16874 end Is_Protected_Self_Reference;
16876 -----------------------------
16877 -- Is_RCI_Pkg_Spec_Or_Body --
16878 -----------------------------
16880 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
16882 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
16883 -- Return True if the unit of Cunit is an RCI package declaration
16885 ---------------------------
16886 -- Is_RCI_Pkg_Decl_Cunit --
16887 ---------------------------
16889 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
16890 The_Unit : constant Node_Id := Unit (Cunit);
16892 begin
16893 if Nkind (The_Unit) /= N_Package_Declaration then
16894 return False;
16895 end if;
16897 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
16898 end Is_RCI_Pkg_Decl_Cunit;
16900 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
16902 begin
16903 return Is_RCI_Pkg_Decl_Cunit (Cunit)
16904 or else
16905 (Nkind (Unit (Cunit)) = N_Package_Body
16906 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
16907 end Is_RCI_Pkg_Spec_Or_Body;
16909 -----------------------------------------
16910 -- Is_Remote_Access_To_Class_Wide_Type --
16911 -----------------------------------------
16913 function Is_Remote_Access_To_Class_Wide_Type
16914 (E : Entity_Id) return Boolean
16916 begin
16917 -- A remote access to class-wide type is a general access to object type
16918 -- declared in the visible part of a Remote_Types or Remote_Call_
16919 -- Interface unit.
16921 return Ekind (E) = E_General_Access_Type
16922 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16923 end Is_Remote_Access_To_Class_Wide_Type;
16925 -----------------------------------------
16926 -- Is_Remote_Access_To_Subprogram_Type --
16927 -----------------------------------------
16929 function Is_Remote_Access_To_Subprogram_Type
16930 (E : Entity_Id) return Boolean
16932 begin
16933 return (Ekind (E) = E_Access_Subprogram_Type
16934 or else (Ekind (E) = E_Record_Type
16935 and then Present (Corresponding_Remote_Type (E))))
16936 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16937 end Is_Remote_Access_To_Subprogram_Type;
16939 --------------------
16940 -- Is_Remote_Call --
16941 --------------------
16943 function Is_Remote_Call (N : Node_Id) return Boolean is
16944 begin
16945 if Nkind (N) not in N_Subprogram_Call then
16947 -- An entry call cannot be remote
16949 return False;
16951 elsif Nkind (Name (N)) in N_Has_Entity
16952 and then Is_Remote_Call_Interface (Entity (Name (N)))
16953 then
16954 -- A subprogram declared in the spec of a RCI package is remote
16956 return True;
16958 elsif Nkind (Name (N)) = N_Explicit_Dereference
16959 and then Is_Remote_Access_To_Subprogram_Type
16960 (Etype (Prefix (Name (N))))
16961 then
16962 -- The dereference of a RAS is a remote call
16964 return True;
16966 elsif Present (Controlling_Argument (N))
16967 and then Is_Remote_Access_To_Class_Wide_Type
16968 (Etype (Controlling_Argument (N)))
16969 then
16970 -- Any primitive operation call with a controlling argument of
16971 -- a RACW type is a remote call.
16973 return True;
16974 end if;
16976 -- All other calls are local calls
16978 return False;
16979 end Is_Remote_Call;
16981 ----------------------
16982 -- Is_Renamed_Entry --
16983 ----------------------
16985 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
16986 Orig_Node : Node_Id := Empty;
16987 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
16989 function Is_Entry (Nam : Node_Id) return Boolean;
16990 -- Determine whether Nam is an entry. Traverse selectors if there are
16991 -- nested selected components.
16993 --------------
16994 -- Is_Entry --
16995 --------------
16997 function Is_Entry (Nam : Node_Id) return Boolean is
16998 begin
16999 if Nkind (Nam) = N_Selected_Component then
17000 return Is_Entry (Selector_Name (Nam));
17001 end if;
17003 return Ekind (Entity (Nam)) = E_Entry;
17004 end Is_Entry;
17006 -- Start of processing for Is_Renamed_Entry
17008 begin
17009 if Present (Alias (Proc_Nam)) then
17010 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
17011 end if;
17013 -- Look for a rewritten subprogram renaming declaration
17015 if Nkind (Subp_Decl) = N_Subprogram_Declaration
17016 and then Present (Original_Node (Subp_Decl))
17017 then
17018 Orig_Node := Original_Node (Subp_Decl);
17019 end if;
17021 -- The rewritten subprogram is actually an entry
17023 if Present (Orig_Node)
17024 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
17025 and then Is_Entry (Name (Orig_Node))
17026 then
17027 return True;
17028 end if;
17030 return False;
17031 end Is_Renamed_Entry;
17033 -----------------------------
17034 -- Is_Renaming_Declaration --
17035 -----------------------------
17037 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
17038 begin
17039 case Nkind (N) is
17040 when N_Exception_Renaming_Declaration
17041 | N_Generic_Function_Renaming_Declaration
17042 | N_Generic_Package_Renaming_Declaration
17043 | N_Generic_Procedure_Renaming_Declaration
17044 | N_Object_Renaming_Declaration
17045 | N_Package_Renaming_Declaration
17046 | N_Subprogram_Renaming_Declaration
17048 return True;
17050 when others =>
17051 return False;
17052 end case;
17053 end Is_Renaming_Declaration;
17055 ----------------------------
17056 -- Is_Reversible_Iterator --
17057 ----------------------------
17059 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
17060 Ifaces_List : Elist_Id;
17061 Iface_Elmt : Elmt_Id;
17062 Iface : Entity_Id;
17064 begin
17065 if Is_Class_Wide_Type (Typ)
17066 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
17067 and then In_Predefined_Unit (Root_Type (Typ))
17068 then
17069 return True;
17071 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17072 return False;
17074 else
17075 Collect_Interfaces (Typ, Ifaces_List);
17077 Iface_Elmt := First_Elmt (Ifaces_List);
17078 while Present (Iface_Elmt) loop
17079 Iface := Node (Iface_Elmt);
17080 if Chars (Iface) = Name_Reversible_Iterator
17081 and then In_Predefined_Unit (Iface)
17082 then
17083 return True;
17084 end if;
17086 Next_Elmt (Iface_Elmt);
17087 end loop;
17088 end if;
17090 return False;
17091 end Is_Reversible_Iterator;
17093 ----------------------
17094 -- Is_Selector_Name --
17095 ----------------------
17097 function Is_Selector_Name (N : Node_Id) return Boolean is
17098 begin
17099 if not Is_List_Member (N) then
17100 declare
17101 P : constant Node_Id := Parent (N);
17102 begin
17103 return Nkind_In (P, N_Expanded_Name,
17104 N_Generic_Association,
17105 N_Parameter_Association,
17106 N_Selected_Component)
17107 and then Selector_Name (P) = N;
17108 end;
17110 else
17111 declare
17112 L : constant List_Id := List_Containing (N);
17113 P : constant Node_Id := Parent (L);
17114 begin
17115 return (Nkind (P) = N_Discriminant_Association
17116 and then Selector_Names (P) = L)
17117 or else
17118 (Nkind (P) = N_Component_Association
17119 and then Choices (P) = L);
17120 end;
17121 end if;
17122 end Is_Selector_Name;
17124 ---------------------------------
17125 -- Is_Single_Concurrent_Object --
17126 ---------------------------------
17128 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
17129 begin
17130 return
17131 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
17132 end Is_Single_Concurrent_Object;
17134 -------------------------------
17135 -- Is_Single_Concurrent_Type --
17136 -------------------------------
17138 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
17139 begin
17140 return
17141 Ekind_In (Id, E_Protected_Type, E_Task_Type)
17142 and then Is_Single_Concurrent_Type_Declaration
17143 (Declaration_Node (Id));
17144 end Is_Single_Concurrent_Type;
17146 -------------------------------------------
17147 -- Is_Single_Concurrent_Type_Declaration --
17148 -------------------------------------------
17150 function Is_Single_Concurrent_Type_Declaration
17151 (N : Node_Id) return Boolean
17153 begin
17154 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
17155 N_Single_Task_Declaration);
17156 end Is_Single_Concurrent_Type_Declaration;
17158 ---------------------------------------------
17159 -- Is_Single_Precision_Floating_Point_Type --
17160 ---------------------------------------------
17162 function Is_Single_Precision_Floating_Point_Type
17163 (E : Entity_Id) return Boolean is
17164 begin
17165 return Is_Floating_Point_Type (E)
17166 and then Machine_Radix_Value (E) = Uint_2
17167 and then Machine_Mantissa_Value (E) = Uint_24
17168 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
17169 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
17170 end Is_Single_Precision_Floating_Point_Type;
17172 --------------------------------
17173 -- Is_Single_Protected_Object --
17174 --------------------------------
17176 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
17177 begin
17178 return
17179 Ekind (Id) = E_Variable
17180 and then Ekind (Etype (Id)) = E_Protected_Type
17181 and then Is_Single_Concurrent_Type (Etype (Id));
17182 end Is_Single_Protected_Object;
17184 ---------------------------
17185 -- Is_Single_Task_Object --
17186 ---------------------------
17188 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
17189 begin
17190 return
17191 Ekind (Id) = E_Variable
17192 and then Ekind (Etype (Id)) = E_Task_Type
17193 and then Is_Single_Concurrent_Type (Etype (Id));
17194 end Is_Single_Task_Object;
17196 -------------------------------------
17197 -- Is_SPARK_05_Initialization_Expr --
17198 -------------------------------------
17200 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
17201 Is_Ok : Boolean;
17202 Expr : Node_Id;
17203 Comp_Assn : Node_Id;
17204 Orig_N : constant Node_Id := Original_Node (N);
17206 begin
17207 Is_Ok := True;
17209 if not Comes_From_Source (Orig_N) then
17210 goto Done;
17211 end if;
17213 pragma Assert (Nkind (Orig_N) in N_Subexpr);
17215 case Nkind (Orig_N) is
17216 when N_Character_Literal
17217 | N_Integer_Literal
17218 | N_Real_Literal
17219 | N_String_Literal
17221 null;
17223 when N_Expanded_Name
17224 | N_Identifier
17226 if Is_Entity_Name (Orig_N)
17227 and then Present (Entity (Orig_N)) -- needed in some cases
17228 then
17229 case Ekind (Entity (Orig_N)) is
17230 when E_Constant
17231 | E_Enumeration_Literal
17232 | E_Named_Integer
17233 | E_Named_Real
17235 null;
17237 when others =>
17238 if Is_Type (Entity (Orig_N)) then
17239 null;
17240 else
17241 Is_Ok := False;
17242 end if;
17243 end case;
17244 end if;
17246 when N_Qualified_Expression
17247 | N_Type_Conversion
17249 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17251 when N_Unary_Op =>
17252 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17254 when N_Binary_Op
17255 | N_Membership_Test
17256 | N_Short_Circuit
17258 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17259 and then
17260 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17262 when N_Aggregate
17263 | N_Extension_Aggregate
17265 if Nkind (Orig_N) = N_Extension_Aggregate then
17266 Is_Ok :=
17267 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17268 end if;
17270 Expr := First (Expressions (Orig_N));
17271 while Present (Expr) loop
17272 if not Is_SPARK_05_Initialization_Expr (Expr) then
17273 Is_Ok := False;
17274 goto Done;
17275 end if;
17277 Next (Expr);
17278 end loop;
17280 Comp_Assn := First (Component_Associations (Orig_N));
17281 while Present (Comp_Assn) loop
17282 Expr := Expression (Comp_Assn);
17284 -- Note: test for Present here needed for box assocation
17286 if Present (Expr)
17287 and then not Is_SPARK_05_Initialization_Expr (Expr)
17288 then
17289 Is_Ok := False;
17290 goto Done;
17291 end if;
17293 Next (Comp_Assn);
17294 end loop;
17296 when N_Attribute_Reference =>
17297 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17298 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17299 end if;
17301 Expr := First (Expressions (Orig_N));
17302 while Present (Expr) loop
17303 if not Is_SPARK_05_Initialization_Expr (Expr) then
17304 Is_Ok := False;
17305 goto Done;
17306 end if;
17308 Next (Expr);
17309 end loop;
17311 -- Selected components might be expanded named not yet resolved, so
17312 -- default on the safe side. (Eg on sparklex.ads)
17314 when N_Selected_Component =>
17315 null;
17317 when others =>
17318 Is_Ok := False;
17319 end case;
17321 <<Done>>
17322 return Is_Ok;
17323 end Is_SPARK_05_Initialization_Expr;
17325 ----------------------------------
17326 -- Is_SPARK_05_Object_Reference --
17327 ----------------------------------
17329 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17330 begin
17331 if Is_Entity_Name (N) then
17332 return Present (Entity (N))
17333 and then
17334 (Ekind_In (Entity (N), E_Constant, E_Variable)
17335 or else Ekind (Entity (N)) in Formal_Kind);
17337 else
17338 case Nkind (N) is
17339 when N_Selected_Component =>
17340 return Is_SPARK_05_Object_Reference (Prefix (N));
17342 when others =>
17343 return False;
17344 end case;
17345 end if;
17346 end Is_SPARK_05_Object_Reference;
17348 -----------------------------
17349 -- Is_Specific_Tagged_Type --
17350 -----------------------------
17352 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17353 Full_Typ : Entity_Id;
17355 begin
17356 -- Handle private types
17358 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17359 Full_Typ := Full_View (Typ);
17360 else
17361 Full_Typ := Typ;
17362 end if;
17364 -- A specific tagged type is a non-class-wide tagged type
17366 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17367 end Is_Specific_Tagged_Type;
17369 ------------------
17370 -- Is_Statement --
17371 ------------------
17373 function Is_Statement (N : Node_Id) return Boolean is
17374 begin
17375 return
17376 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17377 or else Nkind (N) = N_Procedure_Call_Statement;
17378 end Is_Statement;
17380 ---------------------------------------
17381 -- Is_Subprogram_Contract_Annotation --
17382 ---------------------------------------
17384 function Is_Subprogram_Contract_Annotation
17385 (Item : Node_Id) return Boolean
17387 Nam : Name_Id;
17389 begin
17390 if Nkind (Item) = N_Aspect_Specification then
17391 Nam := Chars (Identifier (Item));
17393 else pragma Assert (Nkind (Item) = N_Pragma);
17394 Nam := Pragma_Name (Item);
17395 end if;
17397 return Nam = Name_Contract_Cases
17398 or else Nam = Name_Depends
17399 or else Nam = Name_Extensions_Visible
17400 or else Nam = Name_Global
17401 or else Nam = Name_Post
17402 or else Nam = Name_Post_Class
17403 or else Nam = Name_Postcondition
17404 or else Nam = Name_Pre
17405 or else Nam = Name_Pre_Class
17406 or else Nam = Name_Precondition
17407 or else Nam = Name_Refined_Depends
17408 or else Nam = Name_Refined_Global
17409 or else Nam = Name_Refined_Post
17410 or else Nam = Name_Test_Case;
17411 end Is_Subprogram_Contract_Annotation;
17413 --------------------------------------------------
17414 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17415 --------------------------------------------------
17417 function Is_Subprogram_Stub_Without_Prior_Declaration
17418 (N : Node_Id) return Boolean
17420 begin
17421 -- A subprogram stub without prior declaration serves as declaration for
17422 -- the actual subprogram body. As such, it has an attached defining
17423 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
17425 return Nkind (N) = N_Subprogram_Body_Stub
17426 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
17427 end Is_Subprogram_Stub_Without_Prior_Declaration;
17429 ---------------------------
17430 -- Is_Suitable_Primitive --
17431 ---------------------------
17433 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
17434 begin
17435 -- The Default_Initial_Condition and invariant procedures must not be
17436 -- treated as primitive operations even when they apply to a tagged
17437 -- type. These routines must not act as targets of dispatching calls
17438 -- because they already utilize class-wide-precondition semantics to
17439 -- handle inheritance and overriding.
17441 if Ekind (Subp_Id) = E_Procedure
17442 and then (Is_DIC_Procedure (Subp_Id)
17443 or else
17444 Is_Invariant_Procedure (Subp_Id))
17445 then
17446 return False;
17447 end if;
17449 return True;
17450 end Is_Suitable_Primitive;
17452 --------------------------
17453 -- Is_Suspension_Object --
17454 --------------------------
17456 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
17457 begin
17458 -- This approach does an exact name match rather than to rely on
17459 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17460 -- front end at point where all auxiliary tables are locked and any
17461 -- modifications to them are treated as violations. Do not tamper with
17462 -- the tables, instead examine the Chars fields of all the scopes of Id.
17464 return
17465 Chars (Id) = Name_Suspension_Object
17466 and then Present (Scope (Id))
17467 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
17468 and then Present (Scope (Scope (Id)))
17469 and then Chars (Scope (Scope (Id))) = Name_Ada
17470 and then Present (Scope (Scope (Scope (Id))))
17471 and then Scope (Scope (Scope (Id))) = Standard_Standard;
17472 end Is_Suspension_Object;
17474 ----------------------------
17475 -- Is_Synchronized_Object --
17476 ----------------------------
17478 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
17479 Prag : Node_Id;
17481 begin
17482 if Is_Object (Id) then
17484 -- The object is synchronized if it is of a type that yields a
17485 -- synchronized object.
17487 if Yields_Synchronized_Object (Etype (Id)) then
17488 return True;
17490 -- The object is synchronized if it is atomic and Async_Writers is
17491 -- enabled.
17493 elsif Is_Atomic_Object_Entity (Id)
17494 and then Async_Writers_Enabled (Id)
17495 then
17496 return True;
17498 -- A constant is a synchronized object by default
17500 elsif Ekind (Id) = E_Constant then
17501 return True;
17503 -- A variable is a synchronized object if it is subject to pragma
17504 -- Constant_After_Elaboration.
17506 elsif Ekind (Id) = E_Variable then
17507 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
17509 return Present (Prag) and then Is_Enabled_Pragma (Prag);
17510 end if;
17511 end if;
17513 -- Otherwise the input is not an object or it does not qualify as a
17514 -- synchronized object.
17516 return False;
17517 end Is_Synchronized_Object;
17519 ---------------------------------
17520 -- Is_Synchronized_Tagged_Type --
17521 ---------------------------------
17523 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
17524 Kind : constant Entity_Kind := Ekind (Base_Type (E));
17526 begin
17527 -- A task or protected type derived from an interface is a tagged type.
17528 -- Such a tagged type is called a synchronized tagged type, as are
17529 -- synchronized interfaces and private extensions whose declaration
17530 -- includes the reserved word synchronized.
17532 return (Is_Tagged_Type (E)
17533 and then (Kind = E_Task_Type
17534 or else
17535 Kind = E_Protected_Type))
17536 or else
17537 (Is_Interface (E)
17538 and then Is_Synchronized_Interface (E))
17539 or else
17540 (Ekind (E) = E_Record_Type_With_Private
17541 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
17542 and then (Synchronized_Present (Parent (E))
17543 or else Is_Synchronized_Interface (Etype (E))));
17544 end Is_Synchronized_Tagged_Type;
17546 -----------------
17547 -- Is_Transfer --
17548 -----------------
17550 function Is_Transfer (N : Node_Id) return Boolean is
17551 Kind : constant Node_Kind := Nkind (N);
17553 begin
17554 if Kind = N_Simple_Return_Statement
17555 or else
17556 Kind = N_Extended_Return_Statement
17557 or else
17558 Kind = N_Goto_Statement
17559 or else
17560 Kind = N_Raise_Statement
17561 or else
17562 Kind = N_Requeue_Statement
17563 then
17564 return True;
17566 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
17567 and then No (Condition (N))
17568 then
17569 return True;
17571 elsif Kind = N_Procedure_Call_Statement
17572 and then Is_Entity_Name (Name (N))
17573 and then Present (Entity (Name (N)))
17574 and then No_Return (Entity (Name (N)))
17575 then
17576 return True;
17578 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
17579 return True;
17581 else
17582 return False;
17583 end if;
17584 end Is_Transfer;
17586 -------------
17587 -- Is_True --
17588 -------------
17590 function Is_True (U : Uint) return Boolean is
17591 begin
17592 return (U /= 0);
17593 end Is_True;
17595 --------------------------------------
17596 -- Is_Unchecked_Conversion_Instance --
17597 --------------------------------------
17599 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
17600 Par : Node_Id;
17602 begin
17603 -- Look for a function whose generic parent is the predefined intrinsic
17604 -- function Unchecked_Conversion, or for one that renames such an
17605 -- instance.
17607 if Ekind (Id) = E_Function then
17608 Par := Parent (Id);
17610 if Nkind (Par) = N_Function_Specification then
17611 Par := Generic_Parent (Par);
17613 if Present (Par) then
17614 return
17615 Chars (Par) = Name_Unchecked_Conversion
17616 and then Is_Intrinsic_Subprogram (Par)
17617 and then In_Predefined_Unit (Par);
17618 else
17619 return
17620 Present (Alias (Id))
17621 and then Is_Unchecked_Conversion_Instance (Alias (Id));
17622 end if;
17623 end if;
17624 end if;
17626 return False;
17627 end Is_Unchecked_Conversion_Instance;
17629 -------------------------------
17630 -- Is_Universal_Numeric_Type --
17631 -------------------------------
17633 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
17634 begin
17635 return T = Universal_Integer or else T = Universal_Real;
17636 end Is_Universal_Numeric_Type;
17638 ------------------------------
17639 -- Is_User_Defined_Equality --
17640 ------------------------------
17642 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
17643 begin
17644 return Ekind (Id) = E_Function
17645 and then Chars (Id) = Name_Op_Eq
17646 and then Comes_From_Source (Id)
17648 -- Internally generated equalities have a full type declaration
17649 -- as their parent.
17651 and then Nkind (Parent (Id)) = N_Function_Specification;
17652 end Is_User_Defined_Equality;
17654 --------------------------------------
17655 -- Is_Validation_Variable_Reference --
17656 --------------------------------------
17658 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
17659 Var : constant Node_Id := Unqual_Conv (N);
17660 Var_Id : Entity_Id;
17662 begin
17663 Var_Id := Empty;
17665 if Is_Entity_Name (Var) then
17666 Var_Id := Entity (Var);
17667 end if;
17669 return
17670 Present (Var_Id)
17671 and then Ekind (Var_Id) = E_Variable
17672 and then Present (Validated_Object (Var_Id));
17673 end Is_Validation_Variable_Reference;
17675 ----------------------------
17676 -- Is_Variable_Size_Array --
17677 ----------------------------
17679 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
17680 Idx : Node_Id;
17682 begin
17683 pragma Assert (Is_Array_Type (E));
17685 -- Check if some index is initialized with a non-constant value
17687 Idx := First_Index (E);
17688 while Present (Idx) loop
17689 if Nkind (Idx) = N_Range then
17690 if not Is_Constant_Bound (Low_Bound (Idx))
17691 or else not Is_Constant_Bound (High_Bound (Idx))
17692 then
17693 return True;
17694 end if;
17695 end if;
17697 Idx := Next_Index (Idx);
17698 end loop;
17700 return False;
17701 end Is_Variable_Size_Array;
17703 -----------------------------
17704 -- Is_Variable_Size_Record --
17705 -----------------------------
17707 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
17708 Comp : Entity_Id;
17709 Comp_Typ : Entity_Id;
17711 begin
17712 pragma Assert (Is_Record_Type (E));
17714 Comp := First_Component (E);
17715 while Present (Comp) loop
17716 Comp_Typ := Underlying_Type (Etype (Comp));
17718 -- Recursive call if the record type has discriminants
17720 if Is_Record_Type (Comp_Typ)
17721 and then Has_Discriminants (Comp_Typ)
17722 and then Is_Variable_Size_Record (Comp_Typ)
17723 then
17724 return True;
17726 elsif Is_Array_Type (Comp_Typ)
17727 and then Is_Variable_Size_Array (Comp_Typ)
17728 then
17729 return True;
17730 end if;
17732 Next_Component (Comp);
17733 end loop;
17735 return False;
17736 end Is_Variable_Size_Record;
17738 -----------------
17739 -- Is_Variable --
17740 -----------------
17742 function Is_Variable
17743 (N : Node_Id;
17744 Use_Original_Node : Boolean := True) return Boolean
17746 Orig_Node : Node_Id;
17748 function In_Protected_Function (E : Entity_Id) return Boolean;
17749 -- Within a protected function, the private components of the enclosing
17750 -- protected type are constants. A function nested within a (protected)
17751 -- procedure is not itself protected. Within the body of a protected
17752 -- function the current instance of the protected type is a constant.
17754 function Is_Variable_Prefix (P : Node_Id) return Boolean;
17755 -- Prefixes can involve implicit dereferences, in which case we must
17756 -- test for the case of a reference of a constant access type, which can
17757 -- can never be a variable.
17759 ---------------------------
17760 -- In_Protected_Function --
17761 ---------------------------
17763 function In_Protected_Function (E : Entity_Id) return Boolean is
17764 Prot : Entity_Id;
17765 S : Entity_Id;
17767 begin
17768 -- E is the current instance of a type
17770 if Is_Type (E) then
17771 Prot := E;
17773 -- E is an object
17775 else
17776 Prot := Scope (E);
17777 end if;
17779 if not Is_Protected_Type (Prot) then
17780 return False;
17782 else
17783 S := Current_Scope;
17784 while Present (S) and then S /= Prot loop
17785 if Ekind (S) = E_Function and then Scope (S) = Prot then
17786 return True;
17787 end if;
17789 S := Scope (S);
17790 end loop;
17792 return False;
17793 end if;
17794 end In_Protected_Function;
17796 ------------------------
17797 -- Is_Variable_Prefix --
17798 ------------------------
17800 function Is_Variable_Prefix (P : Node_Id) return Boolean is
17801 begin
17802 if Is_Access_Type (Etype (P)) then
17803 return not Is_Access_Constant (Root_Type (Etype (P)));
17805 -- For the case of an indexed component whose prefix has a packed
17806 -- array type, the prefix has been rewritten into a type conversion.
17807 -- Determine variable-ness from the converted expression.
17809 elsif Nkind (P) = N_Type_Conversion
17810 and then not Comes_From_Source (P)
17811 and then Is_Array_Type (Etype (P))
17812 and then Is_Packed (Etype (P))
17813 then
17814 return Is_Variable (Expression (P));
17816 else
17817 return Is_Variable (P);
17818 end if;
17819 end Is_Variable_Prefix;
17821 -- Start of processing for Is_Variable
17823 begin
17824 -- Special check, allow x'Deref(expr) as a variable
17826 if Nkind (N) = N_Attribute_Reference
17827 and then Attribute_Name (N) = Name_Deref
17828 then
17829 return True;
17830 end if;
17832 -- Check if we perform the test on the original node since this may be a
17833 -- test of syntactic categories which must not be disturbed by whatever
17834 -- rewriting might have occurred. For example, an aggregate, which is
17835 -- certainly NOT a variable, could be turned into a variable by
17836 -- expansion.
17838 if Use_Original_Node then
17839 Orig_Node := Original_Node (N);
17840 else
17841 Orig_Node := N;
17842 end if;
17844 -- Definitely OK if Assignment_OK is set. Since this is something that
17845 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
17847 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
17848 return True;
17850 -- Normally we go to the original node, but there is one exception where
17851 -- we use the rewritten node, namely when it is an explicit dereference.
17852 -- The generated code may rewrite a prefix which is an access type with
17853 -- an explicit dereference. The dereference is a variable, even though
17854 -- the original node may not be (since it could be a constant of the
17855 -- access type).
17857 -- In Ada 2005 we have a further case to consider: the prefix may be a
17858 -- function call given in prefix notation. The original node appears to
17859 -- be a selected component, but we need to examine the call.
17861 elsif Nkind (N) = N_Explicit_Dereference
17862 and then Nkind (Orig_Node) /= N_Explicit_Dereference
17863 and then Present (Etype (Orig_Node))
17864 and then Is_Access_Type (Etype (Orig_Node))
17865 then
17866 -- Note that if the prefix is an explicit dereference that does not
17867 -- come from source, we must check for a rewritten function call in
17868 -- prefixed notation before other forms of rewriting, to prevent a
17869 -- compiler crash.
17871 return
17872 (Nkind (Orig_Node) = N_Function_Call
17873 and then not Is_Access_Constant (Etype (Prefix (N))))
17874 or else
17875 Is_Variable_Prefix (Original_Node (Prefix (N)));
17877 -- in Ada 2012, the dereference may have been added for a type with
17878 -- a declared implicit dereference aspect. Check that it is not an
17879 -- access to constant.
17881 elsif Nkind (N) = N_Explicit_Dereference
17882 and then Present (Etype (Orig_Node))
17883 and then Ada_Version >= Ada_2012
17884 and then Has_Implicit_Dereference (Etype (Orig_Node))
17885 then
17886 return not Is_Access_Constant (Etype (Prefix (N)));
17888 -- A function call is never a variable
17890 elsif Nkind (N) = N_Function_Call then
17891 return False;
17893 -- All remaining checks use the original node
17895 elsif Is_Entity_Name (Orig_Node)
17896 and then Present (Entity (Orig_Node))
17897 then
17898 declare
17899 E : constant Entity_Id := Entity (Orig_Node);
17900 K : constant Entity_Kind := Ekind (E);
17902 begin
17903 if Is_Loop_Parameter (E) then
17904 return False;
17905 end if;
17907 return (K = E_Variable
17908 and then Nkind (Parent (E)) /= N_Exception_Handler)
17909 or else (K = E_Component
17910 and then not In_Protected_Function (E))
17911 or else K = E_Out_Parameter
17912 or else K = E_In_Out_Parameter
17913 or else K = E_Generic_In_Out_Parameter
17915 -- Current instance of type. If this is a protected type, check
17916 -- we are not within the body of one of its protected functions.
17918 or else (Is_Type (E)
17919 and then In_Open_Scopes (E)
17920 and then not In_Protected_Function (E))
17922 or else (Is_Incomplete_Or_Private_Type (E)
17923 and then In_Open_Scopes (Full_View (E)));
17924 end;
17926 else
17927 case Nkind (Orig_Node) is
17928 when N_Indexed_Component
17929 | N_Slice
17931 return Is_Variable_Prefix (Prefix (Orig_Node));
17933 when N_Selected_Component =>
17934 return (Is_Variable (Selector_Name (Orig_Node))
17935 and then Is_Variable_Prefix (Prefix (Orig_Node)))
17936 or else
17937 (Nkind (N) = N_Expanded_Name
17938 and then Scope (Entity (N)) = Entity (Prefix (N)));
17940 -- For an explicit dereference, the type of the prefix cannot
17941 -- be an access to constant or an access to subprogram.
17943 when N_Explicit_Dereference =>
17944 declare
17945 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
17946 begin
17947 return Is_Access_Type (Typ)
17948 and then not Is_Access_Constant (Root_Type (Typ))
17949 and then Ekind (Typ) /= E_Access_Subprogram_Type;
17950 end;
17952 -- The type conversion is the case where we do not deal with the
17953 -- context dependent special case of an actual parameter. Thus
17954 -- the type conversion is only considered a variable for the
17955 -- purposes of this routine if the target type is tagged. However,
17956 -- a type conversion is considered to be a variable if it does not
17957 -- come from source (this deals for example with the conversions
17958 -- of expressions to their actual subtypes).
17960 when N_Type_Conversion =>
17961 return Is_Variable (Expression (Orig_Node))
17962 and then
17963 (not Comes_From_Source (Orig_Node)
17964 or else
17965 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
17966 and then
17967 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
17969 -- GNAT allows an unchecked type conversion as a variable. This
17970 -- only affects the generation of internal expanded code, since
17971 -- calls to instantiations of Unchecked_Conversion are never
17972 -- considered variables (since they are function calls).
17974 when N_Unchecked_Type_Conversion =>
17975 return Is_Variable (Expression (Orig_Node));
17977 when others =>
17978 return False;
17979 end case;
17980 end if;
17981 end Is_Variable;
17983 ---------------------------
17984 -- Is_Visibly_Controlled --
17985 ---------------------------
17987 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
17988 Root : constant Entity_Id := Root_Type (T);
17989 begin
17990 return Chars (Scope (Root)) = Name_Finalization
17991 and then Chars (Scope (Scope (Root))) = Name_Ada
17992 and then Scope (Scope (Scope (Root))) = Standard_Standard;
17993 end Is_Visibly_Controlled;
17995 --------------------------
17996 -- Is_Volatile_Function --
17997 --------------------------
17999 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
18000 begin
18001 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
18003 -- A function declared within a protected type is volatile
18005 if Is_Protected_Type (Scope (Func_Id)) then
18006 return True;
18008 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18009 -- either the source or the target are effectively volatile.
18011 elsif Is_Unchecked_Conversion_Instance (Func_Id)
18012 and then Has_Effectively_Volatile_Profile (Func_Id)
18013 then
18014 return True;
18016 -- Otherwise the function is treated as volatile if it is subject to
18017 -- enabled pragma Volatile_Function.
18019 else
18020 return
18021 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
18022 end if;
18023 end Is_Volatile_Function;
18025 ------------------------
18026 -- Is_Volatile_Object --
18027 ------------------------
18029 function Is_Volatile_Object (N : Node_Id) return Boolean is
18030 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
18031 -- If prefix is an implicit dereference, examine designated type
18033 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
18034 -- Determines if given object has volatile components
18036 ------------------------
18037 -- Is_Volatile_Prefix --
18038 ------------------------
18040 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
18041 Typ : constant Entity_Id := Etype (N);
18043 begin
18044 if Is_Access_Type (Typ) then
18045 declare
18046 Dtyp : constant Entity_Id := Designated_Type (Typ);
18048 begin
18049 return Is_Volatile (Dtyp)
18050 or else Has_Volatile_Components (Dtyp);
18051 end;
18053 else
18054 return Object_Has_Volatile_Components (N);
18055 end if;
18056 end Is_Volatile_Prefix;
18058 ------------------------------------
18059 -- Object_Has_Volatile_Components --
18060 ------------------------------------
18062 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
18063 Typ : constant Entity_Id := Etype (N);
18065 begin
18066 if Is_Volatile (Typ)
18067 or else Has_Volatile_Components (Typ)
18068 then
18069 return True;
18071 elsif Is_Entity_Name (N)
18072 and then (Has_Volatile_Components (Entity (N))
18073 or else Is_Volatile (Entity (N)))
18074 then
18075 return True;
18077 elsif Nkind (N) = N_Indexed_Component
18078 or else Nkind (N) = N_Selected_Component
18079 then
18080 return Is_Volatile_Prefix (Prefix (N));
18082 else
18083 return False;
18084 end if;
18085 end Object_Has_Volatile_Components;
18087 -- Start of processing for Is_Volatile_Object
18089 begin
18090 if Nkind (N) = N_Defining_Identifier then
18091 return Is_Volatile (N) or else Is_Volatile (Etype (N));
18093 elsif Nkind (N) = N_Expanded_Name then
18094 return Is_Volatile_Object (Entity (N));
18096 elsif Is_Volatile (Etype (N))
18097 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
18098 then
18099 return True;
18101 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
18102 and then Is_Volatile_Prefix (Prefix (N))
18103 then
18104 return True;
18106 elsif Nkind (N) = N_Selected_Component
18107 and then Is_Volatile (Entity (Selector_Name (N)))
18108 then
18109 return True;
18111 else
18112 return False;
18113 end if;
18114 end Is_Volatile_Object;
18116 -----------------------------
18117 -- Iterate_Call_Parameters --
18118 -----------------------------
18120 procedure Iterate_Call_Parameters (Call : Node_Id) is
18121 Actual : Node_Id := First_Actual (Call);
18122 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
18124 begin
18125 while Present (Formal) and then Present (Actual) loop
18126 Handle_Parameter (Formal, Actual);
18128 Next_Formal (Formal);
18129 Next_Actual (Actual);
18130 end loop;
18132 pragma Assert (No (Formal));
18133 pragma Assert (No (Actual));
18134 end Iterate_Call_Parameters;
18136 ---------------------------
18137 -- Itype_Has_Declaration --
18138 ---------------------------
18140 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
18141 begin
18142 pragma Assert (Is_Itype (Id));
18143 return Present (Parent (Id))
18144 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
18145 N_Subtype_Declaration)
18146 and then Defining_Entity (Parent (Id)) = Id;
18147 end Itype_Has_Declaration;
18149 -------------------------
18150 -- Kill_Current_Values --
18151 -------------------------
18153 procedure Kill_Current_Values
18154 (Ent : Entity_Id;
18155 Last_Assignment_Only : Boolean := False)
18157 begin
18158 if Is_Assignable (Ent) then
18159 Set_Last_Assignment (Ent, Empty);
18160 end if;
18162 if Is_Object (Ent) then
18163 if not Last_Assignment_Only then
18164 Kill_Checks (Ent);
18165 Set_Current_Value (Ent, Empty);
18167 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18168 -- for a constant. Once the constant is elaborated, its value is
18169 -- not changed, therefore the associated flags that describe the
18170 -- value should not be modified either.
18172 if Ekind (Ent) = E_Constant then
18173 null;
18175 -- Non-constant entities
18177 else
18178 if not Can_Never_Be_Null (Ent) then
18179 Set_Is_Known_Non_Null (Ent, False);
18180 end if;
18182 Set_Is_Known_Null (Ent, False);
18184 -- Reset the Is_Known_Valid flag unless the type is always
18185 -- valid. This does not apply to a loop parameter because its
18186 -- bounds are defined by the loop header and therefore always
18187 -- valid.
18189 if not Is_Known_Valid (Etype (Ent))
18190 and then Ekind (Ent) /= E_Loop_Parameter
18191 then
18192 Set_Is_Known_Valid (Ent, False);
18193 end if;
18194 end if;
18195 end if;
18196 end if;
18197 end Kill_Current_Values;
18199 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
18200 S : Entity_Id;
18202 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
18203 -- Clear current value for entity E and all entities chained to E
18205 ------------------------------------------
18206 -- Kill_Current_Values_For_Entity_Chain --
18207 ------------------------------------------
18209 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
18210 Ent : Entity_Id;
18211 begin
18212 Ent := E;
18213 while Present (Ent) loop
18214 Kill_Current_Values (Ent, Last_Assignment_Only);
18215 Next_Entity (Ent);
18216 end loop;
18217 end Kill_Current_Values_For_Entity_Chain;
18219 -- Start of processing for Kill_Current_Values
18221 begin
18222 -- Kill all saved checks, a special case of killing saved values
18224 if not Last_Assignment_Only then
18225 Kill_All_Checks;
18226 end if;
18228 -- Loop through relevant scopes, which includes the current scope and
18229 -- any parent scopes if the current scope is a block or a package.
18231 S := Current_Scope;
18232 Scope_Loop : loop
18234 -- Clear current values of all entities in current scope
18236 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18238 -- If scope is a package, also clear current values of all private
18239 -- entities in the scope.
18241 if Is_Package_Or_Generic_Package (S)
18242 or else Is_Concurrent_Type (S)
18243 then
18244 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18245 end if;
18247 -- If this is a not a subprogram, deal with parents
18249 if not Is_Subprogram (S) then
18250 S := Scope (S);
18251 exit Scope_Loop when S = Standard_Standard;
18252 else
18253 exit Scope_Loop;
18254 end if;
18255 end loop Scope_Loop;
18256 end Kill_Current_Values;
18258 --------------------------
18259 -- Kill_Size_Check_Code --
18260 --------------------------
18262 procedure Kill_Size_Check_Code (E : Entity_Id) is
18263 begin
18264 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18265 and then Present (Size_Check_Code (E))
18266 then
18267 Remove (Size_Check_Code (E));
18268 Set_Size_Check_Code (E, Empty);
18269 end if;
18270 end Kill_Size_Check_Code;
18272 --------------------
18273 -- Known_Non_Null --
18274 --------------------
18276 function Known_Non_Null (N : Node_Id) return Boolean is
18277 Status : constant Null_Status_Kind := Null_Status (N);
18279 Id : Entity_Id;
18280 Op : Node_Kind;
18281 Val : Node_Id;
18283 begin
18284 -- The expression yields a non-null value ignoring simple flow analysis
18286 if Status = Is_Non_Null then
18287 return True;
18289 -- Otherwise check whether N is a reference to an entity that appears
18290 -- within a conditional construct.
18292 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18294 -- First check if we are in decisive conditional
18296 Get_Current_Value_Condition (N, Op, Val);
18298 if Known_Null (Val) then
18299 if Op = N_Op_Eq then
18300 return False;
18301 elsif Op = N_Op_Ne then
18302 return True;
18303 end if;
18304 end if;
18306 -- If OK to do replacement, test Is_Known_Non_Null flag
18308 Id := Entity (N);
18310 if OK_To_Do_Constant_Replacement (Id) then
18311 return Is_Known_Non_Null (Id);
18312 end if;
18313 end if;
18315 -- Otherwise it is not possible to determine whether N yields a non-null
18316 -- value.
18318 return False;
18319 end Known_Non_Null;
18321 ----------------
18322 -- Known_Null --
18323 ----------------
18325 function Known_Null (N : Node_Id) return Boolean is
18326 Status : constant Null_Status_Kind := Null_Status (N);
18328 Id : Entity_Id;
18329 Op : Node_Kind;
18330 Val : Node_Id;
18332 begin
18333 -- The expression yields a null value ignoring simple flow analysis
18335 if Status = Is_Null then
18336 return True;
18338 -- Otherwise check whether N is a reference to an entity that appears
18339 -- within a conditional construct.
18341 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18343 -- First check if we are in decisive conditional
18345 Get_Current_Value_Condition (N, Op, Val);
18347 if Known_Null (Val) then
18348 if Op = N_Op_Eq then
18349 return True;
18350 elsif Op = N_Op_Ne then
18351 return False;
18352 end if;
18353 end if;
18355 -- If OK to do replacement, test Is_Known_Null flag
18357 Id := Entity (N);
18359 if OK_To_Do_Constant_Replacement (Id) then
18360 return Is_Known_Null (Id);
18361 end if;
18362 end if;
18364 -- Otherwise it is not possible to determine whether N yields a null
18365 -- value.
18367 return False;
18368 end Known_Null;
18370 --------------------------
18371 -- Known_To_Be_Assigned --
18372 --------------------------
18374 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18375 P : constant Node_Id := Parent (N);
18377 begin
18378 case Nkind (P) is
18380 -- Test left side of assignment
18382 when N_Assignment_Statement =>
18383 return N = Name (P);
18385 -- Function call arguments are never lvalues
18387 when N_Function_Call =>
18388 return False;
18390 -- Positional parameter for procedure or accept call
18392 when N_Accept_Statement
18393 | N_Procedure_Call_Statement
18395 declare
18396 Proc : Entity_Id;
18397 Form : Entity_Id;
18398 Act : Node_Id;
18400 begin
18401 Proc := Get_Subprogram_Entity (P);
18403 if No (Proc) then
18404 return False;
18405 end if;
18407 -- If we are not a list member, something is strange, so
18408 -- be conservative and return False.
18410 if not Is_List_Member (N) then
18411 return False;
18412 end if;
18414 -- We are going to find the right formal by stepping forward
18415 -- through the formals, as we step backwards in the actuals.
18417 Form := First_Formal (Proc);
18418 Act := N;
18419 loop
18420 -- If no formal, something is weird, so be conservative
18421 -- and return False.
18423 if No (Form) then
18424 return False;
18425 end if;
18427 Prev (Act);
18428 exit when No (Act);
18429 Next_Formal (Form);
18430 end loop;
18432 return Ekind (Form) /= E_In_Parameter;
18433 end;
18435 -- Named parameter for procedure or accept call
18437 when N_Parameter_Association =>
18438 declare
18439 Proc : Entity_Id;
18440 Form : Entity_Id;
18442 begin
18443 Proc := Get_Subprogram_Entity (Parent (P));
18445 if No (Proc) then
18446 return False;
18447 end if;
18449 -- Loop through formals to find the one that matches
18451 Form := First_Formal (Proc);
18452 loop
18453 -- If no matching formal, that's peculiar, some kind of
18454 -- previous error, so return False to be conservative.
18455 -- Actually this also happens in legal code in the case
18456 -- where P is a parameter association for an Extra_Formal???
18458 if No (Form) then
18459 return False;
18460 end if;
18462 -- Else test for match
18464 if Chars (Form) = Chars (Selector_Name (P)) then
18465 return Ekind (Form) /= E_In_Parameter;
18466 end if;
18468 Next_Formal (Form);
18469 end loop;
18470 end;
18472 -- Test for appearing in a conversion that itself appears
18473 -- in an lvalue context, since this should be an lvalue.
18475 when N_Type_Conversion =>
18476 return Known_To_Be_Assigned (P);
18478 -- All other references are definitely not known to be modifications
18480 when others =>
18481 return False;
18482 end case;
18483 end Known_To_Be_Assigned;
18485 ---------------------------
18486 -- Last_Source_Statement --
18487 ---------------------------
18489 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
18490 N : Node_Id;
18492 begin
18493 N := Last (Statements (HSS));
18494 while Present (N) loop
18495 exit when Comes_From_Source (N);
18496 Prev (N);
18497 end loop;
18499 return N;
18500 end Last_Source_Statement;
18502 -----------------------
18503 -- Mark_Coextensions --
18504 -----------------------
18506 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
18507 Is_Dynamic : Boolean;
18508 -- Indicates whether the context causes nested coextensions to be
18509 -- dynamic or static
18511 function Mark_Allocator (N : Node_Id) return Traverse_Result;
18512 -- Recognize an allocator node and label it as a dynamic coextension
18514 --------------------
18515 -- Mark_Allocator --
18516 --------------------
18518 function Mark_Allocator (N : Node_Id) return Traverse_Result is
18519 begin
18520 if Nkind (N) = N_Allocator then
18521 if Is_Dynamic then
18522 Set_Is_Static_Coextension (N, False);
18523 Set_Is_Dynamic_Coextension (N);
18525 -- If the allocator expression is potentially dynamic, it may
18526 -- be expanded out of order and require dynamic allocation
18527 -- anyway, so we treat the coextension itself as dynamic.
18528 -- Potential optimization ???
18530 elsif Nkind (Expression (N)) = N_Qualified_Expression
18531 and then Nkind (Expression (Expression (N))) = N_Op_Concat
18532 then
18533 Set_Is_Static_Coextension (N, False);
18534 Set_Is_Dynamic_Coextension (N);
18535 else
18536 Set_Is_Dynamic_Coextension (N, False);
18537 Set_Is_Static_Coextension (N);
18538 end if;
18539 end if;
18541 return OK;
18542 end Mark_Allocator;
18544 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
18546 -- Start of processing for Mark_Coextensions
18548 begin
18549 -- An allocator that appears on the right-hand side of an assignment is
18550 -- treated as a potentially dynamic coextension when the right-hand side
18551 -- is an allocator or a qualified expression.
18553 -- Obj := new ...'(new Coextension ...);
18555 if Nkind (Context_Nod) = N_Assignment_Statement then
18556 Is_Dynamic :=
18557 Nkind_In (Expression (Context_Nod), N_Allocator,
18558 N_Qualified_Expression);
18560 -- An allocator that appears within the expression of a simple return
18561 -- statement is treated as a potentially dynamic coextension when the
18562 -- expression is either aggregate, allocator, or qualified expression.
18564 -- return (new Coextension ...);
18565 -- return new ...'(new Coextension ...);
18567 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
18568 Is_Dynamic :=
18569 Nkind_In (Expression (Context_Nod), N_Aggregate,
18570 N_Allocator,
18571 N_Qualified_Expression);
18573 -- An alloctor that appears within the initialization expression of an
18574 -- object declaration is considered a potentially dynamic coextension
18575 -- when the initialization expression is an allocator or a qualified
18576 -- expression.
18578 -- Obj : ... := new ...'(new Coextension ...);
18580 -- A similar case arises when the object declaration is part of an
18581 -- extended return statement.
18583 -- return Obj : ... := new ...'(new Coextension ...);
18584 -- return Obj : ... := (new Coextension ...);
18586 elsif Nkind (Context_Nod) = N_Object_Declaration then
18587 Is_Dynamic :=
18588 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
18589 or else
18590 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
18592 -- This routine should not be called with constructs that cannot contain
18593 -- coextensions.
18595 else
18596 raise Program_Error;
18597 end if;
18599 Mark_Allocators (Root_Nod);
18600 end Mark_Coextensions;
18602 ---------------------------------
18603 -- Mark_Elaboration_Attributes --
18604 ---------------------------------
18606 procedure Mark_Elaboration_Attributes
18607 (N_Id : Node_Or_Entity_Id;
18608 Checks : Boolean := False;
18609 Level : Boolean := False;
18610 Modes : Boolean := False;
18611 Warnings : Boolean := False)
18613 function Elaboration_Checks_OK
18614 (Target_Id : Entity_Id;
18615 Context_Id : Entity_Id) return Boolean;
18616 -- Determine whether elaboration checks are enabled for target Target_Id
18617 -- which resides within context Context_Id.
18619 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
18620 -- Preserve relevant attributes of the context in arbitrary entity Id
18622 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
18623 -- Preserve relevant attributes of the context in arbitrary node N
18625 ---------------------------
18626 -- Elaboration_Checks_OK --
18627 ---------------------------
18629 function Elaboration_Checks_OK
18630 (Target_Id : Entity_Id;
18631 Context_Id : Entity_Id) return Boolean
18633 Encl_Scop : Entity_Id;
18635 begin
18636 -- Elaboration checks are suppressed for the target
18638 if Elaboration_Checks_Suppressed (Target_Id) then
18639 return False;
18640 end if;
18642 -- Otherwise elaboration checks are OK for the target, but may be
18643 -- suppressed for the context where the target is declared.
18645 Encl_Scop := Context_Id;
18646 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
18647 if Elaboration_Checks_Suppressed (Encl_Scop) then
18648 return False;
18649 end if;
18651 Encl_Scop := Scope (Encl_Scop);
18652 end loop;
18654 -- Neither the target nor its declarative context have elaboration
18655 -- checks suppressed.
18657 return True;
18658 end Elaboration_Checks_OK;
18660 ------------------------------------
18661 -- Mark_Elaboration_Attributes_Id --
18662 ------------------------------------
18664 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
18665 begin
18666 -- Mark the status of elaboration checks in effect. Do not reset the
18667 -- status in case the entity is reanalyzed with checks suppressed.
18669 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
18670 Set_Is_Elaboration_Checks_OK_Id (Id,
18671 Elaboration_Checks_OK
18672 (Target_Id => Id,
18673 Context_Id => Scope (Id)));
18674 end if;
18676 -- Mark the status of elaboration warnings in effect. Do not reset
18677 -- the status in case the entity is reanalyzed with warnings off.
18679 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
18680 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
18681 end if;
18682 end Mark_Elaboration_Attributes_Id;
18684 --------------------------------------
18685 -- Mark_Elaboration_Attributes_Node --
18686 --------------------------------------
18688 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
18689 function Extract_Name (N : Node_Id) return Node_Id;
18690 -- Obtain the Name attribute of call or instantiation N
18692 ------------------
18693 -- Extract_Name --
18694 ------------------
18696 function Extract_Name (N : Node_Id) return Node_Id is
18697 Nam : Node_Id;
18699 begin
18700 Nam := Name (N);
18702 -- A call to an entry family appears in indexed form
18704 if Nkind (Nam) = N_Indexed_Component then
18705 Nam := Prefix (Nam);
18706 end if;
18708 -- The name may also appear in qualified form
18710 if Nkind (Nam) = N_Selected_Component then
18711 Nam := Selector_Name (Nam);
18712 end if;
18714 return Nam;
18715 end Extract_Name;
18717 -- Local variables
18719 Context_Id : Entity_Id;
18720 Nam : Node_Id;
18722 -- Start of processing for Mark_Elaboration_Attributes_Node
18724 begin
18725 -- Mark the status of elaboration checks in effect. Do not reset the
18726 -- status in case the node is reanalyzed with checks suppressed.
18728 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
18730 -- Assignments, attribute references, and variable references do
18731 -- not have a "declarative" context.
18733 Context_Id := Empty;
18735 -- The status of elaboration checks for calls and instantiations
18736 -- depends on the most recent pragma Suppress/Unsuppress, as well
18737 -- as the suppression status of the context where the target is
18738 -- defined.
18740 -- package Pack is
18741 -- function Func ...;
18742 -- end Pack;
18744 -- with Pack;
18745 -- procedure Main is
18746 -- pragma Suppress (Elaboration_Checks, Pack);
18747 -- X : ... := Pack.Func;
18748 -- ...
18750 -- In the example above, the call to Func has elaboration checks
18751 -- enabled because there is no active general purpose suppression
18752 -- pragma, however the elaboration checks of Pack are explicitly
18753 -- suppressed. As a result the elaboration checks of the call must
18754 -- be disabled in order to preserve this dependency.
18756 if Nkind_In (N, N_Entry_Call_Statement,
18757 N_Function_Call,
18758 N_Function_Instantiation,
18759 N_Package_Instantiation,
18760 N_Procedure_Call_Statement,
18761 N_Procedure_Instantiation)
18762 then
18763 Nam := Extract_Name (N);
18765 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
18766 Context_Id := Scope (Entity (Nam));
18767 end if;
18768 end if;
18770 Set_Is_Elaboration_Checks_OK_Node (N,
18771 Elaboration_Checks_OK
18772 (Target_Id => Empty,
18773 Context_Id => Context_Id));
18774 end if;
18776 -- Mark the enclosing level of the node. Do not reset the status in
18777 -- case the node is relocated and reanalyzed.
18779 if Level and then not Is_Declaration_Level_Node (N) then
18780 Set_Is_Declaration_Level_Node (N,
18781 Find_Enclosing_Level (N) = Declaration_Level);
18782 end if;
18784 -- Mark the Ghost and SPARK mode in effect
18786 if Modes then
18787 if Ghost_Mode = Ignore then
18788 Set_Is_Ignored_Ghost_Node (N);
18789 end if;
18791 if SPARK_Mode = On then
18792 Set_Is_SPARK_Mode_On_Node (N);
18793 end if;
18794 end if;
18796 -- Mark the status of elaboration warnings in effect. Do not reset
18797 -- the status in case the node is reanalyzed with warnings off.
18799 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
18800 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
18801 end if;
18802 end Mark_Elaboration_Attributes_Node;
18804 -- Start of processing for Mark_Elaboration_Attributes
18806 begin
18807 -- Do not capture any elaboration-related attributes when switch -gnatH
18808 -- (legacy elaboration checking mode enabled) is in effect because the
18809 -- attributes are useless to the legacy model.
18811 if Legacy_Elaboration_Checks then
18812 return;
18813 end if;
18815 if Nkind (N_Id) in N_Entity then
18816 Mark_Elaboration_Attributes_Id (N_Id);
18817 else
18818 Mark_Elaboration_Attributes_Node (N_Id);
18819 end if;
18820 end Mark_Elaboration_Attributes;
18822 ----------------------------------
18823 -- Matching_Static_Array_Bounds --
18824 ----------------------------------
18826 function Matching_Static_Array_Bounds
18827 (L_Typ : Node_Id;
18828 R_Typ : Node_Id) return Boolean
18830 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
18831 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
18833 L_Index : Node_Id := Empty; -- init to ...
18834 R_Index : Node_Id := Empty; -- ...avoid warnings
18835 L_Low : Node_Id;
18836 L_High : Node_Id;
18837 L_Len : Uint;
18838 R_Low : Node_Id;
18839 R_High : Node_Id;
18840 R_Len : Uint;
18842 begin
18843 if L_Ndims /= R_Ndims then
18844 return False;
18845 end if;
18847 -- Unconstrained types do not have static bounds
18849 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
18850 return False;
18851 end if;
18853 -- First treat specially the first dimension, as the lower bound and
18854 -- length of string literals are not stored like those of arrays.
18856 if Ekind (L_Typ) = E_String_Literal_Subtype then
18857 L_Low := String_Literal_Low_Bound (L_Typ);
18858 L_Len := String_Literal_Length (L_Typ);
18859 else
18860 L_Index := First_Index (L_Typ);
18861 Get_Index_Bounds (L_Index, L_Low, L_High);
18863 if Is_OK_Static_Expression (L_Low)
18864 and then
18865 Is_OK_Static_Expression (L_High)
18866 then
18867 if Expr_Value (L_High) < Expr_Value (L_Low) then
18868 L_Len := Uint_0;
18869 else
18870 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
18871 end if;
18872 else
18873 return False;
18874 end if;
18875 end if;
18877 if Ekind (R_Typ) = E_String_Literal_Subtype then
18878 R_Low := String_Literal_Low_Bound (R_Typ);
18879 R_Len := String_Literal_Length (R_Typ);
18880 else
18881 R_Index := First_Index (R_Typ);
18882 Get_Index_Bounds (R_Index, R_Low, R_High);
18884 if Is_OK_Static_Expression (R_Low)
18885 and then
18886 Is_OK_Static_Expression (R_High)
18887 then
18888 if Expr_Value (R_High) < Expr_Value (R_Low) then
18889 R_Len := Uint_0;
18890 else
18891 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
18892 end if;
18893 else
18894 return False;
18895 end if;
18896 end if;
18898 if (Is_OK_Static_Expression (L_Low)
18899 and then
18900 Is_OK_Static_Expression (R_Low))
18901 and then Expr_Value (L_Low) = Expr_Value (R_Low)
18902 and then L_Len = R_Len
18903 then
18904 null;
18905 else
18906 return False;
18907 end if;
18909 -- Then treat all other dimensions
18911 for Indx in 2 .. L_Ndims loop
18912 Next (L_Index);
18913 Next (R_Index);
18915 Get_Index_Bounds (L_Index, L_Low, L_High);
18916 Get_Index_Bounds (R_Index, R_Low, R_High);
18918 if (Is_OK_Static_Expression (L_Low) and then
18919 Is_OK_Static_Expression (L_High) and then
18920 Is_OK_Static_Expression (R_Low) and then
18921 Is_OK_Static_Expression (R_High))
18922 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
18923 and then
18924 Expr_Value (L_High) = Expr_Value (R_High))
18925 then
18926 null;
18927 else
18928 return False;
18929 end if;
18930 end loop;
18932 -- If we fall through the loop, all indexes matched
18934 return True;
18935 end Matching_Static_Array_Bounds;
18937 -------------------
18938 -- May_Be_Lvalue --
18939 -------------------
18941 function May_Be_Lvalue (N : Node_Id) return Boolean is
18942 P : constant Node_Id := Parent (N);
18944 begin
18945 case Nkind (P) is
18947 -- Test left side of assignment
18949 when N_Assignment_Statement =>
18950 return N = Name (P);
18952 -- Test prefix of component or attribute. Note that the prefix of an
18953 -- explicit or implicit dereference cannot be an l-value. In the case
18954 -- of a 'Read attribute, the reference can be an actual in the
18955 -- argument list of the attribute.
18957 when N_Attribute_Reference =>
18958 return (N = Prefix (P)
18959 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
18960 or else
18961 Attribute_Name (P) = Name_Read;
18963 -- For an expanded name, the name is an lvalue if the expanded name
18964 -- is an lvalue, but the prefix is never an lvalue, since it is just
18965 -- the scope where the name is found.
18967 when N_Expanded_Name =>
18968 if N = Prefix (P) then
18969 return May_Be_Lvalue (P);
18970 else
18971 return False;
18972 end if;
18974 -- For a selected component A.B, A is certainly an lvalue if A.B is.
18975 -- B is a little interesting, if we have A.B := 3, there is some
18976 -- discussion as to whether B is an lvalue or not, we choose to say
18977 -- it is. Note however that A is not an lvalue if it is of an access
18978 -- type since this is an implicit dereference.
18980 when N_Selected_Component =>
18981 if N = Prefix (P)
18982 and then Present (Etype (N))
18983 and then Is_Access_Type (Etype (N))
18984 then
18985 return False;
18986 else
18987 return May_Be_Lvalue (P);
18988 end if;
18990 -- For an indexed component or slice, the index or slice bounds is
18991 -- never an lvalue. The prefix is an lvalue if the indexed component
18992 -- or slice is an lvalue, except if it is an access type, where we
18993 -- have an implicit dereference.
18995 when N_Indexed_Component
18996 | N_Slice
18998 if N /= Prefix (P)
18999 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
19000 then
19001 return False;
19002 else
19003 return May_Be_Lvalue (P);
19004 end if;
19006 -- Prefix of a reference is an lvalue if the reference is an lvalue
19008 when N_Reference =>
19009 return May_Be_Lvalue (P);
19011 -- Prefix of explicit dereference is never an lvalue
19013 when N_Explicit_Dereference =>
19014 return False;
19016 -- Positional parameter for subprogram, entry, or accept call.
19017 -- In older versions of Ada function call arguments are never
19018 -- lvalues. In Ada 2012 functions can have in-out parameters.
19020 when N_Accept_Statement
19021 | N_Entry_Call_Statement
19022 | N_Subprogram_Call
19024 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
19025 return False;
19026 end if;
19028 -- The following mechanism is clumsy and fragile. A single flag
19029 -- set in Resolve_Actuals would be preferable ???
19031 declare
19032 Proc : Entity_Id;
19033 Form : Entity_Id;
19034 Act : Node_Id;
19036 begin
19037 Proc := Get_Subprogram_Entity (P);
19039 if No (Proc) then
19040 return True;
19041 end if;
19043 -- If we are not a list member, something is strange, so be
19044 -- conservative and return True.
19046 if not Is_List_Member (N) then
19047 return True;
19048 end if;
19050 -- We are going to find the right formal by stepping forward
19051 -- through the formals, as we step backwards in the actuals.
19053 Form := First_Formal (Proc);
19054 Act := N;
19055 loop
19056 -- If no formal, something is weird, so be conservative and
19057 -- return True.
19059 if No (Form) then
19060 return True;
19061 end if;
19063 Prev (Act);
19064 exit when No (Act);
19065 Next_Formal (Form);
19066 end loop;
19068 return Ekind (Form) /= E_In_Parameter;
19069 end;
19071 -- Named parameter for procedure or accept call
19073 when N_Parameter_Association =>
19074 declare
19075 Proc : Entity_Id;
19076 Form : Entity_Id;
19078 begin
19079 Proc := Get_Subprogram_Entity (Parent (P));
19081 if No (Proc) then
19082 return True;
19083 end if;
19085 -- Loop through formals to find the one that matches
19087 Form := First_Formal (Proc);
19088 loop
19089 -- If no matching formal, that's peculiar, some kind of
19090 -- previous error, so return True to be conservative.
19091 -- Actually happens with legal code for an unresolved call
19092 -- where we may get the wrong homonym???
19094 if No (Form) then
19095 return True;
19096 end if;
19098 -- Else test for match
19100 if Chars (Form) = Chars (Selector_Name (P)) then
19101 return Ekind (Form) /= E_In_Parameter;
19102 end if;
19104 Next_Formal (Form);
19105 end loop;
19106 end;
19108 -- Test for appearing in a conversion that itself appears in an
19109 -- lvalue context, since this should be an lvalue.
19111 when N_Type_Conversion =>
19112 return May_Be_Lvalue (P);
19114 -- Test for appearance in object renaming declaration
19116 when N_Object_Renaming_Declaration =>
19117 return True;
19119 -- All other references are definitely not lvalues
19121 when others =>
19122 return False;
19123 end case;
19124 end May_Be_Lvalue;
19126 -----------------
19127 -- Might_Raise --
19128 -----------------
19130 function Might_Raise (N : Node_Id) return Boolean is
19131 Result : Boolean := False;
19133 function Process (N : Node_Id) return Traverse_Result;
19134 -- Set Result to True if we find something that could raise an exception
19136 -------------
19137 -- Process --
19138 -------------
19140 function Process (N : Node_Id) return Traverse_Result is
19141 begin
19142 if Nkind_In (N, N_Procedure_Call_Statement,
19143 N_Function_Call,
19144 N_Raise_Statement,
19145 N_Raise_Constraint_Error,
19146 N_Raise_Program_Error,
19147 N_Raise_Storage_Error)
19148 then
19149 Result := True;
19150 return Abandon;
19151 else
19152 return OK;
19153 end if;
19154 end Process;
19156 procedure Set_Result is new Traverse_Proc (Process);
19158 -- Start of processing for Might_Raise
19160 begin
19161 -- False if exceptions can't be propagated
19163 if No_Exception_Handlers_Set then
19164 return False;
19165 end if;
19167 -- If the checks handled by the back end are not disabled, we cannot
19168 -- ensure that no exception will be raised.
19170 if not Access_Checks_Suppressed (Empty)
19171 or else not Discriminant_Checks_Suppressed (Empty)
19172 or else not Range_Checks_Suppressed (Empty)
19173 or else not Index_Checks_Suppressed (Empty)
19174 or else Opt.Stack_Checking_Enabled
19175 then
19176 return True;
19177 end if;
19179 Set_Result (N);
19180 return Result;
19181 end Might_Raise;
19183 --------------------------------
19184 -- Nearest_Enclosing_Instance --
19185 --------------------------------
19187 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
19188 Inst : Entity_Id;
19190 begin
19191 Inst := Scope (E);
19192 while Present (Inst) and then Inst /= Standard_Standard loop
19193 if Is_Generic_Instance (Inst) then
19194 return Inst;
19195 end if;
19197 Inst := Scope (Inst);
19198 end loop;
19200 return Empty;
19201 end Nearest_Enclosing_Instance;
19203 ----------------------
19204 -- Needs_One_Actual --
19205 ----------------------
19207 function Needs_One_Actual (E : Entity_Id) return Boolean is
19208 Formal : Entity_Id;
19210 begin
19211 -- Ada 2005 or later, and formals present. The first formal must be
19212 -- of a type that supports prefix notation: a controlling argument,
19213 -- a class-wide type, or an access to such.
19215 if Ada_Version >= Ada_2005
19216 and then Present (First_Formal (E))
19217 and then No (Default_Value (First_Formal (E)))
19218 and then
19219 (Is_Controlling_Formal (First_Formal (E))
19220 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
19221 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
19222 then
19223 Formal := Next_Formal (First_Formal (E));
19224 while Present (Formal) loop
19225 if No (Default_Value (Formal)) then
19226 return False;
19227 end if;
19229 Next_Formal (Formal);
19230 end loop;
19232 return True;
19234 -- Ada 83/95 or no formals
19236 else
19237 return False;
19238 end if;
19239 end Needs_One_Actual;
19241 ---------------------------------
19242 -- Needs_Simple_Initialization --
19243 ---------------------------------
19245 function Needs_Simple_Initialization
19246 (Typ : Entity_Id;
19247 Consider_IS : Boolean := True) return Boolean
19249 Consider_IS_NS : constant Boolean :=
19250 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19252 begin
19253 -- Never need initialization if it is suppressed
19255 if Initialization_Suppressed (Typ) then
19256 return False;
19257 end if;
19259 -- Check for private type, in which case test applies to the underlying
19260 -- type of the private type.
19262 if Is_Private_Type (Typ) then
19263 declare
19264 RT : constant Entity_Id := Underlying_Type (Typ);
19265 begin
19266 if Present (RT) then
19267 return Needs_Simple_Initialization (RT);
19268 else
19269 return False;
19270 end if;
19271 end;
19273 -- Scalar type with Default_Value aspect requires initialization
19275 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
19276 return True;
19278 -- Cases needing simple initialization are access types, and, if pragma
19279 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19280 -- types.
19282 elsif Is_Access_Type (Typ)
19283 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
19284 then
19285 return True;
19287 -- If Initialize/Normalize_Scalars is in effect, string objects also
19288 -- need initialization, unless they are created in the course of
19289 -- expanding an aggregate (since in the latter case they will be
19290 -- filled with appropriate initializing values before they are used).
19292 elsif Consider_IS_NS
19293 and then Is_Standard_String_Type (Typ)
19294 and then
19295 (not Is_Itype (Typ)
19296 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
19297 then
19298 return True;
19300 else
19301 return False;
19302 end if;
19303 end Needs_Simple_Initialization;
19305 -------------------------------------
19306 -- Needs_Variable_Reference_Marker --
19307 -------------------------------------
19309 function Needs_Variable_Reference_Marker
19310 (N : Node_Id;
19311 Calls_OK : Boolean) return Boolean
19313 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
19314 -- Deteremine whether variable reference Ref appears within a suitable
19315 -- context that allows the creation of a marker.
19317 -----------------------------
19318 -- Within_Suitable_Context --
19319 -----------------------------
19321 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
19322 Par : Node_Id;
19324 begin
19325 Par := Ref;
19326 while Present (Par) loop
19328 -- The context is not suitable when the reference appears within
19329 -- the formal part of an instantiation which acts as compilation
19330 -- unit because there is no proper list for the insertion of the
19331 -- marker.
19333 if Nkind (Par) = N_Generic_Association
19334 and then Nkind (Parent (Par)) in N_Generic_Instantiation
19335 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
19336 then
19337 return False;
19339 -- The context is not suitable when the reference appears within
19340 -- a pragma. If the pragma has run-time semantics, the reference
19341 -- will be reconsidered once the pragma is expanded.
19343 elsif Nkind (Par) = N_Pragma then
19344 return False;
19346 -- The context is not suitable when the reference appears within a
19347 -- subprogram call, and the caller requests this behavior.
19349 elsif not Calls_OK
19350 and then Nkind_In (Par, N_Entry_Call_Statement,
19351 N_Function_Call,
19352 N_Procedure_Call_Statement)
19353 then
19354 return False;
19356 -- Prevent the search from going too far
19358 elsif Is_Body_Or_Package_Declaration (Par) then
19359 exit;
19360 end if;
19362 Par := Parent (Par);
19363 end loop;
19365 return True;
19366 end Within_Suitable_Context;
19368 -- Local variables
19370 Prag : Node_Id;
19371 Var_Id : Entity_Id;
19373 -- Start of processing for Needs_Variable_Reference_Marker
19375 begin
19376 -- No marker needs to be created when switch -gnatH (legacy elaboration
19377 -- checking mode enabled) is in effect because the legacy ABE mechanism
19378 -- does not use markers.
19380 if Legacy_Elaboration_Checks then
19381 return False;
19383 -- No marker needs to be created for ASIS because ABE diagnostics and
19384 -- checks are not performed in this mode.
19386 elsif ASIS_Mode then
19387 return False;
19389 -- No marker needs to be created when the reference is preanalyzed
19390 -- because the marker will be inserted in the wrong place.
19392 elsif Preanalysis_Active then
19393 return False;
19395 -- Only references warrant a marker
19397 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
19398 return False;
19400 -- Only source references warrant a marker
19402 elsif not Comes_From_Source (N) then
19403 return False;
19405 -- No marker needs to be created when the reference is erroneous, left
19406 -- in a bad state, or does not denote a variable.
19408 elsif not (Present (Entity (N))
19409 and then Ekind (Entity (N)) = E_Variable
19410 and then Entity (N) /= Any_Id)
19411 then
19412 return False;
19413 end if;
19415 Var_Id := Entity (N);
19416 Prag := SPARK_Pragma (Var_Id);
19418 -- Both the variable and reference must appear in SPARK_Mode On regions
19419 -- because this elaboration scenario falls under the SPARK rules.
19421 if not (Comes_From_Source (Var_Id)
19422 and then Present (Prag)
19423 and then Get_SPARK_Mode_From_Annotation (Prag) = On
19424 and then Is_SPARK_Mode_On_Node (N))
19425 then
19426 return False;
19428 -- No marker needs to be created when the reference does not appear
19429 -- within a suitable context (see body for details).
19431 -- Performance note: parent traversal
19433 elsif not Within_Suitable_Context (N) then
19434 return False;
19435 end if;
19437 -- At this point it is known that the variable reference will play a
19438 -- role in ABE diagnostics and requires a marker.
19440 return True;
19441 end Needs_Variable_Reference_Marker;
19443 ------------------------
19444 -- New_Copy_List_Tree --
19445 ------------------------
19447 function New_Copy_List_Tree (List : List_Id) return List_Id is
19448 NL : List_Id;
19449 E : Node_Id;
19451 begin
19452 if List = No_List then
19453 return No_List;
19455 else
19456 NL := New_List;
19457 E := First (List);
19459 while Present (E) loop
19460 Append (New_Copy_Tree (E), NL);
19461 E := Next (E);
19462 end loop;
19464 return NL;
19465 end if;
19466 end New_Copy_List_Tree;
19468 -------------------
19469 -- New_Copy_Tree --
19470 -------------------
19472 -- The following tables play a key role in replicating entities and Itypes.
19473 -- They are intentionally declared at the library level rather than within
19474 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19475 -- optimization saves up to 2% of the entire compilation time spent in the
19476 -- front end. Care should be taken to reset the tables on each new call to
19477 -- New_Copy_Tree.
19479 NCT_Table_Max : constant := 511;
19481 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
19483 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
19484 -- Obtain the hash value of node or entity Key
19486 --------------------
19487 -- NCT_Table_Hash --
19488 --------------------
19490 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
19491 begin
19492 return NCT_Table_Index (Key mod NCT_Table_Max);
19493 end NCT_Table_Hash;
19495 ----------------------
19496 -- NCT_New_Entities --
19497 ----------------------
19499 -- The following table maps old entities and Itypes to their corresponding
19500 -- new entities and Itypes.
19502 -- Aaa -> Xxx
19504 package NCT_New_Entities is new Simple_HTable (
19505 Header_Num => NCT_Table_Index,
19506 Element => Entity_Id,
19507 No_Element => Empty,
19508 Key => Entity_Id,
19509 Hash => NCT_Table_Hash,
19510 Equal => "=");
19512 ------------------------
19513 -- NCT_Pending_Itypes --
19514 ------------------------
19516 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19517 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19518 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19519 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19521 -- Ppp -> (Xxx, Yyy, Zzz)
19523 -- The set is expressed as an Elist
19525 package NCT_Pending_Itypes is new Simple_HTable (
19526 Header_Num => NCT_Table_Index,
19527 Element => Elist_Id,
19528 No_Element => No_Elist,
19529 Key => Node_Id,
19530 Hash => NCT_Table_Hash,
19531 Equal => "=");
19533 NCT_Tables_In_Use : Boolean := False;
19534 -- This flag keeps track of whether the two tables NCT_New_Entities and
19535 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19536 -- where certain operations are not performed if the tables are not in
19537 -- use. This saves up to 8% of the entire compilation time spent in the
19538 -- front end.
19540 -------------------
19541 -- New_Copy_Tree --
19542 -------------------
19544 function New_Copy_Tree
19545 (Source : Node_Id;
19546 Map : Elist_Id := No_Elist;
19547 New_Sloc : Source_Ptr := No_Location;
19548 New_Scope : Entity_Id := Empty;
19549 Scopes_In_EWA_OK : Boolean := False) return Node_Id
19551 -- This routine performs low-level tree manipulations and needs access
19552 -- to the internals of the tree.
19554 use Atree.Unchecked_Access;
19555 use Atree_Private_Part;
19557 EWA_Level : Nat := 0;
19558 -- This counter keeps track of how many N_Expression_With_Actions nodes
19559 -- are encountered during a depth-first traversal of the subtree. These
19560 -- nodes may define new entities in their Actions lists and thus require
19561 -- special processing.
19563 EWA_Inner_Scope_Level : Nat := 0;
19564 -- This counter keeps track of how many scoping constructs appear within
19565 -- an N_Expression_With_Actions node.
19567 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
19568 pragma Inline (Add_New_Entity);
19569 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19570 -- value New_Id. Old_Id is an entity which appears within the Actions
19571 -- list of an N_Expression_With_Actions node, or within an entity map.
19572 -- New_Id is the corresponding new entity generated during Phase 1.
19574 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
19575 pragma Inline (Add_New_Entity);
19576 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19577 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19578 -- an itype.
19580 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
19581 pragma Inline (Build_NCT_Tables);
19582 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19583 -- information supplied in entity map Entity_Map. The format of the
19584 -- entity map must be as follows:
19586 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19588 function Copy_Any_Node_With_Replacement
19589 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
19590 pragma Inline (Copy_Any_Node_With_Replacement);
19591 -- Replicate entity or node N by invoking one of the following routines:
19593 -- Copy_Node_With_Replacement
19594 -- Corresponding_Entity
19596 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
19597 -- Replicate the elements of entity list List
19599 function Copy_Field_With_Replacement
19600 (Field : Union_Id;
19601 Old_Par : Node_Id := Empty;
19602 New_Par : Node_Id := Empty;
19603 Semantic : Boolean := False) return Union_Id;
19604 -- Replicate field Field by invoking one of the following routines:
19606 -- Copy_Elist_With_Replacement
19607 -- Copy_List_With_Replacement
19608 -- Copy_Node_With_Replacement
19609 -- Corresponding_Entity
19611 -- If the field is not an entity list, entity, itype, syntactic list,
19612 -- or node, then the field is returned unchanged. The routine always
19613 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19614 -- the expected parent of a syntactic field. New_Par is the new parent
19615 -- associated with a replicated syntactic field. Flag Semantic should
19616 -- be set when the input is a semantic field.
19618 function Copy_List_With_Replacement (List : List_Id) return List_Id;
19619 -- Replicate the elements of syntactic list List
19621 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
19622 -- Replicate node N
19624 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
19625 pragma Inline (Corresponding_Entity);
19626 -- Return the corresponding new entity of Id generated during Phase 1.
19627 -- If there is no such entity, return Id.
19629 function In_Entity_Map
19630 (Id : Entity_Id;
19631 Entity_Map : Elist_Id) return Boolean;
19632 pragma Inline (In_Entity_Map);
19633 -- Determine whether entity Id is one of the old ids specified in entity
19634 -- map Entity_Map. The format of the entity map must be as follows:
19636 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19638 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
19639 pragma Inline (Update_CFS_Sloc);
19640 -- Update the Comes_From_Source and Sloc attributes of node or entity N
19642 procedure Update_First_Real_Statement
19643 (Old_HSS : Node_Id;
19644 New_HSS : Node_Id);
19645 pragma Inline (Update_First_Real_Statement);
19646 -- Update semantic attribute First_Real_Statement of handled sequence of
19647 -- statements New_HSS based on handled sequence of statements Old_HSS.
19649 procedure Update_Named_Associations
19650 (Old_Call : Node_Id;
19651 New_Call : Node_Id);
19652 pragma Inline (Update_Named_Associations);
19653 -- Update semantic chain First/Next_Named_Association of call New_call
19654 -- based on call Old_Call.
19656 procedure Update_New_Entities (Entity_Map : Elist_Id);
19657 pragma Inline (Update_New_Entities);
19658 -- Update the semantic attributes of all new entities generated during
19659 -- Phase 1 that do not appear in entity map Entity_Map. The format of
19660 -- the entity map must be as follows:
19662 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19664 procedure Update_Pending_Itypes
19665 (Old_Assoc : Node_Id;
19666 New_Assoc : Node_Id);
19667 pragma Inline (Update_Pending_Itypes);
19668 -- Update semantic attribute Associated_Node_For_Itype to refer to node
19669 -- New_Assoc for all itypes whose associated node is Old_Assoc.
19671 procedure Update_Semantic_Fields (Id : Entity_Id);
19672 pragma Inline (Update_Semantic_Fields);
19673 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
19674 -- or itype Id.
19676 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
19677 pragma Inline (Visit_Any_Node);
19678 -- Visit entity of node N by invoking one of the following routines:
19680 -- Visit_Entity
19681 -- Visit_Itype
19682 -- Visit_Node
19684 procedure Visit_Elist (List : Elist_Id);
19685 -- Visit the elements of entity list List
19687 procedure Visit_Entity (Id : Entity_Id);
19688 -- Visit entity Id. This action may create a new entity of Id and save
19689 -- it in table NCT_New_Entities.
19691 procedure Visit_Field
19692 (Field : Union_Id;
19693 Par_Nod : Node_Id := Empty;
19694 Semantic : Boolean := False);
19695 -- Visit field Field by invoking one of the following routines:
19697 -- Visit_Elist
19698 -- Visit_Entity
19699 -- Visit_Itype
19700 -- Visit_List
19701 -- Visit_Node
19703 -- If the field is not an entity list, entity, itype, syntactic list,
19704 -- or node, then the field is not visited. The routine always visits
19705 -- valid syntactic fields. Par_Nod is the expected parent of the
19706 -- syntactic field. Flag Semantic should be set when the input is a
19707 -- semantic field.
19709 procedure Visit_Itype (Itype : Entity_Id);
19710 -- Visit itype Itype. This action may create a new entity for Itype and
19711 -- save it in table NCT_New_Entities. In addition, the routine may map
19712 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
19714 procedure Visit_List (List : List_Id);
19715 -- Visit the elements of syntactic list List
19717 procedure Visit_Node (N : Node_Id);
19718 -- Visit node N
19720 procedure Visit_Semantic_Fields (Id : Entity_Id);
19721 pragma Inline (Visit_Semantic_Fields);
19722 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
19723 -- fields of entity or itype Id.
19725 --------------------
19726 -- Add_New_Entity --
19727 --------------------
19729 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
19730 begin
19731 pragma Assert (Present (Old_Id));
19732 pragma Assert (Present (New_Id));
19733 pragma Assert (Nkind (Old_Id) in N_Entity);
19734 pragma Assert (Nkind (New_Id) in N_Entity);
19736 NCT_Tables_In_Use := True;
19738 -- Sanity check the NCT_New_Entities table. No previous mapping with
19739 -- key Old_Id should exist.
19741 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
19743 -- Establish the mapping
19745 -- Old_Id -> New_Id
19747 NCT_New_Entities.Set (Old_Id, New_Id);
19748 end Add_New_Entity;
19750 -----------------------
19751 -- Add_Pending_Itype --
19752 -----------------------
19754 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
19755 Itypes : Elist_Id;
19757 begin
19758 pragma Assert (Present (Assoc_Nod));
19759 pragma Assert (Present (Itype));
19760 pragma Assert (Nkind (Itype) in N_Entity);
19761 pragma Assert (Is_Itype (Itype));
19763 NCT_Tables_In_Use := True;
19765 -- It is not possible to sanity check the NCT_Pendint_Itypes table
19766 -- directly because a single node may act as the associated node for
19767 -- multiple itypes.
19769 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
19771 if No (Itypes) then
19772 Itypes := New_Elmt_List;
19773 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
19774 end if;
19776 -- Establish the mapping
19778 -- Assoc_Nod -> (Itype, ...)
19780 -- Avoid inserting the same itype multiple times. This involves a
19781 -- linear search, however the set of itypes with the same associated
19782 -- node is very small.
19784 Append_Unique_Elmt (Itype, Itypes);
19785 end Add_Pending_Itype;
19787 ----------------------
19788 -- Build_NCT_Tables --
19789 ----------------------
19791 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
19792 Elmt : Elmt_Id;
19793 Old_Id : Entity_Id;
19794 New_Id : Entity_Id;
19796 begin
19797 -- Nothing to do when there is no entity map
19799 if No (Entity_Map) then
19800 return;
19801 end if;
19803 Elmt := First_Elmt (Entity_Map);
19804 while Present (Elmt) loop
19806 -- Extract the (Old_Id, New_Id) pair from the entity map
19808 Old_Id := Node (Elmt);
19809 Next_Elmt (Elmt);
19811 New_Id := Node (Elmt);
19812 Next_Elmt (Elmt);
19814 -- Establish the following mapping within table NCT_New_Entities
19816 -- Old_Id -> New_Id
19818 Add_New_Entity (Old_Id, New_Id);
19820 -- Establish the following mapping within table NCT_Pending_Itypes
19821 -- when the new entity is an itype.
19823 -- Assoc_Nod -> (New_Id, ...)
19825 -- IMPORTANT: the associated node is that of the old itype because
19826 -- the node will be replicated in Phase 2.
19828 if Is_Itype (Old_Id) then
19829 Add_Pending_Itype
19830 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
19831 Itype => New_Id);
19832 end if;
19833 end loop;
19834 end Build_NCT_Tables;
19836 ------------------------------------
19837 -- Copy_Any_Node_With_Replacement --
19838 ------------------------------------
19840 function Copy_Any_Node_With_Replacement
19841 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
19843 begin
19844 if Nkind (N) in N_Entity then
19845 return Corresponding_Entity (N);
19846 else
19847 return Copy_Node_With_Replacement (N);
19848 end if;
19849 end Copy_Any_Node_With_Replacement;
19851 ---------------------------------
19852 -- Copy_Elist_With_Replacement --
19853 ---------------------------------
19855 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
19856 Elmt : Elmt_Id;
19857 Result : Elist_Id;
19859 begin
19860 -- Copy the contents of the old list. Note that the list itself may
19861 -- be empty, in which case the routine returns a new empty list. This
19862 -- avoids sharing lists between subtrees. The element of an entity
19863 -- list could be an entity or a node, hence the invocation of routine
19864 -- Copy_Any_Node_With_Replacement.
19866 if Present (List) then
19867 Result := New_Elmt_List;
19869 Elmt := First_Elmt (List);
19870 while Present (Elmt) loop
19871 Append_Elmt
19872 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
19874 Next_Elmt (Elmt);
19875 end loop;
19877 -- Otherwise the list does not exist
19879 else
19880 Result := No_Elist;
19881 end if;
19883 return Result;
19884 end Copy_Elist_With_Replacement;
19886 ---------------------------------
19887 -- Copy_Field_With_Replacement --
19888 ---------------------------------
19890 function Copy_Field_With_Replacement
19891 (Field : Union_Id;
19892 Old_Par : Node_Id := Empty;
19893 New_Par : Node_Id := Empty;
19894 Semantic : Boolean := False) return Union_Id
19896 begin
19897 -- The field is empty
19899 if Field = Union_Id (Empty) then
19900 return Field;
19902 -- The field is an entity/itype/node
19904 elsif Field in Node_Range then
19905 declare
19906 Old_N : constant Node_Id := Node_Id (Field);
19907 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
19909 New_N : Node_Id;
19911 begin
19912 -- The field is an entity/itype
19914 if Nkind (Old_N) in N_Entity then
19916 -- An entity/itype is always replicated
19918 New_N := Corresponding_Entity (Old_N);
19920 -- Update the parent pointer when the entity is a syntactic
19921 -- field. Note that itypes do not have parent pointers.
19923 if Syntactic and then New_N /= Old_N then
19924 Set_Parent (New_N, New_Par);
19925 end if;
19927 -- The field is a node
19929 else
19930 -- A node is replicated when it is either a syntactic field
19931 -- or when the caller treats it as a semantic attribute.
19933 if Syntactic or else Semantic then
19934 New_N := Copy_Node_With_Replacement (Old_N);
19936 -- Update the parent pointer when the node is a syntactic
19937 -- field.
19939 if Syntactic and then New_N /= Old_N then
19940 Set_Parent (New_N, New_Par);
19941 end if;
19943 -- Otherwise the node is returned unchanged
19945 else
19946 New_N := Old_N;
19947 end if;
19948 end if;
19950 return Union_Id (New_N);
19951 end;
19953 -- The field is an entity list
19955 elsif Field in Elist_Range then
19956 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
19958 -- The field is a syntactic list
19960 elsif Field in List_Range then
19961 declare
19962 Old_List : constant List_Id := List_Id (Field);
19963 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
19965 New_List : List_Id;
19967 begin
19968 -- A list is replicated when it is either a syntactic field or
19969 -- when the caller treats it as a semantic attribute.
19971 if Syntactic or else Semantic then
19972 New_List := Copy_List_With_Replacement (Old_List);
19974 -- Update the parent pointer when the list is a syntactic
19975 -- field.
19977 if Syntactic and then New_List /= Old_List then
19978 Set_Parent (New_List, New_Par);
19979 end if;
19981 -- Otherwise the list is returned unchanged
19983 else
19984 New_List := Old_List;
19985 end if;
19987 return Union_Id (New_List);
19988 end;
19990 -- Otherwise the field denotes an attribute that does not need to be
19991 -- replicated (Chars, literals, etc).
19993 else
19994 return Field;
19995 end if;
19996 end Copy_Field_With_Replacement;
19998 --------------------------------
19999 -- Copy_List_With_Replacement --
20000 --------------------------------
20002 function Copy_List_With_Replacement (List : List_Id) return List_Id is
20003 Elmt : Node_Id;
20004 Result : List_Id;
20006 begin
20007 -- Copy the contents of the old list. Note that the list itself may
20008 -- be empty, in which case the routine returns a new empty list. This
20009 -- avoids sharing lists between subtrees. The element of a syntactic
20010 -- list is always a node, never an entity or itype, hence the call to
20011 -- routine Copy_Node_With_Replacement.
20013 if Present (List) then
20014 Result := New_List;
20016 Elmt := First (List);
20017 while Present (Elmt) loop
20018 Append (Copy_Node_With_Replacement (Elmt), Result);
20020 Next (Elmt);
20021 end loop;
20023 -- Otherwise the list does not exist
20025 else
20026 Result := No_List;
20027 end if;
20029 return Result;
20030 end Copy_List_With_Replacement;
20032 --------------------------------
20033 -- Copy_Node_With_Replacement --
20034 --------------------------------
20036 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
20037 Result : Node_Id;
20039 begin
20040 -- Assume that the node must be returned unchanged
20042 Result := N;
20044 if N > Empty_Or_Error then
20045 pragma Assert (Nkind (N) not in N_Entity);
20047 Result := New_Copy (N);
20049 Set_Field1 (Result,
20050 Copy_Field_With_Replacement
20051 (Field => Field1 (Result),
20052 Old_Par => N,
20053 New_Par => Result));
20055 Set_Field2 (Result,
20056 Copy_Field_With_Replacement
20057 (Field => Field2 (Result),
20058 Old_Par => N,
20059 New_Par => Result));
20061 Set_Field3 (Result,
20062 Copy_Field_With_Replacement
20063 (Field => Field3 (Result),
20064 Old_Par => N,
20065 New_Par => Result));
20067 Set_Field4 (Result,
20068 Copy_Field_With_Replacement
20069 (Field => Field4 (Result),
20070 Old_Par => N,
20071 New_Par => Result));
20073 Set_Field5 (Result,
20074 Copy_Field_With_Replacement
20075 (Field => Field5 (Result),
20076 Old_Par => N,
20077 New_Par => Result));
20079 -- Update the Comes_From_Source and Sloc attributes of the node
20080 -- in case the caller has supplied new values.
20082 Update_CFS_Sloc (Result);
20084 -- Update the Associated_Node_For_Itype attribute of all itypes
20085 -- created during Phase 1 whose associated node is N. As a result
20086 -- the Associated_Node_For_Itype refers to the replicated node.
20087 -- No action needs to be taken when the Associated_Node_For_Itype
20088 -- refers to an entity because this was already handled during
20089 -- Phase 1, in Visit_Itype.
20091 Update_Pending_Itypes
20092 (Old_Assoc => N,
20093 New_Assoc => Result);
20095 -- Update the First/Next_Named_Association chain for a replicated
20096 -- call.
20098 if Nkind_In (N, N_Entry_Call_Statement,
20099 N_Function_Call,
20100 N_Procedure_Call_Statement)
20101 then
20102 Update_Named_Associations
20103 (Old_Call => N,
20104 New_Call => Result);
20106 -- Update the Renamed_Object attribute of a replicated object
20107 -- declaration.
20109 elsif Nkind (N) = N_Object_Renaming_Declaration then
20110 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
20112 -- Update the First_Real_Statement attribute of a replicated
20113 -- handled sequence of statements.
20115 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
20116 Update_First_Real_Statement
20117 (Old_HSS => N,
20118 New_HSS => Result);
20119 end if;
20120 end if;
20122 return Result;
20123 end Copy_Node_With_Replacement;
20125 --------------------------
20126 -- Corresponding_Entity --
20127 --------------------------
20129 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
20130 New_Id : Entity_Id;
20131 Result : Entity_Id;
20133 begin
20134 -- Assume that the entity must be returned unchanged
20136 Result := Id;
20138 if Id > Empty_Or_Error then
20139 pragma Assert (Nkind (Id) in N_Entity);
20141 -- Determine whether the entity has a corresponding new entity
20142 -- generated during Phase 1 and if it does, use it.
20144 if NCT_Tables_In_Use then
20145 New_Id := NCT_New_Entities.Get (Id);
20147 if Present (New_Id) then
20148 Result := New_Id;
20149 end if;
20150 end if;
20151 end if;
20153 return Result;
20154 end Corresponding_Entity;
20156 -------------------
20157 -- In_Entity_Map --
20158 -------------------
20160 function In_Entity_Map
20161 (Id : Entity_Id;
20162 Entity_Map : Elist_Id) return Boolean
20164 Elmt : Elmt_Id;
20165 Old_Id : Entity_Id;
20167 begin
20168 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20169 -- step always skips the New_Id portion of the pair.
20171 if Present (Entity_Map) then
20172 Elmt := First_Elmt (Entity_Map);
20173 while Present (Elmt) loop
20174 Old_Id := Node (Elmt);
20176 if Old_Id = Id then
20177 return True;
20178 end if;
20180 Next_Elmt (Elmt);
20181 Next_Elmt (Elmt);
20182 end loop;
20183 end if;
20185 return False;
20186 end In_Entity_Map;
20188 ---------------------
20189 -- Update_CFS_Sloc --
20190 ---------------------
20192 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
20193 begin
20194 -- A new source location defaults the Comes_From_Source attribute
20196 if New_Sloc /= No_Location then
20197 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
20198 Set_Sloc (N, New_Sloc);
20199 end if;
20200 end Update_CFS_Sloc;
20202 ---------------------------------
20203 -- Update_First_Real_Statement --
20204 ---------------------------------
20206 procedure Update_First_Real_Statement
20207 (Old_HSS : Node_Id;
20208 New_HSS : Node_Id)
20210 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
20212 New_Stmt : Node_Id;
20213 Old_Stmt : Node_Id;
20215 begin
20216 -- Recreate the First_Real_Statement attribute of a handled sequence
20217 -- of statements by traversing the statement lists of both sequences
20218 -- in parallel.
20220 if Present (Old_First_Stmt) then
20221 New_Stmt := First (Statements (New_HSS));
20222 Old_Stmt := First (Statements (Old_HSS));
20223 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
20224 Next (New_Stmt);
20225 Next (Old_Stmt);
20226 end loop;
20228 pragma Assert (Present (New_Stmt));
20229 pragma Assert (Present (Old_Stmt));
20231 Set_First_Real_Statement (New_HSS, New_Stmt);
20232 end if;
20233 end Update_First_Real_Statement;
20235 -------------------------------
20236 -- Update_Named_Associations --
20237 -------------------------------
20239 procedure Update_Named_Associations
20240 (Old_Call : Node_Id;
20241 New_Call : Node_Id)
20243 New_Act : Node_Id;
20244 New_Next : Node_Id;
20245 Old_Act : Node_Id;
20246 Old_Next : Node_Id;
20248 begin
20249 -- Recreate the First/Next_Named_Actual chain of a call by traversing
20250 -- the chains of both the old and new calls in parallel.
20252 New_Act := First (Parameter_Associations (New_Call));
20253 Old_Act := First (Parameter_Associations (Old_Call));
20254 while Present (Old_Act) loop
20255 if Nkind (Old_Act) = N_Parameter_Association
20256 and then Present (Next_Named_Actual (Old_Act))
20257 then
20258 if First_Named_Actual (Old_Call) =
20259 Explicit_Actual_Parameter (Old_Act)
20260 then
20261 Set_First_Named_Actual (New_Call,
20262 Explicit_Actual_Parameter (New_Act));
20263 end if;
20265 -- Scan the actual parameter list to find the next suitable
20266 -- named actual. Note that the list may be out of order.
20268 New_Next := First (Parameter_Associations (New_Call));
20269 Old_Next := First (Parameter_Associations (Old_Call));
20270 while Nkind (Old_Next) /= N_Parameter_Association
20271 or else Explicit_Actual_Parameter (Old_Next) /=
20272 Next_Named_Actual (Old_Act)
20273 loop
20274 Next (New_Next);
20275 Next (Old_Next);
20276 end loop;
20278 Set_Next_Named_Actual (New_Act,
20279 Explicit_Actual_Parameter (New_Next));
20280 end if;
20282 Next (New_Act);
20283 Next (Old_Act);
20284 end loop;
20285 end Update_Named_Associations;
20287 -------------------------
20288 -- Update_New_Entities --
20289 -------------------------
20291 procedure Update_New_Entities (Entity_Map : Elist_Id) is
20292 New_Id : Entity_Id := Empty;
20293 Old_Id : Entity_Id := Empty;
20295 begin
20296 if NCT_Tables_In_Use then
20297 NCT_New_Entities.Get_First (Old_Id, New_Id);
20299 -- Update the semantic fields of all new entities created during
20300 -- Phase 1 which were not supplied via an entity map.
20301 -- ??? Is there a better way of distinguishing those?
20303 while Present (Old_Id) and then Present (New_Id) loop
20304 if not (Present (Entity_Map)
20305 and then In_Entity_Map (Old_Id, Entity_Map))
20306 then
20307 Update_Semantic_Fields (New_Id);
20308 end if;
20310 NCT_New_Entities.Get_Next (Old_Id, New_Id);
20311 end loop;
20312 end if;
20313 end Update_New_Entities;
20315 ---------------------------
20316 -- Update_Pending_Itypes --
20317 ---------------------------
20319 procedure Update_Pending_Itypes
20320 (Old_Assoc : Node_Id;
20321 New_Assoc : Node_Id)
20323 Item : Elmt_Id;
20324 Itypes : Elist_Id;
20326 begin
20327 if NCT_Tables_In_Use then
20328 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
20330 -- Update the Associated_Node_For_Itype attribute for all itypes
20331 -- which originally refer to Old_Assoc to designate New_Assoc.
20333 if Present (Itypes) then
20334 Item := First_Elmt (Itypes);
20335 while Present (Item) loop
20336 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
20338 Next_Elmt (Item);
20339 end loop;
20340 end if;
20341 end if;
20342 end Update_Pending_Itypes;
20344 ----------------------------
20345 -- Update_Semantic_Fields --
20346 ----------------------------
20348 procedure Update_Semantic_Fields (Id : Entity_Id) is
20349 begin
20350 -- Discriminant_Constraint
20352 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20353 Set_Discriminant_Constraint (Id, Elist_Id (
20354 Copy_Field_With_Replacement
20355 (Field => Union_Id (Discriminant_Constraint (Id)),
20356 Semantic => True)));
20357 end if;
20359 -- Etype
20361 Set_Etype (Id, Node_Id (
20362 Copy_Field_With_Replacement
20363 (Field => Union_Id (Etype (Id)),
20364 Semantic => True)));
20366 -- First_Index
20367 -- Packed_Array_Impl_Type
20369 if Is_Array_Type (Id) then
20370 if Present (First_Index (Id)) then
20371 Set_First_Index (Id, First (List_Id (
20372 Copy_Field_With_Replacement
20373 (Field => Union_Id (List_Containing (First_Index (Id))),
20374 Semantic => True))));
20375 end if;
20377 if Is_Packed (Id) then
20378 Set_Packed_Array_Impl_Type (Id, Node_Id (
20379 Copy_Field_With_Replacement
20380 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20381 Semantic => True)));
20382 end if;
20383 end if;
20385 -- Prev_Entity
20387 Set_Prev_Entity (Id, Node_Id (
20388 Copy_Field_With_Replacement
20389 (Field => Union_Id (Prev_Entity (Id)),
20390 Semantic => True)));
20392 -- Next_Entity
20394 Set_Next_Entity (Id, Node_Id (
20395 Copy_Field_With_Replacement
20396 (Field => Union_Id (Next_Entity (Id)),
20397 Semantic => True)));
20399 -- Scalar_Range
20401 if Is_Discrete_Type (Id) then
20402 Set_Scalar_Range (Id, Node_Id (
20403 Copy_Field_With_Replacement
20404 (Field => Union_Id (Scalar_Range (Id)),
20405 Semantic => True)));
20406 end if;
20408 -- Scope
20410 -- Update the scope when the caller specified an explicit one
20412 if Present (New_Scope) then
20413 Set_Scope (Id, New_Scope);
20414 else
20415 Set_Scope (Id, Node_Id (
20416 Copy_Field_With_Replacement
20417 (Field => Union_Id (Scope (Id)),
20418 Semantic => True)));
20419 end if;
20420 end Update_Semantic_Fields;
20422 --------------------
20423 -- Visit_Any_Node --
20424 --------------------
20426 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
20427 begin
20428 if Nkind (N) in N_Entity then
20429 if Is_Itype (N) then
20430 Visit_Itype (N);
20431 else
20432 Visit_Entity (N);
20433 end if;
20434 else
20435 Visit_Node (N);
20436 end if;
20437 end Visit_Any_Node;
20439 -----------------
20440 -- Visit_Elist --
20441 -----------------
20443 procedure Visit_Elist (List : Elist_Id) is
20444 Elmt : Elmt_Id;
20446 begin
20447 -- The element of an entity list could be an entity, itype, or a
20448 -- node, hence the call to Visit_Any_Node.
20450 if Present (List) then
20451 Elmt := First_Elmt (List);
20452 while Present (Elmt) loop
20453 Visit_Any_Node (Node (Elmt));
20455 Next_Elmt (Elmt);
20456 end loop;
20457 end if;
20458 end Visit_Elist;
20460 ------------------
20461 -- Visit_Entity --
20462 ------------------
20464 procedure Visit_Entity (Id : Entity_Id) is
20465 New_Id : Entity_Id;
20467 begin
20468 pragma Assert (Nkind (Id) in N_Entity);
20469 pragma Assert (not Is_Itype (Id));
20471 -- Nothing to do when the entity is not defined in the Actions list
20472 -- of an N_Expression_With_Actions node.
20474 if EWA_Level = 0 then
20475 return;
20477 -- Nothing to do when the entity is defined in a scoping construct
20478 -- within an N_Expression_With_Actions node, unless the caller has
20479 -- requested their replication.
20481 -- ??? should this restriction be eliminated?
20483 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
20484 return;
20486 -- Nothing to do when the entity does not denote a construct that
20487 -- may appear within an N_Expression_With_Actions node. Relaxing
20488 -- this restriction leads to a performance penalty.
20490 -- ??? this list is flaky, and may hide dormant bugs
20492 elsif not Ekind_In (Id, E_Block,
20493 E_Constant,
20494 E_Label,
20495 E_Procedure,
20496 E_Variable)
20497 and then not Is_Type (Id)
20498 then
20499 return;
20501 -- Nothing to do when the entity was already visited
20503 elsif NCT_Tables_In_Use
20504 and then Present (NCT_New_Entities.Get (Id))
20505 then
20506 return;
20508 -- Nothing to do when the declaration node of the entity is not in
20509 -- the subtree being replicated.
20511 elsif not In_Subtree
20512 (N => Declaration_Node (Id),
20513 Root => Source)
20514 then
20515 return;
20516 end if;
20518 -- Create a new entity by directly copying the old entity. This
20519 -- action causes all attributes of the old entity to be inherited.
20521 New_Id := New_Copy (Id);
20523 -- Create a new name for the new entity because the back end needs
20524 -- distinct names for debugging purposes.
20526 Set_Chars (New_Id, New_Internal_Name ('T'));
20528 -- Update the Comes_From_Source and Sloc attributes of the entity in
20529 -- case the caller has supplied new values.
20531 Update_CFS_Sloc (New_Id);
20533 -- Establish the following mapping within table NCT_New_Entities:
20535 -- Id -> New_Id
20537 Add_New_Entity (Id, New_Id);
20539 -- Deal with the semantic fields of entities. The fields are visited
20540 -- because they may mention entities which reside within the subtree
20541 -- being copied.
20543 Visit_Semantic_Fields (Id);
20544 end Visit_Entity;
20546 -----------------
20547 -- Visit_Field --
20548 -----------------
20550 procedure Visit_Field
20551 (Field : Union_Id;
20552 Par_Nod : Node_Id := Empty;
20553 Semantic : Boolean := False)
20555 begin
20556 -- The field is empty
20558 if Field = Union_Id (Empty) then
20559 return;
20561 -- The field is an entity/itype/node
20563 elsif Field in Node_Range then
20564 declare
20565 N : constant Node_Id := Node_Id (Field);
20567 begin
20568 -- The field is an entity/itype
20570 if Nkind (N) in N_Entity then
20572 -- Itypes are always visited
20574 if Is_Itype (N) then
20575 Visit_Itype (N);
20577 -- An entity is visited when it is either a syntactic field
20578 -- or when the caller treats it as a semantic attribute.
20580 elsif Parent (N) = Par_Nod or else Semantic then
20581 Visit_Entity (N);
20582 end if;
20584 -- The field is a node
20586 else
20587 -- A node is visited when it is either a syntactic field or
20588 -- when the caller treats it as a semantic attribute.
20590 if Parent (N) = Par_Nod or else Semantic then
20591 Visit_Node (N);
20592 end if;
20593 end if;
20594 end;
20596 -- The field is an entity list
20598 elsif Field in Elist_Range then
20599 Visit_Elist (Elist_Id (Field));
20601 -- The field is a syntax list
20603 elsif Field in List_Range then
20604 declare
20605 List : constant List_Id := List_Id (Field);
20607 begin
20608 -- A syntax list is visited when it is either a syntactic field
20609 -- or when the caller treats it as a semantic attribute.
20611 if Parent (List) = Par_Nod or else Semantic then
20612 Visit_List (List);
20613 end if;
20614 end;
20616 -- Otherwise the field denotes information which does not need to be
20617 -- visited (chars, literals, etc.).
20619 else
20620 null;
20621 end if;
20622 end Visit_Field;
20624 -----------------
20625 -- Visit_Itype --
20626 -----------------
20628 procedure Visit_Itype (Itype : Entity_Id) is
20629 New_Assoc : Node_Id;
20630 New_Itype : Entity_Id;
20631 Old_Assoc : Node_Id;
20633 begin
20634 pragma Assert (Nkind (Itype) in N_Entity);
20635 pragma Assert (Is_Itype (Itype));
20637 -- Itypes that describe the designated type of access to subprograms
20638 -- have the structure of subprogram declarations, with signatures,
20639 -- etc. Either we duplicate the signatures completely, or choose to
20640 -- share such itypes, which is fine because their elaboration will
20641 -- have no side effects.
20643 if Ekind (Itype) = E_Subprogram_Type then
20644 return;
20646 -- Nothing to do if the itype was already visited
20648 elsif NCT_Tables_In_Use
20649 and then Present (NCT_New_Entities.Get (Itype))
20650 then
20651 return;
20653 -- Nothing to do if the associated node of the itype is not within
20654 -- the subtree being replicated.
20656 elsif not In_Subtree
20657 (N => Associated_Node_For_Itype (Itype),
20658 Root => Source)
20659 then
20660 return;
20661 end if;
20663 -- Create a new itype by directly copying the old itype. This action
20664 -- causes all attributes of the old itype to be inherited.
20666 New_Itype := New_Copy (Itype);
20668 -- Create a new name for the new itype because the back end requires
20669 -- distinct names for debugging purposes.
20671 Set_Chars (New_Itype, New_Internal_Name ('T'));
20673 -- Update the Comes_From_Source and Sloc attributes of the itype in
20674 -- case the caller has supplied new values.
20676 Update_CFS_Sloc (New_Itype);
20678 -- Establish the following mapping within table NCT_New_Entities:
20680 -- Itype -> New_Itype
20682 Add_New_Entity (Itype, New_Itype);
20684 -- The new itype must be unfrozen because the resulting subtree may
20685 -- be inserted anywhere and cause an earlier or later freezing.
20687 if Present (Freeze_Node (New_Itype)) then
20688 Set_Freeze_Node (New_Itype, Empty);
20689 Set_Is_Frozen (New_Itype, False);
20690 end if;
20692 -- If a record subtype is simply copied, the entity list will be
20693 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
20694 -- ??? What does this do?
20696 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
20697 Set_Cloned_Subtype (New_Itype, Itype);
20698 end if;
20700 -- The associated node may denote an entity, in which case it may
20701 -- already have a new corresponding entity created during a prior
20702 -- call to Visit_Entity or Visit_Itype for the same subtree.
20704 -- Given
20705 -- Old_Assoc ---------> New_Assoc
20707 -- Created by Visit_Itype
20708 -- Itype -------------> New_Itype
20709 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
20711 -- In the example above, Old_Assoc is an arbitrary entity that was
20712 -- already visited for the same subtree and has a corresponding new
20713 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
20714 -- of copying entities, however it must be updated to New_Assoc.
20716 Old_Assoc := Associated_Node_For_Itype (Itype);
20718 if Nkind (Old_Assoc) in N_Entity then
20719 if NCT_Tables_In_Use then
20720 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
20722 if Present (New_Assoc) then
20723 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
20724 end if;
20725 end if;
20727 -- Otherwise the associated node denotes a node. Postpone the update
20728 -- until Phase 2 when the node is replicated. Establish the following
20729 -- mapping within table NCT_Pending_Itypes:
20731 -- Old_Assoc -> (New_Type, ...)
20733 else
20734 Add_Pending_Itype (Old_Assoc, New_Itype);
20735 end if;
20737 -- Deal with the semantic fields of itypes. The fields are visited
20738 -- because they may mention entities that reside within the subtree
20739 -- being copied.
20741 Visit_Semantic_Fields (Itype);
20742 end Visit_Itype;
20744 ----------------
20745 -- Visit_List --
20746 ----------------
20748 procedure Visit_List (List : List_Id) is
20749 Elmt : Node_Id;
20751 begin
20752 -- Note that the element of a syntactic list is always a node, never
20753 -- an entity or itype, hence the call to Visit_Node.
20755 if Present (List) then
20756 Elmt := First (List);
20757 while Present (Elmt) loop
20758 Visit_Node (Elmt);
20760 Next (Elmt);
20761 end loop;
20762 end if;
20763 end Visit_List;
20765 ----------------
20766 -- Visit_Node --
20767 ----------------
20769 procedure Visit_Node (N : Node_Or_Entity_Id) is
20770 begin
20771 pragma Assert (Nkind (N) not in N_Entity);
20773 if Nkind (N) = N_Expression_With_Actions then
20774 EWA_Level := EWA_Level + 1;
20776 elsif EWA_Level > 0
20777 and then Nkind_In (N, N_Block_Statement,
20778 N_Subprogram_Body,
20779 N_Subprogram_Declaration)
20780 then
20781 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
20782 end if;
20784 Visit_Field
20785 (Field => Field1 (N),
20786 Par_Nod => N);
20788 Visit_Field
20789 (Field => Field2 (N),
20790 Par_Nod => N);
20792 Visit_Field
20793 (Field => Field3 (N),
20794 Par_Nod => N);
20796 Visit_Field
20797 (Field => Field4 (N),
20798 Par_Nod => N);
20800 Visit_Field
20801 (Field => Field5 (N),
20802 Par_Nod => N);
20804 if EWA_Level > 0
20805 and then Nkind_In (N, N_Block_Statement,
20806 N_Subprogram_Body,
20807 N_Subprogram_Declaration)
20808 then
20809 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
20811 elsif Nkind (N) = N_Expression_With_Actions then
20812 EWA_Level := EWA_Level - 1;
20813 end if;
20814 end Visit_Node;
20816 ---------------------------
20817 -- Visit_Semantic_Fields --
20818 ---------------------------
20820 procedure Visit_Semantic_Fields (Id : Entity_Id) is
20821 begin
20822 pragma Assert (Nkind (Id) in N_Entity);
20824 -- Discriminant_Constraint
20826 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20827 Visit_Field
20828 (Field => Union_Id (Discriminant_Constraint (Id)),
20829 Semantic => True);
20830 end if;
20832 -- Etype
20834 Visit_Field
20835 (Field => Union_Id (Etype (Id)),
20836 Semantic => True);
20838 -- First_Index
20839 -- Packed_Array_Impl_Type
20841 if Is_Array_Type (Id) then
20842 if Present (First_Index (Id)) then
20843 Visit_Field
20844 (Field => Union_Id (List_Containing (First_Index (Id))),
20845 Semantic => True);
20846 end if;
20848 if Is_Packed (Id) then
20849 Visit_Field
20850 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20851 Semantic => True);
20852 end if;
20853 end if;
20855 -- Scalar_Range
20857 if Is_Discrete_Type (Id) then
20858 Visit_Field
20859 (Field => Union_Id (Scalar_Range (Id)),
20860 Semantic => True);
20861 end if;
20862 end Visit_Semantic_Fields;
20864 -- Start of processing for New_Copy_Tree
20866 begin
20867 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
20868 -- shallow copies for each node within, and then updating the child and
20869 -- parent pointers accordingly. This process is straightforward, however
20870 -- the routine must deal with the following complications:
20872 -- * Entities defined within N_Expression_With_Actions nodes must be
20873 -- replicated rather than shared to avoid introducing two identical
20874 -- symbols within the same scope. Note that no other expression can
20875 -- currently define entities.
20877 -- do
20878 -- Source_Low : ...;
20879 -- Source_High : ...;
20881 -- <reference to Source_Low>
20882 -- <reference to Source_High>
20883 -- in ... end;
20885 -- New_Copy_Tree handles this case by first creating new entities
20886 -- and then updating all existing references to point to these new
20887 -- entities.
20889 -- do
20890 -- New_Low : ...;
20891 -- New_High : ...;
20893 -- <reference to New_Low>
20894 -- <reference to New_High>
20895 -- in ... end;
20897 -- * Itypes defined within the subtree must be replicated to avoid any
20898 -- dependencies on invalid or inaccessible data.
20900 -- subtype Source_Itype is ... range Source_Low .. Source_High;
20902 -- New_Copy_Tree handles this case by first creating a new itype in
20903 -- the same fashion as entities, and then updating various relevant
20904 -- constraints.
20906 -- subtype New_Itype is ... range New_Low .. New_High;
20908 -- * The Associated_Node_For_Itype field of itypes must be updated to
20909 -- reference the proper replicated entity or node.
20911 -- * Semantic fields of entities such as Etype and Scope must be
20912 -- updated to reference the proper replicated entities.
20914 -- * Semantic fields of nodes such as First_Real_Statement must be
20915 -- updated to reference the proper replicated nodes.
20917 -- To meet all these demands, routine New_Copy_Tree is split into two
20918 -- phases.
20920 -- Phase 1 traverses the tree in order to locate entities and itypes
20921 -- defined within the subtree. New entities are generated and saved in
20922 -- table NCT_New_Entities. The semantic fields of all new entities and
20923 -- itypes are then updated accordingly.
20925 -- Phase 2 traverses the tree in order to replicate each node. Various
20926 -- semantic fields of nodes and entities are updated accordingly.
20928 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
20929 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
20930 -- data inside.
20932 if NCT_Tables_In_Use then
20933 NCT_Tables_In_Use := False;
20935 NCT_New_Entities.Reset;
20936 NCT_Pending_Itypes.Reset;
20937 end if;
20939 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
20940 -- supplied by a linear entity map. The tables offer faster access to
20941 -- the same data.
20943 Build_NCT_Tables (Map);
20945 -- Execute Phase 1. Traverse the subtree and generate new entities for
20946 -- the following cases:
20948 -- * An entity defined within an N_Expression_With_Actions node
20950 -- * An itype referenced within the subtree where the associated node
20951 -- is also in the subtree.
20953 -- All new entities are accessible via table NCT_New_Entities, which
20954 -- contains mappings of the form:
20956 -- Old_Entity -> New_Entity
20957 -- Old_Itype -> New_Itype
20959 -- In addition, the associated nodes of all new itypes are mapped in
20960 -- table NCT_Pending_Itypes:
20962 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
20964 Visit_Any_Node (Source);
20966 -- Update the semantic attributes of all new entities generated during
20967 -- Phase 1 before starting Phase 2. The updates could be performed in
20968 -- routine Corresponding_Entity, however this may cause the same entity
20969 -- to be updated multiple times, effectively generating useless nodes.
20970 -- Keeping the updates separates from Phase 2 ensures that only one set
20971 -- of attributes is generated for an entity at any one time.
20973 Update_New_Entities (Map);
20975 -- Execute Phase 2. Replicate the source subtree one node at a time.
20976 -- The following transformations take place:
20978 -- * References to entities and itypes are updated to refer to the
20979 -- new entities and itypes generated during Phase 1.
20981 -- * All Associated_Node_For_Itype attributes of itypes are updated
20982 -- to refer to the new replicated Associated_Node_For_Itype.
20984 return Copy_Node_With_Replacement (Source);
20985 end New_Copy_Tree;
20987 -------------------------
20988 -- New_External_Entity --
20989 -------------------------
20991 function New_External_Entity
20992 (Kind : Entity_Kind;
20993 Scope_Id : Entity_Id;
20994 Sloc_Value : Source_Ptr;
20995 Related_Id : Entity_Id;
20996 Suffix : Character;
20997 Suffix_Index : Int := 0;
20998 Prefix : Character := ' ') return Entity_Id
21000 N : constant Entity_Id :=
21001 Make_Defining_Identifier (Sloc_Value,
21002 New_External_Name
21003 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
21005 begin
21006 Set_Ekind (N, Kind);
21007 Set_Is_Internal (N, True);
21008 Append_Entity (N, Scope_Id);
21009 Set_Public_Status (N);
21011 if Kind in Type_Kind then
21012 Init_Size_Align (N);
21013 end if;
21015 return N;
21016 end New_External_Entity;
21018 -------------------------
21019 -- New_Internal_Entity --
21020 -------------------------
21022 function New_Internal_Entity
21023 (Kind : Entity_Kind;
21024 Scope_Id : Entity_Id;
21025 Sloc_Value : Source_Ptr;
21026 Id_Char : Character) return Entity_Id
21028 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
21030 begin
21031 Set_Ekind (N, Kind);
21032 Set_Is_Internal (N, True);
21033 Append_Entity (N, Scope_Id);
21035 if Kind in Type_Kind then
21036 Init_Size_Align (N);
21037 end if;
21039 return N;
21040 end New_Internal_Entity;
21042 -----------------
21043 -- Next_Actual --
21044 -----------------
21046 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
21047 Par : constant Node_Id := Parent (Actual_Id);
21048 N : Node_Id;
21050 begin
21051 -- If we are pointing at a positional parameter, it is a member of a
21052 -- node list (the list of parameters), and the next parameter is the
21053 -- next node on the list, unless we hit a parameter association, then
21054 -- we shift to using the chain whose head is the First_Named_Actual in
21055 -- the parent, and then is threaded using the Next_Named_Actual of the
21056 -- Parameter_Association. All this fiddling is because the original node
21057 -- list is in the textual call order, and what we need is the
21058 -- declaration order.
21060 if Is_List_Member (Actual_Id) then
21061 N := Next (Actual_Id);
21063 if Nkind (N) = N_Parameter_Association then
21065 -- In case of a build-in-place call, the call will no longer be a
21066 -- call; it will have been rewritten.
21068 if Nkind_In (Par, N_Entry_Call_Statement,
21069 N_Function_Call,
21070 N_Procedure_Call_Statement)
21071 then
21072 return First_Named_Actual (Par);
21074 -- In case of a call rewritten in GNATprove mode while "inlining
21075 -- for proof" go to the original call.
21077 elsif Nkind (Par) = N_Null_Statement then
21078 pragma Assert
21079 (GNATprove_Mode
21080 and then
21081 Nkind (Original_Node (Par)) in N_Subprogram_Call);
21083 return First_Named_Actual (Original_Node (Par));
21084 else
21085 return Empty;
21086 end if;
21087 else
21088 return N;
21089 end if;
21091 else
21092 return Next_Named_Actual (Parent (Actual_Id));
21093 end if;
21094 end Next_Actual;
21096 procedure Next_Actual (Actual_Id : in out Node_Id) is
21097 begin
21098 Actual_Id := Next_Actual (Actual_Id);
21099 end Next_Actual;
21101 -----------------
21102 -- Next_Global --
21103 -----------------
21105 function Next_Global (Node : Node_Id) return Node_Id is
21106 begin
21107 -- The global item may either be in a list, or by itself, in which case
21108 -- there is no next global item with the same mode.
21110 if Is_List_Member (Node) then
21111 return Next (Node);
21112 else
21113 return Empty;
21114 end if;
21115 end Next_Global;
21117 procedure Next_Global (Node : in out Node_Id) is
21118 begin
21119 Node := Next_Global (Node);
21120 end Next_Global;
21122 ----------------------------------
21123 -- New_Requires_Transient_Scope --
21124 ----------------------------------
21126 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21127 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
21128 -- This is called for untagged records and protected types, with
21129 -- nondefaulted discriminants. Returns True if the size of function
21130 -- results is known at the call site, False otherwise. Returns False
21131 -- if there is a variant part that depends on the discriminants of
21132 -- this type, or if there is an array constrained by the discriminants
21133 -- of this type. ???Currently, this is overly conservative (the array
21134 -- could be nested inside some other record that is constrained by
21135 -- nondiscriminants). That is, the recursive calls are too conservative.
21137 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
21138 -- Returns True if Typ is a nonlimited record with defaulted
21139 -- discriminants whose max size makes it unsuitable for allocating on
21140 -- the primary stack.
21142 ------------------------------
21143 -- Caller_Known_Size_Record --
21144 ------------------------------
21146 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
21147 pragma Assert (Typ = Underlying_Type (Typ));
21149 begin
21150 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
21151 return False;
21152 end if;
21154 declare
21155 Comp : Entity_Id;
21157 begin
21158 Comp := First_Entity (Typ);
21159 while Present (Comp) loop
21161 -- Only look at E_Component entities. No need to look at
21162 -- E_Discriminant entities, and we must ignore internal
21163 -- subtypes generated for constrained components.
21165 if Ekind (Comp) = E_Component then
21166 declare
21167 Comp_Type : constant Entity_Id :=
21168 Underlying_Type (Etype (Comp));
21170 begin
21171 if Is_Record_Type (Comp_Type)
21172 or else
21173 Is_Protected_Type (Comp_Type)
21174 then
21175 if not Caller_Known_Size_Record (Comp_Type) then
21176 return False;
21177 end if;
21179 elsif Is_Array_Type (Comp_Type) then
21180 if Size_Depends_On_Discriminant (Comp_Type) then
21181 return False;
21182 end if;
21183 end if;
21184 end;
21185 end if;
21187 Next_Entity (Comp);
21188 end loop;
21189 end;
21191 return True;
21192 end Caller_Known_Size_Record;
21194 ------------------------------
21195 -- Large_Max_Size_Mutable --
21196 ------------------------------
21198 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
21199 pragma Assert (Typ = Underlying_Type (Typ));
21201 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
21202 -- Returns true if the discrete type T has a large range
21204 ----------------------------
21205 -- Is_Large_Discrete_Type --
21206 ----------------------------
21208 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
21209 Threshold : constant Int := 16;
21210 -- Arbitrary threshold above which we consider it "large". We want
21211 -- a fairly large threshold, because these large types really
21212 -- shouldn't have default discriminants in the first place, in
21213 -- most cases.
21215 begin
21216 return UI_To_Int (RM_Size (T)) > Threshold;
21217 end Is_Large_Discrete_Type;
21219 -- Start of processing for Large_Max_Size_Mutable
21221 begin
21222 if Is_Record_Type (Typ)
21223 and then not Is_Limited_View (Typ)
21224 and then Has_Defaulted_Discriminants (Typ)
21225 then
21226 -- Loop through the components, looking for an array whose upper
21227 -- bound(s) depends on discriminants, where both the subtype of
21228 -- the discriminant and the index subtype are too large.
21230 declare
21231 Comp : Entity_Id;
21233 begin
21234 Comp := First_Entity (Typ);
21235 while Present (Comp) loop
21236 if Ekind (Comp) = E_Component then
21237 declare
21238 Comp_Type : constant Entity_Id :=
21239 Underlying_Type (Etype (Comp));
21241 Hi : Node_Id;
21242 Indx : Node_Id;
21243 Ityp : Entity_Id;
21245 begin
21246 if Is_Array_Type (Comp_Type) then
21247 Indx := First_Index (Comp_Type);
21249 while Present (Indx) loop
21250 Ityp := Etype (Indx);
21251 Hi := Type_High_Bound (Ityp);
21253 if Nkind (Hi) = N_Identifier
21254 and then Ekind (Entity (Hi)) = E_Discriminant
21255 and then Is_Large_Discrete_Type (Ityp)
21256 and then Is_Large_Discrete_Type
21257 (Etype (Entity (Hi)))
21258 then
21259 return True;
21260 end if;
21262 Next_Index (Indx);
21263 end loop;
21264 end if;
21265 end;
21266 end if;
21268 Next_Entity (Comp);
21269 end loop;
21270 end;
21271 end if;
21273 return False;
21274 end Large_Max_Size_Mutable;
21276 -- Local declarations
21278 Typ : constant Entity_Id := Underlying_Type (Id);
21280 -- Start of processing for New_Requires_Transient_Scope
21282 begin
21283 -- This is a private type which is not completed yet. This can only
21284 -- happen in a default expression (of a formal parameter or of a
21285 -- record component). Do not expand transient scope in this case.
21287 if No (Typ) then
21288 return False;
21290 -- Do not expand transient scope for non-existent procedure return or
21291 -- string literal types.
21293 elsif Typ = Standard_Void_Type
21294 or else Ekind (Typ) = E_String_Literal_Subtype
21295 then
21296 return False;
21298 -- If Typ is a generic formal incomplete type, then we want to look at
21299 -- the actual type.
21301 elsif Ekind (Typ) = E_Record_Subtype
21302 and then Present (Cloned_Subtype (Typ))
21303 then
21304 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
21306 -- Functions returning specific tagged types may dispatch on result, so
21307 -- their returned value is allocated on the secondary stack, even in the
21308 -- definite case. We must treat nondispatching functions the same way,
21309 -- because access-to-function types can point at both, so the calling
21310 -- conventions must be compatible. Is_Tagged_Type includes controlled
21311 -- types and class-wide types. Controlled type temporaries need
21312 -- finalization.
21314 -- ???It's not clear why we need to return noncontrolled types with
21315 -- controlled components on the secondary stack.
21317 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
21318 return True;
21320 -- Untagged definite subtypes are known size. This includes all
21321 -- elementary [sub]types. Tasks are known size even if they have
21322 -- discriminants. So we return False here, with one exception:
21323 -- For a type like:
21324 -- type T (Last : Natural := 0) is
21325 -- X : String (1 .. Last);
21326 -- end record;
21327 -- we return True. That's because for "P(F(...));", where F returns T,
21328 -- we don't know the size of the result at the call site, so if we
21329 -- allocated it on the primary stack, we would have to allocate the
21330 -- maximum size, which is way too big.
21332 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
21333 return Large_Max_Size_Mutable (Typ);
21335 -- Indefinite (discriminated) untagged record or protected type
21337 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
21338 return not Caller_Known_Size_Record (Typ);
21340 -- Unconstrained array
21342 else
21343 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
21344 return True;
21345 end if;
21346 end New_Requires_Transient_Scope;
21348 --------------------------
21349 -- No_Heap_Finalization --
21350 --------------------------
21352 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
21353 begin
21354 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
21355 and then Is_Library_Level_Entity (Typ)
21356 then
21357 -- A global No_Heap_Finalization pragma applies to all library-level
21358 -- named access-to-object types.
21360 if Present (No_Heap_Finalization_Pragma) then
21361 return True;
21363 -- The library-level named access-to-object type itself is subject to
21364 -- pragma No_Heap_Finalization.
21366 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
21367 return True;
21368 end if;
21369 end if;
21371 return False;
21372 end No_Heap_Finalization;
21374 -----------------------
21375 -- Normalize_Actuals --
21376 -----------------------
21378 -- Chain actuals according to formals of subprogram. If there are no named
21379 -- associations, the chain is simply the list of Parameter Associations,
21380 -- since the order is the same as the declaration order. If there are named
21381 -- associations, then the First_Named_Actual field in the N_Function_Call
21382 -- or N_Procedure_Call_Statement node points to the Parameter_Association
21383 -- node for the parameter that comes first in declaration order. The
21384 -- remaining named parameters are then chained in declaration order using
21385 -- Next_Named_Actual.
21387 -- This routine also verifies that the number of actuals is compatible with
21388 -- the number and default values of formals, but performs no type checking
21389 -- (type checking is done by the caller).
21391 -- If the matching succeeds, Success is set to True and the caller proceeds
21392 -- with type-checking. If the match is unsuccessful, then Success is set to
21393 -- False, and the caller attempts a different interpretation, if there is
21394 -- one.
21396 -- If the flag Report is on, the call is not overloaded, and a failure to
21397 -- match can be reported here, rather than in the caller.
21399 procedure Normalize_Actuals
21400 (N : Node_Id;
21401 S : Entity_Id;
21402 Report : Boolean;
21403 Success : out Boolean)
21405 Actuals : constant List_Id := Parameter_Associations (N);
21406 Actual : Node_Id := Empty;
21407 Formal : Entity_Id;
21408 Last : Node_Id := Empty;
21409 First_Named : Node_Id := Empty;
21410 Found : Boolean;
21412 Formals_To_Match : Integer := 0;
21413 Actuals_To_Match : Integer := 0;
21415 procedure Chain (A : Node_Id);
21416 -- Add named actual at the proper place in the list, using the
21417 -- Next_Named_Actual link.
21419 function Reporting return Boolean;
21420 -- Determines if an error is to be reported. To report an error, we
21421 -- need Report to be True, and also we do not report errors caused
21422 -- by calls to init procs that occur within other init procs. Such
21423 -- errors must always be cascaded errors, since if all the types are
21424 -- declared correctly, the compiler will certainly build decent calls.
21426 -----------
21427 -- Chain --
21428 -----------
21430 procedure Chain (A : Node_Id) is
21431 begin
21432 if No (Last) then
21434 -- Call node points to first actual in list
21436 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
21438 else
21439 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
21440 end if;
21442 Last := A;
21443 Set_Next_Named_Actual (Last, Empty);
21444 end Chain;
21446 ---------------
21447 -- Reporting --
21448 ---------------
21450 function Reporting return Boolean is
21451 begin
21452 if not Report then
21453 return False;
21455 elsif not Within_Init_Proc then
21456 return True;
21458 elsif Is_Init_Proc (Entity (Name (N))) then
21459 return False;
21461 else
21462 return True;
21463 end if;
21464 end Reporting;
21466 -- Start of processing for Normalize_Actuals
21468 begin
21469 if Is_Access_Type (S) then
21471 -- The name in the call is a function call that returns an access
21472 -- to subprogram. The designated type has the list of formals.
21474 Formal := First_Formal (Designated_Type (S));
21475 else
21476 Formal := First_Formal (S);
21477 end if;
21479 while Present (Formal) loop
21480 Formals_To_Match := Formals_To_Match + 1;
21481 Next_Formal (Formal);
21482 end loop;
21484 -- Find if there is a named association, and verify that no positional
21485 -- associations appear after named ones.
21487 if Present (Actuals) then
21488 Actual := First (Actuals);
21489 end if;
21491 while Present (Actual)
21492 and then Nkind (Actual) /= N_Parameter_Association
21493 loop
21494 Actuals_To_Match := Actuals_To_Match + 1;
21495 Next (Actual);
21496 end loop;
21498 if No (Actual) and Actuals_To_Match = Formals_To_Match then
21500 -- Most common case: positional notation, no defaults
21502 Success := True;
21503 return;
21505 elsif Actuals_To_Match > Formals_To_Match then
21507 -- Too many actuals: will not work
21509 if Reporting then
21510 if Is_Entity_Name (Name (N)) then
21511 Error_Msg_N ("too many arguments in call to&", Name (N));
21512 else
21513 Error_Msg_N ("too many arguments in call", N);
21514 end if;
21515 end if;
21517 Success := False;
21518 return;
21519 end if;
21521 First_Named := Actual;
21523 while Present (Actual) loop
21524 if Nkind (Actual) /= N_Parameter_Association then
21525 Error_Msg_N
21526 ("positional parameters not allowed after named ones", Actual);
21527 Success := False;
21528 return;
21530 else
21531 Actuals_To_Match := Actuals_To_Match + 1;
21532 end if;
21534 Next (Actual);
21535 end loop;
21537 if Present (Actuals) then
21538 Actual := First (Actuals);
21539 end if;
21541 Formal := First_Formal (S);
21542 while Present (Formal) loop
21544 -- Match the formals in order. If the corresponding actual is
21545 -- positional, nothing to do. Else scan the list of named actuals
21546 -- to find the one with the right name.
21548 if Present (Actual)
21549 and then Nkind (Actual) /= N_Parameter_Association
21550 then
21551 Next (Actual);
21552 Actuals_To_Match := Actuals_To_Match - 1;
21553 Formals_To_Match := Formals_To_Match - 1;
21555 else
21556 -- For named parameters, search the list of actuals to find
21557 -- one that matches the next formal name.
21559 Actual := First_Named;
21560 Found := False;
21561 while Present (Actual) loop
21562 if Chars (Selector_Name (Actual)) = Chars (Formal) then
21563 Found := True;
21564 Chain (Actual);
21565 Actuals_To_Match := Actuals_To_Match - 1;
21566 Formals_To_Match := Formals_To_Match - 1;
21567 exit;
21568 end if;
21570 Next (Actual);
21571 end loop;
21573 if not Found then
21574 if Ekind (Formal) /= E_In_Parameter
21575 or else No (Default_Value (Formal))
21576 then
21577 if Reporting then
21578 if (Comes_From_Source (S)
21579 or else Sloc (S) = Standard_Location)
21580 and then Is_Overloadable (S)
21581 then
21582 if No (Actuals)
21583 and then
21584 Nkind_In (Parent (N), N_Procedure_Call_Statement,
21585 N_Function_Call,
21586 N_Parameter_Association)
21587 and then Ekind (S) /= E_Function
21588 then
21589 Set_Etype (N, Etype (S));
21591 else
21592 Error_Msg_Name_1 := Chars (S);
21593 Error_Msg_Sloc := Sloc (S);
21594 Error_Msg_NE
21595 ("missing argument for parameter & "
21596 & "in call to % declared #", N, Formal);
21597 end if;
21599 elsif Is_Overloadable (S) then
21600 Error_Msg_Name_1 := Chars (S);
21602 -- Point to type derivation that generated the
21603 -- operation.
21605 Error_Msg_Sloc := Sloc (Parent (S));
21607 Error_Msg_NE
21608 ("missing argument for parameter & "
21609 & "in call to % (inherited) #", N, Formal);
21611 else
21612 Error_Msg_NE
21613 ("missing argument for parameter &", N, Formal);
21614 end if;
21615 end if;
21617 Success := False;
21618 return;
21620 else
21621 Formals_To_Match := Formals_To_Match - 1;
21622 end if;
21623 end if;
21624 end if;
21626 Next_Formal (Formal);
21627 end loop;
21629 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
21630 Success := True;
21631 return;
21633 else
21634 if Reporting then
21636 -- Find some superfluous named actual that did not get
21637 -- attached to the list of associations.
21639 Actual := First (Actuals);
21640 while Present (Actual) loop
21641 if Nkind (Actual) = N_Parameter_Association
21642 and then Actual /= Last
21643 and then No (Next_Named_Actual (Actual))
21644 then
21645 -- A validity check may introduce a copy of a call that
21646 -- includes an extra actual (for example for an unrelated
21647 -- accessibility check). Check that the extra actual matches
21648 -- some extra formal, which must exist already because
21649 -- subprogram must be frozen at this point.
21651 if Present (Extra_Formals (S))
21652 and then not Comes_From_Source (Actual)
21653 and then Nkind (Actual) = N_Parameter_Association
21654 and then Chars (Extra_Formals (S)) =
21655 Chars (Selector_Name (Actual))
21656 then
21657 null;
21658 else
21659 Error_Msg_N
21660 ("unmatched actual & in call", Selector_Name (Actual));
21661 exit;
21662 end if;
21663 end if;
21665 Next (Actual);
21666 end loop;
21667 end if;
21669 Success := False;
21670 return;
21671 end if;
21672 end Normalize_Actuals;
21674 --------------------------------
21675 -- Note_Possible_Modification --
21676 --------------------------------
21678 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
21679 Modification_Comes_From_Source : constant Boolean :=
21680 Comes_From_Source (Parent (N));
21682 Ent : Entity_Id;
21683 Exp : Node_Id;
21685 begin
21686 -- Loop to find referenced entity, if there is one
21688 Exp := N;
21689 loop
21690 Ent := Empty;
21692 if Is_Entity_Name (Exp) then
21693 Ent := Entity (Exp);
21695 -- If the entity is missing, it is an undeclared identifier,
21696 -- and there is nothing to annotate.
21698 if No (Ent) then
21699 return;
21700 end if;
21702 elsif Nkind (Exp) = N_Explicit_Dereference then
21703 declare
21704 P : constant Node_Id := Prefix (Exp);
21706 begin
21707 -- In formal verification mode, keep track of all reads and
21708 -- writes through explicit dereferences.
21710 if GNATprove_Mode then
21711 SPARK_Specific.Generate_Dereference (N, 'm');
21712 end if;
21714 if Nkind (P) = N_Selected_Component
21715 and then Present (Entry_Formal (Entity (Selector_Name (P))))
21716 then
21717 -- Case of a reference to an entry formal
21719 Ent := Entry_Formal (Entity (Selector_Name (P)));
21721 elsif Nkind (P) = N_Identifier
21722 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
21723 and then Present (Expression (Parent (Entity (P))))
21724 and then Nkind (Expression (Parent (Entity (P)))) =
21725 N_Reference
21726 then
21727 -- Case of a reference to a value on which side effects have
21728 -- been removed.
21730 Exp := Prefix (Expression (Parent (Entity (P))));
21731 goto Continue;
21733 else
21734 return;
21735 end if;
21736 end;
21738 elsif Nkind_In (Exp, N_Type_Conversion,
21739 N_Unchecked_Type_Conversion)
21740 then
21741 Exp := Expression (Exp);
21742 goto Continue;
21744 elsif Nkind_In (Exp, N_Slice,
21745 N_Indexed_Component,
21746 N_Selected_Component)
21747 then
21748 -- Special check, if the prefix is an access type, then return
21749 -- since we are modifying the thing pointed to, not the prefix.
21750 -- When we are expanding, most usually the prefix is replaced
21751 -- by an explicit dereference, and this test is not needed, but
21752 -- in some cases (notably -gnatc mode and generics) when we do
21753 -- not do full expansion, we need this special test.
21755 if Is_Access_Type (Etype (Prefix (Exp))) then
21756 return;
21758 -- Otherwise go to prefix and keep going
21760 else
21761 Exp := Prefix (Exp);
21762 goto Continue;
21763 end if;
21765 -- All other cases, not a modification
21767 else
21768 return;
21769 end if;
21771 -- Now look for entity being referenced
21773 if Present (Ent) then
21774 if Is_Object (Ent) then
21775 if Comes_From_Source (Exp)
21776 or else Modification_Comes_From_Source
21777 then
21778 -- Give warning if pragma unmodified is given and we are
21779 -- sure this is a modification.
21781 if Has_Pragma_Unmodified (Ent) and then Sure then
21783 -- Note that the entity may be present only as a result
21784 -- of pragma Unused.
21786 if Has_Pragma_Unused (Ent) then
21787 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
21788 else
21789 Error_Msg_NE
21790 ("??pragma Unmodified given for &!", N, Ent);
21791 end if;
21792 end if;
21794 Set_Never_Set_In_Source (Ent, False);
21795 end if;
21797 Set_Is_True_Constant (Ent, False);
21798 Set_Current_Value (Ent, Empty);
21799 Set_Is_Known_Null (Ent, False);
21801 if not Can_Never_Be_Null (Ent) then
21802 Set_Is_Known_Non_Null (Ent, False);
21803 end if;
21805 -- Follow renaming chain
21807 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
21808 and then Present (Renamed_Object (Ent))
21809 then
21810 Exp := Renamed_Object (Ent);
21812 -- If the entity is the loop variable in an iteration over
21813 -- a container, retrieve container expression to indicate
21814 -- possible modification.
21816 if Present (Related_Expression (Ent))
21817 and then Nkind (Parent (Related_Expression (Ent))) =
21818 N_Iterator_Specification
21819 then
21820 Exp := Original_Node (Related_Expression (Ent));
21821 end if;
21823 goto Continue;
21825 -- The expression may be the renaming of a subcomponent of an
21826 -- array or container. The assignment to the subcomponent is
21827 -- a modification of the container.
21829 elsif Comes_From_Source (Original_Node (Exp))
21830 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
21831 N_Indexed_Component)
21832 then
21833 Exp := Prefix (Original_Node (Exp));
21834 goto Continue;
21835 end if;
21837 -- Generate a reference only if the assignment comes from
21838 -- source. This excludes, for example, calls to a dispatching
21839 -- assignment operation when the left-hand side is tagged. In
21840 -- GNATprove mode, we need those references also on generated
21841 -- code, as these are used to compute the local effects of
21842 -- subprograms.
21844 if Modification_Comes_From_Source or GNATprove_Mode then
21845 Generate_Reference (Ent, Exp, 'm');
21847 -- If the target of the assignment is the bound variable
21848 -- in an iterator, indicate that the corresponding array
21849 -- or container is also modified.
21851 if Ada_Version >= Ada_2012
21852 and then Nkind (Parent (Ent)) = N_Iterator_Specification
21853 then
21854 declare
21855 Domain : constant Node_Id := Name (Parent (Ent));
21857 begin
21858 -- TBD : in the full version of the construct, the
21859 -- domain of iteration can be given by an expression.
21861 if Is_Entity_Name (Domain) then
21862 Generate_Reference (Entity (Domain), Exp, 'm');
21863 Set_Is_True_Constant (Entity (Domain), False);
21864 Set_Never_Set_In_Source (Entity (Domain), False);
21865 end if;
21866 end;
21867 end if;
21868 end if;
21869 end if;
21871 Kill_Checks (Ent);
21873 -- If we are sure this is a modification from source, and we know
21874 -- this modifies a constant, then give an appropriate warning.
21876 if Sure
21877 and then Modification_Comes_From_Source
21878 and then Overlays_Constant (Ent)
21879 and then Address_Clause_Overlay_Warnings
21880 then
21881 declare
21882 Addr : constant Node_Id := Address_Clause (Ent);
21883 O_Ent : Entity_Id;
21884 Off : Boolean;
21886 begin
21887 Find_Overlaid_Entity (Addr, O_Ent, Off);
21889 Error_Msg_Sloc := Sloc (Addr);
21890 Error_Msg_NE
21891 ("??constant& may be modified via address clause#",
21892 N, O_Ent);
21893 end;
21894 end if;
21896 return;
21897 end if;
21899 <<Continue>>
21900 null;
21901 end loop;
21902 end Note_Possible_Modification;
21904 -----------------
21905 -- Null_Status --
21906 -----------------
21908 function Null_Status (N : Node_Id) return Null_Status_Kind is
21909 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
21910 -- Determine whether definition Def carries a null exclusion
21912 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
21913 -- Determine the null status of arbitrary entity Id
21915 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
21916 -- Determine the null status of type Typ
21918 ---------------------------
21919 -- Is_Null_Excluding_Def --
21920 ---------------------------
21922 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
21923 begin
21924 return
21925 Nkind_In (Def, N_Access_Definition,
21926 N_Access_Function_Definition,
21927 N_Access_Procedure_Definition,
21928 N_Access_To_Object_Definition,
21929 N_Component_Definition,
21930 N_Derived_Type_Definition)
21931 and then Null_Exclusion_Present (Def);
21932 end Is_Null_Excluding_Def;
21934 ---------------------------
21935 -- Null_Status_Of_Entity --
21936 ---------------------------
21938 function Null_Status_Of_Entity
21939 (Id : Entity_Id) return Null_Status_Kind
21941 Decl : constant Node_Id := Declaration_Node (Id);
21942 Def : Node_Id;
21944 begin
21945 -- The value of an imported or exported entity may be set externally
21946 -- regardless of a null exclusion. As a result, the value cannot be
21947 -- determined statically.
21949 if Is_Imported (Id) or else Is_Exported (Id) then
21950 return Unknown;
21952 elsif Nkind_In (Decl, N_Component_Declaration,
21953 N_Discriminant_Specification,
21954 N_Formal_Object_Declaration,
21955 N_Object_Declaration,
21956 N_Object_Renaming_Declaration,
21957 N_Parameter_Specification)
21958 then
21959 -- A component declaration yields a non-null value when either
21960 -- its component definition or access definition carries a null
21961 -- exclusion.
21963 if Nkind (Decl) = N_Component_Declaration then
21964 Def := Component_Definition (Decl);
21966 if Is_Null_Excluding_Def (Def) then
21967 return Is_Non_Null;
21968 end if;
21970 Def := Access_Definition (Def);
21972 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21973 return Is_Non_Null;
21974 end if;
21976 -- A formal object declaration yields a non-null value if its
21977 -- access definition carries a null exclusion. If the object is
21978 -- default initialized, then the value depends on the expression.
21980 elsif Nkind (Decl) = N_Formal_Object_Declaration then
21981 Def := Access_Definition (Decl);
21983 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21984 return Is_Non_Null;
21985 end if;
21987 -- A constant may yield a null or non-null value depending on its
21988 -- initialization expression.
21990 elsif Ekind (Id) = E_Constant then
21991 return Null_Status (Constant_Value (Id));
21993 -- The construct yields a non-null value when it has a null
21994 -- exclusion.
21996 elsif Null_Exclusion_Present (Decl) then
21997 return Is_Non_Null;
21999 -- An object renaming declaration yields a non-null value if its
22000 -- access definition carries a null exclusion. Otherwise the value
22001 -- depends on the renamed name.
22003 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
22004 Def := Access_Definition (Decl);
22006 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22007 return Is_Non_Null;
22009 else
22010 return Null_Status (Name (Decl));
22011 end if;
22012 end if;
22013 end if;
22015 -- At this point the declaration of the entity does not carry a null
22016 -- exclusion and lacks an initialization expression. Check the status
22017 -- of its type.
22019 return Null_Status_Of_Type (Etype (Id));
22020 end Null_Status_Of_Entity;
22022 -------------------------
22023 -- Null_Status_Of_Type --
22024 -------------------------
22026 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
22027 Curr : Entity_Id;
22028 Decl : Node_Id;
22030 begin
22031 -- Traverse the type chain looking for types with null exclusion
22033 Curr := Typ;
22034 while Present (Curr) and then Etype (Curr) /= Curr loop
22035 Decl := Parent (Curr);
22037 -- Guard against itypes which do not always have declarations. A
22038 -- type yields a non-null value if it carries a null exclusion.
22040 if Present (Decl) then
22041 if Nkind (Decl) = N_Full_Type_Declaration
22042 and then Is_Null_Excluding_Def (Type_Definition (Decl))
22043 then
22044 return Is_Non_Null;
22046 elsif Nkind (Decl) = N_Subtype_Declaration
22047 and then Null_Exclusion_Present (Decl)
22048 then
22049 return Is_Non_Null;
22050 end if;
22051 end if;
22053 Curr := Etype (Curr);
22054 end loop;
22056 -- The type chain does not contain any null excluding types
22058 return Unknown;
22059 end Null_Status_Of_Type;
22061 -- Start of processing for Null_Status
22063 begin
22064 -- An allocator always creates a non-null value
22066 if Nkind (N) = N_Allocator then
22067 return Is_Non_Null;
22069 -- Taking the 'Access of something yields a non-null value
22071 elsif Nkind (N) = N_Attribute_Reference
22072 and then Nam_In (Attribute_Name (N), Name_Access,
22073 Name_Unchecked_Access,
22074 Name_Unrestricted_Access)
22075 then
22076 return Is_Non_Null;
22078 -- "null" yields null
22080 elsif Nkind (N) = N_Null then
22081 return Is_Null;
22083 -- Check the status of the operand of a type conversion
22085 elsif Nkind (N) = N_Type_Conversion then
22086 return Null_Status (Expression (N));
22088 -- The input denotes a reference to an entity. Determine whether the
22089 -- entity or its type yields a null or non-null value.
22091 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22092 return Null_Status_Of_Entity (Entity (N));
22093 end if;
22095 -- Otherwise it is not possible to determine the null status of the
22096 -- subexpression at compile time without resorting to simple flow
22097 -- analysis.
22099 return Unknown;
22100 end Null_Status;
22102 --------------------------------------
22103 -- Null_To_Null_Address_Convert_OK --
22104 --------------------------------------
22106 function Null_To_Null_Address_Convert_OK
22107 (N : Node_Id;
22108 Typ : Entity_Id := Empty) return Boolean
22110 begin
22111 if not Relaxed_RM_Semantics then
22112 return False;
22113 end if;
22115 if Nkind (N) = N_Null then
22116 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
22118 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
22119 then
22120 declare
22121 L : constant Node_Id := Left_Opnd (N);
22122 R : constant Node_Id := Right_Opnd (N);
22124 begin
22125 -- We check the Etype of the complementary operand since the
22126 -- N_Null node is not decorated at this stage.
22128 return
22129 ((Nkind (L) = N_Null
22130 and then Is_Descendant_Of_Address (Etype (R)))
22131 or else
22132 (Nkind (R) = N_Null
22133 and then Is_Descendant_Of_Address (Etype (L))));
22134 end;
22135 end if;
22137 return False;
22138 end Null_To_Null_Address_Convert_OK;
22140 ---------------------------------
22141 -- Number_Of_Elements_In_Array --
22142 ---------------------------------
22144 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
22145 Indx : Node_Id;
22146 Typ : Entity_Id;
22147 Low : Node_Id;
22148 High : Node_Id;
22149 Num : Int := 1;
22151 begin
22152 pragma Assert (Is_Array_Type (T));
22154 Indx := First_Index (T);
22155 while Present (Indx) loop
22156 Typ := Underlying_Type (Etype (Indx));
22158 -- Never look at junk bounds of a generic type
22160 if Is_Generic_Type (Typ) then
22161 return 0;
22162 end if;
22164 -- Check the array bounds are known at compile time and return zero
22165 -- if they are not.
22167 Low := Type_Low_Bound (Typ);
22168 High := Type_High_Bound (Typ);
22170 if not Compile_Time_Known_Value (Low) then
22171 return 0;
22172 elsif not Compile_Time_Known_Value (High) then
22173 return 0;
22174 else
22175 Num :=
22176 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
22177 end if;
22179 Next_Index (Indx);
22180 end loop;
22182 return Num;
22183 end Number_Of_Elements_In_Array;
22185 -------------------------
22186 -- Object_Access_Level --
22187 -------------------------
22189 -- Returns the static accessibility level of the view denoted by Obj. Note
22190 -- that the value returned is the result of a call to Scope_Depth. Only
22191 -- scope depths associated with dynamic scopes can actually be returned.
22192 -- Since only relative levels matter for accessibility checking, the fact
22193 -- that the distance between successive levels of accessibility is not
22194 -- always one is immaterial (invariant: if level(E2) is deeper than
22195 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
22197 function Object_Access_Level (Obj : Node_Id) return Uint is
22198 function Is_Interface_Conversion (N : Node_Id) return Boolean;
22199 -- Determine whether N is a construct of the form
22200 -- Some_Type (Operand._tag'Address)
22201 -- This construct appears in the context of dispatching calls.
22203 function Reference_To (Obj : Node_Id) return Node_Id;
22204 -- An explicit dereference is created when removing side effects from
22205 -- expressions for constraint checking purposes. In this case a local
22206 -- access type is created for it. The correct access level is that of
22207 -- the original source node. We detect this case by noting that the
22208 -- prefix of the dereference is created by an object declaration whose
22209 -- initial expression is a reference.
22211 -----------------------------
22212 -- Is_Interface_Conversion --
22213 -----------------------------
22215 function Is_Interface_Conversion (N : Node_Id) return Boolean is
22216 begin
22217 return Nkind (N) = N_Unchecked_Type_Conversion
22218 and then Nkind (Expression (N)) = N_Attribute_Reference
22219 and then Attribute_Name (Expression (N)) = Name_Address;
22220 end Is_Interface_Conversion;
22222 ------------------
22223 -- Reference_To --
22224 ------------------
22226 function Reference_To (Obj : Node_Id) return Node_Id is
22227 Pref : constant Node_Id := Prefix (Obj);
22228 begin
22229 if Is_Entity_Name (Pref)
22230 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
22231 and then Present (Expression (Parent (Entity (Pref))))
22232 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
22233 then
22234 return (Prefix (Expression (Parent (Entity (Pref)))));
22235 else
22236 return Empty;
22237 end if;
22238 end Reference_To;
22240 -- Local variables
22242 E : Entity_Id;
22244 -- Start of processing for Object_Access_Level
22246 begin
22247 if Nkind (Obj) = N_Defining_Identifier
22248 or else Is_Entity_Name (Obj)
22249 then
22250 if Nkind (Obj) = N_Defining_Identifier then
22251 E := Obj;
22252 else
22253 E := Entity (Obj);
22254 end if;
22256 if Is_Prival (E) then
22257 E := Prival_Link (E);
22258 end if;
22260 -- If E is a type then it denotes a current instance. For this case
22261 -- we add one to the normal accessibility level of the type to ensure
22262 -- that current instances are treated as always being deeper than
22263 -- than the level of any visible named access type (see 3.10.2(21)).
22265 if Is_Type (E) then
22266 return Type_Access_Level (E) + 1;
22268 elsif Present (Renamed_Object (E)) then
22269 return Object_Access_Level (Renamed_Object (E));
22271 -- Similarly, if E is a component of the current instance of a
22272 -- protected type, any instance of it is assumed to be at a deeper
22273 -- level than the type. For a protected object (whose type is an
22274 -- anonymous protected type) its components are at the same level
22275 -- as the type itself.
22277 elsif not Is_Overloadable (E)
22278 and then Ekind (Scope (E)) = E_Protected_Type
22279 and then Comes_From_Source (Scope (E))
22280 then
22281 return Type_Access_Level (Scope (E)) + 1;
22283 else
22284 -- Aliased formals of functions take their access level from the
22285 -- point of call, i.e. require a dynamic check. For static check
22286 -- purposes, this is smaller than the level of the subprogram
22287 -- itself. For procedures the aliased makes no difference.
22289 if Is_Formal (E)
22290 and then Is_Aliased (E)
22291 and then Ekind (Scope (E)) = E_Function
22292 then
22293 return Type_Access_Level (Etype (E));
22295 else
22296 return Scope_Depth (Enclosing_Dynamic_Scope (E));
22297 end if;
22298 end if;
22300 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
22301 if Is_Access_Type (Etype (Prefix (Obj))) then
22302 return Type_Access_Level (Etype (Prefix (Obj)));
22303 else
22304 return Object_Access_Level (Prefix (Obj));
22305 end if;
22307 elsif Nkind (Obj) = N_Explicit_Dereference then
22309 -- If the prefix is a selected access discriminant then we make a
22310 -- recursive call on the prefix, which will in turn check the level
22311 -- of the prefix object of the selected discriminant.
22313 -- In Ada 2012, if the discriminant has implicit dereference and
22314 -- the context is a selected component, treat this as an object of
22315 -- unknown scope (see below). This is necessary in compile-only mode;
22316 -- otherwise expansion will already have transformed the prefix into
22317 -- a temporary.
22319 if Nkind (Prefix (Obj)) = N_Selected_Component
22320 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
22321 and then
22322 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
22323 and then
22324 (not Has_Implicit_Dereference
22325 (Entity (Selector_Name (Prefix (Obj))))
22326 or else Nkind (Parent (Obj)) /= N_Selected_Component)
22327 then
22328 return Object_Access_Level (Prefix (Obj));
22330 -- Detect an interface conversion in the context of a dispatching
22331 -- call. Use the original form of the conversion to find the access
22332 -- level of the operand.
22334 elsif Is_Interface (Etype (Obj))
22335 and then Is_Interface_Conversion (Prefix (Obj))
22336 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
22337 then
22338 return Object_Access_Level (Original_Node (Obj));
22340 elsif not Comes_From_Source (Obj) then
22341 declare
22342 Ref : constant Node_Id := Reference_To (Obj);
22343 begin
22344 if Present (Ref) then
22345 return Object_Access_Level (Ref);
22346 else
22347 return Type_Access_Level (Etype (Prefix (Obj)));
22348 end if;
22349 end;
22351 else
22352 return Type_Access_Level (Etype (Prefix (Obj)));
22353 end if;
22355 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
22356 return Object_Access_Level (Expression (Obj));
22358 elsif Nkind (Obj) = N_Function_Call then
22360 -- Function results are objects, so we get either the access level of
22361 -- the function or, in the case of an indirect call, the level of the
22362 -- access-to-subprogram type. (This code is used for Ada 95, but it
22363 -- looks wrong, because it seems that we should be checking the level
22364 -- of the call itself, even for Ada 95. However, using the Ada 2005
22365 -- version of the code causes regressions in several tests that are
22366 -- compiled with -gnat95. ???)
22368 if Ada_Version < Ada_2005 then
22369 if Is_Entity_Name (Name (Obj)) then
22370 return Subprogram_Access_Level (Entity (Name (Obj)));
22371 else
22372 return Type_Access_Level (Etype (Prefix (Name (Obj))));
22373 end if;
22375 -- For Ada 2005, the level of the result object of a function call is
22376 -- defined to be the level of the call's innermost enclosing master.
22377 -- We determine that by querying the depth of the innermost enclosing
22378 -- dynamic scope.
22380 else
22381 Return_Master_Scope_Depth_Of_Call : declare
22382 function Innermost_Master_Scope_Depth
22383 (N : Node_Id) return Uint;
22384 -- Returns the scope depth of the given node's innermost
22385 -- enclosing dynamic scope (effectively the accessibility
22386 -- level of the innermost enclosing master).
22388 ----------------------------------
22389 -- Innermost_Master_Scope_Depth --
22390 ----------------------------------
22392 function Innermost_Master_Scope_Depth
22393 (N : Node_Id) return Uint
22395 Node_Par : Node_Id := Parent (N);
22397 begin
22398 -- Locate the nearest enclosing node (by traversing Parents)
22399 -- that Defining_Entity can be applied to, and return the
22400 -- depth of that entity's nearest enclosing dynamic scope.
22402 while Present (Node_Par) loop
22403 case Nkind (Node_Par) is
22404 when N_Abstract_Subprogram_Declaration
22405 | N_Block_Statement
22406 | N_Body_Stub
22407 | N_Component_Declaration
22408 | N_Entry_Body
22409 | N_Entry_Declaration
22410 | N_Exception_Declaration
22411 | N_Formal_Object_Declaration
22412 | N_Formal_Package_Declaration
22413 | N_Formal_Subprogram_Declaration
22414 | N_Formal_Type_Declaration
22415 | N_Full_Type_Declaration
22416 | N_Function_Specification
22417 | N_Generic_Declaration
22418 | N_Generic_Instantiation
22419 | N_Implicit_Label_Declaration
22420 | N_Incomplete_Type_Declaration
22421 | N_Loop_Parameter_Specification
22422 | N_Number_Declaration
22423 | N_Object_Declaration
22424 | N_Package_Declaration
22425 | N_Package_Specification
22426 | N_Parameter_Specification
22427 | N_Private_Extension_Declaration
22428 | N_Private_Type_Declaration
22429 | N_Procedure_Specification
22430 | N_Proper_Body
22431 | N_Protected_Type_Declaration
22432 | N_Renaming_Declaration
22433 | N_Single_Protected_Declaration
22434 | N_Single_Task_Declaration
22435 | N_Subprogram_Declaration
22436 | N_Subtype_Declaration
22437 | N_Subunit
22438 | N_Task_Type_Declaration
22440 return Scope_Depth
22441 (Nearest_Dynamic_Scope
22442 (Defining_Entity (Node_Par)));
22444 -- For a return statement within a function, return
22445 -- the depth of the function itself. This is not just
22446 -- a small optimization, but matters when analyzing
22447 -- the expression in an expression function before
22448 -- the body is created.
22450 when N_Simple_Return_Statement =>
22451 if Ekind (Current_Scope) = E_Function then
22452 return Scope_Depth (Current_Scope);
22453 end if;
22455 when others =>
22456 null;
22457 end case;
22459 Node_Par := Parent (Node_Par);
22460 end loop;
22462 pragma Assert (False);
22464 -- Should never reach the following return
22466 return Scope_Depth (Current_Scope) + 1;
22467 end Innermost_Master_Scope_Depth;
22469 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22471 begin
22472 return Innermost_Master_Scope_Depth (Obj);
22473 end Return_Master_Scope_Depth_Of_Call;
22474 end if;
22476 -- For convenience we handle qualified expressions, even though they
22477 -- aren't technically object names.
22479 elsif Nkind (Obj) = N_Qualified_Expression then
22480 return Object_Access_Level (Expression (Obj));
22482 -- Ditto for aggregates. They have the level of the temporary that
22483 -- will hold their value.
22485 elsif Nkind (Obj) = N_Aggregate then
22486 return Object_Access_Level (Current_Scope);
22488 -- Otherwise return the scope level of Standard. (If there are cases
22489 -- that fall through to this point they will be treated as having
22490 -- global accessibility for now. ???)
22492 else
22493 return Scope_Depth (Standard_Standard);
22494 end if;
22495 end Object_Access_Level;
22497 ----------------------------------
22498 -- Old_Requires_Transient_Scope --
22499 ----------------------------------
22501 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22502 Typ : constant Entity_Id := Underlying_Type (Id);
22504 begin
22505 -- This is a private type which is not completed yet. This can only
22506 -- happen in a default expression (of a formal parameter or of a
22507 -- record component). Do not expand transient scope in this case.
22509 if No (Typ) then
22510 return False;
22512 -- Do not expand transient scope for non-existent procedure return
22514 elsif Typ = Standard_Void_Type then
22515 return False;
22517 -- Elementary types do not require a transient scope
22519 elsif Is_Elementary_Type (Typ) then
22520 return False;
22522 -- Generally, indefinite subtypes require a transient scope, since the
22523 -- back end cannot generate temporaries, since this is not a valid type
22524 -- for declaring an object. It might be possible to relax this in the
22525 -- future, e.g. by declaring the maximum possible space for the type.
22527 elsif not Is_Definite_Subtype (Typ) then
22528 return True;
22530 -- Functions returning tagged types may dispatch on result so their
22531 -- returned value is allocated on the secondary stack. Controlled
22532 -- type temporaries need finalization.
22534 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22535 return True;
22537 -- Record type
22539 elsif Is_Record_Type (Typ) then
22540 declare
22541 Comp : Entity_Id;
22543 begin
22544 Comp := First_Entity (Typ);
22545 while Present (Comp) loop
22546 if Ekind (Comp) = E_Component then
22548 -- ???It's not clear we need a full recursive call to
22549 -- Old_Requires_Transient_Scope here. Note that the
22550 -- following can't happen.
22552 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
22553 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
22555 if Old_Requires_Transient_Scope (Etype (Comp)) then
22556 return True;
22557 end if;
22558 end if;
22560 Next_Entity (Comp);
22561 end loop;
22562 end;
22564 return False;
22566 -- String literal types never require transient scope
22568 elsif Ekind (Typ) = E_String_Literal_Subtype then
22569 return False;
22571 -- Array type. Note that we already know that this is a constrained
22572 -- array, since unconstrained arrays will fail the indefinite test.
22574 elsif Is_Array_Type (Typ) then
22576 -- If component type requires a transient scope, the array does too
22578 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
22579 return True;
22581 -- Otherwise, we only need a transient scope if the size depends on
22582 -- the value of one or more discriminants.
22584 else
22585 return Size_Depends_On_Discriminant (Typ);
22586 end if;
22588 -- All other cases do not require a transient scope
22590 else
22591 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
22592 return False;
22593 end if;
22594 end Old_Requires_Transient_Scope;
22596 ---------------------------------
22597 -- Original_Aspect_Pragma_Name --
22598 ---------------------------------
22600 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
22601 Item : Node_Id;
22602 Item_Nam : Name_Id;
22604 begin
22605 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
22607 Item := N;
22609 -- The pragma was generated to emulate an aspect, use the original
22610 -- aspect specification.
22612 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
22613 Item := Corresponding_Aspect (Item);
22614 end if;
22616 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
22617 -- Post and Post_Class rewrite their pragma identifier to preserve the
22618 -- original name.
22619 -- ??? this is kludgey
22621 if Nkind (Item) = N_Pragma then
22622 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
22624 else
22625 pragma Assert (Nkind (Item) = N_Aspect_Specification);
22626 Item_Nam := Chars (Identifier (Item));
22627 end if;
22629 -- Deal with 'Class by converting the name to its _XXX form
22631 if Class_Present (Item) then
22632 if Item_Nam = Name_Invariant then
22633 Item_Nam := Name_uInvariant;
22635 elsif Item_Nam = Name_Post then
22636 Item_Nam := Name_uPost;
22638 elsif Item_Nam = Name_Pre then
22639 Item_Nam := Name_uPre;
22641 elsif Nam_In (Item_Nam, Name_Type_Invariant,
22642 Name_Type_Invariant_Class)
22643 then
22644 Item_Nam := Name_uType_Invariant;
22646 -- Nothing to do for other cases (e.g. a Check that derived from
22647 -- Pre_Class and has the flag set). Also we do nothing if the name
22648 -- is already in special _xxx form.
22650 end if;
22651 end if;
22653 return Item_Nam;
22654 end Original_Aspect_Pragma_Name;
22656 --------------------------------------
22657 -- Original_Corresponding_Operation --
22658 --------------------------------------
22660 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
22662 Typ : constant Entity_Id := Find_Dispatching_Type (S);
22664 begin
22665 -- If S is an inherited primitive S2 the original corresponding
22666 -- operation of S is the original corresponding operation of S2
22668 if Present (Alias (S))
22669 and then Find_Dispatching_Type (Alias (S)) /= Typ
22670 then
22671 return Original_Corresponding_Operation (Alias (S));
22673 -- If S overrides an inherited subprogram S2 the original corresponding
22674 -- operation of S is the original corresponding operation of S2
22676 elsif Present (Overridden_Operation (S)) then
22677 return Original_Corresponding_Operation (Overridden_Operation (S));
22679 -- otherwise it is S itself
22681 else
22682 return S;
22683 end if;
22684 end Original_Corresponding_Operation;
22686 -------------------
22687 -- Output_Entity --
22688 -------------------
22690 procedure Output_Entity (Id : Entity_Id) is
22691 Scop : Entity_Id;
22693 begin
22694 Scop := Scope (Id);
22696 -- The entity may lack a scope when it is in the process of being
22697 -- analyzed. Use the current scope as an approximation.
22699 if No (Scop) then
22700 Scop := Current_Scope;
22701 end if;
22703 Output_Name (Chars (Id), Scop);
22704 end Output_Entity;
22706 -----------------
22707 -- Output_Name --
22708 -----------------
22710 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
22711 begin
22712 Write_Str
22713 (Get_Name_String
22714 (Get_Qualified_Name
22715 (Nam => Nam,
22716 Suffix => No_Name,
22717 Scop => Scop)));
22718 Write_Eol;
22719 end Output_Name;
22721 ----------------------
22722 -- Policy_In_Effect --
22723 ----------------------
22725 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
22726 function Policy_In_List (List : Node_Id) return Name_Id;
22727 -- Determine the mode of a policy in a N_Pragma list
22729 --------------------
22730 -- Policy_In_List --
22731 --------------------
22733 function Policy_In_List (List : Node_Id) return Name_Id is
22734 Arg1 : Node_Id;
22735 Arg2 : Node_Id;
22736 Prag : Node_Id;
22738 begin
22739 Prag := List;
22740 while Present (Prag) loop
22741 Arg1 := First (Pragma_Argument_Associations (Prag));
22742 Arg2 := Next (Arg1);
22744 Arg1 := Get_Pragma_Arg (Arg1);
22745 Arg2 := Get_Pragma_Arg (Arg2);
22747 -- The current Check_Policy pragma matches the requested policy or
22748 -- appears in the single argument form (Assertion, policy_id).
22750 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
22751 return Chars (Arg2);
22752 end if;
22754 Prag := Next_Pragma (Prag);
22755 end loop;
22757 return No_Name;
22758 end Policy_In_List;
22760 -- Local variables
22762 Kind : Name_Id;
22764 -- Start of processing for Policy_In_Effect
22766 begin
22767 if not Is_Valid_Assertion_Kind (Policy) then
22768 raise Program_Error;
22769 end if;
22771 -- Inspect all policy pragmas that appear within scopes (if any)
22773 Kind := Policy_In_List (Check_Policy_List);
22775 -- Inspect all configuration policy pragmas (if any)
22777 if Kind = No_Name then
22778 Kind := Policy_In_List (Check_Policy_List_Config);
22779 end if;
22781 -- The context lacks policy pragmas, determine the mode based on whether
22782 -- assertions are enabled at the configuration level. This ensures that
22783 -- the policy is preserved when analyzing generics.
22785 if Kind = No_Name then
22786 if Assertions_Enabled_Config then
22787 Kind := Name_Check;
22788 else
22789 Kind := Name_Ignore;
22790 end if;
22791 end if;
22793 -- In CodePeer mode and GNATprove mode, we need to consider all
22794 -- assertions, unless they are disabled. Force Name_Check on
22795 -- ignored assertions.
22797 if Nam_In (Kind, Name_Ignore, Name_Off)
22798 and then (CodePeer_Mode or GNATprove_Mode)
22799 then
22800 Kind := Name_Check;
22801 end if;
22803 return Kind;
22804 end Policy_In_Effect;
22806 ----------------------------------
22807 -- Predicate_Tests_On_Arguments --
22808 ----------------------------------
22810 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
22811 begin
22812 -- Always test predicates on indirect call
22814 if Ekind (Subp) = E_Subprogram_Type then
22815 return True;
22817 -- Do not test predicates on call to generated default Finalize, since
22818 -- we are not interested in whether something we are finalizing (and
22819 -- typically destroying) satisfies its predicates.
22821 elsif Chars (Subp) = Name_Finalize
22822 and then not Comes_From_Source (Subp)
22823 then
22824 return False;
22826 -- Do not test predicates on any internally generated routines
22828 elsif Is_Internal_Name (Chars (Subp)) then
22829 return False;
22831 -- Do not test predicates on call to Init_Proc, since if needed the
22832 -- predicate test will occur at some other point.
22834 elsif Is_Init_Proc (Subp) then
22835 return False;
22837 -- Do not test predicates on call to predicate function, since this
22838 -- would cause infinite recursion.
22840 elsif Ekind (Subp) = E_Function
22841 and then (Is_Predicate_Function (Subp)
22842 or else
22843 Is_Predicate_Function_M (Subp))
22844 then
22845 return False;
22847 -- For now, no other exceptions
22849 else
22850 return True;
22851 end if;
22852 end Predicate_Tests_On_Arguments;
22854 -----------------------
22855 -- Private_Component --
22856 -----------------------
22858 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
22859 Ancestor : constant Entity_Id := Base_Type (Type_Id);
22861 function Trace_Components
22862 (T : Entity_Id;
22863 Check : Boolean) return Entity_Id;
22864 -- Recursive function that does the work, and checks against circular
22865 -- definition for each subcomponent type.
22867 ----------------------
22868 -- Trace_Components --
22869 ----------------------
22871 function Trace_Components
22872 (T : Entity_Id;
22873 Check : Boolean) return Entity_Id
22875 Btype : constant Entity_Id := Base_Type (T);
22876 Component : Entity_Id;
22877 P : Entity_Id;
22878 Candidate : Entity_Id := Empty;
22880 begin
22881 if Check and then Btype = Ancestor then
22882 Error_Msg_N ("circular type definition", Type_Id);
22883 return Any_Type;
22884 end if;
22886 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
22887 if Present (Full_View (Btype))
22888 and then Is_Record_Type (Full_View (Btype))
22889 and then not Is_Frozen (Btype)
22890 then
22891 -- To indicate that the ancestor depends on a private type, the
22892 -- current Btype is sufficient. However, to check for circular
22893 -- definition we must recurse on the full view.
22895 Candidate := Trace_Components (Full_View (Btype), True);
22897 if Candidate = Any_Type then
22898 return Any_Type;
22899 else
22900 return Btype;
22901 end if;
22903 else
22904 return Btype;
22905 end if;
22907 elsif Is_Array_Type (Btype) then
22908 return Trace_Components (Component_Type (Btype), True);
22910 elsif Is_Record_Type (Btype) then
22911 Component := First_Entity (Btype);
22912 while Present (Component)
22913 and then Comes_From_Source (Component)
22914 loop
22915 -- Skip anonymous types generated by constrained components
22917 if not Is_Type (Component) then
22918 P := Trace_Components (Etype (Component), True);
22920 if Present (P) then
22921 if P = Any_Type then
22922 return P;
22923 else
22924 Candidate := P;
22925 end if;
22926 end if;
22927 end if;
22929 Next_Entity (Component);
22930 end loop;
22932 return Candidate;
22934 else
22935 return Empty;
22936 end if;
22937 end Trace_Components;
22939 -- Start of processing for Private_Component
22941 begin
22942 return Trace_Components (Type_Id, False);
22943 end Private_Component;
22945 ---------------------------
22946 -- Primitive_Names_Match --
22947 ---------------------------
22949 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
22950 function Non_Internal_Name (E : Entity_Id) return Name_Id;
22951 -- Given an internal name, returns the corresponding non-internal name
22953 ------------------------
22954 -- Non_Internal_Name --
22955 ------------------------
22957 function Non_Internal_Name (E : Entity_Id) return Name_Id is
22958 begin
22959 Get_Name_String (Chars (E));
22960 Name_Len := Name_Len - 1;
22961 return Name_Find;
22962 end Non_Internal_Name;
22964 -- Start of processing for Primitive_Names_Match
22966 begin
22967 pragma Assert (Present (E1) and then Present (E2));
22969 return Chars (E1) = Chars (E2)
22970 or else
22971 (not Is_Internal_Name (Chars (E1))
22972 and then Is_Internal_Name (Chars (E2))
22973 and then Non_Internal_Name (E2) = Chars (E1))
22974 or else
22975 (not Is_Internal_Name (Chars (E2))
22976 and then Is_Internal_Name (Chars (E1))
22977 and then Non_Internal_Name (E1) = Chars (E2))
22978 or else
22979 (Is_Predefined_Dispatching_Operation (E1)
22980 and then Is_Predefined_Dispatching_Operation (E2)
22981 and then Same_TSS (E1, E2))
22982 or else
22983 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
22984 end Primitive_Names_Match;
22986 -----------------------
22987 -- Process_End_Label --
22988 -----------------------
22990 procedure Process_End_Label
22991 (N : Node_Id;
22992 Typ : Character;
22993 Ent : Entity_Id)
22995 Loc : Source_Ptr;
22996 Nam : Node_Id;
22997 Scop : Entity_Id;
22999 Label_Ref : Boolean;
23000 -- Set True if reference to end label itself is required
23002 Endl : Node_Id;
23003 -- Gets set to the operator symbol or identifier that references the
23004 -- entity Ent. For the child unit case, this is the identifier from the
23005 -- designator. For other cases, this is simply Endl.
23007 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
23008 -- N is an identifier node that appears as a parent unit reference in
23009 -- the case where Ent is a child unit. This procedure generates an
23010 -- appropriate cross-reference entry. E is the corresponding entity.
23012 -------------------------
23013 -- Generate_Parent_Ref --
23014 -------------------------
23016 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
23017 begin
23018 -- If names do not match, something weird, skip reference
23020 if Chars (E) = Chars (N) then
23022 -- Generate the reference. We do NOT consider this as a reference
23023 -- for unreferenced symbol purposes.
23025 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
23027 if Style_Check then
23028 Style.Check_Identifier (N, E);
23029 end if;
23030 end if;
23031 end Generate_Parent_Ref;
23033 -- Start of processing for Process_End_Label
23035 begin
23036 -- If no node, ignore. This happens in some error situations, and
23037 -- also for some internally generated structures where no end label
23038 -- references are required in any case.
23040 if No (N) then
23041 return;
23042 end if;
23044 -- Nothing to do if no End_Label, happens for internally generated
23045 -- constructs where we don't want an end label reference anyway. Also
23046 -- nothing to do if Endl is a string literal, which means there was
23047 -- some prior error (bad operator symbol)
23049 Endl := End_Label (N);
23051 if No (Endl) or else Nkind (Endl) = N_String_Literal then
23052 return;
23053 end if;
23055 -- Reference node is not in extended main source unit
23057 if not In_Extended_Main_Source_Unit (N) then
23059 -- Generally we do not collect references except for the extended
23060 -- main source unit. The one exception is the 'e' entry for a
23061 -- package spec, where it is useful for a client to have the
23062 -- ending information to define scopes.
23064 if Typ /= 'e' then
23065 return;
23067 else
23068 Label_Ref := False;
23070 -- For this case, we can ignore any parent references, but we
23071 -- need the package name itself for the 'e' entry.
23073 if Nkind (Endl) = N_Designator then
23074 Endl := Identifier (Endl);
23075 end if;
23076 end if;
23078 -- Reference is in extended main source unit
23080 else
23081 Label_Ref := True;
23083 -- For designator, generate references for the parent entries
23085 if Nkind (Endl) = N_Designator then
23087 -- Generate references for the prefix if the END line comes from
23088 -- source (otherwise we do not need these references) We climb the
23089 -- scope stack to find the expected entities.
23091 if Comes_From_Source (Endl) then
23092 Nam := Name (Endl);
23093 Scop := Current_Scope;
23094 while Nkind (Nam) = N_Selected_Component loop
23095 Scop := Scope (Scop);
23096 exit when No (Scop);
23097 Generate_Parent_Ref (Selector_Name (Nam), Scop);
23098 Nam := Prefix (Nam);
23099 end loop;
23101 if Present (Scop) then
23102 Generate_Parent_Ref (Nam, Scope (Scop));
23103 end if;
23104 end if;
23106 Endl := Identifier (Endl);
23107 end if;
23108 end if;
23110 -- If the end label is not for the given entity, then either we have
23111 -- some previous error, or this is a generic instantiation for which
23112 -- we do not need to make a cross-reference in this case anyway. In
23113 -- either case we simply ignore the call.
23115 if Chars (Ent) /= Chars (Endl) then
23116 return;
23117 end if;
23119 -- If label was really there, then generate a normal reference and then
23120 -- adjust the location in the end label to point past the name (which
23121 -- should almost always be the semicolon).
23123 Loc := Sloc (Endl);
23125 if Comes_From_Source (Endl) then
23127 -- If a label reference is required, then do the style check and
23128 -- generate an l-type cross-reference entry for the label
23130 if Label_Ref then
23131 if Style_Check then
23132 Style.Check_Identifier (Endl, Ent);
23133 end if;
23135 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
23136 end if;
23138 -- Set the location to point past the label (normally this will
23139 -- mean the semicolon immediately following the label). This is
23140 -- done for the sake of the 'e' or 't' entry generated below.
23142 Get_Decoded_Name_String (Chars (Endl));
23143 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
23145 else
23146 -- In SPARK mode, no missing label is allowed for packages and
23147 -- subprogram bodies. Detect those cases by testing whether
23148 -- Process_End_Label was called for a body (Typ = 't') or a package.
23150 if Restriction_Check_Required (SPARK_05)
23151 and then (Typ = 't' or else Ekind (Ent) = E_Package)
23152 then
23153 Error_Msg_Node_1 := Endl;
23154 Check_SPARK_05_Restriction
23155 ("`END &` required", Endl, Force => True);
23156 end if;
23157 end if;
23159 -- Now generate the e/t reference
23161 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
23163 -- Restore Sloc, in case modified above, since we have an identifier
23164 -- and the normal Sloc should be left set in the tree.
23166 Set_Sloc (Endl, Loc);
23167 end Process_End_Label;
23169 --------------------------------
23170 -- Propagate_Concurrent_Flags --
23171 --------------------------------
23173 procedure Propagate_Concurrent_Flags
23174 (Typ : Entity_Id;
23175 Comp_Typ : Entity_Id)
23177 begin
23178 if Has_Task (Comp_Typ) then
23179 Set_Has_Task (Typ);
23180 end if;
23182 if Has_Protected (Comp_Typ) then
23183 Set_Has_Protected (Typ);
23184 end if;
23186 if Has_Timing_Event (Comp_Typ) then
23187 Set_Has_Timing_Event (Typ);
23188 end if;
23189 end Propagate_Concurrent_Flags;
23191 ------------------------------
23192 -- Propagate_DIC_Attributes --
23193 ------------------------------
23195 procedure Propagate_DIC_Attributes
23196 (Typ : Entity_Id;
23197 From_Typ : Entity_Id)
23199 DIC_Proc : Entity_Id;
23201 begin
23202 if Present (Typ) and then Present (From_Typ) then
23203 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23205 -- Nothing to do if both the source and the destination denote the
23206 -- same type.
23208 if From_Typ = Typ then
23209 return;
23210 end if;
23212 DIC_Proc := DIC_Procedure (From_Typ);
23214 -- The setting of the attributes is intentionally conservative. This
23215 -- prevents accidental clobbering of enabled attributes.
23217 if Has_Inherited_DIC (From_Typ)
23218 and then not Has_Inherited_DIC (Typ)
23219 then
23220 Set_Has_Inherited_DIC (Typ);
23221 end if;
23223 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
23224 Set_Has_Own_DIC (Typ);
23225 end if;
23227 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
23228 Set_DIC_Procedure (Typ, DIC_Proc);
23229 end if;
23230 end if;
23231 end Propagate_DIC_Attributes;
23233 ------------------------------------
23234 -- Propagate_Invariant_Attributes --
23235 ------------------------------------
23237 procedure Propagate_Invariant_Attributes
23238 (Typ : Entity_Id;
23239 From_Typ : Entity_Id)
23241 Full_IP : Entity_Id;
23242 Part_IP : Entity_Id;
23244 begin
23245 if Present (Typ) and then Present (From_Typ) then
23246 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23248 -- Nothing to do if both the source and the destination denote the
23249 -- same type.
23251 if From_Typ = Typ then
23252 return;
23253 end if;
23255 Full_IP := Invariant_Procedure (From_Typ);
23256 Part_IP := Partial_Invariant_Procedure (From_Typ);
23258 -- The setting of the attributes is intentionally conservative. This
23259 -- prevents accidental clobbering of enabled attributes.
23261 if Has_Inheritable_Invariants (From_Typ)
23262 and then not Has_Inheritable_Invariants (Typ)
23263 then
23264 Set_Has_Inheritable_Invariants (Typ);
23265 end if;
23267 if Has_Inherited_Invariants (From_Typ)
23268 and then not Has_Inherited_Invariants (Typ)
23269 then
23270 Set_Has_Inherited_Invariants (Typ);
23271 end if;
23273 if Has_Own_Invariants (From_Typ)
23274 and then not Has_Own_Invariants (Typ)
23275 then
23276 Set_Has_Own_Invariants (Typ);
23277 end if;
23279 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
23280 Set_Invariant_Procedure (Typ, Full_IP);
23281 end if;
23283 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
23284 then
23285 Set_Partial_Invariant_Procedure (Typ, Part_IP);
23286 end if;
23287 end if;
23288 end Propagate_Invariant_Attributes;
23290 ---------------------------------------
23291 -- Record_Possible_Part_Of_Reference --
23292 ---------------------------------------
23294 procedure Record_Possible_Part_Of_Reference
23295 (Var_Id : Entity_Id;
23296 Ref : Node_Id)
23298 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
23299 Refs : Elist_Id;
23301 begin
23302 -- The variable is a constituent of a single protected/task type. Such
23303 -- a variable acts as a component of the type and must appear within a
23304 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
23305 -- verify its legality now.
23307 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
23308 Check_Part_Of_Reference (Var_Id, Ref);
23310 -- The variable is subject to pragma Part_Of and may eventually become a
23311 -- constituent of a single protected/task type. Record the reference to
23312 -- verify its placement when the contract of the variable is analyzed.
23314 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
23315 Refs := Part_Of_References (Var_Id);
23317 if No (Refs) then
23318 Refs := New_Elmt_List;
23319 Set_Part_Of_References (Var_Id, Refs);
23320 end if;
23322 Append_Elmt (Ref, Refs);
23323 end if;
23324 end Record_Possible_Part_Of_Reference;
23326 ----------------
23327 -- Referenced --
23328 ----------------
23330 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
23331 Seen : Boolean := False;
23333 function Is_Reference (N : Node_Id) return Traverse_Result;
23334 -- Determine whether node N denotes a reference to Id. If this is the
23335 -- case, set global flag Seen to True and stop the traversal.
23337 ------------------
23338 -- Is_Reference --
23339 ------------------
23341 function Is_Reference (N : Node_Id) return Traverse_Result is
23342 begin
23343 if Is_Entity_Name (N)
23344 and then Present (Entity (N))
23345 and then Entity (N) = Id
23346 then
23347 Seen := True;
23348 return Abandon;
23349 else
23350 return OK;
23351 end if;
23352 end Is_Reference;
23354 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
23356 -- Start of processing for Referenced
23358 begin
23359 Inspect_Expression (Expr);
23360 return Seen;
23361 end Referenced;
23363 ------------------------------------
23364 -- References_Generic_Formal_Type --
23365 ------------------------------------
23367 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
23369 function Process (N : Node_Id) return Traverse_Result;
23370 -- Process one node in search for generic formal type
23372 -------------
23373 -- Process --
23374 -------------
23376 function Process (N : Node_Id) return Traverse_Result is
23377 begin
23378 if Nkind (N) in N_Has_Entity then
23379 declare
23380 E : constant Entity_Id := Entity (N);
23381 begin
23382 if Present (E) then
23383 if Is_Generic_Type (E) then
23384 return Abandon;
23385 elsif Present (Etype (E))
23386 and then Is_Generic_Type (Etype (E))
23387 then
23388 return Abandon;
23389 end if;
23390 end if;
23391 end;
23392 end if;
23394 return Atree.OK;
23395 end Process;
23397 function Traverse is new Traverse_Func (Process);
23398 -- Traverse tree to look for generic type
23400 begin
23401 if Inside_A_Generic then
23402 return Traverse (N) = Abandon;
23403 else
23404 return False;
23405 end if;
23406 end References_Generic_Formal_Type;
23408 -------------------------------
23409 -- Remove_Entity_And_Homonym --
23410 -------------------------------
23412 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
23413 begin
23414 Remove_Entity (Id);
23415 Remove_Homonym (Id);
23416 end Remove_Entity_And_Homonym;
23418 --------------------
23419 -- Remove_Homonym --
23420 --------------------
23422 procedure Remove_Homonym (Id : Entity_Id) is
23423 Hom : Entity_Id;
23424 Prev : Entity_Id := Empty;
23426 begin
23427 if Id = Current_Entity (Id) then
23428 if Present (Homonym (Id)) then
23429 Set_Current_Entity (Homonym (Id));
23430 else
23431 Set_Name_Entity_Id (Chars (Id), Empty);
23432 end if;
23434 else
23435 Hom := Current_Entity (Id);
23436 while Present (Hom) and then Hom /= Id loop
23437 Prev := Hom;
23438 Hom := Homonym (Hom);
23439 end loop;
23441 -- If Id is not on the homonym chain, nothing to do
23443 if Present (Hom) then
23444 Set_Homonym (Prev, Homonym (Id));
23445 end if;
23446 end if;
23447 end Remove_Homonym;
23449 ------------------------------
23450 -- Remove_Overloaded_Entity --
23451 ------------------------------
23453 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
23454 procedure Remove_Primitive_Of (Typ : Entity_Id);
23455 -- Remove primitive subprogram Id from the list of primitives that
23456 -- belong to type Typ.
23458 -------------------------
23459 -- Remove_Primitive_Of --
23460 -------------------------
23462 procedure Remove_Primitive_Of (Typ : Entity_Id) is
23463 Prims : Elist_Id;
23465 begin
23466 if Is_Tagged_Type (Typ) then
23467 Prims := Direct_Primitive_Operations (Typ);
23469 if Present (Prims) then
23470 Remove (Prims, Id);
23471 end if;
23472 end if;
23473 end Remove_Primitive_Of;
23475 -- Local variables
23477 Formal : Entity_Id;
23479 -- Start of processing for Remove_Overloaded_Entity
23481 begin
23482 Remove_Entity_And_Homonym (Id);
23484 -- The entity denotes a primitive subprogram. Remove it from the list of
23485 -- primitives of the associated controlling type.
23487 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
23488 Formal := First_Formal (Id);
23489 while Present (Formal) loop
23490 if Is_Controlling_Formal (Formal) then
23491 Remove_Primitive_Of (Etype (Formal));
23492 exit;
23493 end if;
23495 Next_Formal (Formal);
23496 end loop;
23498 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
23499 Remove_Primitive_Of (Etype (Id));
23500 end if;
23501 end if;
23502 end Remove_Overloaded_Entity;
23504 ---------------------
23505 -- Rep_To_Pos_Flag --
23506 ---------------------
23508 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
23509 begin
23510 return New_Occurrence_Of
23511 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
23512 end Rep_To_Pos_Flag;
23514 --------------------
23515 -- Require_Entity --
23516 --------------------
23518 procedure Require_Entity (N : Node_Id) is
23519 begin
23520 if Is_Entity_Name (N) and then No (Entity (N)) then
23521 if Total_Errors_Detected /= 0 then
23522 Set_Entity (N, Any_Id);
23523 else
23524 raise Program_Error;
23525 end if;
23526 end if;
23527 end Require_Entity;
23529 ------------------------------
23530 -- Requires_Transient_Scope --
23531 ------------------------------
23533 -- A transient scope is required when variable-sized temporaries are
23534 -- allocated on the secondary stack, or when finalization actions must be
23535 -- generated before the next instruction.
23537 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23538 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
23540 begin
23541 if Debug_Flag_QQ then
23542 return Old_Result;
23543 end if;
23545 declare
23546 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
23548 begin
23549 -- Assert that we're not putting things on the secondary stack if we
23550 -- didn't before; we are trying to AVOID secondary stack when
23551 -- possible.
23553 if not Old_Result then
23554 pragma Assert (not New_Result);
23555 null;
23556 end if;
23558 if New_Result /= Old_Result then
23559 Results_Differ (Id, Old_Result, New_Result);
23560 end if;
23562 return New_Result;
23563 end;
23564 end Requires_Transient_Scope;
23566 --------------------
23567 -- Results_Differ --
23568 --------------------
23570 procedure Results_Differ
23571 (Id : Entity_Id;
23572 Old_Val : Boolean;
23573 New_Val : Boolean)
23575 begin
23576 if False then -- False to disable; True for debugging
23577 Treepr.Print_Tree_Node (Id);
23579 if Old_Val = New_Val then
23580 raise Program_Error;
23581 end if;
23582 end if;
23583 end Results_Differ;
23585 --------------------------
23586 -- Reset_Analyzed_Flags --
23587 --------------------------
23589 procedure Reset_Analyzed_Flags (N : Node_Id) is
23590 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
23591 -- Function used to reset Analyzed flags in tree. Note that we do
23592 -- not reset Analyzed flags in entities, since there is no need to
23593 -- reanalyze entities, and indeed, it is wrong to do so, since it
23594 -- can result in generating auxiliary stuff more than once.
23596 --------------------
23597 -- Clear_Analyzed --
23598 --------------------
23600 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
23601 begin
23602 if Nkind (N) not in N_Entity then
23603 Set_Analyzed (N, False);
23604 end if;
23606 return OK;
23607 end Clear_Analyzed;
23609 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
23611 -- Start of processing for Reset_Analyzed_Flags
23613 begin
23614 Reset_Analyzed (N);
23615 end Reset_Analyzed_Flags;
23617 ------------------------
23618 -- Restore_SPARK_Mode --
23619 ------------------------
23621 procedure Restore_SPARK_Mode
23622 (Mode : SPARK_Mode_Type;
23623 Prag : Node_Id)
23625 begin
23626 SPARK_Mode := Mode;
23627 SPARK_Mode_Pragma := Prag;
23628 end Restore_SPARK_Mode;
23630 --------------------------------
23631 -- Returns_Unconstrained_Type --
23632 --------------------------------
23634 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
23635 begin
23636 return Ekind (Subp) = E_Function
23637 and then not Is_Scalar_Type (Etype (Subp))
23638 and then not Is_Access_Type (Etype (Subp))
23639 and then not Is_Constrained (Etype (Subp));
23640 end Returns_Unconstrained_Type;
23642 ----------------------------
23643 -- Root_Type_Of_Full_View --
23644 ----------------------------
23646 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
23647 Rtyp : constant Entity_Id := Root_Type (T);
23649 begin
23650 -- The root type of the full view may itself be a private type. Keep
23651 -- looking for the ultimate derivation parent.
23653 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
23654 return Root_Type_Of_Full_View (Full_View (Rtyp));
23655 else
23656 return Rtyp;
23657 end if;
23658 end Root_Type_Of_Full_View;
23660 ---------------------------
23661 -- Safe_To_Capture_Value --
23662 ---------------------------
23664 function Safe_To_Capture_Value
23665 (N : Node_Id;
23666 Ent : Entity_Id;
23667 Cond : Boolean := False) return Boolean
23669 begin
23670 -- The only entities for which we track constant values are variables
23671 -- which are not renamings, constants, out parameters, and in out
23672 -- parameters, so check if we have this case.
23674 -- Note: it may seem odd to track constant values for constants, but in
23675 -- fact this routine is used for other purposes than simply capturing
23676 -- the value. In particular, the setting of Known[_Non]_Null.
23678 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
23679 or else
23680 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
23681 then
23682 null;
23684 -- For conditionals, we also allow loop parameters and all formals,
23685 -- including in parameters.
23687 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
23688 null;
23690 -- For all other cases, not just unsafe, but impossible to capture
23691 -- Current_Value, since the above are the only entities which have
23692 -- Current_Value fields.
23694 else
23695 return False;
23696 end if;
23698 -- Skip if volatile or aliased, since funny things might be going on in
23699 -- these cases which we cannot necessarily track. Also skip any variable
23700 -- for which an address clause is given, or whose address is taken. Also
23701 -- never capture value of library level variables (an attempt to do so
23702 -- can occur in the case of package elaboration code).
23704 if Treat_As_Volatile (Ent)
23705 or else Is_Aliased (Ent)
23706 or else Present (Address_Clause (Ent))
23707 or else Address_Taken (Ent)
23708 or else (Is_Library_Level_Entity (Ent)
23709 and then Ekind (Ent) = E_Variable)
23710 then
23711 return False;
23712 end if;
23714 -- OK, all above conditions are met. We also require that the scope of
23715 -- the reference be the same as the scope of the entity, not counting
23716 -- packages and blocks and loops.
23718 declare
23719 E_Scope : constant Entity_Id := Scope (Ent);
23720 R_Scope : Entity_Id;
23722 begin
23723 R_Scope := Current_Scope;
23724 while R_Scope /= Standard_Standard loop
23725 exit when R_Scope = E_Scope;
23727 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
23728 return False;
23729 else
23730 R_Scope := Scope (R_Scope);
23731 end if;
23732 end loop;
23733 end;
23735 -- We also require that the reference does not appear in a context
23736 -- where it is not sure to be executed (i.e. a conditional context
23737 -- or an exception handler). We skip this if Cond is True, since the
23738 -- capturing of values from conditional tests handles this ok.
23740 if Cond then
23741 return True;
23742 end if;
23744 declare
23745 Desc : Node_Id;
23746 P : Node_Id;
23748 begin
23749 Desc := N;
23751 -- Seems dubious that case expressions are not handled here ???
23753 P := Parent (N);
23754 while Present (P) loop
23755 if Nkind (P) = N_If_Statement
23756 or else Nkind (P) = N_Case_Statement
23757 or else (Nkind (P) in N_Short_Circuit
23758 and then Desc = Right_Opnd (P))
23759 or else (Nkind (P) = N_If_Expression
23760 and then Desc /= First (Expressions (P)))
23761 or else Nkind (P) = N_Exception_Handler
23762 or else Nkind (P) = N_Selective_Accept
23763 or else Nkind (P) = N_Conditional_Entry_Call
23764 or else Nkind (P) = N_Timed_Entry_Call
23765 or else Nkind (P) = N_Asynchronous_Select
23766 then
23767 return False;
23769 else
23770 Desc := P;
23771 P := Parent (P);
23773 -- A special Ada 2012 case: the original node may be part
23774 -- of the else_actions of a conditional expression, in which
23775 -- case it might not have been expanded yet, and appears in
23776 -- a non-syntactic list of actions. In that case it is clearly
23777 -- not safe to save a value.
23779 if No (P)
23780 and then Is_List_Member (Desc)
23781 and then No (Parent (List_Containing (Desc)))
23782 then
23783 return False;
23784 end if;
23785 end if;
23786 end loop;
23787 end;
23789 -- OK, looks safe to set value
23791 return True;
23792 end Safe_To_Capture_Value;
23794 ---------------
23795 -- Same_Name --
23796 ---------------
23798 function Same_Name (N1, N2 : Node_Id) return Boolean is
23799 K1 : constant Node_Kind := Nkind (N1);
23800 K2 : constant Node_Kind := Nkind (N2);
23802 begin
23803 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
23804 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
23805 then
23806 return Chars (N1) = Chars (N2);
23808 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
23809 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
23810 then
23811 return Same_Name (Selector_Name (N1), Selector_Name (N2))
23812 and then Same_Name (Prefix (N1), Prefix (N2));
23814 else
23815 return False;
23816 end if;
23817 end Same_Name;
23819 -----------------
23820 -- Same_Object --
23821 -----------------
23823 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
23824 N1 : constant Node_Id := Original_Node (Node1);
23825 N2 : constant Node_Id := Original_Node (Node2);
23826 -- We do the tests on original nodes, since we are most interested
23827 -- in the original source, not any expansion that got in the way.
23829 K1 : constant Node_Kind := Nkind (N1);
23830 K2 : constant Node_Kind := Nkind (N2);
23832 begin
23833 -- First case, both are entities with same entity
23835 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
23836 declare
23837 EN1 : constant Entity_Id := Entity (N1);
23838 EN2 : constant Entity_Id := Entity (N2);
23839 begin
23840 if Present (EN1) and then Present (EN2)
23841 and then (Ekind_In (EN1, E_Variable, E_Constant)
23842 or else Is_Formal (EN1))
23843 and then EN1 = EN2
23844 then
23845 return True;
23846 end if;
23847 end;
23848 end if;
23850 -- Second case, selected component with same selector, same record
23852 if K1 = N_Selected_Component
23853 and then K2 = N_Selected_Component
23854 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
23855 then
23856 return Same_Object (Prefix (N1), Prefix (N2));
23858 -- Third case, indexed component with same subscripts, same array
23860 elsif K1 = N_Indexed_Component
23861 and then K2 = N_Indexed_Component
23862 and then Same_Object (Prefix (N1), Prefix (N2))
23863 then
23864 declare
23865 E1, E2 : Node_Id;
23866 begin
23867 E1 := First (Expressions (N1));
23868 E2 := First (Expressions (N2));
23869 while Present (E1) loop
23870 if not Same_Value (E1, E2) then
23871 return False;
23872 else
23873 Next (E1);
23874 Next (E2);
23875 end if;
23876 end loop;
23878 return True;
23879 end;
23881 -- Fourth case, slice of same array with same bounds
23883 elsif K1 = N_Slice
23884 and then K2 = N_Slice
23885 and then Nkind (Discrete_Range (N1)) = N_Range
23886 and then Nkind (Discrete_Range (N2)) = N_Range
23887 and then Same_Value (Low_Bound (Discrete_Range (N1)),
23888 Low_Bound (Discrete_Range (N2)))
23889 and then Same_Value (High_Bound (Discrete_Range (N1)),
23890 High_Bound (Discrete_Range (N2)))
23891 then
23892 return Same_Name (Prefix (N1), Prefix (N2));
23894 -- All other cases, not clearly the same object
23896 else
23897 return False;
23898 end if;
23899 end Same_Object;
23901 ---------------
23902 -- Same_Type --
23903 ---------------
23905 function Same_Type (T1, T2 : Entity_Id) return Boolean is
23906 begin
23907 if T1 = T2 then
23908 return True;
23910 elsif not Is_Constrained (T1)
23911 and then not Is_Constrained (T2)
23912 and then Base_Type (T1) = Base_Type (T2)
23913 then
23914 return True;
23916 -- For now don't bother with case of identical constraints, to be
23917 -- fiddled with later on perhaps (this is only used for optimization
23918 -- purposes, so it is not critical to do a best possible job)
23920 else
23921 return False;
23922 end if;
23923 end Same_Type;
23925 ----------------
23926 -- Same_Value --
23927 ----------------
23929 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
23930 begin
23931 if Compile_Time_Known_Value (Node1)
23932 and then Compile_Time_Known_Value (Node2)
23933 then
23934 -- Handle properly compile-time expressions that are not
23935 -- scalar.
23937 if Is_String_Type (Etype (Node1)) then
23938 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
23940 else
23941 return Expr_Value (Node1) = Expr_Value (Node2);
23942 end if;
23944 elsif Same_Object (Node1, Node2) then
23945 return True;
23946 else
23947 return False;
23948 end if;
23949 end Same_Value;
23951 --------------------
23952 -- Set_SPARK_Mode --
23953 --------------------
23955 procedure Set_SPARK_Mode (Context : Entity_Id) is
23956 begin
23957 -- Do not consider illegal or partially decorated constructs
23959 if Ekind (Context) = E_Void or else Error_Posted (Context) then
23960 null;
23962 elsif Present (SPARK_Pragma (Context)) then
23963 Install_SPARK_Mode
23964 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
23965 Prag => SPARK_Pragma (Context));
23966 end if;
23967 end Set_SPARK_Mode;
23969 -------------------------
23970 -- Scalar_Part_Present --
23971 -------------------------
23973 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
23974 Val_Typ : constant Entity_Id := Validated_View (Typ);
23975 Field : Entity_Id;
23977 begin
23978 if Is_Scalar_Type (Val_Typ) then
23979 return True;
23981 elsif Is_Array_Type (Val_Typ) then
23982 return Scalar_Part_Present (Component_Type (Val_Typ));
23984 elsif Is_Record_Type (Val_Typ) then
23985 Field := First_Component_Or_Discriminant (Val_Typ);
23986 while Present (Field) loop
23987 if Scalar_Part_Present (Etype (Field)) then
23988 return True;
23989 end if;
23991 Next_Component_Or_Discriminant (Field);
23992 end loop;
23993 end if;
23995 return False;
23996 end Scalar_Part_Present;
23998 ------------------------
23999 -- Scope_Is_Transient --
24000 ------------------------
24002 function Scope_Is_Transient return Boolean is
24003 begin
24004 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
24005 end Scope_Is_Transient;
24007 ------------------
24008 -- Scope_Within --
24009 ------------------
24011 function Scope_Within
24012 (Inner : Entity_Id;
24013 Outer : Entity_Id) return Boolean
24015 Curr : Entity_Id;
24017 begin
24018 Curr := Inner;
24019 while Present (Curr) and then Curr /= Standard_Standard loop
24020 Curr := Scope (Curr);
24022 if Curr = Outer then
24023 return True;
24025 -- A selective accept body appears within a task type, but the
24026 -- enclosing subprogram is the procedure of the task body.
24028 elsif Ekind (Curr) = E_Task_Type
24029 and then Outer = Task_Body_Procedure (Curr)
24030 then
24031 return True;
24033 -- Ditto for the body of a protected operation
24035 elsif Is_Subprogram (Curr)
24036 and then Outer = Protected_Body_Subprogram (Curr)
24037 then
24038 return True;
24040 -- Outside of its scope, a synchronized type may just be private
24042 elsif Is_Private_Type (Curr)
24043 and then Present (Full_View (Curr))
24044 and then Is_Concurrent_Type (Full_View (Curr))
24045 then
24046 return Scope_Within (Full_View (Curr), Outer);
24047 end if;
24048 end loop;
24050 return False;
24051 end Scope_Within;
24053 --------------------------
24054 -- Scope_Within_Or_Same --
24055 --------------------------
24057 function Scope_Within_Or_Same
24058 (Inner : Entity_Id;
24059 Outer : Entity_Id) return Boolean
24061 Curr : Entity_Id;
24063 begin
24064 Curr := Inner;
24065 while Present (Curr) and then Curr /= Standard_Standard loop
24066 if Curr = Outer then
24067 return True;
24068 end if;
24070 Curr := Scope (Curr);
24071 end loop;
24073 return False;
24074 end Scope_Within_Or_Same;
24076 --------------------
24077 -- Set_Convention --
24078 --------------------
24080 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
24081 begin
24082 Basic_Set_Convention (E, Val);
24084 if Is_Type (E)
24085 and then Is_Access_Subprogram_Type (Base_Type (E))
24086 and then Has_Foreign_Convention (E)
24087 then
24088 Set_Can_Use_Internal_Rep (E, False);
24089 end if;
24091 -- If E is an object, including a component, and the type of E is an
24092 -- anonymous access type with no convention set, then also set the
24093 -- convention of the anonymous access type. We do not do this for
24094 -- anonymous protected types, since protected types always have the
24095 -- default convention.
24097 if Present (Etype (E))
24098 and then (Is_Object (E)
24100 -- Allow E_Void (happens for pragma Convention appearing
24101 -- in the middle of a record applying to a component)
24103 or else Ekind (E) = E_Void)
24104 then
24105 declare
24106 Typ : constant Entity_Id := Etype (E);
24108 begin
24109 if Ekind_In (Typ, E_Anonymous_Access_Type,
24110 E_Anonymous_Access_Subprogram_Type)
24111 and then not Has_Convention_Pragma (Typ)
24112 then
24113 Basic_Set_Convention (Typ, Val);
24114 Set_Has_Convention_Pragma (Typ);
24116 -- And for the access subprogram type, deal similarly with the
24117 -- designated E_Subprogram_Type, which is always internal.
24119 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
24120 declare
24121 Dtype : constant Entity_Id := Designated_Type (Typ);
24122 begin
24123 if Ekind (Dtype) = E_Subprogram_Type
24124 and then not Has_Convention_Pragma (Dtype)
24125 then
24126 Basic_Set_Convention (Dtype, Val);
24127 Set_Has_Convention_Pragma (Dtype);
24128 end if;
24129 end;
24130 end if;
24131 end if;
24132 end;
24133 end if;
24134 end Set_Convention;
24136 ------------------------
24137 -- Set_Current_Entity --
24138 ------------------------
24140 -- The given entity is to be set as the currently visible definition of its
24141 -- associated name (i.e. the Node_Id associated with its name). All we have
24142 -- to do is to get the name from the identifier, and then set the
24143 -- associated Node_Id to point to the given entity.
24145 procedure Set_Current_Entity (E : Entity_Id) is
24146 begin
24147 Set_Name_Entity_Id (Chars (E), E);
24148 end Set_Current_Entity;
24150 ---------------------------
24151 -- Set_Debug_Info_Needed --
24152 ---------------------------
24154 procedure Set_Debug_Info_Needed (T : Entity_Id) is
24156 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
24157 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
24158 -- Used to set debug info in a related node if not set already
24160 --------------------------------------
24161 -- Set_Debug_Info_Needed_If_Not_Set --
24162 --------------------------------------
24164 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
24165 begin
24166 if Present (E) and then not Needs_Debug_Info (E) then
24167 Set_Debug_Info_Needed (E);
24169 -- For a private type, indicate that the full view also needs
24170 -- debug information.
24172 if Is_Type (E)
24173 and then Is_Private_Type (E)
24174 and then Present (Full_View (E))
24175 then
24176 Set_Debug_Info_Needed (Full_View (E));
24177 end if;
24178 end if;
24179 end Set_Debug_Info_Needed_If_Not_Set;
24181 -- Start of processing for Set_Debug_Info_Needed
24183 begin
24184 -- Nothing to do if there is no available entity
24186 if No (T) then
24187 return;
24189 -- Nothing to do for an entity with suppressed debug information
24191 elsif Debug_Info_Off (T) then
24192 return;
24194 -- Nothing to do for an ignored Ghost entity because the entity will be
24195 -- eliminated from the tree.
24197 elsif Is_Ignored_Ghost_Entity (T) then
24198 return;
24200 -- Nothing to do if entity comes from a predefined file. Library files
24201 -- are compiled without debug information, but inlined bodies of these
24202 -- routines may appear in user code, and debug information on them ends
24203 -- up complicating debugging the user code.
24205 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
24206 Set_Needs_Debug_Info (T, False);
24207 end if;
24209 -- Set flag in entity itself. Note that we will go through the following
24210 -- circuitry even if the flag is already set on T. That's intentional,
24211 -- it makes sure that the flag will be set in subsidiary entities.
24213 Set_Needs_Debug_Info (T);
24215 -- Set flag on subsidiary entities if not set already
24217 if Is_Object (T) then
24218 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24220 elsif Is_Type (T) then
24221 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24223 if Is_Record_Type (T) then
24224 declare
24225 Ent : Entity_Id := First_Entity (T);
24226 begin
24227 while Present (Ent) loop
24228 Set_Debug_Info_Needed_If_Not_Set (Ent);
24229 Next_Entity (Ent);
24230 end loop;
24231 end;
24233 -- For a class wide subtype, we also need debug information
24234 -- for the equivalent type.
24236 if Ekind (T) = E_Class_Wide_Subtype then
24237 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
24238 end if;
24240 elsif Is_Array_Type (T) then
24241 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
24243 declare
24244 Indx : Node_Id := First_Index (T);
24245 begin
24246 while Present (Indx) loop
24247 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
24248 Indx := Next_Index (Indx);
24249 end loop;
24250 end;
24252 -- For a packed array type, we also need debug information for
24253 -- the type used to represent the packed array. Conversely, we
24254 -- also need it for the former if we need it for the latter.
24256 if Is_Packed (T) then
24257 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
24258 end if;
24260 if Is_Packed_Array_Impl_Type (T) then
24261 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
24262 end if;
24264 elsif Is_Access_Type (T) then
24265 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
24267 elsif Is_Private_Type (T) then
24268 declare
24269 FV : constant Entity_Id := Full_View (T);
24271 begin
24272 Set_Debug_Info_Needed_If_Not_Set (FV);
24274 -- If the full view is itself a derived private type, we need
24275 -- debug information on its underlying type.
24277 if Present (FV)
24278 and then Is_Private_Type (FV)
24279 and then Present (Underlying_Full_View (FV))
24280 then
24281 Set_Needs_Debug_Info (Underlying_Full_View (FV));
24282 end if;
24283 end;
24285 elsif Is_Protected_Type (T) then
24286 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
24288 elsif Is_Scalar_Type (T) then
24290 -- If the subrange bounds are materialized by dedicated constant
24291 -- objects, also include them in the debug info to make sure the
24292 -- debugger can properly use them.
24294 if Present (Scalar_Range (T))
24295 and then Nkind (Scalar_Range (T)) = N_Range
24296 then
24297 declare
24298 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
24299 High_Bnd : constant Node_Id := Type_High_Bound (T);
24301 begin
24302 if Is_Entity_Name (Low_Bnd) then
24303 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
24304 end if;
24306 if Is_Entity_Name (High_Bnd) then
24307 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
24308 end if;
24309 end;
24310 end if;
24311 end if;
24312 end if;
24313 end Set_Debug_Info_Needed;
24315 ----------------------------
24316 -- Set_Entity_With_Checks --
24317 ----------------------------
24319 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
24320 Val_Actual : Entity_Id;
24321 Nod : Node_Id;
24322 Post_Node : Node_Id;
24324 begin
24325 -- Unconditionally set the entity
24327 Set_Entity (N, Val);
24329 -- The node to post on is the selector in the case of an expanded name,
24330 -- and otherwise the node itself.
24332 if Nkind (N) = N_Expanded_Name then
24333 Post_Node := Selector_Name (N);
24334 else
24335 Post_Node := N;
24336 end if;
24338 -- Check for violation of No_Fixed_IO
24340 if Restriction_Check_Required (No_Fixed_IO)
24341 and then
24342 ((RTU_Loaded (Ada_Text_IO)
24343 and then (Is_RTE (Val, RE_Decimal_IO)
24344 or else
24345 Is_RTE (Val, RE_Fixed_IO)))
24347 or else
24348 (RTU_Loaded (Ada_Wide_Text_IO)
24349 and then (Is_RTE (Val, RO_WT_Decimal_IO)
24350 or else
24351 Is_RTE (Val, RO_WT_Fixed_IO)))
24353 or else
24354 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
24355 and then (Is_RTE (Val, RO_WW_Decimal_IO)
24356 or else
24357 Is_RTE (Val, RO_WW_Fixed_IO))))
24359 -- A special extra check, don't complain about a reference from within
24360 -- the Ada.Interrupts package itself!
24362 and then not In_Same_Extended_Unit (N, Val)
24363 then
24364 Check_Restriction (No_Fixed_IO, Post_Node);
24365 end if;
24367 -- Remaining checks are only done on source nodes. Note that we test
24368 -- for violation of No_Fixed_IO even on non-source nodes, because the
24369 -- cases for checking violations of this restriction are instantiations
24370 -- where the reference in the instance has Comes_From_Source False.
24372 if not Comes_From_Source (N) then
24373 return;
24374 end if;
24376 -- Check for violation of No_Abort_Statements, which is triggered by
24377 -- call to Ada.Task_Identification.Abort_Task.
24379 if Restriction_Check_Required (No_Abort_Statements)
24380 and then (Is_RTE (Val, RE_Abort_Task))
24382 -- A special extra check, don't complain about a reference from within
24383 -- the Ada.Task_Identification package itself!
24385 and then not In_Same_Extended_Unit (N, Val)
24386 then
24387 Check_Restriction (No_Abort_Statements, Post_Node);
24388 end if;
24390 if Val = Standard_Long_Long_Integer then
24391 Check_Restriction (No_Long_Long_Integers, Post_Node);
24392 end if;
24394 -- Check for violation of No_Dynamic_Attachment
24396 if Restriction_Check_Required (No_Dynamic_Attachment)
24397 and then RTU_Loaded (Ada_Interrupts)
24398 and then (Is_RTE (Val, RE_Is_Reserved) or else
24399 Is_RTE (Val, RE_Is_Attached) or else
24400 Is_RTE (Val, RE_Current_Handler) or else
24401 Is_RTE (Val, RE_Attach_Handler) or else
24402 Is_RTE (Val, RE_Exchange_Handler) or else
24403 Is_RTE (Val, RE_Detach_Handler) or else
24404 Is_RTE (Val, RE_Reference))
24406 -- A special extra check, don't complain about a reference from within
24407 -- the Ada.Interrupts package itself!
24409 and then not In_Same_Extended_Unit (N, Val)
24410 then
24411 Check_Restriction (No_Dynamic_Attachment, Post_Node);
24412 end if;
24414 -- Check for No_Implementation_Identifiers
24416 if Restriction_Check_Required (No_Implementation_Identifiers) then
24418 -- We have an implementation defined entity if it is marked as
24419 -- implementation defined, or is defined in a package marked as
24420 -- implementation defined. However, library packages themselves
24421 -- are excluded (we don't want to flag Interfaces itself, just
24422 -- the entities within it).
24424 if (Is_Implementation_Defined (Val)
24425 or else
24426 (Present (Scope (Val))
24427 and then Is_Implementation_Defined (Scope (Val))))
24428 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
24429 and then Is_Library_Level_Entity (Val))
24430 then
24431 Check_Restriction (No_Implementation_Identifiers, Post_Node);
24432 end if;
24433 end if;
24435 -- Do the style check
24437 if Style_Check
24438 and then not Suppress_Style_Checks (Val)
24439 and then not In_Instance
24440 then
24441 if Nkind (N) = N_Identifier then
24442 Nod := N;
24443 elsif Nkind (N) = N_Expanded_Name then
24444 Nod := Selector_Name (N);
24445 else
24446 return;
24447 end if;
24449 -- A special situation arises for derived operations, where we want
24450 -- to do the check against the parent (since the Sloc of the derived
24451 -- operation points to the derived type declaration itself).
24453 Val_Actual := Val;
24454 while not Comes_From_Source (Val_Actual)
24455 and then Nkind (Val_Actual) in N_Entity
24456 and then (Ekind (Val_Actual) = E_Enumeration_Literal
24457 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
24458 and then Present (Alias (Val_Actual))
24459 loop
24460 Val_Actual := Alias (Val_Actual);
24461 end loop;
24463 -- Renaming declarations for generic actuals do not come from source,
24464 -- and have a different name from that of the entity they rename, so
24465 -- there is no style check to perform here.
24467 if Chars (Nod) = Chars (Val_Actual) then
24468 Style.Check_Identifier (Nod, Val_Actual);
24469 end if;
24470 end if;
24472 Set_Entity (N, Val);
24473 end Set_Entity_With_Checks;
24475 ------------------------------
24476 -- Set_Invalid_Scalar_Value --
24477 ------------------------------
24479 procedure Set_Invalid_Scalar_Value
24480 (Scal_Typ : Float_Scalar_Id;
24481 Value : Ureal)
24483 Slot : Ureal renames Invalid_Floats (Scal_Typ);
24485 begin
24486 -- Detect an attempt to set a different value for the same scalar type
24488 pragma Assert (Slot = No_Ureal);
24489 Slot := Value;
24490 end Set_Invalid_Scalar_Value;
24492 ------------------------------
24493 -- Set_Invalid_Scalar_Value --
24494 ------------------------------
24496 procedure Set_Invalid_Scalar_Value
24497 (Scal_Typ : Integer_Scalar_Id;
24498 Value : Uint)
24500 Slot : Uint renames Invalid_Integers (Scal_Typ);
24502 begin
24503 -- Detect an attempt to set a different value for the same scalar type
24505 pragma Assert (Slot = No_Uint);
24506 Slot := Value;
24507 end Set_Invalid_Scalar_Value;
24509 ------------------------
24510 -- Set_Name_Entity_Id --
24511 ------------------------
24513 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
24514 begin
24515 Set_Name_Table_Int (Id, Int (Val));
24516 end Set_Name_Entity_Id;
24518 ---------------------
24519 -- Set_Next_Actual --
24520 ---------------------
24522 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
24523 begin
24524 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
24525 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
24526 end if;
24527 end Set_Next_Actual;
24529 ----------------------------------
24530 -- Set_Optimize_Alignment_Flags --
24531 ----------------------------------
24533 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
24534 begin
24535 if Optimize_Alignment = 'S' then
24536 Set_Optimize_Alignment_Space (E);
24537 elsif Optimize_Alignment = 'T' then
24538 Set_Optimize_Alignment_Time (E);
24539 end if;
24540 end Set_Optimize_Alignment_Flags;
24542 -----------------------
24543 -- Set_Public_Status --
24544 -----------------------
24546 procedure Set_Public_Status (Id : Entity_Id) is
24547 S : constant Entity_Id := Current_Scope;
24549 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
24550 -- Determines if E is defined within handled statement sequence or
24551 -- an if statement, returns True if so, False otherwise.
24553 ----------------------
24554 -- Within_HSS_Or_If --
24555 ----------------------
24557 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
24558 N : Node_Id;
24559 begin
24560 N := Declaration_Node (E);
24561 loop
24562 N := Parent (N);
24564 if No (N) then
24565 return False;
24567 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
24568 N_If_Statement)
24569 then
24570 return True;
24571 end if;
24572 end loop;
24573 end Within_HSS_Or_If;
24575 -- Start of processing for Set_Public_Status
24577 begin
24578 -- Everything in the scope of Standard is public
24580 if S = Standard_Standard then
24581 Set_Is_Public (Id);
24583 -- Entity is definitely not public if enclosing scope is not public
24585 elsif not Is_Public (S) then
24586 return;
24588 -- An object or function declaration that occurs in a handled sequence
24589 -- of statements or within an if statement is the declaration for a
24590 -- temporary object or local subprogram generated by the expander. It
24591 -- never needs to be made public and furthermore, making it public can
24592 -- cause back end problems.
24594 elsif Nkind_In (Parent (Id), N_Object_Declaration,
24595 N_Function_Specification)
24596 and then Within_HSS_Or_If (Id)
24597 then
24598 return;
24600 -- Entities in public packages or records are public
24602 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
24603 Set_Is_Public (Id);
24605 -- The bounds of an entry family declaration can generate object
24606 -- declarations that are visible to the back-end, e.g. in the
24607 -- the declaration of a composite type that contains tasks.
24609 elsif Is_Concurrent_Type (S)
24610 and then not Has_Completion (S)
24611 and then Nkind (Parent (Id)) = N_Object_Declaration
24612 then
24613 Set_Is_Public (Id);
24614 end if;
24615 end Set_Public_Status;
24617 -----------------------------
24618 -- Set_Referenced_Modified --
24619 -----------------------------
24621 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
24622 Pref : Node_Id;
24624 begin
24625 -- Deal with indexed or selected component where prefix is modified
24627 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
24628 Pref := Prefix (N);
24630 -- If prefix is access type, then it is the designated object that is
24631 -- being modified, which means we have no entity to set the flag on.
24633 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
24634 return;
24636 -- Otherwise chase the prefix
24638 else
24639 Set_Referenced_Modified (Pref, Out_Param);
24640 end if;
24642 -- Otherwise see if we have an entity name (only other case to process)
24644 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
24645 Set_Referenced_As_LHS (Entity (N), not Out_Param);
24646 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
24647 end if;
24648 end Set_Referenced_Modified;
24650 ------------------
24651 -- Set_Rep_Info --
24652 ------------------
24654 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
24655 begin
24656 Set_Is_Atomic (T1, Is_Atomic (T2));
24657 Set_Is_Independent (T1, Is_Independent (T2));
24658 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
24660 if Is_Base_Type (T1) then
24661 Set_Is_Volatile (T1, Is_Volatile (T2));
24662 end if;
24663 end Set_Rep_Info;
24665 ----------------------------
24666 -- Set_Scope_Is_Transient --
24667 ----------------------------
24669 procedure Set_Scope_Is_Transient (V : Boolean := True) is
24670 begin
24671 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
24672 end Set_Scope_Is_Transient;
24674 -------------------
24675 -- Set_Size_Info --
24676 -------------------
24678 procedure Set_Size_Info (T1, T2 : Entity_Id) is
24679 begin
24680 -- We copy Esize, but not RM_Size, since in general RM_Size is
24681 -- subtype specific and does not get inherited by all subtypes.
24683 Set_Esize (T1, Esize (T2));
24684 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
24686 if Is_Discrete_Or_Fixed_Point_Type (T1)
24687 and then
24688 Is_Discrete_Or_Fixed_Point_Type (T2)
24689 then
24690 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
24691 end if;
24693 Set_Alignment (T1, Alignment (T2));
24694 end Set_Size_Info;
24696 ------------------------------
24697 -- Should_Ignore_Pragma_Par --
24698 ------------------------------
24700 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
24701 pragma Assert (Compiler_State = Parsing);
24702 -- This one can't work during semantic analysis, because we don't have a
24703 -- correct Current_Source_File.
24705 Result : constant Boolean :=
24706 Get_Name_Table_Boolean3 (Prag_Name)
24707 and then not Is_Internal_File_Name
24708 (File_Name (Current_Source_File));
24709 begin
24710 return Result;
24711 end Should_Ignore_Pragma_Par;
24713 ------------------------------
24714 -- Should_Ignore_Pragma_Sem --
24715 ------------------------------
24717 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
24718 pragma Assert (Compiler_State = Analyzing);
24719 Prag_Name : constant Name_Id := Pragma_Name (N);
24720 Result : constant Boolean :=
24721 Get_Name_Table_Boolean3 (Prag_Name)
24722 and then not In_Internal_Unit (N);
24724 begin
24725 return Result;
24726 end Should_Ignore_Pragma_Sem;
24728 --------------------
24729 -- Static_Boolean --
24730 --------------------
24732 function Static_Boolean (N : Node_Id) return Uint is
24733 begin
24734 Analyze_And_Resolve (N, Standard_Boolean);
24736 if N = Error
24737 or else Error_Posted (N)
24738 or else Etype (N) = Any_Type
24739 then
24740 return No_Uint;
24741 end if;
24743 if Is_OK_Static_Expression (N) then
24744 if not Raises_Constraint_Error (N) then
24745 return Expr_Value (N);
24746 else
24747 return No_Uint;
24748 end if;
24750 elsif Etype (N) = Any_Type then
24751 return No_Uint;
24753 else
24754 Flag_Non_Static_Expr
24755 ("static boolean expression required here", N);
24756 return No_Uint;
24757 end if;
24758 end Static_Boolean;
24760 --------------------
24761 -- Static_Integer --
24762 --------------------
24764 function Static_Integer (N : Node_Id) return Uint is
24765 begin
24766 Analyze_And_Resolve (N, Any_Integer);
24768 if N = Error
24769 or else Error_Posted (N)
24770 or else Etype (N) = Any_Type
24771 then
24772 return No_Uint;
24773 end if;
24775 if Is_OK_Static_Expression (N) then
24776 if not Raises_Constraint_Error (N) then
24777 return Expr_Value (N);
24778 else
24779 return No_Uint;
24780 end if;
24782 elsif Etype (N) = Any_Type then
24783 return No_Uint;
24785 else
24786 Flag_Non_Static_Expr
24787 ("static integer expression required here", N);
24788 return No_Uint;
24789 end if;
24790 end Static_Integer;
24792 --------------------------
24793 -- Statically_Different --
24794 --------------------------
24796 function Statically_Different (E1, E2 : Node_Id) return Boolean is
24797 R1 : constant Node_Id := Get_Referenced_Object (E1);
24798 R2 : constant Node_Id := Get_Referenced_Object (E2);
24799 begin
24800 return Is_Entity_Name (R1)
24801 and then Is_Entity_Name (R2)
24802 and then Entity (R1) /= Entity (R2)
24803 and then not Is_Formal (Entity (R1))
24804 and then not Is_Formal (Entity (R2));
24805 end Statically_Different;
24807 --------------------------------------
24808 -- Subject_To_Loop_Entry_Attributes --
24809 --------------------------------------
24811 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
24812 Stmt : Node_Id;
24814 begin
24815 Stmt := N;
24817 -- The expansion mechanism transform a loop subject to at least one
24818 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
24819 -- the conditional part.
24821 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
24822 and then Nkind (Original_Node (N)) = N_Loop_Statement
24823 then
24824 Stmt := Original_Node (N);
24825 end if;
24827 return
24828 Nkind (Stmt) = N_Loop_Statement
24829 and then Present (Identifier (Stmt))
24830 and then Present (Entity (Identifier (Stmt)))
24831 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
24832 end Subject_To_Loop_Entry_Attributes;
24834 -----------------------------
24835 -- Subprogram_Access_Level --
24836 -----------------------------
24838 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
24839 begin
24840 if Present (Alias (Subp)) then
24841 return Subprogram_Access_Level (Alias (Subp));
24842 else
24843 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
24844 end if;
24845 end Subprogram_Access_Level;
24847 ---------------------
24848 -- Subprogram_Name --
24849 ---------------------
24851 function Subprogram_Name (N : Node_Id) return String is
24852 Buf : Bounded_String;
24853 Ent : Node_Id := N;
24854 Nod : Node_Id;
24856 begin
24857 while Present (Ent) loop
24858 case Nkind (Ent) is
24859 when N_Subprogram_Body =>
24860 Ent := Defining_Unit_Name (Specification (Ent));
24861 exit;
24863 when N_Subprogram_Declaration =>
24864 Nod := Corresponding_Body (Ent);
24866 if Present (Nod) then
24867 Ent := Nod;
24868 else
24869 Ent := Defining_Unit_Name (Specification (Ent));
24870 end if;
24872 exit;
24874 when N_Subprogram_Instantiation
24875 | N_Package_Body
24876 | N_Package_Specification
24878 Ent := Defining_Unit_Name (Ent);
24879 exit;
24881 when N_Protected_Type_Declaration =>
24882 Ent := Corresponding_Body (Ent);
24883 exit;
24885 when N_Protected_Body
24886 | N_Task_Body
24888 Ent := Defining_Identifier (Ent);
24889 exit;
24891 when others =>
24892 null;
24893 end case;
24895 Ent := Parent (Ent);
24896 end loop;
24898 if No (Ent) then
24899 return "unknown subprogram:unknown file:0:0";
24900 end if;
24902 -- If the subprogram is a child unit, use its simple name to start the
24903 -- construction of the fully qualified name.
24905 if Nkind (Ent) = N_Defining_Program_Unit_Name then
24906 Ent := Defining_Identifier (Ent);
24907 end if;
24909 Append_Entity_Name (Buf, Ent);
24911 -- Append homonym number if needed
24913 if Nkind (N) in N_Entity and then Has_Homonym (N) then
24914 declare
24915 H : Entity_Id := Homonym (N);
24916 Nr : Nat := 1;
24918 begin
24919 while Present (H) loop
24920 if Scope (H) = Scope (N) then
24921 Nr := Nr + 1;
24922 end if;
24924 H := Homonym (H);
24925 end loop;
24927 if Nr > 1 then
24928 Append (Buf, '#');
24929 Append (Buf, Nr);
24930 end if;
24931 end;
24932 end if;
24934 -- Append source location of Ent to Buf so that the string will
24935 -- look like "subp:file:line:col".
24937 declare
24938 Loc : constant Source_Ptr := Sloc (Ent);
24939 begin
24940 Append (Buf, ':');
24941 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
24942 Append (Buf, ':');
24943 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
24944 Append (Buf, ':');
24945 Append (Buf, Nat (Get_Column_Number (Loc)));
24946 end;
24948 return +Buf;
24949 end Subprogram_Name;
24951 -------------------------------
24952 -- Support_Atomic_Primitives --
24953 -------------------------------
24955 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
24956 Size : Int;
24958 begin
24959 -- Verify the alignment of Typ is known
24961 if not Known_Alignment (Typ) then
24962 return False;
24963 end if;
24965 if Known_Static_Esize (Typ) then
24966 Size := UI_To_Int (Esize (Typ));
24968 -- If the Esize (Object_Size) is unknown at compile time, look at the
24969 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
24971 elsif Known_Static_RM_Size (Typ) then
24972 Size := UI_To_Int (RM_Size (Typ));
24974 -- Otherwise, the size is considered to be unknown.
24976 else
24977 return False;
24978 end if;
24980 -- Check that the size of the component is 8, 16, 32, or 64 bits and
24981 -- that Typ is properly aligned.
24983 case Size is
24984 when 8 | 16 | 32 | 64 =>
24985 return Size = UI_To_Int (Alignment (Typ)) * 8;
24987 when others =>
24988 return False;
24989 end case;
24990 end Support_Atomic_Primitives;
24992 -----------------
24993 -- Trace_Scope --
24994 -----------------
24996 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
24997 begin
24998 if Debug_Flag_W then
24999 for J in 0 .. Scope_Stack.Last loop
25000 Write_Str (" ");
25001 end loop;
25003 Write_Str (Msg);
25004 Write_Name (Chars (E));
25005 Write_Str (" from ");
25006 Write_Location (Sloc (N));
25007 Write_Eol;
25008 end if;
25009 end Trace_Scope;
25011 -----------------------
25012 -- Transfer_Entities --
25013 -----------------------
25015 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
25016 procedure Set_Public_Status_Of (Id : Entity_Id);
25017 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25018 -- Set_Public_Status. If successful and Id denotes a record type, set
25019 -- the Is_Public attribute of its fields.
25021 --------------------------
25022 -- Set_Public_Status_Of --
25023 --------------------------
25025 procedure Set_Public_Status_Of (Id : Entity_Id) is
25026 Field : Entity_Id;
25028 begin
25029 if not Is_Public (Id) then
25030 Set_Public_Status (Id);
25032 -- When the input entity is a public record type, ensure that all
25033 -- its internal fields are also exposed to the linker. The fields
25034 -- of a class-wide type are never made public.
25036 if Is_Public (Id)
25037 and then Is_Record_Type (Id)
25038 and then not Is_Class_Wide_Type (Id)
25039 then
25040 Field := First_Entity (Id);
25041 while Present (Field) loop
25042 Set_Is_Public (Field);
25043 Next_Entity (Field);
25044 end loop;
25045 end if;
25046 end if;
25047 end Set_Public_Status_Of;
25049 -- Local variables
25051 Full_Id : Entity_Id;
25052 Id : Entity_Id;
25054 -- Start of processing for Transfer_Entities
25056 begin
25057 Id := First_Entity (From);
25059 if Present (Id) then
25061 -- Merge the entity chain of the source scope with that of the
25062 -- destination scope.
25064 if Present (Last_Entity (To)) then
25065 Link_Entities (Last_Entity (To), Id);
25066 else
25067 Set_First_Entity (To, Id);
25068 end if;
25070 Set_Last_Entity (To, Last_Entity (From));
25072 -- Inspect the entities of the source scope and update their Scope
25073 -- attribute.
25075 while Present (Id) loop
25076 Set_Scope (Id, To);
25077 Set_Public_Status_Of (Id);
25079 -- Handle an internally generated full view for a private type
25081 if Is_Private_Type (Id)
25082 and then Present (Full_View (Id))
25083 and then Is_Itype (Full_View (Id))
25084 then
25085 Full_Id := Full_View (Id);
25087 Set_Scope (Full_Id, To);
25088 Set_Public_Status_Of (Full_Id);
25089 end if;
25091 Next_Entity (Id);
25092 end loop;
25094 Set_First_Entity (From, Empty);
25095 Set_Last_Entity (From, Empty);
25096 end if;
25097 end Transfer_Entities;
25099 -----------------------
25100 -- Type_Access_Level --
25101 -----------------------
25103 function Type_Access_Level (Typ : Entity_Id) return Uint is
25104 Btyp : Entity_Id;
25106 begin
25107 Btyp := Base_Type (Typ);
25109 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
25110 -- simply use the level where the type is declared. This is true for
25111 -- stand-alone object declarations, and for anonymous access types
25112 -- associated with components the level is the same as that of the
25113 -- enclosing composite type. However, special treatment is needed for
25114 -- the cases of access parameters, return objects of an anonymous access
25115 -- type, and, in Ada 95, access discriminants of limited types.
25117 if Is_Access_Type (Btyp) then
25118 if Ekind (Btyp) = E_Anonymous_Access_Type then
25120 -- If the type is a nonlocal anonymous access type (such as for
25121 -- an access parameter) we treat it as being declared at the
25122 -- library level to ensure that names such as X.all'access don't
25123 -- fail static accessibility checks.
25125 if not Is_Local_Anonymous_Access (Typ) then
25126 return Scope_Depth (Standard_Standard);
25128 -- If this is a return object, the accessibility level is that of
25129 -- the result subtype of the enclosing function. The test here is
25130 -- little complicated, because we have to account for extended
25131 -- return statements that have been rewritten as blocks, in which
25132 -- case we have to find and the Is_Return_Object attribute of the
25133 -- itype's associated object. It would be nice to find a way to
25134 -- simplify this test, but it doesn't seem worthwhile to add a new
25135 -- flag just for purposes of this test. ???
25137 elsif Ekind (Scope (Btyp)) = E_Return_Statement
25138 or else
25139 (Is_Itype (Btyp)
25140 and then Nkind (Associated_Node_For_Itype (Btyp)) =
25141 N_Object_Declaration
25142 and then Is_Return_Object
25143 (Defining_Identifier
25144 (Associated_Node_For_Itype (Btyp))))
25145 then
25146 declare
25147 Scop : Entity_Id;
25149 begin
25150 Scop := Scope (Scope (Btyp));
25151 while Present (Scop) loop
25152 exit when Ekind (Scop) = E_Function;
25153 Scop := Scope (Scop);
25154 end loop;
25156 -- Treat the return object's type as having the level of the
25157 -- function's result subtype (as per RM05-6.5(5.3/2)).
25159 return Type_Access_Level (Etype (Scop));
25160 end;
25161 end if;
25162 end if;
25164 Btyp := Root_Type (Btyp);
25166 -- The accessibility level of anonymous access types associated with
25167 -- discriminants is that of the current instance of the type, and
25168 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
25170 -- AI-402: access discriminants have accessibility based on the
25171 -- object rather than the type in Ada 2005, so the above paragraph
25172 -- doesn't apply.
25174 -- ??? Needs completion with rules from AI-416
25176 if Ada_Version <= Ada_95
25177 and then Ekind (Typ) = E_Anonymous_Access_Type
25178 and then Present (Associated_Node_For_Itype (Typ))
25179 and then Nkind (Associated_Node_For_Itype (Typ)) =
25180 N_Discriminant_Specification
25181 then
25182 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
25183 end if;
25184 end if;
25186 -- Return library level for a generic formal type. This is done because
25187 -- RM(10.3.2) says that "The statically deeper relationship does not
25188 -- apply to ... a descendant of a generic formal type". Rather than
25189 -- checking at each point where a static accessibility check is
25190 -- performed to see if we are dealing with a formal type, this rule is
25191 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
25192 -- return extreme values for a formal type; Deepest_Type_Access_Level
25193 -- returns Int'Last. By calling the appropriate function from among the
25194 -- two, we ensure that the static accessibility check will pass if we
25195 -- happen to run into a formal type. More specifically, we should call
25196 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
25197 -- call occurs as part of a static accessibility check and the error
25198 -- case is the case where the type's level is too shallow (as opposed
25199 -- to too deep).
25201 if Is_Generic_Type (Root_Type (Btyp)) then
25202 return Scope_Depth (Standard_Standard);
25203 end if;
25205 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
25206 end Type_Access_Level;
25208 ------------------------------------
25209 -- Type_Without_Stream_Operation --
25210 ------------------------------------
25212 function Type_Without_Stream_Operation
25213 (T : Entity_Id;
25214 Op : TSS_Name_Type := TSS_Null) return Entity_Id
25216 BT : constant Entity_Id := Base_Type (T);
25217 Op_Missing : Boolean;
25219 begin
25220 if not Restriction_Active (No_Default_Stream_Attributes) then
25221 return Empty;
25222 end if;
25224 if Is_Elementary_Type (T) then
25225 if Op = TSS_Null then
25226 Op_Missing :=
25227 No (TSS (BT, TSS_Stream_Read))
25228 or else No (TSS (BT, TSS_Stream_Write));
25230 else
25231 Op_Missing := No (TSS (BT, Op));
25232 end if;
25234 if Op_Missing then
25235 return T;
25236 else
25237 return Empty;
25238 end if;
25240 elsif Is_Array_Type (T) then
25241 return Type_Without_Stream_Operation (Component_Type (T), Op);
25243 elsif Is_Record_Type (T) then
25244 declare
25245 Comp : Entity_Id;
25246 C_Typ : Entity_Id;
25248 begin
25249 Comp := First_Component (T);
25250 while Present (Comp) loop
25251 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
25253 if Present (C_Typ) then
25254 return C_Typ;
25255 end if;
25257 Next_Component (Comp);
25258 end loop;
25260 return Empty;
25261 end;
25263 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
25264 return Type_Without_Stream_Operation (Full_View (T), Op);
25265 else
25266 return Empty;
25267 end if;
25268 end Type_Without_Stream_Operation;
25270 ---------------------
25271 -- Ultimate_Prefix --
25272 ---------------------
25274 function Ultimate_Prefix (N : Node_Id) return Node_Id is
25275 Pref : Node_Id;
25277 begin
25278 Pref := N;
25279 while Nkind_In (Pref, N_Explicit_Dereference,
25280 N_Indexed_Component,
25281 N_Selected_Component,
25282 N_Slice)
25283 loop
25284 Pref := Prefix (Pref);
25285 end loop;
25287 return Pref;
25288 end Ultimate_Prefix;
25290 ----------------------------
25291 -- Unique_Defining_Entity --
25292 ----------------------------
25294 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
25295 begin
25296 return Unique_Entity (Defining_Entity (N));
25297 end Unique_Defining_Entity;
25299 -------------------
25300 -- Unique_Entity --
25301 -------------------
25303 function Unique_Entity (E : Entity_Id) return Entity_Id is
25304 U : Entity_Id := E;
25305 P : Node_Id;
25307 begin
25308 case Ekind (E) is
25309 when E_Constant =>
25310 if Present (Full_View (E)) then
25311 U := Full_View (E);
25312 end if;
25314 when Entry_Kind =>
25315 if Nkind (Parent (E)) = N_Entry_Body then
25316 declare
25317 Prot_Item : Entity_Id;
25318 Prot_Type : Entity_Id;
25320 begin
25321 if Ekind (E) = E_Entry then
25322 Prot_Type := Scope (E);
25324 -- Bodies of entry families are nested within an extra scope
25325 -- that contains an entry index declaration.
25327 else
25328 Prot_Type := Scope (Scope (E));
25329 end if;
25331 -- A protected type may be declared as a private type, in
25332 -- which case we need to get its full view.
25334 if Is_Private_Type (Prot_Type) then
25335 Prot_Type := Full_View (Prot_Type);
25336 end if;
25338 -- Full view may not be present on error, in which case
25339 -- return E by default.
25341 if Present (Prot_Type) then
25342 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
25344 -- Traverse the entity list of the protected type and
25345 -- locate an entry declaration which matches the entry
25346 -- body.
25348 Prot_Item := First_Entity (Prot_Type);
25349 while Present (Prot_Item) loop
25350 if Ekind (Prot_Item) in Entry_Kind
25351 and then Corresponding_Body (Parent (Prot_Item)) = E
25352 then
25353 U := Prot_Item;
25354 exit;
25355 end if;
25357 Next_Entity (Prot_Item);
25358 end loop;
25359 end if;
25360 end;
25361 end if;
25363 when Formal_Kind =>
25364 if Present (Spec_Entity (E)) then
25365 U := Spec_Entity (E);
25366 end if;
25368 when E_Package_Body =>
25369 P := Parent (E);
25371 if Nkind (P) = N_Defining_Program_Unit_Name then
25372 P := Parent (P);
25373 end if;
25375 if Nkind (P) = N_Package_Body
25376 and then Present (Corresponding_Spec (P))
25377 then
25378 U := Corresponding_Spec (P);
25380 elsif Nkind (P) = N_Package_Body_Stub
25381 and then Present (Corresponding_Spec_Of_Stub (P))
25382 then
25383 U := Corresponding_Spec_Of_Stub (P);
25384 end if;
25386 when E_Protected_Body =>
25387 P := Parent (E);
25389 if Nkind (P) = N_Protected_Body
25390 and then Present (Corresponding_Spec (P))
25391 then
25392 U := Corresponding_Spec (P);
25394 elsif Nkind (P) = N_Protected_Body_Stub
25395 and then Present (Corresponding_Spec_Of_Stub (P))
25396 then
25397 U := Corresponding_Spec_Of_Stub (P);
25399 if Is_Single_Protected_Object (U) then
25400 U := Etype (U);
25401 end if;
25402 end if;
25404 if Is_Private_Type (U) then
25405 U := Full_View (U);
25406 end if;
25408 when E_Subprogram_Body =>
25409 P := Parent (E);
25411 if Nkind (P) = N_Defining_Program_Unit_Name then
25412 P := Parent (P);
25413 end if;
25415 P := Parent (P);
25417 if Nkind (P) = N_Subprogram_Body
25418 and then Present (Corresponding_Spec (P))
25419 then
25420 U := Corresponding_Spec (P);
25422 elsif Nkind (P) = N_Subprogram_Body_Stub
25423 and then Present (Corresponding_Spec_Of_Stub (P))
25424 then
25425 U := Corresponding_Spec_Of_Stub (P);
25427 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
25428 U := Corresponding_Spec (P);
25429 end if;
25431 when E_Task_Body =>
25432 P := Parent (E);
25434 if Nkind (P) = N_Task_Body
25435 and then Present (Corresponding_Spec (P))
25436 then
25437 U := Corresponding_Spec (P);
25439 elsif Nkind (P) = N_Task_Body_Stub
25440 and then Present (Corresponding_Spec_Of_Stub (P))
25441 then
25442 U := Corresponding_Spec_Of_Stub (P);
25444 if Is_Single_Task_Object (U) then
25445 U := Etype (U);
25446 end if;
25447 end if;
25449 if Is_Private_Type (U) then
25450 U := Full_View (U);
25451 end if;
25453 when Type_Kind =>
25454 if Present (Full_View (E)) then
25455 U := Full_View (E);
25456 end if;
25458 when others =>
25459 null;
25460 end case;
25462 return U;
25463 end Unique_Entity;
25465 -----------------
25466 -- Unique_Name --
25467 -----------------
25469 function Unique_Name (E : Entity_Id) return String is
25471 -- Names in E_Subprogram_Body or E_Package_Body entities are not
25472 -- reliable, as they may not include the overloading suffix. Instead,
25473 -- when looking for the name of E or one of its enclosing scope, we get
25474 -- the name of the corresponding Unique_Entity.
25476 U : constant Entity_Id := Unique_Entity (E);
25478 function This_Name return String;
25480 ---------------
25481 -- This_Name --
25482 ---------------
25484 function This_Name return String is
25485 begin
25486 return Get_Name_String (Chars (U));
25487 end This_Name;
25489 -- Start of processing for Unique_Name
25491 begin
25492 if E = Standard_Standard
25493 or else Has_Fully_Qualified_Name (E)
25494 then
25495 return This_Name;
25497 elsif Ekind (E) = E_Enumeration_Literal then
25498 return Unique_Name (Etype (E)) & "__" & This_Name;
25500 else
25501 declare
25502 S : constant Entity_Id := Scope (U);
25503 pragma Assert (Present (S));
25505 begin
25506 -- Prefix names of predefined types with standard__, but leave
25507 -- names of user-defined packages and subprograms without prefix
25508 -- (even if technically they are nested in the Standard package).
25510 if S = Standard_Standard then
25511 if Ekind (U) = E_Package or else Is_Subprogram (U) then
25512 return This_Name;
25513 else
25514 return Unique_Name (S) & "__" & This_Name;
25515 end if;
25517 -- For intances of generic subprograms use the name of the related
25518 -- instace and skip the scope of its wrapper package.
25520 elsif Is_Wrapper_Package (S) then
25521 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
25522 -- Wrapper package and the instantiation are in the same scope
25524 declare
25525 Enclosing_Name : constant String :=
25526 Unique_Name (Scope (S)) & "__" &
25527 Get_Name_String (Chars (Related_Instance (S)));
25529 begin
25530 if Is_Subprogram (U)
25531 and then not Is_Generic_Actual_Subprogram (U)
25532 then
25533 return Enclosing_Name;
25534 else
25535 return Enclosing_Name & "__" & This_Name;
25536 end if;
25537 end;
25539 else
25540 return Unique_Name (S) & "__" & This_Name;
25541 end if;
25542 end;
25543 end if;
25544 end Unique_Name;
25546 ---------------------
25547 -- Unit_Is_Visible --
25548 ---------------------
25550 function Unit_Is_Visible (U : Entity_Id) return Boolean is
25551 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
25552 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
25554 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
25555 -- For a child unit, check whether unit appears in a with_clause
25556 -- of a parent.
25558 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
25559 -- Scan the context clause of one compilation unit looking for a
25560 -- with_clause for the unit in question.
25562 ----------------------------
25563 -- Unit_In_Parent_Context --
25564 ----------------------------
25566 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
25567 begin
25568 if Unit_In_Context (Par_Unit) then
25569 return True;
25571 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
25572 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
25574 else
25575 return False;
25576 end if;
25577 end Unit_In_Parent_Context;
25579 ---------------------
25580 -- Unit_In_Context --
25581 ---------------------
25583 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
25584 Clause : Node_Id;
25586 begin
25587 Clause := First (Context_Items (Comp_Unit));
25588 while Present (Clause) loop
25589 if Nkind (Clause) = N_With_Clause then
25590 if Library_Unit (Clause) = U then
25591 return True;
25593 -- The with_clause may denote a renaming of the unit we are
25594 -- looking for, eg. Text_IO which renames Ada.Text_IO.
25596 elsif
25597 Renamed_Entity (Entity (Name (Clause))) =
25598 Defining_Entity (Unit (U))
25599 then
25600 return True;
25601 end if;
25602 end if;
25604 Next (Clause);
25605 end loop;
25607 return False;
25608 end Unit_In_Context;
25610 -- Start of processing for Unit_Is_Visible
25612 begin
25613 -- The currrent unit is directly visible
25615 if Curr = U then
25616 return True;
25618 elsif Unit_In_Context (Curr) then
25619 return True;
25621 -- If the current unit is a body, check the context of the spec
25623 elsif Nkind (Unit (Curr)) = N_Package_Body
25624 or else
25625 (Nkind (Unit (Curr)) = N_Subprogram_Body
25626 and then not Acts_As_Spec (Unit (Curr)))
25627 then
25628 if Unit_In_Context (Library_Unit (Curr)) then
25629 return True;
25630 end if;
25631 end if;
25633 -- If the spec is a child unit, examine the parents
25635 if Is_Child_Unit (Curr_Entity) then
25636 if Nkind (Unit (Curr)) in N_Unit_Body then
25637 return
25638 Unit_In_Parent_Context
25639 (Parent_Spec (Unit (Library_Unit (Curr))));
25640 else
25641 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
25642 end if;
25644 else
25645 return False;
25646 end if;
25647 end Unit_Is_Visible;
25649 ------------------------------
25650 -- Universal_Interpretation --
25651 ------------------------------
25653 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
25654 Index : Interp_Index;
25655 It : Interp;
25657 begin
25658 -- The argument may be a formal parameter of an operator or subprogram
25659 -- with multiple interpretations, or else an expression for an actual.
25661 if Nkind (Opnd) = N_Defining_Identifier
25662 or else not Is_Overloaded (Opnd)
25663 then
25664 if Etype (Opnd) = Universal_Integer
25665 or else Etype (Opnd) = Universal_Real
25666 then
25667 return Etype (Opnd);
25668 else
25669 return Empty;
25670 end if;
25672 else
25673 Get_First_Interp (Opnd, Index, It);
25674 while Present (It.Typ) loop
25675 if It.Typ = Universal_Integer
25676 or else It.Typ = Universal_Real
25677 then
25678 return It.Typ;
25679 end if;
25681 Get_Next_Interp (Index, It);
25682 end loop;
25684 return Empty;
25685 end if;
25686 end Universal_Interpretation;
25688 ---------------
25689 -- Unqualify --
25690 ---------------
25692 function Unqualify (Expr : Node_Id) return Node_Id is
25693 begin
25694 -- Recurse to handle unlikely case of multiple levels of qualification
25696 if Nkind (Expr) = N_Qualified_Expression then
25697 return Unqualify (Expression (Expr));
25699 -- Normal case, not a qualified expression
25701 else
25702 return Expr;
25703 end if;
25704 end Unqualify;
25706 -----------------
25707 -- Unqual_Conv --
25708 -----------------
25710 function Unqual_Conv (Expr : Node_Id) return Node_Id is
25711 begin
25712 -- Recurse to handle unlikely case of multiple levels of qualification
25713 -- and/or conversion.
25715 if Nkind_In (Expr, N_Qualified_Expression,
25716 N_Type_Conversion,
25717 N_Unchecked_Type_Conversion)
25718 then
25719 return Unqual_Conv (Expression (Expr));
25721 -- Normal case, not a qualified expression
25723 else
25724 return Expr;
25725 end if;
25726 end Unqual_Conv;
25728 --------------------
25729 -- Validated_View --
25730 --------------------
25732 function Validated_View (Typ : Entity_Id) return Entity_Id is
25733 Continue : Boolean;
25734 Val_Typ : Entity_Id;
25736 begin
25737 Continue := True;
25738 Val_Typ := Base_Type (Typ);
25740 -- Obtain the full view of the input type by stripping away concurrency,
25741 -- derivations, and privacy.
25743 while Continue loop
25744 Continue := False;
25746 if Is_Concurrent_Type (Val_Typ) then
25747 if Present (Corresponding_Record_Type (Val_Typ)) then
25748 Continue := True;
25749 Val_Typ := Corresponding_Record_Type (Val_Typ);
25750 end if;
25752 elsif Is_Derived_Type (Val_Typ) then
25753 Continue := True;
25754 Val_Typ := Etype (Val_Typ);
25756 elsif Is_Private_Type (Val_Typ) then
25757 if Present (Underlying_Full_View (Val_Typ)) then
25758 Continue := True;
25759 Val_Typ := Underlying_Full_View (Val_Typ);
25761 elsif Present (Full_View (Val_Typ)) then
25762 Continue := True;
25763 Val_Typ := Full_View (Val_Typ);
25764 end if;
25765 end if;
25766 end loop;
25768 return Val_Typ;
25769 end Validated_View;
25771 -----------------------
25772 -- Visible_Ancestors --
25773 -----------------------
25775 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
25776 List_1 : Elist_Id;
25777 List_2 : Elist_Id;
25778 Elmt : Elmt_Id;
25780 begin
25781 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
25783 -- Collect all the parents and progenitors of Typ. If the full-view of
25784 -- private parents and progenitors is available then it is used to
25785 -- generate the list of visible ancestors; otherwise their partial
25786 -- view is added to the resulting list.
25788 Collect_Parents
25789 (T => Typ,
25790 List => List_1,
25791 Use_Full_View => True);
25793 Collect_Interfaces
25794 (T => Typ,
25795 Ifaces_List => List_2,
25796 Exclude_Parents => True,
25797 Use_Full_View => True);
25799 -- Join the two lists. Avoid duplications because an interface may
25800 -- simultaneously be parent and progenitor of a type.
25802 Elmt := First_Elmt (List_2);
25803 while Present (Elmt) loop
25804 Append_Unique_Elmt (Node (Elmt), List_1);
25805 Next_Elmt (Elmt);
25806 end loop;
25808 return List_1;
25809 end Visible_Ancestors;
25811 ----------------------
25812 -- Within_Init_Proc --
25813 ----------------------
25815 function Within_Init_Proc return Boolean is
25816 S : Entity_Id;
25818 begin
25819 S := Current_Scope;
25820 while not Is_Overloadable (S) loop
25821 if S = Standard_Standard then
25822 return False;
25823 else
25824 S := Scope (S);
25825 end if;
25826 end loop;
25828 return Is_Init_Proc (S);
25829 end Within_Init_Proc;
25831 ---------------------------
25832 -- Within_Protected_Type --
25833 ---------------------------
25835 function Within_Protected_Type (E : Entity_Id) return Boolean is
25836 Scop : Entity_Id := Scope (E);
25838 begin
25839 while Present (Scop) loop
25840 if Ekind (Scop) = E_Protected_Type then
25841 return True;
25842 end if;
25844 Scop := Scope (Scop);
25845 end loop;
25847 return False;
25848 end Within_Protected_Type;
25850 ------------------
25851 -- Within_Scope --
25852 ------------------
25854 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
25855 begin
25856 return Scope_Within_Or_Same (Scope (E), S);
25857 end Within_Scope;
25859 ----------------------------
25860 -- Within_Subprogram_Call --
25861 ----------------------------
25863 function Within_Subprogram_Call (N : Node_Id) return Boolean is
25864 Par : Node_Id;
25866 begin
25867 -- Climb the parent chain looking for a function or procedure call
25869 Par := N;
25870 while Present (Par) loop
25871 if Nkind_In (Par, N_Entry_Call_Statement,
25872 N_Function_Call,
25873 N_Procedure_Call_Statement)
25874 then
25875 return True;
25877 -- Prevent the search from going too far
25879 elsif Is_Body_Or_Package_Declaration (Par) then
25880 exit;
25881 end if;
25883 Par := Parent (Par);
25884 end loop;
25886 return False;
25887 end Within_Subprogram_Call;
25889 ----------------
25890 -- Wrong_Type --
25891 ----------------
25893 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
25894 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
25895 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
25897 Matching_Field : Entity_Id;
25898 -- Entity to give a more precise suggestion on how to write a one-
25899 -- element positional aggregate.
25901 function Has_One_Matching_Field return Boolean;
25902 -- Determines if Expec_Type is a record type with a single component or
25903 -- discriminant whose type matches the found type or is one dimensional
25904 -- array whose component type matches the found type. In the case of
25905 -- one discriminant, we ignore the variant parts. That's not accurate,
25906 -- but good enough for the warning.
25908 ----------------------------
25909 -- Has_One_Matching_Field --
25910 ----------------------------
25912 function Has_One_Matching_Field return Boolean is
25913 E : Entity_Id;
25915 begin
25916 Matching_Field := Empty;
25918 if Is_Array_Type (Expec_Type)
25919 and then Number_Dimensions (Expec_Type) = 1
25920 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
25921 then
25922 -- Use type name if available. This excludes multidimensional
25923 -- arrays and anonymous arrays.
25925 if Comes_From_Source (Expec_Type) then
25926 Matching_Field := Expec_Type;
25928 -- For an assignment, use name of target
25930 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
25931 and then Is_Entity_Name (Name (Parent (Expr)))
25932 then
25933 Matching_Field := Entity (Name (Parent (Expr)));
25934 end if;
25936 return True;
25938 elsif not Is_Record_Type (Expec_Type) then
25939 return False;
25941 else
25942 E := First_Entity (Expec_Type);
25943 loop
25944 if No (E) then
25945 return False;
25947 elsif not Ekind_In (E, E_Discriminant, E_Component)
25948 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
25949 then
25950 Next_Entity (E);
25952 else
25953 exit;
25954 end if;
25955 end loop;
25957 if not Covers (Etype (E), Found_Type) then
25958 return False;
25960 elsif Present (Next_Entity (E))
25961 and then (Ekind (E) = E_Component
25962 or else Ekind (Next_Entity (E)) = E_Discriminant)
25963 then
25964 return False;
25966 else
25967 Matching_Field := E;
25968 return True;
25969 end if;
25970 end if;
25971 end Has_One_Matching_Field;
25973 -- Start of processing for Wrong_Type
25975 begin
25976 -- Don't output message if either type is Any_Type, or if a message
25977 -- has already been posted for this node. We need to do the latter
25978 -- check explicitly (it is ordinarily done in Errout), because we
25979 -- are using ! to force the output of the error messages.
25981 if Expec_Type = Any_Type
25982 or else Found_Type = Any_Type
25983 or else Error_Posted (Expr)
25984 then
25985 return;
25987 -- If one of the types is a Taft-Amendment type and the other it its
25988 -- completion, it must be an illegal use of a TAT in the spec, for
25989 -- which an error was already emitted. Avoid cascaded errors.
25991 elsif Is_Incomplete_Type (Expec_Type)
25992 and then Has_Completion_In_Body (Expec_Type)
25993 and then Full_View (Expec_Type) = Etype (Expr)
25994 then
25995 return;
25997 elsif Is_Incomplete_Type (Etype (Expr))
25998 and then Has_Completion_In_Body (Etype (Expr))
25999 and then Full_View (Etype (Expr)) = Expec_Type
26000 then
26001 return;
26003 -- In an instance, there is an ongoing problem with completion of
26004 -- type derived from private types. Their structure is what Gigi
26005 -- expects, but the Etype is the parent type rather than the
26006 -- derived private type itself. Do not flag error in this case. The
26007 -- private completion is an entity without a parent, like an Itype.
26008 -- Similarly, full and partial views may be incorrect in the instance.
26009 -- There is no simple way to insure that it is consistent ???
26011 -- A similar view discrepancy can happen in an inlined body, for the
26012 -- same reason: inserted body may be outside of the original package
26013 -- and only partial views are visible at the point of insertion.
26015 elsif In_Instance or else In_Inlined_Body then
26016 if Etype (Etype (Expr)) = Etype (Expected_Type)
26017 and then
26018 (Has_Private_Declaration (Expected_Type)
26019 or else Has_Private_Declaration (Etype (Expr)))
26020 and then No (Parent (Expected_Type))
26021 then
26022 return;
26024 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
26025 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
26026 then
26027 return;
26029 elsif Is_Private_Type (Expected_Type)
26030 and then Present (Full_View (Expected_Type))
26031 and then Covers (Full_View (Expected_Type), Etype (Expr))
26032 then
26033 return;
26035 -- Conversely, type of expression may be the private one
26037 elsif Is_Private_Type (Base_Type (Etype (Expr)))
26038 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
26039 then
26040 return;
26041 end if;
26042 end if;
26044 -- An interesting special check. If the expression is parenthesized
26045 -- and its type corresponds to the type of the sole component of the
26046 -- expected record type, or to the component type of the expected one
26047 -- dimensional array type, then assume we have a bad aggregate attempt.
26049 if Nkind (Expr) in N_Subexpr
26050 and then Paren_Count (Expr) /= 0
26051 and then Has_One_Matching_Field
26052 then
26053 Error_Msg_N ("positional aggregate cannot have one component", Expr);
26055 if Present (Matching_Field) then
26056 if Is_Array_Type (Expec_Type) then
26057 Error_Msg_NE
26058 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
26059 else
26060 Error_Msg_NE
26061 ("\write instead `& ='> ...`", Expr, Matching_Field);
26062 end if;
26063 end if;
26065 -- Another special check, if we are looking for a pool-specific access
26066 -- type and we found an E_Access_Attribute_Type, then we have the case
26067 -- of an Access attribute being used in a context which needs a pool-
26068 -- specific type, which is never allowed. The one extra check we make
26069 -- is that the expected designated type covers the Found_Type.
26071 elsif Is_Access_Type (Expec_Type)
26072 and then Ekind (Found_Type) = E_Access_Attribute_Type
26073 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
26074 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
26075 and then Covers
26076 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
26077 then
26078 Error_Msg_N -- CODEFIX
26079 ("result must be general access type!", Expr);
26080 Error_Msg_NE -- CODEFIX
26081 ("add ALL to }!", Expr, Expec_Type);
26083 -- Another special check, if the expected type is an integer type,
26084 -- but the expression is of type System.Address, and the parent is
26085 -- an addition or subtraction operation whose left operand is the
26086 -- expression in question and whose right operand is of an integral
26087 -- type, then this is an attempt at address arithmetic, so give
26088 -- appropriate message.
26090 elsif Is_Integer_Type (Expec_Type)
26091 and then Is_RTE (Found_Type, RE_Address)
26092 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
26093 and then Expr = Left_Opnd (Parent (Expr))
26094 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
26095 then
26096 Error_Msg_N
26097 ("address arithmetic not predefined in package System",
26098 Parent (Expr));
26099 Error_Msg_N
26100 ("\possible missing with/use of System.Storage_Elements",
26101 Parent (Expr));
26102 return;
26104 -- If the expected type is an anonymous access type, as for access
26105 -- parameters and discriminants, the error is on the designated types.
26107 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
26108 if Comes_From_Source (Expec_Type) then
26109 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26110 else
26111 Error_Msg_NE
26112 ("expected an access type with designated}",
26113 Expr, Designated_Type (Expec_Type));
26114 end if;
26116 if Is_Access_Type (Found_Type)
26117 and then not Comes_From_Source (Found_Type)
26118 then
26119 Error_Msg_NE
26120 ("\\found an access type with designated}!",
26121 Expr, Designated_Type (Found_Type));
26122 else
26123 if From_Limited_With (Found_Type) then
26124 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
26125 Error_Msg_Qual_Level := 99;
26126 Error_Msg_NE -- CODEFIX
26127 ("\\missing `WITH &;", Expr, Scope (Found_Type));
26128 Error_Msg_Qual_Level := 0;
26129 else
26130 Error_Msg_NE ("found}!", Expr, Found_Type);
26131 end if;
26132 end if;
26134 -- Normal case of one type found, some other type expected
26136 else
26137 -- If the names of the two types are the same, see if some number
26138 -- of levels of qualification will help. Don't try more than three
26139 -- levels, and if we get to standard, it's no use (and probably
26140 -- represents an error in the compiler) Also do not bother with
26141 -- internal scope names.
26143 declare
26144 Expec_Scope : Entity_Id;
26145 Found_Scope : Entity_Id;
26147 begin
26148 Expec_Scope := Expec_Type;
26149 Found_Scope := Found_Type;
26151 for Levels in Nat range 0 .. 3 loop
26152 if Chars (Expec_Scope) /= Chars (Found_Scope) then
26153 Error_Msg_Qual_Level := Levels;
26154 exit;
26155 end if;
26157 Expec_Scope := Scope (Expec_Scope);
26158 Found_Scope := Scope (Found_Scope);
26160 exit when Expec_Scope = Standard_Standard
26161 or else Found_Scope = Standard_Standard
26162 or else not Comes_From_Source (Expec_Scope)
26163 or else not Comes_From_Source (Found_Scope);
26164 end loop;
26165 end;
26167 if Is_Record_Type (Expec_Type)
26168 and then Present (Corresponding_Remote_Type (Expec_Type))
26169 then
26170 Error_Msg_NE ("expected}!", Expr,
26171 Corresponding_Remote_Type (Expec_Type));
26172 else
26173 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26174 end if;
26176 if Is_Entity_Name (Expr)
26177 and then Is_Package_Or_Generic_Package (Entity (Expr))
26178 then
26179 Error_Msg_N ("\\found package name!", Expr);
26181 elsif Is_Entity_Name (Expr)
26182 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
26183 then
26184 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
26185 Error_Msg_N
26186 ("found procedure name, possibly missing Access attribute!",
26187 Expr);
26188 else
26189 Error_Msg_N
26190 ("\\found procedure name instead of function!", Expr);
26191 end if;
26193 elsif Nkind (Expr) = N_Function_Call
26194 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
26195 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
26196 and then No (Parameter_Associations (Expr))
26197 then
26198 Error_Msg_N
26199 ("found function name, possibly missing Access attribute!",
26200 Expr);
26202 -- Catch common error: a prefix or infix operator which is not
26203 -- directly visible because the type isn't.
26205 elsif Nkind (Expr) in N_Op
26206 and then Is_Overloaded (Expr)
26207 and then not Is_Immediately_Visible (Expec_Type)
26208 and then not Is_Potentially_Use_Visible (Expec_Type)
26209 and then not In_Use (Expec_Type)
26210 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
26211 then
26212 Error_Msg_N
26213 ("operator of the type is not directly visible!", Expr);
26215 elsif Ekind (Found_Type) = E_Void
26216 and then Present (Parent (Found_Type))
26217 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
26218 then
26219 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
26221 else
26222 Error_Msg_NE ("\\found}!", Expr, Found_Type);
26223 end if;
26225 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
26226 -- of the same modular type, and (M1 and M2) = 0 was intended.
26228 if Expec_Type = Standard_Boolean
26229 and then Is_Modular_Integer_Type (Found_Type)
26230 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
26231 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
26232 then
26233 declare
26234 Op : constant Node_Id := Right_Opnd (Parent (Expr));
26235 L : constant Node_Id := Left_Opnd (Op);
26236 R : constant Node_Id := Right_Opnd (Op);
26238 begin
26239 -- The case for the message is when the left operand of the
26240 -- comparison is the same modular type, or when it is an
26241 -- integer literal (or other universal integer expression),
26242 -- which would have been typed as the modular type if the
26243 -- parens had been there.
26245 if (Etype (L) = Found_Type
26246 or else
26247 Etype (L) = Universal_Integer)
26248 and then Is_Integer_Type (Etype (R))
26249 then
26250 Error_Msg_N
26251 ("\\possible missing parens for modular operation", Expr);
26252 end if;
26253 end;
26254 end if;
26256 -- Reset error message qualification indication
26258 Error_Msg_Qual_Level := 0;
26259 end if;
26260 end Wrong_Type;
26262 --------------------------------
26263 -- Yields_Synchronized_Object --
26264 --------------------------------
26266 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
26267 Has_Sync_Comp : Boolean := False;
26268 Id : Entity_Id;
26270 begin
26271 -- An array type yields a synchronized object if its component type
26272 -- yields a synchronized object.
26274 if Is_Array_Type (Typ) then
26275 return Yields_Synchronized_Object (Component_Type (Typ));
26277 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
26278 -- yields a synchronized object by default.
26280 elsif Is_Descendant_Of_Suspension_Object (Typ) then
26281 return True;
26283 -- A protected type yields a synchronized object by default
26285 elsif Is_Protected_Type (Typ) then
26286 return True;
26288 -- A record type or type extension yields a synchronized object when its
26289 -- discriminants (if any) lack default values and all components are of
26290 -- a type that yelds a synchronized object.
26292 elsif Is_Record_Type (Typ) then
26294 -- Inspect all entities defined in the scope of the type, looking for
26295 -- components of a type that does not yeld a synchronized object or
26296 -- for discriminants with default values.
26298 Id := First_Entity (Typ);
26299 while Present (Id) loop
26300 if Comes_From_Source (Id) then
26301 if Ekind (Id) = E_Component then
26302 if Yields_Synchronized_Object (Etype (Id)) then
26303 Has_Sync_Comp := True;
26305 -- The component does not yield a synchronized object
26307 else
26308 return False;
26309 end if;
26311 elsif Ekind (Id) = E_Discriminant
26312 and then Present (Expression (Parent (Id)))
26313 then
26314 return False;
26315 end if;
26316 end if;
26318 Next_Entity (Id);
26319 end loop;
26321 -- Ensure that the parent type of a type extension yields a
26322 -- synchronized object.
26324 if Etype (Typ) /= Typ
26325 and then not Yields_Synchronized_Object (Etype (Typ))
26326 then
26327 return False;
26328 end if;
26330 -- If we get here, then all discriminants lack default values and all
26331 -- components are of a type that yields a synchronized object.
26333 return Has_Sync_Comp;
26335 -- A synchronized interface type yields a synchronized object by default
26337 elsif Is_Synchronized_Interface (Typ) then
26338 return True;
26340 -- A task type yelds a synchronized object by default
26342 elsif Is_Task_Type (Typ) then
26343 return True;
26345 -- Otherwise the type does not yield a synchronized object
26347 else
26348 return False;
26349 end if;
26350 end Yields_Synchronized_Object;
26352 ---------------------------
26353 -- Yields_Universal_Type --
26354 ---------------------------
26356 function Yields_Universal_Type (N : Node_Id) return Boolean is
26357 begin
26358 -- Integer and real literals are of a universal type
26360 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
26361 return True;
26363 -- The values of certain attributes are of a universal type
26365 elsif Nkind (N) = N_Attribute_Reference then
26366 return
26367 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
26369 -- ??? There are possibly other cases to consider
26371 else
26372 return False;
26373 end if;
26374 end Yields_Universal_Type;
26376 begin
26377 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
26378 end Sem_Util;