LWG 2975 ensure construct(pair<T,U>*, ...) used to construct pairs
[official-gcc.git] / gcc / ada / sem_util.adb
blob70c02da6ea1b39c067f25e82bd10e4211b3ec16c
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 -- Warn on infinite recursion if call is to current function
3885 elsif Nkind (N) = N_Function_Call
3886 and then Is_Entity_Name (Name (N))
3887 and then Entity (Name (N)) = Subp_Id
3888 and then not Is_Potentially_Unevaluated (N)
3889 then
3890 Error_Msg_NE
3891 ("call to & within its postcondition will lead to infinite "
3892 & "recursion?", N, Subp_Id);
3893 return OK;
3895 -- Continue the traversal
3897 else
3898 return OK;
3899 end if;
3900 end Is_Function_Result;
3902 ------------------------
3903 -- Is_Trivial_Boolean --
3904 ------------------------
3906 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3907 begin
3908 return
3909 Comes_From_Source (N)
3910 and then Is_Entity_Name (N)
3911 and then (Entity (N) = Standard_True
3912 or else
3913 Entity (N) = Standard_False);
3914 end Is_Trivial_Boolean;
3916 -------------------------
3917 -- Mentions_Post_State --
3918 -------------------------
3920 function Mentions_Post_State (N : Node_Id) return Boolean is
3921 Post_State_Seen : Boolean := False;
3923 function Is_Post_State (N : Node_Id) return Traverse_Result;
3924 -- Attempt to find a construct that denotes a post-state. If this
3925 -- is the case, set flag Post_State_Seen.
3927 -------------------
3928 -- Is_Post_State --
3929 -------------------
3931 function Is_Post_State (N : Node_Id) return Traverse_Result is
3932 Ent : Entity_Id;
3934 begin
3935 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3936 Post_State_Seen := True;
3937 return Abandon;
3939 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3940 Ent := Entity (N);
3942 -- Treat an undecorated reference as OK
3944 if No (Ent)
3946 -- A reference to an assignable entity is considered a
3947 -- change in the post-state of a subprogram.
3949 or else Ekind_In (Ent, E_Generic_In_Out_Parameter,
3950 E_In_Out_Parameter,
3951 E_Out_Parameter,
3952 E_Variable)
3954 -- The reference may be modified through a dereference
3956 or else (Is_Access_Type (Etype (Ent))
3957 and then Nkind (Parent (N)) =
3958 N_Selected_Component)
3959 then
3960 Post_State_Seen := True;
3961 return Abandon;
3962 end if;
3964 elsif Nkind (N) = N_Attribute_Reference then
3965 if Attribute_Name (N) = Name_Old then
3966 return Skip;
3968 elsif Attribute_Name (N) = Name_Result then
3969 Post_State_Seen := True;
3970 return Abandon;
3971 end if;
3972 end if;
3974 return OK;
3975 end Is_Post_State;
3977 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3979 -- Start of processing for Mentions_Post_State
3981 begin
3982 Find_Post_State (N);
3984 return Post_State_Seen;
3985 end Mentions_Post_State;
3987 -- Local variables
3989 Expr : constant Node_Id :=
3990 Get_Pragma_Arg
3991 (First (Pragma_Argument_Associations (Prag)));
3992 Nam : constant Name_Id := Pragma_Name (Prag);
3993 CCase : Node_Id;
3995 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3997 begin
3998 -- Examine all consequences
4000 if Nam = Name_Contract_Cases then
4001 CCase := First (Component_Associations (Expr));
4002 while Present (CCase) loop
4003 Check_Expression (Expression (CCase));
4005 Next (CCase);
4006 end loop;
4008 -- Examine the expression of a postcondition
4010 else pragma Assert (Nam_In (Nam, Name_Postcondition,
4011 Name_Refined_Post));
4012 Check_Expression (Expr);
4013 end if;
4014 end Check_Result_And_Post_State_In_Pragma;
4016 --------------------------
4017 -- Has_In_Out_Parameter --
4018 --------------------------
4020 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
4021 Formal : Entity_Id;
4023 begin
4024 -- Traverse the formals looking for an IN OUT parameter
4026 Formal := First_Formal (Subp_Id);
4027 while Present (Formal) loop
4028 if Ekind (Formal) = E_In_Out_Parameter then
4029 return True;
4030 end if;
4032 Next_Formal (Formal);
4033 end loop;
4035 return False;
4036 end Has_In_Out_Parameter;
4038 -- Local variables
4040 Items : constant Node_Id := Contract (Subp_Id);
4041 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
4042 Case_Prag : Node_Id := Empty;
4043 Post_Prag : Node_Id := Empty;
4044 Prag : Node_Id;
4045 Seen_In_Case : Boolean := False;
4046 Seen_In_Post : Boolean := False;
4047 Spec_Id : Entity_Id;
4049 -- Start of processing for Check_Result_And_Post_State
4051 begin
4052 -- The lack of attribute 'Result or a post-state is classified as a
4053 -- suspicious contract. Do not perform the check if the corresponding
4054 -- swich is not set.
4056 if not Warn_On_Suspicious_Contract then
4057 return;
4059 -- Nothing to do if there is no contract
4061 elsif No (Items) then
4062 return;
4063 end if;
4065 -- Retrieve the entity of the subprogram spec (if any)
4067 if Nkind (Subp_Decl) = N_Subprogram_Body
4068 and then Present (Corresponding_Spec (Subp_Decl))
4069 then
4070 Spec_Id := Corresponding_Spec (Subp_Decl);
4072 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
4073 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
4074 then
4075 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
4077 else
4078 Spec_Id := Subp_Id;
4079 end if;
4081 -- Examine all postconditions for attribute 'Result and a post-state
4083 Prag := Pre_Post_Conditions (Items);
4084 while Present (Prag) loop
4085 if Nam_In (Pragma_Name_Unmapped (Prag),
4086 Name_Postcondition, Name_Refined_Post)
4087 and then not Error_Posted (Prag)
4088 then
4089 Post_Prag := Prag;
4090 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
4091 end if;
4093 Prag := Next_Pragma (Prag);
4094 end loop;
4096 -- Examine the contract cases of the subprogram for attribute 'Result
4097 -- and a post-state.
4099 Prag := Contract_Test_Cases (Items);
4100 while Present (Prag) loop
4101 if Pragma_Name (Prag) = Name_Contract_Cases
4102 and then not Error_Posted (Prag)
4103 then
4104 Case_Prag := Prag;
4105 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
4106 end if;
4108 Prag := Next_Pragma (Prag);
4109 end loop;
4111 -- Do not emit any errors if the subprogram is not a function
4113 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
4114 null;
4116 -- Regardless of whether the function has postconditions or contract
4117 -- cases, or whether they mention attribute 'Result, an IN OUT formal
4118 -- parameter is always treated as a result.
4120 elsif Has_In_Out_Parameter (Spec_Id) then
4121 null;
4123 -- The function has both a postcondition and contract cases and they do
4124 -- not mention attribute 'Result.
4126 elsif Present (Case_Prag)
4127 and then not Seen_In_Case
4128 and then Present (Post_Prag)
4129 and then not Seen_In_Post
4130 then
4131 Error_Msg_N
4132 ("neither postcondition nor contract cases mention function "
4133 & "result?T?", Post_Prag);
4135 -- The function has contract cases only and they do not mention
4136 -- attribute 'Result.
4138 elsif Present (Case_Prag) and then not Seen_In_Case then
4139 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
4141 -- The function has postconditions only and they do not mention
4142 -- attribute 'Result.
4144 elsif Present (Post_Prag) and then not Seen_In_Post then
4145 Error_Msg_N
4146 ("postcondition does not mention function result?T?", Post_Prag);
4147 end if;
4148 end Check_Result_And_Post_State;
4150 -----------------------------
4151 -- Check_State_Refinements --
4152 -----------------------------
4154 procedure Check_State_Refinements
4155 (Context : Node_Id;
4156 Is_Main_Unit : Boolean := False)
4158 procedure Check_Package (Pack : Node_Id);
4159 -- Verify that all abstract states of a [generic] package denoted by its
4160 -- declarative node Pack have proper refinement. Recursively verify the
4161 -- visible and private declarations of the [generic] package for other
4162 -- nested packages.
4164 procedure Check_Packages_In (Decls : List_Id);
4165 -- Seek out [generic] package declarations within declarative list Decls
4166 -- and verify the status of their abstract state refinement.
4168 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
4169 -- Determine whether construct N is subject to pragma SPARK_Mode Off
4171 -------------------
4172 -- Check_Package --
4173 -------------------
4175 procedure Check_Package (Pack : Node_Id) is
4176 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
4177 Spec : constant Node_Id := Specification (Pack);
4178 States : constant Elist_Id :=
4179 Abstract_States (Defining_Entity (Pack));
4181 State_Elmt : Elmt_Id;
4182 State_Id : Entity_Id;
4184 begin
4185 -- Do not verify proper state refinement when the package is subject
4186 -- to pragma SPARK_Mode Off because this disables the requirement for
4187 -- state refinement.
4189 if SPARK_Mode_Is_Off (Pack) then
4190 null;
4192 -- State refinement can only occur in a completing package body. Do
4193 -- not verify proper state refinement when the body is subject to
4194 -- pragma SPARK_Mode Off because this disables the requirement for
4195 -- state refinement.
4197 elsif Present (Body_Id)
4198 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
4199 then
4200 null;
4202 -- Do not verify proper state refinement when the package is an
4203 -- instance as this check was already performed in the generic.
4205 elsif Present (Generic_Parent (Spec)) then
4206 null;
4208 -- Otherwise examine the contents of the package
4210 else
4211 if Present (States) then
4212 State_Elmt := First_Elmt (States);
4213 while Present (State_Elmt) loop
4214 State_Id := Node (State_Elmt);
4216 -- Emit an error when a non-null state lacks any form of
4217 -- refinement.
4219 if not Is_Null_State (State_Id)
4220 and then not Has_Null_Refinement (State_Id)
4221 and then not Has_Non_Null_Refinement (State_Id)
4222 then
4223 Error_Msg_N ("state & requires refinement", State_Id);
4224 end if;
4226 Next_Elmt (State_Elmt);
4227 end loop;
4228 end if;
4230 Check_Packages_In (Visible_Declarations (Spec));
4231 Check_Packages_In (Private_Declarations (Spec));
4232 end if;
4233 end Check_Package;
4235 -----------------------
4236 -- Check_Packages_In --
4237 -----------------------
4239 procedure Check_Packages_In (Decls : List_Id) is
4240 Decl : Node_Id;
4242 begin
4243 if Present (Decls) then
4244 Decl := First (Decls);
4245 while Present (Decl) loop
4246 if Nkind_In (Decl, N_Generic_Package_Declaration,
4247 N_Package_Declaration)
4248 then
4249 Check_Package (Decl);
4250 end if;
4252 Next (Decl);
4253 end loop;
4254 end if;
4255 end Check_Packages_In;
4257 -----------------------
4258 -- SPARK_Mode_Is_Off --
4259 -----------------------
4261 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
4262 Id : constant Entity_Id := Defining_Entity (N);
4263 Prag : constant Node_Id := SPARK_Pragma (Id);
4265 begin
4266 -- Default the mode to "off" when the context is an instance and all
4267 -- SPARK_Mode pragmas found within are to be ignored.
4269 if Ignore_SPARK_Mode_Pragmas (Id) then
4270 return True;
4272 else
4273 return
4274 Present (Prag)
4275 and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
4276 end if;
4277 end SPARK_Mode_Is_Off;
4279 -- Start of processing for Check_State_Refinements
4281 begin
4282 -- A block may declare a nested package
4284 if Nkind (Context) = N_Block_Statement then
4285 Check_Packages_In (Declarations (Context));
4287 -- An entry, protected, subprogram, or task body may declare a nested
4288 -- package.
4290 elsif Nkind_In (Context, N_Entry_Body,
4291 N_Protected_Body,
4292 N_Subprogram_Body,
4293 N_Task_Body)
4294 then
4295 -- Do not verify proper state refinement when the body is subject to
4296 -- pragma SPARK_Mode Off because this disables the requirement for
4297 -- state refinement.
4299 if not SPARK_Mode_Is_Off (Context) then
4300 Check_Packages_In (Declarations (Context));
4301 end if;
4303 -- A package body may declare a nested package
4305 elsif Nkind (Context) = N_Package_Body then
4306 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
4308 -- Do not verify proper state refinement when the body is subject to
4309 -- pragma SPARK_Mode Off because this disables the requirement for
4310 -- state refinement.
4312 if not SPARK_Mode_Is_Off (Context) then
4313 Check_Packages_In (Declarations (Context));
4314 end if;
4316 -- A library level [generic] package may declare a nested package
4318 elsif Nkind_In (Context, N_Generic_Package_Declaration,
4319 N_Package_Declaration)
4320 and then Is_Main_Unit
4321 then
4322 Check_Package (Context);
4323 end if;
4324 end Check_State_Refinements;
4326 ------------------------------
4327 -- Check_Unprotected_Access --
4328 ------------------------------
4330 procedure Check_Unprotected_Access
4331 (Context : Node_Id;
4332 Expr : Node_Id)
4334 Cont_Encl_Typ : Entity_Id;
4335 Pref_Encl_Typ : Entity_Id;
4337 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
4338 -- Check whether Obj is a private component of a protected object.
4339 -- Return the protected type where the component resides, Empty
4340 -- otherwise.
4342 function Is_Public_Operation return Boolean;
4343 -- Verify that the enclosing operation is callable from outside the
4344 -- protected object, to minimize false positives.
4346 ------------------------------
4347 -- Enclosing_Protected_Type --
4348 ------------------------------
4350 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
4351 begin
4352 if Is_Entity_Name (Obj) then
4353 declare
4354 Ent : Entity_Id := Entity (Obj);
4356 begin
4357 -- The object can be a renaming of a private component, use
4358 -- the original record component.
4360 if Is_Prival (Ent) then
4361 Ent := Prival_Link (Ent);
4362 end if;
4364 if Is_Protected_Type (Scope (Ent)) then
4365 return Scope (Ent);
4366 end if;
4367 end;
4368 end if;
4370 -- For indexed and selected components, recursively check the prefix
4372 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
4373 return Enclosing_Protected_Type (Prefix (Obj));
4375 -- The object does not denote a protected component
4377 else
4378 return Empty;
4379 end if;
4380 end Enclosing_Protected_Type;
4382 -------------------------
4383 -- Is_Public_Operation --
4384 -------------------------
4386 function Is_Public_Operation return Boolean is
4387 S : Entity_Id;
4388 E : Entity_Id;
4390 begin
4391 S := Current_Scope;
4392 while Present (S) and then S /= Pref_Encl_Typ loop
4393 if Scope (S) = Pref_Encl_Typ then
4394 E := First_Entity (Pref_Encl_Typ);
4395 while Present (E)
4396 and then E /= First_Private_Entity (Pref_Encl_Typ)
4397 loop
4398 if E = S then
4399 return True;
4400 end if;
4402 Next_Entity (E);
4403 end loop;
4404 end if;
4406 S := Scope (S);
4407 end loop;
4409 return False;
4410 end Is_Public_Operation;
4412 -- Start of processing for Check_Unprotected_Access
4414 begin
4415 if Nkind (Expr) = N_Attribute_Reference
4416 and then Attribute_Name (Expr) = Name_Unchecked_Access
4417 then
4418 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
4419 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
4421 -- Check whether we are trying to export a protected component to a
4422 -- context with an equal or lower access level.
4424 if Present (Pref_Encl_Typ)
4425 and then No (Cont_Encl_Typ)
4426 and then Is_Public_Operation
4427 and then Scope_Depth (Pref_Encl_Typ) >=
4428 Object_Access_Level (Context)
4429 then
4430 Error_Msg_N
4431 ("??possible unprotected access to protected data", Expr);
4432 end if;
4433 end if;
4434 end Check_Unprotected_Access;
4436 ------------------------------
4437 -- Check_Unused_Body_States --
4438 ------------------------------
4440 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
4441 procedure Process_Refinement_Clause
4442 (Clause : Node_Id;
4443 States : Elist_Id);
4444 -- Inspect all constituents of refinement clause Clause and remove any
4445 -- matches from body state list States.
4447 procedure Report_Unused_Body_States (States : Elist_Id);
4448 -- Emit errors for each abstract state or object found in list States
4450 -------------------------------
4451 -- Process_Refinement_Clause --
4452 -------------------------------
4454 procedure Process_Refinement_Clause
4455 (Clause : Node_Id;
4456 States : Elist_Id)
4458 procedure Process_Constituent (Constit : Node_Id);
4459 -- Remove constituent Constit from body state list States
4461 -------------------------
4462 -- Process_Constituent --
4463 -------------------------
4465 procedure Process_Constituent (Constit : Node_Id) is
4466 Constit_Id : Entity_Id;
4468 begin
4469 -- Guard against illegal constituents. Only abstract states and
4470 -- objects can appear on the right hand side of a refinement.
4472 if Is_Entity_Name (Constit) then
4473 Constit_Id := Entity_Of (Constit);
4475 if Present (Constit_Id)
4476 and then Ekind_In (Constit_Id, E_Abstract_State,
4477 E_Constant,
4478 E_Variable)
4479 then
4480 Remove (States, Constit_Id);
4481 end if;
4482 end if;
4483 end Process_Constituent;
4485 -- Local variables
4487 Constit : Node_Id;
4489 -- Start of processing for Process_Refinement_Clause
4491 begin
4492 if Nkind (Clause) = N_Component_Association then
4493 Constit := Expression (Clause);
4495 -- Multiple constituents appear as an aggregate
4497 if Nkind (Constit) = N_Aggregate then
4498 Constit := First (Expressions (Constit));
4499 while Present (Constit) loop
4500 Process_Constituent (Constit);
4501 Next (Constit);
4502 end loop;
4504 -- Various forms of a single constituent
4506 else
4507 Process_Constituent (Constit);
4508 end if;
4509 end if;
4510 end Process_Refinement_Clause;
4512 -------------------------------
4513 -- Report_Unused_Body_States --
4514 -------------------------------
4516 procedure Report_Unused_Body_States (States : Elist_Id) is
4517 Posted : Boolean := False;
4518 State_Elmt : Elmt_Id;
4519 State_Id : Entity_Id;
4521 begin
4522 if Present (States) then
4523 State_Elmt := First_Elmt (States);
4524 while Present (State_Elmt) loop
4525 State_Id := Node (State_Elmt);
4527 -- Constants are part of the hidden state of a package, but the
4528 -- compiler cannot determine whether they have variable input
4529 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4530 -- hidden state. Do not emit an error when a constant does not
4531 -- participate in a state refinement, even though it acts as a
4532 -- hidden state.
4534 if Ekind (State_Id) = E_Constant then
4535 null;
4537 -- Generate an error message of the form:
4539 -- body of package ... has unused hidden states
4540 -- abstract state ... defined at ...
4541 -- variable ... defined at ...
4543 else
4544 if not Posted then
4545 Posted := True;
4546 SPARK_Msg_N
4547 ("body of package & has unused hidden states", Body_Id);
4548 end if;
4550 Error_Msg_Sloc := Sloc (State_Id);
4552 if Ekind (State_Id) = E_Abstract_State then
4553 SPARK_Msg_NE
4554 ("\abstract state & defined #", Body_Id, State_Id);
4556 else
4557 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
4558 end if;
4559 end if;
4561 Next_Elmt (State_Elmt);
4562 end loop;
4563 end if;
4564 end Report_Unused_Body_States;
4566 -- Local variables
4568 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
4569 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
4570 Clause : Node_Id;
4571 States : Elist_Id;
4573 -- Start of processing for Check_Unused_Body_States
4575 begin
4576 -- Inspect the clauses of pragma Refined_State and determine whether all
4577 -- visible states declared within the package body participate in the
4578 -- refinement.
4580 if Present (Prag) then
4581 Clause := Expression (Get_Argument (Prag, Spec_Id));
4582 States := Collect_Body_States (Body_Id);
4584 -- Multiple non-null state refinements appear as an aggregate
4586 if Nkind (Clause) = N_Aggregate then
4587 Clause := First (Component_Associations (Clause));
4588 while Present (Clause) loop
4589 Process_Refinement_Clause (Clause, States);
4590 Next (Clause);
4591 end loop;
4593 -- Various forms of a single state refinement
4595 else
4596 Process_Refinement_Clause (Clause, States);
4597 end if;
4599 -- Ensure that all abstract states and objects declared in the
4600 -- package body state space are utilized as constituents.
4602 Report_Unused_Body_States (States);
4603 end if;
4604 end Check_Unused_Body_States;
4606 -----------------
4607 -- Choice_List --
4608 -----------------
4610 function Choice_List (N : Node_Id) return List_Id is
4611 begin
4612 if Nkind (N) = N_Iterated_Component_Association then
4613 return Discrete_Choices (N);
4614 else
4615 return Choices (N);
4616 end if;
4617 end Choice_List;
4619 -------------------------
4620 -- Collect_Body_States --
4621 -------------------------
4623 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
4624 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
4625 -- Determine whether object Obj_Id is a suitable visible state of a
4626 -- package body.
4628 procedure Collect_Visible_States
4629 (Pack_Id : Entity_Id;
4630 States : in out Elist_Id);
4631 -- Gather the entities of all abstract states and objects declared in
4632 -- the visible state space of package Pack_Id.
4634 ----------------------------
4635 -- Collect_Visible_States --
4636 ----------------------------
4638 procedure Collect_Visible_States
4639 (Pack_Id : Entity_Id;
4640 States : in out Elist_Id)
4642 Item_Id : Entity_Id;
4644 begin
4645 -- Traverse the entity chain of the package and inspect all visible
4646 -- items.
4648 Item_Id := First_Entity (Pack_Id);
4649 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
4651 -- Do not consider internally generated items as those cannot be
4652 -- named and participate in refinement.
4654 if not Comes_From_Source (Item_Id) then
4655 null;
4657 elsif Ekind (Item_Id) = E_Abstract_State then
4658 Append_New_Elmt (Item_Id, States);
4660 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
4661 and then Is_Visible_Object (Item_Id)
4662 then
4663 Append_New_Elmt (Item_Id, States);
4665 -- Recursively gather the visible states of a nested package
4667 elsif Ekind (Item_Id) = E_Package then
4668 Collect_Visible_States (Item_Id, States);
4669 end if;
4671 Next_Entity (Item_Id);
4672 end loop;
4673 end Collect_Visible_States;
4675 -----------------------
4676 -- Is_Visible_Object --
4677 -----------------------
4679 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
4680 begin
4681 -- Objects that map generic formals to their actuals are not visible
4682 -- from outside the generic instantiation.
4684 if Present (Corresponding_Generic_Association
4685 (Declaration_Node (Obj_Id)))
4686 then
4687 return False;
4689 -- Constituents of a single protected/task type act as components of
4690 -- the type and are not visible from outside the type.
4692 elsif Ekind (Obj_Id) = E_Variable
4693 and then Present (Encapsulating_State (Obj_Id))
4694 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
4695 then
4696 return False;
4698 else
4699 return True;
4700 end if;
4701 end Is_Visible_Object;
4703 -- Local variables
4705 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
4706 Decl : Node_Id;
4707 Item_Id : Entity_Id;
4708 States : Elist_Id := No_Elist;
4710 -- Start of processing for Collect_Body_States
4712 begin
4713 -- Inspect the declarations of the body looking for source objects,
4714 -- packages and package instantiations. Note that even though this
4715 -- processing is very similar to Collect_Visible_States, a package
4716 -- body does not have a First/Next_Entity list.
4718 Decl := First (Declarations (Body_Decl));
4719 while Present (Decl) loop
4721 -- Capture source objects as internally generated temporaries cannot
4722 -- be named and participate in refinement.
4724 if Nkind (Decl) = N_Object_Declaration then
4725 Item_Id := Defining_Entity (Decl);
4727 if Comes_From_Source (Item_Id)
4728 and then Is_Visible_Object (Item_Id)
4729 then
4730 Append_New_Elmt (Item_Id, States);
4731 end if;
4733 -- Capture the visible abstract states and objects of a source
4734 -- package [instantiation].
4736 elsif Nkind (Decl) = N_Package_Declaration then
4737 Item_Id := Defining_Entity (Decl);
4739 if Comes_From_Source (Item_Id) then
4740 Collect_Visible_States (Item_Id, States);
4741 end if;
4742 end if;
4744 Next (Decl);
4745 end loop;
4747 return States;
4748 end Collect_Body_States;
4750 ------------------------
4751 -- Collect_Interfaces --
4752 ------------------------
4754 procedure Collect_Interfaces
4755 (T : Entity_Id;
4756 Ifaces_List : out Elist_Id;
4757 Exclude_Parents : Boolean := False;
4758 Use_Full_View : Boolean := True)
4760 procedure Collect (Typ : Entity_Id);
4761 -- Subsidiary subprogram used to traverse the whole list
4762 -- of directly and indirectly implemented interfaces
4764 -------------
4765 -- Collect --
4766 -------------
4768 procedure Collect (Typ : Entity_Id) is
4769 Ancestor : Entity_Id;
4770 Full_T : Entity_Id;
4771 Id : Node_Id;
4772 Iface : Entity_Id;
4774 begin
4775 Full_T := Typ;
4777 -- Handle private types and subtypes
4779 if Use_Full_View
4780 and then Is_Private_Type (Typ)
4781 and then Present (Full_View (Typ))
4782 then
4783 Full_T := Full_View (Typ);
4785 if Ekind (Full_T) = E_Record_Subtype then
4786 Full_T := Etype (Typ);
4788 if Present (Full_View (Full_T)) then
4789 Full_T := Full_View (Full_T);
4790 end if;
4791 end if;
4792 end if;
4794 -- Include the ancestor if we are generating the whole list of
4795 -- abstract interfaces.
4797 if Etype (Full_T) /= Typ
4799 -- Protect the frontend against wrong sources. For example:
4801 -- package P is
4802 -- type A is tagged null record;
4803 -- type B is new A with private;
4804 -- type C is new A with private;
4805 -- private
4806 -- type B is new C with null record;
4807 -- type C is new B with null record;
4808 -- end P;
4810 and then Etype (Full_T) /= T
4811 then
4812 Ancestor := Etype (Full_T);
4813 Collect (Ancestor);
4815 if Is_Interface (Ancestor) and then not Exclude_Parents then
4816 Append_Unique_Elmt (Ancestor, Ifaces_List);
4817 end if;
4818 end if;
4820 -- Traverse the graph of ancestor interfaces
4822 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4823 Id := First (Abstract_Interface_List (Full_T));
4824 while Present (Id) loop
4825 Iface := Etype (Id);
4827 -- Protect against wrong uses. For example:
4828 -- type I is interface;
4829 -- type O is tagged null record;
4830 -- type Wrong is new I and O with null record; -- ERROR
4832 if Is_Interface (Iface) then
4833 if Exclude_Parents
4834 and then Etype (T) /= T
4835 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4836 then
4837 null;
4838 else
4839 Collect (Iface);
4840 Append_Unique_Elmt (Iface, Ifaces_List);
4841 end if;
4842 end if;
4844 Next (Id);
4845 end loop;
4846 end if;
4847 end Collect;
4849 -- Start of processing for Collect_Interfaces
4851 begin
4852 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4853 Ifaces_List := New_Elmt_List;
4854 Collect (T);
4855 end Collect_Interfaces;
4857 ----------------------------------
4858 -- Collect_Interface_Components --
4859 ----------------------------------
4861 procedure Collect_Interface_Components
4862 (Tagged_Type : Entity_Id;
4863 Components_List : out Elist_Id)
4865 procedure Collect (Typ : Entity_Id);
4866 -- Subsidiary subprogram used to climb to the parents
4868 -------------
4869 -- Collect --
4870 -------------
4872 procedure Collect (Typ : Entity_Id) is
4873 Tag_Comp : Entity_Id;
4874 Parent_Typ : Entity_Id;
4876 begin
4877 -- Handle private types
4879 if Present (Full_View (Etype (Typ))) then
4880 Parent_Typ := Full_View (Etype (Typ));
4881 else
4882 Parent_Typ := Etype (Typ);
4883 end if;
4885 if Parent_Typ /= Typ
4887 -- Protect the frontend against wrong sources. For example:
4889 -- package P is
4890 -- type A is tagged null record;
4891 -- type B is new A with private;
4892 -- type C is new A with private;
4893 -- private
4894 -- type B is new C with null record;
4895 -- type C is new B with null record;
4896 -- end P;
4898 and then Parent_Typ /= Tagged_Type
4899 then
4900 Collect (Parent_Typ);
4901 end if;
4903 -- Collect the components containing tags of secondary dispatch
4904 -- tables.
4906 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4907 while Present (Tag_Comp) loop
4908 pragma Assert (Present (Related_Type (Tag_Comp)));
4909 Append_Elmt (Tag_Comp, Components_List);
4911 Tag_Comp := Next_Tag_Component (Tag_Comp);
4912 end loop;
4913 end Collect;
4915 -- Start of processing for Collect_Interface_Components
4917 begin
4918 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4919 and then Is_Tagged_Type (Tagged_Type));
4921 Components_List := New_Elmt_List;
4922 Collect (Tagged_Type);
4923 end Collect_Interface_Components;
4925 -----------------------------
4926 -- Collect_Interfaces_Info --
4927 -----------------------------
4929 procedure Collect_Interfaces_Info
4930 (T : Entity_Id;
4931 Ifaces_List : out Elist_Id;
4932 Components_List : out Elist_Id;
4933 Tags_List : out Elist_Id)
4935 Comps_List : Elist_Id;
4936 Comp_Elmt : Elmt_Id;
4937 Comp_Iface : Entity_Id;
4938 Iface_Elmt : Elmt_Id;
4939 Iface : Entity_Id;
4941 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4942 -- Search for the secondary tag associated with the interface type
4943 -- Iface that is implemented by T.
4945 ----------------
4946 -- Search_Tag --
4947 ----------------
4949 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4950 ADT : Elmt_Id;
4951 begin
4952 if not Is_CPP_Class (T) then
4953 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4954 else
4955 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4956 end if;
4958 while Present (ADT)
4959 and then Is_Tag (Node (ADT))
4960 and then Related_Type (Node (ADT)) /= Iface
4961 loop
4962 -- Skip secondary dispatch table referencing thunks to user
4963 -- defined primitives covered by this interface.
4965 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4966 Next_Elmt (ADT);
4968 -- Skip secondary dispatch tables of Ada types
4970 if not Is_CPP_Class (T) then
4972 -- Skip secondary dispatch table referencing thunks to
4973 -- predefined primitives.
4975 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4976 Next_Elmt (ADT);
4978 -- Skip secondary dispatch table referencing user-defined
4979 -- primitives covered by this interface.
4981 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4982 Next_Elmt (ADT);
4984 -- Skip secondary dispatch table referencing predefined
4985 -- primitives.
4987 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4988 Next_Elmt (ADT);
4989 end if;
4990 end loop;
4992 pragma Assert (Is_Tag (Node (ADT)));
4993 return Node (ADT);
4994 end Search_Tag;
4996 -- Start of processing for Collect_Interfaces_Info
4998 begin
4999 Collect_Interfaces (T, Ifaces_List);
5000 Collect_Interface_Components (T, Comps_List);
5002 -- Search for the record component and tag associated with each
5003 -- interface type of T.
5005 Components_List := New_Elmt_List;
5006 Tags_List := New_Elmt_List;
5008 Iface_Elmt := First_Elmt (Ifaces_List);
5009 while Present (Iface_Elmt) loop
5010 Iface := Node (Iface_Elmt);
5012 -- Associate the primary tag component and the primary dispatch table
5013 -- with all the interfaces that are parents of T
5015 if Is_Ancestor (Iface, T, Use_Full_View => True) then
5016 Append_Elmt (First_Tag_Component (T), Components_List);
5017 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
5019 -- Otherwise search for the tag component and secondary dispatch
5020 -- table of Iface
5022 else
5023 Comp_Elmt := First_Elmt (Comps_List);
5024 while Present (Comp_Elmt) loop
5025 Comp_Iface := Related_Type (Node (Comp_Elmt));
5027 if Comp_Iface = Iface
5028 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
5029 then
5030 Append_Elmt (Node (Comp_Elmt), Components_List);
5031 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
5032 exit;
5033 end if;
5035 Next_Elmt (Comp_Elmt);
5036 end loop;
5037 pragma Assert (Present (Comp_Elmt));
5038 end if;
5040 Next_Elmt (Iface_Elmt);
5041 end loop;
5042 end Collect_Interfaces_Info;
5044 ---------------------
5045 -- Collect_Parents --
5046 ---------------------
5048 procedure Collect_Parents
5049 (T : Entity_Id;
5050 List : out Elist_Id;
5051 Use_Full_View : Boolean := True)
5053 Current_Typ : Entity_Id := T;
5054 Parent_Typ : Entity_Id;
5056 begin
5057 List := New_Elmt_List;
5059 -- No action if the if the type has no parents
5061 if T = Etype (T) then
5062 return;
5063 end if;
5065 loop
5066 Parent_Typ := Etype (Current_Typ);
5068 if Is_Private_Type (Parent_Typ)
5069 and then Present (Full_View (Parent_Typ))
5070 and then Use_Full_View
5071 then
5072 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5073 end if;
5075 Append_Elmt (Parent_Typ, List);
5077 exit when Parent_Typ = Current_Typ;
5078 Current_Typ := Parent_Typ;
5079 end loop;
5080 end Collect_Parents;
5082 ----------------------------------
5083 -- Collect_Primitive_Operations --
5084 ----------------------------------
5086 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
5087 B_Type : constant Entity_Id := Base_Type (T);
5089 function Match (E : Entity_Id) return Boolean;
5090 -- True if E's base type is B_Type, or E is of an anonymous access type
5091 -- and the base type of its designated type is B_Type.
5093 -----------
5094 -- Match --
5095 -----------
5097 function Match (E : Entity_Id) return Boolean is
5098 Etyp : Entity_Id := Etype (E);
5100 begin
5101 if Ekind (Etyp) = E_Anonymous_Access_Type then
5102 Etyp := Designated_Type (Etyp);
5103 end if;
5105 -- In Ada 2012 a primitive operation may have a formal of an
5106 -- incomplete view of the parent type.
5108 return Base_Type (Etyp) = B_Type
5109 or else
5110 (Ada_Version >= Ada_2012
5111 and then Ekind (Etyp) = E_Incomplete_Type
5112 and then Full_View (Etyp) = B_Type);
5113 end Match;
5115 -- Local variables
5117 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
5118 B_Scope : Entity_Id := Scope (B_Type);
5119 Op_List : Elist_Id;
5120 Eq_Prims_List : Elist_Id := No_Elist;
5121 Formal : Entity_Id;
5122 Is_Prim : Boolean;
5123 Is_Type_In_Pkg : Boolean;
5124 Formal_Derived : Boolean := False;
5125 Id : Entity_Id;
5127 -- Start of processing for Collect_Primitive_Operations
5129 begin
5130 -- For tagged types, the primitive operations are collected as they
5131 -- are declared, and held in an explicit list which is simply returned.
5133 if Is_Tagged_Type (B_Type) then
5134 return Primitive_Operations (B_Type);
5136 -- An untagged generic type that is a derived type inherits the
5137 -- primitive operations of its parent type. Other formal types only
5138 -- have predefined operators, which are not explicitly represented.
5140 elsif Is_Generic_Type (B_Type) then
5141 if Nkind (B_Decl) = N_Formal_Type_Declaration
5142 and then Nkind (Formal_Type_Definition (B_Decl)) =
5143 N_Formal_Derived_Type_Definition
5144 then
5145 Formal_Derived := True;
5146 else
5147 return New_Elmt_List;
5148 end if;
5149 end if;
5151 Op_List := New_Elmt_List;
5153 if B_Scope = Standard_Standard then
5154 if B_Type = Standard_String then
5155 Append_Elmt (Standard_Op_Concat, Op_List);
5157 elsif B_Type = Standard_Wide_String then
5158 Append_Elmt (Standard_Op_Concatw, Op_List);
5160 else
5161 null;
5162 end if;
5164 -- Locate the primitive subprograms of the type
5166 else
5167 -- The primitive operations appear after the base type, except if the
5168 -- derivation happens within the private part of B_Scope and the type
5169 -- is a private type, in which case both the type and some primitive
5170 -- operations may appear before the base type, and the list of
5171 -- candidates starts after the type.
5173 if In_Open_Scopes (B_Scope)
5174 and then Scope (T) = B_Scope
5175 and then In_Private_Part (B_Scope)
5176 then
5177 Id := Next_Entity (T);
5179 -- In Ada 2012, If the type has an incomplete partial view, there may
5180 -- be primitive operations declared before the full view, so we need
5181 -- to start scanning from the incomplete view, which is earlier on
5182 -- the entity chain.
5184 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
5185 and then Present (Incomplete_View (Parent (B_Type)))
5186 then
5187 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
5189 -- If T is a derived from a type with an incomplete view declared
5190 -- elsewhere, that incomplete view is irrelevant, we want the
5191 -- operations in the scope of T.
5193 if Scope (Id) /= Scope (B_Type) then
5194 Id := Next_Entity (B_Type);
5195 end if;
5197 else
5198 Id := Next_Entity (B_Type);
5199 end if;
5201 -- Set flag if this is a type in a package spec
5203 Is_Type_In_Pkg :=
5204 Is_Package_Or_Generic_Package (B_Scope)
5205 and then
5206 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
5207 N_Package_Body;
5209 while Present (Id) loop
5211 -- Test whether the result type or any of the parameter types of
5212 -- each subprogram following the type match that type when the
5213 -- type is declared in a package spec, is a derived type, or the
5214 -- subprogram is marked as primitive. (The Is_Primitive test is
5215 -- needed to find primitives of nonderived types in declarative
5216 -- parts that happen to override the predefined "=" operator.)
5218 -- Note that generic formal subprograms are not considered to be
5219 -- primitive operations and thus are never inherited.
5221 if Is_Overloadable (Id)
5222 and then (Is_Type_In_Pkg
5223 or else Is_Derived_Type (B_Type)
5224 or else Is_Primitive (Id))
5225 and then Nkind (Parent (Parent (Id)))
5226 not in N_Formal_Subprogram_Declaration
5227 then
5228 Is_Prim := False;
5230 if Match (Id) then
5231 Is_Prim := True;
5233 else
5234 Formal := First_Formal (Id);
5235 while Present (Formal) loop
5236 if Match (Formal) then
5237 Is_Prim := True;
5238 exit;
5239 end if;
5241 Next_Formal (Formal);
5242 end loop;
5243 end if;
5245 -- For a formal derived type, the only primitives are the ones
5246 -- inherited from the parent type. Operations appearing in the
5247 -- package declaration are not primitive for it.
5249 if Is_Prim
5250 and then (not Formal_Derived or else Present (Alias (Id)))
5251 then
5252 -- In the special case of an equality operator aliased to
5253 -- an overriding dispatching equality belonging to the same
5254 -- type, we don't include it in the list of primitives.
5255 -- This avoids inheriting multiple equality operators when
5256 -- deriving from untagged private types whose full type is
5257 -- tagged, which can otherwise cause ambiguities. Note that
5258 -- this should only happen for this kind of untagged parent
5259 -- type, since normally dispatching operations are inherited
5260 -- using the type's Primitive_Operations list.
5262 if Chars (Id) = Name_Op_Eq
5263 and then Is_Dispatching_Operation (Id)
5264 and then Present (Alias (Id))
5265 and then Present (Overridden_Operation (Alias (Id)))
5266 and then Base_Type (Etype (First_Entity (Id))) =
5267 Base_Type (Etype (First_Entity (Alias (Id))))
5268 then
5269 null;
5271 -- Include the subprogram in the list of primitives
5273 else
5274 Append_Elmt (Id, Op_List);
5276 -- Save collected equality primitives for later filtering
5277 -- (if we are processing a private type for which we can
5278 -- collect several candidates).
5280 if Inherits_From_Tagged_Full_View (T)
5281 and then Chars (Id) = Name_Op_Eq
5282 and then Etype (First_Formal (Id)) =
5283 Etype (Next_Formal (First_Formal (Id)))
5284 then
5285 if No (Eq_Prims_List) then
5286 Eq_Prims_List := New_Elmt_List;
5287 end if;
5289 Append_Elmt (Id, Eq_Prims_List);
5290 end if;
5291 end if;
5292 end if;
5293 end if;
5295 Next_Entity (Id);
5297 -- For a type declared in System, some of its operations may
5298 -- appear in the target-specific extension to System.
5300 if No (Id)
5301 and then B_Scope = RTU_Entity (System)
5302 and then Present_System_Aux
5303 then
5304 B_Scope := System_Aux_Id;
5305 Id := First_Entity (System_Aux_Id);
5306 end if;
5307 end loop;
5309 -- Filter collected equality primitives
5311 if Inherits_From_Tagged_Full_View (T)
5312 and then Present (Eq_Prims_List)
5313 then
5314 declare
5315 First : constant Elmt_Id := First_Elmt (Eq_Prims_List);
5316 Second : Elmt_Id;
5318 begin
5319 pragma Assert (No (Next_Elmt (First))
5320 or else No (Next_Elmt (Next_Elmt (First))));
5322 -- No action needed if we have collected a single equality
5323 -- primitive
5325 if Present (Next_Elmt (First)) then
5326 Second := Next_Elmt (First);
5328 if Is_Dispatching_Operation
5329 (Ultimate_Alias (Node (First)))
5330 then
5331 Remove (Op_List, Node (First));
5333 elsif Is_Dispatching_Operation
5334 (Ultimate_Alias (Node (Second)))
5335 then
5336 Remove (Op_List, Node (Second));
5338 else
5339 pragma Assert (False);
5340 raise Program_Error;
5341 end if;
5342 end if;
5343 end;
5344 end if;
5345 end if;
5347 return Op_List;
5348 end Collect_Primitive_Operations;
5350 -----------------------------------
5351 -- Compile_Time_Constraint_Error --
5352 -----------------------------------
5354 function Compile_Time_Constraint_Error
5355 (N : Node_Id;
5356 Msg : String;
5357 Ent : Entity_Id := Empty;
5358 Loc : Source_Ptr := No_Location;
5359 Warn : Boolean := False) return Node_Id
5361 Msgc : String (1 .. Msg'Length + 3);
5362 -- Copy of message, with room for possible ?? or << and ! at end
5364 Msgl : Natural;
5365 Wmsg : Boolean;
5366 Eloc : Source_Ptr;
5368 -- Start of processing for Compile_Time_Constraint_Error
5370 begin
5371 -- If this is a warning, convert it into an error if we are in code
5372 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5373 -- warning. The rationale is that a compile-time constraint error should
5374 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5375 -- a few cases we prefer to issue a warning and generate both a suitable
5376 -- run-time error in GNAT and a suitable check message in GNATprove.
5377 -- Those cases are those that likely correspond to deactivated SPARK
5378 -- code, so that this kind of code can be compiled and analyzed instead
5379 -- of being rejected.
5381 Error_Msg_Warn := Warn or SPARK_Mode /= On;
5383 -- A static constraint error in an instance body is not a fatal error.
5384 -- we choose to inhibit the message altogether, because there is no
5385 -- obvious node (for now) on which to post it. On the other hand the
5386 -- offending node must be replaced with a constraint_error in any case.
5388 -- No messages are generated if we already posted an error on this node
5390 if not Error_Posted (N) then
5391 if Loc /= No_Location then
5392 Eloc := Loc;
5393 else
5394 Eloc := Sloc (N);
5395 end if;
5397 -- Copy message to Msgc, converting any ? in the message into <
5398 -- instead, so that we have an error in GNATprove mode.
5400 Msgl := Msg'Length;
5402 for J in 1 .. Msgl loop
5403 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
5404 Msgc (J) := '<';
5405 else
5406 Msgc (J) := Msg (J);
5407 end if;
5408 end loop;
5410 -- Message is a warning, even in Ada 95 case
5412 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
5413 Wmsg := True;
5415 -- In Ada 83, all messages are warnings. In the private part and the
5416 -- body of an instance, constraint_checks are only warnings. We also
5417 -- make this a warning if the Warn parameter is set.
5419 elsif Warn
5420 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
5421 or else In_Instance_Not_Visible
5422 then
5423 Msgl := Msgl + 1;
5424 Msgc (Msgl) := '<';
5425 Msgl := Msgl + 1;
5426 Msgc (Msgl) := '<';
5427 Wmsg := True;
5429 -- Otherwise we have a real error message (Ada 95 static case) and we
5430 -- make this an unconditional message. Note that in the warning case
5431 -- we do not make the message unconditional, it seems reasonable to
5432 -- delete messages like this (about exceptions that will be raised)
5433 -- in dead code.
5435 else
5436 Wmsg := False;
5437 Msgl := Msgl + 1;
5438 Msgc (Msgl) := '!';
5439 end if;
5441 -- One more test, skip the warning if the related expression is
5442 -- statically unevaluated, since we don't want to warn about what
5443 -- will happen when something is evaluated if it never will be
5444 -- evaluated.
5446 if not Is_Statically_Unevaluated (N) then
5447 if Present (Ent) then
5448 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
5449 else
5450 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
5451 end if;
5453 if Wmsg then
5455 -- Check whether the context is an Init_Proc
5457 if Inside_Init_Proc then
5458 declare
5459 Conc_Typ : constant Entity_Id :=
5460 Corresponding_Concurrent_Type
5461 (Entity (Parameter_Type (First
5462 (Parameter_Specifications
5463 (Parent (Current_Scope))))));
5465 begin
5466 -- Don't complain if the corresponding concurrent type
5467 -- doesn't come from source (i.e. a single task/protected
5468 -- object).
5470 if Present (Conc_Typ)
5471 and then not Comes_From_Source (Conc_Typ)
5472 then
5473 Error_Msg_NEL
5474 ("\& [<<", N, Standard_Constraint_Error, Eloc);
5476 else
5477 if GNATprove_Mode then
5478 Error_Msg_NEL
5479 ("\& would have been raised for objects of this "
5480 & "type", N, Standard_Constraint_Error, Eloc);
5481 else
5482 Error_Msg_NEL
5483 ("\& will be raised for objects of this type??",
5484 N, Standard_Constraint_Error, Eloc);
5485 end if;
5486 end if;
5487 end;
5489 else
5490 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
5491 end if;
5493 else
5494 Error_Msg ("\static expression fails Constraint_Check", Eloc);
5495 Set_Error_Posted (N);
5496 end if;
5497 end if;
5498 end if;
5500 return N;
5501 end Compile_Time_Constraint_Error;
5503 -----------------------
5504 -- Conditional_Delay --
5505 -----------------------
5507 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
5508 begin
5509 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
5510 Set_Has_Delayed_Freeze (New_Ent);
5511 end if;
5512 end Conditional_Delay;
5514 -------------------------
5515 -- Copy_Component_List --
5516 -------------------------
5518 function Copy_Component_List
5519 (R_Typ : Entity_Id;
5520 Loc : Source_Ptr) return List_Id
5522 Comp : Node_Id;
5523 Comps : constant List_Id := New_List;
5525 begin
5526 Comp := First_Component (Underlying_Type (R_Typ));
5527 while Present (Comp) loop
5528 if Comes_From_Source (Comp) then
5529 declare
5530 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
5531 begin
5532 Append_To (Comps,
5533 Make_Component_Declaration (Loc,
5534 Defining_Identifier =>
5535 Make_Defining_Identifier (Loc, Chars (Comp)),
5536 Component_Definition =>
5537 New_Copy_Tree
5538 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
5539 end;
5540 end if;
5542 Next_Component (Comp);
5543 end loop;
5545 return Comps;
5546 end Copy_Component_List;
5548 -------------------------
5549 -- Copy_Parameter_List --
5550 -------------------------
5552 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
5553 Loc : constant Source_Ptr := Sloc (Subp_Id);
5554 Plist : List_Id;
5555 Formal : Entity_Id;
5557 begin
5558 if No (First_Formal (Subp_Id)) then
5559 return No_List;
5560 else
5561 Plist := New_List;
5562 Formal := First_Formal (Subp_Id);
5563 while Present (Formal) loop
5564 Append_To (Plist,
5565 Make_Parameter_Specification (Loc,
5566 Defining_Identifier =>
5567 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
5568 In_Present => In_Present (Parent (Formal)),
5569 Out_Present => Out_Present (Parent (Formal)),
5570 Parameter_Type =>
5571 New_Occurrence_Of (Etype (Formal), Loc),
5572 Expression =>
5573 New_Copy_Tree (Expression (Parent (Formal)))));
5575 Next_Formal (Formal);
5576 end loop;
5577 end if;
5579 return Plist;
5580 end Copy_Parameter_List;
5582 ----------------------------
5583 -- Copy_SPARK_Mode_Aspect --
5584 ----------------------------
5586 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
5587 pragma Assert (not Has_Aspects (To));
5588 Asp : Node_Id;
5590 begin
5591 if Has_Aspects (From) then
5592 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
5594 if Present (Asp) then
5595 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
5596 Set_Has_Aspects (To, True);
5597 end if;
5598 end if;
5599 end Copy_SPARK_Mode_Aspect;
5601 --------------------------
5602 -- Copy_Subprogram_Spec --
5603 --------------------------
5605 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
5606 Def_Id : Node_Id;
5607 Formal_Spec : Node_Id;
5608 Result : Node_Id;
5610 begin
5611 -- The structure of the original tree must be replicated without any
5612 -- alterations. Use New_Copy_Tree for this purpose.
5614 Result := New_Copy_Tree (Spec);
5616 -- However, the spec of a null procedure carries the corresponding null
5617 -- statement of the body (created by the parser), and this cannot be
5618 -- shared with the new subprogram spec.
5620 if Nkind (Result) = N_Procedure_Specification then
5621 Set_Null_Statement (Result, Empty);
5622 end if;
5624 -- Create a new entity for the defining unit name
5626 Def_Id := Defining_Unit_Name (Result);
5627 Set_Defining_Unit_Name (Result,
5628 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5630 -- Create new entities for the formal parameters
5632 if Present (Parameter_Specifications (Result)) then
5633 Formal_Spec := First (Parameter_Specifications (Result));
5634 while Present (Formal_Spec) loop
5635 Def_Id := Defining_Identifier (Formal_Spec);
5636 Set_Defining_Identifier (Formal_Spec,
5637 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5639 Next (Formal_Spec);
5640 end loop;
5641 end if;
5643 return Result;
5644 end Copy_Subprogram_Spec;
5646 --------------------------------
5647 -- Corresponding_Generic_Type --
5648 --------------------------------
5650 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5651 Inst : Entity_Id;
5652 Gen : Entity_Id;
5653 Typ : Entity_Id;
5655 begin
5656 if not Is_Generic_Actual_Type (T) then
5657 return Any_Type;
5659 -- If the actual is the actual of an enclosing instance, resolution
5660 -- was correct in the generic.
5662 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5663 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5664 and then
5665 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5666 then
5667 return Any_Type;
5669 else
5670 Inst := Scope (T);
5672 if Is_Wrapper_Package (Inst) then
5673 Inst := Related_Instance (Inst);
5674 end if;
5676 Gen :=
5677 Generic_Parent
5678 (Specification (Unit_Declaration_Node (Inst)));
5680 -- Generic actual has the same name as the corresponding formal
5682 Typ := First_Entity (Gen);
5683 while Present (Typ) loop
5684 if Chars (Typ) = Chars (T) then
5685 return Typ;
5686 end if;
5688 Next_Entity (Typ);
5689 end loop;
5691 return Any_Type;
5692 end if;
5693 end Corresponding_Generic_Type;
5695 --------------------
5696 -- Current_Entity --
5697 --------------------
5699 -- The currently visible definition for a given identifier is the
5700 -- one most chained at the start of the visibility chain, i.e. the
5701 -- one that is referenced by the Node_Id value of the name of the
5702 -- given identifier.
5704 function Current_Entity (N : Node_Id) return Entity_Id is
5705 begin
5706 return Get_Name_Entity_Id (Chars (N));
5707 end Current_Entity;
5709 -----------------------------
5710 -- Current_Entity_In_Scope --
5711 -----------------------------
5713 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5714 E : Entity_Id;
5715 CS : constant Entity_Id := Current_Scope;
5717 Transient_Case : constant Boolean := Scope_Is_Transient;
5719 begin
5720 E := Get_Name_Entity_Id (Chars (N));
5721 while Present (E)
5722 and then Scope (E) /= CS
5723 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5724 loop
5725 E := Homonym (E);
5726 end loop;
5728 return E;
5729 end Current_Entity_In_Scope;
5731 -------------------
5732 -- Current_Scope --
5733 -------------------
5735 function Current_Scope return Entity_Id is
5736 begin
5737 if Scope_Stack.Last = -1 then
5738 return Standard_Standard;
5739 else
5740 declare
5741 C : constant Entity_Id :=
5742 Scope_Stack.Table (Scope_Stack.Last).Entity;
5743 begin
5744 if Present (C) then
5745 return C;
5746 else
5747 return Standard_Standard;
5748 end if;
5749 end;
5750 end if;
5751 end Current_Scope;
5753 ----------------------------
5754 -- Current_Scope_No_Loops --
5755 ----------------------------
5757 function Current_Scope_No_Loops return Entity_Id is
5758 S : Entity_Id;
5760 begin
5761 -- Examine the scope stack starting from the current scope and skip any
5762 -- internally generated loops.
5764 S := Current_Scope;
5765 while Present (S) and then S /= Standard_Standard loop
5766 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5767 S := Scope (S);
5768 else
5769 exit;
5770 end if;
5771 end loop;
5773 return S;
5774 end Current_Scope_No_Loops;
5776 ------------------------
5777 -- Current_Subprogram --
5778 ------------------------
5780 function Current_Subprogram return Entity_Id is
5781 Scop : constant Entity_Id := Current_Scope;
5782 begin
5783 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5784 return Scop;
5785 else
5786 return Enclosing_Subprogram (Scop);
5787 end if;
5788 end Current_Subprogram;
5790 ----------------------------------
5791 -- Deepest_Type_Access_Level --
5792 ----------------------------------
5794 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5795 begin
5796 if Ekind (Typ) = E_Anonymous_Access_Type
5797 and then not Is_Local_Anonymous_Access (Typ)
5798 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5799 then
5800 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5801 -- access type.
5803 return
5804 Scope_Depth (Enclosing_Dynamic_Scope
5805 (Defining_Identifier
5806 (Associated_Node_For_Itype (Typ))));
5808 -- For generic formal type, return Int'Last (infinite).
5809 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5811 elsif Is_Generic_Type (Root_Type (Typ)) then
5812 return UI_From_Int (Int'Last);
5814 else
5815 return Type_Access_Level (Typ);
5816 end if;
5817 end Deepest_Type_Access_Level;
5819 ---------------------
5820 -- Defining_Entity --
5821 ---------------------
5823 function Defining_Entity
5824 (N : Node_Id;
5825 Empty_On_Errors : Boolean := False;
5826 Concurrent_Subunit : Boolean := False) return Entity_Id
5828 begin
5829 case Nkind (N) is
5830 when N_Abstract_Subprogram_Declaration
5831 | N_Expression_Function
5832 | N_Formal_Subprogram_Declaration
5833 | N_Generic_Package_Declaration
5834 | N_Generic_Subprogram_Declaration
5835 | N_Package_Declaration
5836 | N_Subprogram_Body
5837 | N_Subprogram_Body_Stub
5838 | N_Subprogram_Declaration
5839 | N_Subprogram_Renaming_Declaration
5841 return Defining_Entity (Specification (N));
5843 when N_Component_Declaration
5844 | N_Defining_Program_Unit_Name
5845 | N_Discriminant_Specification
5846 | N_Entry_Body
5847 | N_Entry_Declaration
5848 | N_Entry_Index_Specification
5849 | N_Exception_Declaration
5850 | N_Exception_Renaming_Declaration
5851 | N_Formal_Object_Declaration
5852 | N_Formal_Package_Declaration
5853 | N_Formal_Type_Declaration
5854 | N_Full_Type_Declaration
5855 | N_Implicit_Label_Declaration
5856 | N_Incomplete_Type_Declaration
5857 | N_Iterator_Specification
5858 | N_Loop_Parameter_Specification
5859 | N_Number_Declaration
5860 | N_Object_Declaration
5861 | N_Object_Renaming_Declaration
5862 | N_Package_Body_Stub
5863 | N_Parameter_Specification
5864 | N_Private_Extension_Declaration
5865 | N_Private_Type_Declaration
5866 | N_Protected_Body
5867 | N_Protected_Body_Stub
5868 | N_Protected_Type_Declaration
5869 | N_Single_Protected_Declaration
5870 | N_Single_Task_Declaration
5871 | N_Subtype_Declaration
5872 | N_Task_Body
5873 | N_Task_Body_Stub
5874 | N_Task_Type_Declaration
5876 return Defining_Identifier (N);
5878 when N_Subunit =>
5879 declare
5880 Bod : constant Node_Id := Proper_Body (N);
5881 Orig_Bod : constant Node_Id := Original_Node (Bod);
5883 begin
5884 -- Retrieve the entity of the original protected or task body
5885 -- if requested by the caller.
5887 if Concurrent_Subunit
5888 and then Nkind (Bod) = N_Null_Statement
5889 and then Nkind_In (Orig_Bod, N_Protected_Body, N_Task_Body)
5890 then
5891 return Defining_Entity (Orig_Bod);
5892 else
5893 return Defining_Entity (Bod);
5894 end if;
5895 end;
5897 when N_Function_Instantiation
5898 | N_Function_Specification
5899 | N_Generic_Function_Renaming_Declaration
5900 | N_Generic_Package_Renaming_Declaration
5901 | N_Generic_Procedure_Renaming_Declaration
5902 | N_Package_Body
5903 | N_Package_Instantiation
5904 | N_Package_Renaming_Declaration
5905 | N_Package_Specification
5906 | N_Procedure_Instantiation
5907 | N_Procedure_Specification
5909 declare
5910 Nam : constant Node_Id := Defining_Unit_Name (N);
5911 Err : Entity_Id := Empty;
5913 begin
5914 if Nkind (Nam) in N_Entity then
5915 return Nam;
5917 -- For Error, make up a name and attach to declaration so we
5918 -- can continue semantic analysis.
5920 elsif Nam = Error then
5921 if Empty_On_Errors then
5922 return Empty;
5923 else
5924 Err := Make_Temporary (Sloc (N), 'T');
5925 Set_Defining_Unit_Name (N, Err);
5927 return Err;
5928 end if;
5930 -- If not an entity, get defining identifier
5932 else
5933 return Defining_Identifier (Nam);
5934 end if;
5935 end;
5937 when N_Block_Statement
5938 | N_Loop_Statement
5940 return Entity (Identifier (N));
5942 when others =>
5943 if Empty_On_Errors then
5944 return Empty;
5945 else
5946 raise Program_Error;
5947 end if;
5948 end case;
5949 end Defining_Entity;
5951 --------------------------
5952 -- Denotes_Discriminant --
5953 --------------------------
5955 function Denotes_Discriminant
5956 (N : Node_Id;
5957 Check_Concurrent : Boolean := False) return Boolean
5959 E : Entity_Id;
5961 begin
5962 if not Is_Entity_Name (N) or else No (Entity (N)) then
5963 return False;
5964 else
5965 E := Entity (N);
5966 end if;
5968 -- If we are checking for a protected type, the discriminant may have
5969 -- been rewritten as the corresponding discriminal of the original type
5970 -- or of the corresponding concurrent record, depending on whether we
5971 -- are in the spec or body of the protected type.
5973 return Ekind (E) = E_Discriminant
5974 or else
5975 (Check_Concurrent
5976 and then Ekind (E) = E_In_Parameter
5977 and then Present (Discriminal_Link (E))
5978 and then
5979 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5980 or else
5981 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5982 end Denotes_Discriminant;
5984 -------------------------
5985 -- Denotes_Same_Object --
5986 -------------------------
5988 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5989 Obj1 : Node_Id := A1;
5990 Obj2 : Node_Id := A2;
5992 function Has_Prefix (N : Node_Id) return Boolean;
5993 -- Return True if N has attribute Prefix
5995 function Is_Renaming (N : Node_Id) return Boolean;
5996 -- Return true if N names a renaming entity
5998 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5999 -- For renamings, return False if the prefix of any dereference within
6000 -- the renamed object_name is a variable, or any expression within the
6001 -- renamed object_name contains references to variables or calls on
6002 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
6004 ----------------
6005 -- Has_Prefix --
6006 ----------------
6008 function Has_Prefix (N : Node_Id) return Boolean is
6009 begin
6010 return
6011 Nkind_In (N,
6012 N_Attribute_Reference,
6013 N_Expanded_Name,
6014 N_Explicit_Dereference,
6015 N_Indexed_Component,
6016 N_Reference,
6017 N_Selected_Component,
6018 N_Slice);
6019 end Has_Prefix;
6021 -----------------
6022 -- Is_Renaming --
6023 -----------------
6025 function Is_Renaming (N : Node_Id) return Boolean is
6026 begin
6027 return Is_Entity_Name (N)
6028 and then Present (Renamed_Entity (Entity (N)));
6029 end Is_Renaming;
6031 -----------------------
6032 -- Is_Valid_Renaming --
6033 -----------------------
6035 function Is_Valid_Renaming (N : Node_Id) return Boolean is
6037 function Check_Renaming (N : Node_Id) return Boolean;
6038 -- Recursive function used to traverse all the prefixes of N
6040 function Check_Renaming (N : Node_Id) return Boolean is
6041 begin
6042 if Is_Renaming (N)
6043 and then not Check_Renaming (Renamed_Entity (Entity (N)))
6044 then
6045 return False;
6046 end if;
6048 if Nkind (N) = N_Indexed_Component then
6049 declare
6050 Indx : Node_Id;
6052 begin
6053 Indx := First (Expressions (N));
6054 while Present (Indx) loop
6055 if not Is_OK_Static_Expression (Indx) then
6056 return False;
6057 end if;
6059 Next_Index (Indx);
6060 end loop;
6061 end;
6062 end if;
6064 if Has_Prefix (N) then
6065 declare
6066 P : constant Node_Id := Prefix (N);
6068 begin
6069 if Nkind (N) = N_Explicit_Dereference
6070 and then Is_Variable (P)
6071 then
6072 return False;
6074 elsif Is_Entity_Name (P)
6075 and then Ekind (Entity (P)) = E_Function
6076 then
6077 return False;
6079 elsif Nkind (P) = N_Function_Call then
6080 return False;
6081 end if;
6083 -- Recursion to continue traversing the prefix of the
6084 -- renaming expression
6086 return Check_Renaming (P);
6087 end;
6088 end if;
6090 return True;
6091 end Check_Renaming;
6093 -- Start of processing for Is_Valid_Renaming
6095 begin
6096 return Check_Renaming (N);
6097 end Is_Valid_Renaming;
6099 -- Start of processing for Denotes_Same_Object
6101 begin
6102 -- Both names statically denote the same stand-alone object or parameter
6103 -- (RM 6.4.1(6.5/3))
6105 if Is_Entity_Name (Obj1)
6106 and then Is_Entity_Name (Obj2)
6107 and then Entity (Obj1) = Entity (Obj2)
6108 then
6109 return True;
6110 end if;
6112 -- For renamings, the prefix of any dereference within the renamed
6113 -- object_name is not a variable, and any expression within the
6114 -- renamed object_name contains no references to variables nor
6115 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
6117 if Is_Renaming (Obj1) then
6118 if Is_Valid_Renaming (Obj1) then
6119 Obj1 := Renamed_Entity (Entity (Obj1));
6120 else
6121 return False;
6122 end if;
6123 end if;
6125 if Is_Renaming (Obj2) then
6126 if Is_Valid_Renaming (Obj2) then
6127 Obj2 := Renamed_Entity (Entity (Obj2));
6128 else
6129 return False;
6130 end if;
6131 end if;
6133 -- No match if not same node kind (such cases are handled by
6134 -- Denotes_Same_Prefix)
6136 if Nkind (Obj1) /= Nkind (Obj2) then
6137 return False;
6139 -- After handling valid renamings, one of the two names statically
6140 -- denoted a renaming declaration whose renamed object_name is known
6141 -- to denote the same object as the other (RM 6.4.1(6.10/3))
6143 elsif Is_Entity_Name (Obj1) then
6144 if Is_Entity_Name (Obj2) then
6145 return Entity (Obj1) = Entity (Obj2);
6146 else
6147 return False;
6148 end if;
6150 -- Both names are selected_components, their prefixes are known to
6151 -- denote the same object, and their selector_names denote the same
6152 -- component (RM 6.4.1(6.6/3)).
6154 elsif Nkind (Obj1) = N_Selected_Component then
6155 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6156 and then
6157 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
6159 -- Both names are dereferences and the dereferenced names are known to
6160 -- denote the same object (RM 6.4.1(6.7/3))
6162 elsif Nkind (Obj1) = N_Explicit_Dereference then
6163 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
6165 -- Both names are indexed_components, their prefixes are known to denote
6166 -- the same object, and each of the pairs of corresponding index values
6167 -- are either both static expressions with the same static value or both
6168 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6170 elsif Nkind (Obj1) = N_Indexed_Component then
6171 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
6172 return False;
6173 else
6174 declare
6175 Indx1 : Node_Id;
6176 Indx2 : Node_Id;
6178 begin
6179 Indx1 := First (Expressions (Obj1));
6180 Indx2 := First (Expressions (Obj2));
6181 while Present (Indx1) loop
6183 -- Indexes must denote the same static value or same object
6185 if Is_OK_Static_Expression (Indx1) then
6186 if not Is_OK_Static_Expression (Indx2) then
6187 return False;
6189 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
6190 return False;
6191 end if;
6193 elsif not Denotes_Same_Object (Indx1, Indx2) then
6194 return False;
6195 end if;
6197 Next (Indx1);
6198 Next (Indx2);
6199 end loop;
6201 return True;
6202 end;
6203 end if;
6205 -- Both names are slices, their prefixes are known to denote the same
6206 -- object, and the two slices have statically matching index constraints
6207 -- (RM 6.4.1(6.9/3))
6209 elsif Nkind (Obj1) = N_Slice
6210 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
6211 then
6212 declare
6213 Lo1, Lo2, Hi1, Hi2 : Node_Id;
6215 begin
6216 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
6217 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
6219 -- Check whether bounds are statically identical. There is no
6220 -- attempt to detect partial overlap of slices.
6222 return Denotes_Same_Object (Lo1, Lo2)
6223 and then
6224 Denotes_Same_Object (Hi1, Hi2);
6225 end;
6227 -- In the recursion, literals appear as indexes
6229 elsif Nkind (Obj1) = N_Integer_Literal
6230 and then
6231 Nkind (Obj2) = N_Integer_Literal
6232 then
6233 return Intval (Obj1) = Intval (Obj2);
6235 else
6236 return False;
6237 end if;
6238 end Denotes_Same_Object;
6240 -------------------------
6241 -- Denotes_Same_Prefix --
6242 -------------------------
6244 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
6245 begin
6246 if Is_Entity_Name (A1) then
6247 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
6248 and then not Is_Access_Type (Etype (A1))
6249 then
6250 return Denotes_Same_Object (A1, Prefix (A2))
6251 or else Denotes_Same_Prefix (A1, Prefix (A2));
6252 else
6253 return False;
6254 end if;
6256 elsif Is_Entity_Name (A2) then
6257 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
6259 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
6260 and then
6261 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
6262 then
6263 declare
6264 Root1, Root2 : Node_Id;
6265 Depth1, Depth2 : Nat := 0;
6267 begin
6268 Root1 := Prefix (A1);
6269 while not Is_Entity_Name (Root1) loop
6270 if not Nkind_In
6271 (Root1, N_Selected_Component, N_Indexed_Component)
6272 then
6273 return False;
6274 else
6275 Root1 := Prefix (Root1);
6276 end if;
6278 Depth1 := Depth1 + 1;
6279 end loop;
6281 Root2 := Prefix (A2);
6282 while not Is_Entity_Name (Root2) loop
6283 if not Nkind_In (Root2, N_Selected_Component,
6284 N_Indexed_Component)
6285 then
6286 return False;
6287 else
6288 Root2 := Prefix (Root2);
6289 end if;
6291 Depth2 := Depth2 + 1;
6292 end loop;
6294 -- If both have the same depth and they do not denote the same
6295 -- object, they are disjoint and no warning is needed.
6297 if Depth1 = Depth2 then
6298 return False;
6300 elsif Depth1 > Depth2 then
6301 Root1 := Prefix (A1);
6302 for J in 1 .. Depth1 - Depth2 - 1 loop
6303 Root1 := Prefix (Root1);
6304 end loop;
6306 return Denotes_Same_Object (Root1, A2);
6308 else
6309 Root2 := Prefix (A2);
6310 for J in 1 .. Depth2 - Depth1 - 1 loop
6311 Root2 := Prefix (Root2);
6312 end loop;
6314 return Denotes_Same_Object (A1, Root2);
6315 end if;
6316 end;
6318 else
6319 return False;
6320 end if;
6321 end Denotes_Same_Prefix;
6323 ----------------------
6324 -- Denotes_Variable --
6325 ----------------------
6327 function Denotes_Variable (N : Node_Id) return Boolean is
6328 begin
6329 return Is_Variable (N) and then Paren_Count (N) = 0;
6330 end Denotes_Variable;
6332 -----------------------------
6333 -- Depends_On_Discriminant --
6334 -----------------------------
6336 function Depends_On_Discriminant (N : Node_Id) return Boolean is
6337 L : Node_Id;
6338 H : Node_Id;
6340 begin
6341 Get_Index_Bounds (N, L, H);
6342 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
6343 end Depends_On_Discriminant;
6345 -------------------------
6346 -- Designate_Same_Unit --
6347 -------------------------
6349 function Designate_Same_Unit
6350 (Name1 : Node_Id;
6351 Name2 : Node_Id) return Boolean
6353 K1 : constant Node_Kind := Nkind (Name1);
6354 K2 : constant Node_Kind := Nkind (Name2);
6356 function Prefix_Node (N : Node_Id) return Node_Id;
6357 -- Returns the parent unit name node of a defining program unit name
6358 -- or the prefix if N is a selected component or an expanded name.
6360 function Select_Node (N : Node_Id) return Node_Id;
6361 -- Returns the defining identifier node of a defining program unit
6362 -- name or the selector node if N is a selected component or an
6363 -- expanded name.
6365 -----------------
6366 -- Prefix_Node --
6367 -----------------
6369 function Prefix_Node (N : Node_Id) return Node_Id is
6370 begin
6371 if Nkind (N) = N_Defining_Program_Unit_Name then
6372 return Name (N);
6373 else
6374 return Prefix (N);
6375 end if;
6376 end Prefix_Node;
6378 -----------------
6379 -- Select_Node --
6380 -----------------
6382 function Select_Node (N : Node_Id) return Node_Id is
6383 begin
6384 if Nkind (N) = N_Defining_Program_Unit_Name then
6385 return Defining_Identifier (N);
6386 else
6387 return Selector_Name (N);
6388 end if;
6389 end Select_Node;
6391 -- Start of processing for Designate_Same_Unit
6393 begin
6394 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
6395 and then
6396 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
6397 then
6398 return Chars (Name1) = Chars (Name2);
6400 elsif Nkind_In (K1, N_Expanded_Name,
6401 N_Selected_Component,
6402 N_Defining_Program_Unit_Name)
6403 and then
6404 Nkind_In (K2, N_Expanded_Name,
6405 N_Selected_Component,
6406 N_Defining_Program_Unit_Name)
6407 then
6408 return
6409 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
6410 and then
6411 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
6413 else
6414 return False;
6415 end if;
6416 end Designate_Same_Unit;
6418 ---------------------------------------------
6419 -- Diagnose_Iterated_Component_Association --
6420 ---------------------------------------------
6422 procedure Diagnose_Iterated_Component_Association (N : Node_Id) is
6423 Def_Id : constant Entity_Id := Defining_Identifier (N);
6424 Aggr : Node_Id;
6426 begin
6427 -- Determine whether the iterated component association appears within
6428 -- an aggregate. If this is the case, raise Program_Error because the
6429 -- iterated component association cannot be left in the tree as is and
6430 -- must always be processed by the related aggregate.
6432 Aggr := N;
6433 while Present (Aggr) loop
6434 if Nkind (Aggr) = N_Aggregate then
6435 raise Program_Error;
6437 -- Prevent the search from going too far
6439 elsif Is_Body_Or_Package_Declaration (Aggr) then
6440 exit;
6441 end if;
6443 Aggr := Parent (Aggr);
6444 end loop;
6446 -- At this point it is known that the iterated component association is
6447 -- not within an aggregate. This is really a quantified expression with
6448 -- a missing "all" or "some" quantifier.
6450 Error_Msg_N ("missing quantifier", Def_Id);
6452 -- Rewrite the iterated component association as True to prevent any
6453 -- cascaded errors.
6455 Rewrite (N, New_Occurrence_Of (Standard_True, Sloc (N)));
6456 Analyze (N);
6457 end Diagnose_Iterated_Component_Association;
6459 ---------------------------------
6460 -- Dynamic_Accessibility_Level --
6461 ---------------------------------
6463 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
6464 Loc : constant Source_Ptr := Sloc (Expr);
6466 function Make_Level_Literal (Level : Uint) return Node_Id;
6467 -- Construct an integer literal representing an accessibility level
6468 -- with its type set to Natural.
6470 ------------------------
6471 -- Make_Level_Literal --
6472 ------------------------
6474 function Make_Level_Literal (Level : Uint) return Node_Id is
6475 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
6477 begin
6478 Set_Etype (Result, Standard_Natural);
6479 return Result;
6480 end Make_Level_Literal;
6482 -- Local variables
6484 E : Entity_Id;
6486 -- Start of processing for Dynamic_Accessibility_Level
6488 begin
6489 if Is_Entity_Name (Expr) then
6490 E := Entity (Expr);
6492 if Present (Renamed_Object (E)) then
6493 return Dynamic_Accessibility_Level (Renamed_Object (E));
6494 end if;
6496 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
6497 if Present (Extra_Accessibility (E)) then
6498 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
6499 end if;
6500 end if;
6501 end if;
6503 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6505 case Nkind (Expr) is
6507 -- For access discriminant, the level of the enclosing object
6509 when N_Selected_Component =>
6510 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
6511 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
6512 E_Anonymous_Access_Type
6513 then
6514 return Make_Level_Literal (Object_Access_Level (Expr));
6515 end if;
6517 when N_Attribute_Reference =>
6518 case Get_Attribute_Id (Attribute_Name (Expr)) is
6520 -- For X'Access, the level of the prefix X
6522 when Attribute_Access =>
6523 return Make_Level_Literal
6524 (Object_Access_Level (Prefix (Expr)));
6526 -- Treat the unchecked attributes as library-level
6528 when Attribute_Unchecked_Access
6529 | Attribute_Unrestricted_Access
6531 return Make_Level_Literal (Scope_Depth (Standard_Standard));
6533 -- No other access-valued attributes
6535 when others =>
6536 raise Program_Error;
6537 end case;
6539 when N_Allocator =>
6541 -- Unimplemented: depends on context. As an actual parameter where
6542 -- formal type is anonymous, use
6543 -- Scope_Depth (Current_Scope) + 1.
6544 -- For other cases, see 3.10.2(14/3) and following. ???
6546 null;
6548 when N_Type_Conversion =>
6549 if not Is_Local_Anonymous_Access (Etype (Expr)) then
6551 -- Handle type conversions introduced for a rename of an
6552 -- Ada 2012 stand-alone object of an anonymous access type.
6554 return Dynamic_Accessibility_Level (Expression (Expr));
6555 end if;
6557 when others =>
6558 null;
6559 end case;
6561 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
6562 end Dynamic_Accessibility_Level;
6564 ------------------------
6565 -- Discriminated_Size --
6566 ------------------------
6568 function Discriminated_Size (Comp : Entity_Id) return Boolean is
6569 function Non_Static_Bound (Bound : Node_Id) return Boolean;
6570 -- Check whether the bound of an index is non-static and does denote
6571 -- a discriminant, in which case any object of the type (protected or
6572 -- otherwise) will have a non-static size.
6574 ----------------------
6575 -- Non_Static_Bound --
6576 ----------------------
6578 function Non_Static_Bound (Bound : Node_Id) return Boolean is
6579 begin
6580 if Is_OK_Static_Expression (Bound) then
6581 return False;
6583 -- If the bound is given by a discriminant it is non-static
6584 -- (A static constraint replaces the reference with the value).
6585 -- In an protected object the discriminant has been replaced by
6586 -- the corresponding discriminal within the protected operation.
6588 elsif Is_Entity_Name (Bound)
6589 and then
6590 (Ekind (Entity (Bound)) = E_Discriminant
6591 or else Present (Discriminal_Link (Entity (Bound))))
6592 then
6593 return False;
6595 else
6596 return True;
6597 end if;
6598 end Non_Static_Bound;
6600 -- Local variables
6602 Typ : constant Entity_Id := Etype (Comp);
6603 Index : Node_Id;
6605 -- Start of processing for Discriminated_Size
6607 begin
6608 if not Is_Array_Type (Typ) then
6609 return False;
6610 end if;
6612 if Ekind (Typ) = E_Array_Subtype then
6613 Index := First_Index (Typ);
6614 while Present (Index) loop
6615 if Non_Static_Bound (Low_Bound (Index))
6616 or else Non_Static_Bound (High_Bound (Index))
6617 then
6618 return False;
6619 end if;
6621 Next_Index (Index);
6622 end loop;
6624 return True;
6625 end if;
6627 return False;
6628 end Discriminated_Size;
6630 -----------------------------------
6631 -- Effective_Extra_Accessibility --
6632 -----------------------------------
6634 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
6635 begin
6636 if Present (Renamed_Object (Id))
6637 and then Is_Entity_Name (Renamed_Object (Id))
6638 then
6639 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
6640 else
6641 return Extra_Accessibility (Id);
6642 end if;
6643 end Effective_Extra_Accessibility;
6645 -----------------------------
6646 -- Effective_Reads_Enabled --
6647 -----------------------------
6649 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
6650 begin
6651 return Has_Enabled_Property (Id, Name_Effective_Reads);
6652 end Effective_Reads_Enabled;
6654 ------------------------------
6655 -- Effective_Writes_Enabled --
6656 ------------------------------
6658 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
6659 begin
6660 return Has_Enabled_Property (Id, Name_Effective_Writes);
6661 end Effective_Writes_Enabled;
6663 ------------------------------
6664 -- Enclosing_Comp_Unit_Node --
6665 ------------------------------
6667 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
6668 Current_Node : Node_Id;
6670 begin
6671 Current_Node := N;
6672 while Present (Current_Node)
6673 and then Nkind (Current_Node) /= N_Compilation_Unit
6674 loop
6675 Current_Node := Parent (Current_Node);
6676 end loop;
6678 if Nkind (Current_Node) /= N_Compilation_Unit then
6679 return Empty;
6680 else
6681 return Current_Node;
6682 end if;
6683 end Enclosing_Comp_Unit_Node;
6685 --------------------------
6686 -- Enclosing_CPP_Parent --
6687 --------------------------
6689 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
6690 Parent_Typ : Entity_Id := Typ;
6692 begin
6693 while not Is_CPP_Class (Parent_Typ)
6694 and then Etype (Parent_Typ) /= Parent_Typ
6695 loop
6696 Parent_Typ := Etype (Parent_Typ);
6698 if Is_Private_Type (Parent_Typ) then
6699 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6700 end if;
6701 end loop;
6703 pragma Assert (Is_CPP_Class (Parent_Typ));
6704 return Parent_Typ;
6705 end Enclosing_CPP_Parent;
6707 ---------------------------
6708 -- Enclosing_Declaration --
6709 ---------------------------
6711 function Enclosing_Declaration (N : Node_Id) return Node_Id is
6712 Decl : Node_Id := N;
6714 begin
6715 while Present (Decl)
6716 and then not (Nkind (Decl) in N_Declaration
6717 or else
6718 Nkind (Decl) in N_Later_Decl_Item
6719 or else
6720 Nkind (Decl) = N_Number_Declaration)
6721 loop
6722 Decl := Parent (Decl);
6723 end loop;
6725 return Decl;
6726 end Enclosing_Declaration;
6728 ----------------------------
6729 -- Enclosing_Generic_Body --
6730 ----------------------------
6732 function Enclosing_Generic_Body
6733 (N : Node_Id) return Node_Id
6735 P : Node_Id;
6736 Decl : Node_Id;
6737 Spec : Node_Id;
6739 begin
6740 P := Parent (N);
6741 while Present (P) loop
6742 if Nkind (P) = N_Package_Body
6743 or else Nkind (P) = N_Subprogram_Body
6744 then
6745 Spec := Corresponding_Spec (P);
6747 if Present (Spec) then
6748 Decl := Unit_Declaration_Node (Spec);
6750 if Nkind (Decl) = N_Generic_Package_Declaration
6751 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6752 then
6753 return P;
6754 end if;
6755 end if;
6756 end if;
6758 P := Parent (P);
6759 end loop;
6761 return Empty;
6762 end Enclosing_Generic_Body;
6764 ----------------------------
6765 -- Enclosing_Generic_Unit --
6766 ----------------------------
6768 function Enclosing_Generic_Unit
6769 (N : Node_Id) return Node_Id
6771 P : Node_Id;
6772 Decl : Node_Id;
6773 Spec : Node_Id;
6775 begin
6776 P := Parent (N);
6777 while Present (P) loop
6778 if Nkind (P) = N_Generic_Package_Declaration
6779 or else Nkind (P) = N_Generic_Subprogram_Declaration
6780 then
6781 return P;
6783 elsif Nkind (P) = N_Package_Body
6784 or else Nkind (P) = N_Subprogram_Body
6785 then
6786 Spec := Corresponding_Spec (P);
6788 if Present (Spec) then
6789 Decl := Unit_Declaration_Node (Spec);
6791 if Nkind (Decl) = N_Generic_Package_Declaration
6792 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6793 then
6794 return Decl;
6795 end if;
6796 end if;
6797 end if;
6799 P := Parent (P);
6800 end loop;
6802 return Empty;
6803 end Enclosing_Generic_Unit;
6805 -------------------------------
6806 -- Enclosing_Lib_Unit_Entity --
6807 -------------------------------
6809 function Enclosing_Lib_Unit_Entity
6810 (E : Entity_Id := Current_Scope) return Entity_Id
6812 Unit_Entity : Entity_Id;
6814 begin
6815 -- Look for enclosing library unit entity by following scope links.
6816 -- Equivalent to, but faster than indexing through the scope stack.
6818 Unit_Entity := E;
6819 while (Present (Scope (Unit_Entity))
6820 and then Scope (Unit_Entity) /= Standard_Standard)
6821 and not Is_Child_Unit (Unit_Entity)
6822 loop
6823 Unit_Entity := Scope (Unit_Entity);
6824 end loop;
6826 return Unit_Entity;
6827 end Enclosing_Lib_Unit_Entity;
6829 -----------------------------
6830 -- Enclosing_Lib_Unit_Node --
6831 -----------------------------
6833 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6834 Encl_Unit : Node_Id;
6836 begin
6837 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6838 while Present (Encl_Unit)
6839 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6840 loop
6841 Encl_Unit := Library_Unit (Encl_Unit);
6842 end loop;
6844 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6845 return Encl_Unit;
6846 end Enclosing_Lib_Unit_Node;
6848 -----------------------
6849 -- Enclosing_Package --
6850 -----------------------
6852 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6853 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6855 begin
6856 if Dynamic_Scope = Standard_Standard then
6857 return Standard_Standard;
6859 elsif Dynamic_Scope = Empty then
6860 return Empty;
6862 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6863 E_Generic_Package)
6864 then
6865 return Dynamic_Scope;
6867 else
6868 return Enclosing_Package (Dynamic_Scope);
6869 end if;
6870 end Enclosing_Package;
6872 -------------------------------------
6873 -- Enclosing_Package_Or_Subprogram --
6874 -------------------------------------
6876 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6877 S : Entity_Id;
6879 begin
6880 S := Scope (E);
6881 while Present (S) loop
6882 if Is_Package_Or_Generic_Package (S)
6883 or else Ekind (S) = E_Package_Body
6884 then
6885 return S;
6887 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6888 or else Ekind (S) = E_Subprogram_Body
6889 then
6890 return S;
6892 else
6893 S := Scope (S);
6894 end if;
6895 end loop;
6897 return Empty;
6898 end Enclosing_Package_Or_Subprogram;
6900 --------------------------
6901 -- Enclosing_Subprogram --
6902 --------------------------
6904 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6905 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6907 begin
6908 if Dynamic_Scope = Standard_Standard then
6909 return Empty;
6911 elsif Dynamic_Scope = Empty then
6912 return Empty;
6914 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6915 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6917 elsif Ekind (Dynamic_Scope) = E_Block
6918 or else Ekind (Dynamic_Scope) = E_Return_Statement
6919 then
6920 return Enclosing_Subprogram (Dynamic_Scope);
6922 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6923 return Get_Task_Body_Procedure (Dynamic_Scope);
6925 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6926 and then Present (Full_View (Dynamic_Scope))
6927 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6928 then
6929 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6931 -- No body is generated if the protected operation is eliminated
6933 elsif Convention (Dynamic_Scope) = Convention_Protected
6934 and then not Is_Eliminated (Dynamic_Scope)
6935 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6936 then
6937 return Protected_Body_Subprogram (Dynamic_Scope);
6939 else
6940 return Dynamic_Scope;
6941 end if;
6942 end Enclosing_Subprogram;
6944 --------------------------
6945 -- End_Keyword_Location --
6946 --------------------------
6948 function End_Keyword_Location (N : Node_Id) return Source_Ptr is
6949 function End_Label_Loc (Nod : Node_Id) return Source_Ptr;
6950 -- Return the source location of Nod's end label according to the
6951 -- following precedence rules:
6953 -- 1) If the end label exists, return its location
6954 -- 2) If Nod exists, return its location
6955 -- 3) Return the location of N
6957 -------------------
6958 -- End_Label_Loc --
6959 -------------------
6961 function End_Label_Loc (Nod : Node_Id) return Source_Ptr is
6962 Label : Node_Id;
6964 begin
6965 if Present (Nod) then
6966 Label := End_Label (Nod);
6968 if Present (Label) then
6969 return Sloc (Label);
6970 else
6971 return Sloc (Nod);
6972 end if;
6974 else
6975 return Sloc (N);
6976 end if;
6977 end End_Label_Loc;
6979 -- Local variables
6981 Owner : Node_Id;
6983 -- Start of processing for End_Keyword_Location
6985 begin
6986 if Nkind_In (N, N_Block_Statement,
6987 N_Entry_Body,
6988 N_Package_Body,
6989 N_Subprogram_Body,
6990 N_Task_Body)
6991 then
6992 Owner := Handled_Statement_Sequence (N);
6994 elsif Nkind (N) = N_Package_Declaration then
6995 Owner := Specification (N);
6997 elsif Nkind (N) = N_Protected_Body then
6998 Owner := N;
7000 elsif Nkind_In (N, N_Protected_Type_Declaration,
7001 N_Single_Protected_Declaration)
7002 then
7003 Owner := Protected_Definition (N);
7005 elsif Nkind_In (N, N_Single_Task_Declaration,
7006 N_Task_Type_Declaration)
7007 then
7008 Owner := Task_Definition (N);
7010 -- This routine should not be called with other contexts
7012 else
7013 pragma Assert (False);
7014 null;
7015 end if;
7017 return End_Label_Loc (Owner);
7018 end End_Keyword_Location;
7020 ------------------------
7021 -- Ensure_Freeze_Node --
7022 ------------------------
7024 procedure Ensure_Freeze_Node (E : Entity_Id) is
7025 FN : Node_Id;
7026 begin
7027 if No (Freeze_Node (E)) then
7028 FN := Make_Freeze_Entity (Sloc (E));
7029 Set_Has_Delayed_Freeze (E);
7030 Set_Freeze_Node (E, FN);
7031 Set_Access_Types_To_Process (FN, No_Elist);
7032 Set_TSS_Elist (FN, No_Elist);
7033 Set_Entity (FN, E);
7034 end if;
7035 end Ensure_Freeze_Node;
7037 ----------------
7038 -- Enter_Name --
7039 ----------------
7041 procedure Enter_Name (Def_Id : Entity_Id) is
7042 C : constant Entity_Id := Current_Entity (Def_Id);
7043 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
7044 S : constant Entity_Id := Current_Scope;
7046 begin
7047 Generate_Definition (Def_Id);
7049 -- Add new name to current scope declarations. Check for duplicate
7050 -- declaration, which may or may not be a genuine error.
7052 if Present (E) then
7054 -- Case of previous entity entered because of a missing declaration
7055 -- or else a bad subtype indication. Best is to use the new entity,
7056 -- and make the previous one invisible.
7058 if Etype (E) = Any_Type then
7059 Set_Is_Immediately_Visible (E, False);
7061 -- Case of renaming declaration constructed for package instances.
7062 -- if there is an explicit declaration with the same identifier,
7063 -- the renaming is not immediately visible any longer, but remains
7064 -- visible through selected component notation.
7066 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
7067 and then not Comes_From_Source (E)
7068 then
7069 Set_Is_Immediately_Visible (E, False);
7071 -- The new entity may be the package renaming, which has the same
7072 -- same name as a generic formal which has been seen already.
7074 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
7075 and then not Comes_From_Source (Def_Id)
7076 then
7077 Set_Is_Immediately_Visible (E, False);
7079 -- For a fat pointer corresponding to a remote access to subprogram,
7080 -- we use the same identifier as the RAS type, so that the proper
7081 -- name appears in the stub. This type is only retrieved through
7082 -- the RAS type and never by visibility, and is not added to the
7083 -- visibility list (see below).
7085 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
7086 and then Ekind (Def_Id) = E_Record_Type
7087 and then Present (Corresponding_Remote_Type (Def_Id))
7088 then
7089 null;
7091 -- Case of an implicit operation or derived literal. The new entity
7092 -- hides the implicit one, which is removed from all visibility,
7093 -- i.e. the entity list of its scope, and homonym chain of its name.
7095 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
7096 or else Is_Internal (E)
7097 then
7098 declare
7099 Decl : constant Node_Id := Parent (E);
7100 Prev : Entity_Id;
7101 Prev_Vis : Entity_Id;
7103 begin
7104 -- If E is an implicit declaration, it cannot be the first
7105 -- entity in the scope.
7107 Prev := First_Entity (Current_Scope);
7108 while Present (Prev) and then Next_Entity (Prev) /= E loop
7109 Next_Entity (Prev);
7110 end loop;
7112 if No (Prev) then
7114 -- If E is not on the entity chain of the current scope,
7115 -- it is an implicit declaration in the generic formal
7116 -- part of a generic subprogram. When analyzing the body,
7117 -- the generic formals are visible but not on the entity
7118 -- chain of the subprogram. The new entity will become
7119 -- the visible one in the body.
7121 pragma Assert
7122 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
7123 null;
7125 else
7126 Link_Entities (Prev, Next_Entity (E));
7128 if No (Next_Entity (Prev)) then
7129 Set_Last_Entity (Current_Scope, Prev);
7130 end if;
7132 if E = Current_Entity (E) then
7133 Prev_Vis := Empty;
7135 else
7136 Prev_Vis := Current_Entity (E);
7137 while Homonym (Prev_Vis) /= E loop
7138 Prev_Vis := Homonym (Prev_Vis);
7139 end loop;
7140 end if;
7142 if Present (Prev_Vis) then
7144 -- Skip E in the visibility chain
7146 Set_Homonym (Prev_Vis, Homonym (E));
7148 else
7149 Set_Name_Entity_Id (Chars (E), Homonym (E));
7150 end if;
7151 end if;
7152 end;
7154 -- This section of code could use a comment ???
7156 elsif Present (Etype (E))
7157 and then Is_Concurrent_Type (Etype (E))
7158 and then E = Def_Id
7159 then
7160 return;
7162 -- If the homograph is a protected component renaming, it should not
7163 -- be hiding the current entity. Such renamings are treated as weak
7164 -- declarations.
7166 elsif Is_Prival (E) then
7167 Set_Is_Immediately_Visible (E, False);
7169 -- In this case the current entity is a protected component renaming.
7170 -- Perform minimal decoration by setting the scope and return since
7171 -- the prival should not be hiding other visible entities.
7173 elsif Is_Prival (Def_Id) then
7174 Set_Scope (Def_Id, Current_Scope);
7175 return;
7177 -- Analogous to privals, the discriminal generated for an entry index
7178 -- parameter acts as a weak declaration. Perform minimal decoration
7179 -- to avoid bogus errors.
7181 elsif Is_Discriminal (Def_Id)
7182 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
7183 then
7184 Set_Scope (Def_Id, Current_Scope);
7185 return;
7187 -- In the body or private part of an instance, a type extension may
7188 -- introduce a component with the same name as that of an actual. The
7189 -- legality rule is not enforced, but the semantics of the full type
7190 -- with two components of same name are not clear at this point???
7192 elsif In_Instance_Not_Visible then
7193 null;
7195 -- When compiling a package body, some child units may have become
7196 -- visible. They cannot conflict with local entities that hide them.
7198 elsif Is_Child_Unit (E)
7199 and then In_Open_Scopes (Scope (E))
7200 and then not Is_Immediately_Visible (E)
7201 then
7202 null;
7204 -- Conversely, with front-end inlining we may compile the parent body
7205 -- first, and a child unit subsequently. The context is now the
7206 -- parent spec, and body entities are not visible.
7208 elsif Is_Child_Unit (Def_Id)
7209 and then Is_Package_Body_Entity (E)
7210 and then not In_Package_Body (Current_Scope)
7211 then
7212 null;
7214 -- Case of genuine duplicate declaration
7216 else
7217 Error_Msg_Sloc := Sloc (E);
7219 -- If the previous declaration is an incomplete type declaration
7220 -- this may be an attempt to complete it with a private type. The
7221 -- following avoids confusing cascaded errors.
7223 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
7224 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
7225 then
7226 Error_Msg_N
7227 ("incomplete type cannot be completed with a private " &
7228 "declaration", Parent (Def_Id));
7229 Set_Is_Immediately_Visible (E, False);
7230 Set_Full_View (E, Def_Id);
7232 -- An inherited component of a record conflicts with a new
7233 -- discriminant. The discriminant is inserted first in the scope,
7234 -- but the error should be posted on it, not on the component.
7236 elsif Ekind (E) = E_Discriminant
7237 and then Present (Scope (Def_Id))
7238 and then Scope (Def_Id) /= Current_Scope
7239 then
7240 Error_Msg_Sloc := Sloc (Def_Id);
7241 Error_Msg_N ("& conflicts with declaration#", E);
7242 return;
7244 -- If the name of the unit appears in its own context clause, a
7245 -- dummy package with the name has already been created, and the
7246 -- error emitted. Try to continue quietly.
7248 elsif Error_Posted (E)
7249 and then Sloc (E) = No_Location
7250 and then Nkind (Parent (E)) = N_Package_Specification
7251 and then Current_Scope = Standard_Standard
7252 then
7253 Set_Scope (Def_Id, Current_Scope);
7254 return;
7256 else
7257 Error_Msg_N ("& conflicts with declaration#", Def_Id);
7259 -- Avoid cascaded messages with duplicate components in
7260 -- derived types.
7262 if Ekind_In (E, E_Component, E_Discriminant) then
7263 return;
7264 end if;
7265 end if;
7267 if Nkind (Parent (Parent (Def_Id))) =
7268 N_Generic_Subprogram_Declaration
7269 and then Def_Id =
7270 Defining_Entity (Specification (Parent (Parent (Def_Id))))
7271 then
7272 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
7273 end if;
7275 -- If entity is in standard, then we are in trouble, because it
7276 -- means that we have a library package with a duplicated name.
7277 -- That's hard to recover from, so abort.
7279 if S = Standard_Standard then
7280 raise Unrecoverable_Error;
7282 -- Otherwise we continue with the declaration. Having two
7283 -- identical declarations should not cause us too much trouble.
7285 else
7286 null;
7287 end if;
7288 end if;
7289 end if;
7291 -- If we fall through, declaration is OK, at least OK enough to continue
7293 -- If Def_Id is a discriminant or a record component we are in the midst
7294 -- of inheriting components in a derived record definition. Preserve
7295 -- their Ekind and Etype.
7297 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
7298 null;
7300 -- If a type is already set, leave it alone (happens when a type
7301 -- declaration is reanalyzed following a call to the optimizer).
7303 elsif Present (Etype (Def_Id)) then
7304 null;
7306 -- Otherwise, the kind E_Void insures that premature uses of the entity
7307 -- will be detected. Any_Type insures that no cascaded errors will occur
7309 else
7310 Set_Ekind (Def_Id, E_Void);
7311 Set_Etype (Def_Id, Any_Type);
7312 end if;
7314 -- Inherited discriminants and components in derived record types are
7315 -- immediately visible. Itypes are not.
7317 -- Unless the Itype is for a record type with a corresponding remote
7318 -- type (what is that about, it was not commented ???)
7320 if Ekind_In (Def_Id, E_Discriminant, E_Component)
7321 or else
7322 ((not Is_Record_Type (Def_Id)
7323 or else No (Corresponding_Remote_Type (Def_Id)))
7324 and then not Is_Itype (Def_Id))
7325 then
7326 Set_Is_Immediately_Visible (Def_Id);
7327 Set_Current_Entity (Def_Id);
7328 end if;
7330 Set_Homonym (Def_Id, C);
7331 Append_Entity (Def_Id, S);
7332 Set_Public_Status (Def_Id);
7334 -- Declaring a homonym is not allowed in SPARK ...
7336 if Present (C) and then Restriction_Check_Required (SPARK_05) then
7337 declare
7338 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
7339 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
7340 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
7342 begin
7343 -- ... unless the new declaration is in a subprogram, and the
7344 -- visible declaration is a variable declaration or a parameter
7345 -- specification outside that subprogram.
7347 if Present (Enclosing_Subp)
7348 and then Nkind_In (Parent (C), N_Object_Declaration,
7349 N_Parameter_Specification)
7350 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
7351 then
7352 null;
7354 -- ... or the new declaration is in a package, and the visible
7355 -- declaration occurs outside that package.
7357 elsif Present (Enclosing_Pack)
7358 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
7359 then
7360 null;
7362 -- ... or the new declaration is a component declaration in a
7363 -- record type definition.
7365 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
7366 null;
7368 -- Don't issue error for non-source entities
7370 elsif Comes_From_Source (Def_Id)
7371 and then Comes_From_Source (C)
7372 then
7373 Error_Msg_Sloc := Sloc (C);
7374 Check_SPARK_05_Restriction
7375 ("redeclaration of identifier &#", Def_Id);
7376 end if;
7377 end;
7378 end if;
7380 -- Warn if new entity hides an old one
7382 if Warn_On_Hiding and then Present (C)
7384 -- Don't warn for record components since they always have a well
7385 -- defined scope which does not confuse other uses. Note that in
7386 -- some cases, Ekind has not been set yet.
7388 and then Ekind (C) /= E_Component
7389 and then Ekind (C) /= E_Discriminant
7390 and then Nkind (Parent (C)) /= N_Component_Declaration
7391 and then Ekind (Def_Id) /= E_Component
7392 and then Ekind (Def_Id) /= E_Discriminant
7393 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
7395 -- Don't warn for one character variables. It is too common to use
7396 -- such variables as locals and will just cause too many false hits.
7398 and then Length_Of_Name (Chars (C)) /= 1
7400 -- Don't warn for non-source entities
7402 and then Comes_From_Source (C)
7403 and then Comes_From_Source (Def_Id)
7405 -- Don't warn unless entity in question is in extended main source
7407 and then In_Extended_Main_Source_Unit (Def_Id)
7409 -- Finally, the hidden entity must be either immediately visible or
7410 -- use visible (i.e. from a used package).
7412 and then
7413 (Is_Immediately_Visible (C)
7414 or else
7415 Is_Potentially_Use_Visible (C))
7416 then
7417 Error_Msg_Sloc := Sloc (C);
7418 Error_Msg_N ("declaration hides &#?h?", Def_Id);
7419 end if;
7420 end Enter_Name;
7422 ---------------
7423 -- Entity_Of --
7424 ---------------
7426 function Entity_Of (N : Node_Id) return Entity_Id is
7427 Id : Entity_Id;
7428 Ren : Node_Id;
7430 begin
7431 -- Assume that the arbitrary node does not have an entity
7433 Id := Empty;
7435 if Is_Entity_Name (N) then
7436 Id := Entity (N);
7438 -- Follow a possible chain of renamings to reach the earliest renamed
7439 -- source object.
7441 while Present (Id)
7442 and then Is_Object (Id)
7443 and then Present (Renamed_Object (Id))
7444 loop
7445 Ren := Renamed_Object (Id);
7447 -- The reference renames an abstract state or a whole object
7449 -- Obj : ...;
7450 -- Ren : ... renames Obj;
7452 if Is_Entity_Name (Ren) then
7453 Id := Entity (Ren);
7455 -- The reference renames a function result. Check the original
7456 -- node in case expansion relocates the function call.
7458 -- Ren : ... renames Func_Call;
7460 elsif Nkind (Original_Node (Ren)) = N_Function_Call then
7461 exit;
7463 -- Otherwise the reference renames something which does not yield
7464 -- an abstract state or a whole object. Treat the reference as not
7465 -- having a proper entity for SPARK legality purposes.
7467 else
7468 Id := Empty;
7469 exit;
7470 end if;
7471 end loop;
7472 end if;
7474 return Id;
7475 end Entity_Of;
7477 --------------------------
7478 -- Examine_Array_Bounds --
7479 --------------------------
7481 procedure Examine_Array_Bounds
7482 (Typ : Entity_Id;
7483 All_Static : out Boolean;
7484 Has_Empty : out Boolean)
7486 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean;
7487 -- Determine whether bound Bound is a suitable static bound
7489 ------------------------
7490 -- Is_OK_Static_Bound --
7491 ------------------------
7493 function Is_OK_Static_Bound (Bound : Node_Id) return Boolean is
7494 begin
7495 return
7496 not Error_Posted (Bound)
7497 and then Is_OK_Static_Expression (Bound);
7498 end Is_OK_Static_Bound;
7500 -- Local variables
7502 Hi_Bound : Node_Id;
7503 Index : Node_Id;
7504 Lo_Bound : Node_Id;
7506 -- Start of processing for Examine_Array_Bounds
7508 begin
7509 -- An unconstrained array type does not have static bounds, and it is
7510 -- not known whether they are empty or not.
7512 if not Is_Constrained (Typ) then
7513 All_Static := False;
7514 Has_Empty := False;
7516 -- A string literal has static bounds, and is not empty as long as it
7517 -- contains at least one character.
7519 elsif Ekind (Typ) = E_String_Literal_Subtype then
7520 All_Static := True;
7521 Has_Empty := String_Literal_Length (Typ) > 0;
7522 end if;
7524 -- Assume that all bounds are static and not empty
7526 All_Static := True;
7527 Has_Empty := False;
7529 -- Examine each index
7531 Index := First_Index (Typ);
7532 while Present (Index) loop
7533 if Is_Discrete_Type (Etype (Index)) then
7534 Get_Index_Bounds (Index, Lo_Bound, Hi_Bound);
7536 if Is_OK_Static_Bound (Lo_Bound)
7537 and then
7538 Is_OK_Static_Bound (Hi_Bound)
7539 then
7540 -- The static bounds produce an empty range
7542 if Is_Null_Range (Lo_Bound, Hi_Bound) then
7543 Has_Empty := True;
7544 end if;
7546 -- Otherwise at least one of the bounds is not static
7548 else
7549 All_Static := False;
7550 end if;
7552 -- Otherwise the index is non-discrete, therefore not static
7554 else
7555 All_Static := False;
7556 end if;
7558 Next_Index (Index);
7559 end loop;
7560 end Examine_Array_Bounds;
7562 --------------------------
7563 -- Explain_Limited_Type --
7564 --------------------------
7566 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
7567 C : Entity_Id;
7569 begin
7570 -- For array, component type must be limited
7572 if Is_Array_Type (T) then
7573 Error_Msg_Node_2 := T;
7574 Error_Msg_NE
7575 ("\component type& of type& is limited", N, Component_Type (T));
7576 Explain_Limited_Type (Component_Type (T), N);
7578 elsif Is_Record_Type (T) then
7580 -- No need for extra messages if explicit limited record
7582 if Is_Limited_Record (Base_Type (T)) then
7583 return;
7584 end if;
7586 -- Otherwise find a limited component. Check only components that
7587 -- come from source, or inherited components that appear in the
7588 -- source of the ancestor.
7590 C := First_Component (T);
7591 while Present (C) loop
7592 if Is_Limited_Type (Etype (C))
7593 and then
7594 (Comes_From_Source (C)
7595 or else
7596 (Present (Original_Record_Component (C))
7597 and then
7598 Comes_From_Source (Original_Record_Component (C))))
7599 then
7600 Error_Msg_Node_2 := T;
7601 Error_Msg_NE ("\component& of type& has limited type", N, C);
7602 Explain_Limited_Type (Etype (C), N);
7603 return;
7604 end if;
7606 Next_Component (C);
7607 end loop;
7609 -- The type may be declared explicitly limited, even if no component
7610 -- of it is limited, in which case we fall out of the loop.
7611 return;
7612 end if;
7613 end Explain_Limited_Type;
7615 ---------------------------------------
7616 -- Expression_Of_Expression_Function --
7617 ---------------------------------------
7619 function Expression_Of_Expression_Function
7620 (Subp : Entity_Id) return Node_Id
7622 Expr_Func : Node_Id;
7624 begin
7625 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
7627 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
7628 N_Expression_Function
7629 then
7630 Expr_Func := Original_Node (Subprogram_Spec (Subp));
7632 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
7633 N_Expression_Function
7634 then
7635 Expr_Func := Original_Node (Subprogram_Body (Subp));
7637 else
7638 pragma Assert (False);
7639 null;
7640 end if;
7642 return Original_Node (Expression (Expr_Func));
7643 end Expression_Of_Expression_Function;
7645 -------------------------------
7646 -- Extensions_Visible_Status --
7647 -------------------------------
7649 function Extensions_Visible_Status
7650 (Id : Entity_Id) return Extensions_Visible_Mode
7652 Arg : Node_Id;
7653 Decl : Node_Id;
7654 Expr : Node_Id;
7655 Prag : Node_Id;
7656 Subp : Entity_Id;
7658 begin
7659 -- When a formal parameter is subject to Extensions_Visible, the pragma
7660 -- is stored in the contract of related subprogram.
7662 if Is_Formal (Id) then
7663 Subp := Scope (Id);
7665 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
7666 Subp := Id;
7668 -- No other construct carries this pragma
7670 else
7671 return Extensions_Visible_None;
7672 end if;
7674 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
7676 -- In certain cases analysis may request the Extensions_Visible status
7677 -- of an expression function before the pragma has been analyzed yet.
7678 -- Inspect the declarative items after the expression function looking
7679 -- for the pragma (if any).
7681 if No (Prag) and then Is_Expression_Function (Subp) then
7682 Decl := Next (Unit_Declaration_Node (Subp));
7683 while Present (Decl) loop
7684 if Nkind (Decl) = N_Pragma
7685 and then Pragma_Name (Decl) = Name_Extensions_Visible
7686 then
7687 Prag := Decl;
7688 exit;
7690 -- A source construct ends the region where Extensions_Visible may
7691 -- appear, stop the traversal. An expanded expression function is
7692 -- no longer a source construct, but it must still be recognized.
7694 elsif Comes_From_Source (Decl)
7695 or else
7696 (Nkind_In (Decl, N_Subprogram_Body,
7697 N_Subprogram_Declaration)
7698 and then Is_Expression_Function (Defining_Entity (Decl)))
7699 then
7700 exit;
7701 end if;
7703 Next (Decl);
7704 end loop;
7705 end if;
7707 -- Extract the value from the Boolean expression (if any)
7709 if Present (Prag) then
7710 Arg := First (Pragma_Argument_Associations (Prag));
7712 if Present (Arg) then
7713 Expr := Get_Pragma_Arg (Arg);
7715 -- When the associated subprogram is an expression function, the
7716 -- argument of the pragma may not have been analyzed.
7718 if not Analyzed (Expr) then
7719 Preanalyze_And_Resolve (Expr, Standard_Boolean);
7720 end if;
7722 -- Guard against cascading errors when the argument of pragma
7723 -- Extensions_Visible is not a valid static Boolean expression.
7725 if Error_Posted (Expr) then
7726 return Extensions_Visible_None;
7728 elsif Is_True (Expr_Value (Expr)) then
7729 return Extensions_Visible_True;
7731 else
7732 return Extensions_Visible_False;
7733 end if;
7735 -- Otherwise the aspect or pragma defaults to True
7737 else
7738 return Extensions_Visible_True;
7739 end if;
7741 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7742 -- directly specified. In SPARK code, its value defaults to "False".
7744 elsif SPARK_Mode = On then
7745 return Extensions_Visible_False;
7747 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7748 -- "True".
7750 else
7751 return Extensions_Visible_True;
7752 end if;
7753 end Extensions_Visible_Status;
7755 -----------------
7756 -- Find_Actual --
7757 -----------------
7759 procedure Find_Actual
7760 (N : Node_Id;
7761 Formal : out Entity_Id;
7762 Call : out Node_Id)
7764 Context : constant Node_Id := Parent (N);
7765 Actual : Node_Id;
7766 Call_Nam : Node_Id;
7768 begin
7769 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
7770 and then N = Prefix (Context)
7771 then
7772 Find_Actual (Context, Formal, Call);
7773 return;
7775 elsif Nkind (Context) = N_Parameter_Association
7776 and then N = Explicit_Actual_Parameter (Context)
7777 then
7778 Call := Parent (Context);
7780 elsif Nkind_In (Context, N_Entry_Call_Statement,
7781 N_Function_Call,
7782 N_Procedure_Call_Statement)
7783 then
7784 Call := Context;
7786 else
7787 Formal := Empty;
7788 Call := Empty;
7789 return;
7790 end if;
7792 -- If we have a call to a subprogram look for the parameter. Note that
7793 -- we exclude overloaded calls, since we don't know enough to be sure
7794 -- of giving the right answer in this case.
7796 if Nkind_In (Call, N_Entry_Call_Statement,
7797 N_Function_Call,
7798 N_Procedure_Call_Statement)
7799 then
7800 Call_Nam := Name (Call);
7802 -- A call to a protected or task entry appears as a selected
7803 -- component rather than an expanded name.
7805 if Nkind (Call_Nam) = N_Selected_Component then
7806 Call_Nam := Selector_Name (Call_Nam);
7807 end if;
7809 if Is_Entity_Name (Call_Nam)
7810 and then Present (Entity (Call_Nam))
7811 and then Is_Overloadable (Entity (Call_Nam))
7812 and then not Is_Overloaded (Call_Nam)
7813 then
7814 -- If node is name in call it is not an actual
7816 if N = Call_Nam then
7817 Formal := Empty;
7818 Call := Empty;
7819 return;
7820 end if;
7822 -- Fall here if we are definitely a parameter
7824 Actual := First_Actual (Call);
7825 Formal := First_Formal (Entity (Call_Nam));
7826 while Present (Formal) and then Present (Actual) loop
7827 if Actual = N then
7828 return;
7830 -- An actual that is the prefix in a prefixed call may have
7831 -- been rewritten in the call, after the deferred reference
7832 -- was collected. Check if sloc and kinds and names match.
7834 elsif Sloc (Actual) = Sloc (N)
7835 and then Nkind (Actual) = N_Identifier
7836 and then Nkind (Actual) = Nkind (N)
7837 and then Chars (Actual) = Chars (N)
7838 then
7839 return;
7841 else
7842 Actual := Next_Actual (Actual);
7843 Formal := Next_Formal (Formal);
7844 end if;
7845 end loop;
7846 end if;
7847 end if;
7849 -- Fall through here if we did not find matching actual
7851 Formal := Empty;
7852 Call := Empty;
7853 end Find_Actual;
7855 ---------------------------
7856 -- Find_Body_Discriminal --
7857 ---------------------------
7859 function Find_Body_Discriminal
7860 (Spec_Discriminant : Entity_Id) return Entity_Id
7862 Tsk : Entity_Id;
7863 Disc : Entity_Id;
7865 begin
7866 -- If expansion is suppressed, then the scope can be the concurrent type
7867 -- itself rather than a corresponding concurrent record type.
7869 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
7870 Tsk := Scope (Spec_Discriminant);
7872 else
7873 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
7875 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
7876 end if;
7878 -- Find discriminant of original concurrent type, and use its current
7879 -- discriminal, which is the renaming within the task/protected body.
7881 Disc := First_Discriminant (Tsk);
7882 while Present (Disc) loop
7883 if Chars (Disc) = Chars (Spec_Discriminant) then
7884 return Discriminal (Disc);
7885 end if;
7887 Next_Discriminant (Disc);
7888 end loop;
7890 -- That loop should always succeed in finding a matching entry and
7891 -- returning. Fatal error if not.
7893 raise Program_Error;
7894 end Find_Body_Discriminal;
7896 -------------------------------------
7897 -- Find_Corresponding_Discriminant --
7898 -------------------------------------
7900 function Find_Corresponding_Discriminant
7901 (Id : Node_Id;
7902 Typ : Entity_Id) return Entity_Id
7904 Par_Disc : Entity_Id;
7905 Old_Disc : Entity_Id;
7906 New_Disc : Entity_Id;
7908 begin
7909 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
7911 -- The original type may currently be private, and the discriminant
7912 -- only appear on its full view.
7914 if Is_Private_Type (Scope (Par_Disc))
7915 and then not Has_Discriminants (Scope (Par_Disc))
7916 and then Present (Full_View (Scope (Par_Disc)))
7917 then
7918 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
7919 else
7920 Old_Disc := First_Discriminant (Scope (Par_Disc));
7921 end if;
7923 if Is_Class_Wide_Type (Typ) then
7924 New_Disc := First_Discriminant (Root_Type (Typ));
7925 else
7926 New_Disc := First_Discriminant (Typ);
7927 end if;
7929 while Present (Old_Disc) and then Present (New_Disc) loop
7930 if Old_Disc = Par_Disc then
7931 return New_Disc;
7932 end if;
7934 Next_Discriminant (Old_Disc);
7935 Next_Discriminant (New_Disc);
7936 end loop;
7938 -- Should always find it
7940 raise Program_Error;
7941 end Find_Corresponding_Discriminant;
7943 -------------------
7944 -- Find_DIC_Type --
7945 -------------------
7947 function Find_DIC_Type (Typ : Entity_Id) return Entity_Id is
7948 Curr_Typ : Entity_Id;
7949 -- The current type being examined in the parent hierarchy traversal
7951 DIC_Typ : Entity_Id;
7952 -- The type which carries the DIC pragma. This variable denotes the
7953 -- partial view when private types are involved.
7955 Par_Typ : Entity_Id;
7956 -- The parent type of the current type. This variable denotes the full
7957 -- view when private types are involved.
7959 begin
7960 -- The input type defines its own DIC pragma, therefore it is the owner
7962 if Has_Own_DIC (Typ) then
7963 DIC_Typ := Typ;
7965 -- Otherwise the DIC pragma is inherited from a parent type
7967 else
7968 pragma Assert (Has_Inherited_DIC (Typ));
7970 -- Climb the parent chain
7972 Curr_Typ := Typ;
7973 loop
7974 -- Inspect the parent type. Do not consider subtypes as they
7975 -- inherit the DIC attributes from their base types.
7977 DIC_Typ := Base_Type (Etype (Curr_Typ));
7979 -- Look at the full view of a private type because the type may
7980 -- have a hidden parent introduced in the full view.
7982 Par_Typ := DIC_Typ;
7984 if Is_Private_Type (Par_Typ)
7985 and then Present (Full_View (Par_Typ))
7986 then
7987 Par_Typ := Full_View (Par_Typ);
7988 end if;
7990 -- Stop the climb once the nearest parent type which defines a DIC
7991 -- pragma of its own is encountered or when the root of the parent
7992 -- chain is reached.
7994 exit when Has_Own_DIC (DIC_Typ) or else Curr_Typ = Par_Typ;
7996 Curr_Typ := Par_Typ;
7997 end loop;
7998 end if;
8000 return DIC_Typ;
8001 end Find_DIC_Type;
8003 ----------------------------------
8004 -- Find_Enclosing_Iterator_Loop --
8005 ----------------------------------
8007 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
8008 Constr : Node_Id;
8009 S : Entity_Id;
8011 begin
8012 -- Traverse the scope chain looking for an iterator loop. Such loops are
8013 -- usually transformed into blocks, hence the use of Original_Node.
8015 S := Id;
8016 while Present (S) and then S /= Standard_Standard loop
8017 if Ekind (S) = E_Loop
8018 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
8019 then
8020 Constr := Original_Node (Label_Construct (Parent (S)));
8022 if Nkind (Constr) = N_Loop_Statement
8023 and then Present (Iteration_Scheme (Constr))
8024 and then Nkind (Iterator_Specification
8025 (Iteration_Scheme (Constr))) =
8026 N_Iterator_Specification
8027 then
8028 return S;
8029 end if;
8030 end if;
8032 S := Scope (S);
8033 end loop;
8035 return Empty;
8036 end Find_Enclosing_Iterator_Loop;
8038 --------------------------
8039 -- Find_Enclosing_Scope --
8040 --------------------------
8042 function Find_Enclosing_Scope (N : Node_Id) return Entity_Id is
8043 Par : Node_Id;
8045 begin
8046 -- Examine the parent chain looking for a construct which defines a
8047 -- scope.
8049 Par := Parent (N);
8050 while Present (Par) loop
8051 case Nkind (Par) is
8053 -- The construct denotes a declaration, the proper scope is its
8054 -- entity.
8056 when N_Entry_Declaration
8057 | N_Expression_Function
8058 | N_Full_Type_Declaration
8059 | N_Generic_Package_Declaration
8060 | N_Generic_Subprogram_Declaration
8061 | N_Package_Declaration
8062 | N_Private_Extension_Declaration
8063 | N_Protected_Type_Declaration
8064 | N_Single_Protected_Declaration
8065 | N_Single_Task_Declaration
8066 | N_Subprogram_Declaration
8067 | N_Task_Type_Declaration
8069 return Defining_Entity (Par);
8071 -- The construct denotes a body, the proper scope is the entity of
8072 -- the corresponding spec or that of the body if the body does not
8073 -- complete a previous declaration.
8075 when N_Entry_Body
8076 | N_Package_Body
8077 | N_Protected_Body
8078 | N_Subprogram_Body
8079 | N_Task_Body
8081 return Unique_Defining_Entity (Par);
8083 -- Special cases
8085 -- Blocks carry either a source or an internally-generated scope,
8086 -- unless the block is a byproduct of exception handling.
8088 when N_Block_Statement =>
8089 if not Exception_Junk (Par) then
8090 return Entity (Identifier (Par));
8091 end if;
8093 -- Loops carry an internally-generated scope
8095 when N_Loop_Statement =>
8096 return Entity (Identifier (Par));
8098 -- Extended return statements carry an internally-generated scope
8100 when N_Extended_Return_Statement =>
8101 return Return_Statement_Entity (Par);
8103 -- A traversal from a subunit continues via the corresponding stub
8105 when N_Subunit =>
8106 Par := Corresponding_Stub (Par);
8108 when others =>
8109 null;
8110 end case;
8112 Par := Parent (Par);
8113 end loop;
8115 return Standard_Standard;
8116 end Find_Enclosing_Scope;
8118 ------------------------------------
8119 -- Find_Loop_In_Conditional_Block --
8120 ------------------------------------
8122 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
8123 Stmt : Node_Id;
8125 begin
8126 Stmt := N;
8128 if Nkind (Stmt) = N_If_Statement then
8129 Stmt := First (Then_Statements (Stmt));
8130 end if;
8132 pragma Assert (Nkind (Stmt) = N_Block_Statement);
8134 -- Inspect the statements of the conditional block. In general the loop
8135 -- should be the first statement in the statement sequence of the block,
8136 -- but the finalization machinery may have introduced extra object
8137 -- declarations.
8139 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
8140 while Present (Stmt) loop
8141 if Nkind (Stmt) = N_Loop_Statement then
8142 return Stmt;
8143 end if;
8145 Next (Stmt);
8146 end loop;
8148 -- The expansion of attribute 'Loop_Entry produced a malformed block
8150 raise Program_Error;
8151 end Find_Loop_In_Conditional_Block;
8153 --------------------------
8154 -- Find_Overlaid_Entity --
8155 --------------------------
8157 procedure Find_Overlaid_Entity
8158 (N : Node_Id;
8159 Ent : out Entity_Id;
8160 Off : out Boolean)
8162 Expr : Node_Id;
8164 begin
8165 -- We are looking for one of the two following forms:
8167 -- for X'Address use Y'Address
8169 -- or
8171 -- Const : constant Address := expr;
8172 -- ...
8173 -- for X'Address use Const;
8175 -- In the second case, the expr is either Y'Address, or recursively a
8176 -- constant that eventually references Y'Address.
8178 Ent := Empty;
8179 Off := False;
8181 if Nkind (N) = N_Attribute_Definition_Clause
8182 and then Chars (N) = Name_Address
8183 then
8184 Expr := Expression (N);
8186 -- This loop checks the form of the expression for Y'Address,
8187 -- using recursion to deal with intermediate constants.
8189 loop
8190 -- Check for Y'Address
8192 if Nkind (Expr) = N_Attribute_Reference
8193 and then Attribute_Name (Expr) = Name_Address
8194 then
8195 Expr := Prefix (Expr);
8196 exit;
8198 -- Check for Const where Const is a constant entity
8200 elsif Is_Entity_Name (Expr)
8201 and then Ekind (Entity (Expr)) = E_Constant
8202 then
8203 Expr := Constant_Value (Entity (Expr));
8205 -- Anything else does not need checking
8207 else
8208 return;
8209 end if;
8210 end loop;
8212 -- This loop checks the form of the prefix for an entity, using
8213 -- recursion to deal with intermediate components.
8215 loop
8216 -- Check for Y where Y is an entity
8218 if Is_Entity_Name (Expr) then
8219 Ent := Entity (Expr);
8220 return;
8222 -- Check for components
8224 elsif
8225 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
8226 then
8227 Expr := Prefix (Expr);
8228 Off := True;
8230 -- Anything else does not need checking
8232 else
8233 return;
8234 end if;
8235 end loop;
8236 end if;
8237 end Find_Overlaid_Entity;
8239 -------------------------
8240 -- Find_Parameter_Type --
8241 -------------------------
8243 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
8244 begin
8245 if Nkind (Param) /= N_Parameter_Specification then
8246 return Empty;
8248 -- For an access parameter, obtain the type from the formal entity
8249 -- itself, because access to subprogram nodes do not carry a type.
8250 -- Shouldn't we always use the formal entity ???
8252 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
8253 return Etype (Defining_Identifier (Param));
8255 else
8256 return Etype (Parameter_Type (Param));
8257 end if;
8258 end Find_Parameter_Type;
8260 -----------------------------------
8261 -- Find_Placement_In_State_Space --
8262 -----------------------------------
8264 procedure Find_Placement_In_State_Space
8265 (Item_Id : Entity_Id;
8266 Placement : out State_Space_Kind;
8267 Pack_Id : out Entity_Id)
8269 Context : Entity_Id;
8271 begin
8272 -- Assume that the item does not appear in the state space of a package
8274 Placement := Not_In_Package;
8275 Pack_Id := Empty;
8277 -- Climb the scope stack and examine the enclosing context
8279 Context := Scope (Item_Id);
8280 while Present (Context) and then Context /= Standard_Standard loop
8281 if Is_Package_Or_Generic_Package (Context) then
8282 Pack_Id := Context;
8284 -- A package body is a cut off point for the traversal as the item
8285 -- cannot be visible to the outside from this point on. Note that
8286 -- this test must be done first as a body is also classified as a
8287 -- private part.
8289 if In_Package_Body (Context) then
8290 Placement := Body_State_Space;
8291 return;
8293 -- The private part of a package is a cut off point for the
8294 -- traversal as the item cannot be visible to the outside from
8295 -- this point on.
8297 elsif In_Private_Part (Context) then
8298 Placement := Private_State_Space;
8299 return;
8301 -- When the item appears in the visible state space of a package,
8302 -- continue to climb the scope stack as this may not be the final
8303 -- state space.
8305 else
8306 Placement := Visible_State_Space;
8308 -- The visible state space of a child unit acts as the proper
8309 -- placement of an item.
8311 if Is_Child_Unit (Context) then
8312 return;
8313 end if;
8314 end if;
8316 -- The item or its enclosing package appear in a construct that has
8317 -- no state space.
8319 else
8320 Placement := Not_In_Package;
8321 return;
8322 end if;
8324 Context := Scope (Context);
8325 end loop;
8326 end Find_Placement_In_State_Space;
8328 -----------------------
8329 -- Find_Primitive_Eq --
8330 -----------------------
8332 function Find_Primitive_Eq (Typ : Entity_Id) return Entity_Id is
8333 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id;
8334 -- Search for the equality primitive; return Empty if the primitive is
8335 -- not found.
8337 ------------------
8338 -- Find_Eq_Prim --
8339 ------------------
8341 function Find_Eq_Prim (Prims_List : Elist_Id) return Entity_Id is
8342 Prim : Entity_Id;
8343 Prim_Elmt : Elmt_Id;
8345 begin
8346 Prim_Elmt := First_Elmt (Prims_List);
8347 while Present (Prim_Elmt) loop
8348 Prim := Node (Prim_Elmt);
8350 -- Locate primitive equality with the right signature
8352 if Chars (Prim) = Name_Op_Eq
8353 and then Etype (First_Formal (Prim)) =
8354 Etype (Next_Formal (First_Formal (Prim)))
8355 and then Base_Type (Etype (Prim)) = Standard_Boolean
8356 then
8357 return Prim;
8358 end if;
8360 Next_Elmt (Prim_Elmt);
8361 end loop;
8363 return Empty;
8364 end Find_Eq_Prim;
8366 -- Local Variables
8368 Eq_Prim : Entity_Id;
8369 Full_Type : Entity_Id;
8371 -- Start of processing for Find_Primitive_Eq
8373 begin
8374 if Is_Private_Type (Typ) then
8375 Full_Type := Underlying_Type (Typ);
8376 else
8377 Full_Type := Typ;
8378 end if;
8380 if No (Full_Type) then
8381 return Empty;
8382 end if;
8384 Full_Type := Base_Type (Full_Type);
8386 -- When the base type itself is private, use the full view
8388 if Is_Private_Type (Full_Type) then
8389 Full_Type := Underlying_Type (Full_Type);
8390 end if;
8392 if Is_Class_Wide_Type (Full_Type) then
8393 Full_Type := Root_Type (Full_Type);
8394 end if;
8396 if not Is_Tagged_Type (Full_Type) then
8397 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8399 -- If this is an untagged private type completed with a derivation of
8400 -- an untagged private type whose full view is a tagged type, we use
8401 -- the primitive operations of the private parent type (since it does
8402 -- not have a full view, and also because its equality primitive may
8403 -- have been overridden in its untagged full view). If no equality was
8404 -- defined for it then take its dispatching equality primitive.
8406 elsif Inherits_From_Tagged_Full_View (Typ) then
8407 Eq_Prim := Find_Eq_Prim (Collect_Primitive_Operations (Typ));
8409 if No (Eq_Prim) then
8410 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8411 end if;
8413 else
8414 Eq_Prim := Find_Eq_Prim (Primitive_Operations (Full_Type));
8415 end if;
8417 return Eq_Prim;
8418 end Find_Primitive_Eq;
8420 ------------------------
8421 -- Find_Specific_Type --
8422 ------------------------
8424 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
8425 Typ : Entity_Id := Root_Type (CW);
8427 begin
8428 if Ekind (Typ) = E_Incomplete_Type then
8429 if From_Limited_With (Typ) then
8430 Typ := Non_Limited_View (Typ);
8431 else
8432 Typ := Full_View (Typ);
8433 end if;
8434 end if;
8436 if Is_Private_Type (Typ)
8437 and then not Is_Tagged_Type (Typ)
8438 and then Present (Full_View (Typ))
8439 then
8440 return Full_View (Typ);
8441 else
8442 return Typ;
8443 end if;
8444 end Find_Specific_Type;
8446 -----------------------------
8447 -- Find_Static_Alternative --
8448 -----------------------------
8450 function Find_Static_Alternative (N : Node_Id) return Node_Id is
8451 Expr : constant Node_Id := Expression (N);
8452 Val : constant Uint := Expr_Value (Expr);
8453 Alt : Node_Id;
8454 Choice : Node_Id;
8456 begin
8457 Alt := First (Alternatives (N));
8459 Search : loop
8460 if Nkind (Alt) /= N_Pragma then
8461 Choice := First (Discrete_Choices (Alt));
8462 while Present (Choice) loop
8464 -- Others choice, always matches
8466 if Nkind (Choice) = N_Others_Choice then
8467 exit Search;
8469 -- Range, check if value is in the range
8471 elsif Nkind (Choice) = N_Range then
8472 exit Search when
8473 Val >= Expr_Value (Low_Bound (Choice))
8474 and then
8475 Val <= Expr_Value (High_Bound (Choice));
8477 -- Choice is a subtype name. Note that we know it must
8478 -- be a static subtype, since otherwise it would have
8479 -- been diagnosed as illegal.
8481 elsif Is_Entity_Name (Choice)
8482 and then Is_Type (Entity (Choice))
8483 then
8484 exit Search when Is_In_Range (Expr, Etype (Choice),
8485 Assume_Valid => False);
8487 -- Choice is a subtype indication
8489 elsif Nkind (Choice) = N_Subtype_Indication then
8490 declare
8491 C : constant Node_Id := Constraint (Choice);
8492 R : constant Node_Id := Range_Expression (C);
8494 begin
8495 exit Search when
8496 Val >= Expr_Value (Low_Bound (R))
8497 and then
8498 Val <= Expr_Value (High_Bound (R));
8499 end;
8501 -- Choice is a simple expression
8503 else
8504 exit Search when Val = Expr_Value (Choice);
8505 end if;
8507 Next (Choice);
8508 end loop;
8509 end if;
8511 Next (Alt);
8512 pragma Assert (Present (Alt));
8513 end loop Search;
8515 -- The above loop *must* terminate by finding a match, since we know the
8516 -- case statement is valid, and the value of the expression is known at
8517 -- compile time. When we fall out of the loop, Alt points to the
8518 -- alternative that we know will be selected at run time.
8520 return Alt;
8521 end Find_Static_Alternative;
8523 ------------------
8524 -- First_Actual --
8525 ------------------
8527 function First_Actual (Node : Node_Id) return Node_Id is
8528 N : Node_Id;
8530 begin
8531 if No (Parameter_Associations (Node)) then
8532 return Empty;
8533 end if;
8535 N := First (Parameter_Associations (Node));
8537 if Nkind (N) = N_Parameter_Association then
8538 return First_Named_Actual (Node);
8539 else
8540 return N;
8541 end if;
8542 end First_Actual;
8544 ------------------
8545 -- First_Global --
8546 ------------------
8548 function First_Global
8549 (Subp : Entity_Id;
8550 Global_Mode : Name_Id;
8551 Refined : Boolean := False) return Node_Id
8553 function First_From_Global_List
8554 (List : Node_Id;
8555 Global_Mode : Name_Id := Name_Input) return Entity_Id;
8556 -- Get the first item with suitable mode from List
8558 ----------------------------
8559 -- First_From_Global_List --
8560 ----------------------------
8562 function First_From_Global_List
8563 (List : Node_Id;
8564 Global_Mode : Name_Id := Name_Input) return Entity_Id
8566 Assoc : Node_Id;
8568 begin
8569 -- Empty list (no global items)
8571 if Nkind (List) = N_Null then
8572 return Empty;
8574 -- Single global item declaration (only input items)
8576 elsif Nkind_In (List, N_Expanded_Name,
8577 N_Identifier,
8578 N_Selected_Component)
8579 then
8580 if Global_Mode = Name_Input then
8581 return List;
8582 else
8583 return Empty;
8584 end if;
8586 -- Simple global list (only input items) or moded global list
8587 -- declaration.
8589 elsif Nkind (List) = N_Aggregate then
8590 if Present (Expressions (List)) then
8591 if Global_Mode = Name_Input then
8592 return First (Expressions (List));
8593 else
8594 return Empty;
8595 end if;
8597 else
8598 Assoc := First (Component_Associations (List));
8599 while Present (Assoc) loop
8601 -- When we find the desired mode in an association, call
8602 -- recursively First_From_Global_List as if the mode was
8603 -- Name_Input, in order to reuse the existing machinery
8604 -- for the other cases.
8606 if Chars (First (Choices (Assoc))) = Global_Mode then
8607 return First_From_Global_List (Expression (Assoc));
8608 end if;
8610 Next (Assoc);
8611 end loop;
8613 return Empty;
8614 end if;
8616 -- To accommodate partial decoration of disabled SPARK features,
8617 -- this routine may be called with illegal input. If this is the
8618 -- case, do not raise Program_Error.
8620 else
8621 return Empty;
8622 end if;
8623 end First_From_Global_List;
8625 -- Local variables
8627 Global : Node_Id := Empty;
8628 Body_Id : Entity_Id;
8630 begin
8631 pragma Assert (Global_Mode = Name_Input
8632 or else Global_Mode = Name_Output
8633 or else Global_Mode = Name_In_Out
8634 or else Global_Mode = Name_Proof_In);
8636 -- Retrieve the suitable pragma Global or Refined_Global. In the second
8637 -- case, it can only be located on the body entity.
8639 if Refined then
8640 Body_Id := Subprogram_Body_Entity (Subp);
8641 if Present (Body_Id) then
8642 Global := Get_Pragma (Body_Id, Pragma_Refined_Global);
8643 end if;
8644 else
8645 Global := Get_Pragma (Subp, Pragma_Global);
8646 end if;
8648 -- No corresponding global if pragma is not present
8650 if No (Global) then
8651 return Empty;
8653 -- Otherwise retrieve the corresponding list of items depending on the
8654 -- Global_Mode.
8656 else
8657 return First_From_Global_List
8658 (Expression (Get_Argument (Global, Subp)), Global_Mode);
8659 end if;
8660 end First_Global;
8662 -------------
8663 -- Fix_Msg --
8664 -------------
8666 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
8667 Is_Task : constant Boolean :=
8668 Ekind_In (Id, E_Task_Body, E_Task_Type)
8669 or else Is_Single_Task_Object (Id);
8670 Msg_Last : constant Natural := Msg'Last;
8671 Msg_Index : Natural;
8672 Res : String (Msg'Range) := (others => ' ');
8673 Res_Index : Natural;
8675 begin
8676 -- Copy all characters from the input message Msg to result Res with
8677 -- suitable replacements.
8679 Msg_Index := Msg'First;
8680 Res_Index := Res'First;
8681 while Msg_Index <= Msg_Last loop
8683 -- Replace "subprogram" with a different word
8685 if Msg_Index <= Msg_Last - 10
8686 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
8687 then
8688 if Ekind_In (Id, E_Entry, E_Entry_Family) then
8689 Res (Res_Index .. Res_Index + 4) := "entry";
8690 Res_Index := Res_Index + 5;
8692 elsif Is_Task then
8693 Res (Res_Index .. Res_Index + 8) := "task type";
8694 Res_Index := Res_Index + 9;
8696 else
8697 Res (Res_Index .. Res_Index + 9) := "subprogram";
8698 Res_Index := Res_Index + 10;
8699 end if;
8701 Msg_Index := Msg_Index + 10;
8703 -- Replace "protected" with a different word
8705 elsif Msg_Index <= Msg_Last - 9
8706 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
8707 and then Is_Task
8708 then
8709 Res (Res_Index .. Res_Index + 3) := "task";
8710 Res_Index := Res_Index + 4;
8711 Msg_Index := Msg_Index + 9;
8713 -- Otherwise copy the character
8715 else
8716 Res (Res_Index) := Msg (Msg_Index);
8717 Msg_Index := Msg_Index + 1;
8718 Res_Index := Res_Index + 1;
8719 end if;
8720 end loop;
8722 return Res (Res'First .. Res_Index - 1);
8723 end Fix_Msg;
8725 -------------------------
8726 -- From_Nested_Package --
8727 -------------------------
8729 function From_Nested_Package (T : Entity_Id) return Boolean is
8730 Pack : constant Entity_Id := Scope (T);
8732 begin
8733 return
8734 Ekind (Pack) = E_Package
8735 and then not Is_Frozen (Pack)
8736 and then not Scope_Within_Or_Same (Current_Scope, Pack)
8737 and then In_Open_Scopes (Scope (Pack));
8738 end From_Nested_Package;
8740 -----------------------
8741 -- Gather_Components --
8742 -----------------------
8744 procedure Gather_Components
8745 (Typ : Entity_Id;
8746 Comp_List : Node_Id;
8747 Governed_By : List_Id;
8748 Into : Elist_Id;
8749 Report_Errors : out Boolean)
8751 Assoc : Node_Id;
8752 Variant : Node_Id;
8753 Discrete_Choice : Node_Id;
8754 Comp_Item : Node_Id;
8756 Discrim : Entity_Id;
8757 Discrim_Name : Node_Id;
8758 Discrim_Value : Node_Id;
8760 begin
8761 Report_Errors := False;
8763 if No (Comp_List) or else Null_Present (Comp_List) then
8764 return;
8766 elsif Present (Component_Items (Comp_List)) then
8767 Comp_Item := First (Component_Items (Comp_List));
8769 else
8770 Comp_Item := Empty;
8771 end if;
8773 while Present (Comp_Item) loop
8775 -- Skip the tag of a tagged record, the interface tags, as well
8776 -- as all items that are not user components (anonymous types,
8777 -- rep clauses, Parent field, controller field).
8779 if Nkind (Comp_Item) = N_Component_Declaration then
8780 declare
8781 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
8782 begin
8783 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
8784 Append_Elmt (Comp, Into);
8785 end if;
8786 end;
8787 end if;
8789 Next (Comp_Item);
8790 end loop;
8792 if No (Variant_Part (Comp_List)) then
8793 return;
8794 else
8795 Discrim_Name := Name (Variant_Part (Comp_List));
8796 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
8797 end if;
8799 -- Look for the discriminant that governs this variant part.
8800 -- The discriminant *must* be in the Governed_By List
8802 Assoc := First (Governed_By);
8803 Find_Constraint : loop
8804 Discrim := First (Choices (Assoc));
8805 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
8806 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
8807 and then
8808 Chars (Corresponding_Discriminant (Entity (Discrim))) =
8809 Chars (Discrim_Name))
8810 or else Chars (Original_Record_Component (Entity (Discrim)))
8811 = Chars (Discrim_Name);
8813 if No (Next (Assoc)) then
8814 if not Is_Constrained (Typ)
8815 and then Is_Derived_Type (Typ)
8816 and then Present (Stored_Constraint (Typ))
8817 then
8818 -- If the type is a tagged type with inherited discriminants,
8819 -- use the stored constraint on the parent in order to find
8820 -- the values of discriminants that are otherwise hidden by an
8821 -- explicit constraint. Renamed discriminants are handled in
8822 -- the code above.
8824 -- If several parent discriminants are renamed by a single
8825 -- discriminant of the derived type, the call to obtain the
8826 -- Corresponding_Discriminant field only retrieves the last
8827 -- of them. We recover the constraint on the others from the
8828 -- Stored_Constraint as well.
8830 declare
8831 D : Entity_Id;
8832 C : Elmt_Id;
8834 begin
8835 D := First_Discriminant (Etype (Typ));
8836 C := First_Elmt (Stored_Constraint (Typ));
8837 while Present (D) and then Present (C) loop
8838 if Chars (Discrim_Name) = Chars (D) then
8839 if Is_Entity_Name (Node (C))
8840 and then Entity (Node (C)) = Entity (Discrim)
8841 then
8842 -- D is renamed by Discrim, whose value is given in
8843 -- Assoc.
8845 null;
8847 else
8848 Assoc :=
8849 Make_Component_Association (Sloc (Typ),
8850 New_List
8851 (New_Occurrence_Of (D, Sloc (Typ))),
8852 Duplicate_Subexpr_No_Checks (Node (C)));
8853 end if;
8854 exit Find_Constraint;
8855 end if;
8857 Next_Discriminant (D);
8858 Next_Elmt (C);
8859 end loop;
8860 end;
8861 end if;
8862 end if;
8864 if No (Next (Assoc)) then
8865 Error_Msg_NE (" missing value for discriminant&",
8866 First (Governed_By), Discrim_Name);
8867 Report_Errors := True;
8868 return;
8869 end if;
8871 Next (Assoc);
8872 end loop Find_Constraint;
8874 Discrim_Value := Expression (Assoc);
8876 if not Is_OK_Static_Expression (Discrim_Value) then
8878 -- If the variant part is governed by a discriminant of the type
8879 -- this is an error. If the variant part and the discriminant are
8880 -- inherited from an ancestor this is legal (AI05-120) unless the
8881 -- components are being gathered for an aggregate, in which case
8882 -- the caller must check Report_Errors.
8884 if Scope (Original_Record_Component
8885 ((Entity (First (Choices (Assoc)))))) = Typ
8886 then
8887 Error_Msg_FE
8888 ("value for discriminant & must be static!",
8889 Discrim_Value, Discrim);
8890 Why_Not_Static (Discrim_Value);
8891 end if;
8893 Report_Errors := True;
8894 return;
8895 end if;
8897 Search_For_Discriminant_Value : declare
8898 Low : Node_Id;
8899 High : Node_Id;
8901 UI_High : Uint;
8902 UI_Low : Uint;
8903 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
8905 begin
8906 Find_Discrete_Value : while Present (Variant) loop
8907 Discrete_Choice := First (Discrete_Choices (Variant));
8908 while Present (Discrete_Choice) loop
8909 exit Find_Discrete_Value when
8910 Nkind (Discrete_Choice) = N_Others_Choice;
8912 Get_Index_Bounds (Discrete_Choice, Low, High);
8914 UI_Low := Expr_Value (Low);
8915 UI_High := Expr_Value (High);
8917 exit Find_Discrete_Value when
8918 UI_Low <= UI_Discrim_Value
8919 and then
8920 UI_High >= UI_Discrim_Value;
8922 Next (Discrete_Choice);
8923 end loop;
8925 Next_Non_Pragma (Variant);
8926 end loop Find_Discrete_Value;
8927 end Search_For_Discriminant_Value;
8929 -- The case statement must include a variant that corresponds to the
8930 -- value of the discriminant, unless the discriminant type has a
8931 -- static predicate. In that case the absence of an others_choice that
8932 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8934 if No (Variant)
8935 and then not Has_Static_Predicate (Etype (Discrim_Name))
8936 then
8937 Error_Msg_NE
8938 ("value of discriminant & is out of range", Discrim_Value, Discrim);
8939 Report_Errors := True;
8940 return;
8941 end if;
8943 -- If we have found the corresponding choice, recursively add its
8944 -- components to the Into list. The nested components are part of
8945 -- the same record type.
8947 if Present (Variant) then
8948 Gather_Components
8949 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
8950 end if;
8951 end Gather_Components;
8953 ------------------------
8954 -- Get_Actual_Subtype --
8955 ------------------------
8957 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
8958 Typ : constant Entity_Id := Etype (N);
8959 Utyp : Entity_Id := Underlying_Type (Typ);
8960 Decl : Node_Id;
8961 Atyp : Entity_Id;
8963 begin
8964 if No (Utyp) then
8965 Utyp := Typ;
8966 end if;
8968 -- If what we have is an identifier that references a subprogram
8969 -- formal, or a variable or constant object, then we get the actual
8970 -- subtype from the referenced entity if one has been built.
8972 if Nkind (N) = N_Identifier
8973 and then
8974 (Is_Formal (Entity (N))
8975 or else Ekind (Entity (N)) = E_Constant
8976 or else Ekind (Entity (N)) = E_Variable)
8977 and then Present (Actual_Subtype (Entity (N)))
8978 then
8979 return Actual_Subtype (Entity (N));
8981 -- Actual subtype of unchecked union is always itself. We never need
8982 -- the "real" actual subtype. If we did, we couldn't get it anyway
8983 -- because the discriminant is not available. The restrictions on
8984 -- Unchecked_Union are designed to make sure that this is OK.
8986 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
8987 return Typ;
8989 -- Here for the unconstrained case, we must find actual subtype
8990 -- No actual subtype is available, so we must build it on the fly.
8992 -- Checking the type, not the underlying type, for constrainedness
8993 -- seems to be necessary. Maybe all the tests should be on the type???
8995 elsif (not Is_Constrained (Typ))
8996 and then (Is_Array_Type (Utyp)
8997 or else (Is_Record_Type (Utyp)
8998 and then Has_Discriminants (Utyp)))
8999 and then not Has_Unknown_Discriminants (Utyp)
9000 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
9001 then
9002 -- Nothing to do if in spec expression (why not???)
9004 if In_Spec_Expression then
9005 return Typ;
9007 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
9009 -- If the type has no discriminants, there is no subtype to
9010 -- build, even if the underlying type is discriminated.
9012 return Typ;
9014 -- Else build the actual subtype
9016 else
9017 Decl := Build_Actual_Subtype (Typ, N);
9018 Atyp := Defining_Identifier (Decl);
9020 -- If Build_Actual_Subtype generated a new declaration then use it
9022 if Atyp /= Typ then
9024 -- The actual subtype is an Itype, so analyze the declaration,
9025 -- but do not attach it to the tree, to get the type defined.
9027 Set_Parent (Decl, N);
9028 Set_Is_Itype (Atyp);
9029 Analyze (Decl, Suppress => All_Checks);
9030 Set_Associated_Node_For_Itype (Atyp, N);
9031 Set_Has_Delayed_Freeze (Atyp, False);
9033 -- We need to freeze the actual subtype immediately. This is
9034 -- needed, because otherwise this Itype will not get frozen
9035 -- at all, and it is always safe to freeze on creation because
9036 -- any associated types must be frozen at this point.
9038 Freeze_Itype (Atyp, N);
9039 return Atyp;
9041 -- Otherwise we did not build a declaration, so return original
9043 else
9044 return Typ;
9045 end if;
9046 end if;
9048 -- For all remaining cases, the actual subtype is the same as
9049 -- the nominal type.
9051 else
9052 return Typ;
9053 end if;
9054 end Get_Actual_Subtype;
9056 -------------------------------------
9057 -- Get_Actual_Subtype_If_Available --
9058 -------------------------------------
9060 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
9061 Typ : constant Entity_Id := Etype (N);
9063 begin
9064 -- If what we have is an identifier that references a subprogram
9065 -- formal, or a variable or constant object, then we get the actual
9066 -- subtype from the referenced entity if one has been built.
9068 if Nkind (N) = N_Identifier
9069 and then
9070 (Is_Formal (Entity (N))
9071 or else Ekind (Entity (N)) = E_Constant
9072 or else Ekind (Entity (N)) = E_Variable)
9073 and then Present (Actual_Subtype (Entity (N)))
9074 then
9075 return Actual_Subtype (Entity (N));
9077 -- Otherwise the Etype of N is returned unchanged
9079 else
9080 return Typ;
9081 end if;
9082 end Get_Actual_Subtype_If_Available;
9084 ------------------------
9085 -- Get_Body_From_Stub --
9086 ------------------------
9088 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
9089 begin
9090 return Proper_Body (Unit (Library_Unit (N)));
9091 end Get_Body_From_Stub;
9093 ---------------------
9094 -- Get_Cursor_Type --
9095 ---------------------
9097 function Get_Cursor_Type
9098 (Aspect : Node_Id;
9099 Typ : Entity_Id) return Entity_Id
9101 Assoc : Node_Id;
9102 Func : Entity_Id;
9103 First_Op : Entity_Id;
9104 Cursor : Entity_Id;
9106 begin
9107 -- If error already detected, return
9109 if Error_Posted (Aspect) then
9110 return Any_Type;
9111 end if;
9113 -- The cursor type for an Iterable aspect is the return type of a
9114 -- non-overloaded First primitive operation. Locate association for
9115 -- First.
9117 Assoc := First (Component_Associations (Expression (Aspect)));
9118 First_Op := Any_Id;
9119 while Present (Assoc) loop
9120 if Chars (First (Choices (Assoc))) = Name_First then
9121 First_Op := Expression (Assoc);
9122 exit;
9123 end if;
9125 Next (Assoc);
9126 end loop;
9128 if First_Op = Any_Id then
9129 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
9130 return Any_Type;
9131 end if;
9133 Cursor := Any_Type;
9135 -- Locate function with desired name and profile in scope of type
9136 -- In the rare case where the type is an integer type, a base type
9137 -- is created for it, check that the base type of the first formal
9138 -- of First matches the base type of the domain.
9140 Func := First_Entity (Scope (Typ));
9141 while Present (Func) loop
9142 if Chars (Func) = Chars (First_Op)
9143 and then Ekind (Func) = E_Function
9144 and then Present (First_Formal (Func))
9145 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
9146 and then No (Next_Formal (First_Formal (Func)))
9147 then
9148 if Cursor /= Any_Type then
9149 Error_Msg_N
9150 ("Operation First for iterable type must be unique", Aspect);
9151 return Any_Type;
9152 else
9153 Cursor := Etype (Func);
9154 end if;
9155 end if;
9157 Next_Entity (Func);
9158 end loop;
9160 -- If not found, no way to resolve remaining primitives.
9162 if Cursor = Any_Type then
9163 Error_Msg_N
9164 ("No legal primitive operation First for Iterable type", Aspect);
9165 end if;
9167 return Cursor;
9168 end Get_Cursor_Type;
9170 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
9171 begin
9172 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
9173 end Get_Cursor_Type;
9175 -------------------------------
9176 -- Get_Default_External_Name --
9177 -------------------------------
9179 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
9180 begin
9181 Get_Decoded_Name_String (Chars (E));
9183 if Opt.External_Name_Imp_Casing = Uppercase then
9184 Set_Casing (All_Upper_Case);
9185 else
9186 Set_Casing (All_Lower_Case);
9187 end if;
9189 return
9190 Make_String_Literal (Sloc (E),
9191 Strval => String_From_Name_Buffer);
9192 end Get_Default_External_Name;
9194 --------------------------
9195 -- Get_Enclosing_Object --
9196 --------------------------
9198 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
9199 begin
9200 if Is_Entity_Name (N) then
9201 return Entity (N);
9202 else
9203 case Nkind (N) is
9204 when N_Indexed_Component
9205 | N_Selected_Component
9206 | N_Slice
9208 -- If not generating code, a dereference may be left implicit.
9209 -- In thoses cases, return Empty.
9211 if Is_Access_Type (Etype (Prefix (N))) then
9212 return Empty;
9213 else
9214 return Get_Enclosing_Object (Prefix (N));
9215 end if;
9217 when N_Type_Conversion =>
9218 return Get_Enclosing_Object (Expression (N));
9220 when others =>
9221 return Empty;
9222 end case;
9223 end if;
9224 end Get_Enclosing_Object;
9226 ---------------------------
9227 -- Get_Enum_Lit_From_Pos --
9228 ---------------------------
9230 function Get_Enum_Lit_From_Pos
9231 (T : Entity_Id;
9232 Pos : Uint;
9233 Loc : Source_Ptr) return Node_Id
9235 Btyp : Entity_Id := Base_Type (T);
9236 Lit : Node_Id;
9237 LLoc : Source_Ptr;
9239 begin
9240 -- In the case where the literal is of type Character, Wide_Character
9241 -- or Wide_Wide_Character or of a type derived from them, there needs
9242 -- to be some special handling since there is no explicit chain of
9243 -- literals to search. Instead, an N_Character_Literal node is created
9244 -- with the appropriate Char_Code and Chars fields.
9246 if Is_Standard_Character_Type (T) then
9247 Set_Character_Literal_Name (UI_To_CC (Pos));
9249 return
9250 Make_Character_Literal (Loc,
9251 Chars => Name_Find,
9252 Char_Literal_Value => Pos);
9254 -- For all other cases, we have a complete table of literals, and
9255 -- we simply iterate through the chain of literal until the one
9256 -- with the desired position value is found.
9258 else
9259 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
9260 Btyp := Full_View (Btyp);
9261 end if;
9263 Lit := First_Literal (Btyp);
9265 -- Position in the enumeration type starts at 0
9267 if UI_To_Int (Pos) < 0 then
9268 raise Constraint_Error;
9269 end if;
9271 for J in 1 .. UI_To_Int (Pos) loop
9272 Next_Literal (Lit);
9274 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
9275 -- inside the loop to avoid calling Next_Literal on Empty.
9277 if No (Lit) then
9278 raise Constraint_Error;
9279 end if;
9280 end loop;
9282 -- Create a new node from Lit, with source location provided by Loc
9283 -- if not equal to No_Location, or by copying the source location of
9284 -- Lit otherwise.
9286 LLoc := Loc;
9288 if LLoc = No_Location then
9289 LLoc := Sloc (Lit);
9290 end if;
9292 return New_Occurrence_Of (Lit, LLoc);
9293 end if;
9294 end Get_Enum_Lit_From_Pos;
9296 ------------------------
9297 -- Get_Generic_Entity --
9298 ------------------------
9300 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
9301 Ent : constant Entity_Id := Entity (Name (N));
9302 begin
9303 if Present (Renamed_Object (Ent)) then
9304 return Renamed_Object (Ent);
9305 else
9306 return Ent;
9307 end if;
9308 end Get_Generic_Entity;
9310 -------------------------------------
9311 -- Get_Incomplete_View_Of_Ancestor --
9312 -------------------------------------
9314 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
9315 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9316 Par_Scope : Entity_Id;
9317 Par_Type : Entity_Id;
9319 begin
9320 -- The incomplete view of an ancestor is only relevant for private
9321 -- derived types in child units.
9323 if not Is_Derived_Type (E)
9324 or else not Is_Child_Unit (Cur_Unit)
9325 then
9326 return Empty;
9328 else
9329 Par_Scope := Scope (Cur_Unit);
9330 if No (Par_Scope) then
9331 return Empty;
9332 end if;
9334 Par_Type := Etype (Base_Type (E));
9336 -- Traverse list of ancestor types until we find one declared in
9337 -- a parent or grandparent unit (two levels seem sufficient).
9339 while Present (Par_Type) loop
9340 if Scope (Par_Type) = Par_Scope
9341 or else Scope (Par_Type) = Scope (Par_Scope)
9342 then
9343 return Par_Type;
9345 elsif not Is_Derived_Type (Par_Type) then
9346 return Empty;
9348 else
9349 Par_Type := Etype (Base_Type (Par_Type));
9350 end if;
9351 end loop;
9353 -- If none found, there is no relevant ancestor type.
9355 return Empty;
9356 end if;
9357 end Get_Incomplete_View_Of_Ancestor;
9359 ----------------------
9360 -- Get_Index_Bounds --
9361 ----------------------
9363 procedure Get_Index_Bounds
9364 (N : Node_Id;
9365 L : out Node_Id;
9366 H : out Node_Id;
9367 Use_Full_View : Boolean := False)
9369 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
9370 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
9371 -- Typ qualifies, the scalar range is obtained from the full view of the
9372 -- type.
9374 --------------------------
9375 -- Scalar_Range_Of_Type --
9376 --------------------------
9378 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
9379 T : Entity_Id := Typ;
9381 begin
9382 if Use_Full_View and then Present (Full_View (T)) then
9383 T := Full_View (T);
9384 end if;
9386 return Scalar_Range (T);
9387 end Scalar_Range_Of_Type;
9389 -- Local variables
9391 Kind : constant Node_Kind := Nkind (N);
9392 Rng : Node_Id;
9394 -- Start of processing for Get_Index_Bounds
9396 begin
9397 if Kind = N_Range then
9398 L := Low_Bound (N);
9399 H := High_Bound (N);
9401 elsif Kind = N_Subtype_Indication then
9402 Rng := Range_Expression (Constraint (N));
9404 if Rng = Error then
9405 L := Error;
9406 H := Error;
9407 return;
9409 else
9410 L := Low_Bound (Range_Expression (Constraint (N)));
9411 H := High_Bound (Range_Expression (Constraint (N)));
9412 end if;
9414 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
9415 Rng := Scalar_Range_Of_Type (Entity (N));
9417 if Error_Posted (Rng) then
9418 L := Error;
9419 H := Error;
9421 elsif Nkind (Rng) = N_Subtype_Indication then
9422 Get_Index_Bounds (Rng, L, H);
9424 else
9425 L := Low_Bound (Rng);
9426 H := High_Bound (Rng);
9427 end if;
9429 else
9430 -- N is an expression, indicating a range with one value
9432 L := N;
9433 H := N;
9434 end if;
9435 end Get_Index_Bounds;
9437 -----------------------------
9438 -- Get_Interfacing_Aspects --
9439 -----------------------------
9441 procedure Get_Interfacing_Aspects
9442 (Iface_Asp : Node_Id;
9443 Conv_Asp : out Node_Id;
9444 EN_Asp : out Node_Id;
9445 Expo_Asp : out Node_Id;
9446 Imp_Asp : out Node_Id;
9447 LN_Asp : out Node_Id;
9448 Do_Checks : Boolean := False)
9450 procedure Save_Or_Duplication_Error
9451 (Asp : Node_Id;
9452 To : in out Node_Id);
9453 -- Save the value of aspect Asp in node To. If To already has a value,
9454 -- then this is considered a duplicate use of aspect. Emit an error if
9455 -- flag Do_Checks is set.
9457 -------------------------------
9458 -- Save_Or_Duplication_Error --
9459 -------------------------------
9461 procedure Save_Or_Duplication_Error
9462 (Asp : Node_Id;
9463 To : in out Node_Id)
9465 begin
9466 -- Detect an extra aspect and issue an error
9468 if Present (To) then
9469 if Do_Checks then
9470 Error_Msg_Name_1 := Chars (Identifier (Asp));
9471 Error_Msg_Sloc := Sloc (To);
9472 Error_Msg_N ("aspect % previously given #", Asp);
9473 end if;
9475 -- Otherwise capture the aspect
9477 else
9478 To := Asp;
9479 end if;
9480 end Save_Or_Duplication_Error;
9482 -- Local variables
9484 Asp : Node_Id;
9485 Asp_Id : Aspect_Id;
9487 -- The following variables capture each individual aspect
9489 Conv : Node_Id := Empty;
9490 EN : Node_Id := Empty;
9491 Expo : Node_Id := Empty;
9492 Imp : Node_Id := Empty;
9493 LN : Node_Id := Empty;
9495 -- Start of processing for Get_Interfacing_Aspects
9497 begin
9498 -- The input interfacing aspect should reside in an aspect specification
9499 -- list.
9501 pragma Assert (Is_List_Member (Iface_Asp));
9503 -- Examine the aspect specifications of the related entity. Find and
9504 -- capture all interfacing aspects. Detect duplicates and emit errors
9505 -- if applicable.
9507 Asp := First (List_Containing (Iface_Asp));
9508 while Present (Asp) loop
9509 Asp_Id := Get_Aspect_Id (Asp);
9511 if Asp_Id = Aspect_Convention then
9512 Save_Or_Duplication_Error (Asp, Conv);
9514 elsif Asp_Id = Aspect_External_Name then
9515 Save_Or_Duplication_Error (Asp, EN);
9517 elsif Asp_Id = Aspect_Export then
9518 Save_Or_Duplication_Error (Asp, Expo);
9520 elsif Asp_Id = Aspect_Import then
9521 Save_Or_Duplication_Error (Asp, Imp);
9523 elsif Asp_Id = Aspect_Link_Name then
9524 Save_Or_Duplication_Error (Asp, LN);
9525 end if;
9527 Next (Asp);
9528 end loop;
9530 Conv_Asp := Conv;
9531 EN_Asp := EN;
9532 Expo_Asp := Expo;
9533 Imp_Asp := Imp;
9534 LN_Asp := LN;
9535 end Get_Interfacing_Aspects;
9537 ---------------------------------
9538 -- Get_Iterable_Type_Primitive --
9539 ---------------------------------
9541 function Get_Iterable_Type_Primitive
9542 (Typ : Entity_Id;
9543 Nam : Name_Id) return Entity_Id
9545 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
9546 Assoc : Node_Id;
9548 begin
9549 if No (Funcs) then
9550 return Empty;
9552 else
9553 Assoc := First (Component_Associations (Funcs));
9554 while Present (Assoc) loop
9555 if Chars (First (Choices (Assoc))) = Nam then
9556 return Entity (Expression (Assoc));
9557 end if;
9559 Assoc := Next (Assoc);
9560 end loop;
9562 return Empty;
9563 end if;
9564 end Get_Iterable_Type_Primitive;
9566 ----------------------------------
9567 -- Get_Library_Unit_Name_String --
9568 ----------------------------------
9570 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
9571 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
9573 begin
9574 Get_Unit_Name_String (Unit_Name_Id);
9576 -- Remove seven last character (" (spec)" or " (body)")
9578 Name_Len := Name_Len - 7;
9579 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
9580 end Get_Library_Unit_Name_String;
9582 --------------------------
9583 -- Get_Max_Queue_Length --
9584 --------------------------
9586 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
9587 pragma Assert (Is_Entry (Id));
9588 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
9590 begin
9591 -- A value of 0 represents no maximum specified, and entries and entry
9592 -- families with no Max_Queue_Length aspect or pragma default to it.
9594 if not Present (Prag) then
9595 return Uint_0;
9596 end if;
9598 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
9599 end Get_Max_Queue_Length;
9601 ------------------------
9602 -- Get_Name_Entity_Id --
9603 ------------------------
9605 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
9606 begin
9607 return Entity_Id (Get_Name_Table_Int (Id));
9608 end Get_Name_Entity_Id;
9610 ------------------------------
9611 -- Get_Name_From_CTC_Pragma --
9612 ------------------------------
9614 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
9615 Arg : constant Node_Id :=
9616 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
9617 begin
9618 return Strval (Expr_Value_S (Arg));
9619 end Get_Name_From_CTC_Pragma;
9621 -----------------------
9622 -- Get_Parent_Entity --
9623 -----------------------
9625 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
9626 begin
9627 if Nkind (Unit) = N_Package_Body
9628 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
9629 then
9630 return Defining_Entity
9631 (Specification (Instance_Spec (Original_Node (Unit))));
9632 elsif Nkind (Unit) = N_Package_Instantiation then
9633 return Defining_Entity (Specification (Instance_Spec (Unit)));
9634 else
9635 return Defining_Entity (Unit);
9636 end if;
9637 end Get_Parent_Entity;
9639 -------------------
9640 -- Get_Pragma_Id --
9641 -------------------
9643 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
9644 begin
9645 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
9646 end Get_Pragma_Id;
9648 ------------------------
9649 -- Get_Qualified_Name --
9650 ------------------------
9652 function Get_Qualified_Name
9653 (Id : Entity_Id;
9654 Suffix : Entity_Id := Empty) return Name_Id
9656 Suffix_Nam : Name_Id := No_Name;
9658 begin
9659 if Present (Suffix) then
9660 Suffix_Nam := Chars (Suffix);
9661 end if;
9663 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
9664 end Get_Qualified_Name;
9666 function Get_Qualified_Name
9667 (Nam : Name_Id;
9668 Suffix : Name_Id := No_Name;
9669 Scop : Entity_Id := Current_Scope) return Name_Id
9671 procedure Add_Scope (S : Entity_Id);
9672 -- Add the fully qualified form of scope S to the name buffer. The
9673 -- format is:
9674 -- s-1__s__
9676 ---------------
9677 -- Add_Scope --
9678 ---------------
9680 procedure Add_Scope (S : Entity_Id) is
9681 begin
9682 if S = Empty then
9683 null;
9685 elsif S = Standard_Standard then
9686 null;
9688 else
9689 Add_Scope (Scope (S));
9690 Get_Name_String_And_Append (Chars (S));
9691 Add_Str_To_Name_Buffer ("__");
9692 end if;
9693 end Add_Scope;
9695 -- Start of processing for Get_Qualified_Name
9697 begin
9698 Name_Len := 0;
9699 Add_Scope (Scop);
9701 -- Append the base name after all scopes have been chained
9703 Get_Name_String_And_Append (Nam);
9705 -- Append the suffix (if present)
9707 if Suffix /= No_Name then
9708 Add_Str_To_Name_Buffer ("__");
9709 Get_Name_String_And_Append (Suffix);
9710 end if;
9712 return Name_Find;
9713 end Get_Qualified_Name;
9715 -----------------------
9716 -- Get_Reason_String --
9717 -----------------------
9719 procedure Get_Reason_String (N : Node_Id) is
9720 begin
9721 if Nkind (N) = N_String_Literal then
9722 Store_String_Chars (Strval (N));
9724 elsif Nkind (N) = N_Op_Concat then
9725 Get_Reason_String (Left_Opnd (N));
9726 Get_Reason_String (Right_Opnd (N));
9728 -- If not of required form, error
9730 else
9731 Error_Msg_N
9732 ("Reason for pragma Warnings has wrong form", N);
9733 Error_Msg_N
9734 ("\must be string literal or concatenation of string literals", N);
9735 return;
9736 end if;
9737 end Get_Reason_String;
9739 --------------------------------
9740 -- Get_Reference_Discriminant --
9741 --------------------------------
9743 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
9744 D : Entity_Id;
9746 begin
9747 D := First_Discriminant (Typ);
9748 while Present (D) loop
9749 if Has_Implicit_Dereference (D) then
9750 return D;
9751 end if;
9752 Next_Discriminant (D);
9753 end loop;
9755 return Empty;
9756 end Get_Reference_Discriminant;
9758 ---------------------------
9759 -- Get_Referenced_Object --
9760 ---------------------------
9762 function Get_Referenced_Object (N : Node_Id) return Node_Id is
9763 R : Node_Id;
9765 begin
9766 R := N;
9767 while Is_Entity_Name (R)
9768 and then Present (Renamed_Object (Entity (R)))
9769 loop
9770 R := Renamed_Object (Entity (R));
9771 end loop;
9773 return R;
9774 end Get_Referenced_Object;
9776 ------------------------
9777 -- Get_Renamed_Entity --
9778 ------------------------
9780 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
9781 R : Entity_Id;
9783 begin
9784 R := E;
9785 while Present (Renamed_Entity (R)) loop
9786 R := Renamed_Entity (R);
9787 end loop;
9789 return R;
9790 end Get_Renamed_Entity;
9792 -----------------------
9793 -- Get_Return_Object --
9794 -----------------------
9796 function Get_Return_Object (N : Node_Id) return Entity_Id is
9797 Decl : Node_Id;
9799 begin
9800 Decl := First (Return_Object_Declarations (N));
9801 while Present (Decl) loop
9802 exit when Nkind (Decl) = N_Object_Declaration
9803 and then Is_Return_Object (Defining_Identifier (Decl));
9804 Next (Decl);
9805 end loop;
9807 pragma Assert (Present (Decl));
9808 return Defining_Identifier (Decl);
9809 end Get_Return_Object;
9811 ---------------------------
9812 -- Get_Subprogram_Entity --
9813 ---------------------------
9815 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
9816 Subp : Node_Id;
9817 Subp_Id : Entity_Id;
9819 begin
9820 if Nkind (Nod) = N_Accept_Statement then
9821 Subp := Entry_Direct_Name (Nod);
9823 elsif Nkind (Nod) = N_Slice then
9824 Subp := Prefix (Nod);
9826 else
9827 Subp := Name (Nod);
9828 end if;
9830 -- Strip the subprogram call
9832 loop
9833 if Nkind_In (Subp, N_Explicit_Dereference,
9834 N_Indexed_Component,
9835 N_Selected_Component)
9836 then
9837 Subp := Prefix (Subp);
9839 elsif Nkind_In (Subp, N_Type_Conversion,
9840 N_Unchecked_Type_Conversion)
9841 then
9842 Subp := Expression (Subp);
9844 else
9845 exit;
9846 end if;
9847 end loop;
9849 -- Extract the entity of the subprogram call
9851 if Is_Entity_Name (Subp) then
9852 Subp_Id := Entity (Subp);
9854 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
9855 Subp_Id := Directly_Designated_Type (Subp_Id);
9856 end if;
9858 if Is_Subprogram (Subp_Id) then
9859 return Subp_Id;
9860 else
9861 return Empty;
9862 end if;
9864 -- The search did not find a construct that denotes a subprogram
9866 else
9867 return Empty;
9868 end if;
9869 end Get_Subprogram_Entity;
9871 -----------------------------
9872 -- Get_Task_Body_Procedure --
9873 -----------------------------
9875 function Get_Task_Body_Procedure (E : Entity_Id) return Entity_Id is
9876 begin
9877 -- Note: A task type may be the completion of a private type with
9878 -- discriminants. When performing elaboration checks on a task
9879 -- declaration, the current view of the type may be the private one,
9880 -- and the procedure that holds the body of the task is held in its
9881 -- underlying type.
9883 -- This is an odd function, why not have Task_Body_Procedure do
9884 -- the following digging???
9886 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
9887 end Get_Task_Body_Procedure;
9889 -------------------------
9890 -- Get_User_Defined_Eq --
9891 -------------------------
9893 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
9894 Prim : Elmt_Id;
9895 Op : Entity_Id;
9897 begin
9898 Prim := First_Elmt (Collect_Primitive_Operations (E));
9899 while Present (Prim) loop
9900 Op := Node (Prim);
9902 if Chars (Op) = Name_Op_Eq
9903 and then Etype (Op) = Standard_Boolean
9904 and then Etype (First_Formal (Op)) = E
9905 and then Etype (Next_Formal (First_Formal (Op))) = E
9906 then
9907 return Op;
9908 end if;
9910 Next_Elmt (Prim);
9911 end loop;
9913 return Empty;
9914 end Get_User_Defined_Eq;
9916 ---------------
9917 -- Get_Views --
9918 ---------------
9920 procedure Get_Views
9921 (Typ : Entity_Id;
9922 Priv_Typ : out Entity_Id;
9923 Full_Typ : out Entity_Id;
9924 Full_Base : out Entity_Id;
9925 CRec_Typ : out Entity_Id)
9927 IP_View : Entity_Id;
9929 begin
9930 -- Assume that none of the views can be recovered
9932 Priv_Typ := Empty;
9933 Full_Typ := Empty;
9934 Full_Base := Empty;
9935 CRec_Typ := Empty;
9937 -- The input type is the corresponding record type of a protected or a
9938 -- task type.
9940 if Ekind (Typ) = E_Record_Type
9941 and then Is_Concurrent_Record_Type (Typ)
9942 then
9943 CRec_Typ := Typ;
9944 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
9945 Full_Base := Base_Type (Full_Typ);
9946 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
9948 -- Otherwise the input type denotes an arbitrary type
9950 else
9951 IP_View := Incomplete_Or_Partial_View (Typ);
9953 -- The input type denotes the full view of a private type
9955 if Present (IP_View) then
9956 Priv_Typ := IP_View;
9957 Full_Typ := Typ;
9959 -- The input type is a private type
9961 elsif Is_Private_Type (Typ) then
9962 Priv_Typ := Typ;
9963 Full_Typ := Full_View (Priv_Typ);
9965 -- Otherwise the input type does not have any views
9967 else
9968 Full_Typ := Typ;
9969 end if;
9971 if Present (Full_Typ) then
9972 Full_Base := Base_Type (Full_Typ);
9974 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
9975 CRec_Typ := Corresponding_Record_Type (Full_Typ);
9976 end if;
9977 end if;
9978 end if;
9979 end Get_Views;
9981 -----------------------
9982 -- Has_Access_Values --
9983 -----------------------
9985 function Has_Access_Values (T : Entity_Id) return Boolean is
9986 Typ : constant Entity_Id := Underlying_Type (T);
9988 begin
9989 -- Case of a private type which is not completed yet. This can only
9990 -- happen in the case of a generic format type appearing directly, or
9991 -- as a component of the type to which this function is being applied
9992 -- at the top level. Return False in this case, since we certainly do
9993 -- not know that the type contains access types.
9995 if No (Typ) then
9996 return False;
9998 elsif Is_Access_Type (Typ) then
9999 return True;
10001 elsif Is_Array_Type (Typ) then
10002 return Has_Access_Values (Component_Type (Typ));
10004 elsif Is_Record_Type (Typ) then
10005 declare
10006 Comp : Entity_Id;
10008 begin
10009 -- Loop to Check components
10011 Comp := First_Component_Or_Discriminant (Typ);
10012 while Present (Comp) loop
10014 -- Check for access component, tag field does not count, even
10015 -- though it is implemented internally using an access type.
10017 if Has_Access_Values (Etype (Comp))
10018 and then Chars (Comp) /= Name_uTag
10019 then
10020 return True;
10021 end if;
10023 Next_Component_Or_Discriminant (Comp);
10024 end loop;
10025 end;
10027 return False;
10029 else
10030 return False;
10031 end if;
10032 end Has_Access_Values;
10034 ------------------------------
10035 -- Has_Compatible_Alignment --
10036 ------------------------------
10038 function Has_Compatible_Alignment
10039 (Obj : Entity_Id;
10040 Expr : Node_Id;
10041 Layout_Done : Boolean) return Alignment_Result
10043 function Has_Compatible_Alignment_Internal
10044 (Obj : Entity_Id;
10045 Expr : Node_Id;
10046 Layout_Done : Boolean;
10047 Default : Alignment_Result) return Alignment_Result;
10048 -- This is the internal recursive function that actually does the work.
10049 -- There is one additional parameter, which says what the result should
10050 -- be if no alignment information is found, and there is no definite
10051 -- indication of compatible alignments. At the outer level, this is set
10052 -- to Unknown, but for internal recursive calls in the case where types
10053 -- are known to be correct, it is set to Known_Compatible.
10055 ---------------------------------------
10056 -- Has_Compatible_Alignment_Internal --
10057 ---------------------------------------
10059 function Has_Compatible_Alignment_Internal
10060 (Obj : Entity_Id;
10061 Expr : Node_Id;
10062 Layout_Done : Boolean;
10063 Default : Alignment_Result) return Alignment_Result
10065 Result : Alignment_Result := Known_Compatible;
10066 -- Holds the current status of the result. Note that once a value of
10067 -- Known_Incompatible is set, it is sticky and does not get changed
10068 -- to Unknown (the value in Result only gets worse as we go along,
10069 -- never better).
10071 Offs : Uint := No_Uint;
10072 -- Set to a factor of the offset from the base object when Expr is a
10073 -- selected or indexed component, based on Component_Bit_Offset and
10074 -- Component_Size respectively. A negative value is used to represent
10075 -- a value which is not known at compile time.
10077 procedure Check_Prefix;
10078 -- Checks the prefix recursively in the case where the expression
10079 -- is an indexed or selected component.
10081 procedure Set_Result (R : Alignment_Result);
10082 -- If R represents a worse outcome (unknown instead of known
10083 -- compatible, or known incompatible), then set Result to R.
10085 ------------------
10086 -- Check_Prefix --
10087 ------------------
10089 procedure Check_Prefix is
10090 begin
10091 -- The subtlety here is that in doing a recursive call to check
10092 -- the prefix, we have to decide what to do in the case where we
10093 -- don't find any specific indication of an alignment problem.
10095 -- At the outer level, we normally set Unknown as the result in
10096 -- this case, since we can only set Known_Compatible if we really
10097 -- know that the alignment value is OK, but for the recursive
10098 -- call, in the case where the types match, and we have not
10099 -- specified a peculiar alignment for the object, we are only
10100 -- concerned about suspicious rep clauses, the default case does
10101 -- not affect us, since the compiler will, in the absence of such
10102 -- rep clauses, ensure that the alignment is correct.
10104 if Default = Known_Compatible
10105 or else
10106 (Etype (Obj) = Etype (Expr)
10107 and then (Unknown_Alignment (Obj)
10108 or else
10109 Alignment (Obj) = Alignment (Etype (Obj))))
10110 then
10111 Set_Result
10112 (Has_Compatible_Alignment_Internal
10113 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
10115 -- In all other cases, we need a full check on the prefix
10117 else
10118 Set_Result
10119 (Has_Compatible_Alignment_Internal
10120 (Obj, Prefix (Expr), Layout_Done, Unknown));
10121 end if;
10122 end Check_Prefix;
10124 ----------------
10125 -- Set_Result --
10126 ----------------
10128 procedure Set_Result (R : Alignment_Result) is
10129 begin
10130 if R > Result then
10131 Result := R;
10132 end if;
10133 end Set_Result;
10135 -- Start of processing for Has_Compatible_Alignment_Internal
10137 begin
10138 -- If Expr is a selected component, we must make sure there is no
10139 -- potentially troublesome component clause and that the record is
10140 -- not packed if the layout is not done.
10142 if Nkind (Expr) = N_Selected_Component then
10144 -- Packing generates unknown alignment if layout is not done
10146 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
10147 Set_Result (Unknown);
10148 end if;
10150 -- Check prefix and component offset
10152 Check_Prefix;
10153 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
10155 -- If Expr is an indexed component, we must make sure there is no
10156 -- potentially troublesome Component_Size clause and that the array
10157 -- is not bit-packed if the layout is not done.
10159 elsif Nkind (Expr) = N_Indexed_Component then
10160 declare
10161 Typ : constant Entity_Id := Etype (Prefix (Expr));
10163 begin
10164 -- Packing generates unknown alignment if layout is not done
10166 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
10167 Set_Result (Unknown);
10168 end if;
10170 -- Check prefix and component offset (or at least size)
10172 Check_Prefix;
10173 Offs := Indexed_Component_Bit_Offset (Expr);
10174 if Offs = No_Uint then
10175 Offs := Component_Size (Typ);
10176 end if;
10177 end;
10178 end if;
10180 -- If we have a null offset, the result is entirely determined by
10181 -- the base object and has already been computed recursively.
10183 if Offs = Uint_0 then
10184 null;
10186 -- Case where we know the alignment of the object
10188 elsif Known_Alignment (Obj) then
10189 declare
10190 ObjA : constant Uint := Alignment (Obj);
10191 ExpA : Uint := No_Uint;
10192 SizA : Uint := No_Uint;
10194 begin
10195 -- If alignment of Obj is 1, then we are always OK
10197 if ObjA = 1 then
10198 Set_Result (Known_Compatible);
10200 -- Alignment of Obj is greater than 1, so we need to check
10202 else
10203 -- If we have an offset, see if it is compatible
10205 if Offs /= No_Uint and Offs > Uint_0 then
10206 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
10207 Set_Result (Known_Incompatible);
10208 end if;
10210 -- See if Expr is an object with known alignment
10212 elsif Is_Entity_Name (Expr)
10213 and then Known_Alignment (Entity (Expr))
10214 then
10215 ExpA := Alignment (Entity (Expr));
10217 -- Otherwise, we can use the alignment of the type of
10218 -- Expr given that we already checked for
10219 -- discombobulating rep clauses for the cases of indexed
10220 -- and selected components above.
10222 elsif Known_Alignment (Etype (Expr)) then
10223 ExpA := Alignment (Etype (Expr));
10225 -- Otherwise the alignment is unknown
10227 else
10228 Set_Result (Default);
10229 end if;
10231 -- If we got an alignment, see if it is acceptable
10233 if ExpA /= No_Uint and then ExpA < ObjA then
10234 Set_Result (Known_Incompatible);
10235 end if;
10237 -- If Expr is not a piece of a larger object, see if size
10238 -- is given. If so, check that it is not too small for the
10239 -- required alignment.
10241 if Offs /= No_Uint then
10242 null;
10244 -- See if Expr is an object with known size
10246 elsif Is_Entity_Name (Expr)
10247 and then Known_Static_Esize (Entity (Expr))
10248 then
10249 SizA := Esize (Entity (Expr));
10251 -- Otherwise, we check the object size of the Expr type
10253 elsif Known_Static_Esize (Etype (Expr)) then
10254 SizA := Esize (Etype (Expr));
10255 end if;
10257 -- If we got a size, see if it is a multiple of the Obj
10258 -- alignment, if not, then the alignment cannot be
10259 -- acceptable, since the size is always a multiple of the
10260 -- alignment.
10262 if SizA /= No_Uint then
10263 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
10264 Set_Result (Known_Incompatible);
10265 end if;
10266 end if;
10267 end if;
10268 end;
10270 -- If we do not know required alignment, any non-zero offset is a
10271 -- potential problem (but certainly may be OK, so result is unknown).
10273 elsif Offs /= No_Uint then
10274 Set_Result (Unknown);
10276 -- If we can't find the result by direct comparison of alignment
10277 -- values, then there is still one case that we can determine known
10278 -- result, and that is when we can determine that the types are the
10279 -- same, and no alignments are specified. Then we known that the
10280 -- alignments are compatible, even if we don't know the alignment
10281 -- value in the front end.
10283 elsif Etype (Obj) = Etype (Expr) then
10285 -- Types are the same, but we have to check for possible size
10286 -- and alignments on the Expr object that may make the alignment
10287 -- different, even though the types are the same.
10289 if Is_Entity_Name (Expr) then
10291 -- First check alignment of the Expr object. Any alignment less
10292 -- than Maximum_Alignment is worrisome since this is the case
10293 -- where we do not know the alignment of Obj.
10295 if Known_Alignment (Entity (Expr))
10296 and then UI_To_Int (Alignment (Entity (Expr))) <
10297 Ttypes.Maximum_Alignment
10298 then
10299 Set_Result (Unknown);
10301 -- Now check size of Expr object. Any size that is not an
10302 -- even multiple of Maximum_Alignment is also worrisome
10303 -- since it may cause the alignment of the object to be less
10304 -- than the alignment of the type.
10306 elsif Known_Static_Esize (Entity (Expr))
10307 and then
10308 (UI_To_Int (Esize (Entity (Expr))) mod
10309 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
10310 /= 0
10311 then
10312 Set_Result (Unknown);
10314 -- Otherwise same type is decisive
10316 else
10317 Set_Result (Known_Compatible);
10318 end if;
10319 end if;
10321 -- Another case to deal with is when there is an explicit size or
10322 -- alignment clause when the types are not the same. If so, then the
10323 -- result is Unknown. We don't need to do this test if the Default is
10324 -- Unknown, since that result will be set in any case.
10326 elsif Default /= Unknown
10327 and then (Has_Size_Clause (Etype (Expr))
10328 or else
10329 Has_Alignment_Clause (Etype (Expr)))
10330 then
10331 Set_Result (Unknown);
10333 -- If no indication found, set default
10335 else
10336 Set_Result (Default);
10337 end if;
10339 -- Return worst result found
10341 return Result;
10342 end Has_Compatible_Alignment_Internal;
10344 -- Start of processing for Has_Compatible_Alignment
10346 begin
10347 -- If Obj has no specified alignment, then set alignment from the type
10348 -- alignment. Perhaps we should always do this, but for sure we should
10349 -- do it when there is an address clause since we can do more if the
10350 -- alignment is known.
10352 if Unknown_Alignment (Obj) then
10353 Set_Alignment (Obj, Alignment (Etype (Obj)));
10354 end if;
10356 -- Now do the internal call that does all the work
10358 return
10359 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
10360 end Has_Compatible_Alignment;
10362 ----------------------
10363 -- Has_Declarations --
10364 ----------------------
10366 function Has_Declarations (N : Node_Id) return Boolean is
10367 begin
10368 return Nkind_In (Nkind (N), N_Accept_Statement,
10369 N_Block_Statement,
10370 N_Compilation_Unit_Aux,
10371 N_Entry_Body,
10372 N_Package_Body,
10373 N_Protected_Body,
10374 N_Subprogram_Body,
10375 N_Task_Body,
10376 N_Package_Specification);
10377 end Has_Declarations;
10379 ---------------------------------
10380 -- Has_Defaulted_Discriminants --
10381 ---------------------------------
10383 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
10384 begin
10385 return Has_Discriminants (Typ)
10386 and then Present (First_Discriminant (Typ))
10387 and then Present (Discriminant_Default_Value
10388 (First_Discriminant (Typ)));
10389 end Has_Defaulted_Discriminants;
10391 -------------------
10392 -- Has_Denormals --
10393 -------------------
10395 function Has_Denormals (E : Entity_Id) return Boolean is
10396 begin
10397 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
10398 end Has_Denormals;
10400 -------------------------------------------
10401 -- Has_Discriminant_Dependent_Constraint --
10402 -------------------------------------------
10404 function Has_Discriminant_Dependent_Constraint
10405 (Comp : Entity_Id) return Boolean
10407 Comp_Decl : constant Node_Id := Parent (Comp);
10408 Subt_Indic : Node_Id;
10409 Constr : Node_Id;
10410 Assn : Node_Id;
10412 begin
10413 -- Discriminants can't depend on discriminants
10415 if Ekind (Comp) = E_Discriminant then
10416 return False;
10418 else
10419 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
10421 if Nkind (Subt_Indic) = N_Subtype_Indication then
10422 Constr := Constraint (Subt_Indic);
10424 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
10425 Assn := First (Constraints (Constr));
10426 while Present (Assn) loop
10427 case Nkind (Assn) is
10428 when N_Identifier
10429 | N_Range
10430 | N_Subtype_Indication
10432 if Depends_On_Discriminant (Assn) then
10433 return True;
10434 end if;
10436 when N_Discriminant_Association =>
10437 if Depends_On_Discriminant (Expression (Assn)) then
10438 return True;
10439 end if;
10441 when others =>
10442 null;
10443 end case;
10445 Next (Assn);
10446 end loop;
10447 end if;
10448 end if;
10449 end if;
10451 return False;
10452 end Has_Discriminant_Dependent_Constraint;
10454 --------------------------------------
10455 -- Has_Effectively_Volatile_Profile --
10456 --------------------------------------
10458 function Has_Effectively_Volatile_Profile
10459 (Subp_Id : Entity_Id) return Boolean
10461 Formal : Entity_Id;
10463 begin
10464 -- Inspect the formal parameters looking for an effectively volatile
10465 -- type.
10467 Formal := First_Formal (Subp_Id);
10468 while Present (Formal) loop
10469 if Is_Effectively_Volatile (Etype (Formal)) then
10470 return True;
10471 end if;
10473 Next_Formal (Formal);
10474 end loop;
10476 -- Inspect the return type of functions
10478 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
10479 and then Is_Effectively_Volatile (Etype (Subp_Id))
10480 then
10481 return True;
10482 end if;
10484 return False;
10485 end Has_Effectively_Volatile_Profile;
10487 --------------------------
10488 -- Has_Enabled_Property --
10489 --------------------------
10491 function Has_Enabled_Property
10492 (Item_Id : Entity_Id;
10493 Property : Name_Id) return Boolean
10495 function Protected_Object_Has_Enabled_Property return Boolean;
10496 -- Determine whether a protected object denoted by Item_Id has the
10497 -- property enabled.
10499 function State_Has_Enabled_Property return Boolean;
10500 -- Determine whether a state denoted by Item_Id has the property enabled
10502 function Variable_Has_Enabled_Property return Boolean;
10503 -- Determine whether a variable denoted by Item_Id has the property
10504 -- enabled.
10506 -------------------------------------------
10507 -- Protected_Object_Has_Enabled_Property --
10508 -------------------------------------------
10510 function Protected_Object_Has_Enabled_Property return Boolean is
10511 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
10512 Constit_Elmt : Elmt_Id;
10513 Constit_Id : Entity_Id;
10515 begin
10516 -- Protected objects always have the properties Async_Readers and
10517 -- Async_Writers (SPARK RM 7.1.2(16)).
10519 if Property = Name_Async_Readers
10520 or else Property = Name_Async_Writers
10521 then
10522 return True;
10524 -- Protected objects that have Part_Of components also inherit their
10525 -- properties Effective_Reads and Effective_Writes
10526 -- (SPARK RM 7.1.2(16)).
10528 elsif Present (Constits) then
10529 Constit_Elmt := First_Elmt (Constits);
10530 while Present (Constit_Elmt) loop
10531 Constit_Id := Node (Constit_Elmt);
10533 if Has_Enabled_Property (Constit_Id, Property) then
10534 return True;
10535 end if;
10537 Next_Elmt (Constit_Elmt);
10538 end loop;
10539 end if;
10541 return False;
10542 end Protected_Object_Has_Enabled_Property;
10544 --------------------------------
10545 -- State_Has_Enabled_Property --
10546 --------------------------------
10548 function State_Has_Enabled_Property return Boolean is
10549 Decl : constant Node_Id := Parent (Item_Id);
10551 procedure Find_Simple_Properties
10552 (Has_External : out Boolean;
10553 Has_Synchronous : out Boolean);
10554 -- Extract the simple properties associated with declaration Decl
10556 function Is_Enabled_External_Property return Boolean;
10557 -- Determine whether property Property appears within the external
10558 -- property list of declaration Decl, and return its status.
10560 ----------------------------
10561 -- Find_Simple_Properties --
10562 ----------------------------
10564 procedure Find_Simple_Properties
10565 (Has_External : out Boolean;
10566 Has_Synchronous : out Boolean)
10568 Opt : Node_Id;
10570 begin
10571 -- Assume that none of the properties are available
10573 Has_External := False;
10574 Has_Synchronous := False;
10576 Opt := First (Expressions (Decl));
10577 while Present (Opt) loop
10578 if Nkind (Opt) = N_Identifier then
10579 if Chars (Opt) = Name_External then
10580 Has_External := True;
10582 elsif Chars (Opt) = Name_Synchronous then
10583 Has_Synchronous := True;
10584 end if;
10585 end if;
10587 Next (Opt);
10588 end loop;
10589 end Find_Simple_Properties;
10591 ----------------------------------
10592 -- Is_Enabled_External_Property --
10593 ----------------------------------
10595 function Is_Enabled_External_Property return Boolean is
10596 Opt : Node_Id;
10597 Opt_Nam : Node_Id;
10598 Prop : Node_Id;
10599 Prop_Nam : Node_Id;
10600 Props : Node_Id;
10602 begin
10603 Opt := First (Component_Associations (Decl));
10604 while Present (Opt) loop
10605 Opt_Nam := First (Choices (Opt));
10607 if Nkind (Opt_Nam) = N_Identifier
10608 and then Chars (Opt_Nam) = Name_External
10609 then
10610 Props := Expression (Opt);
10612 -- Multiple properties appear as an aggregate
10614 if Nkind (Props) = N_Aggregate then
10616 -- Simple property form
10618 Prop := First (Expressions (Props));
10619 while Present (Prop) loop
10620 if Chars (Prop) = Property then
10621 return True;
10622 end if;
10624 Next (Prop);
10625 end loop;
10627 -- Property with expression form
10629 Prop := First (Component_Associations (Props));
10630 while Present (Prop) loop
10631 Prop_Nam := First (Choices (Prop));
10633 -- The property can be represented in two ways:
10634 -- others => <value>
10635 -- <property> => <value>
10637 if Nkind (Prop_Nam) = N_Others_Choice
10638 or else (Nkind (Prop_Nam) = N_Identifier
10639 and then Chars (Prop_Nam) = Property)
10640 then
10641 return Is_True (Expr_Value (Expression (Prop)));
10642 end if;
10644 Next (Prop);
10645 end loop;
10647 -- Single property
10649 else
10650 return Chars (Props) = Property;
10651 end if;
10652 end if;
10654 Next (Opt);
10655 end loop;
10657 return False;
10658 end Is_Enabled_External_Property;
10660 -- Local variables
10662 Has_External : Boolean;
10663 Has_Synchronous : Boolean;
10665 -- Start of processing for State_Has_Enabled_Property
10667 begin
10668 -- The declaration of an external abstract state appears as an
10669 -- extension aggregate. If this is not the case, properties can
10670 -- never be set.
10672 if Nkind (Decl) /= N_Extension_Aggregate then
10673 return False;
10674 end if;
10676 Find_Simple_Properties (Has_External, Has_Synchronous);
10678 -- Simple option External enables all properties (SPARK RM 7.1.2(2))
10680 if Has_External then
10681 return True;
10683 -- Option External may enable or disable specific properties
10685 elsif Is_Enabled_External_Property then
10686 return True;
10688 -- Simple option Synchronous
10690 -- enables disables
10691 -- Asynch_Readers Effective_Reads
10692 -- Asynch_Writers Effective_Writes
10694 -- Note that both forms of External have higher precedence than
10695 -- Synchronous (SPARK RM 7.1.4(10)).
10697 elsif Has_Synchronous then
10698 return Nam_In (Property, Name_Async_Readers, Name_Async_Writers);
10699 end if;
10701 return False;
10702 end State_Has_Enabled_Property;
10704 -----------------------------------
10705 -- Variable_Has_Enabled_Property --
10706 -----------------------------------
10708 function Variable_Has_Enabled_Property return Boolean is
10709 function Is_Enabled (Prag : Node_Id) return Boolean;
10710 -- Determine whether property pragma Prag (if present) denotes an
10711 -- enabled property.
10713 ----------------
10714 -- Is_Enabled --
10715 ----------------
10717 function Is_Enabled (Prag : Node_Id) return Boolean is
10718 Arg1 : Node_Id;
10720 begin
10721 if Present (Prag) then
10722 Arg1 := First (Pragma_Argument_Associations (Prag));
10724 -- The pragma has an optional Boolean expression, the related
10725 -- property is enabled only when the expression evaluates to
10726 -- True.
10728 if Present (Arg1) then
10729 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
10731 -- Otherwise the lack of expression enables the property by
10732 -- default.
10734 else
10735 return True;
10736 end if;
10738 -- The property was never set in the first place
10740 else
10741 return False;
10742 end if;
10743 end Is_Enabled;
10745 -- Local variables
10747 AR : constant Node_Id :=
10748 Get_Pragma (Item_Id, Pragma_Async_Readers);
10749 AW : constant Node_Id :=
10750 Get_Pragma (Item_Id, Pragma_Async_Writers);
10751 ER : constant Node_Id :=
10752 Get_Pragma (Item_Id, Pragma_Effective_Reads);
10753 EW : constant Node_Id :=
10754 Get_Pragma (Item_Id, Pragma_Effective_Writes);
10756 -- Start of processing for Variable_Has_Enabled_Property
10758 begin
10759 -- A non-effectively volatile object can never possess external
10760 -- properties.
10762 if not Is_Effectively_Volatile (Item_Id) then
10763 return False;
10765 -- External properties related to variables come in two flavors -
10766 -- explicit and implicit. The explicit case is characterized by the
10767 -- presence of a property pragma with an optional Boolean flag. The
10768 -- property is enabled when the flag evaluates to True or the flag is
10769 -- missing altogether.
10771 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
10772 return True;
10774 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
10775 return True;
10777 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
10778 return True;
10780 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
10781 return True;
10783 -- The implicit case lacks all property pragmas
10785 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
10786 if Is_Protected_Type (Etype (Item_Id)) then
10787 return Protected_Object_Has_Enabled_Property;
10788 else
10789 return True;
10790 end if;
10792 else
10793 return False;
10794 end if;
10795 end Variable_Has_Enabled_Property;
10797 -- Start of processing for Has_Enabled_Property
10799 begin
10800 -- Abstract states and variables have a flexible scheme of specifying
10801 -- external properties.
10803 if Ekind (Item_Id) = E_Abstract_State then
10804 return State_Has_Enabled_Property;
10806 elsif Ekind (Item_Id) = E_Variable then
10807 return Variable_Has_Enabled_Property;
10809 -- By default, protected objects only have the properties Async_Readers
10810 -- and Async_Writers. If they have Part_Of components, they also inherit
10811 -- their properties Effective_Reads and Effective_Writes
10812 -- (SPARK RM 7.1.2(16)).
10814 elsif Ekind (Item_Id) = E_Protected_Object then
10815 return Protected_Object_Has_Enabled_Property;
10817 -- Otherwise a property is enabled when the related item is effectively
10818 -- volatile.
10820 else
10821 return Is_Effectively_Volatile (Item_Id);
10822 end if;
10823 end Has_Enabled_Property;
10825 -------------------------------------
10826 -- Has_Full_Default_Initialization --
10827 -------------------------------------
10829 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
10830 Comp : Entity_Id;
10832 begin
10833 -- A type subject to pragma Default_Initial_Condition may be fully
10834 -- default initialized depending on inheritance and the argument of
10835 -- the pragma. Since any type may act as the full view of a private
10836 -- type, this check must be performed prior to the specialized tests
10837 -- below.
10839 if Has_Fully_Default_Initializing_DIC_Pragma (Typ) then
10840 return True;
10841 end if;
10843 -- A scalar type is fully default initialized if it is subject to aspect
10844 -- Default_Value.
10846 if Is_Scalar_Type (Typ) then
10847 return Has_Default_Aspect (Typ);
10849 -- An array type is fully default initialized if its element type is
10850 -- scalar and the array type carries aspect Default_Component_Value or
10851 -- the element type is fully default initialized.
10853 elsif Is_Array_Type (Typ) then
10854 return
10855 Has_Default_Aspect (Typ)
10856 or else Has_Full_Default_Initialization (Component_Type (Typ));
10858 -- A protected type, record type, or type extension is fully default
10859 -- initialized if all its components either carry an initialization
10860 -- expression or have a type that is fully default initialized. The
10861 -- parent type of a type extension must be fully default initialized.
10863 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
10865 -- Inspect all entities defined in the scope of the type, looking for
10866 -- uninitialized components.
10868 Comp := First_Entity (Typ);
10869 while Present (Comp) loop
10870 if Ekind (Comp) = E_Component
10871 and then Comes_From_Source (Comp)
10872 and then No (Expression (Parent (Comp)))
10873 and then not Has_Full_Default_Initialization (Etype (Comp))
10874 then
10875 return False;
10876 end if;
10878 Next_Entity (Comp);
10879 end loop;
10881 -- Ensure that the parent type of a type extension is fully default
10882 -- initialized.
10884 if Etype (Typ) /= Typ
10885 and then not Has_Full_Default_Initialization (Etype (Typ))
10886 then
10887 return False;
10888 end if;
10890 -- If we get here, then all components and parent portion are fully
10891 -- default initialized.
10893 return True;
10895 -- A task type is fully default initialized by default
10897 elsif Is_Task_Type (Typ) then
10898 return True;
10900 -- Otherwise the type is not fully default initialized
10902 else
10903 return False;
10904 end if;
10905 end Has_Full_Default_Initialization;
10907 -----------------------------------------------
10908 -- Has_Fully_Default_Initializing_DIC_Pragma --
10909 -----------------------------------------------
10911 function Has_Fully_Default_Initializing_DIC_Pragma
10912 (Typ : Entity_Id) return Boolean
10914 Args : List_Id;
10915 Prag : Node_Id;
10917 begin
10918 -- A type that inherits pragma Default_Initial_Condition from a parent
10919 -- type is automatically fully default initialized.
10921 if Has_Inherited_DIC (Typ) then
10922 return True;
10924 -- Otherwise the type is fully default initialized only when the pragma
10925 -- appears without an argument, or the argument is non-null.
10927 elsif Has_Own_DIC (Typ) then
10928 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
10929 pragma Assert (Present (Prag));
10930 Args := Pragma_Argument_Associations (Prag);
10932 -- The pragma appears without an argument in which case it defaults
10933 -- to True.
10935 if No (Args) then
10936 return True;
10938 -- The pragma appears with a non-null expression
10940 elsif Nkind (Get_Pragma_Arg (First (Args))) /= N_Null then
10941 return True;
10942 end if;
10943 end if;
10945 return False;
10946 end Has_Fully_Default_Initializing_DIC_Pragma;
10948 --------------------
10949 -- Has_Infinities --
10950 --------------------
10952 function Has_Infinities (E : Entity_Id) return Boolean is
10953 begin
10954 return
10955 Is_Floating_Point_Type (E)
10956 and then Nkind (Scalar_Range (E)) = N_Range
10957 and then Includes_Infinities (Scalar_Range (E));
10958 end Has_Infinities;
10960 --------------------
10961 -- Has_Interfaces --
10962 --------------------
10964 function Has_Interfaces
10965 (T : Entity_Id;
10966 Use_Full_View : Boolean := True) return Boolean
10968 Typ : Entity_Id := Base_Type (T);
10970 begin
10971 -- Handle concurrent types
10973 if Is_Concurrent_Type (Typ) then
10974 Typ := Corresponding_Record_Type (Typ);
10975 end if;
10977 if not Present (Typ)
10978 or else not Is_Record_Type (Typ)
10979 or else not Is_Tagged_Type (Typ)
10980 then
10981 return False;
10982 end if;
10984 -- Handle private types
10986 if Use_Full_View and then Present (Full_View (Typ)) then
10987 Typ := Full_View (Typ);
10988 end if;
10990 -- Handle concurrent record types
10992 if Is_Concurrent_Record_Type (Typ)
10993 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
10994 then
10995 return True;
10996 end if;
10998 loop
10999 if Is_Interface (Typ)
11000 or else
11001 (Is_Record_Type (Typ)
11002 and then Present (Interfaces (Typ))
11003 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
11004 then
11005 return True;
11006 end if;
11008 exit when Etype (Typ) = Typ
11010 -- Handle private types
11012 or else (Present (Full_View (Etype (Typ)))
11013 and then Full_View (Etype (Typ)) = Typ)
11015 -- Protect frontend against wrong sources with cyclic derivations
11017 or else Etype (Typ) = T;
11019 -- Climb to the ancestor type handling private types
11021 if Present (Full_View (Etype (Typ))) then
11022 Typ := Full_View (Etype (Typ));
11023 else
11024 Typ := Etype (Typ);
11025 end if;
11026 end loop;
11028 return False;
11029 end Has_Interfaces;
11031 --------------------------
11032 -- Has_Max_Queue_Length --
11033 --------------------------
11035 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
11036 begin
11037 return
11038 Ekind (Id) = E_Entry
11039 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
11040 end Has_Max_Queue_Length;
11042 ---------------------------------
11043 -- Has_No_Obvious_Side_Effects --
11044 ---------------------------------
11046 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
11047 begin
11048 -- For now handle literals, constants, and non-volatile variables and
11049 -- expressions combining these with operators or short circuit forms.
11051 if Nkind (N) in N_Numeric_Or_String_Literal then
11052 return True;
11054 elsif Nkind (N) = N_Character_Literal then
11055 return True;
11057 elsif Nkind (N) in N_Unary_Op then
11058 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
11060 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
11061 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
11062 and then
11063 Has_No_Obvious_Side_Effects (Right_Opnd (N));
11065 elsif Nkind (N) = N_Expression_With_Actions
11066 and then Is_Empty_List (Actions (N))
11067 then
11068 return Has_No_Obvious_Side_Effects (Expression (N));
11070 elsif Nkind (N) in N_Has_Entity then
11071 return Present (Entity (N))
11072 and then Ekind_In (Entity (N), E_Variable,
11073 E_Constant,
11074 E_Enumeration_Literal,
11075 E_In_Parameter,
11076 E_Out_Parameter,
11077 E_In_Out_Parameter)
11078 and then not Is_Volatile (Entity (N));
11080 else
11081 return False;
11082 end if;
11083 end Has_No_Obvious_Side_Effects;
11085 -----------------------------
11086 -- Has_Non_Null_Refinement --
11087 -----------------------------
11089 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
11090 Constits : Elist_Id;
11092 begin
11093 pragma Assert (Ekind (Id) = E_Abstract_State);
11094 Constits := Refinement_Constituents (Id);
11096 -- For a refinement to be non-null, the first constituent must be
11097 -- anything other than null.
11099 return
11100 Present (Constits)
11101 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
11102 end Has_Non_Null_Refinement;
11104 -----------------------------
11105 -- Has_Non_Null_Statements --
11106 -----------------------------
11108 function Has_Non_Null_Statements (L : List_Id) return Boolean is
11109 Node : Node_Id;
11111 begin
11112 if Is_Non_Empty_List (L) then
11113 Node := First (L);
11115 loop
11116 if Nkind (Node) /= N_Null_Statement then
11117 return True;
11118 end if;
11120 Next (Node);
11121 exit when Node = Empty;
11122 end loop;
11123 end if;
11125 return False;
11126 end Has_Non_Null_Statements;
11128 ----------------------------------
11129 -- Has_Non_Trivial_Precondition --
11130 ----------------------------------
11132 function Has_Non_Trivial_Precondition (Subp : Entity_Id) return Boolean is
11133 Pre : constant Node_Id := Find_Aspect (Subp, Aspect_Pre);
11135 begin
11136 return
11137 Present (Pre)
11138 and then Class_Present (Pre)
11139 and then not Is_Entity_Name (Expression (Pre));
11140 end Has_Non_Trivial_Precondition;
11142 -------------------
11143 -- Has_Null_Body --
11144 -------------------
11146 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
11147 Body_Id : Entity_Id;
11148 Decl : Node_Id;
11149 Spec : Node_Id;
11150 Stmt1 : Node_Id;
11151 Stmt2 : Node_Id;
11153 begin
11154 Spec := Parent (Proc_Id);
11155 Decl := Parent (Spec);
11157 -- Retrieve the entity of the procedure body (e.g. invariant proc).
11159 if Nkind (Spec) = N_Procedure_Specification
11160 and then Nkind (Decl) = N_Subprogram_Declaration
11161 then
11162 Body_Id := Corresponding_Body (Decl);
11164 -- The body acts as a spec
11166 else
11167 Body_Id := Proc_Id;
11168 end if;
11170 -- The body will be generated later
11172 if No (Body_Id) then
11173 return False;
11174 end if;
11176 Spec := Parent (Body_Id);
11177 Decl := Parent (Spec);
11179 pragma Assert
11180 (Nkind (Spec) = N_Procedure_Specification
11181 and then Nkind (Decl) = N_Subprogram_Body);
11183 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
11185 -- Look for a null statement followed by an optional return
11186 -- statement.
11188 if Nkind (Stmt1) = N_Null_Statement then
11189 Stmt2 := Next (Stmt1);
11191 if Present (Stmt2) then
11192 return Nkind (Stmt2) = N_Simple_Return_Statement;
11193 else
11194 return True;
11195 end if;
11196 end if;
11198 return False;
11199 end Has_Null_Body;
11201 ------------------------
11202 -- Has_Null_Exclusion --
11203 ------------------------
11205 function Has_Null_Exclusion (N : Node_Id) return Boolean is
11206 begin
11207 case Nkind (N) is
11208 when N_Access_Definition
11209 | N_Access_Function_Definition
11210 | N_Access_Procedure_Definition
11211 | N_Access_To_Object_Definition
11212 | N_Allocator
11213 | N_Derived_Type_Definition
11214 | N_Function_Specification
11215 | N_Subtype_Declaration
11217 return Null_Exclusion_Present (N);
11219 when N_Component_Definition
11220 | N_Formal_Object_Declaration
11221 | N_Object_Renaming_Declaration
11223 if Present (Subtype_Mark (N)) then
11224 return Null_Exclusion_Present (N);
11225 else pragma Assert (Present (Access_Definition (N)));
11226 return Null_Exclusion_Present (Access_Definition (N));
11227 end if;
11229 when N_Discriminant_Specification =>
11230 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
11231 return Null_Exclusion_Present (Discriminant_Type (N));
11232 else
11233 return Null_Exclusion_Present (N);
11234 end if;
11236 when N_Object_Declaration =>
11237 if Nkind (Object_Definition (N)) = N_Access_Definition then
11238 return Null_Exclusion_Present (Object_Definition (N));
11239 else
11240 return Null_Exclusion_Present (N);
11241 end if;
11243 when N_Parameter_Specification =>
11244 if Nkind (Parameter_Type (N)) = N_Access_Definition then
11245 return Null_Exclusion_Present (Parameter_Type (N));
11246 else
11247 return Null_Exclusion_Present (N);
11248 end if;
11250 when others =>
11251 return False;
11252 end case;
11253 end Has_Null_Exclusion;
11255 ------------------------
11256 -- Has_Null_Extension --
11257 ------------------------
11259 function Has_Null_Extension (T : Entity_Id) return Boolean is
11260 B : constant Entity_Id := Base_Type (T);
11261 Comps : Node_Id;
11262 Ext : Node_Id;
11264 begin
11265 if Nkind (Parent (B)) = N_Full_Type_Declaration
11266 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
11267 then
11268 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
11270 if Present (Ext) then
11271 if Null_Present (Ext) then
11272 return True;
11273 else
11274 Comps := Component_List (Ext);
11276 -- The null component list is rewritten during analysis to
11277 -- include the parent component. Any other component indicates
11278 -- that the extension was not originally null.
11280 return Null_Present (Comps)
11281 or else No (Next (First (Component_Items (Comps))));
11282 end if;
11283 else
11284 return False;
11285 end if;
11287 else
11288 return False;
11289 end if;
11290 end Has_Null_Extension;
11292 -------------------------
11293 -- Has_Null_Refinement --
11294 -------------------------
11296 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
11297 Constits : Elist_Id;
11299 begin
11300 pragma Assert (Ekind (Id) = E_Abstract_State);
11301 Constits := Refinement_Constituents (Id);
11303 -- For a refinement to be null, the state's sole constituent must be a
11304 -- null.
11306 return
11307 Present (Constits)
11308 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
11309 end Has_Null_Refinement;
11311 -------------------------------
11312 -- Has_Overriding_Initialize --
11313 -------------------------------
11315 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
11316 BT : constant Entity_Id := Base_Type (T);
11317 P : Elmt_Id;
11319 begin
11320 if Is_Controlled (BT) then
11321 if Is_RTU (Scope (BT), Ada_Finalization) then
11322 return False;
11324 elsif Present (Primitive_Operations (BT)) then
11325 P := First_Elmt (Primitive_Operations (BT));
11326 while Present (P) loop
11327 declare
11328 Init : constant Entity_Id := Node (P);
11329 Formal : constant Entity_Id := First_Formal (Init);
11330 begin
11331 if Ekind (Init) = E_Procedure
11332 and then Chars (Init) = Name_Initialize
11333 and then Comes_From_Source (Init)
11334 and then Present (Formal)
11335 and then Etype (Formal) = BT
11336 and then No (Next_Formal (Formal))
11337 and then (Ada_Version < Ada_2012
11338 or else not Null_Present (Parent (Init)))
11339 then
11340 return True;
11341 end if;
11342 end;
11344 Next_Elmt (P);
11345 end loop;
11346 end if;
11348 -- Here if type itself does not have a non-null Initialize operation:
11349 -- check immediate ancestor.
11351 if Is_Derived_Type (BT)
11352 and then Has_Overriding_Initialize (Etype (BT))
11353 then
11354 return True;
11355 end if;
11356 end if;
11358 return False;
11359 end Has_Overriding_Initialize;
11361 --------------------------------------
11362 -- Has_Preelaborable_Initialization --
11363 --------------------------------------
11365 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
11366 Has_PE : Boolean;
11368 procedure Check_Components (E : Entity_Id);
11369 -- Check component/discriminant chain, sets Has_PE False if a component
11370 -- or discriminant does not meet the preelaborable initialization rules.
11372 ----------------------
11373 -- Check_Components --
11374 ----------------------
11376 procedure Check_Components (E : Entity_Id) is
11377 Ent : Entity_Id;
11378 Exp : Node_Id;
11380 begin
11381 -- Loop through entities of record or protected type
11383 Ent := E;
11384 while Present (Ent) loop
11386 -- We are interested only in components and discriminants
11388 Exp := Empty;
11390 case Ekind (Ent) is
11391 when E_Component =>
11393 -- Get default expression if any. If there is no declaration
11394 -- node, it means we have an internal entity. The parent and
11395 -- tag fields are examples of such entities. For such cases,
11396 -- we just test the type of the entity.
11398 if Present (Declaration_Node (Ent)) then
11399 Exp := Expression (Declaration_Node (Ent));
11400 end if;
11402 when E_Discriminant =>
11404 -- Note: for a renamed discriminant, the Declaration_Node
11405 -- may point to the one from the ancestor, and have a
11406 -- different expression, so use the proper attribute to
11407 -- retrieve the expression from the derived constraint.
11409 Exp := Discriminant_Default_Value (Ent);
11411 when others =>
11412 goto Check_Next_Entity;
11413 end case;
11415 -- A component has PI if it has no default expression and the
11416 -- component type has PI.
11418 if No (Exp) then
11419 if not Has_Preelaborable_Initialization (Etype (Ent)) then
11420 Has_PE := False;
11421 exit;
11422 end if;
11424 -- Require the default expression to be preelaborable
11426 elsif not Is_Preelaborable_Construct (Exp) then
11427 Has_PE := False;
11428 exit;
11429 end if;
11431 <<Check_Next_Entity>>
11432 Next_Entity (Ent);
11433 end loop;
11434 end Check_Components;
11436 -- Start of processing for Has_Preelaborable_Initialization
11438 begin
11439 -- Immediate return if already marked as known preelaborable init. This
11440 -- covers types for which this function has already been called once
11441 -- and returned True (in which case the result is cached), and also
11442 -- types to which a pragma Preelaborable_Initialization applies.
11444 if Known_To_Have_Preelab_Init (E) then
11445 return True;
11446 end if;
11448 -- If the type is a subtype representing a generic actual type, then
11449 -- test whether its base type has preelaborable initialization since
11450 -- the subtype representing the actual does not inherit this attribute
11451 -- from the actual or formal. (but maybe it should???)
11453 if Is_Generic_Actual_Type (E) then
11454 return Has_Preelaborable_Initialization (Base_Type (E));
11455 end if;
11457 -- All elementary types have preelaborable initialization
11459 if Is_Elementary_Type (E) then
11460 Has_PE := True;
11462 -- Array types have PI if the component type has PI
11464 elsif Is_Array_Type (E) then
11465 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
11467 -- A derived type has preelaborable initialization if its parent type
11468 -- has preelaborable initialization and (in the case of a derived record
11469 -- extension) if the non-inherited components all have preelaborable
11470 -- initialization. However, a user-defined controlled type with an
11471 -- overriding Initialize procedure does not have preelaborable
11472 -- initialization.
11474 elsif Is_Derived_Type (E) then
11476 -- If the derived type is a private extension then it doesn't have
11477 -- preelaborable initialization.
11479 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
11480 return False;
11481 end if;
11483 -- First check whether ancestor type has preelaborable initialization
11485 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
11487 -- If OK, check extension components (if any)
11489 if Has_PE and then Is_Record_Type (E) then
11490 Check_Components (First_Entity (E));
11491 end if;
11493 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
11494 -- with a user defined Initialize procedure does not have PI. If
11495 -- the type is untagged, the control primitives come from a component
11496 -- that has already been checked.
11498 if Has_PE
11499 and then Is_Controlled (E)
11500 and then Is_Tagged_Type (E)
11501 and then Has_Overriding_Initialize (E)
11502 then
11503 Has_PE := False;
11504 end if;
11506 -- Private types not derived from a type having preelaborable init and
11507 -- that are not marked with pragma Preelaborable_Initialization do not
11508 -- have preelaborable initialization.
11510 elsif Is_Private_Type (E) then
11511 return False;
11513 -- Record type has PI if it is non private and all components have PI
11515 elsif Is_Record_Type (E) then
11516 Has_PE := True;
11517 Check_Components (First_Entity (E));
11519 -- Protected types must not have entries, and components must meet
11520 -- same set of rules as for record components.
11522 elsif Is_Protected_Type (E) then
11523 if Has_Entries (E) then
11524 Has_PE := False;
11525 else
11526 Has_PE := True;
11527 Check_Components (First_Entity (E));
11528 Check_Components (First_Private_Entity (E));
11529 end if;
11531 -- Type System.Address always has preelaborable initialization
11533 elsif Is_RTE (E, RE_Address) then
11534 Has_PE := True;
11536 -- In all other cases, type does not have preelaborable initialization
11538 else
11539 return False;
11540 end if;
11542 -- If type has preelaborable initialization, cache result
11544 if Has_PE then
11545 Set_Known_To_Have_Preelab_Init (E);
11546 end if;
11548 return Has_PE;
11549 end Has_Preelaborable_Initialization;
11551 ---------------------------
11552 -- Has_Private_Component --
11553 ---------------------------
11555 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
11556 Btype : Entity_Id := Base_Type (Type_Id);
11557 Component : Entity_Id;
11559 begin
11560 if Error_Posted (Type_Id)
11561 or else Error_Posted (Btype)
11562 then
11563 return False;
11564 end if;
11566 if Is_Class_Wide_Type (Btype) then
11567 Btype := Root_Type (Btype);
11568 end if;
11570 if Is_Private_Type (Btype) then
11571 declare
11572 UT : constant Entity_Id := Underlying_Type (Btype);
11573 begin
11574 if No (UT) then
11575 if No (Full_View (Btype)) then
11576 return not Is_Generic_Type (Btype)
11577 and then
11578 not Is_Generic_Type (Root_Type (Btype));
11579 else
11580 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
11581 end if;
11582 else
11583 return not Is_Frozen (UT) and then Has_Private_Component (UT);
11584 end if;
11585 end;
11587 elsif Is_Array_Type (Btype) then
11588 return Has_Private_Component (Component_Type (Btype));
11590 elsif Is_Record_Type (Btype) then
11591 Component := First_Component (Btype);
11592 while Present (Component) loop
11593 if Has_Private_Component (Etype (Component)) then
11594 return True;
11595 end if;
11597 Next_Component (Component);
11598 end loop;
11600 return False;
11602 elsif Is_Protected_Type (Btype)
11603 and then Present (Corresponding_Record_Type (Btype))
11604 then
11605 return Has_Private_Component (Corresponding_Record_Type (Btype));
11607 else
11608 return False;
11609 end if;
11610 end Has_Private_Component;
11612 ----------------------
11613 -- Has_Signed_Zeros --
11614 ----------------------
11616 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
11617 begin
11618 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
11619 end Has_Signed_Zeros;
11621 ------------------------------
11622 -- Has_Significant_Contract --
11623 ------------------------------
11625 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
11626 Subp_Nam : constant Name_Id := Chars (Subp_Id);
11628 begin
11629 -- _Finalizer procedure
11631 if Subp_Nam = Name_uFinalizer then
11632 return False;
11634 -- _Postconditions procedure
11636 elsif Subp_Nam = Name_uPostconditions then
11637 return False;
11639 -- Predicate function
11641 elsif Ekind (Subp_Id) = E_Function
11642 and then Is_Predicate_Function (Subp_Id)
11643 then
11644 return False;
11646 -- TSS subprogram
11648 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
11649 return False;
11651 else
11652 return True;
11653 end if;
11654 end Has_Significant_Contract;
11656 -----------------------------
11657 -- Has_Static_Array_Bounds --
11658 -----------------------------
11660 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
11661 All_Static : Boolean;
11662 Dummy : Boolean;
11664 begin
11665 Examine_Array_Bounds (Typ, All_Static, Dummy);
11667 return All_Static;
11668 end Has_Static_Array_Bounds;
11670 ---------------------------------------
11671 -- Has_Static_Non_Empty_Array_Bounds --
11672 ---------------------------------------
11674 function Has_Static_Non_Empty_Array_Bounds (Typ : Node_Id) return Boolean is
11675 All_Static : Boolean;
11676 Has_Empty : Boolean;
11678 begin
11679 Examine_Array_Bounds (Typ, All_Static, Has_Empty);
11681 return All_Static and not Has_Empty;
11682 end Has_Static_Non_Empty_Array_Bounds;
11684 ----------------
11685 -- Has_Stream --
11686 ----------------
11688 function Has_Stream (T : Entity_Id) return Boolean is
11689 E : Entity_Id;
11691 begin
11692 if No (T) then
11693 return False;
11695 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
11696 return True;
11698 elsif Is_Array_Type (T) then
11699 return Has_Stream (Component_Type (T));
11701 elsif Is_Record_Type (T) then
11702 E := First_Component (T);
11703 while Present (E) loop
11704 if Has_Stream (Etype (E)) then
11705 return True;
11706 else
11707 Next_Component (E);
11708 end if;
11709 end loop;
11711 return False;
11713 elsif Is_Private_Type (T) then
11714 return Has_Stream (Underlying_Type (T));
11716 else
11717 return False;
11718 end if;
11719 end Has_Stream;
11721 ----------------
11722 -- Has_Suffix --
11723 ----------------
11725 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
11726 begin
11727 Get_Name_String (Chars (E));
11728 return Name_Buffer (Name_Len) = Suffix;
11729 end Has_Suffix;
11731 ----------------
11732 -- Add_Suffix --
11733 ----------------
11735 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11736 begin
11737 Get_Name_String (Chars (E));
11738 Add_Char_To_Name_Buffer (Suffix);
11739 return Name_Find;
11740 end Add_Suffix;
11742 -------------------
11743 -- Remove_Suffix --
11744 -------------------
11746 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
11747 begin
11748 pragma Assert (Has_Suffix (E, Suffix));
11749 Get_Name_String (Chars (E));
11750 Name_Len := Name_Len - 1;
11751 return Name_Find;
11752 end Remove_Suffix;
11754 ----------------------------------
11755 -- Replace_Null_By_Null_Address --
11756 ----------------------------------
11758 procedure Replace_Null_By_Null_Address (N : Node_Id) is
11759 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
11760 -- Replace operand Op with a reference to Null_Address when the operand
11761 -- denotes a null Address. Other_Op denotes the other operand.
11763 --------------------------
11764 -- Replace_Null_Operand --
11765 --------------------------
11767 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
11768 begin
11769 -- Check the type of the complementary operand since the N_Null node
11770 -- has not been decorated yet.
11772 if Nkind (Op) = N_Null
11773 and then Is_Descendant_Of_Address (Etype (Other_Op))
11774 then
11775 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
11776 end if;
11777 end Replace_Null_Operand;
11779 -- Start of processing for Replace_Null_By_Null_Address
11781 begin
11782 pragma Assert (Relaxed_RM_Semantics);
11783 pragma Assert (Nkind_In (N, N_Null,
11784 N_Op_Eq,
11785 N_Op_Ge,
11786 N_Op_Gt,
11787 N_Op_Le,
11788 N_Op_Lt,
11789 N_Op_Ne));
11791 if Nkind (N) = N_Null then
11792 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
11794 else
11795 declare
11796 L : constant Node_Id := Left_Opnd (N);
11797 R : constant Node_Id := Right_Opnd (N);
11799 begin
11800 Replace_Null_Operand (L, Other_Op => R);
11801 Replace_Null_Operand (R, Other_Op => L);
11802 end;
11803 end if;
11804 end Replace_Null_By_Null_Address;
11806 --------------------------
11807 -- Has_Tagged_Component --
11808 --------------------------
11810 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
11811 Comp : Entity_Id;
11813 begin
11814 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
11815 return Has_Tagged_Component (Underlying_Type (Typ));
11817 elsif Is_Array_Type (Typ) then
11818 return Has_Tagged_Component (Component_Type (Typ));
11820 elsif Is_Tagged_Type (Typ) then
11821 return True;
11823 elsif Is_Record_Type (Typ) then
11824 Comp := First_Component (Typ);
11825 while Present (Comp) loop
11826 if Has_Tagged_Component (Etype (Comp)) then
11827 return True;
11828 end if;
11830 Next_Component (Comp);
11831 end loop;
11833 return False;
11835 else
11836 return False;
11837 end if;
11838 end Has_Tagged_Component;
11840 -----------------------------
11841 -- Has_Undefined_Reference --
11842 -----------------------------
11844 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
11845 Has_Undef_Ref : Boolean := False;
11846 -- Flag set when expression Expr contains at least one undefined
11847 -- reference.
11849 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
11850 -- Determine whether N denotes a reference and if it does, whether it is
11851 -- undefined.
11853 ----------------------------
11854 -- Is_Undefined_Reference --
11855 ----------------------------
11857 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
11858 begin
11859 if Is_Entity_Name (N)
11860 and then Present (Entity (N))
11861 and then Entity (N) = Any_Id
11862 then
11863 Has_Undef_Ref := True;
11864 return Abandon;
11865 end if;
11867 return OK;
11868 end Is_Undefined_Reference;
11870 procedure Find_Undefined_References is
11871 new Traverse_Proc (Is_Undefined_Reference);
11873 -- Start of processing for Has_Undefined_Reference
11875 begin
11876 Find_Undefined_References (Expr);
11878 return Has_Undef_Ref;
11879 end Has_Undefined_Reference;
11881 ----------------------------
11882 -- Has_Volatile_Component --
11883 ----------------------------
11885 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
11886 Comp : Entity_Id;
11888 begin
11889 if Has_Volatile_Components (Typ) then
11890 return True;
11892 elsif Is_Array_Type (Typ) then
11893 return Is_Volatile (Component_Type (Typ));
11895 elsif Is_Record_Type (Typ) then
11896 Comp := First_Component (Typ);
11897 while Present (Comp) loop
11898 if Is_Volatile_Object (Comp) then
11899 return True;
11900 end if;
11902 Comp := Next_Component (Comp);
11903 end loop;
11904 end if;
11906 return False;
11907 end Has_Volatile_Component;
11909 -------------------------
11910 -- Implementation_Kind --
11911 -------------------------
11913 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
11914 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
11915 Arg : Node_Id;
11916 begin
11917 pragma Assert (Present (Impl_Prag));
11918 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
11919 return Chars (Get_Pragma_Arg (Arg));
11920 end Implementation_Kind;
11922 --------------------------
11923 -- Implements_Interface --
11924 --------------------------
11926 function Implements_Interface
11927 (Typ_Ent : Entity_Id;
11928 Iface_Ent : Entity_Id;
11929 Exclude_Parents : Boolean := False) return Boolean
11931 Ifaces_List : Elist_Id;
11932 Elmt : Elmt_Id;
11933 Iface : Entity_Id := Base_Type (Iface_Ent);
11934 Typ : Entity_Id := Base_Type (Typ_Ent);
11936 begin
11937 if Is_Class_Wide_Type (Typ) then
11938 Typ := Root_Type (Typ);
11939 end if;
11941 if not Has_Interfaces (Typ) then
11942 return False;
11943 end if;
11945 if Is_Class_Wide_Type (Iface) then
11946 Iface := Root_Type (Iface);
11947 end if;
11949 Collect_Interfaces (Typ, Ifaces_List);
11951 Elmt := First_Elmt (Ifaces_List);
11952 while Present (Elmt) loop
11953 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
11954 and then Exclude_Parents
11955 then
11956 null;
11958 elsif Node (Elmt) = Iface then
11959 return True;
11960 end if;
11962 Next_Elmt (Elmt);
11963 end loop;
11965 return False;
11966 end Implements_Interface;
11968 ------------------------------------
11969 -- In_Assertion_Expression_Pragma --
11970 ------------------------------------
11972 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
11973 Par : Node_Id;
11974 Prag : Node_Id := Empty;
11976 begin
11977 -- Climb the parent chain looking for an enclosing pragma
11979 Par := N;
11980 while Present (Par) loop
11981 if Nkind (Par) = N_Pragma then
11982 Prag := Par;
11983 exit;
11985 -- Precondition-like pragmas are expanded into if statements, check
11986 -- the original node instead.
11988 elsif Nkind (Original_Node (Par)) = N_Pragma then
11989 Prag := Original_Node (Par);
11990 exit;
11992 -- The expansion of attribute 'Old generates a constant to capture
11993 -- the result of the prefix. If the parent traversal reaches
11994 -- one of these constants, then the node technically came from a
11995 -- postcondition-like pragma. Note that the Ekind is not tested here
11996 -- because N may be the expression of an object declaration which is
11997 -- currently being analyzed. Such objects carry Ekind of E_Void.
11999 elsif Nkind (Par) = N_Object_Declaration
12000 and then Constant_Present (Par)
12001 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
12002 then
12003 return True;
12005 -- Prevent the search from going too far
12007 elsif Is_Body_Or_Package_Declaration (Par) then
12008 return False;
12009 end if;
12011 Par := Parent (Par);
12012 end loop;
12014 return
12015 Present (Prag)
12016 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
12017 end In_Assertion_Expression_Pragma;
12019 ----------------------
12020 -- In_Generic_Scope --
12021 ----------------------
12023 function In_Generic_Scope (E : Entity_Id) return Boolean is
12024 S : Entity_Id;
12026 begin
12027 S := Scope (E);
12028 while Present (S) and then S /= Standard_Standard loop
12029 if Is_Generic_Unit (S) then
12030 return True;
12031 end if;
12033 S := Scope (S);
12034 end loop;
12036 return False;
12037 end In_Generic_Scope;
12039 -----------------
12040 -- In_Instance --
12041 -----------------
12043 function In_Instance return Boolean is
12044 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
12045 S : Entity_Id;
12047 begin
12048 S := Current_Scope;
12049 while Present (S) and then S /= Standard_Standard loop
12050 if Is_Generic_Instance (S) then
12052 -- A child instance is always compiled in the context of a parent
12053 -- instance. Nevertheless, the actuals are not analyzed in an
12054 -- instance context. We detect this case by examining the current
12055 -- compilation unit, which must be a child instance, and checking
12056 -- that it is not currently on the scope stack.
12058 if Is_Child_Unit (Curr_Unit)
12059 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
12060 N_Package_Instantiation
12061 and then not In_Open_Scopes (Curr_Unit)
12062 then
12063 return False;
12064 else
12065 return True;
12066 end if;
12067 end if;
12069 S := Scope (S);
12070 end loop;
12072 return False;
12073 end In_Instance;
12075 ----------------------
12076 -- In_Instance_Body --
12077 ----------------------
12079 function In_Instance_Body return Boolean is
12080 S : Entity_Id;
12082 begin
12083 S := Current_Scope;
12084 while Present (S) and then S /= Standard_Standard loop
12085 if Ekind_In (S, E_Function, E_Procedure)
12086 and then Is_Generic_Instance (S)
12087 then
12088 return True;
12090 elsif Ekind (S) = E_Package
12091 and then In_Package_Body (S)
12092 and then Is_Generic_Instance (S)
12093 then
12094 return True;
12095 end if;
12097 S := Scope (S);
12098 end loop;
12100 return False;
12101 end In_Instance_Body;
12103 -----------------------------
12104 -- In_Instance_Not_Visible --
12105 -----------------------------
12107 function In_Instance_Not_Visible return Boolean is
12108 S : Entity_Id;
12110 begin
12111 S := Current_Scope;
12112 while Present (S) and then S /= Standard_Standard loop
12113 if Ekind_In (S, E_Function, E_Procedure)
12114 and then Is_Generic_Instance (S)
12115 then
12116 return True;
12118 elsif Ekind (S) = E_Package
12119 and then (In_Package_Body (S) or else In_Private_Part (S))
12120 and then Is_Generic_Instance (S)
12121 then
12122 return True;
12123 end if;
12125 S := Scope (S);
12126 end loop;
12128 return False;
12129 end In_Instance_Not_Visible;
12131 ------------------------------
12132 -- In_Instance_Visible_Part --
12133 ------------------------------
12135 function In_Instance_Visible_Part
12136 (Id : Entity_Id := Current_Scope) return Boolean
12138 Inst : Entity_Id;
12140 begin
12141 Inst := Id;
12142 while Present (Inst) and then Inst /= Standard_Standard loop
12143 if Ekind (Inst) = E_Package
12144 and then Is_Generic_Instance (Inst)
12145 and then not In_Package_Body (Inst)
12146 and then not In_Private_Part (Inst)
12147 then
12148 return True;
12149 end if;
12151 Inst := Scope (Inst);
12152 end loop;
12154 return False;
12155 end In_Instance_Visible_Part;
12157 ---------------------
12158 -- In_Package_Body --
12159 ---------------------
12161 function In_Package_Body return Boolean is
12162 S : Entity_Id;
12164 begin
12165 S := Current_Scope;
12166 while Present (S) and then S /= Standard_Standard loop
12167 if Ekind (S) = E_Package and then In_Package_Body (S) then
12168 return True;
12169 else
12170 S := Scope (S);
12171 end if;
12172 end loop;
12174 return False;
12175 end In_Package_Body;
12177 --------------------------
12178 -- In_Pragma_Expression --
12179 --------------------------
12181 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
12182 P : Node_Id;
12183 begin
12184 P := Parent (N);
12185 loop
12186 if No (P) then
12187 return False;
12188 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
12189 return True;
12190 else
12191 P := Parent (P);
12192 end if;
12193 end loop;
12194 end In_Pragma_Expression;
12196 ---------------------------
12197 -- In_Pre_Post_Condition --
12198 ---------------------------
12200 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
12201 Par : Node_Id;
12202 Prag : Node_Id := Empty;
12203 Prag_Id : Pragma_Id;
12205 begin
12206 -- Climb the parent chain looking for an enclosing pragma
12208 Par := N;
12209 while Present (Par) loop
12210 if Nkind (Par) = N_Pragma then
12211 Prag := Par;
12212 exit;
12214 -- Prevent the search from going too far
12216 elsif Is_Body_Or_Package_Declaration (Par) then
12217 exit;
12218 end if;
12220 Par := Parent (Par);
12221 end loop;
12223 if Present (Prag) then
12224 Prag_Id := Get_Pragma_Id (Prag);
12226 return
12227 Prag_Id = Pragma_Post
12228 or else Prag_Id = Pragma_Post_Class
12229 or else Prag_Id = Pragma_Postcondition
12230 or else Prag_Id = Pragma_Pre
12231 or else Prag_Id = Pragma_Pre_Class
12232 or else Prag_Id = Pragma_Precondition;
12234 -- Otherwise the node is not enclosed by a pre/postcondition pragma
12236 else
12237 return False;
12238 end if;
12239 end In_Pre_Post_Condition;
12241 -------------------------------------
12242 -- In_Reverse_Storage_Order_Object --
12243 -------------------------------------
12245 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
12246 Pref : Node_Id;
12247 Btyp : Entity_Id := Empty;
12249 begin
12250 -- Climb up indexed components
12252 Pref := N;
12253 loop
12254 case Nkind (Pref) is
12255 when N_Selected_Component =>
12256 Pref := Prefix (Pref);
12257 exit;
12259 when N_Indexed_Component =>
12260 Pref := Prefix (Pref);
12262 when others =>
12263 Pref := Empty;
12264 exit;
12265 end case;
12266 end loop;
12268 if Present (Pref) then
12269 Btyp := Base_Type (Etype (Pref));
12270 end if;
12272 return Present (Btyp)
12273 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
12274 and then Reverse_Storage_Order (Btyp);
12275 end In_Reverse_Storage_Order_Object;
12277 ------------------------------
12278 -- In_Same_Declarative_Part --
12279 ------------------------------
12281 function In_Same_Declarative_Part
12282 (Context : Node_Id;
12283 N : Node_Id) return Boolean
12285 Cont : Node_Id := Context;
12286 Nod : Node_Id;
12288 begin
12289 if Nkind (Cont) = N_Compilation_Unit_Aux then
12290 Cont := Parent (Cont);
12291 end if;
12293 Nod := Parent (N);
12294 while Present (Nod) loop
12295 if Nod = Cont then
12296 return True;
12298 elsif Nkind_In (Nod, N_Accept_Statement,
12299 N_Block_Statement,
12300 N_Compilation_Unit,
12301 N_Entry_Body,
12302 N_Package_Body,
12303 N_Package_Declaration,
12304 N_Protected_Body,
12305 N_Subprogram_Body,
12306 N_Task_Body)
12307 then
12308 return False;
12310 elsif Nkind (Nod) = N_Subunit then
12311 Nod := Corresponding_Stub (Nod);
12313 else
12314 Nod := Parent (Nod);
12315 end if;
12316 end loop;
12318 return False;
12319 end In_Same_Declarative_Part;
12321 --------------------------------------
12322 -- In_Subprogram_Or_Concurrent_Unit --
12323 --------------------------------------
12325 function In_Subprogram_Or_Concurrent_Unit return Boolean is
12326 E : Entity_Id;
12327 K : Entity_Kind;
12329 begin
12330 -- Use scope chain to check successively outer scopes
12332 E := Current_Scope;
12333 loop
12334 K := Ekind (E);
12336 if K in Subprogram_Kind
12337 or else K in Concurrent_Kind
12338 or else K in Generic_Subprogram_Kind
12339 then
12340 return True;
12342 elsif E = Standard_Standard then
12343 return False;
12344 end if;
12346 E := Scope (E);
12347 end loop;
12348 end In_Subprogram_Or_Concurrent_Unit;
12350 ----------------
12351 -- In_Subtree --
12352 ----------------
12354 function In_Subtree (N : Node_Id; Root : Node_Id) return Boolean is
12355 Curr : Node_Id;
12357 begin
12358 Curr := N;
12359 while Present (Curr) loop
12360 if Curr = Root then
12361 return True;
12362 end if;
12364 Curr := Parent (Curr);
12365 end loop;
12367 return False;
12368 end In_Subtree;
12370 ----------------
12371 -- In_Subtree --
12372 ----------------
12374 function In_Subtree
12375 (N : Node_Id;
12376 Root1 : Node_Id;
12377 Root2 : Node_Id) return Boolean
12379 Curr : Node_Id;
12381 begin
12382 Curr := N;
12383 while Present (Curr) loop
12384 if Curr = Root1 or else Curr = Root2 then
12385 return True;
12386 end if;
12388 Curr := Parent (Curr);
12389 end loop;
12391 return False;
12392 end In_Subtree;
12394 ---------------------
12395 -- In_Visible_Part --
12396 ---------------------
12398 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
12399 begin
12400 return Is_Package_Or_Generic_Package (Scope_Id)
12401 and then In_Open_Scopes (Scope_Id)
12402 and then not In_Package_Body (Scope_Id)
12403 and then not In_Private_Part (Scope_Id);
12404 end In_Visible_Part;
12406 --------------------------------
12407 -- Incomplete_Or_Partial_View --
12408 --------------------------------
12410 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
12411 function Inspect_Decls
12412 (Decls : List_Id;
12413 Taft : Boolean := False) return Entity_Id;
12414 -- Check whether a declarative region contains the incomplete or partial
12415 -- view of Id.
12417 -------------------
12418 -- Inspect_Decls --
12419 -------------------
12421 function Inspect_Decls
12422 (Decls : List_Id;
12423 Taft : Boolean := False) return Entity_Id
12425 Decl : Node_Id;
12426 Match : Node_Id;
12428 begin
12429 Decl := First (Decls);
12430 while Present (Decl) loop
12431 Match := Empty;
12433 -- The partial view of a Taft-amendment type is an incomplete
12434 -- type.
12436 if Taft then
12437 if Nkind (Decl) = N_Incomplete_Type_Declaration then
12438 Match := Defining_Identifier (Decl);
12439 end if;
12441 -- Otherwise look for a private type whose full view matches the
12442 -- input type. Note that this checks full_type_declaration nodes
12443 -- to account for derivations from a private type where the type
12444 -- declaration hold the partial view and the full view is an
12445 -- itype.
12447 elsif Nkind_In (Decl, N_Full_Type_Declaration,
12448 N_Private_Extension_Declaration,
12449 N_Private_Type_Declaration)
12450 then
12451 Match := Defining_Identifier (Decl);
12452 end if;
12454 -- Guard against unanalyzed entities
12456 if Present (Match)
12457 and then Is_Type (Match)
12458 and then Present (Full_View (Match))
12459 and then Full_View (Match) = Id
12460 then
12461 return Match;
12462 end if;
12464 Next (Decl);
12465 end loop;
12467 return Empty;
12468 end Inspect_Decls;
12470 -- Local variables
12472 Prev : Entity_Id;
12474 -- Start of processing for Incomplete_Or_Partial_View
12476 begin
12477 -- Deferred constant or incomplete type case
12479 Prev := Current_Entity_In_Scope (Id);
12481 if Present (Prev)
12482 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
12483 and then Present (Full_View (Prev))
12484 and then Full_View (Prev) = Id
12485 then
12486 return Prev;
12487 end if;
12489 -- Private or Taft amendment type case
12491 declare
12492 Pkg : constant Entity_Id := Scope (Id);
12493 Pkg_Decl : Node_Id := Pkg;
12495 begin
12496 if Present (Pkg)
12497 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
12498 then
12499 while Nkind (Pkg_Decl) /= N_Package_Specification loop
12500 Pkg_Decl := Parent (Pkg_Decl);
12501 end loop;
12503 -- It is knows that Typ has a private view, look for it in the
12504 -- visible declarations of the enclosing scope. A special case
12505 -- of this is when the two views have been exchanged - the full
12506 -- appears earlier than the private.
12508 if Has_Private_Declaration (Id) then
12509 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
12511 -- Exchanged view case, look in the private declarations
12513 if No (Prev) then
12514 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
12515 end if;
12517 return Prev;
12519 -- Otherwise if this is the package body, then Typ is a potential
12520 -- Taft amendment type. The incomplete view should be located in
12521 -- the private declarations of the enclosing scope.
12523 elsif In_Package_Body (Pkg) then
12524 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
12525 end if;
12526 end if;
12527 end;
12529 -- The type has no incomplete or private view
12531 return Empty;
12532 end Incomplete_Or_Partial_View;
12534 ---------------------------------------
12535 -- Incomplete_View_From_Limited_With --
12536 ---------------------------------------
12538 function Incomplete_View_From_Limited_With
12539 (Typ : Entity_Id) return Entity_Id
12541 begin
12542 -- It might make sense to make this an attribute in Einfo, and set it
12543 -- in Sem_Ch10 in Build_Shadow_Entity. However, we're running short on
12544 -- slots for new attributes, and it seems a bit simpler to just search
12545 -- the Limited_View (if it exists) for an incomplete type whose
12546 -- Non_Limited_View is Typ.
12548 if Ekind (Scope (Typ)) = E_Package
12549 and then Present (Limited_View (Scope (Typ)))
12550 then
12551 declare
12552 Ent : Entity_Id := First_Entity (Limited_View (Scope (Typ)));
12553 begin
12554 while Present (Ent) loop
12555 if Ekind (Ent) in Incomplete_Kind
12556 and then Non_Limited_View (Ent) = Typ
12557 then
12558 return Ent;
12559 end if;
12561 Ent := Next_Entity (Ent);
12562 end loop;
12563 end;
12564 end if;
12566 return Typ;
12567 end Incomplete_View_From_Limited_With;
12569 ----------------------------------
12570 -- Indexed_Component_Bit_Offset --
12571 ----------------------------------
12573 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
12574 Exp : constant Node_Id := First (Expressions (N));
12575 Typ : constant Entity_Id := Etype (Prefix (N));
12576 Off : constant Uint := Component_Size (Typ);
12577 Ind : Node_Id;
12579 begin
12580 -- Return early if the component size is not known or variable
12582 if Off = No_Uint or else Off < Uint_0 then
12583 return No_Uint;
12584 end if;
12586 -- Deal with the degenerate case of an empty component
12588 if Off = Uint_0 then
12589 return Off;
12590 end if;
12592 -- Check that both the index value and the low bound are known
12594 if not Compile_Time_Known_Value (Exp) then
12595 return No_Uint;
12596 end if;
12598 Ind := First_Index (Typ);
12599 if No (Ind) then
12600 return No_Uint;
12601 end if;
12603 if Nkind (Ind) = N_Subtype_Indication then
12604 Ind := Constraint (Ind);
12606 if Nkind (Ind) = N_Range_Constraint then
12607 Ind := Range_Expression (Ind);
12608 end if;
12609 end if;
12611 if Nkind (Ind) /= N_Range
12612 or else not Compile_Time_Known_Value (Low_Bound (Ind))
12613 then
12614 return No_Uint;
12615 end if;
12617 -- Return the scaled offset
12619 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
12620 end Indexed_Component_Bit_Offset;
12622 ----------------------------
12623 -- Inherit_Rep_Item_Chain --
12624 ----------------------------
12626 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
12627 Item : Node_Id;
12628 Next_Item : Node_Id;
12630 begin
12631 -- There are several inheritance scenarios to consider depending on
12632 -- whether both types have rep item chains and whether the destination
12633 -- type already inherits part of the source type's rep item chain.
12635 -- 1) The source type lacks a rep item chain
12636 -- From_Typ ---> Empty
12638 -- Typ --------> Item (or Empty)
12640 -- In this case inheritance cannot take place because there are no items
12641 -- to inherit.
12643 -- 2) The destination type lacks a rep item chain
12644 -- From_Typ ---> Item ---> ...
12646 -- Typ --------> Empty
12648 -- Inheritance takes place by setting the First_Rep_Item of the
12649 -- destination type to the First_Rep_Item of the source type.
12650 -- From_Typ ---> Item ---> ...
12651 -- ^
12652 -- Typ -----------+
12654 -- 3.1) Both source and destination types have at least one rep item.
12655 -- The destination type does NOT inherit a rep item from the source
12656 -- type.
12657 -- From_Typ ---> Item ---> Item
12659 -- Typ --------> Item ---> Item
12661 -- Inheritance takes place by setting the Next_Rep_Item of the last item
12662 -- of the destination type to the First_Rep_Item of the source type.
12663 -- From_Typ -------------------> Item ---> Item
12664 -- ^
12665 -- Typ --------> Item ---> Item --+
12667 -- 3.2) Both source and destination types have at least one rep item.
12668 -- The destination type DOES inherit part of the rep item chain of the
12669 -- source type.
12670 -- From_Typ ---> Item ---> Item ---> Item
12671 -- ^
12672 -- Typ --------> Item ------+
12674 -- This rare case arises when the full view of a private extension must
12675 -- inherit the rep item chain from the full view of its parent type and
12676 -- the full view of the parent type contains extra rep items. Currently
12677 -- only invariants may lead to such form of inheritance.
12679 -- type From_Typ is tagged private
12680 -- with Type_Invariant'Class => Item_2;
12682 -- type Typ is new From_Typ with private
12683 -- with Type_Invariant => Item_4;
12685 -- At this point the rep item chains contain the following items
12687 -- From_Typ -----------> Item_2 ---> Item_3
12688 -- ^
12689 -- Typ --------> Item_4 --+
12691 -- The full views of both types may introduce extra invariants
12693 -- type From_Typ is tagged null record
12694 -- with Type_Invariant => Item_1;
12696 -- type Typ is new From_Typ with null record;
12698 -- The full view of Typ would have to inherit any new rep items added to
12699 -- the full view of From_Typ.
12701 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
12702 -- ^
12703 -- Typ --------> Item_4 --+
12705 -- To achieve this form of inheritance, the destination type must first
12706 -- sever the link between its own rep chain and that of the source type,
12707 -- then inheritance 3.1 takes place.
12709 -- Case 1: The source type lacks a rep item chain
12711 if No (First_Rep_Item (From_Typ)) then
12712 return;
12714 -- Case 2: The destination type lacks a rep item chain
12716 elsif No (First_Rep_Item (Typ)) then
12717 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12719 -- Case 3: Both the source and destination types have at least one rep
12720 -- item. Traverse the rep item chain of the destination type to find the
12721 -- last rep item.
12723 else
12724 Item := Empty;
12725 Next_Item := First_Rep_Item (Typ);
12726 while Present (Next_Item) loop
12728 -- Detect a link between the destination type's rep chain and that
12729 -- of the source type. There are two possibilities:
12731 -- Variant 1
12732 -- Next_Item
12733 -- V
12734 -- From_Typ ---> Item_1 --->
12735 -- ^
12736 -- Typ -----------+
12738 -- Item is Empty
12740 -- Variant 2
12741 -- Next_Item
12742 -- V
12743 -- From_Typ ---> Item_1 ---> Item_2 --->
12744 -- ^
12745 -- Typ --------> Item_3 ------+
12746 -- ^
12747 -- Item
12749 if Has_Rep_Item (From_Typ, Next_Item) then
12750 exit;
12751 end if;
12753 Item := Next_Item;
12754 Next_Item := Next_Rep_Item (Next_Item);
12755 end loop;
12757 -- Inherit the source type's rep item chain
12759 if Present (Item) then
12760 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
12761 else
12762 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
12763 end if;
12764 end if;
12765 end Inherit_Rep_Item_Chain;
12767 ------------------------------------
12768 -- Inherits_From_Tagged_Full_View --
12769 ------------------------------------
12771 function Inherits_From_Tagged_Full_View (Typ : Entity_Id) return Boolean is
12772 begin
12773 return Is_Private_Type (Typ)
12774 and then Present (Full_View (Typ))
12775 and then Is_Private_Type (Full_View (Typ))
12776 and then not Is_Tagged_Type (Full_View (Typ))
12777 and then Present (Underlying_Type (Full_View (Typ)))
12778 and then Is_Tagged_Type (Underlying_Type (Full_View (Typ)));
12779 end Inherits_From_Tagged_Full_View;
12781 ---------------------------------
12782 -- Insert_Explicit_Dereference --
12783 ---------------------------------
12785 procedure Insert_Explicit_Dereference (N : Node_Id) is
12786 New_Prefix : constant Node_Id := Relocate_Node (N);
12787 Ent : Entity_Id := Empty;
12788 Pref : Node_Id;
12789 I : Interp_Index;
12790 It : Interp;
12791 T : Entity_Id;
12793 begin
12794 Save_Interps (N, New_Prefix);
12796 Rewrite (N,
12797 Make_Explicit_Dereference (Sloc (Parent (N)),
12798 Prefix => New_Prefix));
12800 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
12802 if Is_Overloaded (New_Prefix) then
12804 -- The dereference is also overloaded, and its interpretations are
12805 -- the designated types of the interpretations of the original node.
12807 Set_Etype (N, Any_Type);
12809 Get_First_Interp (New_Prefix, I, It);
12810 while Present (It.Nam) loop
12811 T := It.Typ;
12813 if Is_Access_Type (T) then
12814 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
12815 end if;
12817 Get_Next_Interp (I, It);
12818 end loop;
12820 End_Interp_List;
12822 else
12823 -- Prefix is unambiguous: mark the original prefix (which might
12824 -- Come_From_Source) as a reference, since the new (relocated) one
12825 -- won't be taken into account.
12827 if Is_Entity_Name (New_Prefix) then
12828 Ent := Entity (New_Prefix);
12829 Pref := New_Prefix;
12831 -- For a retrieval of a subcomponent of some composite object,
12832 -- retrieve the ultimate entity if there is one.
12834 elsif Nkind_In (New_Prefix, N_Selected_Component,
12835 N_Indexed_Component)
12836 then
12837 Pref := Prefix (New_Prefix);
12838 while Present (Pref)
12839 and then Nkind_In (Pref, N_Selected_Component,
12840 N_Indexed_Component)
12841 loop
12842 Pref := Prefix (Pref);
12843 end loop;
12845 if Present (Pref) and then Is_Entity_Name (Pref) then
12846 Ent := Entity (Pref);
12847 end if;
12848 end if;
12850 -- Place the reference on the entity node
12852 if Present (Ent) then
12853 Generate_Reference (Ent, Pref);
12854 end if;
12855 end if;
12856 end Insert_Explicit_Dereference;
12858 ------------------------------------------
12859 -- Inspect_Deferred_Constant_Completion --
12860 ------------------------------------------
12862 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
12863 Decl : Node_Id;
12865 begin
12866 Decl := First (Decls);
12867 while Present (Decl) loop
12869 -- Deferred constant signature
12871 if Nkind (Decl) = N_Object_Declaration
12872 and then Constant_Present (Decl)
12873 and then No (Expression (Decl))
12875 -- No need to check internally generated constants
12877 and then Comes_From_Source (Decl)
12879 -- The constant is not completed. A full object declaration or a
12880 -- pragma Import complete a deferred constant.
12882 and then not Has_Completion (Defining_Identifier (Decl))
12883 then
12884 Error_Msg_N
12885 ("constant declaration requires initialization expression",
12886 Defining_Identifier (Decl));
12887 end if;
12889 Decl := Next (Decl);
12890 end loop;
12891 end Inspect_Deferred_Constant_Completion;
12893 -------------------------------
12894 -- Install_Elaboration_Model --
12895 -------------------------------
12897 procedure Install_Elaboration_Model (Unit_Id : Entity_Id) is
12898 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id;
12899 -- Try to find pragma Elaboration_Checks in arbitrary list L. Return
12900 -- Empty if there is no such pragma.
12902 ------------------------------------
12903 -- Find_Elaboration_Checks_Pragma --
12904 ------------------------------------
12906 function Find_Elaboration_Checks_Pragma (L : List_Id) return Node_Id is
12907 Item : Node_Id;
12909 begin
12910 Item := First (L);
12911 while Present (Item) loop
12912 if Nkind (Item) = N_Pragma
12913 and then Pragma_Name (Item) = Name_Elaboration_Checks
12914 then
12915 return Item;
12916 end if;
12918 Next (Item);
12919 end loop;
12921 return Empty;
12922 end Find_Elaboration_Checks_Pragma;
12924 -- Local variables
12926 Args : List_Id;
12927 Model : Node_Id;
12928 Prag : Node_Id;
12929 Unit : Node_Id;
12931 -- Start of processing for Install_Elaboration_Model
12933 begin
12934 -- Nothing to do when the unit does not exist
12936 if No (Unit_Id) then
12937 return;
12938 end if;
12940 Unit := Parent (Unit_Declaration_Node (Unit_Id));
12942 -- Nothing to do when the unit is not a library unit
12944 if Nkind (Unit) /= N_Compilation_Unit then
12945 return;
12946 end if;
12948 Prag := Find_Elaboration_Checks_Pragma (Context_Items (Unit));
12950 -- The compilation unit is subject to pragma Elaboration_Checks. Set the
12951 -- elaboration model as specified by the pragma.
12953 if Present (Prag) then
12954 Args := Pragma_Argument_Associations (Prag);
12956 -- Guard against an illegal pragma. The sole argument must be an
12957 -- identifier which specifies either Dynamic or Static model.
12959 if Present (Args) then
12960 Model := Get_Pragma_Arg (First (Args));
12962 if Nkind (Model) = N_Identifier then
12963 Dynamic_Elaboration_Checks := Chars (Model) = Name_Dynamic;
12964 end if;
12965 end if;
12966 end if;
12967 end Install_Elaboration_Model;
12969 -----------------------------
12970 -- Install_Generic_Formals --
12971 -----------------------------
12973 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
12974 E : Entity_Id;
12976 begin
12977 pragma Assert (Is_Generic_Subprogram (Subp_Id));
12979 E := First_Entity (Subp_Id);
12980 while Present (E) loop
12981 Install_Entity (E);
12982 Next_Entity (E);
12983 end loop;
12984 end Install_Generic_Formals;
12986 ------------------------
12987 -- Install_SPARK_Mode --
12988 ------------------------
12990 procedure Install_SPARK_Mode (Mode : SPARK_Mode_Type; Prag : Node_Id) is
12991 begin
12992 SPARK_Mode := Mode;
12993 SPARK_Mode_Pragma := Prag;
12994 end Install_SPARK_Mode;
12996 --------------------------
12997 -- Invalid_Scalar_Value --
12998 --------------------------
13000 function Invalid_Scalar_Value
13001 (Loc : Source_Ptr;
13002 Scal_Typ : Scalar_Id) return Node_Id
13004 function Invalid_Binder_Value return Node_Id;
13005 -- Return a reference to the corresponding invalid value for type
13006 -- Scal_Typ as defined in unit System.Scalar_Values.
13008 function Invalid_Float_Value return Node_Id;
13009 -- Return the invalid value of float type Scal_Typ
13011 function Invalid_Integer_Value return Node_Id;
13012 -- Return the invalid value of integer type Scal_Typ
13014 procedure Set_Invalid_Binder_Values;
13015 -- Set the contents of collection Invalid_Binder_Values
13017 --------------------------
13018 -- Invalid_Binder_Value --
13019 --------------------------
13021 function Invalid_Binder_Value return Node_Id is
13022 Val_Id : Entity_Id;
13024 begin
13025 -- Initialize the collection of invalid binder values the first time
13026 -- around.
13028 Set_Invalid_Binder_Values;
13030 -- Obtain the corresponding variable from System.Scalar_Values which
13031 -- holds the invalid value for this type.
13033 Val_Id := Invalid_Binder_Values (Scal_Typ);
13034 pragma Assert (Present (Val_Id));
13036 return New_Occurrence_Of (Val_Id, Loc);
13037 end Invalid_Binder_Value;
13039 -------------------------
13040 -- Invalid_Float_Value --
13041 -------------------------
13043 function Invalid_Float_Value return Node_Id is
13044 Value : constant Ureal := Invalid_Floats (Scal_Typ);
13046 begin
13047 -- Pragma Invalid_Scalars did not specify an invalid value for this
13048 -- type. Fall back to the value provided by the binder.
13050 if Value = No_Ureal then
13051 return Invalid_Binder_Value;
13052 else
13053 return Make_Real_Literal (Loc, Realval => Value);
13054 end if;
13055 end Invalid_Float_Value;
13057 ---------------------------
13058 -- Invalid_Integer_Value --
13059 ---------------------------
13061 function Invalid_Integer_Value return Node_Id is
13062 Value : constant Uint := Invalid_Integers (Scal_Typ);
13064 begin
13065 -- Pragma Invalid_Scalars did not specify an invalid value for this
13066 -- type. Fall back to the value provided by the binder.
13068 if Value = No_Uint then
13069 return Invalid_Binder_Value;
13070 else
13071 return Make_Integer_Literal (Loc, Intval => Value);
13072 end if;
13073 end Invalid_Integer_Value;
13075 -------------------------------
13076 -- Set_Invalid_Binder_Values --
13077 -------------------------------
13079 procedure Set_Invalid_Binder_Values is
13080 begin
13081 if not Invalid_Binder_Values_Set then
13082 Invalid_Binder_Values_Set := True;
13084 -- Initialize the contents of the collection once since RTE calls
13085 -- are not cheap.
13087 Invalid_Binder_Values :=
13088 (Name_Short_Float => RTE (RE_IS_Isf),
13089 Name_Float => RTE (RE_IS_Ifl),
13090 Name_Long_Float => RTE (RE_IS_Ilf),
13091 Name_Long_Long_Float => RTE (RE_IS_Ill),
13092 Name_Signed_8 => RTE (RE_IS_Is1),
13093 Name_Signed_16 => RTE (RE_IS_Is2),
13094 Name_Signed_32 => RTE (RE_IS_Is4),
13095 Name_Signed_64 => RTE (RE_IS_Is8),
13096 Name_Unsigned_8 => RTE (RE_IS_Iu1),
13097 Name_Unsigned_16 => RTE (RE_IS_Iu2),
13098 Name_Unsigned_32 => RTE (RE_IS_Iu4),
13099 Name_Unsigned_64 => RTE (RE_IS_Iu8));
13100 end if;
13101 end Set_Invalid_Binder_Values;
13103 -- Start of processing for Invalid_Scalar_Value
13105 begin
13106 if Scal_Typ in Float_Scalar_Id then
13107 return Invalid_Float_Value;
13109 else pragma Assert (Scal_Typ in Integer_Scalar_Id);
13110 return Invalid_Integer_Value;
13111 end if;
13112 end Invalid_Scalar_Value;
13114 -----------------------------
13115 -- Is_Actual_Out_Parameter --
13116 -----------------------------
13118 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
13119 Formal : Entity_Id;
13120 Call : Node_Id;
13121 begin
13122 Find_Actual (N, Formal, Call);
13123 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
13124 end Is_Actual_Out_Parameter;
13126 -------------------------
13127 -- Is_Actual_Parameter --
13128 -------------------------
13130 function Is_Actual_Parameter (N : Node_Id) return Boolean is
13131 PK : constant Node_Kind := Nkind (Parent (N));
13133 begin
13134 case PK is
13135 when N_Parameter_Association =>
13136 return N = Explicit_Actual_Parameter (Parent (N));
13138 when N_Subprogram_Call =>
13139 return Is_List_Member (N)
13140 and then
13141 List_Containing (N) = Parameter_Associations (Parent (N));
13143 when others =>
13144 return False;
13145 end case;
13146 end Is_Actual_Parameter;
13148 --------------------------------
13149 -- Is_Actual_Tagged_Parameter --
13150 --------------------------------
13152 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
13153 Formal : Entity_Id;
13154 Call : Node_Id;
13155 begin
13156 Find_Actual (N, Formal, Call);
13157 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
13158 end Is_Actual_Tagged_Parameter;
13160 ---------------------
13161 -- Is_Aliased_View --
13162 ---------------------
13164 function Is_Aliased_View (Obj : Node_Id) return Boolean is
13165 E : Entity_Id;
13167 begin
13168 if Is_Entity_Name (Obj) then
13169 E := Entity (Obj);
13171 return
13172 (Is_Object (E)
13173 and then
13174 (Is_Aliased (E)
13175 or else (Present (Renamed_Object (E))
13176 and then Is_Aliased_View (Renamed_Object (E)))))
13178 or else ((Is_Formal (E) or else Is_Formal_Object (E))
13179 and then Is_Tagged_Type (Etype (E)))
13181 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
13183 -- Current instance of type, either directly or as rewritten
13184 -- reference to the current object.
13186 or else (Is_Entity_Name (Original_Node (Obj))
13187 and then Present (Entity (Original_Node (Obj)))
13188 and then Is_Type (Entity (Original_Node (Obj))))
13190 or else (Is_Type (E) and then E = Current_Scope)
13192 or else (Is_Incomplete_Or_Private_Type (E)
13193 and then Full_View (E) = Current_Scope)
13195 -- Ada 2012 AI05-0053: the return object of an extended return
13196 -- statement is aliased if its type is immutably limited.
13198 or else (Is_Return_Object (E)
13199 and then Is_Limited_View (Etype (E)));
13201 elsif Nkind (Obj) = N_Selected_Component then
13202 return Is_Aliased (Entity (Selector_Name (Obj)));
13204 elsif Nkind (Obj) = N_Indexed_Component then
13205 return Has_Aliased_Components (Etype (Prefix (Obj)))
13206 or else
13207 (Is_Access_Type (Etype (Prefix (Obj)))
13208 and then Has_Aliased_Components
13209 (Designated_Type (Etype (Prefix (Obj)))));
13211 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
13212 return Is_Tagged_Type (Etype (Obj))
13213 and then Is_Aliased_View (Expression (Obj));
13215 elsif Nkind (Obj) = N_Explicit_Dereference then
13216 return Nkind (Original_Node (Obj)) /= N_Function_Call;
13218 else
13219 return False;
13220 end if;
13221 end Is_Aliased_View;
13223 -------------------------
13224 -- Is_Ancestor_Package --
13225 -------------------------
13227 function Is_Ancestor_Package
13228 (E1 : Entity_Id;
13229 E2 : Entity_Id) return Boolean
13231 Par : Entity_Id;
13233 begin
13234 Par := E2;
13235 while Present (Par) and then Par /= Standard_Standard loop
13236 if Par = E1 then
13237 return True;
13238 end if;
13240 Par := Scope (Par);
13241 end loop;
13243 return False;
13244 end Is_Ancestor_Package;
13246 ----------------------
13247 -- Is_Atomic_Object --
13248 ----------------------
13250 function Is_Atomic_Object (N : Node_Id) return Boolean is
13251 function Is_Atomic_Entity (Id : Entity_Id) return Boolean;
13252 pragma Inline (Is_Atomic_Entity);
13253 -- Determine whether arbitrary entity Id is either atomic or has atomic
13254 -- components.
13256 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean;
13257 -- Determine whether prefix Pref of an indexed or selected component is
13258 -- an atomic object.
13260 ----------------------
13261 -- Is_Atomic_Entity --
13262 ----------------------
13264 function Is_Atomic_Entity (Id : Entity_Id) return Boolean is
13265 begin
13266 return Is_Atomic (Id) or else Has_Atomic_Components (Id);
13267 end Is_Atomic_Entity;
13269 ----------------------
13270 -- Is_Atomic_Prefix --
13271 ----------------------
13273 function Is_Atomic_Prefix (Pref : Node_Id) return Boolean is
13274 Typ : constant Entity_Id := Etype (Pref);
13276 begin
13277 if Is_Access_Type (Typ) then
13278 return Has_Atomic_Components (Designated_Type (Typ));
13280 elsif Is_Atomic_Entity (Typ) then
13281 return True;
13283 elsif Is_Entity_Name (Pref)
13284 and then Is_Atomic_Entity (Entity (Pref))
13285 then
13286 return True;
13288 elsif Nkind (Pref) = N_Indexed_Component then
13289 return Is_Atomic_Prefix (Prefix (Pref));
13291 elsif Nkind (Pref) = N_Selected_Component then
13292 return
13293 Is_Atomic_Prefix (Prefix (Pref))
13294 or else Is_Atomic (Entity (Selector_Name (Pref)));
13295 end if;
13297 return False;
13298 end Is_Atomic_Prefix;
13300 -- Start of processing for Is_Atomic_Object
13302 begin
13303 if Is_Entity_Name (N) then
13304 return Is_Atomic_Object_Entity (Entity (N));
13306 elsif Nkind (N) = N_Indexed_Component then
13307 return Is_Atomic (Etype (N)) or else Is_Atomic_Prefix (Prefix (N));
13309 elsif Nkind (N) = N_Selected_Component then
13310 return
13311 Is_Atomic (Etype (N))
13312 or else Is_Atomic_Prefix (Prefix (N))
13313 or else Is_Atomic (Entity (Selector_Name (N)));
13314 end if;
13316 return False;
13317 end Is_Atomic_Object;
13319 -----------------------------
13320 -- Is_Atomic_Object_Entity --
13321 -----------------------------
13323 function Is_Atomic_Object_Entity (Id : Entity_Id) return Boolean is
13324 begin
13325 return
13326 Is_Object (Id)
13327 and then (Is_Atomic (Id) or else Is_Atomic (Etype (Id)));
13328 end Is_Atomic_Object_Entity;
13330 -----------------------------
13331 -- Is_Atomic_Or_VFA_Object --
13332 -----------------------------
13334 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
13335 begin
13336 return Is_Atomic_Object (N)
13337 or else (Is_Object_Reference (N)
13338 and then Is_Entity_Name (N)
13339 and then (Is_Volatile_Full_Access (Entity (N))
13340 or else
13341 Is_Volatile_Full_Access (Etype (Entity (N)))));
13342 end Is_Atomic_Or_VFA_Object;
13344 -------------------------
13345 -- Is_Attribute_Result --
13346 -------------------------
13348 function Is_Attribute_Result (N : Node_Id) return Boolean is
13349 begin
13350 return Nkind (N) = N_Attribute_Reference
13351 and then Attribute_Name (N) = Name_Result;
13352 end Is_Attribute_Result;
13354 -------------------------
13355 -- Is_Attribute_Update --
13356 -------------------------
13358 function Is_Attribute_Update (N : Node_Id) return Boolean is
13359 begin
13360 return Nkind (N) = N_Attribute_Reference
13361 and then Attribute_Name (N) = Name_Update;
13362 end Is_Attribute_Update;
13364 ------------------------------------
13365 -- Is_Body_Or_Package_Declaration --
13366 ------------------------------------
13368 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
13369 begin
13370 return Nkind_In (N, N_Entry_Body,
13371 N_Package_Body,
13372 N_Package_Declaration,
13373 N_Protected_Body,
13374 N_Subprogram_Body,
13375 N_Task_Body);
13376 end Is_Body_Or_Package_Declaration;
13378 -----------------------
13379 -- Is_Bounded_String --
13380 -----------------------
13382 function Is_Bounded_String (T : Entity_Id) return Boolean is
13383 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
13385 begin
13386 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
13387 -- Super_String, or one of the [Wide_]Wide_ versions. This will
13388 -- be True for all the Bounded_String types in instances of the
13389 -- Generic_Bounded_Length generics, and for types derived from those.
13391 return Present (Under)
13392 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
13393 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
13394 Is_RTE (Root_Type (Under), RO_WW_Super_String));
13395 end Is_Bounded_String;
13397 ---------------------
13398 -- Is_CCT_Instance --
13399 ---------------------
13401 function Is_CCT_Instance
13402 (Ref_Id : Entity_Id;
13403 Context_Id : Entity_Id) return Boolean
13405 begin
13406 pragma Assert (Ekind_In (Ref_Id, E_Protected_Type, E_Task_Type));
13408 if Is_Single_Task_Object (Context_Id) then
13409 return Scope_Within_Or_Same (Etype (Context_Id), Ref_Id);
13411 else
13412 pragma Assert (Ekind_In (Context_Id, E_Entry,
13413 E_Entry_Family,
13414 E_Function,
13415 E_Package,
13416 E_Procedure,
13417 E_Protected_Type,
13418 E_Task_Type)
13419 or else
13420 Is_Record_Type (Context_Id));
13421 return Scope_Within_Or_Same (Context_Id, Ref_Id);
13422 end if;
13423 end Is_CCT_Instance;
13425 -------------------------
13426 -- Is_Child_Or_Sibling --
13427 -------------------------
13429 function Is_Child_Or_Sibling
13430 (Pack_1 : Entity_Id;
13431 Pack_2 : Entity_Id) return Boolean
13433 function Distance_From_Standard (Pack : Entity_Id) return Nat;
13434 -- Given an arbitrary package, return the number of "climbs" necessary
13435 -- to reach scope Standard_Standard.
13437 procedure Equalize_Depths
13438 (Pack : in out Entity_Id;
13439 Depth : in out Nat;
13440 Depth_To_Reach : Nat);
13441 -- Given an arbitrary package, its depth and a target depth to reach,
13442 -- climb the scope chain until the said depth is reached. The pointer
13443 -- to the package and its depth a modified during the climb.
13445 ----------------------------
13446 -- Distance_From_Standard --
13447 ----------------------------
13449 function Distance_From_Standard (Pack : Entity_Id) return Nat is
13450 Dist : Nat;
13451 Scop : Entity_Id;
13453 begin
13454 Dist := 0;
13455 Scop := Pack;
13456 while Present (Scop) and then Scop /= Standard_Standard loop
13457 Dist := Dist + 1;
13458 Scop := Scope (Scop);
13459 end loop;
13461 return Dist;
13462 end Distance_From_Standard;
13464 ---------------------
13465 -- Equalize_Depths --
13466 ---------------------
13468 procedure Equalize_Depths
13469 (Pack : in out Entity_Id;
13470 Depth : in out Nat;
13471 Depth_To_Reach : Nat)
13473 begin
13474 -- The package must be at a greater or equal depth
13476 if Depth < Depth_To_Reach then
13477 raise Program_Error;
13478 end if;
13480 -- Climb the scope chain until the desired depth is reached
13482 while Present (Pack) and then Depth /= Depth_To_Reach loop
13483 Pack := Scope (Pack);
13484 Depth := Depth - 1;
13485 end loop;
13486 end Equalize_Depths;
13488 -- Local variables
13490 P_1 : Entity_Id := Pack_1;
13491 P_1_Child : Boolean := False;
13492 P_1_Depth : Nat := Distance_From_Standard (P_1);
13493 P_2 : Entity_Id := Pack_2;
13494 P_2_Child : Boolean := False;
13495 P_2_Depth : Nat := Distance_From_Standard (P_2);
13497 -- Start of processing for Is_Child_Or_Sibling
13499 begin
13500 pragma Assert
13501 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
13503 -- Both packages denote the same entity, therefore they cannot be
13504 -- children or siblings.
13506 if P_1 = P_2 then
13507 return False;
13509 -- One of the packages is at a deeper level than the other. Note that
13510 -- both may still come from different hierarchies.
13512 -- (root) P_2
13513 -- / \ :
13514 -- X P_2 or X
13515 -- : :
13516 -- P_1 P_1
13518 elsif P_1_Depth > P_2_Depth then
13519 Equalize_Depths
13520 (Pack => P_1,
13521 Depth => P_1_Depth,
13522 Depth_To_Reach => P_2_Depth);
13523 P_1_Child := True;
13525 -- (root) P_1
13526 -- / \ :
13527 -- P_1 X or X
13528 -- : :
13529 -- P_2 P_2
13531 elsif P_2_Depth > P_1_Depth then
13532 Equalize_Depths
13533 (Pack => P_2,
13534 Depth => P_2_Depth,
13535 Depth_To_Reach => P_1_Depth);
13536 P_2_Child := True;
13537 end if;
13539 -- At this stage the package pointers have been elevated to the same
13540 -- depth. If the related entities are the same, then one package is a
13541 -- potential child of the other:
13543 -- P_1
13544 -- :
13545 -- X became P_1 P_2 or vice versa
13546 -- :
13547 -- P_2
13549 if P_1 = P_2 then
13550 if P_1_Child then
13551 return Is_Child_Unit (Pack_1);
13553 else pragma Assert (P_2_Child);
13554 return Is_Child_Unit (Pack_2);
13555 end if;
13557 -- The packages may come from the same package chain or from entirely
13558 -- different hierarcies. To determine this, climb the scope stack until
13559 -- a common root is found.
13561 -- (root) (root 1) (root 2)
13562 -- / \ | |
13563 -- P_1 P_2 P_1 P_2
13565 else
13566 while Present (P_1) and then Present (P_2) loop
13568 -- The two packages may be siblings
13570 if P_1 = P_2 then
13571 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
13572 end if;
13574 P_1 := Scope (P_1);
13575 P_2 := Scope (P_2);
13576 end loop;
13577 end if;
13579 return False;
13580 end Is_Child_Or_Sibling;
13582 -----------------------------
13583 -- Is_Concurrent_Interface --
13584 -----------------------------
13586 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
13587 begin
13588 return Is_Interface (T)
13589 and then
13590 (Is_Protected_Interface (T)
13591 or else Is_Synchronized_Interface (T)
13592 or else Is_Task_Interface (T));
13593 end Is_Concurrent_Interface;
13595 -----------------------
13596 -- Is_Constant_Bound --
13597 -----------------------
13599 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
13600 begin
13601 if Compile_Time_Known_Value (Exp) then
13602 return True;
13604 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
13605 return Is_Constant_Object (Entity (Exp))
13606 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
13608 elsif Nkind (Exp) in N_Binary_Op then
13609 return Is_Constant_Bound (Left_Opnd (Exp))
13610 and then Is_Constant_Bound (Right_Opnd (Exp))
13611 and then Scope (Entity (Exp)) = Standard_Standard;
13613 else
13614 return False;
13615 end if;
13616 end Is_Constant_Bound;
13618 ---------------------------
13619 -- Is_Container_Element --
13620 ---------------------------
13622 function Is_Container_Element (Exp : Node_Id) return Boolean is
13623 Loc : constant Source_Ptr := Sloc (Exp);
13624 Pref : constant Node_Id := Prefix (Exp);
13626 Call : Node_Id;
13627 -- Call to an indexing aspect
13629 Cont_Typ : Entity_Id;
13630 -- The type of the container being accessed
13632 Elem_Typ : Entity_Id;
13633 -- Its element type
13635 Indexing : Entity_Id;
13636 Is_Const : Boolean;
13637 -- Indicates that constant indexing is used, and the element is thus
13638 -- a constant.
13640 Ref_Typ : Entity_Id;
13641 -- The reference type returned by the indexing operation
13643 begin
13644 -- If C is a container, in a context that imposes the element type of
13645 -- that container, the indexing notation C (X) is rewritten as:
13647 -- Indexing (C, X).Discr.all
13649 -- where Indexing is one of the indexing aspects of the container.
13650 -- If the context does not require a reference, the construct can be
13651 -- rewritten as
13653 -- Element (C, X)
13655 -- First, verify that the construct has the proper form
13657 if not Expander_Active then
13658 return False;
13660 elsif Nkind (Pref) /= N_Selected_Component then
13661 return False;
13663 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
13664 return False;
13666 else
13667 Call := Prefix (Pref);
13668 Ref_Typ := Etype (Call);
13669 end if;
13671 if not Has_Implicit_Dereference (Ref_Typ)
13672 or else No (First (Parameter_Associations (Call)))
13673 or else not Is_Entity_Name (Name (Call))
13674 then
13675 return False;
13676 end if;
13678 -- Retrieve type of container object, and its iterator aspects
13680 Cont_Typ := Etype (First (Parameter_Associations (Call)));
13681 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
13682 Is_Const := False;
13684 if No (Indexing) then
13686 -- Container should have at least one indexing operation
13688 return False;
13690 elsif Entity (Name (Call)) /= Entity (Indexing) then
13692 -- This may be a variable indexing operation
13694 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
13696 if No (Indexing)
13697 or else Entity (Name (Call)) /= Entity (Indexing)
13698 then
13699 return False;
13700 end if;
13702 else
13703 Is_Const := True;
13704 end if;
13706 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
13708 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
13709 return False;
13710 end if;
13712 -- Check that the expression is not the target of an assignment, in
13713 -- which case the rewriting is not possible.
13715 if not Is_Const then
13716 declare
13717 Par : Node_Id;
13719 begin
13720 Par := Exp;
13721 while Present (Par)
13722 loop
13723 if Nkind (Parent (Par)) = N_Assignment_Statement
13724 and then Par = Name (Parent (Par))
13725 then
13726 return False;
13728 -- A renaming produces a reference, and the transformation
13729 -- does not apply.
13731 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
13732 return False;
13734 elsif Nkind_In
13735 (Nkind (Parent (Par)), N_Function_Call,
13736 N_Procedure_Call_Statement,
13737 N_Entry_Call_Statement)
13738 then
13739 -- Check that the element is not part of an actual for an
13740 -- in-out parameter.
13742 declare
13743 F : Entity_Id;
13744 A : Node_Id;
13746 begin
13747 F := First_Formal (Entity (Name (Parent (Par))));
13748 A := First (Parameter_Associations (Parent (Par)));
13749 while Present (F) loop
13750 if A = Par and then Ekind (F) /= E_In_Parameter then
13751 return False;
13752 end if;
13754 Next_Formal (F);
13755 Next (A);
13756 end loop;
13757 end;
13759 -- E_In_Parameter in a call: element is not modified.
13761 exit;
13762 end if;
13764 Par := Parent (Par);
13765 end loop;
13766 end;
13767 end if;
13769 -- The expression has the proper form and the context requires the
13770 -- element type. Retrieve the Element function of the container and
13771 -- rewrite the construct as a call to it.
13773 declare
13774 Op : Elmt_Id;
13776 begin
13777 Op := First_Elmt (Primitive_Operations (Cont_Typ));
13778 while Present (Op) loop
13779 exit when Chars (Node (Op)) = Name_Element;
13780 Next_Elmt (Op);
13781 end loop;
13783 if No (Op) then
13784 return False;
13786 else
13787 Rewrite (Exp,
13788 Make_Function_Call (Loc,
13789 Name => New_Occurrence_Of (Node (Op), Loc),
13790 Parameter_Associations => Parameter_Associations (Call)));
13791 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
13792 return True;
13793 end if;
13794 end;
13795 end Is_Container_Element;
13797 ----------------------------
13798 -- Is_Contract_Annotation --
13799 ----------------------------
13801 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
13802 begin
13803 return Is_Package_Contract_Annotation (Item)
13804 or else
13805 Is_Subprogram_Contract_Annotation (Item);
13806 end Is_Contract_Annotation;
13808 --------------------------------------
13809 -- Is_Controlling_Limited_Procedure --
13810 --------------------------------------
13812 function Is_Controlling_Limited_Procedure
13813 (Proc_Nam : Entity_Id) return Boolean
13815 Param : Node_Id;
13816 Param_Typ : Entity_Id := Empty;
13818 begin
13819 if Ekind (Proc_Nam) = E_Procedure
13820 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
13821 then
13822 Param :=
13823 Parameter_Type
13824 (First (Parameter_Specifications (Parent (Proc_Nam))));
13826 -- The formal may be an anonymous access type
13828 if Nkind (Param) = N_Access_Definition then
13829 Param_Typ := Entity (Subtype_Mark (Param));
13830 else
13831 Param_Typ := Etype (Param);
13832 end if;
13834 -- In the case where an Itype was created for a dispatchin call, the
13835 -- procedure call has been rewritten. The actual may be an access to
13836 -- interface type in which case it is the designated type that is the
13837 -- controlling type.
13839 elsif Present (Associated_Node_For_Itype (Proc_Nam))
13840 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
13841 and then
13842 Present (Parameter_Associations
13843 (Associated_Node_For_Itype (Proc_Nam)))
13844 then
13845 Param_Typ :=
13846 Etype (First (Parameter_Associations
13847 (Associated_Node_For_Itype (Proc_Nam))));
13849 if Ekind (Param_Typ) = E_Anonymous_Access_Type then
13850 Param_Typ := Directly_Designated_Type (Param_Typ);
13851 end if;
13852 end if;
13854 if Present (Param_Typ) then
13855 return
13856 Is_Interface (Param_Typ)
13857 and then Is_Limited_Record (Param_Typ);
13858 end if;
13860 return False;
13861 end Is_Controlling_Limited_Procedure;
13863 -----------------------------
13864 -- Is_CPP_Constructor_Call --
13865 -----------------------------
13867 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
13868 begin
13869 return Nkind (N) = N_Function_Call
13870 and then Is_CPP_Class (Etype (Etype (N)))
13871 and then Is_Constructor (Entity (Name (N)))
13872 and then Is_Imported (Entity (Name (N)));
13873 end Is_CPP_Constructor_Call;
13875 -------------------------
13876 -- Is_Current_Instance --
13877 -------------------------
13879 function Is_Current_Instance (N : Node_Id) return Boolean is
13880 Typ : constant Entity_Id := Entity (N);
13881 P : Node_Id;
13883 begin
13884 -- Simplest case: entity is a concurrent type and we are currently
13885 -- inside the body. This will eventually be expanded into a call to
13886 -- Self (for tasks) or _object (for protected objects).
13888 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
13889 return True;
13891 else
13892 -- Check whether the context is a (sub)type declaration for the
13893 -- type entity.
13895 P := Parent (N);
13896 while Present (P) loop
13897 if Nkind_In (P, N_Full_Type_Declaration,
13898 N_Private_Type_Declaration,
13899 N_Subtype_Declaration)
13900 and then Comes_From_Source (P)
13901 and then Defining_Entity (P) = Typ
13902 then
13903 return True;
13905 -- A subtype name may appear in an aspect specification for a
13906 -- Predicate_Failure aspect, for which we do not construct a
13907 -- wrapper procedure. The subtype will be replaced by the
13908 -- expression being tested when the corresponding predicate
13909 -- check is expanded.
13911 elsif Nkind (P) = N_Aspect_Specification
13912 and then Nkind (Parent (P)) = N_Subtype_Declaration
13913 then
13914 return True;
13916 elsif Nkind (P) = N_Pragma
13917 and then Get_Pragma_Id (P) = Pragma_Predicate_Failure
13918 then
13919 return True;
13920 end if;
13922 P := Parent (P);
13923 end loop;
13924 end if;
13926 -- In any other context this is not a current occurrence
13928 return False;
13929 end Is_Current_Instance;
13931 --------------------
13932 -- Is_Declaration --
13933 --------------------
13935 function Is_Declaration
13936 (N : Node_Id;
13937 Body_OK : Boolean := True;
13938 Concurrent_OK : Boolean := True;
13939 Formal_OK : Boolean := True;
13940 Generic_OK : Boolean := True;
13941 Instantiation_OK : Boolean := True;
13942 Renaming_OK : Boolean := True;
13943 Stub_OK : Boolean := True;
13944 Subprogram_OK : Boolean := True;
13945 Type_OK : Boolean := True) return Boolean
13947 begin
13948 case Nkind (N) is
13950 -- Body declarations
13952 when N_Proper_Body =>
13953 return Body_OK;
13955 -- Concurrent type declarations
13957 when N_Protected_Type_Declaration
13958 | N_Single_Protected_Declaration
13959 | N_Single_Task_Declaration
13960 | N_Task_Type_Declaration
13962 return Concurrent_OK or Type_OK;
13964 -- Formal declarations
13966 when N_Formal_Abstract_Subprogram_Declaration
13967 | N_Formal_Concrete_Subprogram_Declaration
13968 | N_Formal_Object_Declaration
13969 | N_Formal_Package_Declaration
13970 | N_Formal_Type_Declaration
13972 return Formal_OK;
13974 -- Generic declarations
13976 when N_Generic_Package_Declaration
13977 | N_Generic_Subprogram_Declaration
13979 return Generic_OK;
13981 -- Generic instantiations
13983 when N_Function_Instantiation
13984 | N_Package_Instantiation
13985 | N_Procedure_Instantiation
13987 return Instantiation_OK;
13989 -- Generic renaming declarations
13991 when N_Generic_Renaming_Declaration =>
13992 return Generic_OK or Renaming_OK;
13994 -- Renaming declarations
13996 when N_Exception_Renaming_Declaration
13997 | N_Object_Renaming_Declaration
13998 | N_Package_Renaming_Declaration
13999 | N_Subprogram_Renaming_Declaration
14001 return Renaming_OK;
14003 -- Stub declarations
14005 when N_Body_Stub =>
14006 return Stub_OK;
14008 -- Subprogram declarations
14010 when N_Abstract_Subprogram_Declaration
14011 | N_Entry_Declaration
14012 | N_Expression_Function
14013 | N_Subprogram_Declaration
14015 return Subprogram_OK;
14017 -- Type declarations
14019 when N_Full_Type_Declaration
14020 | N_Incomplete_Type_Declaration
14021 | N_Private_Extension_Declaration
14022 | N_Private_Type_Declaration
14023 | N_Subtype_Declaration
14025 return Type_OK;
14027 -- Miscellaneous
14029 when N_Component_Declaration
14030 | N_Exception_Declaration
14031 | N_Implicit_Label_Declaration
14032 | N_Number_Declaration
14033 | N_Object_Declaration
14034 | N_Package_Declaration
14036 return True;
14038 when others =>
14039 return False;
14040 end case;
14041 end Is_Declaration;
14043 --------------------------------
14044 -- Is_Declared_Within_Variant --
14045 --------------------------------
14047 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
14048 Comp_Decl : constant Node_Id := Parent (Comp);
14049 Comp_List : constant Node_Id := Parent (Comp_Decl);
14050 begin
14051 return Nkind (Parent (Comp_List)) = N_Variant;
14052 end Is_Declared_Within_Variant;
14054 ----------------------------------------------
14055 -- Is_Dependent_Component_Of_Mutable_Object --
14056 ----------------------------------------------
14058 function Is_Dependent_Component_Of_Mutable_Object
14059 (Object : Node_Id) return Boolean
14061 P : Node_Id;
14062 Prefix_Type : Entity_Id;
14063 P_Aliased : Boolean := False;
14064 Comp : Entity_Id;
14066 Deref : Node_Id := Object;
14067 -- Dereference node, in something like X.all.Y(2)
14069 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
14071 begin
14072 -- Find the dereference node if any
14074 while Nkind_In (Deref, N_Indexed_Component,
14075 N_Selected_Component,
14076 N_Slice)
14077 loop
14078 Deref := Prefix (Deref);
14079 end loop;
14081 -- Ada 2005: If we have a component or slice of a dereference,
14082 -- something like X.all.Y (2), and the type of X is access-to-constant,
14083 -- Is_Variable will return False, because it is indeed a constant
14084 -- view. But it might be a view of a variable object, so we want the
14085 -- following condition to be True in that case.
14087 if Is_Variable (Object)
14088 or else (Ada_Version >= Ada_2005
14089 and then Nkind (Deref) = N_Explicit_Dereference)
14090 then
14091 if Nkind (Object) = N_Selected_Component then
14092 P := Prefix (Object);
14093 Prefix_Type := Etype (P);
14095 if Is_Entity_Name (P) then
14096 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
14097 Prefix_Type := Base_Type (Prefix_Type);
14098 end if;
14100 if Is_Aliased (Entity (P)) then
14101 P_Aliased := True;
14102 end if;
14104 -- A discriminant check on a selected component may be expanded
14105 -- into a dereference when removing side effects. Recover the
14106 -- original node and its type, which may be unconstrained.
14108 elsif Nkind (P) = N_Explicit_Dereference
14109 and then not (Comes_From_Source (P))
14110 then
14111 P := Original_Node (P);
14112 Prefix_Type := Etype (P);
14114 else
14115 -- Check for prefix being an aliased component???
14117 null;
14119 end if;
14121 -- A heap object is constrained by its initial value
14123 -- Ada 2005 (AI-363): Always assume the object could be mutable in
14124 -- the dereferenced case, since the access value might denote an
14125 -- unconstrained aliased object, whereas in Ada 95 the designated
14126 -- object is guaranteed to be constrained. A worst-case assumption
14127 -- has to apply in Ada 2005 because we can't tell at compile
14128 -- time whether the object is "constrained by its initial value",
14129 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
14130 -- rules (these rules are acknowledged to need fixing). We don't
14131 -- impose this more stringent checking for earlier Ada versions or
14132 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
14133 -- benefit, though it's unclear on why using -gnat95 would not be
14134 -- sufficient???).
14136 if Ada_Version < Ada_2005 or else Relaxed_RM_Semantics then
14137 if Is_Access_Type (Prefix_Type)
14138 or else Nkind (P) = N_Explicit_Dereference
14139 then
14140 return False;
14141 end if;
14143 else pragma Assert (Ada_Version >= Ada_2005);
14144 if Is_Access_Type (Prefix_Type) then
14146 -- If the access type is pool-specific, and there is no
14147 -- constrained partial view of the designated type, then the
14148 -- designated object is known to be constrained.
14150 if Ekind (Prefix_Type) = E_Access_Type
14151 and then not Object_Type_Has_Constrained_Partial_View
14152 (Typ => Designated_Type (Prefix_Type),
14153 Scop => Current_Scope)
14154 then
14155 return False;
14157 -- Otherwise (general access type, or there is a constrained
14158 -- partial view of the designated type), we need to check
14159 -- based on the designated type.
14161 else
14162 Prefix_Type := Designated_Type (Prefix_Type);
14163 end if;
14164 end if;
14165 end if;
14167 Comp :=
14168 Original_Record_Component (Entity (Selector_Name (Object)));
14170 -- As per AI-0017, the renaming is illegal in a generic body, even
14171 -- if the subtype is indefinite.
14173 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
14175 if not Is_Constrained (Prefix_Type)
14176 and then (Is_Definite_Subtype (Prefix_Type)
14177 or else
14178 (Is_Generic_Type (Prefix_Type)
14179 and then Ekind (Current_Scope) = E_Generic_Package
14180 and then In_Package_Body (Current_Scope)))
14182 and then (Is_Declared_Within_Variant (Comp)
14183 or else Has_Discriminant_Dependent_Constraint (Comp))
14184 and then (not P_Aliased or else Ada_Version >= Ada_2005)
14185 then
14186 return True;
14188 -- If the prefix is of an access type at this point, then we want
14189 -- to return False, rather than calling this function recursively
14190 -- on the access object (which itself might be a discriminant-
14191 -- dependent component of some other object, but that isn't
14192 -- relevant to checking the object passed to us). This avoids
14193 -- issuing wrong errors when compiling with -gnatc, where there
14194 -- can be implicit dereferences that have not been expanded.
14196 elsif Is_Access_Type (Etype (Prefix (Object))) then
14197 return False;
14199 else
14200 return
14201 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14202 end if;
14204 elsif Nkind (Object) = N_Indexed_Component
14205 or else Nkind (Object) = N_Slice
14206 then
14207 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
14209 -- A type conversion that Is_Variable is a view conversion:
14210 -- go back to the denoted object.
14212 elsif Nkind (Object) = N_Type_Conversion then
14213 return
14214 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
14215 end if;
14216 end if;
14218 return False;
14219 end Is_Dependent_Component_Of_Mutable_Object;
14221 ---------------------
14222 -- Is_Dereferenced --
14223 ---------------------
14225 function Is_Dereferenced (N : Node_Id) return Boolean is
14226 P : constant Node_Id := Parent (N);
14227 begin
14228 return Nkind_In (P, N_Selected_Component,
14229 N_Explicit_Dereference,
14230 N_Indexed_Component,
14231 N_Slice)
14232 and then Prefix (P) = N;
14233 end Is_Dereferenced;
14235 ----------------------
14236 -- Is_Descendant_Of --
14237 ----------------------
14239 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
14240 T : Entity_Id;
14241 Etyp : Entity_Id;
14243 begin
14244 pragma Assert (Nkind (T1) in N_Entity);
14245 pragma Assert (Nkind (T2) in N_Entity);
14247 T := Base_Type (T1);
14249 -- Immediate return if the types match
14251 if T = T2 then
14252 return True;
14254 -- Comment needed here ???
14256 elsif Ekind (T) = E_Class_Wide_Type then
14257 return Etype (T) = T2;
14259 -- All other cases
14261 else
14262 loop
14263 Etyp := Etype (T);
14265 -- Done if we found the type we are looking for
14267 if Etyp = T2 then
14268 return True;
14270 -- Done if no more derivations to check
14272 elsif T = T1
14273 or else T = Etyp
14274 then
14275 return False;
14277 -- Following test catches error cases resulting from prev errors
14279 elsif No (Etyp) then
14280 return False;
14282 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
14283 return False;
14285 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
14286 return False;
14287 end if;
14289 T := Base_Type (Etyp);
14290 end loop;
14291 end if;
14292 end Is_Descendant_Of;
14294 ----------------------------------------
14295 -- Is_Descendant_Of_Suspension_Object --
14296 ----------------------------------------
14298 function Is_Descendant_Of_Suspension_Object
14299 (Typ : Entity_Id) return Boolean
14301 Cur_Typ : Entity_Id;
14302 Par_Typ : Entity_Id;
14304 begin
14305 -- Climb the type derivation chain checking each parent type against
14306 -- Suspension_Object.
14308 Cur_Typ := Base_Type (Typ);
14309 while Present (Cur_Typ) loop
14310 Par_Typ := Etype (Cur_Typ);
14312 -- The current type is a match
14314 if Is_Suspension_Object (Cur_Typ) then
14315 return True;
14317 -- Stop the traversal once the root of the derivation chain has been
14318 -- reached. In that case the current type is its own base type.
14320 elsif Cur_Typ = Par_Typ then
14321 exit;
14322 end if;
14324 Cur_Typ := Base_Type (Par_Typ);
14325 end loop;
14327 return False;
14328 end Is_Descendant_Of_Suspension_Object;
14330 ---------------------------------------------
14331 -- Is_Double_Precision_Floating_Point_Type --
14332 ---------------------------------------------
14334 function Is_Double_Precision_Floating_Point_Type
14335 (E : Entity_Id) return Boolean is
14336 begin
14337 return Is_Floating_Point_Type (E)
14338 and then Machine_Radix_Value (E) = Uint_2
14339 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
14340 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
14341 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
14342 end Is_Double_Precision_Floating_Point_Type;
14344 -----------------------------
14345 -- Is_Effectively_Volatile --
14346 -----------------------------
14348 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
14349 begin
14350 if Is_Type (Id) then
14352 -- An arbitrary type is effectively volatile when it is subject to
14353 -- pragma Atomic or Volatile.
14355 if Is_Volatile (Id) then
14356 return True;
14358 -- An array type is effectively volatile when it is subject to pragma
14359 -- Atomic_Components or Volatile_Components or its component type is
14360 -- effectively volatile.
14362 elsif Is_Array_Type (Id) then
14363 declare
14364 Anc : Entity_Id := Base_Type (Id);
14365 begin
14366 if Is_Private_Type (Anc) then
14367 Anc := Full_View (Anc);
14368 end if;
14370 -- Test for presence of ancestor, as the full view of a private
14371 -- type may be missing in case of error.
14373 return
14374 Has_Volatile_Components (Id)
14375 or else
14376 (Present (Anc)
14377 and then Is_Effectively_Volatile (Component_Type (Anc)));
14378 end;
14380 -- A protected type is always volatile
14382 elsif Is_Protected_Type (Id) then
14383 return True;
14385 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
14386 -- automatically volatile.
14388 elsif Is_Descendant_Of_Suspension_Object (Id) then
14389 return True;
14391 -- Otherwise the type is not effectively volatile
14393 else
14394 return False;
14395 end if;
14397 -- Otherwise Id denotes an object
14399 else
14400 return
14401 Is_Volatile (Id)
14402 or else Has_Volatile_Components (Id)
14403 or else Is_Effectively_Volatile (Etype (Id));
14404 end if;
14405 end Is_Effectively_Volatile;
14407 ------------------------------------
14408 -- Is_Effectively_Volatile_Object --
14409 ------------------------------------
14411 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
14412 begin
14413 if Is_Entity_Name (N) then
14414 return Is_Effectively_Volatile (Entity (N));
14416 elsif Nkind (N) = N_Indexed_Component then
14417 return Is_Effectively_Volatile_Object (Prefix (N));
14419 elsif Nkind (N) = N_Selected_Component then
14420 return
14421 Is_Effectively_Volatile_Object (Prefix (N))
14422 or else
14423 Is_Effectively_Volatile_Object (Selector_Name (N));
14425 else
14426 return False;
14427 end if;
14428 end Is_Effectively_Volatile_Object;
14430 -------------------
14431 -- Is_Entry_Body --
14432 -------------------
14434 function Is_Entry_Body (Id : Entity_Id) return Boolean is
14435 begin
14436 return
14437 Ekind_In (Id, E_Entry, E_Entry_Family)
14438 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
14439 end Is_Entry_Body;
14441 --------------------------
14442 -- Is_Entry_Declaration --
14443 --------------------------
14445 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
14446 begin
14447 return
14448 Ekind_In (Id, E_Entry, E_Entry_Family)
14449 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
14450 end Is_Entry_Declaration;
14452 ------------------------------------
14453 -- Is_Expanded_Priority_Attribute --
14454 ------------------------------------
14456 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
14457 begin
14458 return
14459 Nkind (E) = N_Function_Call
14460 and then not Configurable_Run_Time_Mode
14461 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
14462 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
14463 end Is_Expanded_Priority_Attribute;
14465 ----------------------------
14466 -- Is_Expression_Function --
14467 ----------------------------
14469 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
14470 begin
14471 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
14472 return
14473 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
14474 N_Expression_Function;
14475 else
14476 return False;
14477 end if;
14478 end Is_Expression_Function;
14480 ------------------------------------------
14481 -- Is_Expression_Function_Or_Completion --
14482 ------------------------------------------
14484 function Is_Expression_Function_Or_Completion
14485 (Subp : Entity_Id) return Boolean
14487 Subp_Decl : Node_Id;
14489 begin
14490 if Ekind (Subp) = E_Function then
14491 Subp_Decl := Unit_Declaration_Node (Subp);
14493 -- The function declaration is either an expression function or is
14494 -- completed by an expression function body.
14496 return
14497 Is_Expression_Function (Subp)
14498 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
14499 and then Present (Corresponding_Body (Subp_Decl))
14500 and then Is_Expression_Function
14501 (Corresponding_Body (Subp_Decl)));
14503 elsif Ekind (Subp) = E_Subprogram_Body then
14504 return Is_Expression_Function (Subp);
14506 else
14507 return False;
14508 end if;
14509 end Is_Expression_Function_Or_Completion;
14511 -----------------------
14512 -- Is_EVF_Expression --
14513 -----------------------
14515 function Is_EVF_Expression (N : Node_Id) return Boolean is
14516 Orig_N : constant Node_Id := Original_Node (N);
14517 Alt : Node_Id;
14518 Expr : Node_Id;
14519 Id : Entity_Id;
14521 begin
14522 -- Detect a reference to a formal parameter of a specific tagged type
14523 -- whose related subprogram is subject to pragma Expresions_Visible with
14524 -- value "False".
14526 if Is_Entity_Name (N) and then Present (Entity (N)) then
14527 Id := Entity (N);
14529 return
14530 Is_Formal (Id)
14531 and then Is_Specific_Tagged_Type (Etype (Id))
14532 and then Extensions_Visible_Status (Id) =
14533 Extensions_Visible_False;
14535 -- A case expression is an EVF expression when it contains at least one
14536 -- EVF dependent_expression. Note that a case expression may have been
14537 -- expanded, hence the use of Original_Node.
14539 elsif Nkind (Orig_N) = N_Case_Expression then
14540 Alt := First (Alternatives (Orig_N));
14541 while Present (Alt) loop
14542 if Is_EVF_Expression (Expression (Alt)) then
14543 return True;
14544 end if;
14546 Next (Alt);
14547 end loop;
14549 -- An if expression is an EVF expression when it contains at least one
14550 -- EVF dependent_expression. Note that an if expression may have been
14551 -- expanded, hence the use of Original_Node.
14553 elsif Nkind (Orig_N) = N_If_Expression then
14554 Expr := Next (First (Expressions (Orig_N)));
14555 while Present (Expr) loop
14556 if Is_EVF_Expression (Expr) then
14557 return True;
14558 end if;
14560 Next (Expr);
14561 end loop;
14563 -- A qualified expression or a type conversion is an EVF expression when
14564 -- its operand is an EVF expression.
14566 elsif Nkind_In (N, N_Qualified_Expression,
14567 N_Unchecked_Type_Conversion,
14568 N_Type_Conversion)
14569 then
14570 return Is_EVF_Expression (Expression (N));
14572 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
14573 -- their prefix denotes an EVF expression.
14575 elsif Nkind (N) = N_Attribute_Reference
14576 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
14577 Name_Old,
14578 Name_Update)
14579 then
14580 return Is_EVF_Expression (Prefix (N));
14581 end if;
14583 return False;
14584 end Is_EVF_Expression;
14586 --------------
14587 -- Is_False --
14588 --------------
14590 function Is_False (U : Uint) return Boolean is
14591 begin
14592 return (U = 0);
14593 end Is_False;
14595 ---------------------------
14596 -- Is_Fixed_Model_Number --
14597 ---------------------------
14599 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
14600 S : constant Ureal := Small_Value (T);
14601 M : Urealp.Save_Mark;
14602 R : Boolean;
14604 begin
14605 M := Urealp.Mark;
14606 R := (U = UR_Trunc (U / S) * S);
14607 Urealp.Release (M);
14608 return R;
14609 end Is_Fixed_Model_Number;
14611 -------------------------------
14612 -- Is_Fully_Initialized_Type --
14613 -------------------------------
14615 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
14616 begin
14617 -- Scalar types
14619 if Is_Scalar_Type (Typ) then
14621 -- A scalar type with an aspect Default_Value is fully initialized
14623 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
14624 -- of a scalar type, but we don't take that into account here, since
14625 -- we don't want these to affect warnings.
14627 return Has_Default_Aspect (Typ);
14629 elsif Is_Access_Type (Typ) then
14630 return True;
14632 elsif Is_Array_Type (Typ) then
14633 if Is_Fully_Initialized_Type (Component_Type (Typ))
14634 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
14635 then
14636 return True;
14637 end if;
14639 -- An interesting case, if we have a constrained type one of whose
14640 -- bounds is known to be null, then there are no elements to be
14641 -- initialized, so all the elements are initialized.
14643 if Is_Constrained (Typ) then
14644 declare
14645 Indx : Node_Id;
14646 Indx_Typ : Entity_Id;
14647 Lbd, Hbd : Node_Id;
14649 begin
14650 Indx := First_Index (Typ);
14651 while Present (Indx) loop
14652 if Etype (Indx) = Any_Type then
14653 return False;
14655 -- If index is a range, use directly
14657 elsif Nkind (Indx) = N_Range then
14658 Lbd := Low_Bound (Indx);
14659 Hbd := High_Bound (Indx);
14661 else
14662 Indx_Typ := Etype (Indx);
14664 if Is_Private_Type (Indx_Typ) then
14665 Indx_Typ := Full_View (Indx_Typ);
14666 end if;
14668 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
14669 return False;
14670 else
14671 Lbd := Type_Low_Bound (Indx_Typ);
14672 Hbd := Type_High_Bound (Indx_Typ);
14673 end if;
14674 end if;
14676 if Compile_Time_Known_Value (Lbd)
14677 and then
14678 Compile_Time_Known_Value (Hbd)
14679 then
14680 if Expr_Value (Hbd) < Expr_Value (Lbd) then
14681 return True;
14682 end if;
14683 end if;
14685 Next_Index (Indx);
14686 end loop;
14687 end;
14688 end if;
14690 -- If no null indexes, then type is not fully initialized
14692 return False;
14694 -- Record types
14696 elsif Is_Record_Type (Typ) then
14697 if Has_Discriminants (Typ)
14698 and then
14699 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
14700 and then Is_Fully_Initialized_Variant (Typ)
14701 then
14702 return True;
14703 end if;
14705 -- We consider bounded string types to be fully initialized, because
14706 -- otherwise we get false alarms when the Data component is not
14707 -- default-initialized.
14709 if Is_Bounded_String (Typ) then
14710 return True;
14711 end if;
14713 -- Controlled records are considered to be fully initialized if
14714 -- there is a user defined Initialize routine. This may not be
14715 -- entirely correct, but as the spec notes, we are guessing here
14716 -- what is best from the point of view of issuing warnings.
14718 if Is_Controlled (Typ) then
14719 declare
14720 Utyp : constant Entity_Id := Underlying_Type (Typ);
14722 begin
14723 if Present (Utyp) then
14724 declare
14725 Init : constant Entity_Id :=
14726 (Find_Optional_Prim_Op
14727 (Underlying_Type (Typ), Name_Initialize));
14729 begin
14730 if Present (Init)
14731 and then Comes_From_Source (Init)
14732 and then not In_Predefined_Unit (Init)
14733 then
14734 return True;
14736 elsif Has_Null_Extension (Typ)
14737 and then
14738 Is_Fully_Initialized_Type
14739 (Etype (Base_Type (Typ)))
14740 then
14741 return True;
14742 end if;
14743 end;
14744 end if;
14745 end;
14746 end if;
14748 -- Otherwise see if all record components are initialized
14750 declare
14751 Ent : Entity_Id;
14753 begin
14754 Ent := First_Entity (Typ);
14755 while Present (Ent) loop
14756 if Ekind (Ent) = E_Component
14757 and then (No (Parent (Ent))
14758 or else No (Expression (Parent (Ent))))
14759 and then not Is_Fully_Initialized_Type (Etype (Ent))
14761 -- Special VM case for tag components, which need to be
14762 -- defined in this case, but are never initialized as VMs
14763 -- are using other dispatching mechanisms. Ignore this
14764 -- uninitialized case. Note that this applies both to the
14765 -- uTag entry and the main vtable pointer (CPP_Class case).
14767 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
14768 then
14769 return False;
14770 end if;
14772 Next_Entity (Ent);
14773 end loop;
14774 end;
14776 -- No uninitialized components, so type is fully initialized.
14777 -- Note that this catches the case of no components as well.
14779 return True;
14781 elsif Is_Concurrent_Type (Typ) then
14782 return True;
14784 elsif Is_Private_Type (Typ) then
14785 declare
14786 U : constant Entity_Id := Underlying_Type (Typ);
14788 begin
14789 if No (U) then
14790 return False;
14791 else
14792 return Is_Fully_Initialized_Type (U);
14793 end if;
14794 end;
14796 else
14797 return False;
14798 end if;
14799 end Is_Fully_Initialized_Type;
14801 ----------------------------------
14802 -- Is_Fully_Initialized_Variant --
14803 ----------------------------------
14805 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
14806 Loc : constant Source_Ptr := Sloc (Typ);
14807 Constraints : constant List_Id := New_List;
14808 Components : constant Elist_Id := New_Elmt_List;
14809 Comp_Elmt : Elmt_Id;
14810 Comp_Id : Node_Id;
14811 Comp_List : Node_Id;
14812 Discr : Entity_Id;
14813 Discr_Val : Node_Id;
14815 Report_Errors : Boolean;
14816 pragma Warnings (Off, Report_Errors);
14818 begin
14819 if Serious_Errors_Detected > 0 then
14820 return False;
14821 end if;
14823 if Is_Record_Type (Typ)
14824 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
14825 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
14826 then
14827 Comp_List := Component_List (Type_Definition (Parent (Typ)));
14829 Discr := First_Discriminant (Typ);
14830 while Present (Discr) loop
14831 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
14832 Discr_Val := Expression (Parent (Discr));
14834 if Present (Discr_Val)
14835 and then Is_OK_Static_Expression (Discr_Val)
14836 then
14837 Append_To (Constraints,
14838 Make_Component_Association (Loc,
14839 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
14840 Expression => New_Copy (Discr_Val)));
14841 else
14842 return False;
14843 end if;
14844 else
14845 return False;
14846 end if;
14848 Next_Discriminant (Discr);
14849 end loop;
14851 Gather_Components
14852 (Typ => Typ,
14853 Comp_List => Comp_List,
14854 Governed_By => Constraints,
14855 Into => Components,
14856 Report_Errors => Report_Errors);
14858 -- Check that each component present is fully initialized
14860 Comp_Elmt := First_Elmt (Components);
14861 while Present (Comp_Elmt) loop
14862 Comp_Id := Node (Comp_Elmt);
14864 if Ekind (Comp_Id) = E_Component
14865 and then (No (Parent (Comp_Id))
14866 or else No (Expression (Parent (Comp_Id))))
14867 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
14868 then
14869 return False;
14870 end if;
14872 Next_Elmt (Comp_Elmt);
14873 end loop;
14875 return True;
14877 elsif Is_Private_Type (Typ) then
14878 declare
14879 U : constant Entity_Id := Underlying_Type (Typ);
14881 begin
14882 if No (U) then
14883 return False;
14884 else
14885 return Is_Fully_Initialized_Variant (U);
14886 end if;
14887 end;
14889 else
14890 return False;
14891 end if;
14892 end Is_Fully_Initialized_Variant;
14894 ------------------------------------
14895 -- Is_Generic_Declaration_Or_Body --
14896 ------------------------------------
14898 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
14899 Spec_Decl : Node_Id;
14901 begin
14902 -- Package/subprogram body
14904 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
14905 and then Present (Corresponding_Spec (Decl))
14906 then
14907 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
14909 -- Package/subprogram body stub
14911 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
14912 and then Present (Corresponding_Spec_Of_Stub (Decl))
14913 then
14914 Spec_Decl :=
14915 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
14917 -- All other cases
14919 else
14920 Spec_Decl := Decl;
14921 end if;
14923 -- Rather than inspecting the defining entity of the spec declaration,
14924 -- look at its Nkind. This takes care of the case where the analysis of
14925 -- a generic body modifies the Ekind of its spec to allow for recursive
14926 -- calls.
14928 return
14929 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
14930 N_Generic_Subprogram_Declaration);
14931 end Is_Generic_Declaration_Or_Body;
14933 ----------------------------
14934 -- Is_Inherited_Operation --
14935 ----------------------------
14937 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
14938 pragma Assert (Is_Overloadable (E));
14939 Kind : constant Node_Kind := Nkind (Parent (E));
14940 begin
14941 return Kind = N_Full_Type_Declaration
14942 or else Kind = N_Private_Extension_Declaration
14943 or else Kind = N_Subtype_Declaration
14944 or else (Ekind (E) = E_Enumeration_Literal
14945 and then Is_Derived_Type (Etype (E)));
14946 end Is_Inherited_Operation;
14948 -------------------------------------
14949 -- Is_Inherited_Operation_For_Type --
14950 -------------------------------------
14952 function Is_Inherited_Operation_For_Type
14953 (E : Entity_Id;
14954 Typ : Entity_Id) return Boolean
14956 begin
14957 -- Check that the operation has been created by the type declaration
14959 return Is_Inherited_Operation (E)
14960 and then Defining_Identifier (Parent (E)) = Typ;
14961 end Is_Inherited_Operation_For_Type;
14963 --------------------------------------
14964 -- Is_Inlinable_Expression_Function --
14965 --------------------------------------
14967 function Is_Inlinable_Expression_Function
14968 (Subp : Entity_Id) return Boolean
14970 Return_Expr : Node_Id;
14972 begin
14973 if Is_Expression_Function_Or_Completion (Subp)
14974 and then Has_Pragma_Inline_Always (Subp)
14975 and then Needs_No_Actuals (Subp)
14976 and then No (Contract (Subp))
14977 and then not Is_Dispatching_Operation (Subp)
14978 and then Needs_Finalization (Etype (Subp))
14979 and then not Is_Class_Wide_Type (Etype (Subp))
14980 and then not (Has_Invariants (Etype (Subp)))
14981 and then Present (Subprogram_Body (Subp))
14982 and then Was_Expression_Function (Subprogram_Body (Subp))
14983 then
14984 Return_Expr := Expression_Of_Expression_Function (Subp);
14986 -- The returned object must not have a qualified expression and its
14987 -- nominal subtype must be statically compatible with the result
14988 -- subtype of the expression function.
14990 return
14991 Nkind (Return_Expr) = N_Identifier
14992 and then Etype (Return_Expr) = Etype (Subp);
14993 end if;
14995 return False;
14996 end Is_Inlinable_Expression_Function;
14998 -----------------
14999 -- Is_Iterator --
15000 -----------------
15002 function Is_Iterator (Typ : Entity_Id) return Boolean is
15003 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
15004 -- Determine whether type Iter_Typ is a predefined forward or reversible
15005 -- iterator.
15007 ----------------------
15008 -- Denotes_Iterator --
15009 ----------------------
15011 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
15012 begin
15013 -- Check that the name matches, and that the ultimate ancestor is in
15014 -- a predefined unit, i.e the one that declares iterator interfaces.
15016 return
15017 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
15018 Name_Reversible_Iterator)
15019 and then In_Predefined_Unit (Root_Type (Iter_Typ));
15020 end Denotes_Iterator;
15022 -- Local variables
15024 Iface_Elmt : Elmt_Id;
15025 Ifaces : Elist_Id;
15027 -- Start of processing for Is_Iterator
15029 begin
15030 -- The type may be a subtype of a descendant of the proper instance of
15031 -- the predefined interface type, so we must use the root type of the
15032 -- given type. The same is done for Is_Reversible_Iterator.
15034 if Is_Class_Wide_Type (Typ)
15035 and then Denotes_Iterator (Root_Type (Typ))
15036 then
15037 return True;
15039 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
15040 return False;
15042 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
15043 return True;
15045 else
15046 Collect_Interfaces (Typ, Ifaces);
15048 Iface_Elmt := First_Elmt (Ifaces);
15049 while Present (Iface_Elmt) loop
15050 if Denotes_Iterator (Node (Iface_Elmt)) then
15051 return True;
15052 end if;
15054 Next_Elmt (Iface_Elmt);
15055 end loop;
15057 return False;
15058 end if;
15059 end Is_Iterator;
15061 ----------------------------
15062 -- Is_Iterator_Over_Array --
15063 ----------------------------
15065 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
15066 Container : constant Node_Id := Name (N);
15067 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
15068 begin
15069 return Is_Array_Type (Container_Typ);
15070 end Is_Iterator_Over_Array;
15072 ------------
15073 -- Is_LHS --
15074 ------------
15076 -- We seem to have a lot of overlapping functions that do similar things
15077 -- (testing for left hand sides or lvalues???).
15079 function Is_LHS (N : Node_Id) return Is_LHS_Result is
15080 P : constant Node_Id := Parent (N);
15082 begin
15083 -- Return True if we are the left hand side of an assignment statement
15085 if Nkind (P) = N_Assignment_Statement then
15086 if Name (P) = N then
15087 return Yes;
15088 else
15089 return No;
15090 end if;
15092 -- Case of prefix of indexed or selected component or slice
15094 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
15095 and then N = Prefix (P)
15096 then
15097 -- Here we have the case where the parent P is N.Q or N(Q .. R).
15098 -- If P is an LHS, then N is also effectively an LHS, but there
15099 -- is an important exception. If N is of an access type, then
15100 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
15101 -- case this makes N.all a left hand side but not N itself.
15103 -- If we don't know the type yet, this is the case where we return
15104 -- Unknown, since the answer depends on the type which is unknown.
15106 if No (Etype (N)) then
15107 return Unknown;
15109 -- We have an Etype set, so we can check it
15111 elsif Is_Access_Type (Etype (N)) then
15112 return No;
15114 -- OK, not access type case, so just test whole expression
15116 else
15117 return Is_LHS (P);
15118 end if;
15120 -- All other cases are not left hand sides
15122 else
15123 return No;
15124 end if;
15125 end Is_LHS;
15127 -----------------------------
15128 -- Is_Library_Level_Entity --
15129 -----------------------------
15131 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
15132 begin
15133 -- The following is a small optimization, and it also properly handles
15134 -- discriminals, which in task bodies might appear in expressions before
15135 -- the corresponding procedure has been created, and which therefore do
15136 -- not have an assigned scope.
15138 if Is_Formal (E) then
15139 return False;
15140 end if;
15142 -- Normal test is simply that the enclosing dynamic scope is Standard
15144 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
15145 end Is_Library_Level_Entity;
15147 --------------------------------
15148 -- Is_Limited_Class_Wide_Type --
15149 --------------------------------
15151 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
15152 begin
15153 return
15154 Is_Class_Wide_Type (Typ)
15155 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
15156 end Is_Limited_Class_Wide_Type;
15158 ---------------------------------
15159 -- Is_Local_Variable_Reference --
15160 ---------------------------------
15162 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
15163 begin
15164 if not Is_Entity_Name (Expr) then
15165 return False;
15167 else
15168 declare
15169 Ent : constant Entity_Id := Entity (Expr);
15170 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
15171 begin
15172 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
15173 return False;
15174 else
15175 return Present (Sub) and then Sub = Current_Subprogram;
15176 end if;
15177 end;
15178 end if;
15179 end Is_Local_Variable_Reference;
15181 -----------------------
15182 -- Is_Name_Reference --
15183 -----------------------
15185 function Is_Name_Reference (N : Node_Id) return Boolean is
15186 begin
15187 if Is_Entity_Name (N) then
15188 return Present (Entity (N)) and then Is_Object (Entity (N));
15189 end if;
15191 case Nkind (N) is
15192 when N_Indexed_Component
15193 | N_Slice
15195 return
15196 Is_Name_Reference (Prefix (N))
15197 or else Is_Access_Type (Etype (Prefix (N)));
15199 -- Attributes 'Input, 'Old and 'Result produce objects
15201 when N_Attribute_Reference =>
15202 return
15203 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
15205 when N_Selected_Component =>
15206 return
15207 Is_Name_Reference (Selector_Name (N))
15208 and then
15209 (Is_Name_Reference (Prefix (N))
15210 or else Is_Access_Type (Etype (Prefix (N))));
15212 when N_Explicit_Dereference =>
15213 return True;
15215 -- A view conversion of a tagged name is a name reference
15217 when N_Type_Conversion =>
15218 return
15219 Is_Tagged_Type (Etype (Subtype_Mark (N)))
15220 and then Is_Tagged_Type (Etype (Expression (N)))
15221 and then Is_Name_Reference (Expression (N));
15223 -- An unchecked type conversion is considered to be a name if the
15224 -- operand is a name (this construction arises only as a result of
15225 -- expansion activities).
15227 when N_Unchecked_Type_Conversion =>
15228 return Is_Name_Reference (Expression (N));
15230 when others =>
15231 return False;
15232 end case;
15233 end Is_Name_Reference;
15235 ------------------------------------
15236 -- Is_Non_Preelaborable_Construct --
15237 ------------------------------------
15239 function Is_Non_Preelaborable_Construct (N : Node_Id) return Boolean is
15241 -- NOTE: the routines within Is_Non_Preelaborable_Construct are
15242 -- intentionally unnested to avoid deep indentation of code.
15244 Non_Preelaborable : exception;
15245 -- This exception is raised when the construct violates preelaborability
15246 -- to terminate the recursion.
15248 procedure Visit (Nod : Node_Id);
15249 -- Semantically inspect construct Nod to determine whether it violates
15250 -- preelaborability. This routine raises Non_Preelaborable.
15252 procedure Visit_List (List : List_Id);
15253 pragma Inline (Visit_List);
15254 -- Invoke Visit on each element of list List. This routine raises
15255 -- Non_Preelaborable.
15257 procedure Visit_Pragma (Prag : Node_Id);
15258 pragma Inline (Visit_Pragma);
15259 -- Semantically inspect pragma Prag to determine whether it violates
15260 -- preelaborability. This routine raises Non_Preelaborable.
15262 procedure Visit_Subexpression (Expr : Node_Id);
15263 pragma Inline (Visit_Subexpression);
15264 -- Semantically inspect expression Expr to determine whether it violates
15265 -- preelaborability. This routine raises Non_Preelaborable.
15267 -----------
15268 -- Visit --
15269 -----------
15271 procedure Visit (Nod : Node_Id) is
15272 begin
15273 case Nkind (Nod) is
15275 -- Declarations
15277 when N_Component_Declaration =>
15279 -- Defining_Identifier is left out because it is not relevant
15280 -- for preelaborability.
15282 Visit (Component_Definition (Nod));
15283 Visit (Expression (Nod));
15285 when N_Derived_Type_Definition =>
15287 -- Interface_List is left out because it is not relevant for
15288 -- preelaborability.
15290 Visit (Record_Extension_Part (Nod));
15291 Visit (Subtype_Indication (Nod));
15293 when N_Entry_Declaration =>
15295 -- A protected type with at leat one entry is not preelaborable
15296 -- while task types are never preelaborable. This renders entry
15297 -- declarations non-preelaborable.
15299 raise Non_Preelaborable;
15301 when N_Full_Type_Declaration =>
15303 -- Defining_Identifier and Discriminant_Specifications are left
15304 -- out because they are not relevant for preelaborability.
15306 Visit (Type_Definition (Nod));
15308 when N_Function_Instantiation
15309 | N_Package_Instantiation
15310 | N_Procedure_Instantiation
15312 -- Defining_Unit_Name and Name are left out because they are
15313 -- not relevant for preelaborability.
15315 Visit_List (Generic_Associations (Nod));
15317 when N_Object_Declaration =>
15319 -- Defining_Identifier is left out because it is not relevant
15320 -- for preelaborability.
15322 Visit (Object_Definition (Nod));
15324 if Has_Init_Expression (Nod) then
15325 Visit (Expression (Nod));
15327 elsif not Has_Preelaborable_Initialization
15328 (Etype (Defining_Entity (Nod)))
15329 then
15330 raise Non_Preelaborable;
15331 end if;
15333 when N_Private_Extension_Declaration
15334 | N_Subtype_Declaration
15336 -- Defining_Identifier, Discriminant_Specifications, and
15337 -- Interface_List are left out because they are not relevant
15338 -- for preelaborability.
15340 Visit (Subtype_Indication (Nod));
15342 when N_Protected_Type_Declaration
15343 | N_Single_Protected_Declaration
15345 -- Defining_Identifier, Discriminant_Specifications, and
15346 -- Interface_List are left out because they are not relevant
15347 -- for preelaborability.
15349 Visit (Protected_Definition (Nod));
15351 -- A [single] task type is never preelaborable
15353 when N_Single_Task_Declaration
15354 | N_Task_Type_Declaration
15356 raise Non_Preelaborable;
15358 -- Pragmas
15360 when N_Pragma =>
15361 Visit_Pragma (Nod);
15363 -- Statements
15365 when N_Statement_Other_Than_Procedure_Call =>
15366 if Nkind (Nod) /= N_Null_Statement then
15367 raise Non_Preelaborable;
15368 end if;
15370 -- Subexpressions
15372 when N_Subexpr =>
15373 Visit_Subexpression (Nod);
15375 -- Special
15377 when N_Access_To_Object_Definition =>
15378 Visit (Subtype_Indication (Nod));
15380 when N_Case_Expression_Alternative =>
15381 Visit (Expression (Nod));
15382 Visit_List (Discrete_Choices (Nod));
15384 when N_Component_Definition =>
15385 Visit (Access_Definition (Nod));
15386 Visit (Subtype_Indication (Nod));
15388 when N_Component_List =>
15389 Visit_List (Component_Items (Nod));
15390 Visit (Variant_Part (Nod));
15392 when N_Constrained_Array_Definition =>
15393 Visit_List (Discrete_Subtype_Definitions (Nod));
15394 Visit (Component_Definition (Nod));
15396 when N_Delta_Constraint
15397 | N_Digits_Constraint
15399 -- Delta_Expression and Digits_Expression are left out because
15400 -- they are not relevant for preelaborability.
15402 Visit (Range_Constraint (Nod));
15404 when N_Discriminant_Specification =>
15406 -- Defining_Identifier and Expression are left out because they
15407 -- are not relevant for preelaborability.
15409 Visit (Discriminant_Type (Nod));
15411 when N_Generic_Association =>
15413 -- Selector_Name is left out because it is not relevant for
15414 -- preelaborability.
15416 Visit (Explicit_Generic_Actual_Parameter (Nod));
15418 when N_Index_Or_Discriminant_Constraint =>
15419 Visit_List (Constraints (Nod));
15421 when N_Iterator_Specification =>
15423 -- Defining_Identifier is left out because it is not relevant
15424 -- for preelaborability.
15426 Visit (Name (Nod));
15427 Visit (Subtype_Indication (Nod));
15429 when N_Loop_Parameter_Specification =>
15431 -- Defining_Identifier is left out because it is not relevant
15432 -- for preelaborability.
15434 Visit (Discrete_Subtype_Definition (Nod));
15436 when N_Protected_Definition =>
15438 -- End_Label is left out because it is not relevant for
15439 -- preelaborability.
15441 Visit_List (Private_Declarations (Nod));
15442 Visit_List (Visible_Declarations (Nod));
15444 when N_Range_Constraint =>
15445 Visit (Range_Expression (Nod));
15447 when N_Record_Definition
15448 | N_Variant
15450 -- End_Label, Discrete_Choices, and Interface_List are left out
15451 -- because they are not relevant for preelaborability.
15453 Visit (Component_List (Nod));
15455 when N_Subtype_Indication =>
15457 -- Subtype_Mark is left out because it is not relevant for
15458 -- preelaborability.
15460 Visit (Constraint (Nod));
15462 when N_Unconstrained_Array_Definition =>
15464 -- Subtype_Marks is left out because it is not relevant for
15465 -- preelaborability.
15467 Visit (Component_Definition (Nod));
15469 when N_Variant_Part =>
15471 -- Name is left out because it is not relevant for
15472 -- preelaborability.
15474 Visit_List (Variants (Nod));
15476 -- Default
15478 when others =>
15479 null;
15480 end case;
15481 end Visit;
15483 ----------------
15484 -- Visit_List --
15485 ----------------
15487 procedure Visit_List (List : List_Id) is
15488 Nod : Node_Id;
15490 begin
15491 if Present (List) then
15492 Nod := First (List);
15493 while Present (Nod) loop
15494 Visit (Nod);
15495 Next (Nod);
15496 end loop;
15497 end if;
15498 end Visit_List;
15500 ------------------
15501 -- Visit_Pragma --
15502 ------------------
15504 procedure Visit_Pragma (Prag : Node_Id) is
15505 begin
15506 case Get_Pragma_Id (Prag) is
15507 when Pragma_Assert
15508 | Pragma_Assert_And_Cut
15509 | Pragma_Assume
15510 | Pragma_Async_Readers
15511 | Pragma_Async_Writers
15512 | Pragma_Attribute_Definition
15513 | Pragma_Check
15514 | Pragma_Constant_After_Elaboration
15515 | Pragma_CPU
15516 | Pragma_Deadline_Floor
15517 | Pragma_Dispatching_Domain
15518 | Pragma_Effective_Reads
15519 | Pragma_Effective_Writes
15520 | Pragma_Extensions_Visible
15521 | Pragma_Ghost
15522 | Pragma_Secondary_Stack_Size
15523 | Pragma_Task_Name
15524 | Pragma_Volatile_Function
15526 Visit_List (Pragma_Argument_Associations (Prag));
15528 -- Default
15530 when others =>
15531 null;
15532 end case;
15533 end Visit_Pragma;
15535 -------------------------
15536 -- Visit_Subexpression --
15537 -------------------------
15539 procedure Visit_Subexpression (Expr : Node_Id) is
15540 procedure Visit_Aggregate (Aggr : Node_Id);
15541 pragma Inline (Visit_Aggregate);
15542 -- Semantically inspect aggregate Aggr to determine whether it
15543 -- violates preelaborability.
15545 ---------------------
15546 -- Visit_Aggregate --
15547 ---------------------
15549 procedure Visit_Aggregate (Aggr : Node_Id) is
15550 begin
15551 if not Is_Preelaborable_Aggregate (Aggr) then
15552 raise Non_Preelaborable;
15553 end if;
15554 end Visit_Aggregate;
15556 -- Start of processing for Visit_Subexpression
15558 begin
15559 case Nkind (Expr) is
15560 when N_Allocator
15561 | N_Qualified_Expression
15562 | N_Type_Conversion
15563 | N_Unchecked_Expression
15564 | N_Unchecked_Type_Conversion
15566 -- Subpool_Handle_Name and Subtype_Mark are left out because
15567 -- they are not relevant for preelaborability.
15569 Visit (Expression (Expr));
15571 when N_Aggregate
15572 | N_Extension_Aggregate
15574 Visit_Aggregate (Expr);
15576 when N_Attribute_Reference
15577 | N_Explicit_Dereference
15578 | N_Reference
15580 -- Attribute_Name and Expressions are left out because they are
15581 -- not relevant for preelaborability.
15583 Visit (Prefix (Expr));
15585 when N_Case_Expression =>
15587 -- End_Span is left out because it is not relevant for
15588 -- preelaborability.
15590 Visit_List (Alternatives (Expr));
15591 Visit (Expression (Expr));
15593 when N_Delta_Aggregate =>
15594 Visit_Aggregate (Expr);
15595 Visit (Expression (Expr));
15597 when N_Expression_With_Actions =>
15598 Visit_List (Actions (Expr));
15599 Visit (Expression (Expr));
15601 when N_If_Expression =>
15602 Visit_List (Expressions (Expr));
15604 when N_Quantified_Expression =>
15605 Visit (Condition (Expr));
15606 Visit (Iterator_Specification (Expr));
15607 Visit (Loop_Parameter_Specification (Expr));
15609 when N_Range =>
15610 Visit (High_Bound (Expr));
15611 Visit (Low_Bound (Expr));
15613 when N_Slice =>
15614 Visit (Discrete_Range (Expr));
15615 Visit (Prefix (Expr));
15617 -- Default
15619 when others =>
15621 -- The evaluation of an object name is not preelaborable,
15622 -- unless the name is a static expression (checked further
15623 -- below), or statically denotes a discriminant.
15625 if Is_Entity_Name (Expr) then
15626 Object_Name : declare
15627 Id : constant Entity_Id := Entity (Expr);
15629 begin
15630 if Is_Object (Id) then
15631 if Ekind (Id) = E_Discriminant then
15632 null;
15634 elsif Ekind_In (Id, E_Constant, E_In_Parameter)
15635 and then Present (Discriminal_Link (Id))
15636 then
15637 null;
15639 else
15640 raise Non_Preelaborable;
15641 end if;
15642 end if;
15643 end Object_Name;
15645 -- A non-static expression is not preelaborable
15647 elsif not Is_OK_Static_Expression (Expr) then
15648 raise Non_Preelaborable;
15649 end if;
15650 end case;
15651 end Visit_Subexpression;
15653 -- Start of processing for Is_Non_Preelaborable_Construct
15655 begin
15656 Visit (N);
15658 -- At this point it is known that the construct is preelaborable
15660 return False;
15662 exception
15664 -- The elaboration of the construct performs an action which violates
15665 -- preelaborability.
15667 when Non_Preelaborable =>
15668 return True;
15669 end Is_Non_Preelaborable_Construct;
15671 ---------------------------------
15672 -- Is_Nontrivial_DIC_Procedure --
15673 ---------------------------------
15675 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
15676 Body_Decl : Node_Id;
15677 Stmt : Node_Id;
15679 begin
15680 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
15681 Body_Decl :=
15682 Unit_Declaration_Node
15683 (Corresponding_Body (Unit_Declaration_Node (Id)));
15685 -- The body of the Default_Initial_Condition procedure must contain
15686 -- at least one statement, otherwise the generation of the subprogram
15687 -- body failed.
15689 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
15691 -- To qualify as nontrivial, the first statement of the procedure
15692 -- must be a check in the form of an if statement. If the original
15693 -- Default_Initial_Condition expression was folded, then the first
15694 -- statement is not a check.
15696 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
15698 return
15699 Nkind (Stmt) = N_If_Statement
15700 and then Nkind (Original_Node (Stmt)) = N_Pragma;
15701 end if;
15703 return False;
15704 end Is_Nontrivial_DIC_Procedure;
15706 -------------------------
15707 -- Is_Null_Record_Type --
15708 -------------------------
15710 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
15711 Decl : constant Node_Id := Parent (T);
15712 begin
15713 return Nkind (Decl) = N_Full_Type_Declaration
15714 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
15715 and then
15716 (No (Component_List (Type_Definition (Decl)))
15717 or else Null_Present (Component_List (Type_Definition (Decl))));
15718 end Is_Null_Record_Type;
15720 ---------------------
15721 -- Is_Object_Image --
15722 ---------------------
15724 function Is_Object_Image (Prefix : Node_Id) return Boolean is
15725 begin
15726 -- When the type of the prefix is not scalar, then the prefix is not
15727 -- valid in any scenario.
15729 if not Is_Scalar_Type (Etype (Prefix)) then
15730 return False;
15731 end if;
15733 -- Here we test for the case that the prefix is not a type and assume
15734 -- if it is not then it must be a named value or an object reference.
15735 -- This is because the parser always checks that prefixes of attributes
15736 -- are named.
15738 return not (Is_Entity_Name (Prefix) and then Is_Type (Entity (Prefix)));
15739 end Is_Object_Image;
15741 -------------------------
15742 -- Is_Object_Reference --
15743 -------------------------
15745 function Is_Object_Reference (N : Node_Id) return Boolean is
15746 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
15747 -- Determine whether N is the name of an internally-generated renaming
15749 --------------------------------------
15750 -- Is_Internally_Generated_Renaming --
15751 --------------------------------------
15753 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
15754 P : Node_Id;
15756 begin
15757 P := N;
15758 while Present (P) loop
15759 if Nkind (P) = N_Object_Renaming_Declaration then
15760 return not Comes_From_Source (P);
15761 elsif Is_List_Member (P) then
15762 return False;
15763 end if;
15765 P := Parent (P);
15766 end loop;
15768 return False;
15769 end Is_Internally_Generated_Renaming;
15771 -- Start of processing for Is_Object_Reference
15773 begin
15774 if Is_Entity_Name (N) then
15775 return Present (Entity (N)) and then Is_Object (Entity (N));
15777 else
15778 case Nkind (N) is
15779 when N_Indexed_Component
15780 | N_Slice
15782 return
15783 Is_Object_Reference (Prefix (N))
15784 or else Is_Access_Type (Etype (Prefix (N)));
15786 -- In Ada 95, a function call is a constant object; a procedure
15787 -- call is not.
15789 -- Note that predefined operators are functions as well, and so
15790 -- are attributes that are (can be renamed as) functions.
15792 when N_Binary_Op
15793 | N_Function_Call
15794 | N_Unary_Op
15796 return Etype (N) /= Standard_Void_Type;
15798 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
15799 -- objects, even though they are not functions.
15801 when N_Attribute_Reference =>
15802 return
15803 Nam_In (Attribute_Name (N), Name_Loop_Entry,
15804 Name_Old,
15805 Name_Result)
15806 or else Is_Function_Attribute_Name (Attribute_Name (N));
15808 when N_Selected_Component =>
15809 return
15810 Is_Object_Reference (Selector_Name (N))
15811 and then
15812 (Is_Object_Reference (Prefix (N))
15813 or else Is_Access_Type (Etype (Prefix (N))));
15815 -- An explicit dereference denotes an object, except that a
15816 -- conditional expression gets turned into an explicit dereference
15817 -- in some cases, and conditional expressions are not object
15818 -- names.
15820 when N_Explicit_Dereference =>
15821 return not Nkind_In (Original_Node (N), N_Case_Expression,
15822 N_If_Expression);
15824 -- A view conversion of a tagged object is an object reference
15826 when N_Type_Conversion =>
15827 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
15828 and then Is_Tagged_Type (Etype (Expression (N)))
15829 and then Is_Object_Reference (Expression (N));
15831 -- An unchecked type conversion is considered to be an object if
15832 -- the operand is an object (this construction arises only as a
15833 -- result of expansion activities).
15835 when N_Unchecked_Type_Conversion =>
15836 return True;
15838 -- Allow string literals to act as objects as long as they appear
15839 -- in internally-generated renamings. The expansion of iterators
15840 -- may generate such renamings when the range involves a string
15841 -- literal.
15843 when N_String_Literal =>
15844 return Is_Internally_Generated_Renaming (Parent (N));
15846 -- AI05-0003: In Ada 2012 a qualified expression is a name.
15847 -- This allows disambiguation of function calls and the use
15848 -- of aggregates in more contexts.
15850 when N_Qualified_Expression =>
15851 if Ada_Version < Ada_2012 then
15852 return False;
15853 else
15854 return Is_Object_Reference (Expression (N))
15855 or else Nkind (Expression (N)) = N_Aggregate;
15856 end if;
15858 when others =>
15859 return False;
15860 end case;
15861 end if;
15862 end Is_Object_Reference;
15864 -----------------------------------
15865 -- Is_OK_Variable_For_Out_Formal --
15866 -----------------------------------
15868 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
15869 begin
15870 Note_Possible_Modification (AV, Sure => True);
15872 -- We must reject parenthesized variable names. Comes_From_Source is
15873 -- checked because there are currently cases where the compiler violates
15874 -- this rule (e.g. passing a task object to its controlled Initialize
15875 -- routine). This should be properly documented in sinfo???
15877 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
15878 return False;
15880 -- A variable is always allowed
15882 elsif Is_Variable (AV) then
15883 return True;
15885 -- Generalized indexing operations are rewritten as explicit
15886 -- dereferences, and it is only during resolution that we can
15887 -- check whether the context requires an access_to_variable type.
15889 elsif Nkind (AV) = N_Explicit_Dereference
15890 and then Ada_Version >= Ada_2012
15891 and then Nkind (Original_Node (AV)) = N_Indexed_Component
15892 and then Present (Etype (Original_Node (AV)))
15893 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
15894 then
15895 return not Is_Access_Constant (Etype (Prefix (AV)));
15897 -- Unchecked conversions are allowed only if they come from the
15898 -- generated code, which sometimes uses unchecked conversions for out
15899 -- parameters in cases where code generation is unaffected. We tell
15900 -- source unchecked conversions by seeing if they are rewrites of
15901 -- an original Unchecked_Conversion function call, or of an explicit
15902 -- conversion of a function call or an aggregate (as may happen in the
15903 -- expansion of a packed array aggregate).
15905 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
15906 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
15907 return False;
15909 elsif Comes_From_Source (AV)
15910 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
15911 then
15912 return False;
15914 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
15915 return Is_OK_Variable_For_Out_Formal (Expression (AV));
15917 else
15918 return True;
15919 end if;
15921 -- Normal type conversions are allowed if argument is a variable
15923 elsif Nkind (AV) = N_Type_Conversion then
15924 if Is_Variable (Expression (AV))
15925 and then Paren_Count (Expression (AV)) = 0
15926 then
15927 Note_Possible_Modification (Expression (AV), Sure => True);
15928 return True;
15930 -- We also allow a non-parenthesized expression that raises
15931 -- constraint error if it rewrites what used to be a variable
15933 elsif Raises_Constraint_Error (Expression (AV))
15934 and then Paren_Count (Expression (AV)) = 0
15935 and then Is_Variable (Original_Node (Expression (AV)))
15936 then
15937 return True;
15939 -- Type conversion of something other than a variable
15941 else
15942 return False;
15943 end if;
15945 -- If this node is rewritten, then test the original form, if that is
15946 -- OK, then we consider the rewritten node OK (for example, if the
15947 -- original node is a conversion, then Is_Variable will not be true
15948 -- but we still want to allow the conversion if it converts a variable).
15950 elsif Is_Rewrite_Substitution (AV) then
15952 -- In Ada 2012, the explicit dereference may be a rewritten call to a
15953 -- Reference function.
15955 if Ada_Version >= Ada_2012
15956 and then Nkind (Original_Node (AV)) = N_Function_Call
15957 and then
15958 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
15959 then
15961 -- Check that this is not a constant reference.
15963 return not Is_Access_Constant (Etype (Prefix (AV)));
15965 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
15966 return
15967 not Is_Access_Constant (Etype
15968 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
15970 else
15971 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
15972 end if;
15974 -- All other non-variables are rejected
15976 else
15977 return False;
15978 end if;
15979 end Is_OK_Variable_For_Out_Formal;
15981 ----------------------------
15982 -- Is_OK_Volatile_Context --
15983 ----------------------------
15985 function Is_OK_Volatile_Context
15986 (Context : Node_Id;
15987 Obj_Ref : Node_Id) return Boolean
15989 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
15990 -- Determine whether an arbitrary node denotes a call to a protected
15991 -- entry, function, or procedure in prefixed form where the prefix is
15992 -- Obj_Ref.
15994 function Within_Check (Nod : Node_Id) return Boolean;
15995 -- Determine whether an arbitrary node appears in a check node
15997 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
15998 -- Determine whether an arbitrary entity appears in a volatile function
16000 ---------------------------------
16001 -- Is_Protected_Operation_Call --
16002 ---------------------------------
16004 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
16005 Pref : Node_Id;
16006 Subp : Node_Id;
16008 begin
16009 -- A call to a protected operations retains its selected component
16010 -- form as opposed to other prefixed calls that are transformed in
16011 -- expanded names.
16013 if Nkind (Nod) = N_Selected_Component then
16014 Pref := Prefix (Nod);
16015 Subp := Selector_Name (Nod);
16017 return
16018 Pref = Obj_Ref
16019 and then Present (Etype (Pref))
16020 and then Is_Protected_Type (Etype (Pref))
16021 and then Is_Entity_Name (Subp)
16022 and then Present (Entity (Subp))
16023 and then Ekind_In (Entity (Subp), E_Entry,
16024 E_Entry_Family,
16025 E_Function,
16026 E_Procedure);
16027 else
16028 return False;
16029 end if;
16030 end Is_Protected_Operation_Call;
16032 ------------------
16033 -- Within_Check --
16034 ------------------
16036 function Within_Check (Nod : Node_Id) return Boolean is
16037 Par : Node_Id;
16039 begin
16040 -- Climb the parent chain looking for a check node
16042 Par := Nod;
16043 while Present (Par) loop
16044 if Nkind (Par) in N_Raise_xxx_Error then
16045 return True;
16047 -- Prevent the search from going too far
16049 elsif Is_Body_Or_Package_Declaration (Par) then
16050 exit;
16051 end if;
16053 Par := Parent (Par);
16054 end loop;
16056 return False;
16057 end Within_Check;
16059 ------------------------------
16060 -- Within_Volatile_Function --
16061 ------------------------------
16063 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
16064 Func_Id : Entity_Id;
16066 begin
16067 -- Traverse the scope stack looking for a [generic] function
16069 Func_Id := Id;
16070 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
16071 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
16072 return Is_Volatile_Function (Func_Id);
16073 end if;
16075 Func_Id := Scope (Func_Id);
16076 end loop;
16078 return False;
16079 end Within_Volatile_Function;
16081 -- Local variables
16083 Obj_Id : Entity_Id;
16085 -- Start of processing for Is_OK_Volatile_Context
16087 begin
16088 -- The volatile object appears on either side of an assignment
16090 if Nkind (Context) = N_Assignment_Statement then
16091 return True;
16093 -- The volatile object is part of the initialization expression of
16094 -- another object.
16096 elsif Nkind (Context) = N_Object_Declaration
16097 and then Present (Expression (Context))
16098 and then Expression (Context) = Obj_Ref
16099 then
16100 Obj_Id := Defining_Entity (Context);
16102 -- The volatile object acts as the initialization expression of an
16103 -- extended return statement. This is valid context as long as the
16104 -- function is volatile.
16106 if Is_Return_Object (Obj_Id) then
16107 return Within_Volatile_Function (Obj_Id);
16109 -- Otherwise this is a normal object initialization
16111 else
16112 return True;
16113 end if;
16115 -- The volatile object acts as the name of a renaming declaration
16117 elsif Nkind (Context) = N_Object_Renaming_Declaration
16118 and then Name (Context) = Obj_Ref
16119 then
16120 return True;
16122 -- The volatile object appears as an actual parameter in a call to an
16123 -- instance of Unchecked_Conversion whose result is renamed.
16125 elsif Nkind (Context) = N_Function_Call
16126 and then Is_Entity_Name (Name (Context))
16127 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
16128 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
16129 then
16130 return True;
16132 -- The volatile object is actually the prefix in a protected entry,
16133 -- function, or procedure call.
16135 elsif Is_Protected_Operation_Call (Context) then
16136 return True;
16138 -- The volatile object appears as the expression of a simple return
16139 -- statement that applies to a volatile function.
16141 elsif Nkind (Context) = N_Simple_Return_Statement
16142 and then Expression (Context) = Obj_Ref
16143 then
16144 return
16145 Within_Volatile_Function (Return_Statement_Entity (Context));
16147 -- The volatile object appears as the prefix of a name occurring in a
16148 -- non-interfering context.
16150 elsif Nkind_In (Context, N_Attribute_Reference,
16151 N_Explicit_Dereference,
16152 N_Indexed_Component,
16153 N_Selected_Component,
16154 N_Slice)
16155 and then Prefix (Context) = Obj_Ref
16156 and then Is_OK_Volatile_Context
16157 (Context => Parent (Context),
16158 Obj_Ref => Context)
16159 then
16160 return True;
16162 -- The volatile object appears as the prefix of attributes Address,
16163 -- Alignment, Component_Size, First, First_Bit, Last, Last_Bit, Length,
16164 -- Position, Size, Storage_Size.
16166 elsif Nkind (Context) = N_Attribute_Reference
16167 and then Prefix (Context) = Obj_Ref
16168 and then Nam_In (Attribute_Name (Context), Name_Address,
16169 Name_Alignment,
16170 Name_Component_Size,
16171 Name_First,
16172 Name_First_Bit,
16173 Name_Last,
16174 Name_Last_Bit,
16175 Name_Length,
16176 Name_Position,
16177 Name_Size,
16178 Name_Storage_Size)
16179 then
16180 return True;
16182 -- The volatile object appears as the expression of a type conversion
16183 -- occurring in a non-interfering context.
16185 elsif Nkind_In (Context, N_Type_Conversion,
16186 N_Unchecked_Type_Conversion)
16187 and then Expression (Context) = Obj_Ref
16188 and then Is_OK_Volatile_Context
16189 (Context => Parent (Context),
16190 Obj_Ref => Context)
16191 then
16192 return True;
16194 -- The volatile object appears as the expression in a delay statement
16196 elsif Nkind (Context) in N_Delay_Statement then
16197 return True;
16199 -- Allow references to volatile objects in various checks. This is not a
16200 -- direct SPARK 2014 requirement.
16202 elsif Within_Check (Context) then
16203 return True;
16205 -- Assume that references to effectively volatile objects that appear
16206 -- as actual parameters in a subprogram call are always legal. A full
16207 -- legality check is done when the actuals are resolved (see routine
16208 -- Resolve_Actuals).
16210 elsif Within_Subprogram_Call (Context) then
16211 return True;
16213 -- Otherwise the context is not suitable for an effectively volatile
16214 -- object.
16216 else
16217 return False;
16218 end if;
16219 end Is_OK_Volatile_Context;
16221 ------------------------------------
16222 -- Is_Package_Contract_Annotation --
16223 ------------------------------------
16225 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
16226 Nam : Name_Id;
16228 begin
16229 if Nkind (Item) = N_Aspect_Specification then
16230 Nam := Chars (Identifier (Item));
16232 else pragma Assert (Nkind (Item) = N_Pragma);
16233 Nam := Pragma_Name (Item);
16234 end if;
16236 return Nam = Name_Abstract_State
16237 or else Nam = Name_Initial_Condition
16238 or else Nam = Name_Initializes
16239 or else Nam = Name_Refined_State;
16240 end Is_Package_Contract_Annotation;
16242 -----------------------------------
16243 -- Is_Partially_Initialized_Type --
16244 -----------------------------------
16246 function Is_Partially_Initialized_Type
16247 (Typ : Entity_Id;
16248 Include_Implicit : Boolean := True) return Boolean
16250 begin
16251 if Is_Scalar_Type (Typ) then
16252 return False;
16254 elsif Is_Access_Type (Typ) then
16255 return Include_Implicit;
16257 elsif Is_Array_Type (Typ) then
16259 -- If component type is partially initialized, so is array type
16261 if Is_Partially_Initialized_Type
16262 (Component_Type (Typ), Include_Implicit)
16263 then
16264 return True;
16266 -- Otherwise we are only partially initialized if we are fully
16267 -- initialized (this is the empty array case, no point in us
16268 -- duplicating that code here).
16270 else
16271 return Is_Fully_Initialized_Type (Typ);
16272 end if;
16274 elsif Is_Record_Type (Typ) then
16276 -- A discriminated type is always partially initialized if in
16277 -- all mode
16279 if Has_Discriminants (Typ) and then Include_Implicit then
16280 return True;
16282 -- A tagged type is always partially initialized
16284 elsif Is_Tagged_Type (Typ) then
16285 return True;
16287 -- Case of non-discriminated record
16289 else
16290 declare
16291 Ent : Entity_Id;
16293 Component_Present : Boolean := False;
16294 -- Set True if at least one component is present. If no
16295 -- components are present, then record type is fully
16296 -- initialized (another odd case, like the null array).
16298 begin
16299 -- Loop through components
16301 Ent := First_Entity (Typ);
16302 while Present (Ent) loop
16303 if Ekind (Ent) = E_Component then
16304 Component_Present := True;
16306 -- If a component has an initialization expression then
16307 -- the enclosing record type is partially initialized
16309 if Present (Parent (Ent))
16310 and then Present (Expression (Parent (Ent)))
16311 then
16312 return True;
16314 -- If a component is of a type which is itself partially
16315 -- initialized, then the enclosing record type is also.
16317 elsif Is_Partially_Initialized_Type
16318 (Etype (Ent), Include_Implicit)
16319 then
16320 return True;
16321 end if;
16322 end if;
16324 Next_Entity (Ent);
16325 end loop;
16327 -- No initialized components found. If we found any components
16328 -- they were all uninitialized so the result is false.
16330 if Component_Present then
16331 return False;
16333 -- But if we found no components, then all the components are
16334 -- initialized so we consider the type to be initialized.
16336 else
16337 return True;
16338 end if;
16339 end;
16340 end if;
16342 -- Concurrent types are always fully initialized
16344 elsif Is_Concurrent_Type (Typ) then
16345 return True;
16347 -- For a private type, go to underlying type. If there is no underlying
16348 -- type then just assume this partially initialized. Not clear if this
16349 -- can happen in a non-error case, but no harm in testing for this.
16351 elsif Is_Private_Type (Typ) then
16352 declare
16353 U : constant Entity_Id := Underlying_Type (Typ);
16354 begin
16355 if No (U) then
16356 return True;
16357 else
16358 return Is_Partially_Initialized_Type (U, Include_Implicit);
16359 end if;
16360 end;
16362 -- For any other type (are there any?) assume partially initialized
16364 else
16365 return True;
16366 end if;
16367 end Is_Partially_Initialized_Type;
16369 ------------------------------------
16370 -- Is_Potentially_Persistent_Type --
16371 ------------------------------------
16373 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
16374 Comp : Entity_Id;
16375 Indx : Node_Id;
16377 begin
16378 -- For private type, test corresponding full type
16380 if Is_Private_Type (T) then
16381 return Is_Potentially_Persistent_Type (Full_View (T));
16383 -- Scalar types are potentially persistent
16385 elsif Is_Scalar_Type (T) then
16386 return True;
16388 -- Record type is potentially persistent if not tagged and the types of
16389 -- all it components are potentially persistent, and no component has
16390 -- an initialization expression.
16392 elsif Is_Record_Type (T)
16393 and then not Is_Tagged_Type (T)
16394 and then not Is_Partially_Initialized_Type (T)
16395 then
16396 Comp := First_Component (T);
16397 while Present (Comp) loop
16398 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
16399 return False;
16400 else
16401 Next_Entity (Comp);
16402 end if;
16403 end loop;
16405 return True;
16407 -- Array type is potentially persistent if its component type is
16408 -- potentially persistent and if all its constraints are static.
16410 elsif Is_Array_Type (T) then
16411 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
16412 return False;
16413 end if;
16415 Indx := First_Index (T);
16416 while Present (Indx) loop
16417 if not Is_OK_Static_Subtype (Etype (Indx)) then
16418 return False;
16419 else
16420 Next_Index (Indx);
16421 end if;
16422 end loop;
16424 return True;
16426 -- All other types are not potentially persistent
16428 else
16429 return False;
16430 end if;
16431 end Is_Potentially_Persistent_Type;
16433 --------------------------------
16434 -- Is_Potentially_Unevaluated --
16435 --------------------------------
16437 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
16438 Par : Node_Id;
16439 Expr : Node_Id;
16441 begin
16442 Expr := N;
16443 Par := N;
16445 -- A postcondition whose expression is a short-circuit is broken down
16446 -- into individual aspects for better exception reporting. The original
16447 -- short-circuit expression is rewritten as the second operand, and an
16448 -- occurrence of 'Old in that operand is potentially unevaluated.
16449 -- See sem_ch13.adb for details of this transformation. The reference
16450 -- to 'Old may appear within an expression, so we must look for the
16451 -- enclosing pragma argument in the tree that contains the reference.
16453 while Present (Par)
16454 and then Nkind (Par) /= N_Pragma_Argument_Association
16455 loop
16456 if Is_Rewrite_Substitution (Par)
16457 and then Nkind (Original_Node (Par)) = N_And_Then
16458 then
16459 return True;
16460 end if;
16462 Par := Parent (Par);
16463 end loop;
16465 -- Other cases; 'Old appears within other expression (not the top-level
16466 -- conjunct in a postcondition) with a potentially unevaluated operand.
16468 Par := Parent (Expr);
16469 while not Nkind_In (Par, N_And_Then,
16470 N_Case_Expression,
16471 N_If_Expression,
16472 N_In,
16473 N_Not_In,
16474 N_Or_Else,
16475 N_Quantified_Expression)
16476 loop
16477 Expr := Par;
16478 Par := Parent (Par);
16480 -- If the context is not an expression, or if is the result of
16481 -- expansion of an enclosing construct (such as another attribute)
16482 -- the predicate does not apply.
16484 if Nkind (Par) = N_Case_Expression_Alternative then
16485 null;
16487 elsif Nkind (Par) not in N_Subexpr
16488 or else not Comes_From_Source (Par)
16489 then
16490 return False;
16491 end if;
16492 end loop;
16494 if Nkind (Par) = N_If_Expression then
16495 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
16497 elsif Nkind (Par) = N_Case_Expression then
16498 return Expr /= Expression (Par);
16500 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
16501 return Expr = Right_Opnd (Par);
16503 elsif Nkind_In (Par, N_In, N_Not_In) then
16505 -- If the membership includes several alternatives, only the first is
16506 -- definitely evaluated.
16508 if Present (Alternatives (Par)) then
16509 return Expr /= First (Alternatives (Par));
16511 -- If this is a range membership both bounds are evaluated
16513 else
16514 return False;
16515 end if;
16517 elsif Nkind (Par) = N_Quantified_Expression then
16518 return Expr = Condition (Par);
16520 else
16521 return False;
16522 end if;
16523 end Is_Potentially_Unevaluated;
16525 -----------------------------------------
16526 -- Is_Predefined_Dispatching_Operation --
16527 -----------------------------------------
16529 function Is_Predefined_Dispatching_Operation
16530 (E : Entity_Id) return Boolean
16532 TSS_Name : TSS_Name_Type;
16534 begin
16535 if not Is_Dispatching_Operation (E) then
16536 return False;
16537 end if;
16539 Get_Name_String (Chars (E));
16541 -- Most predefined primitives have internally generated names. Equality
16542 -- must be treated differently; the predefined operation is recognized
16543 -- as a homogeneous binary operator that returns Boolean.
16545 if Name_Len > TSS_Name_Type'Last then
16546 TSS_Name :=
16547 TSS_Name_Type
16548 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16550 if Nam_In (Chars (E), Name_uAssign, Name_uSize)
16551 or else
16552 (Chars (E) = Name_Op_Eq
16553 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16554 or else TSS_Name = TSS_Deep_Adjust
16555 or else TSS_Name = TSS_Deep_Finalize
16556 or else TSS_Name = TSS_Stream_Input
16557 or else TSS_Name = TSS_Stream_Output
16558 or else TSS_Name = TSS_Stream_Read
16559 or else TSS_Name = TSS_Stream_Write
16560 or else Is_Predefined_Interface_Primitive (E)
16561 then
16562 return True;
16563 end if;
16564 end if;
16566 return False;
16567 end Is_Predefined_Dispatching_Operation;
16569 ---------------------------------------
16570 -- Is_Predefined_Interface_Primitive --
16571 ---------------------------------------
16573 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
16574 begin
16575 -- In VM targets we don't restrict the functionality of this test to
16576 -- compiling in Ada 2005 mode since in VM targets any tagged type has
16577 -- these primitives.
16579 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
16580 and then Nam_In (Chars (E), Name_uDisp_Asynchronous_Select,
16581 Name_uDisp_Conditional_Select,
16582 Name_uDisp_Get_Prim_Op_Kind,
16583 Name_uDisp_Get_Task_Id,
16584 Name_uDisp_Requeue,
16585 Name_uDisp_Timed_Select);
16586 end Is_Predefined_Interface_Primitive;
16588 ---------------------------------------
16589 -- Is_Predefined_Internal_Operation --
16590 ---------------------------------------
16592 function Is_Predefined_Internal_Operation
16593 (E : Entity_Id) return Boolean
16595 TSS_Name : TSS_Name_Type;
16597 begin
16598 if not Is_Dispatching_Operation (E) then
16599 return False;
16600 end if;
16602 Get_Name_String (Chars (E));
16604 -- Most predefined primitives have internally generated names. Equality
16605 -- must be treated differently; the predefined operation is recognized
16606 -- as a homogeneous binary operator that returns Boolean.
16608 if Name_Len > TSS_Name_Type'Last then
16609 TSS_Name :=
16610 TSS_Name_Type
16611 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
16613 if Nam_In (Chars (E), Name_uSize, Name_uAssign)
16614 or else
16615 (Chars (E) = Name_Op_Eq
16616 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
16617 or else TSS_Name = TSS_Deep_Adjust
16618 or else TSS_Name = TSS_Deep_Finalize
16619 or else Is_Predefined_Interface_Primitive (E)
16620 then
16621 return True;
16622 end if;
16623 end if;
16625 return False;
16626 end Is_Predefined_Internal_Operation;
16628 --------------------------------
16629 -- Is_Preelaborable_Aggregate --
16630 --------------------------------
16632 function Is_Preelaborable_Aggregate (Aggr : Node_Id) return Boolean is
16633 Aggr_Typ : constant Entity_Id := Etype (Aggr);
16634 Array_Aggr : constant Boolean := Is_Array_Type (Aggr_Typ);
16636 Anc_Part : Node_Id;
16637 Assoc : Node_Id;
16638 Choice : Node_Id;
16639 Comp_Typ : Entity_Id := Empty; -- init to avoid warning
16640 Expr : Node_Id;
16642 begin
16643 if Array_Aggr then
16644 Comp_Typ := Component_Type (Aggr_Typ);
16645 end if;
16647 -- Inspect the ancestor part
16649 if Nkind (Aggr) = N_Extension_Aggregate then
16650 Anc_Part := Ancestor_Part (Aggr);
16652 -- The ancestor denotes a subtype mark
16654 if Is_Entity_Name (Anc_Part)
16655 and then Is_Type (Entity (Anc_Part))
16656 then
16657 if not Has_Preelaborable_Initialization (Entity (Anc_Part)) then
16658 return False;
16659 end if;
16661 -- Otherwise the ancestor denotes an expression
16663 elsif not Is_Preelaborable_Construct (Anc_Part) then
16664 return False;
16665 end if;
16666 end if;
16668 -- Inspect the positional associations
16670 Expr := First (Expressions (Aggr));
16671 while Present (Expr) loop
16672 if not Is_Preelaborable_Construct (Expr) then
16673 return False;
16674 end if;
16676 Next (Expr);
16677 end loop;
16679 -- Inspect the named associations
16681 Assoc := First (Component_Associations (Aggr));
16682 while Present (Assoc) loop
16684 -- Inspect the choices of the current named association
16686 Choice := First (Choices (Assoc));
16687 while Present (Choice) loop
16688 if Array_Aggr then
16690 -- For a choice to be preelaborable, it must denote either a
16691 -- static range or a static expression.
16693 if Nkind (Choice) = N_Others_Choice then
16694 null;
16696 elsif Nkind (Choice) = N_Range then
16697 if not Is_OK_Static_Range (Choice) then
16698 return False;
16699 end if;
16701 elsif not Is_OK_Static_Expression (Choice) then
16702 return False;
16703 end if;
16705 else
16706 Comp_Typ := Etype (Choice);
16707 end if;
16709 Next (Choice);
16710 end loop;
16712 -- The type of the choice must have preelaborable initialization if
16713 -- the association carries a <>.
16715 pragma Assert (Present (Comp_Typ));
16716 if Box_Present (Assoc) then
16717 if not Has_Preelaborable_Initialization (Comp_Typ) then
16718 return False;
16719 end if;
16721 -- The type of the expression must have preelaborable initialization
16723 elsif not Is_Preelaborable_Construct (Expression (Assoc)) then
16724 return False;
16725 end if;
16727 Next (Assoc);
16728 end loop;
16730 -- At this point the aggregate is preelaborable
16732 return True;
16733 end Is_Preelaborable_Aggregate;
16735 --------------------------------
16736 -- Is_Preelaborable_Construct --
16737 --------------------------------
16739 function Is_Preelaborable_Construct (N : Node_Id) return Boolean is
16740 begin
16741 -- Aggregates
16743 if Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
16744 return Is_Preelaborable_Aggregate (N);
16746 -- Attributes are allowed in general, even if their prefix is a formal
16747 -- type. It seems that certain attributes known not to be static might
16748 -- not be allowed, but there are no rules to prevent them.
16750 elsif Nkind (N) = N_Attribute_Reference then
16751 return True;
16753 -- Expressions
16755 elsif Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
16756 return True;
16758 elsif Nkind (N) = N_Qualified_Expression then
16759 return Is_Preelaborable_Construct (Expression (N));
16761 -- Names are preelaborable when they denote a discriminant of an
16762 -- enclosing type. Discriminals are also considered for this check.
16764 elsif Is_Entity_Name (N)
16765 and then Present (Entity (N))
16766 and then
16767 (Ekind (Entity (N)) = E_Discriminant
16768 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
16769 and then Present (Discriminal_Link (Entity (N)))))
16770 then
16771 return True;
16773 -- Statements
16775 elsif Nkind (N) = N_Null then
16776 return True;
16778 -- Otherwise the construct is not preelaborable
16780 else
16781 return False;
16782 end if;
16783 end Is_Preelaborable_Construct;
16785 ---------------------------------
16786 -- Is_Protected_Self_Reference --
16787 ---------------------------------
16789 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
16791 function In_Access_Definition (N : Node_Id) return Boolean;
16792 -- Returns true if N belongs to an access definition
16794 --------------------------
16795 -- In_Access_Definition --
16796 --------------------------
16798 function In_Access_Definition (N : Node_Id) return Boolean is
16799 P : Node_Id;
16801 begin
16802 P := Parent (N);
16803 while Present (P) loop
16804 if Nkind (P) = N_Access_Definition then
16805 return True;
16806 end if;
16808 P := Parent (P);
16809 end loop;
16811 return False;
16812 end In_Access_Definition;
16814 -- Start of processing for Is_Protected_Self_Reference
16816 begin
16817 -- Verify that prefix is analyzed and has the proper form. Note that
16818 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
16819 -- produce the address of an entity, do not analyze their prefix
16820 -- because they denote entities that are not necessarily visible.
16821 -- Neither of them can apply to a protected type.
16823 return Ada_Version >= Ada_2005
16824 and then Is_Entity_Name (N)
16825 and then Present (Entity (N))
16826 and then Is_Protected_Type (Entity (N))
16827 and then In_Open_Scopes (Entity (N))
16828 and then not In_Access_Definition (N);
16829 end Is_Protected_Self_Reference;
16831 -----------------------------
16832 -- Is_RCI_Pkg_Spec_Or_Body --
16833 -----------------------------
16835 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
16837 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
16838 -- Return True if the unit of Cunit is an RCI package declaration
16840 ---------------------------
16841 -- Is_RCI_Pkg_Decl_Cunit --
16842 ---------------------------
16844 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
16845 The_Unit : constant Node_Id := Unit (Cunit);
16847 begin
16848 if Nkind (The_Unit) /= N_Package_Declaration then
16849 return False;
16850 end if;
16852 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
16853 end Is_RCI_Pkg_Decl_Cunit;
16855 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
16857 begin
16858 return Is_RCI_Pkg_Decl_Cunit (Cunit)
16859 or else
16860 (Nkind (Unit (Cunit)) = N_Package_Body
16861 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
16862 end Is_RCI_Pkg_Spec_Or_Body;
16864 -----------------------------------------
16865 -- Is_Remote_Access_To_Class_Wide_Type --
16866 -----------------------------------------
16868 function Is_Remote_Access_To_Class_Wide_Type
16869 (E : Entity_Id) return Boolean
16871 begin
16872 -- A remote access to class-wide type is a general access to object type
16873 -- declared in the visible part of a Remote_Types or Remote_Call_
16874 -- Interface unit.
16876 return Ekind (E) = E_General_Access_Type
16877 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16878 end Is_Remote_Access_To_Class_Wide_Type;
16880 -----------------------------------------
16881 -- Is_Remote_Access_To_Subprogram_Type --
16882 -----------------------------------------
16884 function Is_Remote_Access_To_Subprogram_Type
16885 (E : Entity_Id) return Boolean
16887 begin
16888 return (Ekind (E) = E_Access_Subprogram_Type
16889 or else (Ekind (E) = E_Record_Type
16890 and then Present (Corresponding_Remote_Type (E))))
16891 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
16892 end Is_Remote_Access_To_Subprogram_Type;
16894 --------------------
16895 -- Is_Remote_Call --
16896 --------------------
16898 function Is_Remote_Call (N : Node_Id) return Boolean is
16899 begin
16900 if Nkind (N) not in N_Subprogram_Call then
16902 -- An entry call cannot be remote
16904 return False;
16906 elsif Nkind (Name (N)) in N_Has_Entity
16907 and then Is_Remote_Call_Interface (Entity (Name (N)))
16908 then
16909 -- A subprogram declared in the spec of a RCI package is remote
16911 return True;
16913 elsif Nkind (Name (N)) = N_Explicit_Dereference
16914 and then Is_Remote_Access_To_Subprogram_Type
16915 (Etype (Prefix (Name (N))))
16916 then
16917 -- The dereference of a RAS is a remote call
16919 return True;
16921 elsif Present (Controlling_Argument (N))
16922 and then Is_Remote_Access_To_Class_Wide_Type
16923 (Etype (Controlling_Argument (N)))
16924 then
16925 -- Any primitive operation call with a controlling argument of
16926 -- a RACW type is a remote call.
16928 return True;
16929 end if;
16931 -- All other calls are local calls
16933 return False;
16934 end Is_Remote_Call;
16936 ----------------------
16937 -- Is_Renamed_Entry --
16938 ----------------------
16940 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
16941 Orig_Node : Node_Id := Empty;
16942 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
16944 function Is_Entry (Nam : Node_Id) return Boolean;
16945 -- Determine whether Nam is an entry. Traverse selectors if there are
16946 -- nested selected components.
16948 --------------
16949 -- Is_Entry --
16950 --------------
16952 function Is_Entry (Nam : Node_Id) return Boolean is
16953 begin
16954 if Nkind (Nam) = N_Selected_Component then
16955 return Is_Entry (Selector_Name (Nam));
16956 end if;
16958 return Ekind (Entity (Nam)) = E_Entry;
16959 end Is_Entry;
16961 -- Start of processing for Is_Renamed_Entry
16963 begin
16964 if Present (Alias (Proc_Nam)) then
16965 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
16966 end if;
16968 -- Look for a rewritten subprogram renaming declaration
16970 if Nkind (Subp_Decl) = N_Subprogram_Declaration
16971 and then Present (Original_Node (Subp_Decl))
16972 then
16973 Orig_Node := Original_Node (Subp_Decl);
16974 end if;
16976 -- The rewritten subprogram is actually an entry
16978 if Present (Orig_Node)
16979 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
16980 and then Is_Entry (Name (Orig_Node))
16981 then
16982 return True;
16983 end if;
16985 return False;
16986 end Is_Renamed_Entry;
16988 -----------------------------
16989 -- Is_Renaming_Declaration --
16990 -----------------------------
16992 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
16993 begin
16994 case Nkind (N) is
16995 when N_Exception_Renaming_Declaration
16996 | N_Generic_Function_Renaming_Declaration
16997 | N_Generic_Package_Renaming_Declaration
16998 | N_Generic_Procedure_Renaming_Declaration
16999 | N_Object_Renaming_Declaration
17000 | N_Package_Renaming_Declaration
17001 | N_Subprogram_Renaming_Declaration
17003 return True;
17005 when others =>
17006 return False;
17007 end case;
17008 end Is_Renaming_Declaration;
17010 ----------------------------
17011 -- Is_Reversible_Iterator --
17012 ----------------------------
17014 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
17015 Ifaces_List : Elist_Id;
17016 Iface_Elmt : Elmt_Id;
17017 Iface : Entity_Id;
17019 begin
17020 if Is_Class_Wide_Type (Typ)
17021 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
17022 and then In_Predefined_Unit (Root_Type (Typ))
17023 then
17024 return True;
17026 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
17027 return False;
17029 else
17030 Collect_Interfaces (Typ, Ifaces_List);
17032 Iface_Elmt := First_Elmt (Ifaces_List);
17033 while Present (Iface_Elmt) loop
17034 Iface := Node (Iface_Elmt);
17035 if Chars (Iface) = Name_Reversible_Iterator
17036 and then In_Predefined_Unit (Iface)
17037 then
17038 return True;
17039 end if;
17041 Next_Elmt (Iface_Elmt);
17042 end loop;
17043 end if;
17045 return False;
17046 end Is_Reversible_Iterator;
17048 ----------------------
17049 -- Is_Selector_Name --
17050 ----------------------
17052 function Is_Selector_Name (N : Node_Id) return Boolean is
17053 begin
17054 if not Is_List_Member (N) then
17055 declare
17056 P : constant Node_Id := Parent (N);
17057 begin
17058 return Nkind_In (P, N_Expanded_Name,
17059 N_Generic_Association,
17060 N_Parameter_Association,
17061 N_Selected_Component)
17062 and then Selector_Name (P) = N;
17063 end;
17065 else
17066 declare
17067 L : constant List_Id := List_Containing (N);
17068 P : constant Node_Id := Parent (L);
17069 begin
17070 return (Nkind (P) = N_Discriminant_Association
17071 and then Selector_Names (P) = L)
17072 or else
17073 (Nkind (P) = N_Component_Association
17074 and then Choices (P) = L);
17075 end;
17076 end if;
17077 end Is_Selector_Name;
17079 ---------------------------------
17080 -- Is_Single_Concurrent_Object --
17081 ---------------------------------
17083 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
17084 begin
17085 return
17086 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
17087 end Is_Single_Concurrent_Object;
17089 -------------------------------
17090 -- Is_Single_Concurrent_Type --
17091 -------------------------------
17093 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
17094 begin
17095 return
17096 Ekind_In (Id, E_Protected_Type, E_Task_Type)
17097 and then Is_Single_Concurrent_Type_Declaration
17098 (Declaration_Node (Id));
17099 end Is_Single_Concurrent_Type;
17101 -------------------------------------------
17102 -- Is_Single_Concurrent_Type_Declaration --
17103 -------------------------------------------
17105 function Is_Single_Concurrent_Type_Declaration
17106 (N : Node_Id) return Boolean
17108 begin
17109 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
17110 N_Single_Task_Declaration);
17111 end Is_Single_Concurrent_Type_Declaration;
17113 ---------------------------------------------
17114 -- Is_Single_Precision_Floating_Point_Type --
17115 ---------------------------------------------
17117 function Is_Single_Precision_Floating_Point_Type
17118 (E : Entity_Id) return Boolean is
17119 begin
17120 return Is_Floating_Point_Type (E)
17121 and then Machine_Radix_Value (E) = Uint_2
17122 and then Machine_Mantissa_Value (E) = Uint_24
17123 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
17124 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
17125 end Is_Single_Precision_Floating_Point_Type;
17127 --------------------------------
17128 -- Is_Single_Protected_Object --
17129 --------------------------------
17131 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
17132 begin
17133 return
17134 Ekind (Id) = E_Variable
17135 and then Ekind (Etype (Id)) = E_Protected_Type
17136 and then Is_Single_Concurrent_Type (Etype (Id));
17137 end Is_Single_Protected_Object;
17139 ---------------------------
17140 -- Is_Single_Task_Object --
17141 ---------------------------
17143 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
17144 begin
17145 return
17146 Ekind (Id) = E_Variable
17147 and then Ekind (Etype (Id)) = E_Task_Type
17148 and then Is_Single_Concurrent_Type (Etype (Id));
17149 end Is_Single_Task_Object;
17151 -------------------------------------
17152 -- Is_SPARK_05_Initialization_Expr --
17153 -------------------------------------
17155 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
17156 Is_Ok : Boolean;
17157 Expr : Node_Id;
17158 Comp_Assn : Node_Id;
17159 Orig_N : constant Node_Id := Original_Node (N);
17161 begin
17162 Is_Ok := True;
17164 if not Comes_From_Source (Orig_N) then
17165 goto Done;
17166 end if;
17168 pragma Assert (Nkind (Orig_N) in N_Subexpr);
17170 case Nkind (Orig_N) is
17171 when N_Character_Literal
17172 | N_Integer_Literal
17173 | N_Real_Literal
17174 | N_String_Literal
17176 null;
17178 when N_Expanded_Name
17179 | N_Identifier
17181 if Is_Entity_Name (Orig_N)
17182 and then Present (Entity (Orig_N)) -- needed in some cases
17183 then
17184 case Ekind (Entity (Orig_N)) is
17185 when E_Constant
17186 | E_Enumeration_Literal
17187 | E_Named_Integer
17188 | E_Named_Real
17190 null;
17192 when others =>
17193 if Is_Type (Entity (Orig_N)) then
17194 null;
17195 else
17196 Is_Ok := False;
17197 end if;
17198 end case;
17199 end if;
17201 when N_Qualified_Expression
17202 | N_Type_Conversion
17204 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
17206 when N_Unary_Op =>
17207 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17209 when N_Binary_Op
17210 | N_Membership_Test
17211 | N_Short_Circuit
17213 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
17214 and then
17215 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
17217 when N_Aggregate
17218 | N_Extension_Aggregate
17220 if Nkind (Orig_N) = N_Extension_Aggregate then
17221 Is_Ok :=
17222 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
17223 end if;
17225 Expr := First (Expressions (Orig_N));
17226 while Present (Expr) loop
17227 if not Is_SPARK_05_Initialization_Expr (Expr) then
17228 Is_Ok := False;
17229 goto Done;
17230 end if;
17232 Next (Expr);
17233 end loop;
17235 Comp_Assn := First (Component_Associations (Orig_N));
17236 while Present (Comp_Assn) loop
17237 Expr := Expression (Comp_Assn);
17239 -- Note: test for Present here needed for box assocation
17241 if Present (Expr)
17242 and then not Is_SPARK_05_Initialization_Expr (Expr)
17243 then
17244 Is_Ok := False;
17245 goto Done;
17246 end if;
17248 Next (Comp_Assn);
17249 end loop;
17251 when N_Attribute_Reference =>
17252 if Nkind (Prefix (Orig_N)) in N_Subexpr then
17253 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
17254 end if;
17256 Expr := First (Expressions (Orig_N));
17257 while Present (Expr) loop
17258 if not Is_SPARK_05_Initialization_Expr (Expr) then
17259 Is_Ok := False;
17260 goto Done;
17261 end if;
17263 Next (Expr);
17264 end loop;
17266 -- Selected components might be expanded named not yet resolved, so
17267 -- default on the safe side. (Eg on sparklex.ads)
17269 when N_Selected_Component =>
17270 null;
17272 when others =>
17273 Is_Ok := False;
17274 end case;
17276 <<Done>>
17277 return Is_Ok;
17278 end Is_SPARK_05_Initialization_Expr;
17280 ----------------------------------
17281 -- Is_SPARK_05_Object_Reference --
17282 ----------------------------------
17284 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
17285 begin
17286 if Is_Entity_Name (N) then
17287 return Present (Entity (N))
17288 and then
17289 (Ekind_In (Entity (N), E_Constant, E_Variable)
17290 or else Ekind (Entity (N)) in Formal_Kind);
17292 else
17293 case Nkind (N) is
17294 when N_Selected_Component =>
17295 return Is_SPARK_05_Object_Reference (Prefix (N));
17297 when others =>
17298 return False;
17299 end case;
17300 end if;
17301 end Is_SPARK_05_Object_Reference;
17303 -----------------------------
17304 -- Is_Specific_Tagged_Type --
17305 -----------------------------
17307 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
17308 Full_Typ : Entity_Id;
17310 begin
17311 -- Handle private types
17313 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
17314 Full_Typ := Full_View (Typ);
17315 else
17316 Full_Typ := Typ;
17317 end if;
17319 -- A specific tagged type is a non-class-wide tagged type
17321 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
17322 end Is_Specific_Tagged_Type;
17324 ------------------
17325 -- Is_Statement --
17326 ------------------
17328 function Is_Statement (N : Node_Id) return Boolean is
17329 begin
17330 return
17331 Nkind (N) in N_Statement_Other_Than_Procedure_Call
17332 or else Nkind (N) = N_Procedure_Call_Statement;
17333 end Is_Statement;
17335 ---------------------------------------
17336 -- Is_Subprogram_Contract_Annotation --
17337 ---------------------------------------
17339 function Is_Subprogram_Contract_Annotation
17340 (Item : Node_Id) return Boolean
17342 Nam : Name_Id;
17344 begin
17345 if Nkind (Item) = N_Aspect_Specification then
17346 Nam := Chars (Identifier (Item));
17348 else pragma Assert (Nkind (Item) = N_Pragma);
17349 Nam := Pragma_Name (Item);
17350 end if;
17352 return Nam = Name_Contract_Cases
17353 or else Nam = Name_Depends
17354 or else Nam = Name_Extensions_Visible
17355 or else Nam = Name_Global
17356 or else Nam = Name_Post
17357 or else Nam = Name_Post_Class
17358 or else Nam = Name_Postcondition
17359 or else Nam = Name_Pre
17360 or else Nam = Name_Pre_Class
17361 or else Nam = Name_Precondition
17362 or else Nam = Name_Refined_Depends
17363 or else Nam = Name_Refined_Global
17364 or else Nam = Name_Refined_Post
17365 or else Nam = Name_Test_Case;
17366 end Is_Subprogram_Contract_Annotation;
17368 --------------------------------------------------
17369 -- Is_Subprogram_Stub_Without_Prior_Declaration --
17370 --------------------------------------------------
17372 function Is_Subprogram_Stub_Without_Prior_Declaration
17373 (N : Node_Id) return Boolean
17375 begin
17376 -- A subprogram stub without prior declaration serves as declaration for
17377 -- the actual subprogram body. As such, it has an attached defining
17378 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
17380 return Nkind (N) = N_Subprogram_Body_Stub
17381 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
17382 end Is_Subprogram_Stub_Without_Prior_Declaration;
17384 ---------------------------
17385 -- Is_Suitable_Primitive --
17386 ---------------------------
17388 function Is_Suitable_Primitive (Subp_Id : Entity_Id) return Boolean is
17389 begin
17390 -- The Default_Initial_Condition and invariant procedures must not be
17391 -- treated as primitive operations even when they apply to a tagged
17392 -- type. These routines must not act as targets of dispatching calls
17393 -- because they already utilize class-wide-precondition semantics to
17394 -- handle inheritance and overriding.
17396 if Ekind (Subp_Id) = E_Procedure
17397 and then (Is_DIC_Procedure (Subp_Id)
17398 or else
17399 Is_Invariant_Procedure (Subp_Id))
17400 then
17401 return False;
17402 end if;
17404 return True;
17405 end Is_Suitable_Primitive;
17407 --------------------------
17408 -- Is_Suspension_Object --
17409 --------------------------
17411 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
17412 begin
17413 -- This approach does an exact name match rather than to rely on
17414 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
17415 -- front end at point where all auxiliary tables are locked and any
17416 -- modifications to them are treated as violations. Do not tamper with
17417 -- the tables, instead examine the Chars fields of all the scopes of Id.
17419 return
17420 Chars (Id) = Name_Suspension_Object
17421 and then Present (Scope (Id))
17422 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
17423 and then Present (Scope (Scope (Id)))
17424 and then Chars (Scope (Scope (Id))) = Name_Ada
17425 and then Present (Scope (Scope (Scope (Id))))
17426 and then Scope (Scope (Scope (Id))) = Standard_Standard;
17427 end Is_Suspension_Object;
17429 ----------------------------
17430 -- Is_Synchronized_Object --
17431 ----------------------------
17433 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
17434 Prag : Node_Id;
17436 begin
17437 if Is_Object (Id) then
17439 -- The object is synchronized if it is of a type that yields a
17440 -- synchronized object.
17442 if Yields_Synchronized_Object (Etype (Id)) then
17443 return True;
17445 -- The object is synchronized if it is atomic and Async_Writers is
17446 -- enabled.
17448 elsif Is_Atomic_Object_Entity (Id)
17449 and then Async_Writers_Enabled (Id)
17450 then
17451 return True;
17453 -- A constant is a synchronized object by default
17455 elsif Ekind (Id) = E_Constant then
17456 return True;
17458 -- A variable is a synchronized object if it is subject to pragma
17459 -- Constant_After_Elaboration.
17461 elsif Ekind (Id) = E_Variable then
17462 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
17464 return Present (Prag) and then Is_Enabled_Pragma (Prag);
17465 end if;
17466 end if;
17468 -- Otherwise the input is not an object or it does not qualify as a
17469 -- synchronized object.
17471 return False;
17472 end Is_Synchronized_Object;
17474 ---------------------------------
17475 -- Is_Synchronized_Tagged_Type --
17476 ---------------------------------
17478 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
17479 Kind : constant Entity_Kind := Ekind (Base_Type (E));
17481 begin
17482 -- A task or protected type derived from an interface is a tagged type.
17483 -- Such a tagged type is called a synchronized tagged type, as are
17484 -- synchronized interfaces and private extensions whose declaration
17485 -- includes the reserved word synchronized.
17487 return (Is_Tagged_Type (E)
17488 and then (Kind = E_Task_Type
17489 or else
17490 Kind = E_Protected_Type))
17491 or else
17492 (Is_Interface (E)
17493 and then Is_Synchronized_Interface (E))
17494 or else
17495 (Ekind (E) = E_Record_Type_With_Private
17496 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
17497 and then (Synchronized_Present (Parent (E))
17498 or else Is_Synchronized_Interface (Etype (E))));
17499 end Is_Synchronized_Tagged_Type;
17501 -----------------
17502 -- Is_Transfer --
17503 -----------------
17505 function Is_Transfer (N : Node_Id) return Boolean is
17506 Kind : constant Node_Kind := Nkind (N);
17508 begin
17509 if Kind = N_Simple_Return_Statement
17510 or else
17511 Kind = N_Extended_Return_Statement
17512 or else
17513 Kind = N_Goto_Statement
17514 or else
17515 Kind = N_Raise_Statement
17516 or else
17517 Kind = N_Requeue_Statement
17518 then
17519 return True;
17521 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
17522 and then No (Condition (N))
17523 then
17524 return True;
17526 elsif Kind = N_Procedure_Call_Statement
17527 and then Is_Entity_Name (Name (N))
17528 and then Present (Entity (Name (N)))
17529 and then No_Return (Entity (Name (N)))
17530 then
17531 return True;
17533 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
17534 return True;
17536 else
17537 return False;
17538 end if;
17539 end Is_Transfer;
17541 -------------
17542 -- Is_True --
17543 -------------
17545 function Is_True (U : Uint) return Boolean is
17546 begin
17547 return (U /= 0);
17548 end Is_True;
17550 --------------------------------------
17551 -- Is_Unchecked_Conversion_Instance --
17552 --------------------------------------
17554 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
17555 Par : Node_Id;
17557 begin
17558 -- Look for a function whose generic parent is the predefined intrinsic
17559 -- function Unchecked_Conversion, or for one that renames such an
17560 -- instance.
17562 if Ekind (Id) = E_Function then
17563 Par := Parent (Id);
17565 if Nkind (Par) = N_Function_Specification then
17566 Par := Generic_Parent (Par);
17568 if Present (Par) then
17569 return
17570 Chars (Par) = Name_Unchecked_Conversion
17571 and then Is_Intrinsic_Subprogram (Par)
17572 and then In_Predefined_Unit (Par);
17573 else
17574 return
17575 Present (Alias (Id))
17576 and then Is_Unchecked_Conversion_Instance (Alias (Id));
17577 end if;
17578 end if;
17579 end if;
17581 return False;
17582 end Is_Unchecked_Conversion_Instance;
17584 -------------------------------
17585 -- Is_Universal_Numeric_Type --
17586 -------------------------------
17588 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
17589 begin
17590 return T = Universal_Integer or else T = Universal_Real;
17591 end Is_Universal_Numeric_Type;
17593 ------------------------------
17594 -- Is_User_Defined_Equality --
17595 ------------------------------
17597 function Is_User_Defined_Equality (Id : Entity_Id) return Boolean is
17598 begin
17599 return Ekind (Id) = E_Function
17600 and then Chars (Id) = Name_Op_Eq
17601 and then Comes_From_Source (Id)
17603 -- Internally generated equalities have a full type declaration
17604 -- as their parent.
17606 and then Nkind (Parent (Id)) = N_Function_Specification;
17607 end Is_User_Defined_Equality;
17609 --------------------------------------
17610 -- Is_Validation_Variable_Reference --
17611 --------------------------------------
17613 function Is_Validation_Variable_Reference (N : Node_Id) return Boolean is
17614 Var : constant Node_Id := Unqual_Conv (N);
17615 Var_Id : Entity_Id;
17617 begin
17618 Var_Id := Empty;
17620 if Is_Entity_Name (Var) then
17621 Var_Id := Entity (Var);
17622 end if;
17624 return
17625 Present (Var_Id)
17626 and then Ekind (Var_Id) = E_Variable
17627 and then Present (Validated_Object (Var_Id));
17628 end Is_Validation_Variable_Reference;
17630 ----------------------------
17631 -- Is_Variable_Size_Array --
17632 ----------------------------
17634 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
17635 Idx : Node_Id;
17637 begin
17638 pragma Assert (Is_Array_Type (E));
17640 -- Check if some index is initialized with a non-constant value
17642 Idx := First_Index (E);
17643 while Present (Idx) loop
17644 if Nkind (Idx) = N_Range then
17645 if not Is_Constant_Bound (Low_Bound (Idx))
17646 or else not Is_Constant_Bound (High_Bound (Idx))
17647 then
17648 return True;
17649 end if;
17650 end if;
17652 Idx := Next_Index (Idx);
17653 end loop;
17655 return False;
17656 end Is_Variable_Size_Array;
17658 -----------------------------
17659 -- Is_Variable_Size_Record --
17660 -----------------------------
17662 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
17663 Comp : Entity_Id;
17664 Comp_Typ : Entity_Id;
17666 begin
17667 pragma Assert (Is_Record_Type (E));
17669 Comp := First_Entity (E);
17670 while Present (Comp) loop
17671 Comp_Typ := Etype (Comp);
17673 -- Recursive call if the record type has discriminants
17675 if Is_Record_Type (Comp_Typ)
17676 and then Has_Discriminants (Comp_Typ)
17677 and then Is_Variable_Size_Record (Comp_Typ)
17678 then
17679 return True;
17681 elsif Is_Array_Type (Comp_Typ)
17682 and then Is_Variable_Size_Array (Comp_Typ)
17683 then
17684 return True;
17685 end if;
17687 Next_Entity (Comp);
17688 end loop;
17690 return False;
17691 end Is_Variable_Size_Record;
17693 -----------------
17694 -- Is_Variable --
17695 -----------------
17697 function Is_Variable
17698 (N : Node_Id;
17699 Use_Original_Node : Boolean := True) return Boolean
17701 Orig_Node : Node_Id;
17703 function In_Protected_Function (E : Entity_Id) return Boolean;
17704 -- Within a protected function, the private components of the enclosing
17705 -- protected type are constants. A function nested within a (protected)
17706 -- procedure is not itself protected. Within the body of a protected
17707 -- function the current instance of the protected type is a constant.
17709 function Is_Variable_Prefix (P : Node_Id) return Boolean;
17710 -- Prefixes can involve implicit dereferences, in which case we must
17711 -- test for the case of a reference of a constant access type, which can
17712 -- can never be a variable.
17714 ---------------------------
17715 -- In_Protected_Function --
17716 ---------------------------
17718 function In_Protected_Function (E : Entity_Id) return Boolean is
17719 Prot : Entity_Id;
17720 S : Entity_Id;
17722 begin
17723 -- E is the current instance of a type
17725 if Is_Type (E) then
17726 Prot := E;
17728 -- E is an object
17730 else
17731 Prot := Scope (E);
17732 end if;
17734 if not Is_Protected_Type (Prot) then
17735 return False;
17737 else
17738 S := Current_Scope;
17739 while Present (S) and then S /= Prot loop
17740 if Ekind (S) = E_Function and then Scope (S) = Prot then
17741 return True;
17742 end if;
17744 S := Scope (S);
17745 end loop;
17747 return False;
17748 end if;
17749 end In_Protected_Function;
17751 ------------------------
17752 -- Is_Variable_Prefix --
17753 ------------------------
17755 function Is_Variable_Prefix (P : Node_Id) return Boolean is
17756 begin
17757 if Is_Access_Type (Etype (P)) then
17758 return not Is_Access_Constant (Root_Type (Etype (P)));
17760 -- For the case of an indexed component whose prefix has a packed
17761 -- array type, the prefix has been rewritten into a type conversion.
17762 -- Determine variable-ness from the converted expression.
17764 elsif Nkind (P) = N_Type_Conversion
17765 and then not Comes_From_Source (P)
17766 and then Is_Array_Type (Etype (P))
17767 and then Is_Packed (Etype (P))
17768 then
17769 return Is_Variable (Expression (P));
17771 else
17772 return Is_Variable (P);
17773 end if;
17774 end Is_Variable_Prefix;
17776 -- Start of processing for Is_Variable
17778 begin
17779 -- Special check, allow x'Deref(expr) as a variable
17781 if Nkind (N) = N_Attribute_Reference
17782 and then Attribute_Name (N) = Name_Deref
17783 then
17784 return True;
17785 end if;
17787 -- Check if we perform the test on the original node since this may be a
17788 -- test of syntactic categories which must not be disturbed by whatever
17789 -- rewriting might have occurred. For example, an aggregate, which is
17790 -- certainly NOT a variable, could be turned into a variable by
17791 -- expansion.
17793 if Use_Original_Node then
17794 Orig_Node := Original_Node (N);
17795 else
17796 Orig_Node := N;
17797 end if;
17799 -- Definitely OK if Assignment_OK is set. Since this is something that
17800 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
17802 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
17803 return True;
17805 -- Normally we go to the original node, but there is one exception where
17806 -- we use the rewritten node, namely when it is an explicit dereference.
17807 -- The generated code may rewrite a prefix which is an access type with
17808 -- an explicit dereference. The dereference is a variable, even though
17809 -- the original node may not be (since it could be a constant of the
17810 -- access type).
17812 -- In Ada 2005 we have a further case to consider: the prefix may be a
17813 -- function call given in prefix notation. The original node appears to
17814 -- be a selected component, but we need to examine the call.
17816 elsif Nkind (N) = N_Explicit_Dereference
17817 and then Nkind (Orig_Node) /= N_Explicit_Dereference
17818 and then Present (Etype (Orig_Node))
17819 and then Is_Access_Type (Etype (Orig_Node))
17820 then
17821 -- Note that if the prefix is an explicit dereference that does not
17822 -- come from source, we must check for a rewritten function call in
17823 -- prefixed notation before other forms of rewriting, to prevent a
17824 -- compiler crash.
17826 return
17827 (Nkind (Orig_Node) = N_Function_Call
17828 and then not Is_Access_Constant (Etype (Prefix (N))))
17829 or else
17830 Is_Variable_Prefix (Original_Node (Prefix (N)));
17832 -- in Ada 2012, the dereference may have been added for a type with
17833 -- a declared implicit dereference aspect. Check that it is not an
17834 -- access to constant.
17836 elsif Nkind (N) = N_Explicit_Dereference
17837 and then Present (Etype (Orig_Node))
17838 and then Ada_Version >= Ada_2012
17839 and then Has_Implicit_Dereference (Etype (Orig_Node))
17840 then
17841 return not Is_Access_Constant (Etype (Prefix (N)));
17843 -- A function call is never a variable
17845 elsif Nkind (N) = N_Function_Call then
17846 return False;
17848 -- All remaining checks use the original node
17850 elsif Is_Entity_Name (Orig_Node)
17851 and then Present (Entity (Orig_Node))
17852 then
17853 declare
17854 E : constant Entity_Id := Entity (Orig_Node);
17855 K : constant Entity_Kind := Ekind (E);
17857 begin
17858 if Is_Loop_Parameter (E) then
17859 return False;
17860 end if;
17862 return (K = E_Variable
17863 and then Nkind (Parent (E)) /= N_Exception_Handler)
17864 or else (K = E_Component
17865 and then not In_Protected_Function (E))
17866 or else K = E_Out_Parameter
17867 or else K = E_In_Out_Parameter
17868 or else K = E_Generic_In_Out_Parameter
17870 -- Current instance of type. If this is a protected type, check
17871 -- we are not within the body of one of its protected functions.
17873 or else (Is_Type (E)
17874 and then In_Open_Scopes (E)
17875 and then not In_Protected_Function (E))
17877 or else (Is_Incomplete_Or_Private_Type (E)
17878 and then In_Open_Scopes (Full_View (E)));
17879 end;
17881 else
17882 case Nkind (Orig_Node) is
17883 when N_Indexed_Component
17884 | N_Slice
17886 return Is_Variable_Prefix (Prefix (Orig_Node));
17888 when N_Selected_Component =>
17889 return (Is_Variable (Selector_Name (Orig_Node))
17890 and then Is_Variable_Prefix (Prefix (Orig_Node)))
17891 or else
17892 (Nkind (N) = N_Expanded_Name
17893 and then Scope (Entity (N)) = Entity (Prefix (N)));
17895 -- For an explicit dereference, the type of the prefix cannot
17896 -- be an access to constant or an access to subprogram.
17898 when N_Explicit_Dereference =>
17899 declare
17900 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
17901 begin
17902 return Is_Access_Type (Typ)
17903 and then not Is_Access_Constant (Root_Type (Typ))
17904 and then Ekind (Typ) /= E_Access_Subprogram_Type;
17905 end;
17907 -- The type conversion is the case where we do not deal with the
17908 -- context dependent special case of an actual parameter. Thus
17909 -- the type conversion is only considered a variable for the
17910 -- purposes of this routine if the target type is tagged. However,
17911 -- a type conversion is considered to be a variable if it does not
17912 -- come from source (this deals for example with the conversions
17913 -- of expressions to their actual subtypes).
17915 when N_Type_Conversion =>
17916 return Is_Variable (Expression (Orig_Node))
17917 and then
17918 (not Comes_From_Source (Orig_Node)
17919 or else
17920 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
17921 and then
17922 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
17924 -- GNAT allows an unchecked type conversion as a variable. This
17925 -- only affects the generation of internal expanded code, since
17926 -- calls to instantiations of Unchecked_Conversion are never
17927 -- considered variables (since they are function calls).
17929 when N_Unchecked_Type_Conversion =>
17930 return Is_Variable (Expression (Orig_Node));
17932 when others =>
17933 return False;
17934 end case;
17935 end if;
17936 end Is_Variable;
17938 ---------------------------
17939 -- Is_Visibly_Controlled --
17940 ---------------------------
17942 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
17943 Root : constant Entity_Id := Root_Type (T);
17944 begin
17945 return Chars (Scope (Root)) = Name_Finalization
17946 and then Chars (Scope (Scope (Root))) = Name_Ada
17947 and then Scope (Scope (Scope (Root))) = Standard_Standard;
17948 end Is_Visibly_Controlled;
17950 --------------------------
17951 -- Is_Volatile_Function --
17952 --------------------------
17954 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
17955 begin
17956 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
17958 -- A function declared within a protected type is volatile
17960 if Is_Protected_Type (Scope (Func_Id)) then
17961 return True;
17963 -- An instance of Ada.Unchecked_Conversion is a volatile function if
17964 -- either the source or the target are effectively volatile.
17966 elsif Is_Unchecked_Conversion_Instance (Func_Id)
17967 and then Has_Effectively_Volatile_Profile (Func_Id)
17968 then
17969 return True;
17971 -- Otherwise the function is treated as volatile if it is subject to
17972 -- enabled pragma Volatile_Function.
17974 else
17975 return
17976 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
17977 end if;
17978 end Is_Volatile_Function;
17980 ------------------------
17981 -- Is_Volatile_Object --
17982 ------------------------
17984 function Is_Volatile_Object (N : Node_Id) return Boolean is
17985 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
17986 -- If prefix is an implicit dereference, examine designated type
17988 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
17989 -- Determines if given object has volatile components
17991 ------------------------
17992 -- Is_Volatile_Prefix --
17993 ------------------------
17995 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
17996 Typ : constant Entity_Id := Etype (N);
17998 begin
17999 if Is_Access_Type (Typ) then
18000 declare
18001 Dtyp : constant Entity_Id := Designated_Type (Typ);
18003 begin
18004 return Is_Volatile (Dtyp)
18005 or else Has_Volatile_Components (Dtyp);
18006 end;
18008 else
18009 return Object_Has_Volatile_Components (N);
18010 end if;
18011 end Is_Volatile_Prefix;
18013 ------------------------------------
18014 -- Object_Has_Volatile_Components --
18015 ------------------------------------
18017 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
18018 Typ : constant Entity_Id := Etype (N);
18020 begin
18021 if Is_Volatile (Typ)
18022 or else Has_Volatile_Components (Typ)
18023 then
18024 return True;
18026 elsif Is_Entity_Name (N)
18027 and then (Has_Volatile_Components (Entity (N))
18028 or else Is_Volatile (Entity (N)))
18029 then
18030 return True;
18032 elsif Nkind (N) = N_Indexed_Component
18033 or else Nkind (N) = N_Selected_Component
18034 then
18035 return Is_Volatile_Prefix (Prefix (N));
18037 else
18038 return False;
18039 end if;
18040 end Object_Has_Volatile_Components;
18042 -- Start of processing for Is_Volatile_Object
18044 begin
18045 if Nkind (N) = N_Defining_Identifier then
18046 return Is_Volatile (N) or else Is_Volatile (Etype (N));
18048 elsif Nkind (N) = N_Expanded_Name then
18049 return Is_Volatile_Object (Entity (N));
18051 elsif Is_Volatile (Etype (N))
18052 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
18053 then
18054 return True;
18056 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
18057 and then Is_Volatile_Prefix (Prefix (N))
18058 then
18059 return True;
18061 elsif Nkind (N) = N_Selected_Component
18062 and then Is_Volatile (Entity (Selector_Name (N)))
18063 then
18064 return True;
18066 else
18067 return False;
18068 end if;
18069 end Is_Volatile_Object;
18071 -----------------------------
18072 -- Iterate_Call_Parameters --
18073 -----------------------------
18075 procedure Iterate_Call_Parameters (Call : Node_Id) is
18076 Actual : Node_Id := First_Actual (Call);
18077 Formal : Entity_Id := First_Formal (Get_Called_Entity (Call));
18079 begin
18080 while Present (Formal) and then Present (Actual) loop
18081 Handle_Parameter (Formal, Actual);
18083 Next_Formal (Formal);
18084 Next_Actual (Actual);
18085 end loop;
18087 pragma Assert (No (Formal));
18088 pragma Assert (No (Actual));
18089 end Iterate_Call_Parameters;
18091 ---------------------------
18092 -- Itype_Has_Declaration --
18093 ---------------------------
18095 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
18096 begin
18097 pragma Assert (Is_Itype (Id));
18098 return Present (Parent (Id))
18099 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
18100 N_Subtype_Declaration)
18101 and then Defining_Entity (Parent (Id)) = Id;
18102 end Itype_Has_Declaration;
18104 -------------------------
18105 -- Kill_Current_Values --
18106 -------------------------
18108 procedure Kill_Current_Values
18109 (Ent : Entity_Id;
18110 Last_Assignment_Only : Boolean := False)
18112 begin
18113 if Is_Assignable (Ent) then
18114 Set_Last_Assignment (Ent, Empty);
18115 end if;
18117 if Is_Object (Ent) then
18118 if not Last_Assignment_Only then
18119 Kill_Checks (Ent);
18120 Set_Current_Value (Ent, Empty);
18122 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
18123 -- for a constant. Once the constant is elaborated, its value is
18124 -- not changed, therefore the associated flags that describe the
18125 -- value should not be modified either.
18127 if Ekind (Ent) = E_Constant then
18128 null;
18130 -- Non-constant entities
18132 else
18133 if not Can_Never_Be_Null (Ent) then
18134 Set_Is_Known_Non_Null (Ent, False);
18135 end if;
18137 Set_Is_Known_Null (Ent, False);
18139 -- Reset the Is_Known_Valid flag unless the type is always
18140 -- valid. This does not apply to a loop parameter because its
18141 -- bounds are defined by the loop header and therefore always
18142 -- valid.
18144 if not Is_Known_Valid (Etype (Ent))
18145 and then Ekind (Ent) /= E_Loop_Parameter
18146 then
18147 Set_Is_Known_Valid (Ent, False);
18148 end if;
18149 end if;
18150 end if;
18151 end if;
18152 end Kill_Current_Values;
18154 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
18155 S : Entity_Id;
18157 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
18158 -- Clear current value for entity E and all entities chained to E
18160 ------------------------------------------
18161 -- Kill_Current_Values_For_Entity_Chain --
18162 ------------------------------------------
18164 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
18165 Ent : Entity_Id;
18166 begin
18167 Ent := E;
18168 while Present (Ent) loop
18169 Kill_Current_Values (Ent, Last_Assignment_Only);
18170 Next_Entity (Ent);
18171 end loop;
18172 end Kill_Current_Values_For_Entity_Chain;
18174 -- Start of processing for Kill_Current_Values
18176 begin
18177 -- Kill all saved checks, a special case of killing saved values
18179 if not Last_Assignment_Only then
18180 Kill_All_Checks;
18181 end if;
18183 -- Loop through relevant scopes, which includes the current scope and
18184 -- any parent scopes if the current scope is a block or a package.
18186 S := Current_Scope;
18187 Scope_Loop : loop
18189 -- Clear current values of all entities in current scope
18191 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
18193 -- If scope is a package, also clear current values of all private
18194 -- entities in the scope.
18196 if Is_Package_Or_Generic_Package (S)
18197 or else Is_Concurrent_Type (S)
18198 then
18199 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
18200 end if;
18202 -- If this is a not a subprogram, deal with parents
18204 if not Is_Subprogram (S) then
18205 S := Scope (S);
18206 exit Scope_Loop when S = Standard_Standard;
18207 else
18208 exit Scope_Loop;
18209 end if;
18210 end loop Scope_Loop;
18211 end Kill_Current_Values;
18213 --------------------------
18214 -- Kill_Size_Check_Code --
18215 --------------------------
18217 procedure Kill_Size_Check_Code (E : Entity_Id) is
18218 begin
18219 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
18220 and then Present (Size_Check_Code (E))
18221 then
18222 Remove (Size_Check_Code (E));
18223 Set_Size_Check_Code (E, Empty);
18224 end if;
18225 end Kill_Size_Check_Code;
18227 --------------------
18228 -- Known_Non_Null --
18229 --------------------
18231 function Known_Non_Null (N : Node_Id) return Boolean is
18232 Status : constant Null_Status_Kind := Null_Status (N);
18234 Id : Entity_Id;
18235 Op : Node_Kind;
18236 Val : Node_Id;
18238 begin
18239 -- The expression yields a non-null value ignoring simple flow analysis
18241 if Status = Is_Non_Null then
18242 return True;
18244 -- Otherwise check whether N is a reference to an entity that appears
18245 -- within a conditional construct.
18247 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18249 -- First check if we are in decisive conditional
18251 Get_Current_Value_Condition (N, Op, Val);
18253 if Known_Null (Val) then
18254 if Op = N_Op_Eq then
18255 return False;
18256 elsif Op = N_Op_Ne then
18257 return True;
18258 end if;
18259 end if;
18261 -- If OK to do replacement, test Is_Known_Non_Null flag
18263 Id := Entity (N);
18265 if OK_To_Do_Constant_Replacement (Id) then
18266 return Is_Known_Non_Null (Id);
18267 end if;
18268 end if;
18270 -- Otherwise it is not possible to determine whether N yields a non-null
18271 -- value.
18273 return False;
18274 end Known_Non_Null;
18276 ----------------
18277 -- Known_Null --
18278 ----------------
18280 function Known_Null (N : Node_Id) return Boolean is
18281 Status : constant Null_Status_Kind := Null_Status (N);
18283 Id : Entity_Id;
18284 Op : Node_Kind;
18285 Val : Node_Id;
18287 begin
18288 -- The expression yields a null value ignoring simple flow analysis
18290 if Status = Is_Null then
18291 return True;
18293 -- Otherwise check whether N is a reference to an entity that appears
18294 -- within a conditional construct.
18296 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
18298 -- First check if we are in decisive conditional
18300 Get_Current_Value_Condition (N, Op, Val);
18302 if Known_Null (Val) then
18303 if Op = N_Op_Eq then
18304 return True;
18305 elsif Op = N_Op_Ne then
18306 return False;
18307 end if;
18308 end if;
18310 -- If OK to do replacement, test Is_Known_Null flag
18312 Id := Entity (N);
18314 if OK_To_Do_Constant_Replacement (Id) then
18315 return Is_Known_Null (Id);
18316 end if;
18317 end if;
18319 -- Otherwise it is not possible to determine whether N yields a null
18320 -- value.
18322 return False;
18323 end Known_Null;
18325 --------------------------
18326 -- Known_To_Be_Assigned --
18327 --------------------------
18329 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
18330 P : constant Node_Id := Parent (N);
18332 begin
18333 case Nkind (P) is
18335 -- Test left side of assignment
18337 when N_Assignment_Statement =>
18338 return N = Name (P);
18340 -- Function call arguments are never lvalues
18342 when N_Function_Call =>
18343 return False;
18345 -- Positional parameter for procedure or accept call
18347 when N_Accept_Statement
18348 | N_Procedure_Call_Statement
18350 declare
18351 Proc : Entity_Id;
18352 Form : Entity_Id;
18353 Act : Node_Id;
18355 begin
18356 Proc := Get_Subprogram_Entity (P);
18358 if No (Proc) then
18359 return False;
18360 end if;
18362 -- If we are not a list member, something is strange, so
18363 -- be conservative and return False.
18365 if not Is_List_Member (N) then
18366 return False;
18367 end if;
18369 -- We are going to find the right formal by stepping forward
18370 -- through the formals, as we step backwards in the actuals.
18372 Form := First_Formal (Proc);
18373 Act := N;
18374 loop
18375 -- If no formal, something is weird, so be conservative
18376 -- and return False.
18378 if No (Form) then
18379 return False;
18380 end if;
18382 Prev (Act);
18383 exit when No (Act);
18384 Next_Formal (Form);
18385 end loop;
18387 return Ekind (Form) /= E_In_Parameter;
18388 end;
18390 -- Named parameter for procedure or accept call
18392 when N_Parameter_Association =>
18393 declare
18394 Proc : Entity_Id;
18395 Form : Entity_Id;
18397 begin
18398 Proc := Get_Subprogram_Entity (Parent (P));
18400 if No (Proc) then
18401 return False;
18402 end if;
18404 -- Loop through formals to find the one that matches
18406 Form := First_Formal (Proc);
18407 loop
18408 -- If no matching formal, that's peculiar, some kind of
18409 -- previous error, so return False to be conservative.
18410 -- Actually this also happens in legal code in the case
18411 -- where P is a parameter association for an Extra_Formal???
18413 if No (Form) then
18414 return False;
18415 end if;
18417 -- Else test for match
18419 if Chars (Form) = Chars (Selector_Name (P)) then
18420 return Ekind (Form) /= E_In_Parameter;
18421 end if;
18423 Next_Formal (Form);
18424 end loop;
18425 end;
18427 -- Test for appearing in a conversion that itself appears
18428 -- in an lvalue context, since this should be an lvalue.
18430 when N_Type_Conversion =>
18431 return Known_To_Be_Assigned (P);
18433 -- All other references are definitely not known to be modifications
18435 when others =>
18436 return False;
18437 end case;
18438 end Known_To_Be_Assigned;
18440 ---------------------------
18441 -- Last_Source_Statement --
18442 ---------------------------
18444 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
18445 N : Node_Id;
18447 begin
18448 N := Last (Statements (HSS));
18449 while Present (N) loop
18450 exit when Comes_From_Source (N);
18451 Prev (N);
18452 end loop;
18454 return N;
18455 end Last_Source_Statement;
18457 -----------------------
18458 -- Mark_Coextensions --
18459 -----------------------
18461 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
18462 Is_Dynamic : Boolean;
18463 -- Indicates whether the context causes nested coextensions to be
18464 -- dynamic or static
18466 function Mark_Allocator (N : Node_Id) return Traverse_Result;
18467 -- Recognize an allocator node and label it as a dynamic coextension
18469 --------------------
18470 -- Mark_Allocator --
18471 --------------------
18473 function Mark_Allocator (N : Node_Id) return Traverse_Result is
18474 begin
18475 if Nkind (N) = N_Allocator then
18476 if Is_Dynamic then
18477 Set_Is_Static_Coextension (N, False);
18478 Set_Is_Dynamic_Coextension (N);
18480 -- If the allocator expression is potentially dynamic, it may
18481 -- be expanded out of order and require dynamic allocation
18482 -- anyway, so we treat the coextension itself as dynamic.
18483 -- Potential optimization ???
18485 elsif Nkind (Expression (N)) = N_Qualified_Expression
18486 and then Nkind (Expression (Expression (N))) = N_Op_Concat
18487 then
18488 Set_Is_Static_Coextension (N, False);
18489 Set_Is_Dynamic_Coextension (N);
18490 else
18491 Set_Is_Dynamic_Coextension (N, False);
18492 Set_Is_Static_Coextension (N);
18493 end if;
18494 end if;
18496 return OK;
18497 end Mark_Allocator;
18499 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
18501 -- Start of processing for Mark_Coextensions
18503 begin
18504 -- An allocator that appears on the right-hand side of an assignment is
18505 -- treated as a potentially dynamic coextension when the right-hand side
18506 -- is an allocator or a qualified expression.
18508 -- Obj := new ...'(new Coextension ...);
18510 if Nkind (Context_Nod) = N_Assignment_Statement then
18511 Is_Dynamic :=
18512 Nkind_In (Expression (Context_Nod), N_Allocator,
18513 N_Qualified_Expression);
18515 -- An allocator that appears within the expression of a simple return
18516 -- statement is treated as a potentially dynamic coextension when the
18517 -- expression is either aggregate, allocator, or qualified expression.
18519 -- return (new Coextension ...);
18520 -- return new ...'(new Coextension ...);
18522 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
18523 Is_Dynamic :=
18524 Nkind_In (Expression (Context_Nod), N_Aggregate,
18525 N_Allocator,
18526 N_Qualified_Expression);
18528 -- An alloctor that appears within the initialization expression of an
18529 -- object declaration is considered a potentially dynamic coextension
18530 -- when the initialization expression is an allocator or a qualified
18531 -- expression.
18533 -- Obj : ... := new ...'(new Coextension ...);
18535 -- A similar case arises when the object declaration is part of an
18536 -- extended return statement.
18538 -- return Obj : ... := new ...'(new Coextension ...);
18539 -- return Obj : ... := (new Coextension ...);
18541 elsif Nkind (Context_Nod) = N_Object_Declaration then
18542 Is_Dynamic :=
18543 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
18544 or else
18545 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
18547 -- This routine should not be called with constructs that cannot contain
18548 -- coextensions.
18550 else
18551 raise Program_Error;
18552 end if;
18554 Mark_Allocators (Root_Nod);
18555 end Mark_Coextensions;
18557 ---------------------------------
18558 -- Mark_Elaboration_Attributes --
18559 ---------------------------------
18561 procedure Mark_Elaboration_Attributes
18562 (N_Id : Node_Or_Entity_Id;
18563 Checks : Boolean := False;
18564 Level : Boolean := False;
18565 Modes : Boolean := False;
18566 Warnings : Boolean := False)
18568 function Elaboration_Checks_OK
18569 (Target_Id : Entity_Id;
18570 Context_Id : Entity_Id) return Boolean;
18571 -- Determine whether elaboration checks are enabled for target Target_Id
18572 -- which resides within context Context_Id.
18574 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id);
18575 -- Preserve relevant attributes of the context in arbitrary entity Id
18577 procedure Mark_Elaboration_Attributes_Node (N : Node_Id);
18578 -- Preserve relevant attributes of the context in arbitrary node N
18580 ---------------------------
18581 -- Elaboration_Checks_OK --
18582 ---------------------------
18584 function Elaboration_Checks_OK
18585 (Target_Id : Entity_Id;
18586 Context_Id : Entity_Id) return Boolean
18588 Encl_Scop : Entity_Id;
18590 begin
18591 -- Elaboration checks are suppressed for the target
18593 if Elaboration_Checks_Suppressed (Target_Id) then
18594 return False;
18595 end if;
18597 -- Otherwise elaboration checks are OK for the target, but may be
18598 -- suppressed for the context where the target is declared.
18600 Encl_Scop := Context_Id;
18601 while Present (Encl_Scop) and then Encl_Scop /= Standard_Standard loop
18602 if Elaboration_Checks_Suppressed (Encl_Scop) then
18603 return False;
18604 end if;
18606 Encl_Scop := Scope (Encl_Scop);
18607 end loop;
18609 -- Neither the target nor its declarative context have elaboration
18610 -- checks suppressed.
18612 return True;
18613 end Elaboration_Checks_OK;
18615 ------------------------------------
18616 -- Mark_Elaboration_Attributes_Id --
18617 ------------------------------------
18619 procedure Mark_Elaboration_Attributes_Id (Id : Entity_Id) is
18620 begin
18621 -- Mark the status of elaboration checks in effect. Do not reset the
18622 -- status in case the entity is reanalyzed with checks suppressed.
18624 if Checks and then not Is_Elaboration_Checks_OK_Id (Id) then
18625 Set_Is_Elaboration_Checks_OK_Id (Id,
18626 Elaboration_Checks_OK
18627 (Target_Id => Id,
18628 Context_Id => Scope (Id)));
18629 end if;
18631 -- Mark the status of elaboration warnings in effect. Do not reset
18632 -- the status in case the entity is reanalyzed with warnings off.
18634 if Warnings and then not Is_Elaboration_Warnings_OK_Id (Id) then
18635 Set_Is_Elaboration_Warnings_OK_Id (Id, Elab_Warnings);
18636 end if;
18637 end Mark_Elaboration_Attributes_Id;
18639 --------------------------------------
18640 -- Mark_Elaboration_Attributes_Node --
18641 --------------------------------------
18643 procedure Mark_Elaboration_Attributes_Node (N : Node_Id) is
18644 function Extract_Name (N : Node_Id) return Node_Id;
18645 -- Obtain the Name attribute of call or instantiation N
18647 ------------------
18648 -- Extract_Name --
18649 ------------------
18651 function Extract_Name (N : Node_Id) return Node_Id is
18652 Nam : Node_Id;
18654 begin
18655 Nam := Name (N);
18657 -- A call to an entry family appears in indexed form
18659 if Nkind (Nam) = N_Indexed_Component then
18660 Nam := Prefix (Nam);
18661 end if;
18663 -- The name may also appear in qualified form
18665 if Nkind (Nam) = N_Selected_Component then
18666 Nam := Selector_Name (Nam);
18667 end if;
18669 return Nam;
18670 end Extract_Name;
18672 -- Local variables
18674 Context_Id : Entity_Id;
18675 Nam : Node_Id;
18677 -- Start of processing for Mark_Elaboration_Attributes_Node
18679 begin
18680 -- Mark the status of elaboration checks in effect. Do not reset the
18681 -- status in case the node is reanalyzed with checks suppressed.
18683 if Checks and then not Is_Elaboration_Checks_OK_Node (N) then
18685 -- Assignments, attribute references, and variable references do
18686 -- not have a "declarative" context.
18688 Context_Id := Empty;
18690 -- The status of elaboration checks for calls and instantiations
18691 -- depends on the most recent pragma Suppress/Unsuppress, as well
18692 -- as the suppression status of the context where the target is
18693 -- defined.
18695 -- package Pack is
18696 -- function Func ...;
18697 -- end Pack;
18699 -- with Pack;
18700 -- procedure Main is
18701 -- pragma Suppress (Elaboration_Checks, Pack);
18702 -- X : ... := Pack.Func;
18703 -- ...
18705 -- In the example above, the call to Func has elaboration checks
18706 -- enabled because there is no active general purpose suppression
18707 -- pragma, however the elaboration checks of Pack are explicitly
18708 -- suppressed. As a result the elaboration checks of the call must
18709 -- be disabled in order to preserve this dependency.
18711 if Nkind_In (N, N_Entry_Call_Statement,
18712 N_Function_Call,
18713 N_Function_Instantiation,
18714 N_Package_Instantiation,
18715 N_Procedure_Call_Statement,
18716 N_Procedure_Instantiation)
18717 then
18718 Nam := Extract_Name (N);
18720 if Is_Entity_Name (Nam) and then Present (Entity (Nam)) then
18721 Context_Id := Scope (Entity (Nam));
18722 end if;
18723 end if;
18725 Set_Is_Elaboration_Checks_OK_Node (N,
18726 Elaboration_Checks_OK
18727 (Target_Id => Empty,
18728 Context_Id => Context_Id));
18729 end if;
18731 -- Mark the enclosing level of the node. Do not reset the status in
18732 -- case the node is relocated and reanalyzed.
18734 if Level and then not Is_Declaration_Level_Node (N) then
18735 Set_Is_Declaration_Level_Node (N,
18736 Find_Enclosing_Level (N) = Declaration_Level);
18737 end if;
18739 -- Mark the Ghost and SPARK mode in effect
18741 if Modes then
18742 if Ghost_Mode = Ignore then
18743 Set_Is_Ignored_Ghost_Node (N);
18744 end if;
18746 if SPARK_Mode = On then
18747 Set_Is_SPARK_Mode_On_Node (N);
18748 end if;
18749 end if;
18751 -- Mark the status of elaboration warnings in effect. Do not reset
18752 -- the status in case the node is reanalyzed with warnings off.
18754 if Warnings and then not Is_Elaboration_Warnings_OK_Node (N) then
18755 Set_Is_Elaboration_Warnings_OK_Node (N, Elab_Warnings);
18756 end if;
18757 end Mark_Elaboration_Attributes_Node;
18759 -- Start of processing for Mark_Elaboration_Attributes
18761 begin
18762 -- Do not capture any elaboration-related attributes when switch -gnatH
18763 -- (legacy elaboration checking mode enabled) is in effect because the
18764 -- attributes are useless to the legacy model.
18766 if Legacy_Elaboration_Checks then
18767 return;
18768 end if;
18770 if Nkind (N_Id) in N_Entity then
18771 Mark_Elaboration_Attributes_Id (N_Id);
18772 else
18773 Mark_Elaboration_Attributes_Node (N_Id);
18774 end if;
18775 end Mark_Elaboration_Attributes;
18777 ----------------------------------
18778 -- Matching_Static_Array_Bounds --
18779 ----------------------------------
18781 function Matching_Static_Array_Bounds
18782 (L_Typ : Node_Id;
18783 R_Typ : Node_Id) return Boolean
18785 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
18786 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
18788 L_Index : Node_Id := Empty; -- init to ...
18789 R_Index : Node_Id := Empty; -- ...avoid warnings
18790 L_Low : Node_Id;
18791 L_High : Node_Id;
18792 L_Len : Uint;
18793 R_Low : Node_Id;
18794 R_High : Node_Id;
18795 R_Len : Uint;
18797 begin
18798 if L_Ndims /= R_Ndims then
18799 return False;
18800 end if;
18802 -- Unconstrained types do not have static bounds
18804 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
18805 return False;
18806 end if;
18808 -- First treat specially the first dimension, as the lower bound and
18809 -- length of string literals are not stored like those of arrays.
18811 if Ekind (L_Typ) = E_String_Literal_Subtype then
18812 L_Low := String_Literal_Low_Bound (L_Typ);
18813 L_Len := String_Literal_Length (L_Typ);
18814 else
18815 L_Index := First_Index (L_Typ);
18816 Get_Index_Bounds (L_Index, L_Low, L_High);
18818 if Is_OK_Static_Expression (L_Low)
18819 and then
18820 Is_OK_Static_Expression (L_High)
18821 then
18822 if Expr_Value (L_High) < Expr_Value (L_Low) then
18823 L_Len := Uint_0;
18824 else
18825 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
18826 end if;
18827 else
18828 return False;
18829 end if;
18830 end if;
18832 if Ekind (R_Typ) = E_String_Literal_Subtype then
18833 R_Low := String_Literal_Low_Bound (R_Typ);
18834 R_Len := String_Literal_Length (R_Typ);
18835 else
18836 R_Index := First_Index (R_Typ);
18837 Get_Index_Bounds (R_Index, R_Low, R_High);
18839 if Is_OK_Static_Expression (R_Low)
18840 and then
18841 Is_OK_Static_Expression (R_High)
18842 then
18843 if Expr_Value (R_High) < Expr_Value (R_Low) then
18844 R_Len := Uint_0;
18845 else
18846 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
18847 end if;
18848 else
18849 return False;
18850 end if;
18851 end if;
18853 if (Is_OK_Static_Expression (L_Low)
18854 and then
18855 Is_OK_Static_Expression (R_Low))
18856 and then Expr_Value (L_Low) = Expr_Value (R_Low)
18857 and then L_Len = R_Len
18858 then
18859 null;
18860 else
18861 return False;
18862 end if;
18864 -- Then treat all other dimensions
18866 for Indx in 2 .. L_Ndims loop
18867 Next (L_Index);
18868 Next (R_Index);
18870 Get_Index_Bounds (L_Index, L_Low, L_High);
18871 Get_Index_Bounds (R_Index, R_Low, R_High);
18873 if (Is_OK_Static_Expression (L_Low) and then
18874 Is_OK_Static_Expression (L_High) and then
18875 Is_OK_Static_Expression (R_Low) and then
18876 Is_OK_Static_Expression (R_High))
18877 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
18878 and then
18879 Expr_Value (L_High) = Expr_Value (R_High))
18880 then
18881 null;
18882 else
18883 return False;
18884 end if;
18885 end loop;
18887 -- If we fall through the loop, all indexes matched
18889 return True;
18890 end Matching_Static_Array_Bounds;
18892 -------------------
18893 -- May_Be_Lvalue --
18894 -------------------
18896 function May_Be_Lvalue (N : Node_Id) return Boolean is
18897 P : constant Node_Id := Parent (N);
18899 begin
18900 case Nkind (P) is
18902 -- Test left side of assignment
18904 when N_Assignment_Statement =>
18905 return N = Name (P);
18907 -- Test prefix of component or attribute. Note that the prefix of an
18908 -- explicit or implicit dereference cannot be an l-value. In the case
18909 -- of a 'Read attribute, the reference can be an actual in the
18910 -- argument list of the attribute.
18912 when N_Attribute_Reference =>
18913 return (N = Prefix (P)
18914 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
18915 or else
18916 Attribute_Name (P) = Name_Read;
18918 -- For an expanded name, the name is an lvalue if the expanded name
18919 -- is an lvalue, but the prefix is never an lvalue, since it is just
18920 -- the scope where the name is found.
18922 when N_Expanded_Name =>
18923 if N = Prefix (P) then
18924 return May_Be_Lvalue (P);
18925 else
18926 return False;
18927 end if;
18929 -- For a selected component A.B, A is certainly an lvalue if A.B is.
18930 -- B is a little interesting, if we have A.B := 3, there is some
18931 -- discussion as to whether B is an lvalue or not, we choose to say
18932 -- it is. Note however that A is not an lvalue if it is of an access
18933 -- type since this is an implicit dereference.
18935 when N_Selected_Component =>
18936 if N = Prefix (P)
18937 and then Present (Etype (N))
18938 and then Is_Access_Type (Etype (N))
18939 then
18940 return False;
18941 else
18942 return May_Be_Lvalue (P);
18943 end if;
18945 -- For an indexed component or slice, the index or slice bounds is
18946 -- never an lvalue. The prefix is an lvalue if the indexed component
18947 -- or slice is an lvalue, except if it is an access type, where we
18948 -- have an implicit dereference.
18950 when N_Indexed_Component
18951 | N_Slice
18953 if N /= Prefix (P)
18954 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
18955 then
18956 return False;
18957 else
18958 return May_Be_Lvalue (P);
18959 end if;
18961 -- Prefix of a reference is an lvalue if the reference is an lvalue
18963 when N_Reference =>
18964 return May_Be_Lvalue (P);
18966 -- Prefix of explicit dereference is never an lvalue
18968 when N_Explicit_Dereference =>
18969 return False;
18971 -- Positional parameter for subprogram, entry, or accept call.
18972 -- In older versions of Ada function call arguments are never
18973 -- lvalues. In Ada 2012 functions can have in-out parameters.
18975 when N_Accept_Statement
18976 | N_Entry_Call_Statement
18977 | N_Subprogram_Call
18979 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
18980 return False;
18981 end if;
18983 -- The following mechanism is clumsy and fragile. A single flag
18984 -- set in Resolve_Actuals would be preferable ???
18986 declare
18987 Proc : Entity_Id;
18988 Form : Entity_Id;
18989 Act : Node_Id;
18991 begin
18992 Proc := Get_Subprogram_Entity (P);
18994 if No (Proc) then
18995 return True;
18996 end if;
18998 -- If we are not a list member, something is strange, so be
18999 -- conservative and return True.
19001 if not Is_List_Member (N) then
19002 return True;
19003 end if;
19005 -- We are going to find the right formal by stepping forward
19006 -- through the formals, as we step backwards in the actuals.
19008 Form := First_Formal (Proc);
19009 Act := N;
19010 loop
19011 -- If no formal, something is weird, so be conservative and
19012 -- return True.
19014 if No (Form) then
19015 return True;
19016 end if;
19018 Prev (Act);
19019 exit when No (Act);
19020 Next_Formal (Form);
19021 end loop;
19023 return Ekind (Form) /= E_In_Parameter;
19024 end;
19026 -- Named parameter for procedure or accept call
19028 when N_Parameter_Association =>
19029 declare
19030 Proc : Entity_Id;
19031 Form : Entity_Id;
19033 begin
19034 Proc := Get_Subprogram_Entity (Parent (P));
19036 if No (Proc) then
19037 return True;
19038 end if;
19040 -- Loop through formals to find the one that matches
19042 Form := First_Formal (Proc);
19043 loop
19044 -- If no matching formal, that's peculiar, some kind of
19045 -- previous error, so return True to be conservative.
19046 -- Actually happens with legal code for an unresolved call
19047 -- where we may get the wrong homonym???
19049 if No (Form) then
19050 return True;
19051 end if;
19053 -- Else test for match
19055 if Chars (Form) = Chars (Selector_Name (P)) then
19056 return Ekind (Form) /= E_In_Parameter;
19057 end if;
19059 Next_Formal (Form);
19060 end loop;
19061 end;
19063 -- Test for appearing in a conversion that itself appears in an
19064 -- lvalue context, since this should be an lvalue.
19066 when N_Type_Conversion =>
19067 return May_Be_Lvalue (P);
19069 -- Test for appearance in object renaming declaration
19071 when N_Object_Renaming_Declaration =>
19072 return True;
19074 -- All other references are definitely not lvalues
19076 when others =>
19077 return False;
19078 end case;
19079 end May_Be_Lvalue;
19081 -----------------
19082 -- Might_Raise --
19083 -----------------
19085 function Might_Raise (N : Node_Id) return Boolean is
19086 Result : Boolean := False;
19088 function Process (N : Node_Id) return Traverse_Result;
19089 -- Set Result to True if we find something that could raise an exception
19091 -------------
19092 -- Process --
19093 -------------
19095 function Process (N : Node_Id) return Traverse_Result is
19096 begin
19097 if Nkind_In (N, N_Procedure_Call_Statement,
19098 N_Function_Call,
19099 N_Raise_Statement,
19100 N_Raise_Constraint_Error,
19101 N_Raise_Program_Error,
19102 N_Raise_Storage_Error)
19103 then
19104 Result := True;
19105 return Abandon;
19106 else
19107 return OK;
19108 end if;
19109 end Process;
19111 procedure Set_Result is new Traverse_Proc (Process);
19113 -- Start of processing for Might_Raise
19115 begin
19116 -- False if exceptions can't be propagated
19118 if No_Exception_Handlers_Set then
19119 return False;
19120 end if;
19122 -- If the checks handled by the back end are not disabled, we cannot
19123 -- ensure that no exception will be raised.
19125 if not Access_Checks_Suppressed (Empty)
19126 or else not Discriminant_Checks_Suppressed (Empty)
19127 or else not Range_Checks_Suppressed (Empty)
19128 or else not Index_Checks_Suppressed (Empty)
19129 or else Opt.Stack_Checking_Enabled
19130 then
19131 return True;
19132 end if;
19134 Set_Result (N);
19135 return Result;
19136 end Might_Raise;
19138 --------------------------------
19139 -- Nearest_Enclosing_Instance --
19140 --------------------------------
19142 function Nearest_Enclosing_Instance (E : Entity_Id) return Entity_Id is
19143 Inst : Entity_Id;
19145 begin
19146 Inst := Scope (E);
19147 while Present (Inst) and then Inst /= Standard_Standard loop
19148 if Is_Generic_Instance (Inst) then
19149 return Inst;
19150 end if;
19152 Inst := Scope (Inst);
19153 end loop;
19155 return Empty;
19156 end Nearest_Enclosing_Instance;
19158 ----------------------
19159 -- Needs_One_Actual --
19160 ----------------------
19162 function Needs_One_Actual (E : Entity_Id) return Boolean is
19163 Formal : Entity_Id;
19165 begin
19166 -- Ada 2005 or later, and formals present. The first formal must be
19167 -- of a type that supports prefix notation: a controlling argument,
19168 -- a class-wide type, or an access to such.
19170 if Ada_Version >= Ada_2005
19171 and then Present (First_Formal (E))
19172 and then No (Default_Value (First_Formal (E)))
19173 and then
19174 (Is_Controlling_Formal (First_Formal (E))
19175 or else Is_Class_Wide_Type (Etype (First_Formal (E)))
19176 or else Is_Anonymous_Access_Type (Etype (First_Formal (E))))
19177 then
19178 Formal := Next_Formal (First_Formal (E));
19179 while Present (Formal) loop
19180 if No (Default_Value (Formal)) then
19181 return False;
19182 end if;
19184 Next_Formal (Formal);
19185 end loop;
19187 return True;
19189 -- Ada 83/95 or no formals
19191 else
19192 return False;
19193 end if;
19194 end Needs_One_Actual;
19196 ---------------------------------
19197 -- Needs_Simple_Initialization --
19198 ---------------------------------
19200 function Needs_Simple_Initialization
19201 (Typ : Entity_Id;
19202 Consider_IS : Boolean := True) return Boolean
19204 Consider_IS_NS : constant Boolean :=
19205 Normalize_Scalars or (Initialize_Scalars and Consider_IS);
19207 begin
19208 -- Never need initialization if it is suppressed
19210 if Initialization_Suppressed (Typ) then
19211 return False;
19212 end if;
19214 -- Check for private type, in which case test applies to the underlying
19215 -- type of the private type.
19217 if Is_Private_Type (Typ) then
19218 declare
19219 RT : constant Entity_Id := Underlying_Type (Typ);
19220 begin
19221 if Present (RT) then
19222 return Needs_Simple_Initialization (RT);
19223 else
19224 return False;
19225 end if;
19226 end;
19228 -- Scalar type with Default_Value aspect requires initialization
19230 elsif Is_Scalar_Type (Typ) and then Has_Default_Aspect (Typ) then
19231 return True;
19233 -- Cases needing simple initialization are access types, and, if pragma
19234 -- Normalize_Scalars or Initialize_Scalars is in effect, then all scalar
19235 -- types.
19237 elsif Is_Access_Type (Typ)
19238 or else (Consider_IS_NS and then (Is_Scalar_Type (Typ)))
19239 then
19240 return True;
19242 -- If Initialize/Normalize_Scalars is in effect, string objects also
19243 -- need initialization, unless they are created in the course of
19244 -- expanding an aggregate (since in the latter case they will be
19245 -- filled with appropriate initializing values before they are used).
19247 elsif Consider_IS_NS
19248 and then Is_Standard_String_Type (Typ)
19249 and then
19250 (not Is_Itype (Typ)
19251 or else Nkind (Associated_Node_For_Itype (Typ)) /= N_Aggregate)
19252 then
19253 return True;
19255 else
19256 return False;
19257 end if;
19258 end Needs_Simple_Initialization;
19260 -------------------------------------
19261 -- Needs_Variable_Reference_Marker --
19262 -------------------------------------
19264 function Needs_Variable_Reference_Marker
19265 (N : Node_Id;
19266 Calls_OK : Boolean) return Boolean
19268 function Within_Suitable_Context (Ref : Node_Id) return Boolean;
19269 -- Deteremine whether variable reference Ref appears within a suitable
19270 -- context that allows the creation of a marker.
19272 -----------------------------
19273 -- Within_Suitable_Context --
19274 -----------------------------
19276 function Within_Suitable_Context (Ref : Node_Id) return Boolean is
19277 Par : Node_Id;
19279 begin
19280 Par := Ref;
19281 while Present (Par) loop
19283 -- The context is not suitable when the reference appears within
19284 -- the formal part of an instantiation which acts as compilation
19285 -- unit because there is no proper list for the insertion of the
19286 -- marker.
19288 if Nkind (Par) = N_Generic_Association
19289 and then Nkind (Parent (Par)) in N_Generic_Instantiation
19290 and then Nkind (Parent (Parent (Par))) = N_Compilation_Unit
19291 then
19292 return False;
19294 -- The context is not suitable when the reference appears within
19295 -- a pragma. If the pragma has run-time semantics, the reference
19296 -- will be reconsidered once the pragma is expanded.
19298 elsif Nkind (Par) = N_Pragma then
19299 return False;
19301 -- The context is not suitable when the reference appears within a
19302 -- subprogram call, and the caller requests this behavior.
19304 elsif not Calls_OK
19305 and then Nkind_In (Par, N_Entry_Call_Statement,
19306 N_Function_Call,
19307 N_Procedure_Call_Statement)
19308 then
19309 return False;
19311 -- Prevent the search from going too far
19313 elsif Is_Body_Or_Package_Declaration (Par) then
19314 exit;
19315 end if;
19317 Par := Parent (Par);
19318 end loop;
19320 return True;
19321 end Within_Suitable_Context;
19323 -- Local variables
19325 Prag : Node_Id;
19326 Var_Id : Entity_Id;
19328 -- Start of processing for Needs_Variable_Reference_Marker
19330 begin
19331 -- No marker needs to be created when switch -gnatH (legacy elaboration
19332 -- checking mode enabled) is in effect because the legacy ABE mechanism
19333 -- does not use markers.
19335 if Legacy_Elaboration_Checks then
19336 return False;
19338 -- No marker needs to be created for ASIS because ABE diagnostics and
19339 -- checks are not performed in this mode.
19341 elsif ASIS_Mode then
19342 return False;
19344 -- No marker needs to be created when the reference is preanalyzed
19345 -- because the marker will be inserted in the wrong place.
19347 elsif Preanalysis_Active then
19348 return False;
19350 -- Only references warrant a marker
19352 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
19353 return False;
19355 -- Only source references warrant a marker
19357 elsif not Comes_From_Source (N) then
19358 return False;
19360 -- No marker needs to be created when the reference is erroneous, left
19361 -- in a bad state, or does not denote a variable.
19363 elsif not (Present (Entity (N))
19364 and then Ekind (Entity (N)) = E_Variable
19365 and then Entity (N) /= Any_Id)
19366 then
19367 return False;
19368 end if;
19370 Var_Id := Entity (N);
19371 Prag := SPARK_Pragma (Var_Id);
19373 -- Both the variable and reference must appear in SPARK_Mode On regions
19374 -- because this elaboration scenario falls under the SPARK rules.
19376 if not (Comes_From_Source (Var_Id)
19377 and then Present (Prag)
19378 and then Get_SPARK_Mode_From_Annotation (Prag) = On
19379 and then Is_SPARK_Mode_On_Node (N))
19380 then
19381 return False;
19383 -- No marker needs to be created when the reference does not appear
19384 -- within a suitable context (see body for details).
19386 -- Performance note: parent traversal
19388 elsif not Within_Suitable_Context (N) then
19389 return False;
19390 end if;
19392 -- At this point it is known that the variable reference will play a
19393 -- role in ABE diagnostics and requires a marker.
19395 return True;
19396 end Needs_Variable_Reference_Marker;
19398 ------------------------
19399 -- New_Copy_List_Tree --
19400 ------------------------
19402 function New_Copy_List_Tree (List : List_Id) return List_Id is
19403 NL : List_Id;
19404 E : Node_Id;
19406 begin
19407 if List = No_List then
19408 return No_List;
19410 else
19411 NL := New_List;
19412 E := First (List);
19414 while Present (E) loop
19415 Append (New_Copy_Tree (E), NL);
19416 E := Next (E);
19417 end loop;
19419 return NL;
19420 end if;
19421 end New_Copy_List_Tree;
19423 -------------------
19424 -- New_Copy_Tree --
19425 -------------------
19427 -- The following tables play a key role in replicating entities and Itypes.
19428 -- They are intentionally declared at the library level rather than within
19429 -- New_Copy_Tree to avoid elaborating them on each call. This performance
19430 -- optimization saves up to 2% of the entire compilation time spent in the
19431 -- front end. Care should be taken to reset the tables on each new call to
19432 -- New_Copy_Tree.
19434 NCT_Table_Max : constant := 511;
19436 subtype NCT_Table_Index is Nat range 0 .. NCT_Table_Max - 1;
19438 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index;
19439 -- Obtain the hash value of node or entity Key
19441 --------------------
19442 -- NCT_Table_Hash --
19443 --------------------
19445 function NCT_Table_Hash (Key : Node_Or_Entity_Id) return NCT_Table_Index is
19446 begin
19447 return NCT_Table_Index (Key mod NCT_Table_Max);
19448 end NCT_Table_Hash;
19450 ----------------------
19451 -- NCT_New_Entities --
19452 ----------------------
19454 -- The following table maps old entities and Itypes to their corresponding
19455 -- new entities and Itypes.
19457 -- Aaa -> Xxx
19459 package NCT_New_Entities is new Simple_HTable (
19460 Header_Num => NCT_Table_Index,
19461 Element => Entity_Id,
19462 No_Element => Empty,
19463 Key => Entity_Id,
19464 Hash => NCT_Table_Hash,
19465 Equal => "=");
19467 ------------------------
19468 -- NCT_Pending_Itypes --
19469 ------------------------
19471 -- The following table maps old Associated_Node_For_Itype nodes to a set of
19472 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
19473 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
19474 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
19476 -- Ppp -> (Xxx, Yyy, Zzz)
19478 -- The set is expressed as an Elist
19480 package NCT_Pending_Itypes is new Simple_HTable (
19481 Header_Num => NCT_Table_Index,
19482 Element => Elist_Id,
19483 No_Element => No_Elist,
19484 Key => Node_Id,
19485 Hash => NCT_Table_Hash,
19486 Equal => "=");
19488 NCT_Tables_In_Use : Boolean := False;
19489 -- This flag keeps track of whether the two tables NCT_New_Entities and
19490 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
19491 -- where certain operations are not performed if the tables are not in
19492 -- use. This saves up to 8% of the entire compilation time spent in the
19493 -- front end.
19495 -------------------
19496 -- New_Copy_Tree --
19497 -------------------
19499 function New_Copy_Tree
19500 (Source : Node_Id;
19501 Map : Elist_Id := No_Elist;
19502 New_Sloc : Source_Ptr := No_Location;
19503 New_Scope : Entity_Id := Empty) return Node_Id
19505 -- This routine performs low-level tree manipulations and needs access
19506 -- to the internals of the tree.
19508 use Atree.Unchecked_Access;
19509 use Atree_Private_Part;
19511 EWA_Level : Nat := 0;
19512 -- This counter keeps track of how many N_Expression_With_Actions nodes
19513 -- are encountered during a depth-first traversal of the subtree. These
19514 -- nodes may define new entities in their Actions lists and thus require
19515 -- special processing.
19517 EWA_Inner_Scope_Level : Nat := 0;
19518 -- This counter keeps track of how many scoping constructs appear within
19519 -- an N_Expression_With_Actions node.
19521 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id);
19522 pragma Inline (Add_New_Entity);
19523 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
19524 -- value New_Id. Old_Id is an entity which appears within the Actions
19525 -- list of an N_Expression_With_Actions node, or within an entity map.
19526 -- New_Id is the corresponding new entity generated during Phase 1.
19528 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id);
19529 pragma Inline (Add_New_Entity);
19530 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
19531 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
19532 -- an itype.
19534 procedure Build_NCT_Tables (Entity_Map : Elist_Id);
19535 pragma Inline (Build_NCT_Tables);
19536 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
19537 -- information supplied in entity map Entity_Map. The format of the
19538 -- entity map must be as follows:
19540 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19542 function Copy_Any_Node_With_Replacement
19543 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id;
19544 pragma Inline (Copy_Any_Node_With_Replacement);
19545 -- Replicate entity or node N by invoking one of the following routines:
19547 -- Copy_Node_With_Replacement
19548 -- Corresponding_Entity
19550 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id;
19551 -- Replicate the elements of entity list List
19553 function Copy_Field_With_Replacement
19554 (Field : Union_Id;
19555 Old_Par : Node_Id := Empty;
19556 New_Par : Node_Id := Empty;
19557 Semantic : Boolean := False) return Union_Id;
19558 -- Replicate field Field by invoking one of the following routines:
19560 -- Copy_Elist_With_Replacement
19561 -- Copy_List_With_Replacement
19562 -- Copy_Node_With_Replacement
19563 -- Corresponding_Entity
19565 -- If the field is not an entity list, entity, itype, syntactic list,
19566 -- or node, then the field is returned unchanged. The routine always
19567 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
19568 -- the expected parent of a syntactic field. New_Par is the new parent
19569 -- associated with a replicated syntactic field. Flag Semantic should
19570 -- be set when the input is a semantic field.
19572 function Copy_List_With_Replacement (List : List_Id) return List_Id;
19573 -- Replicate the elements of syntactic list List
19575 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id;
19576 -- Replicate node N
19578 function Corresponding_Entity (Id : Entity_Id) return Entity_Id;
19579 pragma Inline (Corresponding_Entity);
19580 -- Return the corresponding new entity of Id generated during Phase 1.
19581 -- If there is no such entity, return Id.
19583 function In_Entity_Map
19584 (Id : Entity_Id;
19585 Entity_Map : Elist_Id) return Boolean;
19586 pragma Inline (In_Entity_Map);
19587 -- Determine whether entity Id is one of the old ids specified in entity
19588 -- map Entity_Map. The format of the entity map must be as follows:
19590 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19592 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id);
19593 pragma Inline (Update_CFS_Sloc);
19594 -- Update the Comes_From_Source and Sloc attributes of node or entity N
19596 procedure Update_First_Real_Statement
19597 (Old_HSS : Node_Id;
19598 New_HSS : Node_Id);
19599 pragma Inline (Update_First_Real_Statement);
19600 -- Update semantic attribute First_Real_Statement of handled sequence of
19601 -- statements New_HSS based on handled sequence of statements Old_HSS.
19603 procedure Update_Named_Associations
19604 (Old_Call : Node_Id;
19605 New_Call : Node_Id);
19606 pragma Inline (Update_Named_Associations);
19607 -- Update semantic chain First/Next_Named_Association of call New_call
19608 -- based on call Old_Call.
19610 procedure Update_New_Entities (Entity_Map : Elist_Id);
19611 pragma Inline (Update_New_Entities);
19612 -- Update the semantic attributes of all new entities generated during
19613 -- Phase 1 that do not appear in entity map Entity_Map. The format of
19614 -- the entity map must be as follows:
19616 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
19618 procedure Update_Pending_Itypes
19619 (Old_Assoc : Node_Id;
19620 New_Assoc : Node_Id);
19621 pragma Inline (Update_Pending_Itypes);
19622 -- Update semantic attribute Associated_Node_For_Itype to refer to node
19623 -- New_Assoc for all itypes whose associated node is Old_Assoc.
19625 procedure Update_Semantic_Fields (Id : Entity_Id);
19626 pragma Inline (Update_Semantic_Fields);
19627 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
19628 -- or itype Id.
19630 procedure Visit_Any_Node (N : Node_Or_Entity_Id);
19631 pragma Inline (Visit_Any_Node);
19632 -- Visit entity of node N by invoking one of the following routines:
19634 -- Visit_Entity
19635 -- Visit_Itype
19636 -- Visit_Node
19638 procedure Visit_Elist (List : Elist_Id);
19639 -- Visit the elements of entity list List
19641 procedure Visit_Entity (Id : Entity_Id);
19642 -- Visit entity Id. This action may create a new entity of Id and save
19643 -- it in table NCT_New_Entities.
19645 procedure Visit_Field
19646 (Field : Union_Id;
19647 Par_Nod : Node_Id := Empty;
19648 Semantic : Boolean := False);
19649 -- Visit field Field by invoking one of the following routines:
19651 -- Visit_Elist
19652 -- Visit_Entity
19653 -- Visit_Itype
19654 -- Visit_List
19655 -- Visit_Node
19657 -- If the field is not an entity list, entity, itype, syntactic list,
19658 -- or node, then the field is not visited. The routine always visits
19659 -- valid syntactic fields. Par_Nod is the expected parent of the
19660 -- syntactic field. Flag Semantic should be set when the input is a
19661 -- semantic field.
19663 procedure Visit_Itype (Itype : Entity_Id);
19664 -- Visit itype Itype. This action may create a new entity for Itype and
19665 -- save it in table NCT_New_Entities. In addition, the routine may map
19666 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
19668 procedure Visit_List (List : List_Id);
19669 -- Visit the elements of syntactic list List
19671 procedure Visit_Node (N : Node_Id);
19672 -- Visit node N
19674 procedure Visit_Semantic_Fields (Id : Entity_Id);
19675 pragma Inline (Visit_Semantic_Fields);
19676 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
19677 -- fields of entity or itype Id.
19679 --------------------
19680 -- Add_New_Entity --
19681 --------------------
19683 procedure Add_New_Entity (Old_Id : Entity_Id; New_Id : Entity_Id) is
19684 begin
19685 pragma Assert (Present (Old_Id));
19686 pragma Assert (Present (New_Id));
19687 pragma Assert (Nkind (Old_Id) in N_Entity);
19688 pragma Assert (Nkind (New_Id) in N_Entity);
19690 NCT_Tables_In_Use := True;
19692 -- Sanity check the NCT_New_Entities table. No previous mapping with
19693 -- key Old_Id should exist.
19695 pragma Assert (No (NCT_New_Entities.Get (Old_Id)));
19697 -- Establish the mapping
19699 -- Old_Id -> New_Id
19701 NCT_New_Entities.Set (Old_Id, New_Id);
19702 end Add_New_Entity;
19704 -----------------------
19705 -- Add_Pending_Itype --
19706 -----------------------
19708 procedure Add_Pending_Itype (Assoc_Nod : Node_Id; Itype : Entity_Id) is
19709 Itypes : Elist_Id;
19711 begin
19712 pragma Assert (Present (Assoc_Nod));
19713 pragma Assert (Present (Itype));
19714 pragma Assert (Nkind (Itype) in N_Entity);
19715 pragma Assert (Is_Itype (Itype));
19717 NCT_Tables_In_Use := True;
19719 -- It is not possible to sanity check the NCT_Pendint_Itypes table
19720 -- directly because a single node may act as the associated node for
19721 -- multiple itypes.
19723 Itypes := NCT_Pending_Itypes.Get (Assoc_Nod);
19725 if No (Itypes) then
19726 Itypes := New_Elmt_List;
19727 NCT_Pending_Itypes.Set (Assoc_Nod, Itypes);
19728 end if;
19730 -- Establish the mapping
19732 -- Assoc_Nod -> (Itype, ...)
19734 -- Avoid inserting the same itype multiple times. This involves a
19735 -- linear search, however the set of itypes with the same associated
19736 -- node is very small.
19738 Append_Unique_Elmt (Itype, Itypes);
19739 end Add_Pending_Itype;
19741 ----------------------
19742 -- Build_NCT_Tables --
19743 ----------------------
19745 procedure Build_NCT_Tables (Entity_Map : Elist_Id) is
19746 Elmt : Elmt_Id;
19747 Old_Id : Entity_Id;
19748 New_Id : Entity_Id;
19750 begin
19751 -- Nothing to do when there is no entity map
19753 if No (Entity_Map) then
19754 return;
19755 end if;
19757 Elmt := First_Elmt (Entity_Map);
19758 while Present (Elmt) loop
19760 -- Extract the (Old_Id, New_Id) pair from the entity map
19762 Old_Id := Node (Elmt);
19763 Next_Elmt (Elmt);
19765 New_Id := Node (Elmt);
19766 Next_Elmt (Elmt);
19768 -- Establish the following mapping within table NCT_New_Entities
19770 -- Old_Id -> New_Id
19772 Add_New_Entity (Old_Id, New_Id);
19774 -- Establish the following mapping within table NCT_Pending_Itypes
19775 -- when the new entity is an itype.
19777 -- Assoc_Nod -> (New_Id, ...)
19779 -- IMPORTANT: the associated node is that of the old itype because
19780 -- the node will be replicated in Phase 2.
19782 if Is_Itype (Old_Id) then
19783 Add_Pending_Itype
19784 (Assoc_Nod => Associated_Node_For_Itype (Old_Id),
19785 Itype => New_Id);
19786 end if;
19787 end loop;
19788 end Build_NCT_Tables;
19790 ------------------------------------
19791 -- Copy_Any_Node_With_Replacement --
19792 ------------------------------------
19794 function Copy_Any_Node_With_Replacement
19795 (N : Node_Or_Entity_Id) return Node_Or_Entity_Id
19797 begin
19798 if Nkind (N) in N_Entity then
19799 return Corresponding_Entity (N);
19800 else
19801 return Copy_Node_With_Replacement (N);
19802 end if;
19803 end Copy_Any_Node_With_Replacement;
19805 ---------------------------------
19806 -- Copy_Elist_With_Replacement --
19807 ---------------------------------
19809 function Copy_Elist_With_Replacement (List : Elist_Id) return Elist_Id is
19810 Elmt : Elmt_Id;
19811 Result : Elist_Id;
19813 begin
19814 -- Copy the contents of the old list. Note that the list itself may
19815 -- be empty, in which case the routine returns a new empty list. This
19816 -- avoids sharing lists between subtrees. The element of an entity
19817 -- list could be an entity or a node, hence the invocation of routine
19818 -- Copy_Any_Node_With_Replacement.
19820 if Present (List) then
19821 Result := New_Elmt_List;
19823 Elmt := First_Elmt (List);
19824 while Present (Elmt) loop
19825 Append_Elmt
19826 (Copy_Any_Node_With_Replacement (Node (Elmt)), Result);
19828 Next_Elmt (Elmt);
19829 end loop;
19831 -- Otherwise the list does not exist
19833 else
19834 Result := No_Elist;
19835 end if;
19837 return Result;
19838 end Copy_Elist_With_Replacement;
19840 ---------------------------------
19841 -- Copy_Field_With_Replacement --
19842 ---------------------------------
19844 function Copy_Field_With_Replacement
19845 (Field : Union_Id;
19846 Old_Par : Node_Id := Empty;
19847 New_Par : Node_Id := Empty;
19848 Semantic : Boolean := False) return Union_Id
19850 begin
19851 -- The field is empty
19853 if Field = Union_Id (Empty) then
19854 return Field;
19856 -- The field is an entity/itype/node
19858 elsif Field in Node_Range then
19859 declare
19860 Old_N : constant Node_Id := Node_Id (Field);
19861 Syntactic : constant Boolean := Parent (Old_N) = Old_Par;
19863 New_N : Node_Id;
19865 begin
19866 -- The field is an entity/itype
19868 if Nkind (Old_N) in N_Entity then
19870 -- An entity/itype is always replicated
19872 New_N := Corresponding_Entity (Old_N);
19874 -- Update the parent pointer when the entity is a syntactic
19875 -- field. Note that itypes do not have parent pointers.
19877 if Syntactic and then New_N /= Old_N then
19878 Set_Parent (New_N, New_Par);
19879 end if;
19881 -- The field is a node
19883 else
19884 -- A node is replicated when it is either a syntactic field
19885 -- or when the caller treats it as a semantic attribute.
19887 if Syntactic or else Semantic then
19888 New_N := Copy_Node_With_Replacement (Old_N);
19890 -- Update the parent pointer when the node is a syntactic
19891 -- field.
19893 if Syntactic and then New_N /= Old_N then
19894 Set_Parent (New_N, New_Par);
19895 end if;
19897 -- Otherwise the node is returned unchanged
19899 else
19900 New_N := Old_N;
19901 end if;
19902 end if;
19904 return Union_Id (New_N);
19905 end;
19907 -- The field is an entity list
19909 elsif Field in Elist_Range then
19910 return Union_Id (Copy_Elist_With_Replacement (Elist_Id (Field)));
19912 -- The field is a syntactic list
19914 elsif Field in List_Range then
19915 declare
19916 Old_List : constant List_Id := List_Id (Field);
19917 Syntactic : constant Boolean := Parent (Old_List) = Old_Par;
19919 New_List : List_Id;
19921 begin
19922 -- A list is replicated when it is either a syntactic field or
19923 -- when the caller treats it as a semantic attribute.
19925 if Syntactic or else Semantic then
19926 New_List := Copy_List_With_Replacement (Old_List);
19928 -- Update the parent pointer when the list is a syntactic
19929 -- field.
19931 if Syntactic and then New_List /= Old_List then
19932 Set_Parent (New_List, New_Par);
19933 end if;
19935 -- Otherwise the list is returned unchanged
19937 else
19938 New_List := Old_List;
19939 end if;
19941 return Union_Id (New_List);
19942 end;
19944 -- Otherwise the field denotes an attribute that does not need to be
19945 -- replicated (Chars, literals, etc).
19947 else
19948 return Field;
19949 end if;
19950 end Copy_Field_With_Replacement;
19952 --------------------------------
19953 -- Copy_List_With_Replacement --
19954 --------------------------------
19956 function Copy_List_With_Replacement (List : List_Id) return List_Id is
19957 Elmt : Node_Id;
19958 Result : List_Id;
19960 begin
19961 -- Copy the contents of the old list. Note that the list itself may
19962 -- be empty, in which case the routine returns a new empty list. This
19963 -- avoids sharing lists between subtrees. The element of a syntactic
19964 -- list is always a node, never an entity or itype, hence the call to
19965 -- routine Copy_Node_With_Replacement.
19967 if Present (List) then
19968 Result := New_List;
19970 Elmt := First (List);
19971 while Present (Elmt) loop
19972 Append (Copy_Node_With_Replacement (Elmt), Result);
19974 Next (Elmt);
19975 end loop;
19977 -- Otherwise the list does not exist
19979 else
19980 Result := No_List;
19981 end if;
19983 return Result;
19984 end Copy_List_With_Replacement;
19986 --------------------------------
19987 -- Copy_Node_With_Replacement --
19988 --------------------------------
19990 function Copy_Node_With_Replacement (N : Node_Id) return Node_Id is
19991 Result : Node_Id;
19993 begin
19994 -- Assume that the node must be returned unchanged
19996 Result := N;
19998 if N > Empty_Or_Error then
19999 pragma Assert (Nkind (N) not in N_Entity);
20001 Result := New_Copy (N);
20003 Set_Field1 (Result,
20004 Copy_Field_With_Replacement
20005 (Field => Field1 (Result),
20006 Old_Par => N,
20007 New_Par => Result));
20009 Set_Field2 (Result,
20010 Copy_Field_With_Replacement
20011 (Field => Field2 (Result),
20012 Old_Par => N,
20013 New_Par => Result));
20015 Set_Field3 (Result,
20016 Copy_Field_With_Replacement
20017 (Field => Field3 (Result),
20018 Old_Par => N,
20019 New_Par => Result));
20021 Set_Field4 (Result,
20022 Copy_Field_With_Replacement
20023 (Field => Field4 (Result),
20024 Old_Par => N,
20025 New_Par => Result));
20027 Set_Field5 (Result,
20028 Copy_Field_With_Replacement
20029 (Field => Field5 (Result),
20030 Old_Par => N,
20031 New_Par => Result));
20033 -- Update the Comes_From_Source and Sloc attributes of the node
20034 -- in case the caller has supplied new values.
20036 Update_CFS_Sloc (Result);
20038 -- Update the Associated_Node_For_Itype attribute of all itypes
20039 -- created during Phase 1 whose associated node is N. As a result
20040 -- the Associated_Node_For_Itype refers to the replicated node.
20041 -- No action needs to be taken when the Associated_Node_For_Itype
20042 -- refers to an entity because this was already handled during
20043 -- Phase 1, in Visit_Itype.
20045 Update_Pending_Itypes
20046 (Old_Assoc => N,
20047 New_Assoc => Result);
20049 -- Update the First/Next_Named_Association chain for a replicated
20050 -- call.
20052 if Nkind_In (N, N_Entry_Call_Statement,
20053 N_Function_Call,
20054 N_Procedure_Call_Statement)
20055 then
20056 Update_Named_Associations
20057 (Old_Call => N,
20058 New_Call => Result);
20060 -- Update the Renamed_Object attribute of a replicated object
20061 -- declaration.
20063 elsif Nkind (N) = N_Object_Renaming_Declaration then
20064 Set_Renamed_Object (Defining_Entity (Result), Name (Result));
20066 -- Update the First_Real_Statement attribute of a replicated
20067 -- handled sequence of statements.
20069 elsif Nkind (N) = N_Handled_Sequence_Of_Statements then
20070 Update_First_Real_Statement
20071 (Old_HSS => N,
20072 New_HSS => Result);
20073 end if;
20074 end if;
20076 return Result;
20077 end Copy_Node_With_Replacement;
20079 --------------------------
20080 -- Corresponding_Entity --
20081 --------------------------
20083 function Corresponding_Entity (Id : Entity_Id) return Entity_Id is
20084 New_Id : Entity_Id;
20085 Result : Entity_Id;
20087 begin
20088 -- Assume that the entity must be returned unchanged
20090 Result := Id;
20092 if Id > Empty_Or_Error then
20093 pragma Assert (Nkind (Id) in N_Entity);
20095 -- Determine whether the entity has a corresponding new entity
20096 -- generated during Phase 1 and if it does, use it.
20098 if NCT_Tables_In_Use then
20099 New_Id := NCT_New_Entities.Get (Id);
20101 if Present (New_Id) then
20102 Result := New_Id;
20103 end if;
20104 end if;
20105 end if;
20107 return Result;
20108 end Corresponding_Entity;
20110 -------------------
20111 -- In_Entity_Map --
20112 -------------------
20114 function In_Entity_Map
20115 (Id : Entity_Id;
20116 Entity_Map : Elist_Id) return Boolean
20118 Elmt : Elmt_Id;
20119 Old_Id : Entity_Id;
20121 begin
20122 -- The entity map contains pairs (Old_Id, New_Id). The advancement
20123 -- step always skips the New_Id portion of the pair.
20125 if Present (Entity_Map) then
20126 Elmt := First_Elmt (Entity_Map);
20127 while Present (Elmt) loop
20128 Old_Id := Node (Elmt);
20130 if Old_Id = Id then
20131 return True;
20132 end if;
20134 Next_Elmt (Elmt);
20135 Next_Elmt (Elmt);
20136 end loop;
20137 end if;
20139 return False;
20140 end In_Entity_Map;
20142 ---------------------
20143 -- Update_CFS_Sloc --
20144 ---------------------
20146 procedure Update_CFS_Sloc (N : Node_Or_Entity_Id) is
20147 begin
20148 -- A new source location defaults the Comes_From_Source attribute
20150 if New_Sloc /= No_Location then
20151 Set_Comes_From_Source (N, Default_Node.Comes_From_Source);
20152 Set_Sloc (N, New_Sloc);
20153 end if;
20154 end Update_CFS_Sloc;
20156 ---------------------------------
20157 -- Update_First_Real_Statement --
20158 ---------------------------------
20160 procedure Update_First_Real_Statement
20161 (Old_HSS : Node_Id;
20162 New_HSS : Node_Id)
20164 Old_First_Stmt : constant Node_Id := First_Real_Statement (Old_HSS);
20166 New_Stmt : Node_Id;
20167 Old_Stmt : Node_Id;
20169 begin
20170 -- Recreate the First_Real_Statement attribute of a handled sequence
20171 -- of statements by traversing the statement lists of both sequences
20172 -- in parallel.
20174 if Present (Old_First_Stmt) then
20175 New_Stmt := First (Statements (New_HSS));
20176 Old_Stmt := First (Statements (Old_HSS));
20177 while Present (Old_Stmt) and then Old_Stmt /= Old_First_Stmt loop
20178 Next (New_Stmt);
20179 Next (Old_Stmt);
20180 end loop;
20182 pragma Assert (Present (New_Stmt));
20183 pragma Assert (Present (Old_Stmt));
20185 Set_First_Real_Statement (New_HSS, New_Stmt);
20186 end if;
20187 end Update_First_Real_Statement;
20189 -------------------------------
20190 -- Update_Named_Associations --
20191 -------------------------------
20193 procedure Update_Named_Associations
20194 (Old_Call : Node_Id;
20195 New_Call : Node_Id)
20197 New_Act : Node_Id;
20198 New_Next : Node_Id;
20199 Old_Act : Node_Id;
20200 Old_Next : Node_Id;
20202 begin
20203 -- Recreate the First/Next_Named_Actual chain of a call by traversing
20204 -- the chains of both the old and new calls in parallel.
20206 New_Act := First (Parameter_Associations (New_Call));
20207 Old_Act := First (Parameter_Associations (Old_Call));
20208 while Present (Old_Act) loop
20209 if Nkind (Old_Act) = N_Parameter_Association
20210 and then Present (Next_Named_Actual (Old_Act))
20211 then
20212 if First_Named_Actual (Old_Call) =
20213 Explicit_Actual_Parameter (Old_Act)
20214 then
20215 Set_First_Named_Actual (New_Call,
20216 Explicit_Actual_Parameter (New_Act));
20217 end if;
20219 -- Scan the actual parameter list to find the next suitable
20220 -- named actual. Note that the list may be out of order.
20222 New_Next := First (Parameter_Associations (New_Call));
20223 Old_Next := First (Parameter_Associations (Old_Call));
20224 while Nkind (Old_Next) /= N_Parameter_Association
20225 or else Explicit_Actual_Parameter (Old_Next) /=
20226 Next_Named_Actual (Old_Act)
20227 loop
20228 Next (New_Next);
20229 Next (Old_Next);
20230 end loop;
20232 Set_Next_Named_Actual (New_Act,
20233 Explicit_Actual_Parameter (New_Next));
20234 end if;
20236 Next (New_Act);
20237 Next (Old_Act);
20238 end loop;
20239 end Update_Named_Associations;
20241 -------------------------
20242 -- Update_New_Entities --
20243 -------------------------
20245 procedure Update_New_Entities (Entity_Map : Elist_Id) is
20246 New_Id : Entity_Id := Empty;
20247 Old_Id : Entity_Id := Empty;
20249 begin
20250 if NCT_Tables_In_Use then
20251 NCT_New_Entities.Get_First (Old_Id, New_Id);
20253 -- Update the semantic fields of all new entities created during
20254 -- Phase 1 which were not supplied via an entity map.
20255 -- ??? Is there a better way of distinguishing those?
20257 while Present (Old_Id) and then Present (New_Id) loop
20258 if not (Present (Entity_Map)
20259 and then In_Entity_Map (Old_Id, Entity_Map))
20260 then
20261 Update_Semantic_Fields (New_Id);
20262 end if;
20264 NCT_New_Entities.Get_Next (Old_Id, New_Id);
20265 end loop;
20266 end if;
20267 end Update_New_Entities;
20269 ---------------------------
20270 -- Update_Pending_Itypes --
20271 ---------------------------
20273 procedure Update_Pending_Itypes
20274 (Old_Assoc : Node_Id;
20275 New_Assoc : Node_Id)
20277 Item : Elmt_Id;
20278 Itypes : Elist_Id;
20280 begin
20281 if NCT_Tables_In_Use then
20282 Itypes := NCT_Pending_Itypes.Get (Old_Assoc);
20284 -- Update the Associated_Node_For_Itype attribute for all itypes
20285 -- which originally refer to Old_Assoc to designate New_Assoc.
20287 if Present (Itypes) then
20288 Item := First_Elmt (Itypes);
20289 while Present (Item) loop
20290 Set_Associated_Node_For_Itype (Node (Item), New_Assoc);
20292 Next_Elmt (Item);
20293 end loop;
20294 end if;
20295 end if;
20296 end Update_Pending_Itypes;
20298 ----------------------------
20299 -- Update_Semantic_Fields --
20300 ----------------------------
20302 procedure Update_Semantic_Fields (Id : Entity_Id) is
20303 begin
20304 -- Discriminant_Constraint
20306 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20307 Set_Discriminant_Constraint (Id, Elist_Id (
20308 Copy_Field_With_Replacement
20309 (Field => Union_Id (Discriminant_Constraint (Id)),
20310 Semantic => True)));
20311 end if;
20313 -- Etype
20315 Set_Etype (Id, Node_Id (
20316 Copy_Field_With_Replacement
20317 (Field => Union_Id (Etype (Id)),
20318 Semantic => True)));
20320 -- First_Index
20321 -- Packed_Array_Impl_Type
20323 if Is_Array_Type (Id) then
20324 if Present (First_Index (Id)) then
20325 Set_First_Index (Id, First (List_Id (
20326 Copy_Field_With_Replacement
20327 (Field => Union_Id (List_Containing (First_Index (Id))),
20328 Semantic => True))));
20329 end if;
20331 if Is_Packed (Id) then
20332 Set_Packed_Array_Impl_Type (Id, Node_Id (
20333 Copy_Field_With_Replacement
20334 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20335 Semantic => True)));
20336 end if;
20337 end if;
20339 -- Prev_Entity
20341 Set_Prev_Entity (Id, Node_Id (
20342 Copy_Field_With_Replacement
20343 (Field => Union_Id (Prev_Entity (Id)),
20344 Semantic => True)));
20346 -- Next_Entity
20348 Set_Next_Entity (Id, Node_Id (
20349 Copy_Field_With_Replacement
20350 (Field => Union_Id (Next_Entity (Id)),
20351 Semantic => True)));
20353 -- Scalar_Range
20355 if Is_Discrete_Type (Id) then
20356 Set_Scalar_Range (Id, Node_Id (
20357 Copy_Field_With_Replacement
20358 (Field => Union_Id (Scalar_Range (Id)),
20359 Semantic => True)));
20360 end if;
20362 -- Scope
20364 -- Update the scope when the caller specified an explicit one
20366 if Present (New_Scope) then
20367 Set_Scope (Id, New_Scope);
20368 else
20369 Set_Scope (Id, Node_Id (
20370 Copy_Field_With_Replacement
20371 (Field => Union_Id (Scope (Id)),
20372 Semantic => True)));
20373 end if;
20374 end Update_Semantic_Fields;
20376 --------------------
20377 -- Visit_Any_Node --
20378 --------------------
20380 procedure Visit_Any_Node (N : Node_Or_Entity_Id) is
20381 begin
20382 if Nkind (N) in N_Entity then
20383 if Is_Itype (N) then
20384 Visit_Itype (N);
20385 else
20386 Visit_Entity (N);
20387 end if;
20388 else
20389 Visit_Node (N);
20390 end if;
20391 end Visit_Any_Node;
20393 -----------------
20394 -- Visit_Elist --
20395 -----------------
20397 procedure Visit_Elist (List : Elist_Id) is
20398 Elmt : Elmt_Id;
20400 begin
20401 -- The element of an entity list could be an entity, itype, or a
20402 -- node, hence the call to Visit_Any_Node.
20404 if Present (List) then
20405 Elmt := First_Elmt (List);
20406 while Present (Elmt) loop
20407 Visit_Any_Node (Node (Elmt));
20409 Next_Elmt (Elmt);
20410 end loop;
20411 end if;
20412 end Visit_Elist;
20414 ------------------
20415 -- Visit_Entity --
20416 ------------------
20418 procedure Visit_Entity (Id : Entity_Id) is
20419 New_Id : Entity_Id;
20421 begin
20422 pragma Assert (Nkind (Id) in N_Entity);
20423 pragma Assert (not Is_Itype (Id));
20425 -- Nothing to do if the entity is not defined in the Actions list of
20426 -- an N_Expression_With_Actions node.
20428 if EWA_Level = 0 then
20429 return;
20431 -- Nothing to do if the entity is defined within a scoping construct
20432 -- of an N_Expression_With_Actions node.
20434 elsif EWA_Inner_Scope_Level > 0 then
20435 return;
20437 -- Nothing to do if the entity is not an object or a type. Relaxing
20438 -- this restriction leads to a performance penalty.
20440 elsif not Ekind_In (Id, E_Constant, E_Variable)
20441 and then not Is_Type (Id)
20442 then
20443 return;
20445 -- Nothing to do if the entity was already visited
20447 elsif NCT_Tables_In_Use
20448 and then Present (NCT_New_Entities.Get (Id))
20449 then
20450 return;
20452 -- Nothing to do if the declaration node of the entity is not within
20453 -- the subtree being replicated.
20455 elsif not In_Subtree
20456 (N => Declaration_Node (Id),
20457 Root => Source)
20458 then
20459 return;
20460 end if;
20462 -- Create a new entity by directly copying the old entity. This
20463 -- action causes all attributes of the old entity to be inherited.
20465 New_Id := New_Copy (Id);
20467 -- Create a new name for the new entity because the back end needs
20468 -- distinct names for debugging purposes.
20470 Set_Chars (New_Id, New_Internal_Name ('T'));
20472 -- Update the Comes_From_Source and Sloc attributes of the entity in
20473 -- case the caller has supplied new values.
20475 Update_CFS_Sloc (New_Id);
20477 -- Establish the following mapping within table NCT_New_Entities:
20479 -- Id -> New_Id
20481 Add_New_Entity (Id, New_Id);
20483 -- Deal with the semantic fields of entities. The fields are visited
20484 -- because they may mention entities which reside within the subtree
20485 -- being copied.
20487 Visit_Semantic_Fields (Id);
20488 end Visit_Entity;
20490 -----------------
20491 -- Visit_Field --
20492 -----------------
20494 procedure Visit_Field
20495 (Field : Union_Id;
20496 Par_Nod : Node_Id := Empty;
20497 Semantic : Boolean := False)
20499 begin
20500 -- The field is empty
20502 if Field = Union_Id (Empty) then
20503 return;
20505 -- The field is an entity/itype/node
20507 elsif Field in Node_Range then
20508 declare
20509 N : constant Node_Id := Node_Id (Field);
20511 begin
20512 -- The field is an entity/itype
20514 if Nkind (N) in N_Entity then
20516 -- Itypes are always visited
20518 if Is_Itype (N) then
20519 Visit_Itype (N);
20521 -- An entity is visited when it is either a syntactic field
20522 -- or when the caller treats it as a semantic attribute.
20524 elsif Parent (N) = Par_Nod or else Semantic then
20525 Visit_Entity (N);
20526 end if;
20528 -- The field is a node
20530 else
20531 -- A node is visited when it is either a syntactic field or
20532 -- when the caller treats it as a semantic attribute.
20534 if Parent (N) = Par_Nod or else Semantic then
20535 Visit_Node (N);
20536 end if;
20537 end if;
20538 end;
20540 -- The field is an entity list
20542 elsif Field in Elist_Range then
20543 Visit_Elist (Elist_Id (Field));
20545 -- The field is a syntax list
20547 elsif Field in List_Range then
20548 declare
20549 List : constant List_Id := List_Id (Field);
20551 begin
20552 -- A syntax list is visited when it is either a syntactic field
20553 -- or when the caller treats it as a semantic attribute.
20555 if Parent (List) = Par_Nod or else Semantic then
20556 Visit_List (List);
20557 end if;
20558 end;
20560 -- Otherwise the field denotes information which does not need to be
20561 -- visited (chars, literals, etc.).
20563 else
20564 null;
20565 end if;
20566 end Visit_Field;
20568 -----------------
20569 -- Visit_Itype --
20570 -----------------
20572 procedure Visit_Itype (Itype : Entity_Id) is
20573 New_Assoc : Node_Id;
20574 New_Itype : Entity_Id;
20575 Old_Assoc : Node_Id;
20577 begin
20578 pragma Assert (Nkind (Itype) in N_Entity);
20579 pragma Assert (Is_Itype (Itype));
20581 -- Itypes that describe the designated type of access to subprograms
20582 -- have the structure of subprogram declarations, with signatures,
20583 -- etc. Either we duplicate the signatures completely, or choose to
20584 -- share such itypes, which is fine because their elaboration will
20585 -- have no side effects.
20587 if Ekind (Itype) = E_Subprogram_Type then
20588 return;
20590 -- Nothing to do if the itype was already visited
20592 elsif NCT_Tables_In_Use
20593 and then Present (NCT_New_Entities.Get (Itype))
20594 then
20595 return;
20597 -- Nothing to do if the associated node of the itype is not within
20598 -- the subtree being replicated.
20600 elsif not In_Subtree
20601 (N => Associated_Node_For_Itype (Itype),
20602 Root => Source)
20603 then
20604 return;
20605 end if;
20607 -- Create a new itype by directly copying the old itype. This action
20608 -- causes all attributes of the old itype to be inherited.
20610 New_Itype := New_Copy (Itype);
20612 -- Create a new name for the new itype because the back end requires
20613 -- distinct names for debugging purposes.
20615 Set_Chars (New_Itype, New_Internal_Name ('T'));
20617 -- Update the Comes_From_Source and Sloc attributes of the itype in
20618 -- case the caller has supplied new values.
20620 Update_CFS_Sloc (New_Itype);
20622 -- Establish the following mapping within table NCT_New_Entities:
20624 -- Itype -> New_Itype
20626 Add_New_Entity (Itype, New_Itype);
20628 -- The new itype must be unfrozen because the resulting subtree may
20629 -- be inserted anywhere and cause an earlier or later freezing.
20631 if Present (Freeze_Node (New_Itype)) then
20632 Set_Freeze_Node (New_Itype, Empty);
20633 Set_Is_Frozen (New_Itype, False);
20634 end if;
20636 -- If a record subtype is simply copied, the entity list will be
20637 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
20638 -- ??? What does this do?
20640 if Ekind_In (Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
20641 Set_Cloned_Subtype (New_Itype, Itype);
20642 end if;
20644 -- The associated node may denote an entity, in which case it may
20645 -- already have a new corresponding entity created during a prior
20646 -- call to Visit_Entity or Visit_Itype for the same subtree.
20648 -- Given
20649 -- Old_Assoc ---------> New_Assoc
20651 -- Created by Visit_Itype
20652 -- Itype -------------> New_Itype
20653 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
20655 -- In the example above, Old_Assoc is an arbitrary entity that was
20656 -- already visited for the same subtree and has a corresponding new
20657 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
20658 -- of copying entities, however it must be updated to New_Assoc.
20660 Old_Assoc := Associated_Node_For_Itype (Itype);
20662 if Nkind (Old_Assoc) in N_Entity then
20663 if NCT_Tables_In_Use then
20664 New_Assoc := NCT_New_Entities.Get (Old_Assoc);
20666 if Present (New_Assoc) then
20667 Set_Associated_Node_For_Itype (New_Itype, New_Assoc);
20668 end if;
20669 end if;
20671 -- Otherwise the associated node denotes a node. Postpone the update
20672 -- until Phase 2 when the node is replicated. Establish the following
20673 -- mapping within table NCT_Pending_Itypes:
20675 -- Old_Assoc -> (New_Type, ...)
20677 else
20678 Add_Pending_Itype (Old_Assoc, New_Itype);
20679 end if;
20681 -- Deal with the semantic fields of itypes. The fields are visited
20682 -- because they may mention entities that reside within the subtree
20683 -- being copied.
20685 Visit_Semantic_Fields (Itype);
20686 end Visit_Itype;
20688 ----------------
20689 -- Visit_List --
20690 ----------------
20692 procedure Visit_List (List : List_Id) is
20693 Elmt : Node_Id;
20695 begin
20696 -- Note that the element of a syntactic list is always a node, never
20697 -- an entity or itype, hence the call to Visit_Node.
20699 if Present (List) then
20700 Elmt := First (List);
20701 while Present (Elmt) loop
20702 Visit_Node (Elmt);
20704 Next (Elmt);
20705 end loop;
20706 end if;
20707 end Visit_List;
20709 ----------------
20710 -- Visit_Node --
20711 ----------------
20713 procedure Visit_Node (N : Node_Or_Entity_Id) is
20714 begin
20715 pragma Assert (Nkind (N) not in N_Entity);
20717 if Nkind (N) = N_Expression_With_Actions then
20718 EWA_Level := EWA_Level + 1;
20720 elsif EWA_Level > 0
20721 and then Nkind_In (N, N_Block_Statement,
20722 N_Subprogram_Body,
20723 N_Subprogram_Declaration)
20724 then
20725 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
20726 end if;
20728 Visit_Field
20729 (Field => Field1 (N),
20730 Par_Nod => N);
20732 Visit_Field
20733 (Field => Field2 (N),
20734 Par_Nod => N);
20736 Visit_Field
20737 (Field => Field3 (N),
20738 Par_Nod => N);
20740 Visit_Field
20741 (Field => Field4 (N),
20742 Par_Nod => N);
20744 Visit_Field
20745 (Field => Field5 (N),
20746 Par_Nod => N);
20748 if EWA_Level > 0
20749 and then Nkind_In (N, N_Block_Statement,
20750 N_Subprogram_Body,
20751 N_Subprogram_Declaration)
20752 then
20753 EWA_Inner_Scope_Level := EWA_Inner_Scope_Level - 1;
20755 elsif Nkind (N) = N_Expression_With_Actions then
20756 EWA_Level := EWA_Level - 1;
20757 end if;
20758 end Visit_Node;
20760 ---------------------------
20761 -- Visit_Semantic_Fields --
20762 ---------------------------
20764 procedure Visit_Semantic_Fields (Id : Entity_Id) is
20765 begin
20766 pragma Assert (Nkind (Id) in N_Entity);
20768 -- Discriminant_Constraint
20770 if Is_Type (Id) and then Has_Discriminants (Base_Type (Id)) then
20771 Visit_Field
20772 (Field => Union_Id (Discriminant_Constraint (Id)),
20773 Semantic => True);
20774 end if;
20776 -- Etype
20778 Visit_Field
20779 (Field => Union_Id (Etype (Id)),
20780 Semantic => True);
20782 -- First_Index
20783 -- Packed_Array_Impl_Type
20785 if Is_Array_Type (Id) then
20786 if Present (First_Index (Id)) then
20787 Visit_Field
20788 (Field => Union_Id (List_Containing (First_Index (Id))),
20789 Semantic => True);
20790 end if;
20792 if Is_Packed (Id) then
20793 Visit_Field
20794 (Field => Union_Id (Packed_Array_Impl_Type (Id)),
20795 Semantic => True);
20796 end if;
20797 end if;
20799 -- Scalar_Range
20801 if Is_Discrete_Type (Id) then
20802 Visit_Field
20803 (Field => Union_Id (Scalar_Range (Id)),
20804 Semantic => True);
20805 end if;
20806 end Visit_Semantic_Fields;
20808 -- Start of processing for New_Copy_Tree
20810 begin
20811 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
20812 -- shallow copies for each node within, and then updating the child and
20813 -- parent pointers accordingly. This process is straightforward, however
20814 -- the routine must deal with the following complications:
20816 -- * Entities defined within N_Expression_With_Actions nodes must be
20817 -- replicated rather than shared to avoid introducing two identical
20818 -- symbols within the same scope. Note that no other expression can
20819 -- currently define entities.
20821 -- do
20822 -- Source_Low : ...;
20823 -- Source_High : ...;
20825 -- <reference to Source_Low>
20826 -- <reference to Source_High>
20827 -- in ... end;
20829 -- New_Copy_Tree handles this case by first creating new entities
20830 -- and then updating all existing references to point to these new
20831 -- entities.
20833 -- do
20834 -- New_Low : ...;
20835 -- New_High : ...;
20837 -- <reference to New_Low>
20838 -- <reference to New_High>
20839 -- in ... end;
20841 -- * Itypes defined within the subtree must be replicated to avoid any
20842 -- dependencies on invalid or inaccessible data.
20844 -- subtype Source_Itype is ... range Source_Low .. Source_High;
20846 -- New_Copy_Tree handles this case by first creating a new itype in
20847 -- the same fashion as entities, and then updating various relevant
20848 -- constraints.
20850 -- subtype New_Itype is ... range New_Low .. New_High;
20852 -- * The Associated_Node_For_Itype field of itypes must be updated to
20853 -- reference the proper replicated entity or node.
20855 -- * Semantic fields of entities such as Etype and Scope must be
20856 -- updated to reference the proper replicated entities.
20858 -- * Semantic fields of nodes such as First_Real_Statement must be
20859 -- updated to reference the proper replicated nodes.
20861 -- To meet all these demands, routine New_Copy_Tree is split into two
20862 -- phases.
20864 -- Phase 1 traverses the tree in order to locate entities and itypes
20865 -- defined within the subtree. New entities are generated and saved in
20866 -- table NCT_New_Entities. The semantic fields of all new entities and
20867 -- itypes are then updated accordingly.
20869 -- Phase 2 traverses the tree in order to replicate each node. Various
20870 -- semantic fields of nodes and entities are updated accordingly.
20872 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
20873 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
20874 -- data inside.
20876 if NCT_Tables_In_Use then
20877 NCT_Tables_In_Use := False;
20879 NCT_New_Entities.Reset;
20880 NCT_Pending_Itypes.Reset;
20881 end if;
20883 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
20884 -- supplied by a linear entity map. The tables offer faster access to
20885 -- the same data.
20887 Build_NCT_Tables (Map);
20889 -- Execute Phase 1. Traverse the subtree and generate new entities for
20890 -- the following cases:
20892 -- * An entity defined within an N_Expression_With_Actions node
20894 -- * An itype referenced within the subtree where the associated node
20895 -- is also in the subtree.
20897 -- All new entities are accessible via table NCT_New_Entities, which
20898 -- contains mappings of the form:
20900 -- Old_Entity -> New_Entity
20901 -- Old_Itype -> New_Itype
20903 -- In addition, the associated nodes of all new itypes are mapped in
20904 -- table NCT_Pending_Itypes:
20906 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
20908 Visit_Any_Node (Source);
20910 -- Update the semantic attributes of all new entities generated during
20911 -- Phase 1 before starting Phase 2. The updates could be performed in
20912 -- routine Corresponding_Entity, however this may cause the same entity
20913 -- to be updated multiple times, effectively generating useless nodes.
20914 -- Keeping the updates separates from Phase 2 ensures that only one set
20915 -- of attributes is generated for an entity at any one time.
20917 Update_New_Entities (Map);
20919 -- Execute Phase 2. Replicate the source subtree one node at a time.
20920 -- The following transformations take place:
20922 -- * References to entities and itypes are updated to refer to the
20923 -- new entities and itypes generated during Phase 1.
20925 -- * All Associated_Node_For_Itype attributes of itypes are updated
20926 -- to refer to the new replicated Associated_Node_For_Itype.
20928 return Copy_Node_With_Replacement (Source);
20929 end New_Copy_Tree;
20931 -------------------------
20932 -- New_External_Entity --
20933 -------------------------
20935 function New_External_Entity
20936 (Kind : Entity_Kind;
20937 Scope_Id : Entity_Id;
20938 Sloc_Value : Source_Ptr;
20939 Related_Id : Entity_Id;
20940 Suffix : Character;
20941 Suffix_Index : Nat := 0;
20942 Prefix : Character := ' ') return Entity_Id
20944 N : constant Entity_Id :=
20945 Make_Defining_Identifier (Sloc_Value,
20946 New_External_Name
20947 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
20949 begin
20950 Set_Ekind (N, Kind);
20951 Set_Is_Internal (N, True);
20952 Append_Entity (N, Scope_Id);
20953 Set_Public_Status (N);
20955 if Kind in Type_Kind then
20956 Init_Size_Align (N);
20957 end if;
20959 return N;
20960 end New_External_Entity;
20962 -------------------------
20963 -- New_Internal_Entity --
20964 -------------------------
20966 function New_Internal_Entity
20967 (Kind : Entity_Kind;
20968 Scope_Id : Entity_Id;
20969 Sloc_Value : Source_Ptr;
20970 Id_Char : Character) return Entity_Id
20972 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
20974 begin
20975 Set_Ekind (N, Kind);
20976 Set_Is_Internal (N, True);
20977 Append_Entity (N, Scope_Id);
20979 if Kind in Type_Kind then
20980 Init_Size_Align (N);
20981 end if;
20983 return N;
20984 end New_Internal_Entity;
20986 -----------------
20987 -- Next_Actual --
20988 -----------------
20990 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
20991 N : Node_Id;
20993 begin
20994 -- If we are pointing at a positional parameter, it is a member of a
20995 -- node list (the list of parameters), and the next parameter is the
20996 -- next node on the list, unless we hit a parameter association, then
20997 -- we shift to using the chain whose head is the First_Named_Actual in
20998 -- the parent, and then is threaded using the Next_Named_Actual of the
20999 -- Parameter_Association. All this fiddling is because the original node
21000 -- list is in the textual call order, and what we need is the
21001 -- declaration order.
21003 if Is_List_Member (Actual_Id) then
21004 N := Next (Actual_Id);
21006 if Nkind (N) = N_Parameter_Association then
21008 -- In case of a build-in-place call, the call will no longer be a
21009 -- call; it will have been rewritten.
21011 if Nkind_In (Parent (Actual_Id), N_Entry_Call_Statement,
21012 N_Function_Call,
21013 N_Procedure_Call_Statement)
21014 then
21015 return First_Named_Actual (Parent (Actual_Id));
21016 else
21017 return Empty;
21018 end if;
21019 else
21020 return N;
21021 end if;
21023 else
21024 return Next_Named_Actual (Parent (Actual_Id));
21025 end if;
21026 end Next_Actual;
21028 procedure Next_Actual (Actual_Id : in out Node_Id) is
21029 begin
21030 Actual_Id := Next_Actual (Actual_Id);
21031 end Next_Actual;
21033 -----------------
21034 -- Next_Global --
21035 -----------------
21037 function Next_Global (Node : Node_Id) return Node_Id is
21038 begin
21039 -- The global item may either be in a list, or by itself, in which case
21040 -- there is no next global item with the same mode.
21042 if Is_List_Member (Node) then
21043 return Next (Node);
21044 else
21045 return Empty;
21046 end if;
21047 end Next_Global;
21049 procedure Next_Global (Node : in out Node_Id) is
21050 begin
21051 Node := Next_Global (Node);
21052 end Next_Global;
21054 ----------------------------------
21055 -- New_Requires_Transient_Scope --
21056 ----------------------------------
21058 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
21059 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
21060 -- This is called for untagged records and protected types, with
21061 -- nondefaulted discriminants. Returns True if the size of function
21062 -- results is known at the call site, False otherwise. Returns False
21063 -- if there is a variant part that depends on the discriminants of
21064 -- this type, or if there is an array constrained by the discriminants
21065 -- of this type. ???Currently, this is overly conservative (the array
21066 -- could be nested inside some other record that is constrained by
21067 -- nondiscriminants). That is, the recursive calls are too conservative.
21069 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
21070 -- Returns True if Typ is a nonlimited record with defaulted
21071 -- discriminants whose max size makes it unsuitable for allocating on
21072 -- the primary stack.
21074 ------------------------------
21075 -- Caller_Known_Size_Record --
21076 ------------------------------
21078 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
21079 pragma Assert (Typ = Underlying_Type (Typ));
21081 begin
21082 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
21083 return False;
21084 end if;
21086 declare
21087 Comp : Entity_Id;
21089 begin
21090 Comp := First_Entity (Typ);
21091 while Present (Comp) loop
21093 -- Only look at E_Component entities. No need to look at
21094 -- E_Discriminant entities, and we must ignore internal
21095 -- subtypes generated for constrained components.
21097 if Ekind (Comp) = E_Component then
21098 declare
21099 Comp_Type : constant Entity_Id :=
21100 Underlying_Type (Etype (Comp));
21102 begin
21103 if Is_Record_Type (Comp_Type)
21104 or else
21105 Is_Protected_Type (Comp_Type)
21106 then
21107 if not Caller_Known_Size_Record (Comp_Type) then
21108 return False;
21109 end if;
21111 elsif Is_Array_Type (Comp_Type) then
21112 if Size_Depends_On_Discriminant (Comp_Type) then
21113 return False;
21114 end if;
21115 end if;
21116 end;
21117 end if;
21119 Next_Entity (Comp);
21120 end loop;
21121 end;
21123 return True;
21124 end Caller_Known_Size_Record;
21126 ------------------------------
21127 -- Large_Max_Size_Mutable --
21128 ------------------------------
21130 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
21131 pragma Assert (Typ = Underlying_Type (Typ));
21133 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
21134 -- Returns true if the discrete type T has a large range
21136 ----------------------------
21137 -- Is_Large_Discrete_Type --
21138 ----------------------------
21140 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
21141 Threshold : constant Int := 16;
21142 -- Arbitrary threshold above which we consider it "large". We want
21143 -- a fairly large threshold, because these large types really
21144 -- shouldn't have default discriminants in the first place, in
21145 -- most cases.
21147 begin
21148 return UI_To_Int (RM_Size (T)) > Threshold;
21149 end Is_Large_Discrete_Type;
21151 -- Start of processing for Large_Max_Size_Mutable
21153 begin
21154 if Is_Record_Type (Typ)
21155 and then not Is_Limited_View (Typ)
21156 and then Has_Defaulted_Discriminants (Typ)
21157 then
21158 -- Loop through the components, looking for an array whose upper
21159 -- bound(s) depends on discriminants, where both the subtype of
21160 -- the discriminant and the index subtype are too large.
21162 declare
21163 Comp : Entity_Id;
21165 begin
21166 Comp := First_Entity (Typ);
21167 while Present (Comp) loop
21168 if Ekind (Comp) = E_Component then
21169 declare
21170 Comp_Type : constant Entity_Id :=
21171 Underlying_Type (Etype (Comp));
21173 Hi : Node_Id;
21174 Indx : Node_Id;
21175 Ityp : Entity_Id;
21177 begin
21178 if Is_Array_Type (Comp_Type) then
21179 Indx := First_Index (Comp_Type);
21181 while Present (Indx) loop
21182 Ityp := Etype (Indx);
21183 Hi := Type_High_Bound (Ityp);
21185 if Nkind (Hi) = N_Identifier
21186 and then Ekind (Entity (Hi)) = E_Discriminant
21187 and then Is_Large_Discrete_Type (Ityp)
21188 and then Is_Large_Discrete_Type
21189 (Etype (Entity (Hi)))
21190 then
21191 return True;
21192 end if;
21194 Next_Index (Indx);
21195 end loop;
21196 end if;
21197 end;
21198 end if;
21200 Next_Entity (Comp);
21201 end loop;
21202 end;
21203 end if;
21205 return False;
21206 end Large_Max_Size_Mutable;
21208 -- Local declarations
21210 Typ : constant Entity_Id := Underlying_Type (Id);
21212 -- Start of processing for New_Requires_Transient_Scope
21214 begin
21215 -- This is a private type which is not completed yet. This can only
21216 -- happen in a default expression (of a formal parameter or of a
21217 -- record component). Do not expand transient scope in this case.
21219 if No (Typ) then
21220 return False;
21222 -- Do not expand transient scope for non-existent procedure return or
21223 -- string literal types.
21225 elsif Typ = Standard_Void_Type
21226 or else Ekind (Typ) = E_String_Literal_Subtype
21227 then
21228 return False;
21230 -- If Typ is a generic formal incomplete type, then we want to look at
21231 -- the actual type.
21233 elsif Ekind (Typ) = E_Record_Subtype
21234 and then Present (Cloned_Subtype (Typ))
21235 then
21236 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
21238 -- Functions returning specific tagged types may dispatch on result, so
21239 -- their returned value is allocated on the secondary stack, even in the
21240 -- definite case. We must treat nondispatching functions the same way,
21241 -- because access-to-function types can point at both, so the calling
21242 -- conventions must be compatible. Is_Tagged_Type includes controlled
21243 -- types and class-wide types. Controlled type temporaries need
21244 -- finalization.
21246 -- ???It's not clear why we need to return noncontrolled types with
21247 -- controlled components on the secondary stack.
21249 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
21250 return True;
21252 -- Untagged definite subtypes are known size. This includes all
21253 -- elementary [sub]types. Tasks are known size even if they have
21254 -- discriminants. So we return False here, with one exception:
21255 -- For a type like:
21256 -- type T (Last : Natural := 0) is
21257 -- X : String (1 .. Last);
21258 -- end record;
21259 -- we return True. That's because for "P(F(...));", where F returns T,
21260 -- we don't know the size of the result at the call site, so if we
21261 -- allocated it on the primary stack, we would have to allocate the
21262 -- maximum size, which is way too big.
21264 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
21265 return Large_Max_Size_Mutable (Typ);
21267 -- Indefinite (discriminated) untagged record or protected type
21269 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
21270 return not Caller_Known_Size_Record (Typ);
21272 -- Unconstrained array
21274 else
21275 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
21276 return True;
21277 end if;
21278 end New_Requires_Transient_Scope;
21280 --------------------------
21281 -- No_Heap_Finalization --
21282 --------------------------
21284 function No_Heap_Finalization (Typ : Entity_Id) return Boolean is
21285 begin
21286 if Ekind_In (Typ, E_Access_Type, E_General_Access_Type)
21287 and then Is_Library_Level_Entity (Typ)
21288 then
21289 -- A global No_Heap_Finalization pragma applies to all library-level
21290 -- named access-to-object types.
21292 if Present (No_Heap_Finalization_Pragma) then
21293 return True;
21295 -- The library-level named access-to-object type itself is subject to
21296 -- pragma No_Heap_Finalization.
21298 elsif Present (Get_Pragma (Typ, Pragma_No_Heap_Finalization)) then
21299 return True;
21300 end if;
21301 end if;
21303 return False;
21304 end No_Heap_Finalization;
21306 -----------------------
21307 -- Normalize_Actuals --
21308 -----------------------
21310 -- Chain actuals according to formals of subprogram. If there are no named
21311 -- associations, the chain is simply the list of Parameter Associations,
21312 -- since the order is the same as the declaration order. If there are named
21313 -- associations, then the First_Named_Actual field in the N_Function_Call
21314 -- or N_Procedure_Call_Statement node points to the Parameter_Association
21315 -- node for the parameter that comes first in declaration order. The
21316 -- remaining named parameters are then chained in declaration order using
21317 -- Next_Named_Actual.
21319 -- This routine also verifies that the number of actuals is compatible with
21320 -- the number and default values of formals, but performs no type checking
21321 -- (type checking is done by the caller).
21323 -- If the matching succeeds, Success is set to True and the caller proceeds
21324 -- with type-checking. If the match is unsuccessful, then Success is set to
21325 -- False, and the caller attempts a different interpretation, if there is
21326 -- one.
21328 -- If the flag Report is on, the call is not overloaded, and a failure to
21329 -- match can be reported here, rather than in the caller.
21331 procedure Normalize_Actuals
21332 (N : Node_Id;
21333 S : Entity_Id;
21334 Report : Boolean;
21335 Success : out Boolean)
21337 Actuals : constant List_Id := Parameter_Associations (N);
21338 Actual : Node_Id := Empty;
21339 Formal : Entity_Id;
21340 Last : Node_Id := Empty;
21341 First_Named : Node_Id := Empty;
21342 Found : Boolean;
21344 Formals_To_Match : Integer := 0;
21345 Actuals_To_Match : Integer := 0;
21347 procedure Chain (A : Node_Id);
21348 -- Add named actual at the proper place in the list, using the
21349 -- Next_Named_Actual link.
21351 function Reporting return Boolean;
21352 -- Determines if an error is to be reported. To report an error, we
21353 -- need Report to be True, and also we do not report errors caused
21354 -- by calls to init procs that occur within other init procs. Such
21355 -- errors must always be cascaded errors, since if all the types are
21356 -- declared correctly, the compiler will certainly build decent calls.
21358 -----------
21359 -- Chain --
21360 -----------
21362 procedure Chain (A : Node_Id) is
21363 begin
21364 if No (Last) then
21366 -- Call node points to first actual in list
21368 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
21370 else
21371 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
21372 end if;
21374 Last := A;
21375 Set_Next_Named_Actual (Last, Empty);
21376 end Chain;
21378 ---------------
21379 -- Reporting --
21380 ---------------
21382 function Reporting return Boolean is
21383 begin
21384 if not Report then
21385 return False;
21387 elsif not Within_Init_Proc then
21388 return True;
21390 elsif Is_Init_Proc (Entity (Name (N))) then
21391 return False;
21393 else
21394 return True;
21395 end if;
21396 end Reporting;
21398 -- Start of processing for Normalize_Actuals
21400 begin
21401 if Is_Access_Type (S) then
21403 -- The name in the call is a function call that returns an access
21404 -- to subprogram. The designated type has the list of formals.
21406 Formal := First_Formal (Designated_Type (S));
21407 else
21408 Formal := First_Formal (S);
21409 end if;
21411 while Present (Formal) loop
21412 Formals_To_Match := Formals_To_Match + 1;
21413 Next_Formal (Formal);
21414 end loop;
21416 -- Find if there is a named association, and verify that no positional
21417 -- associations appear after named ones.
21419 if Present (Actuals) then
21420 Actual := First (Actuals);
21421 end if;
21423 while Present (Actual)
21424 and then Nkind (Actual) /= N_Parameter_Association
21425 loop
21426 Actuals_To_Match := Actuals_To_Match + 1;
21427 Next (Actual);
21428 end loop;
21430 if No (Actual) and Actuals_To_Match = Formals_To_Match then
21432 -- Most common case: positional notation, no defaults
21434 Success := True;
21435 return;
21437 elsif Actuals_To_Match > Formals_To_Match then
21439 -- Too many actuals: will not work
21441 if Reporting then
21442 if Is_Entity_Name (Name (N)) then
21443 Error_Msg_N ("too many arguments in call to&", Name (N));
21444 else
21445 Error_Msg_N ("too many arguments in call", N);
21446 end if;
21447 end if;
21449 Success := False;
21450 return;
21451 end if;
21453 First_Named := Actual;
21455 while Present (Actual) loop
21456 if Nkind (Actual) /= N_Parameter_Association then
21457 Error_Msg_N
21458 ("positional parameters not allowed after named ones", Actual);
21459 Success := False;
21460 return;
21462 else
21463 Actuals_To_Match := Actuals_To_Match + 1;
21464 end if;
21466 Next (Actual);
21467 end loop;
21469 if Present (Actuals) then
21470 Actual := First (Actuals);
21471 end if;
21473 Formal := First_Formal (S);
21474 while Present (Formal) loop
21476 -- Match the formals in order. If the corresponding actual is
21477 -- positional, nothing to do. Else scan the list of named actuals
21478 -- to find the one with the right name.
21480 if Present (Actual)
21481 and then Nkind (Actual) /= N_Parameter_Association
21482 then
21483 Next (Actual);
21484 Actuals_To_Match := Actuals_To_Match - 1;
21485 Formals_To_Match := Formals_To_Match - 1;
21487 else
21488 -- For named parameters, search the list of actuals to find
21489 -- one that matches the next formal name.
21491 Actual := First_Named;
21492 Found := False;
21493 while Present (Actual) loop
21494 if Chars (Selector_Name (Actual)) = Chars (Formal) then
21495 Found := True;
21496 Chain (Actual);
21497 Actuals_To_Match := Actuals_To_Match - 1;
21498 Formals_To_Match := Formals_To_Match - 1;
21499 exit;
21500 end if;
21502 Next (Actual);
21503 end loop;
21505 if not Found then
21506 if Ekind (Formal) /= E_In_Parameter
21507 or else No (Default_Value (Formal))
21508 then
21509 if Reporting then
21510 if (Comes_From_Source (S)
21511 or else Sloc (S) = Standard_Location)
21512 and then Is_Overloadable (S)
21513 then
21514 if No (Actuals)
21515 and then
21516 Nkind_In (Parent (N), N_Procedure_Call_Statement,
21517 N_Function_Call,
21518 N_Parameter_Association)
21519 and then Ekind (S) /= E_Function
21520 then
21521 Set_Etype (N, Etype (S));
21523 else
21524 Error_Msg_Name_1 := Chars (S);
21525 Error_Msg_Sloc := Sloc (S);
21526 Error_Msg_NE
21527 ("missing argument for parameter & "
21528 & "in call to % declared #", N, Formal);
21529 end if;
21531 elsif Is_Overloadable (S) then
21532 Error_Msg_Name_1 := Chars (S);
21534 -- Point to type derivation that generated the
21535 -- operation.
21537 Error_Msg_Sloc := Sloc (Parent (S));
21539 Error_Msg_NE
21540 ("missing argument for parameter & "
21541 & "in call to % (inherited) #", N, Formal);
21543 else
21544 Error_Msg_NE
21545 ("missing argument for parameter &", N, Formal);
21546 end if;
21547 end if;
21549 Success := False;
21550 return;
21552 else
21553 Formals_To_Match := Formals_To_Match - 1;
21554 end if;
21555 end if;
21556 end if;
21558 Next_Formal (Formal);
21559 end loop;
21561 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
21562 Success := True;
21563 return;
21565 else
21566 if Reporting then
21568 -- Find some superfluous named actual that did not get
21569 -- attached to the list of associations.
21571 Actual := First (Actuals);
21572 while Present (Actual) loop
21573 if Nkind (Actual) = N_Parameter_Association
21574 and then Actual /= Last
21575 and then No (Next_Named_Actual (Actual))
21576 then
21577 -- A validity check may introduce a copy of a call that
21578 -- includes an extra actual (for example for an unrelated
21579 -- accessibility check). Check that the extra actual matches
21580 -- some extra formal, which must exist already because
21581 -- subprogram must be frozen at this point.
21583 if Present (Extra_Formals (S))
21584 and then not Comes_From_Source (Actual)
21585 and then Nkind (Actual) = N_Parameter_Association
21586 and then Chars (Extra_Formals (S)) =
21587 Chars (Selector_Name (Actual))
21588 then
21589 null;
21590 else
21591 Error_Msg_N
21592 ("unmatched actual & in call", Selector_Name (Actual));
21593 exit;
21594 end if;
21595 end if;
21597 Next (Actual);
21598 end loop;
21599 end if;
21601 Success := False;
21602 return;
21603 end if;
21604 end Normalize_Actuals;
21606 --------------------------------
21607 -- Note_Possible_Modification --
21608 --------------------------------
21610 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
21611 Modification_Comes_From_Source : constant Boolean :=
21612 Comes_From_Source (Parent (N));
21614 Ent : Entity_Id;
21615 Exp : Node_Id;
21617 begin
21618 -- Loop to find referenced entity, if there is one
21620 Exp := N;
21621 loop
21622 Ent := Empty;
21624 if Is_Entity_Name (Exp) then
21625 Ent := Entity (Exp);
21627 -- If the entity is missing, it is an undeclared identifier,
21628 -- and there is nothing to annotate.
21630 if No (Ent) then
21631 return;
21632 end if;
21634 elsif Nkind (Exp) = N_Explicit_Dereference then
21635 declare
21636 P : constant Node_Id := Prefix (Exp);
21638 begin
21639 -- In formal verification mode, keep track of all reads and
21640 -- writes through explicit dereferences.
21642 if GNATprove_Mode then
21643 SPARK_Specific.Generate_Dereference (N, 'm');
21644 end if;
21646 if Nkind (P) = N_Selected_Component
21647 and then Present (Entry_Formal (Entity (Selector_Name (P))))
21648 then
21649 -- Case of a reference to an entry formal
21651 Ent := Entry_Formal (Entity (Selector_Name (P)));
21653 elsif Nkind (P) = N_Identifier
21654 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
21655 and then Present (Expression (Parent (Entity (P))))
21656 and then Nkind (Expression (Parent (Entity (P)))) =
21657 N_Reference
21658 then
21659 -- Case of a reference to a value on which side effects have
21660 -- been removed.
21662 Exp := Prefix (Expression (Parent (Entity (P))));
21663 goto Continue;
21665 else
21666 return;
21667 end if;
21668 end;
21670 elsif Nkind_In (Exp, N_Type_Conversion,
21671 N_Unchecked_Type_Conversion)
21672 then
21673 Exp := Expression (Exp);
21674 goto Continue;
21676 elsif Nkind_In (Exp, N_Slice,
21677 N_Indexed_Component,
21678 N_Selected_Component)
21679 then
21680 -- Special check, if the prefix is an access type, then return
21681 -- since we are modifying the thing pointed to, not the prefix.
21682 -- When we are expanding, most usually the prefix is replaced
21683 -- by an explicit dereference, and this test is not needed, but
21684 -- in some cases (notably -gnatc mode and generics) when we do
21685 -- not do full expansion, we need this special test.
21687 if Is_Access_Type (Etype (Prefix (Exp))) then
21688 return;
21690 -- Otherwise go to prefix and keep going
21692 else
21693 Exp := Prefix (Exp);
21694 goto Continue;
21695 end if;
21697 -- All other cases, not a modification
21699 else
21700 return;
21701 end if;
21703 -- Now look for entity being referenced
21705 if Present (Ent) then
21706 if Is_Object (Ent) then
21707 if Comes_From_Source (Exp)
21708 or else Modification_Comes_From_Source
21709 then
21710 -- Give warning if pragma unmodified is given and we are
21711 -- sure this is a modification.
21713 if Has_Pragma_Unmodified (Ent) and then Sure then
21715 -- Note that the entity may be present only as a result
21716 -- of pragma Unused.
21718 if Has_Pragma_Unused (Ent) then
21719 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
21720 else
21721 Error_Msg_NE
21722 ("??pragma Unmodified given for &!", N, Ent);
21723 end if;
21724 end if;
21726 Set_Never_Set_In_Source (Ent, False);
21727 end if;
21729 Set_Is_True_Constant (Ent, False);
21730 Set_Current_Value (Ent, Empty);
21731 Set_Is_Known_Null (Ent, False);
21733 if not Can_Never_Be_Null (Ent) then
21734 Set_Is_Known_Non_Null (Ent, False);
21735 end if;
21737 -- Follow renaming chain
21739 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
21740 and then Present (Renamed_Object (Ent))
21741 then
21742 Exp := Renamed_Object (Ent);
21744 -- If the entity is the loop variable in an iteration over
21745 -- a container, retrieve container expression to indicate
21746 -- possible modification.
21748 if Present (Related_Expression (Ent))
21749 and then Nkind (Parent (Related_Expression (Ent))) =
21750 N_Iterator_Specification
21751 then
21752 Exp := Original_Node (Related_Expression (Ent));
21753 end if;
21755 goto Continue;
21757 -- The expression may be the renaming of a subcomponent of an
21758 -- array or container. The assignment to the subcomponent is
21759 -- a modification of the container.
21761 elsif Comes_From_Source (Original_Node (Exp))
21762 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
21763 N_Indexed_Component)
21764 then
21765 Exp := Prefix (Original_Node (Exp));
21766 goto Continue;
21767 end if;
21769 -- Generate a reference only if the assignment comes from
21770 -- source. This excludes, for example, calls to a dispatching
21771 -- assignment operation when the left-hand side is tagged. In
21772 -- GNATprove mode, we need those references also on generated
21773 -- code, as these are used to compute the local effects of
21774 -- subprograms.
21776 if Modification_Comes_From_Source or GNATprove_Mode then
21777 Generate_Reference (Ent, Exp, 'm');
21779 -- If the target of the assignment is the bound variable
21780 -- in an iterator, indicate that the corresponding array
21781 -- or container is also modified.
21783 if Ada_Version >= Ada_2012
21784 and then Nkind (Parent (Ent)) = N_Iterator_Specification
21785 then
21786 declare
21787 Domain : constant Node_Id := Name (Parent (Ent));
21789 begin
21790 -- TBD : in the full version of the construct, the
21791 -- domain of iteration can be given by an expression.
21793 if Is_Entity_Name (Domain) then
21794 Generate_Reference (Entity (Domain), Exp, 'm');
21795 Set_Is_True_Constant (Entity (Domain), False);
21796 Set_Never_Set_In_Source (Entity (Domain), False);
21797 end if;
21798 end;
21799 end if;
21800 end if;
21801 end if;
21803 Kill_Checks (Ent);
21805 -- If we are sure this is a modification from source, and we know
21806 -- this modifies a constant, then give an appropriate warning.
21808 if Sure
21809 and then Modification_Comes_From_Source
21810 and then Overlays_Constant (Ent)
21811 and then Address_Clause_Overlay_Warnings
21812 then
21813 declare
21814 Addr : constant Node_Id := Address_Clause (Ent);
21815 O_Ent : Entity_Id;
21816 Off : Boolean;
21818 begin
21819 Find_Overlaid_Entity (Addr, O_Ent, Off);
21821 Error_Msg_Sloc := Sloc (Addr);
21822 Error_Msg_NE
21823 ("??constant& may be modified via address clause#",
21824 N, O_Ent);
21825 end;
21826 end if;
21828 return;
21829 end if;
21831 <<Continue>>
21832 null;
21833 end loop;
21834 end Note_Possible_Modification;
21836 -----------------
21837 -- Null_Status --
21838 -----------------
21840 function Null_Status (N : Node_Id) return Null_Status_Kind is
21841 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean;
21842 -- Determine whether definition Def carries a null exclusion
21844 function Null_Status_Of_Entity (Id : Entity_Id) return Null_Status_Kind;
21845 -- Determine the null status of arbitrary entity Id
21847 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind;
21848 -- Determine the null status of type Typ
21850 ---------------------------
21851 -- Is_Null_Excluding_Def --
21852 ---------------------------
21854 function Is_Null_Excluding_Def (Def : Node_Id) return Boolean is
21855 begin
21856 return
21857 Nkind_In (Def, N_Access_Definition,
21858 N_Access_Function_Definition,
21859 N_Access_Procedure_Definition,
21860 N_Access_To_Object_Definition,
21861 N_Component_Definition,
21862 N_Derived_Type_Definition)
21863 and then Null_Exclusion_Present (Def);
21864 end Is_Null_Excluding_Def;
21866 ---------------------------
21867 -- Null_Status_Of_Entity --
21868 ---------------------------
21870 function Null_Status_Of_Entity
21871 (Id : Entity_Id) return Null_Status_Kind
21873 Decl : constant Node_Id := Declaration_Node (Id);
21874 Def : Node_Id;
21876 begin
21877 -- The value of an imported or exported entity may be set externally
21878 -- regardless of a null exclusion. As a result, the value cannot be
21879 -- determined statically.
21881 if Is_Imported (Id) or else Is_Exported (Id) then
21882 return Unknown;
21884 elsif Nkind_In (Decl, N_Component_Declaration,
21885 N_Discriminant_Specification,
21886 N_Formal_Object_Declaration,
21887 N_Object_Declaration,
21888 N_Object_Renaming_Declaration,
21889 N_Parameter_Specification)
21890 then
21891 -- A component declaration yields a non-null value when either
21892 -- its component definition or access definition carries a null
21893 -- exclusion.
21895 if Nkind (Decl) = N_Component_Declaration then
21896 Def := Component_Definition (Decl);
21898 if Is_Null_Excluding_Def (Def) then
21899 return Is_Non_Null;
21900 end if;
21902 Def := Access_Definition (Def);
21904 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21905 return Is_Non_Null;
21906 end if;
21908 -- A formal object declaration yields a non-null value if its
21909 -- access definition carries a null exclusion. If the object is
21910 -- default initialized, then the value depends on the expression.
21912 elsif Nkind (Decl) = N_Formal_Object_Declaration then
21913 Def := Access_Definition (Decl);
21915 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21916 return Is_Non_Null;
21917 end if;
21919 -- A constant may yield a null or non-null value depending on its
21920 -- initialization expression.
21922 elsif Ekind (Id) = E_Constant then
21923 return Null_Status (Constant_Value (Id));
21925 -- The construct yields a non-null value when it has a null
21926 -- exclusion.
21928 elsif Null_Exclusion_Present (Decl) then
21929 return Is_Non_Null;
21931 -- An object renaming declaration yields a non-null value if its
21932 -- access definition carries a null exclusion. Otherwise the value
21933 -- depends on the renamed name.
21935 elsif Nkind (Decl) = N_Object_Renaming_Declaration then
21936 Def := Access_Definition (Decl);
21938 if Present (Def) and then Is_Null_Excluding_Def (Def) then
21939 return Is_Non_Null;
21941 else
21942 return Null_Status (Name (Decl));
21943 end if;
21944 end if;
21945 end if;
21947 -- At this point the declaration of the entity does not carry a null
21948 -- exclusion and lacks an initialization expression. Check the status
21949 -- of its type.
21951 return Null_Status_Of_Type (Etype (Id));
21952 end Null_Status_Of_Entity;
21954 -------------------------
21955 -- Null_Status_Of_Type --
21956 -------------------------
21958 function Null_Status_Of_Type (Typ : Entity_Id) return Null_Status_Kind is
21959 Curr : Entity_Id;
21960 Decl : Node_Id;
21962 begin
21963 -- Traverse the type chain looking for types with null exclusion
21965 Curr := Typ;
21966 while Present (Curr) and then Etype (Curr) /= Curr loop
21967 Decl := Parent (Curr);
21969 -- Guard against itypes which do not always have declarations. A
21970 -- type yields a non-null value if it carries a null exclusion.
21972 if Present (Decl) then
21973 if Nkind (Decl) = N_Full_Type_Declaration
21974 and then Is_Null_Excluding_Def (Type_Definition (Decl))
21975 then
21976 return Is_Non_Null;
21978 elsif Nkind (Decl) = N_Subtype_Declaration
21979 and then Null_Exclusion_Present (Decl)
21980 then
21981 return Is_Non_Null;
21982 end if;
21983 end if;
21985 Curr := Etype (Curr);
21986 end loop;
21988 -- The type chain does not contain any null excluding types
21990 return Unknown;
21991 end Null_Status_Of_Type;
21993 -- Start of processing for Null_Status
21995 begin
21996 -- An allocator always creates a non-null value
21998 if Nkind (N) = N_Allocator then
21999 return Is_Non_Null;
22001 -- Taking the 'Access of something yields a non-null value
22003 elsif Nkind (N) = N_Attribute_Reference
22004 and then Nam_In (Attribute_Name (N), Name_Access,
22005 Name_Unchecked_Access,
22006 Name_Unrestricted_Access)
22007 then
22008 return Is_Non_Null;
22010 -- "null" yields null
22012 elsif Nkind (N) = N_Null then
22013 return Is_Null;
22015 -- Check the status of the operand of a type conversion
22017 elsif Nkind (N) = N_Type_Conversion then
22018 return Null_Status (Expression (N));
22020 -- The input denotes a reference to an entity. Determine whether the
22021 -- entity or its type yields a null or non-null value.
22023 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
22024 return Null_Status_Of_Entity (Entity (N));
22025 end if;
22027 -- Otherwise it is not possible to determine the null status of the
22028 -- subexpression at compile time without resorting to simple flow
22029 -- analysis.
22031 return Unknown;
22032 end Null_Status;
22034 --------------------------------------
22035 -- Null_To_Null_Address_Convert_OK --
22036 --------------------------------------
22038 function Null_To_Null_Address_Convert_OK
22039 (N : Node_Id;
22040 Typ : Entity_Id := Empty) return Boolean
22042 begin
22043 if not Relaxed_RM_Semantics then
22044 return False;
22045 end if;
22047 if Nkind (N) = N_Null then
22048 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
22050 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
22051 then
22052 declare
22053 L : constant Node_Id := Left_Opnd (N);
22054 R : constant Node_Id := Right_Opnd (N);
22056 begin
22057 -- We check the Etype of the complementary operand since the
22058 -- N_Null node is not decorated at this stage.
22060 return
22061 ((Nkind (L) = N_Null
22062 and then Is_Descendant_Of_Address (Etype (R)))
22063 or else
22064 (Nkind (R) = N_Null
22065 and then Is_Descendant_Of_Address (Etype (L))));
22066 end;
22067 end if;
22069 return False;
22070 end Null_To_Null_Address_Convert_OK;
22072 ---------------------------------
22073 -- Number_Of_Elements_In_Array --
22074 ---------------------------------
22076 function Number_Of_Elements_In_Array (T : Entity_Id) return Int is
22077 Indx : Node_Id;
22078 Typ : Entity_Id;
22079 Low : Node_Id;
22080 High : Node_Id;
22081 Num : Int := 1;
22083 begin
22084 pragma Assert (Is_Array_Type (T));
22086 Indx := First_Index (T);
22087 while Present (Indx) loop
22088 Typ := Underlying_Type (Etype (Indx));
22090 -- Never look at junk bounds of a generic type
22092 if Is_Generic_Type (Typ) then
22093 return 0;
22094 end if;
22096 -- Check the array bounds are known at compile time and return zero
22097 -- if they are not.
22099 Low := Type_Low_Bound (Typ);
22100 High := Type_High_Bound (Typ);
22102 if not Compile_Time_Known_Value (Low) then
22103 return 0;
22104 elsif not Compile_Time_Known_Value (High) then
22105 return 0;
22106 else
22107 Num :=
22108 Num * UI_To_Int ((Expr_Value (High) - Expr_Value (Low) + 1));
22109 end if;
22111 Next_Index (Indx);
22112 end loop;
22114 return Num;
22115 end Number_Of_Elements_In_Array;
22117 -------------------------
22118 -- Object_Access_Level --
22119 -------------------------
22121 -- Returns the static accessibility level of the view denoted by Obj. Note
22122 -- that the value returned is the result of a call to Scope_Depth. Only
22123 -- scope depths associated with dynamic scopes can actually be returned.
22124 -- Since only relative levels matter for accessibility checking, the fact
22125 -- that the distance between successive levels of accessibility is not
22126 -- always one is immaterial (invariant: if level(E2) is deeper than
22127 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
22129 function Object_Access_Level (Obj : Node_Id) return Uint is
22130 function Is_Interface_Conversion (N : Node_Id) return Boolean;
22131 -- Determine whether N is a construct of the form
22132 -- Some_Type (Operand._tag'Address)
22133 -- This construct appears in the context of dispatching calls.
22135 function Reference_To (Obj : Node_Id) return Node_Id;
22136 -- An explicit dereference is created when removing side effects from
22137 -- expressions for constraint checking purposes. In this case a local
22138 -- access type is created for it. The correct access level is that of
22139 -- the original source node. We detect this case by noting that the
22140 -- prefix of the dereference is created by an object declaration whose
22141 -- initial expression is a reference.
22143 -----------------------------
22144 -- Is_Interface_Conversion --
22145 -----------------------------
22147 function Is_Interface_Conversion (N : Node_Id) return Boolean is
22148 begin
22149 return Nkind (N) = N_Unchecked_Type_Conversion
22150 and then Nkind (Expression (N)) = N_Attribute_Reference
22151 and then Attribute_Name (Expression (N)) = Name_Address;
22152 end Is_Interface_Conversion;
22154 ------------------
22155 -- Reference_To --
22156 ------------------
22158 function Reference_To (Obj : Node_Id) return Node_Id is
22159 Pref : constant Node_Id := Prefix (Obj);
22160 begin
22161 if Is_Entity_Name (Pref)
22162 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
22163 and then Present (Expression (Parent (Entity (Pref))))
22164 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
22165 then
22166 return (Prefix (Expression (Parent (Entity (Pref)))));
22167 else
22168 return Empty;
22169 end if;
22170 end Reference_To;
22172 -- Local variables
22174 E : Entity_Id;
22176 -- Start of processing for Object_Access_Level
22178 begin
22179 if Nkind (Obj) = N_Defining_Identifier
22180 or else Is_Entity_Name (Obj)
22181 then
22182 if Nkind (Obj) = N_Defining_Identifier then
22183 E := Obj;
22184 else
22185 E := Entity (Obj);
22186 end if;
22188 if Is_Prival (E) then
22189 E := Prival_Link (E);
22190 end if;
22192 -- If E is a type then it denotes a current instance. For this case
22193 -- we add one to the normal accessibility level of the type to ensure
22194 -- that current instances are treated as always being deeper than
22195 -- than the level of any visible named access type (see 3.10.2(21)).
22197 if Is_Type (E) then
22198 return Type_Access_Level (E) + 1;
22200 elsif Present (Renamed_Object (E)) then
22201 return Object_Access_Level (Renamed_Object (E));
22203 -- Similarly, if E is a component of the current instance of a
22204 -- protected type, any instance of it is assumed to be at a deeper
22205 -- level than the type. For a protected object (whose type is an
22206 -- anonymous protected type) its components are at the same level
22207 -- as the type itself.
22209 elsif not Is_Overloadable (E)
22210 and then Ekind (Scope (E)) = E_Protected_Type
22211 and then Comes_From_Source (Scope (E))
22212 then
22213 return Type_Access_Level (Scope (E)) + 1;
22215 else
22216 -- Aliased formals of functions take their access level from the
22217 -- point of call, i.e. require a dynamic check. For static check
22218 -- purposes, this is smaller than the level of the subprogram
22219 -- itself. For procedures the aliased makes no difference.
22221 if Is_Formal (E)
22222 and then Is_Aliased (E)
22223 and then Ekind (Scope (E)) = E_Function
22224 then
22225 return Type_Access_Level (Etype (E));
22227 else
22228 return Scope_Depth (Enclosing_Dynamic_Scope (E));
22229 end if;
22230 end if;
22232 elsif Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
22233 if Is_Access_Type (Etype (Prefix (Obj))) then
22234 return Type_Access_Level (Etype (Prefix (Obj)));
22235 else
22236 return Object_Access_Level (Prefix (Obj));
22237 end if;
22239 elsif Nkind (Obj) = N_Explicit_Dereference then
22241 -- If the prefix is a selected access discriminant then we make a
22242 -- recursive call on the prefix, which will in turn check the level
22243 -- of the prefix object of the selected discriminant.
22245 -- In Ada 2012, if the discriminant has implicit dereference and
22246 -- the context is a selected component, treat this as an object of
22247 -- unknown scope (see below). This is necessary in compile-only mode;
22248 -- otherwise expansion will already have transformed the prefix into
22249 -- a temporary.
22251 if Nkind (Prefix (Obj)) = N_Selected_Component
22252 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
22253 and then
22254 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
22255 and then
22256 (not Has_Implicit_Dereference
22257 (Entity (Selector_Name (Prefix (Obj))))
22258 or else Nkind (Parent (Obj)) /= N_Selected_Component)
22259 then
22260 return Object_Access_Level (Prefix (Obj));
22262 -- Detect an interface conversion in the context of a dispatching
22263 -- call. Use the original form of the conversion to find the access
22264 -- level of the operand.
22266 elsif Is_Interface (Etype (Obj))
22267 and then Is_Interface_Conversion (Prefix (Obj))
22268 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
22269 then
22270 return Object_Access_Level (Original_Node (Obj));
22272 elsif not Comes_From_Source (Obj) then
22273 declare
22274 Ref : constant Node_Id := Reference_To (Obj);
22275 begin
22276 if Present (Ref) then
22277 return Object_Access_Level (Ref);
22278 else
22279 return Type_Access_Level (Etype (Prefix (Obj)));
22280 end if;
22281 end;
22283 else
22284 return Type_Access_Level (Etype (Prefix (Obj)));
22285 end if;
22287 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
22288 return Object_Access_Level (Expression (Obj));
22290 elsif Nkind (Obj) = N_Function_Call then
22292 -- Function results are objects, so we get either the access level of
22293 -- the function or, in the case of an indirect call, the level of the
22294 -- access-to-subprogram type. (This code is used for Ada 95, but it
22295 -- looks wrong, because it seems that we should be checking the level
22296 -- of the call itself, even for Ada 95. However, using the Ada 2005
22297 -- version of the code causes regressions in several tests that are
22298 -- compiled with -gnat95. ???)
22300 if Ada_Version < Ada_2005 then
22301 if Is_Entity_Name (Name (Obj)) then
22302 return Subprogram_Access_Level (Entity (Name (Obj)));
22303 else
22304 return Type_Access_Level (Etype (Prefix (Name (Obj))));
22305 end if;
22307 -- For Ada 2005, the level of the result object of a function call is
22308 -- defined to be the level of the call's innermost enclosing master.
22309 -- We determine that by querying the depth of the innermost enclosing
22310 -- dynamic scope.
22312 else
22313 Return_Master_Scope_Depth_Of_Call : declare
22314 function Innermost_Master_Scope_Depth
22315 (N : Node_Id) return Uint;
22316 -- Returns the scope depth of the given node's innermost
22317 -- enclosing dynamic scope (effectively the accessibility
22318 -- level of the innermost enclosing master).
22320 ----------------------------------
22321 -- Innermost_Master_Scope_Depth --
22322 ----------------------------------
22324 function Innermost_Master_Scope_Depth
22325 (N : Node_Id) return Uint
22327 Node_Par : Node_Id := Parent (N);
22329 begin
22330 -- Locate the nearest enclosing node (by traversing Parents)
22331 -- that Defining_Entity can be applied to, and return the
22332 -- depth of that entity's nearest enclosing dynamic scope.
22334 while Present (Node_Par) loop
22335 case Nkind (Node_Par) is
22336 when N_Abstract_Subprogram_Declaration
22337 | N_Block_Statement
22338 | N_Body_Stub
22339 | N_Component_Declaration
22340 | N_Entry_Body
22341 | N_Entry_Declaration
22342 | N_Exception_Declaration
22343 | N_Formal_Object_Declaration
22344 | N_Formal_Package_Declaration
22345 | N_Formal_Subprogram_Declaration
22346 | N_Formal_Type_Declaration
22347 | N_Full_Type_Declaration
22348 | N_Function_Specification
22349 | N_Generic_Declaration
22350 | N_Generic_Instantiation
22351 | N_Implicit_Label_Declaration
22352 | N_Incomplete_Type_Declaration
22353 | N_Loop_Parameter_Specification
22354 | N_Number_Declaration
22355 | N_Object_Declaration
22356 | N_Package_Declaration
22357 | N_Package_Specification
22358 | N_Parameter_Specification
22359 | N_Private_Extension_Declaration
22360 | N_Private_Type_Declaration
22361 | N_Procedure_Specification
22362 | N_Proper_Body
22363 | N_Protected_Type_Declaration
22364 | N_Renaming_Declaration
22365 | N_Single_Protected_Declaration
22366 | N_Single_Task_Declaration
22367 | N_Subprogram_Declaration
22368 | N_Subtype_Declaration
22369 | N_Subunit
22370 | N_Task_Type_Declaration
22372 return Scope_Depth
22373 (Nearest_Dynamic_Scope
22374 (Defining_Entity (Node_Par)));
22376 -- For a return statement within a function, return
22377 -- the depth of the function itself. This is not just
22378 -- a small optimization, but matters when analyzing
22379 -- the expression in an expression function before
22380 -- the body is created.
22382 when N_Simple_Return_Statement =>
22383 if Ekind (Current_Scope) = E_Function then
22384 return Scope_Depth (Current_Scope);
22385 end if;
22387 when others =>
22388 null;
22389 end case;
22391 Node_Par := Parent (Node_Par);
22392 end loop;
22394 pragma Assert (False);
22396 -- Should never reach the following return
22398 return Scope_Depth (Current_Scope) + 1;
22399 end Innermost_Master_Scope_Depth;
22401 -- Start of processing for Return_Master_Scope_Depth_Of_Call
22403 begin
22404 return Innermost_Master_Scope_Depth (Obj);
22405 end Return_Master_Scope_Depth_Of_Call;
22406 end if;
22408 -- For convenience we handle qualified expressions, even though they
22409 -- aren't technically object names.
22411 elsif Nkind (Obj) = N_Qualified_Expression then
22412 return Object_Access_Level (Expression (Obj));
22414 -- Ditto for aggregates. They have the level of the temporary that
22415 -- will hold their value.
22417 elsif Nkind (Obj) = N_Aggregate then
22418 return Object_Access_Level (Current_Scope);
22420 -- Otherwise return the scope level of Standard. (If there are cases
22421 -- that fall through to this point they will be treated as having
22422 -- global accessibility for now. ???)
22424 else
22425 return Scope_Depth (Standard_Standard);
22426 end if;
22427 end Object_Access_Level;
22429 ----------------------------------
22430 -- Old_Requires_Transient_Scope --
22431 ----------------------------------
22433 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
22434 Typ : constant Entity_Id := Underlying_Type (Id);
22436 begin
22437 -- This is a private type which is not completed yet. This can only
22438 -- happen in a default expression (of a formal parameter or of a
22439 -- record component). Do not expand transient scope in this case.
22441 if No (Typ) then
22442 return False;
22444 -- Do not expand transient scope for non-existent procedure return
22446 elsif Typ = Standard_Void_Type then
22447 return False;
22449 -- Elementary types do not require a transient scope
22451 elsif Is_Elementary_Type (Typ) then
22452 return False;
22454 -- Generally, indefinite subtypes require a transient scope, since the
22455 -- back end cannot generate temporaries, since this is not a valid type
22456 -- for declaring an object. It might be possible to relax this in the
22457 -- future, e.g. by declaring the maximum possible space for the type.
22459 elsif not Is_Definite_Subtype (Typ) then
22460 return True;
22462 -- Functions returning tagged types may dispatch on result so their
22463 -- returned value is allocated on the secondary stack. Controlled
22464 -- type temporaries need finalization.
22466 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
22467 return True;
22469 -- Record type
22471 elsif Is_Record_Type (Typ) then
22472 declare
22473 Comp : Entity_Id;
22475 begin
22476 Comp := First_Entity (Typ);
22477 while Present (Comp) loop
22478 if Ekind (Comp) = E_Component then
22480 -- ???It's not clear we need a full recursive call to
22481 -- Old_Requires_Transient_Scope here. Note that the
22482 -- following can't happen.
22484 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
22485 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
22487 if Old_Requires_Transient_Scope (Etype (Comp)) then
22488 return True;
22489 end if;
22490 end if;
22492 Next_Entity (Comp);
22493 end loop;
22494 end;
22496 return False;
22498 -- String literal types never require transient scope
22500 elsif Ekind (Typ) = E_String_Literal_Subtype then
22501 return False;
22503 -- Array type. Note that we already know that this is a constrained
22504 -- array, since unconstrained arrays will fail the indefinite test.
22506 elsif Is_Array_Type (Typ) then
22508 -- If component type requires a transient scope, the array does too
22510 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
22511 return True;
22513 -- Otherwise, we only need a transient scope if the size depends on
22514 -- the value of one or more discriminants.
22516 else
22517 return Size_Depends_On_Discriminant (Typ);
22518 end if;
22520 -- All other cases do not require a transient scope
22522 else
22523 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
22524 return False;
22525 end if;
22526 end Old_Requires_Transient_Scope;
22528 ---------------------------------
22529 -- Original_Aspect_Pragma_Name --
22530 ---------------------------------
22532 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
22533 Item : Node_Id;
22534 Item_Nam : Name_Id;
22536 begin
22537 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
22539 Item := N;
22541 -- The pragma was generated to emulate an aspect, use the original
22542 -- aspect specification.
22544 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
22545 Item := Corresponding_Aspect (Item);
22546 end if;
22548 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
22549 -- Post and Post_Class rewrite their pragma identifier to preserve the
22550 -- original name.
22551 -- ??? this is kludgey
22553 if Nkind (Item) = N_Pragma then
22554 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
22556 else
22557 pragma Assert (Nkind (Item) = N_Aspect_Specification);
22558 Item_Nam := Chars (Identifier (Item));
22559 end if;
22561 -- Deal with 'Class by converting the name to its _XXX form
22563 if Class_Present (Item) then
22564 if Item_Nam = Name_Invariant then
22565 Item_Nam := Name_uInvariant;
22567 elsif Item_Nam = Name_Post then
22568 Item_Nam := Name_uPost;
22570 elsif Item_Nam = Name_Pre then
22571 Item_Nam := Name_uPre;
22573 elsif Nam_In (Item_Nam, Name_Type_Invariant,
22574 Name_Type_Invariant_Class)
22575 then
22576 Item_Nam := Name_uType_Invariant;
22578 -- Nothing to do for other cases (e.g. a Check that derived from
22579 -- Pre_Class and has the flag set). Also we do nothing if the name
22580 -- is already in special _xxx form.
22582 end if;
22583 end if;
22585 return Item_Nam;
22586 end Original_Aspect_Pragma_Name;
22588 --------------------------------------
22589 -- Original_Corresponding_Operation --
22590 --------------------------------------
22592 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
22594 Typ : constant Entity_Id := Find_Dispatching_Type (S);
22596 begin
22597 -- If S is an inherited primitive S2 the original corresponding
22598 -- operation of S is the original corresponding operation of S2
22600 if Present (Alias (S))
22601 and then Find_Dispatching_Type (Alias (S)) /= Typ
22602 then
22603 return Original_Corresponding_Operation (Alias (S));
22605 -- If S overrides an inherited subprogram S2 the original corresponding
22606 -- operation of S is the original corresponding operation of S2
22608 elsif Present (Overridden_Operation (S)) then
22609 return Original_Corresponding_Operation (Overridden_Operation (S));
22611 -- otherwise it is S itself
22613 else
22614 return S;
22615 end if;
22616 end Original_Corresponding_Operation;
22618 -------------------
22619 -- Output_Entity --
22620 -------------------
22622 procedure Output_Entity (Id : Entity_Id) is
22623 Scop : Entity_Id;
22625 begin
22626 Scop := Scope (Id);
22628 -- The entity may lack a scope when it is in the process of being
22629 -- analyzed. Use the current scope as an approximation.
22631 if No (Scop) then
22632 Scop := Current_Scope;
22633 end if;
22635 Output_Name (Chars (Id), Scop);
22636 end Output_Entity;
22638 -----------------
22639 -- Output_Name --
22640 -----------------
22642 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
22643 begin
22644 Write_Str
22645 (Get_Name_String
22646 (Get_Qualified_Name
22647 (Nam => Nam,
22648 Suffix => No_Name,
22649 Scop => Scop)));
22650 Write_Eol;
22651 end Output_Name;
22653 ----------------------
22654 -- Policy_In_Effect --
22655 ----------------------
22657 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
22658 function Policy_In_List (List : Node_Id) return Name_Id;
22659 -- Determine the mode of a policy in a N_Pragma list
22661 --------------------
22662 -- Policy_In_List --
22663 --------------------
22665 function Policy_In_List (List : Node_Id) return Name_Id is
22666 Arg1 : Node_Id;
22667 Arg2 : Node_Id;
22668 Prag : Node_Id;
22670 begin
22671 Prag := List;
22672 while Present (Prag) loop
22673 Arg1 := First (Pragma_Argument_Associations (Prag));
22674 Arg2 := Next (Arg1);
22676 Arg1 := Get_Pragma_Arg (Arg1);
22677 Arg2 := Get_Pragma_Arg (Arg2);
22679 -- The current Check_Policy pragma matches the requested policy or
22680 -- appears in the single argument form (Assertion, policy_id).
22682 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
22683 return Chars (Arg2);
22684 end if;
22686 Prag := Next_Pragma (Prag);
22687 end loop;
22689 return No_Name;
22690 end Policy_In_List;
22692 -- Local variables
22694 Kind : Name_Id;
22696 -- Start of processing for Policy_In_Effect
22698 begin
22699 if not Is_Valid_Assertion_Kind (Policy) then
22700 raise Program_Error;
22701 end if;
22703 -- Inspect all policy pragmas that appear within scopes (if any)
22705 Kind := Policy_In_List (Check_Policy_List);
22707 -- Inspect all configuration policy pragmas (if any)
22709 if Kind = No_Name then
22710 Kind := Policy_In_List (Check_Policy_List_Config);
22711 end if;
22713 -- The context lacks policy pragmas, determine the mode based on whether
22714 -- assertions are enabled at the configuration level. This ensures that
22715 -- the policy is preserved when analyzing generics.
22717 if Kind = No_Name then
22718 if Assertions_Enabled_Config then
22719 Kind := Name_Check;
22720 else
22721 Kind := Name_Ignore;
22722 end if;
22723 end if;
22725 -- In CodePeer mode and GNATprove mode, we need to consider all
22726 -- assertions, unless they are disabled. Force Name_Check on
22727 -- ignored assertions.
22729 if Nam_In (Kind, Name_Ignore, Name_Off)
22730 and then (CodePeer_Mode or GNATprove_Mode)
22731 then
22732 Kind := Name_Check;
22733 end if;
22735 return Kind;
22736 end Policy_In_Effect;
22738 ----------------------------------
22739 -- Predicate_Tests_On_Arguments --
22740 ----------------------------------
22742 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
22743 begin
22744 -- Always test predicates on indirect call
22746 if Ekind (Subp) = E_Subprogram_Type then
22747 return True;
22749 -- Do not test predicates on call to generated default Finalize, since
22750 -- we are not interested in whether something we are finalizing (and
22751 -- typically destroying) satisfies its predicates.
22753 elsif Chars (Subp) = Name_Finalize
22754 and then not Comes_From_Source (Subp)
22755 then
22756 return False;
22758 -- Do not test predicates on any internally generated routines
22760 elsif Is_Internal_Name (Chars (Subp)) then
22761 return False;
22763 -- Do not test predicates on call to Init_Proc, since if needed the
22764 -- predicate test will occur at some other point.
22766 elsif Is_Init_Proc (Subp) then
22767 return False;
22769 -- Do not test predicates on call to predicate function, since this
22770 -- would cause infinite recursion.
22772 elsif Ekind (Subp) = E_Function
22773 and then (Is_Predicate_Function (Subp)
22774 or else
22775 Is_Predicate_Function_M (Subp))
22776 then
22777 return False;
22779 -- For now, no other exceptions
22781 else
22782 return True;
22783 end if;
22784 end Predicate_Tests_On_Arguments;
22786 -----------------------
22787 -- Private_Component --
22788 -----------------------
22790 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
22791 Ancestor : constant Entity_Id := Base_Type (Type_Id);
22793 function Trace_Components
22794 (T : Entity_Id;
22795 Check : Boolean) return Entity_Id;
22796 -- Recursive function that does the work, and checks against circular
22797 -- definition for each subcomponent type.
22799 ----------------------
22800 -- Trace_Components --
22801 ----------------------
22803 function Trace_Components
22804 (T : Entity_Id;
22805 Check : Boolean) return Entity_Id
22807 Btype : constant Entity_Id := Base_Type (T);
22808 Component : Entity_Id;
22809 P : Entity_Id;
22810 Candidate : Entity_Id := Empty;
22812 begin
22813 if Check and then Btype = Ancestor then
22814 Error_Msg_N ("circular type definition", Type_Id);
22815 return Any_Type;
22816 end if;
22818 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
22819 if Present (Full_View (Btype))
22820 and then Is_Record_Type (Full_View (Btype))
22821 and then not Is_Frozen (Btype)
22822 then
22823 -- To indicate that the ancestor depends on a private type, the
22824 -- current Btype is sufficient. However, to check for circular
22825 -- definition we must recurse on the full view.
22827 Candidate := Trace_Components (Full_View (Btype), True);
22829 if Candidate = Any_Type then
22830 return Any_Type;
22831 else
22832 return Btype;
22833 end if;
22835 else
22836 return Btype;
22837 end if;
22839 elsif Is_Array_Type (Btype) then
22840 return Trace_Components (Component_Type (Btype), True);
22842 elsif Is_Record_Type (Btype) then
22843 Component := First_Entity (Btype);
22844 while Present (Component)
22845 and then Comes_From_Source (Component)
22846 loop
22847 -- Skip anonymous types generated by constrained components
22849 if not Is_Type (Component) then
22850 P := Trace_Components (Etype (Component), True);
22852 if Present (P) then
22853 if P = Any_Type then
22854 return P;
22855 else
22856 Candidate := P;
22857 end if;
22858 end if;
22859 end if;
22861 Next_Entity (Component);
22862 end loop;
22864 return Candidate;
22866 else
22867 return Empty;
22868 end if;
22869 end Trace_Components;
22871 -- Start of processing for Private_Component
22873 begin
22874 return Trace_Components (Type_Id, False);
22875 end Private_Component;
22877 ---------------------------
22878 -- Primitive_Names_Match --
22879 ---------------------------
22881 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
22882 function Non_Internal_Name (E : Entity_Id) return Name_Id;
22883 -- Given an internal name, returns the corresponding non-internal name
22885 ------------------------
22886 -- Non_Internal_Name --
22887 ------------------------
22889 function Non_Internal_Name (E : Entity_Id) return Name_Id is
22890 begin
22891 Get_Name_String (Chars (E));
22892 Name_Len := Name_Len - 1;
22893 return Name_Find;
22894 end Non_Internal_Name;
22896 -- Start of processing for Primitive_Names_Match
22898 begin
22899 pragma Assert (Present (E1) and then Present (E2));
22901 return Chars (E1) = Chars (E2)
22902 or else
22903 (not Is_Internal_Name (Chars (E1))
22904 and then Is_Internal_Name (Chars (E2))
22905 and then Non_Internal_Name (E2) = Chars (E1))
22906 or else
22907 (not Is_Internal_Name (Chars (E2))
22908 and then Is_Internal_Name (Chars (E1))
22909 and then Non_Internal_Name (E1) = Chars (E2))
22910 or else
22911 (Is_Predefined_Dispatching_Operation (E1)
22912 and then Is_Predefined_Dispatching_Operation (E2)
22913 and then Same_TSS (E1, E2))
22914 or else
22915 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
22916 end Primitive_Names_Match;
22918 -----------------------
22919 -- Process_End_Label --
22920 -----------------------
22922 procedure Process_End_Label
22923 (N : Node_Id;
22924 Typ : Character;
22925 Ent : Entity_Id)
22927 Loc : Source_Ptr;
22928 Nam : Node_Id;
22929 Scop : Entity_Id;
22931 Label_Ref : Boolean;
22932 -- Set True if reference to end label itself is required
22934 Endl : Node_Id;
22935 -- Gets set to the operator symbol or identifier that references the
22936 -- entity Ent. For the child unit case, this is the identifier from the
22937 -- designator. For other cases, this is simply Endl.
22939 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
22940 -- N is an identifier node that appears as a parent unit reference in
22941 -- the case where Ent is a child unit. This procedure generates an
22942 -- appropriate cross-reference entry. E is the corresponding entity.
22944 -------------------------
22945 -- Generate_Parent_Ref --
22946 -------------------------
22948 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
22949 begin
22950 -- If names do not match, something weird, skip reference
22952 if Chars (E) = Chars (N) then
22954 -- Generate the reference. We do NOT consider this as a reference
22955 -- for unreferenced symbol purposes.
22957 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
22959 if Style_Check then
22960 Style.Check_Identifier (N, E);
22961 end if;
22962 end if;
22963 end Generate_Parent_Ref;
22965 -- Start of processing for Process_End_Label
22967 begin
22968 -- If no node, ignore. This happens in some error situations, and
22969 -- also for some internally generated structures where no end label
22970 -- references are required in any case.
22972 if No (N) then
22973 return;
22974 end if;
22976 -- Nothing to do if no End_Label, happens for internally generated
22977 -- constructs where we don't want an end label reference anyway. Also
22978 -- nothing to do if Endl is a string literal, which means there was
22979 -- some prior error (bad operator symbol)
22981 Endl := End_Label (N);
22983 if No (Endl) or else Nkind (Endl) = N_String_Literal then
22984 return;
22985 end if;
22987 -- Reference node is not in extended main source unit
22989 if not In_Extended_Main_Source_Unit (N) then
22991 -- Generally we do not collect references except for the extended
22992 -- main source unit. The one exception is the 'e' entry for a
22993 -- package spec, where it is useful for a client to have the
22994 -- ending information to define scopes.
22996 if Typ /= 'e' then
22997 return;
22999 else
23000 Label_Ref := False;
23002 -- For this case, we can ignore any parent references, but we
23003 -- need the package name itself for the 'e' entry.
23005 if Nkind (Endl) = N_Designator then
23006 Endl := Identifier (Endl);
23007 end if;
23008 end if;
23010 -- Reference is in extended main source unit
23012 else
23013 Label_Ref := True;
23015 -- For designator, generate references for the parent entries
23017 if Nkind (Endl) = N_Designator then
23019 -- Generate references for the prefix if the END line comes from
23020 -- source (otherwise we do not need these references) We climb the
23021 -- scope stack to find the expected entities.
23023 if Comes_From_Source (Endl) then
23024 Nam := Name (Endl);
23025 Scop := Current_Scope;
23026 while Nkind (Nam) = N_Selected_Component loop
23027 Scop := Scope (Scop);
23028 exit when No (Scop);
23029 Generate_Parent_Ref (Selector_Name (Nam), Scop);
23030 Nam := Prefix (Nam);
23031 end loop;
23033 if Present (Scop) then
23034 Generate_Parent_Ref (Nam, Scope (Scop));
23035 end if;
23036 end if;
23038 Endl := Identifier (Endl);
23039 end if;
23040 end if;
23042 -- If the end label is not for the given entity, then either we have
23043 -- some previous error, or this is a generic instantiation for which
23044 -- we do not need to make a cross-reference in this case anyway. In
23045 -- either case we simply ignore the call.
23047 if Chars (Ent) /= Chars (Endl) then
23048 return;
23049 end if;
23051 -- If label was really there, then generate a normal reference and then
23052 -- adjust the location in the end label to point past the name (which
23053 -- should almost always be the semicolon).
23055 Loc := Sloc (Endl);
23057 if Comes_From_Source (Endl) then
23059 -- If a label reference is required, then do the style check and
23060 -- generate an l-type cross-reference entry for the label
23062 if Label_Ref then
23063 if Style_Check then
23064 Style.Check_Identifier (Endl, Ent);
23065 end if;
23067 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
23068 end if;
23070 -- Set the location to point past the label (normally this will
23071 -- mean the semicolon immediately following the label). This is
23072 -- done for the sake of the 'e' or 't' entry generated below.
23074 Get_Decoded_Name_String (Chars (Endl));
23075 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
23077 else
23078 -- In SPARK mode, no missing label is allowed for packages and
23079 -- subprogram bodies. Detect those cases by testing whether
23080 -- Process_End_Label was called for a body (Typ = 't') or a package.
23082 if Restriction_Check_Required (SPARK_05)
23083 and then (Typ = 't' or else Ekind (Ent) = E_Package)
23084 then
23085 Error_Msg_Node_1 := Endl;
23086 Check_SPARK_05_Restriction
23087 ("`END &` required", Endl, Force => True);
23088 end if;
23089 end if;
23091 -- Now generate the e/t reference
23093 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
23095 -- Restore Sloc, in case modified above, since we have an identifier
23096 -- and the normal Sloc should be left set in the tree.
23098 Set_Sloc (Endl, Loc);
23099 end Process_End_Label;
23101 --------------------------------
23102 -- Propagate_Concurrent_Flags --
23103 --------------------------------
23105 procedure Propagate_Concurrent_Flags
23106 (Typ : Entity_Id;
23107 Comp_Typ : Entity_Id)
23109 begin
23110 if Has_Task (Comp_Typ) then
23111 Set_Has_Task (Typ);
23112 end if;
23114 if Has_Protected (Comp_Typ) then
23115 Set_Has_Protected (Typ);
23116 end if;
23118 if Has_Timing_Event (Comp_Typ) then
23119 Set_Has_Timing_Event (Typ);
23120 end if;
23121 end Propagate_Concurrent_Flags;
23123 ------------------------------
23124 -- Propagate_DIC_Attributes --
23125 ------------------------------
23127 procedure Propagate_DIC_Attributes
23128 (Typ : Entity_Id;
23129 From_Typ : Entity_Id)
23131 DIC_Proc : Entity_Id;
23133 begin
23134 if Present (Typ) and then Present (From_Typ) then
23135 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23137 -- Nothing to do if both the source and the destination denote the
23138 -- same type.
23140 if From_Typ = Typ then
23141 return;
23142 end if;
23144 DIC_Proc := DIC_Procedure (From_Typ);
23146 -- The setting of the attributes is intentionally conservative. This
23147 -- prevents accidental clobbering of enabled attributes.
23149 if Has_Inherited_DIC (From_Typ)
23150 and then not Has_Inherited_DIC (Typ)
23151 then
23152 Set_Has_Inherited_DIC (Typ);
23153 end if;
23155 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
23156 Set_Has_Own_DIC (Typ);
23157 end if;
23159 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
23160 Set_DIC_Procedure (Typ, DIC_Proc);
23161 end if;
23162 end if;
23163 end Propagate_DIC_Attributes;
23165 ------------------------------------
23166 -- Propagate_Invariant_Attributes --
23167 ------------------------------------
23169 procedure Propagate_Invariant_Attributes
23170 (Typ : Entity_Id;
23171 From_Typ : Entity_Id)
23173 Full_IP : Entity_Id;
23174 Part_IP : Entity_Id;
23176 begin
23177 if Present (Typ) and then Present (From_Typ) then
23178 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
23180 -- Nothing to do if both the source and the destination denote the
23181 -- same type.
23183 if From_Typ = Typ then
23184 return;
23185 end if;
23187 Full_IP := Invariant_Procedure (From_Typ);
23188 Part_IP := Partial_Invariant_Procedure (From_Typ);
23190 -- The setting of the attributes is intentionally conservative. This
23191 -- prevents accidental clobbering of enabled attributes.
23193 if Has_Inheritable_Invariants (From_Typ)
23194 and then not Has_Inheritable_Invariants (Typ)
23195 then
23196 Set_Has_Inheritable_Invariants (Typ);
23197 end if;
23199 if Has_Inherited_Invariants (From_Typ)
23200 and then not Has_Inherited_Invariants (Typ)
23201 then
23202 Set_Has_Inherited_Invariants (Typ);
23203 end if;
23205 if Has_Own_Invariants (From_Typ)
23206 and then not Has_Own_Invariants (Typ)
23207 then
23208 Set_Has_Own_Invariants (Typ);
23209 end if;
23211 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
23212 Set_Invariant_Procedure (Typ, Full_IP);
23213 end if;
23215 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
23216 then
23217 Set_Partial_Invariant_Procedure (Typ, Part_IP);
23218 end if;
23219 end if;
23220 end Propagate_Invariant_Attributes;
23222 ---------------------------------------
23223 -- Record_Possible_Part_Of_Reference --
23224 ---------------------------------------
23226 procedure Record_Possible_Part_Of_Reference
23227 (Var_Id : Entity_Id;
23228 Ref : Node_Id)
23230 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
23231 Refs : Elist_Id;
23233 begin
23234 -- The variable is a constituent of a single protected/task type. Such
23235 -- a variable acts as a component of the type and must appear within a
23236 -- specific region (SPARK RM 9(3)). Instead of recording the reference,
23237 -- verify its legality now.
23239 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
23240 Check_Part_Of_Reference (Var_Id, Ref);
23242 -- The variable is subject to pragma Part_Of and may eventually become a
23243 -- constituent of a single protected/task type. Record the reference to
23244 -- verify its placement when the contract of the variable is analyzed.
23246 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
23247 Refs := Part_Of_References (Var_Id);
23249 if No (Refs) then
23250 Refs := New_Elmt_List;
23251 Set_Part_Of_References (Var_Id, Refs);
23252 end if;
23254 Append_Elmt (Ref, Refs);
23255 end if;
23256 end Record_Possible_Part_Of_Reference;
23258 ----------------
23259 -- Referenced --
23260 ----------------
23262 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
23263 Seen : Boolean := False;
23265 function Is_Reference (N : Node_Id) return Traverse_Result;
23266 -- Determine whether node N denotes a reference to Id. If this is the
23267 -- case, set global flag Seen to True and stop the traversal.
23269 ------------------
23270 -- Is_Reference --
23271 ------------------
23273 function Is_Reference (N : Node_Id) return Traverse_Result is
23274 begin
23275 if Is_Entity_Name (N)
23276 and then Present (Entity (N))
23277 and then Entity (N) = Id
23278 then
23279 Seen := True;
23280 return Abandon;
23281 else
23282 return OK;
23283 end if;
23284 end Is_Reference;
23286 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
23288 -- Start of processing for Referenced
23290 begin
23291 Inspect_Expression (Expr);
23292 return Seen;
23293 end Referenced;
23295 ------------------------------------
23296 -- References_Generic_Formal_Type --
23297 ------------------------------------
23299 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
23301 function Process (N : Node_Id) return Traverse_Result;
23302 -- Process one node in search for generic formal type
23304 -------------
23305 -- Process --
23306 -------------
23308 function Process (N : Node_Id) return Traverse_Result is
23309 begin
23310 if Nkind (N) in N_Has_Entity then
23311 declare
23312 E : constant Entity_Id := Entity (N);
23313 begin
23314 if Present (E) then
23315 if Is_Generic_Type (E) then
23316 return Abandon;
23317 elsif Present (Etype (E))
23318 and then Is_Generic_Type (Etype (E))
23319 then
23320 return Abandon;
23321 end if;
23322 end if;
23323 end;
23324 end if;
23326 return Atree.OK;
23327 end Process;
23329 function Traverse is new Traverse_Func (Process);
23330 -- Traverse tree to look for generic type
23332 begin
23333 if Inside_A_Generic then
23334 return Traverse (N) = Abandon;
23335 else
23336 return False;
23337 end if;
23338 end References_Generic_Formal_Type;
23340 -------------------------------
23341 -- Remove_Entity_And_Homonym --
23342 -------------------------------
23344 procedure Remove_Entity_And_Homonym (Id : Entity_Id) is
23345 begin
23346 Remove_Entity (Id);
23347 Remove_Homonym (Id);
23348 end Remove_Entity_And_Homonym;
23350 --------------------
23351 -- Remove_Homonym --
23352 --------------------
23354 procedure Remove_Homonym (Id : Entity_Id) is
23355 Hom : Entity_Id;
23356 Prev : Entity_Id := Empty;
23358 begin
23359 if Id = Current_Entity (Id) then
23360 if Present (Homonym (Id)) then
23361 Set_Current_Entity (Homonym (Id));
23362 else
23363 Set_Name_Entity_Id (Chars (Id), Empty);
23364 end if;
23366 else
23367 Hom := Current_Entity (Id);
23368 while Present (Hom) and then Hom /= Id loop
23369 Prev := Hom;
23370 Hom := Homonym (Hom);
23371 end loop;
23373 -- If Id is not on the homonym chain, nothing to do
23375 if Present (Hom) then
23376 Set_Homonym (Prev, Homonym (Id));
23377 end if;
23378 end if;
23379 end Remove_Homonym;
23381 ------------------------------
23382 -- Remove_Overloaded_Entity --
23383 ------------------------------
23385 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
23386 procedure Remove_Primitive_Of (Typ : Entity_Id);
23387 -- Remove primitive subprogram Id from the list of primitives that
23388 -- belong to type Typ.
23390 -------------------------
23391 -- Remove_Primitive_Of --
23392 -------------------------
23394 procedure Remove_Primitive_Of (Typ : Entity_Id) is
23395 Prims : Elist_Id;
23397 begin
23398 if Is_Tagged_Type (Typ) then
23399 Prims := Direct_Primitive_Operations (Typ);
23401 if Present (Prims) then
23402 Remove (Prims, Id);
23403 end if;
23404 end if;
23405 end Remove_Primitive_Of;
23407 -- Local variables
23409 Formal : Entity_Id;
23411 -- Start of processing for Remove_Overloaded_Entity
23413 begin
23414 Remove_Entity_And_Homonym (Id);
23416 -- The entity denotes a primitive subprogram. Remove it from the list of
23417 -- primitives of the associated controlling type.
23419 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
23420 Formal := First_Formal (Id);
23421 while Present (Formal) loop
23422 if Is_Controlling_Formal (Formal) then
23423 Remove_Primitive_Of (Etype (Formal));
23424 exit;
23425 end if;
23427 Next_Formal (Formal);
23428 end loop;
23430 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
23431 Remove_Primitive_Of (Etype (Id));
23432 end if;
23433 end if;
23434 end Remove_Overloaded_Entity;
23436 ---------------------
23437 -- Rep_To_Pos_Flag --
23438 ---------------------
23440 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
23441 begin
23442 return New_Occurrence_Of
23443 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
23444 end Rep_To_Pos_Flag;
23446 --------------------
23447 -- Require_Entity --
23448 --------------------
23450 procedure Require_Entity (N : Node_Id) is
23451 begin
23452 if Is_Entity_Name (N) and then No (Entity (N)) then
23453 if Total_Errors_Detected /= 0 then
23454 Set_Entity (N, Any_Id);
23455 else
23456 raise Program_Error;
23457 end if;
23458 end if;
23459 end Require_Entity;
23461 ------------------------------
23462 -- Requires_Transient_Scope --
23463 ------------------------------
23465 -- A transient scope is required when variable-sized temporaries are
23466 -- allocated on the secondary stack, or when finalization actions must be
23467 -- generated before the next instruction.
23469 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
23470 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
23472 begin
23473 if Debug_Flag_QQ then
23474 return Old_Result;
23475 end if;
23477 declare
23478 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
23480 begin
23481 -- Assert that we're not putting things on the secondary stack if we
23482 -- didn't before; we are trying to AVOID secondary stack when
23483 -- possible.
23485 if not Old_Result then
23486 pragma Assert (not New_Result);
23487 null;
23488 end if;
23490 if New_Result /= Old_Result then
23491 Results_Differ (Id, Old_Result, New_Result);
23492 end if;
23494 return New_Result;
23495 end;
23496 end Requires_Transient_Scope;
23498 --------------------
23499 -- Results_Differ --
23500 --------------------
23502 procedure Results_Differ
23503 (Id : Entity_Id;
23504 Old_Val : Boolean;
23505 New_Val : Boolean)
23507 begin
23508 if False then -- False to disable; True for debugging
23509 Treepr.Print_Tree_Node (Id);
23511 if Old_Val = New_Val then
23512 raise Program_Error;
23513 end if;
23514 end if;
23515 end Results_Differ;
23517 --------------------------
23518 -- Reset_Analyzed_Flags --
23519 --------------------------
23521 procedure Reset_Analyzed_Flags (N : Node_Id) is
23522 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
23523 -- Function used to reset Analyzed flags in tree. Note that we do
23524 -- not reset Analyzed flags in entities, since there is no need to
23525 -- reanalyze entities, and indeed, it is wrong to do so, since it
23526 -- can result in generating auxiliary stuff more than once.
23528 --------------------
23529 -- Clear_Analyzed --
23530 --------------------
23532 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
23533 begin
23534 if Nkind (N) not in N_Entity then
23535 Set_Analyzed (N, False);
23536 end if;
23538 return OK;
23539 end Clear_Analyzed;
23541 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
23543 -- Start of processing for Reset_Analyzed_Flags
23545 begin
23546 Reset_Analyzed (N);
23547 end Reset_Analyzed_Flags;
23549 ------------------------
23550 -- Restore_SPARK_Mode --
23551 ------------------------
23553 procedure Restore_SPARK_Mode
23554 (Mode : SPARK_Mode_Type;
23555 Prag : Node_Id)
23557 begin
23558 SPARK_Mode := Mode;
23559 SPARK_Mode_Pragma := Prag;
23560 end Restore_SPARK_Mode;
23562 --------------------------------
23563 -- Returns_Unconstrained_Type --
23564 --------------------------------
23566 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
23567 begin
23568 return Ekind (Subp) = E_Function
23569 and then not Is_Scalar_Type (Etype (Subp))
23570 and then not Is_Access_Type (Etype (Subp))
23571 and then not Is_Constrained (Etype (Subp));
23572 end Returns_Unconstrained_Type;
23574 ----------------------------
23575 -- Root_Type_Of_Full_View --
23576 ----------------------------
23578 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
23579 Rtyp : constant Entity_Id := Root_Type (T);
23581 begin
23582 -- The root type of the full view may itself be a private type. Keep
23583 -- looking for the ultimate derivation parent.
23585 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
23586 return Root_Type_Of_Full_View (Full_View (Rtyp));
23587 else
23588 return Rtyp;
23589 end if;
23590 end Root_Type_Of_Full_View;
23592 ---------------------------
23593 -- Safe_To_Capture_Value --
23594 ---------------------------
23596 function Safe_To_Capture_Value
23597 (N : Node_Id;
23598 Ent : Entity_Id;
23599 Cond : Boolean := False) return Boolean
23601 begin
23602 -- The only entities for which we track constant values are variables
23603 -- which are not renamings, constants, out parameters, and in out
23604 -- parameters, so check if we have this case.
23606 -- Note: it may seem odd to track constant values for constants, but in
23607 -- fact this routine is used for other purposes than simply capturing
23608 -- the value. In particular, the setting of Known[_Non]_Null.
23610 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
23611 or else
23612 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
23613 then
23614 null;
23616 -- For conditionals, we also allow loop parameters and all formals,
23617 -- including in parameters.
23619 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
23620 null;
23622 -- For all other cases, not just unsafe, but impossible to capture
23623 -- Current_Value, since the above are the only entities which have
23624 -- Current_Value fields.
23626 else
23627 return False;
23628 end if;
23630 -- Skip if volatile or aliased, since funny things might be going on in
23631 -- these cases which we cannot necessarily track. Also skip any variable
23632 -- for which an address clause is given, or whose address is taken. Also
23633 -- never capture value of library level variables (an attempt to do so
23634 -- can occur in the case of package elaboration code).
23636 if Treat_As_Volatile (Ent)
23637 or else Is_Aliased (Ent)
23638 or else Present (Address_Clause (Ent))
23639 or else Address_Taken (Ent)
23640 or else (Is_Library_Level_Entity (Ent)
23641 and then Ekind (Ent) = E_Variable)
23642 then
23643 return False;
23644 end if;
23646 -- OK, all above conditions are met. We also require that the scope of
23647 -- the reference be the same as the scope of the entity, not counting
23648 -- packages and blocks and loops.
23650 declare
23651 E_Scope : constant Entity_Id := Scope (Ent);
23652 R_Scope : Entity_Id;
23654 begin
23655 R_Scope := Current_Scope;
23656 while R_Scope /= Standard_Standard loop
23657 exit when R_Scope = E_Scope;
23659 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
23660 return False;
23661 else
23662 R_Scope := Scope (R_Scope);
23663 end if;
23664 end loop;
23665 end;
23667 -- We also require that the reference does not appear in a context
23668 -- where it is not sure to be executed (i.e. a conditional context
23669 -- or an exception handler). We skip this if Cond is True, since the
23670 -- capturing of values from conditional tests handles this ok.
23672 if Cond then
23673 return True;
23674 end if;
23676 declare
23677 Desc : Node_Id;
23678 P : Node_Id;
23680 begin
23681 Desc := N;
23683 -- Seems dubious that case expressions are not handled here ???
23685 P := Parent (N);
23686 while Present (P) loop
23687 if Nkind (P) = N_If_Statement
23688 or else Nkind (P) = N_Case_Statement
23689 or else (Nkind (P) in N_Short_Circuit
23690 and then Desc = Right_Opnd (P))
23691 or else (Nkind (P) = N_If_Expression
23692 and then Desc /= First (Expressions (P)))
23693 or else Nkind (P) = N_Exception_Handler
23694 or else Nkind (P) = N_Selective_Accept
23695 or else Nkind (P) = N_Conditional_Entry_Call
23696 or else Nkind (P) = N_Timed_Entry_Call
23697 or else Nkind (P) = N_Asynchronous_Select
23698 then
23699 return False;
23701 else
23702 Desc := P;
23703 P := Parent (P);
23705 -- A special Ada 2012 case: the original node may be part
23706 -- of the else_actions of a conditional expression, in which
23707 -- case it might not have been expanded yet, and appears in
23708 -- a non-syntactic list of actions. In that case it is clearly
23709 -- not safe to save a value.
23711 if No (P)
23712 and then Is_List_Member (Desc)
23713 and then No (Parent (List_Containing (Desc)))
23714 then
23715 return False;
23716 end if;
23717 end if;
23718 end loop;
23719 end;
23721 -- OK, looks safe to set value
23723 return True;
23724 end Safe_To_Capture_Value;
23726 ---------------
23727 -- Same_Name --
23728 ---------------
23730 function Same_Name (N1, N2 : Node_Id) return Boolean is
23731 K1 : constant Node_Kind := Nkind (N1);
23732 K2 : constant Node_Kind := Nkind (N2);
23734 begin
23735 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
23736 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
23737 then
23738 return Chars (N1) = Chars (N2);
23740 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
23741 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
23742 then
23743 return Same_Name (Selector_Name (N1), Selector_Name (N2))
23744 and then Same_Name (Prefix (N1), Prefix (N2));
23746 else
23747 return False;
23748 end if;
23749 end Same_Name;
23751 -----------------
23752 -- Same_Object --
23753 -----------------
23755 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
23756 N1 : constant Node_Id := Original_Node (Node1);
23757 N2 : constant Node_Id := Original_Node (Node2);
23758 -- We do the tests on original nodes, since we are most interested
23759 -- in the original source, not any expansion that got in the way.
23761 K1 : constant Node_Kind := Nkind (N1);
23762 K2 : constant Node_Kind := Nkind (N2);
23764 begin
23765 -- First case, both are entities with same entity
23767 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
23768 declare
23769 EN1 : constant Entity_Id := Entity (N1);
23770 EN2 : constant Entity_Id := Entity (N2);
23771 begin
23772 if Present (EN1) and then Present (EN2)
23773 and then (Ekind_In (EN1, E_Variable, E_Constant)
23774 or else Is_Formal (EN1))
23775 and then EN1 = EN2
23776 then
23777 return True;
23778 end if;
23779 end;
23780 end if;
23782 -- Second case, selected component with same selector, same record
23784 if K1 = N_Selected_Component
23785 and then K2 = N_Selected_Component
23786 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
23787 then
23788 return Same_Object (Prefix (N1), Prefix (N2));
23790 -- Third case, indexed component with same subscripts, same array
23792 elsif K1 = N_Indexed_Component
23793 and then K2 = N_Indexed_Component
23794 and then Same_Object (Prefix (N1), Prefix (N2))
23795 then
23796 declare
23797 E1, E2 : Node_Id;
23798 begin
23799 E1 := First (Expressions (N1));
23800 E2 := First (Expressions (N2));
23801 while Present (E1) loop
23802 if not Same_Value (E1, E2) then
23803 return False;
23804 else
23805 Next (E1);
23806 Next (E2);
23807 end if;
23808 end loop;
23810 return True;
23811 end;
23813 -- Fourth case, slice of same array with same bounds
23815 elsif K1 = N_Slice
23816 and then K2 = N_Slice
23817 and then Nkind (Discrete_Range (N1)) = N_Range
23818 and then Nkind (Discrete_Range (N2)) = N_Range
23819 and then Same_Value (Low_Bound (Discrete_Range (N1)),
23820 Low_Bound (Discrete_Range (N2)))
23821 and then Same_Value (High_Bound (Discrete_Range (N1)),
23822 High_Bound (Discrete_Range (N2)))
23823 then
23824 return Same_Name (Prefix (N1), Prefix (N2));
23826 -- All other cases, not clearly the same object
23828 else
23829 return False;
23830 end if;
23831 end Same_Object;
23833 ---------------
23834 -- Same_Type --
23835 ---------------
23837 function Same_Type (T1, T2 : Entity_Id) return Boolean is
23838 begin
23839 if T1 = T2 then
23840 return True;
23842 elsif not Is_Constrained (T1)
23843 and then not Is_Constrained (T2)
23844 and then Base_Type (T1) = Base_Type (T2)
23845 then
23846 return True;
23848 -- For now don't bother with case of identical constraints, to be
23849 -- fiddled with later on perhaps (this is only used for optimization
23850 -- purposes, so it is not critical to do a best possible job)
23852 else
23853 return False;
23854 end if;
23855 end Same_Type;
23857 ----------------
23858 -- Same_Value --
23859 ----------------
23861 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
23862 begin
23863 if Compile_Time_Known_Value (Node1)
23864 and then Compile_Time_Known_Value (Node2)
23865 then
23866 -- Handle properly compile-time expressions that are not
23867 -- scalar.
23869 if Is_String_Type (Etype (Node1)) then
23870 return Expr_Value_S (Node1) = Expr_Value_S (Node2);
23872 else
23873 return Expr_Value (Node1) = Expr_Value (Node2);
23874 end if;
23876 elsif Same_Object (Node1, Node2) then
23877 return True;
23878 else
23879 return False;
23880 end if;
23881 end Same_Value;
23883 --------------------
23884 -- Set_SPARK_Mode --
23885 --------------------
23887 procedure Set_SPARK_Mode (Context : Entity_Id) is
23888 begin
23889 -- Do not consider illegal or partially decorated constructs
23891 if Ekind (Context) = E_Void or else Error_Posted (Context) then
23892 null;
23894 elsif Present (SPARK_Pragma (Context)) then
23895 Install_SPARK_Mode
23896 (Mode => Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context)),
23897 Prag => SPARK_Pragma (Context));
23898 end if;
23899 end Set_SPARK_Mode;
23901 -------------------------
23902 -- Scalar_Part_Present --
23903 -------------------------
23905 function Scalar_Part_Present (Typ : Entity_Id) return Boolean is
23906 Val_Typ : constant Entity_Id := Validated_View (Typ);
23907 Field : Entity_Id;
23909 begin
23910 if Is_Scalar_Type (Val_Typ) then
23911 return True;
23913 elsif Is_Array_Type (Val_Typ) then
23914 return Scalar_Part_Present (Component_Type (Val_Typ));
23916 elsif Is_Record_Type (Val_Typ) then
23917 Field := First_Component_Or_Discriminant (Val_Typ);
23918 while Present (Field) loop
23919 if Scalar_Part_Present (Etype (Field)) then
23920 return True;
23921 end if;
23923 Next_Component_Or_Discriminant (Field);
23924 end loop;
23925 end if;
23927 return False;
23928 end Scalar_Part_Present;
23930 ------------------------
23931 -- Scope_Is_Transient --
23932 ------------------------
23934 function Scope_Is_Transient return Boolean is
23935 begin
23936 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
23937 end Scope_Is_Transient;
23939 ------------------
23940 -- Scope_Within --
23941 ------------------
23943 function Scope_Within
23944 (Inner : Entity_Id;
23945 Outer : Entity_Id) return Boolean
23947 Curr : Entity_Id;
23949 begin
23950 Curr := Inner;
23951 while Present (Curr) and then Curr /= Standard_Standard loop
23952 Curr := Scope (Curr);
23954 if Curr = Outer then
23955 return True;
23956 end if;
23957 end loop;
23959 return False;
23960 end Scope_Within;
23962 --------------------------
23963 -- Scope_Within_Or_Same --
23964 --------------------------
23966 function Scope_Within_Or_Same
23967 (Inner : Entity_Id;
23968 Outer : Entity_Id) return Boolean
23970 Curr : Entity_Id;
23972 begin
23973 Curr := Inner;
23974 while Present (Curr) and then Curr /= Standard_Standard loop
23975 if Curr = Outer then
23976 return True;
23977 end if;
23979 Curr := Scope (Curr);
23980 end loop;
23982 return False;
23983 end Scope_Within_Or_Same;
23985 --------------------
23986 -- Set_Convention --
23987 --------------------
23989 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
23990 begin
23991 Basic_Set_Convention (E, Val);
23993 if Is_Type (E)
23994 and then Is_Access_Subprogram_Type (Base_Type (E))
23995 and then Has_Foreign_Convention (E)
23996 then
23997 Set_Can_Use_Internal_Rep (E, False);
23998 end if;
24000 -- If E is an object, including a component, and the type of E is an
24001 -- anonymous access type with no convention set, then also set the
24002 -- convention of the anonymous access type. We do not do this for
24003 -- anonymous protected types, since protected types always have the
24004 -- default convention.
24006 if Present (Etype (E))
24007 and then (Is_Object (E)
24009 -- Allow E_Void (happens for pragma Convention appearing
24010 -- in the middle of a record applying to a component)
24012 or else Ekind (E) = E_Void)
24013 then
24014 declare
24015 Typ : constant Entity_Id := Etype (E);
24017 begin
24018 if Ekind_In (Typ, E_Anonymous_Access_Type,
24019 E_Anonymous_Access_Subprogram_Type)
24020 and then not Has_Convention_Pragma (Typ)
24021 then
24022 Basic_Set_Convention (Typ, Val);
24023 Set_Has_Convention_Pragma (Typ);
24025 -- And for the access subprogram type, deal similarly with the
24026 -- designated E_Subprogram_Type, which is always internal.
24028 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
24029 declare
24030 Dtype : constant Entity_Id := Designated_Type (Typ);
24031 begin
24032 if Ekind (Dtype) = E_Subprogram_Type
24033 and then not Has_Convention_Pragma (Dtype)
24034 then
24035 Basic_Set_Convention (Dtype, Val);
24036 Set_Has_Convention_Pragma (Dtype);
24037 end if;
24038 end;
24039 end if;
24040 end if;
24041 end;
24042 end if;
24043 end Set_Convention;
24045 ------------------------
24046 -- Set_Current_Entity --
24047 ------------------------
24049 -- The given entity is to be set as the currently visible definition of its
24050 -- associated name (i.e. the Node_Id associated with its name). All we have
24051 -- to do is to get the name from the identifier, and then set the
24052 -- associated Node_Id to point to the given entity.
24054 procedure Set_Current_Entity (E : Entity_Id) is
24055 begin
24056 Set_Name_Entity_Id (Chars (E), E);
24057 end Set_Current_Entity;
24059 ---------------------------
24060 -- Set_Debug_Info_Needed --
24061 ---------------------------
24063 procedure Set_Debug_Info_Needed (T : Entity_Id) is
24065 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
24066 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
24067 -- Used to set debug info in a related node if not set already
24069 --------------------------------------
24070 -- Set_Debug_Info_Needed_If_Not_Set --
24071 --------------------------------------
24073 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
24074 begin
24075 if Present (E) and then not Needs_Debug_Info (E) then
24076 Set_Debug_Info_Needed (E);
24078 -- For a private type, indicate that the full view also needs
24079 -- debug information.
24081 if Is_Type (E)
24082 and then Is_Private_Type (E)
24083 and then Present (Full_View (E))
24084 then
24085 Set_Debug_Info_Needed (Full_View (E));
24086 end if;
24087 end if;
24088 end Set_Debug_Info_Needed_If_Not_Set;
24090 -- Start of processing for Set_Debug_Info_Needed
24092 begin
24093 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
24094 -- indicates that Debug_Info_Needed is never required for the entity.
24095 -- Nothing to do if entity comes from a predefined file. Library files
24096 -- are compiled without debug information, but inlined bodies of these
24097 -- routines may appear in user code, and debug information on them ends
24098 -- up complicating debugging the user code.
24100 if No (T)
24101 or else Debug_Info_Off (T)
24102 then
24103 return;
24105 elsif In_Inlined_Body and then In_Predefined_Unit (T) then
24106 Set_Needs_Debug_Info (T, False);
24107 end if;
24109 -- Set flag in entity itself. Note that we will go through the following
24110 -- circuitry even if the flag is already set on T. That's intentional,
24111 -- it makes sure that the flag will be set in subsidiary entities.
24113 Set_Needs_Debug_Info (T);
24115 -- Set flag on subsidiary entities if not set already
24117 if Is_Object (T) then
24118 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24120 elsif Is_Type (T) then
24121 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
24123 if Is_Record_Type (T) then
24124 declare
24125 Ent : Entity_Id := First_Entity (T);
24126 begin
24127 while Present (Ent) loop
24128 Set_Debug_Info_Needed_If_Not_Set (Ent);
24129 Next_Entity (Ent);
24130 end loop;
24131 end;
24133 -- For a class wide subtype, we also need debug information
24134 -- for the equivalent type.
24136 if Ekind (T) = E_Class_Wide_Subtype then
24137 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
24138 end if;
24140 elsif Is_Array_Type (T) then
24141 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
24143 declare
24144 Indx : Node_Id := First_Index (T);
24145 begin
24146 while Present (Indx) loop
24147 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
24148 Indx := Next_Index (Indx);
24149 end loop;
24150 end;
24152 -- For a packed array type, we also need debug information for
24153 -- the type used to represent the packed array. Conversely, we
24154 -- also need it for the former if we need it for the latter.
24156 if Is_Packed (T) then
24157 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
24158 end if;
24160 if Is_Packed_Array_Impl_Type (T) then
24161 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
24162 end if;
24164 elsif Is_Access_Type (T) then
24165 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
24167 elsif Is_Private_Type (T) then
24168 declare
24169 FV : constant Entity_Id := Full_View (T);
24171 begin
24172 Set_Debug_Info_Needed_If_Not_Set (FV);
24174 -- If the full view is itself a derived private type, we need
24175 -- debug information on its underlying type.
24177 if Present (FV)
24178 and then Is_Private_Type (FV)
24179 and then Present (Underlying_Full_View (FV))
24180 then
24181 Set_Needs_Debug_Info (Underlying_Full_View (FV));
24182 end if;
24183 end;
24185 elsif Is_Protected_Type (T) then
24186 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
24188 elsif Is_Scalar_Type (T) then
24190 -- If the subrange bounds are materialized by dedicated constant
24191 -- objects, also include them in the debug info to make sure the
24192 -- debugger can properly use them.
24194 if Present (Scalar_Range (T))
24195 and then Nkind (Scalar_Range (T)) = N_Range
24196 then
24197 declare
24198 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
24199 High_Bnd : constant Node_Id := Type_High_Bound (T);
24201 begin
24202 if Is_Entity_Name (Low_Bnd) then
24203 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
24204 end if;
24206 if Is_Entity_Name (High_Bnd) then
24207 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
24208 end if;
24209 end;
24210 end if;
24211 end if;
24212 end if;
24213 end Set_Debug_Info_Needed;
24215 ----------------------------
24216 -- Set_Entity_With_Checks --
24217 ----------------------------
24219 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
24220 Val_Actual : Entity_Id;
24221 Nod : Node_Id;
24222 Post_Node : Node_Id;
24224 begin
24225 -- Unconditionally set the entity
24227 Set_Entity (N, Val);
24229 -- The node to post on is the selector in the case of an expanded name,
24230 -- and otherwise the node itself.
24232 if Nkind (N) = N_Expanded_Name then
24233 Post_Node := Selector_Name (N);
24234 else
24235 Post_Node := N;
24236 end if;
24238 -- Check for violation of No_Fixed_IO
24240 if Restriction_Check_Required (No_Fixed_IO)
24241 and then
24242 ((RTU_Loaded (Ada_Text_IO)
24243 and then (Is_RTE (Val, RE_Decimal_IO)
24244 or else
24245 Is_RTE (Val, RE_Fixed_IO)))
24247 or else
24248 (RTU_Loaded (Ada_Wide_Text_IO)
24249 and then (Is_RTE (Val, RO_WT_Decimal_IO)
24250 or else
24251 Is_RTE (Val, RO_WT_Fixed_IO)))
24253 or else
24254 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
24255 and then (Is_RTE (Val, RO_WW_Decimal_IO)
24256 or else
24257 Is_RTE (Val, RO_WW_Fixed_IO))))
24259 -- A special extra check, don't complain about a reference from within
24260 -- the Ada.Interrupts package itself!
24262 and then not In_Same_Extended_Unit (N, Val)
24263 then
24264 Check_Restriction (No_Fixed_IO, Post_Node);
24265 end if;
24267 -- Remaining checks are only done on source nodes. Note that we test
24268 -- for violation of No_Fixed_IO even on non-source nodes, because the
24269 -- cases for checking violations of this restriction are instantiations
24270 -- where the reference in the instance has Comes_From_Source False.
24272 if not Comes_From_Source (N) then
24273 return;
24274 end if;
24276 -- Check for violation of No_Abort_Statements, which is triggered by
24277 -- call to Ada.Task_Identification.Abort_Task.
24279 if Restriction_Check_Required (No_Abort_Statements)
24280 and then (Is_RTE (Val, RE_Abort_Task))
24282 -- A special extra check, don't complain about a reference from within
24283 -- the Ada.Task_Identification package itself!
24285 and then not In_Same_Extended_Unit (N, Val)
24286 then
24287 Check_Restriction (No_Abort_Statements, Post_Node);
24288 end if;
24290 if Val = Standard_Long_Long_Integer then
24291 Check_Restriction (No_Long_Long_Integers, Post_Node);
24292 end if;
24294 -- Check for violation of No_Dynamic_Attachment
24296 if Restriction_Check_Required (No_Dynamic_Attachment)
24297 and then RTU_Loaded (Ada_Interrupts)
24298 and then (Is_RTE (Val, RE_Is_Reserved) or else
24299 Is_RTE (Val, RE_Is_Attached) or else
24300 Is_RTE (Val, RE_Current_Handler) or else
24301 Is_RTE (Val, RE_Attach_Handler) or else
24302 Is_RTE (Val, RE_Exchange_Handler) or else
24303 Is_RTE (Val, RE_Detach_Handler) or else
24304 Is_RTE (Val, RE_Reference))
24306 -- A special extra check, don't complain about a reference from within
24307 -- the Ada.Interrupts package itself!
24309 and then not In_Same_Extended_Unit (N, Val)
24310 then
24311 Check_Restriction (No_Dynamic_Attachment, Post_Node);
24312 end if;
24314 -- Check for No_Implementation_Identifiers
24316 if Restriction_Check_Required (No_Implementation_Identifiers) then
24318 -- We have an implementation defined entity if it is marked as
24319 -- implementation defined, or is defined in a package marked as
24320 -- implementation defined. However, library packages themselves
24321 -- are excluded (we don't want to flag Interfaces itself, just
24322 -- the entities within it).
24324 if (Is_Implementation_Defined (Val)
24325 or else
24326 (Present (Scope (Val))
24327 and then Is_Implementation_Defined (Scope (Val))))
24328 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
24329 and then Is_Library_Level_Entity (Val))
24330 then
24331 Check_Restriction (No_Implementation_Identifiers, Post_Node);
24332 end if;
24333 end if;
24335 -- Do the style check
24337 if Style_Check
24338 and then not Suppress_Style_Checks (Val)
24339 and then not In_Instance
24340 then
24341 if Nkind (N) = N_Identifier then
24342 Nod := N;
24343 elsif Nkind (N) = N_Expanded_Name then
24344 Nod := Selector_Name (N);
24345 else
24346 return;
24347 end if;
24349 -- A special situation arises for derived operations, where we want
24350 -- to do the check against the parent (since the Sloc of the derived
24351 -- operation points to the derived type declaration itself).
24353 Val_Actual := Val;
24354 while not Comes_From_Source (Val_Actual)
24355 and then Nkind (Val_Actual) in N_Entity
24356 and then (Ekind (Val_Actual) = E_Enumeration_Literal
24357 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
24358 and then Present (Alias (Val_Actual))
24359 loop
24360 Val_Actual := Alias (Val_Actual);
24361 end loop;
24363 -- Renaming declarations for generic actuals do not come from source,
24364 -- and have a different name from that of the entity they rename, so
24365 -- there is no style check to perform here.
24367 if Chars (Nod) = Chars (Val_Actual) then
24368 Style.Check_Identifier (Nod, Val_Actual);
24369 end if;
24370 end if;
24372 Set_Entity (N, Val);
24373 end Set_Entity_With_Checks;
24375 ------------------------------
24376 -- Set_Invalid_Scalar_Value --
24377 ------------------------------
24379 procedure Set_Invalid_Scalar_Value
24380 (Scal_Typ : Float_Scalar_Id;
24381 Value : Ureal)
24383 Slot : Ureal renames Invalid_Floats (Scal_Typ);
24385 begin
24386 -- Detect an attempt to set a different value for the same scalar type
24388 pragma Assert (Slot = No_Ureal);
24389 Slot := Value;
24390 end Set_Invalid_Scalar_Value;
24392 ------------------------------
24393 -- Set_Invalid_Scalar_Value --
24394 ------------------------------
24396 procedure Set_Invalid_Scalar_Value
24397 (Scal_Typ : Integer_Scalar_Id;
24398 Value : Uint)
24400 Slot : Uint renames Invalid_Integers (Scal_Typ);
24402 begin
24403 -- Detect an attempt to set a different value for the same scalar type
24405 pragma Assert (Slot = No_Uint);
24406 Slot := Value;
24407 end Set_Invalid_Scalar_Value;
24409 ------------------------
24410 -- Set_Name_Entity_Id --
24411 ------------------------
24413 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
24414 begin
24415 Set_Name_Table_Int (Id, Int (Val));
24416 end Set_Name_Entity_Id;
24418 ---------------------
24419 -- Set_Next_Actual --
24420 ---------------------
24422 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
24423 begin
24424 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
24425 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
24426 end if;
24427 end Set_Next_Actual;
24429 ----------------------------------
24430 -- Set_Optimize_Alignment_Flags --
24431 ----------------------------------
24433 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
24434 begin
24435 if Optimize_Alignment = 'S' then
24436 Set_Optimize_Alignment_Space (E);
24437 elsif Optimize_Alignment = 'T' then
24438 Set_Optimize_Alignment_Time (E);
24439 end if;
24440 end Set_Optimize_Alignment_Flags;
24442 -----------------------
24443 -- Set_Public_Status --
24444 -----------------------
24446 procedure Set_Public_Status (Id : Entity_Id) is
24447 S : constant Entity_Id := Current_Scope;
24449 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
24450 -- Determines if E is defined within handled statement sequence or
24451 -- an if statement, returns True if so, False otherwise.
24453 ----------------------
24454 -- Within_HSS_Or_If --
24455 ----------------------
24457 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
24458 N : Node_Id;
24459 begin
24460 N := Declaration_Node (E);
24461 loop
24462 N := Parent (N);
24464 if No (N) then
24465 return False;
24467 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
24468 N_If_Statement)
24469 then
24470 return True;
24471 end if;
24472 end loop;
24473 end Within_HSS_Or_If;
24475 -- Start of processing for Set_Public_Status
24477 begin
24478 -- Everything in the scope of Standard is public
24480 if S = Standard_Standard then
24481 Set_Is_Public (Id);
24483 -- Entity is definitely not public if enclosing scope is not public
24485 elsif not Is_Public (S) then
24486 return;
24488 -- An object or function declaration that occurs in a handled sequence
24489 -- of statements or within an if statement is the declaration for a
24490 -- temporary object or local subprogram generated by the expander. It
24491 -- never needs to be made public and furthermore, making it public can
24492 -- cause back end problems.
24494 elsif Nkind_In (Parent (Id), N_Object_Declaration,
24495 N_Function_Specification)
24496 and then Within_HSS_Or_If (Id)
24497 then
24498 return;
24500 -- Entities in public packages or records are public
24502 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
24503 Set_Is_Public (Id);
24505 -- The bounds of an entry family declaration can generate object
24506 -- declarations that are visible to the back-end, e.g. in the
24507 -- the declaration of a composite type that contains tasks.
24509 elsif Is_Concurrent_Type (S)
24510 and then not Has_Completion (S)
24511 and then Nkind (Parent (Id)) = N_Object_Declaration
24512 then
24513 Set_Is_Public (Id);
24514 end if;
24515 end Set_Public_Status;
24517 -----------------------------
24518 -- Set_Referenced_Modified --
24519 -----------------------------
24521 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
24522 Pref : Node_Id;
24524 begin
24525 -- Deal with indexed or selected component where prefix is modified
24527 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
24528 Pref := Prefix (N);
24530 -- If prefix is access type, then it is the designated object that is
24531 -- being modified, which means we have no entity to set the flag on.
24533 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
24534 return;
24536 -- Otherwise chase the prefix
24538 else
24539 Set_Referenced_Modified (Pref, Out_Param);
24540 end if;
24542 -- Otherwise see if we have an entity name (only other case to process)
24544 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
24545 Set_Referenced_As_LHS (Entity (N), not Out_Param);
24546 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
24547 end if;
24548 end Set_Referenced_Modified;
24550 ------------------
24551 -- Set_Rep_Info --
24552 ------------------
24554 procedure Set_Rep_Info (T1 : Entity_Id; T2 : Entity_Id) is
24555 begin
24556 Set_Is_Atomic (T1, Is_Atomic (T2));
24557 Set_Is_Independent (T1, Is_Independent (T2));
24558 Set_Is_Volatile_Full_Access (T1, Is_Volatile_Full_Access (T2));
24560 if Is_Base_Type (T1) then
24561 Set_Is_Volatile (T1, Is_Volatile (T2));
24562 end if;
24563 end Set_Rep_Info;
24565 ----------------------------
24566 -- Set_Scope_Is_Transient --
24567 ----------------------------
24569 procedure Set_Scope_Is_Transient (V : Boolean := True) is
24570 begin
24571 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
24572 end Set_Scope_Is_Transient;
24574 -------------------
24575 -- Set_Size_Info --
24576 -------------------
24578 procedure Set_Size_Info (T1, T2 : Entity_Id) is
24579 begin
24580 -- We copy Esize, but not RM_Size, since in general RM_Size is
24581 -- subtype specific and does not get inherited by all subtypes.
24583 Set_Esize (T1, Esize (T2));
24584 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
24586 if Is_Discrete_Or_Fixed_Point_Type (T1)
24587 and then
24588 Is_Discrete_Or_Fixed_Point_Type (T2)
24589 then
24590 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
24591 end if;
24593 Set_Alignment (T1, Alignment (T2));
24594 end Set_Size_Info;
24596 ------------------------------
24597 -- Should_Ignore_Pragma_Par --
24598 ------------------------------
24600 function Should_Ignore_Pragma_Par (Prag_Name : Name_Id) return Boolean is
24601 pragma Assert (Compiler_State = Parsing);
24602 -- This one can't work during semantic analysis, because we don't have a
24603 -- correct Current_Source_File.
24605 Result : constant Boolean :=
24606 Get_Name_Table_Boolean3 (Prag_Name)
24607 and then not Is_Internal_File_Name
24608 (File_Name (Current_Source_File));
24609 begin
24610 return Result;
24611 end Should_Ignore_Pragma_Par;
24613 ------------------------------
24614 -- Should_Ignore_Pragma_Sem --
24615 ------------------------------
24617 function Should_Ignore_Pragma_Sem (N : Node_Id) return Boolean is
24618 pragma Assert (Compiler_State = Analyzing);
24619 Prag_Name : constant Name_Id := Pragma_Name (N);
24620 Result : constant Boolean :=
24621 Get_Name_Table_Boolean3 (Prag_Name)
24622 and then not In_Internal_Unit (N);
24624 begin
24625 return Result;
24626 end Should_Ignore_Pragma_Sem;
24628 --------------------
24629 -- Static_Boolean --
24630 --------------------
24632 function Static_Boolean (N : Node_Id) return Uint is
24633 begin
24634 Analyze_And_Resolve (N, Standard_Boolean);
24636 if N = Error
24637 or else Error_Posted (N)
24638 or else Etype (N) = Any_Type
24639 then
24640 return No_Uint;
24641 end if;
24643 if Is_OK_Static_Expression (N) then
24644 if not Raises_Constraint_Error (N) then
24645 return Expr_Value (N);
24646 else
24647 return No_Uint;
24648 end if;
24650 elsif Etype (N) = Any_Type then
24651 return No_Uint;
24653 else
24654 Flag_Non_Static_Expr
24655 ("static boolean expression required here", N);
24656 return No_Uint;
24657 end if;
24658 end Static_Boolean;
24660 --------------------
24661 -- Static_Integer --
24662 --------------------
24664 function Static_Integer (N : Node_Id) return Uint is
24665 begin
24666 Analyze_And_Resolve (N, Any_Integer);
24668 if N = Error
24669 or else Error_Posted (N)
24670 or else Etype (N) = Any_Type
24671 then
24672 return No_Uint;
24673 end if;
24675 if Is_OK_Static_Expression (N) then
24676 if not Raises_Constraint_Error (N) then
24677 return Expr_Value (N);
24678 else
24679 return No_Uint;
24680 end if;
24682 elsif Etype (N) = Any_Type then
24683 return No_Uint;
24685 else
24686 Flag_Non_Static_Expr
24687 ("static integer expression required here", N);
24688 return No_Uint;
24689 end if;
24690 end Static_Integer;
24692 --------------------------
24693 -- Statically_Different --
24694 --------------------------
24696 function Statically_Different (E1, E2 : Node_Id) return Boolean is
24697 R1 : constant Node_Id := Get_Referenced_Object (E1);
24698 R2 : constant Node_Id := Get_Referenced_Object (E2);
24699 begin
24700 return Is_Entity_Name (R1)
24701 and then Is_Entity_Name (R2)
24702 and then Entity (R1) /= Entity (R2)
24703 and then not Is_Formal (Entity (R1))
24704 and then not Is_Formal (Entity (R2));
24705 end Statically_Different;
24707 --------------------------------------
24708 -- Subject_To_Loop_Entry_Attributes --
24709 --------------------------------------
24711 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
24712 Stmt : Node_Id;
24714 begin
24715 Stmt := N;
24717 -- The expansion mechanism transform a loop subject to at least one
24718 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
24719 -- the conditional part.
24721 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
24722 and then Nkind (Original_Node (N)) = N_Loop_Statement
24723 then
24724 Stmt := Original_Node (N);
24725 end if;
24727 return
24728 Nkind (Stmt) = N_Loop_Statement
24729 and then Present (Identifier (Stmt))
24730 and then Present (Entity (Identifier (Stmt)))
24731 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
24732 end Subject_To_Loop_Entry_Attributes;
24734 -----------------------------
24735 -- Subprogram_Access_Level --
24736 -----------------------------
24738 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
24739 begin
24740 if Present (Alias (Subp)) then
24741 return Subprogram_Access_Level (Alias (Subp));
24742 else
24743 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
24744 end if;
24745 end Subprogram_Access_Level;
24747 ---------------------
24748 -- Subprogram_Name --
24749 ---------------------
24751 function Subprogram_Name (N : Node_Id) return String is
24752 Buf : Bounded_String;
24753 Ent : Node_Id := N;
24754 Nod : Node_Id;
24756 begin
24757 while Present (Ent) loop
24758 case Nkind (Ent) is
24759 when N_Subprogram_Body =>
24760 Ent := Defining_Unit_Name (Specification (Ent));
24761 exit;
24763 when N_Subprogram_Declaration =>
24764 Nod := Corresponding_Body (Ent);
24766 if Present (Nod) then
24767 Ent := Nod;
24768 else
24769 Ent := Defining_Unit_Name (Specification (Ent));
24770 end if;
24772 exit;
24774 when N_Subprogram_Instantiation
24775 | N_Package_Body
24776 | N_Package_Specification
24778 Ent := Defining_Unit_Name (Ent);
24779 exit;
24781 when N_Protected_Type_Declaration =>
24782 Ent := Corresponding_Body (Ent);
24783 exit;
24785 when N_Protected_Body
24786 | N_Task_Body
24788 Ent := Defining_Identifier (Ent);
24789 exit;
24791 when others =>
24792 null;
24793 end case;
24795 Ent := Parent (Ent);
24796 end loop;
24798 if No (Ent) then
24799 return "unknown subprogram:unknown file:0:0";
24800 end if;
24802 -- If the subprogram is a child unit, use its simple name to start the
24803 -- construction of the fully qualified name.
24805 if Nkind (Ent) = N_Defining_Program_Unit_Name then
24806 Ent := Defining_Identifier (Ent);
24807 end if;
24809 Append_Entity_Name (Buf, Ent);
24811 -- Append homonym number if needed
24813 if Nkind (N) in N_Entity and then Has_Homonym (N) then
24814 declare
24815 H : Entity_Id := Homonym (N);
24816 Nr : Nat := 1;
24818 begin
24819 while Present (H) loop
24820 if Scope (H) = Scope (N) then
24821 Nr := Nr + 1;
24822 end if;
24824 H := Homonym (H);
24825 end loop;
24827 if Nr > 1 then
24828 Append (Buf, '#');
24829 Append (Buf, Nr);
24830 end if;
24831 end;
24832 end if;
24834 -- Append source location of Ent to Buf so that the string will
24835 -- look like "subp:file:line:col".
24837 declare
24838 Loc : constant Source_Ptr := Sloc (Ent);
24839 begin
24840 Append (Buf, ':');
24841 Append (Buf, Reference_Name (Get_Source_File_Index (Loc)));
24842 Append (Buf, ':');
24843 Append (Buf, Nat (Get_Logical_Line_Number (Loc)));
24844 Append (Buf, ':');
24845 Append (Buf, Nat (Get_Column_Number (Loc)));
24846 end;
24848 return +Buf;
24849 end Subprogram_Name;
24851 -------------------------------
24852 -- Support_Atomic_Primitives --
24853 -------------------------------
24855 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
24856 Size : Int;
24858 begin
24859 -- Verify the alignment of Typ is known
24861 if not Known_Alignment (Typ) then
24862 return False;
24863 end if;
24865 if Known_Static_Esize (Typ) then
24866 Size := UI_To_Int (Esize (Typ));
24868 -- If the Esize (Object_Size) is unknown at compile time, look at the
24869 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
24871 elsif Known_Static_RM_Size (Typ) then
24872 Size := UI_To_Int (RM_Size (Typ));
24874 -- Otherwise, the size is considered to be unknown.
24876 else
24877 return False;
24878 end if;
24880 -- Check that the size of the component is 8, 16, 32, or 64 bits and
24881 -- that Typ is properly aligned.
24883 case Size is
24884 when 8 | 16 | 32 | 64 =>
24885 return Size = UI_To_Int (Alignment (Typ)) * 8;
24887 when others =>
24888 return False;
24889 end case;
24890 end Support_Atomic_Primitives;
24892 -----------------
24893 -- Trace_Scope --
24894 -----------------
24896 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
24897 begin
24898 if Debug_Flag_W then
24899 for J in 0 .. Scope_Stack.Last loop
24900 Write_Str (" ");
24901 end loop;
24903 Write_Str (Msg);
24904 Write_Name (Chars (E));
24905 Write_Str (" from ");
24906 Write_Location (Sloc (N));
24907 Write_Eol;
24908 end if;
24909 end Trace_Scope;
24911 -----------------------
24912 -- Transfer_Entities --
24913 -----------------------
24915 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
24916 procedure Set_Public_Status_Of (Id : Entity_Id);
24917 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
24918 -- Set_Public_Status. If successful and Id denotes a record type, set
24919 -- the Is_Public attribute of its fields.
24921 --------------------------
24922 -- Set_Public_Status_Of --
24923 --------------------------
24925 procedure Set_Public_Status_Of (Id : Entity_Id) is
24926 Field : Entity_Id;
24928 begin
24929 if not Is_Public (Id) then
24930 Set_Public_Status (Id);
24932 -- When the input entity is a public record type, ensure that all
24933 -- its internal fields are also exposed to the linker. The fields
24934 -- of a class-wide type are never made public.
24936 if Is_Public (Id)
24937 and then Is_Record_Type (Id)
24938 and then not Is_Class_Wide_Type (Id)
24939 then
24940 Field := First_Entity (Id);
24941 while Present (Field) loop
24942 Set_Is_Public (Field);
24943 Next_Entity (Field);
24944 end loop;
24945 end if;
24946 end if;
24947 end Set_Public_Status_Of;
24949 -- Local variables
24951 Full_Id : Entity_Id;
24952 Id : Entity_Id;
24954 -- Start of processing for Transfer_Entities
24956 begin
24957 Id := First_Entity (From);
24959 if Present (Id) then
24961 -- Merge the entity chain of the source scope with that of the
24962 -- destination scope.
24964 if Present (Last_Entity (To)) then
24965 Link_Entities (Last_Entity (To), Id);
24966 else
24967 Set_First_Entity (To, Id);
24968 end if;
24970 Set_Last_Entity (To, Last_Entity (From));
24972 -- Inspect the entities of the source scope and update their Scope
24973 -- attribute.
24975 while Present (Id) loop
24976 Set_Scope (Id, To);
24977 Set_Public_Status_Of (Id);
24979 -- Handle an internally generated full view for a private type
24981 if Is_Private_Type (Id)
24982 and then Present (Full_View (Id))
24983 and then Is_Itype (Full_View (Id))
24984 then
24985 Full_Id := Full_View (Id);
24987 Set_Scope (Full_Id, To);
24988 Set_Public_Status_Of (Full_Id);
24989 end if;
24991 Next_Entity (Id);
24992 end loop;
24994 Set_First_Entity (From, Empty);
24995 Set_Last_Entity (From, Empty);
24996 end if;
24997 end Transfer_Entities;
24999 -----------------------
25000 -- Type_Access_Level --
25001 -----------------------
25003 function Type_Access_Level (Typ : Entity_Id) return Uint is
25004 Btyp : Entity_Id;
25006 begin
25007 Btyp := Base_Type (Typ);
25009 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
25010 -- simply use the level where the type is declared. This is true for
25011 -- stand-alone object declarations, and for anonymous access types
25012 -- associated with components the level is the same as that of the
25013 -- enclosing composite type. However, special treatment is needed for
25014 -- the cases of access parameters, return objects of an anonymous access
25015 -- type, and, in Ada 95, access discriminants of limited types.
25017 if Is_Access_Type (Btyp) then
25018 if Ekind (Btyp) = E_Anonymous_Access_Type then
25020 -- If the type is a nonlocal anonymous access type (such as for
25021 -- an access parameter) we treat it as being declared at the
25022 -- library level to ensure that names such as X.all'access don't
25023 -- fail static accessibility checks.
25025 if not Is_Local_Anonymous_Access (Typ) then
25026 return Scope_Depth (Standard_Standard);
25028 -- If this is a return object, the accessibility level is that of
25029 -- the result subtype of the enclosing function. The test here is
25030 -- little complicated, because we have to account for extended
25031 -- return statements that have been rewritten as blocks, in which
25032 -- case we have to find and the Is_Return_Object attribute of the
25033 -- itype's associated object. It would be nice to find a way to
25034 -- simplify this test, but it doesn't seem worthwhile to add a new
25035 -- flag just for purposes of this test. ???
25037 elsif Ekind (Scope (Btyp)) = E_Return_Statement
25038 or else
25039 (Is_Itype (Btyp)
25040 and then Nkind (Associated_Node_For_Itype (Btyp)) =
25041 N_Object_Declaration
25042 and then Is_Return_Object
25043 (Defining_Identifier
25044 (Associated_Node_For_Itype (Btyp))))
25045 then
25046 declare
25047 Scop : Entity_Id;
25049 begin
25050 Scop := Scope (Scope (Btyp));
25051 while Present (Scop) loop
25052 exit when Ekind (Scop) = E_Function;
25053 Scop := Scope (Scop);
25054 end loop;
25056 -- Treat the return object's type as having the level of the
25057 -- function's result subtype (as per RM05-6.5(5.3/2)).
25059 return Type_Access_Level (Etype (Scop));
25060 end;
25061 end if;
25062 end if;
25064 Btyp := Root_Type (Btyp);
25066 -- The accessibility level of anonymous access types associated with
25067 -- discriminants is that of the current instance of the type, and
25068 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
25070 -- AI-402: access discriminants have accessibility based on the
25071 -- object rather than the type in Ada 2005, so the above paragraph
25072 -- doesn't apply.
25074 -- ??? Needs completion with rules from AI-416
25076 if Ada_Version <= Ada_95
25077 and then Ekind (Typ) = E_Anonymous_Access_Type
25078 and then Present (Associated_Node_For_Itype (Typ))
25079 and then Nkind (Associated_Node_For_Itype (Typ)) =
25080 N_Discriminant_Specification
25081 then
25082 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
25083 end if;
25084 end if;
25086 -- Return library level for a generic formal type. This is done because
25087 -- RM(10.3.2) says that "The statically deeper relationship does not
25088 -- apply to ... a descendant of a generic formal type". Rather than
25089 -- checking at each point where a static accessibility check is
25090 -- performed to see if we are dealing with a formal type, this rule is
25091 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
25092 -- return extreme values for a formal type; Deepest_Type_Access_Level
25093 -- returns Int'Last. By calling the appropriate function from among the
25094 -- two, we ensure that the static accessibility check will pass if we
25095 -- happen to run into a formal type. More specifically, we should call
25096 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
25097 -- call occurs as part of a static accessibility check and the error
25098 -- case is the case where the type's level is too shallow (as opposed
25099 -- to too deep).
25101 if Is_Generic_Type (Root_Type (Btyp)) then
25102 return Scope_Depth (Standard_Standard);
25103 end if;
25105 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
25106 end Type_Access_Level;
25108 ------------------------------------
25109 -- Type_Without_Stream_Operation --
25110 ------------------------------------
25112 function Type_Without_Stream_Operation
25113 (T : Entity_Id;
25114 Op : TSS_Name_Type := TSS_Null) return Entity_Id
25116 BT : constant Entity_Id := Base_Type (T);
25117 Op_Missing : Boolean;
25119 begin
25120 if not Restriction_Active (No_Default_Stream_Attributes) then
25121 return Empty;
25122 end if;
25124 if Is_Elementary_Type (T) then
25125 if Op = TSS_Null then
25126 Op_Missing :=
25127 No (TSS (BT, TSS_Stream_Read))
25128 or else No (TSS (BT, TSS_Stream_Write));
25130 else
25131 Op_Missing := No (TSS (BT, Op));
25132 end if;
25134 if Op_Missing then
25135 return T;
25136 else
25137 return Empty;
25138 end if;
25140 elsif Is_Array_Type (T) then
25141 return Type_Without_Stream_Operation (Component_Type (T), Op);
25143 elsif Is_Record_Type (T) then
25144 declare
25145 Comp : Entity_Id;
25146 C_Typ : Entity_Id;
25148 begin
25149 Comp := First_Component (T);
25150 while Present (Comp) loop
25151 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
25153 if Present (C_Typ) then
25154 return C_Typ;
25155 end if;
25157 Next_Component (Comp);
25158 end loop;
25160 return Empty;
25161 end;
25163 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
25164 return Type_Without_Stream_Operation (Full_View (T), Op);
25165 else
25166 return Empty;
25167 end if;
25168 end Type_Without_Stream_Operation;
25170 ----------------------------
25171 -- Unique_Defining_Entity --
25172 ----------------------------
25174 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
25175 begin
25176 return Unique_Entity (Defining_Entity (N));
25177 end Unique_Defining_Entity;
25179 -------------------
25180 -- Unique_Entity --
25181 -------------------
25183 function Unique_Entity (E : Entity_Id) return Entity_Id is
25184 U : Entity_Id := E;
25185 P : Node_Id;
25187 begin
25188 case Ekind (E) is
25189 when E_Constant =>
25190 if Present (Full_View (E)) then
25191 U := Full_View (E);
25192 end if;
25194 when Entry_Kind =>
25195 if Nkind (Parent (E)) = N_Entry_Body then
25196 declare
25197 Prot_Item : Entity_Id;
25198 Prot_Type : Entity_Id;
25200 begin
25201 if Ekind (E) = E_Entry then
25202 Prot_Type := Scope (E);
25204 -- Bodies of entry families are nested within an extra scope
25205 -- that contains an entry index declaration.
25207 else
25208 Prot_Type := Scope (Scope (E));
25209 end if;
25211 -- A protected type may be declared as a private type, in
25212 -- which case we need to get its full view.
25214 if Is_Private_Type (Prot_Type) then
25215 Prot_Type := Full_View (Prot_Type);
25216 end if;
25218 -- Full view may not be present on error, in which case
25219 -- return E by default.
25221 if Present (Prot_Type) then
25222 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
25224 -- Traverse the entity list of the protected type and
25225 -- locate an entry declaration which matches the entry
25226 -- body.
25228 Prot_Item := First_Entity (Prot_Type);
25229 while Present (Prot_Item) loop
25230 if Ekind (Prot_Item) in Entry_Kind
25231 and then Corresponding_Body (Parent (Prot_Item)) = E
25232 then
25233 U := Prot_Item;
25234 exit;
25235 end if;
25237 Next_Entity (Prot_Item);
25238 end loop;
25239 end if;
25240 end;
25241 end if;
25243 when Formal_Kind =>
25244 if Present (Spec_Entity (E)) then
25245 U := Spec_Entity (E);
25246 end if;
25248 when E_Package_Body =>
25249 P := Parent (E);
25251 if Nkind (P) = N_Defining_Program_Unit_Name then
25252 P := Parent (P);
25253 end if;
25255 if Nkind (P) = N_Package_Body
25256 and then Present (Corresponding_Spec (P))
25257 then
25258 U := Corresponding_Spec (P);
25260 elsif Nkind (P) = N_Package_Body_Stub
25261 and then Present (Corresponding_Spec_Of_Stub (P))
25262 then
25263 U := Corresponding_Spec_Of_Stub (P);
25264 end if;
25266 when E_Protected_Body =>
25267 P := Parent (E);
25269 if Nkind (P) = N_Protected_Body
25270 and then Present (Corresponding_Spec (P))
25271 then
25272 U := Corresponding_Spec (P);
25274 elsif Nkind (P) = N_Protected_Body_Stub
25275 and then Present (Corresponding_Spec_Of_Stub (P))
25276 then
25277 U := Corresponding_Spec_Of_Stub (P);
25279 if Is_Single_Protected_Object (U) then
25280 U := Etype (U);
25281 end if;
25282 end if;
25284 if Is_Private_Type (U) then
25285 U := Full_View (U);
25286 end if;
25288 when E_Subprogram_Body =>
25289 P := Parent (E);
25291 if Nkind (P) = N_Defining_Program_Unit_Name then
25292 P := Parent (P);
25293 end if;
25295 P := Parent (P);
25297 if Nkind (P) = N_Subprogram_Body
25298 and then Present (Corresponding_Spec (P))
25299 then
25300 U := Corresponding_Spec (P);
25302 elsif Nkind (P) = N_Subprogram_Body_Stub
25303 and then Present (Corresponding_Spec_Of_Stub (P))
25304 then
25305 U := Corresponding_Spec_Of_Stub (P);
25307 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
25308 U := Corresponding_Spec (P);
25309 end if;
25311 when E_Task_Body =>
25312 P := Parent (E);
25314 if Nkind (P) = N_Task_Body
25315 and then Present (Corresponding_Spec (P))
25316 then
25317 U := Corresponding_Spec (P);
25319 elsif Nkind (P) = N_Task_Body_Stub
25320 and then Present (Corresponding_Spec_Of_Stub (P))
25321 then
25322 U := Corresponding_Spec_Of_Stub (P);
25324 if Is_Single_Task_Object (U) then
25325 U := Etype (U);
25326 end if;
25327 end if;
25329 if Is_Private_Type (U) then
25330 U := Full_View (U);
25331 end if;
25333 when Type_Kind =>
25334 if Present (Full_View (E)) then
25335 U := Full_View (E);
25336 end if;
25338 when others =>
25339 null;
25340 end case;
25342 return U;
25343 end Unique_Entity;
25345 -----------------
25346 -- Unique_Name --
25347 -----------------
25349 function Unique_Name (E : Entity_Id) return String is
25351 -- Names in E_Subprogram_Body or E_Package_Body entities are not
25352 -- reliable, as they may not include the overloading suffix. Instead,
25353 -- when looking for the name of E or one of its enclosing scope, we get
25354 -- the name of the corresponding Unique_Entity.
25356 U : constant Entity_Id := Unique_Entity (E);
25358 function This_Name return String;
25360 ---------------
25361 -- This_Name --
25362 ---------------
25364 function This_Name return String is
25365 begin
25366 return Get_Name_String (Chars (U));
25367 end This_Name;
25369 -- Start of processing for Unique_Name
25371 begin
25372 if E = Standard_Standard
25373 or else Has_Fully_Qualified_Name (E)
25374 then
25375 return This_Name;
25377 elsif Ekind (E) = E_Enumeration_Literal then
25378 return Unique_Name (Etype (E)) & "__" & This_Name;
25380 else
25381 declare
25382 S : constant Entity_Id := Scope (U);
25383 pragma Assert (Present (S));
25385 begin
25386 -- Prefix names of predefined types with standard__, but leave
25387 -- names of user-defined packages and subprograms without prefix
25388 -- (even if technically they are nested in the Standard package).
25390 if S = Standard_Standard then
25391 if Ekind (U) = E_Package or else Is_Subprogram (U) then
25392 return This_Name;
25393 else
25394 return Unique_Name (S) & "__" & This_Name;
25395 end if;
25397 -- For intances of generic subprograms use the name of the related
25398 -- instace and skip the scope of its wrapper package.
25400 elsif Is_Wrapper_Package (S) then
25401 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
25402 -- Wrapper package and the instantiation are in the same scope
25404 declare
25405 Enclosing_Name : constant String :=
25406 Unique_Name (Scope (S)) & "__" &
25407 Get_Name_String (Chars (Related_Instance (S)));
25409 begin
25410 if Is_Subprogram (U)
25411 and then not Is_Generic_Actual_Subprogram (U)
25412 then
25413 return Enclosing_Name;
25414 else
25415 return Enclosing_Name & "__" & This_Name;
25416 end if;
25417 end;
25419 else
25420 return Unique_Name (S) & "__" & This_Name;
25421 end if;
25422 end;
25423 end if;
25424 end Unique_Name;
25426 ---------------------
25427 -- Unit_Is_Visible --
25428 ---------------------
25430 function Unit_Is_Visible (U : Entity_Id) return Boolean is
25431 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
25432 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
25434 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
25435 -- For a child unit, check whether unit appears in a with_clause
25436 -- of a parent.
25438 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
25439 -- Scan the context clause of one compilation unit looking for a
25440 -- with_clause for the unit in question.
25442 ----------------------------
25443 -- Unit_In_Parent_Context --
25444 ----------------------------
25446 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
25447 begin
25448 if Unit_In_Context (Par_Unit) then
25449 return True;
25451 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
25452 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
25454 else
25455 return False;
25456 end if;
25457 end Unit_In_Parent_Context;
25459 ---------------------
25460 -- Unit_In_Context --
25461 ---------------------
25463 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
25464 Clause : Node_Id;
25466 begin
25467 Clause := First (Context_Items (Comp_Unit));
25468 while Present (Clause) loop
25469 if Nkind (Clause) = N_With_Clause then
25470 if Library_Unit (Clause) = U then
25471 return True;
25473 -- The with_clause may denote a renaming of the unit we are
25474 -- looking for, eg. Text_IO which renames Ada.Text_IO.
25476 elsif
25477 Renamed_Entity (Entity (Name (Clause))) =
25478 Defining_Entity (Unit (U))
25479 then
25480 return True;
25481 end if;
25482 end if;
25484 Next (Clause);
25485 end loop;
25487 return False;
25488 end Unit_In_Context;
25490 -- Start of processing for Unit_Is_Visible
25492 begin
25493 -- The currrent unit is directly visible
25495 if Curr = U then
25496 return True;
25498 elsif Unit_In_Context (Curr) then
25499 return True;
25501 -- If the current unit is a body, check the context of the spec
25503 elsif Nkind (Unit (Curr)) = N_Package_Body
25504 or else
25505 (Nkind (Unit (Curr)) = N_Subprogram_Body
25506 and then not Acts_As_Spec (Unit (Curr)))
25507 then
25508 if Unit_In_Context (Library_Unit (Curr)) then
25509 return True;
25510 end if;
25511 end if;
25513 -- If the spec is a child unit, examine the parents
25515 if Is_Child_Unit (Curr_Entity) then
25516 if Nkind (Unit (Curr)) in N_Unit_Body then
25517 return
25518 Unit_In_Parent_Context
25519 (Parent_Spec (Unit (Library_Unit (Curr))));
25520 else
25521 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
25522 end if;
25524 else
25525 return False;
25526 end if;
25527 end Unit_Is_Visible;
25529 ------------------------------
25530 -- Universal_Interpretation --
25531 ------------------------------
25533 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
25534 Index : Interp_Index;
25535 It : Interp;
25537 begin
25538 -- The argument may be a formal parameter of an operator or subprogram
25539 -- with multiple interpretations, or else an expression for an actual.
25541 if Nkind (Opnd) = N_Defining_Identifier
25542 or else not Is_Overloaded (Opnd)
25543 then
25544 if Etype (Opnd) = Universal_Integer
25545 or else Etype (Opnd) = Universal_Real
25546 then
25547 return Etype (Opnd);
25548 else
25549 return Empty;
25550 end if;
25552 else
25553 Get_First_Interp (Opnd, Index, It);
25554 while Present (It.Typ) loop
25555 if It.Typ = Universal_Integer
25556 or else It.Typ = Universal_Real
25557 then
25558 return It.Typ;
25559 end if;
25561 Get_Next_Interp (Index, It);
25562 end loop;
25564 return Empty;
25565 end if;
25566 end Universal_Interpretation;
25568 ---------------
25569 -- Unqualify --
25570 ---------------
25572 function Unqualify (Expr : Node_Id) return Node_Id is
25573 begin
25574 -- Recurse to handle unlikely case of multiple levels of qualification
25576 if Nkind (Expr) = N_Qualified_Expression then
25577 return Unqualify (Expression (Expr));
25579 -- Normal case, not a qualified expression
25581 else
25582 return Expr;
25583 end if;
25584 end Unqualify;
25586 -----------------
25587 -- Unqual_Conv --
25588 -----------------
25590 function Unqual_Conv (Expr : Node_Id) return Node_Id is
25591 begin
25592 -- Recurse to handle unlikely case of multiple levels of qualification
25593 -- and/or conversion.
25595 if Nkind_In (Expr, N_Qualified_Expression,
25596 N_Type_Conversion,
25597 N_Unchecked_Type_Conversion)
25598 then
25599 return Unqual_Conv (Expression (Expr));
25601 -- Normal case, not a qualified expression
25603 else
25604 return Expr;
25605 end if;
25606 end Unqual_Conv;
25608 --------------------
25609 -- Validated_View --
25610 --------------------
25612 function Validated_View (Typ : Entity_Id) return Entity_Id is
25613 Continue : Boolean;
25614 Val_Typ : Entity_Id;
25616 begin
25617 Continue := True;
25618 Val_Typ := Base_Type (Typ);
25620 -- Obtain the full view of the input type by stripping away concurrency,
25621 -- derivations, and privacy.
25623 while Continue loop
25624 Continue := False;
25626 if Is_Concurrent_Type (Val_Typ) then
25627 if Present (Corresponding_Record_Type (Val_Typ)) then
25628 Continue := True;
25629 Val_Typ := Corresponding_Record_Type (Val_Typ);
25630 end if;
25632 elsif Is_Derived_Type (Val_Typ) then
25633 Continue := True;
25634 Val_Typ := Etype (Val_Typ);
25636 elsif Is_Private_Type (Val_Typ) then
25637 if Present (Underlying_Full_View (Val_Typ)) then
25638 Continue := True;
25639 Val_Typ := Underlying_Full_View (Val_Typ);
25641 elsif Present (Full_View (Val_Typ)) then
25642 Continue := True;
25643 Val_Typ := Full_View (Val_Typ);
25644 end if;
25645 end if;
25646 end loop;
25648 return Val_Typ;
25649 end Validated_View;
25651 -----------------------
25652 -- Visible_Ancestors --
25653 -----------------------
25655 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
25656 List_1 : Elist_Id;
25657 List_2 : Elist_Id;
25658 Elmt : Elmt_Id;
25660 begin
25661 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
25663 -- Collect all the parents and progenitors of Typ. If the full-view of
25664 -- private parents and progenitors is available then it is used to
25665 -- generate the list of visible ancestors; otherwise their partial
25666 -- view is added to the resulting list.
25668 Collect_Parents
25669 (T => Typ,
25670 List => List_1,
25671 Use_Full_View => True);
25673 Collect_Interfaces
25674 (T => Typ,
25675 Ifaces_List => List_2,
25676 Exclude_Parents => True,
25677 Use_Full_View => True);
25679 -- Join the two lists. Avoid duplications because an interface may
25680 -- simultaneously be parent and progenitor of a type.
25682 Elmt := First_Elmt (List_2);
25683 while Present (Elmt) loop
25684 Append_Unique_Elmt (Node (Elmt), List_1);
25685 Next_Elmt (Elmt);
25686 end loop;
25688 return List_1;
25689 end Visible_Ancestors;
25691 ----------------------
25692 -- Within_Init_Proc --
25693 ----------------------
25695 function Within_Init_Proc return Boolean is
25696 S : Entity_Id;
25698 begin
25699 S := Current_Scope;
25700 while not Is_Overloadable (S) loop
25701 if S = Standard_Standard then
25702 return False;
25703 else
25704 S := Scope (S);
25705 end if;
25706 end loop;
25708 return Is_Init_Proc (S);
25709 end Within_Init_Proc;
25711 ---------------------------
25712 -- Within_Protected_Type --
25713 ---------------------------
25715 function Within_Protected_Type (E : Entity_Id) return Boolean is
25716 Scop : Entity_Id := Scope (E);
25718 begin
25719 while Present (Scop) loop
25720 if Ekind (Scop) = E_Protected_Type then
25721 return True;
25722 end if;
25724 Scop := Scope (Scop);
25725 end loop;
25727 return False;
25728 end Within_Protected_Type;
25730 ------------------
25731 -- Within_Scope --
25732 ------------------
25734 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
25735 begin
25736 return Scope_Within_Or_Same (Scope (E), S);
25737 end Within_Scope;
25739 ----------------------------
25740 -- Within_Subprogram_Call --
25741 ----------------------------
25743 function Within_Subprogram_Call (N : Node_Id) return Boolean is
25744 Par : Node_Id;
25746 begin
25747 -- Climb the parent chain looking for a function or procedure call
25749 Par := N;
25750 while Present (Par) loop
25751 if Nkind_In (Par, N_Entry_Call_Statement,
25752 N_Function_Call,
25753 N_Procedure_Call_Statement)
25754 then
25755 return True;
25757 -- Prevent the search from going too far
25759 elsif Is_Body_Or_Package_Declaration (Par) then
25760 exit;
25761 end if;
25763 Par := Parent (Par);
25764 end loop;
25766 return False;
25767 end Within_Subprogram_Call;
25769 ----------------
25770 -- Wrong_Type --
25771 ----------------
25773 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
25774 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
25775 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
25777 Matching_Field : Entity_Id;
25778 -- Entity to give a more precise suggestion on how to write a one-
25779 -- element positional aggregate.
25781 function Has_One_Matching_Field return Boolean;
25782 -- Determines if Expec_Type is a record type with a single component or
25783 -- discriminant whose type matches the found type or is one dimensional
25784 -- array whose component type matches the found type. In the case of
25785 -- one discriminant, we ignore the variant parts. That's not accurate,
25786 -- but good enough for the warning.
25788 ----------------------------
25789 -- Has_One_Matching_Field --
25790 ----------------------------
25792 function Has_One_Matching_Field return Boolean is
25793 E : Entity_Id;
25795 begin
25796 Matching_Field := Empty;
25798 if Is_Array_Type (Expec_Type)
25799 and then Number_Dimensions (Expec_Type) = 1
25800 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
25801 then
25802 -- Use type name if available. This excludes multidimensional
25803 -- arrays and anonymous arrays.
25805 if Comes_From_Source (Expec_Type) then
25806 Matching_Field := Expec_Type;
25808 -- For an assignment, use name of target
25810 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
25811 and then Is_Entity_Name (Name (Parent (Expr)))
25812 then
25813 Matching_Field := Entity (Name (Parent (Expr)));
25814 end if;
25816 return True;
25818 elsif not Is_Record_Type (Expec_Type) then
25819 return False;
25821 else
25822 E := First_Entity (Expec_Type);
25823 loop
25824 if No (E) then
25825 return False;
25827 elsif not Ekind_In (E, E_Discriminant, E_Component)
25828 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
25829 then
25830 Next_Entity (E);
25832 else
25833 exit;
25834 end if;
25835 end loop;
25837 if not Covers (Etype (E), Found_Type) then
25838 return False;
25840 elsif Present (Next_Entity (E))
25841 and then (Ekind (E) = E_Component
25842 or else Ekind (Next_Entity (E)) = E_Discriminant)
25843 then
25844 return False;
25846 else
25847 Matching_Field := E;
25848 return True;
25849 end if;
25850 end if;
25851 end Has_One_Matching_Field;
25853 -- Start of processing for Wrong_Type
25855 begin
25856 -- Don't output message if either type is Any_Type, or if a message
25857 -- has already been posted for this node. We need to do the latter
25858 -- check explicitly (it is ordinarily done in Errout), because we
25859 -- are using ! to force the output of the error messages.
25861 if Expec_Type = Any_Type
25862 or else Found_Type = Any_Type
25863 or else Error_Posted (Expr)
25864 then
25865 return;
25867 -- If one of the types is a Taft-Amendment type and the other it its
25868 -- completion, it must be an illegal use of a TAT in the spec, for
25869 -- which an error was already emitted. Avoid cascaded errors.
25871 elsif Is_Incomplete_Type (Expec_Type)
25872 and then Has_Completion_In_Body (Expec_Type)
25873 and then Full_View (Expec_Type) = Etype (Expr)
25874 then
25875 return;
25877 elsif Is_Incomplete_Type (Etype (Expr))
25878 and then Has_Completion_In_Body (Etype (Expr))
25879 and then Full_View (Etype (Expr)) = Expec_Type
25880 then
25881 return;
25883 -- In an instance, there is an ongoing problem with completion of
25884 -- type derived from private types. Their structure is what Gigi
25885 -- expects, but the Etype is the parent type rather than the
25886 -- derived private type itself. Do not flag error in this case. The
25887 -- private completion is an entity without a parent, like an Itype.
25888 -- Similarly, full and partial views may be incorrect in the instance.
25889 -- There is no simple way to insure that it is consistent ???
25891 -- A similar view discrepancy can happen in an inlined body, for the
25892 -- same reason: inserted body may be outside of the original package
25893 -- and only partial views are visible at the point of insertion.
25895 elsif In_Instance or else In_Inlined_Body then
25896 if Etype (Etype (Expr)) = Etype (Expected_Type)
25897 and then
25898 (Has_Private_Declaration (Expected_Type)
25899 or else Has_Private_Declaration (Etype (Expr)))
25900 and then No (Parent (Expected_Type))
25901 then
25902 return;
25904 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
25905 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
25906 then
25907 return;
25909 elsif Is_Private_Type (Expected_Type)
25910 and then Present (Full_View (Expected_Type))
25911 and then Covers (Full_View (Expected_Type), Etype (Expr))
25912 then
25913 return;
25915 -- Conversely, type of expression may be the private one
25917 elsif Is_Private_Type (Base_Type (Etype (Expr)))
25918 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
25919 then
25920 return;
25921 end if;
25922 end if;
25924 -- An interesting special check. If the expression is parenthesized
25925 -- and its type corresponds to the type of the sole component of the
25926 -- expected record type, or to the component type of the expected one
25927 -- dimensional array type, then assume we have a bad aggregate attempt.
25929 if Nkind (Expr) in N_Subexpr
25930 and then Paren_Count (Expr) /= 0
25931 and then Has_One_Matching_Field
25932 then
25933 Error_Msg_N ("positional aggregate cannot have one component", Expr);
25935 if Present (Matching_Field) then
25936 if Is_Array_Type (Expec_Type) then
25937 Error_Msg_NE
25938 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
25939 else
25940 Error_Msg_NE
25941 ("\write instead `& ='> ...`", Expr, Matching_Field);
25942 end if;
25943 end if;
25945 -- Another special check, if we are looking for a pool-specific access
25946 -- type and we found an E_Access_Attribute_Type, then we have the case
25947 -- of an Access attribute being used in a context which needs a pool-
25948 -- specific type, which is never allowed. The one extra check we make
25949 -- is that the expected designated type covers the Found_Type.
25951 elsif Is_Access_Type (Expec_Type)
25952 and then Ekind (Found_Type) = E_Access_Attribute_Type
25953 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
25954 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
25955 and then Covers
25956 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
25957 then
25958 Error_Msg_N -- CODEFIX
25959 ("result must be general access type!", Expr);
25960 Error_Msg_NE -- CODEFIX
25961 ("add ALL to }!", Expr, Expec_Type);
25963 -- Another special check, if the expected type is an integer type,
25964 -- but the expression is of type System.Address, and the parent is
25965 -- an addition or subtraction operation whose left operand is the
25966 -- expression in question and whose right operand is of an integral
25967 -- type, then this is an attempt at address arithmetic, so give
25968 -- appropriate message.
25970 elsif Is_Integer_Type (Expec_Type)
25971 and then Is_RTE (Found_Type, RE_Address)
25972 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
25973 and then Expr = Left_Opnd (Parent (Expr))
25974 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
25975 then
25976 Error_Msg_N
25977 ("address arithmetic not predefined in package System",
25978 Parent (Expr));
25979 Error_Msg_N
25980 ("\possible missing with/use of System.Storage_Elements",
25981 Parent (Expr));
25982 return;
25984 -- If the expected type is an anonymous access type, as for access
25985 -- parameters and discriminants, the error is on the designated types.
25987 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
25988 if Comes_From_Source (Expec_Type) then
25989 Error_Msg_NE ("expected}!", Expr, Expec_Type);
25990 else
25991 Error_Msg_NE
25992 ("expected an access type with designated}",
25993 Expr, Designated_Type (Expec_Type));
25994 end if;
25996 if Is_Access_Type (Found_Type)
25997 and then not Comes_From_Source (Found_Type)
25998 then
25999 Error_Msg_NE
26000 ("\\found an access type with designated}!",
26001 Expr, Designated_Type (Found_Type));
26002 else
26003 if From_Limited_With (Found_Type) then
26004 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
26005 Error_Msg_Qual_Level := 99;
26006 Error_Msg_NE -- CODEFIX
26007 ("\\missing `WITH &;", Expr, Scope (Found_Type));
26008 Error_Msg_Qual_Level := 0;
26009 else
26010 Error_Msg_NE ("found}!", Expr, Found_Type);
26011 end if;
26012 end if;
26014 -- Normal case of one type found, some other type expected
26016 else
26017 -- If the names of the two types are the same, see if some number
26018 -- of levels of qualification will help. Don't try more than three
26019 -- levels, and if we get to standard, it's no use (and probably
26020 -- represents an error in the compiler) Also do not bother with
26021 -- internal scope names.
26023 declare
26024 Expec_Scope : Entity_Id;
26025 Found_Scope : Entity_Id;
26027 begin
26028 Expec_Scope := Expec_Type;
26029 Found_Scope := Found_Type;
26031 for Levels in Nat range 0 .. 3 loop
26032 if Chars (Expec_Scope) /= Chars (Found_Scope) then
26033 Error_Msg_Qual_Level := Levels;
26034 exit;
26035 end if;
26037 Expec_Scope := Scope (Expec_Scope);
26038 Found_Scope := Scope (Found_Scope);
26040 exit when Expec_Scope = Standard_Standard
26041 or else Found_Scope = Standard_Standard
26042 or else not Comes_From_Source (Expec_Scope)
26043 or else not Comes_From_Source (Found_Scope);
26044 end loop;
26045 end;
26047 if Is_Record_Type (Expec_Type)
26048 and then Present (Corresponding_Remote_Type (Expec_Type))
26049 then
26050 Error_Msg_NE ("expected}!", Expr,
26051 Corresponding_Remote_Type (Expec_Type));
26052 else
26053 Error_Msg_NE ("expected}!", Expr, Expec_Type);
26054 end if;
26056 if Is_Entity_Name (Expr)
26057 and then Is_Package_Or_Generic_Package (Entity (Expr))
26058 then
26059 Error_Msg_N ("\\found package name!", Expr);
26061 elsif Is_Entity_Name (Expr)
26062 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
26063 then
26064 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
26065 Error_Msg_N
26066 ("found procedure name, possibly missing Access attribute!",
26067 Expr);
26068 else
26069 Error_Msg_N
26070 ("\\found procedure name instead of function!", Expr);
26071 end if;
26073 elsif Nkind (Expr) = N_Function_Call
26074 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
26075 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
26076 and then No (Parameter_Associations (Expr))
26077 then
26078 Error_Msg_N
26079 ("found function name, possibly missing Access attribute!",
26080 Expr);
26082 -- Catch common error: a prefix or infix operator which is not
26083 -- directly visible because the type isn't.
26085 elsif Nkind (Expr) in N_Op
26086 and then Is_Overloaded (Expr)
26087 and then not Is_Immediately_Visible (Expec_Type)
26088 and then not Is_Potentially_Use_Visible (Expec_Type)
26089 and then not In_Use (Expec_Type)
26090 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
26091 then
26092 Error_Msg_N
26093 ("operator of the type is not directly visible!", Expr);
26095 elsif Ekind (Found_Type) = E_Void
26096 and then Present (Parent (Found_Type))
26097 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
26098 then
26099 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
26101 else
26102 Error_Msg_NE ("\\found}!", Expr, Found_Type);
26103 end if;
26105 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
26106 -- of the same modular type, and (M1 and M2) = 0 was intended.
26108 if Expec_Type = Standard_Boolean
26109 and then Is_Modular_Integer_Type (Found_Type)
26110 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
26111 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
26112 then
26113 declare
26114 Op : constant Node_Id := Right_Opnd (Parent (Expr));
26115 L : constant Node_Id := Left_Opnd (Op);
26116 R : constant Node_Id := Right_Opnd (Op);
26118 begin
26119 -- The case for the message is when the left operand of the
26120 -- comparison is the same modular type, or when it is an
26121 -- integer literal (or other universal integer expression),
26122 -- which would have been typed as the modular type if the
26123 -- parens had been there.
26125 if (Etype (L) = Found_Type
26126 or else
26127 Etype (L) = Universal_Integer)
26128 and then Is_Integer_Type (Etype (R))
26129 then
26130 Error_Msg_N
26131 ("\\possible missing parens for modular operation", Expr);
26132 end if;
26133 end;
26134 end if;
26136 -- Reset error message qualification indication
26138 Error_Msg_Qual_Level := 0;
26139 end if;
26140 end Wrong_Type;
26142 --------------------------------
26143 -- Yields_Synchronized_Object --
26144 --------------------------------
26146 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
26147 Has_Sync_Comp : Boolean := False;
26148 Id : Entity_Id;
26150 begin
26151 -- An array type yields a synchronized object if its component type
26152 -- yields a synchronized object.
26154 if Is_Array_Type (Typ) then
26155 return Yields_Synchronized_Object (Component_Type (Typ));
26157 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
26158 -- yields a synchronized object by default.
26160 elsif Is_Descendant_Of_Suspension_Object (Typ) then
26161 return True;
26163 -- A protected type yields a synchronized object by default
26165 elsif Is_Protected_Type (Typ) then
26166 return True;
26168 -- A record type or type extension yields a synchronized object when its
26169 -- discriminants (if any) lack default values and all components are of
26170 -- a type that yelds a synchronized object.
26172 elsif Is_Record_Type (Typ) then
26174 -- Inspect all entities defined in the scope of the type, looking for
26175 -- components of a type that does not yeld a synchronized object or
26176 -- for discriminants with default values.
26178 Id := First_Entity (Typ);
26179 while Present (Id) loop
26180 if Comes_From_Source (Id) then
26181 if Ekind (Id) = E_Component then
26182 if Yields_Synchronized_Object (Etype (Id)) then
26183 Has_Sync_Comp := True;
26185 -- The component does not yield a synchronized object
26187 else
26188 return False;
26189 end if;
26191 elsif Ekind (Id) = E_Discriminant
26192 and then Present (Expression (Parent (Id)))
26193 then
26194 return False;
26195 end if;
26196 end if;
26198 Next_Entity (Id);
26199 end loop;
26201 -- Ensure that the parent type of a type extension yields a
26202 -- synchronized object.
26204 if Etype (Typ) /= Typ
26205 and then not Yields_Synchronized_Object (Etype (Typ))
26206 then
26207 return False;
26208 end if;
26210 -- If we get here, then all discriminants lack default values and all
26211 -- components are of a type that yields a synchronized object.
26213 return Has_Sync_Comp;
26215 -- A synchronized interface type yields a synchronized object by default
26217 elsif Is_Synchronized_Interface (Typ) then
26218 return True;
26220 -- A task type yelds a synchronized object by default
26222 elsif Is_Task_Type (Typ) then
26223 return True;
26225 -- Otherwise the type does not yield a synchronized object
26227 else
26228 return False;
26229 end if;
26230 end Yields_Synchronized_Object;
26232 ---------------------------
26233 -- Yields_Universal_Type --
26234 ---------------------------
26236 function Yields_Universal_Type (N : Node_Id) return Boolean is
26237 begin
26238 -- Integer and real literals are of a universal type
26240 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
26241 return True;
26243 -- The values of certain attributes are of a universal type
26245 elsif Nkind (N) = N_Attribute_Reference then
26246 return
26247 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
26249 -- ??? There are possibly other cases to consider
26251 else
26252 return False;
26253 end if;
26254 end Yields_Universal_Type;
26256 begin
26257 Erroutc.Subprogram_Name_Ptr := Subprogram_Name'Access;
26258 end Sem_Util;