[NDS32] Implement bswapsi2 and bswaphi2 patterns.
[official-gcc.git] / gcc / ada / sem_util.adb
blob033903c09eadd0e83f3b08865092f2957628726e
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 -- Find the proper context where the object or state appears
3233 Scop := Scope (Id);
3234 while Present (Scop) loop
3235 Context := Scop;
3237 -- Keep track of the context's visibility
3239 Not_Visible := Not_Visible or else In_Private_Part (Context);
3241 -- Prevent the search from going too far
3243 if Context = Standard_Standard then
3244 return;
3246 -- Objects and states that appear immediately within a subprogram or
3247 -- inside a construct nested within a subprogram do not introduce a
3248 -- hidden state. They behave as local variable declarations.
3250 elsif Is_Subprogram (Context) then
3251 return;
3253 -- When examining a package body, use the entity of the spec as it
3254 -- carries the abstract state declarations.
3256 elsif Ekind (Context) = E_Package_Body then
3257 Context := Spec_Entity (Context);
3258 end if;
3260 -- Stop the traversal when a package subject to a null abstract state
3261 -- has been found.
3263 if Ekind_In (Context, E_Generic_Package, E_Package)
3264 and then Has_Null_Abstract_State (Context)
3265 then
3266 exit;
3267 end if;
3269 Scop := Scope (Scop);
3270 end loop;
3272 -- At this point we know that there is at least one package with a null
3273 -- abstract state in visibility. Emit an error message unconditionally
3274 -- if the entity being processed is a state because the placement of the
3275 -- related package is irrelevant. This is not the case for objects as
3276 -- the intermediate context matters.
3278 if Present (Context)
3279 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3280 then
3281 Error_Msg_N ("cannot introduce hidden state &", Id);
3282 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3283 end if;
3284 end Check_No_Hidden_State;
3286 ----------------------------------------
3287 -- Check_Nonvolatile_Function_Profile --
3288 ----------------------------------------
3290 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3291 Formal : Entity_Id;
3293 begin
3294 -- Inspect all formal parameters
3296 Formal := First_Formal (Func_Id);
3297 while Present (Formal) loop
3298 if Is_Effectively_Volatile (Etype (Formal)) then
3299 Error_Msg_NE
3300 ("nonvolatile function & cannot have a volatile parameter",
3301 Formal, Func_Id);
3302 end if;
3304 Next_Formal (Formal);
3305 end loop;
3307 -- Inspect the return type
3309 if Is_Effectively_Volatile (Etype (Func_Id)) then
3310 Error_Msg_NE
3311 ("nonvolatile function & cannot have a volatile return type",
3312 Result_Definition (Parent (Func_Id)), Func_Id);
3313 end if;
3314 end Check_Nonvolatile_Function_Profile;
3316 -----------------------------
3317 -- Check_Part_Of_Reference --
3318 -----------------------------
3320 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
3321 function Is_Enclosing_Package_Body
3322 (Body_Decl : Node_Id;
3323 Obj_Id : Entity_Id) return Boolean;
3324 pragma Inline (Is_Enclosing_Package_Body);
3325 -- Determine whether package body Body_Decl or its corresponding spec
3326 -- immediately encloses the declaration of object Obj_Id.
3328 function Is_Internal_Declaration_Or_Body
3329 (Decl : Node_Id) return Boolean;
3330 pragma Inline (Is_Internal_Declaration_Or_Body);
3331 -- Determine whether declaration or body denoted by Decl is internal
3333 function Is_Single_Declaration_Or_Body
3334 (Decl : Node_Id;
3335 Conc_Typ : Entity_Id) return Boolean;
3336 pragma Inline (Is_Single_Declaration_Or_Body);
3337 -- Determine whether protected/task declaration or body denoted by Decl
3338 -- belongs to single concurrent type Conc_Typ.
3340 function Is_Single_Task_Pragma
3341 (Prag : Node_Id;
3342 Task_Typ : Entity_Id) return Boolean;
3343 pragma Inline (Is_Single_Task_Pragma);
3344 -- Determine whether pragma Prag belongs to single task type Task_Typ
3346 -------------------------------
3347 -- Is_Enclosing_Package_Body --
3348 -------------------------------
3350 function Is_Enclosing_Package_Body
3351 (Body_Decl : Node_Id;
3352 Obj_Id : Entity_Id) return Boolean
3354 Obj_Context : Node_Id;
3356 begin
3357 -- Find the context of the object declaration
3359 Obj_Context := Parent (Declaration_Node (Obj_Id));
3361 if Nkind (Obj_Context) = N_Package_Specification then
3362 Obj_Context := Parent (Obj_Context);
3363 end if;
3365 -- The object appears immediately within the package body
3367 if Obj_Context = Body_Decl then
3368 return True;
3370 -- The object appears immediately within the corresponding spec
3372 elsif Nkind (Obj_Context) = N_Package_Declaration
3373 and then Unit_Declaration_Node (Corresponding_Spec (Body_Decl)) =
3374 Obj_Context
3375 then
3376 return True;
3377 end if;
3379 return False;
3380 end Is_Enclosing_Package_Body;
3382 -------------------------------------
3383 -- Is_Internal_Declaration_Or_Body --
3384 -------------------------------------
3386 function Is_Internal_Declaration_Or_Body
3387 (Decl : Node_Id) return Boolean
3389 begin
3390 if Comes_From_Source (Decl) then
3391 return False;
3393 -- A body generated for an expression function which has not been
3394 -- inserted into the tree yet (In_Spec_Expression is True) is not
3395 -- considered internal.
3397 elsif Nkind (Decl) = N_Subprogram_Body
3398 and then Was_Expression_Function (Decl)
3399 and then not In_Spec_Expression
3400 then
3401 return False;
3402 end if;
3404 return True;
3405 end Is_Internal_Declaration_Or_Body;
3407 -----------------------------------
3408 -- Is_Single_Declaration_Or_Body --
3409 -----------------------------------
3411 function Is_Single_Declaration_Or_Body
3412 (Decl : Node_Id;
3413 Conc_Typ : Entity_Id) return Boolean
3415 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl);
3417 begin
3418 return
3419 Present (Anonymous_Object (Spec_Id))
3420 and then Anonymous_Object (Spec_Id) = Conc_Typ;
3421 end Is_Single_Declaration_Or_Body;
3423 ---------------------------
3424 -- Is_Single_Task_Pragma --
3425 ---------------------------
3427 function Is_Single_Task_Pragma
3428 (Prag : Node_Id;
3429 Task_Typ : Entity_Id) return Boolean
3431 Decl : constant Node_Id := Find_Related_Declaration_Or_Body (Prag);
3433 begin
3434 -- To qualify, the pragma must be associated with single task type
3435 -- Task_Typ.
3437 return
3438 Is_Single_Task_Object (Task_Typ)
3439 and then Nkind (Decl) = N_Object_Declaration
3440 and then Defining_Entity (Decl) = Task_Typ;
3441 end Is_Single_Task_Pragma;
3443 -- Local variables
3445 Conc_Obj : constant Entity_Id := Encapsulating_State (Var_Id);
3446 Par : Node_Id;
3447 Prag_Nam : Name_Id;
3448 Prev : Node_Id;
3450 -- Start of processing for Check_Part_Of_Reference
3452 begin
3453 -- Nothing to do when the variable was recorded, but did not become a
3454 -- constituent of a single concurrent type.
3456 if No (Conc_Obj) then
3457 return;
3458 end if;
3460 -- Traverse the parent chain looking for a suitable context for the
3461 -- reference to the concurrent constituent.
3463 Prev := Ref;
3464 Par := Parent (Prev);
3465 while Present (Par) loop
3466 if Nkind (Par) = N_Pragma then
3467 Prag_Nam := Pragma_Name (Par);
3469 -- A concurrent constituent is allowed to appear in pragmas
3470 -- Initial_Condition and Initializes as this is part of the
3471 -- elaboration checks for the constituent (SPARK RM 9(3)).
3473 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
3474 return;
3476 -- When the reference appears within pragma Depends or Global,
3477 -- check whether the pragma applies to a single task type. Note
3478 -- that the pragma may not encapsulated by the type definition,
3479 -- but this is still a valid context.
3481 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global)
3482 and then Is_Single_Task_Pragma (Par, Conc_Obj)
3483 then
3484 return;
3485 end if;
3487 -- The reference appears somewhere in the definition of a single
3488 -- concurrent type (SPARK RM 9(3)).
3490 elsif Nkind_In (Par, N_Single_Protected_Declaration,
3491 N_Single_Task_Declaration)
3492 and then Defining_Entity (Par) = Conc_Obj
3493 then
3494 return;
3496 -- The reference appears within the declaration or body of a single
3497 -- concurrent type (SPARK RM 9(3)).
3499 elsif Nkind_In (Par, N_Protected_Body,
3500 N_Protected_Type_Declaration,
3501 N_Task_Body,
3502 N_Task_Type_Declaration)
3503 and then Is_Single_Declaration_Or_Body (Par, Conc_Obj)
3504 then
3505 return;
3507 -- The reference appears within the statement list of the object's
3508 -- immediately enclosing package (SPARK RM 9(3)).
3510 elsif Nkind (Par) = N_Package_Body
3511 and then Nkind (Prev) = N_Handled_Sequence_Of_Statements
3512 and then Is_Enclosing_Package_Body (Par, Var_Id)
3513 then
3514 return;
3516 -- The reference has been relocated within an internally generated
3517 -- package or subprogram. Assume that the reference is legal as the
3518 -- real check was already performed in the original context of the
3519 -- reference.
3521 elsif Nkind_In (Par, N_Package_Body,
3522 N_Package_Declaration,
3523 N_Subprogram_Body,
3524 N_Subprogram_Declaration)
3525 and then Is_Internal_Declaration_Or_Body (Par)
3526 then
3527 return;
3529 -- The reference has been relocated to an inlined body for GNATprove.
3530 -- Assume that the reference is legal as the real check was already
3531 -- performed in the original context of the reference.
3533 elsif GNATprove_Mode
3534 and then Nkind (Par) = N_Subprogram_Body
3535 and then Chars (Defining_Entity (Par)) = Name_uParent
3536 then
3537 return;
3538 end if;
3540 Prev := Par;
3541 Par := Parent (Prev);
3542 end loop;
3544 -- At this point it is known that the reference does not appear within a
3545 -- legal context.
3547 Error_Msg_NE
3548 ("reference to variable & cannot appear in this context", Ref, Var_Id);
3549 Error_Msg_Name_1 := Chars (Var_Id);
3551 if Is_Single_Protected_Object (Conc_Obj) then
3552 Error_Msg_NE
3553 ("\% is constituent of single protected type &", Ref, Conc_Obj);
3555 else
3556 Error_Msg_NE
3557 ("\% is constituent of single task type &", Ref, Conc_Obj);
3558 end if;
3559 end Check_Part_Of_Reference;
3561 ------------------------------------------
3562 -- Check_Potentially_Blocking_Operation --
3563 ------------------------------------------
3565 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3566 S : Entity_Id;
3568 begin
3569 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3570 -- When pragma Detect_Blocking is active, the run time will raise
3571 -- Program_Error. Here we only issue a warning, since we generally
3572 -- support the use of potentially blocking operations in the absence
3573 -- of the pragma.
3575 -- Indirect blocking through a subprogram call cannot be diagnosed
3576 -- statically without interprocedural analysis, so we do not attempt
3577 -- to do it here.
3579 S := Scope (Current_Scope);
3580 while Present (S) and then S /= Standard_Standard loop
3581 if Is_Protected_Type (S) then
3582 Error_Msg_N
3583 ("potentially blocking operation in protected operation??", N);
3584 return;
3585 end if;
3587 S := Scope (S);
3588 end loop;
3589 end Check_Potentially_Blocking_Operation;
3591 ------------------------------------
3592 -- Check_Previous_Null_Procedure --
3593 ------------------------------------
3595 procedure Check_Previous_Null_Procedure
3596 (Decl : Node_Id;
3597 Prev : Entity_Id)
3599 begin
3600 if Ekind (Prev) = E_Procedure
3601 and then Nkind (Parent (Prev)) = N_Procedure_Specification
3602 and then Null_Present (Parent (Prev))
3603 then
3604 Error_Msg_Sloc := Sloc (Prev);
3605 Error_Msg_N
3606 ("declaration cannot complete previous null procedure#", Decl);
3607 end if;
3608 end Check_Previous_Null_Procedure;
3610 ---------------------------------
3611 -- Check_Result_And_Post_State --
3612 ---------------------------------
3614 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3615 procedure Check_Result_And_Post_State_In_Pragma
3616 (Prag : Node_Id;
3617 Result_Seen : in out Boolean);
3618 -- Determine whether pragma Prag mentions attribute 'Result and whether
3619 -- the pragma contains an expression that evaluates differently in pre-
3620 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3621 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3623 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3624 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3625 -- formal parameter.
3627 -------------------------------------------
3628 -- Check_Result_And_Post_State_In_Pragma --
3629 -------------------------------------------
3631 procedure Check_Result_And_Post_State_In_Pragma
3632 (Prag : Node_Id;
3633 Result_Seen : in out Boolean)
3635 procedure Check_Conjunct (Expr : Node_Id);
3636 -- Check an individual conjunct in a conjunction of Boolean
3637 -- expressions, connected by "and" or "and then" operators.
3639 procedure Check_Conjuncts (Expr : Node_Id);
3640 -- Apply the post-state check to every conjunct in an expression, in
3641 -- case this is a conjunction of Boolean expressions. Otherwise apply
3642 -- it to the expression as a whole.
3644 procedure Check_Expression (Expr : Node_Id);
3645 -- Perform the 'Result and post-state checks on a given expression
3647 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3648 -- Attempt to find attribute 'Result in a subtree denoted by N
3650 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3651 -- Determine whether source node N denotes "True" or "False"
3653 function Mentions_Post_State (N : Node_Id) return Boolean;
3654 -- Determine whether a subtree denoted by N mentions any construct
3655 -- that denotes a post-state.
3657 procedure Check_Function_Result is
3658 new Traverse_Proc (Is_Function_Result);
3660 --------------------
3661 -- Check_Conjunct --
3662 --------------------
3664 procedure Check_Conjunct (Expr : Node_Id) is
3665 function Adjust_Message (Msg : String) return String;
3666 -- Prepend a prefix to the input message Msg denoting that the
3667 -- message applies to a conjunct in the expression, when this
3668 -- is the case.
3670 function Applied_On_Conjunct return Boolean;
3671 -- Returns True if the message applies to a conjunct in the
3672 -- expression, instead of the whole expression.
3674 function Has_Global_Output (Subp : Entity_Id) return Boolean;
3675 -- Returns True if Subp has an output in its Global contract
3677 function Has_No_Output (Subp : Entity_Id) return Boolean;
3678 -- Returns True if Subp has no declared output: no function
3679 -- result, no output parameter, and no output in its Global
3680 -- contract.
3682 --------------------
3683 -- Adjust_Message --
3684 --------------------
3686 function Adjust_Message (Msg : String) return String is
3687 begin
3688 if Applied_On_Conjunct then
3689 return "conjunct in " & Msg;
3690 else
3691 return Msg;
3692 end if;
3693 end Adjust_Message;
3695 -------------------------
3696 -- Applied_On_Conjunct --
3697 -------------------------
3699 function Applied_On_Conjunct return Boolean is
3700 begin
3701 -- Expr is the conjunct of an enclosing "and" expression
3703 return Nkind (Parent (Expr)) in N_Subexpr
3705 -- or Expr is a conjunct of an enclosing "and then"
3706 -- expression in a postcondition aspect that was split into
3707 -- multiple pragmas. The first conjunct has the "and then"
3708 -- expression as Original_Node, and other conjuncts have
3709 -- Split_PCC set to True.
3711 or else Nkind (Original_Node (Expr)) = N_And_Then
3712 or else Split_PPC (Prag);
3713 end Applied_On_Conjunct;
3715 -----------------------
3716 -- Has_Global_Output --
3717 -----------------------
3719 function Has_Global_Output (Subp : Entity_Id) return Boolean is
3720 Global : constant Node_Id := Get_Pragma (Subp, Pragma_Global);
3721 List : Node_Id;
3722 Assoc : Node_Id;
3724 begin
3725 if No (Global) then
3726 return False;
3727 end if;
3729 List := Expression (Get_Argument (Global, Subp));
3731 -- Empty list (no global items) or single global item
3732 -- declaration (only input items).
3734 if Nkind_In (List, N_Null,
3735 N_Expanded_Name,
3736 N_Identifier,
3737 N_Selected_Component)
3738 then
3739 return False;
3741 -- Simple global list (only input items) or moded global list
3742 -- declaration.
3744 elsif Nkind (List) = N_Aggregate then
3745 if Present (Expressions (List)) then
3746 return False;
3748 else
3749 Assoc := First (Component_Associations (List));
3750 while Present (Assoc) loop
3751 if Chars (First (Choices (Assoc))) /= Name_Input then
3752 return True;
3753 end if;
3755 Next (Assoc);
3756 end loop;
3758 return False;
3759 end if;
3761 -- To accommodate partial decoration of disabled SPARK
3762 -- features, this routine may be called with illegal input.
3763 -- If this is the case, do not raise Program_Error.
3765 else
3766 return False;
3767 end if;
3768 end Has_Global_Output;
3770 -------------------
3771 -- Has_No_Output --
3772 -------------------
3774 function Has_No_Output (Subp : Entity_Id) return Boolean is
3775 Param : Node_Id;
3777 begin
3778 -- A function has its result as output
3780 if Ekind (Subp) = E_Function then
3781 return False;
3782 end if;
3784 -- An OUT or IN OUT parameter is an output
3786 Param := First_Formal (Subp);
3787 while Present (Param) loop
3788 if Ekind_In (Param, E_Out_Parameter, E_In_Out_Parameter) then
3789 return False;
3790 end if;
3792 Next_Formal (Param);
3793 end loop;
3795 -- An item of mode Output or In_Out in the Global contract is
3796 -- an output.
3798 if Has_Global_Output (Subp) then
3799 return False;
3800 end if;
3802 return True;
3803 end Has_No_Output;
3805 -- Local variables
3807 Err_Node : Node_Id;
3808 -- Error node when reporting a warning on a (refined)
3809 -- postcondition.
3811 -- Start of processing for Check_Conjunct
3813 begin
3814 if Applied_On_Conjunct then
3815 Err_Node := Expr;
3816 else
3817 Err_Node := Prag;
3818 end if;
3820 -- Do not report missing reference to outcome in postcondition if
3821 -- either the postcondition is trivially True or False, or if the
3822 -- subprogram is ghost and has no declared output.
3824 if not Is_Trivial_Boolean (Expr)
3825 and then not Mentions_Post_State (Expr)
3826 and then not (Is_Ghost_Entity (Subp_Id)
3827 and then Has_No_Output (Subp_Id))
3828 then
3829 if Pragma_Name (Prag) = Name_Contract_Cases then
3830 Error_Msg_NE (Adjust_Message
3831 ("contract case does not check the outcome of calling "
3832 & "&?T?"), Expr, Subp_Id);
3834 elsif Pragma_Name (Prag) = Name_Refined_Post then
3835 Error_Msg_NE (Adjust_Message
3836 ("refined postcondition does not check the outcome of "
3837 & "calling &?T?"), Err_Node, Subp_Id);
3839 else
3840 Error_Msg_NE (Adjust_Message
3841 ("postcondition does not check the outcome of calling "
3842 & "&?T?"), Err_Node, Subp_Id);
3843 end if;
3844 end if;
3845 end Check_Conjunct;
3847 ---------------------
3848 -- Check_Conjuncts --
3849 ---------------------
3851 procedure Check_Conjuncts (Expr : Node_Id) is
3852 begin
3853 if Nkind_In (Expr, N_Op_And, N_And_Then) then
3854 Check_Conjuncts (Left_Opnd (Expr));
3855 Check_Conjuncts (Right_Opnd (Expr));
3856 else
3857 Check_Conjunct (Expr);
3858 end if;
3859 end Check_Conjuncts;
3861 ----------------------
3862 -- Check_Expression --
3863 ----------------------
3865 procedure Check_Expression (Expr : Node_Id) is
3866 begin
3867 if not Is_Trivial_Boolean (Expr) then
3868 Check_Function_Result (Expr);
3869 Check_Conjuncts (Expr);
3870 end if;
3871 end Check_Expression;
3873 ------------------------
3874 -- Is_Function_Result --
3875 ------------------------
3877 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3878 begin
3879 if Is_Attribute_Result (N) then
3880 Result_Seen := True;
3881 return Abandon;
3883 -- Continue the traversal
3885 else
3886 return OK;
3887 end if;
3888 end Is_Function_Result;
3890 ------------------------
3891 -- Is_Trivial_Boolean --
3892 ------------------------
3894 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3895 begin
3896 return
3897 Comes_From_Source (N)
3898 and then Is_Entity_Name (N)
3899 and then (Entity (N) = Standard_True
3900 or else
3901 Entity (N) = Standard_False);
3902 end Is_Trivial_Boolean;
3904 -------------------------
3905 -- Mentions_Post_State --
3906 -------------------------
3908 function Mentions_Post_State (N : Node_Id) return Boolean is
3909 Post_State_Seen : Boolean := False;
3911 function Is_Post_State (N : Node_Id) return Traverse_Result;
3912 -- Attempt to find a construct that denotes a post-state. If this
3913 -- is the case, set flag Post_State_Seen.
3915 -------------------
3916 -- Is_Post_State --
3917 -------------------
3919 function Is_Post_State (N : Node_Id) return Traverse_Result is
3920 Ent : Entity_Id;
3922 begin
3923 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3924 Post_State_Seen := True;
3925 return Abandon;
3927 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3928 Ent := Entity (N);
3930 -- Treat an undecorated reference as OK
3932 if No (Ent)
3934 -- A reference to an assignable entity is considered a
3935 -- change in the post-state of a subprogram.
3937 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3938 E_In_Out_Parameter,
3939 E_Out_Parameter,
3940 E_Variable)
3942 -- The reference may be modified through a dereference
3944 or else (Is_Access_Type (Etype (Ent))
3945 and then Nkind (Parent (N)) =
3946 N_Selected_Component)
3947 then
3948 Post_State_Seen := True;
3949 return Abandon;
3950 end if;
3952 elsif Nkind (N) = N_Attribute_Reference then
3953 if Attribute_Name (N) = Name_Old then
3954 return Skip;
3956 elsif Attribute_Name (N) = Name_Result then
3957 Post_State_Seen := True;
3958 return Abandon;
3959 end if;
3960 end if;
3962 return OK;
3963 end Is_Post_State;
3965 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3967 -- Start of processing for Mentions_Post_State
3969 begin
3970 Find_Post_State (N);
3972 return Post_State_Seen;
3973 end Mentions_Post_State;
3975 -- Local variables
3977 Expr : constant Node_Id :=
3978 Get_Pragma_Arg
3979 (First (Pragma_Argument_Associations (Prag)));
3980 Nam : constant Name_Id := Pragma_Name (Prag);
3981 CCase : Node_Id;
3983 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3985 begin
3986 -- Examine all consequences
3988 if Nam = Name_Contract_Cases then
3989 CCase := First (Component_Associations (Expr));
3990 while Present (CCase) loop
3991 Check_Expression (Expression (CCase));
3993 Next (CCase);
3994 end loop;
3996 -- Examine the expression of a postcondition
3998 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3999 Name_Refined_Post));
4000 Check_Expression (Expr);
4001 end if;
4002 end Check_Result_And_Post_State_In_Pragma;
4004 --------------------------
4005 -- Has_In_Out_Parameter --
4006 --------------------------
4008 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
4009 Formal : Entity_Id;
4011 begin
4012 -- Traverse the formals looking for an IN OUT parameter
4014 Formal := First_Formal (Subp_Id);
4015 while Present (Formal) loop
4016 if Ekind (Formal) = E_In_Out_Parameter then
4017 return True;
4018 end if;
4020 Next_Formal (Formal);
4021 end loop;
4023 return False;
4024 end Has_In_Out_Parameter;
4026 -- Local variables
4028 Items : constant Node_Id := Contract (Subp_Id);
4029 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4030 Case_Prag : Node_Id := Empty;
4031 Post_Prag : Node_Id := Empty;
4032 Prag : Node_Id;
4033 Seen_In_Case : Boolean := False;
4034 Seen_In_Post : Boolean := False;
4035 Spec_Id : Entity_Id;
4037 -- Start of processing for Check_Result_And_Post_State
4039 begin
4040 -- The lack of attribute 'Result or a post-state is classified as a
4041 -- suspicious contract. Do not perform the check if the corresponding
4042 -- swich is not set.
4044 if not Warn_On_Suspicious_Contract then
4045 return;
4047 -- Nothing to do if there is no contract
4049 elsif No (Items) then
4050 return;
4051 end if;
4053 -- Retrieve the entity of the subprogram spec (if any)
4055 if Nkind (Subp_Decl) = N_Subprogram_Body
4056 and then Present (Corresponding_Spec (Subp_Decl))
4057 then
4058 Spec_Id := Corresponding_Spec (Subp_Decl);
4060 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4061 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4062 then
4063 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4065 else
4066 Spec_Id := Subp_Id;
4067 end if;
4069 -- Examine all postconditions for attribute 'Result and a post-state
4071 Prag := Pre_Post_Conditions (Items);
4072 while Present (Prag) loop
4073 if Nam_In (Pragma_Name_Unmapped (Prag),
4074 Name_Postcondition, Name_Refined_Post)
4075 and then not Error_Posted (Prag)
4076 then
4077 Post_Prag := Prag;
4078 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4079 end if;
4081 Prag := Next_Pragma (Prag);
4082 end loop;
4084 -- Examine the contract cases of the subprogram for attribute 'Result
4085 -- and a post-state.
4087 Prag := Contract_Test_Cases (Items);
4088 while Present (Prag) loop
4089 if Pragma_Name (Prag) = Name_Contract_Cases
4090 and then not Error_Posted (Prag)
4091 then
4092 Case_Prag := Prag;
4093 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4094 end if;
4096 Prag := Next_Pragma (Prag);
4097 end loop;
4099 -- Do not emit any errors if the subprogram is not a function
4101 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4102 null;
4104 -- Regardless of whether the function has postconditions or contract
4105 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4106 -- parameter is always treated as a result.
4108 elsif Has_In_Out_Parameter (Spec_Id) then
4109 null;
4111 -- The function has both a postcondition and contract cases and they do
4112 -- not mention attribute 'Result.
4114 elsif Present (Case_Prag)
4115 and then not Seen_In_Case
4116 and then Present (Post_Prag)
4117 and then not Seen_In_Post
4118 then
4119 Error_Msg_N
4120 ("neither postcondition nor contract cases mention function "
4121 & "result?T?", Post_Prag);
4123 -- The function has contract cases only and they do not mention
4124 -- attribute 'Result.
4126 elsif Present (Case_Prag) and then not Seen_In_Case then
4127 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4129 -- The function has postconditions only and they do not mention
4130 -- attribute 'Result.
4132 elsif Present (Post_Prag) and then not Seen_In_Post then
4133 Error_Msg_N
4134 ("postcondition does not mention function result?T?", Post_Prag);
4135 end if;
4136 end Check_Result_And_Post_State;
4138 -----------------------------
4139 -- Check_State_Refinements --
4140 -----------------------------
4142 procedure Check_State_Refinements
4143 (Context : Node_Id;
4144 Is_Main_Unit : Boolean := False)
4146 procedure Check_Package (Pack : Node_Id);
4147 -- Verify that all abstract states of a [generic] package denoted by its
4148 -- declarative node Pack have proper refinement. Recursively verify the
4149 -- visible and private declarations of the [generic] package for other
4150 -- nested packages.
4152 procedure Check_Packages_In (Decls : List_Id);
4153 -- Seek out [generic] package declarations within declarative list Decls
4154 -- and verify the status of their abstract state refinement.
4156 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4157 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4159 -------------------
4160 -- Check_Package --
4161 -------------------
4163 procedure Check_Package (Pack : Node_Id) is
4164 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4165 Spec : constant Node_Id := Specification (Pack);
4166 States : constant Elist_Id :=
4167 Abstract_States (Defining_Entity (Pack));
4169 State_Elmt : Elmt_Id;
4170 State_Id : Entity_Id;
4172 begin
4173 -- Do not verify proper state refinement when the package is subject
4174 -- to pragma SPARK_Mode Off because this disables the requirement for
4175 -- state refinement.
4177 if SPARK_Mode_Is_Off (Pack) then
4178 null;
4180 -- State refinement can only occur in a completing package body. Do
4181 -- not verify proper state refinement when the body is subject to
4182 -- pragma SPARK_Mode Off because this disables the requirement for
4183 -- state refinement.
4185 elsif Present (Body_Id)
4186 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4187 then
4188 null;
4190 -- Do not verify proper state refinement when the package is an
4191 -- instance as this check was already performed in the generic.
4193 elsif Present (Generic_Parent (Spec)) then
4194 null;
4196 -- Otherwise examine the contents of the package
4198 else
4199 if Present (States) then
4200 State_Elmt := First_Elmt (States);
4201 while Present (State_Elmt) loop
4202 State_Id := Node (State_Elmt);
4204 -- Emit an error when a non-null state lacks any form of
4205 -- refinement.
4207 if not Is_Null_State (State_Id)
4208 and then not Has_Null_Refinement (State_Id)
4209 and then not Has_Non_Null_Refinement (State_Id)
4210 then
4211 Error_Msg_N ("state & requires refinement", State_Id);
4212 end if;
4214 Next_Elmt (State_Elmt);
4215 end loop;
4216 end if;
4218 Check_Packages_In (Visible_Declarations (Spec));
4219 Check_Packages_In (Private_Declarations (Spec));
4220 end if;
4221 end Check_Package;
4223 -----------------------
4224 -- Check_Packages_In --
4225 -----------------------
4227 procedure Check_Packages_In (Decls : List_Id) is
4228 Decl : Node_Id;
4230 begin
4231 if Present (Decls) then
4232 Decl := First (Decls);
4233 while Present (Decl) loop
4234 if Nkind_In (Decl, N_Generic_Package_Declaration,
4235 N_Package_Declaration)
4236 then
4237 Check_Package (Decl);
4238 end if;
4240 Next (Decl);
4241 end loop;
4242 end if;
4243 end Check_Packages_In;
4245 -----------------------
4246 -- SPARK_Mode_Is_Off --
4247 -----------------------
4249 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4250 Id : constant Entity_Id := Defining_Entity (N);
4251 Prag : constant Node_Id := SPARK_Pragma (Id);
4253 begin
4254 -- Default the mode to "off" when the context is an instance and all
4255 -- SPARK_Mode pragmas found within are to be ignored.
4257 if Ignore_SPARK_Mode_Pragmas (Id) then
4258 return True;
4260 else
4261 return
4262 Present (Prag)
4263 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4264 end if;
4265 end SPARK_Mode_Is_Off;
4267 -- Start of processing for Check_State_Refinements
4269 begin
4270 -- A block may declare a nested package
4272 if Nkind (Context) = N_Block_Statement then
4273 Check_Packages_In (Declarations (Context));
4275 -- An entry, protected, subprogram, or task body may declare a nested
4276 -- package.
4278 elsif Nkind_In (Context, N_Entry_Body,
4279 N_Protected_Body,
4280 N_Subprogram_Body,
4281 N_Task_Body)
4282 then
4283 -- Do not verify proper state refinement when the body is subject to
4284 -- pragma SPARK_Mode Off because this disables the requirement for
4285 -- state refinement.
4287 if not SPARK_Mode_Is_Off (Context) then
4288 Check_Packages_In (Declarations (Context));
4289 end if;
4291 -- A package body may declare a nested package
4293 elsif Nkind (Context) = N_Package_Body then
4294 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4296 -- Do not verify proper state refinement when the body is subject to
4297 -- pragma SPARK_Mode Off because this disables the requirement for
4298 -- state refinement.
4300 if not SPARK_Mode_Is_Off (Context) then
4301 Check_Packages_In (Declarations (Context));
4302 end if;
4304 -- A library level [generic] package may declare a nested package
4306 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4307 N_Package_Declaration)
4308 and then Is_Main_Unit
4309 then
4310 Check_Package (Context);
4311 end if;
4312 end Check_State_Refinements;
4314 ------------------------------
4315 -- Check_Unprotected_Access --
4316 ------------------------------
4318 procedure Check_Unprotected_Access
4319 (Context : Node_Id;
4320 Expr : Node_Id)
4322 Cont_Encl_Typ : Entity_Id;
4323 Pref_Encl_Typ : Entity_Id;
4325 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4326 -- Check whether Obj is a private component of a protected object.
4327 -- Return the protected type where the component resides, Empty
4328 -- otherwise.
4330 function Is_Public_Operation return Boolean;
4331 -- Verify that the enclosing operation is callable from outside the
4332 -- protected object, to minimize false positives.
4334 ------------------------------
4335 -- Enclosing_Protected_Type --
4336 ------------------------------
4338 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4339 begin
4340 if Is_Entity_Name (Obj) then
4341 declare
4342 Ent : Entity_Id := Entity (Obj);
4344 begin
4345 -- The object can be a renaming of a private component, use
4346 -- the original record component.
4348 if Is_Prival (Ent) then
4349 Ent := Prival_Link (Ent);
4350 end if;
4352 if Is_Protected_Type (Scope (Ent)) then
4353 return Scope (Ent);
4354 end if;
4355 end;
4356 end if;
4358 -- For indexed and selected components, recursively check the prefix
4360 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4361 return Enclosing_Protected_Type (Prefix (Obj));
4363 -- The object does not denote a protected component
4365 else
4366 return Empty;
4367 end if;
4368 end Enclosing_Protected_Type;
4370 -------------------------
4371 -- Is_Public_Operation --
4372 -------------------------
4374 function Is_Public_Operation return Boolean is
4375 S : Entity_Id;
4376 E : Entity_Id;
4378 begin
4379 S := Current_Scope;
4380 while Present (S) and then S /= Pref_Encl_Typ loop
4381 if Scope (S) = Pref_Encl_Typ then
4382 E := First_Entity (Pref_Encl_Typ);
4383 while Present (E)
4384 and then E /= First_Private_Entity (Pref_Encl_Typ)
4385 loop
4386 if E = S then
4387 return True;
4388 end if;
4390 Next_Entity (E);
4391 end loop;
4392 end if;
4394 S := Scope (S);
4395 end loop;
4397 return False;
4398 end Is_Public_Operation;
4400 -- Start of processing for Check_Unprotected_Access
4402 begin
4403 if Nkind (Expr) = N_Attribute_Reference
4404 and then Attribute_Name (Expr) = Name_Unchecked_Access
4405 then
4406 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4407 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4409 -- Check whether we are trying to export a protected component to a
4410 -- context with an equal or lower access level.
4412 if Present (Pref_Encl_Typ)
4413 and then No (Cont_Encl_Typ)
4414 and then Is_Public_Operation
4415 and then Scope_Depth (Pref_Encl_Typ) >=
4416 Object_Access_Level (Context)
4417 then
4418 Error_Msg_N
4419 ("??possible unprotected access to protected data", Expr);
4420 end if;
4421 end if;
4422 end Check_Unprotected_Access;
4424 ------------------------------
4425 -- Check_Unused_Body_States --
4426 ------------------------------
4428 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4429 procedure Process_Refinement_Clause
4430 (Clause : Node_Id;
4431 States : Elist_Id);
4432 -- Inspect all constituents of refinement clause Clause and remove any
4433 -- matches from body state list States.
4435 procedure Report_Unused_Body_States (States : Elist_Id);
4436 -- Emit errors for each abstract state or object found in list States
4438 -------------------------------
4439 -- Process_Refinement_Clause --
4440 -------------------------------
4442 procedure Process_Refinement_Clause
4443 (Clause : Node_Id;
4444 States : Elist_Id)
4446 procedure Process_Constituent (Constit : Node_Id);
4447 -- Remove constituent Constit from body state list States
4449 -------------------------
4450 -- Process_Constituent --
4451 -------------------------
4453 procedure Process_Constituent (Constit : Node_Id) is
4454 Constit_Id : Entity_Id;
4456 begin
4457 -- Guard against illegal constituents. Only abstract states and
4458 -- objects can appear on the right hand side of a refinement.
4460 if Is_Entity_Name (Constit) then
4461 Constit_Id := Entity_Of (Constit);
4463 if Present (Constit_Id)
4464 and then Ekind_In (Constit_Id, E_Abstract_State,
4465 E_Constant,
4466 E_Variable)
4467 then
4468 Remove (States, Constit_Id);
4469 end if;
4470 end if;
4471 end Process_Constituent;
4473 -- Local variables
4475 Constit : Node_Id;
4477 -- Start of processing for Process_Refinement_Clause
4479 begin
4480 if Nkind (Clause) = N_Component_Association then
4481 Constit := Expression (Clause);
4483 -- Multiple constituents appear as an aggregate
4485 if Nkind (Constit) = N_Aggregate then
4486 Constit := First (Expressions (Constit));
4487 while Present (Constit) loop
4488 Process_Constituent (Constit);
4489 Next (Constit);
4490 end loop;
4492 -- Various forms of a single constituent
4494 else
4495 Process_Constituent (Constit);
4496 end if;
4497 end if;
4498 end Process_Refinement_Clause;
4500 -------------------------------
4501 -- Report_Unused_Body_States --
4502 -------------------------------
4504 procedure Report_Unused_Body_States (States : Elist_Id) is
4505 Posted : Boolean := False;
4506 State_Elmt : Elmt_Id;
4507 State_Id : Entity_Id;
4509 begin
4510 if Present (States) then
4511 State_Elmt := First_Elmt (States);
4512 while Present (State_Elmt) loop
4513 State_Id := Node (State_Elmt);
4515 -- Constants are part of the hidden state of a package, but the
4516 -- compiler cannot determine whether they have variable input
4517 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4518 -- hidden state. Do not emit an error when a constant does not
4519 -- participate in a state refinement, even though it acts as a
4520 -- hidden state.
4522 if Ekind (State_Id) = E_Constant then
4523 null;
4525 -- Generate an error message of the form:
4527 -- body of package ... has unused hidden states
4528 -- abstract state ... defined at ...
4529 -- variable ... defined at ...
4531 else
4532 if not Posted then
4533 Posted := True;
4534 SPARK_Msg_N
4535 ("body of package & has unused hidden states", Body_Id);
4536 end if;
4538 Error_Msg_Sloc := Sloc (State_Id);
4540 if Ekind (State_Id) = E_Abstract_State then
4541 SPARK_Msg_NE
4542 ("\abstract state & defined #", Body_Id, State_Id);
4544 else
4545 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4546 end if;
4547 end if;
4549 Next_Elmt (State_Elmt);
4550 end loop;
4551 end if;
4552 end Report_Unused_Body_States;
4554 -- Local variables
4556 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4557 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4558 Clause : Node_Id;
4559 States : Elist_Id;
4561 -- Start of processing for Check_Unused_Body_States
4563 begin
4564 -- Inspect the clauses of pragma Refined_State and determine whether all
4565 -- visible states declared within the package body participate in the
4566 -- refinement.
4568 if Present (Prag) then
4569 Clause := Expression (Get_Argument (Prag, Spec_Id));
4570 States := Collect_Body_States (Body_Id);
4572 -- Multiple non-null state refinements appear as an aggregate
4574 if Nkind (Clause) = N_Aggregate then
4575 Clause := First (Component_Associations (Clause));
4576 while Present (Clause) loop
4577 Process_Refinement_Clause (Clause, States);
4578 Next (Clause);
4579 end loop;
4581 -- Various forms of a single state refinement
4583 else
4584 Process_Refinement_Clause (Clause, States);
4585 end if;
4587 -- Ensure that all abstract states and objects declared in the
4588 -- package body state space are utilized as constituents.
4590 Report_Unused_Body_States (States);
4591 end if;
4592 end Check_Unused_Body_States;
4594 -----------------
4595 -- Choice_List --
4596 -----------------
4598 function Choice_List (N : Node_Id) return List_Id is
4599 begin
4600 if Nkind (N) = N_Iterated_Component_Association then
4601 return Discrete_Choices (N);
4602 else
4603 return Choices (N);
4604 end if;
4605 end Choice_List;
4607 -------------------------
4608 -- Collect_Body_States --
4609 -------------------------
4611 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4612 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4613 -- Determine whether object Obj_Id is a suitable visible state of a
4614 -- package body.
4616 procedure Collect_Visible_States
4617 (Pack_Id : Entity_Id;
4618 States : in out Elist_Id);
4619 -- Gather the entities of all abstract states and objects declared in
4620 -- the visible state space of package Pack_Id.
4622 ----------------------------
4623 -- Collect_Visible_States --
4624 ----------------------------
4626 procedure Collect_Visible_States
4627 (Pack_Id : Entity_Id;
4628 States : in out Elist_Id)
4630 Item_Id : Entity_Id;
4632 begin
4633 -- Traverse the entity chain of the package and inspect all visible
4634 -- items.
4636 Item_Id := First_Entity (Pack_Id);
4637 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4639 -- Do not consider internally generated items as those cannot be
4640 -- named and participate in refinement.
4642 if not Comes_From_Source (Item_Id) then
4643 null;
4645 elsif Ekind (Item_Id) = E_Abstract_State then
4646 Append_New_Elmt (Item_Id, States);
4648 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4649 and then Is_Visible_Object (Item_Id)
4650 then
4651 Append_New_Elmt (Item_Id, States);
4653 -- Recursively gather the visible states of a nested package
4655 elsif Ekind (Item_Id) = E_Package then
4656 Collect_Visible_States (Item_Id, States);
4657 end if;
4659 Next_Entity (Item_Id);
4660 end loop;
4661 end Collect_Visible_States;
4663 -----------------------
4664 -- Is_Visible_Object --
4665 -----------------------
4667 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4668 begin
4669 -- Objects that map generic formals to their actuals are not visible
4670 -- from outside the generic instantiation.
4672 if Present (Corresponding_Generic_Association
4673 (Declaration_Node (Obj_Id)))
4674 then
4675 return False;
4677 -- Constituents of a single protected/task type act as components of
4678 -- the type and are not visible from outside the type.
4680 elsif Ekind (Obj_Id) = E_Variable
4681 and then Present (Encapsulating_State (Obj_Id))
4682 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4683 then
4684 return False;
4686 else
4687 return True;
4688 end if;
4689 end Is_Visible_Object;
4691 -- Local variables
4693 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4694 Decl : Node_Id;
4695 Item_Id : Entity_Id;
4696 States : Elist_Id := No_Elist;
4698 -- Start of processing for Collect_Body_States
4700 begin
4701 -- Inspect the declarations of the body looking for source objects,
4702 -- packages and package instantiations. Note that even though this
4703 -- processing is very similar to Collect_Visible_States, a package
4704 -- body does not have a First/Next_Entity list.
4706 Decl := First (Declarations (Body_Decl));
4707 while Present (Decl) loop
4709 -- Capture source objects as internally generated temporaries cannot
4710 -- be named and participate in refinement.
4712 if Nkind (Decl) = N_Object_Declaration then
4713 Item_Id := Defining_Entity (Decl);
4715 if Comes_From_Source (Item_Id)
4716 and then Is_Visible_Object (Item_Id)
4717 then
4718 Append_New_Elmt (Item_Id, States);
4719 end if;
4721 -- Capture the visible abstract states and objects of a source
4722 -- package [instantiation].
4724 elsif Nkind (Decl) = N_Package_Declaration then
4725 Item_Id := Defining_Entity (Decl);
4727 if Comes_From_Source (Item_Id) then
4728 Collect_Visible_States (Item_Id, States);
4729 end if;
4730 end if;
4732 Next (Decl);
4733 end loop;
4735 return States;
4736 end Collect_Body_States;
4738 ------------------------
4739 -- Collect_Interfaces --
4740 ------------------------
4742 procedure Collect_Interfaces
4743 (T : Entity_Id;
4744 Ifaces_List : out Elist_Id;
4745 Exclude_Parents : Boolean := False;
4746 Use_Full_View : Boolean := True)
4748 procedure Collect (Typ : Entity_Id);
4749 -- Subsidiary subprogram used to traverse the whole list
4750 -- of directly and indirectly implemented interfaces
4752 -------------
4753 -- Collect --
4754 -------------
4756 procedure Collect (Typ : Entity_Id) is
4757 Ancestor : Entity_Id;
4758 Full_T : Entity_Id;
4759 Id : Node_Id;
4760 Iface : Entity_Id;
4762 begin
4763 Full_T := Typ;
4765 -- Handle private types and subtypes
4767 if Use_Full_View
4768 and then Is_Private_Type (Typ)
4769 and then Present (Full_View (Typ))
4770 then
4771 Full_T := Full_View (Typ);
4773 if Ekind (Full_T) = E_Record_Subtype then
4774 Full_T := Etype (Typ);
4776 if Present (Full_View (Full_T)) then
4777 Full_T := Full_View (Full_T);
4778 end if;
4779 end if;
4780 end if;
4782 -- Include the ancestor if we are generating the whole list of
4783 -- abstract interfaces.
4785 if Etype (Full_T) /= Typ
4787 -- Protect the frontend against wrong sources. For example:
4789 -- package P is
4790 -- type A is tagged null record;
4791 -- type B is new A with private;
4792 -- type C is new A with private;
4793 -- private
4794 -- type B is new C with null record;
4795 -- type C is new B with null record;
4796 -- end P;
4798 and then Etype (Full_T) /= T
4799 then
4800 Ancestor := Etype (Full_T);
4801 Collect (Ancestor);
4803 if Is_Interface (Ancestor) and then not Exclude_Parents then
4804 Append_Unique_Elmt (Ancestor, Ifaces_List);
4805 end if;
4806 end if;
4808 -- Traverse the graph of ancestor interfaces
4810 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4811 Id := First (Abstract_Interface_List (Full_T));
4812 while Present (Id) loop
4813 Iface := Etype (Id);
4815 -- Protect against wrong uses. For example:
4816 -- type I is interface;
4817 -- type O is tagged null record;
4818 -- type Wrong is new I and O with null record; -- ERROR
4820 if Is_Interface (Iface) then
4821 if Exclude_Parents
4822 and then Etype (T) /= T
4823 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4824 then
4825 null;
4826 else
4827 Collect (Iface);
4828 Append_Unique_Elmt (Iface, Ifaces_List);
4829 end if;
4830 end if;
4832 Next (Id);
4833 end loop;
4834 end if;
4835 end Collect;
4837 -- Start of processing for Collect_Interfaces
4839 begin
4840 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4841 Ifaces_List := New_Elmt_List;
4842 Collect (T);
4843 end Collect_Interfaces;
4845 ----------------------------------
4846 -- Collect_Interface_Components --
4847 ----------------------------------
4849 procedure Collect_Interface_Components
4850 (Tagged_Type : Entity_Id;
4851 Components_List : out Elist_Id)
4853 procedure Collect (Typ : Entity_Id);
4854 -- Subsidiary subprogram used to climb to the parents
4856 -------------
4857 -- Collect --
4858 -------------
4860 procedure Collect (Typ : Entity_Id) is
4861 Tag_Comp : Entity_Id;
4862 Parent_Typ : Entity_Id;
4864 begin
4865 -- Handle private types
4867 if Present (Full_View (Etype (Typ))) then
4868 Parent_Typ := Full_View (Etype (Typ));
4869 else
4870 Parent_Typ := Etype (Typ);
4871 end if;
4873 if Parent_Typ /= Typ
4875 -- Protect the frontend against wrong sources. For example:
4877 -- package P is
4878 -- type A is tagged null record;
4879 -- type B is new A with private;
4880 -- type C is new A with private;
4881 -- private
4882 -- type B is new C with null record;
4883 -- type C is new B with null record;
4884 -- end P;
4886 and then Parent_Typ /= Tagged_Type
4887 then
4888 Collect (Parent_Typ);
4889 end if;
4891 -- Collect the components containing tags of secondary dispatch
4892 -- tables.
4894 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4895 while Present (Tag_Comp) loop
4896 pragma Assert (Present (Related_Type (Tag_Comp)));
4897 Append_Elmt (Tag_Comp, Components_List);
4899 Tag_Comp := Next_Tag_Component (Tag_Comp);
4900 end loop;
4901 end Collect;
4903 -- Start of processing for Collect_Interface_Components
4905 begin
4906 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4907 and then Is_Tagged_Type (Tagged_Type));
4909 Components_List := New_Elmt_List;
4910 Collect (Tagged_Type);
4911 end Collect_Interface_Components;
4913 -----------------------------
4914 -- Collect_Interfaces_Info --
4915 -----------------------------
4917 procedure Collect_Interfaces_Info
4918 (T : Entity_Id;
4919 Ifaces_List : out Elist_Id;
4920 Components_List : out Elist_Id;
4921 Tags_List : out Elist_Id)
4923 Comps_List : Elist_Id;
4924 Comp_Elmt : Elmt_Id;
4925 Comp_Iface : Entity_Id;
4926 Iface_Elmt : Elmt_Id;
4927 Iface : Entity_Id;
4929 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4930 -- Search for the secondary tag associated with the interface type
4931 -- Iface that is implemented by T.
4933 ----------------
4934 -- Search_Tag --
4935 ----------------
4937 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4938 ADT : Elmt_Id;
4939 begin
4940 if not Is_CPP_Class (T) then
4941 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4942 else
4943 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4944 end if;
4946 while Present (ADT)
4947 and then Is_Tag (Node (ADT))
4948 and then Related_Type (Node (ADT)) /= Iface
4949 loop
4950 -- Skip secondary dispatch table referencing thunks to user
4951 -- defined primitives covered by this interface.
4953 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4954 Next_Elmt (ADT);
4956 -- Skip secondary dispatch tables of Ada types
4958 if not Is_CPP_Class (T) then
4960 -- Skip secondary dispatch table referencing thunks to
4961 -- predefined primitives.
4963 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4964 Next_Elmt (ADT);
4966 -- Skip secondary dispatch table referencing user-defined
4967 -- primitives covered by this interface.
4969 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4970 Next_Elmt (ADT);
4972 -- Skip secondary dispatch table referencing predefined
4973 -- primitives.
4975 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4976 Next_Elmt (ADT);
4977 end if;
4978 end loop;
4980 pragma Assert (Is_Tag (Node (ADT)));
4981 return Node (ADT);
4982 end Search_Tag;
4984 -- Start of processing for Collect_Interfaces_Info
4986 begin
4987 Collect_Interfaces (T, Ifaces_List);
4988 Collect_Interface_Components (T, Comps_List);
4990 -- Search for the record component and tag associated with each
4991 -- interface type of T.
4993 Components_List := New_Elmt_List;
4994 Tags_List := New_Elmt_List;
4996 Iface_Elmt := First_Elmt (Ifaces_List);
4997 while Present (Iface_Elmt) loop
4998 Iface := Node (Iface_Elmt);
5000 -- Associate the primary tag component and the primary dispatch table
5001 -- with all the interfaces that are parents of T
5003 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5004 Append_Elmt (First_Tag_Component (T), Components_List);
5005 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5007 -- Otherwise search for the tag component and secondary dispatch
5008 -- table of Iface
5010 else
5011 Comp_Elmt := First_Elmt (Comps_List);
5012 while Present (Comp_Elmt) loop
5013 Comp_Iface := Related_Type (Node (Comp_Elmt));
5015 if Comp_Iface = Iface
5016 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5017 then
5018 Append_Elmt (Node (Comp_Elmt), Components_List);
5019 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5020 exit;
5021 end if;
5023 Next_Elmt (Comp_Elmt);
5024 end loop;
5025 pragma Assert (Present (Comp_Elmt));
5026 end if;
5028 Next_Elmt (Iface_Elmt);
5029 end loop;
5030 end Collect_Interfaces_Info;
5032 ---------------------
5033 -- Collect_Parents --
5034 ---------------------
5036 procedure Collect_Parents
5037 (T : Entity_Id;
5038 List : out Elist_Id;
5039 Use_Full_View : Boolean := True)
5041 Current_Typ : Entity_Id := T;
5042 Parent_Typ : Entity_Id;
5044 begin
5045 List := New_Elmt_List;
5047 -- No action if the if the type has no parents
5049 if T = Etype (T) then
5050 return;
5051 end if;
5053 loop
5054 Parent_Typ := Etype (Current_Typ);
5056 if Is_Private_Type (Parent_Typ)
5057 and then Present (Full_View (Parent_Typ))
5058 and then Use_Full_View
5059 then
5060 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5061 end if;
5063 Append_Elmt (Parent_Typ, List);
5065 exit when Parent_Typ = Current_Typ;
5066 Current_Typ := Parent_Typ;
5067 end loop;
5068 end Collect_Parents;
5070 ----------------------------------
5071 -- Collect_Primitive_Operations --
5072 ----------------------------------
5074 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5075 B_Type : constant Entity_Id := Base_Type (T);
5076 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5077 B_Scope : Entity_Id := Scope (B_Type);
5078 Op_List : Elist_Id;
5079 Formal : Entity_Id;
5080 Is_Prim : Boolean;
5081 Is_Type_In_Pkg : Boolean;
5082 Formal_Derived : Boolean := False;
5083 Id : Entity_Id;
5085 function Match (E : Entity_Id) return Boolean;
5086 -- True if E's base type is B_Type, or E is of an anonymous access type
5087 -- and the base type of its designated type is B_Type.
5089 -----------
5090 -- Match --
5091 -----------
5093 function Match (E : Entity_Id) return Boolean is
5094 Etyp : Entity_Id := Etype (E);
5096 begin
5097 if Ekind (Etyp) = E_Anonymous_Access_Type then
5098 Etyp := Designated_Type (Etyp);
5099 end if;
5101 -- In Ada 2012 a primitive operation may have a formal of an
5102 -- incomplete view of the parent type.
5104 return Base_Type (Etyp) = B_Type
5105 or else
5106 (Ada_Version >= Ada_2012
5107 and then Ekind (Etyp) = E_Incomplete_Type
5108 and then Full_View (Etyp) = B_Type);
5109 end Match;
5111 -- Start of processing for Collect_Primitive_Operations
5113 begin
5114 -- For tagged types, the primitive operations are collected as they
5115 -- are declared, and held in an explicit list which is simply returned.
5117 if Is_Tagged_Type (B_Type) then
5118 return Primitive_Operations (B_Type);
5120 -- An untagged generic type that is a derived type inherits the
5121 -- primitive operations of its parent type. Other formal types only
5122 -- have predefined operators, which are not explicitly represented.
5124 elsif Is_Generic_Type (B_Type) then
5125 if Nkind (B_Decl) = N_Formal_Type_Declaration
5126 and then Nkind (Formal_Type_Definition (B_Decl)) =
5127 N_Formal_Derived_Type_Definition
5128 then
5129 Formal_Derived := True;
5130 else
5131 return New_Elmt_List;
5132 end if;
5133 end if;
5135 Op_List := New_Elmt_List;
5137 if B_Scope = Standard_Standard then
5138 if B_Type = Standard_String then
5139 Append_Elmt (Standard_Op_Concat, Op_List);
5141 elsif B_Type = Standard_Wide_String then
5142 Append_Elmt (Standard_Op_Concatw, Op_List);
5144 else
5145 null;
5146 end if;
5148 -- Locate the primitive subprograms of the type
5150 else
5151 -- The primitive operations appear after the base type, except
5152 -- if the derivation happens within the private part of B_Scope
5153 -- and the type is a private type, in which case both the type
5154 -- and some primitive operations may appear before the base
5155 -- type, and the list of candidates starts after the type.
5157 if In_Open_Scopes (B_Scope)
5158 and then Scope (T) = B_Scope
5159 and then In_Private_Part (B_Scope)
5160 then
5161 Id := Next_Entity (T);
5163 -- In Ada 2012, If the type has an incomplete partial view, there
5164 -- may be primitive operations declared before the full view, so
5165 -- we need to start scanning from the incomplete view, which is
5166 -- earlier on the entity chain.
5168 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5169 and then Present (Incomplete_View (Parent (B_Type)))
5170 then
5171 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5173 -- If T is a derived from a type with an incomplete view declared
5174 -- elsewhere, that incomplete view is irrelevant, we want the
5175 -- operations in the scope of T.
5177 if Scope (Id) /= Scope (B_Type) then
5178 Id := Next_Entity (B_Type);
5179 end if;
5181 else
5182 Id := Next_Entity (B_Type);
5183 end if;
5185 -- Set flag if this is a type in a package spec
5187 Is_Type_In_Pkg :=
5188 Is_Package_Or_Generic_Package (B_Scope)
5189 and then
5190 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5191 N_Package_Body;
5193 while Present (Id) loop
5195 -- Test whether the result type or any of the parameter types of
5196 -- each subprogram following the type match that type when the
5197 -- type is declared in a package spec, is a derived type, or the
5198 -- subprogram is marked as primitive. (The Is_Primitive test is
5199 -- needed to find primitives of nonderived types in declarative
5200 -- parts that happen to override the predefined "=" operator.)
5202 -- Note that generic formal subprograms are not considered to be
5203 -- primitive operations and thus are never inherited.
5205 if Is_Overloadable (Id)
5206 and then (Is_Type_In_Pkg
5207 or else Is_Derived_Type (B_Type)
5208 or else Is_Primitive (Id))
5209 and then Nkind (Parent (Parent (Id)))
5210 not in N_Formal_Subprogram_Declaration
5211 then
5212 Is_Prim := False;
5214 if Match (Id) then
5215 Is_Prim := True;
5217 else
5218 Formal := First_Formal (Id);
5219 while Present (Formal) loop
5220 if Match (Formal) then
5221 Is_Prim := True;
5222 exit;
5223 end if;
5225 Next_Formal (Formal);
5226 end loop;
5227 end if;
5229 -- For a formal derived type, the only primitives are the ones
5230 -- inherited from the parent type. Operations appearing in the
5231 -- package declaration are not primitive for it.
5233 if Is_Prim
5234 and then (not Formal_Derived or else Present (Alias (Id)))
5235 then
5236 -- In the special case of an equality operator aliased to
5237 -- an overriding dispatching equality belonging to the same
5238 -- type, we don't include it in the list of primitives.
5239 -- This avoids inheriting multiple equality operators when
5240 -- deriving from untagged private types whose full type is
5241 -- tagged, which can otherwise cause ambiguities. Note that
5242 -- this should only happen for this kind of untagged parent
5243 -- type, since normally dispatching operations are inherited
5244 -- using the type's Primitive_Operations list.
5246 if Chars (Id) = Name_Op_Eq
5247 and then Is_Dispatching_Operation (Id)
5248 and then Present (Alias (Id))
5249 and then Present (Overridden_Operation (Alias (Id)))
5250 and then Base_Type (Etype (First_Entity (Id))) =
5251 Base_Type (Etype (First_Entity (Alias (Id))))
5252 then
5253 null;
5255 -- Include the subprogram in the list of primitives
5257 else
5258 Append_Elmt (Id, Op_List);
5259 end if;
5260 end if;
5261 end if;
5263 Next_Entity (Id);
5265 -- For a type declared in System, some of its operations may
5266 -- appear in the target-specific extension to System.
5268 if No (Id)
5269 and then B_Scope = RTU_Entity (System)
5270 and then Present_System_Aux
5271 then
5272 B_Scope := System_Aux_Id;
5273 Id := First_Entity (System_Aux_Id);
5274 end if;
5275 end loop;
5276 end if;
5278 return Op_List;
5279 end Collect_Primitive_Operations;
5281 -----------------------------------
5282 -- Compile_Time_Constraint_Error --
5283 -----------------------------------
5285 function Compile_Time_Constraint_Error
5286 (N : Node_Id;
5287 Msg : String;
5288 Ent : Entity_Id := Empty;
5289 Loc : Source_Ptr := No_Location;
5290 Warn : Boolean := False) return Node_Id
5292 Msgc : String (1 .. Msg'Length + 3);
5293 -- Copy of message, with room for possible ?? or << and ! at end
5295 Msgl : Natural;
5296 Wmsg : Boolean;
5297 Eloc : Source_Ptr;
5299 -- Start of processing for Compile_Time_Constraint_Error
5301 begin
5302 -- If this is a warning, convert it into an error if we are in code
5303 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5304 -- warning. The rationale is that a compile-time constraint error should
5305 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5306 -- a few cases we prefer to issue a warning and generate both a suitable
5307 -- run-time error in GNAT and a suitable check message in GNATprove.
5308 -- Those cases are those that likely correspond to deactivated SPARK
5309 -- code, so that this kind of code can be compiled and analyzed instead
5310 -- of being rejected.
5312 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5314 -- A static constraint error in an instance body is not a fatal error.
5315 -- we choose to inhibit the message altogether, because there is no
5316 -- obvious node (for now) on which to post it. On the other hand the
5317 -- offending node must be replaced with a constraint_error in any case.
5319 -- No messages are generated if we already posted an error on this node
5321 if not Error_Posted (N) then
5322 if Loc /= No_Location then
5323 Eloc := Loc;
5324 else
5325 Eloc := Sloc (N);
5326 end if;
5328 -- Copy message to Msgc, converting any ? in the message into <
5329 -- instead, so that we have an error in GNATprove mode.
5331 Msgl := Msg'Length;
5333 for J in 1 .. Msgl loop
5334 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5335 Msgc (J) := '<';
5336 else
5337 Msgc (J) := Msg (J);
5338 end if;
5339 end loop;
5341 -- Message is a warning, even in Ada 95 case
5343 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5344 Wmsg := True;
5346 -- In Ada 83, all messages are warnings. In the private part and the
5347 -- body of an instance, constraint_checks are only warnings. We also
5348 -- make this a warning if the Warn parameter is set.
5350 elsif Warn
5351 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5352 or else In_Instance_Not_Visible
5353 then
5354 Msgl := Msgl + 1;
5355 Msgc (Msgl) := '<';
5356 Msgl := Msgl + 1;
5357 Msgc (Msgl) := '<';
5358 Wmsg := True;
5360 -- Otherwise we have a real error message (Ada 95 static case) and we
5361 -- make this an unconditional message. Note that in the warning case
5362 -- we do not make the message unconditional, it seems reasonable to
5363 -- delete messages like this (about exceptions that will be raised)
5364 -- in dead code.
5366 else
5367 Wmsg := False;
5368 Msgl := Msgl + 1;
5369 Msgc (Msgl) := '!';
5370 end if;
5372 -- One more test, skip the warning if the related expression is
5373 -- statically unevaluated, since we don't want to warn about what
5374 -- will happen when something is evaluated if it never will be
5375 -- evaluated.
5377 if not Is_Statically_Unevaluated (N) then
5378 if Present (Ent) then
5379 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5380 else
5381 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5382 end if;
5384 if Wmsg then
5386 -- Check whether the context is an Init_Proc
5388 if Inside_Init_Proc then
5389 declare
5390 Conc_Typ : constant Entity_Id :=
5391 Corresponding_Concurrent_Type
5392 (Entity (Parameter_Type (First
5393 (Parameter_Specifications
5394 (Parent (Current_Scope))))));
5396 begin
5397 -- Don't complain if the corresponding concurrent type
5398 -- doesn't come from source (i.e. a single task/protected
5399 -- object).
5401 if Present (Conc_Typ)
5402 and then not Comes_From_Source (Conc_Typ)
5403 then
5404 Error_Msg_NEL
5405 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5407 else
5408 if GNATprove_Mode then
5409 Error_Msg_NEL
5410 ("\& would have been raised for objects of this "
5411 & "type", N, Standard_Constraint_Error, Eloc);
5412 else
5413 Error_Msg_NEL
5414 ("\& will be raised for objects of this type??",
5415 N, Standard_Constraint_Error, Eloc);
5416 end if;
5417 end if;
5418 end;
5420 else
5421 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5422 end if;
5424 else
5425 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5426 Set_Error_Posted (N);
5427 end if;
5428 end if;
5429 end if;
5431 return N;
5432 end Compile_Time_Constraint_Error;
5434 -----------------------
5435 -- Conditional_Delay --
5436 -----------------------
5438 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5439 begin
5440 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5441 Set_Has_Delayed_Freeze (New_Ent);
5442 end if;
5443 end Conditional_Delay;
5445 -------------------------
5446 -- Copy_Component_List --
5447 -------------------------
5449 function Copy_Component_List
5450 (R_Typ : Entity_Id;
5451 Loc : Source_Ptr) return List_Id
5453 Comp : Node_Id;
5454 Comps : constant List_Id := New_List;
5456 begin
5457 Comp := First_Component (Underlying_Type (R_Typ));
5458 while Present (Comp) loop
5459 if Comes_From_Source (Comp) then
5460 declare
5461 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5462 begin
5463 Append_To (Comps,
5464 Make_Component_Declaration (Loc,
5465 Defining_Identifier =>
5466 Make_Defining_Identifier (Loc, Chars (Comp)),
5467 Component_Definition =>
5468 New_Copy_Tree
5469 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5470 end;
5471 end if;
5473 Next_Component (Comp);
5474 end loop;
5476 return Comps;
5477 end Copy_Component_List;
5479 -------------------------
5480 -- Copy_Parameter_List --
5481 -------------------------
5483 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5484 Loc : constant Source_Ptr := Sloc (Subp_Id);
5485 Plist : List_Id;
5486 Formal : Entity_Id;
5488 begin
5489 if No (First_Formal (Subp_Id)) then
5490 return No_List;
5491 else
5492 Plist := New_List;
5493 Formal := First_Formal (Subp_Id);
5494 while Present (Formal) loop
5495 Append_To (Plist,
5496 Make_Parameter_Specification (Loc,
5497 Defining_Identifier =>
5498 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5499 In_Present => In_Present (Parent (Formal)),
5500 Out_Present => Out_Present (Parent (Formal)),
5501 Parameter_Type =>
5502 New_Occurrence_Of (Etype (Formal), Loc),
5503 Expression =>
5504 New_Copy_Tree (Expression (Parent (Formal)))));
5506 Next_Formal (Formal);
5507 end loop;
5508 end if;
5510 return Plist;
5511 end Copy_Parameter_List;
5513 ----------------------------
5514 -- Copy_SPARK_Mode_Aspect --
5515 ----------------------------
5517 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5518 pragma Assert (not Has_Aspects (To));
5519 Asp : Node_Id;
5521 begin
5522 if Has_Aspects (From) then
5523 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5525 if Present (Asp) then
5526 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5527 Set_Has_Aspects (To, True);
5528 end if;
5529 end if;
5530 end Copy_SPARK_Mode_Aspect;
5532 --------------------------
5533 -- Copy_Subprogram_Spec --
5534 --------------------------
5536 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5537 Def_Id : Node_Id;
5538 Formal_Spec : Node_Id;
5539 Result : Node_Id;
5541 begin
5542 -- The structure of the original tree must be replicated without any
5543 -- alterations. Use New_Copy_Tree for this purpose.
5545 Result := New_Copy_Tree (Spec);
5547 -- However, the spec of a null procedure carries the corresponding null
5548 -- statement of the body (created by the parser), and this cannot be
5549 -- shared with the new subprogram spec.
5551 if Nkind (Result) = N_Procedure_Specification then
5552 Set_Null_Statement (Result, Empty);
5553 end if;
5555 -- Create a new entity for the defining unit name
5557 Def_Id := Defining_Unit_Name (Result);
5558 Set_Defining_Unit_Name (Result,
5559 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5561 -- Create new entities for the formal parameters
5563 if Present (Parameter_Specifications (Result)) then
5564 Formal_Spec := First (Parameter_Specifications (Result));
5565 while Present (Formal_Spec) loop
5566 Def_Id := Defining_Identifier (Formal_Spec);
5567 Set_Defining_Identifier (Formal_Spec,
5568 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5570 Next (Formal_Spec);
5571 end loop;
5572 end if;
5574 return Result;
5575 end Copy_Subprogram_Spec;
5577 --------------------------------
5578 -- Corresponding_Generic_Type --
5579 --------------------------------
5581 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5582 Inst : Entity_Id;
5583 Gen : Entity_Id;
5584 Typ : Entity_Id;
5586 begin
5587 if not Is_Generic_Actual_Type (T) then
5588 return Any_Type;
5590 -- If the actual is the actual of an enclosing instance, resolution
5591 -- was correct in the generic.
5593 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5594 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5595 and then
5596 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5597 then
5598 return Any_Type;
5600 else
5601 Inst := Scope (T);
5603 if Is_Wrapper_Package (Inst) then
5604 Inst := Related_Instance (Inst);
5605 end if;
5607 Gen :=
5608 Generic_Parent
5609 (Specification (Unit_Declaration_Node (Inst)));
5611 -- Generic actual has the same name as the corresponding formal
5613 Typ := First_Entity (Gen);
5614 while Present (Typ) loop
5615 if Chars (Typ) = Chars (T) then
5616 return Typ;
5617 end if;
5619 Next_Entity (Typ);
5620 end loop;
5622 return Any_Type;
5623 end if;
5624 end Corresponding_Generic_Type;
5626 --------------------
5627 -- Current_Entity --
5628 --------------------
5630 -- The currently visible definition for a given identifier is the
5631 -- one most chained at the start of the visibility chain, i.e. the
5632 -- one that is referenced by the Node_Id value of the name of the
5633 -- given identifier.
5635 function Current_Entity (N : Node_Id) return Entity_Id is
5636 begin
5637 return Get_Name_Entity_Id (Chars (N));
5638 end Current_Entity;
5640 -----------------------------
5641 -- Current_Entity_In_Scope --
5642 -----------------------------
5644 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5645 E : Entity_Id;
5646 CS : constant Entity_Id := Current_Scope;
5648 Transient_Case : constant Boolean := Scope_Is_Transient;
5650 begin
5651 E := Get_Name_Entity_Id (Chars (N));
5652 while Present (E)
5653 and then Scope (E) /= CS
5654 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5655 loop
5656 E := Homonym (E);
5657 end loop;
5659 return E;
5660 end Current_Entity_In_Scope;
5662 -------------------
5663 -- Current_Scope --
5664 -------------------
5666 function Current_Scope return Entity_Id is
5667 begin
5668 if Scope_Stack.Last = -1 then
5669 return Standard_Standard;
5670 else
5671 declare
5672 C : constant Entity_Id :=
5673 Scope_Stack.Table (Scope_Stack.Last).Entity;
5674 begin
5675 if Present (C) then
5676 return C;
5677 else
5678 return Standard_Standard;
5679 end if;
5680 end;
5681 end if;
5682 end Current_Scope;
5684 ----------------------------
5685 -- Current_Scope_No_Loops --
5686 ----------------------------
5688 function Current_Scope_No_Loops return Entity_Id is
5689 S : Entity_Id;
5691 begin
5692 -- Examine the scope stack starting from the current scope and skip any
5693 -- internally generated loops.
5695 S := Current_Scope;
5696 while Present (S) and then S /= Standard_Standard loop
5697 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5698 S := Scope (S);
5699 else
5700 exit;
5701 end if;
5702 end loop;
5704 return S;
5705 end Current_Scope_No_Loops;
5707 ------------------------
5708 -- Current_Subprogram --
5709 ------------------------
5711 function Current_Subprogram return Entity_Id is
5712 Scop : constant Entity_Id := Current_Scope;
5713 begin
5714 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5715 return Scop;
5716 else
5717 return Enclosing_Subprogram (Scop);
5718 end if;
5719 end Current_Subprogram;
5721 ----------------------------------
5722 -- Deepest_Type_Access_Level --
5723 ----------------------------------
5725 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5726 begin
5727 if Ekind (Typ) = E_Anonymous_Access_Type
5728 and then not Is_Local_Anonymous_Access (Typ)
5729 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5730 then
5731 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5732 -- access type.
5734 return
5735 Scope_Depth (Enclosing_Dynamic_Scope
5736 (Defining_Identifier
5737 (Associated_Node_For_Itype (Typ))));
5739 -- For generic formal type, return Int'Last (infinite).
5740 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5742 elsif Is_Generic_Type (Root_Type (Typ)) then
5743 return UI_From_Int (Int'Last);
5745 else
5746 return Type_Access_Level (Typ);
5747 end if;
5748 end Deepest_Type_Access_Level;
5750 ---------------------
5751 -- Defining_Entity --
5752 ---------------------
5754 function Defining_Entity
5755 (N : Node_Id;
5756 Empty_On_Errors : Boolean := False;
5757 Concurrent_Subunit : Boolean := False) return Entity_Id
5759 begin
5760 case Nkind (N) is
5761 when N_Abstract_Subprogram_Declaration
5762 | N_Expression_Function
5763 | N_Formal_Subprogram_Declaration
5764 | N_Generic_Package_Declaration
5765 | N_Generic_Subprogram_Declaration
5766 | N_Package_Declaration
5767 | N_Subprogram_Body
5768 | N_Subprogram_Body_Stub
5769 | N_Subprogram_Declaration
5770 | N_Subprogram_Renaming_Declaration
5772 return Defining_Entity (Specification (N));
5774 when N_Component_Declaration
5775 | N_Defining_Program_Unit_Name
5776 | N_Discriminant_Specification
5777 | N_Entry_Body
5778 | N_Entry_Declaration
5779 | N_Entry_Index_Specification
5780 | N_Exception_Declaration
5781 | N_Exception_Renaming_Declaration
5782 | N_Formal_Object_Declaration
5783 | N_Formal_Package_Declaration
5784 | N_Formal_Type_Declaration
5785 | N_Full_Type_Declaration
5786 | N_Implicit_Label_Declaration
5787 | N_Incomplete_Type_Declaration
5788 | N_Iterator_Specification
5789 | N_Loop_Parameter_Specification
5790 | N_Number_Declaration
5791 | N_Object_Declaration
5792 | N_Object_Renaming_Declaration
5793 | N_Package_Body_Stub
5794 | N_Parameter_Specification
5795 | N_Private_Extension_Declaration
5796 | N_Private_Type_Declaration
5797 | N_Protected_Body
5798 | N_Protected_Body_Stub
5799 | N_Protected_Type_Declaration
5800 | N_Single_Protected_Declaration
5801 | N_Single_Task_Declaration
5802 | N_Subtype_Declaration
5803 | N_Task_Body
5804 | N_Task_Body_Stub
5805 | N_Task_Type_Declaration
5807 return Defining_Identifier (N);
5809 when N_Subunit =>
5810 declare
5811 Bod : constant Node_Id := Proper_Body (N);
5812 Orig_Bod : constant Node_Id := Original_Node (Bod);
5814 begin
5815 -- Retrieve the entity of the original protected or task body
5816 -- if requested by the caller.
5818 if Concurrent_Subunit
5819 and then Nkind (Bod) = N_Null_Statement
5820 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5821 then
5822 return Defining_Entity (Orig_Bod);
5823 else
5824 return Defining_Entity (Bod);
5825 end if;
5826 end;
5828 when N_Function_Instantiation
5829 | N_Function_Specification
5830 | N_Generic_Function_Renaming_Declaration
5831 | N_Generic_Package_Renaming_Declaration
5832 | N_Generic_Procedure_Renaming_Declaration
5833 | N_Package_Body
5834 | N_Package_Instantiation
5835 | N_Package_Renaming_Declaration
5836 | N_Package_Specification
5837 | N_Procedure_Instantiation
5838 | N_Procedure_Specification
5840 declare
5841 Nam : constant Node_Id := Defining_Unit_Name (N);
5842 Err : Entity_Id := Empty;
5844 begin
5845 if Nkind (Nam) in N_Entity then
5846 return Nam;
5848 -- For Error, make up a name and attach to declaration so we
5849 -- can continue semantic analysis.
5851 elsif Nam = Error then
5852 if Empty_On_Errors then
5853 return Empty;
5854 else
5855 Err := Make_Temporary (Sloc (N), 'T');
5856 Set_Defining_Unit_Name (N, Err);
5858 return Err;
5859 end if;
5861 -- If not an entity, get defining identifier
5863 else
5864 return Defining_Identifier (Nam);
5865 end if;
5866 end;
5868 when N_Block_Statement
5869 | N_Loop_Statement
5871 return Entity (Identifier (N));
5873 when others =>
5874 if Empty_On_Errors then
5875 return Empty;
5876 else
5877 raise Program_Error;
5878 end if;
5879 end case;
5880 end Defining_Entity;
5882 --------------------------
5883 -- Denotes_Discriminant --
5884 --------------------------
5886 function Denotes_Discriminant
5887 (N : Node_Id;
5888 Check_Concurrent : Boolean := False) return Boolean
5890 E : Entity_Id;
5892 begin
5893 if not Is_Entity_Name (N) or else No (Entity (N)) then
5894 return False;
5895 else
5896 E := Entity (N);
5897 end if;
5899 -- If we are checking for a protected type, the discriminant may have
5900 -- been rewritten as the corresponding discriminal of the original type
5901 -- or of the corresponding concurrent record, depending on whether we
5902 -- are in the spec or body of the protected type.
5904 return Ekind (E) = E_Discriminant
5905 or else
5906 (Check_Concurrent
5907 and then Ekind (E) = E_In_Parameter
5908 and then Present (Discriminal_Link (E))
5909 and then
5910 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5911 or else
5912 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5913 end Denotes_Discriminant;
5915 -------------------------
5916 -- Denotes_Same_Object --
5917 -------------------------
5919 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5920 Obj1 : Node_Id := A1;
5921 Obj2 : Node_Id := A2;
5923 function Has_Prefix (N : Node_Id) return Boolean;
5924 -- Return True if N has attribute Prefix
5926 function Is_Renaming (N : Node_Id) return Boolean;
5927 -- Return true if N names a renaming entity
5929 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5930 -- For renamings, return False if the prefix of any dereference within
5931 -- the renamed object_name is a variable, or any expression within the
5932 -- renamed object_name contains references to variables or calls on
5933 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5935 ----------------
5936 -- Has_Prefix --
5937 ----------------
5939 function Has_Prefix (N : Node_Id) return Boolean is
5940 begin
5941 return
5942 Nkind_In (N,
5943 N_Attribute_Reference,
5944 N_Expanded_Name,
5945 N_Explicit_Dereference,
5946 N_Indexed_Component,
5947 N_Reference,
5948 N_Selected_Component,
5949 N_Slice);
5950 end Has_Prefix;
5952 -----------------
5953 -- Is_Renaming --
5954 -----------------
5956 function Is_Renaming (N : Node_Id) return Boolean is
5957 begin
5958 return Is_Entity_Name (N)
5959 and then Present (Renamed_Entity (Entity (N)));
5960 end Is_Renaming;
5962 -----------------------
5963 -- Is_Valid_Renaming --
5964 -----------------------
5966 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5968 function Check_Renaming (N : Node_Id) return Boolean;
5969 -- Recursive function used to traverse all the prefixes of N
5971 function Check_Renaming (N : Node_Id) return Boolean is
5972 begin
5973 if Is_Renaming (N)
5974 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5975 then
5976 return False;
5977 end if;
5979 if Nkind (N) = N_Indexed_Component then
5980 declare
5981 Indx : Node_Id;
5983 begin
5984 Indx := First (Expressions (N));
5985 while Present (Indx) loop
5986 if not Is_OK_Static_Expression (Indx) then
5987 return False;
5988 end if;
5990 Next_Index (Indx);
5991 end loop;
5992 end;
5993 end if;
5995 if Has_Prefix (N) then
5996 declare
5997 P : constant Node_Id := Prefix (N);
5999 begin
6000 if Nkind (N) = N_Explicit_Dereference
6001 and then Is_Variable (P)
6002 then
6003 return False;
6005 elsif Is_Entity_Name (P)
6006 and then Ekind (Entity (P)) = E_Function
6007 then
6008 return False;
6010 elsif Nkind (P) = N_Function_Call then
6011 return False;
6012 end if;
6014 -- Recursion to continue traversing the prefix of the
6015 -- renaming expression
6017 return Check_Renaming (P);
6018 end;
6019 end if;
6021 return True;
6022 end Check_Renaming;
6024 -- Start of processing for Is_Valid_Renaming
6026 begin
6027 return Check_Renaming (N);
6028 end Is_Valid_Renaming;
6030 -- Start of processing for Denotes_Same_Object
6032 begin
6033 -- Both names statically denote the same stand-alone object or parameter
6034 -- (RM 6.4.1(6.5/3))
6036 if Is_Entity_Name (Obj1)
6037 and then Is_Entity_Name (Obj2)
6038 and then Entity (Obj1) = Entity (Obj2)
6039 then
6040 return True;
6041 end if;
6043 -- For renamings, the prefix of any dereference within the renamed
6044 -- object_name is not a variable, and any expression within the
6045 -- renamed object_name contains no references to variables nor
6046 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6048 if Is_Renaming (Obj1) then
6049 if Is_Valid_Renaming (Obj1) then
6050 Obj1 := Renamed_Entity (Entity (Obj1));
6051 else
6052 return False;
6053 end if;
6054 end if;
6056 if Is_Renaming (Obj2) then
6057 if Is_Valid_Renaming (Obj2) then
6058 Obj2 := Renamed_Entity (Entity (Obj2));
6059 else
6060 return False;
6061 end if;
6062 end if;
6064 -- No match if not same node kind (such cases are handled by
6065 -- Denotes_Same_Prefix)
6067 if Nkind (Obj1) /= Nkind (Obj2) then
6068 return False;
6070 -- After handling valid renamings, one of the two names statically
6071 -- denoted a renaming declaration whose renamed object_name is known
6072 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6074 elsif Is_Entity_Name (Obj1) then
6075 if Is_Entity_Name (Obj2) then
6076 return Entity (Obj1) = Entity (Obj2);
6077 else
6078 return False;
6079 end if;
6081 -- Both names are selected_components, their prefixes are known to
6082 -- denote the same object, and their selector_names denote the same
6083 -- component (RM 6.4.1(6.6/3)).
6085 elsif Nkind (Obj1) = N_Selected_Component then
6086 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6087 and then
6088 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6090 -- Both names are dereferences and the dereferenced names are known to
6091 -- denote the same object (RM 6.4.1(6.7/3))
6093 elsif Nkind (Obj1) = N_Explicit_Dereference then
6094 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6096 -- Both names are indexed_components, their prefixes are known to denote
6097 -- the same object, and each of the pairs of corresponding index values
6098 -- are either both static expressions with the same static value or both
6099 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6101 elsif Nkind (Obj1) = N_Indexed_Component then
6102 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6103 return False;
6104 else
6105 declare
6106 Indx1 : Node_Id;
6107 Indx2 : Node_Id;
6109 begin
6110 Indx1 := First (Expressions (Obj1));
6111 Indx2 := First (Expressions (Obj2));
6112 while Present (Indx1) loop
6114 -- Indexes must denote the same static value or same object
6116 if Is_OK_Static_Expression (Indx1) then
6117 if not Is_OK_Static_Expression (Indx2) then
6118 return False;
6120 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6121 return False;
6122 end if;
6124 elsif not Denotes_Same_Object (Indx1, Indx2) then
6125 return False;
6126 end if;
6128 Next (Indx1);
6129 Next (Indx2);
6130 end loop;
6132 return True;
6133 end;
6134 end if;
6136 -- Both names are slices, their prefixes are known to denote the same
6137 -- object, and the two slices have statically matching index constraints
6138 -- (RM 6.4.1(6.9/3))
6140 elsif Nkind (Obj1) = N_Slice
6141 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6142 then
6143 declare
6144 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6146 begin
6147 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6148 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6150 -- Check whether bounds are statically identical. There is no
6151 -- attempt to detect partial overlap of slices.
6153 return Denotes_Same_Object (Lo1, Lo2)
6154 and then
6155 Denotes_Same_Object (Hi1, Hi2);
6156 end;
6158 -- In the recursion, literals appear as indexes
6160 elsif Nkind (Obj1) = N_Integer_Literal
6161 and then
6162 Nkind (Obj2) = N_Integer_Literal
6163 then
6164 return Intval (Obj1) = Intval (Obj2);
6166 else
6167 return False;
6168 end if;
6169 end Denotes_Same_Object;
6171 -------------------------
6172 -- Denotes_Same_Prefix --
6173 -------------------------
6175 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6176 begin
6177 if Is_Entity_Name (A1) then
6178 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6179 and then not Is_Access_Type (Etype (A1))
6180 then
6181 return Denotes_Same_Object (A1, Prefix (A2))
6182 or else Denotes_Same_Prefix (A1, Prefix (A2));
6183 else
6184 return False;
6185 end if;
6187 elsif Is_Entity_Name (A2) then
6188 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6190 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6191 and then
6192 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6193 then
6194 declare
6195 Root1, Root2 : Node_Id;
6196 Depth1, Depth2 : Nat := 0;
6198 begin
6199 Root1 := Prefix (A1);
6200 while not Is_Entity_Name (Root1) loop
6201 if not Nkind_In
6202 (Root1, N_Selected_Component, N_Indexed_Component)
6203 then
6204 return False;
6205 else
6206 Root1 := Prefix (Root1);
6207 end if;
6209 Depth1 := Depth1 + 1;
6210 end loop;
6212 Root2 := Prefix (A2);
6213 while not Is_Entity_Name (Root2) loop
6214 if not Nkind_In (Root2, N_Selected_Component,
6215 N_Indexed_Component)
6216 then
6217 return False;
6218 else
6219 Root2 := Prefix (Root2);
6220 end if;
6222 Depth2 := Depth2 + 1;
6223 end loop;
6225 -- If both have the same depth and they do not denote the same
6226 -- object, they are disjoint and no warning is needed.
6228 if Depth1 = Depth2 then
6229 return False;
6231 elsif Depth1 > Depth2 then
6232 Root1 := Prefix (A1);
6233 for J in 1 .. Depth1 - Depth2 - 1 loop
6234 Root1 := Prefix (Root1);
6235 end loop;
6237 return Denotes_Same_Object (Root1, A2);
6239 else
6240 Root2 := Prefix (A2);
6241 for J in 1 .. Depth2 - Depth1 - 1 loop
6242 Root2 := Prefix (Root2);
6243 end loop;
6245 return Denotes_Same_Object (A1, Root2);
6246 end if;
6247 end;
6249 else
6250 return False;
6251 end if;
6252 end Denotes_Same_Prefix;
6254 ----------------------
6255 -- Denotes_Variable --
6256 ----------------------
6258 function Denotes_Variable (N : Node_Id) return Boolean is
6259 begin
6260 return Is_Variable (N) and then Paren_Count (N) = 0;
6261 end Denotes_Variable;
6263 -----------------------------
6264 -- Depends_On_Discriminant --
6265 -----------------------------
6267 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6268 L : Node_Id;
6269 H : Node_Id;
6271 begin
6272 Get_Index_Bounds (N, L, H);
6273 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6274 end Depends_On_Discriminant;
6276 -------------------------
6277 -- Designate_Same_Unit --
6278 -------------------------
6280 function Designate_Same_Unit
6281 (Name1 : Node_Id;
6282 Name2 : Node_Id) return Boolean
6284 K1 : constant Node_Kind := Nkind (Name1);
6285 K2 : constant Node_Kind := Nkind (Name2);
6287 function Prefix_Node (N : Node_Id) return Node_Id;
6288 -- Returns the parent unit name node of a defining program unit name
6289 -- or the prefix if N is a selected component or an expanded name.
6291 function Select_Node (N : Node_Id) return Node_Id;
6292 -- Returns the defining identifier node of a defining program unit
6293 -- name or the selector node if N is a selected component or an
6294 -- expanded name.
6296 -----------------
6297 -- Prefix_Node --
6298 -----------------
6300 function Prefix_Node (N : Node_Id) return Node_Id is
6301 begin
6302 if Nkind (N) = N_Defining_Program_Unit_Name then
6303 return Name (N);
6304 else
6305 return Prefix (N);
6306 end if;
6307 end Prefix_Node;
6309 -----------------
6310 -- Select_Node --
6311 -----------------
6313 function Select_Node (N : Node_Id) return Node_Id is
6314 begin
6315 if Nkind (N) = N_Defining_Program_Unit_Name then
6316 return Defining_Identifier (N);
6317 else
6318 return Selector_Name (N);
6319 end if;
6320 end Select_Node;
6322 -- Start of processing for Designate_Same_Unit
6324 begin
6325 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6326 and then
6327 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6328 then
6329 return Chars (Name1) = Chars (Name2);
6331 elsif Nkind_In (K1, N_Expanded_Name,
6332 N_Selected_Component,
6333 N_Defining_Program_Unit_Name)
6334 and then
6335 Nkind_In (K2, N_Expanded_Name,
6336 N_Selected_Component,
6337 N_Defining_Program_Unit_Name)
6338 then
6339 return
6340 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6341 and then
6342 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6344 else
6345 return False;
6346 end if;
6347 end Designate_Same_Unit;
6349 ---------------------------------------------
6350 -- Diagnose_Iterated_Component_Association --
6351 ---------------------------------------------
6353 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6354 Def_Id : constant Entity_Id := Defining_Identifier (N);
6355 Aggr : Node_Id;
6357 begin
6358 -- Determine whether the iterated component association appears within
6359 -- an aggregate. If this is the case, raise Program_Error because the
6360 -- iterated component association cannot be left in the tree as is and
6361 -- must always be processed by the related aggregate.
6363 Aggr := N;
6364 while Present (Aggr) loop
6365 if Nkind (Aggr) = N_Aggregate then
6366 raise Program_Error;
6368 -- Prevent the search from going too far
6370 elsif Is_Body_Or_Package_Declaration (Aggr) then
6371 exit;
6372 end if;
6374 Aggr := Parent (Aggr);
6375 end loop;
6377 -- At this point it is known that the iterated component association is
6378 -- not within an aggregate. This is really a quantified expression with
6379 -- a missing "all" or "some" quantifier.
6381 Error_Msg_N ("missing quantifier", Def_Id);
6383 -- Rewrite the iterated component association as True to prevent any
6384 -- cascaded errors.
6386 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6387 Analyze (N);
6388 end Diagnose_Iterated_Component_Association;
6390 ---------------------------------
6391 -- Dynamic_Accessibility_Level --
6392 ---------------------------------
6394 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
6395 Loc : constant Source_Ptr := Sloc (Expr);
6397 function Make_Level_Literal (Level : Uint) return Node_Id;
6398 -- Construct an integer literal representing an accessibility level
6399 -- with its type set to Natural.
6401 ------------------------
6402 -- Make_Level_Literal --
6403 ------------------------
6405 function Make_Level_Literal (Level : Uint) return Node_Id is
6406 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6408 begin
6409 Set_Etype (Result, Standard_Natural);
6410 return Result;
6411 end Make_Level_Literal;
6413 -- Local variables
6415 E : Entity_Id;
6417 -- Start of processing for Dynamic_Accessibility_Level
6419 begin
6420 if Is_Entity_Name (Expr) then
6421 E := Entity (Expr);
6423 if Present (Renamed_Object (E)) then
6424 return Dynamic_Accessibility_Level (Renamed_Object (E));
6425 end if;
6427 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6428 if Present (Extra_Accessibility (E)) then
6429 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6430 end if;
6431 end if;
6432 end if;
6434 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6436 case Nkind (Expr) is
6438 -- For access discriminant, the level of the enclosing object
6440 when N_Selected_Component =>
6441 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6442 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6443 E_Anonymous_Access_Type
6444 then
6445 return Make_Level_Literal (Object_Access_Level (Expr));
6446 end if;
6448 when N_Attribute_Reference =>
6449 case Get_Attribute_Id (Attribute_Name (Expr)) is
6451 -- For X'Access, the level of the prefix X
6453 when Attribute_Access =>
6454 return Make_Level_Literal
6455 (Object_Access_Level (Prefix (Expr)));
6457 -- Treat the unchecked attributes as library-level
6459 when Attribute_Unchecked_Access
6460 | Attribute_Unrestricted_Access
6462 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6464 -- No other access-valued attributes
6466 when others =>
6467 raise Program_Error;
6468 end case;
6470 when N_Allocator =>
6472 -- Unimplemented: depends on context. As an actual parameter where
6473 -- formal type is anonymous, use
6474 -- Scope_Depth (Current_Scope) + 1.
6475 -- For other cases, see 3.10.2(14/3) and following. ???
6477 null;
6479 when N_Type_Conversion =>
6480 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6482 -- Handle type conversions introduced for a rename of an
6483 -- Ada 2012 stand-alone object of an anonymous access type.
6485 return Dynamic_Accessibility_Level (Expression (Expr));
6486 end if;
6488 when others =>
6489 null;
6490 end case;
6492 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6493 end Dynamic_Accessibility_Level;
6495 ------------------------
6496 -- Discriminated_Size --
6497 ------------------------
6499 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6500 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6501 -- Check whether the bound of an index is non-static and does denote
6502 -- a discriminant, in which case any object of the type (protected or
6503 -- otherwise) will have a non-static size.
6505 ----------------------
6506 -- Non_Static_Bound --
6507 ----------------------
6509 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6510 begin
6511 if Is_OK_Static_Expression (Bound) then
6512 return False;
6514 -- If the bound is given by a discriminant it is non-static
6515 -- (A static constraint replaces the reference with the value).
6516 -- In an protected object the discriminant has been replaced by
6517 -- the corresponding discriminal within the protected operation.
6519 elsif Is_Entity_Name (Bound)
6520 and then
6521 (Ekind (Entity (Bound)) = E_Discriminant
6522 or else Present (Discriminal_Link (Entity (Bound))))
6523 then
6524 return False;
6526 else
6527 return True;
6528 end if;
6529 end Non_Static_Bound;
6531 -- Local variables
6533 Typ : constant Entity_Id := Etype (Comp);
6534 Index : Node_Id;
6536 -- Start of processing for Discriminated_Size
6538 begin
6539 if not Is_Array_Type (Typ) then
6540 return False;
6541 end if;
6543 if Ekind (Typ) = E_Array_Subtype then
6544 Index := First_Index (Typ);
6545 while Present (Index) loop
6546 if Non_Static_Bound (Low_Bound (Index))
6547 or else Non_Static_Bound (High_Bound (Index))
6548 then
6549 return False;
6550 end if;
6552 Next_Index (Index);
6553 end loop;
6555 return True;
6556 end if;
6558 return False;
6559 end Discriminated_Size;
6561 -----------------------------------
6562 -- Effective_Extra_Accessibility --
6563 -----------------------------------
6565 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6566 begin
6567 if Present (Renamed_Object (Id))
6568 and then Is_Entity_Name (Renamed_Object (Id))
6569 then
6570 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6571 else
6572 return Extra_Accessibility (Id);
6573 end if;
6574 end Effective_Extra_Accessibility;
6576 -----------------------------
6577 -- Effective_Reads_Enabled --
6578 -----------------------------
6580 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6581 begin
6582 return Has_Enabled_Property (Id, Name_Effective_Reads);
6583 end Effective_Reads_Enabled;
6585 ------------------------------
6586 -- Effective_Writes_Enabled --
6587 ------------------------------
6589 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6590 begin
6591 return Has_Enabled_Property (Id, Name_Effective_Writes);
6592 end Effective_Writes_Enabled;
6594 ------------------------------
6595 -- Enclosing_Comp_Unit_Node --
6596 ------------------------------
6598 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6599 Current_Node : Node_Id;
6601 begin
6602 Current_Node := N;
6603 while Present (Current_Node)
6604 and then Nkind (Current_Node) /= N_Compilation_Unit
6605 loop
6606 Current_Node := Parent (Current_Node);
6607 end loop;
6609 if Nkind (Current_Node) /= N_Compilation_Unit then
6610 return Empty;
6611 else
6612 return Current_Node;
6613 end if;
6614 end Enclosing_Comp_Unit_Node;
6616 --------------------------
6617 -- Enclosing_CPP_Parent --
6618 --------------------------
6620 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6621 Parent_Typ : Entity_Id := Typ;
6623 begin
6624 while not Is_CPP_Class (Parent_Typ)
6625 and then Etype (Parent_Typ) /= Parent_Typ
6626 loop
6627 Parent_Typ := Etype (Parent_Typ);
6629 if Is_Private_Type (Parent_Typ) then
6630 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6631 end if;
6632 end loop;
6634 pragma Assert (Is_CPP_Class (Parent_Typ));
6635 return Parent_Typ;
6636 end Enclosing_CPP_Parent;
6638 ---------------------------
6639 -- Enclosing_Declaration --
6640 ---------------------------
6642 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6643 Decl : Node_Id := N;
6645 begin
6646 while Present (Decl)
6647 and then not (Nkind (Decl) in N_Declaration
6648 or else
6649 Nkind (Decl) in N_Later_Decl_Item
6650 or else
6651 Nkind (Decl) = N_Number_Declaration)
6652 loop
6653 Decl := Parent (Decl);
6654 end loop;
6656 return Decl;
6657 end Enclosing_Declaration;
6659 ----------------------------
6660 -- Enclosing_Generic_Body --
6661 ----------------------------
6663 function Enclosing_Generic_Body
6664 (N : Node_Id) return Node_Id
6666 P : Node_Id;
6667 Decl : Node_Id;
6668 Spec : Node_Id;
6670 begin
6671 P := Parent (N);
6672 while Present (P) loop
6673 if Nkind (P) = N_Package_Body
6674 or else Nkind (P) = N_Subprogram_Body
6675 then
6676 Spec := Corresponding_Spec (P);
6678 if Present (Spec) then
6679 Decl := Unit_Declaration_Node (Spec);
6681 if Nkind (Decl) = N_Generic_Package_Declaration
6682 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6683 then
6684 return P;
6685 end if;
6686 end if;
6687 end if;
6689 P := Parent (P);
6690 end loop;
6692 return Empty;
6693 end Enclosing_Generic_Body;
6695 ----------------------------
6696 -- Enclosing_Generic_Unit --
6697 ----------------------------
6699 function Enclosing_Generic_Unit
6700 (N : Node_Id) return Node_Id
6702 P : Node_Id;
6703 Decl : Node_Id;
6704 Spec : Node_Id;
6706 begin
6707 P := Parent (N);
6708 while Present (P) loop
6709 if Nkind (P) = N_Generic_Package_Declaration
6710 or else Nkind (P) = N_Generic_Subprogram_Declaration
6711 then
6712 return P;
6714 elsif Nkind (P) = N_Package_Body
6715 or else Nkind (P) = N_Subprogram_Body
6716 then
6717 Spec := Corresponding_Spec (P);
6719 if Present (Spec) then
6720 Decl := Unit_Declaration_Node (Spec);
6722 if Nkind (Decl) = N_Generic_Package_Declaration
6723 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6724 then
6725 return Decl;
6726 end if;
6727 end if;
6728 end if;
6730 P := Parent (P);
6731 end loop;
6733 return Empty;
6734 end Enclosing_Generic_Unit;
6736 -------------------------------
6737 -- Enclosing_Lib_Unit_Entity --
6738 -------------------------------
6740 function Enclosing_Lib_Unit_Entity
6741 (E : Entity_Id := Current_Scope) return Entity_Id
6743 Unit_Entity : Entity_Id;
6745 begin
6746 -- Look for enclosing library unit entity by following scope links.
6747 -- Equivalent to, but faster than indexing through the scope stack.
6749 Unit_Entity := E;
6750 while (Present (Scope (Unit_Entity))
6751 and then Scope (Unit_Entity) /= Standard_Standard)
6752 and not Is_Child_Unit (Unit_Entity)
6753 loop
6754 Unit_Entity := Scope (Unit_Entity);
6755 end loop;
6757 return Unit_Entity;
6758 end Enclosing_Lib_Unit_Entity;
6760 -----------------------------
6761 -- Enclosing_Lib_Unit_Node --
6762 -----------------------------
6764 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6765 Encl_Unit : Node_Id;
6767 begin
6768 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6769 while Present (Encl_Unit)
6770 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6771 loop
6772 Encl_Unit := Library_Unit (Encl_Unit);
6773 end loop;
6775 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6776 return Encl_Unit;
6777 end Enclosing_Lib_Unit_Node;
6779 -----------------------
6780 -- Enclosing_Package --
6781 -----------------------
6783 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6784 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6786 begin
6787 if Dynamic_Scope = Standard_Standard then
6788 return Standard_Standard;
6790 elsif Dynamic_Scope = Empty then
6791 return Empty;
6793 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6794 E_Generic_Package)
6795 then
6796 return Dynamic_Scope;
6798 else
6799 return Enclosing_Package (Dynamic_Scope);
6800 end if;
6801 end Enclosing_Package;
6803 -------------------------------------
6804 -- Enclosing_Package_Or_Subprogram --
6805 -------------------------------------
6807 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6808 S : Entity_Id;
6810 begin
6811 S := Scope (E);
6812 while Present (S) loop
6813 if Is_Package_Or_Generic_Package (S)
6814 or else Ekind (S) = E_Package_Body
6815 then
6816 return S;
6818 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6819 or else Ekind (S) = E_Subprogram_Body
6820 then
6821 return S;
6823 else
6824 S := Scope (S);
6825 end if;
6826 end loop;
6828 return Empty;
6829 end Enclosing_Package_Or_Subprogram;
6831 --------------------------
6832 -- Enclosing_Subprogram --
6833 --------------------------
6835 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6836 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6838 begin
6839 if Dynamic_Scope = Standard_Standard then
6840 return Empty;
6842 elsif Dynamic_Scope = Empty then
6843 return Empty;
6845 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6846 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6848 elsif Ekind (Dynamic_Scope) = E_Block
6849 or else Ekind (Dynamic_Scope) = E_Return_Statement
6850 then
6851 return Enclosing_Subprogram (Dynamic_Scope);
6853 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6854 return Get_Task_Body_Procedure (Dynamic_Scope);
6856 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6857 and then Present (Full_View (Dynamic_Scope))
6858 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6859 then
6860 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6862 -- No body is generated if the protected operation is eliminated
6864 elsif Convention (Dynamic_Scope) = Convention_Protected
6865 and then not Is_Eliminated (Dynamic_Scope)
6866 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6867 then
6868 return Protected_Body_Subprogram (Dynamic_Scope);
6870 else
6871 return Dynamic_Scope;
6872 end if;
6873 end Enclosing_Subprogram;
6875 --------------------------
6876 -- End_Keyword_Location --
6877 --------------------------
6879 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
6880 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
6881 -- Return the source location of Nod's end label according to the
6882 -- following precedence rules:
6884 -- 1) If the end label exists, return its location
6885 -- 2) If Nod exists, return its location
6886 -- 3) Return the location of N
6888 -------------------
6889 -- End_Label_Loc --
6890 -------------------
6892 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
6893 Label : Node_Id;
6895 begin
6896 if Present (Nod) then
6897 Label := End_Label (Nod);
6899 if Present (Label) then
6900 return Sloc (Label);
6901 else
6902 return Sloc (Nod);
6903 end if;
6905 else
6906 return Sloc (N);
6907 end if;
6908 end End_Label_Loc;
6910 -- Local variables
6912 Owner : Node_Id;
6914 -- Start of processing for End_Keyword_Location
6916 begin
6917 if Nkind_In (N, N_Block_Statement,
6918 N_Entry_Body,
6919 N_Package_Body,
6920 N_Subprogram_Body,
6921 N_Task_Body)
6922 then
6923 Owner := Handled_Statement_Sequence (N);
6925 elsif Nkind (N) = N_Package_Declaration then
6926 Owner := Specification (N);
6928 elsif Nkind (N) = N_Protected_Body then
6929 Owner := N;
6931 elsif Nkind_In (N, N_Protected_Type_Declaration,
6932 N_Single_Protected_Declaration)
6933 then
6934 Owner := Protected_Definition (N);
6936 elsif Nkind_In (N, N_Single_Task_Declaration,
6937 N_Task_Type_Declaration)
6938 then
6939 Owner := Task_Definition (N);
6941 -- This routine should not be called with other contexts
6943 else
6944 pragma Assert (False);
6945 null;
6946 end if;
6948 return End_Label_Loc (Owner);
6949 end End_Keyword_Location;
6951 ------------------------
6952 -- Ensure_Freeze_Node --
6953 ------------------------
6955 procedure Ensure_Freeze_Node (E : Entity_Id) is
6956 FN : Node_Id;
6957 begin
6958 if No (Freeze_Node (E)) then
6959 FN := Make_Freeze_Entity (Sloc (E));
6960 Set_Has_Delayed_Freeze (E);
6961 Set_Freeze_Node (E, FN);
6962 Set_Access_Types_To_Process (FN, No_Elist);
6963 Set_TSS_Elist (FN, No_Elist);
6964 Set_Entity (FN, E);
6965 end if;
6966 end Ensure_Freeze_Node;
6968 ----------------
6969 -- Enter_Name --
6970 ----------------
6972 procedure Enter_Name (Def_Id : Entity_Id) is
6973 C : constant Entity_Id := Current_Entity (Def_Id);
6974 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6975 S : constant Entity_Id := Current_Scope;
6977 begin
6978 Generate_Definition (Def_Id);
6980 -- Add new name to current scope declarations. Check for duplicate
6981 -- declaration, which may or may not be a genuine error.
6983 if Present (E) then
6985 -- Case of previous entity entered because of a missing declaration
6986 -- or else a bad subtype indication. Best is to use the new entity,
6987 -- and make the previous one invisible.
6989 if Etype (E) = Any_Type then
6990 Set_Is_Immediately_Visible (E, False);
6992 -- Case of renaming declaration constructed for package instances.
6993 -- if there is an explicit declaration with the same identifier,
6994 -- the renaming is not immediately visible any longer, but remains
6995 -- visible through selected component notation.
6997 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6998 and then not Comes_From_Source (E)
6999 then
7000 Set_Is_Immediately_Visible (E, False);
7002 -- The new entity may be the package renaming, which has the same
7003 -- same name as a generic formal which has been seen already.
7005 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7006 and then not Comes_From_Source (Def_Id)
7007 then
7008 Set_Is_Immediately_Visible (E, False);
7010 -- For a fat pointer corresponding to a remote access to subprogram,
7011 -- we use the same identifier as the RAS type, so that the proper
7012 -- name appears in the stub. This type is only retrieved through
7013 -- the RAS type and never by visibility, and is not added to the
7014 -- visibility list (see below).
7016 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7017 and then Ekind (Def_Id) = E_Record_Type
7018 and then Present (Corresponding_Remote_Type (Def_Id))
7019 then
7020 null;
7022 -- Case of an implicit operation or derived literal. The new entity
7023 -- hides the implicit one, which is removed from all visibility,
7024 -- i.e. the entity list of its scope, and homonym chain of its name.
7026 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7027 or else Is_Internal (E)
7028 then
7029 declare
7030 Decl : constant Node_Id := Parent (E);
7031 Prev : Entity_Id;
7032 Prev_Vis : Entity_Id;
7034 begin
7035 -- If E is an implicit declaration, it cannot be the first
7036 -- entity in the scope.
7038 Prev := First_Entity (Current_Scope);
7039 while Present (Prev) and then Next_Entity (Prev) /= E loop
7040 Next_Entity (Prev);
7041 end loop;
7043 if No (Prev) then
7045 -- If E is not on the entity chain of the current scope,
7046 -- it is an implicit declaration in the generic formal
7047 -- part of a generic subprogram. When analyzing the body,
7048 -- the generic formals are visible but not on the entity
7049 -- chain of the subprogram. The new entity will become
7050 -- the visible one in the body.
7052 pragma Assert
7053 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7054 null;
7056 else
7057 Link_Entities (Prev, Next_Entity (E));
7059 if No (Next_Entity (Prev)) then
7060 Set_Last_Entity (Current_Scope, Prev);
7061 end if;
7063 if E = Current_Entity (E) then
7064 Prev_Vis := Empty;
7066 else
7067 Prev_Vis := Current_Entity (E);
7068 while Homonym (Prev_Vis) /= E loop
7069 Prev_Vis := Homonym (Prev_Vis);
7070 end loop;
7071 end if;
7073 if Present (Prev_Vis) then
7075 -- Skip E in the visibility chain
7077 Set_Homonym (Prev_Vis, Homonym (E));
7079 else
7080 Set_Name_Entity_Id (Chars (E), Homonym (E));
7081 end if;
7082 end if;
7083 end;
7085 -- This section of code could use a comment ???
7087 elsif Present (Etype (E))
7088 and then Is_Concurrent_Type (Etype (E))
7089 and then E = Def_Id
7090 then
7091 return;
7093 -- If the homograph is a protected component renaming, it should not
7094 -- be hiding the current entity. Such renamings are treated as weak
7095 -- declarations.
7097 elsif Is_Prival (E) then
7098 Set_Is_Immediately_Visible (E, False);
7100 -- In this case the current entity is a protected component renaming.
7101 -- Perform minimal decoration by setting the scope and return since
7102 -- the prival should not be hiding other visible entities.
7104 elsif Is_Prival (Def_Id) then
7105 Set_Scope (Def_Id, Current_Scope);
7106 return;
7108 -- Analogous to privals, the discriminal generated for an entry index
7109 -- parameter acts as a weak declaration. Perform minimal decoration
7110 -- to avoid bogus errors.
7112 elsif Is_Discriminal (Def_Id)
7113 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7114 then
7115 Set_Scope (Def_Id, Current_Scope);
7116 return;
7118 -- In the body or private part of an instance, a type extension may
7119 -- introduce a component with the same name as that of an actual. The
7120 -- legality rule is not enforced, but the semantics of the full type
7121 -- with two components of same name are not clear at this point???
7123 elsif In_Instance_Not_Visible then
7124 null;
7126 -- When compiling a package body, some child units may have become
7127 -- visible. They cannot conflict with local entities that hide them.
7129 elsif Is_Child_Unit (E)
7130 and then In_Open_Scopes (Scope (E))
7131 and then not Is_Immediately_Visible (E)
7132 then
7133 null;
7135 -- Conversely, with front-end inlining we may compile the parent body
7136 -- first, and a child unit subsequently. The context is now the
7137 -- parent spec, and body entities are not visible.
7139 elsif Is_Child_Unit (Def_Id)
7140 and then Is_Package_Body_Entity (E)
7141 and then not In_Package_Body (Current_Scope)
7142 then
7143 null;
7145 -- Case of genuine duplicate declaration
7147 else
7148 Error_Msg_Sloc := Sloc (E);
7150 -- If the previous declaration is an incomplete type declaration
7151 -- this may be an attempt to complete it with a private type. The
7152 -- following avoids confusing cascaded errors.
7154 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7155 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7156 then
7157 Error_Msg_N
7158 ("incomplete type cannot be completed with a private " &
7159 "declaration", Parent (Def_Id));
7160 Set_Is_Immediately_Visible (E, False);
7161 Set_Full_View (E, Def_Id);
7163 -- An inherited component of a record conflicts with a new
7164 -- discriminant. The discriminant is inserted first in the scope,
7165 -- but the error should be posted on it, not on the component.
7167 elsif Ekind (E) = E_Discriminant
7168 and then Present (Scope (Def_Id))
7169 and then Scope (Def_Id) /= Current_Scope
7170 then
7171 Error_Msg_Sloc := Sloc (Def_Id);
7172 Error_Msg_N ("& conflicts with declaration#", E);
7173 return;
7175 -- If the name of the unit appears in its own context clause, a
7176 -- dummy package with the name has already been created, and the
7177 -- error emitted. Try to continue quietly.
7179 elsif Error_Posted (E)
7180 and then Sloc (E) = No_Location
7181 and then Nkind (Parent (E)) = N_Package_Specification
7182 and then Current_Scope = Standard_Standard
7183 then
7184 Set_Scope (Def_Id, Current_Scope);
7185 return;
7187 else
7188 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7190 -- Avoid cascaded messages with duplicate components in
7191 -- derived types.
7193 if Ekind_In (E, E_Component, E_Discriminant) then
7194 return;
7195 end if;
7196 end if;
7198 if Nkind (Parent (Parent (Def_Id))) =
7199 N_Generic_Subprogram_Declaration
7200 and then Def_Id =
7201 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7202 then
7203 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7204 end if;
7206 -- If entity is in standard, then we are in trouble, because it
7207 -- means that we have a library package with a duplicated name.
7208 -- That's hard to recover from, so abort.
7210 if S = Standard_Standard then
7211 raise Unrecoverable_Error;
7213 -- Otherwise we continue with the declaration. Having two
7214 -- identical declarations should not cause us too much trouble.
7216 else
7217 null;
7218 end if;
7219 end if;
7220 end if;
7222 -- If we fall through, declaration is OK, at least OK enough to continue
7224 -- If Def_Id is a discriminant or a record component we are in the midst
7225 -- of inheriting components in a derived record definition. Preserve
7226 -- their Ekind and Etype.
7228 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7229 null;
7231 -- If a type is already set, leave it alone (happens when a type
7232 -- declaration is reanalyzed following a call to the optimizer).
7234 elsif Present (Etype (Def_Id)) then
7235 null;
7237 -- Otherwise, the kind E_Void insures that premature uses of the entity
7238 -- will be detected. Any_Type insures that no cascaded errors will occur
7240 else
7241 Set_Ekind (Def_Id, E_Void);
7242 Set_Etype (Def_Id, Any_Type);
7243 end if;
7245 -- Inherited discriminants and components in derived record types are
7246 -- immediately visible. Itypes are not.
7248 -- Unless the Itype is for a record type with a corresponding remote
7249 -- type (what is that about, it was not commented ???)
7251 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7252 or else
7253 ((not Is_Record_Type (Def_Id)
7254 or else No (Corresponding_Remote_Type (Def_Id)))
7255 and then not Is_Itype (Def_Id))
7256 then
7257 Set_Is_Immediately_Visible (Def_Id);
7258 Set_Current_Entity (Def_Id);
7259 end if;
7261 Set_Homonym (Def_Id, C);
7262 Append_Entity (Def_Id, S);
7263 Set_Public_Status (Def_Id);
7265 -- Declaring a homonym is not allowed in SPARK ...
7267 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7268 declare
7269 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7270 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7271 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7273 begin
7274 -- ... unless the new declaration is in a subprogram, and the
7275 -- visible declaration is a variable declaration or a parameter
7276 -- specification outside that subprogram.
7278 if Present (Enclosing_Subp)
7279 and then Nkind_In (Parent (C), N_Object_Declaration,
7280 N_Parameter_Specification)
7281 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7282 then
7283 null;
7285 -- ... or the new declaration is in a package, and the visible
7286 -- declaration occurs outside that package.
7288 elsif Present (Enclosing_Pack)
7289 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7290 then
7291 null;
7293 -- ... or the new declaration is a component declaration in a
7294 -- record type definition.
7296 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7297 null;
7299 -- Don't issue error for non-source entities
7301 elsif Comes_From_Source (Def_Id)
7302 and then Comes_From_Source (C)
7303 then
7304 Error_Msg_Sloc := Sloc (C);
7305 Check_SPARK_05_Restriction
7306 ("redeclaration of identifier &#", Def_Id);
7307 end if;
7308 end;
7309 end if;
7311 -- Warn if new entity hides an old one
7313 if Warn_On_Hiding and then Present (C)
7315 -- Don't warn for record components since they always have a well
7316 -- defined scope which does not confuse other uses. Note that in
7317 -- some cases, Ekind has not been set yet.
7319 and then Ekind (C) /= E_Component
7320 and then Ekind (C) /= E_Discriminant
7321 and then Nkind (Parent (C)) /= N_Component_Declaration
7322 and then Ekind (Def_Id) /= E_Component
7323 and then Ekind (Def_Id) /= E_Discriminant
7324 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7326 -- Don't warn for one character variables. It is too common to use
7327 -- such variables as locals and will just cause too many false hits.
7329 and then Length_Of_Name (Chars (C)) /= 1
7331 -- Don't warn for non-source entities
7333 and then Comes_From_Source (C)
7334 and then Comes_From_Source (Def_Id)
7336 -- Don't warn unless entity in question is in extended main source
7338 and then In_Extended_Main_Source_Unit (Def_Id)
7340 -- Finally, the hidden entity must be either immediately visible or
7341 -- use visible (i.e. from a used package).
7343 and then
7344 (Is_Immediately_Visible (C)
7345 or else
7346 Is_Potentially_Use_Visible (C))
7347 then
7348 Error_Msg_Sloc := Sloc (C);
7349 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7350 end if;
7351 end Enter_Name;
7353 ---------------
7354 -- Entity_Of --
7355 ---------------
7357 function Entity_Of (N : Node_Id) return Entity_Id is
7358 Id : Entity_Id;
7359 Ren : Node_Id;
7361 begin
7362 -- Assume that the arbitrary node does not have an entity
7364 Id := Empty;
7366 if Is_Entity_Name (N) then
7367 Id := Entity (N);
7369 -- Follow a possible chain of renamings to reach the earliest renamed
7370 -- source object.
7372 while Present (Id)
7373 and then Is_Object (Id)
7374 and then Present (Renamed_Object (Id))
7375 loop
7376 Ren := Renamed_Object (Id);
7378 -- The reference renames an abstract state or a whole object
7380 -- Obj : ...;
7381 -- Ren : ... renames Obj;
7383 if Is_Entity_Name (Ren) then
7384 Id := Entity (Ren);
7386 -- The reference renames a function result. Check the original
7387 -- node in case expansion relocates the function call.
7389 -- Ren : ... renames Func_Call;
7391 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7392 exit;
7394 -- Otherwise the reference renames something which does not yield
7395 -- an abstract state or a whole object. Treat the reference as not
7396 -- having a proper entity for SPARK legality purposes.
7398 else
7399 Id := Empty;
7400 exit;
7401 end if;
7402 end loop;
7403 end if;
7405 return Id;
7406 end Entity_Of;
7408 --------------------------
7409 -- Examine_Array_Bounds --
7410 --------------------------
7412 procedure Examine_Array_Bounds
7413 (Typ : Entity_Id;
7414 All_Static : out Boolean;
7415 Has_Empty : out Boolean)
7417 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7418 -- Determine whether bound Bound is a suitable static bound
7420 ------------------------
7421 -- Is_OK_Static_Bound --
7422 ------------------------
7424 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7425 begin
7426 return
7427 not Error_Posted (Bound)
7428 and then Is_OK_Static_Expression (Bound);
7429 end Is_OK_Static_Bound;
7431 -- Local variables
7433 Hi_Bound : Node_Id;
7434 Index : Node_Id;
7435 Lo_Bound : Node_Id;
7437 -- Start of processing for Examine_Array_Bounds
7439 begin
7440 -- An unconstrained array type does not have static bounds, and it is
7441 -- not known whether they are empty or not.
7443 if not Is_Constrained (Typ) then
7444 All_Static := False;
7445 Has_Empty := False;
7447 -- A string literal has static bounds, and is not empty as long as it
7448 -- contains at least one character.
7450 elsif Ekind (Typ) = E_String_Literal_Subtype then
7451 All_Static := True;
7452 Has_Empty := String_Literal_Length (Typ) > 0;
7453 end if;
7455 -- Assume that all bounds are static and not empty
7457 All_Static := True;
7458 Has_Empty := False;
7460 -- Examine each index
7462 Index := First_Index (Typ);
7463 while Present (Index) loop
7464 if Is_Discrete_Type (Etype (Index)) then
7465 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7467 if Is_OK_Static_Bound (Lo_Bound)
7468 and then
7469 Is_OK_Static_Bound (Hi_Bound)
7470 then
7471 -- The static bounds produce an empty range
7473 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7474 Has_Empty := True;
7475 end if;
7477 -- Otherwise at least one of the bounds is not static
7479 else
7480 All_Static := False;
7481 end if;
7483 -- Otherwise the index is non-discrete, therefore not static
7485 else
7486 All_Static := False;
7487 end if;
7489 Next_Index (Index);
7490 end loop;
7491 end Examine_Array_Bounds;
7493 --------------------------
7494 -- Explain_Limited_Type --
7495 --------------------------
7497 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7498 C : Entity_Id;
7500 begin
7501 -- For array, component type must be limited
7503 if Is_Array_Type (T) then
7504 Error_Msg_Node_2 := T;
7505 Error_Msg_NE
7506 ("\component type& of type& is limited", N, Component_Type (T));
7507 Explain_Limited_Type (Component_Type (T), N);
7509 elsif Is_Record_Type (T) then
7511 -- No need for extra messages if explicit limited record
7513 if Is_Limited_Record (Base_Type (T)) then
7514 return;
7515 end if;
7517 -- Otherwise find a limited component. Check only components that
7518 -- come from source, or inherited components that appear in the
7519 -- source of the ancestor.
7521 C := First_Component (T);
7522 while Present (C) loop
7523 if Is_Limited_Type (Etype (C))
7524 and then
7525 (Comes_From_Source (C)
7526 or else
7527 (Present (Original_Record_Component (C))
7528 and then
7529 Comes_From_Source (Original_Record_Component (C))))
7530 then
7531 Error_Msg_Node_2 := T;
7532 Error_Msg_NE ("\component& of type& has limited type", N, C);
7533 Explain_Limited_Type (Etype (C), N);
7534 return;
7535 end if;
7537 Next_Component (C);
7538 end loop;
7540 -- The type may be declared explicitly limited, even if no component
7541 -- of it is limited, in which case we fall out of the loop.
7542 return;
7543 end if;
7544 end Explain_Limited_Type;
7546 ---------------------------------------
7547 -- Expression_Of_Expression_Function --
7548 ---------------------------------------
7550 function Expression_Of_Expression_Function
7551 (Subp : Entity_Id) return Node_Id
7553 Expr_Func : Node_Id;
7555 begin
7556 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7558 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7559 N_Expression_Function
7560 then
7561 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7563 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7564 N_Expression_Function
7565 then
7566 Expr_Func := Original_Node (Subprogram_Body (Subp));
7568 else
7569 pragma Assert (False);
7570 null;
7571 end if;
7573 return Original_Node (Expression (Expr_Func));
7574 end Expression_Of_Expression_Function;
7576 -------------------------------
7577 -- Extensions_Visible_Status --
7578 -------------------------------
7580 function Extensions_Visible_Status
7581 (Id : Entity_Id) return Extensions_Visible_Mode
7583 Arg : Node_Id;
7584 Decl : Node_Id;
7585 Expr : Node_Id;
7586 Prag : Node_Id;
7587 Subp : Entity_Id;
7589 begin
7590 -- When a formal parameter is subject to Extensions_Visible, the pragma
7591 -- is stored in the contract of related subprogram.
7593 if Is_Formal (Id) then
7594 Subp := Scope (Id);
7596 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7597 Subp := Id;
7599 -- No other construct carries this pragma
7601 else
7602 return Extensions_Visible_None;
7603 end if;
7605 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7607 -- In certain cases analysis may request the Extensions_Visible status
7608 -- of an expression function before the pragma has been analyzed yet.
7609 -- Inspect the declarative items after the expression function looking
7610 -- for the pragma (if any).
7612 if No (Prag) and then Is_Expression_Function (Subp) then
7613 Decl := Next (Unit_Declaration_Node (Subp));
7614 while Present (Decl) loop
7615 if Nkind (Decl) = N_Pragma
7616 and then Pragma_Name (Decl) = Name_Extensions_Visible
7617 then
7618 Prag := Decl;
7619 exit;
7621 -- A source construct ends the region where Extensions_Visible may
7622 -- appear, stop the traversal. An expanded expression function is
7623 -- no longer a source construct, but it must still be recognized.
7625 elsif Comes_From_Source (Decl)
7626 or else
7627 (Nkind_In (Decl, N_Subprogram_Body,
7628 N_Subprogram_Declaration)
7629 and then Is_Expression_Function (Defining_Entity (Decl)))
7630 then
7631 exit;
7632 end if;
7634 Next (Decl);
7635 end loop;
7636 end if;
7638 -- Extract the value from the Boolean expression (if any)
7640 if Present (Prag) then
7641 Arg := First (Pragma_Argument_Associations (Prag));
7643 if Present (Arg) then
7644 Expr := Get_Pragma_Arg (Arg);
7646 -- When the associated subprogram is an expression function, the
7647 -- argument of the pragma may not have been analyzed.
7649 if not Analyzed (Expr) then
7650 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7651 end if;
7653 -- Guard against cascading errors when the argument of pragma
7654 -- Extensions_Visible is not a valid static Boolean expression.
7656 if Error_Posted (Expr) then
7657 return Extensions_Visible_None;
7659 elsif Is_True (Expr_Value (Expr)) then
7660 return Extensions_Visible_True;
7662 else
7663 return Extensions_Visible_False;
7664 end if;
7666 -- Otherwise the aspect or pragma defaults to True
7668 else
7669 return Extensions_Visible_True;
7670 end if;
7672 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7673 -- directly specified. In SPARK code, its value defaults to "False".
7675 elsif SPARK_Mode = On then
7676 return Extensions_Visible_False;
7678 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7679 -- "True".
7681 else
7682 return Extensions_Visible_True;
7683 end if;
7684 end Extensions_Visible_Status;
7686 -----------------
7687 -- Find_Actual --
7688 -----------------
7690 procedure Find_Actual
7691 (N : Node_Id;
7692 Formal : out Entity_Id;
7693 Call : out Node_Id)
7695 Context : constant Node_Id := Parent (N);
7696 Actual : Node_Id;
7697 Call_Nam : Node_Id;
7699 begin
7700 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7701 and then N = Prefix (Context)
7702 then
7703 Find_Actual (Context, Formal, Call);
7704 return;
7706 elsif Nkind (Context) = N_Parameter_Association
7707 and then N = Explicit_Actual_Parameter (Context)
7708 then
7709 Call := Parent (Context);
7711 elsif Nkind_In (Context, N_Entry_Call_Statement,
7712 N_Function_Call,
7713 N_Procedure_Call_Statement)
7714 then
7715 Call := Context;
7717 else
7718 Formal := Empty;
7719 Call := Empty;
7720 return;
7721 end if;
7723 -- If we have a call to a subprogram look for the parameter. Note that
7724 -- we exclude overloaded calls, since we don't know enough to be sure
7725 -- of giving the right answer in this case.
7727 if Nkind_In (Call, N_Entry_Call_Statement,
7728 N_Function_Call,
7729 N_Procedure_Call_Statement)
7730 then
7731 Call_Nam := Name (Call);
7733 -- A call to a protected or task entry appears as a selected
7734 -- component rather than an expanded name.
7736 if Nkind (Call_Nam) = N_Selected_Component then
7737 Call_Nam := Selector_Name (Call_Nam);
7738 end if;
7740 if Is_Entity_Name (Call_Nam)
7741 and then Present (Entity (Call_Nam))
7742 and then Is_Overloadable (Entity (Call_Nam))
7743 and then not Is_Overloaded (Call_Nam)
7744 then
7745 -- If node is name in call it is not an actual
7747 if N = Call_Nam then
7748 Formal := Empty;
7749 Call := Empty;
7750 return;
7751 end if;
7753 -- Fall here if we are definitely a parameter
7755 Actual := First_Actual (Call);
7756 Formal := First_Formal (Entity (Call_Nam));
7757 while Present (Formal) and then Present (Actual) loop
7758 if Actual = N then
7759 return;
7761 -- An actual that is the prefix in a prefixed call may have
7762 -- been rewritten in the call, after the deferred reference
7763 -- was collected. Check if sloc and kinds and names match.
7765 elsif Sloc (Actual) = Sloc (N)
7766 and then Nkind (Actual) = N_Identifier
7767 and then Nkind (Actual) = Nkind (N)
7768 and then Chars (Actual) = Chars (N)
7769 then
7770 return;
7772 else
7773 Actual := Next_Actual (Actual);
7774 Formal := Next_Formal (Formal);
7775 end if;
7776 end loop;
7777 end if;
7778 end if;
7780 -- Fall through here if we did not find matching actual
7782 Formal := Empty;
7783 Call := Empty;
7784 end Find_Actual;
7786 ---------------------------
7787 -- Find_Body_Discriminal --
7788 ---------------------------
7790 function Find_Body_Discriminal
7791 (Spec_Discriminant : Entity_Id) return Entity_Id
7793 Tsk : Entity_Id;
7794 Disc : Entity_Id;
7796 begin
7797 -- If expansion is suppressed, then the scope can be the concurrent type
7798 -- itself rather than a corresponding concurrent record type.
7800 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7801 Tsk := Scope (Spec_Discriminant);
7803 else
7804 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7806 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7807 end if;
7809 -- Find discriminant of original concurrent type, and use its current
7810 -- discriminal, which is the renaming within the task/protected body.
7812 Disc := First_Discriminant (Tsk);
7813 while Present (Disc) loop
7814 if Chars (Disc) = Chars (Spec_Discriminant) then
7815 return Discriminal (Disc);
7816 end if;
7818 Next_Discriminant (Disc);
7819 end loop;
7821 -- That loop should always succeed in finding a matching entry and
7822 -- returning. Fatal error if not.
7824 raise Program_Error;
7825 end Find_Body_Discriminal;
7827 -------------------------------------
7828 -- Find_Corresponding_Discriminant --
7829 -------------------------------------
7831 function Find_Corresponding_Discriminant
7832 (Id : Node_Id;
7833 Typ : Entity_Id) return Entity_Id
7835 Par_Disc : Entity_Id;
7836 Old_Disc : Entity_Id;
7837 New_Disc : Entity_Id;
7839 begin
7840 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7842 -- The original type may currently be private, and the discriminant
7843 -- only appear on its full view.
7845 if Is_Private_Type (Scope (Par_Disc))
7846 and then not Has_Discriminants (Scope (Par_Disc))
7847 and then Present (Full_View (Scope (Par_Disc)))
7848 then
7849 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7850 else
7851 Old_Disc := First_Discriminant (Scope (Par_Disc));
7852 end if;
7854 if Is_Class_Wide_Type (Typ) then
7855 New_Disc := First_Discriminant (Root_Type (Typ));
7856 else
7857 New_Disc := First_Discriminant (Typ);
7858 end if;
7860 while Present (Old_Disc) and then Present (New_Disc) loop
7861 if Old_Disc = Par_Disc then
7862 return New_Disc;
7863 end if;
7865 Next_Discriminant (Old_Disc);
7866 Next_Discriminant (New_Disc);
7867 end loop;
7869 -- Should always find it
7871 raise Program_Error;
7872 end Find_Corresponding_Discriminant;
7874 -------------------
7875 -- Find_DIC_Type --
7876 -------------------
7878 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
7879 Curr_Typ : Entity_Id;
7880 -- The current type being examined in the parent hierarchy traversal
7882 DIC_Typ : Entity_Id;
7883 -- The type which carries the DIC pragma. This variable denotes the
7884 -- partial view when private types are involved.
7886 Par_Typ : Entity_Id;
7887 -- The parent type of the current type. This variable denotes the full
7888 -- view when private types are involved.
7890 begin
7891 -- The input type defines its own DIC pragma, therefore it is the owner
7893 if Has_Own_DIC (Typ) then
7894 DIC_Typ := Typ;
7896 -- Otherwise the DIC pragma is inherited from a parent type
7898 else
7899 pragma Assert (Has_Inherited_DIC (Typ));
7901 -- Climb the parent chain
7903 Curr_Typ := Typ;
7904 loop
7905 -- Inspect the parent type. Do not consider subtypes as they
7906 -- inherit the DIC attributes from their base types.
7908 DIC_Typ := Base_Type (Etype (Curr_Typ));
7910 -- Look at the full view of a private type because the type may
7911 -- have a hidden parent introduced in the full view.
7913 Par_Typ := DIC_Typ;
7915 if Is_Private_Type (Par_Typ)
7916 and then Present (Full_View (Par_Typ))
7917 then
7918 Par_Typ := Full_View (Par_Typ);
7919 end if;
7921 -- Stop the climb once the nearest parent type which defines a DIC
7922 -- pragma of its own is encountered or when the root of the parent
7923 -- chain is reached.
7925 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
7927 Curr_Typ := Par_Typ;
7928 end loop;
7929 end if;
7931 return DIC_Typ;
7932 end Find_DIC_Type;
7934 ----------------------------------
7935 -- Find_Enclosing_Iterator_Loop --
7936 ----------------------------------
7938 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7939 Constr : Node_Id;
7940 S : Entity_Id;
7942 begin
7943 -- Traverse the scope chain looking for an iterator loop. Such loops are
7944 -- usually transformed into blocks, hence the use of Original_Node.
7946 S := Id;
7947 while Present (S) and then S /= Standard_Standard loop
7948 if Ekind (S) = E_Loop
7949 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7950 then
7951 Constr := Original_Node (Label_Construct (Parent (S)));
7953 if Nkind (Constr) = N_Loop_Statement
7954 and then Present (Iteration_Scheme (Constr))
7955 and then Nkind (Iterator_Specification
7956 (Iteration_Scheme (Constr))) =
7957 N_Iterator_Specification
7958 then
7959 return S;
7960 end if;
7961 end if;
7963 S := Scope (S);
7964 end loop;
7966 return Empty;
7967 end Find_Enclosing_Iterator_Loop;
7969 --------------------------
7970 -- Find_Enclosing_Scope --
7971 --------------------------
7973 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
7974 Par : Node_Id;
7976 begin
7977 -- Examine the parent chain looking for a construct which defines a
7978 -- scope.
7980 Par := Parent (N);
7981 while Present (Par) loop
7982 case Nkind (Par) is
7984 -- The construct denotes a declaration, the proper scope is its
7985 -- entity.
7987 when N_Entry_Declaration
7988 | N_Expression_Function
7989 | N_Full_Type_Declaration
7990 | N_Generic_Package_Declaration
7991 | N_Generic_Subprogram_Declaration
7992 | N_Package_Declaration
7993 | N_Private_Extension_Declaration
7994 | N_Protected_Type_Declaration
7995 | N_Single_Protected_Declaration
7996 | N_Single_Task_Declaration
7997 | N_Subprogram_Declaration
7998 | N_Task_Type_Declaration
8000 return Defining_Entity (Par);
8002 -- The construct denotes a body, the proper scope is the entity of
8003 -- the corresponding spec or that of the body if the body does not
8004 -- complete a previous declaration.
8006 when N_Entry_Body
8007 | N_Package_Body
8008 | N_Protected_Body
8009 | N_Subprogram_Body
8010 | N_Task_Body
8012 return Unique_Defining_Entity (Par);
8014 -- Special cases
8016 -- Blocks carry either a source or an internally-generated scope,
8017 -- unless the block is a byproduct of exception handling.
8019 when N_Block_Statement =>
8020 if not Exception_Junk (Par) then
8021 return Entity (Identifier (Par));
8022 end if;
8024 -- Loops carry an internally-generated scope
8026 when N_Loop_Statement =>
8027 return Entity (Identifier (Par));
8029 -- Extended return statements carry an internally-generated scope
8031 when N_Extended_Return_Statement =>
8032 return Return_Statement_Entity (Par);
8034 -- A traversal from a subunit continues via the corresponding stub
8036 when N_Subunit =>
8037 Par := Corresponding_Stub (Par);
8039 when others =>
8040 null;
8041 end case;
8043 Par := Parent (Par);
8044 end loop;
8046 return Standard_Standard;
8047 end Find_Enclosing_Scope;
8049 ------------------------------------
8050 -- Find_Loop_In_Conditional_Block --
8051 ------------------------------------
8053 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8054 Stmt : Node_Id;
8056 begin
8057 Stmt := N;
8059 if Nkind (Stmt) = N_If_Statement then
8060 Stmt := First (Then_Statements (Stmt));
8061 end if;
8063 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8065 -- Inspect the statements of the conditional block. In general the loop
8066 -- should be the first statement in the statement sequence of the block,
8067 -- but the finalization machinery may have introduced extra object
8068 -- declarations.
8070 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8071 while Present (Stmt) loop
8072 if Nkind (Stmt) = N_Loop_Statement then
8073 return Stmt;
8074 end if;
8076 Next (Stmt);
8077 end loop;
8079 -- The expansion of attribute 'Loop_Entry produced a malformed block
8081 raise Program_Error;
8082 end Find_Loop_In_Conditional_Block;
8084 --------------------------
8085 -- Find_Overlaid_Entity --
8086 --------------------------
8088 procedure Find_Overlaid_Entity
8089 (N : Node_Id;
8090 Ent : out Entity_Id;
8091 Off : out Boolean)
8093 Expr : Node_Id;
8095 begin
8096 -- We are looking for one of the two following forms:
8098 -- for X'Address use Y'Address
8100 -- or
8102 -- Const : constant Address := expr;
8103 -- ...
8104 -- for X'Address use Const;
8106 -- In the second case, the expr is either Y'Address, or recursively a
8107 -- constant that eventually references Y'Address.
8109 Ent := Empty;
8110 Off := False;
8112 if Nkind (N) = N_Attribute_Definition_Clause
8113 and then Chars (N) = Name_Address
8114 then
8115 Expr := Expression (N);
8117 -- This loop checks the form of the expression for Y'Address,
8118 -- using recursion to deal with intermediate constants.
8120 loop
8121 -- Check for Y'Address
8123 if Nkind (Expr) = N_Attribute_Reference
8124 and then Attribute_Name (Expr) = Name_Address
8125 then
8126 Expr := Prefix (Expr);
8127 exit;
8129 -- Check for Const where Const is a constant entity
8131 elsif Is_Entity_Name (Expr)
8132 and then Ekind (Entity (Expr)) = E_Constant
8133 then
8134 Expr := Constant_Value (Entity (Expr));
8136 -- Anything else does not need checking
8138 else
8139 return;
8140 end if;
8141 end loop;
8143 -- This loop checks the form of the prefix for an entity, using
8144 -- recursion to deal with intermediate components.
8146 loop
8147 -- Check for Y where Y is an entity
8149 if Is_Entity_Name (Expr) then
8150 Ent := Entity (Expr);
8151 return;
8153 -- Check for components
8155 elsif
8156 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8157 then
8158 Expr := Prefix (Expr);
8159 Off := True;
8161 -- Anything else does not need checking
8163 else
8164 return;
8165 end if;
8166 end loop;
8167 end if;
8168 end Find_Overlaid_Entity;
8170 -------------------------
8171 -- Find_Parameter_Type --
8172 -------------------------
8174 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8175 begin
8176 if Nkind (Param) /= N_Parameter_Specification then
8177 return Empty;
8179 -- For an access parameter, obtain the type from the formal entity
8180 -- itself, because access to subprogram nodes do not carry a type.
8181 -- Shouldn't we always use the formal entity ???
8183 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8184 return Etype (Defining_Identifier (Param));
8186 else
8187 return Etype (Parameter_Type (Param));
8188 end if;
8189 end Find_Parameter_Type;
8191 -----------------------------------
8192 -- Find_Placement_In_State_Space --
8193 -----------------------------------
8195 procedure Find_Placement_In_State_Space
8196 (Item_Id : Entity_Id;
8197 Placement : out State_Space_Kind;
8198 Pack_Id : out Entity_Id)
8200 Context : Entity_Id;
8202 begin
8203 -- Assume that the item does not appear in the state space of a package
8205 Placement := Not_In_Package;
8206 Pack_Id := Empty;
8208 -- Climb the scope stack and examine the enclosing context
8210 Context := Scope (Item_Id);
8211 while Present (Context) and then Context /= Standard_Standard loop
8212 if Is_Package_Or_Generic_Package (Context) then
8213 Pack_Id := Context;
8215 -- A package body is a cut off point for the traversal as the item
8216 -- cannot be visible to the outside from this point on. Note that
8217 -- this test must be done first as a body is also classified as a
8218 -- private part.
8220 if In_Package_Body (Context) then
8221 Placement := Body_State_Space;
8222 return;
8224 -- The private part of a package is a cut off point for the
8225 -- traversal as the item cannot be visible to the outside from
8226 -- this point on.
8228 elsif In_Private_Part (Context) then
8229 Placement := Private_State_Space;
8230 return;
8232 -- When the item appears in the visible state space of a package,
8233 -- continue to climb the scope stack as this may not be the final
8234 -- state space.
8236 else
8237 Placement := Visible_State_Space;
8239 -- The visible state space of a child unit acts as the proper
8240 -- placement of an item.
8242 if Is_Child_Unit (Context) then
8243 return;
8244 end if;
8245 end if;
8247 -- The item or its enclosing package appear in a construct that has
8248 -- no state space.
8250 else
8251 Placement := Not_In_Package;
8252 return;
8253 end if;
8255 Context := Scope (Context);
8256 end loop;
8257 end Find_Placement_In_State_Space;
8259 ------------------------
8260 -- Find_Specific_Type --
8261 ------------------------
8263 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8264 Typ : Entity_Id := Root_Type (CW);
8266 begin
8267 if Ekind (Typ) = E_Incomplete_Type then
8268 if From_Limited_With (Typ) then
8269 Typ := Non_Limited_View (Typ);
8270 else
8271 Typ := Full_View (Typ);
8272 end if;
8273 end if;
8275 if Is_Private_Type (Typ)
8276 and then not Is_Tagged_Type (Typ)
8277 and then Present (Full_View (Typ))
8278 then
8279 return Full_View (Typ);
8280 else
8281 return Typ;
8282 end if;
8283 end Find_Specific_Type;
8285 -----------------------------
8286 -- Find_Static_Alternative --
8287 -----------------------------
8289 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8290 Expr : constant Node_Id := Expression (N);
8291 Val : constant Uint := Expr_Value (Expr);
8292 Alt : Node_Id;
8293 Choice : Node_Id;
8295 begin
8296 Alt := First (Alternatives (N));
8298 Search : loop
8299 if Nkind (Alt) /= N_Pragma then
8300 Choice := First (Discrete_Choices (Alt));
8301 while Present (Choice) loop
8303 -- Others choice, always matches
8305 if Nkind (Choice) = N_Others_Choice then
8306 exit Search;
8308 -- Range, check if value is in the range
8310 elsif Nkind (Choice) = N_Range then
8311 exit Search when
8312 Val >= Expr_Value (Low_Bound (Choice))
8313 and then
8314 Val <= Expr_Value (High_Bound (Choice));
8316 -- Choice is a subtype name. Note that we know it must
8317 -- be a static subtype, since otherwise it would have
8318 -- been diagnosed as illegal.
8320 elsif Is_Entity_Name (Choice)
8321 and then Is_Type (Entity (Choice))
8322 then
8323 exit Search when Is_In_Range (Expr, Etype (Choice),
8324 Assume_Valid => False);
8326 -- Choice is a subtype indication
8328 elsif Nkind (Choice) = N_Subtype_Indication then
8329 declare
8330 C : constant Node_Id := Constraint (Choice);
8331 R : constant Node_Id := Range_Expression (C);
8333 begin
8334 exit Search when
8335 Val >= Expr_Value (Low_Bound (R))
8336 and then
8337 Val <= Expr_Value (High_Bound (R));
8338 end;
8340 -- Choice is a simple expression
8342 else
8343 exit Search when Val = Expr_Value (Choice);
8344 end if;
8346 Next (Choice);
8347 end loop;
8348 end if;
8350 Next (Alt);
8351 pragma Assert (Present (Alt));
8352 end loop Search;
8354 -- The above loop *must* terminate by finding a match, since we know the
8355 -- case statement is valid, and the value of the expression is known at
8356 -- compile time. When we fall out of the loop, Alt points to the
8357 -- alternative that we know will be selected at run time.
8359 return Alt;
8360 end Find_Static_Alternative;
8362 ------------------
8363 -- First_Actual --
8364 ------------------
8366 function First_Actual (Node : Node_Id) return Node_Id is
8367 N : Node_Id;
8369 begin
8370 if No (Parameter_Associations (Node)) then
8371 return Empty;
8372 end if;
8374 N := First (Parameter_Associations (Node));
8376 if Nkind (N) = N_Parameter_Association then
8377 return First_Named_Actual (Node);
8378 else
8379 return N;
8380 end if;
8381 end First_Actual;
8383 ------------------
8384 -- First_Global --
8385 ------------------
8387 function First_Global
8388 (Subp : Entity_Id;
8389 Global_Mode : Name_Id;
8390 Refined : Boolean := False) return Node_Id
8392 function First_From_Global_List
8393 (List : Node_Id;
8394 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8395 -- Get the first item with suitable mode from List
8397 ----------------------------
8398 -- First_From_Global_List --
8399 ----------------------------
8401 function First_From_Global_List
8402 (List : Node_Id;
8403 Global_Mode : Name_Id := Name_Input) return Entity_Id
8405 Assoc : Node_Id;
8407 begin
8408 -- Empty list (no global items)
8410 if Nkind (List) = N_Null then
8411 return Empty;
8413 -- Single global item declaration (only input items)
8415 elsif Nkind_In (List, N_Expanded_Name,
8416 N_Identifier,
8417 N_Selected_Component)
8418 then
8419 if Global_Mode = Name_Input then
8420 return List;
8421 else
8422 return Empty;
8423 end if;
8425 -- Simple global list (only input items) or moded global list
8426 -- declaration.
8428 elsif Nkind (List) = N_Aggregate then
8429 if Present (Expressions (List)) then
8430 if Global_Mode = Name_Input then
8431 return First (Expressions (List));
8432 else
8433 return Empty;
8434 end if;
8436 else
8437 Assoc := First (Component_Associations (List));
8438 while Present (Assoc) loop
8440 -- When we find the desired mode in an association, call
8441 -- recursively First_From_Global_List as if the mode was
8442 -- Name_Input, in order to reuse the existing machinery
8443 -- for the other cases.
8445 if Chars (First (Choices (Assoc))) = Global_Mode then
8446 return First_From_Global_List (Expression (Assoc));
8447 end if;
8449 Next (Assoc);
8450 end loop;
8452 return Empty;
8453 end if;
8455 -- To accommodate partial decoration of disabled SPARK features,
8456 -- this routine may be called with illegal input. If this is the
8457 -- case, do not raise Program_Error.
8459 else
8460 return Empty;
8461 end if;
8462 end First_From_Global_List;
8464 -- Local variables
8466 Global : Node_Id := Empty;
8467 Body_Id : Entity_Id;
8469 begin
8470 pragma Assert (Global_Mode = Name_Input
8471 or else Global_Mode = Name_Output
8472 or else Global_Mode = Name_In_Out
8473 or else Global_Mode = Name_Proof_In);
8475 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8476 -- case, it can only be located on the body entity.
8478 if Refined then
8479 Body_Id := Subprogram_Body_Entity (Subp);
8480 if Present (Body_Id) then
8481 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8482 end if;
8483 else
8484 Global := Get_Pragma (Subp, Pragma_Global);
8485 end if;
8487 -- No corresponding global if pragma is not present
8489 if No (Global) then
8490 return Empty;
8492 -- Otherwise retrieve the corresponding list of items depending on the
8493 -- Global_Mode.
8495 else
8496 return First_From_Global_List
8497 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8498 end if;
8499 end First_Global;
8501 -------------
8502 -- Fix_Msg --
8503 -------------
8505 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8506 Is_Task : constant Boolean :=
8507 Ekind_In (Id, E_Task_Body, E_Task_Type)
8508 or else Is_Single_Task_Object (Id);
8509 Msg_Last : constant Natural := Msg'Last;
8510 Msg_Index : Natural;
8511 Res : String (Msg'Range) := (others => ' ');
8512 Res_Index : Natural;
8514 begin
8515 -- Copy all characters from the input message Msg to result Res with
8516 -- suitable replacements.
8518 Msg_Index := Msg'First;
8519 Res_Index := Res'First;
8520 while Msg_Index <= Msg_Last loop
8522 -- Replace "subprogram" with a different word
8524 if Msg_Index <= Msg_Last - 10
8525 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8526 then
8527 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8528 Res (Res_Index .. Res_Index + 4) := "entry";
8529 Res_Index := Res_Index + 5;
8531 elsif Is_Task then
8532 Res (Res_Index .. Res_Index + 8) := "task type";
8533 Res_Index := Res_Index + 9;
8535 else
8536 Res (Res_Index .. Res_Index + 9) := "subprogram";
8537 Res_Index := Res_Index + 10;
8538 end if;
8540 Msg_Index := Msg_Index + 10;
8542 -- Replace "protected" with a different word
8544 elsif Msg_Index <= Msg_Last - 9
8545 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8546 and then Is_Task
8547 then
8548 Res (Res_Index .. Res_Index + 3) := "task";
8549 Res_Index := Res_Index + 4;
8550 Msg_Index := Msg_Index + 9;
8552 -- Otherwise copy the character
8554 else
8555 Res (Res_Index) := Msg (Msg_Index);
8556 Msg_Index := Msg_Index + 1;
8557 Res_Index := Res_Index + 1;
8558 end if;
8559 end loop;
8561 return Res (Res'First .. Res_Index - 1);
8562 end Fix_Msg;
8564 -------------------------
8565 -- From_Nested_Package --
8566 -------------------------
8568 function From_Nested_Package (T : Entity_Id) return Boolean is
8569 Pack : constant Entity_Id := Scope (T);
8571 begin
8572 return
8573 Ekind (Pack) = E_Package
8574 and then not Is_Frozen (Pack)
8575 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8576 and then In_Open_Scopes (Scope (Pack));
8577 end From_Nested_Package;
8579 -----------------------
8580 -- Gather_Components --
8581 -----------------------
8583 procedure Gather_Components
8584 (Typ : Entity_Id;
8585 Comp_List : Node_Id;
8586 Governed_By : List_Id;
8587 Into : Elist_Id;
8588 Report_Errors : out Boolean)
8590 Assoc : Node_Id;
8591 Variant : Node_Id;
8592 Discrete_Choice : Node_Id;
8593 Comp_Item : Node_Id;
8595 Discrim : Entity_Id;
8596 Discrim_Name : Node_Id;
8597 Discrim_Value : Node_Id;
8599 begin
8600 Report_Errors := False;
8602 if No (Comp_List) or else Null_Present (Comp_List) then
8603 return;
8605 elsif Present (Component_Items (Comp_List)) then
8606 Comp_Item := First (Component_Items (Comp_List));
8608 else
8609 Comp_Item := Empty;
8610 end if;
8612 while Present (Comp_Item) loop
8614 -- Skip the tag of a tagged record, the interface tags, as well
8615 -- as all items that are not user components (anonymous types,
8616 -- rep clauses, Parent field, controller field).
8618 if Nkind (Comp_Item) = N_Component_Declaration then
8619 declare
8620 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8621 begin
8622 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8623 Append_Elmt (Comp, Into);
8624 end if;
8625 end;
8626 end if;
8628 Next (Comp_Item);
8629 end loop;
8631 if No (Variant_Part (Comp_List)) then
8632 return;
8633 else
8634 Discrim_Name := Name (Variant_Part (Comp_List));
8635 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8636 end if;
8638 -- Look for the discriminant that governs this variant part.
8639 -- The discriminant *must* be in the Governed_By List
8641 Assoc := First (Governed_By);
8642 Find_Constraint : loop
8643 Discrim := First (Choices (Assoc));
8644 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
8645 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
8646 and then
8647 Chars (Corresponding_Discriminant (Entity (Discrim))) =
8648 Chars (Discrim_Name))
8649 or else Chars (Original_Record_Component (Entity (Discrim)))
8650 = Chars (Discrim_Name);
8652 if No (Next (Assoc)) then
8653 if not Is_Constrained (Typ)
8654 and then Is_Derived_Type (Typ)
8655 and then Present (Stored_Constraint (Typ))
8656 then
8657 -- If the type is a tagged type with inherited discriminants,
8658 -- use the stored constraint on the parent in order to find
8659 -- the values of discriminants that are otherwise hidden by an
8660 -- explicit constraint. Renamed discriminants are handled in
8661 -- the code above.
8663 -- If several parent discriminants are renamed by a single
8664 -- discriminant of the derived type, the call to obtain the
8665 -- Corresponding_Discriminant field only retrieves the last
8666 -- of them. We recover the constraint on the others from the
8667 -- Stored_Constraint as well.
8669 declare
8670 D : Entity_Id;
8671 C : Elmt_Id;
8673 begin
8674 D := First_Discriminant (Etype (Typ));
8675 C := First_Elmt (Stored_Constraint (Typ));
8676 while Present (D) and then Present (C) loop
8677 if Chars (Discrim_Name) = Chars (D) then
8678 if Is_Entity_Name (Node (C))
8679 and then Entity (Node (C)) = Entity (Discrim)
8680 then
8681 -- D is renamed by Discrim, whose value is given in
8682 -- Assoc.
8684 null;
8686 else
8687 Assoc :=
8688 Make_Component_Association (Sloc (Typ),
8689 New_List
8690 (New_Occurrence_Of (D, Sloc (Typ))),
8691 Duplicate_Subexpr_No_Checks (Node (C)));
8692 end if;
8693 exit Find_Constraint;
8694 end if;
8696 Next_Discriminant (D);
8697 Next_Elmt (C);
8698 end loop;
8699 end;
8700 end if;
8701 end if;
8703 if No (Next (Assoc)) then
8704 Error_Msg_NE (" missing value for discriminant&",
8705 First (Governed_By), Discrim_Name);
8706 Report_Errors := True;
8707 return;
8708 end if;
8710 Next (Assoc);
8711 end loop Find_Constraint;
8713 Discrim_Value := Expression (Assoc);
8715 if not Is_OK_Static_Expression (Discrim_Value) then
8717 -- If the variant part is governed by a discriminant of the type
8718 -- this is an error. If the variant part and the discriminant are
8719 -- inherited from an ancestor this is legal (AI05-120) unless the
8720 -- components are being gathered for an aggregate, in which case
8721 -- the caller must check Report_Errors.
8723 if Scope (Original_Record_Component
8724 ((Entity (First (Choices (Assoc)))))) = Typ
8725 then
8726 Error_Msg_FE
8727 ("value for discriminant & must be static!",
8728 Discrim_Value, Discrim);
8729 Why_Not_Static (Discrim_Value);
8730 end if;
8732 Report_Errors := True;
8733 return;
8734 end if;
8736 Search_For_Discriminant_Value : declare
8737 Low : Node_Id;
8738 High : Node_Id;
8740 UI_High : Uint;
8741 UI_Low : Uint;
8742 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8744 begin
8745 Find_Discrete_Value : while Present (Variant) loop
8746 Discrete_Choice := First (Discrete_Choices (Variant));
8747 while Present (Discrete_Choice) loop
8748 exit Find_Discrete_Value when
8749 Nkind (Discrete_Choice) = N_Others_Choice;
8751 Get_Index_Bounds (Discrete_Choice, Low, High);
8753 UI_Low := Expr_Value (Low);
8754 UI_High := Expr_Value (High);
8756 exit Find_Discrete_Value when
8757 UI_Low <= UI_Discrim_Value
8758 and then
8759 UI_High >= UI_Discrim_Value;
8761 Next (Discrete_Choice);
8762 end loop;
8764 Next_Non_Pragma (Variant);
8765 end loop Find_Discrete_Value;
8766 end Search_For_Discriminant_Value;
8768 -- The case statement must include a variant that corresponds to the
8769 -- value of the discriminant, unless the discriminant type has a
8770 -- static predicate. In that case the absence of an others_choice that
8771 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8773 if No (Variant)
8774 and then not Has_Static_Predicate (Etype (Discrim_Name))
8775 then
8776 Error_Msg_NE
8777 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8778 Report_Errors := True;
8779 return;
8780 end if;
8782 -- If we have found the corresponding choice, recursively add its
8783 -- components to the Into list. The nested components are part of
8784 -- the same record type.
8786 if Present (Variant) then
8787 Gather_Components
8788 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8789 end if;
8790 end Gather_Components;
8792 ------------------------
8793 -- Get_Actual_Subtype --
8794 ------------------------
8796 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8797 Typ : constant Entity_Id := Etype (N);
8798 Utyp : Entity_Id := Underlying_Type (Typ);
8799 Decl : Node_Id;
8800 Atyp : Entity_Id;
8802 begin
8803 if No (Utyp) then
8804 Utyp := Typ;
8805 end if;
8807 -- If what we have is an identifier that references a subprogram
8808 -- formal, or a variable or constant object, then we get the actual
8809 -- subtype from the referenced entity if one has been built.
8811 if Nkind (N) = N_Identifier
8812 and then
8813 (Is_Formal (Entity (N))
8814 or else Ekind (Entity (N)) = E_Constant
8815 or else Ekind (Entity (N)) = E_Variable)
8816 and then Present (Actual_Subtype (Entity (N)))
8817 then
8818 return Actual_Subtype (Entity (N));
8820 -- Actual subtype of unchecked union is always itself. We never need
8821 -- the "real" actual subtype. If we did, we couldn't get it anyway
8822 -- because the discriminant is not available. The restrictions on
8823 -- Unchecked_Union are designed to make sure that this is OK.
8825 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
8826 return Typ;
8828 -- Here for the unconstrained case, we must find actual subtype
8829 -- No actual subtype is available, so we must build it on the fly.
8831 -- Checking the type, not the underlying type, for constrainedness
8832 -- seems to be necessary. Maybe all the tests should be on the type???
8834 elsif (not Is_Constrained (Typ))
8835 and then (Is_Array_Type (Utyp)
8836 or else (Is_Record_Type (Utyp)
8837 and then Has_Discriminants (Utyp)))
8838 and then not Has_Unknown_Discriminants (Utyp)
8839 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
8840 then
8841 -- Nothing to do if in spec expression (why not???)
8843 if In_Spec_Expression then
8844 return Typ;
8846 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
8848 -- If the type has no discriminants, there is no subtype to
8849 -- build, even if the underlying type is discriminated.
8851 return Typ;
8853 -- Else build the actual subtype
8855 else
8856 Decl := Build_Actual_Subtype (Typ, N);
8857 Atyp := Defining_Identifier (Decl);
8859 -- If Build_Actual_Subtype generated a new declaration then use it
8861 if Atyp /= Typ then
8863 -- The actual subtype is an Itype, so analyze the declaration,
8864 -- but do not attach it to the tree, to get the type defined.
8866 Set_Parent (Decl, N);
8867 Set_Is_Itype (Atyp);
8868 Analyze (Decl, Suppress => All_Checks);
8869 Set_Associated_Node_For_Itype (Atyp, N);
8870 Set_Has_Delayed_Freeze (Atyp, False);
8872 -- We need to freeze the actual subtype immediately. This is
8873 -- needed, because otherwise this Itype will not get frozen
8874 -- at all, and it is always safe to freeze on creation because
8875 -- any associated types must be frozen at this point.
8877 Freeze_Itype (Atyp, N);
8878 return Atyp;
8880 -- Otherwise we did not build a declaration, so return original
8882 else
8883 return Typ;
8884 end if;
8885 end if;
8887 -- For all remaining cases, the actual subtype is the same as
8888 -- the nominal type.
8890 else
8891 return Typ;
8892 end if;
8893 end Get_Actual_Subtype;
8895 -------------------------------------
8896 -- Get_Actual_Subtype_If_Available --
8897 -------------------------------------
8899 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
8900 Typ : constant Entity_Id := Etype (N);
8902 begin
8903 -- If what we have is an identifier that references a subprogram
8904 -- formal, or a variable or constant object, then we get the actual
8905 -- subtype from the referenced entity if one has been built.
8907 if Nkind (N) = N_Identifier
8908 and then
8909 (Is_Formal (Entity (N))
8910 or else Ekind (Entity (N)) = E_Constant
8911 or else Ekind (Entity (N)) = E_Variable)
8912 and then Present (Actual_Subtype (Entity (N)))
8913 then
8914 return Actual_Subtype (Entity (N));
8916 -- Otherwise the Etype of N is returned unchanged
8918 else
8919 return Typ;
8920 end if;
8921 end Get_Actual_Subtype_If_Available;
8923 ------------------------
8924 -- Get_Body_From_Stub --
8925 ------------------------
8927 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
8928 begin
8929 return Proper_Body (Unit (Library_Unit (N)));
8930 end Get_Body_From_Stub;
8932 ---------------------
8933 -- Get_Cursor_Type --
8934 ---------------------
8936 function Get_Cursor_Type
8937 (Aspect : Node_Id;
8938 Typ : Entity_Id) return Entity_Id
8940 Assoc : Node_Id;
8941 Func : Entity_Id;
8942 First_Op : Entity_Id;
8943 Cursor : Entity_Id;
8945 begin
8946 -- If error already detected, return
8948 if Error_Posted (Aspect) then
8949 return Any_Type;
8950 end if;
8952 -- The cursor type for an Iterable aspect is the return type of a
8953 -- non-overloaded First primitive operation. Locate association for
8954 -- First.
8956 Assoc := First (Component_Associations (Expression (Aspect)));
8957 First_Op := Any_Id;
8958 while Present (Assoc) loop
8959 if Chars (First (Choices (Assoc))) = Name_First then
8960 First_Op := Expression (Assoc);
8961 exit;
8962 end if;
8964 Next (Assoc);
8965 end loop;
8967 if First_Op = Any_Id then
8968 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
8969 return Any_Type;
8970 end if;
8972 Cursor := Any_Type;
8974 -- Locate function with desired name and profile in scope of type
8975 -- In the rare case where the type is an integer type, a base type
8976 -- is created for it, check that the base type of the first formal
8977 -- of First matches the base type of the domain.
8979 Func := First_Entity (Scope (Typ));
8980 while Present (Func) loop
8981 if Chars (Func) = Chars (First_Op)
8982 and then Ekind (Func) = E_Function
8983 and then Present (First_Formal (Func))
8984 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
8985 and then No (Next_Formal (First_Formal (Func)))
8986 then
8987 if Cursor /= Any_Type then
8988 Error_Msg_N
8989 ("Operation First for iterable type must be unique", Aspect);
8990 return Any_Type;
8991 else
8992 Cursor := Etype (Func);
8993 end if;
8994 end if;
8996 Next_Entity (Func);
8997 end loop;
8999 -- If not found, no way to resolve remaining primitives.
9001 if Cursor = Any_Type then
9002 Error_Msg_N
9003 ("No legal primitive operation First for Iterable type", Aspect);
9004 end if;
9006 return Cursor;
9007 end Get_Cursor_Type;
9009 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9010 begin
9011 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9012 end Get_Cursor_Type;
9014 -------------------------------
9015 -- Get_Default_External_Name --
9016 -------------------------------
9018 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9019 begin
9020 Get_Decoded_Name_String (Chars (E));
9022 if Opt.External_Name_Imp_Casing = Uppercase then
9023 Set_Casing (All_Upper_Case);
9024 else
9025 Set_Casing (All_Lower_Case);
9026 end if;
9028 return
9029 Make_String_Literal (Sloc (E),
9030 Strval => String_From_Name_Buffer);
9031 end Get_Default_External_Name;
9033 --------------------------
9034 -- Get_Enclosing_Object --
9035 --------------------------
9037 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9038 begin
9039 if Is_Entity_Name (N) then
9040 return Entity (N);
9041 else
9042 case Nkind (N) is
9043 when N_Indexed_Component
9044 | N_Selected_Component
9045 | N_Slice
9047 -- If not generating code, a dereference may be left implicit.
9048 -- In thoses cases, return Empty.
9050 if Is_Access_Type (Etype (Prefix (N))) then
9051 return Empty;
9052 else
9053 return Get_Enclosing_Object (Prefix (N));
9054 end if;
9056 when N_Type_Conversion =>
9057 return Get_Enclosing_Object (Expression (N));
9059 when others =>
9060 return Empty;
9061 end case;
9062 end if;
9063 end Get_Enclosing_Object;
9065 ---------------------------
9066 -- Get_Enum_Lit_From_Pos --
9067 ---------------------------
9069 function Get_Enum_Lit_From_Pos
9070 (T : Entity_Id;
9071 Pos : Uint;
9072 Loc : Source_Ptr) return Node_Id
9074 Btyp : Entity_Id := Base_Type (T);
9075 Lit : Node_Id;
9076 LLoc : Source_Ptr;
9078 begin
9079 -- In the case where the literal is of type Character, Wide_Character
9080 -- or Wide_Wide_Character or of a type derived from them, there needs
9081 -- to be some special handling since there is no explicit chain of
9082 -- literals to search. Instead, an N_Character_Literal node is created
9083 -- with the appropriate Char_Code and Chars fields.
9085 if Is_Standard_Character_Type (T) then
9086 Set_Character_Literal_Name (UI_To_CC (Pos));
9088 return
9089 Make_Character_Literal (Loc,
9090 Chars => Name_Find,
9091 Char_Literal_Value => Pos);
9093 -- For all other cases, we have a complete table of literals, and
9094 -- we simply iterate through the chain of literal until the one
9095 -- with the desired position value is found.
9097 else
9098 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9099 Btyp := Full_View (Btyp);
9100 end if;
9102 Lit := First_Literal (Btyp);
9104 -- Position in the enumeration type starts at 0
9106 if UI_To_Int (Pos) < 0 then
9107 raise Constraint_Error;
9108 end if;
9110 for J in 1 .. UI_To_Int (Pos) loop
9111 Next_Literal (Lit);
9113 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9114 -- inside the loop to avoid calling Next_Literal on Empty.
9116 if No (Lit) then
9117 raise Constraint_Error;
9118 end if;
9119 end loop;
9121 -- Create a new node from Lit, with source location provided by Loc
9122 -- if not equal to No_Location, or by copying the source location of
9123 -- Lit otherwise.
9125 LLoc := Loc;
9127 if LLoc = No_Location then
9128 LLoc := Sloc (Lit);
9129 end if;
9131 return New_Occurrence_Of (Lit, LLoc);
9132 end if;
9133 end Get_Enum_Lit_From_Pos;
9135 ------------------------
9136 -- Get_Generic_Entity --
9137 ------------------------
9139 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9140 Ent : constant Entity_Id := Entity (Name (N));
9141 begin
9142 if Present (Renamed_Object (Ent)) then
9143 return Renamed_Object (Ent);
9144 else
9145 return Ent;
9146 end if;
9147 end Get_Generic_Entity;
9149 -------------------------------------
9150 -- Get_Incomplete_View_Of_Ancestor --
9151 -------------------------------------
9153 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9154 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9155 Par_Scope : Entity_Id;
9156 Par_Type : Entity_Id;
9158 begin
9159 -- The incomplete view of an ancestor is only relevant for private
9160 -- derived types in child units.
9162 if not Is_Derived_Type (E)
9163 or else not Is_Child_Unit (Cur_Unit)
9164 then
9165 return Empty;
9167 else
9168 Par_Scope := Scope (Cur_Unit);
9169 if No (Par_Scope) then
9170 return Empty;
9171 end if;
9173 Par_Type := Etype (Base_Type (E));
9175 -- Traverse list of ancestor types until we find one declared in
9176 -- a parent or grandparent unit (two levels seem sufficient).
9178 while Present (Par_Type) loop
9179 if Scope (Par_Type) = Par_Scope
9180 or else Scope (Par_Type) = Scope (Par_Scope)
9181 then
9182 return Par_Type;
9184 elsif not Is_Derived_Type (Par_Type) then
9185 return Empty;
9187 else
9188 Par_Type := Etype (Base_Type (Par_Type));
9189 end if;
9190 end loop;
9192 -- If none found, there is no relevant ancestor type.
9194 return Empty;
9195 end if;
9196 end Get_Incomplete_View_Of_Ancestor;
9198 ----------------------
9199 -- Get_Index_Bounds --
9200 ----------------------
9202 procedure Get_Index_Bounds
9203 (N : Node_Id;
9204 L : out Node_Id;
9205 H : out Node_Id;
9206 Use_Full_View : Boolean := False)
9208 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9209 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9210 -- Typ qualifies, the scalar range is obtained from the full view of the
9211 -- type.
9213 --------------------------
9214 -- Scalar_Range_Of_Type --
9215 --------------------------
9217 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9218 T : Entity_Id := Typ;
9220 begin
9221 if Use_Full_View and then Present (Full_View (T)) then
9222 T := Full_View (T);
9223 end if;
9225 return Scalar_Range (T);
9226 end Scalar_Range_Of_Type;
9228 -- Local variables
9230 Kind : constant Node_Kind := Nkind (N);
9231 Rng : Node_Id;
9233 -- Start of processing for Get_Index_Bounds
9235 begin
9236 if Kind = N_Range then
9237 L := Low_Bound (N);
9238 H := High_Bound (N);
9240 elsif Kind = N_Subtype_Indication then
9241 Rng := Range_Expression (Constraint (N));
9243 if Rng = Error then
9244 L := Error;
9245 H := Error;
9246 return;
9248 else
9249 L := Low_Bound (Range_Expression (Constraint (N)));
9250 H := High_Bound (Range_Expression (Constraint (N)));
9251 end if;
9253 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9254 Rng := Scalar_Range_Of_Type (Entity (N));
9256 if Error_Posted (Rng) then
9257 L := Error;
9258 H := Error;
9260 elsif Nkind (Rng) = N_Subtype_Indication then
9261 Get_Index_Bounds (Rng, L, H);
9263 else
9264 L := Low_Bound (Rng);
9265 H := High_Bound (Rng);
9266 end if;
9268 else
9269 -- N is an expression, indicating a range with one value
9271 L := N;
9272 H := N;
9273 end if;
9274 end Get_Index_Bounds;
9276 -----------------------------
9277 -- Get_Interfacing_Aspects --
9278 -----------------------------
9280 procedure Get_Interfacing_Aspects
9281 (Iface_Asp : Node_Id;
9282 Conv_Asp : out Node_Id;
9283 EN_Asp : out Node_Id;
9284 Expo_Asp : out Node_Id;
9285 Imp_Asp : out Node_Id;
9286 LN_Asp : out Node_Id;
9287 Do_Checks : Boolean := False)
9289 procedure Save_Or_Duplication_Error
9290 (Asp : Node_Id;
9291 To : in out Node_Id);
9292 -- Save the value of aspect Asp in node To. If To already has a value,
9293 -- then this is considered a duplicate use of aspect. Emit an error if
9294 -- flag Do_Checks is set.
9296 -------------------------------
9297 -- Save_Or_Duplication_Error --
9298 -------------------------------
9300 procedure Save_Or_Duplication_Error
9301 (Asp : Node_Id;
9302 To : in out Node_Id)
9304 begin
9305 -- Detect an extra aspect and issue an error
9307 if Present (To) then
9308 if Do_Checks then
9309 Error_Msg_Name_1 := Chars (Identifier (Asp));
9310 Error_Msg_Sloc := Sloc (To);
9311 Error_Msg_N ("aspect % previously given #", Asp);
9312 end if;
9314 -- Otherwise capture the aspect
9316 else
9317 To := Asp;
9318 end if;
9319 end Save_Or_Duplication_Error;
9321 -- Local variables
9323 Asp : Node_Id;
9324 Asp_Id : Aspect_Id;
9326 -- The following variables capture each individual aspect
9328 Conv : Node_Id := Empty;
9329 EN : Node_Id := Empty;
9330 Expo : Node_Id := Empty;
9331 Imp : Node_Id := Empty;
9332 LN : Node_Id := Empty;
9334 -- Start of processing for Get_Interfacing_Aspects
9336 begin
9337 -- The input interfacing aspect should reside in an aspect specification
9338 -- list.
9340 pragma Assert (Is_List_Member (Iface_Asp));
9342 -- Examine the aspect specifications of the related entity. Find and
9343 -- capture all interfacing aspects. Detect duplicates and emit errors
9344 -- if applicable.
9346 Asp := First (List_Containing (Iface_Asp));
9347 while Present (Asp) loop
9348 Asp_Id := Get_Aspect_Id (Asp);
9350 if Asp_Id = Aspect_Convention then
9351 Save_Or_Duplication_Error (Asp, Conv);
9353 elsif Asp_Id = Aspect_External_Name then
9354 Save_Or_Duplication_Error (Asp, EN);
9356 elsif Asp_Id = Aspect_Export then
9357 Save_Or_Duplication_Error (Asp, Expo);
9359 elsif Asp_Id = Aspect_Import then
9360 Save_Or_Duplication_Error (Asp, Imp);
9362 elsif Asp_Id = Aspect_Link_Name then
9363 Save_Or_Duplication_Error (Asp, LN);
9364 end if;
9366 Next (Asp);
9367 end loop;
9369 Conv_Asp := Conv;
9370 EN_Asp := EN;
9371 Expo_Asp := Expo;
9372 Imp_Asp := Imp;
9373 LN_Asp := LN;
9374 end Get_Interfacing_Aspects;
9376 ---------------------------------
9377 -- Get_Iterable_Type_Primitive --
9378 ---------------------------------
9380 function Get_Iterable_Type_Primitive
9381 (Typ : Entity_Id;
9382 Nam : Name_Id) return Entity_Id
9384 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9385 Assoc : Node_Id;
9387 begin
9388 if No (Funcs) then
9389 return Empty;
9391 else
9392 Assoc := First (Component_Associations (Funcs));
9393 while Present (Assoc) loop
9394 if Chars (First (Choices (Assoc))) = Nam then
9395 return Entity (Expression (Assoc));
9396 end if;
9398 Assoc := Next (Assoc);
9399 end loop;
9401 return Empty;
9402 end if;
9403 end Get_Iterable_Type_Primitive;
9405 ----------------------------------
9406 -- Get_Library_Unit_Name_String --
9407 ----------------------------------
9409 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9410 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9412 begin
9413 Get_Unit_Name_String (Unit_Name_Id);
9415 -- Remove seven last character (" (spec)" or " (body)")
9417 Name_Len := Name_Len - 7;
9418 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9419 end Get_Library_Unit_Name_String;
9421 --------------------------
9422 -- Get_Max_Queue_Length --
9423 --------------------------
9425 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9426 pragma Assert (Is_Entry (Id));
9427 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9429 begin
9430 -- A value of 0 represents no maximum specified, and entries and entry
9431 -- families with no Max_Queue_Length aspect or pragma default to it.
9433 if not Present (Prag) then
9434 return Uint_0;
9435 end if;
9437 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9438 end Get_Max_Queue_Length;
9440 ------------------------
9441 -- Get_Name_Entity_Id --
9442 ------------------------
9444 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9445 begin
9446 return Entity_Id (Get_Name_Table_Int (Id));
9447 end Get_Name_Entity_Id;
9449 ------------------------------
9450 -- Get_Name_From_CTC_Pragma --
9451 ------------------------------
9453 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9454 Arg : constant Node_Id :=
9455 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9456 begin
9457 return Strval (Expr_Value_S (Arg));
9458 end Get_Name_From_CTC_Pragma;
9460 -----------------------
9461 -- Get_Parent_Entity --
9462 -----------------------
9464 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9465 begin
9466 if Nkind (Unit) = N_Package_Body
9467 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9468 then
9469 return Defining_Entity
9470 (Specification (Instance_Spec (Original_Node (Unit))));
9471 elsif Nkind (Unit) = N_Package_Instantiation then
9472 return Defining_Entity (Specification (Instance_Spec (Unit)));
9473 else
9474 return Defining_Entity (Unit);
9475 end if;
9476 end Get_Parent_Entity;
9478 -------------------
9479 -- Get_Pragma_Id --
9480 -------------------
9482 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9483 begin
9484 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9485 end Get_Pragma_Id;
9487 ------------------------
9488 -- Get_Qualified_Name --
9489 ------------------------
9491 function Get_Qualified_Name
9492 (Id : Entity_Id;
9493 Suffix : Entity_Id := Empty) return Name_Id
9495 Suffix_Nam : Name_Id := No_Name;
9497 begin
9498 if Present (Suffix) then
9499 Suffix_Nam := Chars (Suffix);
9500 end if;
9502 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9503 end Get_Qualified_Name;
9505 function Get_Qualified_Name
9506 (Nam : Name_Id;
9507 Suffix : Name_Id := No_Name;
9508 Scop : Entity_Id := Current_Scope) return Name_Id
9510 procedure Add_Scope (S : Entity_Id);
9511 -- Add the fully qualified form of scope S to the name buffer. The
9512 -- format is:
9513 -- s-1__s__
9515 ---------------
9516 -- Add_Scope --
9517 ---------------
9519 procedure Add_Scope (S : Entity_Id) is
9520 begin
9521 if S = Empty then
9522 null;
9524 elsif S = Standard_Standard then
9525 null;
9527 else
9528 Add_Scope (Scope (S));
9529 Get_Name_String_And_Append (Chars (S));
9530 Add_Str_To_Name_Buffer ("__");
9531 end if;
9532 end Add_Scope;
9534 -- Start of processing for Get_Qualified_Name
9536 begin
9537 Name_Len := 0;
9538 Add_Scope (Scop);
9540 -- Append the base name after all scopes have been chained
9542 Get_Name_String_And_Append (Nam);
9544 -- Append the suffix (if present)
9546 if Suffix /= No_Name then
9547 Add_Str_To_Name_Buffer ("__");
9548 Get_Name_String_And_Append (Suffix);
9549 end if;
9551 return Name_Find;
9552 end Get_Qualified_Name;
9554 -----------------------
9555 -- Get_Reason_String --
9556 -----------------------
9558 procedure Get_Reason_String (N : Node_Id) is
9559 begin
9560 if Nkind (N) = N_String_Literal then
9561 Store_String_Chars (Strval (N));
9563 elsif Nkind (N) = N_Op_Concat then
9564 Get_Reason_String (Left_Opnd (N));
9565 Get_Reason_String (Right_Opnd (N));
9567 -- If not of required form, error
9569 else
9570 Error_Msg_N
9571 ("Reason for pragma Warnings has wrong form", N);
9572 Error_Msg_N
9573 ("\must be string literal or concatenation of string literals", N);
9574 return;
9575 end if;
9576 end Get_Reason_String;
9578 --------------------------------
9579 -- Get_Reference_Discriminant --
9580 --------------------------------
9582 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9583 D : Entity_Id;
9585 begin
9586 D := First_Discriminant (Typ);
9587 while Present (D) loop
9588 if Has_Implicit_Dereference (D) then
9589 return D;
9590 end if;
9591 Next_Discriminant (D);
9592 end loop;
9594 return Empty;
9595 end Get_Reference_Discriminant;
9597 ---------------------------
9598 -- Get_Referenced_Object --
9599 ---------------------------
9601 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9602 R : Node_Id;
9604 begin
9605 R := N;
9606 while Is_Entity_Name (R)
9607 and then Present (Renamed_Object (Entity (R)))
9608 loop
9609 R := Renamed_Object (Entity (R));
9610 end loop;
9612 return R;
9613 end Get_Referenced_Object;
9615 ------------------------
9616 -- Get_Renamed_Entity --
9617 ------------------------
9619 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9620 R : Entity_Id;
9622 begin
9623 R := E;
9624 while Present (Renamed_Entity (R)) loop
9625 R := Renamed_Entity (R);
9626 end loop;
9628 return R;
9629 end Get_Renamed_Entity;
9631 -----------------------
9632 -- Get_Return_Object --
9633 -----------------------
9635 function Get_Return_Object (N : Node_Id) return Entity_Id is
9636 Decl : Node_Id;
9638 begin
9639 Decl := First (Return_Object_Declarations (N));
9640 while Present (Decl) loop
9641 exit when Nkind (Decl) = N_Object_Declaration
9642 and then Is_Return_Object (Defining_Identifier (Decl));
9643 Next (Decl);
9644 end loop;
9646 pragma Assert (Present (Decl));
9647 return Defining_Identifier (Decl);
9648 end Get_Return_Object;
9650 ---------------------------
9651 -- Get_Subprogram_Entity --
9652 ---------------------------
9654 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9655 Subp : Node_Id;
9656 Subp_Id : Entity_Id;
9658 begin
9659 if Nkind (Nod) = N_Accept_Statement then
9660 Subp := Entry_Direct_Name (Nod);
9662 elsif Nkind (Nod) = N_Slice then
9663 Subp := Prefix (Nod);
9665 else
9666 Subp := Name (Nod);
9667 end if;
9669 -- Strip the subprogram call
9671 loop
9672 if Nkind_In (Subp, N_Explicit_Dereference,
9673 N_Indexed_Component,
9674 N_Selected_Component)
9675 then
9676 Subp := Prefix (Subp);
9678 elsif Nkind_In (Subp, N_Type_Conversion,
9679 N_Unchecked_Type_Conversion)
9680 then
9681 Subp := Expression (Subp);
9683 else
9684 exit;
9685 end if;
9686 end loop;
9688 -- Extract the entity of the subprogram call
9690 if Is_Entity_Name (Subp) then
9691 Subp_Id := Entity (Subp);
9693 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9694 Subp_Id := Directly_Designated_Type (Subp_Id);
9695 end if;
9697 if Is_Subprogram (Subp_Id) then
9698 return Subp_Id;
9699 else
9700 return Empty;
9701 end if;
9703 -- The search did not find a construct that denotes a subprogram
9705 else
9706 return Empty;
9707 end if;
9708 end Get_Subprogram_Entity;
9710 -----------------------------
9711 -- Get_Task_Body_Procedure --
9712 -----------------------------
9714 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
9715 begin
9716 -- Note: A task type may be the completion of a private type with
9717 -- discriminants. When performing elaboration checks on a task
9718 -- declaration, the current view of the type may be the private one,
9719 -- and the procedure that holds the body of the task is held in its
9720 -- underlying type.
9722 -- This is an odd function, why not have Task_Body_Procedure do
9723 -- the following digging???
9725 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9726 end Get_Task_Body_Procedure;
9728 -------------------------
9729 -- Get_User_Defined_Eq --
9730 -------------------------
9732 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9733 Prim : Elmt_Id;
9734 Op : Entity_Id;
9736 begin
9737 Prim := First_Elmt (Collect_Primitive_Operations (E));
9738 while Present (Prim) loop
9739 Op := Node (Prim);
9741 if Chars (Op) = Name_Op_Eq
9742 and then Etype (Op) = Standard_Boolean
9743 and then Etype (First_Formal (Op)) = E
9744 and then Etype (Next_Formal (First_Formal (Op))) = E
9745 then
9746 return Op;
9747 end if;
9749 Next_Elmt (Prim);
9750 end loop;
9752 return Empty;
9753 end Get_User_Defined_Eq;
9755 ---------------
9756 -- Get_Views --
9757 ---------------
9759 procedure Get_Views
9760 (Typ : Entity_Id;
9761 Priv_Typ : out Entity_Id;
9762 Full_Typ : out Entity_Id;
9763 Full_Base : out Entity_Id;
9764 CRec_Typ : out Entity_Id)
9766 IP_View : Entity_Id;
9768 begin
9769 -- Assume that none of the views can be recovered
9771 Priv_Typ := Empty;
9772 Full_Typ := Empty;
9773 Full_Base := Empty;
9774 CRec_Typ := Empty;
9776 -- The input type is the corresponding record type of a protected or a
9777 -- task type.
9779 if Ekind (Typ) = E_Record_Type
9780 and then Is_Concurrent_Record_Type (Typ)
9781 then
9782 CRec_Typ := Typ;
9783 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9784 Full_Base := Base_Type (Full_Typ);
9785 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9787 -- Otherwise the input type denotes an arbitrary type
9789 else
9790 IP_View := Incomplete_Or_Partial_View (Typ);
9792 -- The input type denotes the full view of a private type
9794 if Present (IP_View) then
9795 Priv_Typ := IP_View;
9796 Full_Typ := Typ;
9798 -- The input type is a private type
9800 elsif Is_Private_Type (Typ) then
9801 Priv_Typ := Typ;
9802 Full_Typ := Full_View (Priv_Typ);
9804 -- Otherwise the input type does not have any views
9806 else
9807 Full_Typ := Typ;
9808 end if;
9810 if Present (Full_Typ) then
9811 Full_Base := Base_Type (Full_Typ);
9813 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
9814 CRec_Typ := Corresponding_Record_Type (Full_Typ);
9815 end if;
9816 end if;
9817 end if;
9818 end Get_Views;
9820 -----------------------
9821 -- Has_Access_Values --
9822 -----------------------
9824 function Has_Access_Values (T : Entity_Id) return Boolean is
9825 Typ : constant Entity_Id := Underlying_Type (T);
9827 begin
9828 -- Case of a private type which is not completed yet. This can only
9829 -- happen in the case of a generic format type appearing directly, or
9830 -- as a component of the type to which this function is being applied
9831 -- at the top level. Return False in this case, since we certainly do
9832 -- not know that the type contains access types.
9834 if No (Typ) then
9835 return False;
9837 elsif Is_Access_Type (Typ) then
9838 return True;
9840 elsif Is_Array_Type (Typ) then
9841 return Has_Access_Values (Component_Type (Typ));
9843 elsif Is_Record_Type (Typ) then
9844 declare
9845 Comp : Entity_Id;
9847 begin
9848 -- Loop to Check components
9850 Comp := First_Component_Or_Discriminant (Typ);
9851 while Present (Comp) loop
9853 -- Check for access component, tag field does not count, even
9854 -- though it is implemented internally using an access type.
9856 if Has_Access_Values (Etype (Comp))
9857 and then Chars (Comp) /= Name_uTag
9858 then
9859 return True;
9860 end if;
9862 Next_Component_Or_Discriminant (Comp);
9863 end loop;
9864 end;
9866 return False;
9868 else
9869 return False;
9870 end if;
9871 end Has_Access_Values;
9873 ------------------------------
9874 -- Has_Compatible_Alignment --
9875 ------------------------------
9877 function Has_Compatible_Alignment
9878 (Obj : Entity_Id;
9879 Expr : Node_Id;
9880 Layout_Done : Boolean) return Alignment_Result
9882 function Has_Compatible_Alignment_Internal
9883 (Obj : Entity_Id;
9884 Expr : Node_Id;
9885 Layout_Done : Boolean;
9886 Default : Alignment_Result) return Alignment_Result;
9887 -- This is the internal recursive function that actually does the work.
9888 -- There is one additional parameter, which says what the result should
9889 -- be if no alignment information is found, and there is no definite
9890 -- indication of compatible alignments. At the outer level, this is set
9891 -- to Unknown, but for internal recursive calls in the case where types
9892 -- are known to be correct, it is set to Known_Compatible.
9894 ---------------------------------------
9895 -- Has_Compatible_Alignment_Internal --
9896 ---------------------------------------
9898 function Has_Compatible_Alignment_Internal
9899 (Obj : Entity_Id;
9900 Expr : Node_Id;
9901 Layout_Done : Boolean;
9902 Default : Alignment_Result) return Alignment_Result
9904 Result : Alignment_Result := Known_Compatible;
9905 -- Holds the current status of the result. Note that once a value of
9906 -- Known_Incompatible is set, it is sticky and does not get changed
9907 -- to Unknown (the value in Result only gets worse as we go along,
9908 -- never better).
9910 Offs : Uint := No_Uint;
9911 -- Set to a factor of the offset from the base object when Expr is a
9912 -- selected or indexed component, based on Component_Bit_Offset and
9913 -- Component_Size respectively. A negative value is used to represent
9914 -- a value which is not known at compile time.
9916 procedure Check_Prefix;
9917 -- Checks the prefix recursively in the case where the expression
9918 -- is an indexed or selected component.
9920 procedure Set_Result (R : Alignment_Result);
9921 -- If R represents a worse outcome (unknown instead of known
9922 -- compatible, or known incompatible), then set Result to R.
9924 ------------------
9925 -- Check_Prefix --
9926 ------------------
9928 procedure Check_Prefix is
9929 begin
9930 -- The subtlety here is that in doing a recursive call to check
9931 -- the prefix, we have to decide what to do in the case where we
9932 -- don't find any specific indication of an alignment problem.
9934 -- At the outer level, we normally set Unknown as the result in
9935 -- this case, since we can only set Known_Compatible if we really
9936 -- know that the alignment value is OK, but for the recursive
9937 -- call, in the case where the types match, and we have not
9938 -- specified a peculiar alignment for the object, we are only
9939 -- concerned about suspicious rep clauses, the default case does
9940 -- not affect us, since the compiler will, in the absence of such
9941 -- rep clauses, ensure that the alignment is correct.
9943 if Default = Known_Compatible
9944 or else
9945 (Etype (Obj) = Etype (Expr)
9946 and then (Unknown_Alignment (Obj)
9947 or else
9948 Alignment (Obj) = Alignment (Etype (Obj))))
9949 then
9950 Set_Result
9951 (Has_Compatible_Alignment_Internal
9952 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
9954 -- In all other cases, we need a full check on the prefix
9956 else
9957 Set_Result
9958 (Has_Compatible_Alignment_Internal
9959 (Obj, Prefix (Expr), Layout_Done, Unknown));
9960 end if;
9961 end Check_Prefix;
9963 ----------------
9964 -- Set_Result --
9965 ----------------
9967 procedure Set_Result (R : Alignment_Result) is
9968 begin
9969 if R > Result then
9970 Result := R;
9971 end if;
9972 end Set_Result;
9974 -- Start of processing for Has_Compatible_Alignment_Internal
9976 begin
9977 -- If Expr is a selected component, we must make sure there is no
9978 -- potentially troublesome component clause and that the record is
9979 -- not packed if the layout is not done.
9981 if Nkind (Expr) = N_Selected_Component then
9983 -- Packing generates unknown alignment if layout is not done
9985 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
9986 Set_Result (Unknown);
9987 end if;
9989 -- Check prefix and component offset
9991 Check_Prefix;
9992 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
9994 -- If Expr is an indexed component, we must make sure there is no
9995 -- potentially troublesome Component_Size clause and that the array
9996 -- is not bit-packed if the layout is not done.
9998 elsif Nkind (Expr) = N_Indexed_Component then
9999 declare
10000 Typ : constant Entity_Id := Etype (Prefix (Expr));
10002 begin
10003 -- Packing generates unknown alignment if layout is not done
10005 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10006 Set_Result (Unknown);
10007 end if;
10009 -- Check prefix and component offset (or at least size)
10011 Check_Prefix;
10012 Offs := Indexed_Component_Bit_Offset (Expr);
10013 if Offs = No_Uint then
10014 Offs := Component_Size (Typ);
10015 end if;
10016 end;
10017 end if;
10019 -- If we have a null offset, the result is entirely determined by
10020 -- the base object and has already been computed recursively.
10022 if Offs = Uint_0 then
10023 null;
10025 -- Case where we know the alignment of the object
10027 elsif Known_Alignment (Obj) then
10028 declare
10029 ObjA : constant Uint := Alignment (Obj);
10030 ExpA : Uint := No_Uint;
10031 SizA : Uint := No_Uint;
10033 begin
10034 -- If alignment of Obj is 1, then we are always OK
10036 if ObjA = 1 then
10037 Set_Result (Known_Compatible);
10039 -- Alignment of Obj is greater than 1, so we need to check
10041 else
10042 -- If we have an offset, see if it is compatible
10044 if Offs /= No_Uint and Offs > Uint_0 then
10045 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10046 Set_Result (Known_Incompatible);
10047 end if;
10049 -- See if Expr is an object with known alignment
10051 elsif Is_Entity_Name (Expr)
10052 and then Known_Alignment (Entity (Expr))
10053 then
10054 ExpA := Alignment (Entity (Expr));
10056 -- Otherwise, we can use the alignment of the type of
10057 -- Expr given that we already checked for
10058 -- discombobulating rep clauses for the cases of indexed
10059 -- and selected components above.
10061 elsif Known_Alignment (Etype (Expr)) then
10062 ExpA := Alignment (Etype (Expr));
10064 -- Otherwise the alignment is unknown
10066 else
10067 Set_Result (Default);
10068 end if;
10070 -- If we got an alignment, see if it is acceptable
10072 if ExpA /= No_Uint and then ExpA < ObjA then
10073 Set_Result (Known_Incompatible);
10074 end if;
10076 -- If Expr is not a piece of a larger object, see if size
10077 -- is given. If so, check that it is not too small for the
10078 -- required alignment.
10080 if Offs /= No_Uint then
10081 null;
10083 -- See if Expr is an object with known size
10085 elsif Is_Entity_Name (Expr)
10086 and then Known_Static_Esize (Entity (Expr))
10087 then
10088 SizA := Esize (Entity (Expr));
10090 -- Otherwise, we check the object size of the Expr type
10092 elsif Known_Static_Esize (Etype (Expr)) then
10093 SizA := Esize (Etype (Expr));
10094 end if;
10096 -- If we got a size, see if it is a multiple of the Obj
10097 -- alignment, if not, then the alignment cannot be
10098 -- acceptable, since the size is always a multiple of the
10099 -- alignment.
10101 if SizA /= No_Uint then
10102 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10103 Set_Result (Known_Incompatible);
10104 end if;
10105 end if;
10106 end if;
10107 end;
10109 -- If we do not know required alignment, any non-zero offset is a
10110 -- potential problem (but certainly may be OK, so result is unknown).
10112 elsif Offs /= No_Uint then
10113 Set_Result (Unknown);
10115 -- If we can't find the result by direct comparison of alignment
10116 -- values, then there is still one case that we can determine known
10117 -- result, and that is when we can determine that the types are the
10118 -- same, and no alignments are specified. Then we known that the
10119 -- alignments are compatible, even if we don't know the alignment
10120 -- value in the front end.
10122 elsif Etype (Obj) = Etype (Expr) then
10124 -- Types are the same, but we have to check for possible size
10125 -- and alignments on the Expr object that may make the alignment
10126 -- different, even though the types are the same.
10128 if Is_Entity_Name (Expr) then
10130 -- First check alignment of the Expr object. Any alignment less
10131 -- than Maximum_Alignment is worrisome since this is the case
10132 -- where we do not know the alignment of Obj.
10134 if Known_Alignment (Entity (Expr))
10135 and then UI_To_Int (Alignment (Entity (Expr))) <
10136 Ttypes.Maximum_Alignment
10137 then
10138 Set_Result (Unknown);
10140 -- Now check size of Expr object. Any size that is not an
10141 -- even multiple of Maximum_Alignment is also worrisome
10142 -- since it may cause the alignment of the object to be less
10143 -- than the alignment of the type.
10145 elsif Known_Static_Esize (Entity (Expr))
10146 and then
10147 (UI_To_Int (Esize (Entity (Expr))) mod
10148 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10149 /= 0
10150 then
10151 Set_Result (Unknown);
10153 -- Otherwise same type is decisive
10155 else
10156 Set_Result (Known_Compatible);
10157 end if;
10158 end if;
10160 -- Another case to deal with is when there is an explicit size or
10161 -- alignment clause when the types are not the same. If so, then the
10162 -- result is Unknown. We don't need to do this test if the Default is
10163 -- Unknown, since that result will be set in any case.
10165 elsif Default /= Unknown
10166 and then (Has_Size_Clause (Etype (Expr))
10167 or else
10168 Has_Alignment_Clause (Etype (Expr)))
10169 then
10170 Set_Result (Unknown);
10172 -- If no indication found, set default
10174 else
10175 Set_Result (Default);
10176 end if;
10178 -- Return worst result found
10180 return Result;
10181 end Has_Compatible_Alignment_Internal;
10183 -- Start of processing for Has_Compatible_Alignment
10185 begin
10186 -- If Obj has no specified alignment, then set alignment from the type
10187 -- alignment. Perhaps we should always do this, but for sure we should
10188 -- do it when there is an address clause since we can do more if the
10189 -- alignment is known.
10191 if Unknown_Alignment (Obj) then
10192 Set_Alignment (Obj, Alignment (Etype (Obj)));
10193 end if;
10195 -- Now do the internal call that does all the work
10197 return
10198 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10199 end Has_Compatible_Alignment;
10201 ----------------------
10202 -- Has_Declarations --
10203 ----------------------
10205 function Has_Declarations (N : Node_Id) return Boolean is
10206 begin
10207 return Nkind_In (Nkind (N), N_Accept_Statement,
10208 N_Block_Statement,
10209 N_Compilation_Unit_Aux,
10210 N_Entry_Body,
10211 N_Package_Body,
10212 N_Protected_Body,
10213 N_Subprogram_Body,
10214 N_Task_Body,
10215 N_Package_Specification);
10216 end Has_Declarations;
10218 ---------------------------------
10219 -- Has_Defaulted_Discriminants --
10220 ---------------------------------
10222 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10223 begin
10224 return Has_Discriminants (Typ)
10225 and then Present (First_Discriminant (Typ))
10226 and then Present (Discriminant_Default_Value
10227 (First_Discriminant (Typ)));
10228 end Has_Defaulted_Discriminants;
10230 -------------------
10231 -- Has_Denormals --
10232 -------------------
10234 function Has_Denormals (E : Entity_Id) return Boolean is
10235 begin
10236 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10237 end Has_Denormals;
10239 -------------------------------------------
10240 -- Has_Discriminant_Dependent_Constraint --
10241 -------------------------------------------
10243 function Has_Discriminant_Dependent_Constraint
10244 (Comp : Entity_Id) return Boolean
10246 Comp_Decl : constant Node_Id := Parent (Comp);
10247 Subt_Indic : Node_Id;
10248 Constr : Node_Id;
10249 Assn : Node_Id;
10251 begin
10252 -- Discriminants can't depend on discriminants
10254 if Ekind (Comp) = E_Discriminant then
10255 return False;
10257 else
10258 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10260 if Nkind (Subt_Indic) = N_Subtype_Indication then
10261 Constr := Constraint (Subt_Indic);
10263 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10264 Assn := First (Constraints (Constr));
10265 while Present (Assn) loop
10266 case Nkind (Assn) is
10267 when N_Identifier
10268 | N_Range
10269 | N_Subtype_Indication
10271 if Depends_On_Discriminant (Assn) then
10272 return True;
10273 end if;
10275 when N_Discriminant_Association =>
10276 if Depends_On_Discriminant (Expression (Assn)) then
10277 return True;
10278 end if;
10280 when others =>
10281 null;
10282 end case;
10284 Next (Assn);
10285 end loop;
10286 end if;
10287 end if;
10288 end if;
10290 return False;
10291 end Has_Discriminant_Dependent_Constraint;
10293 --------------------------------------
10294 -- Has_Effectively_Volatile_Profile --
10295 --------------------------------------
10297 function Has_Effectively_Volatile_Profile
10298 (Subp_Id : Entity_Id) return Boolean
10300 Formal : Entity_Id;
10302 begin
10303 -- Inspect the formal parameters looking for an effectively volatile
10304 -- type.
10306 Formal := First_Formal (Subp_Id);
10307 while Present (Formal) loop
10308 if Is_Effectively_Volatile (Etype (Formal)) then
10309 return True;
10310 end if;
10312 Next_Formal (Formal);
10313 end loop;
10315 -- Inspect the return type of functions
10317 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10318 and then Is_Effectively_Volatile (Etype (Subp_Id))
10319 then
10320 return True;
10321 end if;
10323 return False;
10324 end Has_Effectively_Volatile_Profile;
10326 --------------------------
10327 -- Has_Enabled_Property --
10328 --------------------------
10330 function Has_Enabled_Property
10331 (Item_Id : Entity_Id;
10332 Property : Name_Id) return Boolean
10334 function Protected_Object_Has_Enabled_Property return Boolean;
10335 -- Determine whether a protected object denoted by Item_Id has the
10336 -- property enabled.
10338 function State_Has_Enabled_Property return Boolean;
10339 -- Determine whether a state denoted by Item_Id has the property enabled
10341 function Variable_Has_Enabled_Property return Boolean;
10342 -- Determine whether a variable denoted by Item_Id has the property
10343 -- enabled.
10345 -------------------------------------------
10346 -- Protected_Object_Has_Enabled_Property --
10347 -------------------------------------------
10349 function Protected_Object_Has_Enabled_Property return Boolean is
10350 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10351 Constit_Elmt : Elmt_Id;
10352 Constit_Id : Entity_Id;
10354 begin
10355 -- Protected objects always have the properties Async_Readers and
10356 -- Async_Writers (SPARK RM 7.1.2(16)).
10358 if Property = Name_Async_Readers
10359 or else Property = Name_Async_Writers
10360 then
10361 return True;
10363 -- Protected objects that have Part_Of components also inherit their
10364 -- properties Effective_Reads and Effective_Writes
10365 -- (SPARK RM 7.1.2(16)).
10367 elsif Present (Constits) then
10368 Constit_Elmt := First_Elmt (Constits);
10369 while Present (Constit_Elmt) loop
10370 Constit_Id := Node (Constit_Elmt);
10372 if Has_Enabled_Property (Constit_Id, Property) then
10373 return True;
10374 end if;
10376 Next_Elmt (Constit_Elmt);
10377 end loop;
10378 end if;
10380 return False;
10381 end Protected_Object_Has_Enabled_Property;
10383 --------------------------------
10384 -- State_Has_Enabled_Property --
10385 --------------------------------
10387 function State_Has_Enabled_Property return Boolean is
10388 Decl : constant Node_Id := Parent (Item_Id);
10390 procedure Find_Simple_Properties
10391 (Has_External : out Boolean;
10392 Has_Synchronous : out Boolean);
10393 -- Extract the simple properties associated with declaration Decl
10395 function Is_Enabled_External_Property return Boolean;
10396 -- Determine whether property Property appears within the external
10397 -- property list of declaration Decl, and return its status.
10399 ----------------------------
10400 -- Find_Simple_Properties --
10401 ----------------------------
10403 procedure Find_Simple_Properties
10404 (Has_External : out Boolean;
10405 Has_Synchronous : out Boolean)
10407 Opt : Node_Id;
10409 begin
10410 -- Assume that none of the properties are available
10412 Has_External := False;
10413 Has_Synchronous := False;
10415 Opt := First (Expressions (Decl));
10416 while Present (Opt) loop
10417 if Nkind (Opt) = N_Identifier then
10418 if Chars (Opt) = Name_External then
10419 Has_External := True;
10421 elsif Chars (Opt) = Name_Synchronous then
10422 Has_Synchronous := True;
10423 end if;
10424 end if;
10426 Next (Opt);
10427 end loop;
10428 end Find_Simple_Properties;
10430 ----------------------------------
10431 -- Is_Enabled_External_Property --
10432 ----------------------------------
10434 function Is_Enabled_External_Property return Boolean is
10435 Opt : Node_Id;
10436 Opt_Nam : Node_Id;
10437 Prop : Node_Id;
10438 Prop_Nam : Node_Id;
10439 Props : Node_Id;
10441 begin
10442 Opt := First (Component_Associations (Decl));
10443 while Present (Opt) loop
10444 Opt_Nam := First (Choices (Opt));
10446 if Nkind (Opt_Nam) = N_Identifier
10447 and then Chars (Opt_Nam) = Name_External
10448 then
10449 Props := Expression (Opt);
10451 -- Multiple properties appear as an aggregate
10453 if Nkind (Props) = N_Aggregate then
10455 -- Simple property form
10457 Prop := First (Expressions (Props));
10458 while Present (Prop) loop
10459 if Chars (Prop) = Property then
10460 return True;
10461 end if;
10463 Next (Prop);
10464 end loop;
10466 -- Property with expression form
10468 Prop := First (Component_Associations (Props));
10469 while Present (Prop) loop
10470 Prop_Nam := First (Choices (Prop));
10472 -- The property can be represented in two ways:
10473 -- others => <value>
10474 -- <property> => <value>
10476 if Nkind (Prop_Nam) = N_Others_Choice
10477 or else (Nkind (Prop_Nam) = N_Identifier
10478 and then Chars (Prop_Nam) = Property)
10479 then
10480 return Is_True (Expr_Value (Expression (Prop)));
10481 end if;
10483 Next (Prop);
10484 end loop;
10486 -- Single property
10488 else
10489 return Chars (Props) = Property;
10490 end if;
10491 end if;
10493 Next (Opt);
10494 end loop;
10496 return False;
10497 end Is_Enabled_External_Property;
10499 -- Local variables
10501 Has_External : Boolean;
10502 Has_Synchronous : Boolean;
10504 -- Start of processing for State_Has_Enabled_Property
10506 begin
10507 -- The declaration of an external abstract state appears as an
10508 -- extension aggregate. If this is not the case, properties can
10509 -- never be set.
10511 if Nkind (Decl) /= N_Extension_Aggregate then
10512 return False;
10513 end if;
10515 Find_Simple_Properties (Has_External, Has_Synchronous);
10517 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10519 if Has_External then
10520 return True;
10522 -- Option External may enable or disable specific properties
10524 elsif Is_Enabled_External_Property then
10525 return True;
10527 -- Simple option Synchronous
10529 -- enables disables
10530 -- Asynch_Readers Effective_Reads
10531 -- Asynch_Writers Effective_Writes
10533 -- Note that both forms of External have higher precedence than
10534 -- Synchronous (SPARK RM 7.1.4(10)).
10536 elsif Has_Synchronous then
10537 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
10538 end if;
10540 return False;
10541 end State_Has_Enabled_Property;
10543 -----------------------------------
10544 -- Variable_Has_Enabled_Property --
10545 -----------------------------------
10547 function Variable_Has_Enabled_Property return Boolean is
10548 function Is_Enabled (Prag : Node_Id) return Boolean;
10549 -- Determine whether property pragma Prag (if present) denotes an
10550 -- enabled property.
10552 ----------------
10553 -- Is_Enabled --
10554 ----------------
10556 function Is_Enabled (Prag : Node_Id) return Boolean is
10557 Arg1 : Node_Id;
10559 begin
10560 if Present (Prag) then
10561 Arg1 := First (Pragma_Argument_Associations (Prag));
10563 -- The pragma has an optional Boolean expression, the related
10564 -- property is enabled only when the expression evaluates to
10565 -- True.
10567 if Present (Arg1) then
10568 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10570 -- Otherwise the lack of expression enables the property by
10571 -- default.
10573 else
10574 return True;
10575 end if;
10577 -- The property was never set in the first place
10579 else
10580 return False;
10581 end if;
10582 end Is_Enabled;
10584 -- Local variables
10586 AR : constant Node_Id :=
10587 Get_Pragma (Item_Id, Pragma_Async_Readers);
10588 AW : constant Node_Id :=
10589 Get_Pragma (Item_Id, Pragma_Async_Writers);
10590 ER : constant Node_Id :=
10591 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10592 EW : constant Node_Id :=
10593 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10595 -- Start of processing for Variable_Has_Enabled_Property
10597 begin
10598 -- A non-effectively volatile object can never possess external
10599 -- properties.
10601 if not Is_Effectively_Volatile (Item_Id) then
10602 return False;
10604 -- External properties related to variables come in two flavors -
10605 -- explicit and implicit. The explicit case is characterized by the
10606 -- presence of a property pragma with an optional Boolean flag. The
10607 -- property is enabled when the flag evaluates to True or the flag is
10608 -- missing altogether.
10610 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10611 return True;
10613 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10614 return True;
10616 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10617 return True;
10619 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10620 return True;
10622 -- The implicit case lacks all property pragmas
10624 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10625 if Is_Protected_Type (Etype (Item_Id)) then
10626 return Protected_Object_Has_Enabled_Property;
10627 else
10628 return True;
10629 end if;
10631 else
10632 return False;
10633 end if;
10634 end Variable_Has_Enabled_Property;
10636 -- Start of processing for Has_Enabled_Property
10638 begin
10639 -- Abstract states and variables have a flexible scheme of specifying
10640 -- external properties.
10642 if Ekind (Item_Id) = E_Abstract_State then
10643 return State_Has_Enabled_Property;
10645 elsif Ekind (Item_Id) = E_Variable then
10646 return Variable_Has_Enabled_Property;
10648 -- By default, protected objects only have the properties Async_Readers
10649 -- and Async_Writers. If they have Part_Of components, they also inherit
10650 -- their properties Effective_Reads and Effective_Writes
10651 -- (SPARK RM 7.1.2(16)).
10653 elsif Ekind (Item_Id) = E_Protected_Object then
10654 return Protected_Object_Has_Enabled_Property;
10656 -- Otherwise a property is enabled when the related item is effectively
10657 -- volatile.
10659 else
10660 return Is_Effectively_Volatile (Item_Id);
10661 end if;
10662 end Has_Enabled_Property;
10664 -------------------------------------
10665 -- Has_Full_Default_Initialization --
10666 -------------------------------------
10668 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10669 Comp : Entity_Id;
10671 begin
10672 -- A type subject to pragma Default_Initial_Condition may be fully
10673 -- default initialized depending on inheritance and the argument of
10674 -- the pragma. Since any type may act as the full view of a private
10675 -- type, this check must be performed prior to the specialized tests
10676 -- below.
10678 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
10679 return True;
10680 end if;
10682 -- A scalar type is fully default initialized if it is subject to aspect
10683 -- Default_Value.
10685 if Is_Scalar_Type (Typ) then
10686 return Has_Default_Aspect (Typ);
10688 -- An array type is fully default initialized if its element type is
10689 -- scalar and the array type carries aspect Default_Component_Value or
10690 -- the element type is fully default initialized.
10692 elsif Is_Array_Type (Typ) then
10693 return
10694 Has_Default_Aspect (Typ)
10695 or else Has_Full_Default_Initialization (Component_Type (Typ));
10697 -- A protected type, record type, or type extension is fully default
10698 -- initialized if all its components either carry an initialization
10699 -- expression or have a type that is fully default initialized. The
10700 -- parent type of a type extension must be fully default initialized.
10702 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10704 -- Inspect all entities defined in the scope of the type, looking for
10705 -- uninitialized components.
10707 Comp := First_Entity (Typ);
10708 while Present (Comp) loop
10709 if Ekind (Comp) = E_Component
10710 and then Comes_From_Source (Comp)
10711 and then No (Expression (Parent (Comp)))
10712 and then not Has_Full_Default_Initialization (Etype (Comp))
10713 then
10714 return False;
10715 end if;
10717 Next_Entity (Comp);
10718 end loop;
10720 -- Ensure that the parent type of a type extension is fully default
10721 -- initialized.
10723 if Etype (Typ) /= Typ
10724 and then not Has_Full_Default_Initialization (Etype (Typ))
10725 then
10726 return False;
10727 end if;
10729 -- If we get here, then all components and parent portion are fully
10730 -- default initialized.
10732 return True;
10734 -- A task type is fully default initialized by default
10736 elsif Is_Task_Type (Typ) then
10737 return True;
10739 -- Otherwise the type is not fully default initialized
10741 else
10742 return False;
10743 end if;
10744 end Has_Full_Default_Initialization;
10746 -----------------------------------------------
10747 -- Has_Fully_Default_Initializing_DIC_Pragma --
10748 -----------------------------------------------
10750 function Has_Fully_Default_Initializing_DIC_Pragma
10751 (Typ : Entity_Id) return Boolean
10753 Args : List_Id;
10754 Prag : Node_Id;
10756 begin
10757 -- A type that inherits pragma Default_Initial_Condition from a parent
10758 -- type is automatically fully default initialized.
10760 if Has_Inherited_DIC (Typ) then
10761 return True;
10763 -- Otherwise the type is fully default initialized only when the pragma
10764 -- appears without an argument, or the argument is non-null.
10766 elsif Has_Own_DIC (Typ) then
10767 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10768 pragma Assert (Present (Prag));
10769 Args := Pragma_Argument_Associations (Prag);
10771 -- The pragma appears without an argument in which case it defaults
10772 -- to True.
10774 if No (Args) then
10775 return True;
10777 -- The pragma appears with a non-null expression
10779 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
10780 return True;
10781 end if;
10782 end if;
10784 return False;
10785 end Has_Fully_Default_Initializing_DIC_Pragma;
10787 --------------------
10788 -- Has_Infinities --
10789 --------------------
10791 function Has_Infinities (E : Entity_Id) return Boolean is
10792 begin
10793 return
10794 Is_Floating_Point_Type (E)
10795 and then Nkind (Scalar_Range (E)) = N_Range
10796 and then Includes_Infinities (Scalar_Range (E));
10797 end Has_Infinities;
10799 --------------------
10800 -- Has_Interfaces --
10801 --------------------
10803 function Has_Interfaces
10804 (T : Entity_Id;
10805 Use_Full_View : Boolean := True) return Boolean
10807 Typ : Entity_Id := Base_Type (T);
10809 begin
10810 -- Handle concurrent types
10812 if Is_Concurrent_Type (Typ) then
10813 Typ := Corresponding_Record_Type (Typ);
10814 end if;
10816 if not Present (Typ)
10817 or else not Is_Record_Type (Typ)
10818 or else not Is_Tagged_Type (Typ)
10819 then
10820 return False;
10821 end if;
10823 -- Handle private types
10825 if Use_Full_View and then Present (Full_View (Typ)) then
10826 Typ := Full_View (Typ);
10827 end if;
10829 -- Handle concurrent record types
10831 if Is_Concurrent_Record_Type (Typ)
10832 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
10833 then
10834 return True;
10835 end if;
10837 loop
10838 if Is_Interface (Typ)
10839 or else
10840 (Is_Record_Type (Typ)
10841 and then Present (Interfaces (Typ))
10842 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
10843 then
10844 return True;
10845 end if;
10847 exit when Etype (Typ) = Typ
10849 -- Handle private types
10851 or else (Present (Full_View (Etype (Typ)))
10852 and then Full_View (Etype (Typ)) = Typ)
10854 -- Protect frontend against wrong sources with cyclic derivations
10856 or else Etype (Typ) = T;
10858 -- Climb to the ancestor type handling private types
10860 if Present (Full_View (Etype (Typ))) then
10861 Typ := Full_View (Etype (Typ));
10862 else
10863 Typ := Etype (Typ);
10864 end if;
10865 end loop;
10867 return False;
10868 end Has_Interfaces;
10870 --------------------------
10871 -- Has_Max_Queue_Length --
10872 --------------------------
10874 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
10875 begin
10876 return
10877 Ekind (Id) = E_Entry
10878 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
10879 end Has_Max_Queue_Length;
10881 ---------------------------------
10882 -- Has_No_Obvious_Side_Effects --
10883 ---------------------------------
10885 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
10886 begin
10887 -- For now handle literals, constants, and non-volatile variables and
10888 -- expressions combining these with operators or short circuit forms.
10890 if Nkind (N) in N_Numeric_Or_String_Literal then
10891 return True;
10893 elsif Nkind (N) = N_Character_Literal then
10894 return True;
10896 elsif Nkind (N) in N_Unary_Op then
10897 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
10899 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
10900 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
10901 and then
10902 Has_No_Obvious_Side_Effects (Right_Opnd (N));
10904 elsif Nkind (N) = N_Expression_With_Actions
10905 and then Is_Empty_List (Actions (N))
10906 then
10907 return Has_No_Obvious_Side_Effects (Expression (N));
10909 elsif Nkind (N) in N_Has_Entity then
10910 return Present (Entity (N))
10911 and then Ekind_In (Entity (N), E_Variable,
10912 E_Constant,
10913 E_Enumeration_Literal,
10914 E_In_Parameter,
10915 E_Out_Parameter,
10916 E_In_Out_Parameter)
10917 and then not Is_Volatile (Entity (N));
10919 else
10920 return False;
10921 end if;
10922 end Has_No_Obvious_Side_Effects;
10924 -----------------------------
10925 -- Has_Non_Null_Refinement --
10926 -----------------------------
10928 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
10929 Constits : Elist_Id;
10931 begin
10932 pragma Assert (Ekind (Id) = E_Abstract_State);
10933 Constits := Refinement_Constituents (Id);
10935 -- For a refinement to be non-null, the first constituent must be
10936 -- anything other than null.
10938 return
10939 Present (Constits)
10940 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
10941 end Has_Non_Null_Refinement;
10943 -----------------------------
10944 -- Has_Non_Null_Statements --
10945 -----------------------------
10947 function Has_Non_Null_Statements (L : List_Id) return Boolean is
10948 Node : Node_Id;
10950 begin
10951 if Is_Non_Empty_List (L) then
10952 Node := First (L);
10954 loop
10955 if Nkind (Node) /= N_Null_Statement then
10956 return True;
10957 end if;
10959 Next (Node);
10960 exit when Node = Empty;
10961 end loop;
10962 end if;
10964 return False;
10965 end Has_Non_Null_Statements;
10967 ----------------------------------
10968 -- Has_Non_Trivial_Precondition --
10969 ----------------------------------
10971 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
10972 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
10974 begin
10975 return
10976 Present (Pre)
10977 and then Class_Present (Pre)
10978 and then not Is_Entity_Name (Expression (Pre));
10979 end Has_Non_Trivial_Precondition;
10981 -------------------
10982 -- Has_Null_Body --
10983 -------------------
10985 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
10986 Body_Id : Entity_Id;
10987 Decl : Node_Id;
10988 Spec : Node_Id;
10989 Stmt1 : Node_Id;
10990 Stmt2 : Node_Id;
10992 begin
10993 Spec := Parent (Proc_Id);
10994 Decl := Parent (Spec);
10996 -- Retrieve the entity of the procedure body (e.g. invariant proc).
10998 if Nkind (Spec) = N_Procedure_Specification
10999 and then Nkind (Decl) = N_Subprogram_Declaration
11000 then
11001 Body_Id := Corresponding_Body (Decl);
11003 -- The body acts as a spec
11005 else
11006 Body_Id := Proc_Id;
11007 end if;
11009 -- The body will be generated later
11011 if No (Body_Id) then
11012 return False;
11013 end if;
11015 Spec := Parent (Body_Id);
11016 Decl := Parent (Spec);
11018 pragma Assert
11019 (Nkind (Spec) = N_Procedure_Specification
11020 and then Nkind (Decl) = N_Subprogram_Body);
11022 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11024 -- Look for a null statement followed by an optional return
11025 -- statement.
11027 if Nkind (Stmt1) = N_Null_Statement then
11028 Stmt2 := Next (Stmt1);
11030 if Present (Stmt2) then
11031 return Nkind (Stmt2) = N_Simple_Return_Statement;
11032 else
11033 return True;
11034 end if;
11035 end if;
11037 return False;
11038 end Has_Null_Body;
11040 ------------------------
11041 -- Has_Null_Exclusion --
11042 ------------------------
11044 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11045 begin
11046 case Nkind (N) is
11047 when N_Access_Definition
11048 | N_Access_Function_Definition
11049 | N_Access_Procedure_Definition
11050 | N_Access_To_Object_Definition
11051 | N_Allocator
11052 | N_Derived_Type_Definition
11053 | N_Function_Specification
11054 | N_Subtype_Declaration
11056 return Null_Exclusion_Present (N);
11058 when N_Component_Definition
11059 | N_Formal_Object_Declaration
11060 | N_Object_Renaming_Declaration
11062 if Present (Subtype_Mark (N)) then
11063 return Null_Exclusion_Present (N);
11064 else pragma Assert (Present (Access_Definition (N)));
11065 return Null_Exclusion_Present (Access_Definition (N));
11066 end if;
11068 when N_Discriminant_Specification =>
11069 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11070 return Null_Exclusion_Present (Discriminant_Type (N));
11071 else
11072 return Null_Exclusion_Present (N);
11073 end if;
11075 when N_Object_Declaration =>
11076 if Nkind (Object_Definition (N)) = N_Access_Definition then
11077 return Null_Exclusion_Present (Object_Definition (N));
11078 else
11079 return Null_Exclusion_Present (N);
11080 end if;
11082 when N_Parameter_Specification =>
11083 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11084 return Null_Exclusion_Present (Parameter_Type (N));
11085 else
11086 return Null_Exclusion_Present (N);
11087 end if;
11089 when others =>
11090 return False;
11091 end case;
11092 end Has_Null_Exclusion;
11094 ------------------------
11095 -- Has_Null_Extension --
11096 ------------------------
11098 function Has_Null_Extension (T : Entity_Id) return Boolean is
11099 B : constant Entity_Id := Base_Type (T);
11100 Comps : Node_Id;
11101 Ext : Node_Id;
11103 begin
11104 if Nkind (Parent (B)) = N_Full_Type_Declaration
11105 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11106 then
11107 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11109 if Present (Ext) then
11110 if Null_Present (Ext) then
11111 return True;
11112 else
11113 Comps := Component_List (Ext);
11115 -- The null component list is rewritten during analysis to
11116 -- include the parent component. Any other component indicates
11117 -- that the extension was not originally null.
11119 return Null_Present (Comps)
11120 or else No (Next (First (Component_Items (Comps))));
11121 end if;
11122 else
11123 return False;
11124 end if;
11126 else
11127 return False;
11128 end if;
11129 end Has_Null_Extension;
11131 -------------------------
11132 -- Has_Null_Refinement --
11133 -------------------------
11135 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11136 Constits : Elist_Id;
11138 begin
11139 pragma Assert (Ekind (Id) = E_Abstract_State);
11140 Constits := Refinement_Constituents (Id);
11142 -- For a refinement to be null, the state's sole constituent must be a
11143 -- null.
11145 return
11146 Present (Constits)
11147 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11148 end Has_Null_Refinement;
11150 -------------------------------
11151 -- Has_Overriding_Initialize --
11152 -------------------------------
11154 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11155 BT : constant Entity_Id := Base_Type (T);
11156 P : Elmt_Id;
11158 begin
11159 if Is_Controlled (BT) then
11160 if Is_RTU (Scope (BT), Ada_Finalization) then
11161 return False;
11163 elsif Present (Primitive_Operations (BT)) then
11164 P := First_Elmt (Primitive_Operations (BT));
11165 while Present (P) loop
11166 declare
11167 Init : constant Entity_Id := Node (P);
11168 Formal : constant Entity_Id := First_Formal (Init);
11169 begin
11170 if Ekind (Init) = E_Procedure
11171 and then Chars (Init) = Name_Initialize
11172 and then Comes_From_Source (Init)
11173 and then Present (Formal)
11174 and then Etype (Formal) = BT
11175 and then No (Next_Formal (Formal))
11176 and then (Ada_Version < Ada_2012
11177 or else not Null_Present (Parent (Init)))
11178 then
11179 return True;
11180 end if;
11181 end;
11183 Next_Elmt (P);
11184 end loop;
11185 end if;
11187 -- Here if type itself does not have a non-null Initialize operation:
11188 -- check immediate ancestor.
11190 if Is_Derived_Type (BT)
11191 and then Has_Overriding_Initialize (Etype (BT))
11192 then
11193 return True;
11194 end if;
11195 end if;
11197 return False;
11198 end Has_Overriding_Initialize;
11200 --------------------------------------
11201 -- Has_Preelaborable_Initialization --
11202 --------------------------------------
11204 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11205 Has_PE : Boolean;
11207 procedure Check_Components (E : Entity_Id);
11208 -- Check component/discriminant chain, sets Has_PE False if a component
11209 -- or discriminant does not meet the preelaborable initialization rules.
11211 ----------------------
11212 -- Check_Components --
11213 ----------------------
11215 procedure Check_Components (E : Entity_Id) is
11216 Ent : Entity_Id;
11217 Exp : Node_Id;
11219 begin
11220 -- Loop through entities of record or protected type
11222 Ent := E;
11223 while Present (Ent) loop
11225 -- We are interested only in components and discriminants
11227 Exp := Empty;
11229 case Ekind (Ent) is
11230 when E_Component =>
11232 -- Get default expression if any. If there is no declaration
11233 -- node, it means we have an internal entity. The parent and
11234 -- tag fields are examples of such entities. For such cases,
11235 -- we just test the type of the entity.
11237 if Present (Declaration_Node (Ent)) then
11238 Exp := Expression (Declaration_Node (Ent));
11239 end if;
11241 when E_Discriminant =>
11243 -- Note: for a renamed discriminant, the Declaration_Node
11244 -- may point to the one from the ancestor, and have a
11245 -- different expression, so use the proper attribute to
11246 -- retrieve the expression from the derived constraint.
11248 Exp := Discriminant_Default_Value (Ent);
11250 when others =>
11251 goto Check_Next_Entity;
11252 end case;
11254 -- A component has PI if it has no default expression and the
11255 -- component type has PI.
11257 if No (Exp) then
11258 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11259 Has_PE := False;
11260 exit;
11261 end if;
11263 -- Require the default expression to be preelaborable
11265 elsif not Is_Preelaborable_Construct (Exp) then
11266 Has_PE := False;
11267 exit;
11268 end if;
11270 <<Check_Next_Entity>>
11271 Next_Entity (Ent);
11272 end loop;
11273 end Check_Components;
11275 -- Start of processing for Has_Preelaborable_Initialization
11277 begin
11278 -- Immediate return if already marked as known preelaborable init. This
11279 -- covers types for which this function has already been called once
11280 -- and returned True (in which case the result is cached), and also
11281 -- types to which a pragma Preelaborable_Initialization applies.
11283 if Known_To_Have_Preelab_Init (E) then
11284 return True;
11285 end if;
11287 -- If the type is a subtype representing a generic actual type, then
11288 -- test whether its base type has preelaborable initialization since
11289 -- the subtype representing the actual does not inherit this attribute
11290 -- from the actual or formal. (but maybe it should???)
11292 if Is_Generic_Actual_Type (E) then
11293 return Has_Preelaborable_Initialization (Base_Type (E));
11294 end if;
11296 -- All elementary types have preelaborable initialization
11298 if Is_Elementary_Type (E) then
11299 Has_PE := True;
11301 -- Array types have PI if the component type has PI
11303 elsif Is_Array_Type (E) then
11304 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11306 -- A derived type has preelaborable initialization if its parent type
11307 -- has preelaborable initialization and (in the case of a derived record
11308 -- extension) if the non-inherited components all have preelaborable
11309 -- initialization. However, a user-defined controlled type with an
11310 -- overriding Initialize procedure does not have preelaborable
11311 -- initialization.
11313 elsif Is_Derived_Type (E) then
11315 -- If the derived type is a private extension then it doesn't have
11316 -- preelaborable initialization.
11318 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11319 return False;
11320 end if;
11322 -- First check whether ancestor type has preelaborable initialization
11324 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11326 -- If OK, check extension components (if any)
11328 if Has_PE and then Is_Record_Type (E) then
11329 Check_Components (First_Entity (E));
11330 end if;
11332 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11333 -- with a user defined Initialize procedure does not have PI. If
11334 -- the type is untagged, the control primitives come from a component
11335 -- that has already been checked.
11337 if Has_PE
11338 and then Is_Controlled (E)
11339 and then Is_Tagged_Type (E)
11340 and then Has_Overriding_Initialize (E)
11341 then
11342 Has_PE := False;
11343 end if;
11345 -- Private types not derived from a type having preelaborable init and
11346 -- that are not marked with pragma Preelaborable_Initialization do not
11347 -- have preelaborable initialization.
11349 elsif Is_Private_Type (E) then
11350 return False;
11352 -- Record type has PI if it is non private and all components have PI
11354 elsif Is_Record_Type (E) then
11355 Has_PE := True;
11356 Check_Components (First_Entity (E));
11358 -- Protected types must not have entries, and components must meet
11359 -- same set of rules as for record components.
11361 elsif Is_Protected_Type (E) then
11362 if Has_Entries (E) then
11363 Has_PE := False;
11364 else
11365 Has_PE := True;
11366 Check_Components (First_Entity (E));
11367 Check_Components (First_Private_Entity (E));
11368 end if;
11370 -- Type System.Address always has preelaborable initialization
11372 elsif Is_RTE (E, RE_Address) then
11373 Has_PE := True;
11375 -- In all other cases, type does not have preelaborable initialization
11377 else
11378 return False;
11379 end if;
11381 -- If type has preelaborable initialization, cache result
11383 if Has_PE then
11384 Set_Known_To_Have_Preelab_Init (E);
11385 end if;
11387 return Has_PE;
11388 end Has_Preelaborable_Initialization;
11390 ---------------------------
11391 -- Has_Private_Component --
11392 ---------------------------
11394 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11395 Btype : Entity_Id := Base_Type (Type_Id);
11396 Component : Entity_Id;
11398 begin
11399 if Error_Posted (Type_Id)
11400 or else Error_Posted (Btype)
11401 then
11402 return False;
11403 end if;
11405 if Is_Class_Wide_Type (Btype) then
11406 Btype := Root_Type (Btype);
11407 end if;
11409 if Is_Private_Type (Btype) then
11410 declare
11411 UT : constant Entity_Id := Underlying_Type (Btype);
11412 begin
11413 if No (UT) then
11414 if No (Full_View (Btype)) then
11415 return not Is_Generic_Type (Btype)
11416 and then
11417 not Is_Generic_Type (Root_Type (Btype));
11418 else
11419 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11420 end if;
11421 else
11422 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11423 end if;
11424 end;
11426 elsif Is_Array_Type (Btype) then
11427 return Has_Private_Component (Component_Type (Btype));
11429 elsif Is_Record_Type (Btype) then
11430 Component := First_Component (Btype);
11431 while Present (Component) loop
11432 if Has_Private_Component (Etype (Component)) then
11433 return True;
11434 end if;
11436 Next_Component (Component);
11437 end loop;
11439 return False;
11441 elsif Is_Protected_Type (Btype)
11442 and then Present (Corresponding_Record_Type (Btype))
11443 then
11444 return Has_Private_Component (Corresponding_Record_Type (Btype));
11446 else
11447 return False;
11448 end if;
11449 end Has_Private_Component;
11451 ----------------------
11452 -- Has_Signed_Zeros --
11453 ----------------------
11455 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11456 begin
11457 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11458 end Has_Signed_Zeros;
11460 ------------------------------
11461 -- Has_Significant_Contract --
11462 ------------------------------
11464 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11465 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11467 begin
11468 -- _Finalizer procedure
11470 if Subp_Nam = Name_uFinalizer then
11471 return False;
11473 -- _Postconditions procedure
11475 elsif Subp_Nam = Name_uPostconditions then
11476 return False;
11478 -- Predicate function
11480 elsif Ekind (Subp_Id) = E_Function
11481 and then Is_Predicate_Function (Subp_Id)
11482 then
11483 return False;
11485 -- TSS subprogram
11487 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11488 return False;
11490 else
11491 return True;
11492 end if;
11493 end Has_Significant_Contract;
11495 -----------------------------
11496 -- Has_Static_Array_Bounds --
11497 -----------------------------
11499 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11500 All_Static : Boolean;
11501 Dummy : Boolean;
11503 begin
11504 Examine_Array_Bounds (Typ, All_Static, Dummy);
11506 return All_Static;
11507 end Has_Static_Array_Bounds;
11509 ---------------------------------------
11510 -- Has_Static_Non_Empty_Array_Bounds --
11511 ---------------------------------------
11513 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
11514 All_Static : Boolean;
11515 Has_Empty : Boolean;
11517 begin
11518 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
11520 return All_Static and not Has_Empty;
11521 end Has_Static_Non_Empty_Array_Bounds;
11523 ----------------
11524 -- Has_Stream --
11525 ----------------
11527 function Has_Stream (T : Entity_Id) return Boolean is
11528 E : Entity_Id;
11530 begin
11531 if No (T) then
11532 return False;
11534 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11535 return True;
11537 elsif Is_Array_Type (T) then
11538 return Has_Stream (Component_Type (T));
11540 elsif Is_Record_Type (T) then
11541 E := First_Component (T);
11542 while Present (E) loop
11543 if Has_Stream (Etype (E)) then
11544 return True;
11545 else
11546 Next_Component (E);
11547 end if;
11548 end loop;
11550 return False;
11552 elsif Is_Private_Type (T) then
11553 return Has_Stream (Underlying_Type (T));
11555 else
11556 return False;
11557 end if;
11558 end Has_Stream;
11560 ----------------
11561 -- Has_Suffix --
11562 ----------------
11564 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11565 begin
11566 Get_Name_String (Chars (E));
11567 return Name_Buffer (Name_Len) = Suffix;
11568 end Has_Suffix;
11570 ----------------
11571 -- Add_Suffix --
11572 ----------------
11574 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11575 begin
11576 Get_Name_String (Chars (E));
11577 Add_Char_To_Name_Buffer (Suffix);
11578 return Name_Find;
11579 end Add_Suffix;
11581 -------------------
11582 -- Remove_Suffix --
11583 -------------------
11585 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11586 begin
11587 pragma Assert (Has_Suffix (E, Suffix));
11588 Get_Name_String (Chars (E));
11589 Name_Len := Name_Len - 1;
11590 return Name_Find;
11591 end Remove_Suffix;
11593 ----------------------------------
11594 -- Replace_Null_By_Null_Address --
11595 ----------------------------------
11597 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11598 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11599 -- Replace operand Op with a reference to Null_Address when the operand
11600 -- denotes a null Address. Other_Op denotes the other operand.
11602 --------------------------
11603 -- Replace_Null_Operand --
11604 --------------------------
11606 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11607 begin
11608 -- Check the type of the complementary operand since the N_Null node
11609 -- has not been decorated yet.
11611 if Nkind (Op) = N_Null
11612 and then Is_Descendant_Of_Address (Etype (Other_Op))
11613 then
11614 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11615 end if;
11616 end Replace_Null_Operand;
11618 -- Start of processing for Replace_Null_By_Null_Address
11620 begin
11621 pragma Assert (Relaxed_RM_Semantics);
11622 pragma Assert (Nkind_In (N, N_Null,
11623 N_Op_Eq,
11624 N_Op_Ge,
11625 N_Op_Gt,
11626 N_Op_Le,
11627 N_Op_Lt,
11628 N_Op_Ne));
11630 if Nkind (N) = N_Null then
11631 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11633 else
11634 declare
11635 L : constant Node_Id := Left_Opnd (N);
11636 R : constant Node_Id := Right_Opnd (N);
11638 begin
11639 Replace_Null_Operand (L, Other_Op => R);
11640 Replace_Null_Operand (R, Other_Op => L);
11641 end;
11642 end if;
11643 end Replace_Null_By_Null_Address;
11645 --------------------------
11646 -- Has_Tagged_Component --
11647 --------------------------
11649 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11650 Comp : Entity_Id;
11652 begin
11653 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11654 return Has_Tagged_Component (Underlying_Type (Typ));
11656 elsif Is_Array_Type (Typ) then
11657 return Has_Tagged_Component (Component_Type (Typ));
11659 elsif Is_Tagged_Type (Typ) then
11660 return True;
11662 elsif Is_Record_Type (Typ) then
11663 Comp := First_Component (Typ);
11664 while Present (Comp) loop
11665 if Has_Tagged_Component (Etype (Comp)) then
11666 return True;
11667 end if;
11669 Next_Component (Comp);
11670 end loop;
11672 return False;
11674 else
11675 return False;
11676 end if;
11677 end Has_Tagged_Component;
11679 -----------------------------
11680 -- Has_Undefined_Reference --
11681 -----------------------------
11683 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11684 Has_Undef_Ref : Boolean := False;
11685 -- Flag set when expression Expr contains at least one undefined
11686 -- reference.
11688 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11689 -- Determine whether N denotes a reference and if it does, whether it is
11690 -- undefined.
11692 ----------------------------
11693 -- Is_Undefined_Reference --
11694 ----------------------------
11696 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11697 begin
11698 if Is_Entity_Name (N)
11699 and then Present (Entity (N))
11700 and then Entity (N) = Any_Id
11701 then
11702 Has_Undef_Ref := True;
11703 return Abandon;
11704 end if;
11706 return OK;
11707 end Is_Undefined_Reference;
11709 procedure Find_Undefined_References is
11710 new Traverse_Proc (Is_Undefined_Reference);
11712 -- Start of processing for Has_Undefined_Reference
11714 begin
11715 Find_Undefined_References (Expr);
11717 return Has_Undef_Ref;
11718 end Has_Undefined_Reference;
11720 ----------------------------
11721 -- Has_Volatile_Component --
11722 ----------------------------
11724 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11725 Comp : Entity_Id;
11727 begin
11728 if Has_Volatile_Components (Typ) then
11729 return True;
11731 elsif Is_Array_Type (Typ) then
11732 return Is_Volatile (Component_Type (Typ));
11734 elsif Is_Record_Type (Typ) then
11735 Comp := First_Component (Typ);
11736 while Present (Comp) loop
11737 if Is_Volatile_Object (Comp) then
11738 return True;
11739 end if;
11741 Comp := Next_Component (Comp);
11742 end loop;
11743 end if;
11745 return False;
11746 end Has_Volatile_Component;
11748 -------------------------
11749 -- Implementation_Kind --
11750 -------------------------
11752 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11753 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11754 Arg : Node_Id;
11755 begin
11756 pragma Assert (Present (Impl_Prag));
11757 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11758 return Chars (Get_Pragma_Arg (Arg));
11759 end Implementation_Kind;
11761 --------------------------
11762 -- Implements_Interface --
11763 --------------------------
11765 function Implements_Interface
11766 (Typ_Ent : Entity_Id;
11767 Iface_Ent : Entity_Id;
11768 Exclude_Parents : Boolean := False) return Boolean
11770 Ifaces_List : Elist_Id;
11771 Elmt : Elmt_Id;
11772 Iface : Entity_Id := Base_Type (Iface_Ent);
11773 Typ : Entity_Id := Base_Type (Typ_Ent);
11775 begin
11776 if Is_Class_Wide_Type (Typ) then
11777 Typ := Root_Type (Typ);
11778 end if;
11780 if not Has_Interfaces (Typ) then
11781 return False;
11782 end if;
11784 if Is_Class_Wide_Type (Iface) then
11785 Iface := Root_Type (Iface);
11786 end if;
11788 Collect_Interfaces (Typ, Ifaces_List);
11790 Elmt := First_Elmt (Ifaces_List);
11791 while Present (Elmt) loop
11792 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
11793 and then Exclude_Parents
11794 then
11795 null;
11797 elsif Node (Elmt) = Iface then
11798 return True;
11799 end if;
11801 Next_Elmt (Elmt);
11802 end loop;
11804 return False;
11805 end Implements_Interface;
11807 ------------------------------------
11808 -- In_Assertion_Expression_Pragma --
11809 ------------------------------------
11811 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
11812 Par : Node_Id;
11813 Prag : Node_Id := Empty;
11815 begin
11816 -- Climb the parent chain looking for an enclosing pragma
11818 Par := N;
11819 while Present (Par) loop
11820 if Nkind (Par) = N_Pragma then
11821 Prag := Par;
11822 exit;
11824 -- Precondition-like pragmas are expanded into if statements, check
11825 -- the original node instead.
11827 elsif Nkind (Original_Node (Par)) = N_Pragma then
11828 Prag := Original_Node (Par);
11829 exit;
11831 -- The expansion of attribute 'Old generates a constant to capture
11832 -- the result of the prefix. If the parent traversal reaches
11833 -- one of these constants, then the node technically came from a
11834 -- postcondition-like pragma. Note that the Ekind is not tested here
11835 -- because N may be the expression of an object declaration which is
11836 -- currently being analyzed. Such objects carry Ekind of E_Void.
11838 elsif Nkind (Par) = N_Object_Declaration
11839 and then Constant_Present (Par)
11840 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
11841 then
11842 return True;
11844 -- Prevent the search from going too far
11846 elsif Is_Body_Or_Package_Declaration (Par) then
11847 return False;
11848 end if;
11850 Par := Parent (Par);
11851 end loop;
11853 return
11854 Present (Prag)
11855 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
11856 end In_Assertion_Expression_Pragma;
11858 ----------------------
11859 -- In_Generic_Scope --
11860 ----------------------
11862 function In_Generic_Scope (E : Entity_Id) return Boolean is
11863 S : Entity_Id;
11865 begin
11866 S := Scope (E);
11867 while Present (S) and then S /= Standard_Standard loop
11868 if Is_Generic_Unit (S) then
11869 return True;
11870 end if;
11872 S := Scope (S);
11873 end loop;
11875 return False;
11876 end In_Generic_Scope;
11878 -----------------
11879 -- In_Instance --
11880 -----------------
11882 function In_Instance return Boolean is
11883 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
11884 S : Entity_Id;
11886 begin
11887 S := Current_Scope;
11888 while Present (S) and then S /= Standard_Standard loop
11889 if Is_Generic_Instance (S) then
11891 -- A child instance is always compiled in the context of a parent
11892 -- instance. Nevertheless, the actuals are not analyzed in an
11893 -- instance context. We detect this case by examining the current
11894 -- compilation unit, which must be a child instance, and checking
11895 -- that it is not currently on the scope stack.
11897 if Is_Child_Unit (Curr_Unit)
11898 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
11899 N_Package_Instantiation
11900 and then not In_Open_Scopes (Curr_Unit)
11901 then
11902 return False;
11903 else
11904 return True;
11905 end if;
11906 end if;
11908 S := Scope (S);
11909 end loop;
11911 return False;
11912 end In_Instance;
11914 ----------------------
11915 -- In_Instance_Body --
11916 ----------------------
11918 function In_Instance_Body return Boolean is
11919 S : Entity_Id;
11921 begin
11922 S := Current_Scope;
11923 while Present (S) and then S /= Standard_Standard loop
11924 if Ekind_In (S, E_Function, E_Procedure)
11925 and then Is_Generic_Instance (S)
11926 then
11927 return True;
11929 elsif Ekind (S) = E_Package
11930 and then In_Package_Body (S)
11931 and then Is_Generic_Instance (S)
11932 then
11933 return True;
11934 end if;
11936 S := Scope (S);
11937 end loop;
11939 return False;
11940 end In_Instance_Body;
11942 -----------------------------
11943 -- In_Instance_Not_Visible --
11944 -----------------------------
11946 function In_Instance_Not_Visible return Boolean is
11947 S : Entity_Id;
11949 begin
11950 S := Current_Scope;
11951 while Present (S) and then S /= Standard_Standard loop
11952 if Ekind_In (S, E_Function, E_Procedure)
11953 and then Is_Generic_Instance (S)
11954 then
11955 return True;
11957 elsif Ekind (S) = E_Package
11958 and then (In_Package_Body (S) or else In_Private_Part (S))
11959 and then Is_Generic_Instance (S)
11960 then
11961 return True;
11962 end if;
11964 S := Scope (S);
11965 end loop;
11967 return False;
11968 end In_Instance_Not_Visible;
11970 ------------------------------
11971 -- In_Instance_Visible_Part --
11972 ------------------------------
11974 function In_Instance_Visible_Part
11975 (Id : Entity_Id := Current_Scope) return Boolean
11977 Inst : Entity_Id;
11979 begin
11980 Inst := Id;
11981 while Present (Inst) and then Inst /= Standard_Standard loop
11982 if Ekind (Inst) = E_Package
11983 and then Is_Generic_Instance (Inst)
11984 and then not In_Package_Body (Inst)
11985 and then not In_Private_Part (Inst)
11986 then
11987 return True;
11988 end if;
11990 Inst := Scope (Inst);
11991 end loop;
11993 return False;
11994 end In_Instance_Visible_Part;
11996 ---------------------
11997 -- In_Package_Body --
11998 ---------------------
12000 function In_Package_Body return Boolean is
12001 S : Entity_Id;
12003 begin
12004 S := Current_Scope;
12005 while Present (S) and then S /= Standard_Standard loop
12006 if Ekind (S) = E_Package and then In_Package_Body (S) then
12007 return True;
12008 else
12009 S := Scope (S);
12010 end if;
12011 end loop;
12013 return False;
12014 end In_Package_Body;
12016 --------------------------
12017 -- In_Pragma_Expression --
12018 --------------------------
12020 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12021 P : Node_Id;
12022 begin
12023 P := Parent (N);
12024 loop
12025 if No (P) then
12026 return False;
12027 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12028 return True;
12029 else
12030 P := Parent (P);
12031 end if;
12032 end loop;
12033 end In_Pragma_Expression;
12035 ---------------------------
12036 -- In_Pre_Post_Condition --
12037 ---------------------------
12039 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12040 Par : Node_Id;
12041 Prag : Node_Id := Empty;
12042 Prag_Id : Pragma_Id;
12044 begin
12045 -- Climb the parent chain looking for an enclosing pragma
12047 Par := N;
12048 while Present (Par) loop
12049 if Nkind (Par) = N_Pragma then
12050 Prag := Par;
12051 exit;
12053 -- Prevent the search from going too far
12055 elsif Is_Body_Or_Package_Declaration (Par) then
12056 exit;
12057 end if;
12059 Par := Parent (Par);
12060 end loop;
12062 if Present (Prag) then
12063 Prag_Id := Get_Pragma_Id (Prag);
12065 return
12066 Prag_Id = Pragma_Post
12067 or else Prag_Id = Pragma_Post_Class
12068 or else Prag_Id = Pragma_Postcondition
12069 or else Prag_Id = Pragma_Pre
12070 or else Prag_Id = Pragma_Pre_Class
12071 or else Prag_Id = Pragma_Precondition;
12073 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12075 else
12076 return False;
12077 end if;
12078 end In_Pre_Post_Condition;
12080 -------------------------------------
12081 -- In_Reverse_Storage_Order_Object --
12082 -------------------------------------
12084 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12085 Pref : Node_Id;
12086 Btyp : Entity_Id := Empty;
12088 begin
12089 -- Climb up indexed components
12091 Pref := N;
12092 loop
12093 case Nkind (Pref) is
12094 when N_Selected_Component =>
12095 Pref := Prefix (Pref);
12096 exit;
12098 when N_Indexed_Component =>
12099 Pref := Prefix (Pref);
12101 when others =>
12102 Pref := Empty;
12103 exit;
12104 end case;
12105 end loop;
12107 if Present (Pref) then
12108 Btyp := Base_Type (Etype (Pref));
12109 end if;
12111 return Present (Btyp)
12112 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12113 and then Reverse_Storage_Order (Btyp);
12114 end In_Reverse_Storage_Order_Object;
12116 ------------------------------
12117 -- In_Same_Declarative_Part --
12118 ------------------------------
12120 function In_Same_Declarative_Part
12121 (Context : Node_Id;
12122 N : Node_Id) return Boolean
12124 Cont : Node_Id := Context;
12125 Nod : Node_Id;
12127 begin
12128 if Nkind (Cont) = N_Compilation_Unit_Aux then
12129 Cont := Parent (Cont);
12130 end if;
12132 Nod := Parent (N);
12133 while Present (Nod) loop
12134 if Nod = Cont then
12135 return True;
12137 elsif Nkind_In (Nod, N_Accept_Statement,
12138 N_Block_Statement,
12139 N_Compilation_Unit,
12140 N_Entry_Body,
12141 N_Package_Body,
12142 N_Package_Declaration,
12143 N_Protected_Body,
12144 N_Subprogram_Body,
12145 N_Task_Body)
12146 then
12147 return False;
12149 elsif Nkind (Nod) = N_Subunit then
12150 Nod := Corresponding_Stub (Nod);
12152 else
12153 Nod := Parent (Nod);
12154 end if;
12155 end loop;
12157 return False;
12158 end In_Same_Declarative_Part;
12160 --------------------------------------
12161 -- In_Subprogram_Or_Concurrent_Unit --
12162 --------------------------------------
12164 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12165 E : Entity_Id;
12166 K : Entity_Kind;
12168 begin
12169 -- Use scope chain to check successively outer scopes
12171 E := Current_Scope;
12172 loop
12173 K := Ekind (E);
12175 if K in Subprogram_Kind
12176 or else K in Concurrent_Kind
12177 or else K in Generic_Subprogram_Kind
12178 then
12179 return True;
12181 elsif E = Standard_Standard then
12182 return False;
12183 end if;
12185 E := Scope (E);
12186 end loop;
12187 end In_Subprogram_Or_Concurrent_Unit;
12189 ----------------
12190 -- In_Subtree --
12191 ----------------
12193 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12194 Curr : Node_Id;
12196 begin
12197 Curr := N;
12198 while Present (Curr) loop
12199 if Curr = Root then
12200 return True;
12201 end if;
12203 Curr := Parent (Curr);
12204 end loop;
12206 return False;
12207 end In_Subtree;
12209 ----------------
12210 -- In_Subtree --
12211 ----------------
12213 function In_Subtree
12214 (N : Node_Id;
12215 Root1 : Node_Id;
12216 Root2 : Node_Id) return Boolean
12218 Curr : Node_Id;
12220 begin
12221 Curr := N;
12222 while Present (Curr) loop
12223 if Curr = Root1 or else Curr = Root2 then
12224 return True;
12225 end if;
12227 Curr := Parent (Curr);
12228 end loop;
12230 return False;
12231 end In_Subtree;
12233 ---------------------
12234 -- In_Visible_Part --
12235 ---------------------
12237 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12238 begin
12239 return Is_Package_Or_Generic_Package (Scope_Id)
12240 and then In_Open_Scopes (Scope_Id)
12241 and then not In_Package_Body (Scope_Id)
12242 and then not In_Private_Part (Scope_Id);
12243 end In_Visible_Part;
12245 --------------------------------
12246 -- Incomplete_Or_Partial_View --
12247 --------------------------------
12249 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12250 function Inspect_Decls
12251 (Decls : List_Id;
12252 Taft : Boolean := False) return Entity_Id;
12253 -- Check whether a declarative region contains the incomplete or partial
12254 -- view of Id.
12256 -------------------
12257 -- Inspect_Decls --
12258 -------------------
12260 function Inspect_Decls
12261 (Decls : List_Id;
12262 Taft : Boolean := False) return Entity_Id
12264 Decl : Node_Id;
12265 Match : Node_Id;
12267 begin
12268 Decl := First (Decls);
12269 while Present (Decl) loop
12270 Match := Empty;
12272 -- The partial view of a Taft-amendment type is an incomplete
12273 -- type.
12275 if Taft then
12276 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12277 Match := Defining_Identifier (Decl);
12278 end if;
12280 -- Otherwise look for a private type whose full view matches the
12281 -- input type. Note that this checks full_type_declaration nodes
12282 -- to account for derivations from a private type where the type
12283 -- declaration hold the partial view and the full view is an
12284 -- itype.
12286 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12287 N_Private_Extension_Declaration,
12288 N_Private_Type_Declaration)
12289 then
12290 Match := Defining_Identifier (Decl);
12291 end if;
12293 -- Guard against unanalyzed entities
12295 if Present (Match)
12296 and then Is_Type (Match)
12297 and then Present (Full_View (Match))
12298 and then Full_View (Match) = Id
12299 then
12300 return Match;
12301 end if;
12303 Next (Decl);
12304 end loop;
12306 return Empty;
12307 end Inspect_Decls;
12309 -- Local variables
12311 Prev : Entity_Id;
12313 -- Start of processing for Incomplete_Or_Partial_View
12315 begin
12316 -- Deferred constant or incomplete type case
12318 Prev := Current_Entity_In_Scope (Id);
12320 if Present (Prev)
12321 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12322 and then Present (Full_View (Prev))
12323 and then Full_View (Prev) = Id
12324 then
12325 return Prev;
12326 end if;
12328 -- Private or Taft amendment type case
12330 declare
12331 Pkg : constant Entity_Id := Scope (Id);
12332 Pkg_Decl : Node_Id := Pkg;
12334 begin
12335 if Present (Pkg)
12336 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12337 then
12338 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12339 Pkg_Decl := Parent (Pkg_Decl);
12340 end loop;
12342 -- It is knows that Typ has a private view, look for it in the
12343 -- visible declarations of the enclosing scope. A special case
12344 -- of this is when the two views have been exchanged - the full
12345 -- appears earlier than the private.
12347 if Has_Private_Declaration (Id) then
12348 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12350 -- Exchanged view case, look in the private declarations
12352 if No (Prev) then
12353 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12354 end if;
12356 return Prev;
12358 -- Otherwise if this is the package body, then Typ is a potential
12359 -- Taft amendment type. The incomplete view should be located in
12360 -- the private declarations of the enclosing scope.
12362 elsif In_Package_Body (Pkg) then
12363 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12364 end if;
12365 end if;
12366 end;
12368 -- The type has no incomplete or private view
12370 return Empty;
12371 end Incomplete_Or_Partial_View;
12373 ---------------------------------------
12374 -- Incomplete_View_From_Limited_With --
12375 ---------------------------------------
12377 function Incomplete_View_From_Limited_With
12378 (Typ : Entity_Id) return Entity_Id
12380 begin
12381 -- It might make sense to make this an attribute in Einfo, and set it
12382 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12383 -- slots for new attributes, and it seems a bit simpler to just search
12384 -- the Limited_View (if it exists) for an incomplete type whose
12385 -- Non_Limited_View is Typ.
12387 if Ekind (Scope (Typ)) = E_Package
12388 and then Present (Limited_View (Scope (Typ)))
12389 then
12390 declare
12391 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12392 begin
12393 while Present (Ent) loop
12394 if Ekind (Ent) in Incomplete_Kind
12395 and then Non_Limited_View (Ent) = Typ
12396 then
12397 return Ent;
12398 end if;
12400 Ent := Next_Entity (Ent);
12401 end loop;
12402 end;
12403 end if;
12405 return Typ;
12406 end Incomplete_View_From_Limited_With;
12408 ----------------------------------
12409 -- Indexed_Component_Bit_Offset --
12410 ----------------------------------
12412 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12413 Exp : constant Node_Id := First (Expressions (N));
12414 Typ : constant Entity_Id := Etype (Prefix (N));
12415 Off : constant Uint := Component_Size (Typ);
12416 Ind : Node_Id;
12418 begin
12419 -- Return early if the component size is not known or variable
12421 if Off = No_Uint or else Off < Uint_0 then
12422 return No_Uint;
12423 end if;
12425 -- Deal with the degenerate case of an empty component
12427 if Off = Uint_0 then
12428 return Off;
12429 end if;
12431 -- Check that both the index value and the low bound are known
12433 if not Compile_Time_Known_Value (Exp) then
12434 return No_Uint;
12435 end if;
12437 Ind := First_Index (Typ);
12438 if No (Ind) then
12439 return No_Uint;
12440 end if;
12442 if Nkind (Ind) = N_Subtype_Indication then
12443 Ind := Constraint (Ind);
12445 if Nkind (Ind) = N_Range_Constraint then
12446 Ind := Range_Expression (Ind);
12447 end if;
12448 end if;
12450 if Nkind (Ind) /= N_Range
12451 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12452 then
12453 return No_Uint;
12454 end if;
12456 -- Return the scaled offset
12458 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12459 end Indexed_Component_Bit_Offset;
12461 ----------------------------
12462 -- Inherit_Rep_Item_Chain --
12463 ----------------------------
12465 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12466 Item : Node_Id;
12467 Next_Item : Node_Id;
12469 begin
12470 -- There are several inheritance scenarios to consider depending on
12471 -- whether both types have rep item chains and whether the destination
12472 -- type already inherits part of the source type's rep item chain.
12474 -- 1) The source type lacks a rep item chain
12475 -- From_Typ ---> Empty
12477 -- Typ --------> Item (or Empty)
12479 -- In this case inheritance cannot take place because there are no items
12480 -- to inherit.
12482 -- 2) The destination type lacks a rep item chain
12483 -- From_Typ ---> Item ---> ...
12485 -- Typ --------> Empty
12487 -- Inheritance takes place by setting the First_Rep_Item of the
12488 -- destination type to the First_Rep_Item of the source type.
12489 -- From_Typ ---> Item ---> ...
12490 -- ^
12491 -- Typ -----------+
12493 -- 3.1) Both source and destination types have at least one rep item.
12494 -- The destination type does NOT inherit a rep item from the source
12495 -- type.
12496 -- From_Typ ---> Item ---> Item
12498 -- Typ --------> Item ---> Item
12500 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12501 -- of the destination type to the First_Rep_Item of the source type.
12502 -- From_Typ -------------------> Item ---> Item
12503 -- ^
12504 -- Typ --------> Item ---> Item --+
12506 -- 3.2) Both source and destination types have at least one rep item.
12507 -- The destination type DOES inherit part of the rep item chain of the
12508 -- source type.
12509 -- From_Typ ---> Item ---> Item ---> Item
12510 -- ^
12511 -- Typ --------> Item ------+
12513 -- This rare case arises when the full view of a private extension must
12514 -- inherit the rep item chain from the full view of its parent type and
12515 -- the full view of the parent type contains extra rep items. Currently
12516 -- only invariants may lead to such form of inheritance.
12518 -- type From_Typ is tagged private
12519 -- with Type_Invariant'Class => Item_2;
12521 -- type Typ is new From_Typ with private
12522 -- with Type_Invariant => Item_4;
12524 -- At this point the rep item chains contain the following items
12526 -- From_Typ -----------> Item_2 ---> Item_3
12527 -- ^
12528 -- Typ --------> Item_4 --+
12530 -- The full views of both types may introduce extra invariants
12532 -- type From_Typ is tagged null record
12533 -- with Type_Invariant => Item_1;
12535 -- type Typ is new From_Typ with null record;
12537 -- The full view of Typ would have to inherit any new rep items added to
12538 -- the full view of From_Typ.
12540 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12541 -- ^
12542 -- Typ --------> Item_4 --+
12544 -- To achieve this form of inheritance, the destination type must first
12545 -- sever the link between its own rep chain and that of the source type,
12546 -- then inheritance 3.1 takes place.
12548 -- Case 1: The source type lacks a rep item chain
12550 if No (First_Rep_Item (From_Typ)) then
12551 return;
12553 -- Case 2: The destination type lacks a rep item chain
12555 elsif No (First_Rep_Item (Typ)) then
12556 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12558 -- Case 3: Both the source and destination types have at least one rep
12559 -- item. Traverse the rep item chain of the destination type to find the
12560 -- last rep item.
12562 else
12563 Item := Empty;
12564 Next_Item := First_Rep_Item (Typ);
12565 while Present (Next_Item) loop
12567 -- Detect a link between the destination type's rep chain and that
12568 -- of the source type. There are two possibilities:
12570 -- Variant 1
12571 -- Next_Item
12572 -- V
12573 -- From_Typ ---> Item_1 --->
12574 -- ^
12575 -- Typ -----------+
12577 -- Item is Empty
12579 -- Variant 2
12580 -- Next_Item
12581 -- V
12582 -- From_Typ ---> Item_1 ---> Item_2 --->
12583 -- ^
12584 -- Typ --------> Item_3 ------+
12585 -- ^
12586 -- Item
12588 if Has_Rep_Item (From_Typ, Next_Item) then
12589 exit;
12590 end if;
12592 Item := Next_Item;
12593 Next_Item := Next_Rep_Item (Next_Item);
12594 end loop;
12596 -- Inherit the source type's rep item chain
12598 if Present (Item) then
12599 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12600 else
12601 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12602 end if;
12603 end if;
12604 end Inherit_Rep_Item_Chain;
12606 ---------------------------------
12607 -- Insert_Explicit_Dereference --
12608 ---------------------------------
12610 procedure Insert_Explicit_Dereference (N : Node_Id) is
12611 New_Prefix : constant Node_Id := Relocate_Node (N);
12612 Ent : Entity_Id := Empty;
12613 Pref : Node_Id;
12614 I : Interp_Index;
12615 It : Interp;
12616 T : Entity_Id;
12618 begin
12619 Save_Interps (N, New_Prefix);
12621 Rewrite (N,
12622 Make_Explicit_Dereference (Sloc (Parent (N)),
12623 Prefix => New_Prefix));
12625 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12627 if Is_Overloaded (New_Prefix) then
12629 -- The dereference is also overloaded, and its interpretations are
12630 -- the designated types of the interpretations of the original node.
12632 Set_Etype (N, Any_Type);
12634 Get_First_Interp (New_Prefix, I, It);
12635 while Present (It.Nam) loop
12636 T := It.Typ;
12638 if Is_Access_Type (T) then
12639 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12640 end if;
12642 Get_Next_Interp (I, It);
12643 end loop;
12645 End_Interp_List;
12647 else
12648 -- Prefix is unambiguous: mark the original prefix (which might
12649 -- Come_From_Source) as a reference, since the new (relocated) one
12650 -- won't be taken into account.
12652 if Is_Entity_Name (New_Prefix) then
12653 Ent := Entity (New_Prefix);
12654 Pref := New_Prefix;
12656 -- For a retrieval of a subcomponent of some composite object,
12657 -- retrieve the ultimate entity if there is one.
12659 elsif Nkind_In (New_Prefix, N_Selected_Component,
12660 N_Indexed_Component)
12661 then
12662 Pref := Prefix (New_Prefix);
12663 while Present (Pref)
12664 and then Nkind_In (Pref, N_Selected_Component,
12665 N_Indexed_Component)
12666 loop
12667 Pref := Prefix (Pref);
12668 end loop;
12670 if Present (Pref) and then Is_Entity_Name (Pref) then
12671 Ent := Entity (Pref);
12672 end if;
12673 end if;
12675 -- Place the reference on the entity node
12677 if Present (Ent) then
12678 Generate_Reference (Ent, Pref);
12679 end if;
12680 end if;
12681 end Insert_Explicit_Dereference;
12683 ------------------------------------------
12684 -- Inspect_Deferred_Constant_Completion --
12685 ------------------------------------------
12687 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12688 Decl : Node_Id;
12690 begin
12691 Decl := First (Decls);
12692 while Present (Decl) loop
12694 -- Deferred constant signature
12696 if Nkind (Decl) = N_Object_Declaration
12697 and then Constant_Present (Decl)
12698 and then No (Expression (Decl))
12700 -- No need to check internally generated constants
12702 and then Comes_From_Source (Decl)
12704 -- The constant is not completed. A full object declaration or a
12705 -- pragma Import complete a deferred constant.
12707 and then not Has_Completion (Defining_Identifier (Decl))
12708 then
12709 Error_Msg_N
12710 ("constant declaration requires initialization expression",
12711 Defining_Identifier (Decl));
12712 end if;
12714 Decl := Next (Decl);
12715 end loop;
12716 end Inspect_Deferred_Constant_Completion;
12718 -------------------------------
12719 -- Install_Elaboration_Model --
12720 -------------------------------
12722 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
12723 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
12724 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
12725 -- Empty if there is no such pragma.
12727 ------------------------------------
12728 -- Find_Elaboration_Checks_Pragma --
12729 ------------------------------------
12731 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
12732 Item : Node_Id;
12734 begin
12735 Item := First (L);
12736 while Present (Item) loop
12737 if Nkind (Item) = N_Pragma
12738 and then Pragma_Name (Item) = Name_Elaboration_Checks
12739 then
12740 return Item;
12741 end if;
12743 Next (Item);
12744 end loop;
12746 return Empty;
12747 end Find_Elaboration_Checks_Pragma;
12749 -- Local variables
12751 Args : List_Id;
12752 Model : Node_Id;
12753 Prag : Node_Id;
12754 Unit : Node_Id;
12756 -- Start of processing for Install_Elaboration_Model
12758 begin
12759 -- Nothing to do when the unit does not exist
12761 if No (Unit_Id) then
12762 return;
12763 end if;
12765 Unit := Parent (Unit_Declaration_Node (Unit_Id));
12767 -- Nothing to do when the unit is not a library unit
12769 if Nkind (Unit) /= N_Compilation_Unit then
12770 return;
12771 end if;
12773 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
12775 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
12776 -- elaboration model as specified by the pragma.
12778 if Present (Prag) then
12779 Args := Pragma_Argument_Associations (Prag);
12781 -- Guard against an illegal pragma. The sole argument must be an
12782 -- identifier which specifies either Dynamic or Static model.
12784 if Present (Args) then
12785 Model := Get_Pragma_Arg (First (Args));
12787 if Nkind (Model) = N_Identifier then
12788 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
12789 end if;
12790 end if;
12791 end if;
12792 end Install_Elaboration_Model;
12794 -----------------------------
12795 -- Install_Generic_Formals --
12796 -----------------------------
12798 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
12799 E : Entity_Id;
12801 begin
12802 pragma Assert (Is_Generic_Subprogram (Subp_Id));
12804 E := First_Entity (Subp_Id);
12805 while Present (E) loop
12806 Install_Entity (E);
12807 Next_Entity (E);
12808 end loop;
12809 end Install_Generic_Formals;
12811 ------------------------
12812 -- Install_SPARK_Mode --
12813 ------------------------
12815 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
12816 begin
12817 SPARK_Mode := Mode;
12818 SPARK_Mode_Pragma := Prag;
12819 end Install_SPARK_Mode;
12821 --------------------------
12822 -- Invalid_Scalar_Value --
12823 --------------------------
12825 function Invalid_Scalar_Value
12826 (Loc : Source_Ptr;
12827 Scal_Typ : Scalar_Id) return Node_Id
12829 function Invalid_Binder_Value return Node_Id;
12830 -- Return a reference to the corresponding invalid value for type
12831 -- Scal_Typ as defined in unit System.Scalar_Values.
12833 function Invalid_Float_Value return Node_Id;
12834 -- Return the invalid value of float type Scal_Typ
12836 function Invalid_Integer_Value return Node_Id;
12837 -- Return the invalid value of integer type Scal_Typ
12839 procedure Set_Invalid_Binder_Values;
12840 -- Set the contents of collection Invalid_Binder_Values
12842 --------------------------
12843 -- Invalid_Binder_Value --
12844 --------------------------
12846 function Invalid_Binder_Value return Node_Id is
12847 Val_Id : Entity_Id;
12849 begin
12850 -- Initialize the collection of invalid binder values the first time
12851 -- around.
12853 Set_Invalid_Binder_Values;
12855 -- Obtain the corresponding variable from System.Scalar_Values which
12856 -- holds the invalid value for this type.
12858 Val_Id := Invalid_Binder_Values (Scal_Typ);
12859 pragma Assert (Present (Val_Id));
12861 return New_Occurrence_Of (Val_Id, Loc);
12862 end Invalid_Binder_Value;
12864 -------------------------
12865 -- Invalid_Float_Value --
12866 -------------------------
12868 function Invalid_Float_Value return Node_Id is
12869 Value : constant Ureal := Invalid_Floats (Scal_Typ);
12871 begin
12872 -- Pragma Invalid_Scalars did not specify an invalid value for this
12873 -- type. Fall back to the value provided by the binder.
12875 if Value = No_Ureal then
12876 return Invalid_Binder_Value;
12877 else
12878 return Make_Real_Literal (Loc, Realval => Value);
12879 end if;
12880 end Invalid_Float_Value;
12882 ---------------------------
12883 -- Invalid_Integer_Value --
12884 ---------------------------
12886 function Invalid_Integer_Value return Node_Id is
12887 Value : constant Uint := Invalid_Integers (Scal_Typ);
12889 begin
12890 -- Pragma Invalid_Scalars did not specify an invalid value for this
12891 -- type. Fall back to the value provided by the binder.
12893 if Value = No_Uint then
12894 return Invalid_Binder_Value;
12895 else
12896 return Make_Integer_Literal (Loc, Intval => Value);
12897 end if;
12898 end Invalid_Integer_Value;
12900 -------------------------------
12901 -- Set_Invalid_Binder_Values --
12902 -------------------------------
12904 procedure Set_Invalid_Binder_Values is
12905 begin
12906 if not Invalid_Binder_Values_Set then
12907 Invalid_Binder_Values_Set := True;
12909 -- Initialize the contents of the collection once since RTE calls
12910 -- are not cheap.
12912 Invalid_Binder_Values :=
12913 (Name_Short_Float => RTE (RE_IS_Isf),
12914 Name_Float => RTE (RE_IS_Ifl),
12915 Name_Long_Float => RTE (RE_IS_Ilf),
12916 Name_Long_Long_Float => RTE (RE_IS_Ill),
12917 Name_Signed_8 => RTE (RE_IS_Is1),
12918 Name_Signed_16 => RTE (RE_IS_Is2),
12919 Name_Signed_32 => RTE (RE_IS_Is4),
12920 Name_Signed_64 => RTE (RE_IS_Is8),
12921 Name_Unsigned_8 => RTE (RE_IS_Iu1),
12922 Name_Unsigned_16 => RTE (RE_IS_Iu2),
12923 Name_Unsigned_32 => RTE (RE_IS_Iu4),
12924 Name_Unsigned_64 => RTE (RE_IS_Iu8));
12925 end if;
12926 end Set_Invalid_Binder_Values;
12928 -- Start of processing for Invalid_Scalar_Value
12930 begin
12931 if Scal_Typ in Float_Scalar_Id then
12932 return Invalid_Float_Value;
12934 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
12935 return Invalid_Integer_Value;
12936 end if;
12937 end Invalid_Scalar_Value;
12939 -----------------------------
12940 -- Is_Actual_Out_Parameter --
12941 -----------------------------
12943 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
12944 Formal : Entity_Id;
12945 Call : Node_Id;
12946 begin
12947 Find_Actual (N, Formal, Call);
12948 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
12949 end Is_Actual_Out_Parameter;
12951 -------------------------
12952 -- Is_Actual_Parameter --
12953 -------------------------
12955 function Is_Actual_Parameter (N : Node_Id) return Boolean is
12956 PK : constant Node_Kind := Nkind (Parent (N));
12958 begin
12959 case PK is
12960 when N_Parameter_Association =>
12961 return N = Explicit_Actual_Parameter (Parent (N));
12963 when N_Subprogram_Call =>
12964 return Is_List_Member (N)
12965 and then
12966 List_Containing (N) = Parameter_Associations (Parent (N));
12968 when others =>
12969 return False;
12970 end case;
12971 end Is_Actual_Parameter;
12973 --------------------------------
12974 -- Is_Actual_Tagged_Parameter --
12975 --------------------------------
12977 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
12978 Formal : Entity_Id;
12979 Call : Node_Id;
12980 begin
12981 Find_Actual (N, Formal, Call);
12982 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
12983 end Is_Actual_Tagged_Parameter;
12985 ---------------------
12986 -- Is_Aliased_View --
12987 ---------------------
12989 function Is_Aliased_View (Obj : Node_Id) return Boolean is
12990 E : Entity_Id;
12992 begin
12993 if Is_Entity_Name (Obj) then
12994 E := Entity (Obj);
12996 return
12997 (Is_Object (E)
12998 and then
12999 (Is_Aliased (E)
13000 or else (Present (Renamed_Object (E))
13001 and then Is_Aliased_View (Renamed_Object (E)))))
13003 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13004 and then Is_Tagged_Type (Etype (E)))
13006 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13008 -- Current instance of type, either directly or as rewritten
13009 -- reference to the current object.
13011 or else (Is_Entity_Name (Original_Node (Obj))
13012 and then Present (Entity (Original_Node (Obj)))
13013 and then Is_Type (Entity (Original_Node (Obj))))
13015 or else (Is_Type (E) and then E = Current_Scope)
13017 or else (Is_Incomplete_Or_Private_Type (E)
13018 and then Full_View (E) = Current_Scope)
13020 -- Ada 2012 AI05-0053: the return object of an extended return
13021 -- statement is aliased if its type is immutably limited.
13023 or else (Is_Return_Object (E)
13024 and then Is_Limited_View (Etype (E)));
13026 elsif Nkind (Obj) = N_Selected_Component then
13027 return Is_Aliased (Entity (Selector_Name (Obj)));
13029 elsif Nkind (Obj) = N_Indexed_Component then
13030 return Has_Aliased_Components (Etype (Prefix (Obj)))
13031 or else
13032 (Is_Access_Type (Etype (Prefix (Obj)))
13033 and then Has_Aliased_Components
13034 (Designated_Type (Etype (Prefix (Obj)))));
13036 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13037 return Is_Tagged_Type (Etype (Obj))
13038 and then Is_Aliased_View (Expression (Obj));
13040 elsif Nkind (Obj) = N_Explicit_Dereference then
13041 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13043 else
13044 return False;
13045 end if;
13046 end Is_Aliased_View;
13048 -------------------------
13049 -- Is_Ancestor_Package --
13050 -------------------------
13052 function Is_Ancestor_Package
13053 (E1 : Entity_Id;
13054 E2 : Entity_Id) return Boolean
13056 Par : Entity_Id;
13058 begin
13059 Par := E2;
13060 while Present (Par) and then Par /= Standard_Standard loop
13061 if Par = E1 then
13062 return True;
13063 end if;
13065 Par := Scope (Par);
13066 end loop;
13068 return False;
13069 end Is_Ancestor_Package;
13071 ----------------------
13072 -- Is_Atomic_Object --
13073 ----------------------
13075 function Is_Atomic_Object (N : Node_Id) return Boolean is
13077 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
13078 -- Determines if given object has atomic components
13080 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
13081 -- If prefix is an implicit dereference, examine designated type
13083 ----------------------
13084 -- Is_Atomic_Prefix --
13085 ----------------------
13087 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
13088 begin
13089 if Is_Access_Type (Etype (N)) then
13090 return
13091 Has_Atomic_Components (Designated_Type (Etype (N)));
13092 else
13093 return Object_Has_Atomic_Components (N);
13094 end if;
13095 end Is_Atomic_Prefix;
13097 ----------------------------------
13098 -- Object_Has_Atomic_Components --
13099 ----------------------------------
13101 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
13102 begin
13103 if Has_Atomic_Components (Etype (N))
13104 or else Is_Atomic (Etype (N))
13105 then
13106 return True;
13108 elsif Is_Entity_Name (N)
13109 and then (Has_Atomic_Components (Entity (N))
13110 or else Is_Atomic (Entity (N)))
13111 then
13112 return True;
13114 elsif Nkind (N) = N_Selected_Component
13115 and then Is_Atomic (Entity (Selector_Name (N)))
13116 then
13117 return True;
13119 elsif Nkind (N) = N_Indexed_Component
13120 or else Nkind (N) = N_Selected_Component
13121 then
13122 return Is_Atomic_Prefix (Prefix (N));
13124 else
13125 return False;
13126 end if;
13127 end Object_Has_Atomic_Components;
13129 -- Start of processing for Is_Atomic_Object
13131 begin
13132 -- Predicate is not relevant to subprograms
13134 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
13135 return False;
13137 elsif Is_Atomic (Etype (N))
13138 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
13139 then
13140 return True;
13142 elsif Nkind (N) = N_Selected_Component
13143 and then Is_Atomic (Entity (Selector_Name (N)))
13144 then
13145 return True;
13147 elsif Nkind (N) = N_Indexed_Component
13148 or else Nkind (N) = N_Selected_Component
13149 then
13150 return Is_Atomic_Prefix (Prefix (N));
13152 else
13153 return False;
13154 end if;
13155 end Is_Atomic_Object;
13157 -----------------------------
13158 -- Is_Atomic_Or_VFA_Object --
13159 -----------------------------
13161 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13162 begin
13163 return Is_Atomic_Object (N)
13164 or else (Is_Object_Reference (N)
13165 and then Is_Entity_Name (N)
13166 and then (Is_Volatile_Full_Access (Entity (N))
13167 or else
13168 Is_Volatile_Full_Access (Etype (Entity (N)))));
13169 end Is_Atomic_Or_VFA_Object;
13171 -------------------------
13172 -- Is_Attribute_Result --
13173 -------------------------
13175 function Is_Attribute_Result (N : Node_Id) return Boolean is
13176 begin
13177 return Nkind (N) = N_Attribute_Reference
13178 and then Attribute_Name (N) = Name_Result;
13179 end Is_Attribute_Result;
13181 -------------------------
13182 -- Is_Attribute_Update --
13183 -------------------------
13185 function Is_Attribute_Update (N : Node_Id) return Boolean is
13186 begin
13187 return Nkind (N) = N_Attribute_Reference
13188 and then Attribute_Name (N) = Name_Update;
13189 end Is_Attribute_Update;
13191 ------------------------------------
13192 -- Is_Body_Or_Package_Declaration --
13193 ------------------------------------
13195 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13196 begin
13197 return Nkind_In (N, N_Entry_Body,
13198 N_Package_Body,
13199 N_Package_Declaration,
13200 N_Protected_Body,
13201 N_Subprogram_Body,
13202 N_Task_Body);
13203 end Is_Body_Or_Package_Declaration;
13205 -----------------------
13206 -- Is_Bounded_String --
13207 -----------------------
13209 function Is_Bounded_String (T : Entity_Id) return Boolean is
13210 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13212 begin
13213 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13214 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13215 -- be True for all the Bounded_String types in instances of the
13216 -- Generic_Bounded_Length generics, and for types derived from those.
13218 return Present (Under)
13219 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13220 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13221 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13222 end Is_Bounded_String;
13224 ---------------------
13225 -- Is_CCT_Instance --
13226 ---------------------
13228 function Is_CCT_Instance
13229 (Ref_Id : Entity_Id;
13230 Context_Id : Entity_Id) return Boolean
13232 begin
13233 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13235 if Is_Single_Task_Object (Context_Id) then
13236 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13238 else
13239 pragma Assert (Ekind_In (Context_Id, E_Entry,
13240 E_Entry_Family,
13241 E_Function,
13242 E_Package,
13243 E_Procedure,
13244 E_Protected_Type,
13245 E_Task_Type)
13246 or else
13247 Is_Record_Type (Context_Id));
13248 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13249 end if;
13250 end Is_CCT_Instance;
13252 -------------------------
13253 -- Is_Child_Or_Sibling --
13254 -------------------------
13256 function Is_Child_Or_Sibling
13257 (Pack_1 : Entity_Id;
13258 Pack_2 : Entity_Id) return Boolean
13260 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13261 -- Given an arbitrary package, return the number of "climbs" necessary
13262 -- to reach scope Standard_Standard.
13264 procedure Equalize_Depths
13265 (Pack : in out Entity_Id;
13266 Depth : in out Nat;
13267 Depth_To_Reach : Nat);
13268 -- Given an arbitrary package, its depth and a target depth to reach,
13269 -- climb the scope chain until the said depth is reached. The pointer
13270 -- to the package and its depth a modified during the climb.
13272 ----------------------------
13273 -- Distance_From_Standard --
13274 ----------------------------
13276 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13277 Dist : Nat;
13278 Scop : Entity_Id;
13280 begin
13281 Dist := 0;
13282 Scop := Pack;
13283 while Present (Scop) and then Scop /= Standard_Standard loop
13284 Dist := Dist + 1;
13285 Scop := Scope (Scop);
13286 end loop;
13288 return Dist;
13289 end Distance_From_Standard;
13291 ---------------------
13292 -- Equalize_Depths --
13293 ---------------------
13295 procedure Equalize_Depths
13296 (Pack : in out Entity_Id;
13297 Depth : in out Nat;
13298 Depth_To_Reach : Nat)
13300 begin
13301 -- The package must be at a greater or equal depth
13303 if Depth < Depth_To_Reach then
13304 raise Program_Error;
13305 end if;
13307 -- Climb the scope chain until the desired depth is reached
13309 while Present (Pack) and then Depth /= Depth_To_Reach loop
13310 Pack := Scope (Pack);
13311 Depth := Depth - 1;
13312 end loop;
13313 end Equalize_Depths;
13315 -- Local variables
13317 P_1 : Entity_Id := Pack_1;
13318 P_1_Child : Boolean := False;
13319 P_1_Depth : Nat := Distance_From_Standard (P_1);
13320 P_2 : Entity_Id := Pack_2;
13321 P_2_Child : Boolean := False;
13322 P_2_Depth : Nat := Distance_From_Standard (P_2);
13324 -- Start of processing for Is_Child_Or_Sibling
13326 begin
13327 pragma Assert
13328 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13330 -- Both packages denote the same entity, therefore they cannot be
13331 -- children or siblings.
13333 if P_1 = P_2 then
13334 return False;
13336 -- One of the packages is at a deeper level than the other. Note that
13337 -- both may still come from different hierarchies.
13339 -- (root) P_2
13340 -- / \ :
13341 -- X P_2 or X
13342 -- : :
13343 -- P_1 P_1
13345 elsif P_1_Depth > P_2_Depth then
13346 Equalize_Depths
13347 (Pack => P_1,
13348 Depth => P_1_Depth,
13349 Depth_To_Reach => P_2_Depth);
13350 P_1_Child := True;
13352 -- (root) P_1
13353 -- / \ :
13354 -- P_1 X or X
13355 -- : :
13356 -- P_2 P_2
13358 elsif P_2_Depth > P_1_Depth then
13359 Equalize_Depths
13360 (Pack => P_2,
13361 Depth => P_2_Depth,
13362 Depth_To_Reach => P_1_Depth);
13363 P_2_Child := True;
13364 end if;
13366 -- At this stage the package pointers have been elevated to the same
13367 -- depth. If the related entities are the same, then one package is a
13368 -- potential child of the other:
13370 -- P_1
13371 -- :
13372 -- X became P_1 P_2 or vice versa
13373 -- :
13374 -- P_2
13376 if P_1 = P_2 then
13377 if P_1_Child then
13378 return Is_Child_Unit (Pack_1);
13380 else pragma Assert (P_2_Child);
13381 return Is_Child_Unit (Pack_2);
13382 end if;
13384 -- The packages may come from the same package chain or from entirely
13385 -- different hierarcies. To determine this, climb the scope stack until
13386 -- a common root is found.
13388 -- (root) (root 1) (root 2)
13389 -- / \ | |
13390 -- P_1 P_2 P_1 P_2
13392 else
13393 while Present (P_1) and then Present (P_2) loop
13395 -- The two packages may be siblings
13397 if P_1 = P_2 then
13398 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13399 end if;
13401 P_1 := Scope (P_1);
13402 P_2 := Scope (P_2);
13403 end loop;
13404 end if;
13406 return False;
13407 end Is_Child_Or_Sibling;
13409 -----------------------------
13410 -- Is_Concurrent_Interface --
13411 -----------------------------
13413 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13414 begin
13415 return Is_Interface (T)
13416 and then
13417 (Is_Protected_Interface (T)
13418 or else Is_Synchronized_Interface (T)
13419 or else Is_Task_Interface (T));
13420 end Is_Concurrent_Interface;
13422 -----------------------
13423 -- Is_Constant_Bound --
13424 -----------------------
13426 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13427 begin
13428 if Compile_Time_Known_Value (Exp) then
13429 return True;
13431 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13432 return Is_Constant_Object (Entity (Exp))
13433 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13435 elsif Nkind (Exp) in N_Binary_Op then
13436 return Is_Constant_Bound (Left_Opnd (Exp))
13437 and then Is_Constant_Bound (Right_Opnd (Exp))
13438 and then Scope (Entity (Exp)) = Standard_Standard;
13440 else
13441 return False;
13442 end if;
13443 end Is_Constant_Bound;
13445 ---------------------------
13446 -- Is_Container_Element --
13447 ---------------------------
13449 function Is_Container_Element (Exp : Node_Id) return Boolean is
13450 Loc : constant Source_Ptr := Sloc (Exp);
13451 Pref : constant Node_Id := Prefix (Exp);
13453 Call : Node_Id;
13454 -- Call to an indexing aspect
13456 Cont_Typ : Entity_Id;
13457 -- The type of the container being accessed
13459 Elem_Typ : Entity_Id;
13460 -- Its element type
13462 Indexing : Entity_Id;
13463 Is_Const : Boolean;
13464 -- Indicates that constant indexing is used, and the element is thus
13465 -- a constant.
13467 Ref_Typ : Entity_Id;
13468 -- The reference type returned by the indexing operation
13470 begin
13471 -- If C is a container, in a context that imposes the element type of
13472 -- that container, the indexing notation C (X) is rewritten as:
13474 -- Indexing (C, X).Discr.all
13476 -- where Indexing is one of the indexing aspects of the container.
13477 -- If the context does not require a reference, the construct can be
13478 -- rewritten as
13480 -- Element (C, X)
13482 -- First, verify that the construct has the proper form
13484 if not Expander_Active then
13485 return False;
13487 elsif Nkind (Pref) /= N_Selected_Component then
13488 return False;
13490 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13491 return False;
13493 else
13494 Call := Prefix (Pref);
13495 Ref_Typ := Etype (Call);
13496 end if;
13498 if not Has_Implicit_Dereference (Ref_Typ)
13499 or else No (First (Parameter_Associations (Call)))
13500 or else not Is_Entity_Name (Name (Call))
13501 then
13502 return False;
13503 end if;
13505 -- Retrieve type of container object, and its iterator aspects
13507 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13508 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13509 Is_Const := False;
13511 if No (Indexing) then
13513 -- Container should have at least one indexing operation
13515 return False;
13517 elsif Entity (Name (Call)) /= Entity (Indexing) then
13519 -- This may be a variable indexing operation
13521 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13523 if No (Indexing)
13524 or else Entity (Name (Call)) /= Entity (Indexing)
13525 then
13526 return False;
13527 end if;
13529 else
13530 Is_Const := True;
13531 end if;
13533 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13535 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13536 return False;
13537 end if;
13539 -- Check that the expression is not the target of an assignment, in
13540 -- which case the rewriting is not possible.
13542 if not Is_Const then
13543 declare
13544 Par : Node_Id;
13546 begin
13547 Par := Exp;
13548 while Present (Par)
13549 loop
13550 if Nkind (Parent (Par)) = N_Assignment_Statement
13551 and then Par = Name (Parent (Par))
13552 then
13553 return False;
13555 -- A renaming produces a reference, and the transformation
13556 -- does not apply.
13558 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13559 return False;
13561 elsif Nkind_In
13562 (Nkind (Parent (Par)), N_Function_Call,
13563 N_Procedure_Call_Statement,
13564 N_Entry_Call_Statement)
13565 then
13566 -- Check that the element is not part of an actual for an
13567 -- in-out parameter.
13569 declare
13570 F : Entity_Id;
13571 A : Node_Id;
13573 begin
13574 F := First_Formal (Entity (Name (Parent (Par))));
13575 A := First (Parameter_Associations (Parent (Par)));
13576 while Present (F) loop
13577 if A = Par and then Ekind (F) /= E_In_Parameter then
13578 return False;
13579 end if;
13581 Next_Formal (F);
13582 Next (A);
13583 end loop;
13584 end;
13586 -- E_In_Parameter in a call: element is not modified.
13588 exit;
13589 end if;
13591 Par := Parent (Par);
13592 end loop;
13593 end;
13594 end if;
13596 -- The expression has the proper form and the context requires the
13597 -- element type. Retrieve the Element function of the container and
13598 -- rewrite the construct as a call to it.
13600 declare
13601 Op : Elmt_Id;
13603 begin
13604 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13605 while Present (Op) loop
13606 exit when Chars (Node (Op)) = Name_Element;
13607 Next_Elmt (Op);
13608 end loop;
13610 if No (Op) then
13611 return False;
13613 else
13614 Rewrite (Exp,
13615 Make_Function_Call (Loc,
13616 Name => New_Occurrence_Of (Node (Op), Loc),
13617 Parameter_Associations => Parameter_Associations (Call)));
13618 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13619 return True;
13620 end if;
13621 end;
13622 end Is_Container_Element;
13624 ----------------------------
13625 -- Is_Contract_Annotation --
13626 ----------------------------
13628 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13629 begin
13630 return Is_Package_Contract_Annotation (Item)
13631 or else
13632 Is_Subprogram_Contract_Annotation (Item);
13633 end Is_Contract_Annotation;
13635 --------------------------------------
13636 -- Is_Controlling_Limited_Procedure --
13637 --------------------------------------
13639 function Is_Controlling_Limited_Procedure
13640 (Proc_Nam : Entity_Id) return Boolean
13642 Param : Node_Id;
13643 Param_Typ : Entity_Id := Empty;
13645 begin
13646 if Ekind (Proc_Nam) = E_Procedure
13647 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13648 then
13649 Param :=
13650 Parameter_Type
13651 (First (Parameter_Specifications (Parent (Proc_Nam))));
13653 -- The formal may be an anonymous access type
13655 if Nkind (Param) = N_Access_Definition then
13656 Param_Typ := Entity (Subtype_Mark (Param));
13657 else
13658 Param_Typ := Etype (Param);
13659 end if;
13661 -- In the case where an Itype was created for a dispatchin call, the
13662 -- procedure call has been rewritten. The actual may be an access to
13663 -- interface type in which case it is the designated type that is the
13664 -- controlling type.
13666 elsif Present (Associated_Node_For_Itype (Proc_Nam))
13667 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
13668 and then
13669 Present (Parameter_Associations
13670 (Associated_Node_For_Itype (Proc_Nam)))
13671 then
13672 Param_Typ :=
13673 Etype (First (Parameter_Associations
13674 (Associated_Node_For_Itype (Proc_Nam))));
13676 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
13677 Param_Typ := Directly_Designated_Type (Param_Typ);
13678 end if;
13679 end if;
13681 if Present (Param_Typ) then
13682 return
13683 Is_Interface (Param_Typ)
13684 and then Is_Limited_Record (Param_Typ);
13685 end if;
13687 return False;
13688 end Is_Controlling_Limited_Procedure;
13690 -----------------------------
13691 -- Is_CPP_Constructor_Call --
13692 -----------------------------
13694 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
13695 begin
13696 return Nkind (N) = N_Function_Call
13697 and then Is_CPP_Class (Etype (Etype (N)))
13698 and then Is_Constructor (Entity (Name (N)))
13699 and then Is_Imported (Entity (Name (N)));
13700 end Is_CPP_Constructor_Call;
13702 -------------------------
13703 -- Is_Current_Instance --
13704 -------------------------
13706 function Is_Current_Instance (N : Node_Id) return Boolean is
13707 Typ : constant Entity_Id := Entity (N);
13708 P : Node_Id;
13710 begin
13711 -- Simplest case: entity is a concurrent type and we are currently
13712 -- inside the body. This will eventually be expanded into a call to
13713 -- Self (for tasks) or _object (for protected objects).
13715 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13716 return True;
13718 else
13719 -- Check whether the context is a (sub)type declaration for the
13720 -- type entity.
13722 P := Parent (N);
13723 while Present (P) loop
13724 if Nkind_In (P, N_Full_Type_Declaration,
13725 N_Private_Type_Declaration,
13726 N_Subtype_Declaration)
13727 and then Comes_From_Source (P)
13728 and then Defining_Entity (P) = Typ
13729 then
13730 return True;
13732 -- A subtype name may appear in an aspect specification for a
13733 -- Predicate_Failure aspect, for which we do not construct a
13734 -- wrapper procedure. The subtype will be replaced by the
13735 -- expression being tested when the corresponding predicate
13736 -- check is expanded.
13738 elsif Nkind (P) = N_Aspect_Specification
13739 and then Nkind (Parent (P)) = N_Subtype_Declaration
13740 then
13741 return True;
13743 elsif Nkind (P) = N_Pragma
13744 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
13745 then
13746 return True;
13747 end if;
13749 P := Parent (P);
13750 end loop;
13751 end if;
13753 -- In any other context this is not a current occurrence
13755 return False;
13756 end Is_Current_Instance;
13758 --------------------
13759 -- Is_Declaration --
13760 --------------------
13762 function Is_Declaration
13763 (N : Node_Id;
13764 Body_OK : Boolean := True;
13765 Concurrent_OK : Boolean := True;
13766 Formal_OK : Boolean := True;
13767 Generic_OK : Boolean := True;
13768 Instantiation_OK : Boolean := True;
13769 Renaming_OK : Boolean := True;
13770 Stub_OK : Boolean := True;
13771 Subprogram_OK : Boolean := True;
13772 Type_OK : Boolean := True) return Boolean
13774 begin
13775 case Nkind (N) is
13777 -- Body declarations
13779 when N_Proper_Body =>
13780 return Body_OK;
13782 -- Concurrent type declarations
13784 when N_Protected_Type_Declaration
13785 | N_Single_Protected_Declaration
13786 | N_Single_Task_Declaration
13787 | N_Task_Type_Declaration
13789 return Concurrent_OK or Type_OK;
13791 -- Formal declarations
13793 when N_Formal_Abstract_Subprogram_Declaration
13794 | N_Formal_Concrete_Subprogram_Declaration
13795 | N_Formal_Object_Declaration
13796 | N_Formal_Package_Declaration
13797 | N_Formal_Type_Declaration
13799 return Formal_OK;
13801 -- Generic declarations
13803 when N_Generic_Package_Declaration
13804 | N_Generic_Subprogram_Declaration
13806 return Generic_OK;
13808 -- Generic instantiations
13810 when N_Function_Instantiation
13811 | N_Package_Instantiation
13812 | N_Procedure_Instantiation
13814 return Instantiation_OK;
13816 -- Generic renaming declarations
13818 when N_Generic_Renaming_Declaration =>
13819 return Generic_OK or Renaming_OK;
13821 -- Renaming declarations
13823 when N_Exception_Renaming_Declaration
13824 | N_Object_Renaming_Declaration
13825 | N_Package_Renaming_Declaration
13826 | N_Subprogram_Renaming_Declaration
13828 return Renaming_OK;
13830 -- Stub declarations
13832 when N_Body_Stub =>
13833 return Stub_OK;
13835 -- Subprogram declarations
13837 when N_Abstract_Subprogram_Declaration
13838 | N_Entry_Declaration
13839 | N_Expression_Function
13840 | N_Subprogram_Declaration
13842 return Subprogram_OK;
13844 -- Type declarations
13846 when N_Full_Type_Declaration
13847 | N_Incomplete_Type_Declaration
13848 | N_Private_Extension_Declaration
13849 | N_Private_Type_Declaration
13850 | N_Subtype_Declaration
13852 return Type_OK;
13854 -- Miscellaneous
13856 when N_Component_Declaration
13857 | N_Exception_Declaration
13858 | N_Implicit_Label_Declaration
13859 | N_Number_Declaration
13860 | N_Object_Declaration
13861 | N_Package_Declaration
13863 return True;
13865 when others =>
13866 return False;
13867 end case;
13868 end Is_Declaration;
13870 --------------------------------
13871 -- Is_Declared_Within_Variant --
13872 --------------------------------
13874 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
13875 Comp_Decl : constant Node_Id := Parent (Comp);
13876 Comp_List : constant Node_Id := Parent (Comp_Decl);
13877 begin
13878 return Nkind (Parent (Comp_List)) = N_Variant;
13879 end Is_Declared_Within_Variant;
13881 ----------------------------------------------
13882 -- Is_Dependent_Component_Of_Mutable_Object --
13883 ----------------------------------------------
13885 function Is_Dependent_Component_Of_Mutable_Object
13886 (Object : Node_Id) return Boolean
13888 P : Node_Id;
13889 Prefix_Type : Entity_Id;
13890 P_Aliased : Boolean := False;
13891 Comp : Entity_Id;
13893 Deref : Node_Id := Object;
13894 -- Dereference node, in something like X.all.Y(2)
13896 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
13898 begin
13899 -- Find the dereference node if any
13901 while Nkind_In (Deref, N_Indexed_Component,
13902 N_Selected_Component,
13903 N_Slice)
13904 loop
13905 Deref := Prefix (Deref);
13906 end loop;
13908 -- Ada 2005: If we have a component or slice of a dereference,
13909 -- something like X.all.Y (2), and the type of X is access-to-constant,
13910 -- Is_Variable will return False, because it is indeed a constant
13911 -- view. But it might be a view of a variable object, so we want the
13912 -- following condition to be True in that case.
13914 if Is_Variable (Object)
13915 or else (Ada_Version >= Ada_2005
13916 and then Nkind (Deref) = N_Explicit_Dereference)
13917 then
13918 if Nkind (Object) = N_Selected_Component then
13919 P := Prefix (Object);
13920 Prefix_Type := Etype (P);
13922 if Is_Entity_Name (P) then
13923 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
13924 Prefix_Type := Base_Type (Prefix_Type);
13925 end if;
13927 if Is_Aliased (Entity (P)) then
13928 P_Aliased := True;
13929 end if;
13931 -- A discriminant check on a selected component may be expanded
13932 -- into a dereference when removing side effects. Recover the
13933 -- original node and its type, which may be unconstrained.
13935 elsif Nkind (P) = N_Explicit_Dereference
13936 and then not (Comes_From_Source (P))
13937 then
13938 P := Original_Node (P);
13939 Prefix_Type := Etype (P);
13941 else
13942 -- Check for prefix being an aliased component???
13944 null;
13946 end if;
13948 -- A heap object is constrained by its initial value
13950 -- Ada 2005 (AI-363): Always assume the object could be mutable in
13951 -- the dereferenced case, since the access value might denote an
13952 -- unconstrained aliased object, whereas in Ada 95 the designated
13953 -- object is guaranteed to be constrained. A worst-case assumption
13954 -- has to apply in Ada 2005 because we can't tell at compile
13955 -- time whether the object is "constrained by its initial value",
13956 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
13957 -- rules (these rules are acknowledged to need fixing). We don't
13958 -- impose this more stringent checking for earlier Ada versions or
13959 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
13960 -- benefit, though it's unclear on why using -gnat95 would not be
13961 -- sufficient???).
13963 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
13964 if Is_Access_Type (Prefix_Type)
13965 or else Nkind (P) = N_Explicit_Dereference
13966 then
13967 return False;
13968 end if;
13970 else pragma Assert (Ada_Version >= Ada_2005);
13971 if Is_Access_Type (Prefix_Type) then
13973 -- If the access type is pool-specific, and there is no
13974 -- constrained partial view of the designated type, then the
13975 -- designated object is known to be constrained.
13977 if Ekind (Prefix_Type) = E_Access_Type
13978 and then not Object_Type_Has_Constrained_Partial_View
13979 (Typ => Designated_Type (Prefix_Type),
13980 Scop => Current_Scope)
13981 then
13982 return False;
13984 -- Otherwise (general access type, or there is a constrained
13985 -- partial view of the designated type), we need to check
13986 -- based on the designated type.
13988 else
13989 Prefix_Type := Designated_Type (Prefix_Type);
13990 end if;
13991 end if;
13992 end if;
13994 Comp :=
13995 Original_Record_Component (Entity (Selector_Name (Object)));
13997 -- As per AI-0017, the renaming is illegal in a generic body, even
13998 -- if the subtype is indefinite.
14000 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14002 if not Is_Constrained (Prefix_Type)
14003 and then (Is_Definite_Subtype (Prefix_Type)
14004 or else
14005 (Is_Generic_Type (Prefix_Type)
14006 and then Ekind (Current_Scope) = E_Generic_Package
14007 and then In_Package_Body (Current_Scope)))
14009 and then (Is_Declared_Within_Variant (Comp)
14010 or else Has_Discriminant_Dependent_Constraint (Comp))
14011 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14012 then
14013 return True;
14015 -- If the prefix is of an access type at this point, then we want
14016 -- to return False, rather than calling this function recursively
14017 -- on the access object (which itself might be a discriminant-
14018 -- dependent component of some other object, but that isn't
14019 -- relevant to checking the object passed to us). This avoids
14020 -- issuing wrong errors when compiling with -gnatc, where there
14021 -- can be implicit dereferences that have not been expanded.
14023 elsif Is_Access_Type (Etype (Prefix (Object))) then
14024 return False;
14026 else
14027 return
14028 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14029 end if;
14031 elsif Nkind (Object) = N_Indexed_Component
14032 or else Nkind (Object) = N_Slice
14033 then
14034 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14036 -- A type conversion that Is_Variable is a view conversion:
14037 -- go back to the denoted object.
14039 elsif Nkind (Object) = N_Type_Conversion then
14040 return
14041 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14042 end if;
14043 end if;
14045 return False;
14046 end Is_Dependent_Component_Of_Mutable_Object;
14048 ---------------------
14049 -- Is_Dereferenced --
14050 ---------------------
14052 function Is_Dereferenced (N : Node_Id) return Boolean is
14053 P : constant Node_Id := Parent (N);
14054 begin
14055 return Nkind_In (P, N_Selected_Component,
14056 N_Explicit_Dereference,
14057 N_Indexed_Component,
14058 N_Slice)
14059 and then Prefix (P) = N;
14060 end Is_Dereferenced;
14062 ----------------------
14063 -- Is_Descendant_Of --
14064 ----------------------
14066 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14067 T : Entity_Id;
14068 Etyp : Entity_Id;
14070 begin
14071 pragma Assert (Nkind (T1) in N_Entity);
14072 pragma Assert (Nkind (T2) in N_Entity);
14074 T := Base_Type (T1);
14076 -- Immediate return if the types match
14078 if T = T2 then
14079 return True;
14081 -- Comment needed here ???
14083 elsif Ekind (T) = E_Class_Wide_Type then
14084 return Etype (T) = T2;
14086 -- All other cases
14088 else
14089 loop
14090 Etyp := Etype (T);
14092 -- Done if we found the type we are looking for
14094 if Etyp = T2 then
14095 return True;
14097 -- Done if no more derivations to check
14099 elsif T = T1
14100 or else T = Etyp
14101 then
14102 return False;
14104 -- Following test catches error cases resulting from prev errors
14106 elsif No (Etyp) then
14107 return False;
14109 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14110 return False;
14112 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14113 return False;
14114 end if;
14116 T := Base_Type (Etyp);
14117 end loop;
14118 end if;
14119 end Is_Descendant_Of;
14121 ----------------------------------------
14122 -- Is_Descendant_Of_Suspension_Object --
14123 ----------------------------------------
14125 function Is_Descendant_Of_Suspension_Object
14126 (Typ : Entity_Id) return Boolean
14128 Cur_Typ : Entity_Id;
14129 Par_Typ : Entity_Id;
14131 begin
14132 -- Climb the type derivation chain checking each parent type against
14133 -- Suspension_Object.
14135 Cur_Typ := Base_Type (Typ);
14136 while Present (Cur_Typ) loop
14137 Par_Typ := Etype (Cur_Typ);
14139 -- The current type is a match
14141 if Is_Suspension_Object (Cur_Typ) then
14142 return True;
14144 -- Stop the traversal once the root of the derivation chain has been
14145 -- reached. In that case the current type is its own base type.
14147 elsif Cur_Typ = Par_Typ then
14148 exit;
14149 end if;
14151 Cur_Typ := Base_Type (Par_Typ);
14152 end loop;
14154 return False;
14155 end Is_Descendant_Of_Suspension_Object;
14157 ---------------------------------------------
14158 -- Is_Double_Precision_Floating_Point_Type --
14159 ---------------------------------------------
14161 function Is_Double_Precision_Floating_Point_Type
14162 (E : Entity_Id) return Boolean is
14163 begin
14164 return Is_Floating_Point_Type (E)
14165 and then Machine_Radix_Value (E) = Uint_2
14166 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14167 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14168 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14169 end Is_Double_Precision_Floating_Point_Type;
14171 -----------------------------
14172 -- Is_Effectively_Volatile --
14173 -----------------------------
14175 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14176 begin
14177 if Is_Type (Id) then
14179 -- An arbitrary type is effectively volatile when it is subject to
14180 -- pragma Atomic or Volatile.
14182 if Is_Volatile (Id) then
14183 return True;
14185 -- An array type is effectively volatile when it is subject to pragma
14186 -- Atomic_Components or Volatile_Components or its component type is
14187 -- effectively volatile.
14189 elsif Is_Array_Type (Id) then
14190 declare
14191 Anc : Entity_Id := Base_Type (Id);
14192 begin
14193 if Is_Private_Type (Anc) then
14194 Anc := Full_View (Anc);
14195 end if;
14197 -- Test for presence of ancestor, as the full view of a private
14198 -- type may be missing in case of error.
14200 return
14201 Has_Volatile_Components (Id)
14202 or else
14203 (Present (Anc)
14204 and then Is_Effectively_Volatile (Component_Type (Anc)));
14205 end;
14207 -- A protected type is always volatile
14209 elsif Is_Protected_Type (Id) then
14210 return True;
14212 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14213 -- automatically volatile.
14215 elsif Is_Descendant_Of_Suspension_Object (Id) then
14216 return True;
14218 -- Otherwise the type is not effectively volatile
14220 else
14221 return False;
14222 end if;
14224 -- Otherwise Id denotes an object
14226 else
14227 return
14228 Is_Volatile (Id)
14229 or else Has_Volatile_Components (Id)
14230 or else Is_Effectively_Volatile (Etype (Id));
14231 end if;
14232 end Is_Effectively_Volatile;
14234 ------------------------------------
14235 -- Is_Effectively_Volatile_Object --
14236 ------------------------------------
14238 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14239 begin
14240 if Is_Entity_Name (N) then
14241 return Is_Effectively_Volatile (Entity (N));
14243 elsif Nkind (N) = N_Indexed_Component then
14244 return Is_Effectively_Volatile_Object (Prefix (N));
14246 elsif Nkind (N) = N_Selected_Component then
14247 return
14248 Is_Effectively_Volatile_Object (Prefix (N))
14249 or else
14250 Is_Effectively_Volatile_Object (Selector_Name (N));
14252 else
14253 return False;
14254 end if;
14255 end Is_Effectively_Volatile_Object;
14257 -------------------
14258 -- Is_Entry_Body --
14259 -------------------
14261 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14262 begin
14263 return
14264 Ekind_In (Id, E_Entry, E_Entry_Family)
14265 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14266 end Is_Entry_Body;
14268 --------------------------
14269 -- Is_Entry_Declaration --
14270 --------------------------
14272 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14273 begin
14274 return
14275 Ekind_In (Id, E_Entry, E_Entry_Family)
14276 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14277 end Is_Entry_Declaration;
14279 ------------------------------------
14280 -- Is_Expanded_Priority_Attribute --
14281 ------------------------------------
14283 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14284 begin
14285 return
14286 Nkind (E) = N_Function_Call
14287 and then not Configurable_Run_Time_Mode
14288 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14289 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14290 end Is_Expanded_Priority_Attribute;
14292 ----------------------------
14293 -- Is_Expression_Function --
14294 ----------------------------
14296 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14297 begin
14298 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14299 return
14300 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14301 N_Expression_Function;
14302 else
14303 return False;
14304 end if;
14305 end Is_Expression_Function;
14307 ------------------------------------------
14308 -- Is_Expression_Function_Or_Completion --
14309 ------------------------------------------
14311 function Is_Expression_Function_Or_Completion
14312 (Subp : Entity_Id) return Boolean
14314 Subp_Decl : Node_Id;
14316 begin
14317 if Ekind (Subp) = E_Function then
14318 Subp_Decl := Unit_Declaration_Node (Subp);
14320 -- The function declaration is either an expression function or is
14321 -- completed by an expression function body.
14323 return
14324 Is_Expression_Function (Subp)
14325 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
14326 and then Present (Corresponding_Body (Subp_Decl))
14327 and then Is_Expression_Function
14328 (Corresponding_Body (Subp_Decl)));
14330 elsif Ekind (Subp) = E_Subprogram_Body then
14331 return Is_Expression_Function (Subp);
14333 else
14334 return False;
14335 end if;
14336 end Is_Expression_Function_Or_Completion;
14338 -----------------------
14339 -- Is_EVF_Expression --
14340 -----------------------
14342 function Is_EVF_Expression (N : Node_Id) return Boolean is
14343 Orig_N : constant Node_Id := Original_Node (N);
14344 Alt : Node_Id;
14345 Expr : Node_Id;
14346 Id : Entity_Id;
14348 begin
14349 -- Detect a reference to a formal parameter of a specific tagged type
14350 -- whose related subprogram is subject to pragma Expresions_Visible with
14351 -- value "False".
14353 if Is_Entity_Name (N) and then Present (Entity (N)) then
14354 Id := Entity (N);
14356 return
14357 Is_Formal (Id)
14358 and then Is_Specific_Tagged_Type (Etype (Id))
14359 and then Extensions_Visible_Status (Id) =
14360 Extensions_Visible_False;
14362 -- A case expression is an EVF expression when it contains at least one
14363 -- EVF dependent_expression. Note that a case expression may have been
14364 -- expanded, hence the use of Original_Node.
14366 elsif Nkind (Orig_N) = N_Case_Expression then
14367 Alt := First (Alternatives (Orig_N));
14368 while Present (Alt) loop
14369 if Is_EVF_Expression (Expression (Alt)) then
14370 return True;
14371 end if;
14373 Next (Alt);
14374 end loop;
14376 -- An if expression is an EVF expression when it contains at least one
14377 -- EVF dependent_expression. Note that an if expression may have been
14378 -- expanded, hence the use of Original_Node.
14380 elsif Nkind (Orig_N) = N_If_Expression then
14381 Expr := Next (First (Expressions (Orig_N)));
14382 while Present (Expr) loop
14383 if Is_EVF_Expression (Expr) then
14384 return True;
14385 end if;
14387 Next (Expr);
14388 end loop;
14390 -- A qualified expression or a type conversion is an EVF expression when
14391 -- its operand is an EVF expression.
14393 elsif Nkind_In (N, N_Qualified_Expression,
14394 N_Unchecked_Type_Conversion,
14395 N_Type_Conversion)
14396 then
14397 return Is_EVF_Expression (Expression (N));
14399 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14400 -- their prefix denotes an EVF expression.
14402 elsif Nkind (N) = N_Attribute_Reference
14403 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
14404 Name_Old,
14405 Name_Update)
14406 then
14407 return Is_EVF_Expression (Prefix (N));
14408 end if;
14410 return False;
14411 end Is_EVF_Expression;
14413 --------------
14414 -- Is_False --
14415 --------------
14417 function Is_False (U : Uint) return Boolean is
14418 begin
14419 return (U = 0);
14420 end Is_False;
14422 ---------------------------
14423 -- Is_Fixed_Model_Number --
14424 ---------------------------
14426 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
14427 S : constant Ureal := Small_Value (T);
14428 M : Urealp.Save_Mark;
14429 R : Boolean;
14431 begin
14432 M := Urealp.Mark;
14433 R := (U = UR_Trunc (U / S) * S);
14434 Urealp.Release (M);
14435 return R;
14436 end Is_Fixed_Model_Number;
14438 -------------------------------
14439 -- Is_Fully_Initialized_Type --
14440 -------------------------------
14442 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
14443 begin
14444 -- Scalar types
14446 if Is_Scalar_Type (Typ) then
14448 -- A scalar type with an aspect Default_Value is fully initialized
14450 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14451 -- of a scalar type, but we don't take that into account here, since
14452 -- we don't want these to affect warnings.
14454 return Has_Default_Aspect (Typ);
14456 elsif Is_Access_Type (Typ) then
14457 return True;
14459 elsif Is_Array_Type (Typ) then
14460 if Is_Fully_Initialized_Type (Component_Type (Typ))
14461 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14462 then
14463 return True;
14464 end if;
14466 -- An interesting case, if we have a constrained type one of whose
14467 -- bounds is known to be null, then there are no elements to be
14468 -- initialized, so all the elements are initialized.
14470 if Is_Constrained (Typ) then
14471 declare
14472 Indx : Node_Id;
14473 Indx_Typ : Entity_Id;
14474 Lbd, Hbd : Node_Id;
14476 begin
14477 Indx := First_Index (Typ);
14478 while Present (Indx) loop
14479 if Etype (Indx) = Any_Type then
14480 return False;
14482 -- If index is a range, use directly
14484 elsif Nkind (Indx) = N_Range then
14485 Lbd := Low_Bound (Indx);
14486 Hbd := High_Bound (Indx);
14488 else
14489 Indx_Typ := Etype (Indx);
14491 if Is_Private_Type (Indx_Typ) then
14492 Indx_Typ := Full_View (Indx_Typ);
14493 end if;
14495 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14496 return False;
14497 else
14498 Lbd := Type_Low_Bound (Indx_Typ);
14499 Hbd := Type_High_Bound (Indx_Typ);
14500 end if;
14501 end if;
14503 if Compile_Time_Known_Value (Lbd)
14504 and then
14505 Compile_Time_Known_Value (Hbd)
14506 then
14507 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14508 return True;
14509 end if;
14510 end if;
14512 Next_Index (Indx);
14513 end loop;
14514 end;
14515 end if;
14517 -- If no null indexes, then type is not fully initialized
14519 return False;
14521 -- Record types
14523 elsif Is_Record_Type (Typ) then
14524 if Has_Discriminants (Typ)
14525 and then
14526 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14527 and then Is_Fully_Initialized_Variant (Typ)
14528 then
14529 return True;
14530 end if;
14532 -- We consider bounded string types to be fully initialized, because
14533 -- otherwise we get false alarms when the Data component is not
14534 -- default-initialized.
14536 if Is_Bounded_String (Typ) then
14537 return True;
14538 end if;
14540 -- Controlled records are considered to be fully initialized if
14541 -- there is a user defined Initialize routine. This may not be
14542 -- entirely correct, but as the spec notes, we are guessing here
14543 -- what is best from the point of view of issuing warnings.
14545 if Is_Controlled (Typ) then
14546 declare
14547 Utyp : constant Entity_Id := Underlying_Type (Typ);
14549 begin
14550 if Present (Utyp) then
14551 declare
14552 Init : constant Entity_Id :=
14553 (Find_Optional_Prim_Op
14554 (Underlying_Type (Typ), Name_Initialize));
14556 begin
14557 if Present (Init)
14558 and then Comes_From_Source (Init)
14559 and then not In_Predefined_Unit (Init)
14560 then
14561 return True;
14563 elsif Has_Null_Extension (Typ)
14564 and then
14565 Is_Fully_Initialized_Type
14566 (Etype (Base_Type (Typ)))
14567 then
14568 return True;
14569 end if;
14570 end;
14571 end if;
14572 end;
14573 end if;
14575 -- Otherwise see if all record components are initialized
14577 declare
14578 Ent : Entity_Id;
14580 begin
14581 Ent := First_Entity (Typ);
14582 while Present (Ent) loop
14583 if Ekind (Ent) = E_Component
14584 and then (No (Parent (Ent))
14585 or else No (Expression (Parent (Ent))))
14586 and then not Is_Fully_Initialized_Type (Etype (Ent))
14588 -- Special VM case for tag components, which need to be
14589 -- defined in this case, but are never initialized as VMs
14590 -- are using other dispatching mechanisms. Ignore this
14591 -- uninitialized case. Note that this applies both to the
14592 -- uTag entry and the main vtable pointer (CPP_Class case).
14594 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14595 then
14596 return False;
14597 end if;
14599 Next_Entity (Ent);
14600 end loop;
14601 end;
14603 -- No uninitialized components, so type is fully initialized.
14604 -- Note that this catches the case of no components as well.
14606 return True;
14608 elsif Is_Concurrent_Type (Typ) then
14609 return True;
14611 elsif Is_Private_Type (Typ) then
14612 declare
14613 U : constant Entity_Id := Underlying_Type (Typ);
14615 begin
14616 if No (U) then
14617 return False;
14618 else
14619 return Is_Fully_Initialized_Type (U);
14620 end if;
14621 end;
14623 else
14624 return False;
14625 end if;
14626 end Is_Fully_Initialized_Type;
14628 ----------------------------------
14629 -- Is_Fully_Initialized_Variant --
14630 ----------------------------------
14632 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
14633 Loc : constant Source_Ptr := Sloc (Typ);
14634 Constraints : constant List_Id := New_List;
14635 Components : constant Elist_Id := New_Elmt_List;
14636 Comp_Elmt : Elmt_Id;
14637 Comp_Id : Node_Id;
14638 Comp_List : Node_Id;
14639 Discr : Entity_Id;
14640 Discr_Val : Node_Id;
14642 Report_Errors : Boolean;
14643 pragma Warnings (Off, Report_Errors);
14645 begin
14646 if Serious_Errors_Detected > 0 then
14647 return False;
14648 end if;
14650 if Is_Record_Type (Typ)
14651 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
14652 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
14653 then
14654 Comp_List := Component_List (Type_Definition (Parent (Typ)));
14656 Discr := First_Discriminant (Typ);
14657 while Present (Discr) loop
14658 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
14659 Discr_Val := Expression (Parent (Discr));
14661 if Present (Discr_Val)
14662 and then Is_OK_Static_Expression (Discr_Val)
14663 then
14664 Append_To (Constraints,
14665 Make_Component_Association (Loc,
14666 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
14667 Expression => New_Copy (Discr_Val)));
14668 else
14669 return False;
14670 end if;
14671 else
14672 return False;
14673 end if;
14675 Next_Discriminant (Discr);
14676 end loop;
14678 Gather_Components
14679 (Typ => Typ,
14680 Comp_List => Comp_List,
14681 Governed_By => Constraints,
14682 Into => Components,
14683 Report_Errors => Report_Errors);
14685 -- Check that each component present is fully initialized
14687 Comp_Elmt := First_Elmt (Components);
14688 while Present (Comp_Elmt) loop
14689 Comp_Id := Node (Comp_Elmt);
14691 if Ekind (Comp_Id) = E_Component
14692 and then (No (Parent (Comp_Id))
14693 or else No (Expression (Parent (Comp_Id))))
14694 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
14695 then
14696 return False;
14697 end if;
14699 Next_Elmt (Comp_Elmt);
14700 end loop;
14702 return True;
14704 elsif Is_Private_Type (Typ) then
14705 declare
14706 U : constant Entity_Id := Underlying_Type (Typ);
14708 begin
14709 if No (U) then
14710 return False;
14711 else
14712 return Is_Fully_Initialized_Variant (U);
14713 end if;
14714 end;
14716 else
14717 return False;
14718 end if;
14719 end Is_Fully_Initialized_Variant;
14721 ------------------------------------
14722 -- Is_Generic_Declaration_Or_Body --
14723 ------------------------------------
14725 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
14726 Spec_Decl : Node_Id;
14728 begin
14729 -- Package/subprogram body
14731 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
14732 and then Present (Corresponding_Spec (Decl))
14733 then
14734 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
14736 -- Package/subprogram body stub
14738 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
14739 and then Present (Corresponding_Spec_Of_Stub (Decl))
14740 then
14741 Spec_Decl :=
14742 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
14744 -- All other cases
14746 else
14747 Spec_Decl := Decl;
14748 end if;
14750 -- Rather than inspecting the defining entity of the spec declaration,
14751 -- look at its Nkind. This takes care of the case where the analysis of
14752 -- a generic body modifies the Ekind of its spec to allow for recursive
14753 -- calls.
14755 return
14756 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
14757 N_Generic_Subprogram_Declaration);
14758 end Is_Generic_Declaration_Or_Body;
14760 ----------------------------
14761 -- Is_Inherited_Operation --
14762 ----------------------------
14764 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
14765 pragma Assert (Is_Overloadable (E));
14766 Kind : constant Node_Kind := Nkind (Parent (E));
14767 begin
14768 return Kind = N_Full_Type_Declaration
14769 or else Kind = N_Private_Extension_Declaration
14770 or else Kind = N_Subtype_Declaration
14771 or else (Ekind (E) = E_Enumeration_Literal
14772 and then Is_Derived_Type (Etype (E)));
14773 end Is_Inherited_Operation;
14775 -------------------------------------
14776 -- Is_Inherited_Operation_For_Type --
14777 -------------------------------------
14779 function Is_Inherited_Operation_For_Type
14780 (E : Entity_Id;
14781 Typ : Entity_Id) return Boolean
14783 begin
14784 -- Check that the operation has been created by the type declaration
14786 return Is_Inherited_Operation (E)
14787 and then Defining_Identifier (Parent (E)) = Typ;
14788 end Is_Inherited_Operation_For_Type;
14790 --------------------------------------
14791 -- Is_Inlinable_Expression_Function --
14792 --------------------------------------
14794 function Is_Inlinable_Expression_Function
14795 (Subp : Entity_Id) return Boolean
14797 Return_Expr : Node_Id;
14799 begin
14800 if Is_Expression_Function_Or_Completion (Subp)
14801 and then Has_Pragma_Inline_Always (Subp)
14802 and then Needs_No_Actuals (Subp)
14803 and then No (Contract (Subp))
14804 and then not Is_Dispatching_Operation (Subp)
14805 and then Needs_Finalization (Etype (Subp))
14806 and then not Is_Class_Wide_Type (Etype (Subp))
14807 and then not (Has_Invariants (Etype (Subp)))
14808 and then Present (Subprogram_Body (Subp))
14809 and then Was_Expression_Function (Subprogram_Body (Subp))
14810 then
14811 Return_Expr := Expression_Of_Expression_Function (Subp);
14813 -- The returned object must not have a qualified expression and its
14814 -- nominal subtype must be statically compatible with the result
14815 -- subtype of the expression function.
14817 return
14818 Nkind (Return_Expr) = N_Identifier
14819 and then Etype (Return_Expr) = Etype (Subp);
14820 end if;
14822 return False;
14823 end Is_Inlinable_Expression_Function;
14825 -----------------
14826 -- Is_Iterator --
14827 -----------------
14829 function Is_Iterator (Typ : Entity_Id) return Boolean is
14830 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
14831 -- Determine whether type Iter_Typ is a predefined forward or reversible
14832 -- iterator.
14834 ----------------------
14835 -- Denotes_Iterator --
14836 ----------------------
14838 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
14839 begin
14840 -- Check that the name matches, and that the ultimate ancestor is in
14841 -- a predefined unit, i.e the one that declares iterator interfaces.
14843 return
14844 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
14845 Name_Reversible_Iterator)
14846 and then In_Predefined_Unit (Root_Type (Iter_Typ));
14847 end Denotes_Iterator;
14849 -- Local variables
14851 Iface_Elmt : Elmt_Id;
14852 Ifaces : Elist_Id;
14854 -- Start of processing for Is_Iterator
14856 begin
14857 -- The type may be a subtype of a descendant of the proper instance of
14858 -- the predefined interface type, so we must use the root type of the
14859 -- given type. The same is done for Is_Reversible_Iterator.
14861 if Is_Class_Wide_Type (Typ)
14862 and then Denotes_Iterator (Root_Type (Typ))
14863 then
14864 return True;
14866 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14867 return False;
14869 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
14870 return True;
14872 else
14873 Collect_Interfaces (Typ, Ifaces);
14875 Iface_Elmt := First_Elmt (Ifaces);
14876 while Present (Iface_Elmt) loop
14877 if Denotes_Iterator (Node (Iface_Elmt)) then
14878 return True;
14879 end if;
14881 Next_Elmt (Iface_Elmt);
14882 end loop;
14884 return False;
14885 end if;
14886 end Is_Iterator;
14888 ----------------------------
14889 -- Is_Iterator_Over_Array --
14890 ----------------------------
14892 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
14893 Container : constant Node_Id := Name (N);
14894 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
14895 begin
14896 return Is_Array_Type (Container_Typ);
14897 end Is_Iterator_Over_Array;
14899 ------------
14900 -- Is_LHS --
14901 ------------
14903 -- We seem to have a lot of overlapping functions that do similar things
14904 -- (testing for left hand sides or lvalues???).
14906 function Is_LHS (N : Node_Id) return Is_LHS_Result is
14907 P : constant Node_Id := Parent (N);
14909 begin
14910 -- Return True if we are the left hand side of an assignment statement
14912 if Nkind (P) = N_Assignment_Statement then
14913 if Name (P) = N then
14914 return Yes;
14915 else
14916 return No;
14917 end if;
14919 -- Case of prefix of indexed or selected component or slice
14921 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
14922 and then N = Prefix (P)
14923 then
14924 -- Here we have the case where the parent P is N.Q or N(Q .. R).
14925 -- If P is an LHS, then N is also effectively an LHS, but there
14926 -- is an important exception. If N is of an access type, then
14927 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
14928 -- case this makes N.all a left hand side but not N itself.
14930 -- If we don't know the type yet, this is the case where we return
14931 -- Unknown, since the answer depends on the type which is unknown.
14933 if No (Etype (N)) then
14934 return Unknown;
14936 -- We have an Etype set, so we can check it
14938 elsif Is_Access_Type (Etype (N)) then
14939 return No;
14941 -- OK, not access type case, so just test whole expression
14943 else
14944 return Is_LHS (P);
14945 end if;
14947 -- All other cases are not left hand sides
14949 else
14950 return No;
14951 end if;
14952 end Is_LHS;
14954 -----------------------------
14955 -- Is_Library_Level_Entity --
14956 -----------------------------
14958 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
14959 begin
14960 -- The following is a small optimization, and it also properly handles
14961 -- discriminals, which in task bodies might appear in expressions before
14962 -- the corresponding procedure has been created, and which therefore do
14963 -- not have an assigned scope.
14965 if Is_Formal (E) then
14966 return False;
14967 end if;
14969 -- Normal test is simply that the enclosing dynamic scope is Standard
14971 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
14972 end Is_Library_Level_Entity;
14974 --------------------------------
14975 -- Is_Limited_Class_Wide_Type --
14976 --------------------------------
14978 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
14979 begin
14980 return
14981 Is_Class_Wide_Type (Typ)
14982 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
14983 end Is_Limited_Class_Wide_Type;
14985 ---------------------------------
14986 -- Is_Local_Variable_Reference --
14987 ---------------------------------
14989 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
14990 begin
14991 if not Is_Entity_Name (Expr) then
14992 return False;
14994 else
14995 declare
14996 Ent : constant Entity_Id := Entity (Expr);
14997 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
14998 begin
14999 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15000 return False;
15001 else
15002 return Present (Sub) and then Sub = Current_Subprogram;
15003 end if;
15004 end;
15005 end if;
15006 end Is_Local_Variable_Reference;
15008 -----------------------
15009 -- Is_Name_Reference --
15010 -----------------------
15012 function Is_Name_Reference (N : Node_Id) return Boolean is
15013 begin
15014 if Is_Entity_Name (N) then
15015 return Present (Entity (N)) and then Is_Object (Entity (N));
15016 end if;
15018 case Nkind (N) is
15019 when N_Indexed_Component
15020 | N_Slice
15022 return
15023 Is_Name_Reference (Prefix (N))
15024 or else Is_Access_Type (Etype (Prefix (N)));
15026 -- Attributes 'Input, 'Old and 'Result produce objects
15028 when N_Attribute_Reference =>
15029 return
15030 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15032 when N_Selected_Component =>
15033 return
15034 Is_Name_Reference (Selector_Name (N))
15035 and then
15036 (Is_Name_Reference (Prefix (N))
15037 or else Is_Access_Type (Etype (Prefix (N))));
15039 when N_Explicit_Dereference =>
15040 return True;
15042 -- A view conversion of a tagged name is a name reference
15044 when N_Type_Conversion =>
15045 return
15046 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15047 and then Is_Tagged_Type (Etype (Expression (N)))
15048 and then Is_Name_Reference (Expression (N));
15050 -- An unchecked type conversion is considered to be a name if the
15051 -- operand is a name (this construction arises only as a result of
15052 -- expansion activities).
15054 when N_Unchecked_Type_Conversion =>
15055 return Is_Name_Reference (Expression (N));
15057 when others =>
15058 return False;
15059 end case;
15060 end Is_Name_Reference;
15062 ------------------------------------
15063 -- Is_Non_Preelaborable_Construct --
15064 ------------------------------------
15066 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15068 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15069 -- intentionally unnested to avoid deep indentation of code.
15071 Non_Preelaborable : exception;
15072 -- This exception is raised when the construct violates preelaborability
15073 -- to terminate the recursion.
15075 procedure Visit (Nod : Node_Id);
15076 -- Semantically inspect construct Nod to determine whether it violates
15077 -- preelaborability. This routine raises Non_Preelaborable.
15079 procedure Visit_List (List : List_Id);
15080 pragma Inline (Visit_List);
15081 -- Invoke Visit on each element of list List. This routine raises
15082 -- Non_Preelaborable.
15084 procedure Visit_Pragma (Prag : Node_Id);
15085 pragma Inline (Visit_Pragma);
15086 -- Semantically inspect pragma Prag to determine whether it violates
15087 -- preelaborability. This routine raises Non_Preelaborable.
15089 procedure Visit_Subexpression (Expr : Node_Id);
15090 pragma Inline (Visit_Subexpression);
15091 -- Semantically inspect expression Expr to determine whether it violates
15092 -- preelaborability. This routine raises Non_Preelaborable.
15094 -----------
15095 -- Visit --
15096 -----------
15098 procedure Visit (Nod : Node_Id) is
15099 begin
15100 case Nkind (Nod) is
15102 -- Declarations
15104 when N_Component_Declaration =>
15106 -- Defining_Identifier is left out because it is not relevant
15107 -- for preelaborability.
15109 Visit (Component_Definition (Nod));
15110 Visit (Expression (Nod));
15112 when N_Derived_Type_Definition =>
15114 -- Interface_List is left out because it is not relevant for
15115 -- preelaborability.
15117 Visit (Record_Extension_Part (Nod));
15118 Visit (Subtype_Indication (Nod));
15120 when N_Entry_Declaration =>
15122 -- A protected type with at leat one entry is not preelaborable
15123 -- while task types are never preelaborable. This renders entry
15124 -- declarations non-preelaborable.
15126 raise Non_Preelaborable;
15128 when N_Full_Type_Declaration =>
15130 -- Defining_Identifier and Discriminant_Specifications are left
15131 -- out because they are not relevant for preelaborability.
15133 Visit (Type_Definition (Nod));
15135 when N_Function_Instantiation
15136 | N_Package_Instantiation
15137 | N_Procedure_Instantiation
15139 -- Defining_Unit_Name and Name are left out because they are
15140 -- not relevant for preelaborability.
15142 Visit_List (Generic_Associations (Nod));
15144 when N_Object_Declaration =>
15146 -- Defining_Identifier is left out because it is not relevant
15147 -- for preelaborability.
15149 Visit (Object_Definition (Nod));
15151 if Has_Init_Expression (Nod) then
15152 Visit (Expression (Nod));
15154 elsif not Has_Preelaborable_Initialization
15155 (Etype (Defining_Entity (Nod)))
15156 then
15157 raise Non_Preelaborable;
15158 end if;
15160 when N_Private_Extension_Declaration
15161 | N_Subtype_Declaration
15163 -- Defining_Identifier, Discriminant_Specifications, and
15164 -- Interface_List are left out because they are not relevant
15165 -- for preelaborability.
15167 Visit (Subtype_Indication (Nod));
15169 when N_Protected_Type_Declaration
15170 | N_Single_Protected_Declaration
15172 -- Defining_Identifier, Discriminant_Specifications, and
15173 -- Interface_List are left out because they are not relevant
15174 -- for preelaborability.
15176 Visit (Protected_Definition (Nod));
15178 -- A [single] task type is never preelaborable
15180 when N_Single_Task_Declaration
15181 | N_Task_Type_Declaration
15183 raise Non_Preelaborable;
15185 -- Pragmas
15187 when N_Pragma =>
15188 Visit_Pragma (Nod);
15190 -- Statements
15192 when N_Statement_Other_Than_Procedure_Call =>
15193 if Nkind (Nod) /= N_Null_Statement then
15194 raise Non_Preelaborable;
15195 end if;
15197 -- Subexpressions
15199 when N_Subexpr =>
15200 Visit_Subexpression (Nod);
15202 -- Special
15204 when N_Access_To_Object_Definition =>
15205 Visit (Subtype_Indication (Nod));
15207 when N_Case_Expression_Alternative =>
15208 Visit (Expression (Nod));
15209 Visit_List (Discrete_Choices (Nod));
15211 when N_Component_Definition =>
15212 Visit (Access_Definition (Nod));
15213 Visit (Subtype_Indication (Nod));
15215 when N_Component_List =>
15216 Visit_List (Component_Items (Nod));
15217 Visit (Variant_Part (Nod));
15219 when N_Constrained_Array_Definition =>
15220 Visit_List (Discrete_Subtype_Definitions (Nod));
15221 Visit (Component_Definition (Nod));
15223 when N_Delta_Constraint
15224 | N_Digits_Constraint
15226 -- Delta_Expression and Digits_Expression are left out because
15227 -- they are not relevant for preelaborability.
15229 Visit (Range_Constraint (Nod));
15231 when N_Discriminant_Specification =>
15233 -- Defining_Identifier and Expression are left out because they
15234 -- are not relevant for preelaborability.
15236 Visit (Discriminant_Type (Nod));
15238 when N_Generic_Association =>
15240 -- Selector_Name is left out because it is not relevant for
15241 -- preelaborability.
15243 Visit (Explicit_Generic_Actual_Parameter (Nod));
15245 when N_Index_Or_Discriminant_Constraint =>
15246 Visit_List (Constraints (Nod));
15248 when N_Iterator_Specification =>
15250 -- Defining_Identifier is left out because it is not relevant
15251 -- for preelaborability.
15253 Visit (Name (Nod));
15254 Visit (Subtype_Indication (Nod));
15256 when N_Loop_Parameter_Specification =>
15258 -- Defining_Identifier is left out because it is not relevant
15259 -- for preelaborability.
15261 Visit (Discrete_Subtype_Definition (Nod));
15263 when N_Protected_Definition =>
15265 -- End_Label is left out because it is not relevant for
15266 -- preelaborability.
15268 Visit_List (Private_Declarations (Nod));
15269 Visit_List (Visible_Declarations (Nod));
15271 when N_Range_Constraint =>
15272 Visit (Range_Expression (Nod));
15274 when N_Record_Definition
15275 | N_Variant
15277 -- End_Label, Discrete_Choices, and Interface_List are left out
15278 -- because they are not relevant for preelaborability.
15280 Visit (Component_List (Nod));
15282 when N_Subtype_Indication =>
15284 -- Subtype_Mark is left out because it is not relevant for
15285 -- preelaborability.
15287 Visit (Constraint (Nod));
15289 when N_Unconstrained_Array_Definition =>
15291 -- Subtype_Marks is left out because it is not relevant for
15292 -- preelaborability.
15294 Visit (Component_Definition (Nod));
15296 when N_Variant_Part =>
15298 -- Name is left out because it is not relevant for
15299 -- preelaborability.
15301 Visit_List (Variants (Nod));
15303 -- Default
15305 when others =>
15306 null;
15307 end case;
15308 end Visit;
15310 ----------------
15311 -- Visit_List --
15312 ----------------
15314 procedure Visit_List (List : List_Id) is
15315 Nod : Node_Id;
15317 begin
15318 if Present (List) then
15319 Nod := First (List);
15320 while Present (Nod) loop
15321 Visit (Nod);
15322 Next (Nod);
15323 end loop;
15324 end if;
15325 end Visit_List;
15327 ------------------
15328 -- Visit_Pragma --
15329 ------------------
15331 procedure Visit_Pragma (Prag : Node_Id) is
15332 begin
15333 case Get_Pragma_Id (Prag) is
15334 when Pragma_Assert
15335 | Pragma_Assert_And_Cut
15336 | Pragma_Assume
15337 | Pragma_Async_Readers
15338 | Pragma_Async_Writers
15339 | Pragma_Attribute_Definition
15340 | Pragma_Check
15341 | Pragma_Constant_After_Elaboration
15342 | Pragma_CPU
15343 | Pragma_Deadline_Floor
15344 | Pragma_Dispatching_Domain
15345 | Pragma_Effective_Reads
15346 | Pragma_Effective_Writes
15347 | Pragma_Extensions_Visible
15348 | Pragma_Ghost
15349 | Pragma_Secondary_Stack_Size
15350 | Pragma_Task_Name
15351 | Pragma_Volatile_Function
15353 Visit_List (Pragma_Argument_Associations (Prag));
15355 -- Default
15357 when others =>
15358 null;
15359 end case;
15360 end Visit_Pragma;
15362 -------------------------
15363 -- Visit_Subexpression --
15364 -------------------------
15366 procedure Visit_Subexpression (Expr : Node_Id) is
15367 procedure Visit_Aggregate (Aggr : Node_Id);
15368 pragma Inline (Visit_Aggregate);
15369 -- Semantically inspect aggregate Aggr to determine whether it
15370 -- violates preelaborability.
15372 ---------------------
15373 -- Visit_Aggregate --
15374 ---------------------
15376 procedure Visit_Aggregate (Aggr : Node_Id) is
15377 begin
15378 if not Is_Preelaborable_Aggregate (Aggr) then
15379 raise Non_Preelaborable;
15380 end if;
15381 end Visit_Aggregate;
15383 -- Start of processing for Visit_Subexpression
15385 begin
15386 case Nkind (Expr) is
15387 when N_Allocator
15388 | N_Qualified_Expression
15389 | N_Type_Conversion
15390 | N_Unchecked_Expression
15391 | N_Unchecked_Type_Conversion
15393 -- Subpool_Handle_Name and Subtype_Mark are left out because
15394 -- they are not relevant for preelaborability.
15396 Visit (Expression (Expr));
15398 when N_Aggregate
15399 | N_Extension_Aggregate
15401 Visit_Aggregate (Expr);
15403 when N_Attribute_Reference
15404 | N_Explicit_Dereference
15405 | N_Reference
15407 -- Attribute_Name and Expressions are left out because they are
15408 -- not relevant for preelaborability.
15410 Visit (Prefix (Expr));
15412 when N_Case_Expression =>
15414 -- End_Span is left out because it is not relevant for
15415 -- preelaborability.
15417 Visit_List (Alternatives (Expr));
15418 Visit (Expression (Expr));
15420 when N_Delta_Aggregate =>
15421 Visit_Aggregate (Expr);
15422 Visit (Expression (Expr));
15424 when N_Expression_With_Actions =>
15425 Visit_List (Actions (Expr));
15426 Visit (Expression (Expr));
15428 when N_If_Expression =>
15429 Visit_List (Expressions (Expr));
15431 when N_Quantified_Expression =>
15432 Visit (Condition (Expr));
15433 Visit (Iterator_Specification (Expr));
15434 Visit (Loop_Parameter_Specification (Expr));
15436 when N_Range =>
15437 Visit (High_Bound (Expr));
15438 Visit (Low_Bound (Expr));
15440 when N_Slice =>
15441 Visit (Discrete_Range (Expr));
15442 Visit (Prefix (Expr));
15444 -- Default
15446 when others =>
15448 -- The evaluation of an object name is not preelaborable,
15449 -- unless the name is a static expression (checked further
15450 -- below), or statically denotes a discriminant.
15452 if Is_Entity_Name (Expr) then
15453 Object_Name : declare
15454 Id : constant Entity_Id := Entity (Expr);
15456 begin
15457 if Is_Object (Id) then
15458 if Ekind (Id) = E_Discriminant then
15459 null;
15461 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15462 and then Present (Discriminal_Link (Id))
15463 then
15464 null;
15466 else
15467 raise Non_Preelaborable;
15468 end if;
15469 end if;
15470 end Object_Name;
15472 -- A non-static expression is not preelaborable
15474 elsif not Is_OK_Static_Expression (Expr) then
15475 raise Non_Preelaborable;
15476 end if;
15477 end case;
15478 end Visit_Subexpression;
15480 -- Start of processing for Is_Non_Preelaborable_Construct
15482 begin
15483 Visit (N);
15485 -- At this point it is known that the construct is preelaborable
15487 return False;
15489 exception
15491 -- The elaboration of the construct performs an action which violates
15492 -- preelaborability.
15494 when Non_Preelaborable =>
15495 return True;
15496 end Is_Non_Preelaborable_Construct;
15498 ---------------------------------
15499 -- Is_Nontrivial_DIC_Procedure --
15500 ---------------------------------
15502 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15503 Body_Decl : Node_Id;
15504 Stmt : Node_Id;
15506 begin
15507 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15508 Body_Decl :=
15509 Unit_Declaration_Node
15510 (Corresponding_Body (Unit_Declaration_Node (Id)));
15512 -- The body of the Default_Initial_Condition procedure must contain
15513 -- at least one statement, otherwise the generation of the subprogram
15514 -- body failed.
15516 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15518 -- To qualify as nontrivial, the first statement of the procedure
15519 -- must be a check in the form of an if statement. If the original
15520 -- Default_Initial_Condition expression was folded, then the first
15521 -- statement is not a check.
15523 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15525 return
15526 Nkind (Stmt) = N_If_Statement
15527 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15528 end if;
15530 return False;
15531 end Is_Nontrivial_DIC_Procedure;
15533 -------------------------
15534 -- Is_Null_Record_Type --
15535 -------------------------
15537 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15538 Decl : constant Node_Id := Parent (T);
15539 begin
15540 return Nkind (Decl) = N_Full_Type_Declaration
15541 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15542 and then
15543 (No (Component_List (Type_Definition (Decl)))
15544 or else Null_Present (Component_List (Type_Definition (Decl))));
15545 end Is_Null_Record_Type;
15547 ---------------------
15548 -- Is_Object_Image --
15549 ---------------------
15551 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15552 begin
15553 -- When the type of the prefix is not scalar, then the prefix is not
15554 -- valid in any scenario.
15556 if not Is_Scalar_Type (Etype (Prefix)) then
15557 return False;
15558 end if;
15560 -- Here we test for the case that the prefix is not a type and assume
15561 -- if it is not then it must be a named value or an object reference.
15562 -- This is because the parser always checks that prefixes of attributes
15563 -- are named.
15565 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
15566 end Is_Object_Image;
15568 -------------------------
15569 -- Is_Object_Reference --
15570 -------------------------
15572 function Is_Object_Reference (N : Node_Id) return Boolean is
15573 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
15574 -- Determine whether N is the name of an internally-generated renaming
15576 --------------------------------------
15577 -- Is_Internally_Generated_Renaming --
15578 --------------------------------------
15580 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
15581 P : Node_Id;
15583 begin
15584 P := N;
15585 while Present (P) loop
15586 if Nkind (P) = N_Object_Renaming_Declaration then
15587 return not Comes_From_Source (P);
15588 elsif Is_List_Member (P) then
15589 return False;
15590 end if;
15592 P := Parent (P);
15593 end loop;
15595 return False;
15596 end Is_Internally_Generated_Renaming;
15598 -- Start of processing for Is_Object_Reference
15600 begin
15601 if Is_Entity_Name (N) then
15602 return Present (Entity (N)) and then Is_Object (Entity (N));
15604 else
15605 case Nkind (N) is
15606 when N_Indexed_Component
15607 | N_Slice
15609 return
15610 Is_Object_Reference (Prefix (N))
15611 or else Is_Access_Type (Etype (Prefix (N)));
15613 -- In Ada 95, a function call is a constant object; a procedure
15614 -- call is not.
15616 -- Note that predefined operators are functions as well, and so
15617 -- are attributes that are (can be renamed as) functions.
15619 when N_Binary_Op
15620 | N_Function_Call
15621 | N_Unary_Op
15623 return Etype (N) /= Standard_Void_Type;
15625 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
15626 -- objects, even though they are not functions.
15628 when N_Attribute_Reference =>
15629 return
15630 Nam_In (Attribute_Name (N), Name_Loop_Entry,
15631 Name_Old,
15632 Name_Result)
15633 or else Is_Function_Attribute_Name (Attribute_Name (N));
15635 when N_Selected_Component =>
15636 return
15637 Is_Object_Reference (Selector_Name (N))
15638 and then
15639 (Is_Object_Reference (Prefix (N))
15640 or else Is_Access_Type (Etype (Prefix (N))));
15642 -- An explicit dereference denotes an object, except that a
15643 -- conditional expression gets turned into an explicit dereference
15644 -- in some cases, and conditional expressions are not object
15645 -- names.
15647 when N_Explicit_Dereference =>
15648 return not Nkind_In (Original_Node (N), N_Case_Expression,
15649 N_If_Expression);
15651 -- A view conversion of a tagged object is an object reference
15653 when N_Type_Conversion =>
15654 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
15655 and then Is_Tagged_Type (Etype (Expression (N)))
15656 and then Is_Object_Reference (Expression (N));
15658 -- An unchecked type conversion is considered to be an object if
15659 -- the operand is an object (this construction arises only as a
15660 -- result of expansion activities).
15662 when N_Unchecked_Type_Conversion =>
15663 return True;
15665 -- Allow string literals to act as objects as long as they appear
15666 -- in internally-generated renamings. The expansion of iterators
15667 -- may generate such renamings when the range involves a string
15668 -- literal.
15670 when N_String_Literal =>
15671 return Is_Internally_Generated_Renaming (Parent (N));
15673 -- AI05-0003: In Ada 2012 a qualified expression is a name.
15674 -- This allows disambiguation of function calls and the use
15675 -- of aggregates in more contexts.
15677 when N_Qualified_Expression =>
15678 if Ada_Version < Ada_2012 then
15679 return False;
15680 else
15681 return Is_Object_Reference (Expression (N))
15682 or else Nkind (Expression (N)) = N_Aggregate;
15683 end if;
15685 when others =>
15686 return False;
15687 end case;
15688 end if;
15689 end Is_Object_Reference;
15691 -----------------------------------
15692 -- Is_OK_Variable_For_Out_Formal --
15693 -----------------------------------
15695 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
15696 begin
15697 Note_Possible_Modification (AV, Sure => True);
15699 -- We must reject parenthesized variable names. Comes_From_Source is
15700 -- checked because there are currently cases where the compiler violates
15701 -- this rule (e.g. passing a task object to its controlled Initialize
15702 -- routine). This should be properly documented in sinfo???
15704 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
15705 return False;
15707 -- A variable is always allowed
15709 elsif Is_Variable (AV) then
15710 return True;
15712 -- Generalized indexing operations are rewritten as explicit
15713 -- dereferences, and it is only during resolution that we can
15714 -- check whether the context requires an access_to_variable type.
15716 elsif Nkind (AV) = N_Explicit_Dereference
15717 and then Ada_Version >= Ada_2012
15718 and then Nkind (Original_Node (AV)) = N_Indexed_Component
15719 and then Present (Etype (Original_Node (AV)))
15720 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
15721 then
15722 return not Is_Access_Constant (Etype (Prefix (AV)));
15724 -- Unchecked conversions are allowed only if they come from the
15725 -- generated code, which sometimes uses unchecked conversions for out
15726 -- parameters in cases where code generation is unaffected. We tell
15727 -- source unchecked conversions by seeing if they are rewrites of
15728 -- an original Unchecked_Conversion function call, or of an explicit
15729 -- conversion of a function call or an aggregate (as may happen in the
15730 -- expansion of a packed array aggregate).
15732 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
15733 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
15734 return False;
15736 elsif Comes_From_Source (AV)
15737 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
15738 then
15739 return False;
15741 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
15742 return Is_OK_Variable_For_Out_Formal (Expression (AV));
15744 else
15745 return True;
15746 end if;
15748 -- Normal type conversions are allowed if argument is a variable
15750 elsif Nkind (AV) = N_Type_Conversion then
15751 if Is_Variable (Expression (AV))
15752 and then Paren_Count (Expression (AV)) = 0
15753 then
15754 Note_Possible_Modification (Expression (AV), Sure => True);
15755 return True;
15757 -- We also allow a non-parenthesized expression that raises
15758 -- constraint error if it rewrites what used to be a variable
15760 elsif Raises_Constraint_Error (Expression (AV))
15761 and then Paren_Count (Expression (AV)) = 0
15762 and then Is_Variable (Original_Node (Expression (AV)))
15763 then
15764 return True;
15766 -- Type conversion of something other than a variable
15768 else
15769 return False;
15770 end if;
15772 -- If this node is rewritten, then test the original form, if that is
15773 -- OK, then we consider the rewritten node OK (for example, if the
15774 -- original node is a conversion, then Is_Variable will not be true
15775 -- but we still want to allow the conversion if it converts a variable).
15777 elsif Original_Node (AV) /= AV then
15779 -- In Ada 2012, the explicit dereference may be a rewritten call to a
15780 -- Reference function.
15782 if Ada_Version >= Ada_2012
15783 and then Nkind (Original_Node (AV)) = N_Function_Call
15784 and then
15785 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
15786 then
15788 -- Check that this is not a constant reference.
15790 return not Is_Access_Constant (Etype (Prefix (AV)));
15792 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
15793 return
15794 not Is_Access_Constant (Etype
15795 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
15797 else
15798 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
15799 end if;
15801 -- All other non-variables are rejected
15803 else
15804 return False;
15805 end if;
15806 end Is_OK_Variable_For_Out_Formal;
15808 ----------------------------
15809 -- Is_OK_Volatile_Context --
15810 ----------------------------
15812 function Is_OK_Volatile_Context
15813 (Context : Node_Id;
15814 Obj_Ref : Node_Id) return Boolean
15816 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
15817 -- Determine whether an arbitrary node denotes a call to a protected
15818 -- entry, function, or procedure in prefixed form where the prefix is
15819 -- Obj_Ref.
15821 function Within_Check (Nod : Node_Id) return Boolean;
15822 -- Determine whether an arbitrary node appears in a check node
15824 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
15825 -- Determine whether an arbitrary entity appears in a volatile function
15827 ---------------------------------
15828 -- Is_Protected_Operation_Call --
15829 ---------------------------------
15831 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
15832 Pref : Node_Id;
15833 Subp : Node_Id;
15835 begin
15836 -- A call to a protected operations retains its selected component
15837 -- form as opposed to other prefixed calls that are transformed in
15838 -- expanded names.
15840 if Nkind (Nod) = N_Selected_Component then
15841 Pref := Prefix (Nod);
15842 Subp := Selector_Name (Nod);
15844 return
15845 Pref = Obj_Ref
15846 and then Present (Etype (Pref))
15847 and then Is_Protected_Type (Etype (Pref))
15848 and then Is_Entity_Name (Subp)
15849 and then Present (Entity (Subp))
15850 and then Ekind_In (Entity (Subp), E_Entry,
15851 E_Entry_Family,
15852 E_Function,
15853 E_Procedure);
15854 else
15855 return False;
15856 end if;
15857 end Is_Protected_Operation_Call;
15859 ------------------
15860 -- Within_Check --
15861 ------------------
15863 function Within_Check (Nod : Node_Id) return Boolean is
15864 Par : Node_Id;
15866 begin
15867 -- Climb the parent chain looking for a check node
15869 Par := Nod;
15870 while Present (Par) loop
15871 if Nkind (Par) in N_Raise_xxx_Error then
15872 return True;
15874 -- Prevent the search from going too far
15876 elsif Is_Body_Or_Package_Declaration (Par) then
15877 exit;
15878 end if;
15880 Par := Parent (Par);
15881 end loop;
15883 return False;
15884 end Within_Check;
15886 ------------------------------
15887 -- Within_Volatile_Function --
15888 ------------------------------
15890 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
15891 Func_Id : Entity_Id;
15893 begin
15894 -- Traverse the scope stack looking for a [generic] function
15896 Func_Id := Id;
15897 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
15898 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
15899 return Is_Volatile_Function (Func_Id);
15900 end if;
15902 Func_Id := Scope (Func_Id);
15903 end loop;
15905 return False;
15906 end Within_Volatile_Function;
15908 -- Local variables
15910 Obj_Id : Entity_Id;
15912 -- Start of processing for Is_OK_Volatile_Context
15914 begin
15915 -- The volatile object appears on either side of an assignment
15917 if Nkind (Context) = N_Assignment_Statement then
15918 return True;
15920 -- The volatile object is part of the initialization expression of
15921 -- another object.
15923 elsif Nkind (Context) = N_Object_Declaration
15924 and then Present (Expression (Context))
15925 and then Expression (Context) = Obj_Ref
15926 then
15927 Obj_Id := Defining_Entity (Context);
15929 -- The volatile object acts as the initialization expression of an
15930 -- extended return statement. This is valid context as long as the
15931 -- function is volatile.
15933 if Is_Return_Object (Obj_Id) then
15934 return Within_Volatile_Function (Obj_Id);
15936 -- Otherwise this is a normal object initialization
15938 else
15939 return True;
15940 end if;
15942 -- The volatile object acts as the name of a renaming declaration
15944 elsif Nkind (Context) = N_Object_Renaming_Declaration
15945 and then Name (Context) = Obj_Ref
15946 then
15947 return True;
15949 -- The volatile object appears as an actual parameter in a call to an
15950 -- instance of Unchecked_Conversion whose result is renamed.
15952 elsif Nkind (Context) = N_Function_Call
15953 and then Is_Entity_Name (Name (Context))
15954 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
15955 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
15956 then
15957 return True;
15959 -- The volatile object is actually the prefix in a protected entry,
15960 -- function, or procedure call.
15962 elsif Is_Protected_Operation_Call (Context) then
15963 return True;
15965 -- The volatile object appears as the expression of a simple return
15966 -- statement that applies to a volatile function.
15968 elsif Nkind (Context) = N_Simple_Return_Statement
15969 and then Expression (Context) = Obj_Ref
15970 then
15971 return
15972 Within_Volatile_Function (Return_Statement_Entity (Context));
15974 -- The volatile object appears as the prefix of a name occurring in a
15975 -- non-interfering context.
15977 elsif Nkind_In (Context, N_Attribute_Reference,
15978 N_Explicit_Dereference,
15979 N_Indexed_Component,
15980 N_Selected_Component,
15981 N_Slice)
15982 and then Prefix (Context) = Obj_Ref
15983 and then Is_OK_Volatile_Context
15984 (Context => Parent (Context),
15985 Obj_Ref => Context)
15986 then
15987 return True;
15989 -- The volatile object appears as the prefix of attributes Address,
15990 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
15991 -- Storage_Size.
15993 elsif Nkind (Context) = N_Attribute_Reference
15994 and then Prefix (Context) = Obj_Ref
15995 and then Nam_In (Attribute_Name (Context), Name_Address,
15996 Name_Alignment,
15997 Name_Component_Size,
15998 Name_First_Bit,
15999 Name_Last_Bit,
16000 Name_Position,
16001 Name_Size,
16002 Name_Storage_Size)
16003 then
16004 return True;
16006 -- The volatile object appears as the expression of a type conversion
16007 -- occurring in a non-interfering context.
16009 elsif Nkind_In (Context, N_Type_Conversion,
16010 N_Unchecked_Type_Conversion)
16011 and then Expression (Context) = Obj_Ref
16012 and then Is_OK_Volatile_Context
16013 (Context => Parent (Context),
16014 Obj_Ref => Context)
16015 then
16016 return True;
16018 -- The volatile object appears as the expression in a delay statement
16020 elsif Nkind (Context) in N_Delay_Statement then
16021 return True;
16023 -- Allow references to volatile objects in various checks. This is not a
16024 -- direct SPARK 2014 requirement.
16026 elsif Within_Check (Context) then
16027 return True;
16029 -- Assume that references to effectively volatile objects that appear
16030 -- as actual parameters in a subprogram call are always legal. A full
16031 -- legality check is done when the actuals are resolved (see routine
16032 -- Resolve_Actuals).
16034 elsif Within_Subprogram_Call (Context) then
16035 return True;
16037 -- Otherwise the context is not suitable for an effectively volatile
16038 -- object.
16040 else
16041 return False;
16042 end if;
16043 end Is_OK_Volatile_Context;
16045 ------------------------------------
16046 -- Is_Package_Contract_Annotation --
16047 ------------------------------------
16049 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16050 Nam : Name_Id;
16052 begin
16053 if Nkind (Item) = N_Aspect_Specification then
16054 Nam := Chars (Identifier (Item));
16056 else pragma Assert (Nkind (Item) = N_Pragma);
16057 Nam := Pragma_Name (Item);
16058 end if;
16060 return Nam = Name_Abstract_State
16061 or else Nam = Name_Initial_Condition
16062 or else Nam = Name_Initializes
16063 or else Nam = Name_Refined_State;
16064 end Is_Package_Contract_Annotation;
16066 -----------------------------------
16067 -- Is_Partially_Initialized_Type --
16068 -----------------------------------
16070 function Is_Partially_Initialized_Type
16071 (Typ : Entity_Id;
16072 Include_Implicit : Boolean := True) return Boolean
16074 begin
16075 if Is_Scalar_Type (Typ) then
16076 return False;
16078 elsif Is_Access_Type (Typ) then
16079 return Include_Implicit;
16081 elsif Is_Array_Type (Typ) then
16083 -- If component type is partially initialized, so is array type
16085 if Is_Partially_Initialized_Type
16086 (Component_Type (Typ), Include_Implicit)
16087 then
16088 return True;
16090 -- Otherwise we are only partially initialized if we are fully
16091 -- initialized (this is the empty array case, no point in us
16092 -- duplicating that code here).
16094 else
16095 return Is_Fully_Initialized_Type (Typ);
16096 end if;
16098 elsif Is_Record_Type (Typ) then
16100 -- A discriminated type is always partially initialized if in
16101 -- all mode
16103 if Has_Discriminants (Typ) and then Include_Implicit then
16104 return True;
16106 -- A tagged type is always partially initialized
16108 elsif Is_Tagged_Type (Typ) then
16109 return True;
16111 -- Case of non-discriminated record
16113 else
16114 declare
16115 Ent : Entity_Id;
16117 Component_Present : Boolean := False;
16118 -- Set True if at least one component is present. If no
16119 -- components are present, then record type is fully
16120 -- initialized (another odd case, like the null array).
16122 begin
16123 -- Loop through components
16125 Ent := First_Entity (Typ);
16126 while Present (Ent) loop
16127 if Ekind (Ent) = E_Component then
16128 Component_Present := True;
16130 -- If a component has an initialization expression then
16131 -- the enclosing record type is partially initialized
16133 if Present (Parent (Ent))
16134 and then Present (Expression (Parent (Ent)))
16135 then
16136 return True;
16138 -- If a component is of a type which is itself partially
16139 -- initialized, then the enclosing record type is also.
16141 elsif Is_Partially_Initialized_Type
16142 (Etype (Ent), Include_Implicit)
16143 then
16144 return True;
16145 end if;
16146 end if;
16148 Next_Entity (Ent);
16149 end loop;
16151 -- No initialized components found. If we found any components
16152 -- they were all uninitialized so the result is false.
16154 if Component_Present then
16155 return False;
16157 -- But if we found no components, then all the components are
16158 -- initialized so we consider the type to be initialized.
16160 else
16161 return True;
16162 end if;
16163 end;
16164 end if;
16166 -- Concurrent types are always fully initialized
16168 elsif Is_Concurrent_Type (Typ) then
16169 return True;
16171 -- For a private type, go to underlying type. If there is no underlying
16172 -- type then just assume this partially initialized. Not clear if this
16173 -- can happen in a non-error case, but no harm in testing for this.
16175 elsif Is_Private_Type (Typ) then
16176 declare
16177 U : constant Entity_Id := Underlying_Type (Typ);
16178 begin
16179 if No (U) then
16180 return True;
16181 else
16182 return Is_Partially_Initialized_Type (U, Include_Implicit);
16183 end if;
16184 end;
16186 -- For any other type (are there any?) assume partially initialized
16188 else
16189 return True;
16190 end if;
16191 end Is_Partially_Initialized_Type;
16193 ------------------------------------
16194 -- Is_Potentially_Persistent_Type --
16195 ------------------------------------
16197 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16198 Comp : Entity_Id;
16199 Indx : Node_Id;
16201 begin
16202 -- For private type, test corresponding full type
16204 if Is_Private_Type (T) then
16205 return Is_Potentially_Persistent_Type (Full_View (T));
16207 -- Scalar types are potentially persistent
16209 elsif Is_Scalar_Type (T) then
16210 return True;
16212 -- Record type is potentially persistent if not tagged and the types of
16213 -- all it components are potentially persistent, and no component has
16214 -- an initialization expression.
16216 elsif Is_Record_Type (T)
16217 and then not Is_Tagged_Type (T)
16218 and then not Is_Partially_Initialized_Type (T)
16219 then
16220 Comp := First_Component (T);
16221 while Present (Comp) loop
16222 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16223 return False;
16224 else
16225 Next_Entity (Comp);
16226 end if;
16227 end loop;
16229 return True;
16231 -- Array type is potentially persistent if its component type is
16232 -- potentially persistent and if all its constraints are static.
16234 elsif Is_Array_Type (T) then
16235 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
16236 return False;
16237 end if;
16239 Indx := First_Index (T);
16240 while Present (Indx) loop
16241 if not Is_OK_Static_Subtype (Etype (Indx)) then
16242 return False;
16243 else
16244 Next_Index (Indx);
16245 end if;
16246 end loop;
16248 return True;
16250 -- All other types are not potentially persistent
16252 else
16253 return False;
16254 end if;
16255 end Is_Potentially_Persistent_Type;
16257 --------------------------------
16258 -- Is_Potentially_Unevaluated --
16259 --------------------------------
16261 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
16262 Par : Node_Id;
16263 Expr : Node_Id;
16265 begin
16266 Expr := N;
16267 Par := N;
16269 -- A postcondition whose expression is a short-circuit is broken down
16270 -- into individual aspects for better exception reporting. The original
16271 -- short-circuit expression is rewritten as the second operand, and an
16272 -- occurrence of 'Old in that operand is potentially unevaluated.
16273 -- See sem_ch13.adb for details of this transformation. The reference
16274 -- to 'Old may appear within an expression, so we must look for the
16275 -- enclosing pragma argument in the tree that contains the reference.
16277 while Present (Par)
16278 and then Nkind (Par) /= N_Pragma_Argument_Association
16279 loop
16280 if Nkind (Original_Node (Par)) = N_And_Then then
16281 return True;
16282 end if;
16284 Par := Parent (Par);
16285 end loop;
16287 -- Other cases; 'Old appears within other expression (not the top-level
16288 -- conjunct in a postcondition) with a potentially unevaluated operand.
16290 Par := Parent (Expr);
16291 while not Nkind_In (Par, N_And_Then,
16292 N_Case_Expression,
16293 N_If_Expression,
16294 N_In,
16295 N_Not_In,
16296 N_Or_Else,
16297 N_Quantified_Expression)
16298 loop
16299 Expr := Par;
16300 Par := Parent (Par);
16302 -- If the context is not an expression, or if is the result of
16303 -- expansion of an enclosing construct (such as another attribute)
16304 -- the predicate does not apply.
16306 if Nkind (Par) = N_Case_Expression_Alternative then
16307 null;
16309 elsif Nkind (Par) not in N_Subexpr
16310 or else not Comes_From_Source (Par)
16311 then
16312 return False;
16313 end if;
16314 end loop;
16316 if Nkind (Par) = N_If_Expression then
16317 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
16319 elsif Nkind (Par) = N_Case_Expression then
16320 return Expr /= Expression (Par);
16322 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
16323 return Expr = Right_Opnd (Par);
16325 elsif Nkind_In (Par, N_In, N_Not_In) then
16327 -- If the membership includes several alternatives, only the first is
16328 -- definitely evaluated.
16330 if Present (Alternatives (Par)) then
16331 return Expr /= First (Alternatives (Par));
16333 -- If this is a range membership both bounds are evaluated
16335 else
16336 return False;
16337 end if;
16339 elsif Nkind (Par) = N_Quantified_Expression then
16340 return Expr = Condition (Par);
16342 else
16343 return False;
16344 end if;
16345 end Is_Potentially_Unevaluated;
16347 -----------------------------------------
16348 -- Is_Predefined_Dispatching_Operation --
16349 -----------------------------------------
16351 function Is_Predefined_Dispatching_Operation
16352 (E : Entity_Id) return Boolean
16354 TSS_Name : TSS_Name_Type;
16356 begin
16357 if not Is_Dispatching_Operation (E) then
16358 return False;
16359 end if;
16361 Get_Name_String (Chars (E));
16363 -- Most predefined primitives have internally generated names. Equality
16364 -- must be treated differently; the predefined operation is recognized
16365 -- as a homogeneous binary operator that returns Boolean.
16367 if Name_Len > TSS_Name_Type'Last then
16368 TSS_Name :=
16369 TSS_Name_Type
16370 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16372 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
16373 or else
16374 (Chars (E) = Name_Op_Eq
16375 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16376 or else TSS_Name = TSS_Deep_Adjust
16377 or else TSS_Name = TSS_Deep_Finalize
16378 or else TSS_Name = TSS_Stream_Input
16379 or else TSS_Name = TSS_Stream_Output
16380 or else TSS_Name = TSS_Stream_Read
16381 or else TSS_Name = TSS_Stream_Write
16382 or else Is_Predefined_Interface_Primitive (E)
16383 then
16384 return True;
16385 end if;
16386 end if;
16388 return False;
16389 end Is_Predefined_Dispatching_Operation;
16391 ---------------------------------------
16392 -- Is_Predefined_Interface_Primitive --
16393 ---------------------------------------
16395 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
16396 begin
16397 -- In VM targets we don't restrict the functionality of this test to
16398 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16399 -- these primitives.
16401 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
16402 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
16403 Name_uDisp_Conditional_Select,
16404 Name_uDisp_Get_Prim_Op_Kind,
16405 Name_uDisp_Get_Task_Id,
16406 Name_uDisp_Requeue,
16407 Name_uDisp_Timed_Select);
16408 end Is_Predefined_Interface_Primitive;
16410 ---------------------------------------
16411 -- Is_Predefined_Internal_Operation --
16412 ---------------------------------------
16414 function Is_Predefined_Internal_Operation
16415 (E : Entity_Id) return Boolean
16417 TSS_Name : TSS_Name_Type;
16419 begin
16420 if not Is_Dispatching_Operation (E) then
16421 return False;
16422 end if;
16424 Get_Name_String (Chars (E));
16426 -- Most predefined primitives have internally generated names. Equality
16427 -- must be treated differently; the predefined operation is recognized
16428 -- as a homogeneous binary operator that returns Boolean.
16430 if Name_Len > TSS_Name_Type'Last then
16431 TSS_Name :=
16432 TSS_Name_Type
16433 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16435 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
16436 or else
16437 (Chars (E) = Name_Op_Eq
16438 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16439 or else TSS_Name = TSS_Deep_Adjust
16440 or else TSS_Name = TSS_Deep_Finalize
16441 or else Is_Predefined_Interface_Primitive (E)
16442 then
16443 return True;
16444 end if;
16445 end if;
16447 return False;
16448 end Is_Predefined_Internal_Operation;
16450 --------------------------------
16451 -- Is_Preelaborable_Aggregate --
16452 --------------------------------
16454 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
16455 Aggr_Typ : constant Entity_Id := Etype (Aggr);
16456 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
16458 Anc_Part : Node_Id;
16459 Assoc : Node_Id;
16460 Choice : Node_Id;
16461 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
16462 Expr : Node_Id;
16464 begin
16465 if Array_Aggr then
16466 Comp_Typ := Component_Type (Aggr_Typ);
16467 end if;
16469 -- Inspect the ancestor part
16471 if Nkind (Aggr) = N_Extension_Aggregate then
16472 Anc_Part := Ancestor_Part (Aggr);
16474 -- The ancestor denotes a subtype mark
16476 if Is_Entity_Name (Anc_Part)
16477 and then Is_Type (Entity (Anc_Part))
16478 then
16479 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
16480 return False;
16481 end if;
16483 -- Otherwise the ancestor denotes an expression
16485 elsif not Is_Preelaborable_Construct (Anc_Part) then
16486 return False;
16487 end if;
16488 end if;
16490 -- Inspect the positional associations
16492 Expr := First (Expressions (Aggr));
16493 while Present (Expr) loop
16494 if not Is_Preelaborable_Construct (Expr) then
16495 return False;
16496 end if;
16498 Next (Expr);
16499 end loop;
16501 -- Inspect the named associations
16503 Assoc := First (Component_Associations (Aggr));
16504 while Present (Assoc) loop
16506 -- Inspect the choices of the current named association
16508 Choice := First (Choices (Assoc));
16509 while Present (Choice) loop
16510 if Array_Aggr then
16512 -- For a choice to be preelaborable, it must denote either a
16513 -- static range or a static expression.
16515 if Nkind (Choice) = N_Others_Choice then
16516 null;
16518 elsif Nkind (Choice) = N_Range then
16519 if not Is_OK_Static_Range (Choice) then
16520 return False;
16521 end if;
16523 elsif not Is_OK_Static_Expression (Choice) then
16524 return False;
16525 end if;
16527 else
16528 Comp_Typ := Etype (Choice);
16529 end if;
16531 Next (Choice);
16532 end loop;
16534 -- The type of the choice must have preelaborable initialization if
16535 -- the association carries a <>.
16537 pragma Assert (Present (Comp_Typ));
16538 if Box_Present (Assoc) then
16539 if not Has_Preelaborable_Initialization (Comp_Typ) then
16540 return False;
16541 end if;
16543 -- The type of the expression must have preelaborable initialization
16545 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
16546 return False;
16547 end if;
16549 Next (Assoc);
16550 end loop;
16552 -- At this point the aggregate is preelaborable
16554 return True;
16555 end Is_Preelaborable_Aggregate;
16557 --------------------------------
16558 -- Is_Preelaborable_Construct --
16559 --------------------------------
16561 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
16562 begin
16563 -- Aggregates
16565 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
16566 return Is_Preelaborable_Aggregate (N);
16568 -- Attributes are allowed in general, even if their prefix is a formal
16569 -- type. It seems that certain attributes known not to be static might
16570 -- not be allowed, but there are no rules to prevent them.
16572 elsif Nkind (N) = N_Attribute_Reference then
16573 return True;
16575 -- Expressions
16577 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
16578 return True;
16580 elsif Nkind (N) = N_Qualified_Expression then
16581 return Is_Preelaborable_Construct (Expression (N));
16583 -- Names are preelaborable when they denote a discriminant of an
16584 -- enclosing type. Discriminals are also considered for this check.
16586 elsif Is_Entity_Name (N)
16587 and then Present (Entity (N))
16588 and then
16589 (Ekind (Entity (N)) = E_Discriminant
16590 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
16591 and then Present (Discriminal_Link (Entity (N)))))
16592 then
16593 return True;
16595 -- Statements
16597 elsif Nkind (N) = N_Null then
16598 return True;
16600 -- Otherwise the construct is not preelaborable
16602 else
16603 return False;
16604 end if;
16605 end Is_Preelaborable_Construct;
16607 ---------------------------------
16608 -- Is_Protected_Self_Reference --
16609 ---------------------------------
16611 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
16613 function In_Access_Definition (N : Node_Id) return Boolean;
16614 -- Returns true if N belongs to an access definition
16616 --------------------------
16617 -- In_Access_Definition --
16618 --------------------------
16620 function In_Access_Definition (N : Node_Id) return Boolean is
16621 P : Node_Id;
16623 begin
16624 P := Parent (N);
16625 while Present (P) loop
16626 if Nkind (P) = N_Access_Definition then
16627 return True;
16628 end if;
16630 P := Parent (P);
16631 end loop;
16633 return False;
16634 end In_Access_Definition;
16636 -- Start of processing for Is_Protected_Self_Reference
16638 begin
16639 -- Verify that prefix is analyzed and has the proper form. Note that
16640 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
16641 -- produce the address of an entity, do not analyze their prefix
16642 -- because they denote entities that are not necessarily visible.
16643 -- Neither of them can apply to a protected type.
16645 return Ada_Version >= Ada_2005
16646 and then Is_Entity_Name (N)
16647 and then Present (Entity (N))
16648 and then Is_Protected_Type (Entity (N))
16649 and then In_Open_Scopes (Entity (N))
16650 and then not In_Access_Definition (N);
16651 end Is_Protected_Self_Reference;
16653 -----------------------------
16654 -- Is_RCI_Pkg_Spec_Or_Body --
16655 -----------------------------
16657 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
16659 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
16660 -- Return True if the unit of Cunit is an RCI package declaration
16662 ---------------------------
16663 -- Is_RCI_Pkg_Decl_Cunit --
16664 ---------------------------
16666 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
16667 The_Unit : constant Node_Id := Unit (Cunit);
16669 begin
16670 if Nkind (The_Unit) /= N_Package_Declaration then
16671 return False;
16672 end if;
16674 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
16675 end Is_RCI_Pkg_Decl_Cunit;
16677 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
16679 begin
16680 return Is_RCI_Pkg_Decl_Cunit (Cunit)
16681 or else
16682 (Nkind (Unit (Cunit)) = N_Package_Body
16683 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
16684 end Is_RCI_Pkg_Spec_Or_Body;
16686 -----------------------------------------
16687 -- Is_Remote_Access_To_Class_Wide_Type --
16688 -----------------------------------------
16690 function Is_Remote_Access_To_Class_Wide_Type
16691 (E : Entity_Id) return Boolean
16693 begin
16694 -- A remote access to class-wide type is a general access to object type
16695 -- declared in the visible part of a Remote_Types or Remote_Call_
16696 -- Interface unit.
16698 return Ekind (E) = E_General_Access_Type
16699 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16700 end Is_Remote_Access_To_Class_Wide_Type;
16702 -----------------------------------------
16703 -- Is_Remote_Access_To_Subprogram_Type --
16704 -----------------------------------------
16706 function Is_Remote_Access_To_Subprogram_Type
16707 (E : Entity_Id) return Boolean
16709 begin
16710 return (Ekind (E) = E_Access_Subprogram_Type
16711 or else (Ekind (E) = E_Record_Type
16712 and then Present (Corresponding_Remote_Type (E))))
16713 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16714 end Is_Remote_Access_To_Subprogram_Type;
16716 --------------------
16717 -- Is_Remote_Call --
16718 --------------------
16720 function Is_Remote_Call (N : Node_Id) return Boolean is
16721 begin
16722 if Nkind (N) not in N_Subprogram_Call then
16724 -- An entry call cannot be remote
16726 return False;
16728 elsif Nkind (Name (N)) in N_Has_Entity
16729 and then Is_Remote_Call_Interface (Entity (Name (N)))
16730 then
16731 -- A subprogram declared in the spec of a RCI package is remote
16733 return True;
16735 elsif Nkind (Name (N)) = N_Explicit_Dereference
16736 and then Is_Remote_Access_To_Subprogram_Type
16737 (Etype (Prefix (Name (N))))
16738 then
16739 -- The dereference of a RAS is a remote call
16741 return True;
16743 elsif Present (Controlling_Argument (N))
16744 and then Is_Remote_Access_To_Class_Wide_Type
16745 (Etype (Controlling_Argument (N)))
16746 then
16747 -- Any primitive operation call with a controlling argument of
16748 -- a RACW type is a remote call.
16750 return True;
16751 end if;
16753 -- All other calls are local calls
16755 return False;
16756 end Is_Remote_Call;
16758 ----------------------
16759 -- Is_Renamed_Entry --
16760 ----------------------
16762 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
16763 Orig_Node : Node_Id := Empty;
16764 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
16766 function Is_Entry (Nam : Node_Id) return Boolean;
16767 -- Determine whether Nam is an entry. Traverse selectors if there are
16768 -- nested selected components.
16770 --------------
16771 -- Is_Entry --
16772 --------------
16774 function Is_Entry (Nam : Node_Id) return Boolean is
16775 begin
16776 if Nkind (Nam) = N_Selected_Component then
16777 return Is_Entry (Selector_Name (Nam));
16778 end if;
16780 return Ekind (Entity (Nam)) = E_Entry;
16781 end Is_Entry;
16783 -- Start of processing for Is_Renamed_Entry
16785 begin
16786 if Present (Alias (Proc_Nam)) then
16787 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
16788 end if;
16790 -- Look for a rewritten subprogram renaming declaration
16792 if Nkind (Subp_Decl) = N_Subprogram_Declaration
16793 and then Present (Original_Node (Subp_Decl))
16794 then
16795 Orig_Node := Original_Node (Subp_Decl);
16796 end if;
16798 -- The rewritten subprogram is actually an entry
16800 if Present (Orig_Node)
16801 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
16802 and then Is_Entry (Name (Orig_Node))
16803 then
16804 return True;
16805 end if;
16807 return False;
16808 end Is_Renamed_Entry;
16810 -----------------------------
16811 -- Is_Renaming_Declaration --
16812 -----------------------------
16814 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
16815 begin
16816 case Nkind (N) is
16817 when N_Exception_Renaming_Declaration
16818 | N_Generic_Function_Renaming_Declaration
16819 | N_Generic_Package_Renaming_Declaration
16820 | N_Generic_Procedure_Renaming_Declaration
16821 | N_Object_Renaming_Declaration
16822 | N_Package_Renaming_Declaration
16823 | N_Subprogram_Renaming_Declaration
16825 return True;
16827 when others =>
16828 return False;
16829 end case;
16830 end Is_Renaming_Declaration;
16832 ----------------------------
16833 -- Is_Reversible_Iterator --
16834 ----------------------------
16836 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
16837 Ifaces_List : Elist_Id;
16838 Iface_Elmt : Elmt_Id;
16839 Iface : Entity_Id;
16841 begin
16842 if Is_Class_Wide_Type (Typ)
16843 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
16844 and then In_Predefined_Unit (Root_Type (Typ))
16845 then
16846 return True;
16848 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
16849 return False;
16851 else
16852 Collect_Interfaces (Typ, Ifaces_List);
16854 Iface_Elmt := First_Elmt (Ifaces_List);
16855 while Present (Iface_Elmt) loop
16856 Iface := Node (Iface_Elmt);
16857 if Chars (Iface) = Name_Reversible_Iterator
16858 and then In_Predefined_Unit (Iface)
16859 then
16860 return True;
16861 end if;
16863 Next_Elmt (Iface_Elmt);
16864 end loop;
16865 end if;
16867 return False;
16868 end Is_Reversible_Iterator;
16870 ----------------------
16871 -- Is_Selector_Name --
16872 ----------------------
16874 function Is_Selector_Name (N : Node_Id) return Boolean is
16875 begin
16876 if not Is_List_Member (N) then
16877 declare
16878 P : constant Node_Id := Parent (N);
16879 begin
16880 return Nkind_In (P, N_Expanded_Name,
16881 N_Generic_Association,
16882 N_Parameter_Association,
16883 N_Selected_Component)
16884 and then Selector_Name (P) = N;
16885 end;
16887 else
16888 declare
16889 L : constant List_Id := List_Containing (N);
16890 P : constant Node_Id := Parent (L);
16891 begin
16892 return (Nkind (P) = N_Discriminant_Association
16893 and then Selector_Names (P) = L)
16894 or else
16895 (Nkind (P) = N_Component_Association
16896 and then Choices (P) = L);
16897 end;
16898 end if;
16899 end Is_Selector_Name;
16901 ---------------------------------
16902 -- Is_Single_Concurrent_Object --
16903 ---------------------------------
16905 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
16906 begin
16907 return
16908 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
16909 end Is_Single_Concurrent_Object;
16911 -------------------------------
16912 -- Is_Single_Concurrent_Type --
16913 -------------------------------
16915 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
16916 begin
16917 return
16918 Ekind_In (Id, E_Protected_Type, E_Task_Type)
16919 and then Is_Single_Concurrent_Type_Declaration
16920 (Declaration_Node (Id));
16921 end Is_Single_Concurrent_Type;
16923 -------------------------------------------
16924 -- Is_Single_Concurrent_Type_Declaration --
16925 -------------------------------------------
16927 function Is_Single_Concurrent_Type_Declaration
16928 (N : Node_Id) return Boolean
16930 begin
16931 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
16932 N_Single_Task_Declaration);
16933 end Is_Single_Concurrent_Type_Declaration;
16935 ---------------------------------------------
16936 -- Is_Single_Precision_Floating_Point_Type --
16937 ---------------------------------------------
16939 function Is_Single_Precision_Floating_Point_Type
16940 (E : Entity_Id) return Boolean is
16941 begin
16942 return Is_Floating_Point_Type (E)
16943 and then Machine_Radix_Value (E) = Uint_2
16944 and then Machine_Mantissa_Value (E) = Uint_24
16945 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
16946 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
16947 end Is_Single_Precision_Floating_Point_Type;
16949 --------------------------------
16950 -- Is_Single_Protected_Object --
16951 --------------------------------
16953 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
16954 begin
16955 return
16956 Ekind (Id) = E_Variable
16957 and then Ekind (Etype (Id)) = E_Protected_Type
16958 and then Is_Single_Concurrent_Type (Etype (Id));
16959 end Is_Single_Protected_Object;
16961 ---------------------------
16962 -- Is_Single_Task_Object --
16963 ---------------------------
16965 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
16966 begin
16967 return
16968 Ekind (Id) = E_Variable
16969 and then Ekind (Etype (Id)) = E_Task_Type
16970 and then Is_Single_Concurrent_Type (Etype (Id));
16971 end Is_Single_Task_Object;
16973 -------------------------------------
16974 -- Is_SPARK_05_Initialization_Expr --
16975 -------------------------------------
16977 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
16978 Is_Ok : Boolean;
16979 Expr : Node_Id;
16980 Comp_Assn : Node_Id;
16981 Orig_N : constant Node_Id := Original_Node (N);
16983 begin
16984 Is_Ok := True;
16986 if not Comes_From_Source (Orig_N) then
16987 goto Done;
16988 end if;
16990 pragma Assert (Nkind (Orig_N) in N_Subexpr);
16992 case Nkind (Orig_N) is
16993 when N_Character_Literal
16994 | N_Integer_Literal
16995 | N_Real_Literal
16996 | N_String_Literal
16998 null;
17000 when N_Expanded_Name
17001 | N_Identifier
17003 if Is_Entity_Name (Orig_N)
17004 and then Present (Entity (Orig_N)) -- needed in some cases
17005 then
17006 case Ekind (Entity (Orig_N)) is
17007 when E_Constant
17008 | E_Enumeration_Literal
17009 | E_Named_Integer
17010 | E_Named_Real
17012 null;
17014 when others =>
17015 if Is_Type (Entity (Orig_N)) then
17016 null;
17017 else
17018 Is_Ok := False;
17019 end if;
17020 end case;
17021 end if;
17023 when N_Qualified_Expression
17024 | N_Type_Conversion
17026 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17028 when N_Unary_Op =>
17029 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17031 when N_Binary_Op
17032 | N_Membership_Test
17033 | N_Short_Circuit
17035 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17036 and then
17037 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17039 when N_Aggregate
17040 | N_Extension_Aggregate
17042 if Nkind (Orig_N) = N_Extension_Aggregate then
17043 Is_Ok :=
17044 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17045 end if;
17047 Expr := First (Expressions (Orig_N));
17048 while Present (Expr) loop
17049 if not Is_SPARK_05_Initialization_Expr (Expr) then
17050 Is_Ok := False;
17051 goto Done;
17052 end if;
17054 Next (Expr);
17055 end loop;
17057 Comp_Assn := First (Component_Associations (Orig_N));
17058 while Present (Comp_Assn) loop
17059 Expr := Expression (Comp_Assn);
17061 -- Note: test for Present here needed for box assocation
17063 if Present (Expr)
17064 and then not Is_SPARK_05_Initialization_Expr (Expr)
17065 then
17066 Is_Ok := False;
17067 goto Done;
17068 end if;
17070 Next (Comp_Assn);
17071 end loop;
17073 when N_Attribute_Reference =>
17074 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17075 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17076 end if;
17078 Expr := First (Expressions (Orig_N));
17079 while Present (Expr) loop
17080 if not Is_SPARK_05_Initialization_Expr (Expr) then
17081 Is_Ok := False;
17082 goto Done;
17083 end if;
17085 Next (Expr);
17086 end loop;
17088 -- Selected components might be expanded named not yet resolved, so
17089 -- default on the safe side. (Eg on sparklex.ads)
17091 when N_Selected_Component =>
17092 null;
17094 when others =>
17095 Is_Ok := False;
17096 end case;
17098 <<Done>>
17099 return Is_Ok;
17100 end Is_SPARK_05_Initialization_Expr;
17102 ----------------------------------
17103 -- Is_SPARK_05_Object_Reference --
17104 ----------------------------------
17106 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17107 begin
17108 if Is_Entity_Name (N) then
17109 return Present (Entity (N))
17110 and then
17111 (Ekind_In (Entity (N), E_Constant, E_Variable)
17112 or else Ekind (Entity (N)) in Formal_Kind);
17114 else
17115 case Nkind (N) is
17116 when N_Selected_Component =>
17117 return Is_SPARK_05_Object_Reference (Prefix (N));
17119 when others =>
17120 return False;
17121 end case;
17122 end if;
17123 end Is_SPARK_05_Object_Reference;
17125 -----------------------------
17126 -- Is_Specific_Tagged_Type --
17127 -----------------------------
17129 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17130 Full_Typ : Entity_Id;
17132 begin
17133 -- Handle private types
17135 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17136 Full_Typ := Full_View (Typ);
17137 else
17138 Full_Typ := Typ;
17139 end if;
17141 -- A specific tagged type is a non-class-wide tagged type
17143 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17144 end Is_Specific_Tagged_Type;
17146 ------------------
17147 -- Is_Statement --
17148 ------------------
17150 function Is_Statement (N : Node_Id) return Boolean is
17151 begin
17152 return
17153 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17154 or else Nkind (N) = N_Procedure_Call_Statement;
17155 end Is_Statement;
17157 ---------------------------------------
17158 -- Is_Subprogram_Contract_Annotation --
17159 ---------------------------------------
17161 function Is_Subprogram_Contract_Annotation
17162 (Item : Node_Id) return Boolean
17164 Nam : Name_Id;
17166 begin
17167 if Nkind (Item) = N_Aspect_Specification then
17168 Nam := Chars (Identifier (Item));
17170 else pragma Assert (Nkind (Item) = N_Pragma);
17171 Nam := Pragma_Name (Item);
17172 end if;
17174 return Nam = Name_Contract_Cases
17175 or else Nam = Name_Depends
17176 or else Nam = Name_Extensions_Visible
17177 or else Nam = Name_Global
17178 or else Nam = Name_Post
17179 or else Nam = Name_Post_Class
17180 or else Nam = Name_Postcondition
17181 or else Nam = Name_Pre
17182 or else Nam = Name_Pre_Class
17183 or else Nam = Name_Precondition
17184 or else Nam = Name_Refined_Depends
17185 or else Nam = Name_Refined_Global
17186 or else Nam = Name_Refined_Post
17187 or else Nam = Name_Test_Case;
17188 end Is_Subprogram_Contract_Annotation;
17190 --------------------------------------------------
17191 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17192 --------------------------------------------------
17194 function Is_Subprogram_Stub_Without_Prior_Declaration
17195 (N : Node_Id) return Boolean
17197 begin
17198 -- A subprogram stub without prior declaration serves as declaration for
17199 -- the actual subprogram body. As such, it has an attached defining
17200 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
17202 return Nkind (N) = N_Subprogram_Body_Stub
17203 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
17204 end Is_Subprogram_Stub_Without_Prior_Declaration;
17206 ---------------------------
17207 -- Is_Suitable_Primitive --
17208 ---------------------------
17210 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
17211 begin
17212 -- The Default_Initial_Condition and invariant procedures must not be
17213 -- treated as primitive operations even when they apply to a tagged
17214 -- type. These routines must not act as targets of dispatching calls
17215 -- because they already utilize class-wide-precondition semantics to
17216 -- handle inheritance and overriding.
17218 if Ekind (Subp_Id) = E_Procedure
17219 and then (Is_DIC_Procedure (Subp_Id)
17220 or else
17221 Is_Invariant_Procedure (Subp_Id))
17222 then
17223 return False;
17224 end if;
17226 return True;
17227 end Is_Suitable_Primitive;
17229 --------------------------
17230 -- Is_Suspension_Object --
17231 --------------------------
17233 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
17234 begin
17235 -- This approach does an exact name match rather than to rely on
17236 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17237 -- front end at point where all auxiliary tables are locked and any
17238 -- modifications to them are treated as violations. Do not tamper with
17239 -- the tables, instead examine the Chars fields of all the scopes of Id.
17241 return
17242 Chars (Id) = Name_Suspension_Object
17243 and then Present (Scope (Id))
17244 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
17245 and then Present (Scope (Scope (Id)))
17246 and then Chars (Scope (Scope (Id))) = Name_Ada
17247 and then Present (Scope (Scope (Scope (Id))))
17248 and then Scope (Scope (Scope (Id))) = Standard_Standard;
17249 end Is_Suspension_Object;
17251 ----------------------------
17252 -- Is_Synchronized_Object --
17253 ----------------------------
17255 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
17256 Prag : Node_Id;
17258 begin
17259 if Is_Object (Id) then
17261 -- The object is synchronized if it is of a type that yields a
17262 -- synchronized object.
17264 if Yields_Synchronized_Object (Etype (Id)) then
17265 return True;
17267 -- The object is synchronized if it is atomic and Async_Writers is
17268 -- enabled.
17270 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
17271 return True;
17273 -- A constant is a synchronized object by default
17275 elsif Ekind (Id) = E_Constant then
17276 return True;
17278 -- A variable is a synchronized object if it is subject to pragma
17279 -- Constant_After_Elaboration.
17281 elsif Ekind (Id) = E_Variable then
17282 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
17284 return Present (Prag) and then Is_Enabled_Pragma (Prag);
17285 end if;
17286 end if;
17288 -- Otherwise the input is not an object or it does not qualify as a
17289 -- synchronized object.
17291 return False;
17292 end Is_Synchronized_Object;
17294 ---------------------------------
17295 -- Is_Synchronized_Tagged_Type --
17296 ---------------------------------
17298 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
17299 Kind : constant Entity_Kind := Ekind (Base_Type (E));
17301 begin
17302 -- A task or protected type derived from an interface is a tagged type.
17303 -- Such a tagged type is called a synchronized tagged type, as are
17304 -- synchronized interfaces and private extensions whose declaration
17305 -- includes the reserved word synchronized.
17307 return (Is_Tagged_Type (E)
17308 and then (Kind = E_Task_Type
17309 or else
17310 Kind = E_Protected_Type))
17311 or else
17312 (Is_Interface (E)
17313 and then Is_Synchronized_Interface (E))
17314 or else
17315 (Ekind (E) = E_Record_Type_With_Private
17316 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
17317 and then (Synchronized_Present (Parent (E))
17318 or else Is_Synchronized_Interface (Etype (E))));
17319 end Is_Synchronized_Tagged_Type;
17321 -----------------
17322 -- Is_Transfer --
17323 -----------------
17325 function Is_Transfer (N : Node_Id) return Boolean is
17326 Kind : constant Node_Kind := Nkind (N);
17328 begin
17329 if Kind = N_Simple_Return_Statement
17330 or else
17331 Kind = N_Extended_Return_Statement
17332 or else
17333 Kind = N_Goto_Statement
17334 or else
17335 Kind = N_Raise_Statement
17336 or else
17337 Kind = N_Requeue_Statement
17338 then
17339 return True;
17341 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
17342 and then No (Condition (N))
17343 then
17344 return True;
17346 elsif Kind = N_Procedure_Call_Statement
17347 and then Is_Entity_Name (Name (N))
17348 and then Present (Entity (Name (N)))
17349 and then No_Return (Entity (Name (N)))
17350 then
17351 return True;
17353 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
17354 return True;
17356 else
17357 return False;
17358 end if;
17359 end Is_Transfer;
17361 -------------
17362 -- Is_True --
17363 -------------
17365 function Is_True (U : Uint) return Boolean is
17366 begin
17367 return (U /= 0);
17368 end Is_True;
17370 --------------------------------------
17371 -- Is_Unchecked_Conversion_Instance --
17372 --------------------------------------
17374 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
17375 Par : Node_Id;
17377 begin
17378 -- Look for a function whose generic parent is the predefined intrinsic
17379 -- function Unchecked_Conversion, or for one that renames such an
17380 -- instance.
17382 if Ekind (Id) = E_Function then
17383 Par := Parent (Id);
17385 if Nkind (Par) = N_Function_Specification then
17386 Par := Generic_Parent (Par);
17388 if Present (Par) then
17389 return
17390 Chars (Par) = Name_Unchecked_Conversion
17391 and then Is_Intrinsic_Subprogram (Par)
17392 and then In_Predefined_Unit (Par);
17393 else
17394 return
17395 Present (Alias (Id))
17396 and then Is_Unchecked_Conversion_Instance (Alias (Id));
17397 end if;
17398 end if;
17399 end if;
17401 return False;
17402 end Is_Unchecked_Conversion_Instance;
17404 -------------------------------
17405 -- Is_Universal_Numeric_Type --
17406 -------------------------------
17408 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
17409 begin
17410 return T = Universal_Integer or else T = Universal_Real;
17411 end Is_Universal_Numeric_Type;
17413 ------------------------------
17414 -- Is_User_Defined_Equality --
17415 ------------------------------
17417 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
17418 begin
17419 return Ekind (Id) = E_Function
17420 and then Chars (Id) = Name_Op_Eq
17421 and then Comes_From_Source (Id)
17423 -- Internally generated equalities have a full type declaration
17424 -- as their parent.
17426 and then Nkind (Parent (Id)) = N_Function_Specification;
17427 end Is_User_Defined_Equality;
17429 --------------------------------------
17430 -- Is_Validation_Variable_Reference --
17431 --------------------------------------
17433 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
17434 Var : constant Node_Id := Unqual_Conv (N);
17435 Var_Id : Entity_Id;
17437 begin
17438 Var_Id := Empty;
17440 if Is_Entity_Name (Var) then
17441 Var_Id := Entity (Var);
17442 end if;
17444 return
17445 Present (Var_Id)
17446 and then Ekind (Var_Id) = E_Variable
17447 and then Present (Validated_Object (Var_Id));
17448 end Is_Validation_Variable_Reference;
17450 ----------------------------
17451 -- Is_Variable_Size_Array --
17452 ----------------------------
17454 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
17455 Idx : Node_Id;
17457 begin
17458 pragma Assert (Is_Array_Type (E));
17460 -- Check if some index is initialized with a non-constant value
17462 Idx := First_Index (E);
17463 while Present (Idx) loop
17464 if Nkind (Idx) = N_Range then
17465 if not Is_Constant_Bound (Low_Bound (Idx))
17466 or else not Is_Constant_Bound (High_Bound (Idx))
17467 then
17468 return True;
17469 end if;
17470 end if;
17472 Idx := Next_Index (Idx);
17473 end loop;
17475 return False;
17476 end Is_Variable_Size_Array;
17478 -----------------------------
17479 -- Is_Variable_Size_Record --
17480 -----------------------------
17482 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
17483 Comp : Entity_Id;
17484 Comp_Typ : Entity_Id;
17486 begin
17487 pragma Assert (Is_Record_Type (E));
17489 Comp := First_Entity (E);
17490 while Present (Comp) loop
17491 Comp_Typ := Etype (Comp);
17493 -- Recursive call if the record type has discriminants
17495 if Is_Record_Type (Comp_Typ)
17496 and then Has_Discriminants (Comp_Typ)
17497 and then Is_Variable_Size_Record (Comp_Typ)
17498 then
17499 return True;
17501 elsif Is_Array_Type (Comp_Typ)
17502 and then Is_Variable_Size_Array (Comp_Typ)
17503 then
17504 return True;
17505 end if;
17507 Next_Entity (Comp);
17508 end loop;
17510 return False;
17511 end Is_Variable_Size_Record;
17513 -----------------
17514 -- Is_Variable --
17515 -----------------
17517 function Is_Variable
17518 (N : Node_Id;
17519 Use_Original_Node : Boolean := True) return Boolean
17521 Orig_Node : Node_Id;
17523 function In_Protected_Function (E : Entity_Id) return Boolean;
17524 -- Within a protected function, the private components of the enclosing
17525 -- protected type are constants. A function nested within a (protected)
17526 -- procedure is not itself protected. Within the body of a protected
17527 -- function the current instance of the protected type is a constant.
17529 function Is_Variable_Prefix (P : Node_Id) return Boolean;
17530 -- Prefixes can involve implicit dereferences, in which case we must
17531 -- test for the case of a reference of a constant access type, which can
17532 -- can never be a variable.
17534 ---------------------------
17535 -- In_Protected_Function --
17536 ---------------------------
17538 function In_Protected_Function (E : Entity_Id) return Boolean is
17539 Prot : Entity_Id;
17540 S : Entity_Id;
17542 begin
17543 -- E is the current instance of a type
17545 if Is_Type (E) then
17546 Prot := E;
17548 -- E is an object
17550 else
17551 Prot := Scope (E);
17552 end if;
17554 if not Is_Protected_Type (Prot) then
17555 return False;
17557 else
17558 S := Current_Scope;
17559 while Present (S) and then S /= Prot loop
17560 if Ekind (S) = E_Function and then Scope (S) = Prot then
17561 return True;
17562 end if;
17564 S := Scope (S);
17565 end loop;
17567 return False;
17568 end if;
17569 end In_Protected_Function;
17571 ------------------------
17572 -- Is_Variable_Prefix --
17573 ------------------------
17575 function Is_Variable_Prefix (P : Node_Id) return Boolean is
17576 begin
17577 if Is_Access_Type (Etype (P)) then
17578 return not Is_Access_Constant (Root_Type (Etype (P)));
17580 -- For the case of an indexed component whose prefix has a packed
17581 -- array type, the prefix has been rewritten into a type conversion.
17582 -- Determine variable-ness from the converted expression.
17584 elsif Nkind (P) = N_Type_Conversion
17585 and then not Comes_From_Source (P)
17586 and then Is_Array_Type (Etype (P))
17587 and then Is_Packed (Etype (P))
17588 then
17589 return Is_Variable (Expression (P));
17591 else
17592 return Is_Variable (P);
17593 end if;
17594 end Is_Variable_Prefix;
17596 -- Start of processing for Is_Variable
17598 begin
17599 -- Special check, allow x'Deref(expr) as a variable
17601 if Nkind (N) = N_Attribute_Reference
17602 and then Attribute_Name (N) = Name_Deref
17603 then
17604 return True;
17605 end if;
17607 -- Check if we perform the test on the original node since this may be a
17608 -- test of syntactic categories which must not be disturbed by whatever
17609 -- rewriting might have occurred. For example, an aggregate, which is
17610 -- certainly NOT a variable, could be turned into a variable by
17611 -- expansion.
17613 if Use_Original_Node then
17614 Orig_Node := Original_Node (N);
17615 else
17616 Orig_Node := N;
17617 end if;
17619 -- Definitely OK if Assignment_OK is set. Since this is something that
17620 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
17622 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
17623 return True;
17625 -- Normally we go to the original node, but there is one exception where
17626 -- we use the rewritten node, namely when it is an explicit dereference.
17627 -- The generated code may rewrite a prefix which is an access type with
17628 -- an explicit dereference. The dereference is a variable, even though
17629 -- the original node may not be (since it could be a constant of the
17630 -- access type).
17632 -- In Ada 2005 we have a further case to consider: the prefix may be a
17633 -- function call given in prefix notation. The original node appears to
17634 -- be a selected component, but we need to examine the call.
17636 elsif Nkind (N) = N_Explicit_Dereference
17637 and then Nkind (Orig_Node) /= N_Explicit_Dereference
17638 and then Present (Etype (Orig_Node))
17639 and then Is_Access_Type (Etype (Orig_Node))
17640 then
17641 -- Note that if the prefix is an explicit dereference that does not
17642 -- come from source, we must check for a rewritten function call in
17643 -- prefixed notation before other forms of rewriting, to prevent a
17644 -- compiler crash.
17646 return
17647 (Nkind (Orig_Node) = N_Function_Call
17648 and then not Is_Access_Constant (Etype (Prefix (N))))
17649 or else
17650 Is_Variable_Prefix (Original_Node (Prefix (N)));
17652 -- in Ada 2012, the dereference may have been added for a type with
17653 -- a declared implicit dereference aspect. Check that it is not an
17654 -- access to constant.
17656 elsif Nkind (N) = N_Explicit_Dereference
17657 and then Present (Etype (Orig_Node))
17658 and then Ada_Version >= Ada_2012
17659 and then Has_Implicit_Dereference (Etype (Orig_Node))
17660 then
17661 return not Is_Access_Constant (Etype (Prefix (N)));
17663 -- A function call is never a variable
17665 elsif Nkind (N) = N_Function_Call then
17666 return False;
17668 -- All remaining checks use the original node
17670 elsif Is_Entity_Name (Orig_Node)
17671 and then Present (Entity (Orig_Node))
17672 then
17673 declare
17674 E : constant Entity_Id := Entity (Orig_Node);
17675 K : constant Entity_Kind := Ekind (E);
17677 begin
17678 return (K = E_Variable
17679 and then Nkind (Parent (E)) /= N_Exception_Handler)
17680 or else (K = E_Component
17681 and then not In_Protected_Function (E))
17682 or else K = E_Out_Parameter
17683 or else K = E_In_Out_Parameter
17684 or else K = E_Generic_In_Out_Parameter
17686 -- Current instance of type. If this is a protected type, check
17687 -- we are not within the body of one of its protected functions.
17689 or else (Is_Type (E)
17690 and then In_Open_Scopes (E)
17691 and then not In_Protected_Function (E))
17693 or else (Is_Incomplete_Or_Private_Type (E)
17694 and then In_Open_Scopes (Full_View (E)));
17695 end;
17697 else
17698 case Nkind (Orig_Node) is
17699 when N_Indexed_Component
17700 | N_Slice
17702 return Is_Variable_Prefix (Prefix (Orig_Node));
17704 when N_Selected_Component =>
17705 return (Is_Variable (Selector_Name (Orig_Node))
17706 and then Is_Variable_Prefix (Prefix (Orig_Node)))
17707 or else
17708 (Nkind (N) = N_Expanded_Name
17709 and then Scope (Entity (N)) = Entity (Prefix (N)));
17711 -- For an explicit dereference, the type of the prefix cannot
17712 -- be an access to constant or an access to subprogram.
17714 when N_Explicit_Dereference =>
17715 declare
17716 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
17717 begin
17718 return Is_Access_Type (Typ)
17719 and then not Is_Access_Constant (Root_Type (Typ))
17720 and then Ekind (Typ) /= E_Access_Subprogram_Type;
17721 end;
17723 -- The type conversion is the case where we do not deal with the
17724 -- context dependent special case of an actual parameter. Thus
17725 -- the type conversion is only considered a variable for the
17726 -- purposes of this routine if the target type is tagged. However,
17727 -- a type conversion is considered to be a variable if it does not
17728 -- come from source (this deals for example with the conversions
17729 -- of expressions to their actual subtypes).
17731 when N_Type_Conversion =>
17732 return Is_Variable (Expression (Orig_Node))
17733 and then
17734 (not Comes_From_Source (Orig_Node)
17735 or else
17736 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
17737 and then
17738 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
17740 -- GNAT allows an unchecked type conversion as a variable. This
17741 -- only affects the generation of internal expanded code, since
17742 -- calls to instantiations of Unchecked_Conversion are never
17743 -- considered variables (since they are function calls).
17745 when N_Unchecked_Type_Conversion =>
17746 return Is_Variable (Expression (Orig_Node));
17748 when others =>
17749 return False;
17750 end case;
17751 end if;
17752 end Is_Variable;
17754 ---------------------------
17755 -- Is_Visibly_Controlled --
17756 ---------------------------
17758 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
17759 Root : constant Entity_Id := Root_Type (T);
17760 begin
17761 return Chars (Scope (Root)) = Name_Finalization
17762 and then Chars (Scope (Scope (Root))) = Name_Ada
17763 and then Scope (Scope (Scope (Root))) = Standard_Standard;
17764 end Is_Visibly_Controlled;
17766 --------------------------
17767 -- Is_Volatile_Function --
17768 --------------------------
17770 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
17771 begin
17772 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
17774 -- A function declared within a protected type is volatile
17776 if Is_Protected_Type (Scope (Func_Id)) then
17777 return True;
17779 -- An instance of Ada.Unchecked_Conversion is a volatile function if
17780 -- either the source or the target are effectively volatile.
17782 elsif Is_Unchecked_Conversion_Instance (Func_Id)
17783 and then Has_Effectively_Volatile_Profile (Func_Id)
17784 then
17785 return True;
17787 -- Otherwise the function is treated as volatile if it is subject to
17788 -- enabled pragma Volatile_Function.
17790 else
17791 return
17792 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
17793 end if;
17794 end Is_Volatile_Function;
17796 ------------------------
17797 -- Is_Volatile_Object --
17798 ------------------------
17800 function Is_Volatile_Object (N : Node_Id) return Boolean is
17801 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
17802 -- If prefix is an implicit dereference, examine designated type
17804 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
17805 -- Determines if given object has volatile components
17807 ------------------------
17808 -- Is_Volatile_Prefix --
17809 ------------------------
17811 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
17812 Typ : constant Entity_Id := Etype (N);
17814 begin
17815 if Is_Access_Type (Typ) then
17816 declare
17817 Dtyp : constant Entity_Id := Designated_Type (Typ);
17819 begin
17820 return Is_Volatile (Dtyp)
17821 or else Has_Volatile_Components (Dtyp);
17822 end;
17824 else
17825 return Object_Has_Volatile_Components (N);
17826 end if;
17827 end Is_Volatile_Prefix;
17829 ------------------------------------
17830 -- Object_Has_Volatile_Components --
17831 ------------------------------------
17833 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
17834 Typ : constant Entity_Id := Etype (N);
17836 begin
17837 if Is_Volatile (Typ)
17838 or else Has_Volatile_Components (Typ)
17839 then
17840 return True;
17842 elsif Is_Entity_Name (N)
17843 and then (Has_Volatile_Components (Entity (N))
17844 or else Is_Volatile (Entity (N)))
17845 then
17846 return True;
17848 elsif Nkind (N) = N_Indexed_Component
17849 or else Nkind (N) = N_Selected_Component
17850 then
17851 return Is_Volatile_Prefix (Prefix (N));
17853 else
17854 return False;
17855 end if;
17856 end Object_Has_Volatile_Components;
17858 -- Start of processing for Is_Volatile_Object
17860 begin
17861 if Nkind (N) = N_Defining_Identifier then
17862 return Is_Volatile (N) or else Is_Volatile (Etype (N));
17864 elsif Nkind (N) = N_Expanded_Name then
17865 return Is_Volatile_Object (Entity (N));
17867 elsif Is_Volatile (Etype (N))
17868 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
17869 then
17870 return True;
17872 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
17873 and then Is_Volatile_Prefix (Prefix (N))
17874 then
17875 return True;
17877 elsif Nkind (N) = N_Selected_Component
17878 and then Is_Volatile (Entity (Selector_Name (N)))
17879 then
17880 return True;
17882 else
17883 return False;
17884 end if;
17885 end Is_Volatile_Object;
17887 -----------------------------
17888 -- Iterate_Call_Parameters --
17889 -----------------------------
17891 procedure Iterate_Call_Parameters (Call : Node_Id) is
17892 Actual : Node_Id := First_Actual (Call);
17893 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
17895 begin
17896 while Present (Formal) and then Present (Actual) loop
17897 Handle_Parameter (Formal, Actual);
17899 Next_Formal (Formal);
17900 Next_Actual (Actual);
17901 end loop;
17903 pragma Assert (No (Formal));
17904 pragma Assert (No (Actual));
17905 end Iterate_Call_Parameters;
17907 ---------------------------
17908 -- Itype_Has_Declaration --
17909 ---------------------------
17911 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
17912 begin
17913 pragma Assert (Is_Itype (Id));
17914 return Present (Parent (Id))
17915 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
17916 N_Subtype_Declaration)
17917 and then Defining_Entity (Parent (Id)) = Id;
17918 end Itype_Has_Declaration;
17920 -------------------------
17921 -- Kill_Current_Values --
17922 -------------------------
17924 procedure Kill_Current_Values
17925 (Ent : Entity_Id;
17926 Last_Assignment_Only : Boolean := False)
17928 begin
17929 if Is_Assignable (Ent) then
17930 Set_Last_Assignment (Ent, Empty);
17931 end if;
17933 if Is_Object (Ent) then
17934 if not Last_Assignment_Only then
17935 Kill_Checks (Ent);
17936 Set_Current_Value (Ent, Empty);
17938 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
17939 -- for a constant. Once the constant is elaborated, its value is
17940 -- not changed, therefore the associated flags that describe the
17941 -- value should not be modified either.
17943 if Ekind (Ent) = E_Constant then
17944 null;
17946 -- Non-constant entities
17948 else
17949 if not Can_Never_Be_Null (Ent) then
17950 Set_Is_Known_Non_Null (Ent, False);
17951 end if;
17953 Set_Is_Known_Null (Ent, False);
17955 -- Reset the Is_Known_Valid flag unless the type is always
17956 -- valid. This does not apply to a loop parameter because its
17957 -- bounds are defined by the loop header and therefore always
17958 -- valid.
17960 if not Is_Known_Valid (Etype (Ent))
17961 and then Ekind (Ent) /= E_Loop_Parameter
17962 then
17963 Set_Is_Known_Valid (Ent, False);
17964 end if;
17965 end if;
17966 end if;
17967 end if;
17968 end Kill_Current_Values;
17970 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
17971 S : Entity_Id;
17973 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
17974 -- Clear current value for entity E and all entities chained to E
17976 ------------------------------------------
17977 -- Kill_Current_Values_For_Entity_Chain --
17978 ------------------------------------------
17980 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
17981 Ent : Entity_Id;
17982 begin
17983 Ent := E;
17984 while Present (Ent) loop
17985 Kill_Current_Values (Ent, Last_Assignment_Only);
17986 Next_Entity (Ent);
17987 end loop;
17988 end Kill_Current_Values_For_Entity_Chain;
17990 -- Start of processing for Kill_Current_Values
17992 begin
17993 -- Kill all saved checks, a special case of killing saved values
17995 if not Last_Assignment_Only then
17996 Kill_All_Checks;
17997 end if;
17999 -- Loop through relevant scopes, which includes the current scope and
18000 -- any parent scopes if the current scope is a block or a package.
18002 S := Current_Scope;
18003 Scope_Loop : loop
18005 -- Clear current values of all entities in current scope
18007 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18009 -- If scope is a package, also clear current values of all private
18010 -- entities in the scope.
18012 if Is_Package_Or_Generic_Package (S)
18013 or else Is_Concurrent_Type (S)
18014 then
18015 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18016 end if;
18018 -- If this is a not a subprogram, deal with parents
18020 if not Is_Subprogram (S) then
18021 S := Scope (S);
18022 exit Scope_Loop when S = Standard_Standard;
18023 else
18024 exit Scope_Loop;
18025 end if;
18026 end loop Scope_Loop;
18027 end Kill_Current_Values;
18029 --------------------------
18030 -- Kill_Size_Check_Code --
18031 --------------------------
18033 procedure Kill_Size_Check_Code (E : Entity_Id) is
18034 begin
18035 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18036 and then Present (Size_Check_Code (E))
18037 then
18038 Remove (Size_Check_Code (E));
18039 Set_Size_Check_Code (E, Empty);
18040 end if;
18041 end Kill_Size_Check_Code;
18043 --------------------
18044 -- Known_Non_Null --
18045 --------------------
18047 function Known_Non_Null (N : Node_Id) return Boolean is
18048 Status : constant Null_Status_Kind := Null_Status (N);
18050 Id : Entity_Id;
18051 Op : Node_Kind;
18052 Val : Node_Id;
18054 begin
18055 -- The expression yields a non-null value ignoring simple flow analysis
18057 if Status = Is_Non_Null then
18058 return True;
18060 -- Otherwise check whether N is a reference to an entity that appears
18061 -- within a conditional construct.
18063 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18065 -- First check if we are in decisive conditional
18067 Get_Current_Value_Condition (N, Op, Val);
18069 if Known_Null (Val) then
18070 if Op = N_Op_Eq then
18071 return False;
18072 elsif Op = N_Op_Ne then
18073 return True;
18074 end if;
18075 end if;
18077 -- If OK to do replacement, test Is_Known_Non_Null flag
18079 Id := Entity (N);
18081 if OK_To_Do_Constant_Replacement (Id) then
18082 return Is_Known_Non_Null (Id);
18083 end if;
18084 end if;
18086 -- Otherwise it is not possible to determine whether N yields a non-null
18087 -- value.
18089 return False;
18090 end Known_Non_Null;
18092 ----------------
18093 -- Known_Null --
18094 ----------------
18096 function Known_Null (N : Node_Id) return Boolean is
18097 Status : constant Null_Status_Kind := Null_Status (N);
18099 Id : Entity_Id;
18100 Op : Node_Kind;
18101 Val : Node_Id;
18103 begin
18104 -- The expression yields a null value ignoring simple flow analysis
18106 if Status = Is_Null then
18107 return True;
18109 -- Otherwise check whether N is a reference to an entity that appears
18110 -- within a conditional construct.
18112 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18114 -- First check if we are in decisive conditional
18116 Get_Current_Value_Condition (N, Op, Val);
18118 if Known_Null (Val) then
18119 if Op = N_Op_Eq then
18120 return True;
18121 elsif Op = N_Op_Ne then
18122 return False;
18123 end if;
18124 end if;
18126 -- If OK to do replacement, test Is_Known_Null flag
18128 Id := Entity (N);
18130 if OK_To_Do_Constant_Replacement (Id) then
18131 return Is_Known_Null (Id);
18132 end if;
18133 end if;
18135 -- Otherwise it is not possible to determine whether N yields a null
18136 -- value.
18138 return False;
18139 end Known_Null;
18141 --------------------------
18142 -- Known_To_Be_Assigned --
18143 --------------------------
18145 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18146 P : constant Node_Id := Parent (N);
18148 begin
18149 case Nkind (P) is
18151 -- Test left side of assignment
18153 when N_Assignment_Statement =>
18154 return N = Name (P);
18156 -- Function call arguments are never lvalues
18158 when N_Function_Call =>
18159 return False;
18161 -- Positional parameter for procedure or accept call
18163 when N_Accept_Statement
18164 | N_Procedure_Call_Statement
18166 declare
18167 Proc : Entity_Id;
18168 Form : Entity_Id;
18169 Act : Node_Id;
18171 begin
18172 Proc := Get_Subprogram_Entity (P);
18174 if No (Proc) then
18175 return False;
18176 end if;
18178 -- If we are not a list member, something is strange, so
18179 -- be conservative and return False.
18181 if not Is_List_Member (N) then
18182 return False;
18183 end if;
18185 -- We are going to find the right formal by stepping forward
18186 -- through the formals, as we step backwards in the actuals.
18188 Form := First_Formal (Proc);
18189 Act := N;
18190 loop
18191 -- If no formal, something is weird, so be conservative
18192 -- and return False.
18194 if No (Form) then
18195 return False;
18196 end if;
18198 Prev (Act);
18199 exit when No (Act);
18200 Next_Formal (Form);
18201 end loop;
18203 return Ekind (Form) /= E_In_Parameter;
18204 end;
18206 -- Named parameter for procedure or accept call
18208 when N_Parameter_Association =>
18209 declare
18210 Proc : Entity_Id;
18211 Form : Entity_Id;
18213 begin
18214 Proc := Get_Subprogram_Entity (Parent (P));
18216 if No (Proc) then
18217 return False;
18218 end if;
18220 -- Loop through formals to find the one that matches
18222 Form := First_Formal (Proc);
18223 loop
18224 -- If no matching formal, that's peculiar, some kind of
18225 -- previous error, so return False to be conservative.
18226 -- Actually this also happens in legal code in the case
18227 -- where P is a parameter association for an Extra_Formal???
18229 if No (Form) then
18230 return False;
18231 end if;
18233 -- Else test for match
18235 if Chars (Form) = Chars (Selector_Name (P)) then
18236 return Ekind (Form) /= E_In_Parameter;
18237 end if;
18239 Next_Formal (Form);
18240 end loop;
18241 end;
18243 -- Test for appearing in a conversion that itself appears
18244 -- in an lvalue context, since this should be an lvalue.
18246 when N_Type_Conversion =>
18247 return Known_To_Be_Assigned (P);
18249 -- All other references are definitely not known to be modifications
18251 when others =>
18252 return False;
18253 end case;
18254 end Known_To_Be_Assigned;
18256 ---------------------------
18257 -- Last_Source_Statement --
18258 ---------------------------
18260 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
18261 N : Node_Id;
18263 begin
18264 N := Last (Statements (HSS));
18265 while Present (N) loop
18266 exit when Comes_From_Source (N);
18267 Prev (N);
18268 end loop;
18270 return N;
18271 end Last_Source_Statement;
18273 -----------------------
18274 -- Mark_Coextensions --
18275 -----------------------
18277 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
18278 Is_Dynamic : Boolean;
18279 -- Indicates whether the context causes nested coextensions to be
18280 -- dynamic or static
18282 function Mark_Allocator (N : Node_Id) return Traverse_Result;
18283 -- Recognize an allocator node and label it as a dynamic coextension
18285 --------------------
18286 -- Mark_Allocator --
18287 --------------------
18289 function Mark_Allocator (N : Node_Id) return Traverse_Result is
18290 begin
18291 if Nkind (N) = N_Allocator then
18292 if Is_Dynamic then
18293 Set_Is_Dynamic_Coextension (N);
18295 -- If the allocator expression is potentially dynamic, it may
18296 -- be expanded out of order and require dynamic allocation
18297 -- anyway, so we treat the coextension itself as dynamic.
18298 -- Potential optimization ???
18300 elsif Nkind (Expression (N)) = N_Qualified_Expression
18301 and then Nkind (Expression (Expression (N))) = N_Op_Concat
18302 then
18303 Set_Is_Dynamic_Coextension (N);
18304 else
18305 Set_Is_Static_Coextension (N);
18306 end if;
18307 end if;
18309 return OK;
18310 end Mark_Allocator;
18312 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
18314 -- Start of processing for Mark_Coextensions
18316 begin
18317 -- An allocator that appears on the right-hand side of an assignment is
18318 -- treated as a potentially dynamic coextension when the right-hand side
18319 -- is an allocator or a qualified expression.
18321 -- Obj := new ...'(new Coextension ...);
18323 if Nkind (Context_Nod) = N_Assignment_Statement then
18324 Is_Dynamic :=
18325 Nkind_In (Expression (Context_Nod), N_Allocator,
18326 N_Qualified_Expression);
18328 -- An allocator that appears within the expression of a simple return
18329 -- statement is treated as a potentially dynamic coextension when the
18330 -- expression is either aggregate, allocator, or qualified expression.
18332 -- return (new Coextension ...);
18333 -- return new ...'(new Coextension ...);
18335 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
18336 Is_Dynamic :=
18337 Nkind_In (Expression (Context_Nod), N_Aggregate,
18338 N_Allocator,
18339 N_Qualified_Expression);
18341 -- An alloctor that appears within the initialization expression of an
18342 -- object declaration is considered a potentially dynamic coextension
18343 -- when the initialization expression is an allocator or a qualified
18344 -- expression.
18346 -- Obj : ... := new ...'(new Coextension ...);
18348 -- A similar case arises when the object declaration is part of an
18349 -- extended return statement.
18351 -- return Obj : ... := new ...'(new Coextension ...);
18352 -- return Obj : ... := (new Coextension ...);
18354 elsif Nkind (Context_Nod) = N_Object_Declaration then
18355 Is_Dynamic :=
18356 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
18357 or else
18358 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
18360 -- This routine should not be called with constructs that cannot contain
18361 -- coextensions.
18363 else
18364 raise Program_Error;
18365 end if;
18367 Mark_Allocators (Root_Nod);
18368 end Mark_Coextensions;
18370 ---------------------------------
18371 -- Mark_Elaboration_Attributes --
18372 ---------------------------------
18374 procedure Mark_Elaboration_Attributes
18375 (N_Id : Node_Or_Entity_Id;
18376 Checks : Boolean := False;
18377 Level : Boolean := False;
18378 Modes : Boolean := False;
18379 Warnings : Boolean := False)
18381 function Elaboration_Checks_OK
18382 (Target_Id : Entity_Id;
18383 Context_Id : Entity_Id) return Boolean;
18384 -- Determine whether elaboration checks are enabled for target Target_Id
18385 -- which resides within context Context_Id.
18387 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
18388 -- Preserve relevant attributes of the context in arbitrary entity Id
18390 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
18391 -- Preserve relevant attributes of the context in arbitrary node N
18393 ---------------------------
18394 -- Elaboration_Checks_OK --
18395 ---------------------------
18397 function Elaboration_Checks_OK
18398 (Target_Id : Entity_Id;
18399 Context_Id : Entity_Id) return Boolean
18401 Encl_Scop : Entity_Id;
18403 begin
18404 -- Elaboration checks are suppressed for the target
18406 if Elaboration_Checks_Suppressed (Target_Id) then
18407 return False;
18408 end if;
18410 -- Otherwise elaboration checks are OK for the target, but may be
18411 -- suppressed for the context where the target is declared.
18413 Encl_Scop := Context_Id;
18414 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
18415 if Elaboration_Checks_Suppressed (Encl_Scop) then
18416 return False;
18417 end if;
18419 Encl_Scop := Scope (Encl_Scop);
18420 end loop;
18422 -- Neither the target nor its declarative context have elaboration
18423 -- checks suppressed.
18425 return True;
18426 end Elaboration_Checks_OK;
18428 ------------------------------------
18429 -- Mark_Elaboration_Attributes_Id --
18430 ------------------------------------
18432 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
18433 begin
18434 -- Mark the status of elaboration checks in effect. Do not reset the
18435 -- status in case the entity is reanalyzed with checks suppressed.
18437 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
18438 Set_Is_Elaboration_Checks_OK_Id (Id,
18439 Elaboration_Checks_OK
18440 (Target_Id => Id,
18441 Context_Id => Scope (Id)));
18442 end if;
18444 -- Mark the status of elaboration warnings in effect. Do not reset
18445 -- the status in case the entity is reanalyzed with warnings off.
18447 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
18448 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
18449 end if;
18450 end Mark_Elaboration_Attributes_Id;
18452 --------------------------------------
18453 -- Mark_Elaboration_Attributes_Node --
18454 --------------------------------------
18456 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
18457 function Extract_Name (N : Node_Id) return Node_Id;
18458 -- Obtain the Name attribute of call or instantiation N
18460 ------------------
18461 -- Extract_Name --
18462 ------------------
18464 function Extract_Name (N : Node_Id) return Node_Id is
18465 Nam : Node_Id;
18467 begin
18468 Nam := Name (N);
18470 -- A call to an entry family appears in indexed form
18472 if Nkind (Nam) = N_Indexed_Component then
18473 Nam := Prefix (Nam);
18474 end if;
18476 -- The name may also appear in qualified form
18478 if Nkind (Nam) = N_Selected_Component then
18479 Nam := Selector_Name (Nam);
18480 end if;
18482 return Nam;
18483 end Extract_Name;
18485 -- Local variables
18487 Context_Id : Entity_Id;
18488 Nam : Node_Id;
18490 -- Start of processing for Mark_Elaboration_Attributes_Node
18492 begin
18493 -- Mark the status of elaboration checks in effect. Do not reset the
18494 -- status in case the node is reanalyzed with checks suppressed.
18496 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
18498 -- Assignments, attribute references, and variable references do
18499 -- not have a "declarative" context.
18501 Context_Id := Empty;
18503 -- The status of elaboration checks for calls and instantiations
18504 -- depends on the most recent pragma Suppress/Unsuppress, as well
18505 -- as the suppression status of the context where the target is
18506 -- defined.
18508 -- package Pack is
18509 -- function Func ...;
18510 -- end Pack;
18512 -- with Pack;
18513 -- procedure Main is
18514 -- pragma Suppress (Elaboration_Checks, Pack);
18515 -- X : ... := Pack.Func;
18516 -- ...
18518 -- In the example above, the call to Func has elaboration checks
18519 -- enabled because there is no active general purpose suppression
18520 -- pragma, however the elaboration checks of Pack are explicitly
18521 -- suppressed. As a result the elaboration checks of the call must
18522 -- be disabled in order to preserve this dependency.
18524 if Nkind_In (N, N_Entry_Call_Statement,
18525 N_Function_Call,
18526 N_Function_Instantiation,
18527 N_Package_Instantiation,
18528 N_Procedure_Call_Statement,
18529 N_Procedure_Instantiation)
18530 then
18531 Nam := Extract_Name (N);
18533 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
18534 Context_Id := Scope (Entity (Nam));
18535 end if;
18536 end if;
18538 Set_Is_Elaboration_Checks_OK_Node (N,
18539 Elaboration_Checks_OK
18540 (Target_Id => Empty,
18541 Context_Id => Context_Id));
18542 end if;
18544 -- Mark the enclosing level of the node. Do not reset the status in
18545 -- case the node is relocated and reanalyzed.
18547 if Level and then not Is_Declaration_Level_Node (N) then
18548 Set_Is_Declaration_Level_Node (N,
18549 Find_Enclosing_Level (N) = Declaration_Level);
18550 end if;
18552 -- Mark the Ghost and SPARK mode in effect
18554 if Modes then
18555 if Ghost_Mode = Ignore then
18556 Set_Is_Ignored_Ghost_Node (N);
18557 end if;
18559 if SPARK_Mode = On then
18560 Set_Is_SPARK_Mode_On_Node (N);
18561 end if;
18562 end if;
18564 -- Mark the status of elaboration warnings in effect. Do not reset
18565 -- the status in case the node is reanalyzed with warnings off.
18567 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
18568 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
18569 end if;
18570 end Mark_Elaboration_Attributes_Node;
18572 -- Start of processing for Mark_Elaboration_Attributes
18574 begin
18575 -- Do not capture any elaboration-related attributes when switch -gnatH
18576 -- (legacy elaboration checking mode enabled) is in effect because the
18577 -- attributes are useless to the legacy model.
18579 if Legacy_Elaboration_Checks then
18580 return;
18581 end if;
18583 if Nkind (N_Id) in N_Entity then
18584 Mark_Elaboration_Attributes_Id (N_Id);
18585 else
18586 Mark_Elaboration_Attributes_Node (N_Id);
18587 end if;
18588 end Mark_Elaboration_Attributes;
18590 ----------------------------------
18591 -- Matching_Static_Array_Bounds --
18592 ----------------------------------
18594 function Matching_Static_Array_Bounds
18595 (L_Typ : Node_Id;
18596 R_Typ : Node_Id) return Boolean
18598 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
18599 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
18601 L_Index : Node_Id := Empty; -- init to ...
18602 R_Index : Node_Id := Empty; -- ...avoid warnings
18603 L_Low : Node_Id;
18604 L_High : Node_Id;
18605 L_Len : Uint;
18606 R_Low : Node_Id;
18607 R_High : Node_Id;
18608 R_Len : Uint;
18610 begin
18611 if L_Ndims /= R_Ndims then
18612 return False;
18613 end if;
18615 -- Unconstrained types do not have static bounds
18617 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
18618 return False;
18619 end if;
18621 -- First treat specially the first dimension, as the lower bound and
18622 -- length of string literals are not stored like those of arrays.
18624 if Ekind (L_Typ) = E_String_Literal_Subtype then
18625 L_Low := String_Literal_Low_Bound (L_Typ);
18626 L_Len := String_Literal_Length (L_Typ);
18627 else
18628 L_Index := First_Index (L_Typ);
18629 Get_Index_Bounds (L_Index, L_Low, L_High);
18631 if Is_OK_Static_Expression (L_Low)
18632 and then
18633 Is_OK_Static_Expression (L_High)
18634 then
18635 if Expr_Value (L_High) < Expr_Value (L_Low) then
18636 L_Len := Uint_0;
18637 else
18638 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
18639 end if;
18640 else
18641 return False;
18642 end if;
18643 end if;
18645 if Ekind (R_Typ) = E_String_Literal_Subtype then
18646 R_Low := String_Literal_Low_Bound (R_Typ);
18647 R_Len := String_Literal_Length (R_Typ);
18648 else
18649 R_Index := First_Index (R_Typ);
18650 Get_Index_Bounds (R_Index, R_Low, R_High);
18652 if Is_OK_Static_Expression (R_Low)
18653 and then
18654 Is_OK_Static_Expression (R_High)
18655 then
18656 if Expr_Value (R_High) < Expr_Value (R_Low) then
18657 R_Len := Uint_0;
18658 else
18659 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
18660 end if;
18661 else
18662 return False;
18663 end if;
18664 end if;
18666 if (Is_OK_Static_Expression (L_Low)
18667 and then
18668 Is_OK_Static_Expression (R_Low))
18669 and then Expr_Value (L_Low) = Expr_Value (R_Low)
18670 and then L_Len = R_Len
18671 then
18672 null;
18673 else
18674 return False;
18675 end if;
18677 -- Then treat all other dimensions
18679 for Indx in 2 .. L_Ndims loop
18680 Next (L_Index);
18681 Next (R_Index);
18683 Get_Index_Bounds (L_Index, L_Low, L_High);
18684 Get_Index_Bounds (R_Index, R_Low, R_High);
18686 if (Is_OK_Static_Expression (L_Low) and then
18687 Is_OK_Static_Expression (L_High) and then
18688 Is_OK_Static_Expression (R_Low) and then
18689 Is_OK_Static_Expression (R_High))
18690 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
18691 and then
18692 Expr_Value (L_High) = Expr_Value (R_High))
18693 then
18694 null;
18695 else
18696 return False;
18697 end if;
18698 end loop;
18700 -- If we fall through the loop, all indexes matched
18702 return True;
18703 end Matching_Static_Array_Bounds;
18705 -------------------
18706 -- May_Be_Lvalue --
18707 -------------------
18709 function May_Be_Lvalue (N : Node_Id) return Boolean is
18710 P : constant Node_Id := Parent (N);
18712 begin
18713 case Nkind (P) is
18715 -- Test left side of assignment
18717 when N_Assignment_Statement =>
18718 return N = Name (P);
18720 -- Test prefix of component or attribute. Note that the prefix of an
18721 -- explicit or implicit dereference cannot be an l-value. In the case
18722 -- of a 'Read attribute, the reference can be an actual in the
18723 -- argument list of the attribute.
18725 when N_Attribute_Reference =>
18726 return (N = Prefix (P)
18727 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
18728 or else
18729 Attribute_Name (P) = Name_Read;
18731 -- For an expanded name, the name is an lvalue if the expanded name
18732 -- is an lvalue, but the prefix is never an lvalue, since it is just
18733 -- the scope where the name is found.
18735 when N_Expanded_Name =>
18736 if N = Prefix (P) then
18737 return May_Be_Lvalue (P);
18738 else
18739 return False;
18740 end if;
18742 -- For a selected component A.B, A is certainly an lvalue if A.B is.
18743 -- B is a little interesting, if we have A.B := 3, there is some
18744 -- discussion as to whether B is an lvalue or not, we choose to say
18745 -- it is. Note however that A is not an lvalue if it is of an access
18746 -- type since this is an implicit dereference.
18748 when N_Selected_Component =>
18749 if N = Prefix (P)
18750 and then Present (Etype (N))
18751 and then Is_Access_Type (Etype (N))
18752 then
18753 return False;
18754 else
18755 return May_Be_Lvalue (P);
18756 end if;
18758 -- For an indexed component or slice, the index or slice bounds is
18759 -- never an lvalue. The prefix is an lvalue if the indexed component
18760 -- or slice is an lvalue, except if it is an access type, where we
18761 -- have an implicit dereference.
18763 when N_Indexed_Component
18764 | N_Slice
18766 if N /= Prefix (P)
18767 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
18768 then
18769 return False;
18770 else
18771 return May_Be_Lvalue (P);
18772 end if;
18774 -- Prefix of a reference is an lvalue if the reference is an lvalue
18776 when N_Reference =>
18777 return May_Be_Lvalue (P);
18779 -- Prefix of explicit dereference is never an lvalue
18781 when N_Explicit_Dereference =>
18782 return False;
18784 -- Positional parameter for subprogram, entry, or accept call.
18785 -- In older versions of Ada function call arguments are never
18786 -- lvalues. In Ada 2012 functions can have in-out parameters.
18788 when N_Accept_Statement
18789 | N_Entry_Call_Statement
18790 | N_Subprogram_Call
18792 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
18793 return False;
18794 end if;
18796 -- The following mechanism is clumsy and fragile. A single flag
18797 -- set in Resolve_Actuals would be preferable ???
18799 declare
18800 Proc : Entity_Id;
18801 Form : Entity_Id;
18802 Act : Node_Id;
18804 begin
18805 Proc := Get_Subprogram_Entity (P);
18807 if No (Proc) then
18808 return True;
18809 end if;
18811 -- If we are not a list member, something is strange, so be
18812 -- conservative and return True.
18814 if not Is_List_Member (N) then
18815 return True;
18816 end if;
18818 -- We are going to find the right formal by stepping forward
18819 -- through the formals, as we step backwards in the actuals.
18821 Form := First_Formal (Proc);
18822 Act := N;
18823 loop
18824 -- If no formal, something is weird, so be conservative and
18825 -- return True.
18827 if No (Form) then
18828 return True;
18829 end if;
18831 Prev (Act);
18832 exit when No (Act);
18833 Next_Formal (Form);
18834 end loop;
18836 return Ekind (Form) /= E_In_Parameter;
18837 end;
18839 -- Named parameter for procedure or accept call
18841 when N_Parameter_Association =>
18842 declare
18843 Proc : Entity_Id;
18844 Form : Entity_Id;
18846 begin
18847 Proc := Get_Subprogram_Entity (Parent (P));
18849 if No (Proc) then
18850 return True;
18851 end if;
18853 -- Loop through formals to find the one that matches
18855 Form := First_Formal (Proc);
18856 loop
18857 -- If no matching formal, that's peculiar, some kind of
18858 -- previous error, so return True to be conservative.
18859 -- Actually happens with legal code for an unresolved call
18860 -- where we may get the wrong homonym???
18862 if No (Form) then
18863 return True;
18864 end if;
18866 -- Else test for match
18868 if Chars (Form) = Chars (Selector_Name (P)) then
18869 return Ekind (Form) /= E_In_Parameter;
18870 end if;
18872 Next_Formal (Form);
18873 end loop;
18874 end;
18876 -- Test for appearing in a conversion that itself appears in an
18877 -- lvalue context, since this should be an lvalue.
18879 when N_Type_Conversion =>
18880 return May_Be_Lvalue (P);
18882 -- Test for appearance in object renaming declaration
18884 when N_Object_Renaming_Declaration =>
18885 return True;
18887 -- All other references are definitely not lvalues
18889 when others =>
18890 return False;
18891 end case;
18892 end May_Be_Lvalue;
18894 -----------------
18895 -- Might_Raise --
18896 -----------------
18898 function Might_Raise (N : Node_Id) return Boolean is
18899 Result : Boolean := False;
18901 function Process (N : Node_Id) return Traverse_Result;
18902 -- Set Result to True if we find something that could raise an exception
18904 -------------
18905 -- Process --
18906 -------------
18908 function Process (N : Node_Id) return Traverse_Result is
18909 begin
18910 if Nkind_In (N, N_Procedure_Call_Statement,
18911 N_Function_Call,
18912 N_Raise_Statement,
18913 N_Raise_Constraint_Error,
18914 N_Raise_Program_Error,
18915 N_Raise_Storage_Error)
18916 then
18917 Result := True;
18918 return Abandon;
18919 else
18920 return OK;
18921 end if;
18922 end Process;
18924 procedure Set_Result is new Traverse_Proc (Process);
18926 -- Start of processing for Might_Raise
18928 begin
18929 -- False if exceptions can't be propagated
18931 if No_Exception_Handlers_Set then
18932 return False;
18933 end if;
18935 -- If the checks handled by the back end are not disabled, we cannot
18936 -- ensure that no exception will be raised.
18938 if not Access_Checks_Suppressed (Empty)
18939 or else not Discriminant_Checks_Suppressed (Empty)
18940 or else not Range_Checks_Suppressed (Empty)
18941 or else not Index_Checks_Suppressed (Empty)
18942 or else Opt.Stack_Checking_Enabled
18943 then
18944 return True;
18945 end if;
18947 Set_Result (N);
18948 return Result;
18949 end Might_Raise;
18951 --------------------------------
18952 -- Nearest_Enclosing_Instance --
18953 --------------------------------
18955 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
18956 Inst : Entity_Id;
18958 begin
18959 Inst := Scope (E);
18960 while Present (Inst) and then Inst /= Standard_Standard loop
18961 if Is_Generic_Instance (Inst) then
18962 return Inst;
18963 end if;
18965 Inst := Scope (Inst);
18966 end loop;
18968 return Empty;
18969 end Nearest_Enclosing_Instance;
18971 ----------------------
18972 -- Needs_One_Actual --
18973 ----------------------
18975 function Needs_One_Actual (E : Entity_Id) return Boolean is
18976 Formal : Entity_Id;
18978 begin
18979 -- Ada 2005 or later, and formals present. The first formal must be
18980 -- of a type that supports prefix notation: a controlling argument,
18981 -- a class-wide type, or an access to such.
18983 if Ada_Version >= Ada_2005
18984 and then Present (First_Formal (E))
18985 and then No (Default_Value (First_Formal (E)))
18986 and then
18987 (Is_Controlling_Formal (First_Formal (E))
18988 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
18989 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
18990 then
18991 Formal := Next_Formal (First_Formal (E));
18992 while Present (Formal) loop
18993 if No (Default_Value (Formal)) then
18994 return False;
18995 end if;
18997 Next_Formal (Formal);
18998 end loop;
19000 return True;
19002 -- Ada 83/95 or no formals
19004 else
19005 return False;
19006 end if;
19007 end Needs_One_Actual;
19009 ---------------------------------
19010 -- Needs_Simple_Initialization --
19011 ---------------------------------
19013 function Needs_Simple_Initialization
19014 (Typ : Entity_Id;
19015 Consider_IS : Boolean := True) return Boolean
19017 Consider_IS_NS : constant Boolean :=
19018 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19020 begin
19021 -- Never need initialization if it is suppressed
19023 if Initialization_Suppressed (Typ) then
19024 return False;
19025 end if;
19027 -- Check for private type, in which case test applies to the underlying
19028 -- type of the private type.
19030 if Is_Private_Type (Typ) then
19031 declare
19032 RT : constant Entity_Id := Underlying_Type (Typ);
19033 begin
19034 if Present (RT) then
19035 return Needs_Simple_Initialization (RT);
19036 else
19037 return False;
19038 end if;
19039 end;
19041 -- Scalar type with Default_Value aspect requires initialization
19043 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
19044 return True;
19046 -- Cases needing simple initialization are access types, and, if pragma
19047 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19048 -- types.
19050 elsif Is_Access_Type (Typ)
19051 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
19052 then
19053 return True;
19055 -- If Initialize/Normalize_Scalars is in effect, string objects also
19056 -- need initialization, unless they are created in the course of
19057 -- expanding an aggregate (since in the latter case they will be
19058 -- filled with appropriate initializing values before they are used).
19060 elsif Consider_IS_NS
19061 and then Is_Standard_String_Type (Typ)
19062 and then
19063 (not Is_Itype (Typ)
19064 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
19065 then
19066 return True;
19068 else
19069 return False;
19070 end if;
19071 end Needs_Simple_Initialization;
19073 ------------------------
19074 -- New_Copy_List_Tree --
19075 ------------------------
19077 function New_Copy_List_Tree (List : List_Id) return List_Id is
19078 NL : List_Id;
19079 E : Node_Id;
19081 begin
19082 if List = No_List then
19083 return No_List;
19085 else
19086 NL := New_List;
19087 E := First (List);
19089 while Present (E) loop
19090 Append (New_Copy_Tree (E), NL);
19091 E := Next (E);
19092 end loop;
19094 return NL;
19095 end if;
19096 end New_Copy_List_Tree;
19098 -------------------
19099 -- New_Copy_Tree --
19100 -------------------
19102 -- The following tables play a key role in replicating entities and Itypes.
19103 -- They are intentionally declared at the library level rather than within
19104 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19105 -- optimization saves up to 2% of the entire compilation time spent in the
19106 -- front end. Care should be taken to reset the tables on each new call to
19107 -- New_Copy_Tree.
19109 NCT_Table_Max : constant := 511;
19111 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
19113 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
19114 -- Obtain the hash value of node or entity Key
19116 --------------------
19117 -- NCT_Table_Hash --
19118 --------------------
19120 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
19121 begin
19122 return NCT_Table_Index (Key mod NCT_Table_Max);
19123 end NCT_Table_Hash;
19125 ----------------------
19126 -- NCT_New_Entities --
19127 ----------------------
19129 -- The following table maps old entities and Itypes to their corresponding
19130 -- new entities and Itypes.
19132 -- Aaa -> Xxx
19134 package NCT_New_Entities is new Simple_HTable (
19135 Header_Num => NCT_Table_Index,
19136 Element => Entity_Id,
19137 No_Element => Empty,
19138 Key => Entity_Id,
19139 Hash => NCT_Table_Hash,
19140 Equal => "=");
19142 ------------------------
19143 -- NCT_Pending_Itypes --
19144 ------------------------
19146 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19147 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19148 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19149 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19151 -- Ppp -> (Xxx, Yyy, Zzz)
19153 -- The set is expressed as an Elist
19155 package NCT_Pending_Itypes is new Simple_HTable (
19156 Header_Num => NCT_Table_Index,
19157 Element => Elist_Id,
19158 No_Element => No_Elist,
19159 Key => Node_Id,
19160 Hash => NCT_Table_Hash,
19161 Equal => "=");
19163 NCT_Tables_In_Use : Boolean := False;
19164 -- This flag keeps track of whether the two tables NCT_New_Entities and
19165 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19166 -- where certain operations are not performed if the tables are not in
19167 -- use. This saves up to 8% of the entire compilation time spent in the
19168 -- front end.
19170 -------------------
19171 -- New_Copy_Tree --
19172 -------------------
19174 function New_Copy_Tree
19175 (Source : Node_Id;
19176 Map : Elist_Id := No_Elist;
19177 New_Sloc : Source_Ptr := No_Location;
19178 New_Scope : Entity_Id := Empty) return Node_Id
19180 -- This routine performs low-level tree manipulations and needs access
19181 -- to the internals of the tree.
19183 use Atree.Unchecked_Access;
19184 use Atree_Private_Part;
19186 EWA_Level : Nat := 0;
19187 -- This counter keeps track of how many N_Expression_With_Actions nodes
19188 -- are encountered during a depth-first traversal of the subtree. These
19189 -- nodes may define new entities in their Actions lists and thus require
19190 -- special processing.
19192 EWA_Inner_Scope_Level : Nat := 0;
19193 -- This counter keeps track of how many scoping constructs appear within
19194 -- an N_Expression_With_Actions node.
19196 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
19197 pragma Inline (Add_New_Entity);
19198 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19199 -- value New_Id. Old_Id is an entity which appears within the Actions
19200 -- list of an N_Expression_With_Actions node, or within an entity map.
19201 -- New_Id is the corresponding new entity generated during Phase 1.
19203 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
19204 pragma Inline (Add_New_Entity);
19205 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19206 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19207 -- an itype.
19209 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
19210 pragma Inline (Build_NCT_Tables);
19211 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19212 -- information supplied in entity map Entity_Map. The format of the
19213 -- entity map must be as follows:
19215 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19217 function Copy_Any_Node_With_Replacement
19218 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
19219 pragma Inline (Copy_Any_Node_With_Replacement);
19220 -- Replicate entity or node N by invoking one of the following routines:
19222 -- Copy_Node_With_Replacement
19223 -- Corresponding_Entity
19225 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
19226 -- Replicate the elements of entity list List
19228 function Copy_Field_With_Replacement
19229 (Field : Union_Id;
19230 Old_Par : Node_Id := Empty;
19231 New_Par : Node_Id := Empty;
19232 Semantic : Boolean := False) return Union_Id;
19233 -- Replicate field Field by invoking one of the following routines:
19235 -- Copy_Elist_With_Replacement
19236 -- Copy_List_With_Replacement
19237 -- Copy_Node_With_Replacement
19238 -- Corresponding_Entity
19240 -- If the field is not an entity list, entity, itype, syntactic list,
19241 -- or node, then the field is returned unchanged. The routine always
19242 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19243 -- the expected parent of a syntactic field. New_Par is the new parent
19244 -- associated with a replicated syntactic field. Flag Semantic should
19245 -- be set when the input is a semantic field.
19247 function Copy_List_With_Replacement (List : List_Id) return List_Id;
19248 -- Replicate the elements of syntactic list List
19250 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
19251 -- Replicate node N
19253 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
19254 pragma Inline (Corresponding_Entity);
19255 -- Return the corresponding new entity of Id generated during Phase 1.
19256 -- If there is no such entity, return Id.
19258 function In_Entity_Map
19259 (Id : Entity_Id;
19260 Entity_Map : Elist_Id) return Boolean;
19261 pragma Inline (In_Entity_Map);
19262 -- Determine whether entity Id is one of the old ids specified in entity
19263 -- map Entity_Map. The format of the entity map must be as follows:
19265 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19267 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
19268 pragma Inline (Update_CFS_Sloc);
19269 -- Update the Comes_From_Source and Sloc attributes of node or entity N
19271 procedure Update_First_Real_Statement
19272 (Old_HSS : Node_Id;
19273 New_HSS : Node_Id);
19274 pragma Inline (Update_First_Real_Statement);
19275 -- Update semantic attribute First_Real_Statement of handled sequence of
19276 -- statements New_HSS based on handled sequence of statements Old_HSS.
19278 procedure Update_Named_Associations
19279 (Old_Call : Node_Id;
19280 New_Call : Node_Id);
19281 pragma Inline (Update_Named_Associations);
19282 -- Update semantic chain First/Next_Named_Association of call New_call
19283 -- based on call Old_Call.
19285 procedure Update_New_Entities (Entity_Map : Elist_Id);
19286 pragma Inline (Update_New_Entities);
19287 -- Update the semantic attributes of all new entities generated during
19288 -- Phase 1 that do not appear in entity map Entity_Map. The format of
19289 -- the entity map must be as follows:
19291 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19293 procedure Update_Pending_Itypes
19294 (Old_Assoc : Node_Id;
19295 New_Assoc : Node_Id);
19296 pragma Inline (Update_Pending_Itypes);
19297 -- Update semantic attribute Associated_Node_For_Itype to refer to node
19298 -- New_Assoc for all itypes whose associated node is Old_Assoc.
19300 procedure Update_Semantic_Fields (Id : Entity_Id);
19301 pragma Inline (Update_Semantic_Fields);
19302 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
19303 -- or itype Id.
19305 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
19306 pragma Inline (Visit_Any_Node);
19307 -- Visit entity of node N by invoking one of the following routines:
19309 -- Visit_Entity
19310 -- Visit_Itype
19311 -- Visit_Node
19313 procedure Visit_Elist (List : Elist_Id);
19314 -- Visit the elements of entity list List
19316 procedure Visit_Entity (Id : Entity_Id);
19317 -- Visit entity Id. This action may create a new entity of Id and save
19318 -- it in table NCT_New_Entities.
19320 procedure Visit_Field
19321 (Field : Union_Id;
19322 Par_Nod : Node_Id := Empty;
19323 Semantic : Boolean := False);
19324 -- Visit field Field by invoking one of the following routines:
19326 -- Visit_Elist
19327 -- Visit_Entity
19328 -- Visit_Itype
19329 -- Visit_List
19330 -- Visit_Node
19332 -- If the field is not an entity list, entity, itype, syntactic list,
19333 -- or node, then the field is not visited. The routine always visits
19334 -- valid syntactic fields. Par_Nod is the expected parent of the
19335 -- syntactic field. Flag Semantic should be set when the input is a
19336 -- semantic field.
19338 procedure Visit_Itype (Itype : Entity_Id);
19339 -- Visit itype Itype. This action may create a new entity for Itype and
19340 -- save it in table NCT_New_Entities. In addition, the routine may map
19341 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
19343 procedure Visit_List (List : List_Id);
19344 -- Visit the elements of syntactic list List
19346 procedure Visit_Node (N : Node_Id);
19347 -- Visit node N
19349 procedure Visit_Semantic_Fields (Id : Entity_Id);
19350 pragma Inline (Visit_Semantic_Fields);
19351 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
19352 -- fields of entity or itype Id.
19354 --------------------
19355 -- Add_New_Entity --
19356 --------------------
19358 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
19359 begin
19360 pragma Assert (Present (Old_Id));
19361 pragma Assert (Present (New_Id));
19362 pragma Assert (Nkind (Old_Id) in N_Entity);
19363 pragma Assert (Nkind (New_Id) in N_Entity);
19365 NCT_Tables_In_Use := True;
19367 -- Sanity check the NCT_New_Entities table. No previous mapping with
19368 -- key Old_Id should exist.
19370 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
19372 -- Establish the mapping
19374 -- Old_Id -> New_Id
19376 NCT_New_Entities.Set (Old_Id, New_Id);
19377 end Add_New_Entity;
19379 -----------------------
19380 -- Add_Pending_Itype --
19381 -----------------------
19383 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
19384 Itypes : Elist_Id;
19386 begin
19387 pragma Assert (Present (Assoc_Nod));
19388 pragma Assert (Present (Itype));
19389 pragma Assert (Nkind (Itype) in N_Entity);
19390 pragma Assert (Is_Itype (Itype));
19392 NCT_Tables_In_Use := True;
19394 -- It is not possible to sanity check the NCT_Pendint_Itypes table
19395 -- directly because a single node may act as the associated node for
19396 -- multiple itypes.
19398 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
19400 if No (Itypes) then
19401 Itypes := New_Elmt_List;
19402 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
19403 end if;
19405 -- Establish the mapping
19407 -- Assoc_Nod -> (Itype, ...)
19409 -- Avoid inserting the same itype multiple times. This involves a
19410 -- linear search, however the set of itypes with the same associated
19411 -- node is very small.
19413 Append_Unique_Elmt (Itype, Itypes);
19414 end Add_Pending_Itype;
19416 ----------------------
19417 -- Build_NCT_Tables --
19418 ----------------------
19420 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
19421 Elmt : Elmt_Id;
19422 Old_Id : Entity_Id;
19423 New_Id : Entity_Id;
19425 begin
19426 -- Nothing to do when there is no entity map
19428 if No (Entity_Map) then
19429 return;
19430 end if;
19432 Elmt := First_Elmt (Entity_Map);
19433 while Present (Elmt) loop
19435 -- Extract the (Old_Id, New_Id) pair from the entity map
19437 Old_Id := Node (Elmt);
19438 Next_Elmt (Elmt);
19440 New_Id := Node (Elmt);
19441 Next_Elmt (Elmt);
19443 -- Establish the following mapping within table NCT_New_Entities
19445 -- Old_Id -> New_Id
19447 Add_New_Entity (Old_Id, New_Id);
19449 -- Establish the following mapping within table NCT_Pending_Itypes
19450 -- when the new entity is an itype.
19452 -- Assoc_Nod -> (New_Id, ...)
19454 -- IMPORTANT: the associated node is that of the old itype because
19455 -- the node will be replicated in Phase 2.
19457 if Is_Itype (Old_Id) then
19458 Add_Pending_Itype
19459 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
19460 Itype => New_Id);
19461 end if;
19462 end loop;
19463 end Build_NCT_Tables;
19465 ------------------------------------
19466 -- Copy_Any_Node_With_Replacement --
19467 ------------------------------------
19469 function Copy_Any_Node_With_Replacement
19470 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
19472 begin
19473 if Nkind (N) in N_Entity then
19474 return Corresponding_Entity (N);
19475 else
19476 return Copy_Node_With_Replacement (N);
19477 end if;
19478 end Copy_Any_Node_With_Replacement;
19480 ---------------------------------
19481 -- Copy_Elist_With_Replacement --
19482 ---------------------------------
19484 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
19485 Elmt : Elmt_Id;
19486 Result : Elist_Id;
19488 begin
19489 -- Copy the contents of the old list. Note that the list itself may
19490 -- be empty, in which case the routine returns a new empty list. This
19491 -- avoids sharing lists between subtrees. The element of an entity
19492 -- list could be an entity or a node, hence the invocation of routine
19493 -- Copy_Any_Node_With_Replacement.
19495 if Present (List) then
19496 Result := New_Elmt_List;
19498 Elmt := First_Elmt (List);
19499 while Present (Elmt) loop
19500 Append_Elmt
19501 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
19503 Next_Elmt (Elmt);
19504 end loop;
19506 -- Otherwise the list does not exist
19508 else
19509 Result := No_Elist;
19510 end if;
19512 return Result;
19513 end Copy_Elist_With_Replacement;
19515 ---------------------------------
19516 -- Copy_Field_With_Replacement --
19517 ---------------------------------
19519 function Copy_Field_With_Replacement
19520 (Field : Union_Id;
19521 Old_Par : Node_Id := Empty;
19522 New_Par : Node_Id := Empty;
19523 Semantic : Boolean := False) return Union_Id
19525 begin
19526 -- The field is empty
19528 if Field = Union_Id (Empty) then
19529 return Field;
19531 -- The field is an entity/itype/node
19533 elsif Field in Node_Range then
19534 declare
19535 Old_N : constant Node_Id := Node_Id (Field);
19536 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
19538 New_N : Node_Id;
19540 begin
19541 -- The field is an entity/itype
19543 if Nkind (Old_N) in N_Entity then
19545 -- An entity/itype is always replicated
19547 New_N := Corresponding_Entity (Old_N);
19549 -- Update the parent pointer when the entity is a syntactic
19550 -- field. Note that itypes do not have parent pointers.
19552 if Syntactic and then New_N /= Old_N then
19553 Set_Parent (New_N, New_Par);
19554 end if;
19556 -- The field is a node
19558 else
19559 -- A node is replicated when it is either a syntactic field
19560 -- or when the caller treats it as a semantic attribute.
19562 if Syntactic or else Semantic then
19563 New_N := Copy_Node_With_Replacement (Old_N);
19565 -- Update the parent pointer when the node is a syntactic
19566 -- field.
19568 if Syntactic and then New_N /= Old_N then
19569 Set_Parent (New_N, New_Par);
19570 end if;
19572 -- Otherwise the node is returned unchanged
19574 else
19575 New_N := Old_N;
19576 end if;
19577 end if;
19579 return Union_Id (New_N);
19580 end;
19582 -- The field is an entity list
19584 elsif Field in Elist_Range then
19585 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
19587 -- The field is a syntactic list
19589 elsif Field in List_Range then
19590 declare
19591 Old_List : constant List_Id := List_Id (Field);
19592 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
19594 New_List : List_Id;
19596 begin
19597 -- A list is replicated when it is either a syntactic field or
19598 -- when the caller treats it as a semantic attribute.
19600 if Syntactic or else Semantic then
19601 New_List := Copy_List_With_Replacement (Old_List);
19603 -- Update the parent pointer when the list is a syntactic
19604 -- field.
19606 if Syntactic and then New_List /= Old_List then
19607 Set_Parent (New_List, New_Par);
19608 end if;
19610 -- Otherwise the list is returned unchanged
19612 else
19613 New_List := Old_List;
19614 end if;
19616 return Union_Id (New_List);
19617 end;
19619 -- Otherwise the field denotes an attribute that does not need to be
19620 -- replicated (Chars, literals, etc).
19622 else
19623 return Field;
19624 end if;
19625 end Copy_Field_With_Replacement;
19627 --------------------------------
19628 -- Copy_List_With_Replacement --
19629 --------------------------------
19631 function Copy_List_With_Replacement (List : List_Id) return List_Id is
19632 Elmt : Node_Id;
19633 Result : List_Id;
19635 begin
19636 -- Copy the contents of the old list. Note that the list itself may
19637 -- be empty, in which case the routine returns a new empty list. This
19638 -- avoids sharing lists between subtrees. The element of a syntactic
19639 -- list is always a node, never an entity or itype, hence the call to
19640 -- routine Copy_Node_With_Replacement.
19642 if Present (List) then
19643 Result := New_List;
19645 Elmt := First (List);
19646 while Present (Elmt) loop
19647 Append (Copy_Node_With_Replacement (Elmt), Result);
19649 Next (Elmt);
19650 end loop;
19652 -- Otherwise the list does not exist
19654 else
19655 Result := No_List;
19656 end if;
19658 return Result;
19659 end Copy_List_With_Replacement;
19661 --------------------------------
19662 -- Copy_Node_With_Replacement --
19663 --------------------------------
19665 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
19666 Result : Node_Id;
19668 begin
19669 -- Assume that the node must be returned unchanged
19671 Result := N;
19673 if N > Empty_Or_Error then
19674 pragma Assert (Nkind (N) not in N_Entity);
19676 Result := New_Copy (N);
19678 Set_Field1 (Result,
19679 Copy_Field_With_Replacement
19680 (Field => Field1 (Result),
19681 Old_Par => N,
19682 New_Par => Result));
19684 Set_Field2 (Result,
19685 Copy_Field_With_Replacement
19686 (Field => Field2 (Result),
19687 Old_Par => N,
19688 New_Par => Result));
19690 Set_Field3 (Result,
19691 Copy_Field_With_Replacement
19692 (Field => Field3 (Result),
19693 Old_Par => N,
19694 New_Par => Result));
19696 Set_Field4 (Result,
19697 Copy_Field_With_Replacement
19698 (Field => Field4 (Result),
19699 Old_Par => N,
19700 New_Par => Result));
19702 Set_Field5 (Result,
19703 Copy_Field_With_Replacement
19704 (Field => Field5 (Result),
19705 Old_Par => N,
19706 New_Par => Result));
19708 -- Update the Comes_From_Source and Sloc attributes of the node
19709 -- in case the caller has supplied new values.
19711 Update_CFS_Sloc (Result);
19713 -- Update the Associated_Node_For_Itype attribute of all itypes
19714 -- created during Phase 1 whose associated node is N. As a result
19715 -- the Associated_Node_For_Itype refers to the replicated node.
19716 -- No action needs to be taken when the Associated_Node_For_Itype
19717 -- refers to an entity because this was already handled during
19718 -- Phase 1, in Visit_Itype.
19720 Update_Pending_Itypes
19721 (Old_Assoc => N,
19722 New_Assoc => Result);
19724 -- Update the First/Next_Named_Association chain for a replicated
19725 -- call.
19727 if Nkind_In (N, N_Entry_Call_Statement,
19728 N_Function_Call,
19729 N_Procedure_Call_Statement)
19730 then
19731 Update_Named_Associations
19732 (Old_Call => N,
19733 New_Call => Result);
19735 -- Update the Renamed_Object attribute of a replicated object
19736 -- declaration.
19738 elsif Nkind (N) = N_Object_Renaming_Declaration then
19739 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
19741 -- Update the First_Real_Statement attribute of a replicated
19742 -- handled sequence of statements.
19744 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
19745 Update_First_Real_Statement
19746 (Old_HSS => N,
19747 New_HSS => Result);
19748 end if;
19749 end if;
19751 return Result;
19752 end Copy_Node_With_Replacement;
19754 --------------------------
19755 -- Corresponding_Entity --
19756 --------------------------
19758 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
19759 New_Id : Entity_Id;
19760 Result : Entity_Id;
19762 begin
19763 -- Assume that the entity must be returned unchanged
19765 Result := Id;
19767 if Id > Empty_Or_Error then
19768 pragma Assert (Nkind (Id) in N_Entity);
19770 -- Determine whether the entity has a corresponding new entity
19771 -- generated during Phase 1 and if it does, use it.
19773 if NCT_Tables_In_Use then
19774 New_Id := NCT_New_Entities.Get (Id);
19776 if Present (New_Id) then
19777 Result := New_Id;
19778 end if;
19779 end if;
19780 end if;
19782 return Result;
19783 end Corresponding_Entity;
19785 -------------------
19786 -- In_Entity_Map --
19787 -------------------
19789 function In_Entity_Map
19790 (Id : Entity_Id;
19791 Entity_Map : Elist_Id) return Boolean
19793 Elmt : Elmt_Id;
19794 Old_Id : Entity_Id;
19796 begin
19797 -- The entity map contains pairs (Old_Id, New_Id). The advancement
19798 -- step always skips the New_Id portion of the pair.
19800 if Present (Entity_Map) then
19801 Elmt := First_Elmt (Entity_Map);
19802 while Present (Elmt) loop
19803 Old_Id := Node (Elmt);
19805 if Old_Id = Id then
19806 return True;
19807 end if;
19809 Next_Elmt (Elmt);
19810 Next_Elmt (Elmt);
19811 end loop;
19812 end if;
19814 return False;
19815 end In_Entity_Map;
19817 ---------------------
19818 -- Update_CFS_Sloc --
19819 ---------------------
19821 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
19822 begin
19823 -- A new source location defaults the Comes_From_Source attribute
19825 if New_Sloc /= No_Location then
19826 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
19827 Set_Sloc (N, New_Sloc);
19828 end if;
19829 end Update_CFS_Sloc;
19831 ---------------------------------
19832 -- Update_First_Real_Statement --
19833 ---------------------------------
19835 procedure Update_First_Real_Statement
19836 (Old_HSS : Node_Id;
19837 New_HSS : Node_Id)
19839 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
19841 New_Stmt : Node_Id;
19842 Old_Stmt : Node_Id;
19844 begin
19845 -- Recreate the First_Real_Statement attribute of a handled sequence
19846 -- of statements by traversing the statement lists of both sequences
19847 -- in parallel.
19849 if Present (Old_First_Stmt) then
19850 New_Stmt := First (Statements (New_HSS));
19851 Old_Stmt := First (Statements (Old_HSS));
19852 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
19853 Next (New_Stmt);
19854 Next (Old_Stmt);
19855 end loop;
19857 pragma Assert (Present (New_Stmt));
19858 pragma Assert (Present (Old_Stmt));
19860 Set_First_Real_Statement (New_HSS, New_Stmt);
19861 end if;
19862 end Update_First_Real_Statement;
19864 -------------------------------
19865 -- Update_Named_Associations --
19866 -------------------------------
19868 procedure Update_Named_Associations
19869 (Old_Call : Node_Id;
19870 New_Call : Node_Id)
19872 New_Act : Node_Id;
19873 New_Next : Node_Id;
19874 Old_Act : Node_Id;
19875 Old_Next : Node_Id;
19877 begin
19878 -- Recreate the First/Next_Named_Actual chain of a call by traversing
19879 -- the chains of both the old and new calls in parallel.
19881 New_Act := First (Parameter_Associations (New_Call));
19882 Old_Act := First (Parameter_Associations (Old_Call));
19883 while Present (Old_Act) loop
19884 if Nkind (Old_Act) = N_Parameter_Association
19885 and then Present (Next_Named_Actual (Old_Act))
19886 then
19887 if First_Named_Actual (Old_Call) =
19888 Explicit_Actual_Parameter (Old_Act)
19889 then
19890 Set_First_Named_Actual (New_Call,
19891 Explicit_Actual_Parameter (New_Act));
19892 end if;
19894 -- Scan the actual parameter list to find the next suitable
19895 -- named actual. Note that the list may be out of order.
19897 New_Next := First (Parameter_Associations (New_Call));
19898 Old_Next := First (Parameter_Associations (Old_Call));
19899 while Nkind (Old_Next) /= N_Parameter_Association
19900 or else Explicit_Actual_Parameter (Old_Next) /=
19901 Next_Named_Actual (Old_Act)
19902 loop
19903 Next (New_Next);
19904 Next (Old_Next);
19905 end loop;
19907 Set_Next_Named_Actual (New_Act,
19908 Explicit_Actual_Parameter (New_Next));
19909 end if;
19911 Next (New_Act);
19912 Next (Old_Act);
19913 end loop;
19914 end Update_Named_Associations;
19916 -------------------------
19917 -- Update_New_Entities --
19918 -------------------------
19920 procedure Update_New_Entities (Entity_Map : Elist_Id) is
19921 New_Id : Entity_Id := Empty;
19922 Old_Id : Entity_Id := Empty;
19924 begin
19925 if NCT_Tables_In_Use then
19926 NCT_New_Entities.Get_First (Old_Id, New_Id);
19928 -- Update the semantic fields of all new entities created during
19929 -- Phase 1 which were not supplied via an entity map.
19930 -- ??? Is there a better way of distinguishing those?
19932 while Present (Old_Id) and then Present (New_Id) loop
19933 if not (Present (Entity_Map)
19934 and then In_Entity_Map (Old_Id, Entity_Map))
19935 then
19936 Update_Semantic_Fields (New_Id);
19937 end if;
19939 NCT_New_Entities.Get_Next (Old_Id, New_Id);
19940 end loop;
19941 end if;
19942 end Update_New_Entities;
19944 ---------------------------
19945 -- Update_Pending_Itypes --
19946 ---------------------------
19948 procedure Update_Pending_Itypes
19949 (Old_Assoc : Node_Id;
19950 New_Assoc : Node_Id)
19952 Item : Elmt_Id;
19953 Itypes : Elist_Id;
19955 begin
19956 if NCT_Tables_In_Use then
19957 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
19959 -- Update the Associated_Node_For_Itype attribute for all itypes
19960 -- which originally refer to Old_Assoc to designate New_Assoc.
19962 if Present (Itypes) then
19963 Item := First_Elmt (Itypes);
19964 while Present (Item) loop
19965 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
19967 Next_Elmt (Item);
19968 end loop;
19969 end if;
19970 end if;
19971 end Update_Pending_Itypes;
19973 ----------------------------
19974 -- Update_Semantic_Fields --
19975 ----------------------------
19977 procedure Update_Semantic_Fields (Id : Entity_Id) is
19978 begin
19979 -- Discriminant_Constraint
19981 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
19982 Set_Discriminant_Constraint (Id, Elist_Id (
19983 Copy_Field_With_Replacement
19984 (Field => Union_Id (Discriminant_Constraint (Id)),
19985 Semantic => True)));
19986 end if;
19988 -- Etype
19990 Set_Etype (Id, Node_Id (
19991 Copy_Field_With_Replacement
19992 (Field => Union_Id (Etype (Id)),
19993 Semantic => True)));
19995 -- First_Index
19996 -- Packed_Array_Impl_Type
19998 if Is_Array_Type (Id) then
19999 if Present (First_Index (Id)) then
20000 Set_First_Index (Id, First (List_Id (
20001 Copy_Field_With_Replacement
20002 (Field => Union_Id (List_Containing (First_Index (Id))),
20003 Semantic => True))));
20004 end if;
20006 if Is_Packed (Id) then
20007 Set_Packed_Array_Impl_Type (Id, Node_Id (
20008 Copy_Field_With_Replacement
20009 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20010 Semantic => True)));
20011 end if;
20012 end if;
20014 -- Prev_Entity
20016 Set_Prev_Entity (Id, Node_Id (
20017 Copy_Field_With_Replacement
20018 (Field => Union_Id (Prev_Entity (Id)),
20019 Semantic => True)));
20021 -- Next_Entity
20023 Set_Next_Entity (Id, Node_Id (
20024 Copy_Field_With_Replacement
20025 (Field => Union_Id (Next_Entity (Id)),
20026 Semantic => True)));
20028 -- Scalar_Range
20030 if Is_Discrete_Type (Id) then
20031 Set_Scalar_Range (Id, Node_Id (
20032 Copy_Field_With_Replacement
20033 (Field => Union_Id (Scalar_Range (Id)),
20034 Semantic => True)));
20035 end if;
20037 -- Scope
20039 -- Update the scope when the caller specified an explicit one
20041 if Present (New_Scope) then
20042 Set_Scope (Id, New_Scope);
20043 else
20044 Set_Scope (Id, Node_Id (
20045 Copy_Field_With_Replacement
20046 (Field => Union_Id (Scope (Id)),
20047 Semantic => True)));
20048 end if;
20049 end Update_Semantic_Fields;
20051 --------------------
20052 -- Visit_Any_Node --
20053 --------------------
20055 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
20056 begin
20057 if Nkind (N) in N_Entity then
20058 if Is_Itype (N) then
20059 Visit_Itype (N);
20060 else
20061 Visit_Entity (N);
20062 end if;
20063 else
20064 Visit_Node (N);
20065 end if;
20066 end Visit_Any_Node;
20068 -----------------
20069 -- Visit_Elist --
20070 -----------------
20072 procedure Visit_Elist (List : Elist_Id) is
20073 Elmt : Elmt_Id;
20075 begin
20076 -- The element of an entity list could be an entity, itype, or a
20077 -- node, hence the call to Visit_Any_Node.
20079 if Present (List) then
20080 Elmt := First_Elmt (List);
20081 while Present (Elmt) loop
20082 Visit_Any_Node (Node (Elmt));
20084 Next_Elmt (Elmt);
20085 end loop;
20086 end if;
20087 end Visit_Elist;
20089 ------------------
20090 -- Visit_Entity --
20091 ------------------
20093 procedure Visit_Entity (Id : Entity_Id) is
20094 New_Id : Entity_Id;
20096 begin
20097 pragma Assert (Nkind (Id) in N_Entity);
20098 pragma Assert (not Is_Itype (Id));
20100 -- Nothing to do if the entity is not defined in the Actions list of
20101 -- an N_Expression_With_Actions node.
20103 if EWA_Level = 0 then
20104 return;
20106 -- Nothing to do if the entity is defined within a scoping construct
20107 -- of an N_Expression_With_Actions node.
20109 elsif EWA_Inner_Scope_Level > 0 then
20110 return;
20112 -- Nothing to do if the entity is not an object or a type. Relaxing
20113 -- this restriction leads to a performance penalty.
20115 elsif not Ekind_In (Id, E_Constant, E_Variable)
20116 and then not Is_Type (Id)
20117 then
20118 return;
20120 -- Nothing to do if the entity was already visited
20122 elsif NCT_Tables_In_Use
20123 and then Present (NCT_New_Entities.Get (Id))
20124 then
20125 return;
20127 -- Nothing to do if the declaration node of the entity is not within
20128 -- the subtree being replicated.
20130 elsif not In_Subtree
20131 (N => Declaration_Node (Id),
20132 Root => Source)
20133 then
20134 return;
20135 end if;
20137 -- Create a new entity by directly copying the old entity. This
20138 -- action causes all attributes of the old entity to be inherited.
20140 New_Id := New_Copy (Id);
20142 -- Create a new name for the new entity because the back end needs
20143 -- distinct names for debugging purposes.
20145 Set_Chars (New_Id, New_Internal_Name ('T'));
20147 -- Update the Comes_From_Source and Sloc attributes of the entity in
20148 -- case the caller has supplied new values.
20150 Update_CFS_Sloc (New_Id);
20152 -- Establish the following mapping within table NCT_New_Entities:
20154 -- Id -> New_Id
20156 Add_New_Entity (Id, New_Id);
20158 -- Deal with the semantic fields of entities. The fields are visited
20159 -- because they may mention entities which reside within the subtree
20160 -- being copied.
20162 Visit_Semantic_Fields (Id);
20163 end Visit_Entity;
20165 -----------------
20166 -- Visit_Field --
20167 -----------------
20169 procedure Visit_Field
20170 (Field : Union_Id;
20171 Par_Nod : Node_Id := Empty;
20172 Semantic : Boolean := False)
20174 begin
20175 -- The field is empty
20177 if Field = Union_Id (Empty) then
20178 return;
20180 -- The field is an entity/itype/node
20182 elsif Field in Node_Range then
20183 declare
20184 N : constant Node_Id := Node_Id (Field);
20186 begin
20187 -- The field is an entity/itype
20189 if Nkind (N) in N_Entity then
20191 -- Itypes are always visited
20193 if Is_Itype (N) then
20194 Visit_Itype (N);
20196 -- An entity is visited when it is either a syntactic field
20197 -- or when the caller treats it as a semantic attribute.
20199 elsif Parent (N) = Par_Nod or else Semantic then
20200 Visit_Entity (N);
20201 end if;
20203 -- The field is a node
20205 else
20206 -- A node is visited when it is either a syntactic field or
20207 -- when the caller treats it as a semantic attribute.
20209 if Parent (N) = Par_Nod or else Semantic then
20210 Visit_Node (N);
20211 end if;
20212 end if;
20213 end;
20215 -- The field is an entity list
20217 elsif Field in Elist_Range then
20218 Visit_Elist (Elist_Id (Field));
20220 -- The field is a syntax list
20222 elsif Field in List_Range then
20223 declare
20224 List : constant List_Id := List_Id (Field);
20226 begin
20227 -- A syntax list is visited when it is either a syntactic field
20228 -- or when the caller treats it as a semantic attribute.
20230 if Parent (List) = Par_Nod or else Semantic then
20231 Visit_List (List);
20232 end if;
20233 end;
20235 -- Otherwise the field denotes information which does not need to be
20236 -- visited (chars, literals, etc.).
20238 else
20239 null;
20240 end if;
20241 end Visit_Field;
20243 -----------------
20244 -- Visit_Itype --
20245 -----------------
20247 procedure Visit_Itype (Itype : Entity_Id) is
20248 New_Assoc : Node_Id;
20249 New_Itype : Entity_Id;
20250 Old_Assoc : Node_Id;
20252 begin
20253 pragma Assert (Nkind (Itype) in N_Entity);
20254 pragma Assert (Is_Itype (Itype));
20256 -- Itypes that describe the designated type of access to subprograms
20257 -- have the structure of subprogram declarations, with signatures,
20258 -- etc. Either we duplicate the signatures completely, or choose to
20259 -- share such itypes, which is fine because their elaboration will
20260 -- have no side effects.
20262 if Ekind (Itype) = E_Subprogram_Type then
20263 return;
20265 -- Nothing to do if the itype was already visited
20267 elsif NCT_Tables_In_Use
20268 and then Present (NCT_New_Entities.Get (Itype))
20269 then
20270 return;
20272 -- Nothing to do if the associated node of the itype is not within
20273 -- the subtree being replicated.
20275 elsif not In_Subtree
20276 (N => Associated_Node_For_Itype (Itype),
20277 Root => Source)
20278 then
20279 return;
20280 end if;
20282 -- Create a new itype by directly copying the old itype. This action
20283 -- causes all attributes of the old itype to be inherited.
20285 New_Itype := New_Copy (Itype);
20287 -- Create a new name for the new itype because the back end requires
20288 -- distinct names for debugging purposes.
20290 Set_Chars (New_Itype, New_Internal_Name ('T'));
20292 -- Update the Comes_From_Source and Sloc attributes of the itype in
20293 -- case the caller has supplied new values.
20295 Update_CFS_Sloc (New_Itype);
20297 -- Establish the following mapping within table NCT_New_Entities:
20299 -- Itype -> New_Itype
20301 Add_New_Entity (Itype, New_Itype);
20303 -- The new itype must be unfrozen because the resulting subtree may
20304 -- be inserted anywhere and cause an earlier or later freezing.
20306 if Present (Freeze_Node (New_Itype)) then
20307 Set_Freeze_Node (New_Itype, Empty);
20308 Set_Is_Frozen (New_Itype, False);
20309 end if;
20311 -- If a record subtype is simply copied, the entity list will be
20312 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
20313 -- ??? What does this do?
20315 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
20316 Set_Cloned_Subtype (New_Itype, Itype);
20317 end if;
20319 -- The associated node may denote an entity, in which case it may
20320 -- already have a new corresponding entity created during a prior
20321 -- call to Visit_Entity or Visit_Itype for the same subtree.
20323 -- Given
20324 -- Old_Assoc ---------> New_Assoc
20326 -- Created by Visit_Itype
20327 -- Itype -------------> New_Itype
20328 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
20330 -- In the example above, Old_Assoc is an arbitrary entity that was
20331 -- already visited for the same subtree and has a corresponding new
20332 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
20333 -- of copying entities, however it must be updated to New_Assoc.
20335 Old_Assoc := Associated_Node_For_Itype (Itype);
20337 if Nkind (Old_Assoc) in N_Entity then
20338 if NCT_Tables_In_Use then
20339 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
20341 if Present (New_Assoc) then
20342 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
20343 end if;
20344 end if;
20346 -- Otherwise the associated node denotes a node. Postpone the update
20347 -- until Phase 2 when the node is replicated. Establish the following
20348 -- mapping within table NCT_Pending_Itypes:
20350 -- Old_Assoc -> (New_Type, ...)
20352 else
20353 Add_Pending_Itype (Old_Assoc, New_Itype);
20354 end if;
20356 -- Deal with the semantic fields of itypes. The fields are visited
20357 -- because they may mention entities that reside within the subtree
20358 -- being copied.
20360 Visit_Semantic_Fields (Itype);
20361 end Visit_Itype;
20363 ----------------
20364 -- Visit_List --
20365 ----------------
20367 procedure Visit_List (List : List_Id) is
20368 Elmt : Node_Id;
20370 begin
20371 -- Note that the element of a syntactic list is always a node, never
20372 -- an entity or itype, hence the call to Visit_Node.
20374 if Present (List) then
20375 Elmt := First (List);
20376 while Present (Elmt) loop
20377 Visit_Node (Elmt);
20379 Next (Elmt);
20380 end loop;
20381 end if;
20382 end Visit_List;
20384 ----------------
20385 -- Visit_Node --
20386 ----------------
20388 procedure Visit_Node (N : Node_Or_Entity_Id) is
20389 begin
20390 pragma Assert (Nkind (N) not in N_Entity);
20392 if Nkind (N) = N_Expression_With_Actions then
20393 EWA_Level := EWA_Level + 1;
20395 elsif EWA_Level > 0
20396 and then Nkind_In (N, N_Block_Statement,
20397 N_Subprogram_Body,
20398 N_Subprogram_Declaration)
20399 then
20400 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
20401 end if;
20403 Visit_Field
20404 (Field => Field1 (N),
20405 Par_Nod => N);
20407 Visit_Field
20408 (Field => Field2 (N),
20409 Par_Nod => N);
20411 Visit_Field
20412 (Field => Field3 (N),
20413 Par_Nod => N);
20415 Visit_Field
20416 (Field => Field4 (N),
20417 Par_Nod => N);
20419 Visit_Field
20420 (Field => Field5 (N),
20421 Par_Nod => N);
20423 if EWA_Level > 0
20424 and then Nkind_In (N, N_Block_Statement,
20425 N_Subprogram_Body,
20426 N_Subprogram_Declaration)
20427 then
20428 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
20430 elsif Nkind (N) = N_Expression_With_Actions then
20431 EWA_Level := EWA_Level - 1;
20432 end if;
20433 end Visit_Node;
20435 ---------------------------
20436 -- Visit_Semantic_Fields --
20437 ---------------------------
20439 procedure Visit_Semantic_Fields (Id : Entity_Id) is
20440 begin
20441 pragma Assert (Nkind (Id) in N_Entity);
20443 -- Discriminant_Constraint
20445 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20446 Visit_Field
20447 (Field => Union_Id (Discriminant_Constraint (Id)),
20448 Semantic => True);
20449 end if;
20451 -- Etype
20453 Visit_Field
20454 (Field => Union_Id (Etype (Id)),
20455 Semantic => True);
20457 -- First_Index
20458 -- Packed_Array_Impl_Type
20460 if Is_Array_Type (Id) then
20461 if Present (First_Index (Id)) then
20462 Visit_Field
20463 (Field => Union_Id (List_Containing (First_Index (Id))),
20464 Semantic => True);
20465 end if;
20467 if Is_Packed (Id) then
20468 Visit_Field
20469 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20470 Semantic => True);
20471 end if;
20472 end if;
20474 -- Scalar_Range
20476 if Is_Discrete_Type (Id) then
20477 Visit_Field
20478 (Field => Union_Id (Scalar_Range (Id)),
20479 Semantic => True);
20480 end if;
20481 end Visit_Semantic_Fields;
20483 -- Start of processing for New_Copy_Tree
20485 begin
20486 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
20487 -- shallow copies for each node within, and then updating the child and
20488 -- parent pointers accordingly. This process is straightforward, however
20489 -- the routine must deal with the following complications:
20491 -- * Entities defined within N_Expression_With_Actions nodes must be
20492 -- replicated rather than shared to avoid introducing two identical
20493 -- symbols within the same scope. Note that no other expression can
20494 -- currently define entities.
20496 -- do
20497 -- Source_Low : ...;
20498 -- Source_High : ...;
20500 -- <reference to Source_Low>
20501 -- <reference to Source_High>
20502 -- in ... end;
20504 -- New_Copy_Tree handles this case by first creating new entities
20505 -- and then updating all existing references to point to these new
20506 -- entities.
20508 -- do
20509 -- New_Low : ...;
20510 -- New_High : ...;
20512 -- <reference to New_Low>
20513 -- <reference to New_High>
20514 -- in ... end;
20516 -- * Itypes defined within the subtree must be replicated to avoid any
20517 -- dependencies on invalid or inaccessible data.
20519 -- subtype Source_Itype is ... range Source_Low .. Source_High;
20521 -- New_Copy_Tree handles this case by first creating a new itype in
20522 -- the same fashion as entities, and then updating various relevant
20523 -- constraints.
20525 -- subtype New_Itype is ... range New_Low .. New_High;
20527 -- * The Associated_Node_For_Itype field of itypes must be updated to
20528 -- reference the proper replicated entity or node.
20530 -- * Semantic fields of entities such as Etype and Scope must be
20531 -- updated to reference the proper replicated entities.
20533 -- * Semantic fields of nodes such as First_Real_Statement must be
20534 -- updated to reference the proper replicated nodes.
20536 -- To meet all these demands, routine New_Copy_Tree is split into two
20537 -- phases.
20539 -- Phase 1 traverses the tree in order to locate entities and itypes
20540 -- defined within the subtree. New entities are generated and saved in
20541 -- table NCT_New_Entities. The semantic fields of all new entities and
20542 -- itypes are then updated accordingly.
20544 -- Phase 2 traverses the tree in order to replicate each node. Various
20545 -- semantic fields of nodes and entities are updated accordingly.
20547 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
20548 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
20549 -- data inside.
20551 if NCT_Tables_In_Use then
20552 NCT_Tables_In_Use := False;
20554 NCT_New_Entities.Reset;
20555 NCT_Pending_Itypes.Reset;
20556 end if;
20558 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
20559 -- supplied by a linear entity map. The tables offer faster access to
20560 -- the same data.
20562 Build_NCT_Tables (Map);
20564 -- Execute Phase 1. Traverse the subtree and generate new entities for
20565 -- the following cases:
20567 -- * An entity defined within an N_Expression_With_Actions node
20569 -- * An itype referenced within the subtree where the associated node
20570 -- is also in the subtree.
20572 -- All new entities are accessible via table NCT_New_Entities, which
20573 -- contains mappings of the form:
20575 -- Old_Entity -> New_Entity
20576 -- Old_Itype -> New_Itype
20578 -- In addition, the associated nodes of all new itypes are mapped in
20579 -- table NCT_Pending_Itypes:
20581 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
20583 Visit_Any_Node (Source);
20585 -- Update the semantic attributes of all new entities generated during
20586 -- Phase 1 before starting Phase 2. The updates could be performed in
20587 -- routine Corresponding_Entity, however this may cause the same entity
20588 -- to be updated multiple times, effectively generating useless nodes.
20589 -- Keeping the updates separates from Phase 2 ensures that only one set
20590 -- of attributes is generated for an entity at any one time.
20592 Update_New_Entities (Map);
20594 -- Execute Phase 2. Replicate the source subtree one node at a time.
20595 -- The following transformations take place:
20597 -- * References to entities and itypes are updated to refer to the
20598 -- new entities and itypes generated during Phase 1.
20600 -- * All Associated_Node_For_Itype attributes of itypes are updated
20601 -- to refer to the new replicated Associated_Node_For_Itype.
20603 return Copy_Node_With_Replacement (Source);
20604 end New_Copy_Tree;
20606 -------------------------
20607 -- New_External_Entity --
20608 -------------------------
20610 function New_External_Entity
20611 (Kind : Entity_Kind;
20612 Scope_Id : Entity_Id;
20613 Sloc_Value : Source_Ptr;
20614 Related_Id : Entity_Id;
20615 Suffix : Character;
20616 Suffix_Index : Nat := 0;
20617 Prefix : Character := ' ') return Entity_Id
20619 N : constant Entity_Id :=
20620 Make_Defining_Identifier (Sloc_Value,
20621 New_External_Name
20622 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
20624 begin
20625 Set_Ekind (N, Kind);
20626 Set_Is_Internal (N, True);
20627 Append_Entity (N, Scope_Id);
20628 Set_Public_Status (N);
20630 if Kind in Type_Kind then
20631 Init_Size_Align (N);
20632 end if;
20634 return N;
20635 end New_External_Entity;
20637 -------------------------
20638 -- New_Internal_Entity --
20639 -------------------------
20641 function New_Internal_Entity
20642 (Kind : Entity_Kind;
20643 Scope_Id : Entity_Id;
20644 Sloc_Value : Source_Ptr;
20645 Id_Char : Character) return Entity_Id
20647 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
20649 begin
20650 Set_Ekind (N, Kind);
20651 Set_Is_Internal (N, True);
20652 Append_Entity (N, Scope_Id);
20654 if Kind in Type_Kind then
20655 Init_Size_Align (N);
20656 end if;
20658 return N;
20659 end New_Internal_Entity;
20661 -----------------
20662 -- Next_Actual --
20663 -----------------
20665 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
20666 N : Node_Id;
20668 begin
20669 -- If we are pointing at a positional parameter, it is a member of a
20670 -- node list (the list of parameters), and the next parameter is the
20671 -- next node on the list, unless we hit a parameter association, then
20672 -- we shift to using the chain whose head is the First_Named_Actual in
20673 -- the parent, and then is threaded using the Next_Named_Actual of the
20674 -- Parameter_Association. All this fiddling is because the original node
20675 -- list is in the textual call order, and what we need is the
20676 -- declaration order.
20678 if Is_List_Member (Actual_Id) then
20679 N := Next (Actual_Id);
20681 if Nkind (N) = N_Parameter_Association then
20683 -- In case of a build-in-place call, the call will no longer be a
20684 -- call; it will have been rewritten.
20686 if Nkind_In (Parent (Actual_Id), N_Entry_Call_Statement,
20687 N_Function_Call,
20688 N_Procedure_Call_Statement)
20689 then
20690 return First_Named_Actual (Parent (Actual_Id));
20691 else
20692 return Empty;
20693 end if;
20694 else
20695 return N;
20696 end if;
20698 else
20699 return Next_Named_Actual (Parent (Actual_Id));
20700 end if;
20701 end Next_Actual;
20703 procedure Next_Actual (Actual_Id : in out Node_Id) is
20704 begin
20705 Actual_Id := Next_Actual (Actual_Id);
20706 end Next_Actual;
20708 -----------------
20709 -- Next_Global --
20710 -----------------
20712 function Next_Global (Node : Node_Id) return Node_Id is
20713 begin
20714 -- The global item may either be in a list, or by itself, in which case
20715 -- there is no next global item with the same mode.
20717 if Is_List_Member (Node) then
20718 return Next (Node);
20719 else
20720 return Empty;
20721 end if;
20722 end Next_Global;
20724 procedure Next_Global (Node : in out Node_Id) is
20725 begin
20726 Node := Next_Global (Node);
20727 end Next_Global;
20729 ----------------------------------
20730 -- New_Requires_Transient_Scope --
20731 ----------------------------------
20733 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
20734 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
20735 -- This is called for untagged records and protected types, with
20736 -- nondefaulted discriminants. Returns True if the size of function
20737 -- results is known at the call site, False otherwise. Returns False
20738 -- if there is a variant part that depends on the discriminants of
20739 -- this type, or if there is an array constrained by the discriminants
20740 -- of this type. ???Currently, this is overly conservative (the array
20741 -- could be nested inside some other record that is constrained by
20742 -- nondiscriminants). That is, the recursive calls are too conservative.
20744 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
20745 -- Returns True if Typ is a nonlimited record with defaulted
20746 -- discriminants whose max size makes it unsuitable for allocating on
20747 -- the primary stack.
20749 ------------------------------
20750 -- Caller_Known_Size_Record --
20751 ------------------------------
20753 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
20754 pragma Assert (Typ = Underlying_Type (Typ));
20756 begin
20757 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
20758 return False;
20759 end if;
20761 declare
20762 Comp : Entity_Id;
20764 begin
20765 Comp := First_Entity (Typ);
20766 while Present (Comp) loop
20768 -- Only look at E_Component entities. No need to look at
20769 -- E_Discriminant entities, and we must ignore internal
20770 -- subtypes generated for constrained components.
20772 if Ekind (Comp) = E_Component then
20773 declare
20774 Comp_Type : constant Entity_Id :=
20775 Underlying_Type (Etype (Comp));
20777 begin
20778 if Is_Record_Type (Comp_Type)
20779 or else
20780 Is_Protected_Type (Comp_Type)
20781 then
20782 if not Caller_Known_Size_Record (Comp_Type) then
20783 return False;
20784 end if;
20786 elsif Is_Array_Type (Comp_Type) then
20787 if Size_Depends_On_Discriminant (Comp_Type) then
20788 return False;
20789 end if;
20790 end if;
20791 end;
20792 end if;
20794 Next_Entity (Comp);
20795 end loop;
20796 end;
20798 return True;
20799 end Caller_Known_Size_Record;
20801 ------------------------------
20802 -- Large_Max_Size_Mutable --
20803 ------------------------------
20805 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
20806 pragma Assert (Typ = Underlying_Type (Typ));
20808 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
20809 -- Returns true if the discrete type T has a large range
20811 ----------------------------
20812 -- Is_Large_Discrete_Type --
20813 ----------------------------
20815 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
20816 Threshold : constant Int := 16;
20817 -- Arbitrary threshold above which we consider it "large". We want
20818 -- a fairly large threshold, because these large types really
20819 -- shouldn't have default discriminants in the first place, in
20820 -- most cases.
20822 begin
20823 return UI_To_Int (RM_Size (T)) > Threshold;
20824 end Is_Large_Discrete_Type;
20826 -- Start of processing for Large_Max_Size_Mutable
20828 begin
20829 if Is_Record_Type (Typ)
20830 and then not Is_Limited_View (Typ)
20831 and then Has_Defaulted_Discriminants (Typ)
20832 then
20833 -- Loop through the components, looking for an array whose upper
20834 -- bound(s) depends on discriminants, where both the subtype of
20835 -- the discriminant and the index subtype are too large.
20837 declare
20838 Comp : Entity_Id;
20840 begin
20841 Comp := First_Entity (Typ);
20842 while Present (Comp) loop
20843 if Ekind (Comp) = E_Component then
20844 declare
20845 Comp_Type : constant Entity_Id :=
20846 Underlying_Type (Etype (Comp));
20848 Hi : Node_Id;
20849 Indx : Node_Id;
20850 Ityp : Entity_Id;
20852 begin
20853 if Is_Array_Type (Comp_Type) then
20854 Indx := First_Index (Comp_Type);
20856 while Present (Indx) loop
20857 Ityp := Etype (Indx);
20858 Hi := Type_High_Bound (Ityp);
20860 if Nkind (Hi) = N_Identifier
20861 and then Ekind (Entity (Hi)) = E_Discriminant
20862 and then Is_Large_Discrete_Type (Ityp)
20863 and then Is_Large_Discrete_Type
20864 (Etype (Entity (Hi)))
20865 then
20866 return True;
20867 end if;
20869 Next_Index (Indx);
20870 end loop;
20871 end if;
20872 end;
20873 end if;
20875 Next_Entity (Comp);
20876 end loop;
20877 end;
20878 end if;
20880 return False;
20881 end Large_Max_Size_Mutable;
20883 -- Local declarations
20885 Typ : constant Entity_Id := Underlying_Type (Id);
20887 -- Start of processing for New_Requires_Transient_Scope
20889 begin
20890 -- This is a private type which is not completed yet. This can only
20891 -- happen in a default expression (of a formal parameter or of a
20892 -- record component). Do not expand transient scope in this case.
20894 if No (Typ) then
20895 return False;
20897 -- Do not expand transient scope for non-existent procedure return or
20898 -- string literal types.
20900 elsif Typ = Standard_Void_Type
20901 or else Ekind (Typ) = E_String_Literal_Subtype
20902 then
20903 return False;
20905 -- If Typ is a generic formal incomplete type, then we want to look at
20906 -- the actual type.
20908 elsif Ekind (Typ) = E_Record_Subtype
20909 and then Present (Cloned_Subtype (Typ))
20910 then
20911 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
20913 -- Functions returning specific tagged types may dispatch on result, so
20914 -- their returned value is allocated on the secondary stack, even in the
20915 -- definite case. We must treat nondispatching functions the same way,
20916 -- because access-to-function types can point at both, so the calling
20917 -- conventions must be compatible. Is_Tagged_Type includes controlled
20918 -- types and class-wide types. Controlled type temporaries need
20919 -- finalization.
20921 -- ???It's not clear why we need to return noncontrolled types with
20922 -- controlled components on the secondary stack.
20924 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
20925 return True;
20927 -- Untagged definite subtypes are known size. This includes all
20928 -- elementary [sub]types. Tasks are known size even if they have
20929 -- discriminants. So we return False here, with one exception:
20930 -- For a type like:
20931 -- type T (Last : Natural := 0) is
20932 -- X : String (1 .. Last);
20933 -- end record;
20934 -- we return True. That's because for "P(F(...));", where F returns T,
20935 -- we don't know the size of the result at the call site, so if we
20936 -- allocated it on the primary stack, we would have to allocate the
20937 -- maximum size, which is way too big.
20939 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
20940 return Large_Max_Size_Mutable (Typ);
20942 -- Indefinite (discriminated) untagged record or protected type
20944 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
20945 return not Caller_Known_Size_Record (Typ);
20947 -- Unconstrained array
20949 else
20950 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
20951 return True;
20952 end if;
20953 end New_Requires_Transient_Scope;
20955 --------------------------
20956 -- No_Heap_Finalization --
20957 --------------------------
20959 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
20960 begin
20961 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
20962 and then Is_Library_Level_Entity (Typ)
20963 then
20964 -- A global No_Heap_Finalization pragma applies to all library-level
20965 -- named access-to-object types.
20967 if Present (No_Heap_Finalization_Pragma) then
20968 return True;
20970 -- The library-level named access-to-object type itself is subject to
20971 -- pragma No_Heap_Finalization.
20973 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
20974 return True;
20975 end if;
20976 end if;
20978 return False;
20979 end No_Heap_Finalization;
20981 -----------------------
20982 -- Normalize_Actuals --
20983 -----------------------
20985 -- Chain actuals according to formals of subprogram. If there are no named
20986 -- associations, the chain is simply the list of Parameter Associations,
20987 -- since the order is the same as the declaration order. If there are named
20988 -- associations, then the First_Named_Actual field in the N_Function_Call
20989 -- or N_Procedure_Call_Statement node points to the Parameter_Association
20990 -- node for the parameter that comes first in declaration order. The
20991 -- remaining named parameters are then chained in declaration order using
20992 -- Next_Named_Actual.
20994 -- This routine also verifies that the number of actuals is compatible with
20995 -- the number and default values of formals, but performs no type checking
20996 -- (type checking is done by the caller).
20998 -- If the matching succeeds, Success is set to True and the caller proceeds
20999 -- with type-checking. If the match is unsuccessful, then Success is set to
21000 -- False, and the caller attempts a different interpretation, if there is
21001 -- one.
21003 -- If the flag Report is on, the call is not overloaded, and a failure to
21004 -- match can be reported here, rather than in the caller.
21006 procedure Normalize_Actuals
21007 (N : Node_Id;
21008 S : Entity_Id;
21009 Report : Boolean;
21010 Success : out Boolean)
21012 Actuals : constant List_Id := Parameter_Associations (N);
21013 Actual : Node_Id := Empty;
21014 Formal : Entity_Id;
21015 Last : Node_Id := Empty;
21016 First_Named : Node_Id := Empty;
21017 Found : Boolean;
21019 Formals_To_Match : Integer := 0;
21020 Actuals_To_Match : Integer := 0;
21022 procedure Chain (A : Node_Id);
21023 -- Add named actual at the proper place in the list, using the
21024 -- Next_Named_Actual link.
21026 function Reporting return Boolean;
21027 -- Determines if an error is to be reported. To report an error, we
21028 -- need Report to be True, and also we do not report errors caused
21029 -- by calls to init procs that occur within other init procs. Such
21030 -- errors must always be cascaded errors, since if all the types are
21031 -- declared correctly, the compiler will certainly build decent calls.
21033 -----------
21034 -- Chain --
21035 -----------
21037 procedure Chain (A : Node_Id) is
21038 begin
21039 if No (Last) then
21041 -- Call node points to first actual in list
21043 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
21045 else
21046 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
21047 end if;
21049 Last := A;
21050 Set_Next_Named_Actual (Last, Empty);
21051 end Chain;
21053 ---------------
21054 -- Reporting --
21055 ---------------
21057 function Reporting return Boolean is
21058 begin
21059 if not Report then
21060 return False;
21062 elsif not Within_Init_Proc then
21063 return True;
21065 elsif Is_Init_Proc (Entity (Name (N))) then
21066 return False;
21068 else
21069 return True;
21070 end if;
21071 end Reporting;
21073 -- Start of processing for Normalize_Actuals
21075 begin
21076 if Is_Access_Type (S) then
21078 -- The name in the call is a function call that returns an access
21079 -- to subprogram. The designated type has the list of formals.
21081 Formal := First_Formal (Designated_Type (S));
21082 else
21083 Formal := First_Formal (S);
21084 end if;
21086 while Present (Formal) loop
21087 Formals_To_Match := Formals_To_Match + 1;
21088 Next_Formal (Formal);
21089 end loop;
21091 -- Find if there is a named association, and verify that no positional
21092 -- associations appear after named ones.
21094 if Present (Actuals) then
21095 Actual := First (Actuals);
21096 end if;
21098 while Present (Actual)
21099 and then Nkind (Actual) /= N_Parameter_Association
21100 loop
21101 Actuals_To_Match := Actuals_To_Match + 1;
21102 Next (Actual);
21103 end loop;
21105 if No (Actual) and Actuals_To_Match = Formals_To_Match then
21107 -- Most common case: positional notation, no defaults
21109 Success := True;
21110 return;
21112 elsif Actuals_To_Match > Formals_To_Match then
21114 -- Too many actuals: will not work
21116 if Reporting then
21117 if Is_Entity_Name (Name (N)) then
21118 Error_Msg_N ("too many arguments in call to&", Name (N));
21119 else
21120 Error_Msg_N ("too many arguments in call", N);
21121 end if;
21122 end if;
21124 Success := False;
21125 return;
21126 end if;
21128 First_Named := Actual;
21130 while Present (Actual) loop
21131 if Nkind (Actual) /= N_Parameter_Association then
21132 Error_Msg_N
21133 ("positional parameters not allowed after named ones", Actual);
21134 Success := False;
21135 return;
21137 else
21138 Actuals_To_Match := Actuals_To_Match + 1;
21139 end if;
21141 Next (Actual);
21142 end loop;
21144 if Present (Actuals) then
21145 Actual := First (Actuals);
21146 end if;
21148 Formal := First_Formal (S);
21149 while Present (Formal) loop
21151 -- Match the formals in order. If the corresponding actual is
21152 -- positional, nothing to do. Else scan the list of named actuals
21153 -- to find the one with the right name.
21155 if Present (Actual)
21156 and then Nkind (Actual) /= N_Parameter_Association
21157 then
21158 Next (Actual);
21159 Actuals_To_Match := Actuals_To_Match - 1;
21160 Formals_To_Match := Formals_To_Match - 1;
21162 else
21163 -- For named parameters, search the list of actuals to find
21164 -- one that matches the next formal name.
21166 Actual := First_Named;
21167 Found := False;
21168 while Present (Actual) loop
21169 if Chars (Selector_Name (Actual)) = Chars (Formal) then
21170 Found := True;
21171 Chain (Actual);
21172 Actuals_To_Match := Actuals_To_Match - 1;
21173 Formals_To_Match := Formals_To_Match - 1;
21174 exit;
21175 end if;
21177 Next (Actual);
21178 end loop;
21180 if not Found then
21181 if Ekind (Formal) /= E_In_Parameter
21182 or else No (Default_Value (Formal))
21183 then
21184 if Reporting then
21185 if (Comes_From_Source (S)
21186 or else Sloc (S) = Standard_Location)
21187 and then Is_Overloadable (S)
21188 then
21189 if No (Actuals)
21190 and then
21191 Nkind_In (Parent (N), N_Procedure_Call_Statement,
21192 N_Function_Call,
21193 N_Parameter_Association)
21194 and then Ekind (S) /= E_Function
21195 then
21196 Set_Etype (N, Etype (S));
21198 else
21199 Error_Msg_Name_1 := Chars (S);
21200 Error_Msg_Sloc := Sloc (S);
21201 Error_Msg_NE
21202 ("missing argument for parameter & "
21203 & "in call to % declared #", N, Formal);
21204 end if;
21206 elsif Is_Overloadable (S) then
21207 Error_Msg_Name_1 := Chars (S);
21209 -- Point to type derivation that generated the
21210 -- operation.
21212 Error_Msg_Sloc := Sloc (Parent (S));
21214 Error_Msg_NE
21215 ("missing argument for parameter & "
21216 & "in call to % (inherited) #", N, Formal);
21218 else
21219 Error_Msg_NE
21220 ("missing argument for parameter &", N, Formal);
21221 end if;
21222 end if;
21224 Success := False;
21225 return;
21227 else
21228 Formals_To_Match := Formals_To_Match - 1;
21229 end if;
21230 end if;
21231 end if;
21233 Next_Formal (Formal);
21234 end loop;
21236 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
21237 Success := True;
21238 return;
21240 else
21241 if Reporting then
21243 -- Find some superfluous named actual that did not get
21244 -- attached to the list of associations.
21246 Actual := First (Actuals);
21247 while Present (Actual) loop
21248 if Nkind (Actual) = N_Parameter_Association
21249 and then Actual /= Last
21250 and then No (Next_Named_Actual (Actual))
21251 then
21252 -- A validity check may introduce a copy of a call that
21253 -- includes an extra actual (for example for an unrelated
21254 -- accessibility check). Check that the extra actual matches
21255 -- some extra formal, which must exist already because
21256 -- subprogram must be frozen at this point.
21258 if Present (Extra_Formals (S))
21259 and then not Comes_From_Source (Actual)
21260 and then Nkind (Actual) = N_Parameter_Association
21261 and then Chars (Extra_Formals (S)) =
21262 Chars (Selector_Name (Actual))
21263 then
21264 null;
21265 else
21266 Error_Msg_N
21267 ("unmatched actual & in call", Selector_Name (Actual));
21268 exit;
21269 end if;
21270 end if;
21272 Next (Actual);
21273 end loop;
21274 end if;
21276 Success := False;
21277 return;
21278 end if;
21279 end Normalize_Actuals;
21281 --------------------------------
21282 -- Note_Possible_Modification --
21283 --------------------------------
21285 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
21286 Modification_Comes_From_Source : constant Boolean :=
21287 Comes_From_Source (Parent (N));
21289 Ent : Entity_Id;
21290 Exp : Node_Id;
21292 begin
21293 -- Loop to find referenced entity, if there is one
21295 Exp := N;
21296 loop
21297 Ent := Empty;
21299 if Is_Entity_Name (Exp) then
21300 Ent := Entity (Exp);
21302 -- If the entity is missing, it is an undeclared identifier,
21303 -- and there is nothing to annotate.
21305 if No (Ent) then
21306 return;
21307 end if;
21309 elsif Nkind (Exp) = N_Explicit_Dereference then
21310 declare
21311 P : constant Node_Id := Prefix (Exp);
21313 begin
21314 -- In formal verification mode, keep track of all reads and
21315 -- writes through explicit dereferences.
21317 if GNATprove_Mode then
21318 SPARK_Specific.Generate_Dereference (N, 'm');
21319 end if;
21321 if Nkind (P) = N_Selected_Component
21322 and then Present (Entry_Formal (Entity (Selector_Name (P))))
21323 then
21324 -- Case of a reference to an entry formal
21326 Ent := Entry_Formal (Entity (Selector_Name (P)));
21328 elsif Nkind (P) = N_Identifier
21329 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
21330 and then Present (Expression (Parent (Entity (P))))
21331 and then Nkind (Expression (Parent (Entity (P)))) =
21332 N_Reference
21333 then
21334 -- Case of a reference to a value on which side effects have
21335 -- been removed.
21337 Exp := Prefix (Expression (Parent (Entity (P))));
21338 goto Continue;
21340 else
21341 return;
21342 end if;
21343 end;
21345 elsif Nkind_In (Exp, N_Type_Conversion,
21346 N_Unchecked_Type_Conversion)
21347 then
21348 Exp := Expression (Exp);
21349 goto Continue;
21351 elsif Nkind_In (Exp, N_Slice,
21352 N_Indexed_Component,
21353 N_Selected_Component)
21354 then
21355 -- Special check, if the prefix is an access type, then return
21356 -- since we are modifying the thing pointed to, not the prefix.
21357 -- When we are expanding, most usually the prefix is replaced
21358 -- by an explicit dereference, and this test is not needed, but
21359 -- in some cases (notably -gnatc mode and generics) when we do
21360 -- not do full expansion, we need this special test.
21362 if Is_Access_Type (Etype (Prefix (Exp))) then
21363 return;
21365 -- Otherwise go to prefix and keep going
21367 else
21368 Exp := Prefix (Exp);
21369 goto Continue;
21370 end if;
21372 -- All other cases, not a modification
21374 else
21375 return;
21376 end if;
21378 -- Now look for entity being referenced
21380 if Present (Ent) then
21381 if Is_Object (Ent) then
21382 if Comes_From_Source (Exp)
21383 or else Modification_Comes_From_Source
21384 then
21385 -- Give warning if pragma unmodified is given and we are
21386 -- sure this is a modification.
21388 if Has_Pragma_Unmodified (Ent) and then Sure then
21390 -- Note that the entity may be present only as a result
21391 -- of pragma Unused.
21393 if Has_Pragma_Unused (Ent) then
21394 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
21395 else
21396 Error_Msg_NE
21397 ("??pragma Unmodified given for &!", N, Ent);
21398 end if;
21399 end if;
21401 Set_Never_Set_In_Source (Ent, False);
21402 end if;
21404 Set_Is_True_Constant (Ent, False);
21405 Set_Current_Value (Ent, Empty);
21406 Set_Is_Known_Null (Ent, False);
21408 if not Can_Never_Be_Null (Ent) then
21409 Set_Is_Known_Non_Null (Ent, False);
21410 end if;
21412 -- Follow renaming chain
21414 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
21415 and then Present (Renamed_Object (Ent))
21416 then
21417 Exp := Renamed_Object (Ent);
21419 -- If the entity is the loop variable in an iteration over
21420 -- a container, retrieve container expression to indicate
21421 -- possible modification.
21423 if Present (Related_Expression (Ent))
21424 and then Nkind (Parent (Related_Expression (Ent))) =
21425 N_Iterator_Specification
21426 then
21427 Exp := Original_Node (Related_Expression (Ent));
21428 end if;
21430 goto Continue;
21432 -- The expression may be the renaming of a subcomponent of an
21433 -- array or container. The assignment to the subcomponent is
21434 -- a modification of the container.
21436 elsif Comes_From_Source (Original_Node (Exp))
21437 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
21438 N_Indexed_Component)
21439 then
21440 Exp := Prefix (Original_Node (Exp));
21441 goto Continue;
21442 end if;
21444 -- Generate a reference only if the assignment comes from
21445 -- source. This excludes, for example, calls to a dispatching
21446 -- assignment operation when the left-hand side is tagged. In
21447 -- GNATprove mode, we need those references also on generated
21448 -- code, as these are used to compute the local effects of
21449 -- subprograms.
21451 if Modification_Comes_From_Source or GNATprove_Mode then
21452 Generate_Reference (Ent, Exp, 'm');
21454 -- If the target of the assignment is the bound variable
21455 -- in an iterator, indicate that the corresponding array
21456 -- or container is also modified.
21458 if Ada_Version >= Ada_2012
21459 and then Nkind (Parent (Ent)) = N_Iterator_Specification
21460 then
21461 declare
21462 Domain : constant Node_Id := Name (Parent (Ent));
21464 begin
21465 -- TBD : in the full version of the construct, the
21466 -- domain of iteration can be given by an expression.
21468 if Is_Entity_Name (Domain) then
21469 Generate_Reference (Entity (Domain), Exp, 'm');
21470 Set_Is_True_Constant (Entity (Domain), False);
21471 Set_Never_Set_In_Source (Entity (Domain), False);
21472 end if;
21473 end;
21474 end if;
21475 end if;
21476 end if;
21478 Kill_Checks (Ent);
21480 -- If we are sure this is a modification from source, and we know
21481 -- this modifies a constant, then give an appropriate warning.
21483 if Sure
21484 and then Modification_Comes_From_Source
21485 and then Overlays_Constant (Ent)
21486 and then Address_Clause_Overlay_Warnings
21487 then
21488 declare
21489 Addr : constant Node_Id := Address_Clause (Ent);
21490 O_Ent : Entity_Id;
21491 Off : Boolean;
21493 begin
21494 Find_Overlaid_Entity (Addr, O_Ent, Off);
21496 Error_Msg_Sloc := Sloc (Addr);
21497 Error_Msg_NE
21498 ("??constant& may be modified via address clause#",
21499 N, O_Ent);
21500 end;
21501 end if;
21503 return;
21504 end if;
21506 <<Continue>>
21507 null;
21508 end loop;
21509 end Note_Possible_Modification;
21511 -----------------
21512 -- Null_Status --
21513 -----------------
21515 function Null_Status (N : Node_Id) return Null_Status_Kind is
21516 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
21517 -- Determine whether definition Def carries a null exclusion
21519 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
21520 -- Determine the null status of arbitrary entity Id
21522 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
21523 -- Determine the null status of type Typ
21525 ---------------------------
21526 -- Is_Null_Excluding_Def --
21527 ---------------------------
21529 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
21530 begin
21531 return
21532 Nkind_In (Def, N_Access_Definition,
21533 N_Access_Function_Definition,
21534 N_Access_Procedure_Definition,
21535 N_Access_To_Object_Definition,
21536 N_Component_Definition,
21537 N_Derived_Type_Definition)
21538 and then Null_Exclusion_Present (Def);
21539 end Is_Null_Excluding_Def;
21541 ---------------------------
21542 -- Null_Status_Of_Entity --
21543 ---------------------------
21545 function Null_Status_Of_Entity
21546 (Id : Entity_Id) return Null_Status_Kind
21548 Decl : constant Node_Id := Declaration_Node (Id);
21549 Def : Node_Id;
21551 begin
21552 -- The value of an imported or exported entity may be set externally
21553 -- regardless of a null exclusion. As a result, the value cannot be
21554 -- determined statically.
21556 if Is_Imported (Id) or else Is_Exported (Id) then
21557 return Unknown;
21559 elsif Nkind_In (Decl, N_Component_Declaration,
21560 N_Discriminant_Specification,
21561 N_Formal_Object_Declaration,
21562 N_Object_Declaration,
21563 N_Object_Renaming_Declaration,
21564 N_Parameter_Specification)
21565 then
21566 -- A component declaration yields a non-null value when either
21567 -- its component definition or access definition carries a null
21568 -- exclusion.
21570 if Nkind (Decl) = N_Component_Declaration then
21571 Def := Component_Definition (Decl);
21573 if Is_Null_Excluding_Def (Def) then
21574 return Is_Non_Null;
21575 end if;
21577 Def := Access_Definition (Def);
21579 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21580 return Is_Non_Null;
21581 end if;
21583 -- A formal object declaration yields a non-null value if its
21584 -- access definition carries a null exclusion. If the object is
21585 -- default initialized, then the value depends on the expression.
21587 elsif Nkind (Decl) = N_Formal_Object_Declaration then
21588 Def := Access_Definition (Decl);
21590 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21591 return Is_Non_Null;
21592 end if;
21594 -- A constant may yield a null or non-null value depending on its
21595 -- initialization expression.
21597 elsif Ekind (Id) = E_Constant then
21598 return Null_Status (Constant_Value (Id));
21600 -- The construct yields a non-null value when it has a null
21601 -- exclusion.
21603 elsif Null_Exclusion_Present (Decl) then
21604 return Is_Non_Null;
21606 -- An object renaming declaration yields a non-null value if its
21607 -- access definition carries a null exclusion. Otherwise the value
21608 -- depends on the renamed name.
21610 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
21611 Def := Access_Definition (Decl);
21613 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21614 return Is_Non_Null;
21616 else
21617 return Null_Status (Name (Decl));
21618 end if;
21619 end if;
21620 end if;
21622 -- At this point the declaration of the entity does not carry a null
21623 -- exclusion and lacks an initialization expression. Check the status
21624 -- of its type.
21626 return Null_Status_Of_Type (Etype (Id));
21627 end Null_Status_Of_Entity;
21629 -------------------------
21630 -- Null_Status_Of_Type --
21631 -------------------------
21633 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
21634 Curr : Entity_Id;
21635 Decl : Node_Id;
21637 begin
21638 -- Traverse the type chain looking for types with null exclusion
21640 Curr := Typ;
21641 while Present (Curr) and then Etype (Curr) /= Curr loop
21642 Decl := Parent (Curr);
21644 -- Guard against itypes which do not always have declarations. A
21645 -- type yields a non-null value if it carries a null exclusion.
21647 if Present (Decl) then
21648 if Nkind (Decl) = N_Full_Type_Declaration
21649 and then Is_Null_Excluding_Def (Type_Definition (Decl))
21650 then
21651 return Is_Non_Null;
21653 elsif Nkind (Decl) = N_Subtype_Declaration
21654 and then Null_Exclusion_Present (Decl)
21655 then
21656 return Is_Non_Null;
21657 end if;
21658 end if;
21660 Curr := Etype (Curr);
21661 end loop;
21663 -- The type chain does not contain any null excluding types
21665 return Unknown;
21666 end Null_Status_Of_Type;
21668 -- Start of processing for Null_Status
21670 begin
21671 -- An allocator always creates a non-null value
21673 if Nkind (N) = N_Allocator then
21674 return Is_Non_Null;
21676 -- Taking the 'Access of something yields a non-null value
21678 elsif Nkind (N) = N_Attribute_Reference
21679 and then Nam_In (Attribute_Name (N), Name_Access,
21680 Name_Unchecked_Access,
21681 Name_Unrestricted_Access)
21682 then
21683 return Is_Non_Null;
21685 -- "null" yields null
21687 elsif Nkind (N) = N_Null then
21688 return Is_Null;
21690 -- Check the status of the operand of a type conversion
21692 elsif Nkind (N) = N_Type_Conversion then
21693 return Null_Status (Expression (N));
21695 -- The input denotes a reference to an entity. Determine whether the
21696 -- entity or its type yields a null or non-null value.
21698 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
21699 return Null_Status_Of_Entity (Entity (N));
21700 end if;
21702 -- Otherwise it is not possible to determine the null status of the
21703 -- subexpression at compile time without resorting to simple flow
21704 -- analysis.
21706 return Unknown;
21707 end Null_Status;
21709 --------------------------------------
21710 -- Null_To_Null_Address_Convert_OK --
21711 --------------------------------------
21713 function Null_To_Null_Address_Convert_OK
21714 (N : Node_Id;
21715 Typ : Entity_Id := Empty) return Boolean
21717 begin
21718 if not Relaxed_RM_Semantics then
21719 return False;
21720 end if;
21722 if Nkind (N) = N_Null then
21723 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
21725 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
21726 then
21727 declare
21728 L : constant Node_Id := Left_Opnd (N);
21729 R : constant Node_Id := Right_Opnd (N);
21731 begin
21732 -- We check the Etype of the complementary operand since the
21733 -- N_Null node is not decorated at this stage.
21735 return
21736 ((Nkind (L) = N_Null
21737 and then Is_Descendant_Of_Address (Etype (R)))
21738 or else
21739 (Nkind (R) = N_Null
21740 and then Is_Descendant_Of_Address (Etype (L))));
21741 end;
21742 end if;
21744 return False;
21745 end Null_To_Null_Address_Convert_OK;
21747 ---------------------------------
21748 -- Number_Of_Elements_In_Array --
21749 ---------------------------------
21751 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
21752 Indx : Node_Id;
21753 Typ : Entity_Id;
21754 Low : Node_Id;
21755 High : Node_Id;
21756 Num : Int := 1;
21758 begin
21759 pragma Assert (Is_Array_Type (T));
21761 Indx := First_Index (T);
21762 while Present (Indx) loop
21763 Typ := Underlying_Type (Etype (Indx));
21765 -- Never look at junk bounds of a generic type
21767 if Is_Generic_Type (Typ) then
21768 return 0;
21769 end if;
21771 -- Check the array bounds are known at compile time and return zero
21772 -- if they are not.
21774 Low := Type_Low_Bound (Typ);
21775 High := Type_High_Bound (Typ);
21777 if not Compile_Time_Known_Value (Low) then
21778 return 0;
21779 elsif not Compile_Time_Known_Value (High) then
21780 return 0;
21781 else
21782 Num :=
21783 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
21784 end if;
21786 Next_Index (Indx);
21787 end loop;
21789 return Num;
21790 end Number_Of_Elements_In_Array;
21792 -------------------------
21793 -- Object_Access_Level --
21794 -------------------------
21796 -- Returns the static accessibility level of the view denoted by Obj. Note
21797 -- that the value returned is the result of a call to Scope_Depth. Only
21798 -- scope depths associated with dynamic scopes can actually be returned.
21799 -- Since only relative levels matter for accessibility checking, the fact
21800 -- that the distance between successive levels of accessibility is not
21801 -- always one is immaterial (invariant: if level(E2) is deeper than
21802 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
21804 function Object_Access_Level (Obj : Node_Id) return Uint is
21805 function Is_Interface_Conversion (N : Node_Id) return Boolean;
21806 -- Determine whether N is a construct of the form
21807 -- Some_Type (Operand._tag'Address)
21808 -- This construct appears in the context of dispatching calls.
21810 function Reference_To (Obj : Node_Id) return Node_Id;
21811 -- An explicit dereference is created when removing side effects from
21812 -- expressions for constraint checking purposes. In this case a local
21813 -- access type is created for it. The correct access level is that of
21814 -- the original source node. We detect this case by noting that the
21815 -- prefix of the dereference is created by an object declaration whose
21816 -- initial expression is a reference.
21818 -----------------------------
21819 -- Is_Interface_Conversion --
21820 -----------------------------
21822 function Is_Interface_Conversion (N : Node_Id) return Boolean is
21823 begin
21824 return Nkind (N) = N_Unchecked_Type_Conversion
21825 and then Nkind (Expression (N)) = N_Attribute_Reference
21826 and then Attribute_Name (Expression (N)) = Name_Address;
21827 end Is_Interface_Conversion;
21829 ------------------
21830 -- Reference_To --
21831 ------------------
21833 function Reference_To (Obj : Node_Id) return Node_Id is
21834 Pref : constant Node_Id := Prefix (Obj);
21835 begin
21836 if Is_Entity_Name (Pref)
21837 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
21838 and then Present (Expression (Parent (Entity (Pref))))
21839 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
21840 then
21841 return (Prefix (Expression (Parent (Entity (Pref)))));
21842 else
21843 return Empty;
21844 end if;
21845 end Reference_To;
21847 -- Local variables
21849 E : Entity_Id;
21851 -- Start of processing for Object_Access_Level
21853 begin
21854 if Nkind (Obj) = N_Defining_Identifier
21855 or else Is_Entity_Name (Obj)
21856 then
21857 if Nkind (Obj) = N_Defining_Identifier then
21858 E := Obj;
21859 else
21860 E := Entity (Obj);
21861 end if;
21863 if Is_Prival (E) then
21864 E := Prival_Link (E);
21865 end if;
21867 -- If E is a type then it denotes a current instance. For this case
21868 -- we add one to the normal accessibility level of the type to ensure
21869 -- that current instances are treated as always being deeper than
21870 -- than the level of any visible named access type (see 3.10.2(21)).
21872 if Is_Type (E) then
21873 return Type_Access_Level (E) + 1;
21875 elsif Present (Renamed_Object (E)) then
21876 return Object_Access_Level (Renamed_Object (E));
21878 -- Similarly, if E is a component of the current instance of a
21879 -- protected type, any instance of it is assumed to be at a deeper
21880 -- level than the type. For a protected object (whose type is an
21881 -- anonymous protected type) its components are at the same level
21882 -- as the type itself.
21884 elsif not Is_Overloadable (E)
21885 and then Ekind (Scope (E)) = E_Protected_Type
21886 and then Comes_From_Source (Scope (E))
21887 then
21888 return Type_Access_Level (Scope (E)) + 1;
21890 else
21891 -- Aliased formals of functions take their access level from the
21892 -- point of call, i.e. require a dynamic check. For static check
21893 -- purposes, this is smaller than the level of the subprogram
21894 -- itself. For procedures the aliased makes no difference.
21896 if Is_Formal (E)
21897 and then Is_Aliased (E)
21898 and then Ekind (Scope (E)) = E_Function
21899 then
21900 return Type_Access_Level (Etype (E));
21902 else
21903 return Scope_Depth (Enclosing_Dynamic_Scope (E));
21904 end if;
21905 end if;
21907 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
21908 if Is_Access_Type (Etype (Prefix (Obj))) then
21909 return Type_Access_Level (Etype (Prefix (Obj)));
21910 else
21911 return Object_Access_Level (Prefix (Obj));
21912 end if;
21914 elsif Nkind (Obj) = N_Explicit_Dereference then
21916 -- If the prefix is a selected access discriminant then we make a
21917 -- recursive call on the prefix, which will in turn check the level
21918 -- of the prefix object of the selected discriminant.
21920 -- In Ada 2012, if the discriminant has implicit dereference and
21921 -- the context is a selected component, treat this as an object of
21922 -- unknown scope (see below). This is necessary in compile-only mode;
21923 -- otherwise expansion will already have transformed the prefix into
21924 -- a temporary.
21926 if Nkind (Prefix (Obj)) = N_Selected_Component
21927 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
21928 and then
21929 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
21930 and then
21931 (not Has_Implicit_Dereference
21932 (Entity (Selector_Name (Prefix (Obj))))
21933 or else Nkind (Parent (Obj)) /= N_Selected_Component)
21934 then
21935 return Object_Access_Level (Prefix (Obj));
21937 -- Detect an interface conversion in the context of a dispatching
21938 -- call. Use the original form of the conversion to find the access
21939 -- level of the operand.
21941 elsif Is_Interface (Etype (Obj))
21942 and then Is_Interface_Conversion (Prefix (Obj))
21943 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
21944 then
21945 return Object_Access_Level (Original_Node (Obj));
21947 elsif not Comes_From_Source (Obj) then
21948 declare
21949 Ref : constant Node_Id := Reference_To (Obj);
21950 begin
21951 if Present (Ref) then
21952 return Object_Access_Level (Ref);
21953 else
21954 return Type_Access_Level (Etype (Prefix (Obj)));
21955 end if;
21956 end;
21958 else
21959 return Type_Access_Level (Etype (Prefix (Obj)));
21960 end if;
21962 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
21963 return Object_Access_Level (Expression (Obj));
21965 elsif Nkind (Obj) = N_Function_Call then
21967 -- Function results are objects, so we get either the access level of
21968 -- the function or, in the case of an indirect call, the level of the
21969 -- access-to-subprogram type. (This code is used for Ada 95, but it
21970 -- looks wrong, because it seems that we should be checking the level
21971 -- of the call itself, even for Ada 95. However, using the Ada 2005
21972 -- version of the code causes regressions in several tests that are
21973 -- compiled with -gnat95. ???)
21975 if Ada_Version < Ada_2005 then
21976 if Is_Entity_Name (Name (Obj)) then
21977 return Subprogram_Access_Level (Entity (Name (Obj)));
21978 else
21979 return Type_Access_Level (Etype (Prefix (Name (Obj))));
21980 end if;
21982 -- For Ada 2005, the level of the result object of a function call is
21983 -- defined to be the level of the call's innermost enclosing master.
21984 -- We determine that by querying the depth of the innermost enclosing
21985 -- dynamic scope.
21987 else
21988 Return_Master_Scope_Depth_Of_Call : declare
21989 function Innermost_Master_Scope_Depth
21990 (N : Node_Id) return Uint;
21991 -- Returns the scope depth of the given node's innermost
21992 -- enclosing dynamic scope (effectively the accessibility
21993 -- level of the innermost enclosing master).
21995 ----------------------------------
21996 -- Innermost_Master_Scope_Depth --
21997 ----------------------------------
21999 function Innermost_Master_Scope_Depth
22000 (N : Node_Id) return Uint
22002 Node_Par : Node_Id := Parent (N);
22004 begin
22005 -- Locate the nearest enclosing node (by traversing Parents)
22006 -- that Defining_Entity can be applied to, and return the
22007 -- depth of that entity's nearest enclosing dynamic scope.
22009 while Present (Node_Par) loop
22010 case Nkind (Node_Par) is
22011 when N_Abstract_Subprogram_Declaration
22012 | N_Block_Statement
22013 | N_Body_Stub
22014 | N_Component_Declaration
22015 | N_Entry_Body
22016 | N_Entry_Declaration
22017 | N_Exception_Declaration
22018 | N_Formal_Object_Declaration
22019 | N_Formal_Package_Declaration
22020 | N_Formal_Subprogram_Declaration
22021 | N_Formal_Type_Declaration
22022 | N_Full_Type_Declaration
22023 | N_Function_Specification
22024 | N_Generic_Declaration
22025 | N_Generic_Instantiation
22026 | N_Implicit_Label_Declaration
22027 | N_Incomplete_Type_Declaration
22028 | N_Loop_Parameter_Specification
22029 | N_Number_Declaration
22030 | N_Object_Declaration
22031 | N_Package_Declaration
22032 | N_Package_Specification
22033 | N_Parameter_Specification
22034 | N_Private_Extension_Declaration
22035 | N_Private_Type_Declaration
22036 | N_Procedure_Specification
22037 | N_Proper_Body
22038 | N_Protected_Type_Declaration
22039 | N_Renaming_Declaration
22040 | N_Single_Protected_Declaration
22041 | N_Single_Task_Declaration
22042 | N_Subprogram_Declaration
22043 | N_Subtype_Declaration
22044 | N_Subunit
22045 | N_Task_Type_Declaration
22047 return Scope_Depth
22048 (Nearest_Dynamic_Scope
22049 (Defining_Entity (Node_Par)));
22051 -- For a return statement within a function, return
22052 -- the depth of the function itself. This is not just
22053 -- a small optimization, but matters when analyzing
22054 -- the expression in an expression function before
22055 -- the body is created.
22057 when N_Simple_Return_Statement =>
22058 if Ekind (Current_Scope) = E_Function then
22059 return Scope_Depth (Current_Scope);
22060 end if;
22062 when others =>
22063 null;
22064 end case;
22066 Node_Par := Parent (Node_Par);
22067 end loop;
22069 pragma Assert (False);
22071 -- Should never reach the following return
22073 return Scope_Depth (Current_Scope) + 1;
22074 end Innermost_Master_Scope_Depth;
22076 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22078 begin
22079 return Innermost_Master_Scope_Depth (Obj);
22080 end Return_Master_Scope_Depth_Of_Call;
22081 end if;
22083 -- For convenience we handle qualified expressions, even though they
22084 -- aren't technically object names.
22086 elsif Nkind (Obj) = N_Qualified_Expression then
22087 return Object_Access_Level (Expression (Obj));
22089 -- Ditto for aggregates. They have the level of the temporary that
22090 -- will hold their value.
22092 elsif Nkind (Obj) = N_Aggregate then
22093 return Object_Access_Level (Current_Scope);
22095 -- Otherwise return the scope level of Standard. (If there are cases
22096 -- that fall through to this point they will be treated as having
22097 -- global accessibility for now. ???)
22099 else
22100 return Scope_Depth (Standard_Standard);
22101 end if;
22102 end Object_Access_Level;
22104 ----------------------------------
22105 -- Old_Requires_Transient_Scope --
22106 ----------------------------------
22108 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22109 Typ : constant Entity_Id := Underlying_Type (Id);
22111 begin
22112 -- This is a private type which is not completed yet. This can only
22113 -- happen in a default expression (of a formal parameter or of a
22114 -- record component). Do not expand transient scope in this case.
22116 if No (Typ) then
22117 return False;
22119 -- Do not expand transient scope for non-existent procedure return
22121 elsif Typ = Standard_Void_Type then
22122 return False;
22124 -- Elementary types do not require a transient scope
22126 elsif Is_Elementary_Type (Typ) then
22127 return False;
22129 -- Generally, indefinite subtypes require a transient scope, since the
22130 -- back end cannot generate temporaries, since this is not a valid type
22131 -- for declaring an object. It might be possible to relax this in the
22132 -- future, e.g. by declaring the maximum possible space for the type.
22134 elsif not Is_Definite_Subtype (Typ) then
22135 return True;
22137 -- Functions returning tagged types may dispatch on result so their
22138 -- returned value is allocated on the secondary stack. Controlled
22139 -- type temporaries need finalization.
22141 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22142 return True;
22144 -- Record type
22146 elsif Is_Record_Type (Typ) then
22147 declare
22148 Comp : Entity_Id;
22150 begin
22151 Comp := First_Entity (Typ);
22152 while Present (Comp) loop
22153 if Ekind (Comp) = E_Component then
22155 -- ???It's not clear we need a full recursive call to
22156 -- Old_Requires_Transient_Scope here. Note that the
22157 -- following can't happen.
22159 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
22160 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
22162 if Old_Requires_Transient_Scope (Etype (Comp)) then
22163 return True;
22164 end if;
22165 end if;
22167 Next_Entity (Comp);
22168 end loop;
22169 end;
22171 return False;
22173 -- String literal types never require transient scope
22175 elsif Ekind (Typ) = E_String_Literal_Subtype then
22176 return False;
22178 -- Array type. Note that we already know that this is a constrained
22179 -- array, since unconstrained arrays will fail the indefinite test.
22181 elsif Is_Array_Type (Typ) then
22183 -- If component type requires a transient scope, the array does too
22185 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
22186 return True;
22188 -- Otherwise, we only need a transient scope if the size depends on
22189 -- the value of one or more discriminants.
22191 else
22192 return Size_Depends_On_Discriminant (Typ);
22193 end if;
22195 -- All other cases do not require a transient scope
22197 else
22198 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
22199 return False;
22200 end if;
22201 end Old_Requires_Transient_Scope;
22203 ---------------------------------
22204 -- Original_Aspect_Pragma_Name --
22205 ---------------------------------
22207 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
22208 Item : Node_Id;
22209 Item_Nam : Name_Id;
22211 begin
22212 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
22214 Item := N;
22216 -- The pragma was generated to emulate an aspect, use the original
22217 -- aspect specification.
22219 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
22220 Item := Corresponding_Aspect (Item);
22221 end if;
22223 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
22224 -- Post and Post_Class rewrite their pragma identifier to preserve the
22225 -- original name.
22226 -- ??? this is kludgey
22228 if Nkind (Item) = N_Pragma then
22229 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
22231 else
22232 pragma Assert (Nkind (Item) = N_Aspect_Specification);
22233 Item_Nam := Chars (Identifier (Item));
22234 end if;
22236 -- Deal with 'Class by converting the name to its _XXX form
22238 if Class_Present (Item) then
22239 if Item_Nam = Name_Invariant then
22240 Item_Nam := Name_uInvariant;
22242 elsif Item_Nam = Name_Post then
22243 Item_Nam := Name_uPost;
22245 elsif Item_Nam = Name_Pre then
22246 Item_Nam := Name_uPre;
22248 elsif Nam_In (Item_Nam, Name_Type_Invariant,
22249 Name_Type_Invariant_Class)
22250 then
22251 Item_Nam := Name_uType_Invariant;
22253 -- Nothing to do for other cases (e.g. a Check that derived from
22254 -- Pre_Class and has the flag set). Also we do nothing if the name
22255 -- is already in special _xxx form.
22257 end if;
22258 end if;
22260 return Item_Nam;
22261 end Original_Aspect_Pragma_Name;
22263 --------------------------------------
22264 -- Original_Corresponding_Operation --
22265 --------------------------------------
22267 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
22269 Typ : constant Entity_Id := Find_Dispatching_Type (S);
22271 begin
22272 -- If S is an inherited primitive S2 the original corresponding
22273 -- operation of S is the original corresponding operation of S2
22275 if Present (Alias (S))
22276 and then Find_Dispatching_Type (Alias (S)) /= Typ
22277 then
22278 return Original_Corresponding_Operation (Alias (S));
22280 -- If S overrides an inherited subprogram S2 the original corresponding
22281 -- operation of S is the original corresponding operation of S2
22283 elsif Present (Overridden_Operation (S)) then
22284 return Original_Corresponding_Operation (Overridden_Operation (S));
22286 -- otherwise it is S itself
22288 else
22289 return S;
22290 end if;
22291 end Original_Corresponding_Operation;
22293 -------------------
22294 -- Output_Entity --
22295 -------------------
22297 procedure Output_Entity (Id : Entity_Id) is
22298 Scop : Entity_Id;
22300 begin
22301 Scop := Scope (Id);
22303 -- The entity may lack a scope when it is in the process of being
22304 -- analyzed. Use the current scope as an approximation.
22306 if No (Scop) then
22307 Scop := Current_Scope;
22308 end if;
22310 Output_Name (Chars (Id), Scop);
22311 end Output_Entity;
22313 -----------------
22314 -- Output_Name --
22315 -----------------
22317 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
22318 begin
22319 Write_Str
22320 (Get_Name_String
22321 (Get_Qualified_Name
22322 (Nam => Nam,
22323 Suffix => No_Name,
22324 Scop => Scop)));
22325 Write_Eol;
22326 end Output_Name;
22328 ----------------------
22329 -- Policy_In_Effect --
22330 ----------------------
22332 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
22333 function Policy_In_List (List : Node_Id) return Name_Id;
22334 -- Determine the mode of a policy in a N_Pragma list
22336 --------------------
22337 -- Policy_In_List --
22338 --------------------
22340 function Policy_In_List (List : Node_Id) return Name_Id is
22341 Arg1 : Node_Id;
22342 Arg2 : Node_Id;
22343 Prag : Node_Id;
22345 begin
22346 Prag := List;
22347 while Present (Prag) loop
22348 Arg1 := First (Pragma_Argument_Associations (Prag));
22349 Arg2 := Next (Arg1);
22351 Arg1 := Get_Pragma_Arg (Arg1);
22352 Arg2 := Get_Pragma_Arg (Arg2);
22354 -- The current Check_Policy pragma matches the requested policy or
22355 -- appears in the single argument form (Assertion, policy_id).
22357 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
22358 return Chars (Arg2);
22359 end if;
22361 Prag := Next_Pragma (Prag);
22362 end loop;
22364 return No_Name;
22365 end Policy_In_List;
22367 -- Local variables
22369 Kind : Name_Id;
22371 -- Start of processing for Policy_In_Effect
22373 begin
22374 if not Is_Valid_Assertion_Kind (Policy) then
22375 raise Program_Error;
22376 end if;
22378 -- Inspect all policy pragmas that appear within scopes (if any)
22380 Kind := Policy_In_List (Check_Policy_List);
22382 -- Inspect all configuration policy pragmas (if any)
22384 if Kind = No_Name then
22385 Kind := Policy_In_List (Check_Policy_List_Config);
22386 end if;
22388 -- The context lacks policy pragmas, determine the mode based on whether
22389 -- assertions are enabled at the configuration level. This ensures that
22390 -- the policy is preserved when analyzing generics.
22392 if Kind = No_Name then
22393 if Assertions_Enabled_Config then
22394 Kind := Name_Check;
22395 else
22396 Kind := Name_Ignore;
22397 end if;
22398 end if;
22400 return Kind;
22401 end Policy_In_Effect;
22403 ----------------------------------
22404 -- Predicate_Tests_On_Arguments --
22405 ----------------------------------
22407 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
22408 begin
22409 -- Always test predicates on indirect call
22411 if Ekind (Subp) = E_Subprogram_Type then
22412 return True;
22414 -- Do not test predicates on call to generated default Finalize, since
22415 -- we are not interested in whether something we are finalizing (and
22416 -- typically destroying) satisfies its predicates.
22418 elsif Chars (Subp) = Name_Finalize
22419 and then not Comes_From_Source (Subp)
22420 then
22421 return False;
22423 -- Do not test predicates on any internally generated routines
22425 elsif Is_Internal_Name (Chars (Subp)) then
22426 return False;
22428 -- Do not test predicates on call to Init_Proc, since if needed the
22429 -- predicate test will occur at some other point.
22431 elsif Is_Init_Proc (Subp) then
22432 return False;
22434 -- Do not test predicates on call to predicate function, since this
22435 -- would cause infinite recursion.
22437 elsif Ekind (Subp) = E_Function
22438 and then (Is_Predicate_Function (Subp)
22439 or else
22440 Is_Predicate_Function_M (Subp))
22441 then
22442 return False;
22444 -- For now, no other exceptions
22446 else
22447 return True;
22448 end if;
22449 end Predicate_Tests_On_Arguments;
22451 -----------------------
22452 -- Private_Component --
22453 -----------------------
22455 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
22456 Ancestor : constant Entity_Id := Base_Type (Type_Id);
22458 function Trace_Components
22459 (T : Entity_Id;
22460 Check : Boolean) return Entity_Id;
22461 -- Recursive function that does the work, and checks against circular
22462 -- definition for each subcomponent type.
22464 ----------------------
22465 -- Trace_Components --
22466 ----------------------
22468 function Trace_Components
22469 (T : Entity_Id;
22470 Check : Boolean) return Entity_Id
22472 Btype : constant Entity_Id := Base_Type (T);
22473 Component : Entity_Id;
22474 P : Entity_Id;
22475 Candidate : Entity_Id := Empty;
22477 begin
22478 if Check and then Btype = Ancestor then
22479 Error_Msg_N ("circular type definition", Type_Id);
22480 return Any_Type;
22481 end if;
22483 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
22484 if Present (Full_View (Btype))
22485 and then Is_Record_Type (Full_View (Btype))
22486 and then not Is_Frozen (Btype)
22487 then
22488 -- To indicate that the ancestor depends on a private type, the
22489 -- current Btype is sufficient. However, to check for circular
22490 -- definition we must recurse on the full view.
22492 Candidate := Trace_Components (Full_View (Btype), True);
22494 if Candidate = Any_Type then
22495 return Any_Type;
22496 else
22497 return Btype;
22498 end if;
22500 else
22501 return Btype;
22502 end if;
22504 elsif Is_Array_Type (Btype) then
22505 return Trace_Components (Component_Type (Btype), True);
22507 elsif Is_Record_Type (Btype) then
22508 Component := First_Entity (Btype);
22509 while Present (Component)
22510 and then Comes_From_Source (Component)
22511 loop
22512 -- Skip anonymous types generated by constrained components
22514 if not Is_Type (Component) then
22515 P := Trace_Components (Etype (Component), True);
22517 if Present (P) then
22518 if P = Any_Type then
22519 return P;
22520 else
22521 Candidate := P;
22522 end if;
22523 end if;
22524 end if;
22526 Next_Entity (Component);
22527 end loop;
22529 return Candidate;
22531 else
22532 return Empty;
22533 end if;
22534 end Trace_Components;
22536 -- Start of processing for Private_Component
22538 begin
22539 return Trace_Components (Type_Id, False);
22540 end Private_Component;
22542 ---------------------------
22543 -- Primitive_Names_Match --
22544 ---------------------------
22546 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
22547 function Non_Internal_Name (E : Entity_Id) return Name_Id;
22548 -- Given an internal name, returns the corresponding non-internal name
22550 ------------------------
22551 -- Non_Internal_Name --
22552 ------------------------
22554 function Non_Internal_Name (E : Entity_Id) return Name_Id is
22555 begin
22556 Get_Name_String (Chars (E));
22557 Name_Len := Name_Len - 1;
22558 return Name_Find;
22559 end Non_Internal_Name;
22561 -- Start of processing for Primitive_Names_Match
22563 begin
22564 pragma Assert (Present (E1) and then Present (E2));
22566 return Chars (E1) = Chars (E2)
22567 or else
22568 (not Is_Internal_Name (Chars (E1))
22569 and then Is_Internal_Name (Chars (E2))
22570 and then Non_Internal_Name (E2) = Chars (E1))
22571 or else
22572 (not Is_Internal_Name (Chars (E2))
22573 and then Is_Internal_Name (Chars (E1))
22574 and then Non_Internal_Name (E1) = Chars (E2))
22575 or else
22576 (Is_Predefined_Dispatching_Operation (E1)
22577 and then Is_Predefined_Dispatching_Operation (E2)
22578 and then Same_TSS (E1, E2))
22579 or else
22580 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
22581 end Primitive_Names_Match;
22583 -----------------------
22584 -- Process_End_Label --
22585 -----------------------
22587 procedure Process_End_Label
22588 (N : Node_Id;
22589 Typ : Character;
22590 Ent : Entity_Id)
22592 Loc : Source_Ptr;
22593 Nam : Node_Id;
22594 Scop : Entity_Id;
22596 Label_Ref : Boolean;
22597 -- Set True if reference to end label itself is required
22599 Endl : Node_Id;
22600 -- Gets set to the operator symbol or identifier that references the
22601 -- entity Ent. For the child unit case, this is the identifier from the
22602 -- designator. For other cases, this is simply Endl.
22604 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
22605 -- N is an identifier node that appears as a parent unit reference in
22606 -- the case where Ent is a child unit. This procedure generates an
22607 -- appropriate cross-reference entry. E is the corresponding entity.
22609 -------------------------
22610 -- Generate_Parent_Ref --
22611 -------------------------
22613 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
22614 begin
22615 -- If names do not match, something weird, skip reference
22617 if Chars (E) = Chars (N) then
22619 -- Generate the reference. We do NOT consider this as a reference
22620 -- for unreferenced symbol purposes.
22622 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
22624 if Style_Check then
22625 Style.Check_Identifier (N, E);
22626 end if;
22627 end if;
22628 end Generate_Parent_Ref;
22630 -- Start of processing for Process_End_Label
22632 begin
22633 -- If no node, ignore. This happens in some error situations, and
22634 -- also for some internally generated structures where no end label
22635 -- references are required in any case.
22637 if No (N) then
22638 return;
22639 end if;
22641 -- Nothing to do if no End_Label, happens for internally generated
22642 -- constructs where we don't want an end label reference anyway. Also
22643 -- nothing to do if Endl is a string literal, which means there was
22644 -- some prior error (bad operator symbol)
22646 Endl := End_Label (N);
22648 if No (Endl) or else Nkind (Endl) = N_String_Literal then
22649 return;
22650 end if;
22652 -- Reference node is not in extended main source unit
22654 if not In_Extended_Main_Source_Unit (N) then
22656 -- Generally we do not collect references except for the extended
22657 -- main source unit. The one exception is the 'e' entry for a
22658 -- package spec, where it is useful for a client to have the
22659 -- ending information to define scopes.
22661 if Typ /= 'e' then
22662 return;
22664 else
22665 Label_Ref := False;
22667 -- For this case, we can ignore any parent references, but we
22668 -- need the package name itself for the 'e' entry.
22670 if Nkind (Endl) = N_Designator then
22671 Endl := Identifier (Endl);
22672 end if;
22673 end if;
22675 -- Reference is in extended main source unit
22677 else
22678 Label_Ref := True;
22680 -- For designator, generate references for the parent entries
22682 if Nkind (Endl) = N_Designator then
22684 -- Generate references for the prefix if the END line comes from
22685 -- source (otherwise we do not need these references) We climb the
22686 -- scope stack to find the expected entities.
22688 if Comes_From_Source (Endl) then
22689 Nam := Name (Endl);
22690 Scop := Current_Scope;
22691 while Nkind (Nam) = N_Selected_Component loop
22692 Scop := Scope (Scop);
22693 exit when No (Scop);
22694 Generate_Parent_Ref (Selector_Name (Nam), Scop);
22695 Nam := Prefix (Nam);
22696 end loop;
22698 if Present (Scop) then
22699 Generate_Parent_Ref (Nam, Scope (Scop));
22700 end if;
22701 end if;
22703 Endl := Identifier (Endl);
22704 end if;
22705 end if;
22707 -- If the end label is not for the given entity, then either we have
22708 -- some previous error, or this is a generic instantiation for which
22709 -- we do not need to make a cross-reference in this case anyway. In
22710 -- either case we simply ignore the call.
22712 if Chars (Ent) /= Chars (Endl) then
22713 return;
22714 end if;
22716 -- If label was really there, then generate a normal reference and then
22717 -- adjust the location in the end label to point past the name (which
22718 -- should almost always be the semicolon).
22720 Loc := Sloc (Endl);
22722 if Comes_From_Source (Endl) then
22724 -- If a label reference is required, then do the style check and
22725 -- generate an l-type cross-reference entry for the label
22727 if Label_Ref then
22728 if Style_Check then
22729 Style.Check_Identifier (Endl, Ent);
22730 end if;
22732 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
22733 end if;
22735 -- Set the location to point past the label (normally this will
22736 -- mean the semicolon immediately following the label). This is
22737 -- done for the sake of the 'e' or 't' entry generated below.
22739 Get_Decoded_Name_String (Chars (Endl));
22740 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
22742 else
22743 -- In SPARK mode, no missing label is allowed for packages and
22744 -- subprogram bodies. Detect those cases by testing whether
22745 -- Process_End_Label was called for a body (Typ = 't') or a package.
22747 if Restriction_Check_Required (SPARK_05)
22748 and then (Typ = 't' or else Ekind (Ent) = E_Package)
22749 then
22750 Error_Msg_Node_1 := Endl;
22751 Check_SPARK_05_Restriction
22752 ("`END &` required", Endl, Force => True);
22753 end if;
22754 end if;
22756 -- Now generate the e/t reference
22758 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
22760 -- Restore Sloc, in case modified above, since we have an identifier
22761 -- and the normal Sloc should be left set in the tree.
22763 Set_Sloc (Endl, Loc);
22764 end Process_End_Label;
22766 --------------------------------
22767 -- Propagate_Concurrent_Flags --
22768 --------------------------------
22770 procedure Propagate_Concurrent_Flags
22771 (Typ : Entity_Id;
22772 Comp_Typ : Entity_Id)
22774 begin
22775 if Has_Task (Comp_Typ) then
22776 Set_Has_Task (Typ);
22777 end if;
22779 if Has_Protected (Comp_Typ) then
22780 Set_Has_Protected (Typ);
22781 end if;
22783 if Has_Timing_Event (Comp_Typ) then
22784 Set_Has_Timing_Event (Typ);
22785 end if;
22786 end Propagate_Concurrent_Flags;
22788 ------------------------------
22789 -- Propagate_DIC_Attributes --
22790 ------------------------------
22792 procedure Propagate_DIC_Attributes
22793 (Typ : Entity_Id;
22794 From_Typ : Entity_Id)
22796 DIC_Proc : Entity_Id;
22798 begin
22799 if Present (Typ) and then Present (From_Typ) then
22800 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
22802 -- Nothing to do if both the source and the destination denote the
22803 -- same type.
22805 if From_Typ = Typ then
22806 return;
22807 end if;
22809 DIC_Proc := DIC_Procedure (From_Typ);
22811 -- The setting of the attributes is intentionally conservative. This
22812 -- prevents accidental clobbering of enabled attributes.
22814 if Has_Inherited_DIC (From_Typ)
22815 and then not Has_Inherited_DIC (Typ)
22816 then
22817 Set_Has_Inherited_DIC (Typ);
22818 end if;
22820 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
22821 Set_Has_Own_DIC (Typ);
22822 end if;
22824 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
22825 Set_DIC_Procedure (Typ, DIC_Proc);
22826 end if;
22827 end if;
22828 end Propagate_DIC_Attributes;
22830 ------------------------------------
22831 -- Propagate_Invariant_Attributes --
22832 ------------------------------------
22834 procedure Propagate_Invariant_Attributes
22835 (Typ : Entity_Id;
22836 From_Typ : Entity_Id)
22838 Full_IP : Entity_Id;
22839 Part_IP : Entity_Id;
22841 begin
22842 if Present (Typ) and then Present (From_Typ) then
22843 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
22845 -- Nothing to do if both the source and the destination denote the
22846 -- same type.
22848 if From_Typ = Typ then
22849 return;
22850 end if;
22852 Full_IP := Invariant_Procedure (From_Typ);
22853 Part_IP := Partial_Invariant_Procedure (From_Typ);
22855 -- The setting of the attributes is intentionally conservative. This
22856 -- prevents accidental clobbering of enabled attributes.
22858 if Has_Inheritable_Invariants (From_Typ)
22859 and then not Has_Inheritable_Invariants (Typ)
22860 then
22861 Set_Has_Inheritable_Invariants (Typ, True);
22862 end if;
22864 if Has_Inherited_Invariants (From_Typ)
22865 and then not Has_Inherited_Invariants (Typ)
22866 then
22867 Set_Has_Inherited_Invariants (Typ, True);
22868 end if;
22870 if Has_Own_Invariants (From_Typ)
22871 and then not Has_Own_Invariants (Typ)
22872 then
22873 Set_Has_Own_Invariants (Typ, True);
22874 end if;
22876 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
22877 Set_Invariant_Procedure (Typ, Full_IP);
22878 end if;
22880 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
22881 then
22882 Set_Partial_Invariant_Procedure (Typ, Part_IP);
22883 end if;
22884 end if;
22885 end Propagate_Invariant_Attributes;
22887 ---------------------------------------
22888 -- Record_Possible_Part_Of_Reference --
22889 ---------------------------------------
22891 procedure Record_Possible_Part_Of_Reference
22892 (Var_Id : Entity_Id;
22893 Ref : Node_Id)
22895 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
22896 Refs : Elist_Id;
22898 begin
22899 -- The variable is a constituent of a single protected/task type. Such
22900 -- a variable acts as a component of the type and must appear within a
22901 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
22902 -- verify its legality now.
22904 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
22905 Check_Part_Of_Reference (Var_Id, Ref);
22907 -- The variable is subject to pragma Part_Of and may eventually become a
22908 -- constituent of a single protected/task type. Record the reference to
22909 -- verify its placement when the contract of the variable is analyzed.
22911 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
22912 Refs := Part_Of_References (Var_Id);
22914 if No (Refs) then
22915 Refs := New_Elmt_List;
22916 Set_Part_Of_References (Var_Id, Refs);
22917 end if;
22919 Append_Elmt (Ref, Refs);
22920 end if;
22921 end Record_Possible_Part_Of_Reference;
22923 ----------------
22924 -- Referenced --
22925 ----------------
22927 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
22928 Seen : Boolean := False;
22930 function Is_Reference (N : Node_Id) return Traverse_Result;
22931 -- Determine whether node N denotes a reference to Id. If this is the
22932 -- case, set global flag Seen to True and stop the traversal.
22934 ------------------
22935 -- Is_Reference --
22936 ------------------
22938 function Is_Reference (N : Node_Id) return Traverse_Result is
22939 begin
22940 if Is_Entity_Name (N)
22941 and then Present (Entity (N))
22942 and then Entity (N) = Id
22943 then
22944 Seen := True;
22945 return Abandon;
22946 else
22947 return OK;
22948 end if;
22949 end Is_Reference;
22951 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
22953 -- Start of processing for Referenced
22955 begin
22956 Inspect_Expression (Expr);
22957 return Seen;
22958 end Referenced;
22960 ------------------------------------
22961 -- References_Generic_Formal_Type --
22962 ------------------------------------
22964 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
22966 function Process (N : Node_Id) return Traverse_Result;
22967 -- Process one node in search for generic formal type
22969 -------------
22970 -- Process --
22971 -------------
22973 function Process (N : Node_Id) return Traverse_Result is
22974 begin
22975 if Nkind (N) in N_Has_Entity then
22976 declare
22977 E : constant Entity_Id := Entity (N);
22978 begin
22979 if Present (E) then
22980 if Is_Generic_Type (E) then
22981 return Abandon;
22982 elsif Present (Etype (E))
22983 and then Is_Generic_Type (Etype (E))
22984 then
22985 return Abandon;
22986 end if;
22987 end if;
22988 end;
22989 end if;
22991 return Atree.OK;
22992 end Process;
22994 function Traverse is new Traverse_Func (Process);
22995 -- Traverse tree to look for generic type
22997 begin
22998 if Inside_A_Generic then
22999 return Traverse (N) = Abandon;
23000 else
23001 return False;
23002 end if;
23003 end References_Generic_Formal_Type;
23005 -------------------------------
23006 -- Remove_Entity_And_Homonym --
23007 -------------------------------
23009 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
23010 begin
23011 Remove_Entity (Id);
23012 Remove_Homonym (Id);
23013 end Remove_Entity_And_Homonym;
23015 --------------------
23016 -- Remove_Homonym --
23017 --------------------
23019 procedure Remove_Homonym (Id : Entity_Id) is
23020 Hom : Entity_Id;
23021 Prev : Entity_Id := Empty;
23023 begin
23024 if Id = Current_Entity (Id) then
23025 if Present (Homonym (Id)) then
23026 Set_Current_Entity (Homonym (Id));
23027 else
23028 Set_Name_Entity_Id (Chars (Id), Empty);
23029 end if;
23031 else
23032 Hom := Current_Entity (Id);
23033 while Present (Hom) and then Hom /= Id loop
23034 Prev := Hom;
23035 Hom := Homonym (Hom);
23036 end loop;
23038 -- If Id is not on the homonym chain, nothing to do
23040 if Present (Hom) then
23041 Set_Homonym (Prev, Homonym (Id));
23042 end if;
23043 end if;
23044 end Remove_Homonym;
23046 ------------------------------
23047 -- Remove_Overloaded_Entity --
23048 ------------------------------
23050 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
23051 procedure Remove_Primitive_Of (Typ : Entity_Id);
23052 -- Remove primitive subprogram Id from the list of primitives that
23053 -- belong to type Typ.
23055 -------------------------
23056 -- Remove_Primitive_Of --
23057 -------------------------
23059 procedure Remove_Primitive_Of (Typ : Entity_Id) is
23060 Prims : Elist_Id;
23062 begin
23063 if Is_Tagged_Type (Typ) then
23064 Prims := Direct_Primitive_Operations (Typ);
23066 if Present (Prims) then
23067 Remove (Prims, Id);
23068 end if;
23069 end if;
23070 end Remove_Primitive_Of;
23072 -- Local variables
23074 Formal : Entity_Id;
23076 -- Start of processing for Remove_Overloaded_Entity
23078 begin
23079 Remove_Entity_And_Homonym (Id);
23081 -- The entity denotes a primitive subprogram. Remove it from the list of
23082 -- primitives of the associated controlling type.
23084 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
23085 Formal := First_Formal (Id);
23086 while Present (Formal) loop
23087 if Is_Controlling_Formal (Formal) then
23088 Remove_Primitive_Of (Etype (Formal));
23089 exit;
23090 end if;
23092 Next_Formal (Formal);
23093 end loop;
23095 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
23096 Remove_Primitive_Of (Etype (Id));
23097 end if;
23098 end if;
23099 end Remove_Overloaded_Entity;
23101 ---------------------
23102 -- Rep_To_Pos_Flag --
23103 ---------------------
23105 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
23106 begin
23107 return New_Occurrence_Of
23108 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
23109 end Rep_To_Pos_Flag;
23111 --------------------
23112 -- Require_Entity --
23113 --------------------
23115 procedure Require_Entity (N : Node_Id) is
23116 begin
23117 if Is_Entity_Name (N) and then No (Entity (N)) then
23118 if Total_Errors_Detected /= 0 then
23119 Set_Entity (N, Any_Id);
23120 else
23121 raise Program_Error;
23122 end if;
23123 end if;
23124 end Require_Entity;
23126 ------------------------------
23127 -- Requires_Transient_Scope --
23128 ------------------------------
23130 -- A transient scope is required when variable-sized temporaries are
23131 -- allocated on the secondary stack, or when finalization actions must be
23132 -- generated before the next instruction.
23134 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23135 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
23137 begin
23138 if Debug_Flag_QQ then
23139 return Old_Result;
23140 end if;
23142 declare
23143 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
23145 begin
23146 -- Assert that we're not putting things on the secondary stack if we
23147 -- didn't before; we are trying to AVOID secondary stack when
23148 -- possible.
23150 if not Old_Result then
23151 pragma Assert (not New_Result);
23152 null;
23153 end if;
23155 if New_Result /= Old_Result then
23156 Results_Differ (Id, Old_Result, New_Result);
23157 end if;
23159 return New_Result;
23160 end;
23161 end Requires_Transient_Scope;
23163 --------------------
23164 -- Results_Differ --
23165 --------------------
23167 procedure Results_Differ
23168 (Id : Entity_Id;
23169 Old_Val : Boolean;
23170 New_Val : Boolean)
23172 begin
23173 if False then -- False to disable; True for debugging
23174 Treepr.Print_Tree_Node (Id);
23176 if Old_Val = New_Val then
23177 raise Program_Error;
23178 end if;
23179 end if;
23180 end Results_Differ;
23182 --------------------------
23183 -- Reset_Analyzed_Flags --
23184 --------------------------
23186 procedure Reset_Analyzed_Flags (N : Node_Id) is
23187 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
23188 -- Function used to reset Analyzed flags in tree. Note that we do
23189 -- not reset Analyzed flags in entities, since there is no need to
23190 -- reanalyze entities, and indeed, it is wrong to do so, since it
23191 -- can result in generating auxiliary stuff more than once.
23193 --------------------
23194 -- Clear_Analyzed --
23195 --------------------
23197 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
23198 begin
23199 if Nkind (N) not in N_Entity then
23200 Set_Analyzed (N, False);
23201 end if;
23203 return OK;
23204 end Clear_Analyzed;
23206 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
23208 -- Start of processing for Reset_Analyzed_Flags
23210 begin
23211 Reset_Analyzed (N);
23212 end Reset_Analyzed_Flags;
23214 ------------------------
23215 -- Restore_SPARK_Mode --
23216 ------------------------
23218 procedure Restore_SPARK_Mode
23219 (Mode : SPARK_Mode_Type;
23220 Prag : Node_Id)
23222 begin
23223 SPARK_Mode := Mode;
23224 SPARK_Mode_Pragma := Prag;
23225 end Restore_SPARK_Mode;
23227 --------------------------------
23228 -- Returns_Unconstrained_Type --
23229 --------------------------------
23231 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
23232 begin
23233 return Ekind (Subp) = E_Function
23234 and then not Is_Scalar_Type (Etype (Subp))
23235 and then not Is_Access_Type (Etype (Subp))
23236 and then not Is_Constrained (Etype (Subp));
23237 end Returns_Unconstrained_Type;
23239 ----------------------------
23240 -- Root_Type_Of_Full_View --
23241 ----------------------------
23243 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
23244 Rtyp : constant Entity_Id := Root_Type (T);
23246 begin
23247 -- The root type of the full view may itself be a private type. Keep
23248 -- looking for the ultimate derivation parent.
23250 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
23251 return Root_Type_Of_Full_View (Full_View (Rtyp));
23252 else
23253 return Rtyp;
23254 end if;
23255 end Root_Type_Of_Full_View;
23257 ---------------------------
23258 -- Safe_To_Capture_Value --
23259 ---------------------------
23261 function Safe_To_Capture_Value
23262 (N : Node_Id;
23263 Ent : Entity_Id;
23264 Cond : Boolean := False) return Boolean
23266 begin
23267 -- The only entities for which we track constant values are variables
23268 -- which are not renamings, constants, out parameters, and in out
23269 -- parameters, so check if we have this case.
23271 -- Note: it may seem odd to track constant values for constants, but in
23272 -- fact this routine is used for other purposes than simply capturing
23273 -- the value. In particular, the setting of Known[_Non]_Null.
23275 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
23276 or else
23277 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
23278 then
23279 null;
23281 -- For conditionals, we also allow loop parameters and all formals,
23282 -- including in parameters.
23284 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
23285 null;
23287 -- For all other cases, not just unsafe, but impossible to capture
23288 -- Current_Value, since the above are the only entities which have
23289 -- Current_Value fields.
23291 else
23292 return False;
23293 end if;
23295 -- Skip if volatile or aliased, since funny things might be going on in
23296 -- these cases which we cannot necessarily track. Also skip any variable
23297 -- for which an address clause is given, or whose address is taken. Also
23298 -- never capture value of library level variables (an attempt to do so
23299 -- can occur in the case of package elaboration code).
23301 if Treat_As_Volatile (Ent)
23302 or else Is_Aliased (Ent)
23303 or else Present (Address_Clause (Ent))
23304 or else Address_Taken (Ent)
23305 or else (Is_Library_Level_Entity (Ent)
23306 and then Ekind (Ent) = E_Variable)
23307 then
23308 return False;
23309 end if;
23311 -- OK, all above conditions are met. We also require that the scope of
23312 -- the reference be the same as the scope of the entity, not counting
23313 -- packages and blocks and loops.
23315 declare
23316 E_Scope : constant Entity_Id := Scope (Ent);
23317 R_Scope : Entity_Id;
23319 begin
23320 R_Scope := Current_Scope;
23321 while R_Scope /= Standard_Standard loop
23322 exit when R_Scope = E_Scope;
23324 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
23325 return False;
23326 else
23327 R_Scope := Scope (R_Scope);
23328 end if;
23329 end loop;
23330 end;
23332 -- We also require that the reference does not appear in a context
23333 -- where it is not sure to be executed (i.e. a conditional context
23334 -- or an exception handler). We skip this if Cond is True, since the
23335 -- capturing of values from conditional tests handles this ok.
23337 if Cond then
23338 return True;
23339 end if;
23341 declare
23342 Desc : Node_Id;
23343 P : Node_Id;
23345 begin
23346 Desc := N;
23348 -- Seems dubious that case expressions are not handled here ???
23350 P := Parent (N);
23351 while Present (P) loop
23352 if Nkind (P) = N_If_Statement
23353 or else Nkind (P) = N_Case_Statement
23354 or else (Nkind (P) in N_Short_Circuit
23355 and then Desc = Right_Opnd (P))
23356 or else (Nkind (P) = N_If_Expression
23357 and then Desc /= First (Expressions (P)))
23358 or else Nkind (P) = N_Exception_Handler
23359 or else Nkind (P) = N_Selective_Accept
23360 or else Nkind (P) = N_Conditional_Entry_Call
23361 or else Nkind (P) = N_Timed_Entry_Call
23362 or else Nkind (P) = N_Asynchronous_Select
23363 then
23364 return False;
23366 else
23367 Desc := P;
23368 P := Parent (P);
23370 -- A special Ada 2012 case: the original node may be part
23371 -- of the else_actions of a conditional expression, in which
23372 -- case it might not have been expanded yet, and appears in
23373 -- a non-syntactic list of actions. In that case it is clearly
23374 -- not safe to save a value.
23376 if No (P)
23377 and then Is_List_Member (Desc)
23378 and then No (Parent (List_Containing (Desc)))
23379 then
23380 return False;
23381 end if;
23382 end if;
23383 end loop;
23384 end;
23386 -- OK, looks safe to set value
23388 return True;
23389 end Safe_To_Capture_Value;
23391 ---------------
23392 -- Same_Name --
23393 ---------------
23395 function Same_Name (N1, N2 : Node_Id) return Boolean is
23396 K1 : constant Node_Kind := Nkind (N1);
23397 K2 : constant Node_Kind := Nkind (N2);
23399 begin
23400 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
23401 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
23402 then
23403 return Chars (N1) = Chars (N2);
23405 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
23406 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
23407 then
23408 return Same_Name (Selector_Name (N1), Selector_Name (N2))
23409 and then Same_Name (Prefix (N1), Prefix (N2));
23411 else
23412 return False;
23413 end if;
23414 end Same_Name;
23416 -----------------
23417 -- Same_Object --
23418 -----------------
23420 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
23421 N1 : constant Node_Id := Original_Node (Node1);
23422 N2 : constant Node_Id := Original_Node (Node2);
23423 -- We do the tests on original nodes, since we are most interested
23424 -- in the original source, not any expansion that got in the way.
23426 K1 : constant Node_Kind := Nkind (N1);
23427 K2 : constant Node_Kind := Nkind (N2);
23429 begin
23430 -- First case, both are entities with same entity
23432 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
23433 declare
23434 EN1 : constant Entity_Id := Entity (N1);
23435 EN2 : constant Entity_Id := Entity (N2);
23436 begin
23437 if Present (EN1) and then Present (EN2)
23438 and then (Ekind_In (EN1, E_Variable, E_Constant)
23439 or else Is_Formal (EN1))
23440 and then EN1 = EN2
23441 then
23442 return True;
23443 end if;
23444 end;
23445 end if;
23447 -- Second case, selected component with same selector, same record
23449 if K1 = N_Selected_Component
23450 and then K2 = N_Selected_Component
23451 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
23452 then
23453 return Same_Object (Prefix (N1), Prefix (N2));
23455 -- Third case, indexed component with same subscripts, same array
23457 elsif K1 = N_Indexed_Component
23458 and then K2 = N_Indexed_Component
23459 and then Same_Object (Prefix (N1), Prefix (N2))
23460 then
23461 declare
23462 E1, E2 : Node_Id;
23463 begin
23464 E1 := First (Expressions (N1));
23465 E2 := First (Expressions (N2));
23466 while Present (E1) loop
23467 if not Same_Value (E1, E2) then
23468 return False;
23469 else
23470 Next (E1);
23471 Next (E2);
23472 end if;
23473 end loop;
23475 return True;
23476 end;
23478 -- Fourth case, slice of same array with same bounds
23480 elsif K1 = N_Slice
23481 and then K2 = N_Slice
23482 and then Nkind (Discrete_Range (N1)) = N_Range
23483 and then Nkind (Discrete_Range (N2)) = N_Range
23484 and then Same_Value (Low_Bound (Discrete_Range (N1)),
23485 Low_Bound (Discrete_Range (N2)))
23486 and then Same_Value (High_Bound (Discrete_Range (N1)),
23487 High_Bound (Discrete_Range (N2)))
23488 then
23489 return Same_Name (Prefix (N1), Prefix (N2));
23491 -- All other cases, not clearly the same object
23493 else
23494 return False;
23495 end if;
23496 end Same_Object;
23498 ---------------
23499 -- Same_Type --
23500 ---------------
23502 function Same_Type (T1, T2 : Entity_Id) return Boolean is
23503 begin
23504 if T1 = T2 then
23505 return True;
23507 elsif not Is_Constrained (T1)
23508 and then not Is_Constrained (T2)
23509 and then Base_Type (T1) = Base_Type (T2)
23510 then
23511 return True;
23513 -- For now don't bother with case of identical constraints, to be
23514 -- fiddled with later on perhaps (this is only used for optimization
23515 -- purposes, so it is not critical to do a best possible job)
23517 else
23518 return False;
23519 end if;
23520 end Same_Type;
23522 ----------------
23523 -- Same_Value --
23524 ----------------
23526 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
23527 begin
23528 if Compile_Time_Known_Value (Node1)
23529 and then Compile_Time_Known_Value (Node2)
23530 then
23531 -- Handle properly compile-time expressions that are not
23532 -- scalar.
23534 if Is_String_Type (Etype (Node1)) then
23535 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
23537 else
23538 return Expr_Value (Node1) = Expr_Value (Node2);
23539 end if;
23541 elsif Same_Object (Node1, Node2) then
23542 return True;
23543 else
23544 return False;
23545 end if;
23546 end Same_Value;
23548 --------------------
23549 -- Set_SPARK_Mode --
23550 --------------------
23552 procedure Set_SPARK_Mode (Context : Entity_Id) is
23553 begin
23554 -- Do not consider illegal or partially decorated constructs
23556 if Ekind (Context) = E_Void or else Error_Posted (Context) then
23557 null;
23559 elsif Present (SPARK_Pragma (Context)) then
23560 Install_SPARK_Mode
23561 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
23562 Prag => SPARK_Pragma (Context));
23563 end if;
23564 end Set_SPARK_Mode;
23566 -------------------------
23567 -- Scalar_Part_Present --
23568 -------------------------
23570 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
23571 Val_Typ : constant Entity_Id := Validated_View (Typ);
23572 Field : Entity_Id;
23574 begin
23575 if Is_Scalar_Type (Val_Typ) then
23576 return True;
23578 elsif Is_Array_Type (Val_Typ) then
23579 return Scalar_Part_Present (Component_Type (Val_Typ));
23581 elsif Is_Record_Type (Val_Typ) then
23582 Field := First_Component_Or_Discriminant (Val_Typ);
23583 while Present (Field) loop
23584 if Scalar_Part_Present (Etype (Field)) then
23585 return True;
23586 end if;
23588 Next_Component_Or_Discriminant (Field);
23589 end loop;
23590 end if;
23592 return False;
23593 end Scalar_Part_Present;
23595 ------------------------
23596 -- Scope_Is_Transient --
23597 ------------------------
23599 function Scope_Is_Transient return Boolean is
23600 begin
23601 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
23602 end Scope_Is_Transient;
23604 ------------------
23605 -- Scope_Within --
23606 ------------------
23608 function Scope_Within
23609 (Inner : Entity_Id;
23610 Outer : Entity_Id) return Boolean
23612 Curr : Entity_Id;
23614 begin
23615 Curr := Inner;
23616 while Present (Curr) and then Curr /= Standard_Standard loop
23617 Curr := Scope (Curr);
23619 if Curr = Outer then
23620 return True;
23621 end if;
23622 end loop;
23624 return False;
23625 end Scope_Within;
23627 --------------------------
23628 -- Scope_Within_Or_Same --
23629 --------------------------
23631 function Scope_Within_Or_Same
23632 (Inner : Entity_Id;
23633 Outer : Entity_Id) return Boolean
23635 Curr : Entity_Id;
23637 begin
23638 Curr := Inner;
23639 while Present (Curr) and then Curr /= Standard_Standard loop
23640 if Curr = Outer then
23641 return True;
23642 end if;
23644 Curr := Scope (Curr);
23645 end loop;
23647 return False;
23648 end Scope_Within_Or_Same;
23650 --------------------
23651 -- Set_Convention --
23652 --------------------
23654 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
23655 begin
23656 Basic_Set_Convention (E, Val);
23658 if Is_Type (E)
23659 and then Is_Access_Subprogram_Type (Base_Type (E))
23660 and then Has_Foreign_Convention (E)
23661 then
23662 Set_Can_Use_Internal_Rep (E, False);
23663 end if;
23665 -- If E is an object, including a component, and the type of E is an
23666 -- anonymous access type with no convention set, then also set the
23667 -- convention of the anonymous access type. We do not do this for
23668 -- anonymous protected types, since protected types always have the
23669 -- default convention.
23671 if Present (Etype (E))
23672 and then (Is_Object (E)
23674 -- Allow E_Void (happens for pragma Convention appearing
23675 -- in the middle of a record applying to a component)
23677 or else Ekind (E) = E_Void)
23678 then
23679 declare
23680 Typ : constant Entity_Id := Etype (E);
23682 begin
23683 if Ekind_In (Typ, E_Anonymous_Access_Type,
23684 E_Anonymous_Access_Subprogram_Type)
23685 and then not Has_Convention_Pragma (Typ)
23686 then
23687 Basic_Set_Convention (Typ, Val);
23688 Set_Has_Convention_Pragma (Typ);
23690 -- And for the access subprogram type, deal similarly with the
23691 -- designated E_Subprogram_Type, which is always internal.
23693 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
23694 declare
23695 Dtype : constant Entity_Id := Designated_Type (Typ);
23696 begin
23697 if Ekind (Dtype) = E_Subprogram_Type
23698 and then not Has_Convention_Pragma (Dtype)
23699 then
23700 Basic_Set_Convention (Dtype, Val);
23701 Set_Has_Convention_Pragma (Dtype);
23702 end if;
23703 end;
23704 end if;
23705 end if;
23706 end;
23707 end if;
23708 end Set_Convention;
23710 ------------------------
23711 -- Set_Current_Entity --
23712 ------------------------
23714 -- The given entity is to be set as the currently visible definition of its
23715 -- associated name (i.e. the Node_Id associated with its name). All we have
23716 -- to do is to get the name from the identifier, and then set the
23717 -- associated Node_Id to point to the given entity.
23719 procedure Set_Current_Entity (E : Entity_Id) is
23720 begin
23721 Set_Name_Entity_Id (Chars (E), E);
23722 end Set_Current_Entity;
23724 ---------------------------
23725 -- Set_Debug_Info_Needed --
23726 ---------------------------
23728 procedure Set_Debug_Info_Needed (T : Entity_Id) is
23730 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
23731 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
23732 -- Used to set debug info in a related node if not set already
23734 --------------------------------------
23735 -- Set_Debug_Info_Needed_If_Not_Set --
23736 --------------------------------------
23738 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
23739 begin
23740 if Present (E) and then not Needs_Debug_Info (E) then
23741 Set_Debug_Info_Needed (E);
23743 -- For a private type, indicate that the full view also needs
23744 -- debug information.
23746 if Is_Type (E)
23747 and then Is_Private_Type (E)
23748 and then Present (Full_View (E))
23749 then
23750 Set_Debug_Info_Needed (Full_View (E));
23751 end if;
23752 end if;
23753 end Set_Debug_Info_Needed_If_Not_Set;
23755 -- Start of processing for Set_Debug_Info_Needed
23757 begin
23758 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
23759 -- indicates that Debug_Info_Needed is never required for the entity.
23760 -- Nothing to do if entity comes from a predefined file. Library files
23761 -- are compiled without debug information, but inlined bodies of these
23762 -- routines may appear in user code, and debug information on them ends
23763 -- up complicating debugging the user code.
23765 if No (T)
23766 or else Debug_Info_Off (T)
23767 then
23768 return;
23770 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
23771 Set_Needs_Debug_Info (T, False);
23772 end if;
23774 -- Set flag in entity itself. Note that we will go through the following
23775 -- circuitry even if the flag is already set on T. That's intentional,
23776 -- it makes sure that the flag will be set in subsidiary entities.
23778 Set_Needs_Debug_Info (T);
23780 -- Set flag on subsidiary entities if not set already
23782 if Is_Object (T) then
23783 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
23785 elsif Is_Type (T) then
23786 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
23788 if Is_Record_Type (T) then
23789 declare
23790 Ent : Entity_Id := First_Entity (T);
23791 begin
23792 while Present (Ent) loop
23793 Set_Debug_Info_Needed_If_Not_Set (Ent);
23794 Next_Entity (Ent);
23795 end loop;
23796 end;
23798 -- For a class wide subtype, we also need debug information
23799 -- for the equivalent type.
23801 if Ekind (T) = E_Class_Wide_Subtype then
23802 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
23803 end if;
23805 elsif Is_Array_Type (T) then
23806 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
23808 declare
23809 Indx : Node_Id := First_Index (T);
23810 begin
23811 while Present (Indx) loop
23812 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
23813 Indx := Next_Index (Indx);
23814 end loop;
23815 end;
23817 -- For a packed array type, we also need debug information for
23818 -- the type used to represent the packed array. Conversely, we
23819 -- also need it for the former if we need it for the latter.
23821 if Is_Packed (T) then
23822 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
23823 end if;
23825 if Is_Packed_Array_Impl_Type (T) then
23826 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
23827 end if;
23829 elsif Is_Access_Type (T) then
23830 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
23832 elsif Is_Private_Type (T) then
23833 declare
23834 FV : constant Entity_Id := Full_View (T);
23836 begin
23837 Set_Debug_Info_Needed_If_Not_Set (FV);
23839 -- If the full view is itself a derived private type, we need
23840 -- debug information on its underlying type.
23842 if Present (FV)
23843 and then Is_Private_Type (FV)
23844 and then Present (Underlying_Full_View (FV))
23845 then
23846 Set_Needs_Debug_Info (Underlying_Full_View (FV));
23847 end if;
23848 end;
23850 elsif Is_Protected_Type (T) then
23851 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
23853 elsif Is_Scalar_Type (T) then
23855 -- If the subrange bounds are materialized by dedicated constant
23856 -- objects, also include them in the debug info to make sure the
23857 -- debugger can properly use them.
23859 if Present (Scalar_Range (T))
23860 and then Nkind (Scalar_Range (T)) = N_Range
23861 then
23862 declare
23863 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
23864 High_Bnd : constant Node_Id := Type_High_Bound (T);
23866 begin
23867 if Is_Entity_Name (Low_Bnd) then
23868 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
23869 end if;
23871 if Is_Entity_Name (High_Bnd) then
23872 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
23873 end if;
23874 end;
23875 end if;
23876 end if;
23877 end if;
23878 end Set_Debug_Info_Needed;
23880 ----------------------------
23881 -- Set_Entity_With_Checks --
23882 ----------------------------
23884 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
23885 Val_Actual : Entity_Id;
23886 Nod : Node_Id;
23887 Post_Node : Node_Id;
23889 begin
23890 -- Unconditionally set the entity
23892 Set_Entity (N, Val);
23894 -- The node to post on is the selector in the case of an expanded name,
23895 -- and otherwise the node itself.
23897 if Nkind (N) = N_Expanded_Name then
23898 Post_Node := Selector_Name (N);
23899 else
23900 Post_Node := N;
23901 end if;
23903 -- Check for violation of No_Fixed_IO
23905 if Restriction_Check_Required (No_Fixed_IO)
23906 and then
23907 ((RTU_Loaded (Ada_Text_IO)
23908 and then (Is_RTE (Val, RE_Decimal_IO)
23909 or else
23910 Is_RTE (Val, RE_Fixed_IO)))
23912 or else
23913 (RTU_Loaded (Ada_Wide_Text_IO)
23914 and then (Is_RTE (Val, RO_WT_Decimal_IO)
23915 or else
23916 Is_RTE (Val, RO_WT_Fixed_IO)))
23918 or else
23919 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
23920 and then (Is_RTE (Val, RO_WW_Decimal_IO)
23921 or else
23922 Is_RTE (Val, RO_WW_Fixed_IO))))
23924 -- A special extra check, don't complain about a reference from within
23925 -- the Ada.Interrupts package itself!
23927 and then not In_Same_Extended_Unit (N, Val)
23928 then
23929 Check_Restriction (No_Fixed_IO, Post_Node);
23930 end if;
23932 -- Remaining checks are only done on source nodes. Note that we test
23933 -- for violation of No_Fixed_IO even on non-source nodes, because the
23934 -- cases for checking violations of this restriction are instantiations
23935 -- where the reference in the instance has Comes_From_Source False.
23937 if not Comes_From_Source (N) then
23938 return;
23939 end if;
23941 -- Check for violation of No_Abort_Statements, which is triggered by
23942 -- call to Ada.Task_Identification.Abort_Task.
23944 if Restriction_Check_Required (No_Abort_Statements)
23945 and then (Is_RTE (Val, RE_Abort_Task))
23947 -- A special extra check, don't complain about a reference from within
23948 -- the Ada.Task_Identification package itself!
23950 and then not In_Same_Extended_Unit (N, Val)
23951 then
23952 Check_Restriction (No_Abort_Statements, Post_Node);
23953 end if;
23955 if Val = Standard_Long_Long_Integer then
23956 Check_Restriction (No_Long_Long_Integers, Post_Node);
23957 end if;
23959 -- Check for violation of No_Dynamic_Attachment
23961 if Restriction_Check_Required (No_Dynamic_Attachment)
23962 and then RTU_Loaded (Ada_Interrupts)
23963 and then (Is_RTE (Val, RE_Is_Reserved) or else
23964 Is_RTE (Val, RE_Is_Attached) or else
23965 Is_RTE (Val, RE_Current_Handler) or else
23966 Is_RTE (Val, RE_Attach_Handler) or else
23967 Is_RTE (Val, RE_Exchange_Handler) or else
23968 Is_RTE (Val, RE_Detach_Handler) or else
23969 Is_RTE (Val, RE_Reference))
23971 -- A special extra check, don't complain about a reference from within
23972 -- the Ada.Interrupts package itself!
23974 and then not In_Same_Extended_Unit (N, Val)
23975 then
23976 Check_Restriction (No_Dynamic_Attachment, Post_Node);
23977 end if;
23979 -- Check for No_Implementation_Identifiers
23981 if Restriction_Check_Required (No_Implementation_Identifiers) then
23983 -- We have an implementation defined entity if it is marked as
23984 -- implementation defined, or is defined in a package marked as
23985 -- implementation defined. However, library packages themselves
23986 -- are excluded (we don't want to flag Interfaces itself, just
23987 -- the entities within it).
23989 if (Is_Implementation_Defined (Val)
23990 or else
23991 (Present (Scope (Val))
23992 and then Is_Implementation_Defined (Scope (Val))))
23993 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
23994 and then Is_Library_Level_Entity (Val))
23995 then
23996 Check_Restriction (No_Implementation_Identifiers, Post_Node);
23997 end if;
23998 end if;
24000 -- Do the style check
24002 if Style_Check
24003 and then not Suppress_Style_Checks (Val)
24004 and then not In_Instance
24005 then
24006 if Nkind (N) = N_Identifier then
24007 Nod := N;
24008 elsif Nkind (N) = N_Expanded_Name then
24009 Nod := Selector_Name (N);
24010 else
24011 return;
24012 end if;
24014 -- A special situation arises for derived operations, where we want
24015 -- to do the check against the parent (since the Sloc of the derived
24016 -- operation points to the derived type declaration itself).
24018 Val_Actual := Val;
24019 while not Comes_From_Source (Val_Actual)
24020 and then Nkind (Val_Actual) in N_Entity
24021 and then (Ekind (Val_Actual) = E_Enumeration_Literal
24022 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
24023 and then Present (Alias (Val_Actual))
24024 loop
24025 Val_Actual := Alias (Val_Actual);
24026 end loop;
24028 -- Renaming declarations for generic actuals do not come from source,
24029 -- and have a different name from that of the entity they rename, so
24030 -- there is no style check to perform here.
24032 if Chars (Nod) = Chars (Val_Actual) then
24033 Style.Check_Identifier (Nod, Val_Actual);
24034 end if;
24035 end if;
24037 Set_Entity (N, Val);
24038 end Set_Entity_With_Checks;
24040 ------------------------------
24041 -- Set_Invalid_Scalar_Value --
24042 ------------------------------
24044 procedure Set_Invalid_Scalar_Value
24045 (Scal_Typ : Float_Scalar_Id;
24046 Value : Ureal)
24048 Slot : Ureal renames Invalid_Floats (Scal_Typ);
24050 begin
24051 -- Detect an attempt to set a different value for the same scalar type
24053 pragma Assert (Slot = No_Ureal);
24054 Slot := Value;
24055 end Set_Invalid_Scalar_Value;
24057 ------------------------------
24058 -- Set_Invalid_Scalar_Value --
24059 ------------------------------
24061 procedure Set_Invalid_Scalar_Value
24062 (Scal_Typ : Integer_Scalar_Id;
24063 Value : Uint)
24065 Slot : Uint renames Invalid_Integers (Scal_Typ);
24067 begin
24068 -- Detect an attempt to set a different value for the same scalar type
24070 pragma Assert (Slot = No_Uint);
24071 Slot := Value;
24072 end Set_Invalid_Scalar_Value;
24074 ------------------------
24075 -- Set_Name_Entity_Id --
24076 ------------------------
24078 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
24079 begin
24080 Set_Name_Table_Int (Id, Int (Val));
24081 end Set_Name_Entity_Id;
24083 ---------------------
24084 -- Set_Next_Actual --
24085 ---------------------
24087 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
24088 begin
24089 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
24090 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
24091 end if;
24092 end Set_Next_Actual;
24094 ----------------------------------
24095 -- Set_Optimize_Alignment_Flags --
24096 ----------------------------------
24098 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
24099 begin
24100 if Optimize_Alignment = 'S' then
24101 Set_Optimize_Alignment_Space (E);
24102 elsif Optimize_Alignment = 'T' then
24103 Set_Optimize_Alignment_Time (E);
24104 end if;
24105 end Set_Optimize_Alignment_Flags;
24107 -----------------------
24108 -- Set_Public_Status --
24109 -----------------------
24111 procedure Set_Public_Status (Id : Entity_Id) is
24112 S : constant Entity_Id := Current_Scope;
24114 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
24115 -- Determines if E is defined within handled statement sequence or
24116 -- an if statement, returns True if so, False otherwise.
24118 ----------------------
24119 -- Within_HSS_Or_If --
24120 ----------------------
24122 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
24123 N : Node_Id;
24124 begin
24125 N := Declaration_Node (E);
24126 loop
24127 N := Parent (N);
24129 if No (N) then
24130 return False;
24132 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
24133 N_If_Statement)
24134 then
24135 return True;
24136 end if;
24137 end loop;
24138 end Within_HSS_Or_If;
24140 -- Start of processing for Set_Public_Status
24142 begin
24143 -- Everything in the scope of Standard is public
24145 if S = Standard_Standard then
24146 Set_Is_Public (Id);
24148 -- Entity is definitely not public if enclosing scope is not public
24150 elsif not Is_Public (S) then
24151 return;
24153 -- An object or function declaration that occurs in a handled sequence
24154 -- of statements or within an if statement is the declaration for a
24155 -- temporary object or local subprogram generated by the expander. It
24156 -- never needs to be made public and furthermore, making it public can
24157 -- cause back end problems.
24159 elsif Nkind_In (Parent (Id), N_Object_Declaration,
24160 N_Function_Specification)
24161 and then Within_HSS_Or_If (Id)
24162 then
24163 return;
24165 -- Entities in public packages or records are public
24167 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
24168 Set_Is_Public (Id);
24170 -- The bounds of an entry family declaration can generate object
24171 -- declarations that are visible to the back-end, e.g. in the
24172 -- the declaration of a composite type that contains tasks.
24174 elsif Is_Concurrent_Type (S)
24175 and then not Has_Completion (S)
24176 and then Nkind (Parent (Id)) = N_Object_Declaration
24177 then
24178 Set_Is_Public (Id);
24179 end if;
24180 end Set_Public_Status;
24182 -----------------------------
24183 -- Set_Referenced_Modified --
24184 -----------------------------
24186 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
24187 Pref : Node_Id;
24189 begin
24190 -- Deal with indexed or selected component where prefix is modified
24192 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
24193 Pref := Prefix (N);
24195 -- If prefix is access type, then it is the designated object that is
24196 -- being modified, which means we have no entity to set the flag on.
24198 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
24199 return;
24201 -- Otherwise chase the prefix
24203 else
24204 Set_Referenced_Modified (Pref, Out_Param);
24205 end if;
24207 -- Otherwise see if we have an entity name (only other case to process)
24209 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
24210 Set_Referenced_As_LHS (Entity (N), not Out_Param);
24211 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
24212 end if;
24213 end Set_Referenced_Modified;
24215 ------------------
24216 -- Set_Rep_Info --
24217 ------------------
24219 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
24220 begin
24221 Set_Is_Atomic (T1, Is_Atomic (T2));
24222 Set_Is_Independent (T1, Is_Independent (T2));
24223 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
24225 if Is_Base_Type (T1) then
24226 Set_Is_Volatile (T1, Is_Volatile (T2));
24227 end if;
24228 end Set_Rep_Info;
24230 ----------------------------
24231 -- Set_Scope_Is_Transient --
24232 ----------------------------
24234 procedure Set_Scope_Is_Transient (V : Boolean := True) is
24235 begin
24236 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
24237 end Set_Scope_Is_Transient;
24239 -------------------
24240 -- Set_Size_Info --
24241 -------------------
24243 procedure Set_Size_Info (T1, T2 : Entity_Id) is
24244 begin
24245 -- We copy Esize, but not RM_Size, since in general RM_Size is
24246 -- subtype specific and does not get inherited by all subtypes.
24248 Set_Esize (T1, Esize (T2));
24249 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
24251 if Is_Discrete_Or_Fixed_Point_Type (T1)
24252 and then
24253 Is_Discrete_Or_Fixed_Point_Type (T2)
24254 then
24255 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
24256 end if;
24258 Set_Alignment (T1, Alignment (T2));
24259 end Set_Size_Info;
24261 ------------------------------
24262 -- Should_Ignore_Pragma_Par --
24263 ------------------------------
24265 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
24266 pragma Assert (Compiler_State = Parsing);
24267 -- This one can't work during semantic analysis, because we don't have a
24268 -- correct Current_Source_File.
24270 Result : constant Boolean :=
24271 Get_Name_Table_Boolean3 (Prag_Name)
24272 and then not Is_Internal_File_Name
24273 (File_Name (Current_Source_File));
24274 begin
24275 return Result;
24276 end Should_Ignore_Pragma_Par;
24278 ------------------------------
24279 -- Should_Ignore_Pragma_Sem --
24280 ------------------------------
24282 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
24283 pragma Assert (Compiler_State = Analyzing);
24284 Prag_Name : constant Name_Id := Pragma_Name (N);
24285 Result : constant Boolean :=
24286 Get_Name_Table_Boolean3 (Prag_Name)
24287 and then not In_Internal_Unit (N);
24289 begin
24290 return Result;
24291 end Should_Ignore_Pragma_Sem;
24293 --------------------
24294 -- Static_Boolean --
24295 --------------------
24297 function Static_Boolean (N : Node_Id) return Uint is
24298 begin
24299 Analyze_And_Resolve (N, Standard_Boolean);
24301 if N = Error
24302 or else Error_Posted (N)
24303 or else Etype (N) = Any_Type
24304 then
24305 return No_Uint;
24306 end if;
24308 if Is_OK_Static_Expression (N) then
24309 if not Raises_Constraint_Error (N) then
24310 return Expr_Value (N);
24311 else
24312 return No_Uint;
24313 end if;
24315 elsif Etype (N) = Any_Type then
24316 return No_Uint;
24318 else
24319 Flag_Non_Static_Expr
24320 ("static boolean expression required here", N);
24321 return No_Uint;
24322 end if;
24323 end Static_Boolean;
24325 --------------------
24326 -- Static_Integer --
24327 --------------------
24329 function Static_Integer (N : Node_Id) return Uint is
24330 begin
24331 Analyze_And_Resolve (N, Any_Integer);
24333 if N = Error
24334 or else Error_Posted (N)
24335 or else Etype (N) = Any_Type
24336 then
24337 return No_Uint;
24338 end if;
24340 if Is_OK_Static_Expression (N) then
24341 if not Raises_Constraint_Error (N) then
24342 return Expr_Value (N);
24343 else
24344 return No_Uint;
24345 end if;
24347 elsif Etype (N) = Any_Type then
24348 return No_Uint;
24350 else
24351 Flag_Non_Static_Expr
24352 ("static integer expression required here", N);
24353 return No_Uint;
24354 end if;
24355 end Static_Integer;
24357 --------------------------
24358 -- Statically_Different --
24359 --------------------------
24361 function Statically_Different (E1, E2 : Node_Id) return Boolean is
24362 R1 : constant Node_Id := Get_Referenced_Object (E1);
24363 R2 : constant Node_Id := Get_Referenced_Object (E2);
24364 begin
24365 return Is_Entity_Name (R1)
24366 and then Is_Entity_Name (R2)
24367 and then Entity (R1) /= Entity (R2)
24368 and then not Is_Formal (Entity (R1))
24369 and then not Is_Formal (Entity (R2));
24370 end Statically_Different;
24372 --------------------------------------
24373 -- Subject_To_Loop_Entry_Attributes --
24374 --------------------------------------
24376 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
24377 Stmt : Node_Id;
24379 begin
24380 Stmt := N;
24382 -- The expansion mechanism transform a loop subject to at least one
24383 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
24384 -- the conditional part.
24386 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
24387 and then Nkind (Original_Node (N)) = N_Loop_Statement
24388 then
24389 Stmt := Original_Node (N);
24390 end if;
24392 return
24393 Nkind (Stmt) = N_Loop_Statement
24394 and then Present (Identifier (Stmt))
24395 and then Present (Entity (Identifier (Stmt)))
24396 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
24397 end Subject_To_Loop_Entry_Attributes;
24399 -----------------------------
24400 -- Subprogram_Access_Level --
24401 -----------------------------
24403 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
24404 begin
24405 if Present (Alias (Subp)) then
24406 return Subprogram_Access_Level (Alias (Subp));
24407 else
24408 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
24409 end if;
24410 end Subprogram_Access_Level;
24412 ---------------------
24413 -- Subprogram_Name --
24414 ---------------------
24416 function Subprogram_Name (N : Node_Id) return String is
24417 Buf : Bounded_String;
24418 Ent : Node_Id := N;
24419 Nod : Node_Id;
24421 begin
24422 while Present (Ent) loop
24423 case Nkind (Ent) is
24424 when N_Subprogram_Body =>
24425 Ent := Defining_Unit_Name (Specification (Ent));
24426 exit;
24428 when N_Subprogram_Declaration =>
24429 Nod := Corresponding_Body (Ent);
24431 if Present (Nod) then
24432 Ent := Nod;
24433 else
24434 Ent := Defining_Unit_Name (Specification (Ent));
24435 end if;
24437 exit;
24439 when N_Subprogram_Instantiation
24440 | N_Package_Body
24441 | N_Package_Specification
24443 Ent := Defining_Unit_Name (Ent);
24444 exit;
24446 when N_Protected_Type_Declaration =>
24447 Ent := Corresponding_Body (Ent);
24448 exit;
24450 when N_Protected_Body
24451 | N_Task_Body
24453 Ent := Defining_Identifier (Ent);
24454 exit;
24456 when others =>
24457 null;
24458 end case;
24460 Ent := Parent (Ent);
24461 end loop;
24463 if No (Ent) then
24464 return "unknown subprogram:unknown file:0:0";
24465 end if;
24467 -- If the subprogram is a child unit, use its simple name to start the
24468 -- construction of the fully qualified name.
24470 if Nkind (Ent) = N_Defining_Program_Unit_Name then
24471 Ent := Defining_Identifier (Ent);
24472 end if;
24474 Append_Entity_Name (Buf, Ent);
24476 -- Append homonym number if needed
24478 if Nkind (N) in N_Entity and then Has_Homonym (N) then
24479 declare
24480 H : Entity_Id := Homonym (N);
24481 Nr : Nat := 1;
24483 begin
24484 while Present (H) loop
24485 if Scope (H) = Scope (N) then
24486 Nr := Nr + 1;
24487 end if;
24489 H := Homonym (H);
24490 end loop;
24492 if Nr > 1 then
24493 Append (Buf, '#');
24494 Append (Buf, Nr);
24495 end if;
24496 end;
24497 end if;
24499 -- Append source location of Ent to Buf so that the string will
24500 -- look like "subp:file:line:col".
24502 declare
24503 Loc : constant Source_Ptr := Sloc (Ent);
24504 begin
24505 Append (Buf, ':');
24506 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
24507 Append (Buf, ':');
24508 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
24509 Append (Buf, ':');
24510 Append (Buf, Nat (Get_Column_Number (Loc)));
24511 end;
24513 return +Buf;
24514 end Subprogram_Name;
24516 -------------------------------
24517 -- Support_Atomic_Primitives --
24518 -------------------------------
24520 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
24521 Size : Int;
24523 begin
24524 -- Verify the alignment of Typ is known
24526 if not Known_Alignment (Typ) then
24527 return False;
24528 end if;
24530 if Known_Static_Esize (Typ) then
24531 Size := UI_To_Int (Esize (Typ));
24533 -- If the Esize (Object_Size) is unknown at compile time, look at the
24534 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
24536 elsif Known_Static_RM_Size (Typ) then
24537 Size := UI_To_Int (RM_Size (Typ));
24539 -- Otherwise, the size is considered to be unknown.
24541 else
24542 return False;
24543 end if;
24545 -- Check that the size of the component is 8, 16, 32, or 64 bits and
24546 -- that Typ is properly aligned.
24548 case Size is
24549 when 8 | 16 | 32 | 64 =>
24550 return Size = UI_To_Int (Alignment (Typ)) * 8;
24552 when others =>
24553 return False;
24554 end case;
24555 end Support_Atomic_Primitives;
24557 -----------------
24558 -- Trace_Scope --
24559 -----------------
24561 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
24562 begin
24563 if Debug_Flag_W then
24564 for J in 0 .. Scope_Stack.Last loop
24565 Write_Str (" ");
24566 end loop;
24568 Write_Str (Msg);
24569 Write_Name (Chars (E));
24570 Write_Str (" from ");
24571 Write_Location (Sloc (N));
24572 Write_Eol;
24573 end if;
24574 end Trace_Scope;
24576 -----------------------
24577 -- Transfer_Entities --
24578 -----------------------
24580 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
24581 procedure Set_Public_Status_Of (Id : Entity_Id);
24582 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
24583 -- Set_Public_Status. If successful and Id denotes a record type, set
24584 -- the Is_Public attribute of its fields.
24586 --------------------------
24587 -- Set_Public_Status_Of --
24588 --------------------------
24590 procedure Set_Public_Status_Of (Id : Entity_Id) is
24591 Field : Entity_Id;
24593 begin
24594 if not Is_Public (Id) then
24595 Set_Public_Status (Id);
24597 -- When the input entity is a public record type, ensure that all
24598 -- its internal fields are also exposed to the linker. The fields
24599 -- of a class-wide type are never made public.
24601 if Is_Public (Id)
24602 and then Is_Record_Type (Id)
24603 and then not Is_Class_Wide_Type (Id)
24604 then
24605 Field := First_Entity (Id);
24606 while Present (Field) loop
24607 Set_Is_Public (Field);
24608 Next_Entity (Field);
24609 end loop;
24610 end if;
24611 end if;
24612 end Set_Public_Status_Of;
24614 -- Local variables
24616 Full_Id : Entity_Id;
24617 Id : Entity_Id;
24619 -- Start of processing for Transfer_Entities
24621 begin
24622 Id := First_Entity (From);
24624 if Present (Id) then
24626 -- Merge the entity chain of the source scope with that of the
24627 -- destination scope.
24629 if Present (Last_Entity (To)) then
24630 Link_Entities (Last_Entity (To), Id);
24631 else
24632 Set_First_Entity (To, Id);
24633 end if;
24635 Set_Last_Entity (To, Last_Entity (From));
24637 -- Inspect the entities of the source scope and update their Scope
24638 -- attribute.
24640 while Present (Id) loop
24641 Set_Scope (Id, To);
24642 Set_Public_Status_Of (Id);
24644 -- Handle an internally generated full view for a private type
24646 if Is_Private_Type (Id)
24647 and then Present (Full_View (Id))
24648 and then Is_Itype (Full_View (Id))
24649 then
24650 Full_Id := Full_View (Id);
24652 Set_Scope (Full_Id, To);
24653 Set_Public_Status_Of (Full_Id);
24654 end if;
24656 Next_Entity (Id);
24657 end loop;
24659 Set_First_Entity (From, Empty);
24660 Set_Last_Entity (From, Empty);
24661 end if;
24662 end Transfer_Entities;
24664 -----------------------
24665 -- Type_Access_Level --
24666 -----------------------
24668 function Type_Access_Level (Typ : Entity_Id) return Uint is
24669 Btyp : Entity_Id;
24671 begin
24672 Btyp := Base_Type (Typ);
24674 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
24675 -- simply use the level where the type is declared. This is true for
24676 -- stand-alone object declarations, and for anonymous access types
24677 -- associated with components the level is the same as that of the
24678 -- enclosing composite type. However, special treatment is needed for
24679 -- the cases of access parameters, return objects of an anonymous access
24680 -- type, and, in Ada 95, access discriminants of limited types.
24682 if Is_Access_Type (Btyp) then
24683 if Ekind (Btyp) = E_Anonymous_Access_Type then
24685 -- If the type is a nonlocal anonymous access type (such as for
24686 -- an access parameter) we treat it as being declared at the
24687 -- library level to ensure that names such as X.all'access don't
24688 -- fail static accessibility checks.
24690 if not Is_Local_Anonymous_Access (Typ) then
24691 return Scope_Depth (Standard_Standard);
24693 -- If this is a return object, the accessibility level is that of
24694 -- the result subtype of the enclosing function. The test here is
24695 -- little complicated, because we have to account for extended
24696 -- return statements that have been rewritten as blocks, in which
24697 -- case we have to find and the Is_Return_Object attribute of the
24698 -- itype's associated object. It would be nice to find a way to
24699 -- simplify this test, but it doesn't seem worthwhile to add a new
24700 -- flag just for purposes of this test. ???
24702 elsif Ekind (Scope (Btyp)) = E_Return_Statement
24703 or else
24704 (Is_Itype (Btyp)
24705 and then Nkind (Associated_Node_For_Itype (Btyp)) =
24706 N_Object_Declaration
24707 and then Is_Return_Object
24708 (Defining_Identifier
24709 (Associated_Node_For_Itype (Btyp))))
24710 then
24711 declare
24712 Scop : Entity_Id;
24714 begin
24715 Scop := Scope (Scope (Btyp));
24716 while Present (Scop) loop
24717 exit when Ekind (Scop) = E_Function;
24718 Scop := Scope (Scop);
24719 end loop;
24721 -- Treat the return object's type as having the level of the
24722 -- function's result subtype (as per RM05-6.5(5.3/2)).
24724 return Type_Access_Level (Etype (Scop));
24725 end;
24726 end if;
24727 end if;
24729 Btyp := Root_Type (Btyp);
24731 -- The accessibility level of anonymous access types associated with
24732 -- discriminants is that of the current instance of the type, and
24733 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
24735 -- AI-402: access discriminants have accessibility based on the
24736 -- object rather than the type in Ada 2005, so the above paragraph
24737 -- doesn't apply.
24739 -- ??? Needs completion with rules from AI-416
24741 if Ada_Version <= Ada_95
24742 and then Ekind (Typ) = E_Anonymous_Access_Type
24743 and then Present (Associated_Node_For_Itype (Typ))
24744 and then Nkind (Associated_Node_For_Itype (Typ)) =
24745 N_Discriminant_Specification
24746 then
24747 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
24748 end if;
24749 end if;
24751 -- Return library level for a generic formal type. This is done because
24752 -- RM(10.3.2) says that "The statically deeper relationship does not
24753 -- apply to ... a descendant of a generic formal type". Rather than
24754 -- checking at each point where a static accessibility check is
24755 -- performed to see if we are dealing with a formal type, this rule is
24756 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
24757 -- return extreme values for a formal type; Deepest_Type_Access_Level
24758 -- returns Int'Last. By calling the appropriate function from among the
24759 -- two, we ensure that the static accessibility check will pass if we
24760 -- happen to run into a formal type. More specifically, we should call
24761 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
24762 -- call occurs as part of a static accessibility check and the error
24763 -- case is the case where the type's level is too shallow (as opposed
24764 -- to too deep).
24766 if Is_Generic_Type (Root_Type (Btyp)) then
24767 return Scope_Depth (Standard_Standard);
24768 end if;
24770 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
24771 end Type_Access_Level;
24773 ------------------------------------
24774 -- Type_Without_Stream_Operation --
24775 ------------------------------------
24777 function Type_Without_Stream_Operation
24778 (T : Entity_Id;
24779 Op : TSS_Name_Type := TSS_Null) return Entity_Id
24781 BT : constant Entity_Id := Base_Type (T);
24782 Op_Missing : Boolean;
24784 begin
24785 if not Restriction_Active (No_Default_Stream_Attributes) then
24786 return Empty;
24787 end if;
24789 if Is_Elementary_Type (T) then
24790 if Op = TSS_Null then
24791 Op_Missing :=
24792 No (TSS (BT, TSS_Stream_Read))
24793 or else No (TSS (BT, TSS_Stream_Write));
24795 else
24796 Op_Missing := No (TSS (BT, Op));
24797 end if;
24799 if Op_Missing then
24800 return T;
24801 else
24802 return Empty;
24803 end if;
24805 elsif Is_Array_Type (T) then
24806 return Type_Without_Stream_Operation (Component_Type (T), Op);
24808 elsif Is_Record_Type (T) then
24809 declare
24810 Comp : Entity_Id;
24811 C_Typ : Entity_Id;
24813 begin
24814 Comp := First_Component (T);
24815 while Present (Comp) loop
24816 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
24818 if Present (C_Typ) then
24819 return C_Typ;
24820 end if;
24822 Next_Component (Comp);
24823 end loop;
24825 return Empty;
24826 end;
24828 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
24829 return Type_Without_Stream_Operation (Full_View (T), Op);
24830 else
24831 return Empty;
24832 end if;
24833 end Type_Without_Stream_Operation;
24835 ----------------------------
24836 -- Unique_Defining_Entity --
24837 ----------------------------
24839 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
24840 begin
24841 return Unique_Entity (Defining_Entity (N));
24842 end Unique_Defining_Entity;
24844 -------------------
24845 -- Unique_Entity --
24846 -------------------
24848 function Unique_Entity (E : Entity_Id) return Entity_Id is
24849 U : Entity_Id := E;
24850 P : Node_Id;
24852 begin
24853 case Ekind (E) is
24854 when E_Constant =>
24855 if Present (Full_View (E)) then
24856 U := Full_View (E);
24857 end if;
24859 when Entry_Kind =>
24860 if Nkind (Parent (E)) = N_Entry_Body then
24861 declare
24862 Prot_Item : Entity_Id;
24863 Prot_Type : Entity_Id;
24865 begin
24866 if Ekind (E) = E_Entry then
24867 Prot_Type := Scope (E);
24869 -- Bodies of entry families are nested within an extra scope
24870 -- that contains an entry index declaration.
24872 else
24873 Prot_Type := Scope (Scope (E));
24874 end if;
24876 -- A protected type may be declared as a private type, in
24877 -- which case we need to get its full view.
24879 if Is_Private_Type (Prot_Type) then
24880 Prot_Type := Full_View (Prot_Type);
24881 end if;
24883 -- Full view may not be present on error, in which case
24884 -- return E by default.
24886 if Present (Prot_Type) then
24887 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
24889 -- Traverse the entity list of the protected type and
24890 -- locate an entry declaration which matches the entry
24891 -- body.
24893 Prot_Item := First_Entity (Prot_Type);
24894 while Present (Prot_Item) loop
24895 if Ekind (Prot_Item) in Entry_Kind
24896 and then Corresponding_Body (Parent (Prot_Item)) = E
24897 then
24898 U := Prot_Item;
24899 exit;
24900 end if;
24902 Next_Entity (Prot_Item);
24903 end loop;
24904 end if;
24905 end;
24906 end if;
24908 when Formal_Kind =>
24909 if Present (Spec_Entity (E)) then
24910 U := Spec_Entity (E);
24911 end if;
24913 when E_Package_Body =>
24914 P := Parent (E);
24916 if Nkind (P) = N_Defining_Program_Unit_Name then
24917 P := Parent (P);
24918 end if;
24920 if Nkind (P) = N_Package_Body
24921 and then Present (Corresponding_Spec (P))
24922 then
24923 U := Corresponding_Spec (P);
24925 elsif Nkind (P) = N_Package_Body_Stub
24926 and then Present (Corresponding_Spec_Of_Stub (P))
24927 then
24928 U := Corresponding_Spec_Of_Stub (P);
24929 end if;
24931 when E_Protected_Body =>
24932 P := Parent (E);
24934 if Nkind (P) = N_Protected_Body
24935 and then Present (Corresponding_Spec (P))
24936 then
24937 U := Corresponding_Spec (P);
24939 elsif Nkind (P) = N_Protected_Body_Stub
24940 and then Present (Corresponding_Spec_Of_Stub (P))
24941 then
24942 U := Corresponding_Spec_Of_Stub (P);
24944 if Is_Single_Protected_Object (U) then
24945 U := Etype (U);
24946 end if;
24947 end if;
24949 if Is_Private_Type (U) then
24950 U := Full_View (U);
24951 end if;
24953 when E_Subprogram_Body =>
24954 P := Parent (E);
24956 if Nkind (P) = N_Defining_Program_Unit_Name then
24957 P := Parent (P);
24958 end if;
24960 P := Parent (P);
24962 if Nkind (P) = N_Subprogram_Body
24963 and then Present (Corresponding_Spec (P))
24964 then
24965 U := Corresponding_Spec (P);
24967 elsif Nkind (P) = N_Subprogram_Body_Stub
24968 and then Present (Corresponding_Spec_Of_Stub (P))
24969 then
24970 U := Corresponding_Spec_Of_Stub (P);
24972 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
24973 U := Corresponding_Spec (P);
24974 end if;
24976 when E_Task_Body =>
24977 P := Parent (E);
24979 if Nkind (P) = N_Task_Body
24980 and then Present (Corresponding_Spec (P))
24981 then
24982 U := Corresponding_Spec (P);
24984 elsif Nkind (P) = N_Task_Body_Stub
24985 and then Present (Corresponding_Spec_Of_Stub (P))
24986 then
24987 U := Corresponding_Spec_Of_Stub (P);
24989 if Is_Single_Task_Object (U) then
24990 U := Etype (U);
24991 end if;
24992 end if;
24994 if Is_Private_Type (U) then
24995 U := Full_View (U);
24996 end if;
24998 when Type_Kind =>
24999 if Present (Full_View (E)) then
25000 U := Full_View (E);
25001 end if;
25003 when others =>
25004 null;
25005 end case;
25007 return U;
25008 end Unique_Entity;
25010 -----------------
25011 -- Unique_Name --
25012 -----------------
25014 function Unique_Name (E : Entity_Id) return String is
25016 -- Names in E_Subprogram_Body or E_Package_Body entities are not
25017 -- reliable, as they may not include the overloading suffix. Instead,
25018 -- when looking for the name of E or one of its enclosing scope, we get
25019 -- the name of the corresponding Unique_Entity.
25021 U : constant Entity_Id := Unique_Entity (E);
25023 function This_Name return String;
25025 ---------------
25026 -- This_Name --
25027 ---------------
25029 function This_Name return String is
25030 begin
25031 return Get_Name_String (Chars (U));
25032 end This_Name;
25034 -- Start of processing for Unique_Name
25036 begin
25037 if E = Standard_Standard
25038 or else Has_Fully_Qualified_Name (E)
25039 then
25040 return This_Name;
25042 elsif Ekind (E) = E_Enumeration_Literal then
25043 return Unique_Name (Etype (E)) & "__" & This_Name;
25045 else
25046 declare
25047 S : constant Entity_Id := Scope (U);
25048 pragma Assert (Present (S));
25050 begin
25051 -- Prefix names of predefined types with standard__, but leave
25052 -- names of user-defined packages and subprograms without prefix
25053 -- (even if technically they are nested in the Standard package).
25055 if S = Standard_Standard then
25056 if Ekind (U) = E_Package or else Is_Subprogram (U) then
25057 return This_Name;
25058 else
25059 return Unique_Name (S) & "__" & This_Name;
25060 end if;
25062 -- For intances of generic subprograms use the name of the related
25063 -- instace and skip the scope of its wrapper package.
25065 elsif Is_Wrapper_Package (S) then
25066 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
25067 -- Wrapper package and the instantiation are in the same scope
25069 declare
25070 Enclosing_Name : constant String :=
25071 Unique_Name (Scope (S)) & "__" &
25072 Get_Name_String (Chars (Related_Instance (S)));
25074 begin
25075 if Is_Subprogram (U)
25076 and then not Is_Generic_Actual_Subprogram (U)
25077 then
25078 return Enclosing_Name;
25079 else
25080 return Enclosing_Name & "__" & This_Name;
25081 end if;
25082 end;
25084 else
25085 return Unique_Name (S) & "__" & This_Name;
25086 end if;
25087 end;
25088 end if;
25089 end Unique_Name;
25091 ---------------------
25092 -- Unit_Is_Visible --
25093 ---------------------
25095 function Unit_Is_Visible (U : Entity_Id) return Boolean is
25096 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
25097 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
25099 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
25100 -- For a child unit, check whether unit appears in a with_clause
25101 -- of a parent.
25103 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
25104 -- Scan the context clause of one compilation unit looking for a
25105 -- with_clause for the unit in question.
25107 ----------------------------
25108 -- Unit_In_Parent_Context --
25109 ----------------------------
25111 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
25112 begin
25113 if Unit_In_Context (Par_Unit) then
25114 return True;
25116 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
25117 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
25119 else
25120 return False;
25121 end if;
25122 end Unit_In_Parent_Context;
25124 ---------------------
25125 -- Unit_In_Context --
25126 ---------------------
25128 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
25129 Clause : Node_Id;
25131 begin
25132 Clause := First (Context_Items (Comp_Unit));
25133 while Present (Clause) loop
25134 if Nkind (Clause) = N_With_Clause then
25135 if Library_Unit (Clause) = U then
25136 return True;
25138 -- The with_clause may denote a renaming of the unit we are
25139 -- looking for, eg. Text_IO which renames Ada.Text_IO.
25141 elsif
25142 Renamed_Entity (Entity (Name (Clause))) =
25143 Defining_Entity (Unit (U))
25144 then
25145 return True;
25146 end if;
25147 end if;
25149 Next (Clause);
25150 end loop;
25152 return False;
25153 end Unit_In_Context;
25155 -- Start of processing for Unit_Is_Visible
25157 begin
25158 -- The currrent unit is directly visible
25160 if Curr = U then
25161 return True;
25163 elsif Unit_In_Context (Curr) then
25164 return True;
25166 -- If the current unit is a body, check the context of the spec
25168 elsif Nkind (Unit (Curr)) = N_Package_Body
25169 or else
25170 (Nkind (Unit (Curr)) = N_Subprogram_Body
25171 and then not Acts_As_Spec (Unit (Curr)))
25172 then
25173 if Unit_In_Context (Library_Unit (Curr)) then
25174 return True;
25175 end if;
25176 end if;
25178 -- If the spec is a child unit, examine the parents
25180 if Is_Child_Unit (Curr_Entity) then
25181 if Nkind (Unit (Curr)) in N_Unit_Body then
25182 return
25183 Unit_In_Parent_Context
25184 (Parent_Spec (Unit (Library_Unit (Curr))));
25185 else
25186 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
25187 end if;
25189 else
25190 return False;
25191 end if;
25192 end Unit_Is_Visible;
25194 ------------------------------
25195 -- Universal_Interpretation --
25196 ------------------------------
25198 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
25199 Index : Interp_Index;
25200 It : Interp;
25202 begin
25203 -- The argument may be a formal parameter of an operator or subprogram
25204 -- with multiple interpretations, or else an expression for an actual.
25206 if Nkind (Opnd) = N_Defining_Identifier
25207 or else not Is_Overloaded (Opnd)
25208 then
25209 if Etype (Opnd) = Universal_Integer
25210 or else Etype (Opnd) = Universal_Real
25211 then
25212 return Etype (Opnd);
25213 else
25214 return Empty;
25215 end if;
25217 else
25218 Get_First_Interp (Opnd, Index, It);
25219 while Present (It.Typ) loop
25220 if It.Typ = Universal_Integer
25221 or else It.Typ = Universal_Real
25222 then
25223 return It.Typ;
25224 end if;
25226 Get_Next_Interp (Index, It);
25227 end loop;
25229 return Empty;
25230 end if;
25231 end Universal_Interpretation;
25233 ---------------
25234 -- Unqualify --
25235 ---------------
25237 function Unqualify (Expr : Node_Id) return Node_Id is
25238 begin
25239 -- Recurse to handle unlikely case of multiple levels of qualification
25241 if Nkind (Expr) = N_Qualified_Expression then
25242 return Unqualify (Expression (Expr));
25244 -- Normal case, not a qualified expression
25246 else
25247 return Expr;
25248 end if;
25249 end Unqualify;
25251 -----------------
25252 -- Unqual_Conv --
25253 -----------------
25255 function Unqual_Conv (Expr : Node_Id) return Node_Id is
25256 begin
25257 -- Recurse to handle unlikely case of multiple levels of qualification
25258 -- and/or conversion.
25260 if Nkind_In (Expr, N_Qualified_Expression,
25261 N_Type_Conversion,
25262 N_Unchecked_Type_Conversion)
25263 then
25264 return Unqual_Conv (Expression (Expr));
25266 -- Normal case, not a qualified expression
25268 else
25269 return Expr;
25270 end if;
25271 end Unqual_Conv;
25273 --------------------
25274 -- Validated_View --
25275 --------------------
25277 function Validated_View (Typ : Entity_Id) return Entity_Id is
25278 Continue : Boolean;
25279 Val_Typ : Entity_Id;
25281 begin
25282 Continue := True;
25283 Val_Typ := Base_Type (Typ);
25285 -- Obtain the full view of the input type by stripping away concurrency,
25286 -- derivations, and privacy.
25288 while Continue loop
25289 Continue := False;
25291 if Is_Concurrent_Type (Val_Typ) then
25292 if Present (Corresponding_Record_Type (Val_Typ)) then
25293 Continue := True;
25294 Val_Typ := Corresponding_Record_Type (Val_Typ);
25295 end if;
25297 elsif Is_Derived_Type (Val_Typ) then
25298 Continue := True;
25299 Val_Typ := Etype (Val_Typ);
25301 elsif Is_Private_Type (Val_Typ) then
25302 if Present (Underlying_Full_View (Val_Typ)) then
25303 Continue := True;
25304 Val_Typ := Underlying_Full_View (Val_Typ);
25306 elsif Present (Full_View (Val_Typ)) then
25307 Continue := True;
25308 Val_Typ := Full_View (Val_Typ);
25309 end if;
25310 end if;
25311 end loop;
25313 return Val_Typ;
25314 end Validated_View;
25316 -----------------------
25317 -- Visible_Ancestors --
25318 -----------------------
25320 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
25321 List_1 : Elist_Id;
25322 List_2 : Elist_Id;
25323 Elmt : Elmt_Id;
25325 begin
25326 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
25328 -- Collect all the parents and progenitors of Typ. If the full-view of
25329 -- private parents and progenitors is available then it is used to
25330 -- generate the list of visible ancestors; otherwise their partial
25331 -- view is added to the resulting list.
25333 Collect_Parents
25334 (T => Typ,
25335 List => List_1,
25336 Use_Full_View => True);
25338 Collect_Interfaces
25339 (T => Typ,
25340 Ifaces_List => List_2,
25341 Exclude_Parents => True,
25342 Use_Full_View => True);
25344 -- Join the two lists. Avoid duplications because an interface may
25345 -- simultaneously be parent and progenitor of a type.
25347 Elmt := First_Elmt (List_2);
25348 while Present (Elmt) loop
25349 Append_Unique_Elmt (Node (Elmt), List_1);
25350 Next_Elmt (Elmt);
25351 end loop;
25353 return List_1;
25354 end Visible_Ancestors;
25356 ----------------------
25357 -- Within_Init_Proc --
25358 ----------------------
25360 function Within_Init_Proc return Boolean is
25361 S : Entity_Id;
25363 begin
25364 S := Current_Scope;
25365 while not Is_Overloadable (S) loop
25366 if S = Standard_Standard then
25367 return False;
25368 else
25369 S := Scope (S);
25370 end if;
25371 end loop;
25373 return Is_Init_Proc (S);
25374 end Within_Init_Proc;
25376 ---------------------------
25377 -- Within_Protected_Type --
25378 ---------------------------
25380 function Within_Protected_Type (E : Entity_Id) return Boolean is
25381 Scop : Entity_Id := Scope (E);
25383 begin
25384 while Present (Scop) loop
25385 if Ekind (Scop) = E_Protected_Type then
25386 return True;
25387 end if;
25389 Scop := Scope (Scop);
25390 end loop;
25392 return False;
25393 end Within_Protected_Type;
25395 ------------------
25396 -- Within_Scope --
25397 ------------------
25399 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
25400 begin
25401 return Scope_Within_Or_Same (Scope (E), S);
25402 end Within_Scope;
25404 ----------------------------
25405 -- Within_Subprogram_Call --
25406 ----------------------------
25408 function Within_Subprogram_Call (N : Node_Id) return Boolean is
25409 Par : Node_Id;
25411 begin
25412 -- Climb the parent chain looking for a function or procedure call
25414 Par := N;
25415 while Present (Par) loop
25416 if Nkind_In (Par, N_Entry_Call_Statement,
25417 N_Function_Call,
25418 N_Procedure_Call_Statement)
25419 then
25420 return True;
25422 -- Prevent the search from going too far
25424 elsif Is_Body_Or_Package_Declaration (Par) then
25425 exit;
25426 end if;
25428 Par := Parent (Par);
25429 end loop;
25431 return False;
25432 end Within_Subprogram_Call;
25434 ----------------
25435 -- Wrong_Type --
25436 ----------------
25438 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
25439 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
25440 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
25442 Matching_Field : Entity_Id;
25443 -- Entity to give a more precise suggestion on how to write a one-
25444 -- element positional aggregate.
25446 function Has_One_Matching_Field return Boolean;
25447 -- Determines if Expec_Type is a record type with a single component or
25448 -- discriminant whose type matches the found type or is one dimensional
25449 -- array whose component type matches the found type. In the case of
25450 -- one discriminant, we ignore the variant parts. That's not accurate,
25451 -- but good enough for the warning.
25453 ----------------------------
25454 -- Has_One_Matching_Field --
25455 ----------------------------
25457 function Has_One_Matching_Field return Boolean is
25458 E : Entity_Id;
25460 begin
25461 Matching_Field := Empty;
25463 if Is_Array_Type (Expec_Type)
25464 and then Number_Dimensions (Expec_Type) = 1
25465 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
25466 then
25467 -- Use type name if available. This excludes multidimensional
25468 -- arrays and anonymous arrays.
25470 if Comes_From_Source (Expec_Type) then
25471 Matching_Field := Expec_Type;
25473 -- For an assignment, use name of target
25475 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
25476 and then Is_Entity_Name (Name (Parent (Expr)))
25477 then
25478 Matching_Field := Entity (Name (Parent (Expr)));
25479 end if;
25481 return True;
25483 elsif not Is_Record_Type (Expec_Type) then
25484 return False;
25486 else
25487 E := First_Entity (Expec_Type);
25488 loop
25489 if No (E) then
25490 return False;
25492 elsif not Ekind_In (E, E_Discriminant, E_Component)
25493 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
25494 then
25495 Next_Entity (E);
25497 else
25498 exit;
25499 end if;
25500 end loop;
25502 if not Covers (Etype (E), Found_Type) then
25503 return False;
25505 elsif Present (Next_Entity (E))
25506 and then (Ekind (E) = E_Component
25507 or else Ekind (Next_Entity (E)) = E_Discriminant)
25508 then
25509 return False;
25511 else
25512 Matching_Field := E;
25513 return True;
25514 end if;
25515 end if;
25516 end Has_One_Matching_Field;
25518 -- Start of processing for Wrong_Type
25520 begin
25521 -- Don't output message if either type is Any_Type, or if a message
25522 -- has already been posted for this node. We need to do the latter
25523 -- check explicitly (it is ordinarily done in Errout), because we
25524 -- are using ! to force the output of the error messages.
25526 if Expec_Type = Any_Type
25527 or else Found_Type = Any_Type
25528 or else Error_Posted (Expr)
25529 then
25530 return;
25532 -- If one of the types is a Taft-Amendment type and the other it its
25533 -- completion, it must be an illegal use of a TAT in the spec, for
25534 -- which an error was already emitted. Avoid cascaded errors.
25536 elsif Is_Incomplete_Type (Expec_Type)
25537 and then Has_Completion_In_Body (Expec_Type)
25538 and then Full_View (Expec_Type) = Etype (Expr)
25539 then
25540 return;
25542 elsif Is_Incomplete_Type (Etype (Expr))
25543 and then Has_Completion_In_Body (Etype (Expr))
25544 and then Full_View (Etype (Expr)) = Expec_Type
25545 then
25546 return;
25548 -- In an instance, there is an ongoing problem with completion of
25549 -- type derived from private types. Their structure is what Gigi
25550 -- expects, but the Etype is the parent type rather than the
25551 -- derived private type itself. Do not flag error in this case. The
25552 -- private completion is an entity without a parent, like an Itype.
25553 -- Similarly, full and partial views may be incorrect in the instance.
25554 -- There is no simple way to insure that it is consistent ???
25556 -- A similar view discrepancy can happen in an inlined body, for the
25557 -- same reason: inserted body may be outside of the original package
25558 -- and only partial views are visible at the point of insertion.
25560 elsif In_Instance or else In_Inlined_Body then
25561 if Etype (Etype (Expr)) = Etype (Expected_Type)
25562 and then
25563 (Has_Private_Declaration (Expected_Type)
25564 or else Has_Private_Declaration (Etype (Expr)))
25565 and then No (Parent (Expected_Type))
25566 then
25567 return;
25569 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
25570 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
25571 then
25572 return;
25574 elsif Is_Private_Type (Expected_Type)
25575 and then Present (Full_View (Expected_Type))
25576 and then Covers (Full_View (Expected_Type), Etype (Expr))
25577 then
25578 return;
25580 -- Conversely, type of expression may be the private one
25582 elsif Is_Private_Type (Base_Type (Etype (Expr)))
25583 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
25584 then
25585 return;
25586 end if;
25587 end if;
25589 -- An interesting special check. If the expression is parenthesized
25590 -- and its type corresponds to the type of the sole component of the
25591 -- expected record type, or to the component type of the expected one
25592 -- dimensional array type, then assume we have a bad aggregate attempt.
25594 if Nkind (Expr) in N_Subexpr
25595 and then Paren_Count (Expr) /= 0
25596 and then Has_One_Matching_Field
25597 then
25598 Error_Msg_N ("positional aggregate cannot have one component", Expr);
25600 if Present (Matching_Field) then
25601 if Is_Array_Type (Expec_Type) then
25602 Error_Msg_NE
25603 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
25604 else
25605 Error_Msg_NE
25606 ("\write instead `& ='> ...`", Expr, Matching_Field);
25607 end if;
25608 end if;
25610 -- Another special check, if we are looking for a pool-specific access
25611 -- type and we found an E_Access_Attribute_Type, then we have the case
25612 -- of an Access attribute being used in a context which needs a pool-
25613 -- specific type, which is never allowed. The one extra check we make
25614 -- is that the expected designated type covers the Found_Type.
25616 elsif Is_Access_Type (Expec_Type)
25617 and then Ekind (Found_Type) = E_Access_Attribute_Type
25618 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
25619 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
25620 and then Covers
25621 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
25622 then
25623 Error_Msg_N -- CODEFIX
25624 ("result must be general access type!", Expr);
25625 Error_Msg_NE -- CODEFIX
25626 ("add ALL to }!", Expr, Expec_Type);
25628 -- Another special check, if the expected type is an integer type,
25629 -- but the expression is of type System.Address, and the parent is
25630 -- an addition or subtraction operation whose left operand is the
25631 -- expression in question and whose right operand is of an integral
25632 -- type, then this is an attempt at address arithmetic, so give
25633 -- appropriate message.
25635 elsif Is_Integer_Type (Expec_Type)
25636 and then Is_RTE (Found_Type, RE_Address)
25637 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
25638 and then Expr = Left_Opnd (Parent (Expr))
25639 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
25640 then
25641 Error_Msg_N
25642 ("address arithmetic not predefined in package System",
25643 Parent (Expr));
25644 Error_Msg_N
25645 ("\possible missing with/use of System.Storage_Elements",
25646 Parent (Expr));
25647 return;
25649 -- If the expected type is an anonymous access type, as for access
25650 -- parameters and discriminants, the error is on the designated types.
25652 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
25653 if Comes_From_Source (Expec_Type) then
25654 Error_Msg_NE ("expected}!", Expr, Expec_Type);
25655 else
25656 Error_Msg_NE
25657 ("expected an access type with designated}",
25658 Expr, Designated_Type (Expec_Type));
25659 end if;
25661 if Is_Access_Type (Found_Type)
25662 and then not Comes_From_Source (Found_Type)
25663 then
25664 Error_Msg_NE
25665 ("\\found an access type with designated}!",
25666 Expr, Designated_Type (Found_Type));
25667 else
25668 if From_Limited_With (Found_Type) then
25669 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
25670 Error_Msg_Qual_Level := 99;
25671 Error_Msg_NE -- CODEFIX
25672 ("\\missing `WITH &;", Expr, Scope (Found_Type));
25673 Error_Msg_Qual_Level := 0;
25674 else
25675 Error_Msg_NE ("found}!", Expr, Found_Type);
25676 end if;
25677 end if;
25679 -- Normal case of one type found, some other type expected
25681 else
25682 -- If the names of the two types are the same, see if some number
25683 -- of levels of qualification will help. Don't try more than three
25684 -- levels, and if we get to standard, it's no use (and probably
25685 -- represents an error in the compiler) Also do not bother with
25686 -- internal scope names.
25688 declare
25689 Expec_Scope : Entity_Id;
25690 Found_Scope : Entity_Id;
25692 begin
25693 Expec_Scope := Expec_Type;
25694 Found_Scope := Found_Type;
25696 for Levels in Nat range 0 .. 3 loop
25697 if Chars (Expec_Scope) /= Chars (Found_Scope) then
25698 Error_Msg_Qual_Level := Levels;
25699 exit;
25700 end if;
25702 Expec_Scope := Scope (Expec_Scope);
25703 Found_Scope := Scope (Found_Scope);
25705 exit when Expec_Scope = Standard_Standard
25706 or else Found_Scope = Standard_Standard
25707 or else not Comes_From_Source (Expec_Scope)
25708 or else not Comes_From_Source (Found_Scope);
25709 end loop;
25710 end;
25712 if Is_Record_Type (Expec_Type)
25713 and then Present (Corresponding_Remote_Type (Expec_Type))
25714 then
25715 Error_Msg_NE ("expected}!", Expr,
25716 Corresponding_Remote_Type (Expec_Type));
25717 else
25718 Error_Msg_NE ("expected}!", Expr, Expec_Type);
25719 end if;
25721 if Is_Entity_Name (Expr)
25722 and then Is_Package_Or_Generic_Package (Entity (Expr))
25723 then
25724 Error_Msg_N ("\\found package name!", Expr);
25726 elsif Is_Entity_Name (Expr)
25727 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
25728 then
25729 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
25730 Error_Msg_N
25731 ("found procedure name, possibly missing Access attribute!",
25732 Expr);
25733 else
25734 Error_Msg_N
25735 ("\\found procedure name instead of function!", Expr);
25736 end if;
25738 elsif Nkind (Expr) = N_Function_Call
25739 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
25740 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
25741 and then No (Parameter_Associations (Expr))
25742 then
25743 Error_Msg_N
25744 ("found function name, possibly missing Access attribute!",
25745 Expr);
25747 -- Catch common error: a prefix or infix operator which is not
25748 -- directly visible because the type isn't.
25750 elsif Nkind (Expr) in N_Op
25751 and then Is_Overloaded (Expr)
25752 and then not Is_Immediately_Visible (Expec_Type)
25753 and then not Is_Potentially_Use_Visible (Expec_Type)
25754 and then not In_Use (Expec_Type)
25755 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
25756 then
25757 Error_Msg_N
25758 ("operator of the type is not directly visible!", Expr);
25760 elsif Ekind (Found_Type) = E_Void
25761 and then Present (Parent (Found_Type))
25762 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
25763 then
25764 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
25766 else
25767 Error_Msg_NE ("\\found}!", Expr, Found_Type);
25768 end if;
25770 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
25771 -- of the same modular type, and (M1 and M2) = 0 was intended.
25773 if Expec_Type = Standard_Boolean
25774 and then Is_Modular_Integer_Type (Found_Type)
25775 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
25776 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
25777 then
25778 declare
25779 Op : constant Node_Id := Right_Opnd (Parent (Expr));
25780 L : constant Node_Id := Left_Opnd (Op);
25781 R : constant Node_Id := Right_Opnd (Op);
25783 begin
25784 -- The case for the message is when the left operand of the
25785 -- comparison is the same modular type, or when it is an
25786 -- integer literal (or other universal integer expression),
25787 -- which would have been typed as the modular type if the
25788 -- parens had been there.
25790 if (Etype (L) = Found_Type
25791 or else
25792 Etype (L) = Universal_Integer)
25793 and then Is_Integer_Type (Etype (R))
25794 then
25795 Error_Msg_N
25796 ("\\possible missing parens for modular operation", Expr);
25797 end if;
25798 end;
25799 end if;
25801 -- Reset error message qualification indication
25803 Error_Msg_Qual_Level := 0;
25804 end if;
25805 end Wrong_Type;
25807 --------------------------------
25808 -- Yields_Synchronized_Object --
25809 --------------------------------
25811 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
25812 Has_Sync_Comp : Boolean := False;
25813 Id : Entity_Id;
25815 begin
25816 -- An array type yields a synchronized object if its component type
25817 -- yields a synchronized object.
25819 if Is_Array_Type (Typ) then
25820 return Yields_Synchronized_Object (Component_Type (Typ));
25822 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
25823 -- yields a synchronized object by default.
25825 elsif Is_Descendant_Of_Suspension_Object (Typ) then
25826 return True;
25828 -- A protected type yields a synchronized object by default
25830 elsif Is_Protected_Type (Typ) then
25831 return True;
25833 -- A record type or type extension yields a synchronized object when its
25834 -- discriminants (if any) lack default values and all components are of
25835 -- a type that yelds a synchronized object.
25837 elsif Is_Record_Type (Typ) then
25839 -- Inspect all entities defined in the scope of the type, looking for
25840 -- components of a type that does not yeld a synchronized object or
25841 -- for discriminants with default values.
25843 Id := First_Entity (Typ);
25844 while Present (Id) loop
25845 if Comes_From_Source (Id) then
25846 if Ekind (Id) = E_Component then
25847 if Yields_Synchronized_Object (Etype (Id)) then
25848 Has_Sync_Comp := True;
25850 -- The component does not yield a synchronized object
25852 else
25853 return False;
25854 end if;
25856 elsif Ekind (Id) = E_Discriminant
25857 and then Present (Expression (Parent (Id)))
25858 then
25859 return False;
25860 end if;
25861 end if;
25863 Next_Entity (Id);
25864 end loop;
25866 -- Ensure that the parent type of a type extension yields a
25867 -- synchronized object.
25869 if Etype (Typ) /= Typ
25870 and then not Yields_Synchronized_Object (Etype (Typ))
25871 then
25872 return False;
25873 end if;
25875 -- If we get here, then all discriminants lack default values and all
25876 -- components are of a type that yields a synchronized object.
25878 return Has_Sync_Comp;
25880 -- A synchronized interface type yields a synchronized object by default
25882 elsif Is_Synchronized_Interface (Typ) then
25883 return True;
25885 -- A task type yelds a synchronized object by default
25887 elsif Is_Task_Type (Typ) then
25888 return True;
25890 -- Otherwise the type does not yield a synchronized object
25892 else
25893 return False;
25894 end if;
25895 end Yields_Synchronized_Object;
25897 ---------------------------
25898 -- Yields_Universal_Type --
25899 ---------------------------
25901 function Yields_Universal_Type (N : Node_Id) return Boolean is
25902 begin
25903 -- Integer and real literals are of a universal type
25905 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
25906 return True;
25908 -- The values of certain attributes are of a universal type
25910 elsif Nkind (N) = N_Attribute_Reference then
25911 return
25912 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
25914 -- ??? There are possibly other cases to consider
25916 else
25917 return False;
25918 end if;
25919 end Yields_Universal_Type;
25921 begin
25922 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
25923 end Sem_Util;