gcc/testsuite/ChangeLog:
[official-gcc.git] / gcc / ada / sem_util.adb
blobbfa2b4fb141fa2e81e5144f94d30e08487ec633f
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,
8597 N_Identifier,
8598 N_Selected_Component)
8599 then
8600 if Global_Mode = Name_Input then
8601 return List;
8602 else
8603 return Empty;
8604 end if;
8606 -- Simple global list (only input items) or moded global list
8607 -- declaration.
8609 elsif Nkind (List) = N_Aggregate then
8610 if Present (Expressions (List)) then
8611 if Global_Mode = Name_Input then
8612 return First (Expressions (List));
8613 else
8614 return Empty;
8615 end if;
8617 else
8618 Assoc := First (Component_Associations (List));
8619 while Present (Assoc) loop
8621 -- When we find the desired mode in an association, call
8622 -- recursively First_From_Global_List as if the mode was
8623 -- Name_Input, in order to reuse the existing machinery
8624 -- for the other cases.
8626 if Chars (First (Choices (Assoc))) = Global_Mode then
8627 return First_From_Global_List (Expression (Assoc));
8628 end if;
8630 Next (Assoc);
8631 end loop;
8633 return Empty;
8634 end if;
8636 -- To accommodate partial decoration of disabled SPARK features,
8637 -- this routine may be called with illegal input. If this is the
8638 -- case, do not raise Program_Error.
8640 else
8641 return Empty;
8642 end if;
8643 end First_From_Global_List;
8645 -- Local variables
8647 Global : Node_Id := Empty;
8648 Body_Id : Entity_Id;
8650 begin
8651 pragma Assert (Global_Mode = Name_Input
8652 or else Global_Mode = Name_Output
8653 or else Global_Mode = Name_In_Out
8654 or else Global_Mode = Name_Proof_In);
8656 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8657 -- case, it can only be located on the body entity.
8659 if Refined then
8660 Body_Id := Subprogram_Body_Entity (Subp);
8661 if Present (Body_Id) then
8662 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8663 end if;
8664 else
8665 Global := Get_Pragma (Subp, Pragma_Global);
8666 end if;
8668 -- No corresponding global if pragma is not present
8670 if No (Global) then
8671 return Empty;
8673 -- Otherwise retrieve the corresponding list of items depending on the
8674 -- Global_Mode.
8676 else
8677 return First_From_Global_List
8678 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8679 end if;
8680 end First_Global;
8682 -------------
8683 -- Fix_Msg --
8684 -------------
8686 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8687 Is_Task : constant Boolean :=
8688 Ekind_In (Id, E_Task_Body, E_Task_Type)
8689 or else Is_Single_Task_Object (Id);
8690 Msg_Last : constant Natural := Msg'Last;
8691 Msg_Index : Natural;
8692 Res : String (Msg'Range) := (others => ' ');
8693 Res_Index : Natural;
8695 begin
8696 -- Copy all characters from the input message Msg to result Res with
8697 -- suitable replacements.
8699 Msg_Index := Msg'First;
8700 Res_Index := Res'First;
8701 while Msg_Index <= Msg_Last loop
8703 -- Replace "subprogram" with a different word
8705 if Msg_Index <= Msg_Last - 10
8706 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8707 then
8708 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8709 Res (Res_Index .. Res_Index + 4) := "entry";
8710 Res_Index := Res_Index + 5;
8712 elsif Is_Task then
8713 Res (Res_Index .. Res_Index + 8) := "task type";
8714 Res_Index := Res_Index + 9;
8716 else
8717 Res (Res_Index .. Res_Index + 9) := "subprogram";
8718 Res_Index := Res_Index + 10;
8719 end if;
8721 Msg_Index := Msg_Index + 10;
8723 -- Replace "protected" with a different word
8725 elsif Msg_Index <= Msg_Last - 9
8726 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8727 and then Is_Task
8728 then
8729 Res (Res_Index .. Res_Index + 3) := "task";
8730 Res_Index := Res_Index + 4;
8731 Msg_Index := Msg_Index + 9;
8733 -- Otherwise copy the character
8735 else
8736 Res (Res_Index) := Msg (Msg_Index);
8737 Msg_Index := Msg_Index + 1;
8738 Res_Index := Res_Index + 1;
8739 end if;
8740 end loop;
8742 return Res (Res'First .. Res_Index - 1);
8743 end Fix_Msg;
8745 -------------------------
8746 -- From_Nested_Package --
8747 -------------------------
8749 function From_Nested_Package (T : Entity_Id) return Boolean is
8750 Pack : constant Entity_Id := Scope (T);
8752 begin
8753 return
8754 Ekind (Pack) = E_Package
8755 and then not Is_Frozen (Pack)
8756 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8757 and then In_Open_Scopes (Scope (Pack));
8758 end From_Nested_Package;
8760 -----------------------
8761 -- Gather_Components --
8762 -----------------------
8764 procedure Gather_Components
8765 (Typ : Entity_Id;
8766 Comp_List : Node_Id;
8767 Governed_By : List_Id;
8768 Into : Elist_Id;
8769 Report_Errors : out Boolean)
8771 Assoc : Node_Id;
8772 Variant : Node_Id;
8773 Discrete_Choice : Node_Id;
8774 Comp_Item : Node_Id;
8776 Discrim : Entity_Id;
8777 Discrim_Name : Node_Id;
8778 Discrim_Value : Node_Id;
8780 begin
8781 Report_Errors := False;
8783 if No (Comp_List) or else Null_Present (Comp_List) then
8784 return;
8786 elsif Present (Component_Items (Comp_List)) then
8787 Comp_Item := First (Component_Items (Comp_List));
8789 else
8790 Comp_Item := Empty;
8791 end if;
8793 while Present (Comp_Item) loop
8795 -- Skip the tag of a tagged record, the interface tags, as well
8796 -- as all items that are not user components (anonymous types,
8797 -- rep clauses, Parent field, controller field).
8799 if Nkind (Comp_Item) = N_Component_Declaration then
8800 declare
8801 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8802 begin
8803 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8804 Append_Elmt (Comp, Into);
8805 end if;
8806 end;
8807 end if;
8809 Next (Comp_Item);
8810 end loop;
8812 if No (Variant_Part (Comp_List)) then
8813 return;
8814 else
8815 Discrim_Name := Name (Variant_Part (Comp_List));
8816 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8817 end if;
8819 -- Look for the discriminant that governs this variant part.
8820 -- The discriminant *must* be in the Governed_By List
8822 Assoc := First (Governed_By);
8823 Find_Constraint : loop
8824 Discrim := First (Choices (Assoc));
8825 exit Find_Constraint when
8826 Chars (Discrim_Name) = Chars (Discrim)
8827 or else
8828 (Present (Corresponding_Discriminant (Entity (Discrim)))
8829 and then Chars (Corresponding_Discriminant
8830 (Entity (Discrim))) = Chars (Discrim_Name))
8831 or else
8832 Chars (Original_Record_Component (Entity (Discrim))) =
8833 Chars (Discrim_Name);
8835 if No (Next (Assoc)) then
8836 if not Is_Constrained (Typ) and then Is_Derived_Type (Typ) then
8838 -- If the type is a tagged type with inherited discriminants,
8839 -- use the stored constraint on the parent in order to find
8840 -- the values of discriminants that are otherwise hidden by an
8841 -- explicit constraint. Renamed discriminants are handled in
8842 -- the code above.
8844 -- If several parent discriminants are renamed by a single
8845 -- discriminant of the derived type, the call to obtain the
8846 -- Corresponding_Discriminant field only retrieves the last
8847 -- of them. We recover the constraint on the others from the
8848 -- Stored_Constraint as well.
8850 -- An inherited discriminant may have been constrained in a
8851 -- later ancestor (not the immediate parent) so we must examine
8852 -- the stored constraint of all of them to locate the inherited
8853 -- value.
8855 declare
8856 C : Elmt_Id;
8857 D : Entity_Id;
8858 T : Entity_Id := Typ;
8860 begin
8861 while Is_Derived_Type (T) loop
8862 if Present (Stored_Constraint (T)) then
8863 D := First_Discriminant (Etype (T));
8864 C := First_Elmt (Stored_Constraint (T));
8865 while Present (D) and then Present (C) loop
8866 if Chars (Discrim_Name) = Chars (D) then
8867 if Is_Entity_Name (Node (C))
8868 and then Entity (Node (C)) = Entity (Discrim)
8869 then
8870 -- D is renamed by Discrim, whose value is
8871 -- given in Assoc.
8873 null;
8875 else
8876 Assoc :=
8877 Make_Component_Association (Sloc (Typ),
8878 New_List
8879 (New_Occurrence_Of (D, Sloc (Typ))),
8880 Duplicate_Subexpr_No_Checks (Node (C)));
8881 end if;
8883 exit Find_Constraint;
8884 end if;
8886 Next_Discriminant (D);
8887 Next_Elmt (C);
8888 end loop;
8889 end if;
8891 -- Discriminant may be inherited from ancestor
8893 T := Etype (T);
8894 end loop;
8895 end;
8896 end if;
8897 end if;
8899 if No (Next (Assoc)) then
8900 Error_Msg_NE
8901 (" missing value for discriminant&",
8902 First (Governed_By), Discrim_Name);
8904 Report_Errors := True;
8905 return;
8906 end if;
8908 Next (Assoc);
8909 end loop Find_Constraint;
8911 Discrim_Value := Expression (Assoc);
8913 if not Is_OK_Static_Expression (Discrim_Value) then
8915 -- If the variant part is governed by a discriminant of the type
8916 -- this is an error. If the variant part and the discriminant are
8917 -- inherited from an ancestor this is legal (AI05-120) unless the
8918 -- components are being gathered for an aggregate, in which case
8919 -- the caller must check Report_Errors.
8921 if Scope (Original_Record_Component
8922 ((Entity (First (Choices (Assoc)))))) = Typ
8923 then
8924 Error_Msg_FE
8925 ("value for discriminant & must be static!",
8926 Discrim_Value, Discrim);
8927 Why_Not_Static (Discrim_Value);
8928 end if;
8930 Report_Errors := True;
8931 return;
8932 end if;
8934 Search_For_Discriminant_Value : declare
8935 Low : Node_Id;
8936 High : Node_Id;
8938 UI_High : Uint;
8939 UI_Low : Uint;
8940 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8942 begin
8943 Find_Discrete_Value : while Present (Variant) loop
8944 Discrete_Choice := First (Discrete_Choices (Variant));
8945 while Present (Discrete_Choice) loop
8946 exit Find_Discrete_Value when
8947 Nkind (Discrete_Choice) = N_Others_Choice;
8949 Get_Index_Bounds (Discrete_Choice, Low, High);
8951 UI_Low := Expr_Value (Low);
8952 UI_High := Expr_Value (High);
8954 exit Find_Discrete_Value when
8955 UI_Low <= UI_Discrim_Value
8956 and then
8957 UI_High >= UI_Discrim_Value;
8959 Next (Discrete_Choice);
8960 end loop;
8962 Next_Non_Pragma (Variant);
8963 end loop Find_Discrete_Value;
8964 end Search_For_Discriminant_Value;
8966 -- The case statement must include a variant that corresponds to the
8967 -- value of the discriminant, unless the discriminant type has a
8968 -- static predicate. In that case the absence of an others_choice that
8969 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8971 if No (Variant)
8972 and then not Has_Static_Predicate (Etype (Discrim_Name))
8973 then
8974 Error_Msg_NE
8975 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8976 Report_Errors := True;
8977 return;
8978 end if;
8980 -- If we have found the corresponding choice, recursively add its
8981 -- components to the Into list. The nested components are part of
8982 -- the same record type.
8984 if Present (Variant) then
8985 Gather_Components
8986 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8987 end if;
8988 end Gather_Components;
8990 ------------------------
8991 -- Get_Actual_Subtype --
8992 ------------------------
8994 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8995 Typ : constant Entity_Id := Etype (N);
8996 Utyp : Entity_Id := Underlying_Type (Typ);
8997 Decl : Node_Id;
8998 Atyp : Entity_Id;
9000 begin
9001 if No (Utyp) then
9002 Utyp := Typ;
9003 end if;
9005 -- If what we have is an identifier that references a subprogram
9006 -- formal, or a variable or constant object, then we get the actual
9007 -- subtype from the referenced entity if one has been built.
9009 if Nkind (N) = N_Identifier
9010 and then
9011 (Is_Formal (Entity (N))
9012 or else Ekind (Entity (N)) = E_Constant
9013 or else Ekind (Entity (N)) = E_Variable)
9014 and then Present (Actual_Subtype (Entity (N)))
9015 then
9016 return Actual_Subtype (Entity (N));
9018 -- Actual subtype of unchecked union is always itself. We never need
9019 -- the "real" actual subtype. If we did, we couldn't get it anyway
9020 -- because the discriminant is not available. The restrictions on
9021 -- Unchecked_Union are designed to make sure that this is OK.
9023 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
9024 return Typ;
9026 -- Here for the unconstrained case, we must find actual subtype
9027 -- No actual subtype is available, so we must build it on the fly.
9029 -- Checking the type, not the underlying type, for constrainedness
9030 -- seems to be necessary. Maybe all the tests should be on the type???
9032 elsif (not Is_Constrained (Typ))
9033 and then (Is_Array_Type (Utyp)
9034 or else (Is_Record_Type (Utyp)
9035 and then Has_Discriminants (Utyp)))
9036 and then not Has_Unknown_Discriminants (Utyp)
9037 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9038 then
9039 -- Nothing to do if in spec expression (why not???)
9041 if In_Spec_Expression then
9042 return Typ;
9044 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9046 -- If the type has no discriminants, there is no subtype to
9047 -- build, even if the underlying type is discriminated.
9049 return Typ;
9051 -- Else build the actual subtype
9053 else
9054 Decl := Build_Actual_Subtype (Typ, N);
9055 Atyp := Defining_Identifier (Decl);
9057 -- If Build_Actual_Subtype generated a new declaration then use it
9059 if Atyp /= Typ then
9061 -- The actual subtype is an Itype, so analyze the declaration,
9062 -- but do not attach it to the tree, to get the type defined.
9064 Set_Parent (Decl, N);
9065 Set_Is_Itype (Atyp);
9066 Analyze (Decl, Suppress => All_Checks);
9067 Set_Associated_Node_For_Itype (Atyp, N);
9068 Set_Has_Delayed_Freeze (Atyp, False);
9070 -- We need to freeze the actual subtype immediately. This is
9071 -- needed, because otherwise this Itype will not get frozen
9072 -- at all, and it is always safe to freeze on creation because
9073 -- any associated types must be frozen at this point.
9075 Freeze_Itype (Atyp, N);
9076 return Atyp;
9078 -- Otherwise we did not build a declaration, so return original
9080 else
9081 return Typ;
9082 end if;
9083 end if;
9085 -- For all remaining cases, the actual subtype is the same as
9086 -- the nominal type.
9088 else
9089 return Typ;
9090 end if;
9091 end Get_Actual_Subtype;
9093 -------------------------------------
9094 -- Get_Actual_Subtype_If_Available --
9095 -------------------------------------
9097 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
9098 Typ : constant Entity_Id := Etype (N);
9100 begin
9101 -- If what we have is an identifier that references a subprogram
9102 -- formal, or a variable or constant object, then we get the actual
9103 -- subtype from the referenced entity if one has been built.
9105 if Nkind (N) = N_Identifier
9106 and then
9107 (Is_Formal (Entity (N))
9108 or else Ekind (Entity (N)) = E_Constant
9109 or else Ekind (Entity (N)) = E_Variable)
9110 and then Present (Actual_Subtype (Entity (N)))
9111 then
9112 return Actual_Subtype (Entity (N));
9114 -- Otherwise the Etype of N is returned unchanged
9116 else
9117 return Typ;
9118 end if;
9119 end Get_Actual_Subtype_If_Available;
9121 ------------------------
9122 -- Get_Body_From_Stub --
9123 ------------------------
9125 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
9126 begin
9127 return Proper_Body (Unit (Library_Unit (N)));
9128 end Get_Body_From_Stub;
9130 ---------------------
9131 -- Get_Cursor_Type --
9132 ---------------------
9134 function Get_Cursor_Type
9135 (Aspect : Node_Id;
9136 Typ : Entity_Id) return Entity_Id
9138 Assoc : Node_Id;
9139 Func : Entity_Id;
9140 First_Op : Entity_Id;
9141 Cursor : Entity_Id;
9143 begin
9144 -- If error already detected, return
9146 if Error_Posted (Aspect) then
9147 return Any_Type;
9148 end if;
9150 -- The cursor type for an Iterable aspect is the return type of a
9151 -- non-overloaded First primitive operation. Locate association for
9152 -- First.
9154 Assoc := First (Component_Associations (Expression (Aspect)));
9155 First_Op := Any_Id;
9156 while Present (Assoc) loop
9157 if Chars (First (Choices (Assoc))) = Name_First then
9158 First_Op := Expression (Assoc);
9159 exit;
9160 end if;
9162 Next (Assoc);
9163 end loop;
9165 if First_Op = Any_Id then
9166 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
9167 return Any_Type;
9168 end if;
9170 Cursor := Any_Type;
9172 -- Locate function with desired name and profile in scope of type
9173 -- In the rare case where the type is an integer type, a base type
9174 -- is created for it, check that the base type of the first formal
9175 -- of First matches the base type of the domain.
9177 Func := First_Entity (Scope (Typ));
9178 while Present (Func) loop
9179 if Chars (Func) = Chars (First_Op)
9180 and then Ekind (Func) = E_Function
9181 and then Present (First_Formal (Func))
9182 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
9183 and then No (Next_Formal (First_Formal (Func)))
9184 then
9185 if Cursor /= Any_Type then
9186 Error_Msg_N
9187 ("Operation First for iterable type must be unique", Aspect);
9188 return Any_Type;
9189 else
9190 Cursor := Etype (Func);
9191 end if;
9192 end if;
9194 Next_Entity (Func);
9195 end loop;
9197 -- If not found, no way to resolve remaining primitives.
9199 if Cursor = Any_Type then
9200 Error_Msg_N
9201 ("No legal primitive operation First for Iterable type", Aspect);
9202 end if;
9204 return Cursor;
9205 end Get_Cursor_Type;
9207 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9208 begin
9209 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9210 end Get_Cursor_Type;
9212 -------------------------------
9213 -- Get_Default_External_Name --
9214 -------------------------------
9216 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9217 begin
9218 Get_Decoded_Name_String (Chars (E));
9220 if Opt.External_Name_Imp_Casing = Uppercase then
9221 Set_Casing (All_Upper_Case);
9222 else
9223 Set_Casing (All_Lower_Case);
9224 end if;
9226 return
9227 Make_String_Literal (Sloc (E),
9228 Strval => String_From_Name_Buffer);
9229 end Get_Default_External_Name;
9231 --------------------------
9232 -- Get_Enclosing_Object --
9233 --------------------------
9235 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9236 begin
9237 if Is_Entity_Name (N) then
9238 return Entity (N);
9239 else
9240 case Nkind (N) is
9241 when N_Indexed_Component
9242 | N_Selected_Component
9243 | N_Slice
9245 -- If not generating code, a dereference may be left implicit.
9246 -- In thoses cases, return Empty.
9248 if Is_Access_Type (Etype (Prefix (N))) then
9249 return Empty;
9250 else
9251 return Get_Enclosing_Object (Prefix (N));
9252 end if;
9254 when N_Type_Conversion =>
9255 return Get_Enclosing_Object (Expression (N));
9257 when others =>
9258 return Empty;
9259 end case;
9260 end if;
9261 end Get_Enclosing_Object;
9263 ---------------------------
9264 -- Get_Enum_Lit_From_Pos --
9265 ---------------------------
9267 function Get_Enum_Lit_From_Pos
9268 (T : Entity_Id;
9269 Pos : Uint;
9270 Loc : Source_Ptr) return Node_Id
9272 Btyp : Entity_Id := Base_Type (T);
9273 Lit : Node_Id;
9274 LLoc : Source_Ptr;
9276 begin
9277 -- In the case where the literal is of type Character, Wide_Character
9278 -- or Wide_Wide_Character or of a type derived from them, there needs
9279 -- to be some special handling since there is no explicit chain of
9280 -- literals to search. Instead, an N_Character_Literal node is created
9281 -- with the appropriate Char_Code and Chars fields.
9283 if Is_Standard_Character_Type (T) then
9284 Set_Character_Literal_Name (UI_To_CC (Pos));
9286 return
9287 Make_Character_Literal (Loc,
9288 Chars => Name_Find,
9289 Char_Literal_Value => Pos);
9291 -- For all other cases, we have a complete table of literals, and
9292 -- we simply iterate through the chain of literal until the one
9293 -- with the desired position value is found.
9295 else
9296 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9297 Btyp := Full_View (Btyp);
9298 end if;
9300 Lit := First_Literal (Btyp);
9302 -- Position in the enumeration type starts at 0
9304 if UI_To_Int (Pos) < 0 then
9305 raise Constraint_Error;
9306 end if;
9308 for J in 1 .. UI_To_Int (Pos) loop
9309 Next_Literal (Lit);
9311 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9312 -- inside the loop to avoid calling Next_Literal on Empty.
9314 if No (Lit) then
9315 raise Constraint_Error;
9316 end if;
9317 end loop;
9319 -- Create a new node from Lit, with source location provided by Loc
9320 -- if not equal to No_Location, or by copying the source location of
9321 -- Lit otherwise.
9323 LLoc := Loc;
9325 if LLoc = No_Location then
9326 LLoc := Sloc (Lit);
9327 end if;
9329 return New_Occurrence_Of (Lit, LLoc);
9330 end if;
9331 end Get_Enum_Lit_From_Pos;
9333 ------------------------
9334 -- Get_Generic_Entity --
9335 ------------------------
9337 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9338 Ent : constant Entity_Id := Entity (Name (N));
9339 begin
9340 if Present (Renamed_Object (Ent)) then
9341 return Renamed_Object (Ent);
9342 else
9343 return Ent;
9344 end if;
9345 end Get_Generic_Entity;
9347 -------------------------------------
9348 -- Get_Incomplete_View_Of_Ancestor --
9349 -------------------------------------
9351 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9352 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9353 Par_Scope : Entity_Id;
9354 Par_Type : Entity_Id;
9356 begin
9357 -- The incomplete view of an ancestor is only relevant for private
9358 -- derived types in child units.
9360 if not Is_Derived_Type (E)
9361 or else not Is_Child_Unit (Cur_Unit)
9362 then
9363 return Empty;
9365 else
9366 Par_Scope := Scope (Cur_Unit);
9367 if No (Par_Scope) then
9368 return Empty;
9369 end if;
9371 Par_Type := Etype (Base_Type (E));
9373 -- Traverse list of ancestor types until we find one declared in
9374 -- a parent or grandparent unit (two levels seem sufficient).
9376 while Present (Par_Type) loop
9377 if Scope (Par_Type) = Par_Scope
9378 or else Scope (Par_Type) = Scope (Par_Scope)
9379 then
9380 return Par_Type;
9382 elsif not Is_Derived_Type (Par_Type) then
9383 return Empty;
9385 else
9386 Par_Type := Etype (Base_Type (Par_Type));
9387 end if;
9388 end loop;
9390 -- If none found, there is no relevant ancestor type.
9392 return Empty;
9393 end if;
9394 end Get_Incomplete_View_Of_Ancestor;
9396 ----------------------
9397 -- Get_Index_Bounds --
9398 ----------------------
9400 procedure Get_Index_Bounds
9401 (N : Node_Id;
9402 L : out Node_Id;
9403 H : out Node_Id;
9404 Use_Full_View : Boolean := False)
9406 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9407 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9408 -- Typ qualifies, the scalar range is obtained from the full view of the
9409 -- type.
9411 --------------------------
9412 -- Scalar_Range_Of_Type --
9413 --------------------------
9415 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9416 T : Entity_Id := Typ;
9418 begin
9419 if Use_Full_View and then Present (Full_View (T)) then
9420 T := Full_View (T);
9421 end if;
9423 return Scalar_Range (T);
9424 end Scalar_Range_Of_Type;
9426 -- Local variables
9428 Kind : constant Node_Kind := Nkind (N);
9429 Rng : Node_Id;
9431 -- Start of processing for Get_Index_Bounds
9433 begin
9434 if Kind = N_Range then
9435 L := Low_Bound (N);
9436 H := High_Bound (N);
9438 elsif Kind = N_Subtype_Indication then
9439 Rng := Range_Expression (Constraint (N));
9441 if Rng = Error then
9442 L := Error;
9443 H := Error;
9444 return;
9446 else
9447 L := Low_Bound (Range_Expression (Constraint (N)));
9448 H := High_Bound (Range_Expression (Constraint (N)));
9449 end if;
9451 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9452 Rng := Scalar_Range_Of_Type (Entity (N));
9454 if Error_Posted (Rng) then
9455 L := Error;
9456 H := Error;
9458 elsif Nkind (Rng) = N_Subtype_Indication then
9459 Get_Index_Bounds (Rng, L, H);
9461 else
9462 L := Low_Bound (Rng);
9463 H := High_Bound (Rng);
9464 end if;
9466 else
9467 -- N is an expression, indicating a range with one value
9469 L := N;
9470 H := N;
9471 end if;
9472 end Get_Index_Bounds;
9474 -----------------------------
9475 -- Get_Interfacing_Aspects --
9476 -----------------------------
9478 procedure Get_Interfacing_Aspects
9479 (Iface_Asp : Node_Id;
9480 Conv_Asp : out Node_Id;
9481 EN_Asp : out Node_Id;
9482 Expo_Asp : out Node_Id;
9483 Imp_Asp : out Node_Id;
9484 LN_Asp : out Node_Id;
9485 Do_Checks : Boolean := False)
9487 procedure Save_Or_Duplication_Error
9488 (Asp : Node_Id;
9489 To : in out Node_Id);
9490 -- Save the value of aspect Asp in node To. If To already has a value,
9491 -- then this is considered a duplicate use of aspect. Emit an error if
9492 -- flag Do_Checks is set.
9494 -------------------------------
9495 -- Save_Or_Duplication_Error --
9496 -------------------------------
9498 procedure Save_Or_Duplication_Error
9499 (Asp : Node_Id;
9500 To : in out Node_Id)
9502 begin
9503 -- Detect an extra aspect and issue an error
9505 if Present (To) then
9506 if Do_Checks then
9507 Error_Msg_Name_1 := Chars (Identifier (Asp));
9508 Error_Msg_Sloc := Sloc (To);
9509 Error_Msg_N ("aspect % previously given #", Asp);
9510 end if;
9512 -- Otherwise capture the aspect
9514 else
9515 To := Asp;
9516 end if;
9517 end Save_Or_Duplication_Error;
9519 -- Local variables
9521 Asp : Node_Id;
9522 Asp_Id : Aspect_Id;
9524 -- The following variables capture each individual aspect
9526 Conv : Node_Id := Empty;
9527 EN : Node_Id := Empty;
9528 Expo : Node_Id := Empty;
9529 Imp : Node_Id := Empty;
9530 LN : Node_Id := Empty;
9532 -- Start of processing for Get_Interfacing_Aspects
9534 begin
9535 -- The input interfacing aspect should reside in an aspect specification
9536 -- list.
9538 pragma Assert (Is_List_Member (Iface_Asp));
9540 -- Examine the aspect specifications of the related entity. Find and
9541 -- capture all interfacing aspects. Detect duplicates and emit errors
9542 -- if applicable.
9544 Asp := First (List_Containing (Iface_Asp));
9545 while Present (Asp) loop
9546 Asp_Id := Get_Aspect_Id (Asp);
9548 if Asp_Id = Aspect_Convention then
9549 Save_Or_Duplication_Error (Asp, Conv);
9551 elsif Asp_Id = Aspect_External_Name then
9552 Save_Or_Duplication_Error (Asp, EN);
9554 elsif Asp_Id = Aspect_Export then
9555 Save_Or_Duplication_Error (Asp, Expo);
9557 elsif Asp_Id = Aspect_Import then
9558 Save_Or_Duplication_Error (Asp, Imp);
9560 elsif Asp_Id = Aspect_Link_Name then
9561 Save_Or_Duplication_Error (Asp, LN);
9562 end if;
9564 Next (Asp);
9565 end loop;
9567 Conv_Asp := Conv;
9568 EN_Asp := EN;
9569 Expo_Asp := Expo;
9570 Imp_Asp := Imp;
9571 LN_Asp := LN;
9572 end Get_Interfacing_Aspects;
9574 ---------------------------------
9575 -- Get_Iterable_Type_Primitive --
9576 ---------------------------------
9578 function Get_Iterable_Type_Primitive
9579 (Typ : Entity_Id;
9580 Nam : Name_Id) return Entity_Id
9582 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9583 Assoc : Node_Id;
9585 begin
9586 if No (Funcs) then
9587 return Empty;
9589 else
9590 Assoc := First (Component_Associations (Funcs));
9591 while Present (Assoc) loop
9592 if Chars (First (Choices (Assoc))) = Nam then
9593 return Entity (Expression (Assoc));
9594 end if;
9596 Assoc := Next (Assoc);
9597 end loop;
9599 return Empty;
9600 end if;
9601 end Get_Iterable_Type_Primitive;
9603 ----------------------------------
9604 -- Get_Library_Unit_Name_String --
9605 ----------------------------------
9607 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9608 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9610 begin
9611 Get_Unit_Name_String (Unit_Name_Id);
9613 -- Remove seven last character (" (spec)" or " (body)")
9615 Name_Len := Name_Len - 7;
9616 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9617 end Get_Library_Unit_Name_String;
9619 --------------------------
9620 -- Get_Max_Queue_Length --
9621 --------------------------
9623 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9624 pragma Assert (Is_Entry (Id));
9625 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9627 begin
9628 -- A value of 0 represents no maximum specified, and entries and entry
9629 -- families with no Max_Queue_Length aspect or pragma default to it.
9631 if not Present (Prag) then
9632 return Uint_0;
9633 end if;
9635 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9636 end Get_Max_Queue_Length;
9638 ------------------------
9639 -- Get_Name_Entity_Id --
9640 ------------------------
9642 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9643 begin
9644 return Entity_Id (Get_Name_Table_Int (Id));
9645 end Get_Name_Entity_Id;
9647 ------------------------------
9648 -- Get_Name_From_CTC_Pragma --
9649 ------------------------------
9651 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9652 Arg : constant Node_Id :=
9653 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9654 begin
9655 return Strval (Expr_Value_S (Arg));
9656 end Get_Name_From_CTC_Pragma;
9658 -----------------------
9659 -- Get_Parent_Entity --
9660 -----------------------
9662 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9663 begin
9664 if Nkind (Unit) = N_Package_Body
9665 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9666 then
9667 return Defining_Entity
9668 (Specification (Instance_Spec (Original_Node (Unit))));
9669 elsif Nkind (Unit) = N_Package_Instantiation then
9670 return Defining_Entity (Specification (Instance_Spec (Unit)));
9671 else
9672 return Defining_Entity (Unit);
9673 end if;
9674 end Get_Parent_Entity;
9676 -------------------
9677 -- Get_Pragma_Id --
9678 -------------------
9680 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9681 begin
9682 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9683 end Get_Pragma_Id;
9685 ------------------------
9686 -- Get_Qualified_Name --
9687 ------------------------
9689 function Get_Qualified_Name
9690 (Id : Entity_Id;
9691 Suffix : Entity_Id := Empty) return Name_Id
9693 Suffix_Nam : Name_Id := No_Name;
9695 begin
9696 if Present (Suffix) then
9697 Suffix_Nam := Chars (Suffix);
9698 end if;
9700 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9701 end Get_Qualified_Name;
9703 function Get_Qualified_Name
9704 (Nam : Name_Id;
9705 Suffix : Name_Id := No_Name;
9706 Scop : Entity_Id := Current_Scope) return Name_Id
9708 procedure Add_Scope (S : Entity_Id);
9709 -- Add the fully qualified form of scope S to the name buffer. The
9710 -- format is:
9711 -- s-1__s__
9713 ---------------
9714 -- Add_Scope --
9715 ---------------
9717 procedure Add_Scope (S : Entity_Id) is
9718 begin
9719 if S = Empty then
9720 null;
9722 elsif S = Standard_Standard then
9723 null;
9725 else
9726 Add_Scope (Scope (S));
9727 Get_Name_String_And_Append (Chars (S));
9728 Add_Str_To_Name_Buffer ("__");
9729 end if;
9730 end Add_Scope;
9732 -- Start of processing for Get_Qualified_Name
9734 begin
9735 Name_Len := 0;
9736 Add_Scope (Scop);
9738 -- Append the base name after all scopes have been chained
9740 Get_Name_String_And_Append (Nam);
9742 -- Append the suffix (if present)
9744 if Suffix /= No_Name then
9745 Add_Str_To_Name_Buffer ("__");
9746 Get_Name_String_And_Append (Suffix);
9747 end if;
9749 return Name_Find;
9750 end Get_Qualified_Name;
9752 -----------------------
9753 -- Get_Reason_String --
9754 -----------------------
9756 procedure Get_Reason_String (N : Node_Id) is
9757 begin
9758 if Nkind (N) = N_String_Literal then
9759 Store_String_Chars (Strval (N));
9761 elsif Nkind (N) = N_Op_Concat then
9762 Get_Reason_String (Left_Opnd (N));
9763 Get_Reason_String (Right_Opnd (N));
9765 -- If not of required form, error
9767 else
9768 Error_Msg_N
9769 ("Reason for pragma Warnings has wrong form", N);
9770 Error_Msg_N
9771 ("\must be string literal or concatenation of string literals", N);
9772 return;
9773 end if;
9774 end Get_Reason_String;
9776 --------------------------------
9777 -- Get_Reference_Discriminant --
9778 --------------------------------
9780 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9781 D : Entity_Id;
9783 begin
9784 D := First_Discriminant (Typ);
9785 while Present (D) loop
9786 if Has_Implicit_Dereference (D) then
9787 return D;
9788 end if;
9789 Next_Discriminant (D);
9790 end loop;
9792 return Empty;
9793 end Get_Reference_Discriminant;
9795 ---------------------------
9796 -- Get_Referenced_Object --
9797 ---------------------------
9799 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9800 R : Node_Id;
9802 begin
9803 R := N;
9804 while Is_Entity_Name (R)
9805 and then Present (Renamed_Object (Entity (R)))
9806 loop
9807 R := Renamed_Object (Entity (R));
9808 end loop;
9810 return R;
9811 end Get_Referenced_Object;
9813 ------------------------
9814 -- Get_Renamed_Entity --
9815 ------------------------
9817 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9818 R : Entity_Id;
9820 begin
9821 R := E;
9822 while Present (Renamed_Entity (R)) loop
9823 R := Renamed_Entity (R);
9824 end loop;
9826 return R;
9827 end Get_Renamed_Entity;
9829 -----------------------
9830 -- Get_Return_Object --
9831 -----------------------
9833 function Get_Return_Object (N : Node_Id) return Entity_Id is
9834 Decl : Node_Id;
9836 begin
9837 Decl := First (Return_Object_Declarations (N));
9838 while Present (Decl) loop
9839 exit when Nkind (Decl) = N_Object_Declaration
9840 and then Is_Return_Object (Defining_Identifier (Decl));
9841 Next (Decl);
9842 end loop;
9844 pragma Assert (Present (Decl));
9845 return Defining_Identifier (Decl);
9846 end Get_Return_Object;
9848 ---------------------------
9849 -- Get_Subprogram_Entity --
9850 ---------------------------
9852 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9853 Subp : Node_Id;
9854 Subp_Id : Entity_Id;
9856 begin
9857 if Nkind (Nod) = N_Accept_Statement then
9858 Subp := Entry_Direct_Name (Nod);
9860 elsif Nkind (Nod) = N_Slice then
9861 Subp := Prefix (Nod);
9863 else
9864 Subp := Name (Nod);
9865 end if;
9867 -- Strip the subprogram call
9869 loop
9870 if Nkind_In (Subp, N_Explicit_Dereference,
9871 N_Indexed_Component,
9872 N_Selected_Component)
9873 then
9874 Subp := Prefix (Subp);
9876 elsif Nkind_In (Subp, N_Type_Conversion,
9877 N_Unchecked_Type_Conversion)
9878 then
9879 Subp := Expression (Subp);
9881 else
9882 exit;
9883 end if;
9884 end loop;
9886 -- Extract the entity of the subprogram call
9888 if Is_Entity_Name (Subp) then
9889 Subp_Id := Entity (Subp);
9891 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9892 Subp_Id := Directly_Designated_Type (Subp_Id);
9893 end if;
9895 if Is_Subprogram (Subp_Id) then
9896 return Subp_Id;
9897 else
9898 return Empty;
9899 end if;
9901 -- The search did not find a construct that denotes a subprogram
9903 else
9904 return Empty;
9905 end if;
9906 end Get_Subprogram_Entity;
9908 -----------------------------
9909 -- Get_Task_Body_Procedure --
9910 -----------------------------
9912 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
9913 begin
9914 -- Note: A task type may be the completion of a private type with
9915 -- discriminants. When performing elaboration checks on a task
9916 -- declaration, the current view of the type may be the private one,
9917 -- and the procedure that holds the body of the task is held in its
9918 -- underlying type.
9920 -- This is an odd function, why not have Task_Body_Procedure do
9921 -- the following digging???
9923 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9924 end Get_Task_Body_Procedure;
9926 -------------------------
9927 -- Get_User_Defined_Eq --
9928 -------------------------
9930 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9931 Prim : Elmt_Id;
9932 Op : Entity_Id;
9934 begin
9935 Prim := First_Elmt (Collect_Primitive_Operations (E));
9936 while Present (Prim) loop
9937 Op := Node (Prim);
9939 if Chars (Op) = Name_Op_Eq
9940 and then Etype (Op) = Standard_Boolean
9941 and then Etype (First_Formal (Op)) = E
9942 and then Etype (Next_Formal (First_Formal (Op))) = E
9943 then
9944 return Op;
9945 end if;
9947 Next_Elmt (Prim);
9948 end loop;
9950 return Empty;
9951 end Get_User_Defined_Eq;
9953 ---------------
9954 -- Get_Views --
9955 ---------------
9957 procedure Get_Views
9958 (Typ : Entity_Id;
9959 Priv_Typ : out Entity_Id;
9960 Full_Typ : out Entity_Id;
9961 Full_Base : out Entity_Id;
9962 CRec_Typ : out Entity_Id)
9964 IP_View : Entity_Id;
9966 begin
9967 -- Assume that none of the views can be recovered
9969 Priv_Typ := Empty;
9970 Full_Typ := Empty;
9971 Full_Base := Empty;
9972 CRec_Typ := Empty;
9974 -- The input type is the corresponding record type of a protected or a
9975 -- task type.
9977 if Ekind (Typ) = E_Record_Type
9978 and then Is_Concurrent_Record_Type (Typ)
9979 then
9980 CRec_Typ := Typ;
9981 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9982 Full_Base := Base_Type (Full_Typ);
9983 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9985 -- Otherwise the input type denotes an arbitrary type
9987 else
9988 IP_View := Incomplete_Or_Partial_View (Typ);
9990 -- The input type denotes the full view of a private type
9992 if Present (IP_View) then
9993 Priv_Typ := IP_View;
9994 Full_Typ := Typ;
9996 -- The input type is a private type
9998 elsif Is_Private_Type (Typ) then
9999 Priv_Typ := Typ;
10000 Full_Typ := Full_View (Priv_Typ);
10002 -- Otherwise the input type does not have any views
10004 else
10005 Full_Typ := Typ;
10006 end if;
10008 if Present (Full_Typ) then
10009 Full_Base := Base_Type (Full_Typ);
10011 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
10012 CRec_Typ := Corresponding_Record_Type (Full_Typ);
10013 end if;
10014 end if;
10015 end if;
10016 end Get_Views;
10018 -----------------------
10019 -- Has_Access_Values --
10020 -----------------------
10022 function Has_Access_Values (T : Entity_Id) return Boolean is
10023 Typ : constant Entity_Id := Underlying_Type (T);
10025 begin
10026 -- Case of a private type which is not completed yet. This can only
10027 -- happen in the case of a generic format type appearing directly, or
10028 -- as a component of the type to which this function is being applied
10029 -- at the top level. Return False in this case, since we certainly do
10030 -- not know that the type contains access types.
10032 if No (Typ) then
10033 return False;
10035 elsif Is_Access_Type (Typ) then
10036 return True;
10038 elsif Is_Array_Type (Typ) then
10039 return Has_Access_Values (Component_Type (Typ));
10041 elsif Is_Record_Type (Typ) then
10042 declare
10043 Comp : Entity_Id;
10045 begin
10046 -- Loop to Check components
10048 Comp := First_Component_Or_Discriminant (Typ);
10049 while Present (Comp) loop
10051 -- Check for access component, tag field does not count, even
10052 -- though it is implemented internally using an access type.
10054 if Has_Access_Values (Etype (Comp))
10055 and then Chars (Comp) /= Name_uTag
10056 then
10057 return True;
10058 end if;
10060 Next_Component_Or_Discriminant (Comp);
10061 end loop;
10062 end;
10064 return False;
10066 else
10067 return False;
10068 end if;
10069 end Has_Access_Values;
10071 ------------------------------
10072 -- Has_Compatible_Alignment --
10073 ------------------------------
10075 function Has_Compatible_Alignment
10076 (Obj : Entity_Id;
10077 Expr : Node_Id;
10078 Layout_Done : Boolean) return Alignment_Result
10080 function Has_Compatible_Alignment_Internal
10081 (Obj : Entity_Id;
10082 Expr : Node_Id;
10083 Layout_Done : Boolean;
10084 Default : Alignment_Result) return Alignment_Result;
10085 -- This is the internal recursive function that actually does the work.
10086 -- There is one additional parameter, which says what the result should
10087 -- be if no alignment information is found, and there is no definite
10088 -- indication of compatible alignments. At the outer level, this is set
10089 -- to Unknown, but for internal recursive calls in the case where types
10090 -- are known to be correct, it is set to Known_Compatible.
10092 ---------------------------------------
10093 -- Has_Compatible_Alignment_Internal --
10094 ---------------------------------------
10096 function Has_Compatible_Alignment_Internal
10097 (Obj : Entity_Id;
10098 Expr : Node_Id;
10099 Layout_Done : Boolean;
10100 Default : Alignment_Result) return Alignment_Result
10102 Result : Alignment_Result := Known_Compatible;
10103 -- Holds the current status of the result. Note that once a value of
10104 -- Known_Incompatible is set, it is sticky and does not get changed
10105 -- to Unknown (the value in Result only gets worse as we go along,
10106 -- never better).
10108 Offs : Uint := No_Uint;
10109 -- Set to a factor of the offset from the base object when Expr is a
10110 -- selected or indexed component, based on Component_Bit_Offset and
10111 -- Component_Size respectively. A negative value is used to represent
10112 -- a value which is not known at compile time.
10114 procedure Check_Prefix;
10115 -- Checks the prefix recursively in the case where the expression
10116 -- is an indexed or selected component.
10118 procedure Set_Result (R : Alignment_Result);
10119 -- If R represents a worse outcome (unknown instead of known
10120 -- compatible, or known incompatible), then set Result to R.
10122 ------------------
10123 -- Check_Prefix --
10124 ------------------
10126 procedure Check_Prefix is
10127 begin
10128 -- The subtlety here is that in doing a recursive call to check
10129 -- the prefix, we have to decide what to do in the case where we
10130 -- don't find any specific indication of an alignment problem.
10132 -- At the outer level, we normally set Unknown as the result in
10133 -- this case, since we can only set Known_Compatible if we really
10134 -- know that the alignment value is OK, but for the recursive
10135 -- call, in the case where the types match, and we have not
10136 -- specified a peculiar alignment for the object, we are only
10137 -- concerned about suspicious rep clauses, the default case does
10138 -- not affect us, since the compiler will, in the absence of such
10139 -- rep clauses, ensure that the alignment is correct.
10141 if Default = Known_Compatible
10142 or else
10143 (Etype (Obj) = Etype (Expr)
10144 and then (Unknown_Alignment (Obj)
10145 or else
10146 Alignment (Obj) = Alignment (Etype (Obj))))
10147 then
10148 Set_Result
10149 (Has_Compatible_Alignment_Internal
10150 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
10152 -- In all other cases, we need a full check on the prefix
10154 else
10155 Set_Result
10156 (Has_Compatible_Alignment_Internal
10157 (Obj, Prefix (Expr), Layout_Done, Unknown));
10158 end if;
10159 end Check_Prefix;
10161 ----------------
10162 -- Set_Result --
10163 ----------------
10165 procedure Set_Result (R : Alignment_Result) is
10166 begin
10167 if R > Result then
10168 Result := R;
10169 end if;
10170 end Set_Result;
10172 -- Start of processing for Has_Compatible_Alignment_Internal
10174 begin
10175 -- If Expr is a selected component, we must make sure there is no
10176 -- potentially troublesome component clause and that the record is
10177 -- not packed if the layout is not done.
10179 if Nkind (Expr) = N_Selected_Component then
10181 -- Packing generates unknown alignment if layout is not done
10183 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
10184 Set_Result (Unknown);
10185 end if;
10187 -- Check prefix and component offset
10189 Check_Prefix;
10190 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
10192 -- If Expr is an indexed component, we must make sure there is no
10193 -- potentially troublesome Component_Size clause and that the array
10194 -- is not bit-packed if the layout is not done.
10196 elsif Nkind (Expr) = N_Indexed_Component then
10197 declare
10198 Typ : constant Entity_Id := Etype (Prefix (Expr));
10200 begin
10201 -- Packing generates unknown alignment if layout is not done
10203 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10204 Set_Result (Unknown);
10205 end if;
10207 -- Check prefix and component offset (or at least size)
10209 Check_Prefix;
10210 Offs := Indexed_Component_Bit_Offset (Expr);
10211 if Offs = No_Uint then
10212 Offs := Component_Size (Typ);
10213 end if;
10214 end;
10215 end if;
10217 -- If we have a null offset, the result is entirely determined by
10218 -- the base object and has already been computed recursively.
10220 if Offs = Uint_0 then
10221 null;
10223 -- Case where we know the alignment of the object
10225 elsif Known_Alignment (Obj) then
10226 declare
10227 ObjA : constant Uint := Alignment (Obj);
10228 ExpA : Uint := No_Uint;
10229 SizA : Uint := No_Uint;
10231 begin
10232 -- If alignment of Obj is 1, then we are always OK
10234 if ObjA = 1 then
10235 Set_Result (Known_Compatible);
10237 -- Alignment of Obj is greater than 1, so we need to check
10239 else
10240 -- If we have an offset, see if it is compatible
10242 if Offs /= No_Uint and Offs > Uint_0 then
10243 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10244 Set_Result (Known_Incompatible);
10245 end if;
10247 -- See if Expr is an object with known alignment
10249 elsif Is_Entity_Name (Expr)
10250 and then Known_Alignment (Entity (Expr))
10251 then
10252 ExpA := Alignment (Entity (Expr));
10254 -- Otherwise, we can use the alignment of the type of
10255 -- Expr given that we already checked for
10256 -- discombobulating rep clauses for the cases of indexed
10257 -- and selected components above.
10259 elsif Known_Alignment (Etype (Expr)) then
10260 ExpA := Alignment (Etype (Expr));
10262 -- Otherwise the alignment is unknown
10264 else
10265 Set_Result (Default);
10266 end if;
10268 -- If we got an alignment, see if it is acceptable
10270 if ExpA /= No_Uint and then ExpA < ObjA then
10271 Set_Result (Known_Incompatible);
10272 end if;
10274 -- If Expr is not a piece of a larger object, see if size
10275 -- is given. If so, check that it is not too small for the
10276 -- required alignment.
10278 if Offs /= No_Uint then
10279 null;
10281 -- See if Expr is an object with known size
10283 elsif Is_Entity_Name (Expr)
10284 and then Known_Static_Esize (Entity (Expr))
10285 then
10286 SizA := Esize (Entity (Expr));
10288 -- Otherwise, we check the object size of the Expr type
10290 elsif Known_Static_Esize (Etype (Expr)) then
10291 SizA := Esize (Etype (Expr));
10292 end if;
10294 -- If we got a size, see if it is a multiple of the Obj
10295 -- alignment, if not, then the alignment cannot be
10296 -- acceptable, since the size is always a multiple of the
10297 -- alignment.
10299 if SizA /= No_Uint then
10300 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10301 Set_Result (Known_Incompatible);
10302 end if;
10303 end if;
10304 end if;
10305 end;
10307 -- If we do not know required alignment, any non-zero offset is a
10308 -- potential problem (but certainly may be OK, so result is unknown).
10310 elsif Offs /= No_Uint then
10311 Set_Result (Unknown);
10313 -- If we can't find the result by direct comparison of alignment
10314 -- values, then there is still one case that we can determine known
10315 -- result, and that is when we can determine that the types are the
10316 -- same, and no alignments are specified. Then we known that the
10317 -- alignments are compatible, even if we don't know the alignment
10318 -- value in the front end.
10320 elsif Etype (Obj) = Etype (Expr) then
10322 -- Types are the same, but we have to check for possible size
10323 -- and alignments on the Expr object that may make the alignment
10324 -- different, even though the types are the same.
10326 if Is_Entity_Name (Expr) then
10328 -- First check alignment of the Expr object. Any alignment less
10329 -- than Maximum_Alignment is worrisome since this is the case
10330 -- where we do not know the alignment of Obj.
10332 if Known_Alignment (Entity (Expr))
10333 and then UI_To_Int (Alignment (Entity (Expr))) <
10334 Ttypes.Maximum_Alignment
10335 then
10336 Set_Result (Unknown);
10338 -- Now check size of Expr object. Any size that is not an
10339 -- even multiple of Maximum_Alignment is also worrisome
10340 -- since it may cause the alignment of the object to be less
10341 -- than the alignment of the type.
10343 elsif Known_Static_Esize (Entity (Expr))
10344 and then
10345 (UI_To_Int (Esize (Entity (Expr))) mod
10346 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10347 /= 0
10348 then
10349 Set_Result (Unknown);
10351 -- Otherwise same type is decisive
10353 else
10354 Set_Result (Known_Compatible);
10355 end if;
10356 end if;
10358 -- Another case to deal with is when there is an explicit size or
10359 -- alignment clause when the types are not the same. If so, then the
10360 -- result is Unknown. We don't need to do this test if the Default is
10361 -- Unknown, since that result will be set in any case.
10363 elsif Default /= Unknown
10364 and then (Has_Size_Clause (Etype (Expr))
10365 or else
10366 Has_Alignment_Clause (Etype (Expr)))
10367 then
10368 Set_Result (Unknown);
10370 -- If no indication found, set default
10372 else
10373 Set_Result (Default);
10374 end if;
10376 -- Return worst result found
10378 return Result;
10379 end Has_Compatible_Alignment_Internal;
10381 -- Start of processing for Has_Compatible_Alignment
10383 begin
10384 -- If Obj has no specified alignment, then set alignment from the type
10385 -- alignment. Perhaps we should always do this, but for sure we should
10386 -- do it when there is an address clause since we can do more if the
10387 -- alignment is known.
10389 if Unknown_Alignment (Obj) then
10390 Set_Alignment (Obj, Alignment (Etype (Obj)));
10391 end if;
10393 -- Now do the internal call that does all the work
10395 return
10396 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10397 end Has_Compatible_Alignment;
10399 ----------------------
10400 -- Has_Declarations --
10401 ----------------------
10403 function Has_Declarations (N : Node_Id) return Boolean is
10404 begin
10405 return Nkind_In (Nkind (N), N_Accept_Statement,
10406 N_Block_Statement,
10407 N_Compilation_Unit_Aux,
10408 N_Entry_Body,
10409 N_Package_Body,
10410 N_Protected_Body,
10411 N_Subprogram_Body,
10412 N_Task_Body,
10413 N_Package_Specification);
10414 end Has_Declarations;
10416 ---------------------------------
10417 -- Has_Defaulted_Discriminants --
10418 ---------------------------------
10420 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10421 begin
10422 return Has_Discriminants (Typ)
10423 and then Present (First_Discriminant (Typ))
10424 and then Present (Discriminant_Default_Value
10425 (First_Discriminant (Typ)));
10426 end Has_Defaulted_Discriminants;
10428 -------------------
10429 -- Has_Denormals --
10430 -------------------
10432 function Has_Denormals (E : Entity_Id) return Boolean is
10433 begin
10434 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10435 end Has_Denormals;
10437 -------------------------------------------
10438 -- Has_Discriminant_Dependent_Constraint --
10439 -------------------------------------------
10441 function Has_Discriminant_Dependent_Constraint
10442 (Comp : Entity_Id) return Boolean
10444 Comp_Decl : constant Node_Id := Parent (Comp);
10445 Subt_Indic : Node_Id;
10446 Constr : Node_Id;
10447 Assn : Node_Id;
10449 begin
10450 -- Discriminants can't depend on discriminants
10452 if Ekind (Comp) = E_Discriminant then
10453 return False;
10455 else
10456 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10458 if Nkind (Subt_Indic) = N_Subtype_Indication then
10459 Constr := Constraint (Subt_Indic);
10461 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10462 Assn := First (Constraints (Constr));
10463 while Present (Assn) loop
10464 case Nkind (Assn) is
10465 when N_Identifier
10466 | N_Range
10467 | N_Subtype_Indication
10469 if Depends_On_Discriminant (Assn) then
10470 return True;
10471 end if;
10473 when N_Discriminant_Association =>
10474 if Depends_On_Discriminant (Expression (Assn)) then
10475 return True;
10476 end if;
10478 when others =>
10479 null;
10480 end case;
10482 Next (Assn);
10483 end loop;
10484 end if;
10485 end if;
10486 end if;
10488 return False;
10489 end Has_Discriminant_Dependent_Constraint;
10491 --------------------------------------
10492 -- Has_Effectively_Volatile_Profile --
10493 --------------------------------------
10495 function Has_Effectively_Volatile_Profile
10496 (Subp_Id : Entity_Id) return Boolean
10498 Formal : Entity_Id;
10500 begin
10501 -- Inspect the formal parameters looking for an effectively volatile
10502 -- type.
10504 Formal := First_Formal (Subp_Id);
10505 while Present (Formal) loop
10506 if Is_Effectively_Volatile (Etype (Formal)) then
10507 return True;
10508 end if;
10510 Next_Formal (Formal);
10511 end loop;
10513 -- Inspect the return type of functions
10515 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10516 and then Is_Effectively_Volatile (Etype (Subp_Id))
10517 then
10518 return True;
10519 end if;
10521 return False;
10522 end Has_Effectively_Volatile_Profile;
10524 --------------------------
10525 -- Has_Enabled_Property --
10526 --------------------------
10528 function Has_Enabled_Property
10529 (Item_Id : Entity_Id;
10530 Property : Name_Id) return Boolean
10532 function Protected_Object_Has_Enabled_Property return Boolean;
10533 -- Determine whether a protected object denoted by Item_Id has the
10534 -- property enabled.
10536 function State_Has_Enabled_Property return Boolean;
10537 -- Determine whether a state denoted by Item_Id has the property enabled
10539 function Variable_Has_Enabled_Property return Boolean;
10540 -- Determine whether a variable denoted by Item_Id has the property
10541 -- enabled.
10543 -------------------------------------------
10544 -- Protected_Object_Has_Enabled_Property --
10545 -------------------------------------------
10547 function Protected_Object_Has_Enabled_Property return Boolean is
10548 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10549 Constit_Elmt : Elmt_Id;
10550 Constit_Id : Entity_Id;
10552 begin
10553 -- Protected objects always have the properties Async_Readers and
10554 -- Async_Writers (SPARK RM 7.1.2(16)).
10556 if Property = Name_Async_Readers
10557 or else Property = Name_Async_Writers
10558 then
10559 return True;
10561 -- Protected objects that have Part_Of components also inherit their
10562 -- properties Effective_Reads and Effective_Writes
10563 -- (SPARK RM 7.1.2(16)).
10565 elsif Present (Constits) then
10566 Constit_Elmt := First_Elmt (Constits);
10567 while Present (Constit_Elmt) loop
10568 Constit_Id := Node (Constit_Elmt);
10570 if Has_Enabled_Property (Constit_Id, Property) then
10571 return True;
10572 end if;
10574 Next_Elmt (Constit_Elmt);
10575 end loop;
10576 end if;
10578 return False;
10579 end Protected_Object_Has_Enabled_Property;
10581 --------------------------------
10582 -- State_Has_Enabled_Property --
10583 --------------------------------
10585 function State_Has_Enabled_Property return Boolean is
10586 Decl : constant Node_Id := Parent (Item_Id);
10588 procedure Find_Simple_Properties
10589 (Has_External : out Boolean;
10590 Has_Synchronous : out Boolean);
10591 -- Extract the simple properties associated with declaration Decl
10593 function Is_Enabled_External_Property return Boolean;
10594 -- Determine whether property Property appears within the external
10595 -- property list of declaration Decl, and return its status.
10597 ----------------------------
10598 -- Find_Simple_Properties --
10599 ----------------------------
10601 procedure Find_Simple_Properties
10602 (Has_External : out Boolean;
10603 Has_Synchronous : out Boolean)
10605 Opt : Node_Id;
10607 begin
10608 -- Assume that none of the properties are available
10610 Has_External := False;
10611 Has_Synchronous := False;
10613 Opt := First (Expressions (Decl));
10614 while Present (Opt) loop
10615 if Nkind (Opt) = N_Identifier then
10616 if Chars (Opt) = Name_External then
10617 Has_External := True;
10619 elsif Chars (Opt) = Name_Synchronous then
10620 Has_Synchronous := True;
10621 end if;
10622 end if;
10624 Next (Opt);
10625 end loop;
10626 end Find_Simple_Properties;
10628 ----------------------------------
10629 -- Is_Enabled_External_Property --
10630 ----------------------------------
10632 function Is_Enabled_External_Property return Boolean is
10633 Opt : Node_Id;
10634 Opt_Nam : Node_Id;
10635 Prop : Node_Id;
10636 Prop_Nam : Node_Id;
10637 Props : Node_Id;
10639 begin
10640 Opt := First (Component_Associations (Decl));
10641 while Present (Opt) loop
10642 Opt_Nam := First (Choices (Opt));
10644 if Nkind (Opt_Nam) = N_Identifier
10645 and then Chars (Opt_Nam) = Name_External
10646 then
10647 Props := Expression (Opt);
10649 -- Multiple properties appear as an aggregate
10651 if Nkind (Props) = N_Aggregate then
10653 -- Simple property form
10655 Prop := First (Expressions (Props));
10656 while Present (Prop) loop
10657 if Chars (Prop) = Property then
10658 return True;
10659 end if;
10661 Next (Prop);
10662 end loop;
10664 -- Property with expression form
10666 Prop := First (Component_Associations (Props));
10667 while Present (Prop) loop
10668 Prop_Nam := First (Choices (Prop));
10670 -- The property can be represented in two ways:
10671 -- others => <value>
10672 -- <property> => <value>
10674 if Nkind (Prop_Nam) = N_Others_Choice
10675 or else (Nkind (Prop_Nam) = N_Identifier
10676 and then Chars (Prop_Nam) = Property)
10677 then
10678 return Is_True (Expr_Value (Expression (Prop)));
10679 end if;
10681 Next (Prop);
10682 end loop;
10684 -- Single property
10686 else
10687 return Chars (Props) = Property;
10688 end if;
10689 end if;
10691 Next (Opt);
10692 end loop;
10694 return False;
10695 end Is_Enabled_External_Property;
10697 -- Local variables
10699 Has_External : Boolean;
10700 Has_Synchronous : Boolean;
10702 -- Start of processing for State_Has_Enabled_Property
10704 begin
10705 -- The declaration of an external abstract state appears as an
10706 -- extension aggregate. If this is not the case, properties can
10707 -- never be set.
10709 if Nkind (Decl) /= N_Extension_Aggregate then
10710 return False;
10711 end if;
10713 Find_Simple_Properties (Has_External, Has_Synchronous);
10715 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10717 if Has_External then
10718 return True;
10720 -- Option External may enable or disable specific properties
10722 elsif Is_Enabled_External_Property then
10723 return True;
10725 -- Simple option Synchronous
10727 -- enables disables
10728 -- Asynch_Readers Effective_Reads
10729 -- Asynch_Writers Effective_Writes
10731 -- Note that both forms of External have higher precedence than
10732 -- Synchronous (SPARK RM 7.1.4(10)).
10734 elsif Has_Synchronous then
10735 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
10736 end if;
10738 return False;
10739 end State_Has_Enabled_Property;
10741 -----------------------------------
10742 -- Variable_Has_Enabled_Property --
10743 -----------------------------------
10745 function Variable_Has_Enabled_Property return Boolean is
10746 function Is_Enabled (Prag : Node_Id) return Boolean;
10747 -- Determine whether property pragma Prag (if present) denotes an
10748 -- enabled property.
10750 ----------------
10751 -- Is_Enabled --
10752 ----------------
10754 function Is_Enabled (Prag : Node_Id) return Boolean is
10755 Arg1 : Node_Id;
10757 begin
10758 if Present (Prag) then
10759 Arg1 := First (Pragma_Argument_Associations (Prag));
10761 -- The pragma has an optional Boolean expression, the related
10762 -- property is enabled only when the expression evaluates to
10763 -- True.
10765 if Present (Arg1) then
10766 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10768 -- Otherwise the lack of expression enables the property by
10769 -- default.
10771 else
10772 return True;
10773 end if;
10775 -- The property was never set in the first place
10777 else
10778 return False;
10779 end if;
10780 end Is_Enabled;
10782 -- Local variables
10784 AR : constant Node_Id :=
10785 Get_Pragma (Item_Id, Pragma_Async_Readers);
10786 AW : constant Node_Id :=
10787 Get_Pragma (Item_Id, Pragma_Async_Writers);
10788 ER : constant Node_Id :=
10789 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10790 EW : constant Node_Id :=
10791 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10793 -- Start of processing for Variable_Has_Enabled_Property
10795 begin
10796 -- A non-effectively volatile object can never possess external
10797 -- properties.
10799 if not Is_Effectively_Volatile (Item_Id) then
10800 return False;
10802 -- External properties related to variables come in two flavors -
10803 -- explicit and implicit. The explicit case is characterized by the
10804 -- presence of a property pragma with an optional Boolean flag. The
10805 -- property is enabled when the flag evaluates to True or the flag is
10806 -- missing altogether.
10808 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10809 return True;
10811 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10812 return True;
10814 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10815 return True;
10817 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10818 return True;
10820 -- The implicit case lacks all property pragmas
10822 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10823 if Is_Protected_Type (Etype (Item_Id)) then
10824 return Protected_Object_Has_Enabled_Property;
10825 else
10826 return True;
10827 end if;
10829 else
10830 return False;
10831 end if;
10832 end Variable_Has_Enabled_Property;
10834 -- Start of processing for Has_Enabled_Property
10836 begin
10837 -- Abstract states and variables have a flexible scheme of specifying
10838 -- external properties.
10840 if Ekind (Item_Id) = E_Abstract_State then
10841 return State_Has_Enabled_Property;
10843 elsif Ekind (Item_Id) = E_Variable then
10844 return Variable_Has_Enabled_Property;
10846 -- By default, protected objects only have the properties Async_Readers
10847 -- and Async_Writers. If they have Part_Of components, they also inherit
10848 -- their properties Effective_Reads and Effective_Writes
10849 -- (SPARK RM 7.1.2(16)).
10851 elsif Ekind (Item_Id) = E_Protected_Object then
10852 return Protected_Object_Has_Enabled_Property;
10854 -- Otherwise a property is enabled when the related item is effectively
10855 -- volatile.
10857 else
10858 return Is_Effectively_Volatile (Item_Id);
10859 end if;
10860 end Has_Enabled_Property;
10862 -------------------------------------
10863 -- Has_Full_Default_Initialization --
10864 -------------------------------------
10866 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10867 Comp : Entity_Id;
10869 begin
10870 -- A type subject to pragma Default_Initial_Condition may be fully
10871 -- default initialized depending on inheritance and the argument of
10872 -- the pragma. Since any type may act as the full view of a private
10873 -- type, this check must be performed prior to the specialized tests
10874 -- below.
10876 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
10877 return True;
10878 end if;
10880 -- A scalar type is fully default initialized if it is subject to aspect
10881 -- Default_Value.
10883 if Is_Scalar_Type (Typ) then
10884 return Has_Default_Aspect (Typ);
10886 -- An array type is fully default initialized if its element type is
10887 -- scalar and the array type carries aspect Default_Component_Value or
10888 -- the element type is fully default initialized.
10890 elsif Is_Array_Type (Typ) then
10891 return
10892 Has_Default_Aspect (Typ)
10893 or else Has_Full_Default_Initialization (Component_Type (Typ));
10895 -- A protected type, record type, or type extension is fully default
10896 -- initialized if all its components either carry an initialization
10897 -- expression or have a type that is fully default initialized. The
10898 -- parent type of a type extension must be fully default initialized.
10900 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10902 -- Inspect all entities defined in the scope of the type, looking for
10903 -- uninitialized components.
10905 Comp := First_Entity (Typ);
10906 while Present (Comp) loop
10907 if Ekind (Comp) = E_Component
10908 and then Comes_From_Source (Comp)
10909 and then No (Expression (Parent (Comp)))
10910 and then not Has_Full_Default_Initialization (Etype (Comp))
10911 then
10912 return False;
10913 end if;
10915 Next_Entity (Comp);
10916 end loop;
10918 -- Ensure that the parent type of a type extension is fully default
10919 -- initialized.
10921 if Etype (Typ) /= Typ
10922 and then not Has_Full_Default_Initialization (Etype (Typ))
10923 then
10924 return False;
10925 end if;
10927 -- If we get here, then all components and parent portion are fully
10928 -- default initialized.
10930 return True;
10932 -- A task type is fully default initialized by default
10934 elsif Is_Task_Type (Typ) then
10935 return True;
10937 -- Otherwise the type is not fully default initialized
10939 else
10940 return False;
10941 end if;
10942 end Has_Full_Default_Initialization;
10944 -----------------------------------------------
10945 -- Has_Fully_Default_Initializing_DIC_Pragma --
10946 -----------------------------------------------
10948 function Has_Fully_Default_Initializing_DIC_Pragma
10949 (Typ : Entity_Id) return Boolean
10951 Args : List_Id;
10952 Prag : Node_Id;
10954 begin
10955 -- A type that inherits pragma Default_Initial_Condition from a parent
10956 -- type is automatically fully default initialized.
10958 if Has_Inherited_DIC (Typ) then
10959 return True;
10961 -- Otherwise the type is fully default initialized only when the pragma
10962 -- appears without an argument, or the argument is non-null.
10964 elsif Has_Own_DIC (Typ) then
10965 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10966 pragma Assert (Present (Prag));
10967 Args := Pragma_Argument_Associations (Prag);
10969 -- The pragma appears without an argument in which case it defaults
10970 -- to True.
10972 if No (Args) then
10973 return True;
10975 -- The pragma appears with a non-null expression
10977 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
10978 return True;
10979 end if;
10980 end if;
10982 return False;
10983 end Has_Fully_Default_Initializing_DIC_Pragma;
10985 --------------------
10986 -- Has_Infinities --
10987 --------------------
10989 function Has_Infinities (E : Entity_Id) return Boolean is
10990 begin
10991 return
10992 Is_Floating_Point_Type (E)
10993 and then Nkind (Scalar_Range (E)) = N_Range
10994 and then Includes_Infinities (Scalar_Range (E));
10995 end Has_Infinities;
10997 --------------------
10998 -- Has_Interfaces --
10999 --------------------
11001 function Has_Interfaces
11002 (T : Entity_Id;
11003 Use_Full_View : Boolean := True) return Boolean
11005 Typ : Entity_Id := Base_Type (T);
11007 begin
11008 -- Handle concurrent types
11010 if Is_Concurrent_Type (Typ) then
11011 Typ := Corresponding_Record_Type (Typ);
11012 end if;
11014 if not Present (Typ)
11015 or else not Is_Record_Type (Typ)
11016 or else not Is_Tagged_Type (Typ)
11017 then
11018 return False;
11019 end if;
11021 -- Handle private types
11023 if Use_Full_View and then Present (Full_View (Typ)) then
11024 Typ := Full_View (Typ);
11025 end if;
11027 -- Handle concurrent record types
11029 if Is_Concurrent_Record_Type (Typ)
11030 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
11031 then
11032 return True;
11033 end if;
11035 loop
11036 if Is_Interface (Typ)
11037 or else
11038 (Is_Record_Type (Typ)
11039 and then Present (Interfaces (Typ))
11040 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
11041 then
11042 return True;
11043 end if;
11045 exit when Etype (Typ) = Typ
11047 -- Handle private types
11049 or else (Present (Full_View (Etype (Typ)))
11050 and then Full_View (Etype (Typ)) = Typ)
11052 -- Protect frontend against wrong sources with cyclic derivations
11054 or else Etype (Typ) = T;
11056 -- Climb to the ancestor type handling private types
11058 if Present (Full_View (Etype (Typ))) then
11059 Typ := Full_View (Etype (Typ));
11060 else
11061 Typ := Etype (Typ);
11062 end if;
11063 end loop;
11065 return False;
11066 end Has_Interfaces;
11068 --------------------------
11069 -- Has_Max_Queue_Length --
11070 --------------------------
11072 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
11073 begin
11074 return
11075 Ekind (Id) = E_Entry
11076 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
11077 end Has_Max_Queue_Length;
11079 ---------------------------------
11080 -- Has_No_Obvious_Side_Effects --
11081 ---------------------------------
11083 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
11084 begin
11085 -- For now handle literals, constants, and non-volatile variables and
11086 -- expressions combining these with operators or short circuit forms.
11088 if Nkind (N) in N_Numeric_Or_String_Literal then
11089 return True;
11091 elsif Nkind (N) = N_Character_Literal then
11092 return True;
11094 elsif Nkind (N) in N_Unary_Op then
11095 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
11097 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
11098 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
11099 and then
11100 Has_No_Obvious_Side_Effects (Right_Opnd (N));
11102 elsif Nkind (N) = N_Expression_With_Actions
11103 and then Is_Empty_List (Actions (N))
11104 then
11105 return Has_No_Obvious_Side_Effects (Expression (N));
11107 elsif Nkind (N) in N_Has_Entity then
11108 return Present (Entity (N))
11109 and then Ekind_In (Entity (N), E_Variable,
11110 E_Constant,
11111 E_Enumeration_Literal,
11112 E_In_Parameter,
11113 E_Out_Parameter,
11114 E_In_Out_Parameter)
11115 and then not Is_Volatile (Entity (N));
11117 else
11118 return False;
11119 end if;
11120 end Has_No_Obvious_Side_Effects;
11122 -----------------------------
11123 -- Has_Non_Null_Refinement --
11124 -----------------------------
11126 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
11127 Constits : Elist_Id;
11129 begin
11130 pragma Assert (Ekind (Id) = E_Abstract_State);
11131 Constits := Refinement_Constituents (Id);
11133 -- For a refinement to be non-null, the first constituent must be
11134 -- anything other than null.
11136 return
11137 Present (Constits)
11138 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
11139 end Has_Non_Null_Refinement;
11141 -----------------------------
11142 -- Has_Non_Null_Statements --
11143 -----------------------------
11145 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11146 Node : Node_Id;
11148 begin
11149 if Is_Non_Empty_List (L) then
11150 Node := First (L);
11152 loop
11153 if Nkind (Node) /= N_Null_Statement then
11154 return True;
11155 end if;
11157 Next (Node);
11158 exit when Node = Empty;
11159 end loop;
11160 end if;
11162 return False;
11163 end Has_Non_Null_Statements;
11165 ----------------------------------
11166 -- Has_Non_Trivial_Precondition --
11167 ----------------------------------
11169 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
11170 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
11172 begin
11173 return
11174 Present (Pre)
11175 and then Class_Present (Pre)
11176 and then not Is_Entity_Name (Expression (Pre));
11177 end Has_Non_Trivial_Precondition;
11179 -------------------
11180 -- Has_Null_Body --
11181 -------------------
11183 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
11184 Body_Id : Entity_Id;
11185 Decl : Node_Id;
11186 Spec : Node_Id;
11187 Stmt1 : Node_Id;
11188 Stmt2 : Node_Id;
11190 begin
11191 Spec := Parent (Proc_Id);
11192 Decl := Parent (Spec);
11194 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11196 if Nkind (Spec) = N_Procedure_Specification
11197 and then Nkind (Decl) = N_Subprogram_Declaration
11198 then
11199 Body_Id := Corresponding_Body (Decl);
11201 -- The body acts as a spec
11203 else
11204 Body_Id := Proc_Id;
11205 end if;
11207 -- The body will be generated later
11209 if No (Body_Id) then
11210 return False;
11211 end if;
11213 Spec := Parent (Body_Id);
11214 Decl := Parent (Spec);
11216 pragma Assert
11217 (Nkind (Spec) = N_Procedure_Specification
11218 and then Nkind (Decl) = N_Subprogram_Body);
11220 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11222 -- Look for a null statement followed by an optional return
11223 -- statement.
11225 if Nkind (Stmt1) = N_Null_Statement then
11226 Stmt2 := Next (Stmt1);
11228 if Present (Stmt2) then
11229 return Nkind (Stmt2) = N_Simple_Return_Statement;
11230 else
11231 return True;
11232 end if;
11233 end if;
11235 return False;
11236 end Has_Null_Body;
11238 ------------------------
11239 -- Has_Null_Exclusion --
11240 ------------------------
11242 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11243 begin
11244 case Nkind (N) is
11245 when N_Access_Definition
11246 | N_Access_Function_Definition
11247 | N_Access_Procedure_Definition
11248 | N_Access_To_Object_Definition
11249 | N_Allocator
11250 | N_Derived_Type_Definition
11251 | N_Function_Specification
11252 | N_Subtype_Declaration
11254 return Null_Exclusion_Present (N);
11256 when N_Component_Definition
11257 | N_Formal_Object_Declaration
11258 | N_Object_Renaming_Declaration
11260 if Present (Subtype_Mark (N)) then
11261 return Null_Exclusion_Present (N);
11262 else pragma Assert (Present (Access_Definition (N)));
11263 return Null_Exclusion_Present (Access_Definition (N));
11264 end if;
11266 when N_Discriminant_Specification =>
11267 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11268 return Null_Exclusion_Present (Discriminant_Type (N));
11269 else
11270 return Null_Exclusion_Present (N);
11271 end if;
11273 when N_Object_Declaration =>
11274 if Nkind (Object_Definition (N)) = N_Access_Definition then
11275 return Null_Exclusion_Present (Object_Definition (N));
11276 else
11277 return Null_Exclusion_Present (N);
11278 end if;
11280 when N_Parameter_Specification =>
11281 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11282 return Null_Exclusion_Present (Parameter_Type (N));
11283 else
11284 return Null_Exclusion_Present (N);
11285 end if;
11287 when others =>
11288 return False;
11289 end case;
11290 end Has_Null_Exclusion;
11292 ------------------------
11293 -- Has_Null_Extension --
11294 ------------------------
11296 function Has_Null_Extension (T : Entity_Id) return Boolean is
11297 B : constant Entity_Id := Base_Type (T);
11298 Comps : Node_Id;
11299 Ext : Node_Id;
11301 begin
11302 if Nkind (Parent (B)) = N_Full_Type_Declaration
11303 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11304 then
11305 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11307 if Present (Ext) then
11308 if Null_Present (Ext) then
11309 return True;
11310 else
11311 Comps := Component_List (Ext);
11313 -- The null component list is rewritten during analysis to
11314 -- include the parent component. Any other component indicates
11315 -- that the extension was not originally null.
11317 return Null_Present (Comps)
11318 or else No (Next (First (Component_Items (Comps))));
11319 end if;
11320 else
11321 return False;
11322 end if;
11324 else
11325 return False;
11326 end if;
11327 end Has_Null_Extension;
11329 -------------------------
11330 -- Has_Null_Refinement --
11331 -------------------------
11333 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11334 Constits : Elist_Id;
11336 begin
11337 pragma Assert (Ekind (Id) = E_Abstract_State);
11338 Constits := Refinement_Constituents (Id);
11340 -- For a refinement to be null, the state's sole constituent must be a
11341 -- null.
11343 return
11344 Present (Constits)
11345 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11346 end Has_Null_Refinement;
11348 -------------------------------
11349 -- Has_Overriding_Initialize --
11350 -------------------------------
11352 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11353 BT : constant Entity_Id := Base_Type (T);
11354 P : Elmt_Id;
11356 begin
11357 if Is_Controlled (BT) then
11358 if Is_RTU (Scope (BT), Ada_Finalization) then
11359 return False;
11361 elsif Present (Primitive_Operations (BT)) then
11362 P := First_Elmt (Primitive_Operations (BT));
11363 while Present (P) loop
11364 declare
11365 Init : constant Entity_Id := Node (P);
11366 Formal : constant Entity_Id := First_Formal (Init);
11367 begin
11368 if Ekind (Init) = E_Procedure
11369 and then Chars (Init) = Name_Initialize
11370 and then Comes_From_Source (Init)
11371 and then Present (Formal)
11372 and then Etype (Formal) = BT
11373 and then No (Next_Formal (Formal))
11374 and then (Ada_Version < Ada_2012
11375 or else not Null_Present (Parent (Init)))
11376 then
11377 return True;
11378 end if;
11379 end;
11381 Next_Elmt (P);
11382 end loop;
11383 end if;
11385 -- Here if type itself does not have a non-null Initialize operation:
11386 -- check immediate ancestor.
11388 if Is_Derived_Type (BT)
11389 and then Has_Overriding_Initialize (Etype (BT))
11390 then
11391 return True;
11392 end if;
11393 end if;
11395 return False;
11396 end Has_Overriding_Initialize;
11398 --------------------------------------
11399 -- Has_Preelaborable_Initialization --
11400 --------------------------------------
11402 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11403 Has_PE : Boolean;
11405 procedure Check_Components (E : Entity_Id);
11406 -- Check component/discriminant chain, sets Has_PE False if a component
11407 -- or discriminant does not meet the preelaborable initialization rules.
11409 ----------------------
11410 -- Check_Components --
11411 ----------------------
11413 procedure Check_Components (E : Entity_Id) is
11414 Ent : Entity_Id;
11415 Exp : Node_Id;
11417 begin
11418 -- Loop through entities of record or protected type
11420 Ent := E;
11421 while Present (Ent) loop
11423 -- We are interested only in components and discriminants
11425 Exp := Empty;
11427 case Ekind (Ent) is
11428 when E_Component =>
11430 -- Get default expression if any. If there is no declaration
11431 -- node, it means we have an internal entity. The parent and
11432 -- tag fields are examples of such entities. For such cases,
11433 -- we just test the type of the entity.
11435 if Present (Declaration_Node (Ent)) then
11436 Exp := Expression (Declaration_Node (Ent));
11437 end if;
11439 when E_Discriminant =>
11441 -- Note: for a renamed discriminant, the Declaration_Node
11442 -- may point to the one from the ancestor, and have a
11443 -- different expression, so use the proper attribute to
11444 -- retrieve the expression from the derived constraint.
11446 Exp := Discriminant_Default_Value (Ent);
11448 when others =>
11449 goto Check_Next_Entity;
11450 end case;
11452 -- A component has PI if it has no default expression and the
11453 -- component type has PI.
11455 if No (Exp) then
11456 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11457 Has_PE := False;
11458 exit;
11459 end if;
11461 -- Require the default expression to be preelaborable
11463 elsif not Is_Preelaborable_Construct (Exp) then
11464 Has_PE := False;
11465 exit;
11466 end if;
11468 <<Check_Next_Entity>>
11469 Next_Entity (Ent);
11470 end loop;
11471 end Check_Components;
11473 -- Start of processing for Has_Preelaborable_Initialization
11475 begin
11476 -- Immediate return if already marked as known preelaborable init. This
11477 -- covers types for which this function has already been called once
11478 -- and returned True (in which case the result is cached), and also
11479 -- types to which a pragma Preelaborable_Initialization applies.
11481 if Known_To_Have_Preelab_Init (E) then
11482 return True;
11483 end if;
11485 -- If the type is a subtype representing a generic actual type, then
11486 -- test whether its base type has preelaborable initialization since
11487 -- the subtype representing the actual does not inherit this attribute
11488 -- from the actual or formal. (but maybe it should???)
11490 if Is_Generic_Actual_Type (E) then
11491 return Has_Preelaborable_Initialization (Base_Type (E));
11492 end if;
11494 -- All elementary types have preelaborable initialization
11496 if Is_Elementary_Type (E) then
11497 Has_PE := True;
11499 -- Array types have PI if the component type has PI
11501 elsif Is_Array_Type (E) then
11502 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11504 -- A derived type has preelaborable initialization if its parent type
11505 -- has preelaborable initialization and (in the case of a derived record
11506 -- extension) if the non-inherited components all have preelaborable
11507 -- initialization. However, a user-defined controlled type with an
11508 -- overriding Initialize procedure does not have preelaborable
11509 -- initialization.
11511 elsif Is_Derived_Type (E) then
11513 -- If the derived type is a private extension then it doesn't have
11514 -- preelaborable initialization.
11516 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11517 return False;
11518 end if;
11520 -- First check whether ancestor type has preelaborable initialization
11522 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11524 -- If OK, check extension components (if any)
11526 if Has_PE and then Is_Record_Type (E) then
11527 Check_Components (First_Entity (E));
11528 end if;
11530 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11531 -- with a user defined Initialize procedure does not have PI. If
11532 -- the type is untagged, the control primitives come from a component
11533 -- that has already been checked.
11535 if Has_PE
11536 and then Is_Controlled (E)
11537 and then Is_Tagged_Type (E)
11538 and then Has_Overriding_Initialize (E)
11539 then
11540 Has_PE := False;
11541 end if;
11543 -- Private types not derived from a type having preelaborable init and
11544 -- that are not marked with pragma Preelaborable_Initialization do not
11545 -- have preelaborable initialization.
11547 elsif Is_Private_Type (E) then
11548 return False;
11550 -- Record type has PI if it is non private and all components have PI
11552 elsif Is_Record_Type (E) then
11553 Has_PE := True;
11554 Check_Components (First_Entity (E));
11556 -- Protected types must not have entries, and components must meet
11557 -- same set of rules as for record components.
11559 elsif Is_Protected_Type (E) then
11560 if Has_Entries (E) then
11561 Has_PE := False;
11562 else
11563 Has_PE := True;
11564 Check_Components (First_Entity (E));
11565 Check_Components (First_Private_Entity (E));
11566 end if;
11568 -- Type System.Address always has preelaborable initialization
11570 elsif Is_RTE (E, RE_Address) then
11571 Has_PE := True;
11573 -- In all other cases, type does not have preelaborable initialization
11575 else
11576 return False;
11577 end if;
11579 -- If type has preelaborable initialization, cache result
11581 if Has_PE then
11582 Set_Known_To_Have_Preelab_Init (E);
11583 end if;
11585 return Has_PE;
11586 end Has_Preelaborable_Initialization;
11588 ----------------
11589 -- Has_Prefix --
11590 ----------------
11592 function Has_Prefix (N : Node_Id) return Boolean is
11593 begin
11594 return
11595 Nkind_In (N, N_Attribute_Reference,
11596 N_Expanded_Name,
11597 N_Explicit_Dereference,
11598 N_Indexed_Component,
11599 N_Reference,
11600 N_Selected_Component,
11601 N_Slice);
11602 end Has_Prefix;
11604 ---------------------------
11605 -- Has_Private_Component --
11606 ---------------------------
11608 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11609 Btype : Entity_Id := Base_Type (Type_Id);
11610 Component : Entity_Id;
11612 begin
11613 if Error_Posted (Type_Id)
11614 or else Error_Posted (Btype)
11615 then
11616 return False;
11617 end if;
11619 if Is_Class_Wide_Type (Btype) then
11620 Btype := Root_Type (Btype);
11621 end if;
11623 if Is_Private_Type (Btype) then
11624 declare
11625 UT : constant Entity_Id := Underlying_Type (Btype);
11626 begin
11627 if No (UT) then
11628 if No (Full_View (Btype)) then
11629 return not Is_Generic_Type (Btype)
11630 and then
11631 not Is_Generic_Type (Root_Type (Btype));
11632 else
11633 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11634 end if;
11635 else
11636 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11637 end if;
11638 end;
11640 elsif Is_Array_Type (Btype) then
11641 return Has_Private_Component (Component_Type (Btype));
11643 elsif Is_Record_Type (Btype) then
11644 Component := First_Component (Btype);
11645 while Present (Component) loop
11646 if Has_Private_Component (Etype (Component)) then
11647 return True;
11648 end if;
11650 Next_Component (Component);
11651 end loop;
11653 return False;
11655 elsif Is_Protected_Type (Btype)
11656 and then Present (Corresponding_Record_Type (Btype))
11657 then
11658 return Has_Private_Component (Corresponding_Record_Type (Btype));
11660 else
11661 return False;
11662 end if;
11663 end Has_Private_Component;
11665 ----------------------
11666 -- Has_Signed_Zeros --
11667 ----------------------
11669 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11670 begin
11671 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11672 end Has_Signed_Zeros;
11674 ------------------------------
11675 -- Has_Significant_Contract --
11676 ------------------------------
11678 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11679 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11681 begin
11682 -- _Finalizer procedure
11684 if Subp_Nam = Name_uFinalizer then
11685 return False;
11687 -- _Postconditions procedure
11689 elsif Subp_Nam = Name_uPostconditions then
11690 return False;
11692 -- Predicate function
11694 elsif Ekind (Subp_Id) = E_Function
11695 and then Is_Predicate_Function (Subp_Id)
11696 then
11697 return False;
11699 -- TSS subprogram
11701 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11702 return False;
11704 else
11705 return True;
11706 end if;
11707 end Has_Significant_Contract;
11709 -----------------------------
11710 -- Has_Static_Array_Bounds --
11711 -----------------------------
11713 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11714 All_Static : Boolean;
11715 Dummy : Boolean;
11717 begin
11718 Examine_Array_Bounds (Typ, All_Static, Dummy);
11720 return All_Static;
11721 end Has_Static_Array_Bounds;
11723 ---------------------------------------
11724 -- Has_Static_Non_Empty_Array_Bounds --
11725 ---------------------------------------
11727 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
11728 All_Static : Boolean;
11729 Has_Empty : Boolean;
11731 begin
11732 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
11734 return All_Static and not Has_Empty;
11735 end Has_Static_Non_Empty_Array_Bounds;
11737 ----------------
11738 -- Has_Stream --
11739 ----------------
11741 function Has_Stream (T : Entity_Id) return Boolean is
11742 E : Entity_Id;
11744 begin
11745 if No (T) then
11746 return False;
11748 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11749 return True;
11751 elsif Is_Array_Type (T) then
11752 return Has_Stream (Component_Type (T));
11754 elsif Is_Record_Type (T) then
11755 E := First_Component (T);
11756 while Present (E) loop
11757 if Has_Stream (Etype (E)) then
11758 return True;
11759 else
11760 Next_Component (E);
11761 end if;
11762 end loop;
11764 return False;
11766 elsif Is_Private_Type (T) then
11767 return Has_Stream (Underlying_Type (T));
11769 else
11770 return False;
11771 end if;
11772 end Has_Stream;
11774 ----------------
11775 -- Has_Suffix --
11776 ----------------
11778 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11779 begin
11780 Get_Name_String (Chars (E));
11781 return Name_Buffer (Name_Len) = Suffix;
11782 end Has_Suffix;
11784 ----------------
11785 -- Add_Suffix --
11786 ----------------
11788 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11789 begin
11790 Get_Name_String (Chars (E));
11791 Add_Char_To_Name_Buffer (Suffix);
11792 return Name_Find;
11793 end Add_Suffix;
11795 -------------------
11796 -- Remove_Suffix --
11797 -------------------
11799 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11800 begin
11801 pragma Assert (Has_Suffix (E, Suffix));
11802 Get_Name_String (Chars (E));
11803 Name_Len := Name_Len - 1;
11804 return Name_Find;
11805 end Remove_Suffix;
11807 ----------------------------------
11808 -- Replace_Null_By_Null_Address --
11809 ----------------------------------
11811 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11812 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11813 -- Replace operand Op with a reference to Null_Address when the operand
11814 -- denotes a null Address. Other_Op denotes the other operand.
11816 --------------------------
11817 -- Replace_Null_Operand --
11818 --------------------------
11820 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11821 begin
11822 -- Check the type of the complementary operand since the N_Null node
11823 -- has not been decorated yet.
11825 if Nkind (Op) = N_Null
11826 and then Is_Descendant_Of_Address (Etype (Other_Op))
11827 then
11828 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11829 end if;
11830 end Replace_Null_Operand;
11832 -- Start of processing for Replace_Null_By_Null_Address
11834 begin
11835 pragma Assert (Relaxed_RM_Semantics);
11836 pragma Assert (Nkind_In (N, N_Null,
11837 N_Op_Eq,
11838 N_Op_Ge,
11839 N_Op_Gt,
11840 N_Op_Le,
11841 N_Op_Lt,
11842 N_Op_Ne));
11844 if Nkind (N) = N_Null then
11845 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11847 else
11848 declare
11849 L : constant Node_Id := Left_Opnd (N);
11850 R : constant Node_Id := Right_Opnd (N);
11852 begin
11853 Replace_Null_Operand (L, Other_Op => R);
11854 Replace_Null_Operand (R, Other_Op => L);
11855 end;
11856 end if;
11857 end Replace_Null_By_Null_Address;
11859 --------------------------
11860 -- Has_Tagged_Component --
11861 --------------------------
11863 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11864 Comp : Entity_Id;
11866 begin
11867 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11868 return Has_Tagged_Component (Underlying_Type (Typ));
11870 elsif Is_Array_Type (Typ) then
11871 return Has_Tagged_Component (Component_Type (Typ));
11873 elsif Is_Tagged_Type (Typ) then
11874 return True;
11876 elsif Is_Record_Type (Typ) then
11877 Comp := First_Component (Typ);
11878 while Present (Comp) loop
11879 if Has_Tagged_Component (Etype (Comp)) then
11880 return True;
11881 end if;
11883 Next_Component (Comp);
11884 end loop;
11886 return False;
11888 else
11889 return False;
11890 end if;
11891 end Has_Tagged_Component;
11893 -----------------------------
11894 -- Has_Undefined_Reference --
11895 -----------------------------
11897 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11898 Has_Undef_Ref : Boolean := False;
11899 -- Flag set when expression Expr contains at least one undefined
11900 -- reference.
11902 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11903 -- Determine whether N denotes a reference and if it does, whether it is
11904 -- undefined.
11906 ----------------------------
11907 -- Is_Undefined_Reference --
11908 ----------------------------
11910 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11911 begin
11912 if Is_Entity_Name (N)
11913 and then Present (Entity (N))
11914 and then Entity (N) = Any_Id
11915 then
11916 Has_Undef_Ref := True;
11917 return Abandon;
11918 end if;
11920 return OK;
11921 end Is_Undefined_Reference;
11923 procedure Find_Undefined_References is
11924 new Traverse_Proc (Is_Undefined_Reference);
11926 -- Start of processing for Has_Undefined_Reference
11928 begin
11929 Find_Undefined_References (Expr);
11931 return Has_Undef_Ref;
11932 end Has_Undefined_Reference;
11934 ----------------------------
11935 -- Has_Volatile_Component --
11936 ----------------------------
11938 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11939 Comp : Entity_Id;
11941 begin
11942 if Has_Volatile_Components (Typ) then
11943 return True;
11945 elsif Is_Array_Type (Typ) then
11946 return Is_Volatile (Component_Type (Typ));
11948 elsif Is_Record_Type (Typ) then
11949 Comp := First_Component (Typ);
11950 while Present (Comp) loop
11951 if Is_Volatile_Object (Comp) then
11952 return True;
11953 end if;
11955 Comp := Next_Component (Comp);
11956 end loop;
11957 end if;
11959 return False;
11960 end Has_Volatile_Component;
11962 -------------------------
11963 -- Implementation_Kind --
11964 -------------------------
11966 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11967 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11968 Arg : Node_Id;
11969 begin
11970 pragma Assert (Present (Impl_Prag));
11971 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11972 return Chars (Get_Pragma_Arg (Arg));
11973 end Implementation_Kind;
11975 --------------------------
11976 -- Implements_Interface --
11977 --------------------------
11979 function Implements_Interface
11980 (Typ_Ent : Entity_Id;
11981 Iface_Ent : Entity_Id;
11982 Exclude_Parents : Boolean := False) return Boolean
11984 Ifaces_List : Elist_Id;
11985 Elmt : Elmt_Id;
11986 Iface : Entity_Id := Base_Type (Iface_Ent);
11987 Typ : Entity_Id := Base_Type (Typ_Ent);
11989 begin
11990 if Is_Class_Wide_Type (Typ) then
11991 Typ := Root_Type (Typ);
11992 end if;
11994 if not Has_Interfaces (Typ) then
11995 return False;
11996 end if;
11998 if Is_Class_Wide_Type (Iface) then
11999 Iface := Root_Type (Iface);
12000 end if;
12002 Collect_Interfaces (Typ, Ifaces_List);
12004 Elmt := First_Elmt (Ifaces_List);
12005 while Present (Elmt) loop
12006 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
12007 and then Exclude_Parents
12008 then
12009 null;
12011 elsif Node (Elmt) = Iface then
12012 return True;
12013 end if;
12015 Next_Elmt (Elmt);
12016 end loop;
12018 return False;
12019 end Implements_Interface;
12021 ------------------------------------
12022 -- In_Assertion_Expression_Pragma --
12023 ------------------------------------
12025 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
12026 Par : Node_Id;
12027 Prag : Node_Id := Empty;
12029 begin
12030 -- Climb the parent chain looking for an enclosing pragma
12032 Par := N;
12033 while Present (Par) loop
12034 if Nkind (Par) = N_Pragma then
12035 Prag := Par;
12036 exit;
12038 -- Precondition-like pragmas are expanded into if statements, check
12039 -- the original node instead.
12041 elsif Nkind (Original_Node (Par)) = N_Pragma then
12042 Prag := Original_Node (Par);
12043 exit;
12045 -- The expansion of attribute 'Old generates a constant to capture
12046 -- the result of the prefix. If the parent traversal reaches
12047 -- one of these constants, then the node technically came from a
12048 -- postcondition-like pragma. Note that the Ekind is not tested here
12049 -- because N may be the expression of an object declaration which is
12050 -- currently being analyzed. Such objects carry Ekind of E_Void.
12052 elsif Nkind (Par) = N_Object_Declaration
12053 and then Constant_Present (Par)
12054 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
12055 then
12056 return True;
12058 -- Prevent the search from going too far
12060 elsif Is_Body_Or_Package_Declaration (Par) then
12061 return False;
12062 end if;
12064 Par := Parent (Par);
12065 end loop;
12067 return
12068 Present (Prag)
12069 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
12070 end In_Assertion_Expression_Pragma;
12072 ----------------------
12073 -- In_Generic_Scope --
12074 ----------------------
12076 function In_Generic_Scope (E : Entity_Id) return Boolean is
12077 S : Entity_Id;
12079 begin
12080 S := Scope (E);
12081 while Present (S) and then S /= Standard_Standard loop
12082 if Is_Generic_Unit (S) then
12083 return True;
12084 end if;
12086 S := Scope (S);
12087 end loop;
12089 return False;
12090 end In_Generic_Scope;
12092 -----------------
12093 -- In_Instance --
12094 -----------------
12096 function In_Instance return Boolean is
12097 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12098 S : Entity_Id;
12100 begin
12101 S := Current_Scope;
12102 while Present (S) and then S /= Standard_Standard loop
12103 if Is_Generic_Instance (S) then
12105 -- A child instance is always compiled in the context of a parent
12106 -- instance. Nevertheless, the actuals are not analyzed in an
12107 -- instance context. We detect this case by examining the current
12108 -- compilation unit, which must be a child instance, and checking
12109 -- that it is not currently on the scope stack.
12111 if Is_Child_Unit (Curr_Unit)
12112 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
12113 N_Package_Instantiation
12114 and then not In_Open_Scopes (Curr_Unit)
12115 then
12116 return False;
12117 else
12118 return True;
12119 end if;
12120 end if;
12122 S := Scope (S);
12123 end loop;
12125 return False;
12126 end In_Instance;
12128 ----------------------
12129 -- In_Instance_Body --
12130 ----------------------
12132 function In_Instance_Body return Boolean is
12133 S : Entity_Id;
12135 begin
12136 S := Current_Scope;
12137 while Present (S) and then S /= Standard_Standard loop
12138 if Ekind_In (S, E_Function, E_Procedure)
12139 and then Is_Generic_Instance (S)
12140 then
12141 return True;
12143 elsif Ekind (S) = E_Package
12144 and then In_Package_Body (S)
12145 and then Is_Generic_Instance (S)
12146 then
12147 return True;
12148 end if;
12150 S := Scope (S);
12151 end loop;
12153 return False;
12154 end In_Instance_Body;
12156 -----------------------------
12157 -- In_Instance_Not_Visible --
12158 -----------------------------
12160 function In_Instance_Not_Visible return Boolean is
12161 S : Entity_Id;
12163 begin
12164 S := Current_Scope;
12165 while Present (S) and then S /= Standard_Standard loop
12166 if Ekind_In (S, E_Function, E_Procedure)
12167 and then Is_Generic_Instance (S)
12168 then
12169 return True;
12171 elsif Ekind (S) = E_Package
12172 and then (In_Package_Body (S) or else In_Private_Part (S))
12173 and then Is_Generic_Instance (S)
12174 then
12175 return True;
12176 end if;
12178 S := Scope (S);
12179 end loop;
12181 return False;
12182 end In_Instance_Not_Visible;
12184 ------------------------------
12185 -- In_Instance_Visible_Part --
12186 ------------------------------
12188 function In_Instance_Visible_Part
12189 (Id : Entity_Id := Current_Scope) return Boolean
12191 Inst : Entity_Id;
12193 begin
12194 Inst := Id;
12195 while Present (Inst) and then Inst /= Standard_Standard loop
12196 if Ekind (Inst) = E_Package
12197 and then Is_Generic_Instance (Inst)
12198 and then not In_Package_Body (Inst)
12199 and then not In_Private_Part (Inst)
12200 then
12201 return True;
12202 end if;
12204 Inst := Scope (Inst);
12205 end loop;
12207 return False;
12208 end In_Instance_Visible_Part;
12210 ---------------------
12211 -- In_Package_Body --
12212 ---------------------
12214 function In_Package_Body return Boolean is
12215 S : Entity_Id;
12217 begin
12218 S := Current_Scope;
12219 while Present (S) and then S /= Standard_Standard loop
12220 if Ekind (S) = E_Package and then In_Package_Body (S) then
12221 return True;
12222 else
12223 S := Scope (S);
12224 end if;
12225 end loop;
12227 return False;
12228 end In_Package_Body;
12230 --------------------------
12231 -- In_Pragma_Expression --
12232 --------------------------
12234 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12235 P : Node_Id;
12236 begin
12237 P := Parent (N);
12238 loop
12239 if No (P) then
12240 return False;
12241 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12242 return True;
12243 else
12244 P := Parent (P);
12245 end if;
12246 end loop;
12247 end In_Pragma_Expression;
12249 ---------------------------
12250 -- In_Pre_Post_Condition --
12251 ---------------------------
12253 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12254 Par : Node_Id;
12255 Prag : Node_Id := Empty;
12256 Prag_Id : Pragma_Id;
12258 begin
12259 -- Climb the parent chain looking for an enclosing pragma
12261 Par := N;
12262 while Present (Par) loop
12263 if Nkind (Par) = N_Pragma then
12264 Prag := Par;
12265 exit;
12267 -- Prevent the search from going too far
12269 elsif Is_Body_Or_Package_Declaration (Par) then
12270 exit;
12271 end if;
12273 Par := Parent (Par);
12274 end loop;
12276 if Present (Prag) then
12277 Prag_Id := Get_Pragma_Id (Prag);
12279 return
12280 Prag_Id = Pragma_Post
12281 or else Prag_Id = Pragma_Post_Class
12282 or else Prag_Id = Pragma_Postcondition
12283 or else Prag_Id = Pragma_Pre
12284 or else Prag_Id = Pragma_Pre_Class
12285 or else Prag_Id = Pragma_Precondition;
12287 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12289 else
12290 return False;
12291 end if;
12292 end In_Pre_Post_Condition;
12294 -------------------------------------
12295 -- In_Reverse_Storage_Order_Object --
12296 -------------------------------------
12298 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12299 Pref : Node_Id;
12300 Btyp : Entity_Id := Empty;
12302 begin
12303 -- Climb up indexed components
12305 Pref := N;
12306 loop
12307 case Nkind (Pref) is
12308 when N_Selected_Component =>
12309 Pref := Prefix (Pref);
12310 exit;
12312 when N_Indexed_Component =>
12313 Pref := Prefix (Pref);
12315 when others =>
12316 Pref := Empty;
12317 exit;
12318 end case;
12319 end loop;
12321 if Present (Pref) then
12322 Btyp := Base_Type (Etype (Pref));
12323 end if;
12325 return Present (Btyp)
12326 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12327 and then Reverse_Storage_Order (Btyp);
12328 end In_Reverse_Storage_Order_Object;
12330 ------------------------------
12331 -- In_Same_Declarative_Part --
12332 ------------------------------
12334 function In_Same_Declarative_Part
12335 (Context : Node_Id;
12336 N : Node_Id) return Boolean
12338 Cont : Node_Id := Context;
12339 Nod : Node_Id;
12341 begin
12342 if Nkind (Cont) = N_Compilation_Unit_Aux then
12343 Cont := Parent (Cont);
12344 end if;
12346 Nod := Parent (N);
12347 while Present (Nod) loop
12348 if Nod = Cont then
12349 return True;
12351 elsif Nkind_In (Nod, N_Accept_Statement,
12352 N_Block_Statement,
12353 N_Compilation_Unit,
12354 N_Entry_Body,
12355 N_Package_Body,
12356 N_Package_Declaration,
12357 N_Protected_Body,
12358 N_Subprogram_Body,
12359 N_Task_Body)
12360 then
12361 return False;
12363 elsif Nkind (Nod) = N_Subunit then
12364 Nod := Corresponding_Stub (Nod);
12366 else
12367 Nod := Parent (Nod);
12368 end if;
12369 end loop;
12371 return False;
12372 end In_Same_Declarative_Part;
12374 --------------------------------------
12375 -- In_Subprogram_Or_Concurrent_Unit --
12376 --------------------------------------
12378 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12379 E : Entity_Id;
12380 K : Entity_Kind;
12382 begin
12383 -- Use scope chain to check successively outer scopes
12385 E := Current_Scope;
12386 loop
12387 K := Ekind (E);
12389 if K in Subprogram_Kind
12390 or else K in Concurrent_Kind
12391 or else K in Generic_Subprogram_Kind
12392 then
12393 return True;
12395 elsif E = Standard_Standard then
12396 return False;
12397 end if;
12399 E := Scope (E);
12400 end loop;
12401 end In_Subprogram_Or_Concurrent_Unit;
12403 ----------------
12404 -- In_Subtree --
12405 ----------------
12407 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12408 Curr : Node_Id;
12410 begin
12411 Curr := N;
12412 while Present (Curr) loop
12413 if Curr = Root then
12414 return True;
12415 end if;
12417 Curr := Parent (Curr);
12418 end loop;
12420 return False;
12421 end In_Subtree;
12423 ----------------
12424 -- In_Subtree --
12425 ----------------
12427 function In_Subtree
12428 (N : Node_Id;
12429 Root1 : Node_Id;
12430 Root2 : Node_Id) return Boolean
12432 Curr : Node_Id;
12434 begin
12435 Curr := N;
12436 while Present (Curr) loop
12437 if Curr = Root1 or else Curr = Root2 then
12438 return True;
12439 end if;
12441 Curr := Parent (Curr);
12442 end loop;
12444 return False;
12445 end In_Subtree;
12447 ---------------------
12448 -- In_Visible_Part --
12449 ---------------------
12451 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12452 begin
12453 return Is_Package_Or_Generic_Package (Scope_Id)
12454 and then In_Open_Scopes (Scope_Id)
12455 and then not In_Package_Body (Scope_Id)
12456 and then not In_Private_Part (Scope_Id);
12457 end In_Visible_Part;
12459 --------------------------------
12460 -- Incomplete_Or_Partial_View --
12461 --------------------------------
12463 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12464 function Inspect_Decls
12465 (Decls : List_Id;
12466 Taft : Boolean := False) return Entity_Id;
12467 -- Check whether a declarative region contains the incomplete or partial
12468 -- view of Id.
12470 -------------------
12471 -- Inspect_Decls --
12472 -------------------
12474 function Inspect_Decls
12475 (Decls : List_Id;
12476 Taft : Boolean := False) return Entity_Id
12478 Decl : Node_Id;
12479 Match : Node_Id;
12481 begin
12482 Decl := First (Decls);
12483 while Present (Decl) loop
12484 Match := Empty;
12486 -- The partial view of a Taft-amendment type is an incomplete
12487 -- type.
12489 if Taft then
12490 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12491 Match := Defining_Identifier (Decl);
12492 end if;
12494 -- Otherwise look for a private type whose full view matches the
12495 -- input type. Note that this checks full_type_declaration nodes
12496 -- to account for derivations from a private type where the type
12497 -- declaration hold the partial view and the full view is an
12498 -- itype.
12500 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12501 N_Private_Extension_Declaration,
12502 N_Private_Type_Declaration)
12503 then
12504 Match := Defining_Identifier (Decl);
12505 end if;
12507 -- Guard against unanalyzed entities
12509 if Present (Match)
12510 and then Is_Type (Match)
12511 and then Present (Full_View (Match))
12512 and then Full_View (Match) = Id
12513 then
12514 return Match;
12515 end if;
12517 Next (Decl);
12518 end loop;
12520 return Empty;
12521 end Inspect_Decls;
12523 -- Local variables
12525 Prev : Entity_Id;
12527 -- Start of processing for Incomplete_Or_Partial_View
12529 begin
12530 -- Deferred constant or incomplete type case
12532 Prev := Current_Entity_In_Scope (Id);
12534 if Present (Prev)
12535 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12536 and then Present (Full_View (Prev))
12537 and then Full_View (Prev) = Id
12538 then
12539 return Prev;
12540 end if;
12542 -- Private or Taft amendment type case
12544 declare
12545 Pkg : constant Entity_Id := Scope (Id);
12546 Pkg_Decl : Node_Id := Pkg;
12548 begin
12549 if Present (Pkg)
12550 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12551 then
12552 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12553 Pkg_Decl := Parent (Pkg_Decl);
12554 end loop;
12556 -- It is knows that Typ has a private view, look for it in the
12557 -- visible declarations of the enclosing scope. A special case
12558 -- of this is when the two views have been exchanged - the full
12559 -- appears earlier than the private.
12561 if Has_Private_Declaration (Id) then
12562 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12564 -- Exchanged view case, look in the private declarations
12566 if No (Prev) then
12567 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12568 end if;
12570 return Prev;
12572 -- Otherwise if this is the package body, then Typ is a potential
12573 -- Taft amendment type. The incomplete view should be located in
12574 -- the private declarations of the enclosing scope.
12576 elsif In_Package_Body (Pkg) then
12577 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12578 end if;
12579 end if;
12580 end;
12582 -- The type has no incomplete or private view
12584 return Empty;
12585 end Incomplete_Or_Partial_View;
12587 ---------------------------------------
12588 -- Incomplete_View_From_Limited_With --
12589 ---------------------------------------
12591 function Incomplete_View_From_Limited_With
12592 (Typ : Entity_Id) return Entity_Id
12594 begin
12595 -- It might make sense to make this an attribute in Einfo, and set it
12596 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12597 -- slots for new attributes, and it seems a bit simpler to just search
12598 -- the Limited_View (if it exists) for an incomplete type whose
12599 -- Non_Limited_View is Typ.
12601 if Ekind (Scope (Typ)) = E_Package
12602 and then Present (Limited_View (Scope (Typ)))
12603 then
12604 declare
12605 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12606 begin
12607 while Present (Ent) loop
12608 if Ekind (Ent) in Incomplete_Kind
12609 and then Non_Limited_View (Ent) = Typ
12610 then
12611 return Ent;
12612 end if;
12614 Ent := Next_Entity (Ent);
12615 end loop;
12616 end;
12617 end if;
12619 return Typ;
12620 end Incomplete_View_From_Limited_With;
12622 ----------------------------------
12623 -- Indexed_Component_Bit_Offset --
12624 ----------------------------------
12626 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12627 Exp : constant Node_Id := First (Expressions (N));
12628 Typ : constant Entity_Id := Etype (Prefix (N));
12629 Off : constant Uint := Component_Size (Typ);
12630 Ind : Node_Id;
12632 begin
12633 -- Return early if the component size is not known or variable
12635 if Off = No_Uint or else Off < Uint_0 then
12636 return No_Uint;
12637 end if;
12639 -- Deal with the degenerate case of an empty component
12641 if Off = Uint_0 then
12642 return Off;
12643 end if;
12645 -- Check that both the index value and the low bound are known
12647 if not Compile_Time_Known_Value (Exp) then
12648 return No_Uint;
12649 end if;
12651 Ind := First_Index (Typ);
12652 if No (Ind) then
12653 return No_Uint;
12654 end if;
12656 if Nkind (Ind) = N_Subtype_Indication then
12657 Ind := Constraint (Ind);
12659 if Nkind (Ind) = N_Range_Constraint then
12660 Ind := Range_Expression (Ind);
12661 end if;
12662 end if;
12664 if Nkind (Ind) /= N_Range
12665 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12666 then
12667 return No_Uint;
12668 end if;
12670 -- Return the scaled offset
12672 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12673 end Indexed_Component_Bit_Offset;
12675 ----------------------------
12676 -- Inherit_Rep_Item_Chain --
12677 ----------------------------
12679 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12680 Item : Node_Id;
12681 Next_Item : Node_Id;
12683 begin
12684 -- There are several inheritance scenarios to consider depending on
12685 -- whether both types have rep item chains and whether the destination
12686 -- type already inherits part of the source type's rep item chain.
12688 -- 1) The source type lacks a rep item chain
12689 -- From_Typ ---> Empty
12691 -- Typ --------> Item (or Empty)
12693 -- In this case inheritance cannot take place because there are no items
12694 -- to inherit.
12696 -- 2) The destination type lacks a rep item chain
12697 -- From_Typ ---> Item ---> ...
12699 -- Typ --------> Empty
12701 -- Inheritance takes place by setting the First_Rep_Item of the
12702 -- destination type to the First_Rep_Item of the source type.
12703 -- From_Typ ---> Item ---> ...
12704 -- ^
12705 -- Typ -----------+
12707 -- 3.1) Both source and destination types have at least one rep item.
12708 -- The destination type does NOT inherit a rep item from the source
12709 -- type.
12710 -- From_Typ ---> Item ---> Item
12712 -- Typ --------> Item ---> Item
12714 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12715 -- of the destination type to the First_Rep_Item of the source type.
12716 -- From_Typ -------------------> Item ---> Item
12717 -- ^
12718 -- Typ --------> Item ---> Item --+
12720 -- 3.2) Both source and destination types have at least one rep item.
12721 -- The destination type DOES inherit part of the rep item chain of the
12722 -- source type.
12723 -- From_Typ ---> Item ---> Item ---> Item
12724 -- ^
12725 -- Typ --------> Item ------+
12727 -- This rare case arises when the full view of a private extension must
12728 -- inherit the rep item chain from the full view of its parent type and
12729 -- the full view of the parent type contains extra rep items. Currently
12730 -- only invariants may lead to such form of inheritance.
12732 -- type From_Typ is tagged private
12733 -- with Type_Invariant'Class => Item_2;
12735 -- type Typ is new From_Typ with private
12736 -- with Type_Invariant => Item_4;
12738 -- At this point the rep item chains contain the following items
12740 -- From_Typ -----------> Item_2 ---> Item_3
12741 -- ^
12742 -- Typ --------> Item_4 --+
12744 -- The full views of both types may introduce extra invariants
12746 -- type From_Typ is tagged null record
12747 -- with Type_Invariant => Item_1;
12749 -- type Typ is new From_Typ with null record;
12751 -- The full view of Typ would have to inherit any new rep items added to
12752 -- the full view of From_Typ.
12754 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12755 -- ^
12756 -- Typ --------> Item_4 --+
12758 -- To achieve this form of inheritance, the destination type must first
12759 -- sever the link between its own rep chain and that of the source type,
12760 -- then inheritance 3.1 takes place.
12762 -- Case 1: The source type lacks a rep item chain
12764 if No (First_Rep_Item (From_Typ)) then
12765 return;
12767 -- Case 2: The destination type lacks a rep item chain
12769 elsif No (First_Rep_Item (Typ)) then
12770 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12772 -- Case 3: Both the source and destination types have at least one rep
12773 -- item. Traverse the rep item chain of the destination type to find the
12774 -- last rep item.
12776 else
12777 Item := Empty;
12778 Next_Item := First_Rep_Item (Typ);
12779 while Present (Next_Item) loop
12781 -- Detect a link between the destination type's rep chain and that
12782 -- of the source type. There are two possibilities:
12784 -- Variant 1
12785 -- Next_Item
12786 -- V
12787 -- From_Typ ---> Item_1 --->
12788 -- ^
12789 -- Typ -----------+
12791 -- Item is Empty
12793 -- Variant 2
12794 -- Next_Item
12795 -- V
12796 -- From_Typ ---> Item_1 ---> Item_2 --->
12797 -- ^
12798 -- Typ --------> Item_3 ------+
12799 -- ^
12800 -- Item
12802 if Has_Rep_Item (From_Typ, Next_Item) then
12803 exit;
12804 end if;
12806 Item := Next_Item;
12807 Next_Item := Next_Rep_Item (Next_Item);
12808 end loop;
12810 -- Inherit the source type's rep item chain
12812 if Present (Item) then
12813 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12814 else
12815 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12816 end if;
12817 end if;
12818 end Inherit_Rep_Item_Chain;
12820 ------------------------------------
12821 -- Inherits_From_Tagged_Full_View --
12822 ------------------------------------
12824 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
12825 begin
12826 return Is_Private_Type (Typ)
12827 and then Present (Full_View (Typ))
12828 and then Is_Private_Type (Full_View (Typ))
12829 and then not Is_Tagged_Type (Full_View (Typ))
12830 and then Present (Underlying_Type (Full_View (Typ)))
12831 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
12832 end Inherits_From_Tagged_Full_View;
12834 ---------------------------------
12835 -- Insert_Explicit_Dereference --
12836 ---------------------------------
12838 procedure Insert_Explicit_Dereference (N : Node_Id) is
12839 New_Prefix : constant Node_Id := Relocate_Node (N);
12840 Ent : Entity_Id := Empty;
12841 Pref : Node_Id;
12842 I : Interp_Index;
12843 It : Interp;
12844 T : Entity_Id;
12846 begin
12847 Save_Interps (N, New_Prefix);
12849 Rewrite (N,
12850 Make_Explicit_Dereference (Sloc (Parent (N)),
12851 Prefix => New_Prefix));
12853 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12855 if Is_Overloaded (New_Prefix) then
12857 -- The dereference is also overloaded, and its interpretations are
12858 -- the designated types of the interpretations of the original node.
12860 Set_Etype (N, Any_Type);
12862 Get_First_Interp (New_Prefix, I, It);
12863 while Present (It.Nam) loop
12864 T := It.Typ;
12866 if Is_Access_Type (T) then
12867 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12868 end if;
12870 Get_Next_Interp (I, It);
12871 end loop;
12873 End_Interp_List;
12875 else
12876 -- Prefix is unambiguous: mark the original prefix (which might
12877 -- Come_From_Source) as a reference, since the new (relocated) one
12878 -- won't be taken into account.
12880 if Is_Entity_Name (New_Prefix) then
12881 Ent := Entity (New_Prefix);
12882 Pref := New_Prefix;
12884 -- For a retrieval of a subcomponent of some composite object,
12885 -- retrieve the ultimate entity if there is one.
12887 elsif Nkind_In (New_Prefix, N_Selected_Component,
12888 N_Indexed_Component)
12889 then
12890 Pref := Prefix (New_Prefix);
12891 while Present (Pref)
12892 and then Nkind_In (Pref, N_Selected_Component,
12893 N_Indexed_Component)
12894 loop
12895 Pref := Prefix (Pref);
12896 end loop;
12898 if Present (Pref) and then Is_Entity_Name (Pref) then
12899 Ent := Entity (Pref);
12900 end if;
12901 end if;
12903 -- Place the reference on the entity node
12905 if Present (Ent) then
12906 Generate_Reference (Ent, Pref);
12907 end if;
12908 end if;
12909 end Insert_Explicit_Dereference;
12911 ------------------------------------------
12912 -- Inspect_Deferred_Constant_Completion --
12913 ------------------------------------------
12915 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12916 Decl : Node_Id;
12918 begin
12919 Decl := First (Decls);
12920 while Present (Decl) loop
12922 -- Deferred constant signature
12924 if Nkind (Decl) = N_Object_Declaration
12925 and then Constant_Present (Decl)
12926 and then No (Expression (Decl))
12928 -- No need to check internally generated constants
12930 and then Comes_From_Source (Decl)
12932 -- The constant is not completed. A full object declaration or a
12933 -- pragma Import complete a deferred constant.
12935 and then not Has_Completion (Defining_Identifier (Decl))
12936 then
12937 Error_Msg_N
12938 ("constant declaration requires initialization expression",
12939 Defining_Identifier (Decl));
12940 end if;
12942 Decl := Next (Decl);
12943 end loop;
12944 end Inspect_Deferred_Constant_Completion;
12946 -------------------------------
12947 -- Install_Elaboration_Model --
12948 -------------------------------
12950 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
12951 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
12952 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
12953 -- Empty if there is no such pragma.
12955 ------------------------------------
12956 -- Find_Elaboration_Checks_Pragma --
12957 ------------------------------------
12959 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
12960 Item : Node_Id;
12962 begin
12963 Item := First (L);
12964 while Present (Item) loop
12965 if Nkind (Item) = N_Pragma
12966 and then Pragma_Name (Item) = Name_Elaboration_Checks
12967 then
12968 return Item;
12969 end if;
12971 Next (Item);
12972 end loop;
12974 return Empty;
12975 end Find_Elaboration_Checks_Pragma;
12977 -- Local variables
12979 Args : List_Id;
12980 Model : Node_Id;
12981 Prag : Node_Id;
12982 Unit : Node_Id;
12984 -- Start of processing for Install_Elaboration_Model
12986 begin
12987 -- Nothing to do when the unit does not exist
12989 if No (Unit_Id) then
12990 return;
12991 end if;
12993 Unit := Parent (Unit_Declaration_Node (Unit_Id));
12995 -- Nothing to do when the unit is not a library unit
12997 if Nkind (Unit) /= N_Compilation_Unit then
12998 return;
12999 end if;
13001 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
13003 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
13004 -- elaboration model as specified by the pragma.
13006 if Present (Prag) then
13007 Args := Pragma_Argument_Associations (Prag);
13009 -- Guard against an illegal pragma. The sole argument must be an
13010 -- identifier which specifies either Dynamic or Static model.
13012 if Present (Args) then
13013 Model := Get_Pragma_Arg (First (Args));
13015 if Nkind (Model) = N_Identifier then
13016 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
13017 end if;
13018 end if;
13019 end if;
13020 end Install_Elaboration_Model;
13022 -----------------------------
13023 -- Install_Generic_Formals --
13024 -----------------------------
13026 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
13027 E : Entity_Id;
13029 begin
13030 pragma Assert (Is_Generic_Subprogram (Subp_Id));
13032 E := First_Entity (Subp_Id);
13033 while Present (E) loop
13034 Install_Entity (E);
13035 Next_Entity (E);
13036 end loop;
13037 end Install_Generic_Formals;
13039 ------------------------
13040 -- Install_SPARK_Mode --
13041 ------------------------
13043 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
13044 begin
13045 SPARK_Mode := Mode;
13046 SPARK_Mode_Pragma := Prag;
13047 end Install_SPARK_Mode;
13049 --------------------------
13050 -- Invalid_Scalar_Value --
13051 --------------------------
13053 function Invalid_Scalar_Value
13054 (Loc : Source_Ptr;
13055 Scal_Typ : Scalar_Id) return Node_Id
13057 function Invalid_Binder_Value return Node_Id;
13058 -- Return a reference to the corresponding invalid value for type
13059 -- Scal_Typ as defined in unit System.Scalar_Values.
13061 function Invalid_Float_Value return Node_Id;
13062 -- Return the invalid value of float type Scal_Typ
13064 function Invalid_Integer_Value return Node_Id;
13065 -- Return the invalid value of integer type Scal_Typ
13067 procedure Set_Invalid_Binder_Values;
13068 -- Set the contents of collection Invalid_Binder_Values
13070 --------------------------
13071 -- Invalid_Binder_Value --
13072 --------------------------
13074 function Invalid_Binder_Value return Node_Id is
13075 Val_Id : Entity_Id;
13077 begin
13078 -- Initialize the collection of invalid binder values the first time
13079 -- around.
13081 Set_Invalid_Binder_Values;
13083 -- Obtain the corresponding variable from System.Scalar_Values which
13084 -- holds the invalid value for this type.
13086 Val_Id := Invalid_Binder_Values (Scal_Typ);
13087 pragma Assert (Present (Val_Id));
13089 return New_Occurrence_Of (Val_Id, Loc);
13090 end Invalid_Binder_Value;
13092 -------------------------
13093 -- Invalid_Float_Value --
13094 -------------------------
13096 function Invalid_Float_Value return Node_Id is
13097 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13099 begin
13100 -- Pragma Invalid_Scalars did not specify an invalid value for this
13101 -- type. Fall back to the value provided by the binder.
13103 if Value = No_Ureal then
13104 return Invalid_Binder_Value;
13105 else
13106 return Make_Real_Literal (Loc, Realval => Value);
13107 end if;
13108 end Invalid_Float_Value;
13110 ---------------------------
13111 -- Invalid_Integer_Value --
13112 ---------------------------
13114 function Invalid_Integer_Value return Node_Id is
13115 Value : constant Uint := Invalid_Integers (Scal_Typ);
13117 begin
13118 -- Pragma Invalid_Scalars did not specify an invalid value for this
13119 -- type. Fall back to the value provided by the binder.
13121 if Value = No_Uint then
13122 return Invalid_Binder_Value;
13123 else
13124 return Make_Integer_Literal (Loc, Intval => Value);
13125 end if;
13126 end Invalid_Integer_Value;
13128 -------------------------------
13129 -- Set_Invalid_Binder_Values --
13130 -------------------------------
13132 procedure Set_Invalid_Binder_Values is
13133 begin
13134 if not Invalid_Binder_Values_Set then
13135 Invalid_Binder_Values_Set := True;
13137 -- Initialize the contents of the collection once since RTE calls
13138 -- are not cheap.
13140 Invalid_Binder_Values :=
13141 (Name_Short_Float => RTE (RE_IS_Isf),
13142 Name_Float => RTE (RE_IS_Ifl),
13143 Name_Long_Float => RTE (RE_IS_Ilf),
13144 Name_Long_Long_Float => RTE (RE_IS_Ill),
13145 Name_Signed_8 => RTE (RE_IS_Is1),
13146 Name_Signed_16 => RTE (RE_IS_Is2),
13147 Name_Signed_32 => RTE (RE_IS_Is4),
13148 Name_Signed_64 => RTE (RE_IS_Is8),
13149 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13150 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13151 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13152 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13153 end if;
13154 end Set_Invalid_Binder_Values;
13156 -- Start of processing for Invalid_Scalar_Value
13158 begin
13159 if Scal_Typ in Float_Scalar_Id then
13160 return Invalid_Float_Value;
13162 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13163 return Invalid_Integer_Value;
13164 end if;
13165 end Invalid_Scalar_Value;
13167 -----------------------------
13168 -- Is_Actual_Out_Parameter --
13169 -----------------------------
13171 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
13172 Formal : Entity_Id;
13173 Call : Node_Id;
13174 begin
13175 Find_Actual (N, Formal, Call);
13176 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
13177 end Is_Actual_Out_Parameter;
13179 -------------------------
13180 -- Is_Actual_Parameter --
13181 -------------------------
13183 function Is_Actual_Parameter (N : Node_Id) return Boolean is
13184 PK : constant Node_Kind := Nkind (Parent (N));
13186 begin
13187 case PK is
13188 when N_Parameter_Association =>
13189 return N = Explicit_Actual_Parameter (Parent (N));
13191 when N_Subprogram_Call =>
13192 return Is_List_Member (N)
13193 and then
13194 List_Containing (N) = Parameter_Associations (Parent (N));
13196 when others =>
13197 return False;
13198 end case;
13199 end Is_Actual_Parameter;
13201 --------------------------------
13202 -- Is_Actual_Tagged_Parameter --
13203 --------------------------------
13205 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
13206 Formal : Entity_Id;
13207 Call : Node_Id;
13208 begin
13209 Find_Actual (N, Formal, Call);
13210 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
13211 end Is_Actual_Tagged_Parameter;
13213 ---------------------
13214 -- Is_Aliased_View --
13215 ---------------------
13217 function Is_Aliased_View (Obj : Node_Id) return Boolean is
13218 E : Entity_Id;
13220 begin
13221 if Is_Entity_Name (Obj) then
13222 E := Entity (Obj);
13224 return
13225 (Is_Object (E)
13226 and then
13227 (Is_Aliased (E)
13228 or else (Present (Renamed_Object (E))
13229 and then Is_Aliased_View (Renamed_Object (E)))))
13231 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13232 and then Is_Tagged_Type (Etype (E)))
13234 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13236 -- Current instance of type, either directly or as rewritten
13237 -- reference to the current object.
13239 or else (Is_Entity_Name (Original_Node (Obj))
13240 and then Present (Entity (Original_Node (Obj)))
13241 and then Is_Type (Entity (Original_Node (Obj))))
13243 or else (Is_Type (E) and then E = Current_Scope)
13245 or else (Is_Incomplete_Or_Private_Type (E)
13246 and then Full_View (E) = Current_Scope)
13248 -- Ada 2012 AI05-0053: the return object of an extended return
13249 -- statement is aliased if its type is immutably limited.
13251 or else (Is_Return_Object (E)
13252 and then Is_Limited_View (Etype (E)));
13254 elsif Nkind (Obj) = N_Selected_Component then
13255 return Is_Aliased (Entity (Selector_Name (Obj)));
13257 elsif Nkind (Obj) = N_Indexed_Component then
13258 return Has_Aliased_Components (Etype (Prefix (Obj)))
13259 or else
13260 (Is_Access_Type (Etype (Prefix (Obj)))
13261 and then Has_Aliased_Components
13262 (Designated_Type (Etype (Prefix (Obj)))));
13264 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13265 return Is_Tagged_Type (Etype (Obj))
13266 and then Is_Aliased_View (Expression (Obj));
13268 elsif Nkind (Obj) = N_Explicit_Dereference then
13269 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13271 else
13272 return False;
13273 end if;
13274 end Is_Aliased_View;
13276 -------------------------
13277 -- Is_Ancestor_Package --
13278 -------------------------
13280 function Is_Ancestor_Package
13281 (E1 : Entity_Id;
13282 E2 : Entity_Id) return Boolean
13284 Par : Entity_Id;
13286 begin
13287 Par := E2;
13288 while Present (Par) and then Par /= Standard_Standard loop
13289 if Par = E1 then
13290 return True;
13291 end if;
13293 Par := Scope (Par);
13294 end loop;
13296 return False;
13297 end Is_Ancestor_Package;
13299 ----------------------
13300 -- Is_Atomic_Object --
13301 ----------------------
13303 function Is_Atomic_Object (N : Node_Id) return Boolean is
13304 function Is_Atomic_Entity (Id : Entity_Id) return Boolean;
13305 pragma Inline (Is_Atomic_Entity);
13306 -- Determine whether arbitrary entity Id is either atomic or has atomic
13307 -- components.
13309 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean;
13310 -- Determine whether prefix Pref of an indexed or selected component is
13311 -- an atomic object.
13313 ----------------------
13314 -- Is_Atomic_Entity --
13315 ----------------------
13317 function Is_Atomic_Entity (Id : Entity_Id) return Boolean is
13318 begin
13319 return Is_Atomic (Id) or else Has_Atomic_Components (Id);
13320 end Is_Atomic_Entity;
13322 ----------------------
13323 -- Is_Atomic_Prefix --
13324 ----------------------
13326 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean is
13327 Typ : constant Entity_Id := Etype (Pref);
13329 begin
13330 if Is_Access_Type (Typ) then
13331 return Has_Atomic_Components (Designated_Type (Typ));
13333 elsif Is_Atomic_Entity (Typ) then
13334 return True;
13336 elsif Is_Entity_Name (Pref)
13337 and then Is_Atomic_Entity (Entity (Pref))
13338 then
13339 return True;
13341 elsif Nkind (Pref) = N_Indexed_Component then
13342 return Is_Atomic_Prefix (Prefix (Pref));
13344 elsif Nkind (Pref) = N_Selected_Component then
13345 return
13346 Is_Atomic_Prefix (Prefix (Pref))
13347 or else Is_Atomic (Entity (Selector_Name (Pref)));
13348 end if;
13350 return False;
13351 end Is_Atomic_Prefix;
13353 -- Start of processing for Is_Atomic_Object
13355 begin
13356 if Is_Entity_Name (N) then
13357 return Is_Atomic_Object_Entity (Entity (N));
13359 elsif Nkind (N) = N_Indexed_Component then
13360 return Is_Atomic (Etype (N)) or else Is_Atomic_Prefix (Prefix (N));
13362 elsif Nkind (N) = N_Selected_Component then
13363 return
13364 Is_Atomic (Etype (N))
13365 or else Is_Atomic_Prefix (Prefix (N))
13366 or else Is_Atomic (Entity (Selector_Name (N)));
13367 end if;
13369 return False;
13370 end Is_Atomic_Object;
13372 -----------------------------
13373 -- Is_Atomic_Object_Entity --
13374 -----------------------------
13376 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13377 begin
13378 return
13379 Is_Object (Id)
13380 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13381 end Is_Atomic_Object_Entity;
13383 -----------------------------
13384 -- Is_Atomic_Or_VFA_Object --
13385 -----------------------------
13387 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13388 begin
13389 return Is_Atomic_Object (N)
13390 or else (Is_Object_Reference (N)
13391 and then Is_Entity_Name (N)
13392 and then (Is_Volatile_Full_Access (Entity (N))
13393 or else
13394 Is_Volatile_Full_Access (Etype (Entity (N)))));
13395 end Is_Atomic_Or_VFA_Object;
13397 -------------------------
13398 -- Is_Attribute_Result --
13399 -------------------------
13401 function Is_Attribute_Result (N : Node_Id) return Boolean is
13402 begin
13403 return Nkind (N) = N_Attribute_Reference
13404 and then Attribute_Name (N) = Name_Result;
13405 end Is_Attribute_Result;
13407 -------------------------
13408 -- Is_Attribute_Update --
13409 -------------------------
13411 function Is_Attribute_Update (N : Node_Id) return Boolean is
13412 begin
13413 return Nkind (N) = N_Attribute_Reference
13414 and then Attribute_Name (N) = Name_Update;
13415 end Is_Attribute_Update;
13417 ------------------------------------
13418 -- Is_Body_Or_Package_Declaration --
13419 ------------------------------------
13421 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13422 begin
13423 return Is_Body (N) or else Nkind (N) = N_Package_Declaration;
13424 end Is_Body_Or_Package_Declaration;
13426 -----------------------
13427 -- Is_Bounded_String --
13428 -----------------------
13430 function Is_Bounded_String (T : Entity_Id) return Boolean is
13431 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13433 begin
13434 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13435 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13436 -- be True for all the Bounded_String types in instances of the
13437 -- Generic_Bounded_Length generics, and for types derived from those.
13439 return Present (Under)
13440 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13441 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13442 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13443 end Is_Bounded_String;
13445 ---------------------
13446 -- Is_CCT_Instance --
13447 ---------------------
13449 function Is_CCT_Instance
13450 (Ref_Id : Entity_Id;
13451 Context_Id : Entity_Id) return Boolean
13453 begin
13454 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13456 if Is_Single_Task_Object (Context_Id) then
13457 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13459 else
13460 pragma Assert (Ekind_In (Context_Id, E_Entry,
13461 E_Entry_Family,
13462 E_Function,
13463 E_Package,
13464 E_Procedure,
13465 E_Protected_Type,
13466 E_Task_Type)
13467 or else
13468 Is_Record_Type (Context_Id));
13469 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13470 end if;
13471 end Is_CCT_Instance;
13473 -------------------------
13474 -- Is_Child_Or_Sibling --
13475 -------------------------
13477 function Is_Child_Or_Sibling
13478 (Pack_1 : Entity_Id;
13479 Pack_2 : Entity_Id) return Boolean
13481 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13482 -- Given an arbitrary package, return the number of "climbs" necessary
13483 -- to reach scope Standard_Standard.
13485 procedure Equalize_Depths
13486 (Pack : in out Entity_Id;
13487 Depth : in out Nat;
13488 Depth_To_Reach : Nat);
13489 -- Given an arbitrary package, its depth and a target depth to reach,
13490 -- climb the scope chain until the said depth is reached. The pointer
13491 -- to the package and its depth a modified during the climb.
13493 ----------------------------
13494 -- Distance_From_Standard --
13495 ----------------------------
13497 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13498 Dist : Nat;
13499 Scop : Entity_Id;
13501 begin
13502 Dist := 0;
13503 Scop := Pack;
13504 while Present (Scop) and then Scop /= Standard_Standard loop
13505 Dist := Dist + 1;
13506 Scop := Scope (Scop);
13507 end loop;
13509 return Dist;
13510 end Distance_From_Standard;
13512 ---------------------
13513 -- Equalize_Depths --
13514 ---------------------
13516 procedure Equalize_Depths
13517 (Pack : in out Entity_Id;
13518 Depth : in out Nat;
13519 Depth_To_Reach : Nat)
13521 begin
13522 -- The package must be at a greater or equal depth
13524 if Depth < Depth_To_Reach then
13525 raise Program_Error;
13526 end if;
13528 -- Climb the scope chain until the desired depth is reached
13530 while Present (Pack) and then Depth /= Depth_To_Reach loop
13531 Pack := Scope (Pack);
13532 Depth := Depth - 1;
13533 end loop;
13534 end Equalize_Depths;
13536 -- Local variables
13538 P_1 : Entity_Id := Pack_1;
13539 P_1_Child : Boolean := False;
13540 P_1_Depth : Nat := Distance_From_Standard (P_1);
13541 P_2 : Entity_Id := Pack_2;
13542 P_2_Child : Boolean := False;
13543 P_2_Depth : Nat := Distance_From_Standard (P_2);
13545 -- Start of processing for Is_Child_Or_Sibling
13547 begin
13548 pragma Assert
13549 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13551 -- Both packages denote the same entity, therefore they cannot be
13552 -- children or siblings.
13554 if P_1 = P_2 then
13555 return False;
13557 -- One of the packages is at a deeper level than the other. Note that
13558 -- both may still come from different hierarchies.
13560 -- (root) P_2
13561 -- / \ :
13562 -- X P_2 or X
13563 -- : :
13564 -- P_1 P_1
13566 elsif P_1_Depth > P_2_Depth then
13567 Equalize_Depths
13568 (Pack => P_1,
13569 Depth => P_1_Depth,
13570 Depth_To_Reach => P_2_Depth);
13571 P_1_Child := True;
13573 -- (root) P_1
13574 -- / \ :
13575 -- P_1 X or X
13576 -- : :
13577 -- P_2 P_2
13579 elsif P_2_Depth > P_1_Depth then
13580 Equalize_Depths
13581 (Pack => P_2,
13582 Depth => P_2_Depth,
13583 Depth_To_Reach => P_1_Depth);
13584 P_2_Child := True;
13585 end if;
13587 -- At this stage the package pointers have been elevated to the same
13588 -- depth. If the related entities are the same, then one package is a
13589 -- potential child of the other:
13591 -- P_1
13592 -- :
13593 -- X became P_1 P_2 or vice versa
13594 -- :
13595 -- P_2
13597 if P_1 = P_2 then
13598 if P_1_Child then
13599 return Is_Child_Unit (Pack_1);
13601 else pragma Assert (P_2_Child);
13602 return Is_Child_Unit (Pack_2);
13603 end if;
13605 -- The packages may come from the same package chain or from entirely
13606 -- different hierarcies. To determine this, climb the scope stack until
13607 -- a common root is found.
13609 -- (root) (root 1) (root 2)
13610 -- / \ | |
13611 -- P_1 P_2 P_1 P_2
13613 else
13614 while Present (P_1) and then Present (P_2) loop
13616 -- The two packages may be siblings
13618 if P_1 = P_2 then
13619 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13620 end if;
13622 P_1 := Scope (P_1);
13623 P_2 := Scope (P_2);
13624 end loop;
13625 end if;
13627 return False;
13628 end Is_Child_Or_Sibling;
13630 -----------------------------
13631 -- Is_Concurrent_Interface --
13632 -----------------------------
13634 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13635 begin
13636 return Is_Interface (T)
13637 and then
13638 (Is_Protected_Interface (T)
13639 or else Is_Synchronized_Interface (T)
13640 or else Is_Task_Interface (T));
13641 end Is_Concurrent_Interface;
13643 -----------------------
13644 -- Is_Constant_Bound --
13645 -----------------------
13647 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13648 begin
13649 if Compile_Time_Known_Value (Exp) then
13650 return True;
13652 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13653 return Is_Constant_Object (Entity (Exp))
13654 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13656 elsif Nkind (Exp) in N_Binary_Op then
13657 return Is_Constant_Bound (Left_Opnd (Exp))
13658 and then Is_Constant_Bound (Right_Opnd (Exp))
13659 and then Scope (Entity (Exp)) = Standard_Standard;
13661 else
13662 return False;
13663 end if;
13664 end Is_Constant_Bound;
13666 ---------------------------
13667 -- Is_Container_Element --
13668 ---------------------------
13670 function Is_Container_Element (Exp : Node_Id) return Boolean is
13671 Loc : constant Source_Ptr := Sloc (Exp);
13672 Pref : constant Node_Id := Prefix (Exp);
13674 Call : Node_Id;
13675 -- Call to an indexing aspect
13677 Cont_Typ : Entity_Id;
13678 -- The type of the container being accessed
13680 Elem_Typ : Entity_Id;
13681 -- Its element type
13683 Indexing : Entity_Id;
13684 Is_Const : Boolean;
13685 -- Indicates that constant indexing is used, and the element is thus
13686 -- a constant.
13688 Ref_Typ : Entity_Id;
13689 -- The reference type returned by the indexing operation
13691 begin
13692 -- If C is a container, in a context that imposes the element type of
13693 -- that container, the indexing notation C (X) is rewritten as:
13695 -- Indexing (C, X).Discr.all
13697 -- where Indexing is one of the indexing aspects of the container.
13698 -- If the context does not require a reference, the construct can be
13699 -- rewritten as
13701 -- Element (C, X)
13703 -- First, verify that the construct has the proper form
13705 if not Expander_Active then
13706 return False;
13708 elsif Nkind (Pref) /= N_Selected_Component then
13709 return False;
13711 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13712 return False;
13714 else
13715 Call := Prefix (Pref);
13716 Ref_Typ := Etype (Call);
13717 end if;
13719 if not Has_Implicit_Dereference (Ref_Typ)
13720 or else No (First (Parameter_Associations (Call)))
13721 or else not Is_Entity_Name (Name (Call))
13722 then
13723 return False;
13724 end if;
13726 -- Retrieve type of container object, and its iterator aspects
13728 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13729 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13730 Is_Const := False;
13732 if No (Indexing) then
13734 -- Container should have at least one indexing operation
13736 return False;
13738 elsif Entity (Name (Call)) /= Entity (Indexing) then
13740 -- This may be a variable indexing operation
13742 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13744 if No (Indexing)
13745 or else Entity (Name (Call)) /= Entity (Indexing)
13746 then
13747 return False;
13748 end if;
13750 else
13751 Is_Const := True;
13752 end if;
13754 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13756 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13757 return False;
13758 end if;
13760 -- Check that the expression is not the target of an assignment, in
13761 -- which case the rewriting is not possible.
13763 if not Is_Const then
13764 declare
13765 Par : Node_Id;
13767 begin
13768 Par := Exp;
13769 while Present (Par)
13770 loop
13771 if Nkind (Parent (Par)) = N_Assignment_Statement
13772 and then Par = Name (Parent (Par))
13773 then
13774 return False;
13776 -- A renaming produces a reference, and the transformation
13777 -- does not apply.
13779 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13780 return False;
13782 elsif Nkind_In
13783 (Nkind (Parent (Par)), N_Function_Call,
13784 N_Procedure_Call_Statement,
13785 N_Entry_Call_Statement)
13786 then
13787 -- Check that the element is not part of an actual for an
13788 -- in-out parameter.
13790 declare
13791 F : Entity_Id;
13792 A : Node_Id;
13794 begin
13795 F := First_Formal (Entity (Name (Parent (Par))));
13796 A := First (Parameter_Associations (Parent (Par)));
13797 while Present (F) loop
13798 if A = Par and then Ekind (F) /= E_In_Parameter then
13799 return False;
13800 end if;
13802 Next_Formal (F);
13803 Next (A);
13804 end loop;
13805 end;
13807 -- E_In_Parameter in a call: element is not modified.
13809 exit;
13810 end if;
13812 Par := Parent (Par);
13813 end loop;
13814 end;
13815 end if;
13817 -- The expression has the proper form and the context requires the
13818 -- element type. Retrieve the Element function of the container and
13819 -- rewrite the construct as a call to it.
13821 declare
13822 Op : Elmt_Id;
13824 begin
13825 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13826 while Present (Op) loop
13827 exit when Chars (Node (Op)) = Name_Element;
13828 Next_Elmt (Op);
13829 end loop;
13831 if No (Op) then
13832 return False;
13834 else
13835 Rewrite (Exp,
13836 Make_Function_Call (Loc,
13837 Name => New_Occurrence_Of (Node (Op), Loc),
13838 Parameter_Associations => Parameter_Associations (Call)));
13839 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13840 return True;
13841 end if;
13842 end;
13843 end Is_Container_Element;
13845 ----------------------------
13846 -- Is_Contract_Annotation --
13847 ----------------------------
13849 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13850 begin
13851 return Is_Package_Contract_Annotation (Item)
13852 or else
13853 Is_Subprogram_Contract_Annotation (Item);
13854 end Is_Contract_Annotation;
13856 --------------------------------------
13857 -- Is_Controlling_Limited_Procedure --
13858 --------------------------------------
13860 function Is_Controlling_Limited_Procedure
13861 (Proc_Nam : Entity_Id) return Boolean
13863 Param : Node_Id;
13864 Param_Typ : Entity_Id := Empty;
13866 begin
13867 if Ekind (Proc_Nam) = E_Procedure
13868 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13869 then
13870 Param :=
13871 Parameter_Type
13872 (First (Parameter_Specifications (Parent (Proc_Nam))));
13874 -- The formal may be an anonymous access type
13876 if Nkind (Param) = N_Access_Definition then
13877 Param_Typ := Entity (Subtype_Mark (Param));
13878 else
13879 Param_Typ := Etype (Param);
13880 end if;
13882 -- In the case where an Itype was created for a dispatchin call, the
13883 -- procedure call has been rewritten. The actual may be an access to
13884 -- interface type in which case it is the designated type that is the
13885 -- controlling type.
13887 elsif Present (Associated_Node_For_Itype (Proc_Nam))
13888 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
13889 and then
13890 Present (Parameter_Associations
13891 (Associated_Node_For_Itype (Proc_Nam)))
13892 then
13893 Param_Typ :=
13894 Etype (First (Parameter_Associations
13895 (Associated_Node_For_Itype (Proc_Nam))));
13897 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
13898 Param_Typ := Directly_Designated_Type (Param_Typ);
13899 end if;
13900 end if;
13902 if Present (Param_Typ) then
13903 return
13904 Is_Interface (Param_Typ)
13905 and then Is_Limited_Record (Param_Typ);
13906 end if;
13908 return False;
13909 end Is_Controlling_Limited_Procedure;
13911 -----------------------------
13912 -- Is_CPP_Constructor_Call --
13913 -----------------------------
13915 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
13916 begin
13917 return Nkind (N) = N_Function_Call
13918 and then Is_CPP_Class (Etype (Etype (N)))
13919 and then Is_Constructor (Entity (Name (N)))
13920 and then Is_Imported (Entity (Name (N)));
13921 end Is_CPP_Constructor_Call;
13923 -------------------------
13924 -- Is_Current_Instance --
13925 -------------------------
13927 function Is_Current_Instance (N : Node_Id) return Boolean is
13928 Typ : constant Entity_Id := Entity (N);
13929 P : Node_Id;
13931 begin
13932 -- Simplest case: entity is a concurrent type and we are currently
13933 -- inside the body. This will eventually be expanded into a call to
13934 -- Self (for tasks) or _object (for protected objects).
13936 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13937 return True;
13939 else
13940 -- Check whether the context is a (sub)type declaration for the
13941 -- type entity.
13943 P := Parent (N);
13944 while Present (P) loop
13945 if Nkind_In (P, N_Full_Type_Declaration,
13946 N_Private_Type_Declaration,
13947 N_Subtype_Declaration)
13948 and then Comes_From_Source (P)
13949 and then Defining_Entity (P) = Typ
13950 then
13951 return True;
13953 -- A subtype name may appear in an aspect specification for a
13954 -- Predicate_Failure aspect, for which we do not construct a
13955 -- wrapper procedure. The subtype will be replaced by the
13956 -- expression being tested when the corresponding predicate
13957 -- check is expanded.
13959 elsif Nkind (P) = N_Aspect_Specification
13960 and then Nkind (Parent (P)) = N_Subtype_Declaration
13961 then
13962 return True;
13964 elsif Nkind (P) = N_Pragma
13965 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
13966 then
13967 return True;
13968 end if;
13970 P := Parent (P);
13971 end loop;
13972 end if;
13974 -- In any other context this is not a current occurrence
13976 return False;
13977 end Is_Current_Instance;
13979 --------------------
13980 -- Is_Declaration --
13981 --------------------
13983 function Is_Declaration
13984 (N : Node_Id;
13985 Body_OK : Boolean := True;
13986 Concurrent_OK : Boolean := True;
13987 Formal_OK : Boolean := True;
13988 Generic_OK : Boolean := True;
13989 Instantiation_OK : Boolean := True;
13990 Renaming_OK : Boolean := True;
13991 Stub_OK : Boolean := True;
13992 Subprogram_OK : Boolean := True;
13993 Type_OK : Boolean := True) return Boolean
13995 begin
13996 case Nkind (N) is
13998 -- Body declarations
14000 when N_Proper_Body =>
14001 return Body_OK;
14003 -- Concurrent type declarations
14005 when N_Protected_Type_Declaration
14006 | N_Single_Protected_Declaration
14007 | N_Single_Task_Declaration
14008 | N_Task_Type_Declaration
14010 return Concurrent_OK or Type_OK;
14012 -- Formal declarations
14014 when N_Formal_Abstract_Subprogram_Declaration
14015 | N_Formal_Concrete_Subprogram_Declaration
14016 | N_Formal_Object_Declaration
14017 | N_Formal_Package_Declaration
14018 | N_Formal_Type_Declaration
14020 return Formal_OK;
14022 -- Generic declarations
14024 when N_Generic_Package_Declaration
14025 | N_Generic_Subprogram_Declaration
14027 return Generic_OK;
14029 -- Generic instantiations
14031 when N_Function_Instantiation
14032 | N_Package_Instantiation
14033 | N_Procedure_Instantiation
14035 return Instantiation_OK;
14037 -- Generic renaming declarations
14039 when N_Generic_Renaming_Declaration =>
14040 return Generic_OK or Renaming_OK;
14042 -- Renaming declarations
14044 when N_Exception_Renaming_Declaration
14045 | N_Object_Renaming_Declaration
14046 | N_Package_Renaming_Declaration
14047 | N_Subprogram_Renaming_Declaration
14049 return Renaming_OK;
14051 -- Stub declarations
14053 when N_Body_Stub =>
14054 return Stub_OK;
14056 -- Subprogram declarations
14058 when N_Abstract_Subprogram_Declaration
14059 | N_Entry_Declaration
14060 | N_Expression_Function
14061 | N_Subprogram_Declaration
14063 return Subprogram_OK;
14065 -- Type declarations
14067 when N_Full_Type_Declaration
14068 | N_Incomplete_Type_Declaration
14069 | N_Private_Extension_Declaration
14070 | N_Private_Type_Declaration
14071 | N_Subtype_Declaration
14073 return Type_OK;
14075 -- Miscellaneous
14077 when N_Component_Declaration
14078 | N_Exception_Declaration
14079 | N_Implicit_Label_Declaration
14080 | N_Number_Declaration
14081 | N_Object_Declaration
14082 | N_Package_Declaration
14084 return True;
14086 when others =>
14087 return False;
14088 end case;
14089 end Is_Declaration;
14091 --------------------------------
14092 -- Is_Declared_Within_Variant --
14093 --------------------------------
14095 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
14096 Comp_Decl : constant Node_Id := Parent (Comp);
14097 Comp_List : constant Node_Id := Parent (Comp_Decl);
14098 begin
14099 return Nkind (Parent (Comp_List)) = N_Variant;
14100 end Is_Declared_Within_Variant;
14102 ----------------------------------------------
14103 -- Is_Dependent_Component_Of_Mutable_Object --
14104 ----------------------------------------------
14106 function Is_Dependent_Component_Of_Mutable_Object
14107 (Object : Node_Id) return Boolean
14109 P : Node_Id;
14110 Prefix_Type : Entity_Id;
14111 P_Aliased : Boolean := False;
14112 Comp : Entity_Id;
14114 Deref : Node_Id := Object;
14115 -- Dereference node, in something like X.all.Y(2)
14117 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14119 begin
14120 -- Find the dereference node if any
14122 while Nkind_In (Deref, N_Indexed_Component,
14123 N_Selected_Component,
14124 N_Slice)
14125 loop
14126 Deref := Prefix (Deref);
14127 end loop;
14129 -- Ada 2005: If we have a component or slice of a dereference,
14130 -- something like X.all.Y (2), and the type of X is access-to-constant,
14131 -- Is_Variable will return False, because it is indeed a constant
14132 -- view. But it might be a view of a variable object, so we want the
14133 -- following condition to be True in that case.
14135 if Is_Variable (Object)
14136 or else (Ada_Version >= Ada_2005
14137 and then Nkind (Deref) = N_Explicit_Dereference)
14138 then
14139 if Nkind (Object) = N_Selected_Component then
14140 P := Prefix (Object);
14141 Prefix_Type := Etype (P);
14143 if Is_Entity_Name (P) then
14144 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
14145 Prefix_Type := Base_Type (Prefix_Type);
14146 end if;
14148 if Is_Aliased (Entity (P)) then
14149 P_Aliased := True;
14150 end if;
14152 -- A discriminant check on a selected component may be expanded
14153 -- into a dereference when removing side effects. Recover the
14154 -- original node and its type, which may be unconstrained.
14156 elsif Nkind (P) = N_Explicit_Dereference
14157 and then not (Comes_From_Source (P))
14158 then
14159 P := Original_Node (P);
14160 Prefix_Type := Etype (P);
14162 else
14163 -- Check for prefix being an aliased component???
14165 null;
14167 end if;
14169 -- A heap object is constrained by its initial value
14171 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14172 -- the dereferenced case, since the access value might denote an
14173 -- unconstrained aliased object, whereas in Ada 95 the designated
14174 -- object is guaranteed to be constrained. A worst-case assumption
14175 -- has to apply in Ada 2005 because we can't tell at compile
14176 -- time whether the object is "constrained by its initial value",
14177 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14178 -- rules (these rules are acknowledged to need fixing). We don't
14179 -- impose this more stringent checking for earlier Ada versions or
14180 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14181 -- benefit, though it's unclear on why using -gnat95 would not be
14182 -- sufficient???).
14184 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
14185 if Is_Access_Type (Prefix_Type)
14186 or else Nkind (P) = N_Explicit_Dereference
14187 then
14188 return False;
14189 end if;
14191 else pragma Assert (Ada_Version >= Ada_2005);
14192 if Is_Access_Type (Prefix_Type) then
14194 -- If the access type is pool-specific, and there is no
14195 -- constrained partial view of the designated type, then the
14196 -- designated object is known to be constrained.
14198 if Ekind (Prefix_Type) = E_Access_Type
14199 and then not Object_Type_Has_Constrained_Partial_View
14200 (Typ => Designated_Type (Prefix_Type),
14201 Scop => Current_Scope)
14202 then
14203 return False;
14205 -- Otherwise (general access type, or there is a constrained
14206 -- partial view of the designated type), we need to check
14207 -- based on the designated type.
14209 else
14210 Prefix_Type := Designated_Type (Prefix_Type);
14211 end if;
14212 end if;
14213 end if;
14215 Comp :=
14216 Original_Record_Component (Entity (Selector_Name (Object)));
14218 -- As per AI-0017, the renaming is illegal in a generic body, even
14219 -- if the subtype is indefinite.
14221 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14223 if not Is_Constrained (Prefix_Type)
14224 and then (Is_Definite_Subtype (Prefix_Type)
14225 or else
14226 (Is_Generic_Type (Prefix_Type)
14227 and then Ekind (Current_Scope) = E_Generic_Package
14228 and then In_Package_Body (Current_Scope)))
14230 and then (Is_Declared_Within_Variant (Comp)
14231 or else Has_Discriminant_Dependent_Constraint (Comp))
14232 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14233 then
14234 return True;
14236 -- If the prefix is of an access type at this point, then we want
14237 -- to return False, rather than calling this function recursively
14238 -- on the access object (which itself might be a discriminant-
14239 -- dependent component of some other object, but that isn't
14240 -- relevant to checking the object passed to us). This avoids
14241 -- issuing wrong errors when compiling with -gnatc, where there
14242 -- can be implicit dereferences that have not been expanded.
14244 elsif Is_Access_Type (Etype (Prefix (Object))) then
14245 return False;
14247 else
14248 return
14249 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14250 end if;
14252 elsif Nkind (Object) = N_Indexed_Component
14253 or else Nkind (Object) = N_Slice
14254 then
14255 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14257 -- A type conversion that Is_Variable is a view conversion:
14258 -- go back to the denoted object.
14260 elsif Nkind (Object) = N_Type_Conversion then
14261 return
14262 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14263 end if;
14264 end if;
14266 return False;
14267 end Is_Dependent_Component_Of_Mutable_Object;
14269 ---------------------
14270 -- Is_Dereferenced --
14271 ---------------------
14273 function Is_Dereferenced (N : Node_Id) return Boolean is
14274 P : constant Node_Id := Parent (N);
14275 begin
14276 return Nkind_In (P, N_Selected_Component,
14277 N_Explicit_Dereference,
14278 N_Indexed_Component,
14279 N_Slice)
14280 and then Prefix (P) = N;
14281 end Is_Dereferenced;
14283 ----------------------
14284 -- Is_Descendant_Of --
14285 ----------------------
14287 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14288 T : Entity_Id;
14289 Etyp : Entity_Id;
14291 begin
14292 pragma Assert (Nkind (T1) in N_Entity);
14293 pragma Assert (Nkind (T2) in N_Entity);
14295 T := Base_Type (T1);
14297 -- Immediate return if the types match
14299 if T = T2 then
14300 return True;
14302 -- Comment needed here ???
14304 elsif Ekind (T) = E_Class_Wide_Type then
14305 return Etype (T) = T2;
14307 -- All other cases
14309 else
14310 loop
14311 Etyp := Etype (T);
14313 -- Done if we found the type we are looking for
14315 if Etyp = T2 then
14316 return True;
14318 -- Done if no more derivations to check
14320 elsif T = T1
14321 or else T = Etyp
14322 then
14323 return False;
14325 -- Following test catches error cases resulting from prev errors
14327 elsif No (Etyp) then
14328 return False;
14330 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14331 return False;
14333 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14334 return False;
14335 end if;
14337 T := Base_Type (Etyp);
14338 end loop;
14339 end if;
14340 end Is_Descendant_Of;
14342 ----------------------------------------
14343 -- Is_Descendant_Of_Suspension_Object --
14344 ----------------------------------------
14346 function Is_Descendant_Of_Suspension_Object
14347 (Typ : Entity_Id) return Boolean
14349 Cur_Typ : Entity_Id;
14350 Par_Typ : Entity_Id;
14352 begin
14353 -- Climb the type derivation chain checking each parent type against
14354 -- Suspension_Object.
14356 Cur_Typ := Base_Type (Typ);
14357 while Present (Cur_Typ) loop
14358 Par_Typ := Etype (Cur_Typ);
14360 -- The current type is a match
14362 if Is_Suspension_Object (Cur_Typ) then
14363 return True;
14365 -- Stop the traversal once the root of the derivation chain has been
14366 -- reached. In that case the current type is its own base type.
14368 elsif Cur_Typ = Par_Typ then
14369 exit;
14370 end if;
14372 Cur_Typ := Base_Type (Par_Typ);
14373 end loop;
14375 return False;
14376 end Is_Descendant_Of_Suspension_Object;
14378 ---------------------------------------------
14379 -- Is_Double_Precision_Floating_Point_Type --
14380 ---------------------------------------------
14382 function Is_Double_Precision_Floating_Point_Type
14383 (E : Entity_Id) return Boolean is
14384 begin
14385 return Is_Floating_Point_Type (E)
14386 and then Machine_Radix_Value (E) = Uint_2
14387 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14388 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14389 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14390 end Is_Double_Precision_Floating_Point_Type;
14392 -----------------------------
14393 -- Is_Effectively_Volatile --
14394 -----------------------------
14396 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14397 begin
14398 if Is_Type (Id) then
14400 -- An arbitrary type is effectively volatile when it is subject to
14401 -- pragma Atomic or Volatile.
14403 if Is_Volatile (Id) then
14404 return True;
14406 -- An array type is effectively volatile when it is subject to pragma
14407 -- Atomic_Components or Volatile_Components or its component type is
14408 -- effectively volatile.
14410 elsif Is_Array_Type (Id) then
14411 declare
14412 Anc : Entity_Id := Base_Type (Id);
14413 begin
14414 if Is_Private_Type (Anc) then
14415 Anc := Full_View (Anc);
14416 end if;
14418 -- Test for presence of ancestor, as the full view of a private
14419 -- type may be missing in case of error.
14421 return
14422 Has_Volatile_Components (Id)
14423 or else
14424 (Present (Anc)
14425 and then Is_Effectively_Volatile (Component_Type (Anc)));
14426 end;
14428 -- A protected type is always volatile
14430 elsif Is_Protected_Type (Id) then
14431 return True;
14433 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14434 -- automatically volatile.
14436 elsif Is_Descendant_Of_Suspension_Object (Id) then
14437 return True;
14439 -- Otherwise the type is not effectively volatile
14441 else
14442 return False;
14443 end if;
14445 -- Otherwise Id denotes an object
14447 else
14448 return
14449 Is_Volatile (Id)
14450 or else Has_Volatile_Components (Id)
14451 or else Is_Effectively_Volatile (Etype (Id));
14452 end if;
14453 end Is_Effectively_Volatile;
14455 ------------------------------------
14456 -- Is_Effectively_Volatile_Object --
14457 ------------------------------------
14459 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14460 begin
14461 if Is_Entity_Name (N) then
14462 return Is_Effectively_Volatile (Entity (N));
14464 elsif Nkind (N) = N_Indexed_Component then
14465 return Is_Effectively_Volatile_Object (Prefix (N));
14467 elsif Nkind (N) = N_Selected_Component then
14468 return
14469 Is_Effectively_Volatile_Object (Prefix (N))
14470 or else
14471 Is_Effectively_Volatile_Object (Selector_Name (N));
14473 else
14474 return False;
14475 end if;
14476 end Is_Effectively_Volatile_Object;
14478 -------------------
14479 -- Is_Entry_Body --
14480 -------------------
14482 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14483 begin
14484 return
14485 Ekind_In (Id, E_Entry, E_Entry_Family)
14486 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14487 end Is_Entry_Body;
14489 --------------------------
14490 -- Is_Entry_Declaration --
14491 --------------------------
14493 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14494 begin
14495 return
14496 Ekind_In (Id, E_Entry, E_Entry_Family)
14497 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14498 end Is_Entry_Declaration;
14500 ------------------------------------
14501 -- Is_Expanded_Priority_Attribute --
14502 ------------------------------------
14504 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14505 begin
14506 return
14507 Nkind (E) = N_Function_Call
14508 and then not Configurable_Run_Time_Mode
14509 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14510 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14511 end Is_Expanded_Priority_Attribute;
14513 ----------------------------
14514 -- Is_Expression_Function --
14515 ----------------------------
14517 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14518 begin
14519 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14520 return
14521 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14522 N_Expression_Function;
14523 else
14524 return False;
14525 end if;
14526 end Is_Expression_Function;
14528 ------------------------------------------
14529 -- Is_Expression_Function_Or_Completion --
14530 ------------------------------------------
14532 function Is_Expression_Function_Or_Completion
14533 (Subp : Entity_Id) return Boolean
14535 Subp_Decl : Node_Id;
14537 begin
14538 if Ekind (Subp) = E_Function then
14539 Subp_Decl := Unit_Declaration_Node (Subp);
14541 -- The function declaration is either an expression function or is
14542 -- completed by an expression function body.
14544 return
14545 Is_Expression_Function (Subp)
14546 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
14547 and then Present (Corresponding_Body (Subp_Decl))
14548 and then Is_Expression_Function
14549 (Corresponding_Body (Subp_Decl)));
14551 elsif Ekind (Subp) = E_Subprogram_Body then
14552 return Is_Expression_Function (Subp);
14554 else
14555 return False;
14556 end if;
14557 end Is_Expression_Function_Or_Completion;
14559 -----------------------
14560 -- Is_EVF_Expression --
14561 -----------------------
14563 function Is_EVF_Expression (N : Node_Id) return Boolean is
14564 Orig_N : constant Node_Id := Original_Node (N);
14565 Alt : Node_Id;
14566 Expr : Node_Id;
14567 Id : Entity_Id;
14569 begin
14570 -- Detect a reference to a formal parameter of a specific tagged type
14571 -- whose related subprogram is subject to pragma Expresions_Visible with
14572 -- value "False".
14574 if Is_Entity_Name (N) and then Present (Entity (N)) then
14575 Id := Entity (N);
14577 return
14578 Is_Formal (Id)
14579 and then Is_Specific_Tagged_Type (Etype (Id))
14580 and then Extensions_Visible_Status (Id) =
14581 Extensions_Visible_False;
14583 -- A case expression is an EVF expression when it contains at least one
14584 -- EVF dependent_expression. Note that a case expression may have been
14585 -- expanded, hence the use of Original_Node.
14587 elsif Nkind (Orig_N) = N_Case_Expression then
14588 Alt := First (Alternatives (Orig_N));
14589 while Present (Alt) loop
14590 if Is_EVF_Expression (Expression (Alt)) then
14591 return True;
14592 end if;
14594 Next (Alt);
14595 end loop;
14597 -- An if expression is an EVF expression when it contains at least one
14598 -- EVF dependent_expression. Note that an if expression may have been
14599 -- expanded, hence the use of Original_Node.
14601 elsif Nkind (Orig_N) = N_If_Expression then
14602 Expr := Next (First (Expressions (Orig_N)));
14603 while Present (Expr) loop
14604 if Is_EVF_Expression (Expr) then
14605 return True;
14606 end if;
14608 Next (Expr);
14609 end loop;
14611 -- A qualified expression or a type conversion is an EVF expression when
14612 -- its operand is an EVF expression.
14614 elsif Nkind_In (N, N_Qualified_Expression,
14615 N_Unchecked_Type_Conversion,
14616 N_Type_Conversion)
14617 then
14618 return Is_EVF_Expression (Expression (N));
14620 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14621 -- their prefix denotes an EVF expression.
14623 elsif Nkind (N) = N_Attribute_Reference
14624 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
14625 Name_Old,
14626 Name_Update)
14627 then
14628 return Is_EVF_Expression (Prefix (N));
14629 end if;
14631 return False;
14632 end Is_EVF_Expression;
14634 --------------
14635 -- Is_False --
14636 --------------
14638 function Is_False (U : Uint) return Boolean is
14639 begin
14640 return (U = 0);
14641 end Is_False;
14643 ---------------------------
14644 -- Is_Fixed_Model_Number --
14645 ---------------------------
14647 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
14648 S : constant Ureal := Small_Value (T);
14649 M : Urealp.Save_Mark;
14650 R : Boolean;
14652 begin
14653 M := Urealp.Mark;
14654 R := (U = UR_Trunc (U / S) * S);
14655 Urealp.Release (M);
14656 return R;
14657 end Is_Fixed_Model_Number;
14659 -------------------------------
14660 -- Is_Fully_Initialized_Type --
14661 -------------------------------
14663 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
14664 begin
14665 -- Scalar types
14667 if Is_Scalar_Type (Typ) then
14669 -- A scalar type with an aspect Default_Value is fully initialized
14671 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14672 -- of a scalar type, but we don't take that into account here, since
14673 -- we don't want these to affect warnings.
14675 return Has_Default_Aspect (Typ);
14677 elsif Is_Access_Type (Typ) then
14678 return True;
14680 elsif Is_Array_Type (Typ) then
14681 if Is_Fully_Initialized_Type (Component_Type (Typ))
14682 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14683 then
14684 return True;
14685 end if;
14687 -- An interesting case, if we have a constrained type one of whose
14688 -- bounds is known to be null, then there are no elements to be
14689 -- initialized, so all the elements are initialized.
14691 if Is_Constrained (Typ) then
14692 declare
14693 Indx : Node_Id;
14694 Indx_Typ : Entity_Id;
14695 Lbd, Hbd : Node_Id;
14697 begin
14698 Indx := First_Index (Typ);
14699 while Present (Indx) loop
14700 if Etype (Indx) = Any_Type then
14701 return False;
14703 -- If index is a range, use directly
14705 elsif Nkind (Indx) = N_Range then
14706 Lbd := Low_Bound (Indx);
14707 Hbd := High_Bound (Indx);
14709 else
14710 Indx_Typ := Etype (Indx);
14712 if Is_Private_Type (Indx_Typ) then
14713 Indx_Typ := Full_View (Indx_Typ);
14714 end if;
14716 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14717 return False;
14718 else
14719 Lbd := Type_Low_Bound (Indx_Typ);
14720 Hbd := Type_High_Bound (Indx_Typ);
14721 end if;
14722 end if;
14724 if Compile_Time_Known_Value (Lbd)
14725 and then
14726 Compile_Time_Known_Value (Hbd)
14727 then
14728 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14729 return True;
14730 end if;
14731 end if;
14733 Next_Index (Indx);
14734 end loop;
14735 end;
14736 end if;
14738 -- If no null indexes, then type is not fully initialized
14740 return False;
14742 -- Record types
14744 elsif Is_Record_Type (Typ) then
14745 if Has_Discriminants (Typ)
14746 and then
14747 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14748 and then Is_Fully_Initialized_Variant (Typ)
14749 then
14750 return True;
14751 end if;
14753 -- We consider bounded string types to be fully initialized, because
14754 -- otherwise we get false alarms when the Data component is not
14755 -- default-initialized.
14757 if Is_Bounded_String (Typ) then
14758 return True;
14759 end if;
14761 -- Controlled records are considered to be fully initialized if
14762 -- there is a user defined Initialize routine. This may not be
14763 -- entirely correct, but as the spec notes, we are guessing here
14764 -- what is best from the point of view of issuing warnings.
14766 if Is_Controlled (Typ) then
14767 declare
14768 Utyp : constant Entity_Id := Underlying_Type (Typ);
14770 begin
14771 if Present (Utyp) then
14772 declare
14773 Init : constant Entity_Id :=
14774 (Find_Optional_Prim_Op
14775 (Underlying_Type (Typ), Name_Initialize));
14777 begin
14778 if Present (Init)
14779 and then Comes_From_Source (Init)
14780 and then not In_Predefined_Unit (Init)
14781 then
14782 return True;
14784 elsif Has_Null_Extension (Typ)
14785 and then
14786 Is_Fully_Initialized_Type
14787 (Etype (Base_Type (Typ)))
14788 then
14789 return True;
14790 end if;
14791 end;
14792 end if;
14793 end;
14794 end if;
14796 -- Otherwise see if all record components are initialized
14798 declare
14799 Ent : Entity_Id;
14801 begin
14802 Ent := First_Entity (Typ);
14803 while Present (Ent) loop
14804 if Ekind (Ent) = E_Component
14805 and then (No (Parent (Ent))
14806 or else No (Expression (Parent (Ent))))
14807 and then not Is_Fully_Initialized_Type (Etype (Ent))
14809 -- Special VM case for tag components, which need to be
14810 -- defined in this case, but are never initialized as VMs
14811 -- are using other dispatching mechanisms. Ignore this
14812 -- uninitialized case. Note that this applies both to the
14813 -- uTag entry and the main vtable pointer (CPP_Class case).
14815 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14816 then
14817 return False;
14818 end if;
14820 Next_Entity (Ent);
14821 end loop;
14822 end;
14824 -- No uninitialized components, so type is fully initialized.
14825 -- Note that this catches the case of no components as well.
14827 return True;
14829 elsif Is_Concurrent_Type (Typ) then
14830 return True;
14832 elsif Is_Private_Type (Typ) then
14833 declare
14834 U : constant Entity_Id := Underlying_Type (Typ);
14836 begin
14837 if No (U) then
14838 return False;
14839 else
14840 return Is_Fully_Initialized_Type (U);
14841 end if;
14842 end;
14844 else
14845 return False;
14846 end if;
14847 end Is_Fully_Initialized_Type;
14849 ----------------------------------
14850 -- Is_Fully_Initialized_Variant --
14851 ----------------------------------
14853 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
14854 Loc : constant Source_Ptr := Sloc (Typ);
14855 Constraints : constant List_Id := New_List;
14856 Components : constant Elist_Id := New_Elmt_List;
14857 Comp_Elmt : Elmt_Id;
14858 Comp_Id : Node_Id;
14859 Comp_List : Node_Id;
14860 Discr : Entity_Id;
14861 Discr_Val : Node_Id;
14863 Report_Errors : Boolean;
14864 pragma Warnings (Off, Report_Errors);
14866 begin
14867 if Serious_Errors_Detected > 0 then
14868 return False;
14869 end if;
14871 if Is_Record_Type (Typ)
14872 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
14873 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
14874 then
14875 Comp_List := Component_List (Type_Definition (Parent (Typ)));
14877 Discr := First_Discriminant (Typ);
14878 while Present (Discr) loop
14879 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
14880 Discr_Val := Expression (Parent (Discr));
14882 if Present (Discr_Val)
14883 and then Is_OK_Static_Expression (Discr_Val)
14884 then
14885 Append_To (Constraints,
14886 Make_Component_Association (Loc,
14887 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
14888 Expression => New_Copy (Discr_Val)));
14889 else
14890 return False;
14891 end if;
14892 else
14893 return False;
14894 end if;
14896 Next_Discriminant (Discr);
14897 end loop;
14899 Gather_Components
14900 (Typ => Typ,
14901 Comp_List => Comp_List,
14902 Governed_By => Constraints,
14903 Into => Components,
14904 Report_Errors => Report_Errors);
14906 -- Check that each component present is fully initialized
14908 Comp_Elmt := First_Elmt (Components);
14909 while Present (Comp_Elmt) loop
14910 Comp_Id := Node (Comp_Elmt);
14912 if Ekind (Comp_Id) = E_Component
14913 and then (No (Parent (Comp_Id))
14914 or else No (Expression (Parent (Comp_Id))))
14915 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
14916 then
14917 return False;
14918 end if;
14920 Next_Elmt (Comp_Elmt);
14921 end loop;
14923 return True;
14925 elsif Is_Private_Type (Typ) then
14926 declare
14927 U : constant Entity_Id := Underlying_Type (Typ);
14929 begin
14930 if No (U) then
14931 return False;
14932 else
14933 return Is_Fully_Initialized_Variant (U);
14934 end if;
14935 end;
14937 else
14938 return False;
14939 end if;
14940 end Is_Fully_Initialized_Variant;
14942 ------------------------------------
14943 -- Is_Generic_Declaration_Or_Body --
14944 ------------------------------------
14946 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
14947 Spec_Decl : Node_Id;
14949 begin
14950 -- Package/subprogram body
14952 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
14953 and then Present (Corresponding_Spec (Decl))
14954 then
14955 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
14957 -- Package/subprogram body stub
14959 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
14960 and then Present (Corresponding_Spec_Of_Stub (Decl))
14961 then
14962 Spec_Decl :=
14963 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
14965 -- All other cases
14967 else
14968 Spec_Decl := Decl;
14969 end if;
14971 -- Rather than inspecting the defining entity of the spec declaration,
14972 -- look at its Nkind. This takes care of the case where the analysis of
14973 -- a generic body modifies the Ekind of its spec to allow for recursive
14974 -- calls.
14976 return
14977 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
14978 N_Generic_Subprogram_Declaration);
14979 end Is_Generic_Declaration_Or_Body;
14981 ----------------------------
14982 -- Is_Inherited_Operation --
14983 ----------------------------
14985 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
14986 pragma Assert (Is_Overloadable (E));
14987 Kind : constant Node_Kind := Nkind (Parent (E));
14988 begin
14989 return Kind = N_Full_Type_Declaration
14990 or else Kind = N_Private_Extension_Declaration
14991 or else Kind = N_Subtype_Declaration
14992 or else (Ekind (E) = E_Enumeration_Literal
14993 and then Is_Derived_Type (Etype (E)));
14994 end Is_Inherited_Operation;
14996 -------------------------------------
14997 -- Is_Inherited_Operation_For_Type --
14998 -------------------------------------
15000 function Is_Inherited_Operation_For_Type
15001 (E : Entity_Id;
15002 Typ : Entity_Id) return Boolean
15004 begin
15005 -- Check that the operation has been created by the type declaration
15007 return Is_Inherited_Operation (E)
15008 and then Defining_Identifier (Parent (E)) = Typ;
15009 end Is_Inherited_Operation_For_Type;
15011 --------------------------------------
15012 -- Is_Inlinable_Expression_Function --
15013 --------------------------------------
15015 function Is_Inlinable_Expression_Function
15016 (Subp : Entity_Id) return Boolean
15018 Return_Expr : Node_Id;
15020 begin
15021 if Is_Expression_Function_Or_Completion (Subp)
15022 and then Has_Pragma_Inline_Always (Subp)
15023 and then Needs_No_Actuals (Subp)
15024 and then No (Contract (Subp))
15025 and then not Is_Dispatching_Operation (Subp)
15026 and then Needs_Finalization (Etype (Subp))
15027 and then not Is_Class_Wide_Type (Etype (Subp))
15028 and then not (Has_Invariants (Etype (Subp)))
15029 and then Present (Subprogram_Body (Subp))
15030 and then Was_Expression_Function (Subprogram_Body (Subp))
15031 then
15032 Return_Expr := Expression_Of_Expression_Function (Subp);
15034 -- The returned object must not have a qualified expression and its
15035 -- nominal subtype must be statically compatible with the result
15036 -- subtype of the expression function.
15038 return
15039 Nkind (Return_Expr) = N_Identifier
15040 and then Etype (Return_Expr) = Etype (Subp);
15041 end if;
15043 return False;
15044 end Is_Inlinable_Expression_Function;
15046 -----------------
15047 -- Is_Iterator --
15048 -----------------
15050 function Is_Iterator (Typ : Entity_Id) return Boolean is
15051 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
15052 -- Determine whether type Iter_Typ is a predefined forward or reversible
15053 -- iterator.
15055 ----------------------
15056 -- Denotes_Iterator --
15057 ----------------------
15059 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
15060 begin
15061 -- Check that the name matches, and that the ultimate ancestor is in
15062 -- a predefined unit, i.e the one that declares iterator interfaces.
15064 return
15065 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
15066 Name_Reversible_Iterator)
15067 and then In_Predefined_Unit (Root_Type (Iter_Typ));
15068 end Denotes_Iterator;
15070 -- Local variables
15072 Iface_Elmt : Elmt_Id;
15073 Ifaces : Elist_Id;
15075 -- Start of processing for Is_Iterator
15077 begin
15078 -- The type may be a subtype of a descendant of the proper instance of
15079 -- the predefined interface type, so we must use the root type of the
15080 -- given type. The same is done for Is_Reversible_Iterator.
15082 if Is_Class_Wide_Type (Typ)
15083 and then Denotes_Iterator (Root_Type (Typ))
15084 then
15085 return True;
15087 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15088 return False;
15090 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
15091 return True;
15093 else
15094 Collect_Interfaces (Typ, Ifaces);
15096 Iface_Elmt := First_Elmt (Ifaces);
15097 while Present (Iface_Elmt) loop
15098 if Denotes_Iterator (Node (Iface_Elmt)) then
15099 return True;
15100 end if;
15102 Next_Elmt (Iface_Elmt);
15103 end loop;
15105 return False;
15106 end if;
15107 end Is_Iterator;
15109 ----------------------------
15110 -- Is_Iterator_Over_Array --
15111 ----------------------------
15113 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
15114 Container : constant Node_Id := Name (N);
15115 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
15116 begin
15117 return Is_Array_Type (Container_Typ);
15118 end Is_Iterator_Over_Array;
15120 ------------
15121 -- Is_LHS --
15122 ------------
15124 -- We seem to have a lot of overlapping functions that do similar things
15125 -- (testing for left hand sides or lvalues???).
15127 function Is_LHS (N : Node_Id) return Is_LHS_Result is
15128 P : constant Node_Id := Parent (N);
15130 begin
15131 -- Return True if we are the left hand side of an assignment statement
15133 if Nkind (P) = N_Assignment_Statement then
15134 if Name (P) = N then
15135 return Yes;
15136 else
15137 return No;
15138 end if;
15140 -- Case of prefix of indexed or selected component or slice
15142 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
15143 and then N = Prefix (P)
15144 then
15145 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15146 -- If P is an LHS, then N is also effectively an LHS, but there
15147 -- is an important exception. If N is of an access type, then
15148 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15149 -- case this makes N.all a left hand side but not N itself.
15151 -- If we don't know the type yet, this is the case where we return
15152 -- Unknown, since the answer depends on the type which is unknown.
15154 if No (Etype (N)) then
15155 return Unknown;
15157 -- We have an Etype set, so we can check it
15159 elsif Is_Access_Type (Etype (N)) then
15160 return No;
15162 -- OK, not access type case, so just test whole expression
15164 else
15165 return Is_LHS (P);
15166 end if;
15168 -- All other cases are not left hand sides
15170 else
15171 return No;
15172 end if;
15173 end Is_LHS;
15175 -----------------------------
15176 -- Is_Library_Level_Entity --
15177 -----------------------------
15179 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
15180 begin
15181 -- The following is a small optimization, and it also properly handles
15182 -- discriminals, which in task bodies might appear in expressions before
15183 -- the corresponding procedure has been created, and which therefore do
15184 -- not have an assigned scope.
15186 if Is_Formal (E) then
15187 return False;
15188 end if;
15190 -- Normal test is simply that the enclosing dynamic scope is Standard
15192 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
15193 end Is_Library_Level_Entity;
15195 --------------------------------
15196 -- Is_Limited_Class_Wide_Type --
15197 --------------------------------
15199 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
15200 begin
15201 return
15202 Is_Class_Wide_Type (Typ)
15203 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
15204 end Is_Limited_Class_Wide_Type;
15206 ---------------------------------
15207 -- Is_Local_Variable_Reference --
15208 ---------------------------------
15210 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
15211 begin
15212 if not Is_Entity_Name (Expr) then
15213 return False;
15215 else
15216 declare
15217 Ent : constant Entity_Id := Entity (Expr);
15218 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
15219 begin
15220 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15221 return False;
15222 else
15223 return Present (Sub) and then Sub = Current_Subprogram;
15224 end if;
15225 end;
15226 end if;
15227 end Is_Local_Variable_Reference;
15229 -----------------------
15230 -- Is_Name_Reference --
15231 -----------------------
15233 function Is_Name_Reference (N : Node_Id) return Boolean is
15234 begin
15235 if Is_Entity_Name (N) then
15236 return Present (Entity (N)) and then Is_Object (Entity (N));
15237 end if;
15239 case Nkind (N) is
15240 when N_Indexed_Component
15241 | N_Slice
15243 return
15244 Is_Name_Reference (Prefix (N))
15245 or else Is_Access_Type (Etype (Prefix (N)));
15247 -- Attributes 'Input, 'Old and 'Result produce objects
15249 when N_Attribute_Reference =>
15250 return
15251 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15253 when N_Selected_Component =>
15254 return
15255 Is_Name_Reference (Selector_Name (N))
15256 and then
15257 (Is_Name_Reference (Prefix (N))
15258 or else Is_Access_Type (Etype (Prefix (N))));
15260 when N_Explicit_Dereference =>
15261 return True;
15263 -- A view conversion of a tagged name is a name reference
15265 when N_Type_Conversion =>
15266 return
15267 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15268 and then Is_Tagged_Type (Etype (Expression (N)))
15269 and then Is_Name_Reference (Expression (N));
15271 -- An unchecked type conversion is considered to be a name if the
15272 -- operand is a name (this construction arises only as a result of
15273 -- expansion activities).
15275 when N_Unchecked_Type_Conversion =>
15276 return Is_Name_Reference (Expression (N));
15278 when others =>
15279 return False;
15280 end case;
15281 end Is_Name_Reference;
15283 ------------------------------------
15284 -- Is_Non_Preelaborable_Construct --
15285 ------------------------------------
15287 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15289 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15290 -- intentionally unnested to avoid deep indentation of code.
15292 Non_Preelaborable : exception;
15293 -- This exception is raised when the construct violates preelaborability
15294 -- to terminate the recursion.
15296 procedure Visit (Nod : Node_Id);
15297 -- Semantically inspect construct Nod to determine whether it violates
15298 -- preelaborability. This routine raises Non_Preelaborable.
15300 procedure Visit_List (List : List_Id);
15301 pragma Inline (Visit_List);
15302 -- Invoke Visit on each element of list List. This routine raises
15303 -- Non_Preelaborable.
15305 procedure Visit_Pragma (Prag : Node_Id);
15306 pragma Inline (Visit_Pragma);
15307 -- Semantically inspect pragma Prag to determine whether it violates
15308 -- preelaborability. This routine raises Non_Preelaborable.
15310 procedure Visit_Subexpression (Expr : Node_Id);
15311 pragma Inline (Visit_Subexpression);
15312 -- Semantically inspect expression Expr to determine whether it violates
15313 -- preelaborability. This routine raises Non_Preelaborable.
15315 -----------
15316 -- Visit --
15317 -----------
15319 procedure Visit (Nod : Node_Id) is
15320 begin
15321 case Nkind (Nod) is
15323 -- Declarations
15325 when N_Component_Declaration =>
15327 -- Defining_Identifier is left out because it is not relevant
15328 -- for preelaborability.
15330 Visit (Component_Definition (Nod));
15331 Visit (Expression (Nod));
15333 when N_Derived_Type_Definition =>
15335 -- Interface_List is left out because it is not relevant for
15336 -- preelaborability.
15338 Visit (Record_Extension_Part (Nod));
15339 Visit (Subtype_Indication (Nod));
15341 when N_Entry_Declaration =>
15343 -- A protected type with at leat one entry is not preelaborable
15344 -- while task types are never preelaborable. This renders entry
15345 -- declarations non-preelaborable.
15347 raise Non_Preelaborable;
15349 when N_Full_Type_Declaration =>
15351 -- Defining_Identifier and Discriminant_Specifications are left
15352 -- out because they are not relevant for preelaborability.
15354 Visit (Type_Definition (Nod));
15356 when N_Function_Instantiation
15357 | N_Package_Instantiation
15358 | N_Procedure_Instantiation
15360 -- Defining_Unit_Name and Name are left out because they are
15361 -- not relevant for preelaborability.
15363 Visit_List (Generic_Associations (Nod));
15365 when N_Object_Declaration =>
15367 -- Defining_Identifier is left out because it is not relevant
15368 -- for preelaborability.
15370 Visit (Object_Definition (Nod));
15372 if Has_Init_Expression (Nod) then
15373 Visit (Expression (Nod));
15375 elsif not Has_Preelaborable_Initialization
15376 (Etype (Defining_Entity (Nod)))
15377 then
15378 raise Non_Preelaborable;
15379 end if;
15381 when N_Private_Extension_Declaration
15382 | N_Subtype_Declaration
15384 -- Defining_Identifier, Discriminant_Specifications, and
15385 -- Interface_List are left out because they are not relevant
15386 -- for preelaborability.
15388 Visit (Subtype_Indication (Nod));
15390 when N_Protected_Type_Declaration
15391 | N_Single_Protected_Declaration
15393 -- Defining_Identifier, Discriminant_Specifications, and
15394 -- Interface_List are left out because they are not relevant
15395 -- for preelaborability.
15397 Visit (Protected_Definition (Nod));
15399 -- A [single] task type is never preelaborable
15401 when N_Single_Task_Declaration
15402 | N_Task_Type_Declaration
15404 raise Non_Preelaborable;
15406 -- Pragmas
15408 when N_Pragma =>
15409 Visit_Pragma (Nod);
15411 -- Statements
15413 when N_Statement_Other_Than_Procedure_Call =>
15414 if Nkind (Nod) /= N_Null_Statement then
15415 raise Non_Preelaborable;
15416 end if;
15418 -- Subexpressions
15420 when N_Subexpr =>
15421 Visit_Subexpression (Nod);
15423 -- Special
15425 when N_Access_To_Object_Definition =>
15426 Visit (Subtype_Indication (Nod));
15428 when N_Case_Expression_Alternative =>
15429 Visit (Expression (Nod));
15430 Visit_List (Discrete_Choices (Nod));
15432 when N_Component_Definition =>
15433 Visit (Access_Definition (Nod));
15434 Visit (Subtype_Indication (Nod));
15436 when N_Component_List =>
15437 Visit_List (Component_Items (Nod));
15438 Visit (Variant_Part (Nod));
15440 when N_Constrained_Array_Definition =>
15441 Visit_List (Discrete_Subtype_Definitions (Nod));
15442 Visit (Component_Definition (Nod));
15444 when N_Delta_Constraint
15445 | N_Digits_Constraint
15447 -- Delta_Expression and Digits_Expression are left out because
15448 -- they are not relevant for preelaborability.
15450 Visit (Range_Constraint (Nod));
15452 when N_Discriminant_Specification =>
15454 -- Defining_Identifier and Expression are left out because they
15455 -- are not relevant for preelaborability.
15457 Visit (Discriminant_Type (Nod));
15459 when N_Generic_Association =>
15461 -- Selector_Name is left out because it is not relevant for
15462 -- preelaborability.
15464 Visit (Explicit_Generic_Actual_Parameter (Nod));
15466 when N_Index_Or_Discriminant_Constraint =>
15467 Visit_List (Constraints (Nod));
15469 when N_Iterator_Specification =>
15471 -- Defining_Identifier is left out because it is not relevant
15472 -- for preelaborability.
15474 Visit (Name (Nod));
15475 Visit (Subtype_Indication (Nod));
15477 when N_Loop_Parameter_Specification =>
15479 -- Defining_Identifier is left out because it is not relevant
15480 -- for preelaborability.
15482 Visit (Discrete_Subtype_Definition (Nod));
15484 when N_Protected_Definition =>
15486 -- End_Label is left out because it is not relevant for
15487 -- preelaborability.
15489 Visit_List (Private_Declarations (Nod));
15490 Visit_List (Visible_Declarations (Nod));
15492 when N_Range_Constraint =>
15493 Visit (Range_Expression (Nod));
15495 when N_Record_Definition
15496 | N_Variant
15498 -- End_Label, Discrete_Choices, and Interface_List are left out
15499 -- because they are not relevant for preelaborability.
15501 Visit (Component_List (Nod));
15503 when N_Subtype_Indication =>
15505 -- Subtype_Mark is left out because it is not relevant for
15506 -- preelaborability.
15508 Visit (Constraint (Nod));
15510 when N_Unconstrained_Array_Definition =>
15512 -- Subtype_Marks is left out because it is not relevant for
15513 -- preelaborability.
15515 Visit (Component_Definition (Nod));
15517 when N_Variant_Part =>
15519 -- Name is left out because it is not relevant for
15520 -- preelaborability.
15522 Visit_List (Variants (Nod));
15524 -- Default
15526 when others =>
15527 null;
15528 end case;
15529 end Visit;
15531 ----------------
15532 -- Visit_List --
15533 ----------------
15535 procedure Visit_List (List : List_Id) is
15536 Nod : Node_Id;
15538 begin
15539 if Present (List) then
15540 Nod := First (List);
15541 while Present (Nod) loop
15542 Visit (Nod);
15543 Next (Nod);
15544 end loop;
15545 end if;
15546 end Visit_List;
15548 ------------------
15549 -- Visit_Pragma --
15550 ------------------
15552 procedure Visit_Pragma (Prag : Node_Id) is
15553 begin
15554 case Get_Pragma_Id (Prag) is
15555 when Pragma_Assert
15556 | Pragma_Assert_And_Cut
15557 | Pragma_Assume
15558 | Pragma_Async_Readers
15559 | Pragma_Async_Writers
15560 | Pragma_Attribute_Definition
15561 | Pragma_Check
15562 | Pragma_Constant_After_Elaboration
15563 | Pragma_CPU
15564 | Pragma_Deadline_Floor
15565 | Pragma_Dispatching_Domain
15566 | Pragma_Effective_Reads
15567 | Pragma_Effective_Writes
15568 | Pragma_Extensions_Visible
15569 | Pragma_Ghost
15570 | Pragma_Secondary_Stack_Size
15571 | Pragma_Task_Name
15572 | Pragma_Volatile_Function
15574 Visit_List (Pragma_Argument_Associations (Prag));
15576 -- Default
15578 when others =>
15579 null;
15580 end case;
15581 end Visit_Pragma;
15583 -------------------------
15584 -- Visit_Subexpression --
15585 -------------------------
15587 procedure Visit_Subexpression (Expr : Node_Id) is
15588 procedure Visit_Aggregate (Aggr : Node_Id);
15589 pragma Inline (Visit_Aggregate);
15590 -- Semantically inspect aggregate Aggr to determine whether it
15591 -- violates preelaborability.
15593 ---------------------
15594 -- Visit_Aggregate --
15595 ---------------------
15597 procedure Visit_Aggregate (Aggr : Node_Id) is
15598 begin
15599 if not Is_Preelaborable_Aggregate (Aggr) then
15600 raise Non_Preelaborable;
15601 end if;
15602 end Visit_Aggregate;
15604 -- Start of processing for Visit_Subexpression
15606 begin
15607 case Nkind (Expr) is
15608 when N_Allocator
15609 | N_Qualified_Expression
15610 | N_Type_Conversion
15611 | N_Unchecked_Expression
15612 | N_Unchecked_Type_Conversion
15614 -- Subpool_Handle_Name and Subtype_Mark are left out because
15615 -- they are not relevant for preelaborability.
15617 Visit (Expression (Expr));
15619 when N_Aggregate
15620 | N_Extension_Aggregate
15622 Visit_Aggregate (Expr);
15624 when N_Attribute_Reference
15625 | N_Explicit_Dereference
15626 | N_Reference
15628 -- Attribute_Name and Expressions are left out because they are
15629 -- not relevant for preelaborability.
15631 Visit (Prefix (Expr));
15633 when N_Case_Expression =>
15635 -- End_Span is left out because it is not relevant for
15636 -- preelaborability.
15638 Visit_List (Alternatives (Expr));
15639 Visit (Expression (Expr));
15641 when N_Delta_Aggregate =>
15642 Visit_Aggregate (Expr);
15643 Visit (Expression (Expr));
15645 when N_Expression_With_Actions =>
15646 Visit_List (Actions (Expr));
15647 Visit (Expression (Expr));
15649 when N_If_Expression =>
15650 Visit_List (Expressions (Expr));
15652 when N_Quantified_Expression =>
15653 Visit (Condition (Expr));
15654 Visit (Iterator_Specification (Expr));
15655 Visit (Loop_Parameter_Specification (Expr));
15657 when N_Range =>
15658 Visit (High_Bound (Expr));
15659 Visit (Low_Bound (Expr));
15661 when N_Slice =>
15662 Visit (Discrete_Range (Expr));
15663 Visit (Prefix (Expr));
15665 -- Default
15667 when others =>
15669 -- The evaluation of an object name is not preelaborable,
15670 -- unless the name is a static expression (checked further
15671 -- below), or statically denotes a discriminant.
15673 if Is_Entity_Name (Expr) then
15674 Object_Name : declare
15675 Id : constant Entity_Id := Entity (Expr);
15677 begin
15678 if Is_Object (Id) then
15679 if Ekind (Id) = E_Discriminant then
15680 null;
15682 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15683 and then Present (Discriminal_Link (Id))
15684 then
15685 null;
15687 else
15688 raise Non_Preelaborable;
15689 end if;
15690 end if;
15691 end Object_Name;
15693 -- A non-static expression is not preelaborable
15695 elsif not Is_OK_Static_Expression (Expr) then
15696 raise Non_Preelaborable;
15697 end if;
15698 end case;
15699 end Visit_Subexpression;
15701 -- Start of processing for Is_Non_Preelaborable_Construct
15703 begin
15704 Visit (N);
15706 -- At this point it is known that the construct is preelaborable
15708 return False;
15710 exception
15712 -- The elaboration of the construct performs an action which violates
15713 -- preelaborability.
15715 when Non_Preelaborable =>
15716 return True;
15717 end Is_Non_Preelaborable_Construct;
15719 ---------------------------------
15720 -- Is_Nontrivial_DIC_Procedure --
15721 ---------------------------------
15723 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15724 Body_Decl : Node_Id;
15725 Stmt : Node_Id;
15727 begin
15728 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15729 Body_Decl :=
15730 Unit_Declaration_Node
15731 (Corresponding_Body (Unit_Declaration_Node (Id)));
15733 -- The body of the Default_Initial_Condition procedure must contain
15734 -- at least one statement, otherwise the generation of the subprogram
15735 -- body failed.
15737 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15739 -- To qualify as nontrivial, the first statement of the procedure
15740 -- must be a check in the form of an if statement. If the original
15741 -- Default_Initial_Condition expression was folded, then the first
15742 -- statement is not a check.
15744 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15746 return
15747 Nkind (Stmt) = N_If_Statement
15748 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15749 end if;
15751 return False;
15752 end Is_Nontrivial_DIC_Procedure;
15754 -------------------------
15755 -- Is_Null_Record_Type --
15756 -------------------------
15758 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15759 Decl : constant Node_Id := Parent (T);
15760 begin
15761 return Nkind (Decl) = N_Full_Type_Declaration
15762 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15763 and then
15764 (No (Component_List (Type_Definition (Decl)))
15765 or else Null_Present (Component_List (Type_Definition (Decl))));
15766 end Is_Null_Record_Type;
15768 ---------------------
15769 -- Is_Object_Image --
15770 ---------------------
15772 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15773 begin
15774 -- When the type of the prefix is not scalar, then the prefix is not
15775 -- valid in any scenario.
15777 if not Is_Scalar_Type (Etype (Prefix)) then
15778 return False;
15779 end if;
15781 -- Here we test for the case that the prefix is not a type and assume
15782 -- if it is not then it must be a named value or an object reference.
15783 -- This is because the parser always checks that prefixes of attributes
15784 -- are named.
15786 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
15787 end Is_Object_Image;
15789 -------------------------
15790 -- Is_Object_Reference --
15791 -------------------------
15793 function Is_Object_Reference (N : Node_Id) return Boolean is
15794 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
15795 -- Determine whether N is the name of an internally-generated renaming
15797 --------------------------------------
15798 -- Is_Internally_Generated_Renaming --
15799 --------------------------------------
15801 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
15802 P : Node_Id;
15804 begin
15805 P := N;
15806 while Present (P) loop
15807 if Nkind (P) = N_Object_Renaming_Declaration then
15808 return not Comes_From_Source (P);
15809 elsif Is_List_Member (P) then
15810 return False;
15811 end if;
15813 P := Parent (P);
15814 end loop;
15816 return False;
15817 end Is_Internally_Generated_Renaming;
15819 -- Start of processing for Is_Object_Reference
15821 begin
15822 if Is_Entity_Name (N) then
15823 return Present (Entity (N)) and then Is_Object (Entity (N));
15825 else
15826 case Nkind (N) is
15827 when N_Indexed_Component
15828 | N_Slice
15830 return
15831 Is_Object_Reference (Prefix (N))
15832 or else Is_Access_Type (Etype (Prefix (N)));
15834 -- In Ada 95, a function call is a constant object; a procedure
15835 -- call is not.
15837 -- Note that predefined operators are functions as well, and so
15838 -- are attributes that are (can be renamed as) functions.
15840 when N_Binary_Op
15841 | N_Function_Call
15842 | N_Unary_Op
15844 return Etype (N) /= Standard_Void_Type;
15846 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
15847 -- objects, even though they are not functions.
15849 when N_Attribute_Reference =>
15850 return
15851 Nam_In (Attribute_Name (N), Name_Loop_Entry,
15852 Name_Old,
15853 Name_Result)
15854 or else Is_Function_Attribute_Name (Attribute_Name (N));
15856 when N_Selected_Component =>
15857 return
15858 Is_Object_Reference (Selector_Name (N))
15859 and then
15860 (Is_Object_Reference (Prefix (N))
15861 or else Is_Access_Type (Etype (Prefix (N))));
15863 -- An explicit dereference denotes an object, except that a
15864 -- conditional expression gets turned into an explicit dereference
15865 -- in some cases, and conditional expressions are not object
15866 -- names.
15868 when N_Explicit_Dereference =>
15869 return not Nkind_In (Original_Node (N), N_Case_Expression,
15870 N_If_Expression);
15872 -- A view conversion of a tagged object is an object reference
15874 when N_Type_Conversion =>
15875 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
15876 and then Is_Tagged_Type (Etype (Expression (N)))
15877 and then Is_Object_Reference (Expression (N));
15879 -- An unchecked type conversion is considered to be an object if
15880 -- the operand is an object (this construction arises only as a
15881 -- result of expansion activities).
15883 when N_Unchecked_Type_Conversion =>
15884 return True;
15886 -- Allow string literals to act as objects as long as they appear
15887 -- in internally-generated renamings. The expansion of iterators
15888 -- may generate such renamings when the range involves a string
15889 -- literal.
15891 when N_String_Literal =>
15892 return Is_Internally_Generated_Renaming (Parent (N));
15894 -- AI05-0003: In Ada 2012 a qualified expression is a name.
15895 -- This allows disambiguation of function calls and the use
15896 -- of aggregates in more contexts.
15898 when N_Qualified_Expression =>
15899 if Ada_Version < Ada_2012 then
15900 return False;
15901 else
15902 return Is_Object_Reference (Expression (N))
15903 or else Nkind (Expression (N)) = N_Aggregate;
15904 end if;
15906 when others =>
15907 return False;
15908 end case;
15909 end if;
15910 end Is_Object_Reference;
15912 -----------------------------------
15913 -- Is_OK_Variable_For_Out_Formal --
15914 -----------------------------------
15916 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
15917 begin
15918 Note_Possible_Modification (AV, Sure => True);
15920 -- We must reject parenthesized variable names. Comes_From_Source is
15921 -- checked because there are currently cases where the compiler violates
15922 -- this rule (e.g. passing a task object to its controlled Initialize
15923 -- routine). This should be properly documented in sinfo???
15925 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
15926 return False;
15928 -- A variable is always allowed
15930 elsif Is_Variable (AV) then
15931 return True;
15933 -- Generalized indexing operations are rewritten as explicit
15934 -- dereferences, and it is only during resolution that we can
15935 -- check whether the context requires an access_to_variable type.
15937 elsif Nkind (AV) = N_Explicit_Dereference
15938 and then Ada_Version >= Ada_2012
15939 and then Nkind (Original_Node (AV)) = N_Indexed_Component
15940 and then Present (Etype (Original_Node (AV)))
15941 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
15942 then
15943 return not Is_Access_Constant (Etype (Prefix (AV)));
15945 -- Unchecked conversions are allowed only if they come from the
15946 -- generated code, which sometimes uses unchecked conversions for out
15947 -- parameters in cases where code generation is unaffected. We tell
15948 -- source unchecked conversions by seeing if they are rewrites of
15949 -- an original Unchecked_Conversion function call, or of an explicit
15950 -- conversion of a function call or an aggregate (as may happen in the
15951 -- expansion of a packed array aggregate).
15953 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
15954 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
15955 return False;
15957 elsif Comes_From_Source (AV)
15958 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
15959 then
15960 return False;
15962 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
15963 return Is_OK_Variable_For_Out_Formal (Expression (AV));
15965 else
15966 return True;
15967 end if;
15969 -- Normal type conversions are allowed if argument is a variable
15971 elsif Nkind (AV) = N_Type_Conversion then
15972 if Is_Variable (Expression (AV))
15973 and then Paren_Count (Expression (AV)) = 0
15974 then
15975 Note_Possible_Modification (Expression (AV), Sure => True);
15976 return True;
15978 -- We also allow a non-parenthesized expression that raises
15979 -- constraint error if it rewrites what used to be a variable
15981 elsif Raises_Constraint_Error (Expression (AV))
15982 and then Paren_Count (Expression (AV)) = 0
15983 and then Is_Variable (Original_Node (Expression (AV)))
15984 then
15985 return True;
15987 -- Type conversion of something other than a variable
15989 else
15990 return False;
15991 end if;
15993 -- If this node is rewritten, then test the original form, if that is
15994 -- OK, then we consider the rewritten node OK (for example, if the
15995 -- original node is a conversion, then Is_Variable will not be true
15996 -- but we still want to allow the conversion if it converts a variable).
15998 elsif Is_Rewrite_Substitution (AV) then
16000 -- In Ada 2012, the explicit dereference may be a rewritten call to a
16001 -- Reference function.
16003 if Ada_Version >= Ada_2012
16004 and then Nkind (Original_Node (AV)) = N_Function_Call
16005 and then
16006 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
16007 then
16009 -- Check that this is not a constant reference.
16011 return not Is_Access_Constant (Etype (Prefix (AV)));
16013 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
16014 return
16015 not Is_Access_Constant (Etype
16016 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
16018 else
16019 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
16020 end if;
16022 -- All other non-variables are rejected
16024 else
16025 return False;
16026 end if;
16027 end Is_OK_Variable_For_Out_Formal;
16029 ----------------------------
16030 -- Is_OK_Volatile_Context --
16031 ----------------------------
16033 function Is_OK_Volatile_Context
16034 (Context : Node_Id;
16035 Obj_Ref : Node_Id) return Boolean
16037 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
16038 -- Determine whether an arbitrary node denotes a call to a protected
16039 -- entry, function, or procedure in prefixed form where the prefix is
16040 -- Obj_Ref.
16042 function Within_Check (Nod : Node_Id) return Boolean;
16043 -- Determine whether an arbitrary node appears in a check node
16045 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
16046 -- Determine whether an arbitrary entity appears in a volatile function
16048 ---------------------------------
16049 -- Is_Protected_Operation_Call --
16050 ---------------------------------
16052 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
16053 Pref : Node_Id;
16054 Subp : Node_Id;
16056 begin
16057 -- A call to a protected operations retains its selected component
16058 -- form as opposed to other prefixed calls that are transformed in
16059 -- expanded names.
16061 if Nkind (Nod) = N_Selected_Component then
16062 Pref := Prefix (Nod);
16063 Subp := Selector_Name (Nod);
16065 return
16066 Pref = Obj_Ref
16067 and then Present (Etype (Pref))
16068 and then Is_Protected_Type (Etype (Pref))
16069 and then Is_Entity_Name (Subp)
16070 and then Present (Entity (Subp))
16071 and then Ekind_In (Entity (Subp), E_Entry,
16072 E_Entry_Family,
16073 E_Function,
16074 E_Procedure);
16075 else
16076 return False;
16077 end if;
16078 end Is_Protected_Operation_Call;
16080 ------------------
16081 -- Within_Check --
16082 ------------------
16084 function Within_Check (Nod : Node_Id) return Boolean is
16085 Par : Node_Id;
16087 begin
16088 -- Climb the parent chain looking for a check node
16090 Par := Nod;
16091 while Present (Par) loop
16092 if Nkind (Par) in N_Raise_xxx_Error then
16093 return True;
16095 -- Prevent the search from going too far
16097 elsif Is_Body_Or_Package_Declaration (Par) then
16098 exit;
16099 end if;
16101 Par := Parent (Par);
16102 end loop;
16104 return False;
16105 end Within_Check;
16107 ------------------------------
16108 -- Within_Volatile_Function --
16109 ------------------------------
16111 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
16112 Func_Id : Entity_Id;
16114 begin
16115 -- Traverse the scope stack looking for a [generic] function
16117 Func_Id := Id;
16118 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
16119 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
16120 return Is_Volatile_Function (Func_Id);
16121 end if;
16123 Func_Id := Scope (Func_Id);
16124 end loop;
16126 return False;
16127 end Within_Volatile_Function;
16129 -- Local variables
16131 Obj_Id : Entity_Id;
16133 -- Start of processing for Is_OK_Volatile_Context
16135 begin
16136 -- The volatile object appears on either side of an assignment
16138 if Nkind (Context) = N_Assignment_Statement then
16139 return True;
16141 -- The volatile object is part of the initialization expression of
16142 -- another object.
16144 elsif Nkind (Context) = N_Object_Declaration
16145 and then Present (Expression (Context))
16146 and then Expression (Context) = Obj_Ref
16147 then
16148 Obj_Id := Defining_Entity (Context);
16150 -- The volatile object acts as the initialization expression of an
16151 -- extended return statement. This is valid context as long as the
16152 -- function is volatile.
16154 if Is_Return_Object (Obj_Id) then
16155 return Within_Volatile_Function (Obj_Id);
16157 -- Otherwise this is a normal object initialization
16159 else
16160 return True;
16161 end if;
16163 -- The volatile object acts as the name of a renaming declaration
16165 elsif Nkind (Context) = N_Object_Renaming_Declaration
16166 and then Name (Context) = Obj_Ref
16167 then
16168 return True;
16170 -- The volatile object appears as an actual parameter in a call to an
16171 -- instance of Unchecked_Conversion whose result is renamed.
16173 elsif Nkind (Context) = N_Function_Call
16174 and then Is_Entity_Name (Name (Context))
16175 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
16176 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
16177 then
16178 return True;
16180 -- The volatile object is actually the prefix in a protected entry,
16181 -- function, or procedure call.
16183 elsif Is_Protected_Operation_Call (Context) then
16184 return True;
16186 -- The volatile object appears as the expression of a simple return
16187 -- statement that applies to a volatile function.
16189 elsif Nkind (Context) = N_Simple_Return_Statement
16190 and then Expression (Context) = Obj_Ref
16191 then
16192 return
16193 Within_Volatile_Function (Return_Statement_Entity (Context));
16195 -- The volatile object appears as the prefix of a name occurring in a
16196 -- non-interfering context.
16198 elsif Nkind_In (Context, N_Attribute_Reference,
16199 N_Explicit_Dereference,
16200 N_Indexed_Component,
16201 N_Selected_Component,
16202 N_Slice)
16203 and then Prefix (Context) = Obj_Ref
16204 and then Is_OK_Volatile_Context
16205 (Context => Parent (Context),
16206 Obj_Ref => Context)
16207 then
16208 return True;
16210 -- The volatile object appears as the prefix of attributes Address,
16211 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16212 -- Position, Size, Storage_Size.
16214 elsif Nkind (Context) = N_Attribute_Reference
16215 and then Prefix (Context) = Obj_Ref
16216 and then Nam_In (Attribute_Name (Context), Name_Address,
16217 Name_Alignment,
16218 Name_Component_Size,
16219 Name_First,
16220 Name_First_Bit,
16221 Name_Last,
16222 Name_Last_Bit,
16223 Name_Length,
16224 Name_Position,
16225 Name_Size,
16226 Name_Storage_Size)
16227 then
16228 return True;
16230 -- The volatile object appears as the expression of a type conversion
16231 -- occurring in a non-interfering context.
16233 elsif Nkind_In (Context, N_Type_Conversion,
16234 N_Unchecked_Type_Conversion)
16235 and then Expression (Context) = Obj_Ref
16236 and then Is_OK_Volatile_Context
16237 (Context => Parent (Context),
16238 Obj_Ref => Context)
16239 then
16240 return True;
16242 -- The volatile object appears as the expression in a delay statement
16244 elsif Nkind (Context) in N_Delay_Statement then
16245 return True;
16247 -- Allow references to volatile objects in various checks. This is not a
16248 -- direct SPARK 2014 requirement.
16250 elsif Within_Check (Context) then
16251 return True;
16253 -- Assume that references to effectively volatile objects that appear
16254 -- as actual parameters in a subprogram call are always legal. A full
16255 -- legality check is done when the actuals are resolved (see routine
16256 -- Resolve_Actuals).
16258 elsif Within_Subprogram_Call (Context) then
16259 return True;
16261 -- Otherwise the context is not suitable for an effectively volatile
16262 -- object.
16264 else
16265 return False;
16266 end if;
16267 end Is_OK_Volatile_Context;
16269 ------------------------------------
16270 -- Is_Package_Contract_Annotation --
16271 ------------------------------------
16273 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16274 Nam : Name_Id;
16276 begin
16277 if Nkind (Item) = N_Aspect_Specification then
16278 Nam := Chars (Identifier (Item));
16280 else pragma Assert (Nkind (Item) = N_Pragma);
16281 Nam := Pragma_Name (Item);
16282 end if;
16284 return Nam = Name_Abstract_State
16285 or else Nam = Name_Initial_Condition
16286 or else Nam = Name_Initializes
16287 or else Nam = Name_Refined_State;
16288 end Is_Package_Contract_Annotation;
16290 -----------------------------------
16291 -- Is_Partially_Initialized_Type --
16292 -----------------------------------
16294 function Is_Partially_Initialized_Type
16295 (Typ : Entity_Id;
16296 Include_Implicit : Boolean := True) return Boolean
16298 begin
16299 if Is_Scalar_Type (Typ) then
16300 return False;
16302 elsif Is_Access_Type (Typ) then
16303 return Include_Implicit;
16305 elsif Is_Array_Type (Typ) then
16307 -- If component type is partially initialized, so is array type
16309 if Is_Partially_Initialized_Type
16310 (Component_Type (Typ), Include_Implicit)
16311 then
16312 return True;
16314 -- Otherwise we are only partially initialized if we are fully
16315 -- initialized (this is the empty array case, no point in us
16316 -- duplicating that code here).
16318 else
16319 return Is_Fully_Initialized_Type (Typ);
16320 end if;
16322 elsif Is_Record_Type (Typ) then
16324 -- A discriminated type is always partially initialized if in
16325 -- all mode
16327 if Has_Discriminants (Typ) and then Include_Implicit then
16328 return True;
16330 -- A tagged type is always partially initialized
16332 elsif Is_Tagged_Type (Typ) then
16333 return True;
16335 -- Case of non-discriminated record
16337 else
16338 declare
16339 Ent : Entity_Id;
16341 Component_Present : Boolean := False;
16342 -- Set True if at least one component is present. If no
16343 -- components are present, then record type is fully
16344 -- initialized (another odd case, like the null array).
16346 begin
16347 -- Loop through components
16349 Ent := First_Entity (Typ);
16350 while Present (Ent) loop
16351 if Ekind (Ent) = E_Component then
16352 Component_Present := True;
16354 -- If a component has an initialization expression then
16355 -- the enclosing record type is partially initialized
16357 if Present (Parent (Ent))
16358 and then Present (Expression (Parent (Ent)))
16359 then
16360 return True;
16362 -- If a component is of a type which is itself partially
16363 -- initialized, then the enclosing record type is also.
16365 elsif Is_Partially_Initialized_Type
16366 (Etype (Ent), Include_Implicit)
16367 then
16368 return True;
16369 end if;
16370 end if;
16372 Next_Entity (Ent);
16373 end loop;
16375 -- No initialized components found. If we found any components
16376 -- they were all uninitialized so the result is false.
16378 if Component_Present then
16379 return False;
16381 -- But if we found no components, then all the components are
16382 -- initialized so we consider the type to be initialized.
16384 else
16385 return True;
16386 end if;
16387 end;
16388 end if;
16390 -- Concurrent types are always fully initialized
16392 elsif Is_Concurrent_Type (Typ) then
16393 return True;
16395 -- For a private type, go to underlying type. If there is no underlying
16396 -- type then just assume this partially initialized. Not clear if this
16397 -- can happen in a non-error case, but no harm in testing for this.
16399 elsif Is_Private_Type (Typ) then
16400 declare
16401 U : constant Entity_Id := Underlying_Type (Typ);
16402 begin
16403 if No (U) then
16404 return True;
16405 else
16406 return Is_Partially_Initialized_Type (U, Include_Implicit);
16407 end if;
16408 end;
16410 -- For any other type (are there any?) assume partially initialized
16412 else
16413 return True;
16414 end if;
16415 end Is_Partially_Initialized_Type;
16417 ------------------------------------
16418 -- Is_Potentially_Persistent_Type --
16419 ------------------------------------
16421 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16422 Comp : Entity_Id;
16423 Indx : Node_Id;
16425 begin
16426 -- For private type, test corresponding full type
16428 if Is_Private_Type (T) then
16429 return Is_Potentially_Persistent_Type (Full_View (T));
16431 -- Scalar types are potentially persistent
16433 elsif Is_Scalar_Type (T) then
16434 return True;
16436 -- Record type is potentially persistent if not tagged and the types of
16437 -- all it components are potentially persistent, and no component has
16438 -- an initialization expression.
16440 elsif Is_Record_Type (T)
16441 and then not Is_Tagged_Type (T)
16442 and then not Is_Partially_Initialized_Type (T)
16443 then
16444 Comp := First_Component (T);
16445 while Present (Comp) loop
16446 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16447 return False;
16448 else
16449 Next_Entity (Comp);
16450 end if;
16451 end loop;
16453 return True;
16455 -- Array type is potentially persistent if its component type is
16456 -- potentially persistent and if all its constraints are static.
16458 elsif Is_Array_Type (T) then
16459 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
16460 return False;
16461 end if;
16463 Indx := First_Index (T);
16464 while Present (Indx) loop
16465 if not Is_OK_Static_Subtype (Etype (Indx)) then
16466 return False;
16467 else
16468 Next_Index (Indx);
16469 end if;
16470 end loop;
16472 return True;
16474 -- All other types are not potentially persistent
16476 else
16477 return False;
16478 end if;
16479 end Is_Potentially_Persistent_Type;
16481 --------------------------------
16482 -- Is_Potentially_Unevaluated --
16483 --------------------------------
16485 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
16486 Par : Node_Id;
16487 Expr : Node_Id;
16489 begin
16490 Expr := N;
16491 Par := N;
16493 -- A postcondition whose expression is a short-circuit is broken down
16494 -- into individual aspects for better exception reporting. The original
16495 -- short-circuit expression is rewritten as the second operand, and an
16496 -- occurrence of 'Old in that operand is potentially unevaluated.
16497 -- See sem_ch13.adb for details of this transformation. The reference
16498 -- to 'Old may appear within an expression, so we must look for the
16499 -- enclosing pragma argument in the tree that contains the reference.
16501 while Present (Par)
16502 and then Nkind (Par) /= N_Pragma_Argument_Association
16503 loop
16504 if Is_Rewrite_Substitution (Par)
16505 and then Nkind (Original_Node (Par)) = N_And_Then
16506 then
16507 return True;
16508 end if;
16510 Par := Parent (Par);
16511 end loop;
16513 -- Other cases; 'Old appears within other expression (not the top-level
16514 -- conjunct in a postcondition) with a potentially unevaluated operand.
16516 Par := Parent (Expr);
16517 while not Nkind_In (Par, N_And_Then,
16518 N_Case_Expression,
16519 N_If_Expression,
16520 N_In,
16521 N_Not_In,
16522 N_Or_Else,
16523 N_Quantified_Expression)
16524 loop
16525 Expr := Par;
16526 Par := Parent (Par);
16528 -- If the context is not an expression, or if is the result of
16529 -- expansion of an enclosing construct (such as another attribute)
16530 -- the predicate does not apply.
16532 if Nkind (Par) = N_Case_Expression_Alternative then
16533 null;
16535 elsif Nkind (Par) not in N_Subexpr
16536 or else not Comes_From_Source (Par)
16537 then
16538 return False;
16539 end if;
16540 end loop;
16542 if Nkind (Par) = N_If_Expression then
16543 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
16545 elsif Nkind (Par) = N_Case_Expression then
16546 return Expr /= Expression (Par);
16548 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
16549 return Expr = Right_Opnd (Par);
16551 elsif Nkind_In (Par, N_In, N_Not_In) then
16553 -- If the membership includes several alternatives, only the first is
16554 -- definitely evaluated.
16556 if Present (Alternatives (Par)) then
16557 return Expr /= First (Alternatives (Par));
16559 -- If this is a range membership both bounds are evaluated
16561 else
16562 return False;
16563 end if;
16565 elsif Nkind (Par) = N_Quantified_Expression then
16566 return Expr = Condition (Par);
16568 else
16569 return False;
16570 end if;
16571 end Is_Potentially_Unevaluated;
16573 -----------------------------------------
16574 -- Is_Predefined_Dispatching_Operation --
16575 -----------------------------------------
16577 function Is_Predefined_Dispatching_Operation
16578 (E : Entity_Id) return Boolean
16580 TSS_Name : TSS_Name_Type;
16582 begin
16583 if not Is_Dispatching_Operation (E) then
16584 return False;
16585 end if;
16587 Get_Name_String (Chars (E));
16589 -- Most predefined primitives have internally generated names. Equality
16590 -- must be treated differently; the predefined operation is recognized
16591 -- as a homogeneous binary operator that returns Boolean.
16593 if Name_Len > TSS_Name_Type'Last then
16594 TSS_Name :=
16595 TSS_Name_Type
16596 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16598 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
16599 or else
16600 (Chars (E) = Name_Op_Eq
16601 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16602 or else TSS_Name = TSS_Deep_Adjust
16603 or else TSS_Name = TSS_Deep_Finalize
16604 or else TSS_Name = TSS_Stream_Input
16605 or else TSS_Name = TSS_Stream_Output
16606 or else TSS_Name = TSS_Stream_Read
16607 or else TSS_Name = TSS_Stream_Write
16608 or else Is_Predefined_Interface_Primitive (E)
16609 then
16610 return True;
16611 end if;
16612 end if;
16614 return False;
16615 end Is_Predefined_Dispatching_Operation;
16617 ---------------------------------------
16618 -- Is_Predefined_Interface_Primitive --
16619 ---------------------------------------
16621 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
16622 begin
16623 -- In VM targets we don't restrict the functionality of this test to
16624 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16625 -- these primitives.
16627 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
16628 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
16629 Name_uDisp_Conditional_Select,
16630 Name_uDisp_Get_Prim_Op_Kind,
16631 Name_uDisp_Get_Task_Id,
16632 Name_uDisp_Requeue,
16633 Name_uDisp_Timed_Select);
16634 end Is_Predefined_Interface_Primitive;
16636 ---------------------------------------
16637 -- Is_Predefined_Internal_Operation --
16638 ---------------------------------------
16640 function Is_Predefined_Internal_Operation
16641 (E : Entity_Id) return Boolean
16643 TSS_Name : TSS_Name_Type;
16645 begin
16646 if not Is_Dispatching_Operation (E) then
16647 return False;
16648 end if;
16650 Get_Name_String (Chars (E));
16652 -- Most predefined primitives have internally generated names. Equality
16653 -- must be treated differently; the predefined operation is recognized
16654 -- as a homogeneous binary operator that returns Boolean.
16656 if Name_Len > TSS_Name_Type'Last then
16657 TSS_Name :=
16658 TSS_Name_Type
16659 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16661 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
16662 or else
16663 (Chars (E) = Name_Op_Eq
16664 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16665 or else TSS_Name = TSS_Deep_Adjust
16666 or else TSS_Name = TSS_Deep_Finalize
16667 or else Is_Predefined_Interface_Primitive (E)
16668 then
16669 return True;
16670 end if;
16671 end if;
16673 return False;
16674 end Is_Predefined_Internal_Operation;
16676 --------------------------------
16677 -- Is_Preelaborable_Aggregate --
16678 --------------------------------
16680 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
16681 Aggr_Typ : constant Entity_Id := Etype (Aggr);
16682 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
16684 Anc_Part : Node_Id;
16685 Assoc : Node_Id;
16686 Choice : Node_Id;
16687 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
16688 Expr : Node_Id;
16690 begin
16691 if Array_Aggr then
16692 Comp_Typ := Component_Type (Aggr_Typ);
16693 end if;
16695 -- Inspect the ancestor part
16697 if Nkind (Aggr) = N_Extension_Aggregate then
16698 Anc_Part := Ancestor_Part (Aggr);
16700 -- The ancestor denotes a subtype mark
16702 if Is_Entity_Name (Anc_Part)
16703 and then Is_Type (Entity (Anc_Part))
16704 then
16705 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
16706 return False;
16707 end if;
16709 -- Otherwise the ancestor denotes an expression
16711 elsif not Is_Preelaborable_Construct (Anc_Part) then
16712 return False;
16713 end if;
16714 end if;
16716 -- Inspect the positional associations
16718 Expr := First (Expressions (Aggr));
16719 while Present (Expr) loop
16720 if not Is_Preelaborable_Construct (Expr) then
16721 return False;
16722 end if;
16724 Next (Expr);
16725 end loop;
16727 -- Inspect the named associations
16729 Assoc := First (Component_Associations (Aggr));
16730 while Present (Assoc) loop
16732 -- Inspect the choices of the current named association
16734 Choice := First (Choices (Assoc));
16735 while Present (Choice) loop
16736 if Array_Aggr then
16738 -- For a choice to be preelaborable, it must denote either a
16739 -- static range or a static expression.
16741 if Nkind (Choice) = N_Others_Choice then
16742 null;
16744 elsif Nkind (Choice) = N_Range then
16745 if not Is_OK_Static_Range (Choice) then
16746 return False;
16747 end if;
16749 elsif not Is_OK_Static_Expression (Choice) then
16750 return False;
16751 end if;
16753 else
16754 Comp_Typ := Etype (Choice);
16755 end if;
16757 Next (Choice);
16758 end loop;
16760 -- The type of the choice must have preelaborable initialization if
16761 -- the association carries a <>.
16763 pragma Assert (Present (Comp_Typ));
16764 if Box_Present (Assoc) then
16765 if not Has_Preelaborable_Initialization (Comp_Typ) then
16766 return False;
16767 end if;
16769 -- The type of the expression must have preelaborable initialization
16771 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
16772 return False;
16773 end if;
16775 Next (Assoc);
16776 end loop;
16778 -- At this point the aggregate is preelaborable
16780 return True;
16781 end Is_Preelaborable_Aggregate;
16783 --------------------------------
16784 -- Is_Preelaborable_Construct --
16785 --------------------------------
16787 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
16788 begin
16789 -- Aggregates
16791 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
16792 return Is_Preelaborable_Aggregate (N);
16794 -- Attributes are allowed in general, even if their prefix is a formal
16795 -- type. It seems that certain attributes known not to be static might
16796 -- not be allowed, but there are no rules to prevent them.
16798 elsif Nkind (N) = N_Attribute_Reference then
16799 return True;
16801 -- Expressions
16803 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
16804 return True;
16806 elsif Nkind (N) = N_Qualified_Expression then
16807 return Is_Preelaborable_Construct (Expression (N));
16809 -- Names are preelaborable when they denote a discriminant of an
16810 -- enclosing type. Discriminals are also considered for this check.
16812 elsif Is_Entity_Name (N)
16813 and then Present (Entity (N))
16814 and then
16815 (Ekind (Entity (N)) = E_Discriminant
16816 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
16817 and then Present (Discriminal_Link (Entity (N)))))
16818 then
16819 return True;
16821 -- Statements
16823 elsif Nkind (N) = N_Null then
16824 return True;
16826 -- Otherwise the construct is not preelaborable
16828 else
16829 return False;
16830 end if;
16831 end Is_Preelaborable_Construct;
16833 ---------------------------------
16834 -- Is_Protected_Self_Reference --
16835 ---------------------------------
16837 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
16839 function In_Access_Definition (N : Node_Id) return Boolean;
16840 -- Returns true if N belongs to an access definition
16842 --------------------------
16843 -- In_Access_Definition --
16844 --------------------------
16846 function In_Access_Definition (N : Node_Id) return Boolean is
16847 P : Node_Id;
16849 begin
16850 P := Parent (N);
16851 while Present (P) loop
16852 if Nkind (P) = N_Access_Definition then
16853 return True;
16854 end if;
16856 P := Parent (P);
16857 end loop;
16859 return False;
16860 end In_Access_Definition;
16862 -- Start of processing for Is_Protected_Self_Reference
16864 begin
16865 -- Verify that prefix is analyzed and has the proper form. Note that
16866 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
16867 -- produce the address of an entity, do not analyze their prefix
16868 -- because they denote entities that are not necessarily visible.
16869 -- Neither of them can apply to a protected type.
16871 return Ada_Version >= Ada_2005
16872 and then Is_Entity_Name (N)
16873 and then Present (Entity (N))
16874 and then Is_Protected_Type (Entity (N))
16875 and then In_Open_Scopes (Entity (N))
16876 and then not In_Access_Definition (N);
16877 end Is_Protected_Self_Reference;
16879 -----------------------------
16880 -- Is_RCI_Pkg_Spec_Or_Body --
16881 -----------------------------
16883 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
16885 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
16886 -- Return True if the unit of Cunit is an RCI package declaration
16888 ---------------------------
16889 -- Is_RCI_Pkg_Decl_Cunit --
16890 ---------------------------
16892 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
16893 The_Unit : constant Node_Id := Unit (Cunit);
16895 begin
16896 if Nkind (The_Unit) /= N_Package_Declaration then
16897 return False;
16898 end if;
16900 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
16901 end Is_RCI_Pkg_Decl_Cunit;
16903 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
16905 begin
16906 return Is_RCI_Pkg_Decl_Cunit (Cunit)
16907 or else
16908 (Nkind (Unit (Cunit)) = N_Package_Body
16909 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
16910 end Is_RCI_Pkg_Spec_Or_Body;
16912 -----------------------------------------
16913 -- Is_Remote_Access_To_Class_Wide_Type --
16914 -----------------------------------------
16916 function Is_Remote_Access_To_Class_Wide_Type
16917 (E : Entity_Id) return Boolean
16919 begin
16920 -- A remote access to class-wide type is a general access to object type
16921 -- declared in the visible part of a Remote_Types or Remote_Call_
16922 -- Interface unit.
16924 return Ekind (E) = E_General_Access_Type
16925 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16926 end Is_Remote_Access_To_Class_Wide_Type;
16928 -----------------------------------------
16929 -- Is_Remote_Access_To_Subprogram_Type --
16930 -----------------------------------------
16932 function Is_Remote_Access_To_Subprogram_Type
16933 (E : Entity_Id) return Boolean
16935 begin
16936 return (Ekind (E) = E_Access_Subprogram_Type
16937 or else (Ekind (E) = E_Record_Type
16938 and then Present (Corresponding_Remote_Type (E))))
16939 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16940 end Is_Remote_Access_To_Subprogram_Type;
16942 --------------------
16943 -- Is_Remote_Call --
16944 --------------------
16946 function Is_Remote_Call (N : Node_Id) return Boolean is
16947 begin
16948 if Nkind (N) not in N_Subprogram_Call then
16950 -- An entry call cannot be remote
16952 return False;
16954 elsif Nkind (Name (N)) in N_Has_Entity
16955 and then Is_Remote_Call_Interface (Entity (Name (N)))
16956 then
16957 -- A subprogram declared in the spec of a RCI package is remote
16959 return True;
16961 elsif Nkind (Name (N)) = N_Explicit_Dereference
16962 and then Is_Remote_Access_To_Subprogram_Type
16963 (Etype (Prefix (Name (N))))
16964 then
16965 -- The dereference of a RAS is a remote call
16967 return True;
16969 elsif Present (Controlling_Argument (N))
16970 and then Is_Remote_Access_To_Class_Wide_Type
16971 (Etype (Controlling_Argument (N)))
16972 then
16973 -- Any primitive operation call with a controlling argument of
16974 -- a RACW type is a remote call.
16976 return True;
16977 end if;
16979 -- All other calls are local calls
16981 return False;
16982 end Is_Remote_Call;
16984 ----------------------
16985 -- Is_Renamed_Entry --
16986 ----------------------
16988 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
16989 Orig_Node : Node_Id := Empty;
16990 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
16992 function Is_Entry (Nam : Node_Id) return Boolean;
16993 -- Determine whether Nam is an entry. Traverse selectors if there are
16994 -- nested selected components.
16996 --------------
16997 -- Is_Entry --
16998 --------------
17000 function Is_Entry (Nam : Node_Id) return Boolean is
17001 begin
17002 if Nkind (Nam) = N_Selected_Component then
17003 return Is_Entry (Selector_Name (Nam));
17004 end if;
17006 return Ekind (Entity (Nam)) = E_Entry;
17007 end Is_Entry;
17009 -- Start of processing for Is_Renamed_Entry
17011 begin
17012 if Present (Alias (Proc_Nam)) then
17013 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
17014 end if;
17016 -- Look for a rewritten subprogram renaming declaration
17018 if Nkind (Subp_Decl) = N_Subprogram_Declaration
17019 and then Present (Original_Node (Subp_Decl))
17020 then
17021 Orig_Node := Original_Node (Subp_Decl);
17022 end if;
17024 -- The rewritten subprogram is actually an entry
17026 if Present (Orig_Node)
17027 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
17028 and then Is_Entry (Name (Orig_Node))
17029 then
17030 return True;
17031 end if;
17033 return False;
17034 end Is_Renamed_Entry;
17036 -----------------------------
17037 -- Is_Renaming_Declaration --
17038 -----------------------------
17040 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
17041 begin
17042 case Nkind (N) is
17043 when N_Exception_Renaming_Declaration
17044 | N_Generic_Function_Renaming_Declaration
17045 | N_Generic_Package_Renaming_Declaration
17046 | N_Generic_Procedure_Renaming_Declaration
17047 | N_Object_Renaming_Declaration
17048 | N_Package_Renaming_Declaration
17049 | N_Subprogram_Renaming_Declaration
17051 return True;
17053 when others =>
17054 return False;
17055 end case;
17056 end Is_Renaming_Declaration;
17058 ----------------------------
17059 -- Is_Reversible_Iterator --
17060 ----------------------------
17062 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
17063 Ifaces_List : Elist_Id;
17064 Iface_Elmt : Elmt_Id;
17065 Iface : Entity_Id;
17067 begin
17068 if Is_Class_Wide_Type (Typ)
17069 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
17070 and then In_Predefined_Unit (Root_Type (Typ))
17071 then
17072 return True;
17074 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17075 return False;
17077 else
17078 Collect_Interfaces (Typ, Ifaces_List);
17080 Iface_Elmt := First_Elmt (Ifaces_List);
17081 while Present (Iface_Elmt) loop
17082 Iface := Node (Iface_Elmt);
17083 if Chars (Iface) = Name_Reversible_Iterator
17084 and then In_Predefined_Unit (Iface)
17085 then
17086 return True;
17087 end if;
17089 Next_Elmt (Iface_Elmt);
17090 end loop;
17091 end if;
17093 return False;
17094 end Is_Reversible_Iterator;
17096 ----------------------
17097 -- Is_Selector_Name --
17098 ----------------------
17100 function Is_Selector_Name (N : Node_Id) return Boolean is
17101 begin
17102 if not Is_List_Member (N) then
17103 declare
17104 P : constant Node_Id := Parent (N);
17105 begin
17106 return Nkind_In (P, N_Expanded_Name,
17107 N_Generic_Association,
17108 N_Parameter_Association,
17109 N_Selected_Component)
17110 and then Selector_Name (P) = N;
17111 end;
17113 else
17114 declare
17115 L : constant List_Id := List_Containing (N);
17116 P : constant Node_Id := Parent (L);
17117 begin
17118 return (Nkind (P) = N_Discriminant_Association
17119 and then Selector_Names (P) = L)
17120 or else
17121 (Nkind (P) = N_Component_Association
17122 and then Choices (P) = L);
17123 end;
17124 end if;
17125 end Is_Selector_Name;
17127 ---------------------------------
17128 -- Is_Single_Concurrent_Object --
17129 ---------------------------------
17131 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
17132 begin
17133 return
17134 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
17135 end Is_Single_Concurrent_Object;
17137 -------------------------------
17138 -- Is_Single_Concurrent_Type --
17139 -------------------------------
17141 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
17142 begin
17143 return
17144 Ekind_In (Id, E_Protected_Type, E_Task_Type)
17145 and then Is_Single_Concurrent_Type_Declaration
17146 (Declaration_Node (Id));
17147 end Is_Single_Concurrent_Type;
17149 -------------------------------------------
17150 -- Is_Single_Concurrent_Type_Declaration --
17151 -------------------------------------------
17153 function Is_Single_Concurrent_Type_Declaration
17154 (N : Node_Id) return Boolean
17156 begin
17157 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
17158 N_Single_Task_Declaration);
17159 end Is_Single_Concurrent_Type_Declaration;
17161 ---------------------------------------------
17162 -- Is_Single_Precision_Floating_Point_Type --
17163 ---------------------------------------------
17165 function Is_Single_Precision_Floating_Point_Type
17166 (E : Entity_Id) return Boolean is
17167 begin
17168 return Is_Floating_Point_Type (E)
17169 and then Machine_Radix_Value (E) = Uint_2
17170 and then Machine_Mantissa_Value (E) = Uint_24
17171 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
17172 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
17173 end Is_Single_Precision_Floating_Point_Type;
17175 --------------------------------
17176 -- Is_Single_Protected_Object --
17177 --------------------------------
17179 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
17180 begin
17181 return
17182 Ekind (Id) = E_Variable
17183 and then Ekind (Etype (Id)) = E_Protected_Type
17184 and then Is_Single_Concurrent_Type (Etype (Id));
17185 end Is_Single_Protected_Object;
17187 ---------------------------
17188 -- Is_Single_Task_Object --
17189 ---------------------------
17191 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
17192 begin
17193 return
17194 Ekind (Id) = E_Variable
17195 and then Ekind (Etype (Id)) = E_Task_Type
17196 and then Is_Single_Concurrent_Type (Etype (Id));
17197 end Is_Single_Task_Object;
17199 -------------------------------------
17200 -- Is_SPARK_05_Initialization_Expr --
17201 -------------------------------------
17203 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
17204 Is_Ok : Boolean;
17205 Expr : Node_Id;
17206 Comp_Assn : Node_Id;
17207 Orig_N : constant Node_Id := Original_Node (N);
17209 begin
17210 Is_Ok := True;
17212 if not Comes_From_Source (Orig_N) then
17213 goto Done;
17214 end if;
17216 pragma Assert (Nkind (Orig_N) in N_Subexpr);
17218 case Nkind (Orig_N) is
17219 when N_Character_Literal
17220 | N_Integer_Literal
17221 | N_Real_Literal
17222 | N_String_Literal
17224 null;
17226 when N_Expanded_Name
17227 | N_Identifier
17229 if Is_Entity_Name (Orig_N)
17230 and then Present (Entity (Orig_N)) -- needed in some cases
17231 then
17232 case Ekind (Entity (Orig_N)) is
17233 when E_Constant
17234 | E_Enumeration_Literal
17235 | E_Named_Integer
17236 | E_Named_Real
17238 null;
17240 when others =>
17241 if Is_Type (Entity (Orig_N)) then
17242 null;
17243 else
17244 Is_Ok := False;
17245 end if;
17246 end case;
17247 end if;
17249 when N_Qualified_Expression
17250 | N_Type_Conversion
17252 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17254 when N_Unary_Op =>
17255 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17257 when N_Binary_Op
17258 | N_Membership_Test
17259 | N_Short_Circuit
17261 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17262 and then
17263 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17265 when N_Aggregate
17266 | N_Extension_Aggregate
17268 if Nkind (Orig_N) = N_Extension_Aggregate then
17269 Is_Ok :=
17270 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17271 end if;
17273 Expr := First (Expressions (Orig_N));
17274 while Present (Expr) loop
17275 if not Is_SPARK_05_Initialization_Expr (Expr) then
17276 Is_Ok := False;
17277 goto Done;
17278 end if;
17280 Next (Expr);
17281 end loop;
17283 Comp_Assn := First (Component_Associations (Orig_N));
17284 while Present (Comp_Assn) loop
17285 Expr := Expression (Comp_Assn);
17287 -- Note: test for Present here needed for box assocation
17289 if Present (Expr)
17290 and then not Is_SPARK_05_Initialization_Expr (Expr)
17291 then
17292 Is_Ok := False;
17293 goto Done;
17294 end if;
17296 Next (Comp_Assn);
17297 end loop;
17299 when N_Attribute_Reference =>
17300 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17301 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17302 end if;
17304 Expr := First (Expressions (Orig_N));
17305 while Present (Expr) loop
17306 if not Is_SPARK_05_Initialization_Expr (Expr) then
17307 Is_Ok := False;
17308 goto Done;
17309 end if;
17311 Next (Expr);
17312 end loop;
17314 -- Selected components might be expanded named not yet resolved, so
17315 -- default on the safe side. (Eg on sparklex.ads)
17317 when N_Selected_Component =>
17318 null;
17320 when others =>
17321 Is_Ok := False;
17322 end case;
17324 <<Done>>
17325 return Is_Ok;
17326 end Is_SPARK_05_Initialization_Expr;
17328 ----------------------------------
17329 -- Is_SPARK_05_Object_Reference --
17330 ----------------------------------
17332 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17333 begin
17334 if Is_Entity_Name (N) then
17335 return Present (Entity (N))
17336 and then
17337 (Ekind_In (Entity (N), E_Constant, E_Variable)
17338 or else Ekind (Entity (N)) in Formal_Kind);
17340 else
17341 case Nkind (N) is
17342 when N_Selected_Component =>
17343 return Is_SPARK_05_Object_Reference (Prefix (N));
17345 when others =>
17346 return False;
17347 end case;
17348 end if;
17349 end Is_SPARK_05_Object_Reference;
17351 -----------------------------
17352 -- Is_Specific_Tagged_Type --
17353 -----------------------------
17355 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17356 Full_Typ : Entity_Id;
17358 begin
17359 -- Handle private types
17361 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17362 Full_Typ := Full_View (Typ);
17363 else
17364 Full_Typ := Typ;
17365 end if;
17367 -- A specific tagged type is a non-class-wide tagged type
17369 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17370 end Is_Specific_Tagged_Type;
17372 ------------------
17373 -- Is_Statement --
17374 ------------------
17376 function Is_Statement (N : Node_Id) return Boolean is
17377 begin
17378 return
17379 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17380 or else Nkind (N) = N_Procedure_Call_Statement;
17381 end Is_Statement;
17383 ---------------------------------------
17384 -- Is_Subprogram_Contract_Annotation --
17385 ---------------------------------------
17387 function Is_Subprogram_Contract_Annotation
17388 (Item : Node_Id) return Boolean
17390 Nam : Name_Id;
17392 begin
17393 if Nkind (Item) = N_Aspect_Specification then
17394 Nam := Chars (Identifier (Item));
17396 else pragma Assert (Nkind (Item) = N_Pragma);
17397 Nam := Pragma_Name (Item);
17398 end if;
17400 return Nam = Name_Contract_Cases
17401 or else Nam = Name_Depends
17402 or else Nam = Name_Extensions_Visible
17403 or else Nam = Name_Global
17404 or else Nam = Name_Post
17405 or else Nam = Name_Post_Class
17406 or else Nam = Name_Postcondition
17407 or else Nam = Name_Pre
17408 or else Nam = Name_Pre_Class
17409 or else Nam = Name_Precondition
17410 or else Nam = Name_Refined_Depends
17411 or else Nam = Name_Refined_Global
17412 or else Nam = Name_Refined_Post
17413 or else Nam = Name_Test_Case;
17414 end Is_Subprogram_Contract_Annotation;
17416 --------------------------------------------------
17417 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17418 --------------------------------------------------
17420 function Is_Subprogram_Stub_Without_Prior_Declaration
17421 (N : Node_Id) return Boolean
17423 begin
17424 -- A subprogram stub without prior declaration serves as declaration for
17425 -- the actual subprogram body. As such, it has an attached defining
17426 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
17428 return Nkind (N) = N_Subprogram_Body_Stub
17429 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
17430 end Is_Subprogram_Stub_Without_Prior_Declaration;
17432 ---------------------------
17433 -- Is_Suitable_Primitive --
17434 ---------------------------
17436 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
17437 begin
17438 -- The Default_Initial_Condition and invariant procedures must not be
17439 -- treated as primitive operations even when they apply to a tagged
17440 -- type. These routines must not act as targets of dispatching calls
17441 -- because they already utilize class-wide-precondition semantics to
17442 -- handle inheritance and overriding.
17444 if Ekind (Subp_Id) = E_Procedure
17445 and then (Is_DIC_Procedure (Subp_Id)
17446 or else
17447 Is_Invariant_Procedure (Subp_Id))
17448 then
17449 return False;
17450 end if;
17452 return True;
17453 end Is_Suitable_Primitive;
17455 --------------------------
17456 -- Is_Suspension_Object --
17457 --------------------------
17459 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
17460 begin
17461 -- This approach does an exact name match rather than to rely on
17462 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17463 -- front end at point where all auxiliary tables are locked and any
17464 -- modifications to them are treated as violations. Do not tamper with
17465 -- the tables, instead examine the Chars fields of all the scopes of Id.
17467 return
17468 Chars (Id) = Name_Suspension_Object
17469 and then Present (Scope (Id))
17470 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
17471 and then Present (Scope (Scope (Id)))
17472 and then Chars (Scope (Scope (Id))) = Name_Ada
17473 and then Present (Scope (Scope (Scope (Id))))
17474 and then Scope (Scope (Scope (Id))) = Standard_Standard;
17475 end Is_Suspension_Object;
17477 ----------------------------
17478 -- Is_Synchronized_Object --
17479 ----------------------------
17481 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
17482 Prag : Node_Id;
17484 begin
17485 if Is_Object (Id) then
17487 -- The object is synchronized if it is of a type that yields a
17488 -- synchronized object.
17490 if Yields_Synchronized_Object (Etype (Id)) then
17491 return True;
17493 -- The object is synchronized if it is atomic and Async_Writers is
17494 -- enabled.
17496 elsif Is_Atomic_Object_Entity (Id)
17497 and then Async_Writers_Enabled (Id)
17498 then
17499 return True;
17501 -- A constant is a synchronized object by default
17503 elsif Ekind (Id) = E_Constant then
17504 return True;
17506 -- A variable is a synchronized object if it is subject to pragma
17507 -- Constant_After_Elaboration.
17509 elsif Ekind (Id) = E_Variable then
17510 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
17512 return Present (Prag) and then Is_Enabled_Pragma (Prag);
17513 end if;
17514 end if;
17516 -- Otherwise the input is not an object or it does not qualify as a
17517 -- synchronized object.
17519 return False;
17520 end Is_Synchronized_Object;
17522 ---------------------------------
17523 -- Is_Synchronized_Tagged_Type --
17524 ---------------------------------
17526 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
17527 Kind : constant Entity_Kind := Ekind (Base_Type (E));
17529 begin
17530 -- A task or protected type derived from an interface is a tagged type.
17531 -- Such a tagged type is called a synchronized tagged type, as are
17532 -- synchronized interfaces and private extensions whose declaration
17533 -- includes the reserved word synchronized.
17535 return (Is_Tagged_Type (E)
17536 and then (Kind = E_Task_Type
17537 or else
17538 Kind = E_Protected_Type))
17539 or else
17540 (Is_Interface (E)
17541 and then Is_Synchronized_Interface (E))
17542 or else
17543 (Ekind (E) = E_Record_Type_With_Private
17544 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
17545 and then (Synchronized_Present (Parent (E))
17546 or else Is_Synchronized_Interface (Etype (E))));
17547 end Is_Synchronized_Tagged_Type;
17549 -----------------
17550 -- Is_Transfer --
17551 -----------------
17553 function Is_Transfer (N : Node_Id) return Boolean is
17554 Kind : constant Node_Kind := Nkind (N);
17556 begin
17557 if Kind = N_Simple_Return_Statement
17558 or else
17559 Kind = N_Extended_Return_Statement
17560 or else
17561 Kind = N_Goto_Statement
17562 or else
17563 Kind = N_Raise_Statement
17564 or else
17565 Kind = N_Requeue_Statement
17566 then
17567 return True;
17569 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
17570 and then No (Condition (N))
17571 then
17572 return True;
17574 elsif Kind = N_Procedure_Call_Statement
17575 and then Is_Entity_Name (Name (N))
17576 and then Present (Entity (Name (N)))
17577 and then No_Return (Entity (Name (N)))
17578 then
17579 return True;
17581 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
17582 return True;
17584 else
17585 return False;
17586 end if;
17587 end Is_Transfer;
17589 -------------
17590 -- Is_True --
17591 -------------
17593 function Is_True (U : Uint) return Boolean is
17594 begin
17595 return (U /= 0);
17596 end Is_True;
17598 --------------------------------------
17599 -- Is_Unchecked_Conversion_Instance --
17600 --------------------------------------
17602 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
17603 Par : Node_Id;
17605 begin
17606 -- Look for a function whose generic parent is the predefined intrinsic
17607 -- function Unchecked_Conversion, or for one that renames such an
17608 -- instance.
17610 if Ekind (Id) = E_Function then
17611 Par := Parent (Id);
17613 if Nkind (Par) = N_Function_Specification then
17614 Par := Generic_Parent (Par);
17616 if Present (Par) then
17617 return
17618 Chars (Par) = Name_Unchecked_Conversion
17619 and then Is_Intrinsic_Subprogram (Par)
17620 and then In_Predefined_Unit (Par);
17621 else
17622 return
17623 Present (Alias (Id))
17624 and then Is_Unchecked_Conversion_Instance (Alias (Id));
17625 end if;
17626 end if;
17627 end if;
17629 return False;
17630 end Is_Unchecked_Conversion_Instance;
17632 -------------------------------
17633 -- Is_Universal_Numeric_Type --
17634 -------------------------------
17636 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
17637 begin
17638 return T = Universal_Integer or else T = Universal_Real;
17639 end Is_Universal_Numeric_Type;
17641 ------------------------------
17642 -- Is_User_Defined_Equality --
17643 ------------------------------
17645 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
17646 begin
17647 return Ekind (Id) = E_Function
17648 and then Chars (Id) = Name_Op_Eq
17649 and then Comes_From_Source (Id)
17651 -- Internally generated equalities have a full type declaration
17652 -- as their parent.
17654 and then Nkind (Parent (Id)) = N_Function_Specification;
17655 end Is_User_Defined_Equality;
17657 --------------------------------------
17658 -- Is_Validation_Variable_Reference --
17659 --------------------------------------
17661 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
17662 Var : constant Node_Id := Unqual_Conv (N);
17663 Var_Id : Entity_Id;
17665 begin
17666 Var_Id := Empty;
17668 if Is_Entity_Name (Var) then
17669 Var_Id := Entity (Var);
17670 end if;
17672 return
17673 Present (Var_Id)
17674 and then Ekind (Var_Id) = E_Variable
17675 and then Present (Validated_Object (Var_Id));
17676 end Is_Validation_Variable_Reference;
17678 ----------------------------
17679 -- Is_Variable_Size_Array --
17680 ----------------------------
17682 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
17683 Idx : Node_Id;
17685 begin
17686 pragma Assert (Is_Array_Type (E));
17688 -- Check if some index is initialized with a non-constant value
17690 Idx := First_Index (E);
17691 while Present (Idx) loop
17692 if Nkind (Idx) = N_Range then
17693 if not Is_Constant_Bound (Low_Bound (Idx))
17694 or else not Is_Constant_Bound (High_Bound (Idx))
17695 then
17696 return True;
17697 end if;
17698 end if;
17700 Idx := Next_Index (Idx);
17701 end loop;
17703 return False;
17704 end Is_Variable_Size_Array;
17706 -----------------------------
17707 -- Is_Variable_Size_Record --
17708 -----------------------------
17710 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
17711 Comp : Entity_Id;
17712 Comp_Typ : Entity_Id;
17714 begin
17715 pragma Assert (Is_Record_Type (E));
17717 Comp := First_Entity (E);
17718 while Present (Comp) loop
17719 Comp_Typ := Etype (Comp);
17721 -- Recursive call if the record type has discriminants
17723 if Is_Record_Type (Comp_Typ)
17724 and then Has_Discriminants (Comp_Typ)
17725 and then Is_Variable_Size_Record (Comp_Typ)
17726 then
17727 return True;
17729 elsif Is_Array_Type (Comp_Typ)
17730 and then Is_Variable_Size_Array (Comp_Typ)
17731 then
17732 return True;
17733 end if;
17735 Next_Entity (Comp);
17736 end loop;
17738 return False;
17739 end Is_Variable_Size_Record;
17741 -----------------
17742 -- Is_Variable --
17743 -----------------
17745 function Is_Variable
17746 (N : Node_Id;
17747 Use_Original_Node : Boolean := True) return Boolean
17749 Orig_Node : Node_Id;
17751 function In_Protected_Function (E : Entity_Id) return Boolean;
17752 -- Within a protected function, the private components of the enclosing
17753 -- protected type are constants. A function nested within a (protected)
17754 -- procedure is not itself protected. Within the body of a protected
17755 -- function the current instance of the protected type is a constant.
17757 function Is_Variable_Prefix (P : Node_Id) return Boolean;
17758 -- Prefixes can involve implicit dereferences, in which case we must
17759 -- test for the case of a reference of a constant access type, which can
17760 -- can never be a variable.
17762 ---------------------------
17763 -- In_Protected_Function --
17764 ---------------------------
17766 function In_Protected_Function (E : Entity_Id) return Boolean is
17767 Prot : Entity_Id;
17768 S : Entity_Id;
17770 begin
17771 -- E is the current instance of a type
17773 if Is_Type (E) then
17774 Prot := E;
17776 -- E is an object
17778 else
17779 Prot := Scope (E);
17780 end if;
17782 if not Is_Protected_Type (Prot) then
17783 return False;
17785 else
17786 S := Current_Scope;
17787 while Present (S) and then S /= Prot loop
17788 if Ekind (S) = E_Function and then Scope (S) = Prot then
17789 return True;
17790 end if;
17792 S := Scope (S);
17793 end loop;
17795 return False;
17796 end if;
17797 end In_Protected_Function;
17799 ------------------------
17800 -- Is_Variable_Prefix --
17801 ------------------------
17803 function Is_Variable_Prefix (P : Node_Id) return Boolean is
17804 begin
17805 if Is_Access_Type (Etype (P)) then
17806 return not Is_Access_Constant (Root_Type (Etype (P)));
17808 -- For the case of an indexed component whose prefix has a packed
17809 -- array type, the prefix has been rewritten into a type conversion.
17810 -- Determine variable-ness from the converted expression.
17812 elsif Nkind (P) = N_Type_Conversion
17813 and then not Comes_From_Source (P)
17814 and then Is_Array_Type (Etype (P))
17815 and then Is_Packed (Etype (P))
17816 then
17817 return Is_Variable (Expression (P));
17819 else
17820 return Is_Variable (P);
17821 end if;
17822 end Is_Variable_Prefix;
17824 -- Start of processing for Is_Variable
17826 begin
17827 -- Special check, allow x'Deref(expr) as a variable
17829 if Nkind (N) = N_Attribute_Reference
17830 and then Attribute_Name (N) = Name_Deref
17831 then
17832 return True;
17833 end if;
17835 -- Check if we perform the test on the original node since this may be a
17836 -- test of syntactic categories which must not be disturbed by whatever
17837 -- rewriting might have occurred. For example, an aggregate, which is
17838 -- certainly NOT a variable, could be turned into a variable by
17839 -- expansion.
17841 if Use_Original_Node then
17842 Orig_Node := Original_Node (N);
17843 else
17844 Orig_Node := N;
17845 end if;
17847 -- Definitely OK if Assignment_OK is set. Since this is something that
17848 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
17850 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
17851 return True;
17853 -- Normally we go to the original node, but there is one exception where
17854 -- we use the rewritten node, namely when it is an explicit dereference.
17855 -- The generated code may rewrite a prefix which is an access type with
17856 -- an explicit dereference. The dereference is a variable, even though
17857 -- the original node may not be (since it could be a constant of the
17858 -- access type).
17860 -- In Ada 2005 we have a further case to consider: the prefix may be a
17861 -- function call given in prefix notation. The original node appears to
17862 -- be a selected component, but we need to examine the call.
17864 elsif Nkind (N) = N_Explicit_Dereference
17865 and then Nkind (Orig_Node) /= N_Explicit_Dereference
17866 and then Present (Etype (Orig_Node))
17867 and then Is_Access_Type (Etype (Orig_Node))
17868 then
17869 -- Note that if the prefix is an explicit dereference that does not
17870 -- come from source, we must check for a rewritten function call in
17871 -- prefixed notation before other forms of rewriting, to prevent a
17872 -- compiler crash.
17874 return
17875 (Nkind (Orig_Node) = N_Function_Call
17876 and then not Is_Access_Constant (Etype (Prefix (N))))
17877 or else
17878 Is_Variable_Prefix (Original_Node (Prefix (N)));
17880 -- in Ada 2012, the dereference may have been added for a type with
17881 -- a declared implicit dereference aspect. Check that it is not an
17882 -- access to constant.
17884 elsif Nkind (N) = N_Explicit_Dereference
17885 and then Present (Etype (Orig_Node))
17886 and then Ada_Version >= Ada_2012
17887 and then Has_Implicit_Dereference (Etype (Orig_Node))
17888 then
17889 return not Is_Access_Constant (Etype (Prefix (N)));
17891 -- A function call is never a variable
17893 elsif Nkind (N) = N_Function_Call then
17894 return False;
17896 -- All remaining checks use the original node
17898 elsif Is_Entity_Name (Orig_Node)
17899 and then Present (Entity (Orig_Node))
17900 then
17901 declare
17902 E : constant Entity_Id := Entity (Orig_Node);
17903 K : constant Entity_Kind := Ekind (E);
17905 begin
17906 if Is_Loop_Parameter (E) then
17907 return False;
17908 end if;
17910 return (K = E_Variable
17911 and then Nkind (Parent (E)) /= N_Exception_Handler)
17912 or else (K = E_Component
17913 and then not In_Protected_Function (E))
17914 or else K = E_Out_Parameter
17915 or else K = E_In_Out_Parameter
17916 or else K = E_Generic_In_Out_Parameter
17918 -- Current instance of type. If this is a protected type, check
17919 -- we are not within the body of one of its protected functions.
17921 or else (Is_Type (E)
17922 and then In_Open_Scopes (E)
17923 and then not In_Protected_Function (E))
17925 or else (Is_Incomplete_Or_Private_Type (E)
17926 and then In_Open_Scopes (Full_View (E)));
17927 end;
17929 else
17930 case Nkind (Orig_Node) is
17931 when N_Indexed_Component
17932 | N_Slice
17934 return Is_Variable_Prefix (Prefix (Orig_Node));
17936 when N_Selected_Component =>
17937 return (Is_Variable (Selector_Name (Orig_Node))
17938 and then Is_Variable_Prefix (Prefix (Orig_Node)))
17939 or else
17940 (Nkind (N) = N_Expanded_Name
17941 and then Scope (Entity (N)) = Entity (Prefix (N)));
17943 -- For an explicit dereference, the type of the prefix cannot
17944 -- be an access to constant or an access to subprogram.
17946 when N_Explicit_Dereference =>
17947 declare
17948 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
17949 begin
17950 return Is_Access_Type (Typ)
17951 and then not Is_Access_Constant (Root_Type (Typ))
17952 and then Ekind (Typ) /= E_Access_Subprogram_Type;
17953 end;
17955 -- The type conversion is the case where we do not deal with the
17956 -- context dependent special case of an actual parameter. Thus
17957 -- the type conversion is only considered a variable for the
17958 -- purposes of this routine if the target type is tagged. However,
17959 -- a type conversion is considered to be a variable if it does not
17960 -- come from source (this deals for example with the conversions
17961 -- of expressions to their actual subtypes).
17963 when N_Type_Conversion =>
17964 return Is_Variable (Expression (Orig_Node))
17965 and then
17966 (not Comes_From_Source (Orig_Node)
17967 or else
17968 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
17969 and then
17970 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
17972 -- GNAT allows an unchecked type conversion as a variable. This
17973 -- only affects the generation of internal expanded code, since
17974 -- calls to instantiations of Unchecked_Conversion are never
17975 -- considered variables (since they are function calls).
17977 when N_Unchecked_Type_Conversion =>
17978 return Is_Variable (Expression (Orig_Node));
17980 when others =>
17981 return False;
17982 end case;
17983 end if;
17984 end Is_Variable;
17986 ---------------------------
17987 -- Is_Visibly_Controlled --
17988 ---------------------------
17990 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
17991 Root : constant Entity_Id := Root_Type (T);
17992 begin
17993 return Chars (Scope (Root)) = Name_Finalization
17994 and then Chars (Scope (Scope (Root))) = Name_Ada
17995 and then Scope (Scope (Scope (Root))) = Standard_Standard;
17996 end Is_Visibly_Controlled;
17998 --------------------------
17999 -- Is_Volatile_Function --
18000 --------------------------
18002 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
18003 begin
18004 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
18006 -- A function declared within a protected type is volatile
18008 if Is_Protected_Type (Scope (Func_Id)) then
18009 return True;
18011 -- An instance of Ada.Unchecked_Conversion is a volatile function if
18012 -- either the source or the target are effectively volatile.
18014 elsif Is_Unchecked_Conversion_Instance (Func_Id)
18015 and then Has_Effectively_Volatile_Profile (Func_Id)
18016 then
18017 return True;
18019 -- Otherwise the function is treated as volatile if it is subject to
18020 -- enabled pragma Volatile_Function.
18022 else
18023 return
18024 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
18025 end if;
18026 end Is_Volatile_Function;
18028 ------------------------
18029 -- Is_Volatile_Object --
18030 ------------------------
18032 function Is_Volatile_Object (N : Node_Id) return Boolean is
18033 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
18034 -- If prefix is an implicit dereference, examine designated type
18036 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
18037 -- Determines if given object has volatile components
18039 ------------------------
18040 -- Is_Volatile_Prefix --
18041 ------------------------
18043 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
18044 Typ : constant Entity_Id := Etype (N);
18046 begin
18047 if Is_Access_Type (Typ) then
18048 declare
18049 Dtyp : constant Entity_Id := Designated_Type (Typ);
18051 begin
18052 return Is_Volatile (Dtyp)
18053 or else Has_Volatile_Components (Dtyp);
18054 end;
18056 else
18057 return Object_Has_Volatile_Components (N);
18058 end if;
18059 end Is_Volatile_Prefix;
18061 ------------------------------------
18062 -- Object_Has_Volatile_Components --
18063 ------------------------------------
18065 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
18066 Typ : constant Entity_Id := Etype (N);
18068 begin
18069 if Is_Volatile (Typ)
18070 or else Has_Volatile_Components (Typ)
18071 then
18072 return True;
18074 elsif Is_Entity_Name (N)
18075 and then (Has_Volatile_Components (Entity (N))
18076 or else Is_Volatile (Entity (N)))
18077 then
18078 return True;
18080 elsif Nkind (N) = N_Indexed_Component
18081 or else Nkind (N) = N_Selected_Component
18082 then
18083 return Is_Volatile_Prefix (Prefix (N));
18085 else
18086 return False;
18087 end if;
18088 end Object_Has_Volatile_Components;
18090 -- Start of processing for Is_Volatile_Object
18092 begin
18093 if Nkind (N) = N_Defining_Identifier then
18094 return Is_Volatile (N) or else Is_Volatile (Etype (N));
18096 elsif Nkind (N) = N_Expanded_Name then
18097 return Is_Volatile_Object (Entity (N));
18099 elsif Is_Volatile (Etype (N))
18100 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
18101 then
18102 return True;
18104 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
18105 and then Is_Volatile_Prefix (Prefix (N))
18106 then
18107 return True;
18109 elsif Nkind (N) = N_Selected_Component
18110 and then Is_Volatile (Entity (Selector_Name (N)))
18111 then
18112 return True;
18114 else
18115 return False;
18116 end if;
18117 end Is_Volatile_Object;
18119 -----------------------------
18120 -- Iterate_Call_Parameters --
18121 -----------------------------
18123 procedure Iterate_Call_Parameters (Call : Node_Id) is
18124 Actual : Node_Id := First_Actual (Call);
18125 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
18127 begin
18128 while Present (Formal) and then Present (Actual) loop
18129 Handle_Parameter (Formal, Actual);
18131 Next_Formal (Formal);
18132 Next_Actual (Actual);
18133 end loop;
18135 pragma Assert (No (Formal));
18136 pragma Assert (No (Actual));
18137 end Iterate_Call_Parameters;
18139 ---------------------------
18140 -- Itype_Has_Declaration --
18141 ---------------------------
18143 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
18144 begin
18145 pragma Assert (Is_Itype (Id));
18146 return Present (Parent (Id))
18147 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
18148 N_Subtype_Declaration)
18149 and then Defining_Entity (Parent (Id)) = Id;
18150 end Itype_Has_Declaration;
18152 -------------------------
18153 -- Kill_Current_Values --
18154 -------------------------
18156 procedure Kill_Current_Values
18157 (Ent : Entity_Id;
18158 Last_Assignment_Only : Boolean := False)
18160 begin
18161 if Is_Assignable (Ent) then
18162 Set_Last_Assignment (Ent, Empty);
18163 end if;
18165 if Is_Object (Ent) then
18166 if not Last_Assignment_Only then
18167 Kill_Checks (Ent);
18168 Set_Current_Value (Ent, Empty);
18170 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18171 -- for a constant. Once the constant is elaborated, its value is
18172 -- not changed, therefore the associated flags that describe the
18173 -- value should not be modified either.
18175 if Ekind (Ent) = E_Constant then
18176 null;
18178 -- Non-constant entities
18180 else
18181 if not Can_Never_Be_Null (Ent) then
18182 Set_Is_Known_Non_Null (Ent, False);
18183 end if;
18185 Set_Is_Known_Null (Ent, False);
18187 -- Reset the Is_Known_Valid flag unless the type is always
18188 -- valid. This does not apply to a loop parameter because its
18189 -- bounds are defined by the loop header and therefore always
18190 -- valid.
18192 if not Is_Known_Valid (Etype (Ent))
18193 and then Ekind (Ent) /= E_Loop_Parameter
18194 then
18195 Set_Is_Known_Valid (Ent, False);
18196 end if;
18197 end if;
18198 end if;
18199 end if;
18200 end Kill_Current_Values;
18202 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
18203 S : Entity_Id;
18205 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
18206 -- Clear current value for entity E and all entities chained to E
18208 ------------------------------------------
18209 -- Kill_Current_Values_For_Entity_Chain --
18210 ------------------------------------------
18212 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
18213 Ent : Entity_Id;
18214 begin
18215 Ent := E;
18216 while Present (Ent) loop
18217 Kill_Current_Values (Ent, Last_Assignment_Only);
18218 Next_Entity (Ent);
18219 end loop;
18220 end Kill_Current_Values_For_Entity_Chain;
18222 -- Start of processing for Kill_Current_Values
18224 begin
18225 -- Kill all saved checks, a special case of killing saved values
18227 if not Last_Assignment_Only then
18228 Kill_All_Checks;
18229 end if;
18231 -- Loop through relevant scopes, which includes the current scope and
18232 -- any parent scopes if the current scope is a block or a package.
18234 S := Current_Scope;
18235 Scope_Loop : loop
18237 -- Clear current values of all entities in current scope
18239 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18241 -- If scope is a package, also clear current values of all private
18242 -- entities in the scope.
18244 if Is_Package_Or_Generic_Package (S)
18245 or else Is_Concurrent_Type (S)
18246 then
18247 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18248 end if;
18250 -- If this is a not a subprogram, deal with parents
18252 if not Is_Subprogram (S) then
18253 S := Scope (S);
18254 exit Scope_Loop when S = Standard_Standard;
18255 else
18256 exit Scope_Loop;
18257 end if;
18258 end loop Scope_Loop;
18259 end Kill_Current_Values;
18261 --------------------------
18262 -- Kill_Size_Check_Code --
18263 --------------------------
18265 procedure Kill_Size_Check_Code (E : Entity_Id) is
18266 begin
18267 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18268 and then Present (Size_Check_Code (E))
18269 then
18270 Remove (Size_Check_Code (E));
18271 Set_Size_Check_Code (E, Empty);
18272 end if;
18273 end Kill_Size_Check_Code;
18275 --------------------
18276 -- Known_Non_Null --
18277 --------------------
18279 function Known_Non_Null (N : Node_Id) return Boolean is
18280 Status : constant Null_Status_Kind := Null_Status (N);
18282 Id : Entity_Id;
18283 Op : Node_Kind;
18284 Val : Node_Id;
18286 begin
18287 -- The expression yields a non-null value ignoring simple flow analysis
18289 if Status = Is_Non_Null then
18290 return True;
18292 -- Otherwise check whether N is a reference to an entity that appears
18293 -- within a conditional construct.
18295 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18297 -- First check if we are in decisive conditional
18299 Get_Current_Value_Condition (N, Op, Val);
18301 if Known_Null (Val) then
18302 if Op = N_Op_Eq then
18303 return False;
18304 elsif Op = N_Op_Ne then
18305 return True;
18306 end if;
18307 end if;
18309 -- If OK to do replacement, test Is_Known_Non_Null flag
18311 Id := Entity (N);
18313 if OK_To_Do_Constant_Replacement (Id) then
18314 return Is_Known_Non_Null (Id);
18315 end if;
18316 end if;
18318 -- Otherwise it is not possible to determine whether N yields a non-null
18319 -- value.
18321 return False;
18322 end Known_Non_Null;
18324 ----------------
18325 -- Known_Null --
18326 ----------------
18328 function Known_Null (N : Node_Id) return Boolean is
18329 Status : constant Null_Status_Kind := Null_Status (N);
18331 Id : Entity_Id;
18332 Op : Node_Kind;
18333 Val : Node_Id;
18335 begin
18336 -- The expression yields a null value ignoring simple flow analysis
18338 if Status = Is_Null then
18339 return True;
18341 -- Otherwise check whether N is a reference to an entity that appears
18342 -- within a conditional construct.
18344 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18346 -- First check if we are in decisive conditional
18348 Get_Current_Value_Condition (N, Op, Val);
18350 if Known_Null (Val) then
18351 if Op = N_Op_Eq then
18352 return True;
18353 elsif Op = N_Op_Ne then
18354 return False;
18355 end if;
18356 end if;
18358 -- If OK to do replacement, test Is_Known_Null flag
18360 Id := Entity (N);
18362 if OK_To_Do_Constant_Replacement (Id) then
18363 return Is_Known_Null (Id);
18364 end if;
18365 end if;
18367 -- Otherwise it is not possible to determine whether N yields a null
18368 -- value.
18370 return False;
18371 end Known_Null;
18373 --------------------------
18374 -- Known_To_Be_Assigned --
18375 --------------------------
18377 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18378 P : constant Node_Id := Parent (N);
18380 begin
18381 case Nkind (P) is
18383 -- Test left side of assignment
18385 when N_Assignment_Statement =>
18386 return N = Name (P);
18388 -- Function call arguments are never lvalues
18390 when N_Function_Call =>
18391 return False;
18393 -- Positional parameter for procedure or accept call
18395 when N_Accept_Statement
18396 | N_Procedure_Call_Statement
18398 declare
18399 Proc : Entity_Id;
18400 Form : Entity_Id;
18401 Act : Node_Id;
18403 begin
18404 Proc := Get_Subprogram_Entity (P);
18406 if No (Proc) then
18407 return False;
18408 end if;
18410 -- If we are not a list member, something is strange, so
18411 -- be conservative and return False.
18413 if not Is_List_Member (N) then
18414 return False;
18415 end if;
18417 -- We are going to find the right formal by stepping forward
18418 -- through the formals, as we step backwards in the actuals.
18420 Form := First_Formal (Proc);
18421 Act := N;
18422 loop
18423 -- If no formal, something is weird, so be conservative
18424 -- and return False.
18426 if No (Form) then
18427 return False;
18428 end if;
18430 Prev (Act);
18431 exit when No (Act);
18432 Next_Formal (Form);
18433 end loop;
18435 return Ekind (Form) /= E_In_Parameter;
18436 end;
18438 -- Named parameter for procedure or accept call
18440 when N_Parameter_Association =>
18441 declare
18442 Proc : Entity_Id;
18443 Form : Entity_Id;
18445 begin
18446 Proc := Get_Subprogram_Entity (Parent (P));
18448 if No (Proc) then
18449 return False;
18450 end if;
18452 -- Loop through formals to find the one that matches
18454 Form := First_Formal (Proc);
18455 loop
18456 -- If no matching formal, that's peculiar, some kind of
18457 -- previous error, so return False to be conservative.
18458 -- Actually this also happens in legal code in the case
18459 -- where P is a parameter association for an Extra_Formal???
18461 if No (Form) then
18462 return False;
18463 end if;
18465 -- Else test for match
18467 if Chars (Form) = Chars (Selector_Name (P)) then
18468 return Ekind (Form) /= E_In_Parameter;
18469 end if;
18471 Next_Formal (Form);
18472 end loop;
18473 end;
18475 -- Test for appearing in a conversion that itself appears
18476 -- in an lvalue context, since this should be an lvalue.
18478 when N_Type_Conversion =>
18479 return Known_To_Be_Assigned (P);
18481 -- All other references are definitely not known to be modifications
18483 when others =>
18484 return False;
18485 end case;
18486 end Known_To_Be_Assigned;
18488 ---------------------------
18489 -- Last_Source_Statement --
18490 ---------------------------
18492 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
18493 N : Node_Id;
18495 begin
18496 N := Last (Statements (HSS));
18497 while Present (N) loop
18498 exit when Comes_From_Source (N);
18499 Prev (N);
18500 end loop;
18502 return N;
18503 end Last_Source_Statement;
18505 -----------------------
18506 -- Mark_Coextensions --
18507 -----------------------
18509 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
18510 Is_Dynamic : Boolean;
18511 -- Indicates whether the context causes nested coextensions to be
18512 -- dynamic or static
18514 function Mark_Allocator (N : Node_Id) return Traverse_Result;
18515 -- Recognize an allocator node and label it as a dynamic coextension
18517 --------------------
18518 -- Mark_Allocator --
18519 --------------------
18521 function Mark_Allocator (N : Node_Id) return Traverse_Result is
18522 begin
18523 if Nkind (N) = N_Allocator then
18524 if Is_Dynamic then
18525 Set_Is_Static_Coextension (N, False);
18526 Set_Is_Dynamic_Coextension (N);
18528 -- If the allocator expression is potentially dynamic, it may
18529 -- be expanded out of order and require dynamic allocation
18530 -- anyway, so we treat the coextension itself as dynamic.
18531 -- Potential optimization ???
18533 elsif Nkind (Expression (N)) = N_Qualified_Expression
18534 and then Nkind (Expression (Expression (N))) = N_Op_Concat
18535 then
18536 Set_Is_Static_Coextension (N, False);
18537 Set_Is_Dynamic_Coextension (N);
18538 else
18539 Set_Is_Dynamic_Coextension (N, False);
18540 Set_Is_Static_Coextension (N);
18541 end if;
18542 end if;
18544 return OK;
18545 end Mark_Allocator;
18547 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
18549 -- Start of processing for Mark_Coextensions
18551 begin
18552 -- An allocator that appears on the right-hand side of an assignment is
18553 -- treated as a potentially dynamic coextension when the right-hand side
18554 -- is an allocator or a qualified expression.
18556 -- Obj := new ...'(new Coextension ...);
18558 if Nkind (Context_Nod) = N_Assignment_Statement then
18559 Is_Dynamic :=
18560 Nkind_In (Expression (Context_Nod), N_Allocator,
18561 N_Qualified_Expression);
18563 -- An allocator that appears within the expression of a simple return
18564 -- statement is treated as a potentially dynamic coextension when the
18565 -- expression is either aggregate, allocator, or qualified expression.
18567 -- return (new Coextension ...);
18568 -- return new ...'(new Coextension ...);
18570 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
18571 Is_Dynamic :=
18572 Nkind_In (Expression (Context_Nod), N_Aggregate,
18573 N_Allocator,
18574 N_Qualified_Expression);
18576 -- An alloctor that appears within the initialization expression of an
18577 -- object declaration is considered a potentially dynamic coextension
18578 -- when the initialization expression is an allocator or a qualified
18579 -- expression.
18581 -- Obj : ... := new ...'(new Coextension ...);
18583 -- A similar case arises when the object declaration is part of an
18584 -- extended return statement.
18586 -- return Obj : ... := new ...'(new Coextension ...);
18587 -- return Obj : ... := (new Coextension ...);
18589 elsif Nkind (Context_Nod) = N_Object_Declaration then
18590 Is_Dynamic :=
18591 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
18592 or else
18593 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
18595 -- This routine should not be called with constructs that cannot contain
18596 -- coextensions.
18598 else
18599 raise Program_Error;
18600 end if;
18602 Mark_Allocators (Root_Nod);
18603 end Mark_Coextensions;
18605 ---------------------------------
18606 -- Mark_Elaboration_Attributes --
18607 ---------------------------------
18609 procedure Mark_Elaboration_Attributes
18610 (N_Id : Node_Or_Entity_Id;
18611 Checks : Boolean := False;
18612 Level : Boolean := False;
18613 Modes : Boolean := False;
18614 Warnings : Boolean := False)
18616 function Elaboration_Checks_OK
18617 (Target_Id : Entity_Id;
18618 Context_Id : Entity_Id) return Boolean;
18619 -- Determine whether elaboration checks are enabled for target Target_Id
18620 -- which resides within context Context_Id.
18622 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
18623 -- Preserve relevant attributes of the context in arbitrary entity Id
18625 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
18626 -- Preserve relevant attributes of the context in arbitrary node N
18628 ---------------------------
18629 -- Elaboration_Checks_OK --
18630 ---------------------------
18632 function Elaboration_Checks_OK
18633 (Target_Id : Entity_Id;
18634 Context_Id : Entity_Id) return Boolean
18636 Encl_Scop : Entity_Id;
18638 begin
18639 -- Elaboration checks are suppressed for the target
18641 if Elaboration_Checks_Suppressed (Target_Id) then
18642 return False;
18643 end if;
18645 -- Otherwise elaboration checks are OK for the target, but may be
18646 -- suppressed for the context where the target is declared.
18648 Encl_Scop := Context_Id;
18649 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
18650 if Elaboration_Checks_Suppressed (Encl_Scop) then
18651 return False;
18652 end if;
18654 Encl_Scop := Scope (Encl_Scop);
18655 end loop;
18657 -- Neither the target nor its declarative context have elaboration
18658 -- checks suppressed.
18660 return True;
18661 end Elaboration_Checks_OK;
18663 ------------------------------------
18664 -- Mark_Elaboration_Attributes_Id --
18665 ------------------------------------
18667 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
18668 begin
18669 -- Mark the status of elaboration checks in effect. Do not reset the
18670 -- status in case the entity is reanalyzed with checks suppressed.
18672 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
18673 Set_Is_Elaboration_Checks_OK_Id (Id,
18674 Elaboration_Checks_OK
18675 (Target_Id => Id,
18676 Context_Id => Scope (Id)));
18677 end if;
18679 -- Mark the status of elaboration warnings in effect. Do not reset
18680 -- the status in case the entity is reanalyzed with warnings off.
18682 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
18683 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
18684 end if;
18685 end Mark_Elaboration_Attributes_Id;
18687 --------------------------------------
18688 -- Mark_Elaboration_Attributes_Node --
18689 --------------------------------------
18691 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
18692 function Extract_Name (N : Node_Id) return Node_Id;
18693 -- Obtain the Name attribute of call or instantiation N
18695 ------------------
18696 -- Extract_Name --
18697 ------------------
18699 function Extract_Name (N : Node_Id) return Node_Id is
18700 Nam : Node_Id;
18702 begin
18703 Nam := Name (N);
18705 -- A call to an entry family appears in indexed form
18707 if Nkind (Nam) = N_Indexed_Component then
18708 Nam := Prefix (Nam);
18709 end if;
18711 -- The name may also appear in qualified form
18713 if Nkind (Nam) = N_Selected_Component then
18714 Nam := Selector_Name (Nam);
18715 end if;
18717 return Nam;
18718 end Extract_Name;
18720 -- Local variables
18722 Context_Id : Entity_Id;
18723 Nam : Node_Id;
18725 -- Start of processing for Mark_Elaboration_Attributes_Node
18727 begin
18728 -- Mark the status of elaboration checks in effect. Do not reset the
18729 -- status in case the node is reanalyzed with checks suppressed.
18731 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
18733 -- Assignments, attribute references, and variable references do
18734 -- not have a "declarative" context.
18736 Context_Id := Empty;
18738 -- The status of elaboration checks for calls and instantiations
18739 -- depends on the most recent pragma Suppress/Unsuppress, as well
18740 -- as the suppression status of the context where the target is
18741 -- defined.
18743 -- package Pack is
18744 -- function Func ...;
18745 -- end Pack;
18747 -- with Pack;
18748 -- procedure Main is
18749 -- pragma Suppress (Elaboration_Checks, Pack);
18750 -- X : ... := Pack.Func;
18751 -- ...
18753 -- In the example above, the call to Func has elaboration checks
18754 -- enabled because there is no active general purpose suppression
18755 -- pragma, however the elaboration checks of Pack are explicitly
18756 -- suppressed. As a result the elaboration checks of the call must
18757 -- be disabled in order to preserve this dependency.
18759 if Nkind_In (N, N_Entry_Call_Statement,
18760 N_Function_Call,
18761 N_Function_Instantiation,
18762 N_Package_Instantiation,
18763 N_Procedure_Call_Statement,
18764 N_Procedure_Instantiation)
18765 then
18766 Nam := Extract_Name (N);
18768 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
18769 Context_Id := Scope (Entity (Nam));
18770 end if;
18771 end if;
18773 Set_Is_Elaboration_Checks_OK_Node (N,
18774 Elaboration_Checks_OK
18775 (Target_Id => Empty,
18776 Context_Id => Context_Id));
18777 end if;
18779 -- Mark the enclosing level of the node. Do not reset the status in
18780 -- case the node is relocated and reanalyzed.
18782 if Level and then not Is_Declaration_Level_Node (N) then
18783 Set_Is_Declaration_Level_Node (N,
18784 Find_Enclosing_Level (N) = Declaration_Level);
18785 end if;
18787 -- Mark the Ghost and SPARK mode in effect
18789 if Modes then
18790 if Ghost_Mode = Ignore then
18791 Set_Is_Ignored_Ghost_Node (N);
18792 end if;
18794 if SPARK_Mode = On then
18795 Set_Is_SPARK_Mode_On_Node (N);
18796 end if;
18797 end if;
18799 -- Mark the status of elaboration warnings in effect. Do not reset
18800 -- the status in case the node is reanalyzed with warnings off.
18802 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
18803 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
18804 end if;
18805 end Mark_Elaboration_Attributes_Node;
18807 -- Start of processing for Mark_Elaboration_Attributes
18809 begin
18810 -- Do not capture any elaboration-related attributes when switch -gnatH
18811 -- (legacy elaboration checking mode enabled) is in effect because the
18812 -- attributes are useless to the legacy model.
18814 if Legacy_Elaboration_Checks then
18815 return;
18816 end if;
18818 if Nkind (N_Id) in N_Entity then
18819 Mark_Elaboration_Attributes_Id (N_Id);
18820 else
18821 Mark_Elaboration_Attributes_Node (N_Id);
18822 end if;
18823 end Mark_Elaboration_Attributes;
18825 ----------------------------------
18826 -- Matching_Static_Array_Bounds --
18827 ----------------------------------
18829 function Matching_Static_Array_Bounds
18830 (L_Typ : Node_Id;
18831 R_Typ : Node_Id) return Boolean
18833 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
18834 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
18836 L_Index : Node_Id := Empty; -- init to ...
18837 R_Index : Node_Id := Empty; -- ...avoid warnings
18838 L_Low : Node_Id;
18839 L_High : Node_Id;
18840 L_Len : Uint;
18841 R_Low : Node_Id;
18842 R_High : Node_Id;
18843 R_Len : Uint;
18845 begin
18846 if L_Ndims /= R_Ndims then
18847 return False;
18848 end if;
18850 -- Unconstrained types do not have static bounds
18852 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
18853 return False;
18854 end if;
18856 -- First treat specially the first dimension, as the lower bound and
18857 -- length of string literals are not stored like those of arrays.
18859 if Ekind (L_Typ) = E_String_Literal_Subtype then
18860 L_Low := String_Literal_Low_Bound (L_Typ);
18861 L_Len := String_Literal_Length (L_Typ);
18862 else
18863 L_Index := First_Index (L_Typ);
18864 Get_Index_Bounds (L_Index, L_Low, L_High);
18866 if Is_OK_Static_Expression (L_Low)
18867 and then
18868 Is_OK_Static_Expression (L_High)
18869 then
18870 if Expr_Value (L_High) < Expr_Value (L_Low) then
18871 L_Len := Uint_0;
18872 else
18873 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
18874 end if;
18875 else
18876 return False;
18877 end if;
18878 end if;
18880 if Ekind (R_Typ) = E_String_Literal_Subtype then
18881 R_Low := String_Literal_Low_Bound (R_Typ);
18882 R_Len := String_Literal_Length (R_Typ);
18883 else
18884 R_Index := First_Index (R_Typ);
18885 Get_Index_Bounds (R_Index, R_Low, R_High);
18887 if Is_OK_Static_Expression (R_Low)
18888 and then
18889 Is_OK_Static_Expression (R_High)
18890 then
18891 if Expr_Value (R_High) < Expr_Value (R_Low) then
18892 R_Len := Uint_0;
18893 else
18894 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
18895 end if;
18896 else
18897 return False;
18898 end if;
18899 end if;
18901 if (Is_OK_Static_Expression (L_Low)
18902 and then
18903 Is_OK_Static_Expression (R_Low))
18904 and then Expr_Value (L_Low) = Expr_Value (R_Low)
18905 and then L_Len = R_Len
18906 then
18907 null;
18908 else
18909 return False;
18910 end if;
18912 -- Then treat all other dimensions
18914 for Indx in 2 .. L_Ndims loop
18915 Next (L_Index);
18916 Next (R_Index);
18918 Get_Index_Bounds (L_Index, L_Low, L_High);
18919 Get_Index_Bounds (R_Index, R_Low, R_High);
18921 if (Is_OK_Static_Expression (L_Low) and then
18922 Is_OK_Static_Expression (L_High) and then
18923 Is_OK_Static_Expression (R_Low) and then
18924 Is_OK_Static_Expression (R_High))
18925 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
18926 and then
18927 Expr_Value (L_High) = Expr_Value (R_High))
18928 then
18929 null;
18930 else
18931 return False;
18932 end if;
18933 end loop;
18935 -- If we fall through the loop, all indexes matched
18937 return True;
18938 end Matching_Static_Array_Bounds;
18940 -------------------
18941 -- May_Be_Lvalue --
18942 -------------------
18944 function May_Be_Lvalue (N : Node_Id) return Boolean is
18945 P : constant Node_Id := Parent (N);
18947 begin
18948 case Nkind (P) is
18950 -- Test left side of assignment
18952 when N_Assignment_Statement =>
18953 return N = Name (P);
18955 -- Test prefix of component or attribute. Note that the prefix of an
18956 -- explicit or implicit dereference cannot be an l-value. In the case
18957 -- of a 'Read attribute, the reference can be an actual in the
18958 -- argument list of the attribute.
18960 when N_Attribute_Reference =>
18961 return (N = Prefix (P)
18962 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
18963 or else
18964 Attribute_Name (P) = Name_Read;
18966 -- For an expanded name, the name is an lvalue if the expanded name
18967 -- is an lvalue, but the prefix is never an lvalue, since it is just
18968 -- the scope where the name is found.
18970 when N_Expanded_Name =>
18971 if N = Prefix (P) then
18972 return May_Be_Lvalue (P);
18973 else
18974 return False;
18975 end if;
18977 -- For a selected component A.B, A is certainly an lvalue if A.B is.
18978 -- B is a little interesting, if we have A.B := 3, there is some
18979 -- discussion as to whether B is an lvalue or not, we choose to say
18980 -- it is. Note however that A is not an lvalue if it is of an access
18981 -- type since this is an implicit dereference.
18983 when N_Selected_Component =>
18984 if N = Prefix (P)
18985 and then Present (Etype (N))
18986 and then Is_Access_Type (Etype (N))
18987 then
18988 return False;
18989 else
18990 return May_Be_Lvalue (P);
18991 end if;
18993 -- For an indexed component or slice, the index or slice bounds is
18994 -- never an lvalue. The prefix is an lvalue if the indexed component
18995 -- or slice is an lvalue, except if it is an access type, where we
18996 -- have an implicit dereference.
18998 when N_Indexed_Component
18999 | N_Slice
19001 if N /= Prefix (P)
19002 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
19003 then
19004 return False;
19005 else
19006 return May_Be_Lvalue (P);
19007 end if;
19009 -- Prefix of a reference is an lvalue if the reference is an lvalue
19011 when N_Reference =>
19012 return May_Be_Lvalue (P);
19014 -- Prefix of explicit dereference is never an lvalue
19016 when N_Explicit_Dereference =>
19017 return False;
19019 -- Positional parameter for subprogram, entry, or accept call.
19020 -- In older versions of Ada function call arguments are never
19021 -- lvalues. In Ada 2012 functions can have in-out parameters.
19023 when N_Accept_Statement
19024 | N_Entry_Call_Statement
19025 | N_Subprogram_Call
19027 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
19028 return False;
19029 end if;
19031 -- The following mechanism is clumsy and fragile. A single flag
19032 -- set in Resolve_Actuals would be preferable ???
19034 declare
19035 Proc : Entity_Id;
19036 Form : Entity_Id;
19037 Act : Node_Id;
19039 begin
19040 Proc := Get_Subprogram_Entity (P);
19042 if No (Proc) then
19043 return True;
19044 end if;
19046 -- If we are not a list member, something is strange, so be
19047 -- conservative and return True.
19049 if not Is_List_Member (N) then
19050 return True;
19051 end if;
19053 -- We are going to find the right formal by stepping forward
19054 -- through the formals, as we step backwards in the actuals.
19056 Form := First_Formal (Proc);
19057 Act := N;
19058 loop
19059 -- If no formal, something is weird, so be conservative and
19060 -- return True.
19062 if No (Form) then
19063 return True;
19064 end if;
19066 Prev (Act);
19067 exit when No (Act);
19068 Next_Formal (Form);
19069 end loop;
19071 return Ekind (Form) /= E_In_Parameter;
19072 end;
19074 -- Named parameter for procedure or accept call
19076 when N_Parameter_Association =>
19077 declare
19078 Proc : Entity_Id;
19079 Form : Entity_Id;
19081 begin
19082 Proc := Get_Subprogram_Entity (Parent (P));
19084 if No (Proc) then
19085 return True;
19086 end if;
19088 -- Loop through formals to find the one that matches
19090 Form := First_Formal (Proc);
19091 loop
19092 -- If no matching formal, that's peculiar, some kind of
19093 -- previous error, so return True to be conservative.
19094 -- Actually happens with legal code for an unresolved call
19095 -- where we may get the wrong homonym???
19097 if No (Form) then
19098 return True;
19099 end if;
19101 -- Else test for match
19103 if Chars (Form) = Chars (Selector_Name (P)) then
19104 return Ekind (Form) /= E_In_Parameter;
19105 end if;
19107 Next_Formal (Form);
19108 end loop;
19109 end;
19111 -- Test for appearing in a conversion that itself appears in an
19112 -- lvalue context, since this should be an lvalue.
19114 when N_Type_Conversion =>
19115 return May_Be_Lvalue (P);
19117 -- Test for appearance in object renaming declaration
19119 when N_Object_Renaming_Declaration =>
19120 return True;
19122 -- All other references are definitely not lvalues
19124 when others =>
19125 return False;
19126 end case;
19127 end May_Be_Lvalue;
19129 -----------------
19130 -- Might_Raise --
19131 -----------------
19133 function Might_Raise (N : Node_Id) return Boolean is
19134 Result : Boolean := False;
19136 function Process (N : Node_Id) return Traverse_Result;
19137 -- Set Result to True if we find something that could raise an exception
19139 -------------
19140 -- Process --
19141 -------------
19143 function Process (N : Node_Id) return Traverse_Result is
19144 begin
19145 if Nkind_In (N, N_Procedure_Call_Statement,
19146 N_Function_Call,
19147 N_Raise_Statement,
19148 N_Raise_Constraint_Error,
19149 N_Raise_Program_Error,
19150 N_Raise_Storage_Error)
19151 then
19152 Result := True;
19153 return Abandon;
19154 else
19155 return OK;
19156 end if;
19157 end Process;
19159 procedure Set_Result is new Traverse_Proc (Process);
19161 -- Start of processing for Might_Raise
19163 begin
19164 -- False if exceptions can't be propagated
19166 if No_Exception_Handlers_Set then
19167 return False;
19168 end if;
19170 -- If the checks handled by the back end are not disabled, we cannot
19171 -- ensure that no exception will be raised.
19173 if not Access_Checks_Suppressed (Empty)
19174 or else not Discriminant_Checks_Suppressed (Empty)
19175 or else not Range_Checks_Suppressed (Empty)
19176 or else not Index_Checks_Suppressed (Empty)
19177 or else Opt.Stack_Checking_Enabled
19178 then
19179 return True;
19180 end if;
19182 Set_Result (N);
19183 return Result;
19184 end Might_Raise;
19186 --------------------------------
19187 -- Nearest_Enclosing_Instance --
19188 --------------------------------
19190 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
19191 Inst : Entity_Id;
19193 begin
19194 Inst := Scope (E);
19195 while Present (Inst) and then Inst /= Standard_Standard loop
19196 if Is_Generic_Instance (Inst) then
19197 return Inst;
19198 end if;
19200 Inst := Scope (Inst);
19201 end loop;
19203 return Empty;
19204 end Nearest_Enclosing_Instance;
19206 ----------------------
19207 -- Needs_One_Actual --
19208 ----------------------
19210 function Needs_One_Actual (E : Entity_Id) return Boolean is
19211 Formal : Entity_Id;
19213 begin
19214 -- Ada 2005 or later, and formals present. The first formal must be
19215 -- of a type that supports prefix notation: a controlling argument,
19216 -- a class-wide type, or an access to such.
19218 if Ada_Version >= Ada_2005
19219 and then Present (First_Formal (E))
19220 and then No (Default_Value (First_Formal (E)))
19221 and then
19222 (Is_Controlling_Formal (First_Formal (E))
19223 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
19224 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
19225 then
19226 Formal := Next_Formal (First_Formal (E));
19227 while Present (Formal) loop
19228 if No (Default_Value (Formal)) then
19229 return False;
19230 end if;
19232 Next_Formal (Formal);
19233 end loop;
19235 return True;
19237 -- Ada 83/95 or no formals
19239 else
19240 return False;
19241 end if;
19242 end Needs_One_Actual;
19244 ---------------------------------
19245 -- Needs_Simple_Initialization --
19246 ---------------------------------
19248 function Needs_Simple_Initialization
19249 (Typ : Entity_Id;
19250 Consider_IS : Boolean := True) return Boolean
19252 Consider_IS_NS : constant Boolean :=
19253 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19255 begin
19256 -- Never need initialization if it is suppressed
19258 if Initialization_Suppressed (Typ) then
19259 return False;
19260 end if;
19262 -- Check for private type, in which case test applies to the underlying
19263 -- type of the private type.
19265 if Is_Private_Type (Typ) then
19266 declare
19267 RT : constant Entity_Id := Underlying_Type (Typ);
19268 begin
19269 if Present (RT) then
19270 return Needs_Simple_Initialization (RT);
19271 else
19272 return False;
19273 end if;
19274 end;
19276 -- Scalar type with Default_Value aspect requires initialization
19278 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
19279 return True;
19281 -- Cases needing simple initialization are access types, and, if pragma
19282 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19283 -- types.
19285 elsif Is_Access_Type (Typ)
19286 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
19287 then
19288 return True;
19290 -- If Initialize/Normalize_Scalars is in effect, string objects also
19291 -- need initialization, unless they are created in the course of
19292 -- expanding an aggregate (since in the latter case they will be
19293 -- filled with appropriate initializing values before they are used).
19295 elsif Consider_IS_NS
19296 and then Is_Standard_String_Type (Typ)
19297 and then
19298 (not Is_Itype (Typ)
19299 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
19300 then
19301 return True;
19303 else
19304 return False;
19305 end if;
19306 end Needs_Simple_Initialization;
19308 -------------------------------------
19309 -- Needs_Variable_Reference_Marker --
19310 -------------------------------------
19312 function Needs_Variable_Reference_Marker
19313 (N : Node_Id;
19314 Calls_OK : Boolean) return Boolean
19316 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
19317 -- Deteremine whether variable reference Ref appears within a suitable
19318 -- context that allows the creation of a marker.
19320 -----------------------------
19321 -- Within_Suitable_Context --
19322 -----------------------------
19324 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
19325 Par : Node_Id;
19327 begin
19328 Par := Ref;
19329 while Present (Par) loop
19331 -- The context is not suitable when the reference appears within
19332 -- the formal part of an instantiation which acts as compilation
19333 -- unit because there is no proper list for the insertion of the
19334 -- marker.
19336 if Nkind (Par) = N_Generic_Association
19337 and then Nkind (Parent (Par)) in N_Generic_Instantiation
19338 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
19339 then
19340 return False;
19342 -- The context is not suitable when the reference appears within
19343 -- a pragma. If the pragma has run-time semantics, the reference
19344 -- will be reconsidered once the pragma is expanded.
19346 elsif Nkind (Par) = N_Pragma then
19347 return False;
19349 -- The context is not suitable when the reference appears within a
19350 -- subprogram call, and the caller requests this behavior.
19352 elsif not Calls_OK
19353 and then Nkind_In (Par, N_Entry_Call_Statement,
19354 N_Function_Call,
19355 N_Procedure_Call_Statement)
19356 then
19357 return False;
19359 -- Prevent the search from going too far
19361 elsif Is_Body_Or_Package_Declaration (Par) then
19362 exit;
19363 end if;
19365 Par := Parent (Par);
19366 end loop;
19368 return True;
19369 end Within_Suitable_Context;
19371 -- Local variables
19373 Prag : Node_Id;
19374 Var_Id : Entity_Id;
19376 -- Start of processing for Needs_Variable_Reference_Marker
19378 begin
19379 -- No marker needs to be created when switch -gnatH (legacy elaboration
19380 -- checking mode enabled) is in effect because the legacy ABE mechanism
19381 -- does not use markers.
19383 if Legacy_Elaboration_Checks then
19384 return False;
19386 -- No marker needs to be created for ASIS because ABE diagnostics and
19387 -- checks are not performed in this mode.
19389 elsif ASIS_Mode then
19390 return False;
19392 -- No marker needs to be created when the reference is preanalyzed
19393 -- because the marker will be inserted in the wrong place.
19395 elsif Preanalysis_Active then
19396 return False;
19398 -- Only references warrant a marker
19400 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
19401 return False;
19403 -- Only source references warrant a marker
19405 elsif not Comes_From_Source (N) then
19406 return False;
19408 -- No marker needs to be created when the reference is erroneous, left
19409 -- in a bad state, or does not denote a variable.
19411 elsif not (Present (Entity (N))
19412 and then Ekind (Entity (N)) = E_Variable
19413 and then Entity (N) /= Any_Id)
19414 then
19415 return False;
19416 end if;
19418 Var_Id := Entity (N);
19419 Prag := SPARK_Pragma (Var_Id);
19421 -- Both the variable and reference must appear in SPARK_Mode On regions
19422 -- because this elaboration scenario falls under the SPARK rules.
19424 if not (Comes_From_Source (Var_Id)
19425 and then Present (Prag)
19426 and then Get_SPARK_Mode_From_Annotation (Prag) = On
19427 and then Is_SPARK_Mode_On_Node (N))
19428 then
19429 return False;
19431 -- No marker needs to be created when the reference does not appear
19432 -- within a suitable context (see body for details).
19434 -- Performance note: parent traversal
19436 elsif not Within_Suitable_Context (N) then
19437 return False;
19438 end if;
19440 -- At this point it is known that the variable reference will play a
19441 -- role in ABE diagnostics and requires a marker.
19443 return True;
19444 end Needs_Variable_Reference_Marker;
19446 ------------------------
19447 -- New_Copy_List_Tree --
19448 ------------------------
19450 function New_Copy_List_Tree (List : List_Id) return List_Id is
19451 NL : List_Id;
19452 E : Node_Id;
19454 begin
19455 if List = No_List then
19456 return No_List;
19458 else
19459 NL := New_List;
19460 E := First (List);
19462 while Present (E) loop
19463 Append (New_Copy_Tree (E), NL);
19464 E := Next (E);
19465 end loop;
19467 return NL;
19468 end if;
19469 end New_Copy_List_Tree;
19471 -------------------
19472 -- New_Copy_Tree --
19473 -------------------
19475 -- The following tables play a key role in replicating entities and Itypes.
19476 -- They are intentionally declared at the library level rather than within
19477 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19478 -- optimization saves up to 2% of the entire compilation time spent in the
19479 -- front end. Care should be taken to reset the tables on each new call to
19480 -- New_Copy_Tree.
19482 NCT_Table_Max : constant := 511;
19484 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
19486 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
19487 -- Obtain the hash value of node or entity Key
19489 --------------------
19490 -- NCT_Table_Hash --
19491 --------------------
19493 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
19494 begin
19495 return NCT_Table_Index (Key mod NCT_Table_Max);
19496 end NCT_Table_Hash;
19498 ----------------------
19499 -- NCT_New_Entities --
19500 ----------------------
19502 -- The following table maps old entities and Itypes to their corresponding
19503 -- new entities and Itypes.
19505 -- Aaa -> Xxx
19507 package NCT_New_Entities is new Simple_HTable (
19508 Header_Num => NCT_Table_Index,
19509 Element => Entity_Id,
19510 No_Element => Empty,
19511 Key => Entity_Id,
19512 Hash => NCT_Table_Hash,
19513 Equal => "=");
19515 ------------------------
19516 -- NCT_Pending_Itypes --
19517 ------------------------
19519 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19520 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19521 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19522 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19524 -- Ppp -> (Xxx, Yyy, Zzz)
19526 -- The set is expressed as an Elist
19528 package NCT_Pending_Itypes is new Simple_HTable (
19529 Header_Num => NCT_Table_Index,
19530 Element => Elist_Id,
19531 No_Element => No_Elist,
19532 Key => Node_Id,
19533 Hash => NCT_Table_Hash,
19534 Equal => "=");
19536 NCT_Tables_In_Use : Boolean := False;
19537 -- This flag keeps track of whether the two tables NCT_New_Entities and
19538 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19539 -- where certain operations are not performed if the tables are not in
19540 -- use. This saves up to 8% of the entire compilation time spent in the
19541 -- front end.
19543 -------------------
19544 -- New_Copy_Tree --
19545 -------------------
19547 function New_Copy_Tree
19548 (Source : Node_Id;
19549 Map : Elist_Id := No_Elist;
19550 New_Sloc : Source_Ptr := No_Location;
19551 New_Scope : Entity_Id := Empty;
19552 Scopes_In_EWA_OK : Boolean := False) return Node_Id
19554 -- This routine performs low-level tree manipulations and needs access
19555 -- to the internals of the tree.
19557 use Atree.Unchecked_Access;
19558 use Atree_Private_Part;
19560 EWA_Level : Nat := 0;
19561 -- This counter keeps track of how many N_Expression_With_Actions nodes
19562 -- are encountered during a depth-first traversal of the subtree. These
19563 -- nodes may define new entities in their Actions lists and thus require
19564 -- special processing.
19566 EWA_Inner_Scope_Level : Nat := 0;
19567 -- This counter keeps track of how many scoping constructs appear within
19568 -- an N_Expression_With_Actions node.
19570 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
19571 pragma Inline (Add_New_Entity);
19572 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19573 -- value New_Id. Old_Id is an entity which appears within the Actions
19574 -- list of an N_Expression_With_Actions node, or within an entity map.
19575 -- New_Id is the corresponding new entity generated during Phase 1.
19577 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
19578 pragma Inline (Add_New_Entity);
19579 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19580 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19581 -- an itype.
19583 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
19584 pragma Inline (Build_NCT_Tables);
19585 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19586 -- information supplied in entity map Entity_Map. The format of the
19587 -- entity map must be as follows:
19589 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19591 function Copy_Any_Node_With_Replacement
19592 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
19593 pragma Inline (Copy_Any_Node_With_Replacement);
19594 -- Replicate entity or node N by invoking one of the following routines:
19596 -- Copy_Node_With_Replacement
19597 -- Corresponding_Entity
19599 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
19600 -- Replicate the elements of entity list List
19602 function Copy_Field_With_Replacement
19603 (Field : Union_Id;
19604 Old_Par : Node_Id := Empty;
19605 New_Par : Node_Id := Empty;
19606 Semantic : Boolean := False) return Union_Id;
19607 -- Replicate field Field by invoking one of the following routines:
19609 -- Copy_Elist_With_Replacement
19610 -- Copy_List_With_Replacement
19611 -- Copy_Node_With_Replacement
19612 -- Corresponding_Entity
19614 -- If the field is not an entity list, entity, itype, syntactic list,
19615 -- or node, then the field is returned unchanged. The routine always
19616 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19617 -- the expected parent of a syntactic field. New_Par is the new parent
19618 -- associated with a replicated syntactic field. Flag Semantic should
19619 -- be set when the input is a semantic field.
19621 function Copy_List_With_Replacement (List : List_Id) return List_Id;
19622 -- Replicate the elements of syntactic list List
19624 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
19625 -- Replicate node N
19627 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
19628 pragma Inline (Corresponding_Entity);
19629 -- Return the corresponding new entity of Id generated during Phase 1.
19630 -- If there is no such entity, return Id.
19632 function In_Entity_Map
19633 (Id : Entity_Id;
19634 Entity_Map : Elist_Id) return Boolean;
19635 pragma Inline (In_Entity_Map);
19636 -- Determine whether entity Id is one of the old ids specified in entity
19637 -- map Entity_Map. The format of the entity map must be as follows:
19639 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19641 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
19642 pragma Inline (Update_CFS_Sloc);
19643 -- Update the Comes_From_Source and Sloc attributes of node or entity N
19645 procedure Update_First_Real_Statement
19646 (Old_HSS : Node_Id;
19647 New_HSS : Node_Id);
19648 pragma Inline (Update_First_Real_Statement);
19649 -- Update semantic attribute First_Real_Statement of handled sequence of
19650 -- statements New_HSS based on handled sequence of statements Old_HSS.
19652 procedure Update_Named_Associations
19653 (Old_Call : Node_Id;
19654 New_Call : Node_Id);
19655 pragma Inline (Update_Named_Associations);
19656 -- Update semantic chain First/Next_Named_Association of call New_call
19657 -- based on call Old_Call.
19659 procedure Update_New_Entities (Entity_Map : Elist_Id);
19660 pragma Inline (Update_New_Entities);
19661 -- Update the semantic attributes of all new entities generated during
19662 -- Phase 1 that do not appear in entity map Entity_Map. The format of
19663 -- the entity map must be as follows:
19665 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19667 procedure Update_Pending_Itypes
19668 (Old_Assoc : Node_Id;
19669 New_Assoc : Node_Id);
19670 pragma Inline (Update_Pending_Itypes);
19671 -- Update semantic attribute Associated_Node_For_Itype to refer to node
19672 -- New_Assoc for all itypes whose associated node is Old_Assoc.
19674 procedure Update_Semantic_Fields (Id : Entity_Id);
19675 pragma Inline (Update_Semantic_Fields);
19676 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
19677 -- or itype Id.
19679 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
19680 pragma Inline (Visit_Any_Node);
19681 -- Visit entity of node N by invoking one of the following routines:
19683 -- Visit_Entity
19684 -- Visit_Itype
19685 -- Visit_Node
19687 procedure Visit_Elist (List : Elist_Id);
19688 -- Visit the elements of entity list List
19690 procedure Visit_Entity (Id : Entity_Id);
19691 -- Visit entity Id. This action may create a new entity of Id and save
19692 -- it in table NCT_New_Entities.
19694 procedure Visit_Field
19695 (Field : Union_Id;
19696 Par_Nod : Node_Id := Empty;
19697 Semantic : Boolean := False);
19698 -- Visit field Field by invoking one of the following routines:
19700 -- Visit_Elist
19701 -- Visit_Entity
19702 -- Visit_Itype
19703 -- Visit_List
19704 -- Visit_Node
19706 -- If the field is not an entity list, entity, itype, syntactic list,
19707 -- or node, then the field is not visited. The routine always visits
19708 -- valid syntactic fields. Par_Nod is the expected parent of the
19709 -- syntactic field. Flag Semantic should be set when the input is a
19710 -- semantic field.
19712 procedure Visit_Itype (Itype : Entity_Id);
19713 -- Visit itype Itype. This action may create a new entity for Itype and
19714 -- save it in table NCT_New_Entities. In addition, the routine may map
19715 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
19717 procedure Visit_List (List : List_Id);
19718 -- Visit the elements of syntactic list List
19720 procedure Visit_Node (N : Node_Id);
19721 -- Visit node N
19723 procedure Visit_Semantic_Fields (Id : Entity_Id);
19724 pragma Inline (Visit_Semantic_Fields);
19725 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
19726 -- fields of entity or itype Id.
19728 --------------------
19729 -- Add_New_Entity --
19730 --------------------
19732 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
19733 begin
19734 pragma Assert (Present (Old_Id));
19735 pragma Assert (Present (New_Id));
19736 pragma Assert (Nkind (Old_Id) in N_Entity);
19737 pragma Assert (Nkind (New_Id) in N_Entity);
19739 NCT_Tables_In_Use := True;
19741 -- Sanity check the NCT_New_Entities table. No previous mapping with
19742 -- key Old_Id should exist.
19744 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
19746 -- Establish the mapping
19748 -- Old_Id -> New_Id
19750 NCT_New_Entities.Set (Old_Id, New_Id);
19751 end Add_New_Entity;
19753 -----------------------
19754 -- Add_Pending_Itype --
19755 -----------------------
19757 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
19758 Itypes : Elist_Id;
19760 begin
19761 pragma Assert (Present (Assoc_Nod));
19762 pragma Assert (Present (Itype));
19763 pragma Assert (Nkind (Itype) in N_Entity);
19764 pragma Assert (Is_Itype (Itype));
19766 NCT_Tables_In_Use := True;
19768 -- It is not possible to sanity check the NCT_Pendint_Itypes table
19769 -- directly because a single node may act as the associated node for
19770 -- multiple itypes.
19772 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
19774 if No (Itypes) then
19775 Itypes := New_Elmt_List;
19776 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
19777 end if;
19779 -- Establish the mapping
19781 -- Assoc_Nod -> (Itype, ...)
19783 -- Avoid inserting the same itype multiple times. This involves a
19784 -- linear search, however the set of itypes with the same associated
19785 -- node is very small.
19787 Append_Unique_Elmt (Itype, Itypes);
19788 end Add_Pending_Itype;
19790 ----------------------
19791 -- Build_NCT_Tables --
19792 ----------------------
19794 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
19795 Elmt : Elmt_Id;
19796 Old_Id : Entity_Id;
19797 New_Id : Entity_Id;
19799 begin
19800 -- Nothing to do when there is no entity map
19802 if No (Entity_Map) then
19803 return;
19804 end if;
19806 Elmt := First_Elmt (Entity_Map);
19807 while Present (Elmt) loop
19809 -- Extract the (Old_Id, New_Id) pair from the entity map
19811 Old_Id := Node (Elmt);
19812 Next_Elmt (Elmt);
19814 New_Id := Node (Elmt);
19815 Next_Elmt (Elmt);
19817 -- Establish the following mapping within table NCT_New_Entities
19819 -- Old_Id -> New_Id
19821 Add_New_Entity (Old_Id, New_Id);
19823 -- Establish the following mapping within table NCT_Pending_Itypes
19824 -- when the new entity is an itype.
19826 -- Assoc_Nod -> (New_Id, ...)
19828 -- IMPORTANT: the associated node is that of the old itype because
19829 -- the node will be replicated in Phase 2.
19831 if Is_Itype (Old_Id) then
19832 Add_Pending_Itype
19833 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
19834 Itype => New_Id);
19835 end if;
19836 end loop;
19837 end Build_NCT_Tables;
19839 ------------------------------------
19840 -- Copy_Any_Node_With_Replacement --
19841 ------------------------------------
19843 function Copy_Any_Node_With_Replacement
19844 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
19846 begin
19847 if Nkind (N) in N_Entity then
19848 return Corresponding_Entity (N);
19849 else
19850 return Copy_Node_With_Replacement (N);
19851 end if;
19852 end Copy_Any_Node_With_Replacement;
19854 ---------------------------------
19855 -- Copy_Elist_With_Replacement --
19856 ---------------------------------
19858 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
19859 Elmt : Elmt_Id;
19860 Result : Elist_Id;
19862 begin
19863 -- Copy the contents of the old list. Note that the list itself may
19864 -- be empty, in which case the routine returns a new empty list. This
19865 -- avoids sharing lists between subtrees. The element of an entity
19866 -- list could be an entity or a node, hence the invocation of routine
19867 -- Copy_Any_Node_With_Replacement.
19869 if Present (List) then
19870 Result := New_Elmt_List;
19872 Elmt := First_Elmt (List);
19873 while Present (Elmt) loop
19874 Append_Elmt
19875 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
19877 Next_Elmt (Elmt);
19878 end loop;
19880 -- Otherwise the list does not exist
19882 else
19883 Result := No_Elist;
19884 end if;
19886 return Result;
19887 end Copy_Elist_With_Replacement;
19889 ---------------------------------
19890 -- Copy_Field_With_Replacement --
19891 ---------------------------------
19893 function Copy_Field_With_Replacement
19894 (Field : Union_Id;
19895 Old_Par : Node_Id := Empty;
19896 New_Par : Node_Id := Empty;
19897 Semantic : Boolean := False) return Union_Id
19899 begin
19900 -- The field is empty
19902 if Field = Union_Id (Empty) then
19903 return Field;
19905 -- The field is an entity/itype/node
19907 elsif Field in Node_Range then
19908 declare
19909 Old_N : constant Node_Id := Node_Id (Field);
19910 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
19912 New_N : Node_Id;
19914 begin
19915 -- The field is an entity/itype
19917 if Nkind (Old_N) in N_Entity then
19919 -- An entity/itype is always replicated
19921 New_N := Corresponding_Entity (Old_N);
19923 -- Update the parent pointer when the entity is a syntactic
19924 -- field. Note that itypes do not have parent pointers.
19926 if Syntactic and then New_N /= Old_N then
19927 Set_Parent (New_N, New_Par);
19928 end if;
19930 -- The field is a node
19932 else
19933 -- A node is replicated when it is either a syntactic field
19934 -- or when the caller treats it as a semantic attribute.
19936 if Syntactic or else Semantic then
19937 New_N := Copy_Node_With_Replacement (Old_N);
19939 -- Update the parent pointer when the node is a syntactic
19940 -- field.
19942 if Syntactic and then New_N /= Old_N then
19943 Set_Parent (New_N, New_Par);
19944 end if;
19946 -- Otherwise the node is returned unchanged
19948 else
19949 New_N := Old_N;
19950 end if;
19951 end if;
19953 return Union_Id (New_N);
19954 end;
19956 -- The field is an entity list
19958 elsif Field in Elist_Range then
19959 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
19961 -- The field is a syntactic list
19963 elsif Field in List_Range then
19964 declare
19965 Old_List : constant List_Id := List_Id (Field);
19966 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
19968 New_List : List_Id;
19970 begin
19971 -- A list is replicated when it is either a syntactic field or
19972 -- when the caller treats it as a semantic attribute.
19974 if Syntactic or else Semantic then
19975 New_List := Copy_List_With_Replacement (Old_List);
19977 -- Update the parent pointer when the list is a syntactic
19978 -- field.
19980 if Syntactic and then New_List /= Old_List then
19981 Set_Parent (New_List, New_Par);
19982 end if;
19984 -- Otherwise the list is returned unchanged
19986 else
19987 New_List := Old_List;
19988 end if;
19990 return Union_Id (New_List);
19991 end;
19993 -- Otherwise the field denotes an attribute that does not need to be
19994 -- replicated (Chars, literals, etc).
19996 else
19997 return Field;
19998 end if;
19999 end Copy_Field_With_Replacement;
20001 --------------------------------
20002 -- Copy_List_With_Replacement --
20003 --------------------------------
20005 function Copy_List_With_Replacement (List : List_Id) return List_Id is
20006 Elmt : Node_Id;
20007 Result : List_Id;
20009 begin
20010 -- Copy the contents of the old list. Note that the list itself may
20011 -- be empty, in which case the routine returns a new empty list. This
20012 -- avoids sharing lists between subtrees. The element of a syntactic
20013 -- list is always a node, never an entity or itype, hence the call to
20014 -- routine Copy_Node_With_Replacement.
20016 if Present (List) then
20017 Result := New_List;
20019 Elmt := First (List);
20020 while Present (Elmt) loop
20021 Append (Copy_Node_With_Replacement (Elmt), Result);
20023 Next (Elmt);
20024 end loop;
20026 -- Otherwise the list does not exist
20028 else
20029 Result := No_List;
20030 end if;
20032 return Result;
20033 end Copy_List_With_Replacement;
20035 --------------------------------
20036 -- Copy_Node_With_Replacement --
20037 --------------------------------
20039 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
20040 Result : Node_Id;
20042 begin
20043 -- Assume that the node must be returned unchanged
20045 Result := N;
20047 if N > Empty_Or_Error then
20048 pragma Assert (Nkind (N) not in N_Entity);
20050 Result := New_Copy (N);
20052 Set_Field1 (Result,
20053 Copy_Field_With_Replacement
20054 (Field => Field1 (Result),
20055 Old_Par => N,
20056 New_Par => Result));
20058 Set_Field2 (Result,
20059 Copy_Field_With_Replacement
20060 (Field => Field2 (Result),
20061 Old_Par => N,
20062 New_Par => Result));
20064 Set_Field3 (Result,
20065 Copy_Field_With_Replacement
20066 (Field => Field3 (Result),
20067 Old_Par => N,
20068 New_Par => Result));
20070 Set_Field4 (Result,
20071 Copy_Field_With_Replacement
20072 (Field => Field4 (Result),
20073 Old_Par => N,
20074 New_Par => Result));
20076 Set_Field5 (Result,
20077 Copy_Field_With_Replacement
20078 (Field => Field5 (Result),
20079 Old_Par => N,
20080 New_Par => Result));
20082 -- Update the Comes_From_Source and Sloc attributes of the node
20083 -- in case the caller has supplied new values.
20085 Update_CFS_Sloc (Result);
20087 -- Update the Associated_Node_For_Itype attribute of all itypes
20088 -- created during Phase 1 whose associated node is N. As a result
20089 -- the Associated_Node_For_Itype refers to the replicated node.
20090 -- No action needs to be taken when the Associated_Node_For_Itype
20091 -- refers to an entity because this was already handled during
20092 -- Phase 1, in Visit_Itype.
20094 Update_Pending_Itypes
20095 (Old_Assoc => N,
20096 New_Assoc => Result);
20098 -- Update the First/Next_Named_Association chain for a replicated
20099 -- call.
20101 if Nkind_In (N, N_Entry_Call_Statement,
20102 N_Function_Call,
20103 N_Procedure_Call_Statement)
20104 then
20105 Update_Named_Associations
20106 (Old_Call => N,
20107 New_Call => Result);
20109 -- Update the Renamed_Object attribute of a replicated object
20110 -- declaration.
20112 elsif Nkind (N) = N_Object_Renaming_Declaration then
20113 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
20115 -- Update the First_Real_Statement attribute of a replicated
20116 -- handled sequence of statements.
20118 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
20119 Update_First_Real_Statement
20120 (Old_HSS => N,
20121 New_HSS => Result);
20122 end if;
20123 end if;
20125 return Result;
20126 end Copy_Node_With_Replacement;
20128 --------------------------
20129 -- Corresponding_Entity --
20130 --------------------------
20132 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
20133 New_Id : Entity_Id;
20134 Result : Entity_Id;
20136 begin
20137 -- Assume that the entity must be returned unchanged
20139 Result := Id;
20141 if Id > Empty_Or_Error then
20142 pragma Assert (Nkind (Id) in N_Entity);
20144 -- Determine whether the entity has a corresponding new entity
20145 -- generated during Phase 1 and if it does, use it.
20147 if NCT_Tables_In_Use then
20148 New_Id := NCT_New_Entities.Get (Id);
20150 if Present (New_Id) then
20151 Result := New_Id;
20152 end if;
20153 end if;
20154 end if;
20156 return Result;
20157 end Corresponding_Entity;
20159 -------------------
20160 -- In_Entity_Map --
20161 -------------------
20163 function In_Entity_Map
20164 (Id : Entity_Id;
20165 Entity_Map : Elist_Id) return Boolean
20167 Elmt : Elmt_Id;
20168 Old_Id : Entity_Id;
20170 begin
20171 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20172 -- step always skips the New_Id portion of the pair.
20174 if Present (Entity_Map) then
20175 Elmt := First_Elmt (Entity_Map);
20176 while Present (Elmt) loop
20177 Old_Id := Node (Elmt);
20179 if Old_Id = Id then
20180 return True;
20181 end if;
20183 Next_Elmt (Elmt);
20184 Next_Elmt (Elmt);
20185 end loop;
20186 end if;
20188 return False;
20189 end In_Entity_Map;
20191 ---------------------
20192 -- Update_CFS_Sloc --
20193 ---------------------
20195 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
20196 begin
20197 -- A new source location defaults the Comes_From_Source attribute
20199 if New_Sloc /= No_Location then
20200 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
20201 Set_Sloc (N, New_Sloc);
20202 end if;
20203 end Update_CFS_Sloc;
20205 ---------------------------------
20206 -- Update_First_Real_Statement --
20207 ---------------------------------
20209 procedure Update_First_Real_Statement
20210 (Old_HSS : Node_Id;
20211 New_HSS : Node_Id)
20213 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
20215 New_Stmt : Node_Id;
20216 Old_Stmt : Node_Id;
20218 begin
20219 -- Recreate the First_Real_Statement attribute of a handled sequence
20220 -- of statements by traversing the statement lists of both sequences
20221 -- in parallel.
20223 if Present (Old_First_Stmt) then
20224 New_Stmt := First (Statements (New_HSS));
20225 Old_Stmt := First (Statements (Old_HSS));
20226 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
20227 Next (New_Stmt);
20228 Next (Old_Stmt);
20229 end loop;
20231 pragma Assert (Present (New_Stmt));
20232 pragma Assert (Present (Old_Stmt));
20234 Set_First_Real_Statement (New_HSS, New_Stmt);
20235 end if;
20236 end Update_First_Real_Statement;
20238 -------------------------------
20239 -- Update_Named_Associations --
20240 -------------------------------
20242 procedure Update_Named_Associations
20243 (Old_Call : Node_Id;
20244 New_Call : Node_Id)
20246 New_Act : Node_Id;
20247 New_Next : Node_Id;
20248 Old_Act : Node_Id;
20249 Old_Next : Node_Id;
20251 begin
20252 -- Recreate the First/Next_Named_Actual chain of a call by traversing
20253 -- the chains of both the old and new calls in parallel.
20255 New_Act := First (Parameter_Associations (New_Call));
20256 Old_Act := First (Parameter_Associations (Old_Call));
20257 while Present (Old_Act) loop
20258 if Nkind (Old_Act) = N_Parameter_Association
20259 and then Present (Next_Named_Actual (Old_Act))
20260 then
20261 if First_Named_Actual (Old_Call) =
20262 Explicit_Actual_Parameter (Old_Act)
20263 then
20264 Set_First_Named_Actual (New_Call,
20265 Explicit_Actual_Parameter (New_Act));
20266 end if;
20268 -- Scan the actual parameter list to find the next suitable
20269 -- named actual. Note that the list may be out of order.
20271 New_Next := First (Parameter_Associations (New_Call));
20272 Old_Next := First (Parameter_Associations (Old_Call));
20273 while Nkind (Old_Next) /= N_Parameter_Association
20274 or else Explicit_Actual_Parameter (Old_Next) /=
20275 Next_Named_Actual (Old_Act)
20276 loop
20277 Next (New_Next);
20278 Next (Old_Next);
20279 end loop;
20281 Set_Next_Named_Actual (New_Act,
20282 Explicit_Actual_Parameter (New_Next));
20283 end if;
20285 Next (New_Act);
20286 Next (Old_Act);
20287 end loop;
20288 end Update_Named_Associations;
20290 -------------------------
20291 -- Update_New_Entities --
20292 -------------------------
20294 procedure Update_New_Entities (Entity_Map : Elist_Id) is
20295 New_Id : Entity_Id := Empty;
20296 Old_Id : Entity_Id := Empty;
20298 begin
20299 if NCT_Tables_In_Use then
20300 NCT_New_Entities.Get_First (Old_Id, New_Id);
20302 -- Update the semantic fields of all new entities created during
20303 -- Phase 1 which were not supplied via an entity map.
20304 -- ??? Is there a better way of distinguishing those?
20306 while Present (Old_Id) and then Present (New_Id) loop
20307 if not (Present (Entity_Map)
20308 and then In_Entity_Map (Old_Id, Entity_Map))
20309 then
20310 Update_Semantic_Fields (New_Id);
20311 end if;
20313 NCT_New_Entities.Get_Next (Old_Id, New_Id);
20314 end loop;
20315 end if;
20316 end Update_New_Entities;
20318 ---------------------------
20319 -- Update_Pending_Itypes --
20320 ---------------------------
20322 procedure Update_Pending_Itypes
20323 (Old_Assoc : Node_Id;
20324 New_Assoc : Node_Id)
20326 Item : Elmt_Id;
20327 Itypes : Elist_Id;
20329 begin
20330 if NCT_Tables_In_Use then
20331 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
20333 -- Update the Associated_Node_For_Itype attribute for all itypes
20334 -- which originally refer to Old_Assoc to designate New_Assoc.
20336 if Present (Itypes) then
20337 Item := First_Elmt (Itypes);
20338 while Present (Item) loop
20339 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
20341 Next_Elmt (Item);
20342 end loop;
20343 end if;
20344 end if;
20345 end Update_Pending_Itypes;
20347 ----------------------------
20348 -- Update_Semantic_Fields --
20349 ----------------------------
20351 procedure Update_Semantic_Fields (Id : Entity_Id) is
20352 begin
20353 -- Discriminant_Constraint
20355 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20356 Set_Discriminant_Constraint (Id, Elist_Id (
20357 Copy_Field_With_Replacement
20358 (Field => Union_Id (Discriminant_Constraint (Id)),
20359 Semantic => True)));
20360 end if;
20362 -- Etype
20364 Set_Etype (Id, Node_Id (
20365 Copy_Field_With_Replacement
20366 (Field => Union_Id (Etype (Id)),
20367 Semantic => True)));
20369 -- First_Index
20370 -- Packed_Array_Impl_Type
20372 if Is_Array_Type (Id) then
20373 if Present (First_Index (Id)) then
20374 Set_First_Index (Id, First (List_Id (
20375 Copy_Field_With_Replacement
20376 (Field => Union_Id (List_Containing (First_Index (Id))),
20377 Semantic => True))));
20378 end if;
20380 if Is_Packed (Id) then
20381 Set_Packed_Array_Impl_Type (Id, Node_Id (
20382 Copy_Field_With_Replacement
20383 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20384 Semantic => True)));
20385 end if;
20386 end if;
20388 -- Prev_Entity
20390 Set_Prev_Entity (Id, Node_Id (
20391 Copy_Field_With_Replacement
20392 (Field => Union_Id (Prev_Entity (Id)),
20393 Semantic => True)));
20395 -- Next_Entity
20397 Set_Next_Entity (Id, Node_Id (
20398 Copy_Field_With_Replacement
20399 (Field => Union_Id (Next_Entity (Id)),
20400 Semantic => True)));
20402 -- Scalar_Range
20404 if Is_Discrete_Type (Id) then
20405 Set_Scalar_Range (Id, Node_Id (
20406 Copy_Field_With_Replacement
20407 (Field => Union_Id (Scalar_Range (Id)),
20408 Semantic => True)));
20409 end if;
20411 -- Scope
20413 -- Update the scope when the caller specified an explicit one
20415 if Present (New_Scope) then
20416 Set_Scope (Id, New_Scope);
20417 else
20418 Set_Scope (Id, Node_Id (
20419 Copy_Field_With_Replacement
20420 (Field => Union_Id (Scope (Id)),
20421 Semantic => True)));
20422 end if;
20423 end Update_Semantic_Fields;
20425 --------------------
20426 -- Visit_Any_Node --
20427 --------------------
20429 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
20430 begin
20431 if Nkind (N) in N_Entity then
20432 if Is_Itype (N) then
20433 Visit_Itype (N);
20434 else
20435 Visit_Entity (N);
20436 end if;
20437 else
20438 Visit_Node (N);
20439 end if;
20440 end Visit_Any_Node;
20442 -----------------
20443 -- Visit_Elist --
20444 -----------------
20446 procedure Visit_Elist (List : Elist_Id) is
20447 Elmt : Elmt_Id;
20449 begin
20450 -- The element of an entity list could be an entity, itype, or a
20451 -- node, hence the call to Visit_Any_Node.
20453 if Present (List) then
20454 Elmt := First_Elmt (List);
20455 while Present (Elmt) loop
20456 Visit_Any_Node (Node (Elmt));
20458 Next_Elmt (Elmt);
20459 end loop;
20460 end if;
20461 end Visit_Elist;
20463 ------------------
20464 -- Visit_Entity --
20465 ------------------
20467 procedure Visit_Entity (Id : Entity_Id) is
20468 New_Id : Entity_Id;
20470 begin
20471 pragma Assert (Nkind (Id) in N_Entity);
20472 pragma Assert (not Is_Itype (Id));
20474 -- Nothing to do when the entity is not defined in the Actions list
20475 -- of an N_Expression_With_Actions node.
20477 if EWA_Level = 0 then
20478 return;
20480 -- Nothing to do when the entity is defined in a scoping construct
20481 -- within an N_Expression_With_Actions node, unless the caller has
20482 -- requested their replication.
20484 -- ??? should this restriction be eliminated?
20486 elsif EWA_Inner_Scope_Level > 0 and then not Scopes_In_EWA_OK then
20487 return;
20489 -- Nothing to do when the entity does not denote a construct that
20490 -- may appear within an N_Expression_With_Actions node. Relaxing
20491 -- this restriction leads to a performance penalty.
20493 -- ??? this list is flaky, and may hide dormant bugs
20495 elsif not Ekind_In (Id, E_Block,
20496 E_Constant,
20497 E_Label,
20498 E_Procedure,
20499 E_Variable)
20500 and then not Is_Type (Id)
20501 then
20502 return;
20504 -- Nothing to do when the entity was already visited
20506 elsif NCT_Tables_In_Use
20507 and then Present (NCT_New_Entities.Get (Id))
20508 then
20509 return;
20511 -- Nothing to do when the declaration node of the entity is not in
20512 -- the subtree being replicated.
20514 elsif not In_Subtree
20515 (N => Declaration_Node (Id),
20516 Root => Source)
20517 then
20518 return;
20519 end if;
20521 -- Create a new entity by directly copying the old entity. This
20522 -- action causes all attributes of the old entity to be inherited.
20524 New_Id := New_Copy (Id);
20526 -- Create a new name for the new entity because the back end needs
20527 -- distinct names for debugging purposes.
20529 Set_Chars (New_Id, New_Internal_Name ('T'));
20531 -- Update the Comes_From_Source and Sloc attributes of the entity in
20532 -- case the caller has supplied new values.
20534 Update_CFS_Sloc (New_Id);
20536 -- Establish the following mapping within table NCT_New_Entities:
20538 -- Id -> New_Id
20540 Add_New_Entity (Id, New_Id);
20542 -- Deal with the semantic fields of entities. The fields are visited
20543 -- because they may mention entities which reside within the subtree
20544 -- being copied.
20546 Visit_Semantic_Fields (Id);
20547 end Visit_Entity;
20549 -----------------
20550 -- Visit_Field --
20551 -----------------
20553 procedure Visit_Field
20554 (Field : Union_Id;
20555 Par_Nod : Node_Id := Empty;
20556 Semantic : Boolean := False)
20558 begin
20559 -- The field is empty
20561 if Field = Union_Id (Empty) then
20562 return;
20564 -- The field is an entity/itype/node
20566 elsif Field in Node_Range then
20567 declare
20568 N : constant Node_Id := Node_Id (Field);
20570 begin
20571 -- The field is an entity/itype
20573 if Nkind (N) in N_Entity then
20575 -- Itypes are always visited
20577 if Is_Itype (N) then
20578 Visit_Itype (N);
20580 -- An entity is visited when it is either a syntactic field
20581 -- or when the caller treats it as a semantic attribute.
20583 elsif Parent (N) = Par_Nod or else Semantic then
20584 Visit_Entity (N);
20585 end if;
20587 -- The field is a node
20589 else
20590 -- A node is visited when it is either a syntactic field or
20591 -- when the caller treats it as a semantic attribute.
20593 if Parent (N) = Par_Nod or else Semantic then
20594 Visit_Node (N);
20595 end if;
20596 end if;
20597 end;
20599 -- The field is an entity list
20601 elsif Field in Elist_Range then
20602 Visit_Elist (Elist_Id (Field));
20604 -- The field is a syntax list
20606 elsif Field in List_Range then
20607 declare
20608 List : constant List_Id := List_Id (Field);
20610 begin
20611 -- A syntax list is visited when it is either a syntactic field
20612 -- or when the caller treats it as a semantic attribute.
20614 if Parent (List) = Par_Nod or else Semantic then
20615 Visit_List (List);
20616 end if;
20617 end;
20619 -- Otherwise the field denotes information which does not need to be
20620 -- visited (chars, literals, etc.).
20622 else
20623 null;
20624 end if;
20625 end Visit_Field;
20627 -----------------
20628 -- Visit_Itype --
20629 -----------------
20631 procedure Visit_Itype (Itype : Entity_Id) is
20632 New_Assoc : Node_Id;
20633 New_Itype : Entity_Id;
20634 Old_Assoc : Node_Id;
20636 begin
20637 pragma Assert (Nkind (Itype) in N_Entity);
20638 pragma Assert (Is_Itype (Itype));
20640 -- Itypes that describe the designated type of access to subprograms
20641 -- have the structure of subprogram declarations, with signatures,
20642 -- etc. Either we duplicate the signatures completely, or choose to
20643 -- share such itypes, which is fine because their elaboration will
20644 -- have no side effects.
20646 if Ekind (Itype) = E_Subprogram_Type then
20647 return;
20649 -- Nothing to do if the itype was already visited
20651 elsif NCT_Tables_In_Use
20652 and then Present (NCT_New_Entities.Get (Itype))
20653 then
20654 return;
20656 -- Nothing to do if the associated node of the itype is not within
20657 -- the subtree being replicated.
20659 elsif not In_Subtree
20660 (N => Associated_Node_For_Itype (Itype),
20661 Root => Source)
20662 then
20663 return;
20664 end if;
20666 -- Create a new itype by directly copying the old itype. This action
20667 -- causes all attributes of the old itype to be inherited.
20669 New_Itype := New_Copy (Itype);
20671 -- Create a new name for the new itype because the back end requires
20672 -- distinct names for debugging purposes.
20674 Set_Chars (New_Itype, New_Internal_Name ('T'));
20676 -- Update the Comes_From_Source and Sloc attributes of the itype in
20677 -- case the caller has supplied new values.
20679 Update_CFS_Sloc (New_Itype);
20681 -- Establish the following mapping within table NCT_New_Entities:
20683 -- Itype -> New_Itype
20685 Add_New_Entity (Itype, New_Itype);
20687 -- The new itype must be unfrozen because the resulting subtree may
20688 -- be inserted anywhere and cause an earlier or later freezing.
20690 if Present (Freeze_Node (New_Itype)) then
20691 Set_Freeze_Node (New_Itype, Empty);
20692 Set_Is_Frozen (New_Itype, False);
20693 end if;
20695 -- If a record subtype is simply copied, the entity list will be
20696 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
20697 -- ??? What does this do?
20699 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
20700 Set_Cloned_Subtype (New_Itype, Itype);
20701 end if;
20703 -- The associated node may denote an entity, in which case it may
20704 -- already have a new corresponding entity created during a prior
20705 -- call to Visit_Entity or Visit_Itype for the same subtree.
20707 -- Given
20708 -- Old_Assoc ---------> New_Assoc
20710 -- Created by Visit_Itype
20711 -- Itype -------------> New_Itype
20712 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
20714 -- In the example above, Old_Assoc is an arbitrary entity that was
20715 -- already visited for the same subtree and has a corresponding new
20716 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
20717 -- of copying entities, however it must be updated to New_Assoc.
20719 Old_Assoc := Associated_Node_For_Itype (Itype);
20721 if Nkind (Old_Assoc) in N_Entity then
20722 if NCT_Tables_In_Use then
20723 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
20725 if Present (New_Assoc) then
20726 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
20727 end if;
20728 end if;
20730 -- Otherwise the associated node denotes a node. Postpone the update
20731 -- until Phase 2 when the node is replicated. Establish the following
20732 -- mapping within table NCT_Pending_Itypes:
20734 -- Old_Assoc -> (New_Type, ...)
20736 else
20737 Add_Pending_Itype (Old_Assoc, New_Itype);
20738 end if;
20740 -- Deal with the semantic fields of itypes. The fields are visited
20741 -- because they may mention entities that reside within the subtree
20742 -- being copied.
20744 Visit_Semantic_Fields (Itype);
20745 end Visit_Itype;
20747 ----------------
20748 -- Visit_List --
20749 ----------------
20751 procedure Visit_List (List : List_Id) is
20752 Elmt : Node_Id;
20754 begin
20755 -- Note that the element of a syntactic list is always a node, never
20756 -- an entity or itype, hence the call to Visit_Node.
20758 if Present (List) then
20759 Elmt := First (List);
20760 while Present (Elmt) loop
20761 Visit_Node (Elmt);
20763 Next (Elmt);
20764 end loop;
20765 end if;
20766 end Visit_List;
20768 ----------------
20769 -- Visit_Node --
20770 ----------------
20772 procedure Visit_Node (N : Node_Or_Entity_Id) is
20773 begin
20774 pragma Assert (Nkind (N) not in N_Entity);
20776 if Nkind (N) = N_Expression_With_Actions then
20777 EWA_Level := EWA_Level + 1;
20779 elsif EWA_Level > 0
20780 and then Nkind_In (N, N_Block_Statement,
20781 N_Subprogram_Body,
20782 N_Subprogram_Declaration)
20783 then
20784 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
20785 end if;
20787 Visit_Field
20788 (Field => Field1 (N),
20789 Par_Nod => N);
20791 Visit_Field
20792 (Field => Field2 (N),
20793 Par_Nod => N);
20795 Visit_Field
20796 (Field => Field3 (N),
20797 Par_Nod => N);
20799 Visit_Field
20800 (Field => Field4 (N),
20801 Par_Nod => N);
20803 Visit_Field
20804 (Field => Field5 (N),
20805 Par_Nod => N);
20807 if EWA_Level > 0
20808 and then Nkind_In (N, N_Block_Statement,
20809 N_Subprogram_Body,
20810 N_Subprogram_Declaration)
20811 then
20812 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
20814 elsif Nkind (N) = N_Expression_With_Actions then
20815 EWA_Level := EWA_Level - 1;
20816 end if;
20817 end Visit_Node;
20819 ---------------------------
20820 -- Visit_Semantic_Fields --
20821 ---------------------------
20823 procedure Visit_Semantic_Fields (Id : Entity_Id) is
20824 begin
20825 pragma Assert (Nkind (Id) in N_Entity);
20827 -- Discriminant_Constraint
20829 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20830 Visit_Field
20831 (Field => Union_Id (Discriminant_Constraint (Id)),
20832 Semantic => True);
20833 end if;
20835 -- Etype
20837 Visit_Field
20838 (Field => Union_Id (Etype (Id)),
20839 Semantic => True);
20841 -- First_Index
20842 -- Packed_Array_Impl_Type
20844 if Is_Array_Type (Id) then
20845 if Present (First_Index (Id)) then
20846 Visit_Field
20847 (Field => Union_Id (List_Containing (First_Index (Id))),
20848 Semantic => True);
20849 end if;
20851 if Is_Packed (Id) then
20852 Visit_Field
20853 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20854 Semantic => True);
20855 end if;
20856 end if;
20858 -- Scalar_Range
20860 if Is_Discrete_Type (Id) then
20861 Visit_Field
20862 (Field => Union_Id (Scalar_Range (Id)),
20863 Semantic => True);
20864 end if;
20865 end Visit_Semantic_Fields;
20867 -- Start of processing for New_Copy_Tree
20869 begin
20870 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
20871 -- shallow copies for each node within, and then updating the child and
20872 -- parent pointers accordingly. This process is straightforward, however
20873 -- the routine must deal with the following complications:
20875 -- * Entities defined within N_Expression_With_Actions nodes must be
20876 -- replicated rather than shared to avoid introducing two identical
20877 -- symbols within the same scope. Note that no other expression can
20878 -- currently define entities.
20880 -- do
20881 -- Source_Low : ...;
20882 -- Source_High : ...;
20884 -- <reference to Source_Low>
20885 -- <reference to Source_High>
20886 -- in ... end;
20888 -- New_Copy_Tree handles this case by first creating new entities
20889 -- and then updating all existing references to point to these new
20890 -- entities.
20892 -- do
20893 -- New_Low : ...;
20894 -- New_High : ...;
20896 -- <reference to New_Low>
20897 -- <reference to New_High>
20898 -- in ... end;
20900 -- * Itypes defined within the subtree must be replicated to avoid any
20901 -- dependencies on invalid or inaccessible data.
20903 -- subtype Source_Itype is ... range Source_Low .. Source_High;
20905 -- New_Copy_Tree handles this case by first creating a new itype in
20906 -- the same fashion as entities, and then updating various relevant
20907 -- constraints.
20909 -- subtype New_Itype is ... range New_Low .. New_High;
20911 -- * The Associated_Node_For_Itype field of itypes must be updated to
20912 -- reference the proper replicated entity or node.
20914 -- * Semantic fields of entities such as Etype and Scope must be
20915 -- updated to reference the proper replicated entities.
20917 -- * Semantic fields of nodes such as First_Real_Statement must be
20918 -- updated to reference the proper replicated nodes.
20920 -- To meet all these demands, routine New_Copy_Tree is split into two
20921 -- phases.
20923 -- Phase 1 traverses the tree in order to locate entities and itypes
20924 -- defined within the subtree. New entities are generated and saved in
20925 -- table NCT_New_Entities. The semantic fields of all new entities and
20926 -- itypes are then updated accordingly.
20928 -- Phase 2 traverses the tree in order to replicate each node. Various
20929 -- semantic fields of nodes and entities are updated accordingly.
20931 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
20932 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
20933 -- data inside.
20935 if NCT_Tables_In_Use then
20936 NCT_Tables_In_Use := False;
20938 NCT_New_Entities.Reset;
20939 NCT_Pending_Itypes.Reset;
20940 end if;
20942 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
20943 -- supplied by a linear entity map. The tables offer faster access to
20944 -- the same data.
20946 Build_NCT_Tables (Map);
20948 -- Execute Phase 1. Traverse the subtree and generate new entities for
20949 -- the following cases:
20951 -- * An entity defined within an N_Expression_With_Actions node
20953 -- * An itype referenced within the subtree where the associated node
20954 -- is also in the subtree.
20956 -- All new entities are accessible via table NCT_New_Entities, which
20957 -- contains mappings of the form:
20959 -- Old_Entity -> New_Entity
20960 -- Old_Itype -> New_Itype
20962 -- In addition, the associated nodes of all new itypes are mapped in
20963 -- table NCT_Pending_Itypes:
20965 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
20967 Visit_Any_Node (Source);
20969 -- Update the semantic attributes of all new entities generated during
20970 -- Phase 1 before starting Phase 2. The updates could be performed in
20971 -- routine Corresponding_Entity, however this may cause the same entity
20972 -- to be updated multiple times, effectively generating useless nodes.
20973 -- Keeping the updates separates from Phase 2 ensures that only one set
20974 -- of attributes is generated for an entity at any one time.
20976 Update_New_Entities (Map);
20978 -- Execute Phase 2. Replicate the source subtree one node at a time.
20979 -- The following transformations take place:
20981 -- * References to entities and itypes are updated to refer to the
20982 -- new entities and itypes generated during Phase 1.
20984 -- * All Associated_Node_For_Itype attributes of itypes are updated
20985 -- to refer to the new replicated Associated_Node_For_Itype.
20987 return Copy_Node_With_Replacement (Source);
20988 end New_Copy_Tree;
20990 -------------------------
20991 -- New_External_Entity --
20992 -------------------------
20994 function New_External_Entity
20995 (Kind : Entity_Kind;
20996 Scope_Id : Entity_Id;
20997 Sloc_Value : Source_Ptr;
20998 Related_Id : Entity_Id;
20999 Suffix : Character;
21000 Suffix_Index : Nat := 0;
21001 Prefix : Character := ' ') return Entity_Id
21003 N : constant Entity_Id :=
21004 Make_Defining_Identifier (Sloc_Value,
21005 New_External_Name
21006 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
21008 begin
21009 Set_Ekind (N, Kind);
21010 Set_Is_Internal (N, True);
21011 Append_Entity (N, Scope_Id);
21012 Set_Public_Status (N);
21014 if Kind in Type_Kind then
21015 Init_Size_Align (N);
21016 end if;
21018 return N;
21019 end New_External_Entity;
21021 -------------------------
21022 -- New_Internal_Entity --
21023 -------------------------
21025 function New_Internal_Entity
21026 (Kind : Entity_Kind;
21027 Scope_Id : Entity_Id;
21028 Sloc_Value : Source_Ptr;
21029 Id_Char : Character) return Entity_Id
21031 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
21033 begin
21034 Set_Ekind (N, Kind);
21035 Set_Is_Internal (N, True);
21036 Append_Entity (N, Scope_Id);
21038 if Kind in Type_Kind then
21039 Init_Size_Align (N);
21040 end if;
21042 return N;
21043 end New_Internal_Entity;
21045 -----------------
21046 -- Next_Actual --
21047 -----------------
21049 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
21050 Par : constant Node_Id := Parent (Actual_Id);
21051 N : Node_Id;
21053 begin
21054 -- If we are pointing at a positional parameter, it is a member of a
21055 -- node list (the list of parameters), and the next parameter is the
21056 -- next node on the list, unless we hit a parameter association, then
21057 -- we shift to using the chain whose head is the First_Named_Actual in
21058 -- the parent, and then is threaded using the Next_Named_Actual of the
21059 -- Parameter_Association. All this fiddling is because the original node
21060 -- list is in the textual call order, and what we need is the
21061 -- declaration order.
21063 if Is_List_Member (Actual_Id) then
21064 N := Next (Actual_Id);
21066 if Nkind (N) = N_Parameter_Association then
21068 -- In case of a build-in-place call, the call will no longer be a
21069 -- call; it will have been rewritten.
21071 if Nkind_In (Par, N_Entry_Call_Statement,
21072 N_Function_Call,
21073 N_Procedure_Call_Statement)
21074 then
21075 return First_Named_Actual (Par);
21077 -- In case of a call rewritten in GNATprove mode while "inlining
21078 -- for proof" go to the original call.
21080 elsif Nkind (Par) = N_Null_Statement then
21081 pragma Assert
21082 (GNATprove_Mode
21083 and then
21084 Nkind (Original_Node (Par)) in N_Subprogram_Call);
21086 return First_Named_Actual (Original_Node (Par));
21087 else
21088 return Empty;
21089 end if;
21090 else
21091 return N;
21092 end if;
21094 else
21095 return Next_Named_Actual (Parent (Actual_Id));
21096 end if;
21097 end Next_Actual;
21099 procedure Next_Actual (Actual_Id : in out Node_Id) is
21100 begin
21101 Actual_Id := Next_Actual (Actual_Id);
21102 end Next_Actual;
21104 -----------------
21105 -- Next_Global --
21106 -----------------
21108 function Next_Global (Node : Node_Id) return Node_Id is
21109 begin
21110 -- The global item may either be in a list, or by itself, in which case
21111 -- there is no next global item with the same mode.
21113 if Is_List_Member (Node) then
21114 return Next (Node);
21115 else
21116 return Empty;
21117 end if;
21118 end Next_Global;
21120 procedure Next_Global (Node : in out Node_Id) is
21121 begin
21122 Node := Next_Global (Node);
21123 end Next_Global;
21125 ----------------------------------
21126 -- New_Requires_Transient_Scope --
21127 ----------------------------------
21129 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21130 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
21131 -- This is called for untagged records and protected types, with
21132 -- nondefaulted discriminants. Returns True if the size of function
21133 -- results is known at the call site, False otherwise. Returns False
21134 -- if there is a variant part that depends on the discriminants of
21135 -- this type, or if there is an array constrained by the discriminants
21136 -- of this type. ???Currently, this is overly conservative (the array
21137 -- could be nested inside some other record that is constrained by
21138 -- nondiscriminants). That is, the recursive calls are too conservative.
21140 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
21141 -- Returns True if Typ is a nonlimited record with defaulted
21142 -- discriminants whose max size makes it unsuitable for allocating on
21143 -- the primary stack.
21145 ------------------------------
21146 -- Caller_Known_Size_Record --
21147 ------------------------------
21149 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
21150 pragma Assert (Typ = Underlying_Type (Typ));
21152 begin
21153 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
21154 return False;
21155 end if;
21157 declare
21158 Comp : Entity_Id;
21160 begin
21161 Comp := First_Entity (Typ);
21162 while Present (Comp) loop
21164 -- Only look at E_Component entities. No need to look at
21165 -- E_Discriminant entities, and we must ignore internal
21166 -- subtypes generated for constrained components.
21168 if Ekind (Comp) = E_Component then
21169 declare
21170 Comp_Type : constant Entity_Id :=
21171 Underlying_Type (Etype (Comp));
21173 begin
21174 if Is_Record_Type (Comp_Type)
21175 or else
21176 Is_Protected_Type (Comp_Type)
21177 then
21178 if not Caller_Known_Size_Record (Comp_Type) then
21179 return False;
21180 end if;
21182 elsif Is_Array_Type (Comp_Type) then
21183 if Size_Depends_On_Discriminant (Comp_Type) then
21184 return False;
21185 end if;
21186 end if;
21187 end;
21188 end if;
21190 Next_Entity (Comp);
21191 end loop;
21192 end;
21194 return True;
21195 end Caller_Known_Size_Record;
21197 ------------------------------
21198 -- Large_Max_Size_Mutable --
21199 ------------------------------
21201 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
21202 pragma Assert (Typ = Underlying_Type (Typ));
21204 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
21205 -- Returns true if the discrete type T has a large range
21207 ----------------------------
21208 -- Is_Large_Discrete_Type --
21209 ----------------------------
21211 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
21212 Threshold : constant Int := 16;
21213 -- Arbitrary threshold above which we consider it "large". We want
21214 -- a fairly large threshold, because these large types really
21215 -- shouldn't have default discriminants in the first place, in
21216 -- most cases.
21218 begin
21219 return UI_To_Int (RM_Size (T)) > Threshold;
21220 end Is_Large_Discrete_Type;
21222 -- Start of processing for Large_Max_Size_Mutable
21224 begin
21225 if Is_Record_Type (Typ)
21226 and then not Is_Limited_View (Typ)
21227 and then Has_Defaulted_Discriminants (Typ)
21228 then
21229 -- Loop through the components, looking for an array whose upper
21230 -- bound(s) depends on discriminants, where both the subtype of
21231 -- the discriminant and the index subtype are too large.
21233 declare
21234 Comp : Entity_Id;
21236 begin
21237 Comp := First_Entity (Typ);
21238 while Present (Comp) loop
21239 if Ekind (Comp) = E_Component then
21240 declare
21241 Comp_Type : constant Entity_Id :=
21242 Underlying_Type (Etype (Comp));
21244 Hi : Node_Id;
21245 Indx : Node_Id;
21246 Ityp : Entity_Id;
21248 begin
21249 if Is_Array_Type (Comp_Type) then
21250 Indx := First_Index (Comp_Type);
21252 while Present (Indx) loop
21253 Ityp := Etype (Indx);
21254 Hi := Type_High_Bound (Ityp);
21256 if Nkind (Hi) = N_Identifier
21257 and then Ekind (Entity (Hi)) = E_Discriminant
21258 and then Is_Large_Discrete_Type (Ityp)
21259 and then Is_Large_Discrete_Type
21260 (Etype (Entity (Hi)))
21261 then
21262 return True;
21263 end if;
21265 Next_Index (Indx);
21266 end loop;
21267 end if;
21268 end;
21269 end if;
21271 Next_Entity (Comp);
21272 end loop;
21273 end;
21274 end if;
21276 return False;
21277 end Large_Max_Size_Mutable;
21279 -- Local declarations
21281 Typ : constant Entity_Id := Underlying_Type (Id);
21283 -- Start of processing for New_Requires_Transient_Scope
21285 begin
21286 -- This is a private type which is not completed yet. This can only
21287 -- happen in a default expression (of a formal parameter or of a
21288 -- record component). Do not expand transient scope in this case.
21290 if No (Typ) then
21291 return False;
21293 -- Do not expand transient scope for non-existent procedure return or
21294 -- string literal types.
21296 elsif Typ = Standard_Void_Type
21297 or else Ekind (Typ) = E_String_Literal_Subtype
21298 then
21299 return False;
21301 -- If Typ is a generic formal incomplete type, then we want to look at
21302 -- the actual type.
21304 elsif Ekind (Typ) = E_Record_Subtype
21305 and then Present (Cloned_Subtype (Typ))
21306 then
21307 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
21309 -- Functions returning specific tagged types may dispatch on result, so
21310 -- their returned value is allocated on the secondary stack, even in the
21311 -- definite case. We must treat nondispatching functions the same way,
21312 -- because access-to-function types can point at both, so the calling
21313 -- conventions must be compatible. Is_Tagged_Type includes controlled
21314 -- types and class-wide types. Controlled type temporaries need
21315 -- finalization.
21317 -- ???It's not clear why we need to return noncontrolled types with
21318 -- controlled components on the secondary stack.
21320 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
21321 return True;
21323 -- Untagged definite subtypes are known size. This includes all
21324 -- elementary [sub]types. Tasks are known size even if they have
21325 -- discriminants. So we return False here, with one exception:
21326 -- For a type like:
21327 -- type T (Last : Natural := 0) is
21328 -- X : String (1 .. Last);
21329 -- end record;
21330 -- we return True. That's because for "P(F(...));", where F returns T,
21331 -- we don't know the size of the result at the call site, so if we
21332 -- allocated it on the primary stack, we would have to allocate the
21333 -- maximum size, which is way too big.
21335 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
21336 return Large_Max_Size_Mutable (Typ);
21338 -- Indefinite (discriminated) untagged record or protected type
21340 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
21341 return not Caller_Known_Size_Record (Typ);
21343 -- Unconstrained array
21345 else
21346 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
21347 return True;
21348 end if;
21349 end New_Requires_Transient_Scope;
21351 --------------------------
21352 -- No_Heap_Finalization --
21353 --------------------------
21355 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
21356 begin
21357 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
21358 and then Is_Library_Level_Entity (Typ)
21359 then
21360 -- A global No_Heap_Finalization pragma applies to all library-level
21361 -- named access-to-object types.
21363 if Present (No_Heap_Finalization_Pragma) then
21364 return True;
21366 -- The library-level named access-to-object type itself is subject to
21367 -- pragma No_Heap_Finalization.
21369 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
21370 return True;
21371 end if;
21372 end if;
21374 return False;
21375 end No_Heap_Finalization;
21377 -----------------------
21378 -- Normalize_Actuals --
21379 -----------------------
21381 -- Chain actuals according to formals of subprogram. If there are no named
21382 -- associations, the chain is simply the list of Parameter Associations,
21383 -- since the order is the same as the declaration order. If there are named
21384 -- associations, then the First_Named_Actual field in the N_Function_Call
21385 -- or N_Procedure_Call_Statement node points to the Parameter_Association
21386 -- node for the parameter that comes first in declaration order. The
21387 -- remaining named parameters are then chained in declaration order using
21388 -- Next_Named_Actual.
21390 -- This routine also verifies that the number of actuals is compatible with
21391 -- the number and default values of formals, but performs no type checking
21392 -- (type checking is done by the caller).
21394 -- If the matching succeeds, Success is set to True and the caller proceeds
21395 -- with type-checking. If the match is unsuccessful, then Success is set to
21396 -- False, and the caller attempts a different interpretation, if there is
21397 -- one.
21399 -- If the flag Report is on, the call is not overloaded, and a failure to
21400 -- match can be reported here, rather than in the caller.
21402 procedure Normalize_Actuals
21403 (N : Node_Id;
21404 S : Entity_Id;
21405 Report : Boolean;
21406 Success : out Boolean)
21408 Actuals : constant List_Id := Parameter_Associations (N);
21409 Actual : Node_Id := Empty;
21410 Formal : Entity_Id;
21411 Last : Node_Id := Empty;
21412 First_Named : Node_Id := Empty;
21413 Found : Boolean;
21415 Formals_To_Match : Integer := 0;
21416 Actuals_To_Match : Integer := 0;
21418 procedure Chain (A : Node_Id);
21419 -- Add named actual at the proper place in the list, using the
21420 -- Next_Named_Actual link.
21422 function Reporting return Boolean;
21423 -- Determines if an error is to be reported. To report an error, we
21424 -- need Report to be True, and also we do not report errors caused
21425 -- by calls to init procs that occur within other init procs. Such
21426 -- errors must always be cascaded errors, since if all the types are
21427 -- declared correctly, the compiler will certainly build decent calls.
21429 -----------
21430 -- Chain --
21431 -----------
21433 procedure Chain (A : Node_Id) is
21434 begin
21435 if No (Last) then
21437 -- Call node points to first actual in list
21439 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
21441 else
21442 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
21443 end if;
21445 Last := A;
21446 Set_Next_Named_Actual (Last, Empty);
21447 end Chain;
21449 ---------------
21450 -- Reporting --
21451 ---------------
21453 function Reporting return Boolean is
21454 begin
21455 if not Report then
21456 return False;
21458 elsif not Within_Init_Proc then
21459 return True;
21461 elsif Is_Init_Proc (Entity (Name (N))) then
21462 return False;
21464 else
21465 return True;
21466 end if;
21467 end Reporting;
21469 -- Start of processing for Normalize_Actuals
21471 begin
21472 if Is_Access_Type (S) then
21474 -- The name in the call is a function call that returns an access
21475 -- to subprogram. The designated type has the list of formals.
21477 Formal := First_Formal (Designated_Type (S));
21478 else
21479 Formal := First_Formal (S);
21480 end if;
21482 while Present (Formal) loop
21483 Formals_To_Match := Formals_To_Match + 1;
21484 Next_Formal (Formal);
21485 end loop;
21487 -- Find if there is a named association, and verify that no positional
21488 -- associations appear after named ones.
21490 if Present (Actuals) then
21491 Actual := First (Actuals);
21492 end if;
21494 while Present (Actual)
21495 and then Nkind (Actual) /= N_Parameter_Association
21496 loop
21497 Actuals_To_Match := Actuals_To_Match + 1;
21498 Next (Actual);
21499 end loop;
21501 if No (Actual) and Actuals_To_Match = Formals_To_Match then
21503 -- Most common case: positional notation, no defaults
21505 Success := True;
21506 return;
21508 elsif Actuals_To_Match > Formals_To_Match then
21510 -- Too many actuals: will not work
21512 if Reporting then
21513 if Is_Entity_Name (Name (N)) then
21514 Error_Msg_N ("too many arguments in call to&", Name (N));
21515 else
21516 Error_Msg_N ("too many arguments in call", N);
21517 end if;
21518 end if;
21520 Success := False;
21521 return;
21522 end if;
21524 First_Named := Actual;
21526 while Present (Actual) loop
21527 if Nkind (Actual) /= N_Parameter_Association then
21528 Error_Msg_N
21529 ("positional parameters not allowed after named ones", Actual);
21530 Success := False;
21531 return;
21533 else
21534 Actuals_To_Match := Actuals_To_Match + 1;
21535 end if;
21537 Next (Actual);
21538 end loop;
21540 if Present (Actuals) then
21541 Actual := First (Actuals);
21542 end if;
21544 Formal := First_Formal (S);
21545 while Present (Formal) loop
21547 -- Match the formals in order. If the corresponding actual is
21548 -- positional, nothing to do. Else scan the list of named actuals
21549 -- to find the one with the right name.
21551 if Present (Actual)
21552 and then Nkind (Actual) /= N_Parameter_Association
21553 then
21554 Next (Actual);
21555 Actuals_To_Match := Actuals_To_Match - 1;
21556 Formals_To_Match := Formals_To_Match - 1;
21558 else
21559 -- For named parameters, search the list of actuals to find
21560 -- one that matches the next formal name.
21562 Actual := First_Named;
21563 Found := False;
21564 while Present (Actual) loop
21565 if Chars (Selector_Name (Actual)) = Chars (Formal) then
21566 Found := True;
21567 Chain (Actual);
21568 Actuals_To_Match := Actuals_To_Match - 1;
21569 Formals_To_Match := Formals_To_Match - 1;
21570 exit;
21571 end if;
21573 Next (Actual);
21574 end loop;
21576 if not Found then
21577 if Ekind (Formal) /= E_In_Parameter
21578 or else No (Default_Value (Formal))
21579 then
21580 if Reporting then
21581 if (Comes_From_Source (S)
21582 or else Sloc (S) = Standard_Location)
21583 and then Is_Overloadable (S)
21584 then
21585 if No (Actuals)
21586 and then
21587 Nkind_In (Parent (N), N_Procedure_Call_Statement,
21588 N_Function_Call,
21589 N_Parameter_Association)
21590 and then Ekind (S) /= E_Function
21591 then
21592 Set_Etype (N, Etype (S));
21594 else
21595 Error_Msg_Name_1 := Chars (S);
21596 Error_Msg_Sloc := Sloc (S);
21597 Error_Msg_NE
21598 ("missing argument for parameter & "
21599 & "in call to % declared #", N, Formal);
21600 end if;
21602 elsif Is_Overloadable (S) then
21603 Error_Msg_Name_1 := Chars (S);
21605 -- Point to type derivation that generated the
21606 -- operation.
21608 Error_Msg_Sloc := Sloc (Parent (S));
21610 Error_Msg_NE
21611 ("missing argument for parameter & "
21612 & "in call to % (inherited) #", N, Formal);
21614 else
21615 Error_Msg_NE
21616 ("missing argument for parameter &", N, Formal);
21617 end if;
21618 end if;
21620 Success := False;
21621 return;
21623 else
21624 Formals_To_Match := Formals_To_Match - 1;
21625 end if;
21626 end if;
21627 end if;
21629 Next_Formal (Formal);
21630 end loop;
21632 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
21633 Success := True;
21634 return;
21636 else
21637 if Reporting then
21639 -- Find some superfluous named actual that did not get
21640 -- attached to the list of associations.
21642 Actual := First (Actuals);
21643 while Present (Actual) loop
21644 if Nkind (Actual) = N_Parameter_Association
21645 and then Actual /= Last
21646 and then No (Next_Named_Actual (Actual))
21647 then
21648 -- A validity check may introduce a copy of a call that
21649 -- includes an extra actual (for example for an unrelated
21650 -- accessibility check). Check that the extra actual matches
21651 -- some extra formal, which must exist already because
21652 -- subprogram must be frozen at this point.
21654 if Present (Extra_Formals (S))
21655 and then not Comes_From_Source (Actual)
21656 and then Nkind (Actual) = N_Parameter_Association
21657 and then Chars (Extra_Formals (S)) =
21658 Chars (Selector_Name (Actual))
21659 then
21660 null;
21661 else
21662 Error_Msg_N
21663 ("unmatched actual & in call", Selector_Name (Actual));
21664 exit;
21665 end if;
21666 end if;
21668 Next (Actual);
21669 end loop;
21670 end if;
21672 Success := False;
21673 return;
21674 end if;
21675 end Normalize_Actuals;
21677 --------------------------------
21678 -- Note_Possible_Modification --
21679 --------------------------------
21681 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
21682 Modification_Comes_From_Source : constant Boolean :=
21683 Comes_From_Source (Parent (N));
21685 Ent : Entity_Id;
21686 Exp : Node_Id;
21688 begin
21689 -- Loop to find referenced entity, if there is one
21691 Exp := N;
21692 loop
21693 Ent := Empty;
21695 if Is_Entity_Name (Exp) then
21696 Ent := Entity (Exp);
21698 -- If the entity is missing, it is an undeclared identifier,
21699 -- and there is nothing to annotate.
21701 if No (Ent) then
21702 return;
21703 end if;
21705 elsif Nkind (Exp) = N_Explicit_Dereference then
21706 declare
21707 P : constant Node_Id := Prefix (Exp);
21709 begin
21710 -- In formal verification mode, keep track of all reads and
21711 -- writes through explicit dereferences.
21713 if GNATprove_Mode then
21714 SPARK_Specific.Generate_Dereference (N, 'm');
21715 end if;
21717 if Nkind (P) = N_Selected_Component
21718 and then Present (Entry_Formal (Entity (Selector_Name (P))))
21719 then
21720 -- Case of a reference to an entry formal
21722 Ent := Entry_Formal (Entity (Selector_Name (P)));
21724 elsif Nkind (P) = N_Identifier
21725 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
21726 and then Present (Expression (Parent (Entity (P))))
21727 and then Nkind (Expression (Parent (Entity (P)))) =
21728 N_Reference
21729 then
21730 -- Case of a reference to a value on which side effects have
21731 -- been removed.
21733 Exp := Prefix (Expression (Parent (Entity (P))));
21734 goto Continue;
21736 else
21737 return;
21738 end if;
21739 end;
21741 elsif Nkind_In (Exp, N_Type_Conversion,
21742 N_Unchecked_Type_Conversion)
21743 then
21744 Exp := Expression (Exp);
21745 goto Continue;
21747 elsif Nkind_In (Exp, N_Slice,
21748 N_Indexed_Component,
21749 N_Selected_Component)
21750 then
21751 -- Special check, if the prefix is an access type, then return
21752 -- since we are modifying the thing pointed to, not the prefix.
21753 -- When we are expanding, most usually the prefix is replaced
21754 -- by an explicit dereference, and this test is not needed, but
21755 -- in some cases (notably -gnatc mode and generics) when we do
21756 -- not do full expansion, we need this special test.
21758 if Is_Access_Type (Etype (Prefix (Exp))) then
21759 return;
21761 -- Otherwise go to prefix and keep going
21763 else
21764 Exp := Prefix (Exp);
21765 goto Continue;
21766 end if;
21768 -- All other cases, not a modification
21770 else
21771 return;
21772 end if;
21774 -- Now look for entity being referenced
21776 if Present (Ent) then
21777 if Is_Object (Ent) then
21778 if Comes_From_Source (Exp)
21779 or else Modification_Comes_From_Source
21780 then
21781 -- Give warning if pragma unmodified is given and we are
21782 -- sure this is a modification.
21784 if Has_Pragma_Unmodified (Ent) and then Sure then
21786 -- Note that the entity may be present only as a result
21787 -- of pragma Unused.
21789 if Has_Pragma_Unused (Ent) then
21790 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
21791 else
21792 Error_Msg_NE
21793 ("??pragma Unmodified given for &!", N, Ent);
21794 end if;
21795 end if;
21797 Set_Never_Set_In_Source (Ent, False);
21798 end if;
21800 Set_Is_True_Constant (Ent, False);
21801 Set_Current_Value (Ent, Empty);
21802 Set_Is_Known_Null (Ent, False);
21804 if not Can_Never_Be_Null (Ent) then
21805 Set_Is_Known_Non_Null (Ent, False);
21806 end if;
21808 -- Follow renaming chain
21810 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
21811 and then Present (Renamed_Object (Ent))
21812 then
21813 Exp := Renamed_Object (Ent);
21815 -- If the entity is the loop variable in an iteration over
21816 -- a container, retrieve container expression to indicate
21817 -- possible modification.
21819 if Present (Related_Expression (Ent))
21820 and then Nkind (Parent (Related_Expression (Ent))) =
21821 N_Iterator_Specification
21822 then
21823 Exp := Original_Node (Related_Expression (Ent));
21824 end if;
21826 goto Continue;
21828 -- The expression may be the renaming of a subcomponent of an
21829 -- array or container. The assignment to the subcomponent is
21830 -- a modification of the container.
21832 elsif Comes_From_Source (Original_Node (Exp))
21833 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
21834 N_Indexed_Component)
21835 then
21836 Exp := Prefix (Original_Node (Exp));
21837 goto Continue;
21838 end if;
21840 -- Generate a reference only if the assignment comes from
21841 -- source. This excludes, for example, calls to a dispatching
21842 -- assignment operation when the left-hand side is tagged. In
21843 -- GNATprove mode, we need those references also on generated
21844 -- code, as these are used to compute the local effects of
21845 -- subprograms.
21847 if Modification_Comes_From_Source or GNATprove_Mode then
21848 Generate_Reference (Ent, Exp, 'm');
21850 -- If the target of the assignment is the bound variable
21851 -- in an iterator, indicate that the corresponding array
21852 -- or container is also modified.
21854 if Ada_Version >= Ada_2012
21855 and then Nkind (Parent (Ent)) = N_Iterator_Specification
21856 then
21857 declare
21858 Domain : constant Node_Id := Name (Parent (Ent));
21860 begin
21861 -- TBD : in the full version of the construct, the
21862 -- domain of iteration can be given by an expression.
21864 if Is_Entity_Name (Domain) then
21865 Generate_Reference (Entity (Domain), Exp, 'm');
21866 Set_Is_True_Constant (Entity (Domain), False);
21867 Set_Never_Set_In_Source (Entity (Domain), False);
21868 end if;
21869 end;
21870 end if;
21871 end if;
21872 end if;
21874 Kill_Checks (Ent);
21876 -- If we are sure this is a modification from source, and we know
21877 -- this modifies a constant, then give an appropriate warning.
21879 if Sure
21880 and then Modification_Comes_From_Source
21881 and then Overlays_Constant (Ent)
21882 and then Address_Clause_Overlay_Warnings
21883 then
21884 declare
21885 Addr : constant Node_Id := Address_Clause (Ent);
21886 O_Ent : Entity_Id;
21887 Off : Boolean;
21889 begin
21890 Find_Overlaid_Entity (Addr, O_Ent, Off);
21892 Error_Msg_Sloc := Sloc (Addr);
21893 Error_Msg_NE
21894 ("??constant& may be modified via address clause#",
21895 N, O_Ent);
21896 end;
21897 end if;
21899 return;
21900 end if;
21902 <<Continue>>
21903 null;
21904 end loop;
21905 end Note_Possible_Modification;
21907 -----------------
21908 -- Null_Status --
21909 -----------------
21911 function Null_Status (N : Node_Id) return Null_Status_Kind is
21912 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
21913 -- Determine whether definition Def carries a null exclusion
21915 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
21916 -- Determine the null status of arbitrary entity Id
21918 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
21919 -- Determine the null status of type Typ
21921 ---------------------------
21922 -- Is_Null_Excluding_Def --
21923 ---------------------------
21925 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
21926 begin
21927 return
21928 Nkind_In (Def, N_Access_Definition,
21929 N_Access_Function_Definition,
21930 N_Access_Procedure_Definition,
21931 N_Access_To_Object_Definition,
21932 N_Component_Definition,
21933 N_Derived_Type_Definition)
21934 and then Null_Exclusion_Present (Def);
21935 end Is_Null_Excluding_Def;
21937 ---------------------------
21938 -- Null_Status_Of_Entity --
21939 ---------------------------
21941 function Null_Status_Of_Entity
21942 (Id : Entity_Id) return Null_Status_Kind
21944 Decl : constant Node_Id := Declaration_Node (Id);
21945 Def : Node_Id;
21947 begin
21948 -- The value of an imported or exported entity may be set externally
21949 -- regardless of a null exclusion. As a result, the value cannot be
21950 -- determined statically.
21952 if Is_Imported (Id) or else Is_Exported (Id) then
21953 return Unknown;
21955 elsif Nkind_In (Decl, N_Component_Declaration,
21956 N_Discriminant_Specification,
21957 N_Formal_Object_Declaration,
21958 N_Object_Declaration,
21959 N_Object_Renaming_Declaration,
21960 N_Parameter_Specification)
21961 then
21962 -- A component declaration yields a non-null value when either
21963 -- its component definition or access definition carries a null
21964 -- exclusion.
21966 if Nkind (Decl) = N_Component_Declaration then
21967 Def := Component_Definition (Decl);
21969 if Is_Null_Excluding_Def (Def) then
21970 return Is_Non_Null;
21971 end if;
21973 Def := Access_Definition (Def);
21975 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21976 return Is_Non_Null;
21977 end if;
21979 -- A formal object declaration yields a non-null value if its
21980 -- access definition carries a null exclusion. If the object is
21981 -- default initialized, then the value depends on the expression.
21983 elsif Nkind (Decl) = N_Formal_Object_Declaration then
21984 Def := Access_Definition (Decl);
21986 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21987 return Is_Non_Null;
21988 end if;
21990 -- A constant may yield a null or non-null value depending on its
21991 -- initialization expression.
21993 elsif Ekind (Id) = E_Constant then
21994 return Null_Status (Constant_Value (Id));
21996 -- The construct yields a non-null value when it has a null
21997 -- exclusion.
21999 elsif Null_Exclusion_Present (Decl) then
22000 return Is_Non_Null;
22002 -- An object renaming declaration yields a non-null value if its
22003 -- access definition carries a null exclusion. Otherwise the value
22004 -- depends on the renamed name.
22006 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
22007 Def := Access_Definition (Decl);
22009 if Present (Def) and then Is_Null_Excluding_Def (Def) then
22010 return Is_Non_Null;
22012 else
22013 return Null_Status (Name (Decl));
22014 end if;
22015 end if;
22016 end if;
22018 -- At this point the declaration of the entity does not carry a null
22019 -- exclusion and lacks an initialization expression. Check the status
22020 -- of its type.
22022 return Null_Status_Of_Type (Etype (Id));
22023 end Null_Status_Of_Entity;
22025 -------------------------
22026 -- Null_Status_Of_Type --
22027 -------------------------
22029 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
22030 Curr : Entity_Id;
22031 Decl : Node_Id;
22033 begin
22034 -- Traverse the type chain looking for types with null exclusion
22036 Curr := Typ;
22037 while Present (Curr) and then Etype (Curr) /= Curr loop
22038 Decl := Parent (Curr);
22040 -- Guard against itypes which do not always have declarations. A
22041 -- type yields a non-null value if it carries a null exclusion.
22043 if Present (Decl) then
22044 if Nkind (Decl) = N_Full_Type_Declaration
22045 and then Is_Null_Excluding_Def (Type_Definition (Decl))
22046 then
22047 return Is_Non_Null;
22049 elsif Nkind (Decl) = N_Subtype_Declaration
22050 and then Null_Exclusion_Present (Decl)
22051 then
22052 return Is_Non_Null;
22053 end if;
22054 end if;
22056 Curr := Etype (Curr);
22057 end loop;
22059 -- The type chain does not contain any null excluding types
22061 return Unknown;
22062 end Null_Status_Of_Type;
22064 -- Start of processing for Null_Status
22066 begin
22067 -- An allocator always creates a non-null value
22069 if Nkind (N) = N_Allocator then
22070 return Is_Non_Null;
22072 -- Taking the 'Access of something yields a non-null value
22074 elsif Nkind (N) = N_Attribute_Reference
22075 and then Nam_In (Attribute_Name (N), Name_Access,
22076 Name_Unchecked_Access,
22077 Name_Unrestricted_Access)
22078 then
22079 return Is_Non_Null;
22081 -- "null" yields null
22083 elsif Nkind (N) = N_Null then
22084 return Is_Null;
22086 -- Check the status of the operand of a type conversion
22088 elsif Nkind (N) = N_Type_Conversion then
22089 return Null_Status (Expression (N));
22091 -- The input denotes a reference to an entity. Determine whether the
22092 -- entity or its type yields a null or non-null value.
22094 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22095 return Null_Status_Of_Entity (Entity (N));
22096 end if;
22098 -- Otherwise it is not possible to determine the null status of the
22099 -- subexpression at compile time without resorting to simple flow
22100 -- analysis.
22102 return Unknown;
22103 end Null_Status;
22105 --------------------------------------
22106 -- Null_To_Null_Address_Convert_OK --
22107 --------------------------------------
22109 function Null_To_Null_Address_Convert_OK
22110 (N : Node_Id;
22111 Typ : Entity_Id := Empty) return Boolean
22113 begin
22114 if not Relaxed_RM_Semantics then
22115 return False;
22116 end if;
22118 if Nkind (N) = N_Null then
22119 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
22121 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
22122 then
22123 declare
22124 L : constant Node_Id := Left_Opnd (N);
22125 R : constant Node_Id := Right_Opnd (N);
22127 begin
22128 -- We check the Etype of the complementary operand since the
22129 -- N_Null node is not decorated at this stage.
22131 return
22132 ((Nkind (L) = N_Null
22133 and then Is_Descendant_Of_Address (Etype (R)))
22134 or else
22135 (Nkind (R) = N_Null
22136 and then Is_Descendant_Of_Address (Etype (L))));
22137 end;
22138 end if;
22140 return False;
22141 end Null_To_Null_Address_Convert_OK;
22143 ---------------------------------
22144 -- Number_Of_Elements_In_Array --
22145 ---------------------------------
22147 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
22148 Indx : Node_Id;
22149 Typ : Entity_Id;
22150 Low : Node_Id;
22151 High : Node_Id;
22152 Num : Int := 1;
22154 begin
22155 pragma Assert (Is_Array_Type (T));
22157 Indx := First_Index (T);
22158 while Present (Indx) loop
22159 Typ := Underlying_Type (Etype (Indx));
22161 -- Never look at junk bounds of a generic type
22163 if Is_Generic_Type (Typ) then
22164 return 0;
22165 end if;
22167 -- Check the array bounds are known at compile time and return zero
22168 -- if they are not.
22170 Low := Type_Low_Bound (Typ);
22171 High := Type_High_Bound (Typ);
22173 if not Compile_Time_Known_Value (Low) then
22174 return 0;
22175 elsif not Compile_Time_Known_Value (High) then
22176 return 0;
22177 else
22178 Num :=
22179 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
22180 end if;
22182 Next_Index (Indx);
22183 end loop;
22185 return Num;
22186 end Number_Of_Elements_In_Array;
22188 -------------------------
22189 -- Object_Access_Level --
22190 -------------------------
22192 -- Returns the static accessibility level of the view denoted by Obj. Note
22193 -- that the value returned is the result of a call to Scope_Depth. Only
22194 -- scope depths associated with dynamic scopes can actually be returned.
22195 -- Since only relative levels matter for accessibility checking, the fact
22196 -- that the distance between successive levels of accessibility is not
22197 -- always one is immaterial (invariant: if level(E2) is deeper than
22198 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
22200 function Object_Access_Level (Obj : Node_Id) return Uint is
22201 function Is_Interface_Conversion (N : Node_Id) return Boolean;
22202 -- Determine whether N is a construct of the form
22203 -- Some_Type (Operand._tag'Address)
22204 -- This construct appears in the context of dispatching calls.
22206 function Reference_To (Obj : Node_Id) return Node_Id;
22207 -- An explicit dereference is created when removing side effects from
22208 -- expressions for constraint checking purposes. In this case a local
22209 -- access type is created for it. The correct access level is that of
22210 -- the original source node. We detect this case by noting that the
22211 -- prefix of the dereference is created by an object declaration whose
22212 -- initial expression is a reference.
22214 -----------------------------
22215 -- Is_Interface_Conversion --
22216 -----------------------------
22218 function Is_Interface_Conversion (N : Node_Id) return Boolean is
22219 begin
22220 return Nkind (N) = N_Unchecked_Type_Conversion
22221 and then Nkind (Expression (N)) = N_Attribute_Reference
22222 and then Attribute_Name (Expression (N)) = Name_Address;
22223 end Is_Interface_Conversion;
22225 ------------------
22226 -- Reference_To --
22227 ------------------
22229 function Reference_To (Obj : Node_Id) return Node_Id is
22230 Pref : constant Node_Id := Prefix (Obj);
22231 begin
22232 if Is_Entity_Name (Pref)
22233 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
22234 and then Present (Expression (Parent (Entity (Pref))))
22235 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
22236 then
22237 return (Prefix (Expression (Parent (Entity (Pref)))));
22238 else
22239 return Empty;
22240 end if;
22241 end Reference_To;
22243 -- Local variables
22245 E : Entity_Id;
22247 -- Start of processing for Object_Access_Level
22249 begin
22250 if Nkind (Obj) = N_Defining_Identifier
22251 or else Is_Entity_Name (Obj)
22252 then
22253 if Nkind (Obj) = N_Defining_Identifier then
22254 E := Obj;
22255 else
22256 E := Entity (Obj);
22257 end if;
22259 if Is_Prival (E) then
22260 E := Prival_Link (E);
22261 end if;
22263 -- If E is a type then it denotes a current instance. For this case
22264 -- we add one to the normal accessibility level of the type to ensure
22265 -- that current instances are treated as always being deeper than
22266 -- than the level of any visible named access type (see 3.10.2(21)).
22268 if Is_Type (E) then
22269 return Type_Access_Level (E) + 1;
22271 elsif Present (Renamed_Object (E)) then
22272 return Object_Access_Level (Renamed_Object (E));
22274 -- Similarly, if E is a component of the current instance of a
22275 -- protected type, any instance of it is assumed to be at a deeper
22276 -- level than the type. For a protected object (whose type is an
22277 -- anonymous protected type) its components are at the same level
22278 -- as the type itself.
22280 elsif not Is_Overloadable (E)
22281 and then Ekind (Scope (E)) = E_Protected_Type
22282 and then Comes_From_Source (Scope (E))
22283 then
22284 return Type_Access_Level (Scope (E)) + 1;
22286 else
22287 -- Aliased formals of functions take their access level from the
22288 -- point of call, i.e. require a dynamic check. For static check
22289 -- purposes, this is smaller than the level of the subprogram
22290 -- itself. For procedures the aliased makes no difference.
22292 if Is_Formal (E)
22293 and then Is_Aliased (E)
22294 and then Ekind (Scope (E)) = E_Function
22295 then
22296 return Type_Access_Level (Etype (E));
22298 else
22299 return Scope_Depth (Enclosing_Dynamic_Scope (E));
22300 end if;
22301 end if;
22303 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
22304 if Is_Access_Type (Etype (Prefix (Obj))) then
22305 return Type_Access_Level (Etype (Prefix (Obj)));
22306 else
22307 return Object_Access_Level (Prefix (Obj));
22308 end if;
22310 elsif Nkind (Obj) = N_Explicit_Dereference then
22312 -- If the prefix is a selected access discriminant then we make a
22313 -- recursive call on the prefix, which will in turn check the level
22314 -- of the prefix object of the selected discriminant.
22316 -- In Ada 2012, if the discriminant has implicit dereference and
22317 -- the context is a selected component, treat this as an object of
22318 -- unknown scope (see below). This is necessary in compile-only mode;
22319 -- otherwise expansion will already have transformed the prefix into
22320 -- a temporary.
22322 if Nkind (Prefix (Obj)) = N_Selected_Component
22323 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
22324 and then
22325 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
22326 and then
22327 (not Has_Implicit_Dereference
22328 (Entity (Selector_Name (Prefix (Obj))))
22329 or else Nkind (Parent (Obj)) /= N_Selected_Component)
22330 then
22331 return Object_Access_Level (Prefix (Obj));
22333 -- Detect an interface conversion in the context of a dispatching
22334 -- call. Use the original form of the conversion to find the access
22335 -- level of the operand.
22337 elsif Is_Interface (Etype (Obj))
22338 and then Is_Interface_Conversion (Prefix (Obj))
22339 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
22340 then
22341 return Object_Access_Level (Original_Node (Obj));
22343 elsif not Comes_From_Source (Obj) then
22344 declare
22345 Ref : constant Node_Id := Reference_To (Obj);
22346 begin
22347 if Present (Ref) then
22348 return Object_Access_Level (Ref);
22349 else
22350 return Type_Access_Level (Etype (Prefix (Obj)));
22351 end if;
22352 end;
22354 else
22355 return Type_Access_Level (Etype (Prefix (Obj)));
22356 end if;
22358 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
22359 return Object_Access_Level (Expression (Obj));
22361 elsif Nkind (Obj) = N_Function_Call then
22363 -- Function results are objects, so we get either the access level of
22364 -- the function or, in the case of an indirect call, the level of the
22365 -- access-to-subprogram type. (This code is used for Ada 95, but it
22366 -- looks wrong, because it seems that we should be checking the level
22367 -- of the call itself, even for Ada 95. However, using the Ada 2005
22368 -- version of the code causes regressions in several tests that are
22369 -- compiled with -gnat95. ???)
22371 if Ada_Version < Ada_2005 then
22372 if Is_Entity_Name (Name (Obj)) then
22373 return Subprogram_Access_Level (Entity (Name (Obj)));
22374 else
22375 return Type_Access_Level (Etype (Prefix (Name (Obj))));
22376 end if;
22378 -- For Ada 2005, the level of the result object of a function call is
22379 -- defined to be the level of the call's innermost enclosing master.
22380 -- We determine that by querying the depth of the innermost enclosing
22381 -- dynamic scope.
22383 else
22384 Return_Master_Scope_Depth_Of_Call : declare
22385 function Innermost_Master_Scope_Depth
22386 (N : Node_Id) return Uint;
22387 -- Returns the scope depth of the given node's innermost
22388 -- enclosing dynamic scope (effectively the accessibility
22389 -- level of the innermost enclosing master).
22391 ----------------------------------
22392 -- Innermost_Master_Scope_Depth --
22393 ----------------------------------
22395 function Innermost_Master_Scope_Depth
22396 (N : Node_Id) return Uint
22398 Node_Par : Node_Id := Parent (N);
22400 begin
22401 -- Locate the nearest enclosing node (by traversing Parents)
22402 -- that Defining_Entity can be applied to, and return the
22403 -- depth of that entity's nearest enclosing dynamic scope.
22405 while Present (Node_Par) loop
22406 case Nkind (Node_Par) is
22407 when N_Abstract_Subprogram_Declaration
22408 | N_Block_Statement
22409 | N_Body_Stub
22410 | N_Component_Declaration
22411 | N_Entry_Body
22412 | N_Entry_Declaration
22413 | N_Exception_Declaration
22414 | N_Formal_Object_Declaration
22415 | N_Formal_Package_Declaration
22416 | N_Formal_Subprogram_Declaration
22417 | N_Formal_Type_Declaration
22418 | N_Full_Type_Declaration
22419 | N_Function_Specification
22420 | N_Generic_Declaration
22421 | N_Generic_Instantiation
22422 | N_Implicit_Label_Declaration
22423 | N_Incomplete_Type_Declaration
22424 | N_Loop_Parameter_Specification
22425 | N_Number_Declaration
22426 | N_Object_Declaration
22427 | N_Package_Declaration
22428 | N_Package_Specification
22429 | N_Parameter_Specification
22430 | N_Private_Extension_Declaration
22431 | N_Private_Type_Declaration
22432 | N_Procedure_Specification
22433 | N_Proper_Body
22434 | N_Protected_Type_Declaration
22435 | N_Renaming_Declaration
22436 | N_Single_Protected_Declaration
22437 | N_Single_Task_Declaration
22438 | N_Subprogram_Declaration
22439 | N_Subtype_Declaration
22440 | N_Subunit
22441 | N_Task_Type_Declaration
22443 return Scope_Depth
22444 (Nearest_Dynamic_Scope
22445 (Defining_Entity (Node_Par)));
22447 -- For a return statement within a function, return
22448 -- the depth of the function itself. This is not just
22449 -- a small optimization, but matters when analyzing
22450 -- the expression in an expression function before
22451 -- the body is created.
22453 when N_Simple_Return_Statement =>
22454 if Ekind (Current_Scope) = E_Function then
22455 return Scope_Depth (Current_Scope);
22456 end if;
22458 when others =>
22459 null;
22460 end case;
22462 Node_Par := Parent (Node_Par);
22463 end loop;
22465 pragma Assert (False);
22467 -- Should never reach the following return
22469 return Scope_Depth (Current_Scope) + 1;
22470 end Innermost_Master_Scope_Depth;
22472 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22474 begin
22475 return Innermost_Master_Scope_Depth (Obj);
22476 end Return_Master_Scope_Depth_Of_Call;
22477 end if;
22479 -- For convenience we handle qualified expressions, even though they
22480 -- aren't technically object names.
22482 elsif Nkind (Obj) = N_Qualified_Expression then
22483 return Object_Access_Level (Expression (Obj));
22485 -- Ditto for aggregates. They have the level of the temporary that
22486 -- will hold their value.
22488 elsif Nkind (Obj) = N_Aggregate then
22489 return Object_Access_Level (Current_Scope);
22491 -- Otherwise return the scope level of Standard. (If there are cases
22492 -- that fall through to this point they will be treated as having
22493 -- global accessibility for now. ???)
22495 else
22496 return Scope_Depth (Standard_Standard);
22497 end if;
22498 end Object_Access_Level;
22500 ----------------------------------
22501 -- Old_Requires_Transient_Scope --
22502 ----------------------------------
22504 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22505 Typ : constant Entity_Id := Underlying_Type (Id);
22507 begin
22508 -- This is a private type which is not completed yet. This can only
22509 -- happen in a default expression (of a formal parameter or of a
22510 -- record component). Do not expand transient scope in this case.
22512 if No (Typ) then
22513 return False;
22515 -- Do not expand transient scope for non-existent procedure return
22517 elsif Typ = Standard_Void_Type then
22518 return False;
22520 -- Elementary types do not require a transient scope
22522 elsif Is_Elementary_Type (Typ) then
22523 return False;
22525 -- Generally, indefinite subtypes require a transient scope, since the
22526 -- back end cannot generate temporaries, since this is not a valid type
22527 -- for declaring an object. It might be possible to relax this in the
22528 -- future, e.g. by declaring the maximum possible space for the type.
22530 elsif not Is_Definite_Subtype (Typ) then
22531 return True;
22533 -- Functions returning tagged types may dispatch on result so their
22534 -- returned value is allocated on the secondary stack. Controlled
22535 -- type temporaries need finalization.
22537 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22538 return True;
22540 -- Record type
22542 elsif Is_Record_Type (Typ) then
22543 declare
22544 Comp : Entity_Id;
22546 begin
22547 Comp := First_Entity (Typ);
22548 while Present (Comp) loop
22549 if Ekind (Comp) = E_Component then
22551 -- ???It's not clear we need a full recursive call to
22552 -- Old_Requires_Transient_Scope here. Note that the
22553 -- following can't happen.
22555 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
22556 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
22558 if Old_Requires_Transient_Scope (Etype (Comp)) then
22559 return True;
22560 end if;
22561 end if;
22563 Next_Entity (Comp);
22564 end loop;
22565 end;
22567 return False;
22569 -- String literal types never require transient scope
22571 elsif Ekind (Typ) = E_String_Literal_Subtype then
22572 return False;
22574 -- Array type. Note that we already know that this is a constrained
22575 -- array, since unconstrained arrays will fail the indefinite test.
22577 elsif Is_Array_Type (Typ) then
22579 -- If component type requires a transient scope, the array does too
22581 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
22582 return True;
22584 -- Otherwise, we only need a transient scope if the size depends on
22585 -- the value of one or more discriminants.
22587 else
22588 return Size_Depends_On_Discriminant (Typ);
22589 end if;
22591 -- All other cases do not require a transient scope
22593 else
22594 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
22595 return False;
22596 end if;
22597 end Old_Requires_Transient_Scope;
22599 ---------------------------------
22600 -- Original_Aspect_Pragma_Name --
22601 ---------------------------------
22603 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
22604 Item : Node_Id;
22605 Item_Nam : Name_Id;
22607 begin
22608 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
22610 Item := N;
22612 -- The pragma was generated to emulate an aspect, use the original
22613 -- aspect specification.
22615 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
22616 Item := Corresponding_Aspect (Item);
22617 end if;
22619 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
22620 -- Post and Post_Class rewrite their pragma identifier to preserve the
22621 -- original name.
22622 -- ??? this is kludgey
22624 if Nkind (Item) = N_Pragma then
22625 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
22627 else
22628 pragma Assert (Nkind (Item) = N_Aspect_Specification);
22629 Item_Nam := Chars (Identifier (Item));
22630 end if;
22632 -- Deal with 'Class by converting the name to its _XXX form
22634 if Class_Present (Item) then
22635 if Item_Nam = Name_Invariant then
22636 Item_Nam := Name_uInvariant;
22638 elsif Item_Nam = Name_Post then
22639 Item_Nam := Name_uPost;
22641 elsif Item_Nam = Name_Pre then
22642 Item_Nam := Name_uPre;
22644 elsif Nam_In (Item_Nam, Name_Type_Invariant,
22645 Name_Type_Invariant_Class)
22646 then
22647 Item_Nam := Name_uType_Invariant;
22649 -- Nothing to do for other cases (e.g. a Check that derived from
22650 -- Pre_Class and has the flag set). Also we do nothing if the name
22651 -- is already in special _xxx form.
22653 end if;
22654 end if;
22656 return Item_Nam;
22657 end Original_Aspect_Pragma_Name;
22659 --------------------------------------
22660 -- Original_Corresponding_Operation --
22661 --------------------------------------
22663 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
22665 Typ : constant Entity_Id := Find_Dispatching_Type (S);
22667 begin
22668 -- If S is an inherited primitive S2 the original corresponding
22669 -- operation of S is the original corresponding operation of S2
22671 if Present (Alias (S))
22672 and then Find_Dispatching_Type (Alias (S)) /= Typ
22673 then
22674 return Original_Corresponding_Operation (Alias (S));
22676 -- If S overrides an inherited subprogram S2 the original corresponding
22677 -- operation of S is the original corresponding operation of S2
22679 elsif Present (Overridden_Operation (S)) then
22680 return Original_Corresponding_Operation (Overridden_Operation (S));
22682 -- otherwise it is S itself
22684 else
22685 return S;
22686 end if;
22687 end Original_Corresponding_Operation;
22689 -------------------
22690 -- Output_Entity --
22691 -------------------
22693 procedure Output_Entity (Id : Entity_Id) is
22694 Scop : Entity_Id;
22696 begin
22697 Scop := Scope (Id);
22699 -- The entity may lack a scope when it is in the process of being
22700 -- analyzed. Use the current scope as an approximation.
22702 if No (Scop) then
22703 Scop := Current_Scope;
22704 end if;
22706 Output_Name (Chars (Id), Scop);
22707 end Output_Entity;
22709 -----------------
22710 -- Output_Name --
22711 -----------------
22713 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
22714 begin
22715 Write_Str
22716 (Get_Name_String
22717 (Get_Qualified_Name
22718 (Nam => Nam,
22719 Suffix => No_Name,
22720 Scop => Scop)));
22721 Write_Eol;
22722 end Output_Name;
22724 ----------------------
22725 -- Policy_In_Effect --
22726 ----------------------
22728 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
22729 function Policy_In_List (List : Node_Id) return Name_Id;
22730 -- Determine the mode of a policy in a N_Pragma list
22732 --------------------
22733 -- Policy_In_List --
22734 --------------------
22736 function Policy_In_List (List : Node_Id) return Name_Id is
22737 Arg1 : Node_Id;
22738 Arg2 : Node_Id;
22739 Prag : Node_Id;
22741 begin
22742 Prag := List;
22743 while Present (Prag) loop
22744 Arg1 := First (Pragma_Argument_Associations (Prag));
22745 Arg2 := Next (Arg1);
22747 Arg1 := Get_Pragma_Arg (Arg1);
22748 Arg2 := Get_Pragma_Arg (Arg2);
22750 -- The current Check_Policy pragma matches the requested policy or
22751 -- appears in the single argument form (Assertion, policy_id).
22753 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
22754 return Chars (Arg2);
22755 end if;
22757 Prag := Next_Pragma (Prag);
22758 end loop;
22760 return No_Name;
22761 end Policy_In_List;
22763 -- Local variables
22765 Kind : Name_Id;
22767 -- Start of processing for Policy_In_Effect
22769 begin
22770 if not Is_Valid_Assertion_Kind (Policy) then
22771 raise Program_Error;
22772 end if;
22774 -- Inspect all policy pragmas that appear within scopes (if any)
22776 Kind := Policy_In_List (Check_Policy_List);
22778 -- Inspect all configuration policy pragmas (if any)
22780 if Kind = No_Name then
22781 Kind := Policy_In_List (Check_Policy_List_Config);
22782 end if;
22784 -- The context lacks policy pragmas, determine the mode based on whether
22785 -- assertions are enabled at the configuration level. This ensures that
22786 -- the policy is preserved when analyzing generics.
22788 if Kind = No_Name then
22789 if Assertions_Enabled_Config then
22790 Kind := Name_Check;
22791 else
22792 Kind := Name_Ignore;
22793 end if;
22794 end if;
22796 -- In CodePeer mode and GNATprove mode, we need to consider all
22797 -- assertions, unless they are disabled. Force Name_Check on
22798 -- ignored assertions.
22800 if Nam_In (Kind, Name_Ignore, Name_Off)
22801 and then (CodePeer_Mode or GNATprove_Mode)
22802 then
22803 Kind := Name_Check;
22804 end if;
22806 return Kind;
22807 end Policy_In_Effect;
22809 ----------------------------------
22810 -- Predicate_Tests_On_Arguments --
22811 ----------------------------------
22813 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
22814 begin
22815 -- Always test predicates on indirect call
22817 if Ekind (Subp) = E_Subprogram_Type then
22818 return True;
22820 -- Do not test predicates on call to generated default Finalize, since
22821 -- we are not interested in whether something we are finalizing (and
22822 -- typically destroying) satisfies its predicates.
22824 elsif Chars (Subp) = Name_Finalize
22825 and then not Comes_From_Source (Subp)
22826 then
22827 return False;
22829 -- Do not test predicates on any internally generated routines
22831 elsif Is_Internal_Name (Chars (Subp)) then
22832 return False;
22834 -- Do not test predicates on call to Init_Proc, since if needed the
22835 -- predicate test will occur at some other point.
22837 elsif Is_Init_Proc (Subp) then
22838 return False;
22840 -- Do not test predicates on call to predicate function, since this
22841 -- would cause infinite recursion.
22843 elsif Ekind (Subp) = E_Function
22844 and then (Is_Predicate_Function (Subp)
22845 or else
22846 Is_Predicate_Function_M (Subp))
22847 then
22848 return False;
22850 -- For now, no other exceptions
22852 else
22853 return True;
22854 end if;
22855 end Predicate_Tests_On_Arguments;
22857 -----------------------
22858 -- Private_Component --
22859 -----------------------
22861 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
22862 Ancestor : constant Entity_Id := Base_Type (Type_Id);
22864 function Trace_Components
22865 (T : Entity_Id;
22866 Check : Boolean) return Entity_Id;
22867 -- Recursive function that does the work, and checks against circular
22868 -- definition for each subcomponent type.
22870 ----------------------
22871 -- Trace_Components --
22872 ----------------------
22874 function Trace_Components
22875 (T : Entity_Id;
22876 Check : Boolean) return Entity_Id
22878 Btype : constant Entity_Id := Base_Type (T);
22879 Component : Entity_Id;
22880 P : Entity_Id;
22881 Candidate : Entity_Id := Empty;
22883 begin
22884 if Check and then Btype = Ancestor then
22885 Error_Msg_N ("circular type definition", Type_Id);
22886 return Any_Type;
22887 end if;
22889 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
22890 if Present (Full_View (Btype))
22891 and then Is_Record_Type (Full_View (Btype))
22892 and then not Is_Frozen (Btype)
22893 then
22894 -- To indicate that the ancestor depends on a private type, the
22895 -- current Btype is sufficient. However, to check for circular
22896 -- definition we must recurse on the full view.
22898 Candidate := Trace_Components (Full_View (Btype), True);
22900 if Candidate = Any_Type then
22901 return Any_Type;
22902 else
22903 return Btype;
22904 end if;
22906 else
22907 return Btype;
22908 end if;
22910 elsif Is_Array_Type (Btype) then
22911 return Trace_Components (Component_Type (Btype), True);
22913 elsif Is_Record_Type (Btype) then
22914 Component := First_Entity (Btype);
22915 while Present (Component)
22916 and then Comes_From_Source (Component)
22917 loop
22918 -- Skip anonymous types generated by constrained components
22920 if not Is_Type (Component) then
22921 P := Trace_Components (Etype (Component), True);
22923 if Present (P) then
22924 if P = Any_Type then
22925 return P;
22926 else
22927 Candidate := P;
22928 end if;
22929 end if;
22930 end if;
22932 Next_Entity (Component);
22933 end loop;
22935 return Candidate;
22937 else
22938 return Empty;
22939 end if;
22940 end Trace_Components;
22942 -- Start of processing for Private_Component
22944 begin
22945 return Trace_Components (Type_Id, False);
22946 end Private_Component;
22948 ---------------------------
22949 -- Primitive_Names_Match --
22950 ---------------------------
22952 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
22953 function Non_Internal_Name (E : Entity_Id) return Name_Id;
22954 -- Given an internal name, returns the corresponding non-internal name
22956 ------------------------
22957 -- Non_Internal_Name --
22958 ------------------------
22960 function Non_Internal_Name (E : Entity_Id) return Name_Id is
22961 begin
22962 Get_Name_String (Chars (E));
22963 Name_Len := Name_Len - 1;
22964 return Name_Find;
22965 end Non_Internal_Name;
22967 -- Start of processing for Primitive_Names_Match
22969 begin
22970 pragma Assert (Present (E1) and then Present (E2));
22972 return Chars (E1) = Chars (E2)
22973 or else
22974 (not Is_Internal_Name (Chars (E1))
22975 and then Is_Internal_Name (Chars (E2))
22976 and then Non_Internal_Name (E2) = Chars (E1))
22977 or else
22978 (not Is_Internal_Name (Chars (E2))
22979 and then Is_Internal_Name (Chars (E1))
22980 and then Non_Internal_Name (E1) = Chars (E2))
22981 or else
22982 (Is_Predefined_Dispatching_Operation (E1)
22983 and then Is_Predefined_Dispatching_Operation (E2)
22984 and then Same_TSS (E1, E2))
22985 or else
22986 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
22987 end Primitive_Names_Match;
22989 -----------------------
22990 -- Process_End_Label --
22991 -----------------------
22993 procedure Process_End_Label
22994 (N : Node_Id;
22995 Typ : Character;
22996 Ent : Entity_Id)
22998 Loc : Source_Ptr;
22999 Nam : Node_Id;
23000 Scop : Entity_Id;
23002 Label_Ref : Boolean;
23003 -- Set True if reference to end label itself is required
23005 Endl : Node_Id;
23006 -- Gets set to the operator symbol or identifier that references the
23007 -- entity Ent. For the child unit case, this is the identifier from the
23008 -- designator. For other cases, this is simply Endl.
23010 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
23011 -- N is an identifier node that appears as a parent unit reference in
23012 -- the case where Ent is a child unit. This procedure generates an
23013 -- appropriate cross-reference entry. E is the corresponding entity.
23015 -------------------------
23016 -- Generate_Parent_Ref --
23017 -------------------------
23019 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
23020 begin
23021 -- If names do not match, something weird, skip reference
23023 if Chars (E) = Chars (N) then
23025 -- Generate the reference. We do NOT consider this as a reference
23026 -- for unreferenced symbol purposes.
23028 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
23030 if Style_Check then
23031 Style.Check_Identifier (N, E);
23032 end if;
23033 end if;
23034 end Generate_Parent_Ref;
23036 -- Start of processing for Process_End_Label
23038 begin
23039 -- If no node, ignore. This happens in some error situations, and
23040 -- also for some internally generated structures where no end label
23041 -- references are required in any case.
23043 if No (N) then
23044 return;
23045 end if;
23047 -- Nothing to do if no End_Label, happens for internally generated
23048 -- constructs where we don't want an end label reference anyway. Also
23049 -- nothing to do if Endl is a string literal, which means there was
23050 -- some prior error (bad operator symbol)
23052 Endl := End_Label (N);
23054 if No (Endl) or else Nkind (Endl) = N_String_Literal then
23055 return;
23056 end if;
23058 -- Reference node is not in extended main source unit
23060 if not In_Extended_Main_Source_Unit (N) then
23062 -- Generally we do not collect references except for the extended
23063 -- main source unit. The one exception is the 'e' entry for a
23064 -- package spec, where it is useful for a client to have the
23065 -- ending information to define scopes.
23067 if Typ /= 'e' then
23068 return;
23070 else
23071 Label_Ref := False;
23073 -- For this case, we can ignore any parent references, but we
23074 -- need the package name itself for the 'e' entry.
23076 if Nkind (Endl) = N_Designator then
23077 Endl := Identifier (Endl);
23078 end if;
23079 end if;
23081 -- Reference is in extended main source unit
23083 else
23084 Label_Ref := True;
23086 -- For designator, generate references for the parent entries
23088 if Nkind (Endl) = N_Designator then
23090 -- Generate references for the prefix if the END line comes from
23091 -- source (otherwise we do not need these references) We climb the
23092 -- scope stack to find the expected entities.
23094 if Comes_From_Source (Endl) then
23095 Nam := Name (Endl);
23096 Scop := Current_Scope;
23097 while Nkind (Nam) = N_Selected_Component loop
23098 Scop := Scope (Scop);
23099 exit when No (Scop);
23100 Generate_Parent_Ref (Selector_Name (Nam), Scop);
23101 Nam := Prefix (Nam);
23102 end loop;
23104 if Present (Scop) then
23105 Generate_Parent_Ref (Nam, Scope (Scop));
23106 end if;
23107 end if;
23109 Endl := Identifier (Endl);
23110 end if;
23111 end if;
23113 -- If the end label is not for the given entity, then either we have
23114 -- some previous error, or this is a generic instantiation for which
23115 -- we do not need to make a cross-reference in this case anyway. In
23116 -- either case we simply ignore the call.
23118 if Chars (Ent) /= Chars (Endl) then
23119 return;
23120 end if;
23122 -- If label was really there, then generate a normal reference and then
23123 -- adjust the location in the end label to point past the name (which
23124 -- should almost always be the semicolon).
23126 Loc := Sloc (Endl);
23128 if Comes_From_Source (Endl) then
23130 -- If a label reference is required, then do the style check and
23131 -- generate an l-type cross-reference entry for the label
23133 if Label_Ref then
23134 if Style_Check then
23135 Style.Check_Identifier (Endl, Ent);
23136 end if;
23138 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
23139 end if;
23141 -- Set the location to point past the label (normally this will
23142 -- mean the semicolon immediately following the label). This is
23143 -- done for the sake of the 'e' or 't' entry generated below.
23145 Get_Decoded_Name_String (Chars (Endl));
23146 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
23148 else
23149 -- In SPARK mode, no missing label is allowed for packages and
23150 -- subprogram bodies. Detect those cases by testing whether
23151 -- Process_End_Label was called for a body (Typ = 't') or a package.
23153 if Restriction_Check_Required (SPARK_05)
23154 and then (Typ = 't' or else Ekind (Ent) = E_Package)
23155 then
23156 Error_Msg_Node_1 := Endl;
23157 Check_SPARK_05_Restriction
23158 ("`END &` required", Endl, Force => True);
23159 end if;
23160 end if;
23162 -- Now generate the e/t reference
23164 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
23166 -- Restore Sloc, in case modified above, since we have an identifier
23167 -- and the normal Sloc should be left set in the tree.
23169 Set_Sloc (Endl, Loc);
23170 end Process_End_Label;
23172 --------------------------------
23173 -- Propagate_Concurrent_Flags --
23174 --------------------------------
23176 procedure Propagate_Concurrent_Flags
23177 (Typ : Entity_Id;
23178 Comp_Typ : Entity_Id)
23180 begin
23181 if Has_Task (Comp_Typ) then
23182 Set_Has_Task (Typ);
23183 end if;
23185 if Has_Protected (Comp_Typ) then
23186 Set_Has_Protected (Typ);
23187 end if;
23189 if Has_Timing_Event (Comp_Typ) then
23190 Set_Has_Timing_Event (Typ);
23191 end if;
23192 end Propagate_Concurrent_Flags;
23194 ------------------------------
23195 -- Propagate_DIC_Attributes --
23196 ------------------------------
23198 procedure Propagate_DIC_Attributes
23199 (Typ : Entity_Id;
23200 From_Typ : Entity_Id)
23202 DIC_Proc : Entity_Id;
23204 begin
23205 if Present (Typ) and then Present (From_Typ) then
23206 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23208 -- Nothing to do if both the source and the destination denote the
23209 -- same type.
23211 if From_Typ = Typ then
23212 return;
23213 end if;
23215 DIC_Proc := DIC_Procedure (From_Typ);
23217 -- The setting of the attributes is intentionally conservative. This
23218 -- prevents accidental clobbering of enabled attributes.
23220 if Has_Inherited_DIC (From_Typ)
23221 and then not Has_Inherited_DIC (Typ)
23222 then
23223 Set_Has_Inherited_DIC (Typ);
23224 end if;
23226 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
23227 Set_Has_Own_DIC (Typ);
23228 end if;
23230 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
23231 Set_DIC_Procedure (Typ, DIC_Proc);
23232 end if;
23233 end if;
23234 end Propagate_DIC_Attributes;
23236 ------------------------------------
23237 -- Propagate_Invariant_Attributes --
23238 ------------------------------------
23240 procedure Propagate_Invariant_Attributes
23241 (Typ : Entity_Id;
23242 From_Typ : Entity_Id)
23244 Full_IP : Entity_Id;
23245 Part_IP : Entity_Id;
23247 begin
23248 if Present (Typ) and then Present (From_Typ) then
23249 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23251 -- Nothing to do if both the source and the destination denote the
23252 -- same type.
23254 if From_Typ = Typ then
23255 return;
23256 end if;
23258 Full_IP := Invariant_Procedure (From_Typ);
23259 Part_IP := Partial_Invariant_Procedure (From_Typ);
23261 -- The setting of the attributes is intentionally conservative. This
23262 -- prevents accidental clobbering of enabled attributes.
23264 if Has_Inheritable_Invariants (From_Typ)
23265 and then not Has_Inheritable_Invariants (Typ)
23266 then
23267 Set_Has_Inheritable_Invariants (Typ);
23268 end if;
23270 if Has_Inherited_Invariants (From_Typ)
23271 and then not Has_Inherited_Invariants (Typ)
23272 then
23273 Set_Has_Inherited_Invariants (Typ);
23274 end if;
23276 if Has_Own_Invariants (From_Typ)
23277 and then not Has_Own_Invariants (Typ)
23278 then
23279 Set_Has_Own_Invariants (Typ);
23280 end if;
23282 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
23283 Set_Invariant_Procedure (Typ, Full_IP);
23284 end if;
23286 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
23287 then
23288 Set_Partial_Invariant_Procedure (Typ, Part_IP);
23289 end if;
23290 end if;
23291 end Propagate_Invariant_Attributes;
23293 ---------------------------------------
23294 -- Record_Possible_Part_Of_Reference --
23295 ---------------------------------------
23297 procedure Record_Possible_Part_Of_Reference
23298 (Var_Id : Entity_Id;
23299 Ref : Node_Id)
23301 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
23302 Refs : Elist_Id;
23304 begin
23305 -- The variable is a constituent of a single protected/task type. Such
23306 -- a variable acts as a component of the type and must appear within a
23307 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
23308 -- verify its legality now.
23310 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
23311 Check_Part_Of_Reference (Var_Id, Ref);
23313 -- The variable is subject to pragma Part_Of and may eventually become a
23314 -- constituent of a single protected/task type. Record the reference to
23315 -- verify its placement when the contract of the variable is analyzed.
23317 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
23318 Refs := Part_Of_References (Var_Id);
23320 if No (Refs) then
23321 Refs := New_Elmt_List;
23322 Set_Part_Of_References (Var_Id, Refs);
23323 end if;
23325 Append_Elmt (Ref, Refs);
23326 end if;
23327 end Record_Possible_Part_Of_Reference;
23329 ----------------
23330 -- Referenced --
23331 ----------------
23333 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
23334 Seen : Boolean := False;
23336 function Is_Reference (N : Node_Id) return Traverse_Result;
23337 -- Determine whether node N denotes a reference to Id. If this is the
23338 -- case, set global flag Seen to True and stop the traversal.
23340 ------------------
23341 -- Is_Reference --
23342 ------------------
23344 function Is_Reference (N : Node_Id) return Traverse_Result is
23345 begin
23346 if Is_Entity_Name (N)
23347 and then Present (Entity (N))
23348 and then Entity (N) = Id
23349 then
23350 Seen := True;
23351 return Abandon;
23352 else
23353 return OK;
23354 end if;
23355 end Is_Reference;
23357 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
23359 -- Start of processing for Referenced
23361 begin
23362 Inspect_Expression (Expr);
23363 return Seen;
23364 end Referenced;
23366 ------------------------------------
23367 -- References_Generic_Formal_Type --
23368 ------------------------------------
23370 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
23372 function Process (N : Node_Id) return Traverse_Result;
23373 -- Process one node in search for generic formal type
23375 -------------
23376 -- Process --
23377 -------------
23379 function Process (N : Node_Id) return Traverse_Result is
23380 begin
23381 if Nkind (N) in N_Has_Entity then
23382 declare
23383 E : constant Entity_Id := Entity (N);
23384 begin
23385 if Present (E) then
23386 if Is_Generic_Type (E) then
23387 return Abandon;
23388 elsif Present (Etype (E))
23389 and then Is_Generic_Type (Etype (E))
23390 then
23391 return Abandon;
23392 end if;
23393 end if;
23394 end;
23395 end if;
23397 return Atree.OK;
23398 end Process;
23400 function Traverse is new Traverse_Func (Process);
23401 -- Traverse tree to look for generic type
23403 begin
23404 if Inside_A_Generic then
23405 return Traverse (N) = Abandon;
23406 else
23407 return False;
23408 end if;
23409 end References_Generic_Formal_Type;
23411 -------------------------------
23412 -- Remove_Entity_And_Homonym --
23413 -------------------------------
23415 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
23416 begin
23417 Remove_Entity (Id);
23418 Remove_Homonym (Id);
23419 end Remove_Entity_And_Homonym;
23421 --------------------
23422 -- Remove_Homonym --
23423 --------------------
23425 procedure Remove_Homonym (Id : Entity_Id) is
23426 Hom : Entity_Id;
23427 Prev : Entity_Id := Empty;
23429 begin
23430 if Id = Current_Entity (Id) then
23431 if Present (Homonym (Id)) then
23432 Set_Current_Entity (Homonym (Id));
23433 else
23434 Set_Name_Entity_Id (Chars (Id), Empty);
23435 end if;
23437 else
23438 Hom := Current_Entity (Id);
23439 while Present (Hom) and then Hom /= Id loop
23440 Prev := Hom;
23441 Hom := Homonym (Hom);
23442 end loop;
23444 -- If Id is not on the homonym chain, nothing to do
23446 if Present (Hom) then
23447 Set_Homonym (Prev, Homonym (Id));
23448 end if;
23449 end if;
23450 end Remove_Homonym;
23452 ------------------------------
23453 -- Remove_Overloaded_Entity --
23454 ------------------------------
23456 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
23457 procedure Remove_Primitive_Of (Typ : Entity_Id);
23458 -- Remove primitive subprogram Id from the list of primitives that
23459 -- belong to type Typ.
23461 -------------------------
23462 -- Remove_Primitive_Of --
23463 -------------------------
23465 procedure Remove_Primitive_Of (Typ : Entity_Id) is
23466 Prims : Elist_Id;
23468 begin
23469 if Is_Tagged_Type (Typ) then
23470 Prims := Direct_Primitive_Operations (Typ);
23472 if Present (Prims) then
23473 Remove (Prims, Id);
23474 end if;
23475 end if;
23476 end Remove_Primitive_Of;
23478 -- Local variables
23480 Formal : Entity_Id;
23482 -- Start of processing for Remove_Overloaded_Entity
23484 begin
23485 Remove_Entity_And_Homonym (Id);
23487 -- The entity denotes a primitive subprogram. Remove it from the list of
23488 -- primitives of the associated controlling type.
23490 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
23491 Formal := First_Formal (Id);
23492 while Present (Formal) loop
23493 if Is_Controlling_Formal (Formal) then
23494 Remove_Primitive_Of (Etype (Formal));
23495 exit;
23496 end if;
23498 Next_Formal (Formal);
23499 end loop;
23501 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
23502 Remove_Primitive_Of (Etype (Id));
23503 end if;
23504 end if;
23505 end Remove_Overloaded_Entity;
23507 ---------------------
23508 -- Rep_To_Pos_Flag --
23509 ---------------------
23511 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
23512 begin
23513 return New_Occurrence_Of
23514 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
23515 end Rep_To_Pos_Flag;
23517 --------------------
23518 -- Require_Entity --
23519 --------------------
23521 procedure Require_Entity (N : Node_Id) is
23522 begin
23523 if Is_Entity_Name (N) and then No (Entity (N)) then
23524 if Total_Errors_Detected /= 0 then
23525 Set_Entity (N, Any_Id);
23526 else
23527 raise Program_Error;
23528 end if;
23529 end if;
23530 end Require_Entity;
23532 ------------------------------
23533 -- Requires_Transient_Scope --
23534 ------------------------------
23536 -- A transient scope is required when variable-sized temporaries are
23537 -- allocated on the secondary stack, or when finalization actions must be
23538 -- generated before the next instruction.
23540 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23541 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
23543 begin
23544 if Debug_Flag_QQ then
23545 return Old_Result;
23546 end if;
23548 declare
23549 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
23551 begin
23552 -- Assert that we're not putting things on the secondary stack if we
23553 -- didn't before; we are trying to AVOID secondary stack when
23554 -- possible.
23556 if not Old_Result then
23557 pragma Assert (not New_Result);
23558 null;
23559 end if;
23561 if New_Result /= Old_Result then
23562 Results_Differ (Id, Old_Result, New_Result);
23563 end if;
23565 return New_Result;
23566 end;
23567 end Requires_Transient_Scope;
23569 --------------------
23570 -- Results_Differ --
23571 --------------------
23573 procedure Results_Differ
23574 (Id : Entity_Id;
23575 Old_Val : Boolean;
23576 New_Val : Boolean)
23578 begin
23579 if False then -- False to disable; True for debugging
23580 Treepr.Print_Tree_Node (Id);
23582 if Old_Val = New_Val then
23583 raise Program_Error;
23584 end if;
23585 end if;
23586 end Results_Differ;
23588 --------------------------
23589 -- Reset_Analyzed_Flags --
23590 --------------------------
23592 procedure Reset_Analyzed_Flags (N : Node_Id) is
23593 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
23594 -- Function used to reset Analyzed flags in tree. Note that we do
23595 -- not reset Analyzed flags in entities, since there is no need to
23596 -- reanalyze entities, and indeed, it is wrong to do so, since it
23597 -- can result in generating auxiliary stuff more than once.
23599 --------------------
23600 -- Clear_Analyzed --
23601 --------------------
23603 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
23604 begin
23605 if Nkind (N) not in N_Entity then
23606 Set_Analyzed (N, False);
23607 end if;
23609 return OK;
23610 end Clear_Analyzed;
23612 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
23614 -- Start of processing for Reset_Analyzed_Flags
23616 begin
23617 Reset_Analyzed (N);
23618 end Reset_Analyzed_Flags;
23620 ------------------------
23621 -- Restore_SPARK_Mode --
23622 ------------------------
23624 procedure Restore_SPARK_Mode
23625 (Mode : SPARK_Mode_Type;
23626 Prag : Node_Id)
23628 begin
23629 SPARK_Mode := Mode;
23630 SPARK_Mode_Pragma := Prag;
23631 end Restore_SPARK_Mode;
23633 --------------------------------
23634 -- Returns_Unconstrained_Type --
23635 --------------------------------
23637 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
23638 begin
23639 return Ekind (Subp) = E_Function
23640 and then not Is_Scalar_Type (Etype (Subp))
23641 and then not Is_Access_Type (Etype (Subp))
23642 and then not Is_Constrained (Etype (Subp));
23643 end Returns_Unconstrained_Type;
23645 ----------------------------
23646 -- Root_Type_Of_Full_View --
23647 ----------------------------
23649 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
23650 Rtyp : constant Entity_Id := Root_Type (T);
23652 begin
23653 -- The root type of the full view may itself be a private type. Keep
23654 -- looking for the ultimate derivation parent.
23656 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
23657 return Root_Type_Of_Full_View (Full_View (Rtyp));
23658 else
23659 return Rtyp;
23660 end if;
23661 end Root_Type_Of_Full_View;
23663 ---------------------------
23664 -- Safe_To_Capture_Value --
23665 ---------------------------
23667 function Safe_To_Capture_Value
23668 (N : Node_Id;
23669 Ent : Entity_Id;
23670 Cond : Boolean := False) return Boolean
23672 begin
23673 -- The only entities for which we track constant values are variables
23674 -- which are not renamings, constants, out parameters, and in out
23675 -- parameters, so check if we have this case.
23677 -- Note: it may seem odd to track constant values for constants, but in
23678 -- fact this routine is used for other purposes than simply capturing
23679 -- the value. In particular, the setting of Known[_Non]_Null.
23681 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
23682 or else
23683 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
23684 then
23685 null;
23687 -- For conditionals, we also allow loop parameters and all formals,
23688 -- including in parameters.
23690 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
23691 null;
23693 -- For all other cases, not just unsafe, but impossible to capture
23694 -- Current_Value, since the above are the only entities which have
23695 -- Current_Value fields.
23697 else
23698 return False;
23699 end if;
23701 -- Skip if volatile or aliased, since funny things might be going on in
23702 -- these cases which we cannot necessarily track. Also skip any variable
23703 -- for which an address clause is given, or whose address is taken. Also
23704 -- never capture value of library level variables (an attempt to do so
23705 -- can occur in the case of package elaboration code).
23707 if Treat_As_Volatile (Ent)
23708 or else Is_Aliased (Ent)
23709 or else Present (Address_Clause (Ent))
23710 or else Address_Taken (Ent)
23711 or else (Is_Library_Level_Entity (Ent)
23712 and then Ekind (Ent) = E_Variable)
23713 then
23714 return False;
23715 end if;
23717 -- OK, all above conditions are met. We also require that the scope of
23718 -- the reference be the same as the scope of the entity, not counting
23719 -- packages and blocks and loops.
23721 declare
23722 E_Scope : constant Entity_Id := Scope (Ent);
23723 R_Scope : Entity_Id;
23725 begin
23726 R_Scope := Current_Scope;
23727 while R_Scope /= Standard_Standard loop
23728 exit when R_Scope = E_Scope;
23730 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
23731 return False;
23732 else
23733 R_Scope := Scope (R_Scope);
23734 end if;
23735 end loop;
23736 end;
23738 -- We also require that the reference does not appear in a context
23739 -- where it is not sure to be executed (i.e. a conditional context
23740 -- or an exception handler). We skip this if Cond is True, since the
23741 -- capturing of values from conditional tests handles this ok.
23743 if Cond then
23744 return True;
23745 end if;
23747 declare
23748 Desc : Node_Id;
23749 P : Node_Id;
23751 begin
23752 Desc := N;
23754 -- Seems dubious that case expressions are not handled here ???
23756 P := Parent (N);
23757 while Present (P) loop
23758 if Nkind (P) = N_If_Statement
23759 or else Nkind (P) = N_Case_Statement
23760 or else (Nkind (P) in N_Short_Circuit
23761 and then Desc = Right_Opnd (P))
23762 or else (Nkind (P) = N_If_Expression
23763 and then Desc /= First (Expressions (P)))
23764 or else Nkind (P) = N_Exception_Handler
23765 or else Nkind (P) = N_Selective_Accept
23766 or else Nkind (P) = N_Conditional_Entry_Call
23767 or else Nkind (P) = N_Timed_Entry_Call
23768 or else Nkind (P) = N_Asynchronous_Select
23769 then
23770 return False;
23772 else
23773 Desc := P;
23774 P := Parent (P);
23776 -- A special Ada 2012 case: the original node may be part
23777 -- of the else_actions of a conditional expression, in which
23778 -- case it might not have been expanded yet, and appears in
23779 -- a non-syntactic list of actions. In that case it is clearly
23780 -- not safe to save a value.
23782 if No (P)
23783 and then Is_List_Member (Desc)
23784 and then No (Parent (List_Containing (Desc)))
23785 then
23786 return False;
23787 end if;
23788 end if;
23789 end loop;
23790 end;
23792 -- OK, looks safe to set value
23794 return True;
23795 end Safe_To_Capture_Value;
23797 ---------------
23798 -- Same_Name --
23799 ---------------
23801 function Same_Name (N1, N2 : Node_Id) return Boolean is
23802 K1 : constant Node_Kind := Nkind (N1);
23803 K2 : constant Node_Kind := Nkind (N2);
23805 begin
23806 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
23807 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
23808 then
23809 return Chars (N1) = Chars (N2);
23811 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
23812 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
23813 then
23814 return Same_Name (Selector_Name (N1), Selector_Name (N2))
23815 and then Same_Name (Prefix (N1), Prefix (N2));
23817 else
23818 return False;
23819 end if;
23820 end Same_Name;
23822 -----------------
23823 -- Same_Object --
23824 -----------------
23826 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
23827 N1 : constant Node_Id := Original_Node (Node1);
23828 N2 : constant Node_Id := Original_Node (Node2);
23829 -- We do the tests on original nodes, since we are most interested
23830 -- in the original source, not any expansion that got in the way.
23832 K1 : constant Node_Kind := Nkind (N1);
23833 K2 : constant Node_Kind := Nkind (N2);
23835 begin
23836 -- First case, both are entities with same entity
23838 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
23839 declare
23840 EN1 : constant Entity_Id := Entity (N1);
23841 EN2 : constant Entity_Id := Entity (N2);
23842 begin
23843 if Present (EN1) and then Present (EN2)
23844 and then (Ekind_In (EN1, E_Variable, E_Constant)
23845 or else Is_Formal (EN1))
23846 and then EN1 = EN2
23847 then
23848 return True;
23849 end if;
23850 end;
23851 end if;
23853 -- Second case, selected component with same selector, same record
23855 if K1 = N_Selected_Component
23856 and then K2 = N_Selected_Component
23857 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
23858 then
23859 return Same_Object (Prefix (N1), Prefix (N2));
23861 -- Third case, indexed component with same subscripts, same array
23863 elsif K1 = N_Indexed_Component
23864 and then K2 = N_Indexed_Component
23865 and then Same_Object (Prefix (N1), Prefix (N2))
23866 then
23867 declare
23868 E1, E2 : Node_Id;
23869 begin
23870 E1 := First (Expressions (N1));
23871 E2 := First (Expressions (N2));
23872 while Present (E1) loop
23873 if not Same_Value (E1, E2) then
23874 return False;
23875 else
23876 Next (E1);
23877 Next (E2);
23878 end if;
23879 end loop;
23881 return True;
23882 end;
23884 -- Fourth case, slice of same array with same bounds
23886 elsif K1 = N_Slice
23887 and then K2 = N_Slice
23888 and then Nkind (Discrete_Range (N1)) = N_Range
23889 and then Nkind (Discrete_Range (N2)) = N_Range
23890 and then Same_Value (Low_Bound (Discrete_Range (N1)),
23891 Low_Bound (Discrete_Range (N2)))
23892 and then Same_Value (High_Bound (Discrete_Range (N1)),
23893 High_Bound (Discrete_Range (N2)))
23894 then
23895 return Same_Name (Prefix (N1), Prefix (N2));
23897 -- All other cases, not clearly the same object
23899 else
23900 return False;
23901 end if;
23902 end Same_Object;
23904 ---------------
23905 -- Same_Type --
23906 ---------------
23908 function Same_Type (T1, T2 : Entity_Id) return Boolean is
23909 begin
23910 if T1 = T2 then
23911 return True;
23913 elsif not Is_Constrained (T1)
23914 and then not Is_Constrained (T2)
23915 and then Base_Type (T1) = Base_Type (T2)
23916 then
23917 return True;
23919 -- For now don't bother with case of identical constraints, to be
23920 -- fiddled with later on perhaps (this is only used for optimization
23921 -- purposes, so it is not critical to do a best possible job)
23923 else
23924 return False;
23925 end if;
23926 end Same_Type;
23928 ----------------
23929 -- Same_Value --
23930 ----------------
23932 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
23933 begin
23934 if Compile_Time_Known_Value (Node1)
23935 and then Compile_Time_Known_Value (Node2)
23936 then
23937 -- Handle properly compile-time expressions that are not
23938 -- scalar.
23940 if Is_String_Type (Etype (Node1)) then
23941 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
23943 else
23944 return Expr_Value (Node1) = Expr_Value (Node2);
23945 end if;
23947 elsif Same_Object (Node1, Node2) then
23948 return True;
23949 else
23950 return False;
23951 end if;
23952 end Same_Value;
23954 --------------------
23955 -- Set_SPARK_Mode --
23956 --------------------
23958 procedure Set_SPARK_Mode (Context : Entity_Id) is
23959 begin
23960 -- Do not consider illegal or partially decorated constructs
23962 if Ekind (Context) = E_Void or else Error_Posted (Context) then
23963 null;
23965 elsif Present (SPARK_Pragma (Context)) then
23966 Install_SPARK_Mode
23967 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
23968 Prag => SPARK_Pragma (Context));
23969 end if;
23970 end Set_SPARK_Mode;
23972 -------------------------
23973 -- Scalar_Part_Present --
23974 -------------------------
23976 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
23977 Val_Typ : constant Entity_Id := Validated_View (Typ);
23978 Field : Entity_Id;
23980 begin
23981 if Is_Scalar_Type (Val_Typ) then
23982 return True;
23984 elsif Is_Array_Type (Val_Typ) then
23985 return Scalar_Part_Present (Component_Type (Val_Typ));
23987 elsif Is_Record_Type (Val_Typ) then
23988 Field := First_Component_Or_Discriminant (Val_Typ);
23989 while Present (Field) loop
23990 if Scalar_Part_Present (Etype (Field)) then
23991 return True;
23992 end if;
23994 Next_Component_Or_Discriminant (Field);
23995 end loop;
23996 end if;
23998 return False;
23999 end Scalar_Part_Present;
24001 ------------------------
24002 -- Scope_Is_Transient --
24003 ------------------------
24005 function Scope_Is_Transient return Boolean is
24006 begin
24007 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
24008 end Scope_Is_Transient;
24010 ------------------
24011 -- Scope_Within --
24012 ------------------
24014 function Scope_Within
24015 (Inner : Entity_Id;
24016 Outer : Entity_Id) return Boolean
24018 Curr : Entity_Id;
24020 begin
24021 Curr := Inner;
24022 while Present (Curr) and then Curr /= Standard_Standard loop
24023 Curr := Scope (Curr);
24025 if Curr = Outer then
24026 return True;
24028 -- A selective accept body appears within a task type, but the
24029 -- enclosing subprogram is the procedure of the task body.
24031 elsif Ekind (Curr) = E_Task_Type
24032 and then Outer = Task_Body_Procedure (Curr)
24033 then
24034 return True;
24036 -- Ditto for the body of a protected operation
24038 elsif Is_Subprogram (Curr)
24039 and then Outer = Protected_Body_Subprogram (Curr)
24040 then
24041 return True;
24042 end if;
24043 end loop;
24045 return False;
24046 end Scope_Within;
24048 --------------------------
24049 -- Scope_Within_Or_Same --
24050 --------------------------
24052 function Scope_Within_Or_Same
24053 (Inner : Entity_Id;
24054 Outer : Entity_Id) return Boolean
24056 Curr : Entity_Id;
24058 begin
24059 Curr := Inner;
24060 while Present (Curr) and then Curr /= Standard_Standard loop
24061 if Curr = Outer then
24062 return True;
24063 end if;
24065 Curr := Scope (Curr);
24066 end loop;
24068 return False;
24069 end Scope_Within_Or_Same;
24071 --------------------
24072 -- Set_Convention --
24073 --------------------
24075 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
24076 begin
24077 Basic_Set_Convention (E, Val);
24079 if Is_Type (E)
24080 and then Is_Access_Subprogram_Type (Base_Type (E))
24081 and then Has_Foreign_Convention (E)
24082 then
24083 Set_Can_Use_Internal_Rep (E, False);
24084 end if;
24086 -- If E is an object, including a component, and the type of E is an
24087 -- anonymous access type with no convention set, then also set the
24088 -- convention of the anonymous access type. We do not do this for
24089 -- anonymous protected types, since protected types always have the
24090 -- default convention.
24092 if Present (Etype (E))
24093 and then (Is_Object (E)
24095 -- Allow E_Void (happens for pragma Convention appearing
24096 -- in the middle of a record applying to a component)
24098 or else Ekind (E) = E_Void)
24099 then
24100 declare
24101 Typ : constant Entity_Id := Etype (E);
24103 begin
24104 if Ekind_In (Typ, E_Anonymous_Access_Type,
24105 E_Anonymous_Access_Subprogram_Type)
24106 and then not Has_Convention_Pragma (Typ)
24107 then
24108 Basic_Set_Convention (Typ, Val);
24109 Set_Has_Convention_Pragma (Typ);
24111 -- And for the access subprogram type, deal similarly with the
24112 -- designated E_Subprogram_Type, which is always internal.
24114 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
24115 declare
24116 Dtype : constant Entity_Id := Designated_Type (Typ);
24117 begin
24118 if Ekind (Dtype) = E_Subprogram_Type
24119 and then not Has_Convention_Pragma (Dtype)
24120 then
24121 Basic_Set_Convention (Dtype, Val);
24122 Set_Has_Convention_Pragma (Dtype);
24123 end if;
24124 end;
24125 end if;
24126 end if;
24127 end;
24128 end if;
24129 end Set_Convention;
24131 ------------------------
24132 -- Set_Current_Entity --
24133 ------------------------
24135 -- The given entity is to be set as the currently visible definition of its
24136 -- associated name (i.e. the Node_Id associated with its name). All we have
24137 -- to do is to get the name from the identifier, and then set the
24138 -- associated Node_Id to point to the given entity.
24140 procedure Set_Current_Entity (E : Entity_Id) is
24141 begin
24142 Set_Name_Entity_Id (Chars (E), E);
24143 end Set_Current_Entity;
24145 ---------------------------
24146 -- Set_Debug_Info_Needed --
24147 ---------------------------
24149 procedure Set_Debug_Info_Needed (T : Entity_Id) is
24151 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
24152 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
24153 -- Used to set debug info in a related node if not set already
24155 --------------------------------------
24156 -- Set_Debug_Info_Needed_If_Not_Set --
24157 --------------------------------------
24159 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
24160 begin
24161 if Present (E) and then not Needs_Debug_Info (E) then
24162 Set_Debug_Info_Needed (E);
24164 -- For a private type, indicate that the full view also needs
24165 -- debug information.
24167 if Is_Type (E)
24168 and then Is_Private_Type (E)
24169 and then Present (Full_View (E))
24170 then
24171 Set_Debug_Info_Needed (Full_View (E));
24172 end if;
24173 end if;
24174 end Set_Debug_Info_Needed_If_Not_Set;
24176 -- Start of processing for Set_Debug_Info_Needed
24178 begin
24179 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
24180 -- indicates that Debug_Info_Needed is never required for the entity.
24181 -- Nothing to do if entity comes from a predefined file. Library files
24182 -- are compiled without debug information, but inlined bodies of these
24183 -- routines may appear in user code, and debug information on them ends
24184 -- up complicating debugging the user code.
24186 if No (T)
24187 or else Debug_Info_Off (T)
24188 then
24189 return;
24191 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
24192 Set_Needs_Debug_Info (T, False);
24193 end if;
24195 -- Set flag in entity itself. Note that we will go through the following
24196 -- circuitry even if the flag is already set on T. That's intentional,
24197 -- it makes sure that the flag will be set in subsidiary entities.
24199 Set_Needs_Debug_Info (T);
24201 -- Set flag on subsidiary entities if not set already
24203 if Is_Object (T) then
24204 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24206 elsif Is_Type (T) then
24207 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24209 if Is_Record_Type (T) then
24210 declare
24211 Ent : Entity_Id := First_Entity (T);
24212 begin
24213 while Present (Ent) loop
24214 Set_Debug_Info_Needed_If_Not_Set (Ent);
24215 Next_Entity (Ent);
24216 end loop;
24217 end;
24219 -- For a class wide subtype, we also need debug information
24220 -- for the equivalent type.
24222 if Ekind (T) = E_Class_Wide_Subtype then
24223 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
24224 end if;
24226 elsif Is_Array_Type (T) then
24227 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
24229 declare
24230 Indx : Node_Id := First_Index (T);
24231 begin
24232 while Present (Indx) loop
24233 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
24234 Indx := Next_Index (Indx);
24235 end loop;
24236 end;
24238 -- For a packed array type, we also need debug information for
24239 -- the type used to represent the packed array. Conversely, we
24240 -- also need it for the former if we need it for the latter.
24242 if Is_Packed (T) then
24243 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
24244 end if;
24246 if Is_Packed_Array_Impl_Type (T) then
24247 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
24248 end if;
24250 elsif Is_Access_Type (T) then
24251 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
24253 elsif Is_Private_Type (T) then
24254 declare
24255 FV : constant Entity_Id := Full_View (T);
24257 begin
24258 Set_Debug_Info_Needed_If_Not_Set (FV);
24260 -- If the full view is itself a derived private type, we need
24261 -- debug information on its underlying type.
24263 if Present (FV)
24264 and then Is_Private_Type (FV)
24265 and then Present (Underlying_Full_View (FV))
24266 then
24267 Set_Needs_Debug_Info (Underlying_Full_View (FV));
24268 end if;
24269 end;
24271 elsif Is_Protected_Type (T) then
24272 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
24274 elsif Is_Scalar_Type (T) then
24276 -- If the subrange bounds are materialized by dedicated constant
24277 -- objects, also include them in the debug info to make sure the
24278 -- debugger can properly use them.
24280 if Present (Scalar_Range (T))
24281 and then Nkind (Scalar_Range (T)) = N_Range
24282 then
24283 declare
24284 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
24285 High_Bnd : constant Node_Id := Type_High_Bound (T);
24287 begin
24288 if Is_Entity_Name (Low_Bnd) then
24289 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
24290 end if;
24292 if Is_Entity_Name (High_Bnd) then
24293 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
24294 end if;
24295 end;
24296 end if;
24297 end if;
24298 end if;
24299 end Set_Debug_Info_Needed;
24301 ----------------------------
24302 -- Set_Entity_With_Checks --
24303 ----------------------------
24305 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
24306 Val_Actual : Entity_Id;
24307 Nod : Node_Id;
24308 Post_Node : Node_Id;
24310 begin
24311 -- Unconditionally set the entity
24313 Set_Entity (N, Val);
24315 -- The node to post on is the selector in the case of an expanded name,
24316 -- and otherwise the node itself.
24318 if Nkind (N) = N_Expanded_Name then
24319 Post_Node := Selector_Name (N);
24320 else
24321 Post_Node := N;
24322 end if;
24324 -- Check for violation of No_Fixed_IO
24326 if Restriction_Check_Required (No_Fixed_IO)
24327 and then
24328 ((RTU_Loaded (Ada_Text_IO)
24329 and then (Is_RTE (Val, RE_Decimal_IO)
24330 or else
24331 Is_RTE (Val, RE_Fixed_IO)))
24333 or else
24334 (RTU_Loaded (Ada_Wide_Text_IO)
24335 and then (Is_RTE (Val, RO_WT_Decimal_IO)
24336 or else
24337 Is_RTE (Val, RO_WT_Fixed_IO)))
24339 or else
24340 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
24341 and then (Is_RTE (Val, RO_WW_Decimal_IO)
24342 or else
24343 Is_RTE (Val, RO_WW_Fixed_IO))))
24345 -- A special extra check, don't complain about a reference from within
24346 -- the Ada.Interrupts package itself!
24348 and then not In_Same_Extended_Unit (N, Val)
24349 then
24350 Check_Restriction (No_Fixed_IO, Post_Node);
24351 end if;
24353 -- Remaining checks are only done on source nodes. Note that we test
24354 -- for violation of No_Fixed_IO even on non-source nodes, because the
24355 -- cases for checking violations of this restriction are instantiations
24356 -- where the reference in the instance has Comes_From_Source False.
24358 if not Comes_From_Source (N) then
24359 return;
24360 end if;
24362 -- Check for violation of No_Abort_Statements, which is triggered by
24363 -- call to Ada.Task_Identification.Abort_Task.
24365 if Restriction_Check_Required (No_Abort_Statements)
24366 and then (Is_RTE (Val, RE_Abort_Task))
24368 -- A special extra check, don't complain about a reference from within
24369 -- the Ada.Task_Identification package itself!
24371 and then not In_Same_Extended_Unit (N, Val)
24372 then
24373 Check_Restriction (No_Abort_Statements, Post_Node);
24374 end if;
24376 if Val = Standard_Long_Long_Integer then
24377 Check_Restriction (No_Long_Long_Integers, Post_Node);
24378 end if;
24380 -- Check for violation of No_Dynamic_Attachment
24382 if Restriction_Check_Required (No_Dynamic_Attachment)
24383 and then RTU_Loaded (Ada_Interrupts)
24384 and then (Is_RTE (Val, RE_Is_Reserved) or else
24385 Is_RTE (Val, RE_Is_Attached) or else
24386 Is_RTE (Val, RE_Current_Handler) or else
24387 Is_RTE (Val, RE_Attach_Handler) or else
24388 Is_RTE (Val, RE_Exchange_Handler) or else
24389 Is_RTE (Val, RE_Detach_Handler) or else
24390 Is_RTE (Val, RE_Reference))
24392 -- A special extra check, don't complain about a reference from within
24393 -- the Ada.Interrupts package itself!
24395 and then not In_Same_Extended_Unit (N, Val)
24396 then
24397 Check_Restriction (No_Dynamic_Attachment, Post_Node);
24398 end if;
24400 -- Check for No_Implementation_Identifiers
24402 if Restriction_Check_Required (No_Implementation_Identifiers) then
24404 -- We have an implementation defined entity if it is marked as
24405 -- implementation defined, or is defined in a package marked as
24406 -- implementation defined. However, library packages themselves
24407 -- are excluded (we don't want to flag Interfaces itself, just
24408 -- the entities within it).
24410 if (Is_Implementation_Defined (Val)
24411 or else
24412 (Present (Scope (Val))
24413 and then Is_Implementation_Defined (Scope (Val))))
24414 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
24415 and then Is_Library_Level_Entity (Val))
24416 then
24417 Check_Restriction (No_Implementation_Identifiers, Post_Node);
24418 end if;
24419 end if;
24421 -- Do the style check
24423 if Style_Check
24424 and then not Suppress_Style_Checks (Val)
24425 and then not In_Instance
24426 then
24427 if Nkind (N) = N_Identifier then
24428 Nod := N;
24429 elsif Nkind (N) = N_Expanded_Name then
24430 Nod := Selector_Name (N);
24431 else
24432 return;
24433 end if;
24435 -- A special situation arises for derived operations, where we want
24436 -- to do the check against the parent (since the Sloc of the derived
24437 -- operation points to the derived type declaration itself).
24439 Val_Actual := Val;
24440 while not Comes_From_Source (Val_Actual)
24441 and then Nkind (Val_Actual) in N_Entity
24442 and then (Ekind (Val_Actual) = E_Enumeration_Literal
24443 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
24444 and then Present (Alias (Val_Actual))
24445 loop
24446 Val_Actual := Alias (Val_Actual);
24447 end loop;
24449 -- Renaming declarations for generic actuals do not come from source,
24450 -- and have a different name from that of the entity they rename, so
24451 -- there is no style check to perform here.
24453 if Chars (Nod) = Chars (Val_Actual) then
24454 Style.Check_Identifier (Nod, Val_Actual);
24455 end if;
24456 end if;
24458 Set_Entity (N, Val);
24459 end Set_Entity_With_Checks;
24461 ------------------------------
24462 -- Set_Invalid_Scalar_Value --
24463 ------------------------------
24465 procedure Set_Invalid_Scalar_Value
24466 (Scal_Typ : Float_Scalar_Id;
24467 Value : Ureal)
24469 Slot : Ureal renames Invalid_Floats (Scal_Typ);
24471 begin
24472 -- Detect an attempt to set a different value for the same scalar type
24474 pragma Assert (Slot = No_Ureal);
24475 Slot := Value;
24476 end Set_Invalid_Scalar_Value;
24478 ------------------------------
24479 -- Set_Invalid_Scalar_Value --
24480 ------------------------------
24482 procedure Set_Invalid_Scalar_Value
24483 (Scal_Typ : Integer_Scalar_Id;
24484 Value : Uint)
24486 Slot : Uint renames Invalid_Integers (Scal_Typ);
24488 begin
24489 -- Detect an attempt to set a different value for the same scalar type
24491 pragma Assert (Slot = No_Uint);
24492 Slot := Value;
24493 end Set_Invalid_Scalar_Value;
24495 ------------------------
24496 -- Set_Name_Entity_Id --
24497 ------------------------
24499 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
24500 begin
24501 Set_Name_Table_Int (Id, Int (Val));
24502 end Set_Name_Entity_Id;
24504 ---------------------
24505 -- Set_Next_Actual --
24506 ---------------------
24508 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
24509 begin
24510 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
24511 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
24512 end if;
24513 end Set_Next_Actual;
24515 ----------------------------------
24516 -- Set_Optimize_Alignment_Flags --
24517 ----------------------------------
24519 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
24520 begin
24521 if Optimize_Alignment = 'S' then
24522 Set_Optimize_Alignment_Space (E);
24523 elsif Optimize_Alignment = 'T' then
24524 Set_Optimize_Alignment_Time (E);
24525 end if;
24526 end Set_Optimize_Alignment_Flags;
24528 -----------------------
24529 -- Set_Public_Status --
24530 -----------------------
24532 procedure Set_Public_Status (Id : Entity_Id) is
24533 S : constant Entity_Id := Current_Scope;
24535 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
24536 -- Determines if E is defined within handled statement sequence or
24537 -- an if statement, returns True if so, False otherwise.
24539 ----------------------
24540 -- Within_HSS_Or_If --
24541 ----------------------
24543 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
24544 N : Node_Id;
24545 begin
24546 N := Declaration_Node (E);
24547 loop
24548 N := Parent (N);
24550 if No (N) then
24551 return False;
24553 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
24554 N_If_Statement)
24555 then
24556 return True;
24557 end if;
24558 end loop;
24559 end Within_HSS_Or_If;
24561 -- Start of processing for Set_Public_Status
24563 begin
24564 -- Everything in the scope of Standard is public
24566 if S = Standard_Standard then
24567 Set_Is_Public (Id);
24569 -- Entity is definitely not public if enclosing scope is not public
24571 elsif not Is_Public (S) then
24572 return;
24574 -- An object or function declaration that occurs in a handled sequence
24575 -- of statements or within an if statement is the declaration for a
24576 -- temporary object or local subprogram generated by the expander. It
24577 -- never needs to be made public and furthermore, making it public can
24578 -- cause back end problems.
24580 elsif Nkind_In (Parent (Id), N_Object_Declaration,
24581 N_Function_Specification)
24582 and then Within_HSS_Or_If (Id)
24583 then
24584 return;
24586 -- Entities in public packages or records are public
24588 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
24589 Set_Is_Public (Id);
24591 -- The bounds of an entry family declaration can generate object
24592 -- declarations that are visible to the back-end, e.g. in the
24593 -- the declaration of a composite type that contains tasks.
24595 elsif Is_Concurrent_Type (S)
24596 and then not Has_Completion (S)
24597 and then Nkind (Parent (Id)) = N_Object_Declaration
24598 then
24599 Set_Is_Public (Id);
24600 end if;
24601 end Set_Public_Status;
24603 -----------------------------
24604 -- Set_Referenced_Modified --
24605 -----------------------------
24607 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
24608 Pref : Node_Id;
24610 begin
24611 -- Deal with indexed or selected component where prefix is modified
24613 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
24614 Pref := Prefix (N);
24616 -- If prefix is access type, then it is the designated object that is
24617 -- being modified, which means we have no entity to set the flag on.
24619 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
24620 return;
24622 -- Otherwise chase the prefix
24624 else
24625 Set_Referenced_Modified (Pref, Out_Param);
24626 end if;
24628 -- Otherwise see if we have an entity name (only other case to process)
24630 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
24631 Set_Referenced_As_LHS (Entity (N), not Out_Param);
24632 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
24633 end if;
24634 end Set_Referenced_Modified;
24636 ------------------
24637 -- Set_Rep_Info --
24638 ------------------
24640 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
24641 begin
24642 Set_Is_Atomic (T1, Is_Atomic (T2));
24643 Set_Is_Independent (T1, Is_Independent (T2));
24644 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
24646 if Is_Base_Type (T1) then
24647 Set_Is_Volatile (T1, Is_Volatile (T2));
24648 end if;
24649 end Set_Rep_Info;
24651 ----------------------------
24652 -- Set_Scope_Is_Transient --
24653 ----------------------------
24655 procedure Set_Scope_Is_Transient (V : Boolean := True) is
24656 begin
24657 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
24658 end Set_Scope_Is_Transient;
24660 -------------------
24661 -- Set_Size_Info --
24662 -------------------
24664 procedure Set_Size_Info (T1, T2 : Entity_Id) is
24665 begin
24666 -- We copy Esize, but not RM_Size, since in general RM_Size is
24667 -- subtype specific and does not get inherited by all subtypes.
24669 Set_Esize (T1, Esize (T2));
24670 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
24672 if Is_Discrete_Or_Fixed_Point_Type (T1)
24673 and then
24674 Is_Discrete_Or_Fixed_Point_Type (T2)
24675 then
24676 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
24677 end if;
24679 Set_Alignment (T1, Alignment (T2));
24680 end Set_Size_Info;
24682 ------------------------------
24683 -- Should_Ignore_Pragma_Par --
24684 ------------------------------
24686 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
24687 pragma Assert (Compiler_State = Parsing);
24688 -- This one can't work during semantic analysis, because we don't have a
24689 -- correct Current_Source_File.
24691 Result : constant Boolean :=
24692 Get_Name_Table_Boolean3 (Prag_Name)
24693 and then not Is_Internal_File_Name
24694 (File_Name (Current_Source_File));
24695 begin
24696 return Result;
24697 end Should_Ignore_Pragma_Par;
24699 ------------------------------
24700 -- Should_Ignore_Pragma_Sem --
24701 ------------------------------
24703 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
24704 pragma Assert (Compiler_State = Analyzing);
24705 Prag_Name : constant Name_Id := Pragma_Name (N);
24706 Result : constant Boolean :=
24707 Get_Name_Table_Boolean3 (Prag_Name)
24708 and then not In_Internal_Unit (N);
24710 begin
24711 return Result;
24712 end Should_Ignore_Pragma_Sem;
24714 --------------------
24715 -- Static_Boolean --
24716 --------------------
24718 function Static_Boolean (N : Node_Id) return Uint is
24719 begin
24720 Analyze_And_Resolve (N, Standard_Boolean);
24722 if N = Error
24723 or else Error_Posted (N)
24724 or else Etype (N) = Any_Type
24725 then
24726 return No_Uint;
24727 end if;
24729 if Is_OK_Static_Expression (N) then
24730 if not Raises_Constraint_Error (N) then
24731 return Expr_Value (N);
24732 else
24733 return No_Uint;
24734 end if;
24736 elsif Etype (N) = Any_Type then
24737 return No_Uint;
24739 else
24740 Flag_Non_Static_Expr
24741 ("static boolean expression required here", N);
24742 return No_Uint;
24743 end if;
24744 end Static_Boolean;
24746 --------------------
24747 -- Static_Integer --
24748 --------------------
24750 function Static_Integer (N : Node_Id) return Uint is
24751 begin
24752 Analyze_And_Resolve (N, Any_Integer);
24754 if N = Error
24755 or else Error_Posted (N)
24756 or else Etype (N) = Any_Type
24757 then
24758 return No_Uint;
24759 end if;
24761 if Is_OK_Static_Expression (N) then
24762 if not Raises_Constraint_Error (N) then
24763 return Expr_Value (N);
24764 else
24765 return No_Uint;
24766 end if;
24768 elsif Etype (N) = Any_Type then
24769 return No_Uint;
24771 else
24772 Flag_Non_Static_Expr
24773 ("static integer expression required here", N);
24774 return No_Uint;
24775 end if;
24776 end Static_Integer;
24778 --------------------------
24779 -- Statically_Different --
24780 --------------------------
24782 function Statically_Different (E1, E2 : Node_Id) return Boolean is
24783 R1 : constant Node_Id := Get_Referenced_Object (E1);
24784 R2 : constant Node_Id := Get_Referenced_Object (E2);
24785 begin
24786 return Is_Entity_Name (R1)
24787 and then Is_Entity_Name (R2)
24788 and then Entity (R1) /= Entity (R2)
24789 and then not Is_Formal (Entity (R1))
24790 and then not Is_Formal (Entity (R2));
24791 end Statically_Different;
24793 --------------------------------------
24794 -- Subject_To_Loop_Entry_Attributes --
24795 --------------------------------------
24797 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
24798 Stmt : Node_Id;
24800 begin
24801 Stmt := N;
24803 -- The expansion mechanism transform a loop subject to at least one
24804 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
24805 -- the conditional part.
24807 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
24808 and then Nkind (Original_Node (N)) = N_Loop_Statement
24809 then
24810 Stmt := Original_Node (N);
24811 end if;
24813 return
24814 Nkind (Stmt) = N_Loop_Statement
24815 and then Present (Identifier (Stmt))
24816 and then Present (Entity (Identifier (Stmt)))
24817 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
24818 end Subject_To_Loop_Entry_Attributes;
24820 -----------------------------
24821 -- Subprogram_Access_Level --
24822 -----------------------------
24824 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
24825 begin
24826 if Present (Alias (Subp)) then
24827 return Subprogram_Access_Level (Alias (Subp));
24828 else
24829 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
24830 end if;
24831 end Subprogram_Access_Level;
24833 ---------------------
24834 -- Subprogram_Name --
24835 ---------------------
24837 function Subprogram_Name (N : Node_Id) return String is
24838 Buf : Bounded_String;
24839 Ent : Node_Id := N;
24840 Nod : Node_Id;
24842 begin
24843 while Present (Ent) loop
24844 case Nkind (Ent) is
24845 when N_Subprogram_Body =>
24846 Ent := Defining_Unit_Name (Specification (Ent));
24847 exit;
24849 when N_Subprogram_Declaration =>
24850 Nod := Corresponding_Body (Ent);
24852 if Present (Nod) then
24853 Ent := Nod;
24854 else
24855 Ent := Defining_Unit_Name (Specification (Ent));
24856 end if;
24858 exit;
24860 when N_Subprogram_Instantiation
24861 | N_Package_Body
24862 | N_Package_Specification
24864 Ent := Defining_Unit_Name (Ent);
24865 exit;
24867 when N_Protected_Type_Declaration =>
24868 Ent := Corresponding_Body (Ent);
24869 exit;
24871 when N_Protected_Body
24872 | N_Task_Body
24874 Ent := Defining_Identifier (Ent);
24875 exit;
24877 when others =>
24878 null;
24879 end case;
24881 Ent := Parent (Ent);
24882 end loop;
24884 if No (Ent) then
24885 return "unknown subprogram:unknown file:0:0";
24886 end if;
24888 -- If the subprogram is a child unit, use its simple name to start the
24889 -- construction of the fully qualified name.
24891 if Nkind (Ent) = N_Defining_Program_Unit_Name then
24892 Ent := Defining_Identifier (Ent);
24893 end if;
24895 Append_Entity_Name (Buf, Ent);
24897 -- Append homonym number if needed
24899 if Nkind (N) in N_Entity and then Has_Homonym (N) then
24900 declare
24901 H : Entity_Id := Homonym (N);
24902 Nr : Nat := 1;
24904 begin
24905 while Present (H) loop
24906 if Scope (H) = Scope (N) then
24907 Nr := Nr + 1;
24908 end if;
24910 H := Homonym (H);
24911 end loop;
24913 if Nr > 1 then
24914 Append (Buf, '#');
24915 Append (Buf, Nr);
24916 end if;
24917 end;
24918 end if;
24920 -- Append source location of Ent to Buf so that the string will
24921 -- look like "subp:file:line:col".
24923 declare
24924 Loc : constant Source_Ptr := Sloc (Ent);
24925 begin
24926 Append (Buf, ':');
24927 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
24928 Append (Buf, ':');
24929 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
24930 Append (Buf, ':');
24931 Append (Buf, Nat (Get_Column_Number (Loc)));
24932 end;
24934 return +Buf;
24935 end Subprogram_Name;
24937 -------------------------------
24938 -- Support_Atomic_Primitives --
24939 -------------------------------
24941 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
24942 Size : Int;
24944 begin
24945 -- Verify the alignment of Typ is known
24947 if not Known_Alignment (Typ) then
24948 return False;
24949 end if;
24951 if Known_Static_Esize (Typ) then
24952 Size := UI_To_Int (Esize (Typ));
24954 -- If the Esize (Object_Size) is unknown at compile time, look at the
24955 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
24957 elsif Known_Static_RM_Size (Typ) then
24958 Size := UI_To_Int (RM_Size (Typ));
24960 -- Otherwise, the size is considered to be unknown.
24962 else
24963 return False;
24964 end if;
24966 -- Check that the size of the component is 8, 16, 32, or 64 bits and
24967 -- that Typ is properly aligned.
24969 case Size is
24970 when 8 | 16 | 32 | 64 =>
24971 return Size = UI_To_Int (Alignment (Typ)) * 8;
24973 when others =>
24974 return False;
24975 end case;
24976 end Support_Atomic_Primitives;
24978 -----------------
24979 -- Trace_Scope --
24980 -----------------
24982 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
24983 begin
24984 if Debug_Flag_W then
24985 for J in 0 .. Scope_Stack.Last loop
24986 Write_Str (" ");
24987 end loop;
24989 Write_Str (Msg);
24990 Write_Name (Chars (E));
24991 Write_Str (" from ");
24992 Write_Location (Sloc (N));
24993 Write_Eol;
24994 end if;
24995 end Trace_Scope;
24997 -----------------------
24998 -- Transfer_Entities --
24999 -----------------------
25001 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
25002 procedure Set_Public_Status_Of (Id : Entity_Id);
25003 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
25004 -- Set_Public_Status. If successful and Id denotes a record type, set
25005 -- the Is_Public attribute of its fields.
25007 --------------------------
25008 -- Set_Public_Status_Of --
25009 --------------------------
25011 procedure Set_Public_Status_Of (Id : Entity_Id) is
25012 Field : Entity_Id;
25014 begin
25015 if not Is_Public (Id) then
25016 Set_Public_Status (Id);
25018 -- When the input entity is a public record type, ensure that all
25019 -- its internal fields are also exposed to the linker. The fields
25020 -- of a class-wide type are never made public.
25022 if Is_Public (Id)
25023 and then Is_Record_Type (Id)
25024 and then not Is_Class_Wide_Type (Id)
25025 then
25026 Field := First_Entity (Id);
25027 while Present (Field) loop
25028 Set_Is_Public (Field);
25029 Next_Entity (Field);
25030 end loop;
25031 end if;
25032 end if;
25033 end Set_Public_Status_Of;
25035 -- Local variables
25037 Full_Id : Entity_Id;
25038 Id : Entity_Id;
25040 -- Start of processing for Transfer_Entities
25042 begin
25043 Id := First_Entity (From);
25045 if Present (Id) then
25047 -- Merge the entity chain of the source scope with that of the
25048 -- destination scope.
25050 if Present (Last_Entity (To)) then
25051 Link_Entities (Last_Entity (To), Id);
25052 else
25053 Set_First_Entity (To, Id);
25054 end if;
25056 Set_Last_Entity (To, Last_Entity (From));
25058 -- Inspect the entities of the source scope and update their Scope
25059 -- attribute.
25061 while Present (Id) loop
25062 Set_Scope (Id, To);
25063 Set_Public_Status_Of (Id);
25065 -- Handle an internally generated full view for a private type
25067 if Is_Private_Type (Id)
25068 and then Present (Full_View (Id))
25069 and then Is_Itype (Full_View (Id))
25070 then
25071 Full_Id := Full_View (Id);
25073 Set_Scope (Full_Id, To);
25074 Set_Public_Status_Of (Full_Id);
25075 end if;
25077 Next_Entity (Id);
25078 end loop;
25080 Set_First_Entity (From, Empty);
25081 Set_Last_Entity (From, Empty);
25082 end if;
25083 end Transfer_Entities;
25085 -----------------------
25086 -- Type_Access_Level --
25087 -----------------------
25089 function Type_Access_Level (Typ : Entity_Id) return Uint is
25090 Btyp : Entity_Id;
25092 begin
25093 Btyp := Base_Type (Typ);
25095 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
25096 -- simply use the level where the type is declared. This is true for
25097 -- stand-alone object declarations, and for anonymous access types
25098 -- associated with components the level is the same as that of the
25099 -- enclosing composite type. However, special treatment is needed for
25100 -- the cases of access parameters, return objects of an anonymous access
25101 -- type, and, in Ada 95, access discriminants of limited types.
25103 if Is_Access_Type (Btyp) then
25104 if Ekind (Btyp) = E_Anonymous_Access_Type then
25106 -- If the type is a nonlocal anonymous access type (such as for
25107 -- an access parameter) we treat it as being declared at the
25108 -- library level to ensure that names such as X.all'access don't
25109 -- fail static accessibility checks.
25111 if not Is_Local_Anonymous_Access (Typ) then
25112 return Scope_Depth (Standard_Standard);
25114 -- If this is a return object, the accessibility level is that of
25115 -- the result subtype of the enclosing function. The test here is
25116 -- little complicated, because we have to account for extended
25117 -- return statements that have been rewritten as blocks, in which
25118 -- case we have to find and the Is_Return_Object attribute of the
25119 -- itype's associated object. It would be nice to find a way to
25120 -- simplify this test, but it doesn't seem worthwhile to add a new
25121 -- flag just for purposes of this test. ???
25123 elsif Ekind (Scope (Btyp)) = E_Return_Statement
25124 or else
25125 (Is_Itype (Btyp)
25126 and then Nkind (Associated_Node_For_Itype (Btyp)) =
25127 N_Object_Declaration
25128 and then Is_Return_Object
25129 (Defining_Identifier
25130 (Associated_Node_For_Itype (Btyp))))
25131 then
25132 declare
25133 Scop : Entity_Id;
25135 begin
25136 Scop := Scope (Scope (Btyp));
25137 while Present (Scop) loop
25138 exit when Ekind (Scop) = E_Function;
25139 Scop := Scope (Scop);
25140 end loop;
25142 -- Treat the return object's type as having the level of the
25143 -- function's result subtype (as per RM05-6.5(5.3/2)).
25145 return Type_Access_Level (Etype (Scop));
25146 end;
25147 end if;
25148 end if;
25150 Btyp := Root_Type (Btyp);
25152 -- The accessibility level of anonymous access types associated with
25153 -- discriminants is that of the current instance of the type, and
25154 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
25156 -- AI-402: access discriminants have accessibility based on the
25157 -- object rather than the type in Ada 2005, so the above paragraph
25158 -- doesn't apply.
25160 -- ??? Needs completion with rules from AI-416
25162 if Ada_Version <= Ada_95
25163 and then Ekind (Typ) = E_Anonymous_Access_Type
25164 and then Present (Associated_Node_For_Itype (Typ))
25165 and then Nkind (Associated_Node_For_Itype (Typ)) =
25166 N_Discriminant_Specification
25167 then
25168 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
25169 end if;
25170 end if;
25172 -- Return library level for a generic formal type. This is done because
25173 -- RM(10.3.2) says that "The statically deeper relationship does not
25174 -- apply to ... a descendant of a generic formal type". Rather than
25175 -- checking at each point where a static accessibility check is
25176 -- performed to see if we are dealing with a formal type, this rule is
25177 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
25178 -- return extreme values for a formal type; Deepest_Type_Access_Level
25179 -- returns Int'Last. By calling the appropriate function from among the
25180 -- two, we ensure that the static accessibility check will pass if we
25181 -- happen to run into a formal type. More specifically, we should call
25182 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
25183 -- call occurs as part of a static accessibility check and the error
25184 -- case is the case where the type's level is too shallow (as opposed
25185 -- to too deep).
25187 if Is_Generic_Type (Root_Type (Btyp)) then
25188 return Scope_Depth (Standard_Standard);
25189 end if;
25191 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
25192 end Type_Access_Level;
25194 ------------------------------------
25195 -- Type_Without_Stream_Operation --
25196 ------------------------------------
25198 function Type_Without_Stream_Operation
25199 (T : Entity_Id;
25200 Op : TSS_Name_Type := TSS_Null) return Entity_Id
25202 BT : constant Entity_Id := Base_Type (T);
25203 Op_Missing : Boolean;
25205 begin
25206 if not Restriction_Active (No_Default_Stream_Attributes) then
25207 return Empty;
25208 end if;
25210 if Is_Elementary_Type (T) then
25211 if Op = TSS_Null then
25212 Op_Missing :=
25213 No (TSS (BT, TSS_Stream_Read))
25214 or else No (TSS (BT, TSS_Stream_Write));
25216 else
25217 Op_Missing := No (TSS (BT, Op));
25218 end if;
25220 if Op_Missing then
25221 return T;
25222 else
25223 return Empty;
25224 end if;
25226 elsif Is_Array_Type (T) then
25227 return Type_Without_Stream_Operation (Component_Type (T), Op);
25229 elsif Is_Record_Type (T) then
25230 declare
25231 Comp : Entity_Id;
25232 C_Typ : Entity_Id;
25234 begin
25235 Comp := First_Component (T);
25236 while Present (Comp) loop
25237 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
25239 if Present (C_Typ) then
25240 return C_Typ;
25241 end if;
25243 Next_Component (Comp);
25244 end loop;
25246 return Empty;
25247 end;
25249 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
25250 return Type_Without_Stream_Operation (Full_View (T), Op);
25251 else
25252 return Empty;
25253 end if;
25254 end Type_Without_Stream_Operation;
25256 ----------------------------
25257 -- Unique_Defining_Entity --
25258 ----------------------------
25260 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
25261 begin
25262 return Unique_Entity (Defining_Entity (N));
25263 end Unique_Defining_Entity;
25265 -------------------
25266 -- Unique_Entity --
25267 -------------------
25269 function Unique_Entity (E : Entity_Id) return Entity_Id is
25270 U : Entity_Id := E;
25271 P : Node_Id;
25273 begin
25274 case Ekind (E) is
25275 when E_Constant =>
25276 if Present (Full_View (E)) then
25277 U := Full_View (E);
25278 end if;
25280 when Entry_Kind =>
25281 if Nkind (Parent (E)) = N_Entry_Body then
25282 declare
25283 Prot_Item : Entity_Id;
25284 Prot_Type : Entity_Id;
25286 begin
25287 if Ekind (E) = E_Entry then
25288 Prot_Type := Scope (E);
25290 -- Bodies of entry families are nested within an extra scope
25291 -- that contains an entry index declaration.
25293 else
25294 Prot_Type := Scope (Scope (E));
25295 end if;
25297 -- A protected type may be declared as a private type, in
25298 -- which case we need to get its full view.
25300 if Is_Private_Type (Prot_Type) then
25301 Prot_Type := Full_View (Prot_Type);
25302 end if;
25304 -- Full view may not be present on error, in which case
25305 -- return E by default.
25307 if Present (Prot_Type) then
25308 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
25310 -- Traverse the entity list of the protected type and
25311 -- locate an entry declaration which matches the entry
25312 -- body.
25314 Prot_Item := First_Entity (Prot_Type);
25315 while Present (Prot_Item) loop
25316 if Ekind (Prot_Item) in Entry_Kind
25317 and then Corresponding_Body (Parent (Prot_Item)) = E
25318 then
25319 U := Prot_Item;
25320 exit;
25321 end if;
25323 Next_Entity (Prot_Item);
25324 end loop;
25325 end if;
25326 end;
25327 end if;
25329 when Formal_Kind =>
25330 if Present (Spec_Entity (E)) then
25331 U := Spec_Entity (E);
25332 end if;
25334 when E_Package_Body =>
25335 P := Parent (E);
25337 if Nkind (P) = N_Defining_Program_Unit_Name then
25338 P := Parent (P);
25339 end if;
25341 if Nkind (P) = N_Package_Body
25342 and then Present (Corresponding_Spec (P))
25343 then
25344 U := Corresponding_Spec (P);
25346 elsif Nkind (P) = N_Package_Body_Stub
25347 and then Present (Corresponding_Spec_Of_Stub (P))
25348 then
25349 U := Corresponding_Spec_Of_Stub (P);
25350 end if;
25352 when E_Protected_Body =>
25353 P := Parent (E);
25355 if Nkind (P) = N_Protected_Body
25356 and then Present (Corresponding_Spec (P))
25357 then
25358 U := Corresponding_Spec (P);
25360 elsif Nkind (P) = N_Protected_Body_Stub
25361 and then Present (Corresponding_Spec_Of_Stub (P))
25362 then
25363 U := Corresponding_Spec_Of_Stub (P);
25365 if Is_Single_Protected_Object (U) then
25366 U := Etype (U);
25367 end if;
25368 end if;
25370 if Is_Private_Type (U) then
25371 U := Full_View (U);
25372 end if;
25374 when E_Subprogram_Body =>
25375 P := Parent (E);
25377 if Nkind (P) = N_Defining_Program_Unit_Name then
25378 P := Parent (P);
25379 end if;
25381 P := Parent (P);
25383 if Nkind (P) = N_Subprogram_Body
25384 and then Present (Corresponding_Spec (P))
25385 then
25386 U := Corresponding_Spec (P);
25388 elsif Nkind (P) = N_Subprogram_Body_Stub
25389 and then Present (Corresponding_Spec_Of_Stub (P))
25390 then
25391 U := Corresponding_Spec_Of_Stub (P);
25393 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
25394 U := Corresponding_Spec (P);
25395 end if;
25397 when E_Task_Body =>
25398 P := Parent (E);
25400 if Nkind (P) = N_Task_Body
25401 and then Present (Corresponding_Spec (P))
25402 then
25403 U := Corresponding_Spec (P);
25405 elsif Nkind (P) = N_Task_Body_Stub
25406 and then Present (Corresponding_Spec_Of_Stub (P))
25407 then
25408 U := Corresponding_Spec_Of_Stub (P);
25410 if Is_Single_Task_Object (U) then
25411 U := Etype (U);
25412 end if;
25413 end if;
25415 if Is_Private_Type (U) then
25416 U := Full_View (U);
25417 end if;
25419 when Type_Kind =>
25420 if Present (Full_View (E)) then
25421 U := Full_View (E);
25422 end if;
25424 when others =>
25425 null;
25426 end case;
25428 return U;
25429 end Unique_Entity;
25431 -----------------
25432 -- Unique_Name --
25433 -----------------
25435 function Unique_Name (E : Entity_Id) return String is
25437 -- Names in E_Subprogram_Body or E_Package_Body entities are not
25438 -- reliable, as they may not include the overloading suffix. Instead,
25439 -- when looking for the name of E or one of its enclosing scope, we get
25440 -- the name of the corresponding Unique_Entity.
25442 U : constant Entity_Id := Unique_Entity (E);
25444 function This_Name return String;
25446 ---------------
25447 -- This_Name --
25448 ---------------
25450 function This_Name return String is
25451 begin
25452 return Get_Name_String (Chars (U));
25453 end This_Name;
25455 -- Start of processing for Unique_Name
25457 begin
25458 if E = Standard_Standard
25459 or else Has_Fully_Qualified_Name (E)
25460 then
25461 return This_Name;
25463 elsif Ekind (E) = E_Enumeration_Literal then
25464 return Unique_Name (Etype (E)) & "__" & This_Name;
25466 else
25467 declare
25468 S : constant Entity_Id := Scope (U);
25469 pragma Assert (Present (S));
25471 begin
25472 -- Prefix names of predefined types with standard__, but leave
25473 -- names of user-defined packages and subprograms without prefix
25474 -- (even if technically they are nested in the Standard package).
25476 if S = Standard_Standard then
25477 if Ekind (U) = E_Package or else Is_Subprogram (U) then
25478 return This_Name;
25479 else
25480 return Unique_Name (S) & "__" & This_Name;
25481 end if;
25483 -- For intances of generic subprograms use the name of the related
25484 -- instace and skip the scope of its wrapper package.
25486 elsif Is_Wrapper_Package (S) then
25487 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
25488 -- Wrapper package and the instantiation are in the same scope
25490 declare
25491 Enclosing_Name : constant String :=
25492 Unique_Name (Scope (S)) & "__" &
25493 Get_Name_String (Chars (Related_Instance (S)));
25495 begin
25496 if Is_Subprogram (U)
25497 and then not Is_Generic_Actual_Subprogram (U)
25498 then
25499 return Enclosing_Name;
25500 else
25501 return Enclosing_Name & "__" & This_Name;
25502 end if;
25503 end;
25505 else
25506 return Unique_Name (S) & "__" & This_Name;
25507 end if;
25508 end;
25509 end if;
25510 end Unique_Name;
25512 ---------------------
25513 -- Unit_Is_Visible --
25514 ---------------------
25516 function Unit_Is_Visible (U : Entity_Id) return Boolean is
25517 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
25518 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
25520 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
25521 -- For a child unit, check whether unit appears in a with_clause
25522 -- of a parent.
25524 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
25525 -- Scan the context clause of one compilation unit looking for a
25526 -- with_clause for the unit in question.
25528 ----------------------------
25529 -- Unit_In_Parent_Context --
25530 ----------------------------
25532 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
25533 begin
25534 if Unit_In_Context (Par_Unit) then
25535 return True;
25537 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
25538 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
25540 else
25541 return False;
25542 end if;
25543 end Unit_In_Parent_Context;
25545 ---------------------
25546 -- Unit_In_Context --
25547 ---------------------
25549 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
25550 Clause : Node_Id;
25552 begin
25553 Clause := First (Context_Items (Comp_Unit));
25554 while Present (Clause) loop
25555 if Nkind (Clause) = N_With_Clause then
25556 if Library_Unit (Clause) = U then
25557 return True;
25559 -- The with_clause may denote a renaming of the unit we are
25560 -- looking for, eg. Text_IO which renames Ada.Text_IO.
25562 elsif
25563 Renamed_Entity (Entity (Name (Clause))) =
25564 Defining_Entity (Unit (U))
25565 then
25566 return True;
25567 end if;
25568 end if;
25570 Next (Clause);
25571 end loop;
25573 return False;
25574 end Unit_In_Context;
25576 -- Start of processing for Unit_Is_Visible
25578 begin
25579 -- The currrent unit is directly visible
25581 if Curr = U then
25582 return True;
25584 elsif Unit_In_Context (Curr) then
25585 return True;
25587 -- If the current unit is a body, check the context of the spec
25589 elsif Nkind (Unit (Curr)) = N_Package_Body
25590 or else
25591 (Nkind (Unit (Curr)) = N_Subprogram_Body
25592 and then not Acts_As_Spec (Unit (Curr)))
25593 then
25594 if Unit_In_Context (Library_Unit (Curr)) then
25595 return True;
25596 end if;
25597 end if;
25599 -- If the spec is a child unit, examine the parents
25601 if Is_Child_Unit (Curr_Entity) then
25602 if Nkind (Unit (Curr)) in N_Unit_Body then
25603 return
25604 Unit_In_Parent_Context
25605 (Parent_Spec (Unit (Library_Unit (Curr))));
25606 else
25607 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
25608 end if;
25610 else
25611 return False;
25612 end if;
25613 end Unit_Is_Visible;
25615 ------------------------------
25616 -- Universal_Interpretation --
25617 ------------------------------
25619 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
25620 Index : Interp_Index;
25621 It : Interp;
25623 begin
25624 -- The argument may be a formal parameter of an operator or subprogram
25625 -- with multiple interpretations, or else an expression for an actual.
25627 if Nkind (Opnd) = N_Defining_Identifier
25628 or else not Is_Overloaded (Opnd)
25629 then
25630 if Etype (Opnd) = Universal_Integer
25631 or else Etype (Opnd) = Universal_Real
25632 then
25633 return Etype (Opnd);
25634 else
25635 return Empty;
25636 end if;
25638 else
25639 Get_First_Interp (Opnd, Index, It);
25640 while Present (It.Typ) loop
25641 if It.Typ = Universal_Integer
25642 or else It.Typ = Universal_Real
25643 then
25644 return It.Typ;
25645 end if;
25647 Get_Next_Interp (Index, It);
25648 end loop;
25650 return Empty;
25651 end if;
25652 end Universal_Interpretation;
25654 ---------------
25655 -- Unqualify --
25656 ---------------
25658 function Unqualify (Expr : Node_Id) return Node_Id is
25659 begin
25660 -- Recurse to handle unlikely case of multiple levels of qualification
25662 if Nkind (Expr) = N_Qualified_Expression then
25663 return Unqualify (Expression (Expr));
25665 -- Normal case, not a qualified expression
25667 else
25668 return Expr;
25669 end if;
25670 end Unqualify;
25672 -----------------
25673 -- Unqual_Conv --
25674 -----------------
25676 function Unqual_Conv (Expr : Node_Id) return Node_Id is
25677 begin
25678 -- Recurse to handle unlikely case of multiple levels of qualification
25679 -- and/or conversion.
25681 if Nkind_In (Expr, N_Qualified_Expression,
25682 N_Type_Conversion,
25683 N_Unchecked_Type_Conversion)
25684 then
25685 return Unqual_Conv (Expression (Expr));
25687 -- Normal case, not a qualified expression
25689 else
25690 return Expr;
25691 end if;
25692 end Unqual_Conv;
25694 --------------------
25695 -- Validated_View --
25696 --------------------
25698 function Validated_View (Typ : Entity_Id) return Entity_Id is
25699 Continue : Boolean;
25700 Val_Typ : Entity_Id;
25702 begin
25703 Continue := True;
25704 Val_Typ := Base_Type (Typ);
25706 -- Obtain the full view of the input type by stripping away concurrency,
25707 -- derivations, and privacy.
25709 while Continue loop
25710 Continue := False;
25712 if Is_Concurrent_Type (Val_Typ) then
25713 if Present (Corresponding_Record_Type (Val_Typ)) then
25714 Continue := True;
25715 Val_Typ := Corresponding_Record_Type (Val_Typ);
25716 end if;
25718 elsif Is_Derived_Type (Val_Typ) then
25719 Continue := True;
25720 Val_Typ := Etype (Val_Typ);
25722 elsif Is_Private_Type (Val_Typ) then
25723 if Present (Underlying_Full_View (Val_Typ)) then
25724 Continue := True;
25725 Val_Typ := Underlying_Full_View (Val_Typ);
25727 elsif Present (Full_View (Val_Typ)) then
25728 Continue := True;
25729 Val_Typ := Full_View (Val_Typ);
25730 end if;
25731 end if;
25732 end loop;
25734 return Val_Typ;
25735 end Validated_View;
25737 -----------------------
25738 -- Visible_Ancestors --
25739 -----------------------
25741 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
25742 List_1 : Elist_Id;
25743 List_2 : Elist_Id;
25744 Elmt : Elmt_Id;
25746 begin
25747 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
25749 -- Collect all the parents and progenitors of Typ. If the full-view of
25750 -- private parents and progenitors is available then it is used to
25751 -- generate the list of visible ancestors; otherwise their partial
25752 -- view is added to the resulting list.
25754 Collect_Parents
25755 (T => Typ,
25756 List => List_1,
25757 Use_Full_View => True);
25759 Collect_Interfaces
25760 (T => Typ,
25761 Ifaces_List => List_2,
25762 Exclude_Parents => True,
25763 Use_Full_View => True);
25765 -- Join the two lists. Avoid duplications because an interface may
25766 -- simultaneously be parent and progenitor of a type.
25768 Elmt := First_Elmt (List_2);
25769 while Present (Elmt) loop
25770 Append_Unique_Elmt (Node (Elmt), List_1);
25771 Next_Elmt (Elmt);
25772 end loop;
25774 return List_1;
25775 end Visible_Ancestors;
25777 ----------------------
25778 -- Within_Init_Proc --
25779 ----------------------
25781 function Within_Init_Proc return Boolean is
25782 S : Entity_Id;
25784 begin
25785 S := Current_Scope;
25786 while not Is_Overloadable (S) loop
25787 if S = Standard_Standard then
25788 return False;
25789 else
25790 S := Scope (S);
25791 end if;
25792 end loop;
25794 return Is_Init_Proc (S);
25795 end Within_Init_Proc;
25797 ---------------------------
25798 -- Within_Protected_Type --
25799 ---------------------------
25801 function Within_Protected_Type (E : Entity_Id) return Boolean is
25802 Scop : Entity_Id := Scope (E);
25804 begin
25805 while Present (Scop) loop
25806 if Ekind (Scop) = E_Protected_Type then
25807 return True;
25808 end if;
25810 Scop := Scope (Scop);
25811 end loop;
25813 return False;
25814 end Within_Protected_Type;
25816 ------------------
25817 -- Within_Scope --
25818 ------------------
25820 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
25821 begin
25822 return Scope_Within_Or_Same (Scope (E), S);
25823 end Within_Scope;
25825 ----------------------------
25826 -- Within_Subprogram_Call --
25827 ----------------------------
25829 function Within_Subprogram_Call (N : Node_Id) return Boolean is
25830 Par : Node_Id;
25832 begin
25833 -- Climb the parent chain looking for a function or procedure call
25835 Par := N;
25836 while Present (Par) loop
25837 if Nkind_In (Par, N_Entry_Call_Statement,
25838 N_Function_Call,
25839 N_Procedure_Call_Statement)
25840 then
25841 return True;
25843 -- Prevent the search from going too far
25845 elsif Is_Body_Or_Package_Declaration (Par) then
25846 exit;
25847 end if;
25849 Par := Parent (Par);
25850 end loop;
25852 return False;
25853 end Within_Subprogram_Call;
25855 ----------------
25856 -- Wrong_Type --
25857 ----------------
25859 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
25860 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
25861 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
25863 Matching_Field : Entity_Id;
25864 -- Entity to give a more precise suggestion on how to write a one-
25865 -- element positional aggregate.
25867 function Has_One_Matching_Field return Boolean;
25868 -- Determines if Expec_Type is a record type with a single component or
25869 -- discriminant whose type matches the found type or is one dimensional
25870 -- array whose component type matches the found type. In the case of
25871 -- one discriminant, we ignore the variant parts. That's not accurate,
25872 -- but good enough for the warning.
25874 ----------------------------
25875 -- Has_One_Matching_Field --
25876 ----------------------------
25878 function Has_One_Matching_Field return Boolean is
25879 E : Entity_Id;
25881 begin
25882 Matching_Field := Empty;
25884 if Is_Array_Type (Expec_Type)
25885 and then Number_Dimensions (Expec_Type) = 1
25886 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
25887 then
25888 -- Use type name if available. This excludes multidimensional
25889 -- arrays and anonymous arrays.
25891 if Comes_From_Source (Expec_Type) then
25892 Matching_Field := Expec_Type;
25894 -- For an assignment, use name of target
25896 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
25897 and then Is_Entity_Name (Name (Parent (Expr)))
25898 then
25899 Matching_Field := Entity (Name (Parent (Expr)));
25900 end if;
25902 return True;
25904 elsif not Is_Record_Type (Expec_Type) then
25905 return False;
25907 else
25908 E := First_Entity (Expec_Type);
25909 loop
25910 if No (E) then
25911 return False;
25913 elsif not Ekind_In (E, E_Discriminant, E_Component)
25914 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
25915 then
25916 Next_Entity (E);
25918 else
25919 exit;
25920 end if;
25921 end loop;
25923 if not Covers (Etype (E), Found_Type) then
25924 return False;
25926 elsif Present (Next_Entity (E))
25927 and then (Ekind (E) = E_Component
25928 or else Ekind (Next_Entity (E)) = E_Discriminant)
25929 then
25930 return False;
25932 else
25933 Matching_Field := E;
25934 return True;
25935 end if;
25936 end if;
25937 end Has_One_Matching_Field;
25939 -- Start of processing for Wrong_Type
25941 begin
25942 -- Don't output message if either type is Any_Type, or if a message
25943 -- has already been posted for this node. We need to do the latter
25944 -- check explicitly (it is ordinarily done in Errout), because we
25945 -- are using ! to force the output of the error messages.
25947 if Expec_Type = Any_Type
25948 or else Found_Type = Any_Type
25949 or else Error_Posted (Expr)
25950 then
25951 return;
25953 -- If one of the types is a Taft-Amendment type and the other it its
25954 -- completion, it must be an illegal use of a TAT in the spec, for
25955 -- which an error was already emitted. Avoid cascaded errors.
25957 elsif Is_Incomplete_Type (Expec_Type)
25958 and then Has_Completion_In_Body (Expec_Type)
25959 and then Full_View (Expec_Type) = Etype (Expr)
25960 then
25961 return;
25963 elsif Is_Incomplete_Type (Etype (Expr))
25964 and then Has_Completion_In_Body (Etype (Expr))
25965 and then Full_View (Etype (Expr)) = Expec_Type
25966 then
25967 return;
25969 -- In an instance, there is an ongoing problem with completion of
25970 -- type derived from private types. Their structure is what Gigi
25971 -- expects, but the Etype is the parent type rather than the
25972 -- derived private type itself. Do not flag error in this case. The
25973 -- private completion is an entity without a parent, like an Itype.
25974 -- Similarly, full and partial views may be incorrect in the instance.
25975 -- There is no simple way to insure that it is consistent ???
25977 -- A similar view discrepancy can happen in an inlined body, for the
25978 -- same reason: inserted body may be outside of the original package
25979 -- and only partial views are visible at the point of insertion.
25981 elsif In_Instance or else In_Inlined_Body then
25982 if Etype (Etype (Expr)) = Etype (Expected_Type)
25983 and then
25984 (Has_Private_Declaration (Expected_Type)
25985 or else Has_Private_Declaration (Etype (Expr)))
25986 and then No (Parent (Expected_Type))
25987 then
25988 return;
25990 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
25991 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
25992 then
25993 return;
25995 elsif Is_Private_Type (Expected_Type)
25996 and then Present (Full_View (Expected_Type))
25997 and then Covers (Full_View (Expected_Type), Etype (Expr))
25998 then
25999 return;
26001 -- Conversely, type of expression may be the private one
26003 elsif Is_Private_Type (Base_Type (Etype (Expr)))
26004 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
26005 then
26006 return;
26007 end if;
26008 end if;
26010 -- An interesting special check. If the expression is parenthesized
26011 -- and its type corresponds to the type of the sole component of the
26012 -- expected record type, or to the component type of the expected one
26013 -- dimensional array type, then assume we have a bad aggregate attempt.
26015 if Nkind (Expr) in N_Subexpr
26016 and then Paren_Count (Expr) /= 0
26017 and then Has_One_Matching_Field
26018 then
26019 Error_Msg_N ("positional aggregate cannot have one component", Expr);
26021 if Present (Matching_Field) then
26022 if Is_Array_Type (Expec_Type) then
26023 Error_Msg_NE
26024 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
26025 else
26026 Error_Msg_NE
26027 ("\write instead `& ='> ...`", Expr, Matching_Field);
26028 end if;
26029 end if;
26031 -- Another special check, if we are looking for a pool-specific access
26032 -- type and we found an E_Access_Attribute_Type, then we have the case
26033 -- of an Access attribute being used in a context which needs a pool-
26034 -- specific type, which is never allowed. The one extra check we make
26035 -- is that the expected designated type covers the Found_Type.
26037 elsif Is_Access_Type (Expec_Type)
26038 and then Ekind (Found_Type) = E_Access_Attribute_Type
26039 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
26040 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
26041 and then Covers
26042 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
26043 then
26044 Error_Msg_N -- CODEFIX
26045 ("result must be general access type!", Expr);
26046 Error_Msg_NE -- CODEFIX
26047 ("add ALL to }!", Expr, Expec_Type);
26049 -- Another special check, if the expected type is an integer type,
26050 -- but the expression is of type System.Address, and the parent is
26051 -- an addition or subtraction operation whose left operand is the
26052 -- expression in question and whose right operand is of an integral
26053 -- type, then this is an attempt at address arithmetic, so give
26054 -- appropriate message.
26056 elsif Is_Integer_Type (Expec_Type)
26057 and then Is_RTE (Found_Type, RE_Address)
26058 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
26059 and then Expr = Left_Opnd (Parent (Expr))
26060 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
26061 then
26062 Error_Msg_N
26063 ("address arithmetic not predefined in package System",
26064 Parent (Expr));
26065 Error_Msg_N
26066 ("\possible missing with/use of System.Storage_Elements",
26067 Parent (Expr));
26068 return;
26070 -- If the expected type is an anonymous access type, as for access
26071 -- parameters and discriminants, the error is on the designated types.
26073 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
26074 if Comes_From_Source (Expec_Type) then
26075 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26076 else
26077 Error_Msg_NE
26078 ("expected an access type with designated}",
26079 Expr, Designated_Type (Expec_Type));
26080 end if;
26082 if Is_Access_Type (Found_Type)
26083 and then not Comes_From_Source (Found_Type)
26084 then
26085 Error_Msg_NE
26086 ("\\found an access type with designated}!",
26087 Expr, Designated_Type (Found_Type));
26088 else
26089 if From_Limited_With (Found_Type) then
26090 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
26091 Error_Msg_Qual_Level := 99;
26092 Error_Msg_NE -- CODEFIX
26093 ("\\missing `WITH &;", Expr, Scope (Found_Type));
26094 Error_Msg_Qual_Level := 0;
26095 else
26096 Error_Msg_NE ("found}!", Expr, Found_Type);
26097 end if;
26098 end if;
26100 -- Normal case of one type found, some other type expected
26102 else
26103 -- If the names of the two types are the same, see if some number
26104 -- of levels of qualification will help. Don't try more than three
26105 -- levels, and if we get to standard, it's no use (and probably
26106 -- represents an error in the compiler) Also do not bother with
26107 -- internal scope names.
26109 declare
26110 Expec_Scope : Entity_Id;
26111 Found_Scope : Entity_Id;
26113 begin
26114 Expec_Scope := Expec_Type;
26115 Found_Scope := Found_Type;
26117 for Levels in Nat range 0 .. 3 loop
26118 if Chars (Expec_Scope) /= Chars (Found_Scope) then
26119 Error_Msg_Qual_Level := Levels;
26120 exit;
26121 end if;
26123 Expec_Scope := Scope (Expec_Scope);
26124 Found_Scope := Scope (Found_Scope);
26126 exit when Expec_Scope = Standard_Standard
26127 or else Found_Scope = Standard_Standard
26128 or else not Comes_From_Source (Expec_Scope)
26129 or else not Comes_From_Source (Found_Scope);
26130 end loop;
26131 end;
26133 if Is_Record_Type (Expec_Type)
26134 and then Present (Corresponding_Remote_Type (Expec_Type))
26135 then
26136 Error_Msg_NE ("expected}!", Expr,
26137 Corresponding_Remote_Type (Expec_Type));
26138 else
26139 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26140 end if;
26142 if Is_Entity_Name (Expr)
26143 and then Is_Package_Or_Generic_Package (Entity (Expr))
26144 then
26145 Error_Msg_N ("\\found package name!", Expr);
26147 elsif Is_Entity_Name (Expr)
26148 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
26149 then
26150 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
26151 Error_Msg_N
26152 ("found procedure name, possibly missing Access attribute!",
26153 Expr);
26154 else
26155 Error_Msg_N
26156 ("\\found procedure name instead of function!", Expr);
26157 end if;
26159 elsif Nkind (Expr) = N_Function_Call
26160 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
26161 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
26162 and then No (Parameter_Associations (Expr))
26163 then
26164 Error_Msg_N
26165 ("found function name, possibly missing Access attribute!",
26166 Expr);
26168 -- Catch common error: a prefix or infix operator which is not
26169 -- directly visible because the type isn't.
26171 elsif Nkind (Expr) in N_Op
26172 and then Is_Overloaded (Expr)
26173 and then not Is_Immediately_Visible (Expec_Type)
26174 and then not Is_Potentially_Use_Visible (Expec_Type)
26175 and then not In_Use (Expec_Type)
26176 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
26177 then
26178 Error_Msg_N
26179 ("operator of the type is not directly visible!", Expr);
26181 elsif Ekind (Found_Type) = E_Void
26182 and then Present (Parent (Found_Type))
26183 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
26184 then
26185 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
26187 else
26188 Error_Msg_NE ("\\found}!", Expr, Found_Type);
26189 end if;
26191 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
26192 -- of the same modular type, and (M1 and M2) = 0 was intended.
26194 if Expec_Type = Standard_Boolean
26195 and then Is_Modular_Integer_Type (Found_Type)
26196 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
26197 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
26198 then
26199 declare
26200 Op : constant Node_Id := Right_Opnd (Parent (Expr));
26201 L : constant Node_Id := Left_Opnd (Op);
26202 R : constant Node_Id := Right_Opnd (Op);
26204 begin
26205 -- The case for the message is when the left operand of the
26206 -- comparison is the same modular type, or when it is an
26207 -- integer literal (or other universal integer expression),
26208 -- which would have been typed as the modular type if the
26209 -- parens had been there.
26211 if (Etype (L) = Found_Type
26212 or else
26213 Etype (L) = Universal_Integer)
26214 and then Is_Integer_Type (Etype (R))
26215 then
26216 Error_Msg_N
26217 ("\\possible missing parens for modular operation", Expr);
26218 end if;
26219 end;
26220 end if;
26222 -- Reset error message qualification indication
26224 Error_Msg_Qual_Level := 0;
26225 end if;
26226 end Wrong_Type;
26228 --------------------------------
26229 -- Yields_Synchronized_Object --
26230 --------------------------------
26232 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
26233 Has_Sync_Comp : Boolean := False;
26234 Id : Entity_Id;
26236 begin
26237 -- An array type yields a synchronized object if its component type
26238 -- yields a synchronized object.
26240 if Is_Array_Type (Typ) then
26241 return Yields_Synchronized_Object (Component_Type (Typ));
26243 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
26244 -- yields a synchronized object by default.
26246 elsif Is_Descendant_Of_Suspension_Object (Typ) then
26247 return True;
26249 -- A protected type yields a synchronized object by default
26251 elsif Is_Protected_Type (Typ) then
26252 return True;
26254 -- A record type or type extension yields a synchronized object when its
26255 -- discriminants (if any) lack default values and all components are of
26256 -- a type that yelds a synchronized object.
26258 elsif Is_Record_Type (Typ) then
26260 -- Inspect all entities defined in the scope of the type, looking for
26261 -- components of a type that does not yeld a synchronized object or
26262 -- for discriminants with default values.
26264 Id := First_Entity (Typ);
26265 while Present (Id) loop
26266 if Comes_From_Source (Id) then
26267 if Ekind (Id) = E_Component then
26268 if Yields_Synchronized_Object (Etype (Id)) then
26269 Has_Sync_Comp := True;
26271 -- The component does not yield a synchronized object
26273 else
26274 return False;
26275 end if;
26277 elsif Ekind (Id) = E_Discriminant
26278 and then Present (Expression (Parent (Id)))
26279 then
26280 return False;
26281 end if;
26282 end if;
26284 Next_Entity (Id);
26285 end loop;
26287 -- Ensure that the parent type of a type extension yields a
26288 -- synchronized object.
26290 if Etype (Typ) /= Typ
26291 and then not Yields_Synchronized_Object (Etype (Typ))
26292 then
26293 return False;
26294 end if;
26296 -- If we get here, then all discriminants lack default values and all
26297 -- components are of a type that yields a synchronized object.
26299 return Has_Sync_Comp;
26301 -- A synchronized interface type yields a synchronized object by default
26303 elsif Is_Synchronized_Interface (Typ) then
26304 return True;
26306 -- A task type yelds a synchronized object by default
26308 elsif Is_Task_Type (Typ) then
26309 return True;
26311 -- Otherwise the type does not yield a synchronized object
26313 else
26314 return False;
26315 end if;
26316 end Yields_Synchronized_Object;
26318 ---------------------------
26319 -- Yields_Universal_Type --
26320 ---------------------------
26322 function Yields_Universal_Type (N : Node_Id) return Boolean is
26323 begin
26324 -- Integer and real literals are of a universal type
26326 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
26327 return True;
26329 -- The values of certain attributes are of a universal type
26331 elsif Nkind (N) = N_Attribute_Reference then
26332 return
26333 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
26335 -- ??? There are possibly other cases to consider
26337 else
26338 return False;
26339 end if;
26340 end Yields_Universal_Type;
26342 begin
26343 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
26344 end Sem_Util;