Fix CL.
[official-gcc.git] / gcc / ada / sem_util.adb
blob1d78642e659fb2314bf71256cfb4624a0cf7bed7
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-2016, 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 Exp_Ch11; use Exp_Ch11;
36 with Exp_Disp; use Exp_Disp;
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_Eval; use Sem_Eval;
56 with Sem_Prag; use Sem_Prag;
57 with Sem_Res; use Sem_Res;
58 with Sem_Warn; use Sem_Warn;
59 with Sem_Type; use Sem_Type;
60 with Sinfo; use Sinfo;
61 with Sinput; use Sinput;
62 with Stand; use Stand;
63 with Style;
64 with Stringt; use Stringt;
65 with Targparm; use Targparm;
66 with Tbuild; use Tbuild;
67 with Ttypes; use Ttypes;
68 with Uname; use Uname;
70 with GNAT.HTable; use GNAT.HTable;
72 package body Sem_Util is
74 -----------------------
75 -- Local Subprograms --
76 -----------------------
78 function Build_Component_Subtype
79 (C : List_Id;
80 Loc : Source_Ptr;
81 T : Entity_Id) return Node_Id;
82 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
83 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
84 -- Loc is the source location, T is the original subtype.
86 function Has_Enabled_Property
87 (Item_Id : Entity_Id;
88 Property : Name_Id) return Boolean;
89 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
90 -- Determine whether an abstract state or a variable denoted by entity
91 -- Item_Id has enabled property Property.
93 function Has_Null_Extension (T : Entity_Id) return Boolean;
94 -- T is a derived tagged type. Check whether the type extension is null.
95 -- If the parent type is fully initialized, T can be treated as such.
97 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
98 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
99 -- with discriminants whose default values are static, examine only the
100 -- components in the selected variant to determine whether all of them
101 -- have a default.
103 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
104 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean;
105 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
106 -- the time being. New_Requires_Transient_Scope is used by default; the
107 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
108 -- instead. The intent is to use this temporarily to measure before/after
109 -- efficiency. Note: when this temporary code is removed, the documentation
110 -- of dQ in debug.adb should be removed.
112 procedure Results_Differ
113 (Id : Entity_Id;
114 Old_Val : Boolean;
115 New_Val : Boolean);
116 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
117 -- routine will be removed eventially when New_Requires_Transient_Scope
118 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
119 -- eliminated.
121 ------------------------------
122 -- Abstract_Interface_List --
123 ------------------------------
125 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
126 Nod : Node_Id;
128 begin
129 if Is_Concurrent_Type (Typ) then
131 -- If we are dealing with a synchronized subtype, go to the base
132 -- type, whose declaration has the interface list.
134 -- Shouldn't this be Declaration_Node???
136 Nod := Parent (Base_Type (Typ));
138 if Nkind (Nod) = N_Full_Type_Declaration then
139 return Empty_List;
140 end if;
142 elsif Ekind (Typ) = E_Record_Type_With_Private then
143 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
144 Nod := Type_Definition (Parent (Typ));
146 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
147 if Present (Full_View (Typ))
148 and then
149 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
150 then
151 Nod := Type_Definition (Parent (Full_View (Typ)));
153 -- If the full-view is not available we cannot do anything else
154 -- here (the source has errors).
156 else
157 return Empty_List;
158 end if;
160 -- Support for generic formals with interfaces is still missing ???
162 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
163 return Empty_List;
165 else
166 pragma Assert
167 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
168 Nod := Parent (Typ);
169 end if;
171 elsif Ekind (Typ) = E_Record_Subtype then
172 Nod := Type_Definition (Parent (Etype (Typ)));
174 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
176 -- Recurse, because parent may still be a private extension. Also
177 -- note that the full view of the subtype or the full view of its
178 -- base type may (both) be unavailable.
180 return Abstract_Interface_List (Etype (Typ));
182 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
183 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
184 Nod := Formal_Type_Definition (Parent (Typ));
185 else
186 Nod := Type_Definition (Parent (Typ));
187 end if;
188 end if;
190 return Interface_List (Nod);
191 end Abstract_Interface_List;
193 --------------------------------
194 -- Add_Access_Type_To_Process --
195 --------------------------------
197 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
198 L : Elist_Id;
200 begin
201 Ensure_Freeze_Node (E);
202 L := Access_Types_To_Process (Freeze_Node (E));
204 if No (L) then
205 L := New_Elmt_List;
206 Set_Access_Types_To_Process (Freeze_Node (E), L);
207 end if;
209 Append_Elmt (A, L);
210 end Add_Access_Type_To_Process;
212 --------------------------
213 -- Add_Block_Identifier --
214 --------------------------
216 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
217 Loc : constant Source_Ptr := Sloc (N);
219 begin
220 pragma Assert (Nkind (N) = N_Block_Statement);
222 -- The block already has a label, return its entity
224 if Present (Identifier (N)) then
225 Id := Entity (Identifier (N));
227 -- Create a new block label and set its attributes
229 else
230 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
231 Set_Etype (Id, Standard_Void_Type);
232 Set_Parent (Id, N);
234 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
235 Set_Block_Node (Id, Identifier (N));
236 end if;
237 end Add_Block_Identifier;
239 ----------------------------
240 -- Add_Global_Declaration --
241 ----------------------------
243 procedure Add_Global_Declaration (N : Node_Id) is
244 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
246 begin
247 if No (Declarations (Aux_Node)) then
248 Set_Declarations (Aux_Node, New_List);
249 end if;
251 Append_To (Declarations (Aux_Node), N);
252 Analyze (N);
253 end Add_Global_Declaration;
255 --------------------------------
256 -- Address_Integer_Convert_OK --
257 --------------------------------
259 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
260 begin
261 if Allow_Integer_Address
262 and then ((Is_Descendant_Of_Address (T1)
263 and then Is_Private_Type (T1)
264 and then Is_Integer_Type (T2))
265 or else
266 (Is_Descendant_Of_Address (T2)
267 and then Is_Private_Type (T2)
268 and then Is_Integer_Type (T1)))
269 then
270 return True;
271 else
272 return False;
273 end if;
274 end Address_Integer_Convert_OK;
276 -------------------
277 -- Address_Value --
278 -------------------
280 function Address_Value (N : Node_Id) return Node_Id is
281 Expr : Node_Id := N;
283 begin
284 loop
285 -- For constant, get constant expression
287 if Is_Entity_Name (Expr)
288 and then Ekind (Entity (Expr)) = E_Constant
289 then
290 Expr := Constant_Value (Entity (Expr));
292 -- For unchecked conversion, get result to convert
294 elsif Nkind (Expr) = N_Unchecked_Type_Conversion then
295 Expr := Expression (Expr);
297 -- For (common case) of To_Address call, get argument
299 elsif Nkind (Expr) = N_Function_Call
300 and then Is_Entity_Name (Name (Expr))
301 and then Is_RTE (Entity (Name (Expr)), RE_To_Address)
302 then
303 Expr := First (Parameter_Associations (Expr));
305 if Nkind (Expr) = N_Parameter_Association then
306 Expr := Explicit_Actual_Parameter (Expr);
307 end if;
309 -- We finally have the real expression
311 else
312 exit;
313 end if;
314 end loop;
316 return Expr;
317 end Address_Value;
319 -----------------
320 -- Addressable --
321 -----------------
323 -- For now, just 8/16/32/64
325 function Addressable (V : Uint) return Boolean is
326 begin
327 return V = Uint_8 or else
328 V = Uint_16 or else
329 V = Uint_32 or else
330 V = Uint_64;
331 end Addressable;
333 function Addressable (V : Int) return Boolean is
334 begin
335 return V = 8 or else
336 V = 16 or else
337 V = 32 or else
338 V = 64;
339 end Addressable;
341 ---------------------------------
342 -- Aggregate_Constraint_Checks --
343 ---------------------------------
345 procedure Aggregate_Constraint_Checks
346 (Exp : Node_Id;
347 Check_Typ : Entity_Id)
349 Exp_Typ : constant Entity_Id := Etype (Exp);
351 begin
352 if Raises_Constraint_Error (Exp) then
353 return;
354 end if;
356 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
357 -- component's type to force the appropriate accessibility checks.
359 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
360 -- force the corresponding run-time check
362 if Is_Access_Type (Check_Typ)
363 and then Is_Local_Anonymous_Access (Check_Typ)
364 then
365 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
366 Analyze_And_Resolve (Exp, Check_Typ);
367 Check_Unset_Reference (Exp);
368 end if;
370 -- What follows is really expansion activity, so check that expansion
371 -- is on and is allowed. In GNATprove mode, we also want check flags to
372 -- be added in the tree, so that the formal verification can rely on
373 -- those to be present. In GNATprove mode for formal verification, some
374 -- treatment typically only done during expansion needs to be performed
375 -- on the tree, but it should not be applied inside generics. Otherwise,
376 -- this breaks the name resolution mechanism for generic instances.
378 if not Expander_Active
379 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
380 then
381 return;
382 end if;
384 if Is_Access_Type (Check_Typ)
385 and then Can_Never_Be_Null (Check_Typ)
386 and then not Can_Never_Be_Null (Exp_Typ)
387 then
388 Install_Null_Excluding_Check (Exp);
389 end if;
391 -- First check if we have to insert discriminant checks
393 if Has_Discriminants (Exp_Typ) then
394 Apply_Discriminant_Check (Exp, Check_Typ);
396 -- Next emit length checks for array aggregates
398 elsif Is_Array_Type (Exp_Typ) then
399 Apply_Length_Check (Exp, Check_Typ);
401 -- Finally emit scalar and string checks. If we are dealing with a
402 -- scalar literal we need to check by hand because the Etype of
403 -- literals is not necessarily correct.
405 elsif Is_Scalar_Type (Exp_Typ)
406 and then Compile_Time_Known_Value (Exp)
407 then
408 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
409 Apply_Compile_Time_Constraint_Error
410 (Exp, "value not in range of}??", CE_Range_Check_Failed,
411 Ent => Base_Type (Check_Typ),
412 Typ => Base_Type (Check_Typ));
414 elsif Is_Out_Of_Range (Exp, Check_Typ) then
415 Apply_Compile_Time_Constraint_Error
416 (Exp, "value not in range of}??", CE_Range_Check_Failed,
417 Ent => Check_Typ,
418 Typ => Check_Typ);
420 elsif not Range_Checks_Suppressed (Check_Typ) then
421 Apply_Scalar_Range_Check (Exp, Check_Typ);
422 end if;
424 -- Verify that target type is also scalar, to prevent view anomalies
425 -- in instantiations.
427 elsif (Is_Scalar_Type (Exp_Typ)
428 or else Nkind (Exp) = N_String_Literal)
429 and then Is_Scalar_Type (Check_Typ)
430 and then Exp_Typ /= Check_Typ
431 then
432 if Is_Entity_Name (Exp)
433 and then Ekind (Entity (Exp)) = E_Constant
434 then
435 -- If expression is a constant, it is worthwhile checking whether
436 -- it is a bound of the type.
438 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
439 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
440 or else
441 (Is_Entity_Name (Type_High_Bound (Check_Typ))
442 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
443 then
444 return;
446 else
447 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
448 Analyze_And_Resolve (Exp, Check_Typ);
449 Check_Unset_Reference (Exp);
450 end if;
452 -- Could use a comment on this case ???
454 else
455 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
456 Analyze_And_Resolve (Exp, Check_Typ);
457 Check_Unset_Reference (Exp);
458 end if;
460 end if;
461 end Aggregate_Constraint_Checks;
463 -----------------------
464 -- Alignment_In_Bits --
465 -----------------------
467 function Alignment_In_Bits (E : Entity_Id) return Uint is
468 begin
469 return Alignment (E) * System_Storage_Unit;
470 end Alignment_In_Bits;
472 --------------------------------------
473 -- All_Composite_Constraints_Static --
474 --------------------------------------
476 function All_Composite_Constraints_Static
477 (Constr : Node_Id) return Boolean
479 begin
480 if No (Constr) or else Error_Posted (Constr) then
481 return True;
482 end if;
484 case Nkind (Constr) is
485 when N_Subexpr =>
486 if Nkind (Constr) in N_Has_Entity
487 and then Present (Entity (Constr))
488 then
489 if Is_Type (Entity (Constr)) then
490 return
491 not Is_Discrete_Type (Entity (Constr))
492 or else Is_OK_Static_Subtype (Entity (Constr));
493 end if;
495 elsif Nkind (Constr) = N_Range then
496 return
497 Is_OK_Static_Expression (Low_Bound (Constr))
498 and then
499 Is_OK_Static_Expression (High_Bound (Constr));
501 elsif Nkind (Constr) = N_Attribute_Reference
502 and then Attribute_Name (Constr) = Name_Range
503 then
504 return
505 Is_OK_Static_Expression
506 (Type_Low_Bound (Etype (Prefix (Constr))))
507 and then
508 Is_OK_Static_Expression
509 (Type_High_Bound (Etype (Prefix (Constr))));
510 end if;
512 return
513 not Present (Etype (Constr)) -- previous error
514 or else not Is_Discrete_Type (Etype (Constr))
515 or else Is_OK_Static_Expression (Constr);
517 when N_Discriminant_Association =>
518 return All_Composite_Constraints_Static (Expression (Constr));
520 when N_Range_Constraint =>
521 return
522 All_Composite_Constraints_Static (Range_Expression (Constr));
524 when N_Index_Or_Discriminant_Constraint =>
525 declare
526 One_Cstr : Entity_Id;
527 begin
528 One_Cstr := First (Constraints (Constr));
529 while Present (One_Cstr) loop
530 if not All_Composite_Constraints_Static (One_Cstr) then
531 return False;
532 end if;
534 Next (One_Cstr);
535 end loop;
536 end;
538 return True;
540 when N_Subtype_Indication =>
541 return
542 All_Composite_Constraints_Static (Subtype_Mark (Constr))
543 and then
544 All_Composite_Constraints_Static (Constraint (Constr));
546 when others =>
547 raise Program_Error;
548 end case;
549 end All_Composite_Constraints_Static;
551 ---------------------------------
552 -- Append_Inherited_Subprogram --
553 ---------------------------------
555 procedure Append_Inherited_Subprogram (S : Entity_Id) is
556 Par : constant Entity_Id := Alias (S);
557 -- The parent subprogram
559 Scop : constant Entity_Id := Scope (Par);
560 -- The scope of definition of the parent subprogram
562 Typ : constant Entity_Id := Defining_Entity (Parent (S));
563 -- The derived type of which S is a primitive operation
565 Decl : Node_Id;
566 Next_E : Entity_Id;
568 begin
569 if Ekind (Current_Scope) = E_Package
570 and then In_Private_Part (Current_Scope)
571 and then Has_Private_Declaration (Typ)
572 and then Is_Tagged_Type (Typ)
573 and then Scop = Current_Scope
574 then
575 -- The inherited operation is available at the earliest place after
576 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
577 -- relevant for type extensions. If the parent operation appears
578 -- after the type extension, the operation is not visible.
580 Decl := First
581 (Visible_Declarations
582 (Package_Specification (Current_Scope)));
583 while Present (Decl) loop
584 if Nkind (Decl) = N_Private_Extension_Declaration
585 and then Defining_Entity (Decl) = Typ
586 then
587 if Sloc (Decl) > Sloc (Par) then
588 Next_E := Next_Entity (Par);
589 Set_Next_Entity (Par, S);
590 Set_Next_Entity (S, Next_E);
591 return;
593 else
594 exit;
595 end if;
596 end if;
598 Next (Decl);
599 end loop;
600 end if;
602 -- If partial view is not a type extension, or it appears before the
603 -- subprogram declaration, insert normally at end of entity list.
605 Append_Entity (S, Current_Scope);
606 end Append_Inherited_Subprogram;
608 -----------------------------------------
609 -- Apply_Compile_Time_Constraint_Error --
610 -----------------------------------------
612 procedure Apply_Compile_Time_Constraint_Error
613 (N : Node_Id;
614 Msg : String;
615 Reason : RT_Exception_Code;
616 Ent : Entity_Id := Empty;
617 Typ : Entity_Id := Empty;
618 Loc : Source_Ptr := No_Location;
619 Rep : Boolean := True;
620 Warn : Boolean := False)
622 Stat : constant Boolean := Is_Static_Expression (N);
623 R_Stat : constant Node_Id :=
624 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
625 Rtyp : Entity_Id;
627 begin
628 if No (Typ) then
629 Rtyp := Etype (N);
630 else
631 Rtyp := Typ;
632 end if;
634 Discard_Node
635 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
637 -- In GNATprove mode, do not replace the node with an exception raised.
638 -- In such a case, either the call to Compile_Time_Constraint_Error
639 -- issues an error which stops analysis, or it issues a warning in
640 -- a few cases where a suitable check flag is set for GNATprove to
641 -- generate a check message.
643 if not Rep or GNATprove_Mode then
644 return;
645 end if;
647 -- Now we replace the node by an N_Raise_Constraint_Error node
648 -- This does not need reanalyzing, so set it as analyzed now.
650 Rewrite (N, R_Stat);
651 Set_Analyzed (N, True);
653 Set_Etype (N, Rtyp);
654 Set_Raises_Constraint_Error (N);
656 -- Now deal with possible local raise handling
658 Possible_Local_Raise (N, Standard_Constraint_Error);
660 -- If the original expression was marked as static, the result is
661 -- still marked as static, but the Raises_Constraint_Error flag is
662 -- always set so that further static evaluation is not attempted.
664 if Stat then
665 Set_Is_Static_Expression (N);
666 end if;
667 end Apply_Compile_Time_Constraint_Error;
669 ---------------------------
670 -- Async_Readers_Enabled --
671 ---------------------------
673 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
674 begin
675 return Has_Enabled_Property (Id, Name_Async_Readers);
676 end Async_Readers_Enabled;
678 ---------------------------
679 -- Async_Writers_Enabled --
680 ---------------------------
682 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
683 begin
684 return Has_Enabled_Property (Id, Name_Async_Writers);
685 end Async_Writers_Enabled;
687 --------------------------------------
688 -- Available_Full_View_Of_Component --
689 --------------------------------------
691 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
692 ST : constant Entity_Id := Scope (T);
693 SCT : constant Entity_Id := Scope (Component_Type (T));
694 begin
695 return In_Open_Scopes (ST)
696 and then In_Open_Scopes (SCT)
697 and then Scope_Depth (ST) >= Scope_Depth (SCT);
698 end Available_Full_View_Of_Component;
700 -------------------
701 -- Bad_Attribute --
702 -------------------
704 procedure Bad_Attribute
705 (N : Node_Id;
706 Nam : Name_Id;
707 Warn : Boolean := False)
709 begin
710 Error_Msg_Warn := Warn;
711 Error_Msg_N ("unrecognized attribute&<<", N);
713 -- Check for possible misspelling
715 Error_Msg_Name_1 := First_Attribute_Name;
716 while Error_Msg_Name_1 <= Last_Attribute_Name loop
717 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
718 Error_Msg_N -- CODEFIX
719 ("\possible misspelling of %<<", N);
720 exit;
721 end if;
723 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
724 end loop;
725 end Bad_Attribute;
727 --------------------------------
728 -- Bad_Predicated_Subtype_Use --
729 --------------------------------
731 procedure Bad_Predicated_Subtype_Use
732 (Msg : String;
733 N : Node_Id;
734 Typ : Entity_Id;
735 Suggest_Static : Boolean := False)
737 Gen : Entity_Id;
739 begin
740 -- Avoid cascaded errors
742 if Error_Posted (N) then
743 return;
744 end if;
746 if Inside_A_Generic then
747 Gen := Current_Scope;
748 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
749 Gen := Scope (Gen);
750 end loop;
752 if No (Gen) then
753 return;
754 end if;
756 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
757 Set_No_Predicate_On_Actual (Typ);
758 end if;
760 elsif Has_Predicates (Typ) then
761 if Is_Generic_Actual_Type (Typ) then
763 -- The restriction on loop parameters is only that the type
764 -- should have no dynamic predicates.
766 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
767 and then not Has_Dynamic_Predicate_Aspect (Typ)
768 and then Is_OK_Static_Subtype (Typ)
769 then
770 return;
771 end if;
773 Gen := Current_Scope;
774 while not Is_Generic_Instance (Gen) loop
775 Gen := Scope (Gen);
776 end loop;
778 pragma Assert (Present (Gen));
780 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
781 Error_Msg_Warn := SPARK_Mode /= On;
782 Error_Msg_FE (Msg & "<<", N, Typ);
783 Error_Msg_F ("\Program_Error [<<", N);
785 Insert_Action (N,
786 Make_Raise_Program_Error (Sloc (N),
787 Reason => PE_Bad_Predicated_Generic_Type));
789 else
790 Error_Msg_FE (Msg & "<<", N, Typ);
791 end if;
793 else
794 Error_Msg_FE (Msg, N, Typ);
795 end if;
797 -- Emit an optional suggestion on how to remedy the error if the
798 -- context warrants it.
800 if Suggest_Static and then Has_Static_Predicate (Typ) then
801 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
802 end if;
803 end if;
804 end Bad_Predicated_Subtype_Use;
806 -----------------------------------------
807 -- Bad_Unordered_Enumeration_Reference --
808 -----------------------------------------
810 function Bad_Unordered_Enumeration_Reference
811 (N : Node_Id;
812 T : Entity_Id) return Boolean
814 begin
815 return Is_Enumeration_Type (T)
816 and then Warn_On_Unordered_Enumeration_Type
817 and then not Is_Generic_Type (T)
818 and then Comes_From_Source (N)
819 and then not Has_Pragma_Ordered (T)
820 and then not In_Same_Extended_Unit (N, T);
821 end Bad_Unordered_Enumeration_Reference;
823 --------------------------
824 -- Build_Actual_Subtype --
825 --------------------------
827 function Build_Actual_Subtype
828 (T : Entity_Id;
829 N : Node_Or_Entity_Id) return Node_Id
831 Loc : Source_Ptr;
832 -- Normally Sloc (N), but may point to corresponding body in some cases
834 Constraints : List_Id;
835 Decl : Node_Id;
836 Discr : Entity_Id;
837 Hi : Node_Id;
838 Lo : Node_Id;
839 Subt : Entity_Id;
840 Disc_Type : Entity_Id;
841 Obj : Node_Id;
843 begin
844 Loc := Sloc (N);
846 if Nkind (N) = N_Defining_Identifier then
847 Obj := New_Occurrence_Of (N, Loc);
849 -- If this is a formal parameter of a subprogram declaration, and
850 -- we are compiling the body, we want the declaration for the
851 -- actual subtype to carry the source position of the body, to
852 -- prevent anomalies in gdb when stepping through the code.
854 if Is_Formal (N) then
855 declare
856 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
857 begin
858 if Nkind (Decl) = N_Subprogram_Declaration
859 and then Present (Corresponding_Body (Decl))
860 then
861 Loc := Sloc (Corresponding_Body (Decl));
862 end if;
863 end;
864 end if;
866 else
867 Obj := N;
868 end if;
870 if Is_Array_Type (T) then
871 Constraints := New_List;
872 for J in 1 .. Number_Dimensions (T) loop
874 -- Build an array subtype declaration with the nominal subtype and
875 -- the bounds of the actual. Add the declaration in front of the
876 -- local declarations for the subprogram, for analysis before any
877 -- reference to the formal in the body.
879 Lo :=
880 Make_Attribute_Reference (Loc,
881 Prefix =>
882 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
883 Attribute_Name => Name_First,
884 Expressions => New_List (
885 Make_Integer_Literal (Loc, J)));
887 Hi :=
888 Make_Attribute_Reference (Loc,
889 Prefix =>
890 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
891 Attribute_Name => Name_Last,
892 Expressions => New_List (
893 Make_Integer_Literal (Loc, J)));
895 Append (Make_Range (Loc, Lo, Hi), Constraints);
896 end loop;
898 -- If the type has unknown discriminants there is no constrained
899 -- subtype to build. This is never called for a formal or for a
900 -- lhs, so returning the type is ok ???
902 elsif Has_Unknown_Discriminants (T) then
903 return T;
905 else
906 Constraints := New_List;
908 -- Type T is a generic derived type, inherit the discriminants from
909 -- the parent type.
911 if Is_Private_Type (T)
912 and then No (Full_View (T))
914 -- T was flagged as an error if it was declared as a formal
915 -- derived type with known discriminants. In this case there
916 -- is no need to look at the parent type since T already carries
917 -- its own discriminants.
919 and then not Error_Posted (T)
920 then
921 Disc_Type := Etype (Base_Type (T));
922 else
923 Disc_Type := T;
924 end if;
926 Discr := First_Discriminant (Disc_Type);
927 while Present (Discr) loop
928 Append_To (Constraints,
929 Make_Selected_Component (Loc,
930 Prefix =>
931 Duplicate_Subexpr_No_Checks (Obj),
932 Selector_Name => New_Occurrence_Of (Discr, Loc)));
933 Next_Discriminant (Discr);
934 end loop;
935 end if;
937 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
938 Set_Is_Internal (Subt);
940 Decl :=
941 Make_Subtype_Declaration (Loc,
942 Defining_Identifier => Subt,
943 Subtype_Indication =>
944 Make_Subtype_Indication (Loc,
945 Subtype_Mark => New_Occurrence_Of (T, Loc),
946 Constraint =>
947 Make_Index_Or_Discriminant_Constraint (Loc,
948 Constraints => Constraints)));
950 Mark_Rewrite_Insertion (Decl);
951 return Decl;
952 end Build_Actual_Subtype;
954 ---------------------------------------
955 -- Build_Actual_Subtype_Of_Component --
956 ---------------------------------------
958 function Build_Actual_Subtype_Of_Component
959 (T : Entity_Id;
960 N : Node_Id) return Node_Id
962 Loc : constant Source_Ptr := Sloc (N);
963 P : constant Node_Id := Prefix (N);
964 D : Elmt_Id;
965 Id : Node_Id;
966 Index_Typ : Entity_Id;
968 Desig_Typ : Entity_Id;
969 -- This is either a copy of T, or if T is an access type, then it is
970 -- the directly designated type of this access type.
972 function Build_Actual_Array_Constraint return List_Id;
973 -- If one or more of the bounds of the component depends on
974 -- discriminants, build actual constraint using the discriminants
975 -- of the prefix.
977 function Build_Actual_Record_Constraint return List_Id;
978 -- Similar to previous one, for discriminated components constrained
979 -- by the discriminant of the enclosing object.
981 -----------------------------------
982 -- Build_Actual_Array_Constraint --
983 -----------------------------------
985 function Build_Actual_Array_Constraint return List_Id is
986 Constraints : constant List_Id := New_List;
987 Indx : Node_Id;
988 Hi : Node_Id;
989 Lo : Node_Id;
990 Old_Hi : Node_Id;
991 Old_Lo : Node_Id;
993 begin
994 Indx := First_Index (Desig_Typ);
995 while Present (Indx) loop
996 Old_Lo := Type_Low_Bound (Etype (Indx));
997 Old_Hi := Type_High_Bound (Etype (Indx));
999 if Denotes_Discriminant (Old_Lo) then
1000 Lo :=
1001 Make_Selected_Component (Loc,
1002 Prefix => New_Copy_Tree (P),
1003 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1005 else
1006 Lo := New_Copy_Tree (Old_Lo);
1008 -- The new bound will be reanalyzed in the enclosing
1009 -- declaration. For literal bounds that come from a type
1010 -- declaration, the type of the context must be imposed, so
1011 -- insure that analysis will take place. For non-universal
1012 -- types this is not strictly necessary.
1014 Set_Analyzed (Lo, False);
1015 end if;
1017 if Denotes_Discriminant (Old_Hi) then
1018 Hi :=
1019 Make_Selected_Component (Loc,
1020 Prefix => New_Copy_Tree (P),
1021 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1023 else
1024 Hi := New_Copy_Tree (Old_Hi);
1025 Set_Analyzed (Hi, False);
1026 end if;
1028 Append (Make_Range (Loc, Lo, Hi), Constraints);
1029 Next_Index (Indx);
1030 end loop;
1032 return Constraints;
1033 end Build_Actual_Array_Constraint;
1035 ------------------------------------
1036 -- Build_Actual_Record_Constraint --
1037 ------------------------------------
1039 function Build_Actual_Record_Constraint return List_Id is
1040 Constraints : constant List_Id := New_List;
1041 D : Elmt_Id;
1042 D_Val : Node_Id;
1044 begin
1045 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1046 while Present (D) loop
1047 if Denotes_Discriminant (Node (D)) then
1048 D_Val := Make_Selected_Component (Loc,
1049 Prefix => New_Copy_Tree (P),
1050 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1052 else
1053 D_Val := New_Copy_Tree (Node (D));
1054 end if;
1056 Append (D_Val, Constraints);
1057 Next_Elmt (D);
1058 end loop;
1060 return Constraints;
1061 end Build_Actual_Record_Constraint;
1063 -- Start of processing for Build_Actual_Subtype_Of_Component
1065 begin
1066 -- Why the test for Spec_Expression mode here???
1068 if In_Spec_Expression then
1069 return Empty;
1071 -- More comments for the rest of this body would be good ???
1073 elsif Nkind (N) = N_Explicit_Dereference then
1074 if Is_Composite_Type (T)
1075 and then not Is_Constrained (T)
1076 and then not (Is_Class_Wide_Type (T)
1077 and then Is_Constrained (Root_Type (T)))
1078 and then not Has_Unknown_Discriminants (T)
1079 then
1080 -- If the type of the dereference is already constrained, it is an
1081 -- actual subtype.
1083 if Is_Array_Type (Etype (N))
1084 and then Is_Constrained (Etype (N))
1085 then
1086 return Empty;
1087 else
1088 Remove_Side_Effects (P);
1089 return Build_Actual_Subtype (T, N);
1090 end if;
1091 else
1092 return Empty;
1093 end if;
1094 end if;
1096 if Ekind (T) = E_Access_Subtype then
1097 Desig_Typ := Designated_Type (T);
1098 else
1099 Desig_Typ := T;
1100 end if;
1102 if Ekind (Desig_Typ) = E_Array_Subtype then
1103 Id := First_Index (Desig_Typ);
1104 while Present (Id) loop
1105 Index_Typ := Underlying_Type (Etype (Id));
1107 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1108 or else
1109 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1110 then
1111 Remove_Side_Effects (P);
1112 return
1113 Build_Component_Subtype
1114 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1115 end if;
1117 Next_Index (Id);
1118 end loop;
1120 elsif Is_Composite_Type (Desig_Typ)
1121 and then Has_Discriminants (Desig_Typ)
1122 and then not Has_Unknown_Discriminants (Desig_Typ)
1123 then
1124 if Is_Private_Type (Desig_Typ)
1125 and then No (Discriminant_Constraint (Desig_Typ))
1126 then
1127 Desig_Typ := Full_View (Desig_Typ);
1128 end if;
1130 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1131 while Present (D) loop
1132 if Denotes_Discriminant (Node (D)) then
1133 Remove_Side_Effects (P);
1134 return
1135 Build_Component_Subtype (
1136 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1137 end if;
1139 Next_Elmt (D);
1140 end loop;
1141 end if;
1143 -- If none of the above, the actual and nominal subtypes are the same
1145 return Empty;
1146 end Build_Actual_Subtype_Of_Component;
1148 -----------------------------
1149 -- Build_Component_Subtype --
1150 -----------------------------
1152 function Build_Component_Subtype
1153 (C : List_Id;
1154 Loc : Source_Ptr;
1155 T : Entity_Id) return Node_Id
1157 Subt : Entity_Id;
1158 Decl : Node_Id;
1160 begin
1161 -- Unchecked_Union components do not require component subtypes
1163 if Is_Unchecked_Union (T) then
1164 return Empty;
1165 end if;
1167 Subt := Make_Temporary (Loc, 'S');
1168 Set_Is_Internal (Subt);
1170 Decl :=
1171 Make_Subtype_Declaration (Loc,
1172 Defining_Identifier => Subt,
1173 Subtype_Indication =>
1174 Make_Subtype_Indication (Loc,
1175 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1176 Constraint =>
1177 Make_Index_Or_Discriminant_Constraint (Loc,
1178 Constraints => C)));
1180 Mark_Rewrite_Insertion (Decl);
1181 return Decl;
1182 end Build_Component_Subtype;
1184 ---------------------------
1185 -- Build_Default_Subtype --
1186 ---------------------------
1188 function Build_Default_Subtype
1189 (T : Entity_Id;
1190 N : Node_Id) return Entity_Id
1192 Loc : constant Source_Ptr := Sloc (N);
1193 Disc : Entity_Id;
1195 Bas : Entity_Id;
1196 -- The base type that is to be constrained by the defaults
1198 begin
1199 if not Has_Discriminants (T) or else Is_Constrained (T) then
1200 return T;
1201 end if;
1203 Bas := Base_Type (T);
1205 -- If T is non-private but its base type is private, this is the
1206 -- completion of a subtype declaration whose parent type is private
1207 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1208 -- are to be found in the full view of the base. Check that the private
1209 -- status of T and its base differ.
1211 if Is_Private_Type (Bas)
1212 and then not Is_Private_Type (T)
1213 and then Present (Full_View (Bas))
1214 then
1215 Bas := Full_View (Bas);
1216 end if;
1218 Disc := First_Discriminant (T);
1220 if No (Discriminant_Default_Value (Disc)) then
1221 return T;
1222 end if;
1224 declare
1225 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1226 Constraints : constant List_Id := New_List;
1227 Decl : Node_Id;
1229 begin
1230 while Present (Disc) loop
1231 Append_To (Constraints,
1232 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1233 Next_Discriminant (Disc);
1234 end loop;
1236 Decl :=
1237 Make_Subtype_Declaration (Loc,
1238 Defining_Identifier => Act,
1239 Subtype_Indication =>
1240 Make_Subtype_Indication (Loc,
1241 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1242 Constraint =>
1243 Make_Index_Or_Discriminant_Constraint (Loc,
1244 Constraints => Constraints)));
1246 Insert_Action (N, Decl);
1248 -- If the context is a component declaration the subtype declaration
1249 -- will be analyzed when the enclosing type is frozen, otherwise do
1250 -- it now.
1252 if Ekind (Current_Scope) /= E_Record_Type then
1253 Analyze (Decl);
1254 end if;
1256 return Act;
1257 end;
1258 end Build_Default_Subtype;
1260 --------------------------------------------
1261 -- Build_Discriminal_Subtype_Of_Component --
1262 --------------------------------------------
1264 function Build_Discriminal_Subtype_Of_Component
1265 (T : Entity_Id) return Node_Id
1267 Loc : constant Source_Ptr := Sloc (T);
1268 D : Elmt_Id;
1269 Id : Node_Id;
1271 function Build_Discriminal_Array_Constraint return List_Id;
1272 -- If one or more of the bounds of the component depends on
1273 -- discriminants, build actual constraint using the discriminants
1274 -- of the prefix.
1276 function Build_Discriminal_Record_Constraint return List_Id;
1277 -- Similar to previous one, for discriminated components constrained by
1278 -- the discriminant of the enclosing object.
1280 ----------------------------------------
1281 -- Build_Discriminal_Array_Constraint --
1282 ----------------------------------------
1284 function Build_Discriminal_Array_Constraint return List_Id is
1285 Constraints : constant List_Id := New_List;
1286 Indx : Node_Id;
1287 Hi : Node_Id;
1288 Lo : Node_Id;
1289 Old_Hi : Node_Id;
1290 Old_Lo : Node_Id;
1292 begin
1293 Indx := First_Index (T);
1294 while Present (Indx) loop
1295 Old_Lo := Type_Low_Bound (Etype (Indx));
1296 Old_Hi := Type_High_Bound (Etype (Indx));
1298 if Denotes_Discriminant (Old_Lo) then
1299 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1301 else
1302 Lo := New_Copy_Tree (Old_Lo);
1303 end if;
1305 if Denotes_Discriminant (Old_Hi) then
1306 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1308 else
1309 Hi := New_Copy_Tree (Old_Hi);
1310 end if;
1312 Append (Make_Range (Loc, Lo, Hi), Constraints);
1313 Next_Index (Indx);
1314 end loop;
1316 return Constraints;
1317 end Build_Discriminal_Array_Constraint;
1319 -----------------------------------------
1320 -- Build_Discriminal_Record_Constraint --
1321 -----------------------------------------
1323 function Build_Discriminal_Record_Constraint return List_Id is
1324 Constraints : constant List_Id := New_List;
1325 D : Elmt_Id;
1326 D_Val : Node_Id;
1328 begin
1329 D := First_Elmt (Discriminant_Constraint (T));
1330 while Present (D) loop
1331 if Denotes_Discriminant (Node (D)) then
1332 D_Val :=
1333 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1334 else
1335 D_Val := New_Copy_Tree (Node (D));
1336 end if;
1338 Append (D_Val, Constraints);
1339 Next_Elmt (D);
1340 end loop;
1342 return Constraints;
1343 end Build_Discriminal_Record_Constraint;
1345 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1347 begin
1348 if Ekind (T) = E_Array_Subtype then
1349 Id := First_Index (T);
1350 while Present (Id) loop
1351 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1352 or else
1353 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1354 then
1355 return Build_Component_Subtype
1356 (Build_Discriminal_Array_Constraint, Loc, T);
1357 end if;
1359 Next_Index (Id);
1360 end loop;
1362 elsif Ekind (T) = E_Record_Subtype
1363 and then Has_Discriminants (T)
1364 and then not Has_Unknown_Discriminants (T)
1365 then
1366 D := First_Elmt (Discriminant_Constraint (T));
1367 while Present (D) loop
1368 if Denotes_Discriminant (Node (D)) then
1369 return Build_Component_Subtype
1370 (Build_Discriminal_Record_Constraint, Loc, T);
1371 end if;
1373 Next_Elmt (D);
1374 end loop;
1375 end if;
1377 -- If none of the above, the actual and nominal subtypes are the same
1379 return Empty;
1380 end Build_Discriminal_Subtype_Of_Component;
1382 ------------------------------
1383 -- Build_Elaboration_Entity --
1384 ------------------------------
1386 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1387 Loc : constant Source_Ptr := Sloc (N);
1388 Decl : Node_Id;
1389 Elab_Ent : Entity_Id;
1391 procedure Set_Package_Name (Ent : Entity_Id);
1392 -- Given an entity, sets the fully qualified name of the entity in
1393 -- Name_Buffer, with components separated by double underscores. This
1394 -- is a recursive routine that climbs the scope chain to Standard.
1396 ----------------------
1397 -- Set_Package_Name --
1398 ----------------------
1400 procedure Set_Package_Name (Ent : Entity_Id) is
1401 begin
1402 if Scope (Ent) /= Standard_Standard then
1403 Set_Package_Name (Scope (Ent));
1405 declare
1406 Nam : constant String := Get_Name_String (Chars (Ent));
1407 begin
1408 Name_Buffer (Name_Len + 1) := '_';
1409 Name_Buffer (Name_Len + 2) := '_';
1410 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1411 Name_Len := Name_Len + Nam'Length + 2;
1412 end;
1414 else
1415 Get_Name_String (Chars (Ent));
1416 end if;
1417 end Set_Package_Name;
1419 -- Start of processing for Build_Elaboration_Entity
1421 begin
1422 -- Ignore call if already constructed
1424 if Present (Elaboration_Entity (Spec_Id)) then
1425 return;
1427 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1428 -- no role in analysis.
1430 elsif ASIS_Mode then
1431 return;
1433 -- See if we need elaboration entity.
1435 -- We always need an elaboration entity when preserving control flow, as
1436 -- we want to remain explicit about the unit's elaboration order.
1438 elsif Opt.Suppress_Control_Flow_Optimizations then
1439 null;
1441 -- We always need an elaboration entity for the dynamic elaboration
1442 -- model, since it is needed to properly generate the PE exception for
1443 -- access before elaboration.
1445 elsif Dynamic_Elaboration_Checks then
1446 null;
1448 -- For the static model, we don't need the elaboration counter if this
1449 -- unit is sure to have no elaboration code, since that means there
1450 -- is no elaboration unit to be called. Note that we can't just decide
1451 -- after the fact by looking to see whether there was elaboration code,
1452 -- because that's too late to make this decision.
1454 elsif Restriction_Active (No_Elaboration_Code) then
1455 return;
1457 -- Similarly, for the static model, we can skip the elaboration counter
1458 -- if we have the No_Multiple_Elaboration restriction, since for the
1459 -- static model, that's the only purpose of the counter (to avoid
1460 -- multiple elaboration).
1462 elsif Restriction_Active (No_Multiple_Elaboration) then
1463 return;
1464 end if;
1466 -- Here we need the elaboration entity
1468 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1469 -- name with dots replaced by double underscore. We have to manually
1470 -- construct this name, since it will be elaborated in the outer scope,
1471 -- and thus will not have the unit name automatically prepended.
1473 Set_Package_Name (Spec_Id);
1474 Add_Str_To_Name_Buffer ("_E");
1476 -- Create elaboration counter
1478 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1479 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1481 Decl :=
1482 Make_Object_Declaration (Loc,
1483 Defining_Identifier => Elab_Ent,
1484 Object_Definition =>
1485 New_Occurrence_Of (Standard_Short_Integer, Loc),
1486 Expression => Make_Integer_Literal (Loc, Uint_0));
1488 Push_Scope (Standard_Standard);
1489 Add_Global_Declaration (Decl);
1490 Pop_Scope;
1492 -- Reset True_Constant indication, since we will indeed assign a value
1493 -- to the variable in the binder main. We also kill the Current_Value
1494 -- and Last_Assignment fields for the same reason.
1496 Set_Is_True_Constant (Elab_Ent, False);
1497 Set_Current_Value (Elab_Ent, Empty);
1498 Set_Last_Assignment (Elab_Ent, Empty);
1500 -- We do not want any further qualification of the name (if we did not
1501 -- do this, we would pick up the name of the generic package in the case
1502 -- of a library level generic instantiation).
1504 Set_Has_Qualified_Name (Elab_Ent);
1505 Set_Has_Fully_Qualified_Name (Elab_Ent);
1506 end Build_Elaboration_Entity;
1508 --------------------------------
1509 -- Build_Explicit_Dereference --
1510 --------------------------------
1512 procedure Build_Explicit_Dereference
1513 (Expr : Node_Id;
1514 Disc : Entity_Id)
1516 Loc : constant Source_Ptr := Sloc (Expr);
1517 I : Interp_Index;
1518 It : Interp;
1520 begin
1521 -- An entity of a type with a reference aspect is overloaded with
1522 -- both interpretations: with and without the dereference. Now that
1523 -- the dereference is made explicit, set the type of the node properly,
1524 -- to prevent anomalies in the backend. Same if the expression is an
1525 -- overloaded function call whose return type has a reference aspect.
1527 if Is_Entity_Name (Expr) then
1528 Set_Etype (Expr, Etype (Entity (Expr)));
1530 -- The designated entity will not be examined again when resolving
1531 -- the dereference, so generate a reference to it now.
1533 Generate_Reference (Entity (Expr), Expr);
1535 elsif Nkind (Expr) = N_Function_Call then
1537 -- If the name of the indexing function is overloaded, locate the one
1538 -- whose return type has an implicit dereference on the desired
1539 -- discriminant, and set entity and type of function call.
1541 if Is_Overloaded (Name (Expr)) then
1542 Get_First_Interp (Name (Expr), I, It);
1544 while Present (It.Nam) loop
1545 if Ekind ((It.Typ)) = E_Record_Type
1546 and then First_Entity ((It.Typ)) = Disc
1547 then
1548 Set_Entity (Name (Expr), It.Nam);
1549 Set_Etype (Name (Expr), Etype (It.Nam));
1550 exit;
1551 end if;
1553 Get_Next_Interp (I, It);
1554 end loop;
1555 end if;
1557 -- Set type of call from resolved function name.
1559 Set_Etype (Expr, Etype (Name (Expr)));
1560 end if;
1562 Set_Is_Overloaded (Expr, False);
1564 -- The expression will often be a generalized indexing that yields a
1565 -- container element that is then dereferenced, in which case the
1566 -- generalized indexing call is also non-overloaded.
1568 if Nkind (Expr) = N_Indexed_Component
1569 and then Present (Generalized_Indexing (Expr))
1570 then
1571 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1572 end if;
1574 Rewrite (Expr,
1575 Make_Explicit_Dereference (Loc,
1576 Prefix =>
1577 Make_Selected_Component (Loc,
1578 Prefix => Relocate_Node (Expr),
1579 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1580 Set_Etype (Prefix (Expr), Etype (Disc));
1581 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1582 end Build_Explicit_Dereference;
1584 -----------------------------------
1585 -- Cannot_Raise_Constraint_Error --
1586 -----------------------------------
1588 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1589 begin
1590 if Compile_Time_Known_Value (Expr) then
1591 return True;
1593 elsif Do_Range_Check (Expr) then
1594 return False;
1596 elsif Raises_Constraint_Error (Expr) then
1597 return False;
1599 else
1600 case Nkind (Expr) is
1601 when N_Identifier =>
1602 return True;
1604 when N_Expanded_Name =>
1605 return True;
1607 when N_Selected_Component =>
1608 return not Do_Discriminant_Check (Expr);
1610 when N_Attribute_Reference =>
1611 if Do_Overflow_Check (Expr) then
1612 return False;
1614 elsif No (Expressions (Expr)) then
1615 return True;
1617 else
1618 declare
1619 N : Node_Id;
1621 begin
1622 N := First (Expressions (Expr));
1623 while Present (N) loop
1624 if Cannot_Raise_Constraint_Error (N) then
1625 Next (N);
1626 else
1627 return False;
1628 end if;
1629 end loop;
1631 return True;
1632 end;
1633 end if;
1635 when N_Type_Conversion =>
1636 if Do_Overflow_Check (Expr)
1637 or else Do_Length_Check (Expr)
1638 or else Do_Tag_Check (Expr)
1639 then
1640 return False;
1641 else
1642 return Cannot_Raise_Constraint_Error (Expression (Expr));
1643 end if;
1645 when N_Unchecked_Type_Conversion =>
1646 return Cannot_Raise_Constraint_Error (Expression (Expr));
1648 when N_Unary_Op =>
1649 if Do_Overflow_Check (Expr) then
1650 return False;
1651 else
1652 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1653 end if;
1655 when N_Op_Divide
1656 | N_Op_Mod
1657 | N_Op_Rem
1659 if Do_Division_Check (Expr)
1660 or else
1661 Do_Overflow_Check (Expr)
1662 then
1663 return False;
1664 else
1665 return
1666 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1667 and then
1668 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1669 end if;
1671 when N_Op_Add
1672 | N_Op_And
1673 | N_Op_Concat
1674 | N_Op_Eq
1675 | N_Op_Expon
1676 | N_Op_Ge
1677 | N_Op_Gt
1678 | N_Op_Le
1679 | N_Op_Lt
1680 | N_Op_Multiply
1681 | N_Op_Ne
1682 | N_Op_Or
1683 | N_Op_Rotate_Left
1684 | N_Op_Rotate_Right
1685 | N_Op_Shift_Left
1686 | N_Op_Shift_Right
1687 | N_Op_Shift_Right_Arithmetic
1688 | N_Op_Subtract
1689 | N_Op_Xor
1691 if Do_Overflow_Check (Expr) then
1692 return False;
1693 else
1694 return
1695 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1696 and then
1697 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1698 end if;
1700 when others =>
1701 return False;
1702 end case;
1703 end if;
1704 end Cannot_Raise_Constraint_Error;
1706 -----------------------------
1707 -- Check_Part_Of_Reference --
1708 -----------------------------
1710 procedure Check_Part_Of_Reference (Var_Id : Entity_Id; Ref : Node_Id) is
1711 Conc_Typ : constant Entity_Id := Encapsulating_State (Var_Id);
1712 Decl : Node_Id;
1713 OK_Use : Boolean := False;
1714 Par : Node_Id;
1715 Prag_Nam : Name_Id;
1716 Spec_Id : Entity_Id;
1718 begin
1719 -- Traverse the parent chain looking for a suitable context for the
1720 -- reference to the concurrent constituent.
1722 Par := Parent (Ref);
1723 while Present (Par) loop
1724 if Nkind (Par) = N_Pragma then
1725 Prag_Nam := Pragma_Name (Par);
1727 -- A concurrent constituent is allowed to appear in pragmas
1728 -- Initial_Condition and Initializes as this is part of the
1729 -- elaboration checks for the constituent (SPARK RM 9.3).
1731 if Nam_In (Prag_Nam, Name_Initial_Condition, Name_Initializes) then
1732 OK_Use := True;
1733 exit;
1735 -- When the reference appears within pragma Depends or Global,
1736 -- check whether the pragma applies to a single task type. Note
1737 -- that the pragma is not encapsulated by the type definition,
1738 -- but this is still a valid context.
1740 elsif Nam_In (Prag_Nam, Name_Depends, Name_Global) then
1741 Decl := Find_Related_Declaration_Or_Body (Par);
1743 if Nkind (Decl) = N_Object_Declaration
1744 and then Defining_Entity (Decl) = Conc_Typ
1745 then
1746 OK_Use := True;
1747 exit;
1748 end if;
1749 end if;
1751 -- The reference appears somewhere in the definition of the single
1752 -- protected/task type (SPARK RM 9.3).
1754 elsif Nkind_In (Par, N_Single_Protected_Declaration,
1755 N_Single_Task_Declaration)
1756 and then Defining_Entity (Par) = Conc_Typ
1757 then
1758 OK_Use := True;
1759 exit;
1761 -- The reference appears within the expanded declaration or the body
1762 -- of the single protected/task type (SPARK RM 9.3).
1764 elsif Nkind_In (Par, N_Protected_Body,
1765 N_Protected_Type_Declaration,
1766 N_Task_Body,
1767 N_Task_Type_Declaration)
1768 then
1769 Spec_Id := Unique_Defining_Entity (Par);
1771 if Present (Anonymous_Object (Spec_Id))
1772 and then Anonymous_Object (Spec_Id) = Conc_Typ
1773 then
1774 OK_Use := True;
1775 exit;
1776 end if;
1778 -- The reference has been relocated within an internally generated
1779 -- package or subprogram. Assume that the reference is legal as the
1780 -- real check was already performed in the original context of the
1781 -- reference.
1783 elsif Nkind_In (Par, N_Package_Body,
1784 N_Package_Declaration,
1785 N_Subprogram_Body,
1786 N_Subprogram_Declaration)
1787 and then not Comes_From_Source (Par)
1788 then
1789 OK_Use := True;
1790 exit;
1792 -- The reference has been relocated to an inlined body for GNATprove.
1793 -- Assume that the reference is legal as the real check was already
1794 -- performed in the original context of the reference.
1796 elsif GNATprove_Mode
1797 and then Nkind (Par) = N_Subprogram_Body
1798 and then Chars (Defining_Entity (Par)) = Name_uParent
1799 then
1800 OK_Use := True;
1801 exit;
1802 end if;
1804 Par := Parent (Par);
1805 end loop;
1807 -- The reference is illegal as it appears outside the definition or
1808 -- body of the single protected/task type.
1810 if not OK_Use then
1811 Error_Msg_NE
1812 ("reference to variable & cannot appear in this context",
1813 Ref, Var_Id);
1814 Error_Msg_Name_1 := Chars (Var_Id);
1816 if Ekind (Conc_Typ) = E_Protected_Type then
1817 Error_Msg_NE
1818 ("\% is constituent of single protected type &", Ref, Conc_Typ);
1819 else
1820 Error_Msg_NE
1821 ("\% is constituent of single task type &", Ref, Conc_Typ);
1822 end if;
1823 end if;
1824 end Check_Part_Of_Reference;
1826 -----------------------------------------
1827 -- Check_Dynamically_Tagged_Expression --
1828 -----------------------------------------
1830 procedure Check_Dynamically_Tagged_Expression
1831 (Expr : Node_Id;
1832 Typ : Entity_Id;
1833 Related_Nod : Node_Id)
1835 begin
1836 pragma Assert (Is_Tagged_Type (Typ));
1838 -- In order to avoid spurious errors when analyzing the expanded code,
1839 -- this check is done only for nodes that come from source and for
1840 -- actuals of generic instantiations.
1842 if (Comes_From_Source (Related_Nod)
1843 or else In_Generic_Actual (Expr))
1844 and then (Is_Class_Wide_Type (Etype (Expr))
1845 or else Is_Dynamically_Tagged (Expr))
1846 and then Is_Tagged_Type (Typ)
1847 and then not Is_Class_Wide_Type (Typ)
1848 then
1849 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1850 end if;
1851 end Check_Dynamically_Tagged_Expression;
1853 --------------------------
1854 -- Check_Fully_Declared --
1855 --------------------------
1857 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1858 begin
1859 if Ekind (T) = E_Incomplete_Type then
1861 -- Ada 2005 (AI-50217): If the type is available through a limited
1862 -- with_clause, verify that its full view has been analyzed.
1864 if From_Limited_With (T)
1865 and then Present (Non_Limited_View (T))
1866 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1867 then
1868 -- The non-limited view is fully declared
1870 null;
1872 else
1873 Error_Msg_NE
1874 ("premature usage of incomplete}", N, First_Subtype (T));
1875 end if;
1877 -- Need comments for these tests ???
1879 elsif Has_Private_Component (T)
1880 and then not Is_Generic_Type (Root_Type (T))
1881 and then not In_Spec_Expression
1882 then
1883 -- Special case: if T is the anonymous type created for a single
1884 -- task or protected object, use the name of the source object.
1886 if Is_Concurrent_Type (T)
1887 and then not Comes_From_Source (T)
1888 and then Nkind (N) = N_Object_Declaration
1889 then
1890 Error_Msg_NE
1891 ("type of& has incomplete component",
1892 N, Defining_Identifier (N));
1893 else
1894 Error_Msg_NE
1895 ("premature usage of incomplete}",
1896 N, First_Subtype (T));
1897 end if;
1898 end if;
1899 end Check_Fully_Declared;
1901 -------------------------------------------
1902 -- Check_Function_With_Address_Parameter --
1903 -------------------------------------------
1905 procedure Check_Function_With_Address_Parameter (Subp_Id : Entity_Id) is
1906 F : Entity_Id;
1907 T : Entity_Id;
1909 begin
1910 F := First_Formal (Subp_Id);
1911 while Present (F) loop
1912 T := Etype (F);
1914 if Is_Private_Type (T) and then Present (Full_View (T)) then
1915 T := Full_View (T);
1916 end if;
1918 if Is_Descendant_Of_Address (T) or else Is_Limited_Type (T) then
1919 Set_Is_Pure (Subp_Id, False);
1920 exit;
1921 end if;
1923 Next_Formal (F);
1924 end loop;
1925 end Check_Function_With_Address_Parameter;
1927 -------------------------------------
1928 -- Check_Function_Writable_Actuals --
1929 -------------------------------------
1931 procedure Check_Function_Writable_Actuals (N : Node_Id) is
1932 Writable_Actuals_List : Elist_Id := No_Elist;
1933 Identifiers_List : Elist_Id := No_Elist;
1934 Aggr_Error_Node : Node_Id := Empty;
1935 Error_Node : Node_Id := Empty;
1937 procedure Collect_Identifiers (N : Node_Id);
1938 -- In a single traversal of subtree N collect in Writable_Actuals_List
1939 -- all the actuals of functions with writable actuals, and in the list
1940 -- Identifiers_List collect all the identifiers that are not actuals of
1941 -- functions with writable actuals. If a writable actual is referenced
1942 -- twice as writable actual then Error_Node is set to reference its
1943 -- second occurrence, the error is reported, and the tree traversal
1944 -- is abandoned.
1946 function Get_Function_Id (Call : Node_Id) return Entity_Id;
1947 -- Return the entity associated with the function call
1949 procedure Preanalyze_Without_Errors (N : Node_Id);
1950 -- Preanalyze N without reporting errors. Very dubious, you can't just
1951 -- go analyzing things more than once???
1953 -------------------------
1954 -- Collect_Identifiers --
1955 -------------------------
1957 procedure Collect_Identifiers (N : Node_Id) is
1959 function Check_Node (N : Node_Id) return Traverse_Result;
1960 -- Process a single node during the tree traversal to collect the
1961 -- writable actuals of functions and all the identifiers which are
1962 -- not writable actuals of functions.
1964 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
1965 -- Returns True if List has a node whose Entity is Entity (N)
1967 ----------------
1968 -- Check_Node --
1969 ----------------
1971 function Check_Node (N : Node_Id) return Traverse_Result is
1972 Is_Writable_Actual : Boolean := False;
1973 Id : Entity_Id;
1975 begin
1976 if Nkind (N) = N_Identifier then
1978 -- No analysis possible if the entity is not decorated
1980 if No (Entity (N)) then
1981 return Skip;
1983 -- Don't collect identifiers of packages, called functions, etc
1985 elsif Ekind_In (Entity (N), E_Package,
1986 E_Function,
1987 E_Procedure,
1988 E_Entry)
1989 then
1990 return Skip;
1992 -- For rewritten nodes, continue the traversal in the original
1993 -- subtree. Needed to handle aggregates in original expressions
1994 -- extracted from the tree by Remove_Side_Effects.
1996 elsif Is_Rewrite_Substitution (N) then
1997 Collect_Identifiers (Original_Node (N));
1998 return Skip;
2000 -- For now we skip aggregate discriminants, since they require
2001 -- performing the analysis in two phases to identify conflicts:
2002 -- first one analyzing discriminants and second one analyzing
2003 -- the rest of components (since at run time, discriminants are
2004 -- evaluated prior to components): too much computation cost
2005 -- to identify a corner case???
2007 elsif Nkind (Parent (N)) = N_Component_Association
2008 and then Nkind_In (Parent (Parent (N)),
2009 N_Aggregate,
2010 N_Extension_Aggregate)
2011 then
2012 declare
2013 Choice : constant Node_Id := First (Choices (Parent (N)));
2015 begin
2016 if Ekind (Entity (N)) = E_Discriminant then
2017 return Skip;
2019 elsif Expression (Parent (N)) = N
2020 and then Nkind (Choice) = N_Identifier
2021 and then Ekind (Entity (Choice)) = E_Discriminant
2022 then
2023 return Skip;
2024 end if;
2025 end;
2027 -- Analyze if N is a writable actual of a function
2029 elsif Nkind (Parent (N)) = N_Function_Call then
2030 declare
2031 Call : constant Node_Id := Parent (N);
2032 Actual : Node_Id;
2033 Formal : Node_Id;
2035 begin
2036 Id := Get_Function_Id (Call);
2038 -- In case of previous error, no check is possible
2040 if No (Id) then
2041 return Abandon;
2042 end if;
2044 if Ekind_In (Id, E_Function, E_Generic_Function)
2045 and then Has_Out_Or_In_Out_Parameter (Id)
2046 then
2047 Formal := First_Formal (Id);
2048 Actual := First_Actual (Call);
2049 while Present (Actual) and then Present (Formal) loop
2050 if Actual = N then
2051 if Ekind_In (Formal, E_Out_Parameter,
2052 E_In_Out_Parameter)
2053 then
2054 Is_Writable_Actual := True;
2055 end if;
2057 exit;
2058 end if;
2060 Next_Formal (Formal);
2061 Next_Actual (Actual);
2062 end loop;
2063 end if;
2064 end;
2065 end if;
2067 if Is_Writable_Actual then
2069 -- Skip checking the error in non-elementary types since
2070 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2071 -- store this actual in Writable_Actuals_List since it is
2072 -- needed to perform checks on other constructs that have
2073 -- arbitrary order of evaluation (for example, aggregates).
2075 if not Is_Elementary_Type (Etype (N)) then
2076 if not Contains (Writable_Actuals_List, N) then
2077 Append_New_Elmt (N, To => Writable_Actuals_List);
2078 end if;
2080 -- Second occurrence of an elementary type writable actual
2082 elsif Contains (Writable_Actuals_List, N) then
2084 -- Report the error on the second occurrence of the
2085 -- identifier. We cannot assume that N is the second
2086 -- occurrence (according to their location in the
2087 -- sources), since Traverse_Func walks through Field2
2088 -- last (see comment in the body of Traverse_Func).
2090 declare
2091 Elmt : Elmt_Id;
2093 begin
2094 Elmt := First_Elmt (Writable_Actuals_List);
2095 while Present (Elmt)
2096 and then Entity (Node (Elmt)) /= Entity (N)
2097 loop
2098 Next_Elmt (Elmt);
2099 end loop;
2101 if Sloc (N) > Sloc (Node (Elmt)) then
2102 Error_Node := N;
2103 else
2104 Error_Node := Node (Elmt);
2105 end if;
2107 Error_Msg_NE
2108 ("value may be affected by call to & "
2109 & "because order of evaluation is arbitrary",
2110 Error_Node, Id);
2111 return Abandon;
2112 end;
2114 -- First occurrence of a elementary type writable actual
2116 else
2117 Append_New_Elmt (N, To => Writable_Actuals_List);
2118 end if;
2120 else
2121 if Identifiers_List = No_Elist then
2122 Identifiers_List := New_Elmt_List;
2123 end if;
2125 Append_Unique_Elmt (N, Identifiers_List);
2126 end if;
2127 end if;
2129 return OK;
2130 end Check_Node;
2132 --------------
2133 -- Contains --
2134 --------------
2136 function Contains
2137 (List : Elist_Id;
2138 N : Node_Id) return Boolean
2140 pragma Assert (Nkind (N) in N_Has_Entity);
2142 Elmt : Elmt_Id;
2144 begin
2145 if List = No_Elist then
2146 return False;
2147 end if;
2149 Elmt := First_Elmt (List);
2150 while Present (Elmt) loop
2151 if Entity (Node (Elmt)) = Entity (N) then
2152 return True;
2153 else
2154 Next_Elmt (Elmt);
2155 end if;
2156 end loop;
2158 return False;
2159 end Contains;
2161 ------------------
2162 -- Do_Traversal --
2163 ------------------
2165 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2166 -- The traversal procedure
2168 -- Start of processing for Collect_Identifiers
2170 begin
2171 if Present (Error_Node) then
2172 return;
2173 end if;
2175 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2176 return;
2177 end if;
2179 Do_Traversal (N);
2180 end Collect_Identifiers;
2182 ---------------------
2183 -- Get_Function_Id --
2184 ---------------------
2186 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2187 Nam : constant Node_Id := Name (Call);
2188 Id : Entity_Id;
2190 begin
2191 if Nkind (Nam) = N_Explicit_Dereference then
2192 Id := Etype (Nam);
2193 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2195 elsif Nkind (Nam) = N_Selected_Component then
2196 Id := Entity (Selector_Name (Nam));
2198 elsif Nkind (Nam) = N_Indexed_Component then
2199 Id := Entity (Selector_Name (Prefix (Nam)));
2201 else
2202 Id := Entity (Nam);
2203 end if;
2205 return Id;
2206 end Get_Function_Id;
2208 -------------------------------
2209 -- Preanalyze_Without_Errors --
2210 -------------------------------
2212 procedure Preanalyze_Without_Errors (N : Node_Id) is
2213 Status : constant Boolean := Get_Ignore_Errors;
2214 begin
2215 Set_Ignore_Errors (True);
2216 Preanalyze (N);
2217 Set_Ignore_Errors (Status);
2218 end Preanalyze_Without_Errors;
2220 -- Start of processing for Check_Function_Writable_Actuals
2222 begin
2223 -- The check only applies to Ada 2012 code on which Check_Actuals has
2224 -- been set, and only to constructs that have multiple constituents
2225 -- whose order of evaluation is not specified by the language.
2227 if Ada_Version < Ada_2012
2228 or else not Check_Actuals (N)
2229 or else (not (Nkind (N) in N_Op)
2230 and then not (Nkind (N) in N_Membership_Test)
2231 and then not Nkind_In (N, N_Range,
2232 N_Aggregate,
2233 N_Extension_Aggregate,
2234 N_Full_Type_Declaration,
2235 N_Function_Call,
2236 N_Procedure_Call_Statement,
2237 N_Entry_Call_Statement))
2238 or else (Nkind (N) = N_Full_Type_Declaration
2239 and then not Is_Record_Type (Defining_Identifier (N)))
2241 -- In addition, this check only applies to source code, not to code
2242 -- generated by constraint checks.
2244 or else not Comes_From_Source (N)
2245 then
2246 return;
2247 end if;
2249 -- If a construct C has two or more direct constituents that are names
2250 -- or expressions whose evaluation may occur in an arbitrary order, at
2251 -- least one of which contains a function call with an in out or out
2252 -- parameter, then the construct is legal only if: for each name N that
2253 -- is passed as a parameter of mode in out or out to some inner function
2254 -- call C2 (not including the construct C itself), there is no other
2255 -- name anywhere within a direct constituent of the construct C other
2256 -- than the one containing C2, that is known to refer to the same
2257 -- object (RM 6.4.1(6.17/3)).
2259 case Nkind (N) is
2260 when N_Range =>
2261 Collect_Identifiers (Low_Bound (N));
2262 Collect_Identifiers (High_Bound (N));
2264 when N_Membership_Test
2265 | N_Op
2267 declare
2268 Expr : Node_Id;
2270 begin
2271 Collect_Identifiers (Left_Opnd (N));
2273 if Present (Right_Opnd (N)) then
2274 Collect_Identifiers (Right_Opnd (N));
2275 end if;
2277 if Nkind_In (N, N_In, N_Not_In)
2278 and then Present (Alternatives (N))
2279 then
2280 Expr := First (Alternatives (N));
2281 while Present (Expr) loop
2282 Collect_Identifiers (Expr);
2284 Next (Expr);
2285 end loop;
2286 end if;
2287 end;
2289 when N_Full_Type_Declaration =>
2290 declare
2291 function Get_Record_Part (N : Node_Id) return Node_Id;
2292 -- Return the record part of this record type definition
2294 function Get_Record_Part (N : Node_Id) return Node_Id is
2295 Type_Def : constant Node_Id := Type_Definition (N);
2296 begin
2297 if Nkind (Type_Def) = N_Derived_Type_Definition then
2298 return Record_Extension_Part (Type_Def);
2299 else
2300 return Type_Def;
2301 end if;
2302 end Get_Record_Part;
2304 Comp : Node_Id;
2305 Def_Id : Entity_Id := Defining_Identifier (N);
2306 Rec : Node_Id := Get_Record_Part (N);
2308 begin
2309 -- No need to perform any analysis if the record has no
2310 -- components
2312 if No (Rec) or else No (Component_List (Rec)) then
2313 return;
2314 end if;
2316 -- Collect the identifiers starting from the deepest
2317 -- derivation. Done to report the error in the deepest
2318 -- derivation.
2320 loop
2321 if Present (Component_List (Rec)) then
2322 Comp := First (Component_Items (Component_List (Rec)));
2323 while Present (Comp) loop
2324 if Nkind (Comp) = N_Component_Declaration
2325 and then Present (Expression (Comp))
2326 then
2327 Collect_Identifiers (Expression (Comp));
2328 end if;
2330 Next (Comp);
2331 end loop;
2332 end if;
2334 exit when No (Underlying_Type (Etype (Def_Id)))
2335 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2336 = Def_Id;
2338 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2339 Rec := Get_Record_Part (Parent (Def_Id));
2340 end loop;
2341 end;
2343 when N_Entry_Call_Statement
2344 | N_Subprogram_Call
2346 declare
2347 Id : constant Entity_Id := Get_Function_Id (N);
2348 Formal : Node_Id;
2349 Actual : Node_Id;
2351 begin
2352 Formal := First_Formal (Id);
2353 Actual := First_Actual (N);
2354 while Present (Actual) and then Present (Formal) loop
2355 if Ekind_In (Formal, E_Out_Parameter,
2356 E_In_Out_Parameter)
2357 then
2358 Collect_Identifiers (Actual);
2359 end if;
2361 Next_Formal (Formal);
2362 Next_Actual (Actual);
2363 end loop;
2364 end;
2366 when N_Aggregate
2367 | N_Extension_Aggregate
2369 declare
2370 Assoc : Node_Id;
2371 Choice : Node_Id;
2372 Comp_Expr : Node_Id;
2374 begin
2375 -- Handle the N_Others_Choice of array aggregates with static
2376 -- bounds. There is no need to perform this analysis in
2377 -- aggregates without static bounds since we cannot evaluate
2378 -- if the N_Others_Choice covers several elements. There is
2379 -- no need to handle the N_Others choice of record aggregates
2380 -- since at this stage it has been already expanded by
2381 -- Resolve_Record_Aggregate.
2383 if Is_Array_Type (Etype (N))
2384 and then Nkind (N) = N_Aggregate
2385 and then Present (Aggregate_Bounds (N))
2386 and then Compile_Time_Known_Bounds (Etype (N))
2387 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2389 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2390 then
2391 declare
2392 Count_Components : Uint := Uint_0;
2393 Num_Components : Uint;
2394 Others_Assoc : Node_Id;
2395 Others_Choice : Node_Id := Empty;
2396 Others_Box_Present : Boolean := False;
2398 begin
2399 -- Count positional associations
2401 if Present (Expressions (N)) then
2402 Comp_Expr := First (Expressions (N));
2403 while Present (Comp_Expr) loop
2404 Count_Components := Count_Components + 1;
2405 Next (Comp_Expr);
2406 end loop;
2407 end if;
2409 -- Count the rest of elements and locate the N_Others
2410 -- choice (if any)
2412 Assoc := First (Component_Associations (N));
2413 while Present (Assoc) loop
2414 Choice := First (Choices (Assoc));
2415 while Present (Choice) loop
2416 if Nkind (Choice) = N_Others_Choice then
2417 Others_Assoc := Assoc;
2418 Others_Choice := Choice;
2419 Others_Box_Present := Box_Present (Assoc);
2421 -- Count several components
2423 elsif Nkind_In (Choice, N_Range,
2424 N_Subtype_Indication)
2425 or else (Is_Entity_Name (Choice)
2426 and then Is_Type (Entity (Choice)))
2427 then
2428 declare
2429 L, H : Node_Id;
2430 begin
2431 Get_Index_Bounds (Choice, L, H);
2432 pragma Assert
2433 (Compile_Time_Known_Value (L)
2434 and then Compile_Time_Known_Value (H));
2435 Count_Components :=
2436 Count_Components
2437 + Expr_Value (H) - Expr_Value (L) + 1;
2438 end;
2440 -- Count single component. No other case available
2441 -- since we are handling an aggregate with static
2442 -- bounds.
2444 else
2445 pragma Assert (Is_OK_Static_Expression (Choice)
2446 or else Nkind (Choice) = N_Identifier
2447 or else Nkind (Choice) = N_Integer_Literal);
2449 Count_Components := Count_Components + 1;
2450 end if;
2452 Next (Choice);
2453 end loop;
2455 Next (Assoc);
2456 end loop;
2458 Num_Components :=
2459 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2460 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2462 pragma Assert (Count_Components <= Num_Components);
2464 -- Handle the N_Others choice if it covers several
2465 -- components
2467 if Present (Others_Choice)
2468 and then (Num_Components - Count_Components) > 1
2469 then
2470 if not Others_Box_Present then
2472 -- At this stage, if expansion is active, the
2473 -- expression of the others choice has not been
2474 -- analyzed. Hence we generate a duplicate and
2475 -- we analyze it silently to have available the
2476 -- minimum decoration required to collect the
2477 -- identifiers.
2479 if not Expander_Active then
2480 Comp_Expr := Expression (Others_Assoc);
2481 else
2482 Comp_Expr :=
2483 New_Copy_Tree (Expression (Others_Assoc));
2484 Preanalyze_Without_Errors (Comp_Expr);
2485 end if;
2487 Collect_Identifiers (Comp_Expr);
2489 if Writable_Actuals_List /= No_Elist then
2491 -- As suggested by Robert, at current stage we
2492 -- report occurrences of this case as warnings.
2494 Error_Msg_N
2495 ("writable function parameter may affect "
2496 & "value in other component because order "
2497 & "of evaluation is unspecified??",
2498 Node (First_Elmt (Writable_Actuals_List)));
2499 end if;
2500 end if;
2501 end if;
2502 end;
2504 -- For an array aggregate, a discrete_choice_list that has
2505 -- a nonstatic range is considered as two or more separate
2506 -- occurrences of the expression (RM 6.4.1(20/3)).
2508 elsif Is_Array_Type (Etype (N))
2509 and then Nkind (N) = N_Aggregate
2510 and then Present (Aggregate_Bounds (N))
2511 and then not Compile_Time_Known_Bounds (Etype (N))
2512 then
2513 -- Collect identifiers found in the dynamic bounds
2515 declare
2516 Count_Components : Natural := 0;
2517 Low, High : Node_Id;
2519 begin
2520 Assoc := First (Component_Associations (N));
2521 while Present (Assoc) loop
2522 Choice := First (Choices (Assoc));
2523 while Present (Choice) loop
2524 if Nkind_In (Choice, N_Range,
2525 N_Subtype_Indication)
2526 or else (Is_Entity_Name (Choice)
2527 and then Is_Type (Entity (Choice)))
2528 then
2529 Get_Index_Bounds (Choice, Low, High);
2531 if not Compile_Time_Known_Value (Low) then
2532 Collect_Identifiers (Low);
2534 if No (Aggr_Error_Node) then
2535 Aggr_Error_Node := Low;
2536 end if;
2537 end if;
2539 if not Compile_Time_Known_Value (High) then
2540 Collect_Identifiers (High);
2542 if No (Aggr_Error_Node) then
2543 Aggr_Error_Node := High;
2544 end if;
2545 end if;
2547 -- The RM rule is violated if there is more than
2548 -- a single choice in a component association.
2550 else
2551 Count_Components := Count_Components + 1;
2553 if No (Aggr_Error_Node)
2554 and then Count_Components > 1
2555 then
2556 Aggr_Error_Node := Choice;
2557 end if;
2559 if not Compile_Time_Known_Value (Choice) then
2560 Collect_Identifiers (Choice);
2561 end if;
2562 end if;
2564 Next (Choice);
2565 end loop;
2567 Next (Assoc);
2568 end loop;
2569 end;
2570 end if;
2572 -- Handle ancestor part of extension aggregates
2574 if Nkind (N) = N_Extension_Aggregate then
2575 Collect_Identifiers (Ancestor_Part (N));
2576 end if;
2578 -- Handle positional associations
2580 if Present (Expressions (N)) then
2581 Comp_Expr := First (Expressions (N));
2582 while Present (Comp_Expr) loop
2583 if not Is_OK_Static_Expression (Comp_Expr) then
2584 Collect_Identifiers (Comp_Expr);
2585 end if;
2587 Next (Comp_Expr);
2588 end loop;
2589 end if;
2591 -- Handle discrete associations
2593 if Present (Component_Associations (N)) then
2594 Assoc := First (Component_Associations (N));
2595 while Present (Assoc) loop
2597 if not Box_Present (Assoc) then
2598 Choice := First (Choices (Assoc));
2599 while Present (Choice) loop
2601 -- For now we skip discriminants since it requires
2602 -- performing the analysis in two phases: first one
2603 -- analyzing discriminants and second one analyzing
2604 -- the rest of components since discriminants are
2605 -- evaluated prior to components: too much extra
2606 -- work to detect a corner case???
2608 if Nkind (Choice) in N_Has_Entity
2609 and then Present (Entity (Choice))
2610 and then Ekind (Entity (Choice)) = E_Discriminant
2611 then
2612 null;
2614 elsif Box_Present (Assoc) then
2615 null;
2617 else
2618 if not Analyzed (Expression (Assoc)) then
2619 Comp_Expr :=
2620 New_Copy_Tree (Expression (Assoc));
2621 Set_Parent (Comp_Expr, Parent (N));
2622 Preanalyze_Without_Errors (Comp_Expr);
2623 else
2624 Comp_Expr := Expression (Assoc);
2625 end if;
2627 Collect_Identifiers (Comp_Expr);
2628 end if;
2630 Next (Choice);
2631 end loop;
2632 end if;
2634 Next (Assoc);
2635 end loop;
2636 end if;
2637 end;
2639 when others =>
2640 return;
2641 end case;
2643 -- No further action needed if we already reported an error
2645 if Present (Error_Node) then
2646 return;
2647 end if;
2649 -- Check violation of RM 6.20/3 in aggregates
2651 if Present (Aggr_Error_Node)
2652 and then Writable_Actuals_List /= No_Elist
2653 then
2654 Error_Msg_N
2655 ("value may be affected by call in other component because they "
2656 & "are evaluated in unspecified order",
2657 Node (First_Elmt (Writable_Actuals_List)));
2658 return;
2659 end if;
2661 -- Check if some writable argument of a function is referenced
2663 if Writable_Actuals_List /= No_Elist
2664 and then Identifiers_List /= No_Elist
2665 then
2666 declare
2667 Elmt_1 : Elmt_Id;
2668 Elmt_2 : Elmt_Id;
2670 begin
2671 Elmt_1 := First_Elmt (Writable_Actuals_List);
2672 while Present (Elmt_1) loop
2673 Elmt_2 := First_Elmt (Identifiers_List);
2674 while Present (Elmt_2) loop
2675 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2676 case Nkind (Parent (Node (Elmt_2))) is
2677 when N_Aggregate
2678 | N_Component_Association
2679 | N_Component_Declaration
2681 Error_Msg_N
2682 ("value may be affected by call in other "
2683 & "component because they are evaluated "
2684 & "in unspecified order",
2685 Node (Elmt_2));
2687 when N_In
2688 | N_Not_In
2690 Error_Msg_N
2691 ("value may be affected by call in other "
2692 & "alternative because they are evaluated "
2693 & "in unspecified order",
2694 Node (Elmt_2));
2696 when others =>
2697 Error_Msg_N
2698 ("value of actual may be affected by call in "
2699 & "other actual because they are evaluated "
2700 & "in unspecified order",
2701 Node (Elmt_2));
2702 end case;
2703 end if;
2705 Next_Elmt (Elmt_2);
2706 end loop;
2708 Next_Elmt (Elmt_1);
2709 end loop;
2710 end;
2711 end if;
2712 end Check_Function_Writable_Actuals;
2714 --------------------------------
2715 -- Check_Implicit_Dereference --
2716 --------------------------------
2718 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2719 Disc : Entity_Id;
2720 Desig : Entity_Id;
2721 Nam : Node_Id;
2723 begin
2724 if Nkind (N) = N_Indexed_Component
2725 and then Present (Generalized_Indexing (N))
2726 then
2727 Nam := Generalized_Indexing (N);
2728 else
2729 Nam := N;
2730 end if;
2732 if Ada_Version < Ada_2012
2733 or else not Has_Implicit_Dereference (Base_Type (Typ))
2734 then
2735 return;
2737 elsif not Comes_From_Source (N)
2738 and then Nkind (N) /= N_Indexed_Component
2739 then
2740 return;
2742 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2743 null;
2745 else
2746 Disc := First_Discriminant (Typ);
2747 while Present (Disc) loop
2748 if Has_Implicit_Dereference (Disc) then
2749 Desig := Designated_Type (Etype (Disc));
2750 Add_One_Interp (Nam, Disc, Desig);
2752 -- If the node is a generalized indexing, add interpretation
2753 -- to that node as well, for subsequent resolution.
2755 if Nkind (N) = N_Indexed_Component then
2756 Add_One_Interp (N, Disc, Desig);
2757 end if;
2759 -- If the operation comes from a generic unit and the context
2760 -- is a selected component, the selector name may be global
2761 -- and set in the instance already. Remove the entity to
2762 -- force resolution of the selected component, and the
2763 -- generation of an explicit dereference if needed.
2765 if In_Instance
2766 and then Nkind (Parent (Nam)) = N_Selected_Component
2767 then
2768 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2769 end if;
2771 exit;
2772 end if;
2774 Next_Discriminant (Disc);
2775 end loop;
2776 end if;
2777 end Check_Implicit_Dereference;
2779 ----------------------------------
2780 -- Check_Internal_Protected_Use --
2781 ----------------------------------
2783 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2784 S : Entity_Id;
2785 Prot : Entity_Id;
2787 begin
2788 S := Current_Scope;
2789 while Present (S) loop
2790 if S = Standard_Standard then
2791 return;
2793 elsif Ekind (S) = E_Function
2794 and then Ekind (Scope (S)) = E_Protected_Type
2795 then
2796 Prot := Scope (S);
2797 exit;
2798 end if;
2800 S := Scope (S);
2801 end loop;
2803 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2805 -- An indirect function call (e.g. a callback within a protected
2806 -- function body) is not statically illegal. If the access type is
2807 -- anonymous and is the type of an access parameter, the scope of Nam
2808 -- will be the protected type, but it is not a protected operation.
2810 if Ekind (Nam) = E_Subprogram_Type
2811 and then
2812 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2813 then
2814 null;
2816 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2817 Error_Msg_N
2818 ("within protected function cannot use protected "
2819 & "procedure in renaming or as generic actual", N);
2821 elsif Nkind (N) = N_Attribute_Reference then
2822 Error_Msg_N
2823 ("within protected function cannot take access of "
2824 & " protected procedure", N);
2826 else
2827 Error_Msg_N
2828 ("within protected function, protected object is constant", N);
2829 Error_Msg_N
2830 ("\cannot call operation that may modify it", N);
2831 end if;
2832 end if;
2833 end Check_Internal_Protected_Use;
2835 ---------------------------------------
2836 -- Check_Later_Vs_Basic_Declarations --
2837 ---------------------------------------
2839 procedure Check_Later_Vs_Basic_Declarations
2840 (Decls : List_Id;
2841 During_Parsing : Boolean)
2843 Body_Sloc : Source_Ptr;
2844 Decl : Node_Id;
2846 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2847 -- Return whether Decl is considered as a declarative item.
2848 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2849 -- When During_Parsing is False, the semantics of SPARK is followed.
2851 -------------------------------
2852 -- Is_Later_Declarative_Item --
2853 -------------------------------
2855 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2856 begin
2857 if Nkind (Decl) in N_Later_Decl_Item then
2858 return True;
2860 elsif Nkind (Decl) = N_Pragma then
2861 return True;
2863 elsif During_Parsing then
2864 return False;
2866 -- In SPARK, a package declaration is not considered as a later
2867 -- declarative item.
2869 elsif Nkind (Decl) = N_Package_Declaration then
2870 return False;
2872 -- In SPARK, a renaming is considered as a later declarative item
2874 elsif Nkind (Decl) in N_Renaming_Declaration then
2875 return True;
2877 else
2878 return False;
2879 end if;
2880 end Is_Later_Declarative_Item;
2882 -- Start of processing for Check_Later_Vs_Basic_Declarations
2884 begin
2885 Decl := First (Decls);
2887 -- Loop through sequence of basic declarative items
2889 Outer : while Present (Decl) loop
2890 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2891 and then Nkind (Decl) not in N_Body_Stub
2892 then
2893 Next (Decl);
2895 -- Once a body is encountered, we only allow later declarative
2896 -- items. The inner loop checks the rest of the list.
2898 else
2899 Body_Sloc := Sloc (Decl);
2901 Inner : while Present (Decl) loop
2902 if not Is_Later_Declarative_Item (Decl) then
2903 if During_Parsing then
2904 if Ada_Version = Ada_83 then
2905 Error_Msg_Sloc := Body_Sloc;
2906 Error_Msg_N
2907 ("(Ada 83) decl cannot appear after body#", Decl);
2908 end if;
2909 else
2910 Error_Msg_Sloc := Body_Sloc;
2911 Check_SPARK_05_Restriction
2912 ("decl cannot appear after body#", Decl);
2913 end if;
2914 end if;
2916 Next (Decl);
2917 end loop Inner;
2918 end if;
2919 end loop Outer;
2920 end Check_Later_Vs_Basic_Declarations;
2922 ---------------------------
2923 -- Check_No_Hidden_State --
2924 ---------------------------
2926 procedure Check_No_Hidden_State (Id : Entity_Id) is
2927 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2928 -- Determine whether the entity of a package denoted by Pkg has a null
2929 -- abstract state.
2931 -----------------------------
2932 -- Has_Null_Abstract_State --
2933 -----------------------------
2935 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2936 States : constant Elist_Id := Abstract_States (Pkg);
2938 begin
2939 -- Check first available state of related package. A null abstract
2940 -- state always appears as the sole element of the state list.
2942 return
2943 Present (States)
2944 and then Is_Null_State (Node (First_Elmt (States)));
2945 end Has_Null_Abstract_State;
2947 -- Local variables
2949 Context : Entity_Id := Empty;
2950 Not_Visible : Boolean := False;
2951 Scop : Entity_Id;
2953 -- Start of processing for Check_No_Hidden_State
2955 begin
2956 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2958 -- Find the proper context where the object or state appears
2960 Scop := Scope (Id);
2961 while Present (Scop) loop
2962 Context := Scop;
2964 -- Keep track of the context's visibility
2966 Not_Visible := Not_Visible or else In_Private_Part (Context);
2968 -- Prevent the search from going too far
2970 if Context = Standard_Standard then
2971 return;
2973 -- Objects and states that appear immediately within a subprogram or
2974 -- inside a construct nested within a subprogram do not introduce a
2975 -- hidden state. They behave as local variable declarations.
2977 elsif Is_Subprogram (Context) then
2978 return;
2980 -- When examining a package body, use the entity of the spec as it
2981 -- carries the abstract state declarations.
2983 elsif Ekind (Context) = E_Package_Body then
2984 Context := Spec_Entity (Context);
2985 end if;
2987 -- Stop the traversal when a package subject to a null abstract state
2988 -- has been found.
2990 if Ekind_In (Context, E_Generic_Package, E_Package)
2991 and then Has_Null_Abstract_State (Context)
2992 then
2993 exit;
2994 end if;
2996 Scop := Scope (Scop);
2997 end loop;
2999 -- At this point we know that there is at least one package with a null
3000 -- abstract state in visibility. Emit an error message unconditionally
3001 -- if the entity being processed is a state because the placement of the
3002 -- related package is irrelevant. This is not the case for objects as
3003 -- the intermediate context matters.
3005 if Present (Context)
3006 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3007 then
3008 Error_Msg_N ("cannot introduce hidden state &", Id);
3009 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3010 end if;
3011 end Check_No_Hidden_State;
3013 ----------------------------------------
3014 -- Check_Nonvolatile_Function_Profile --
3015 ----------------------------------------
3017 procedure Check_Nonvolatile_Function_Profile (Func_Id : Entity_Id) is
3018 Formal : Entity_Id;
3020 begin
3021 -- Inspect all formal parameters
3023 Formal := First_Formal (Func_Id);
3024 while Present (Formal) loop
3025 if Is_Effectively_Volatile (Etype (Formal)) then
3026 Error_Msg_NE
3027 ("nonvolatile function & cannot have a volatile parameter",
3028 Formal, Func_Id);
3029 end if;
3031 Next_Formal (Formal);
3032 end loop;
3034 -- Inspect the return type
3036 if Is_Effectively_Volatile (Etype (Func_Id)) then
3037 Error_Msg_NE
3038 ("nonvolatile function & cannot have a volatile return type",
3039 Result_Definition (Parent (Func_Id)), Func_Id);
3040 end if;
3041 end Check_Nonvolatile_Function_Profile;
3043 ------------------------------------------
3044 -- Check_Potentially_Blocking_Operation --
3045 ------------------------------------------
3047 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3048 S : Entity_Id;
3050 begin
3051 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3052 -- When pragma Detect_Blocking is active, the run time will raise
3053 -- Program_Error. Here we only issue a warning, since we generally
3054 -- support the use of potentially blocking operations in the absence
3055 -- of the pragma.
3057 -- Indirect blocking through a subprogram call cannot be diagnosed
3058 -- statically without interprocedural analysis, so we do not attempt
3059 -- to do it here.
3061 S := Scope (Current_Scope);
3062 while Present (S) and then S /= Standard_Standard loop
3063 if Is_Protected_Type (S) then
3064 Error_Msg_N
3065 ("potentially blocking operation in protected operation??", N);
3066 return;
3067 end if;
3069 S := Scope (S);
3070 end loop;
3071 end Check_Potentially_Blocking_Operation;
3073 ---------------------------------
3074 -- Check_Result_And_Post_State --
3075 ---------------------------------
3077 procedure Check_Result_And_Post_State (Subp_Id : Entity_Id) is
3078 procedure Check_Result_And_Post_State_In_Pragma
3079 (Prag : Node_Id;
3080 Result_Seen : in out Boolean);
3081 -- Determine whether pragma Prag mentions attribute 'Result and whether
3082 -- the pragma contains an expression that evaluates differently in pre-
3083 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3084 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3086 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean;
3087 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3088 -- formal parameter.
3090 -------------------------------------------
3091 -- Check_Result_And_Post_State_In_Pragma --
3092 -------------------------------------------
3094 procedure Check_Result_And_Post_State_In_Pragma
3095 (Prag : Node_Id;
3096 Result_Seen : in out Boolean)
3098 procedure Check_Expression (Expr : Node_Id);
3099 -- Perform the 'Result and post-state checks on a given expression
3101 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3102 -- Attempt to find attribute 'Result in a subtree denoted by N
3104 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3105 -- Determine whether source node N denotes "True" or "False"
3107 function Mentions_Post_State (N : Node_Id) return Boolean;
3108 -- Determine whether a subtree denoted by N mentions any construct
3109 -- that denotes a post-state.
3111 procedure Check_Function_Result is
3112 new Traverse_Proc (Is_Function_Result);
3114 ----------------------
3115 -- Check_Expression --
3116 ----------------------
3118 procedure Check_Expression (Expr : Node_Id) is
3119 begin
3120 if not Is_Trivial_Boolean (Expr) then
3121 Check_Function_Result (Expr);
3123 if not Mentions_Post_State (Expr) then
3124 if Pragma_Name (Prag) = Name_Contract_Cases then
3125 Error_Msg_NE
3126 ("contract case does not check the outcome of calling "
3127 & "&?T?", Expr, Subp_Id);
3129 elsif Pragma_Name (Prag) = Name_Refined_Post then
3130 Error_Msg_NE
3131 ("refined postcondition does not check the outcome of "
3132 & "calling &?T?", Prag, Subp_Id);
3134 else
3135 Error_Msg_NE
3136 ("postcondition does not check the outcome of calling "
3137 & "&?T?", Prag, Subp_Id);
3138 end if;
3139 end if;
3140 end if;
3141 end Check_Expression;
3143 ------------------------
3144 -- Is_Function_Result --
3145 ------------------------
3147 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3148 begin
3149 if Is_Attribute_Result (N) then
3150 Result_Seen := True;
3151 return Abandon;
3153 -- Continue the traversal
3155 else
3156 return OK;
3157 end if;
3158 end Is_Function_Result;
3160 ------------------------
3161 -- Is_Trivial_Boolean --
3162 ------------------------
3164 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3165 begin
3166 return
3167 Comes_From_Source (N)
3168 and then Is_Entity_Name (N)
3169 and then (Entity (N) = Standard_True
3170 or else
3171 Entity (N) = Standard_False);
3172 end Is_Trivial_Boolean;
3174 -------------------------
3175 -- Mentions_Post_State --
3176 -------------------------
3178 function Mentions_Post_State (N : Node_Id) return Boolean is
3179 Post_State_Seen : Boolean := False;
3181 function Is_Post_State (N : Node_Id) return Traverse_Result;
3182 -- Attempt to find a construct that denotes a post-state. If this
3183 -- is the case, set flag Post_State_Seen.
3185 -------------------
3186 -- Is_Post_State --
3187 -------------------
3189 function Is_Post_State (N : Node_Id) return Traverse_Result is
3190 Ent : Entity_Id;
3192 begin
3193 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3194 Post_State_Seen := True;
3195 return Abandon;
3197 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3198 Ent := Entity (N);
3200 -- The entity may be modifiable through an implicit
3201 -- dereference.
3203 if No (Ent)
3204 or else Ekind (Ent) in Assignable_Kind
3205 or else (Is_Access_Type (Etype (Ent))
3206 and then Nkind (Parent (N)) =
3207 N_Selected_Component)
3208 then
3209 Post_State_Seen := True;
3210 return Abandon;
3211 end if;
3213 elsif Nkind (N) = N_Attribute_Reference then
3214 if Attribute_Name (N) = Name_Old then
3215 return Skip;
3217 elsif Attribute_Name (N) = Name_Result then
3218 Post_State_Seen := True;
3219 return Abandon;
3220 end if;
3221 end if;
3223 return OK;
3224 end Is_Post_State;
3226 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3228 -- Start of processing for Mentions_Post_State
3230 begin
3231 Find_Post_State (N);
3233 return Post_State_Seen;
3234 end Mentions_Post_State;
3236 -- Local variables
3238 Expr : constant Node_Id :=
3239 Get_Pragma_Arg
3240 (First (Pragma_Argument_Associations (Prag)));
3241 Nam : constant Name_Id := Pragma_Name (Prag);
3242 CCase : Node_Id;
3244 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3246 begin
3247 -- Examine all consequences
3249 if Nam = Name_Contract_Cases then
3250 CCase := First (Component_Associations (Expr));
3251 while Present (CCase) loop
3252 Check_Expression (Expression (CCase));
3254 Next (CCase);
3255 end loop;
3257 -- Examine the expression of a postcondition
3259 else pragma Assert (Nam_In (Nam, Name_Postcondition,
3260 Name_Refined_Post));
3261 Check_Expression (Expr);
3262 end if;
3263 end Check_Result_And_Post_State_In_Pragma;
3265 --------------------------
3266 -- Has_In_Out_Parameter --
3267 --------------------------
3269 function Has_In_Out_Parameter (Subp_Id : Entity_Id) return Boolean is
3270 Formal : Entity_Id;
3272 begin
3273 -- Traverse the formals looking for an IN OUT parameter
3275 Formal := First_Formal (Subp_Id);
3276 while Present (Formal) loop
3277 if Ekind (Formal) = E_In_Out_Parameter then
3278 return True;
3279 end if;
3281 Next_Formal (Formal);
3282 end loop;
3284 return False;
3285 end Has_In_Out_Parameter;
3287 -- Local variables
3289 Items : constant Node_Id := Contract (Subp_Id);
3290 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
3291 Case_Prag : Node_Id := Empty;
3292 Post_Prag : Node_Id := Empty;
3293 Prag : Node_Id;
3294 Seen_In_Case : Boolean := False;
3295 Seen_In_Post : Boolean := False;
3296 Spec_Id : Entity_Id;
3298 -- Start of processing for Check_Result_And_Post_State
3300 begin
3301 -- The lack of attribute 'Result or a post-state is classified as a
3302 -- suspicious contract. Do not perform the check if the corresponding
3303 -- swich is not set.
3305 if not Warn_On_Suspicious_Contract then
3306 return;
3308 -- Nothing to do if there is no contract
3310 elsif No (Items) then
3311 return;
3312 end if;
3314 -- Retrieve the entity of the subprogram spec (if any)
3316 if Nkind (Subp_Decl) = N_Subprogram_Body
3317 and then Present (Corresponding_Spec (Subp_Decl))
3318 then
3319 Spec_Id := Corresponding_Spec (Subp_Decl);
3321 elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub
3322 and then Present (Corresponding_Spec_Of_Stub (Subp_Decl))
3323 then
3324 Spec_Id := Corresponding_Spec_Of_Stub (Subp_Decl);
3326 else
3327 Spec_Id := Subp_Id;
3328 end if;
3330 -- Examine all postconditions for attribute 'Result and a post-state
3332 Prag := Pre_Post_Conditions (Items);
3333 while Present (Prag) loop
3334 if Nam_In (Pragma_Name_Unmapped (Prag),
3335 Name_Postcondition, Name_Refined_Post)
3336 and then not Error_Posted (Prag)
3337 then
3338 Post_Prag := Prag;
3339 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Post);
3340 end if;
3342 Prag := Next_Pragma (Prag);
3343 end loop;
3345 -- Examine the contract cases of the subprogram for attribute 'Result
3346 -- and a post-state.
3348 Prag := Contract_Test_Cases (Items);
3349 while Present (Prag) loop
3350 if Pragma_Name (Prag) = Name_Contract_Cases
3351 and then not Error_Posted (Prag)
3352 then
3353 Case_Prag := Prag;
3354 Check_Result_And_Post_State_In_Pragma (Prag, Seen_In_Case);
3355 end if;
3357 Prag := Next_Pragma (Prag);
3358 end loop;
3360 -- Do not emit any errors if the subprogram is not a function
3362 if not Ekind_In (Spec_Id, E_Function, E_Generic_Function) then
3363 null;
3365 -- Regardless of whether the function has postconditions or contract
3366 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3367 -- parameter is always treated as a result.
3369 elsif Has_In_Out_Parameter (Spec_Id) then
3370 null;
3372 -- The function has both a postcondition and contract cases and they do
3373 -- not mention attribute 'Result.
3375 elsif Present (Case_Prag)
3376 and then not Seen_In_Case
3377 and then Present (Post_Prag)
3378 and then not Seen_In_Post
3379 then
3380 Error_Msg_N
3381 ("neither postcondition nor contract cases mention function "
3382 & "result?T?", Post_Prag);
3384 -- The function has contract cases only and they do not mention
3385 -- attribute 'Result.
3387 elsif Present (Case_Prag) and then not Seen_In_Case then
3388 Error_Msg_N ("contract cases do not mention result?T?", Case_Prag);
3390 -- The function has postconditions only and they do not mention
3391 -- attribute 'Result.
3393 elsif Present (Post_Prag) and then not Seen_In_Post then
3394 Error_Msg_N
3395 ("postcondition does not mention function result?T?", Post_Prag);
3396 end if;
3397 end Check_Result_And_Post_State;
3399 -----------------------------
3400 -- Check_State_Refinements --
3401 -----------------------------
3403 procedure Check_State_Refinements
3404 (Context : Node_Id;
3405 Is_Main_Unit : Boolean := False)
3407 procedure Check_Package (Pack : Node_Id);
3408 -- Verify that all abstract states of a [generic] package denoted by its
3409 -- declarative node Pack have proper refinement. Recursively verify the
3410 -- visible and private declarations of the [generic] package for other
3411 -- nested packages.
3413 procedure Check_Packages_In (Decls : List_Id);
3414 -- Seek out [generic] package declarations within declarative list Decls
3415 -- and verify the status of their abstract state refinement.
3417 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean;
3418 -- Determine whether construct N is subject to pragma SPARK_Mode Off
3420 -------------------
3421 -- Check_Package --
3422 -------------------
3424 procedure Check_Package (Pack : Node_Id) is
3425 Body_Id : constant Entity_Id := Corresponding_Body (Pack);
3426 Spec : constant Node_Id := Specification (Pack);
3427 States : constant Elist_Id :=
3428 Abstract_States (Defining_Entity (Pack));
3430 State_Elmt : Elmt_Id;
3431 State_Id : Entity_Id;
3433 begin
3434 -- Do not verify proper state refinement when the package is subject
3435 -- to pragma SPARK_Mode Off because this disables the requirement for
3436 -- state refinement.
3438 if SPARK_Mode_Is_Off (Pack) then
3439 null;
3441 -- State refinement can only occur in a completing packge body. Do
3442 -- not verify proper state refinement when the body is subject to
3443 -- pragma SPARK_Mode Off because this disables the requirement for
3444 -- state refinement.
3446 elsif Present (Body_Id)
3447 and then SPARK_Mode_Is_Off (Unit_Declaration_Node (Body_Id))
3448 then
3449 null;
3451 -- Do not verify proper state refinement when the package is an
3452 -- instance as this check was already performed in the generic.
3454 elsif Present (Generic_Parent (Spec)) then
3455 null;
3457 -- Otherwise examine the contents of the package
3459 else
3460 if Present (States) then
3461 State_Elmt := First_Elmt (States);
3462 while Present (State_Elmt) loop
3463 State_Id := Node (State_Elmt);
3465 -- Emit an error when a non-null state lacks any form of
3466 -- refinement.
3468 if not Is_Null_State (State_Id)
3469 and then not Has_Null_Refinement (State_Id)
3470 and then not Has_Non_Null_Refinement (State_Id)
3471 then
3472 Error_Msg_N ("state & requires refinement", State_Id);
3473 end if;
3475 Next_Elmt (State_Elmt);
3476 end loop;
3477 end if;
3479 Check_Packages_In (Visible_Declarations (Spec));
3480 Check_Packages_In (Private_Declarations (Spec));
3481 end if;
3482 end Check_Package;
3484 -----------------------
3485 -- Check_Packages_In --
3486 -----------------------
3488 procedure Check_Packages_In (Decls : List_Id) is
3489 Decl : Node_Id;
3491 begin
3492 if Present (Decls) then
3493 Decl := First (Decls);
3494 while Present (Decl) loop
3495 if Nkind_In (Decl, N_Generic_Package_Declaration,
3496 N_Package_Declaration)
3497 then
3498 Check_Package (Decl);
3499 end if;
3501 Next (Decl);
3502 end loop;
3503 end if;
3504 end Check_Packages_In;
3506 -----------------------
3507 -- SPARK_Mode_Is_Off --
3508 -----------------------
3510 function SPARK_Mode_Is_Off (N : Node_Id) return Boolean is
3511 Prag : constant Node_Id := SPARK_Pragma (Defining_Entity (N));
3513 begin
3514 return
3515 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = Off;
3516 end SPARK_Mode_Is_Off;
3518 -- Start of processing for Check_State_Refinements
3520 begin
3521 -- A block may declare a nested package
3523 if Nkind (Context) = N_Block_Statement then
3524 Check_Packages_In (Declarations (Context));
3526 -- An entry, protected, subprogram, or task body may declare a nested
3527 -- package.
3529 elsif Nkind_In (Context, N_Entry_Body,
3530 N_Protected_Body,
3531 N_Subprogram_Body,
3532 N_Task_Body)
3533 then
3534 -- Do not verify proper state refinement when the body is subject to
3535 -- pragma SPARK_Mode Off because this disables the requirement for
3536 -- state refinement.
3538 if not SPARK_Mode_Is_Off (Context) then
3539 Check_Packages_In (Declarations (Context));
3540 end if;
3542 -- A package body may declare a nested package
3544 elsif Nkind (Context) = N_Package_Body then
3545 Check_Package (Unit_Declaration_Node (Corresponding_Spec (Context)));
3547 -- Do not verify proper state refinement when the body is subject to
3548 -- pragma SPARK_Mode Off because this disables the requirement for
3549 -- state refinement.
3551 if not SPARK_Mode_Is_Off (Context) then
3552 Check_Packages_In (Declarations (Context));
3553 end if;
3555 -- A library level [generic] package may declare a nested package
3557 elsif Nkind_In (Context, N_Generic_Package_Declaration,
3558 N_Package_Declaration)
3559 and then Is_Main_Unit
3560 then
3561 Check_Package (Context);
3562 end if;
3563 end Check_State_Refinements;
3565 ------------------------------
3566 -- Check_Unprotected_Access --
3567 ------------------------------
3569 procedure Check_Unprotected_Access
3570 (Context : Node_Id;
3571 Expr : Node_Id)
3573 Cont_Encl_Typ : Entity_Id;
3574 Pref_Encl_Typ : Entity_Id;
3576 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3577 -- Check whether Obj is a private component of a protected object.
3578 -- Return the protected type where the component resides, Empty
3579 -- otherwise.
3581 function Is_Public_Operation return Boolean;
3582 -- Verify that the enclosing operation is callable from outside the
3583 -- protected object, to minimize false positives.
3585 ------------------------------
3586 -- Enclosing_Protected_Type --
3587 ------------------------------
3589 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3590 begin
3591 if Is_Entity_Name (Obj) then
3592 declare
3593 Ent : Entity_Id := Entity (Obj);
3595 begin
3596 -- The object can be a renaming of a private component, use
3597 -- the original record component.
3599 if Is_Prival (Ent) then
3600 Ent := Prival_Link (Ent);
3601 end if;
3603 if Is_Protected_Type (Scope (Ent)) then
3604 return Scope (Ent);
3605 end if;
3606 end;
3607 end if;
3609 -- For indexed and selected components, recursively check the prefix
3611 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3612 return Enclosing_Protected_Type (Prefix (Obj));
3614 -- The object does not denote a protected component
3616 else
3617 return Empty;
3618 end if;
3619 end Enclosing_Protected_Type;
3621 -------------------------
3622 -- Is_Public_Operation --
3623 -------------------------
3625 function Is_Public_Operation return Boolean is
3626 S : Entity_Id;
3627 E : Entity_Id;
3629 begin
3630 S := Current_Scope;
3631 while Present (S) and then S /= Pref_Encl_Typ loop
3632 if Scope (S) = Pref_Encl_Typ then
3633 E := First_Entity (Pref_Encl_Typ);
3634 while Present (E)
3635 and then E /= First_Private_Entity (Pref_Encl_Typ)
3636 loop
3637 if E = S then
3638 return True;
3639 end if;
3641 Next_Entity (E);
3642 end loop;
3643 end if;
3645 S := Scope (S);
3646 end loop;
3648 return False;
3649 end Is_Public_Operation;
3651 -- Start of processing for Check_Unprotected_Access
3653 begin
3654 if Nkind (Expr) = N_Attribute_Reference
3655 and then Attribute_Name (Expr) = Name_Unchecked_Access
3656 then
3657 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3658 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3660 -- Check whether we are trying to export a protected component to a
3661 -- context with an equal or lower access level.
3663 if Present (Pref_Encl_Typ)
3664 and then No (Cont_Encl_Typ)
3665 and then Is_Public_Operation
3666 and then Scope_Depth (Pref_Encl_Typ) >=
3667 Object_Access_Level (Context)
3668 then
3669 Error_Msg_N
3670 ("??possible unprotected access to protected data", Expr);
3671 end if;
3672 end if;
3673 end Check_Unprotected_Access;
3675 ------------------------------
3676 -- Check_Unused_Body_States --
3677 ------------------------------
3679 procedure Check_Unused_Body_States (Body_Id : Entity_Id) is
3680 procedure Process_Refinement_Clause
3681 (Clause : Node_Id;
3682 States : Elist_Id);
3683 -- Inspect all constituents of refinement clause Clause and remove any
3684 -- matches from body state list States.
3686 procedure Report_Unused_Body_States (States : Elist_Id);
3687 -- Emit errors for each abstract state or object found in list States
3689 -------------------------------
3690 -- Process_Refinement_Clause --
3691 -------------------------------
3693 procedure Process_Refinement_Clause
3694 (Clause : Node_Id;
3695 States : Elist_Id)
3697 procedure Process_Constituent (Constit : Node_Id);
3698 -- Remove constituent Constit from body state list States
3700 -------------------------
3701 -- Process_Constituent --
3702 -------------------------
3704 procedure Process_Constituent (Constit : Node_Id) is
3705 Constit_Id : Entity_Id;
3707 begin
3708 -- Guard against illegal constituents. Only abstract states and
3709 -- objects can appear on the right hand side of a refinement.
3711 if Is_Entity_Name (Constit) then
3712 Constit_Id := Entity_Of (Constit);
3714 if Present (Constit_Id)
3715 and then Ekind_In (Constit_Id, E_Abstract_State,
3716 E_Constant,
3717 E_Variable)
3718 then
3719 Remove (States, Constit_Id);
3720 end if;
3721 end if;
3722 end Process_Constituent;
3724 -- Local variables
3726 Constit : Node_Id;
3728 -- Start of processing for Process_Refinement_Clause
3730 begin
3731 if Nkind (Clause) = N_Component_Association then
3732 Constit := Expression (Clause);
3734 -- Multiple constituents appear as an aggregate
3736 if Nkind (Constit) = N_Aggregate then
3737 Constit := First (Expressions (Constit));
3738 while Present (Constit) loop
3739 Process_Constituent (Constit);
3740 Next (Constit);
3741 end loop;
3743 -- Various forms of a single constituent
3745 else
3746 Process_Constituent (Constit);
3747 end if;
3748 end if;
3749 end Process_Refinement_Clause;
3751 -------------------------------
3752 -- Report_Unused_Body_States --
3753 -------------------------------
3755 procedure Report_Unused_Body_States (States : Elist_Id) is
3756 Posted : Boolean := False;
3757 State_Elmt : Elmt_Id;
3758 State_Id : Entity_Id;
3760 begin
3761 if Present (States) then
3762 State_Elmt := First_Elmt (States);
3763 while Present (State_Elmt) loop
3764 State_Id := Node (State_Elmt);
3766 -- Constants are part of the hidden state of a package, but the
3767 -- compiler cannot determine whether they have variable input
3768 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
3769 -- hidden state. Do not emit an error when a constant does not
3770 -- participate in a state refinement, even though it acts as a
3771 -- hidden state.
3773 if Ekind (State_Id) = E_Constant then
3774 null;
3776 -- Generate an error message of the form:
3778 -- body of package ... has unused hidden states
3779 -- abstract state ... defined at ...
3780 -- variable ... defined at ...
3782 else
3783 if not Posted then
3784 Posted := True;
3785 SPARK_Msg_N
3786 ("body of package & has unused hidden states", Body_Id);
3787 end if;
3789 Error_Msg_Sloc := Sloc (State_Id);
3791 if Ekind (State_Id) = E_Abstract_State then
3792 SPARK_Msg_NE
3793 ("\abstract state & defined #", Body_Id, State_Id);
3795 else
3796 SPARK_Msg_NE ("\variable & defined #", Body_Id, State_Id);
3797 end if;
3798 end if;
3800 Next_Elmt (State_Elmt);
3801 end loop;
3802 end if;
3803 end Report_Unused_Body_States;
3805 -- Local variables
3807 Prag : constant Node_Id := Get_Pragma (Body_Id, Pragma_Refined_State);
3808 Spec_Id : constant Entity_Id := Spec_Entity (Body_Id);
3809 Clause : Node_Id;
3810 States : Elist_Id;
3812 -- Start of processing for Check_Unused_Body_States
3814 begin
3815 -- Inspect the clauses of pragma Refined_State and determine whether all
3816 -- visible states declared within the package body participate in the
3817 -- refinement.
3819 if Present (Prag) then
3820 Clause := Expression (Get_Argument (Prag, Spec_Id));
3821 States := Collect_Body_States (Body_Id);
3823 -- Multiple non-null state refinements appear as an aggregate
3825 if Nkind (Clause) = N_Aggregate then
3826 Clause := First (Component_Associations (Clause));
3827 while Present (Clause) loop
3828 Process_Refinement_Clause (Clause, States);
3829 Next (Clause);
3830 end loop;
3832 -- Various forms of a single state refinement
3834 else
3835 Process_Refinement_Clause (Clause, States);
3836 end if;
3838 -- Ensure that all abstract states and objects declared in the
3839 -- package body state space are utilized as constituents.
3841 Report_Unused_Body_States (States);
3842 end if;
3843 end Check_Unused_Body_States;
3845 -----------------
3846 -- Choice_List --
3847 -----------------
3849 function Choice_List (N : Node_Id) return List_Id is
3850 begin
3851 if Nkind (N) = N_Iterated_Component_Association then
3852 return Discrete_Choices (N);
3853 else
3854 return Choices (N);
3855 end if;
3856 end Choice_List;
3858 -------------------------
3859 -- Collect_Body_States --
3860 -------------------------
3862 function Collect_Body_States (Body_Id : Entity_Id) return Elist_Id is
3863 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean;
3864 -- Determine whether object Obj_Id is a suitable visible state of a
3865 -- package body.
3867 procedure Collect_Visible_States
3868 (Pack_Id : Entity_Id;
3869 States : in out Elist_Id);
3870 -- Gather the entities of all abstract states and objects declared in
3871 -- the visible state space of package Pack_Id.
3873 ----------------------------
3874 -- Collect_Visible_States --
3875 ----------------------------
3877 procedure Collect_Visible_States
3878 (Pack_Id : Entity_Id;
3879 States : in out Elist_Id)
3881 Item_Id : Entity_Id;
3883 begin
3884 -- Traverse the entity chain of the package and inspect all visible
3885 -- items.
3887 Item_Id := First_Entity (Pack_Id);
3888 while Present (Item_Id) and then not In_Private_Part (Item_Id) loop
3890 -- Do not consider internally generated items as those cannot be
3891 -- named and participate in refinement.
3893 if not Comes_From_Source (Item_Id) then
3894 null;
3896 elsif Ekind (Item_Id) = E_Abstract_State then
3897 Append_New_Elmt (Item_Id, States);
3899 elsif Ekind_In (Item_Id, E_Constant, E_Variable)
3900 and then Is_Visible_Object (Item_Id)
3901 then
3902 Append_New_Elmt (Item_Id, States);
3904 -- Recursively gather the visible states of a nested package
3906 elsif Ekind (Item_Id) = E_Package then
3907 Collect_Visible_States (Item_Id, States);
3908 end if;
3910 Next_Entity (Item_Id);
3911 end loop;
3912 end Collect_Visible_States;
3914 -----------------------
3915 -- Is_Visible_Object --
3916 -----------------------
3918 function Is_Visible_Object (Obj_Id : Entity_Id) return Boolean is
3919 begin
3920 -- Objects that map generic formals to their actuals are not visible
3921 -- from outside the generic instantiation.
3923 if Present (Corresponding_Generic_Association
3924 (Declaration_Node (Obj_Id)))
3925 then
3926 return False;
3928 -- Constituents of a single protected/task type act as components of
3929 -- the type and are not visible from outside the type.
3931 elsif Ekind (Obj_Id) = E_Variable
3932 and then Present (Encapsulating_State (Obj_Id))
3933 and then Is_Single_Concurrent_Object (Encapsulating_State (Obj_Id))
3934 then
3935 return False;
3937 else
3938 return True;
3939 end if;
3940 end Is_Visible_Object;
3942 -- Local variables
3944 Body_Decl : constant Node_Id := Unit_Declaration_Node (Body_Id);
3945 Decl : Node_Id;
3946 Item_Id : Entity_Id;
3947 States : Elist_Id := No_Elist;
3949 -- Start of processing for Collect_Body_States
3951 begin
3952 -- Inspect the declarations of the body looking for source objects,
3953 -- packages and package instantiations. Note that even though this
3954 -- processing is very similar to Collect_Visible_States, a package
3955 -- body does not have a First/Next_Entity list.
3957 Decl := First (Declarations (Body_Decl));
3958 while Present (Decl) loop
3960 -- Capture source objects as internally generated temporaries cannot
3961 -- be named and participate in refinement.
3963 if Nkind (Decl) = N_Object_Declaration then
3964 Item_Id := Defining_Entity (Decl);
3966 if Comes_From_Source (Item_Id)
3967 and then Is_Visible_Object (Item_Id)
3968 then
3969 Append_New_Elmt (Item_Id, States);
3970 end if;
3972 -- Capture the visible abstract states and objects of a source
3973 -- package [instantiation].
3975 elsif Nkind (Decl) = N_Package_Declaration then
3976 Item_Id := Defining_Entity (Decl);
3978 if Comes_From_Source (Item_Id) then
3979 Collect_Visible_States (Item_Id, States);
3980 end if;
3981 end if;
3983 Next (Decl);
3984 end loop;
3986 return States;
3987 end Collect_Body_States;
3989 ------------------------
3990 -- Collect_Interfaces --
3991 ------------------------
3993 procedure Collect_Interfaces
3994 (T : Entity_Id;
3995 Ifaces_List : out Elist_Id;
3996 Exclude_Parents : Boolean := False;
3997 Use_Full_View : Boolean := True)
3999 procedure Collect (Typ : Entity_Id);
4000 -- Subsidiary subprogram used to traverse the whole list
4001 -- of directly and indirectly implemented interfaces
4003 -------------
4004 -- Collect --
4005 -------------
4007 procedure Collect (Typ : Entity_Id) is
4008 Ancestor : Entity_Id;
4009 Full_T : Entity_Id;
4010 Id : Node_Id;
4011 Iface : Entity_Id;
4013 begin
4014 Full_T := Typ;
4016 -- Handle private types and subtypes
4018 if Use_Full_View
4019 and then Is_Private_Type (Typ)
4020 and then Present (Full_View (Typ))
4021 then
4022 Full_T := Full_View (Typ);
4024 if Ekind (Full_T) = E_Record_Subtype then
4025 Full_T := Etype (Typ);
4027 if Present (Full_View (Full_T)) then
4028 Full_T := Full_View (Full_T);
4029 end if;
4030 end if;
4031 end if;
4033 -- Include the ancestor if we are generating the whole list of
4034 -- abstract interfaces.
4036 if Etype (Full_T) /= Typ
4038 -- Protect the frontend against wrong sources. For example:
4040 -- package P is
4041 -- type A is tagged null record;
4042 -- type B is new A with private;
4043 -- type C is new A with private;
4044 -- private
4045 -- type B is new C with null record;
4046 -- type C is new B with null record;
4047 -- end P;
4049 and then Etype (Full_T) /= T
4050 then
4051 Ancestor := Etype (Full_T);
4052 Collect (Ancestor);
4054 if Is_Interface (Ancestor) and then not Exclude_Parents then
4055 Append_Unique_Elmt (Ancestor, Ifaces_List);
4056 end if;
4057 end if;
4059 -- Traverse the graph of ancestor interfaces
4061 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
4062 Id := First (Abstract_Interface_List (Full_T));
4063 while Present (Id) loop
4064 Iface := Etype (Id);
4066 -- Protect against wrong uses. For example:
4067 -- type I is interface;
4068 -- type O is tagged null record;
4069 -- type Wrong is new I and O with null record; -- ERROR
4071 if Is_Interface (Iface) then
4072 if Exclude_Parents
4073 and then Etype (T) /= T
4074 and then Interface_Present_In_Ancestor (Etype (T), Iface)
4075 then
4076 null;
4077 else
4078 Collect (Iface);
4079 Append_Unique_Elmt (Iface, Ifaces_List);
4080 end if;
4081 end if;
4083 Next (Id);
4084 end loop;
4085 end if;
4086 end Collect;
4088 -- Start of processing for Collect_Interfaces
4090 begin
4091 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
4092 Ifaces_List := New_Elmt_List;
4093 Collect (T);
4094 end Collect_Interfaces;
4096 ----------------------------------
4097 -- Collect_Interface_Components --
4098 ----------------------------------
4100 procedure Collect_Interface_Components
4101 (Tagged_Type : Entity_Id;
4102 Components_List : out Elist_Id)
4104 procedure Collect (Typ : Entity_Id);
4105 -- Subsidiary subprogram used to climb to the parents
4107 -------------
4108 -- Collect --
4109 -------------
4111 procedure Collect (Typ : Entity_Id) is
4112 Tag_Comp : Entity_Id;
4113 Parent_Typ : Entity_Id;
4115 begin
4116 -- Handle private types
4118 if Present (Full_View (Etype (Typ))) then
4119 Parent_Typ := Full_View (Etype (Typ));
4120 else
4121 Parent_Typ := Etype (Typ);
4122 end if;
4124 if Parent_Typ /= Typ
4126 -- Protect the frontend against wrong sources. For example:
4128 -- package P is
4129 -- type A is tagged null record;
4130 -- type B is new A with private;
4131 -- type C is new A with private;
4132 -- private
4133 -- type B is new C with null record;
4134 -- type C is new B with null record;
4135 -- end P;
4137 and then Parent_Typ /= Tagged_Type
4138 then
4139 Collect (Parent_Typ);
4140 end if;
4142 -- Collect the components containing tags of secondary dispatch
4143 -- tables.
4145 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
4146 while Present (Tag_Comp) loop
4147 pragma Assert (Present (Related_Type (Tag_Comp)));
4148 Append_Elmt (Tag_Comp, Components_List);
4150 Tag_Comp := Next_Tag_Component (Tag_Comp);
4151 end loop;
4152 end Collect;
4154 -- Start of processing for Collect_Interface_Components
4156 begin
4157 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
4158 and then Is_Tagged_Type (Tagged_Type));
4160 Components_List := New_Elmt_List;
4161 Collect (Tagged_Type);
4162 end Collect_Interface_Components;
4164 -----------------------------
4165 -- Collect_Interfaces_Info --
4166 -----------------------------
4168 procedure Collect_Interfaces_Info
4169 (T : Entity_Id;
4170 Ifaces_List : out Elist_Id;
4171 Components_List : out Elist_Id;
4172 Tags_List : out Elist_Id)
4174 Comps_List : Elist_Id;
4175 Comp_Elmt : Elmt_Id;
4176 Comp_Iface : Entity_Id;
4177 Iface_Elmt : Elmt_Id;
4178 Iface : Entity_Id;
4180 function Search_Tag (Iface : Entity_Id) return Entity_Id;
4181 -- Search for the secondary tag associated with the interface type
4182 -- Iface that is implemented by T.
4184 ----------------
4185 -- Search_Tag --
4186 ----------------
4188 function Search_Tag (Iface : Entity_Id) return Entity_Id is
4189 ADT : Elmt_Id;
4190 begin
4191 if not Is_CPP_Class (T) then
4192 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
4193 else
4194 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
4195 end if;
4197 while Present (ADT)
4198 and then Is_Tag (Node (ADT))
4199 and then Related_Type (Node (ADT)) /= Iface
4200 loop
4201 -- Skip secondary dispatch table referencing thunks to user
4202 -- defined primitives covered by this interface.
4204 pragma Assert (Has_Suffix (Node (ADT), 'P'));
4205 Next_Elmt (ADT);
4207 -- Skip secondary dispatch tables of Ada types
4209 if not Is_CPP_Class (T) then
4211 -- Skip secondary dispatch table referencing thunks to
4212 -- predefined primitives.
4214 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
4215 Next_Elmt (ADT);
4217 -- Skip secondary dispatch table referencing user-defined
4218 -- primitives covered by this interface.
4220 pragma Assert (Has_Suffix (Node (ADT), 'D'));
4221 Next_Elmt (ADT);
4223 -- Skip secondary dispatch table referencing predefined
4224 -- primitives.
4226 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
4227 Next_Elmt (ADT);
4228 end if;
4229 end loop;
4231 pragma Assert (Is_Tag (Node (ADT)));
4232 return Node (ADT);
4233 end Search_Tag;
4235 -- Start of processing for Collect_Interfaces_Info
4237 begin
4238 Collect_Interfaces (T, Ifaces_List);
4239 Collect_Interface_Components (T, Comps_List);
4241 -- Search for the record component and tag associated with each
4242 -- interface type of T.
4244 Components_List := New_Elmt_List;
4245 Tags_List := New_Elmt_List;
4247 Iface_Elmt := First_Elmt (Ifaces_List);
4248 while Present (Iface_Elmt) loop
4249 Iface := Node (Iface_Elmt);
4251 -- Associate the primary tag component and the primary dispatch table
4252 -- with all the interfaces that are parents of T
4254 if Is_Ancestor (Iface, T, Use_Full_View => True) then
4255 Append_Elmt (First_Tag_Component (T), Components_List);
4256 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
4258 -- Otherwise search for the tag component and secondary dispatch
4259 -- table of Iface
4261 else
4262 Comp_Elmt := First_Elmt (Comps_List);
4263 while Present (Comp_Elmt) loop
4264 Comp_Iface := Related_Type (Node (Comp_Elmt));
4266 if Comp_Iface = Iface
4267 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
4268 then
4269 Append_Elmt (Node (Comp_Elmt), Components_List);
4270 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
4271 exit;
4272 end if;
4274 Next_Elmt (Comp_Elmt);
4275 end loop;
4276 pragma Assert (Present (Comp_Elmt));
4277 end if;
4279 Next_Elmt (Iface_Elmt);
4280 end loop;
4281 end Collect_Interfaces_Info;
4283 ---------------------
4284 -- Collect_Parents --
4285 ---------------------
4287 procedure Collect_Parents
4288 (T : Entity_Id;
4289 List : out Elist_Id;
4290 Use_Full_View : Boolean := True)
4292 Current_Typ : Entity_Id := T;
4293 Parent_Typ : Entity_Id;
4295 begin
4296 List := New_Elmt_List;
4298 -- No action if the if the type has no parents
4300 if T = Etype (T) then
4301 return;
4302 end if;
4304 loop
4305 Parent_Typ := Etype (Current_Typ);
4307 if Is_Private_Type (Parent_Typ)
4308 and then Present (Full_View (Parent_Typ))
4309 and then Use_Full_View
4310 then
4311 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4312 end if;
4314 Append_Elmt (Parent_Typ, List);
4316 exit when Parent_Typ = Current_Typ;
4317 Current_Typ := Parent_Typ;
4318 end loop;
4319 end Collect_Parents;
4321 ----------------------------------
4322 -- Collect_Primitive_Operations --
4323 ----------------------------------
4325 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
4326 B_Type : constant Entity_Id := Base_Type (T);
4327 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
4328 B_Scope : Entity_Id := Scope (B_Type);
4329 Op_List : Elist_Id;
4330 Formal : Entity_Id;
4331 Is_Prim : Boolean;
4332 Is_Type_In_Pkg : Boolean;
4333 Formal_Derived : Boolean := False;
4334 Id : Entity_Id;
4336 function Match (E : Entity_Id) return Boolean;
4337 -- True if E's base type is B_Type, or E is of an anonymous access type
4338 -- and the base type of its designated type is B_Type.
4340 -----------
4341 -- Match --
4342 -----------
4344 function Match (E : Entity_Id) return Boolean is
4345 Etyp : Entity_Id := Etype (E);
4347 begin
4348 if Ekind (Etyp) = E_Anonymous_Access_Type then
4349 Etyp := Designated_Type (Etyp);
4350 end if;
4352 -- In Ada 2012 a primitive operation may have a formal of an
4353 -- incomplete view of the parent type.
4355 return Base_Type (Etyp) = B_Type
4356 or else
4357 (Ada_Version >= Ada_2012
4358 and then Ekind (Etyp) = E_Incomplete_Type
4359 and then Full_View (Etyp) = B_Type);
4360 end Match;
4362 -- Start of processing for Collect_Primitive_Operations
4364 begin
4365 -- For tagged types, the primitive operations are collected as they
4366 -- are declared, and held in an explicit list which is simply returned.
4368 if Is_Tagged_Type (B_Type) then
4369 return Primitive_Operations (B_Type);
4371 -- An untagged generic type that is a derived type inherits the
4372 -- primitive operations of its parent type. Other formal types only
4373 -- have predefined operators, which are not explicitly represented.
4375 elsif Is_Generic_Type (B_Type) then
4376 if Nkind (B_Decl) = N_Formal_Type_Declaration
4377 and then Nkind (Formal_Type_Definition (B_Decl)) =
4378 N_Formal_Derived_Type_Definition
4379 then
4380 Formal_Derived := True;
4381 else
4382 return New_Elmt_List;
4383 end if;
4384 end if;
4386 Op_List := New_Elmt_List;
4388 if B_Scope = Standard_Standard then
4389 if B_Type = Standard_String then
4390 Append_Elmt (Standard_Op_Concat, Op_List);
4392 elsif B_Type = Standard_Wide_String then
4393 Append_Elmt (Standard_Op_Concatw, Op_List);
4395 else
4396 null;
4397 end if;
4399 -- Locate the primitive subprograms of the type
4401 else
4402 -- The primitive operations appear after the base type, except
4403 -- if the derivation happens within the private part of B_Scope
4404 -- and the type is a private type, in which case both the type
4405 -- and some primitive operations may appear before the base
4406 -- type, and the list of candidates starts after the type.
4408 if In_Open_Scopes (B_Scope)
4409 and then Scope (T) = B_Scope
4410 and then In_Private_Part (B_Scope)
4411 then
4412 Id := Next_Entity (T);
4414 -- In Ada 2012, If the type has an incomplete partial view, there
4415 -- may be primitive operations declared before the full view, so
4416 -- we need to start scanning from the incomplete view, which is
4417 -- earlier on the entity chain.
4419 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
4420 and then Present (Incomplete_View (Parent (B_Type)))
4421 then
4422 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
4424 -- If T is a derived from a type with an incomplete view declared
4425 -- elsewhere, that incomplete view is irrelevant, we want the
4426 -- operations in the scope of T.
4428 if Scope (Id) /= Scope (B_Type) then
4429 Id := Next_Entity (B_Type);
4430 end if;
4432 else
4433 Id := Next_Entity (B_Type);
4434 end if;
4436 -- Set flag if this is a type in a package spec
4438 Is_Type_In_Pkg :=
4439 Is_Package_Or_Generic_Package (B_Scope)
4440 and then
4441 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
4442 N_Package_Body;
4444 while Present (Id) loop
4446 -- Test whether the result type or any of the parameter types of
4447 -- each subprogram following the type match that type when the
4448 -- type is declared in a package spec, is a derived type, or the
4449 -- subprogram is marked as primitive. (The Is_Primitive test is
4450 -- needed to find primitives of nonderived types in declarative
4451 -- parts that happen to override the predefined "=" operator.)
4453 -- Note that generic formal subprograms are not considered to be
4454 -- primitive operations and thus are never inherited.
4456 if Is_Overloadable (Id)
4457 and then (Is_Type_In_Pkg
4458 or else Is_Derived_Type (B_Type)
4459 or else Is_Primitive (Id))
4460 and then Nkind (Parent (Parent (Id)))
4461 not in N_Formal_Subprogram_Declaration
4462 then
4463 Is_Prim := False;
4465 if Match (Id) then
4466 Is_Prim := True;
4468 else
4469 Formal := First_Formal (Id);
4470 while Present (Formal) loop
4471 if Match (Formal) then
4472 Is_Prim := True;
4473 exit;
4474 end if;
4476 Next_Formal (Formal);
4477 end loop;
4478 end if;
4480 -- For a formal derived type, the only primitives are the ones
4481 -- inherited from the parent type. Operations appearing in the
4482 -- package declaration are not primitive for it.
4484 if Is_Prim
4485 and then (not Formal_Derived or else Present (Alias (Id)))
4486 then
4487 -- In the special case of an equality operator aliased to
4488 -- an overriding dispatching equality belonging to the same
4489 -- type, we don't include it in the list of primitives.
4490 -- This avoids inheriting multiple equality operators when
4491 -- deriving from untagged private types whose full type is
4492 -- tagged, which can otherwise cause ambiguities. Note that
4493 -- this should only happen for this kind of untagged parent
4494 -- type, since normally dispatching operations are inherited
4495 -- using the type's Primitive_Operations list.
4497 if Chars (Id) = Name_Op_Eq
4498 and then Is_Dispatching_Operation (Id)
4499 and then Present (Alias (Id))
4500 and then Present (Overridden_Operation (Alias (Id)))
4501 and then Base_Type (Etype (First_Entity (Id))) =
4502 Base_Type (Etype (First_Entity (Alias (Id))))
4503 then
4504 null;
4506 -- Include the subprogram in the list of primitives
4508 else
4509 Append_Elmt (Id, Op_List);
4510 end if;
4511 end if;
4512 end if;
4514 Next_Entity (Id);
4516 -- For a type declared in System, some of its operations may
4517 -- appear in the target-specific extension to System.
4519 if No (Id)
4520 and then B_Scope = RTU_Entity (System)
4521 and then Present_System_Aux
4522 then
4523 B_Scope := System_Aux_Id;
4524 Id := First_Entity (System_Aux_Id);
4525 end if;
4526 end loop;
4527 end if;
4529 return Op_List;
4530 end Collect_Primitive_Operations;
4532 -----------------------------------
4533 -- Compile_Time_Constraint_Error --
4534 -----------------------------------
4536 function Compile_Time_Constraint_Error
4537 (N : Node_Id;
4538 Msg : String;
4539 Ent : Entity_Id := Empty;
4540 Loc : Source_Ptr := No_Location;
4541 Warn : Boolean := False) return Node_Id
4543 Msgc : String (1 .. Msg'Length + 3);
4544 -- Copy of message, with room for possible ?? or << and ! at end
4546 Msgl : Natural;
4547 Wmsg : Boolean;
4548 Eloc : Source_Ptr;
4550 -- Start of processing for Compile_Time_Constraint_Error
4552 begin
4553 -- If this is a warning, convert it into an error if we are in code
4554 -- subject to SPARK_Mode being set On, unless Warn is True to force a
4555 -- warning. The rationale is that a compile-time constraint error should
4556 -- lead to an error instead of a warning when SPARK_Mode is On, but in
4557 -- a few cases we prefer to issue a warning and generate both a suitable
4558 -- run-time error in GNAT and a suitable check message in GNATprove.
4559 -- Those cases are those that likely correspond to deactivated SPARK
4560 -- code, so that this kind of code can be compiled and analyzed instead
4561 -- of being rejected.
4563 Error_Msg_Warn := Warn or SPARK_Mode /= On;
4565 -- A static constraint error in an instance body is not a fatal error.
4566 -- we choose to inhibit the message altogether, because there is no
4567 -- obvious node (for now) on which to post it. On the other hand the
4568 -- offending node must be replaced with a constraint_error in any case.
4570 -- No messages are generated if we already posted an error on this node
4572 if not Error_Posted (N) then
4573 if Loc /= No_Location then
4574 Eloc := Loc;
4575 else
4576 Eloc := Sloc (N);
4577 end if;
4579 -- Copy message to Msgc, converting any ? in the message into
4580 -- < instead, so that we have an error in GNATprove mode.
4582 Msgl := Msg'Length;
4584 for J in 1 .. Msgl loop
4585 if Msg (J) = '?' and then (J = 1 or else Msg (J - 1) /= ''') then
4586 Msgc (J) := '<';
4587 else
4588 Msgc (J) := Msg (J);
4589 end if;
4590 end loop;
4592 -- Message is a warning, even in Ada 95 case
4594 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
4595 Wmsg := True;
4597 -- In Ada 83, all messages are warnings. In the private part and
4598 -- the body of an instance, constraint_checks are only warnings.
4599 -- We also make this a warning if the Warn parameter is set.
4601 elsif Warn
4602 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
4603 then
4604 Msgl := Msgl + 1;
4605 Msgc (Msgl) := '<';
4606 Msgl := Msgl + 1;
4607 Msgc (Msgl) := '<';
4608 Wmsg := True;
4610 elsif In_Instance_Not_Visible then
4611 Msgl := Msgl + 1;
4612 Msgc (Msgl) := '<';
4613 Msgl := Msgl + 1;
4614 Msgc (Msgl) := '<';
4615 Wmsg := True;
4617 -- Otherwise we have a real error message (Ada 95 static case)
4618 -- and we make this an unconditional message. Note that in the
4619 -- warning case we do not make the message unconditional, it seems
4620 -- quite reasonable to delete messages like this (about exceptions
4621 -- that will be raised) in dead code.
4623 else
4624 Wmsg := False;
4625 Msgl := Msgl + 1;
4626 Msgc (Msgl) := '!';
4627 end if;
4629 -- One more test, skip the warning if the related expression is
4630 -- statically unevaluated, since we don't want to warn about what
4631 -- will happen when something is evaluated if it never will be
4632 -- evaluated.
4634 if not Is_Statically_Unevaluated (N) then
4635 if Present (Ent) then
4636 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4637 else
4638 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4639 end if;
4641 if Wmsg then
4643 -- Check whether the context is an Init_Proc
4645 if Inside_Init_Proc then
4646 declare
4647 Conc_Typ : constant Entity_Id :=
4648 Corresponding_Concurrent_Type
4649 (Entity (Parameter_Type (First
4650 (Parameter_Specifications
4651 (Parent (Current_Scope))))));
4653 begin
4654 -- Don't complain if the corresponding concurrent type
4655 -- doesn't come from source (i.e. a single task/protected
4656 -- object).
4658 if Present (Conc_Typ)
4659 and then not Comes_From_Source (Conc_Typ)
4660 then
4661 Error_Msg_NEL
4662 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4664 else
4665 if GNATprove_Mode then
4666 Error_Msg_NEL
4667 ("\& would have been raised for objects of this "
4668 & "type", N, Standard_Constraint_Error, Eloc);
4669 else
4670 Error_Msg_NEL
4671 ("\& will be raised for objects of this type??",
4672 N, Standard_Constraint_Error, Eloc);
4673 end if;
4674 end if;
4675 end;
4677 else
4678 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4679 end if;
4681 else
4682 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4683 Set_Error_Posted (N);
4684 end if;
4685 end if;
4686 end if;
4688 return N;
4689 end Compile_Time_Constraint_Error;
4691 -----------------------
4692 -- Conditional_Delay --
4693 -----------------------
4695 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4696 begin
4697 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4698 Set_Has_Delayed_Freeze (New_Ent);
4699 end if;
4700 end Conditional_Delay;
4702 ----------------------------
4703 -- Contains_Refined_State --
4704 ----------------------------
4706 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4707 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4708 -- Determine whether a dependency list mentions a state with a visible
4709 -- refinement.
4711 function Has_State_In_Global (List : Node_Id) return Boolean;
4712 -- Determine whether a global list mentions a state with a visible
4713 -- refinement.
4715 function Is_Refined_State (Item : Node_Id) return Boolean;
4716 -- Determine whether Item is a reference to an abstract state with a
4717 -- visible refinement.
4719 -----------------------------
4720 -- Has_State_In_Dependency --
4721 -----------------------------
4723 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4724 Clause : Node_Id;
4725 Output : Node_Id;
4727 begin
4728 -- A null dependency list does not mention any states
4730 if Nkind (List) = N_Null then
4731 return False;
4733 -- Dependency clauses appear as component associations of an
4734 -- aggregate.
4736 elsif Nkind (List) = N_Aggregate
4737 and then Present (Component_Associations (List))
4738 then
4739 Clause := First (Component_Associations (List));
4740 while Present (Clause) loop
4742 -- Inspect the outputs of a dependency clause
4744 Output := First (Choices (Clause));
4745 while Present (Output) loop
4746 if Is_Refined_State (Output) then
4747 return True;
4748 end if;
4750 Next (Output);
4751 end loop;
4753 -- Inspect the outputs of a dependency clause
4755 if Is_Refined_State (Expression (Clause)) then
4756 return True;
4757 end if;
4759 Next (Clause);
4760 end loop;
4762 -- If we get here, then none of the dependency clauses mention a
4763 -- state with visible refinement.
4765 return False;
4767 -- An illegal pragma managed to sneak in
4769 else
4770 raise Program_Error;
4771 end if;
4772 end Has_State_In_Dependency;
4774 -------------------------
4775 -- Has_State_In_Global --
4776 -------------------------
4778 function Has_State_In_Global (List : Node_Id) return Boolean is
4779 Item : Node_Id;
4781 begin
4782 -- A null global list does not mention any states
4784 if Nkind (List) = N_Null then
4785 return False;
4787 -- Simple global list or moded global list declaration
4789 elsif Nkind (List) = N_Aggregate then
4791 -- The declaration of a simple global list appear as a collection
4792 -- of expressions.
4794 if Present (Expressions (List)) then
4795 Item := First (Expressions (List));
4796 while Present (Item) loop
4797 if Is_Refined_State (Item) then
4798 return True;
4799 end if;
4801 Next (Item);
4802 end loop;
4804 -- The declaration of a moded global list appears as a collection
4805 -- of component associations where individual choices denote
4806 -- modes.
4808 else
4809 Item := First (Component_Associations (List));
4810 while Present (Item) loop
4811 if Has_State_In_Global (Expression (Item)) then
4812 return True;
4813 end if;
4815 Next (Item);
4816 end loop;
4817 end if;
4819 -- If we get here, then the simple/moded global list did not
4820 -- mention any states with a visible refinement.
4822 return False;
4824 -- Single global item declaration
4826 elsif Is_Entity_Name (List) then
4827 return Is_Refined_State (List);
4829 -- An illegal pragma managed to sneak in
4831 else
4832 raise Program_Error;
4833 end if;
4834 end Has_State_In_Global;
4836 ----------------------
4837 -- Is_Refined_State --
4838 ----------------------
4840 function Is_Refined_State (Item : Node_Id) return Boolean is
4841 Elmt : Node_Id;
4842 Item_Id : Entity_Id;
4844 begin
4845 if Nkind (Item) = N_Null then
4846 return False;
4848 -- States cannot be subject to attribute 'Result. This case arises
4849 -- in dependency relations.
4851 elsif Nkind (Item) = N_Attribute_Reference
4852 and then Attribute_Name (Item) = Name_Result
4853 then
4854 return False;
4856 -- Multiple items appear as an aggregate. This case arises in
4857 -- dependency relations.
4859 elsif Nkind (Item) = N_Aggregate
4860 and then Present (Expressions (Item))
4861 then
4862 Elmt := First (Expressions (Item));
4863 while Present (Elmt) loop
4864 if Is_Refined_State (Elmt) then
4865 return True;
4866 end if;
4868 Next (Elmt);
4869 end loop;
4871 -- If we get here, then none of the inputs or outputs reference a
4872 -- state with visible refinement.
4874 return False;
4876 -- Single item
4878 else
4879 Item_Id := Entity_Of (Item);
4881 return
4882 Present (Item_Id)
4883 and then Ekind (Item_Id) = E_Abstract_State
4884 and then Has_Visible_Refinement (Item_Id);
4885 end if;
4886 end Is_Refined_State;
4888 -- Local variables
4890 Arg : constant Node_Id :=
4891 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4892 Nam : constant Name_Id := Pragma_Name (Prag);
4894 -- Start of processing for Contains_Refined_State
4896 begin
4897 if Nam = Name_Depends then
4898 return Has_State_In_Dependency (Arg);
4900 else pragma Assert (Nam = Name_Global);
4901 return Has_State_In_Global (Arg);
4902 end if;
4903 end Contains_Refined_State;
4905 -------------------------
4906 -- Copy_Component_List --
4907 -------------------------
4909 function Copy_Component_List
4910 (R_Typ : Entity_Id;
4911 Loc : Source_Ptr) return List_Id
4913 Comp : Node_Id;
4914 Comps : constant List_Id := New_List;
4916 begin
4917 Comp := First_Component (Underlying_Type (R_Typ));
4918 while Present (Comp) loop
4919 if Comes_From_Source (Comp) then
4920 declare
4921 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4922 begin
4923 Append_To (Comps,
4924 Make_Component_Declaration (Loc,
4925 Defining_Identifier =>
4926 Make_Defining_Identifier (Loc, Chars (Comp)),
4927 Component_Definition =>
4928 New_Copy_Tree
4929 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4930 end;
4931 end if;
4933 Next_Component (Comp);
4934 end loop;
4936 return Comps;
4937 end Copy_Component_List;
4939 -------------------------
4940 -- Copy_Parameter_List --
4941 -------------------------
4943 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4944 Loc : constant Source_Ptr := Sloc (Subp_Id);
4945 Plist : List_Id;
4946 Formal : Entity_Id;
4948 begin
4949 if No (First_Formal (Subp_Id)) then
4950 return No_List;
4951 else
4952 Plist := New_List;
4953 Formal := First_Formal (Subp_Id);
4954 while Present (Formal) loop
4955 Append_To (Plist,
4956 Make_Parameter_Specification (Loc,
4957 Defining_Identifier =>
4958 Make_Defining_Identifier (Sloc (Formal), Chars (Formal)),
4959 In_Present => In_Present (Parent (Formal)),
4960 Out_Present => Out_Present (Parent (Formal)),
4961 Parameter_Type =>
4962 New_Occurrence_Of (Etype (Formal), Loc),
4963 Expression =>
4964 New_Copy_Tree (Expression (Parent (Formal)))));
4966 Next_Formal (Formal);
4967 end loop;
4968 end if;
4970 return Plist;
4971 end Copy_Parameter_List;
4973 ----------------------------
4974 -- Copy_SPARK_Mode_Aspect --
4975 ----------------------------
4977 procedure Copy_SPARK_Mode_Aspect (From : Node_Id; To : Node_Id) is
4978 pragma Assert (not Has_Aspects (To));
4979 Asp : Node_Id;
4981 begin
4982 if Has_Aspects (From) then
4983 Asp := Find_Aspect (Defining_Entity (From), Aspect_SPARK_Mode);
4985 if Present (Asp) then
4986 Set_Aspect_Specifications (To, New_List (New_Copy_Tree (Asp)));
4987 Set_Has_Aspects (To, True);
4988 end if;
4989 end if;
4990 end Copy_SPARK_Mode_Aspect;
4992 --------------------------
4993 -- Copy_Subprogram_Spec --
4994 --------------------------
4996 function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is
4997 Def_Id : Node_Id;
4998 Formal_Spec : Node_Id;
4999 Result : Node_Id;
5001 begin
5002 -- The structure of the original tree must be replicated without any
5003 -- alterations. Use New_Copy_Tree for this purpose.
5005 Result := New_Copy_Tree (Spec);
5007 -- Create a new entity for the defining unit name
5009 Def_Id := Defining_Unit_Name (Result);
5010 Set_Defining_Unit_Name (Result,
5011 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5013 -- Create new entities for the formal parameters
5015 if Present (Parameter_Specifications (Result)) then
5016 Formal_Spec := First (Parameter_Specifications (Result));
5017 while Present (Formal_Spec) loop
5018 Def_Id := Defining_Identifier (Formal_Spec);
5019 Set_Defining_Identifier (Formal_Spec,
5020 Make_Defining_Identifier (Sloc (Def_Id), Chars (Def_Id)));
5022 Next (Formal_Spec);
5023 end loop;
5024 end if;
5026 return Result;
5027 end Copy_Subprogram_Spec;
5029 --------------------------------
5030 -- Corresponding_Generic_Type --
5031 --------------------------------
5033 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
5034 Inst : Entity_Id;
5035 Gen : Entity_Id;
5036 Typ : Entity_Id;
5038 begin
5039 if not Is_Generic_Actual_Type (T) then
5040 return Any_Type;
5042 -- If the actual is the actual of an enclosing instance, resolution
5043 -- was correct in the generic.
5045 elsif Nkind (Parent (T)) = N_Subtype_Declaration
5046 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
5047 and then
5048 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
5049 then
5050 return Any_Type;
5052 else
5053 Inst := Scope (T);
5055 if Is_Wrapper_Package (Inst) then
5056 Inst := Related_Instance (Inst);
5057 end if;
5059 Gen :=
5060 Generic_Parent
5061 (Specification (Unit_Declaration_Node (Inst)));
5063 -- Generic actual has the same name as the corresponding formal
5065 Typ := First_Entity (Gen);
5066 while Present (Typ) loop
5067 if Chars (Typ) = Chars (T) then
5068 return Typ;
5069 end if;
5071 Next_Entity (Typ);
5072 end loop;
5074 return Any_Type;
5075 end if;
5076 end Corresponding_Generic_Type;
5078 --------------------
5079 -- Current_Entity --
5080 --------------------
5082 -- The currently visible definition for a given identifier is the
5083 -- one most chained at the start of the visibility chain, i.e. the
5084 -- one that is referenced by the Node_Id value of the name of the
5085 -- given identifier.
5087 function Current_Entity (N : Node_Id) return Entity_Id is
5088 begin
5089 return Get_Name_Entity_Id (Chars (N));
5090 end Current_Entity;
5092 -----------------------------
5093 -- Current_Entity_In_Scope --
5094 -----------------------------
5096 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
5097 E : Entity_Id;
5098 CS : constant Entity_Id := Current_Scope;
5100 Transient_Case : constant Boolean := Scope_Is_Transient;
5102 begin
5103 E := Get_Name_Entity_Id (Chars (N));
5104 while Present (E)
5105 and then Scope (E) /= CS
5106 and then (not Transient_Case or else Scope (E) /= Scope (CS))
5107 loop
5108 E := Homonym (E);
5109 end loop;
5111 return E;
5112 end Current_Entity_In_Scope;
5114 -------------------
5115 -- Current_Scope --
5116 -------------------
5118 function Current_Scope return Entity_Id is
5119 begin
5120 if Scope_Stack.Last = -1 then
5121 return Standard_Standard;
5122 else
5123 declare
5124 C : constant Entity_Id :=
5125 Scope_Stack.Table (Scope_Stack.Last).Entity;
5126 begin
5127 if Present (C) then
5128 return C;
5129 else
5130 return Standard_Standard;
5131 end if;
5132 end;
5133 end if;
5134 end Current_Scope;
5136 ----------------------------
5137 -- Current_Scope_No_Loops --
5138 ----------------------------
5140 function Current_Scope_No_Loops return Entity_Id is
5141 S : Entity_Id;
5143 begin
5144 -- Examine the scope stack starting from the current scope and skip any
5145 -- internally generated loops.
5147 S := Current_Scope;
5148 while Present (S) and then S /= Standard_Standard loop
5149 if Ekind (S) = E_Loop and then not Comes_From_Source (S) then
5150 S := Scope (S);
5151 else
5152 exit;
5153 end if;
5154 end loop;
5156 return S;
5157 end Current_Scope_No_Loops;
5159 ------------------------
5160 -- Current_Subprogram --
5161 ------------------------
5163 function Current_Subprogram return Entity_Id is
5164 Scop : constant Entity_Id := Current_Scope;
5165 begin
5166 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
5167 return Scop;
5168 else
5169 return Enclosing_Subprogram (Scop);
5170 end if;
5171 end Current_Subprogram;
5173 ----------------------------------
5174 -- Deepest_Type_Access_Level --
5175 ----------------------------------
5177 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
5178 begin
5179 if Ekind (Typ) = E_Anonymous_Access_Type
5180 and then not Is_Local_Anonymous_Access (Typ)
5181 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
5182 then
5183 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5184 -- access type.
5186 return
5187 Scope_Depth (Enclosing_Dynamic_Scope
5188 (Defining_Identifier
5189 (Associated_Node_For_Itype (Typ))));
5191 -- For generic formal type, return Int'Last (infinite).
5192 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5194 elsif Is_Generic_Type (Root_Type (Typ)) then
5195 return UI_From_Int (Int'Last);
5197 else
5198 return Type_Access_Level (Typ);
5199 end if;
5200 end Deepest_Type_Access_Level;
5202 ---------------------
5203 -- Defining_Entity --
5204 ---------------------
5206 function Defining_Entity
5207 (N : Node_Id;
5208 Empty_On_Errors : Boolean := False) return Entity_Id
5210 Err : Entity_Id := Empty;
5212 begin
5213 case Nkind (N) is
5214 when N_Abstract_Subprogram_Declaration
5215 | N_Expression_Function
5216 | N_Formal_Subprogram_Declaration
5217 | N_Generic_Package_Declaration
5218 | N_Generic_Subprogram_Declaration
5219 | N_Package_Declaration
5220 | N_Subprogram_Body
5221 | N_Subprogram_Body_Stub
5222 | N_Subprogram_Declaration
5223 | N_Subprogram_Renaming_Declaration
5225 return Defining_Entity (Specification (N));
5227 when N_Component_Declaration
5228 | N_Defining_Program_Unit_Name
5229 | N_Discriminant_Specification
5230 | N_Entry_Body
5231 | N_Entry_Declaration
5232 | N_Entry_Index_Specification
5233 | N_Exception_Declaration
5234 | N_Exception_Renaming_Declaration
5235 | N_Formal_Object_Declaration
5236 | N_Formal_Package_Declaration
5237 | N_Formal_Type_Declaration
5238 | N_Full_Type_Declaration
5239 | N_Implicit_Label_Declaration
5240 | N_Incomplete_Type_Declaration
5241 | N_Iterator_Specification
5242 | N_Loop_Parameter_Specification
5243 | N_Number_Declaration
5244 | N_Object_Declaration
5245 | N_Object_Renaming_Declaration
5246 | N_Package_Body_Stub
5247 | N_Parameter_Specification
5248 | N_Private_Extension_Declaration
5249 | N_Private_Type_Declaration
5250 | N_Protected_Body
5251 | N_Protected_Body_Stub
5252 | N_Protected_Type_Declaration
5253 | N_Single_Protected_Declaration
5254 | N_Single_Task_Declaration
5255 | N_Subtype_Declaration
5256 | N_Task_Body
5257 | N_Task_Body_Stub
5258 | N_Task_Type_Declaration
5260 return Defining_Identifier (N);
5262 when N_Subunit =>
5263 return Defining_Entity (Proper_Body (N));
5265 when N_Function_Instantiation
5266 | N_Function_Specification
5267 | N_Generic_Function_Renaming_Declaration
5268 | N_Generic_Package_Renaming_Declaration
5269 | N_Generic_Procedure_Renaming_Declaration
5270 | N_Package_Body
5271 | N_Package_Instantiation
5272 | N_Package_Renaming_Declaration
5273 | N_Package_Specification
5274 | N_Procedure_Instantiation
5275 | N_Procedure_Specification
5277 declare
5278 Nam : constant Node_Id := Defining_Unit_Name (N);
5280 begin
5281 if Nkind (Nam) in N_Entity then
5282 return Nam;
5284 -- For Error, make up a name and attach to declaration so we
5285 -- can continue semantic analysis.
5287 elsif Nam = Error then
5288 if Empty_On_Errors then
5289 return Empty;
5290 else
5291 Err := Make_Temporary (Sloc (N), 'T');
5292 Set_Defining_Unit_Name (N, Err);
5294 return Err;
5295 end if;
5297 -- If not an entity, get defining identifier
5299 else
5300 return Defining_Identifier (Nam);
5301 end if;
5302 end;
5304 when N_Block_Statement
5305 | N_Loop_Statement
5307 return Entity (Identifier (N));
5309 when others =>
5310 if Empty_On_Errors then
5311 return Empty;
5312 else
5313 raise Program_Error;
5314 end if;
5315 end case;
5316 end Defining_Entity;
5318 --------------------------
5319 -- Denotes_Discriminant --
5320 --------------------------
5322 function Denotes_Discriminant
5323 (N : Node_Id;
5324 Check_Concurrent : Boolean := False) return Boolean
5326 E : Entity_Id;
5328 begin
5329 if not Is_Entity_Name (N) or else No (Entity (N)) then
5330 return False;
5331 else
5332 E := Entity (N);
5333 end if;
5335 -- If we are checking for a protected type, the discriminant may have
5336 -- been rewritten as the corresponding discriminal of the original type
5337 -- or of the corresponding concurrent record, depending on whether we
5338 -- are in the spec or body of the protected type.
5340 return Ekind (E) = E_Discriminant
5341 or else
5342 (Check_Concurrent
5343 and then Ekind (E) = E_In_Parameter
5344 and then Present (Discriminal_Link (E))
5345 and then
5346 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
5347 or else
5348 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
5349 end Denotes_Discriminant;
5351 -------------------------
5352 -- Denotes_Same_Object --
5353 -------------------------
5355 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
5356 Obj1 : Node_Id := A1;
5357 Obj2 : Node_Id := A2;
5359 function Has_Prefix (N : Node_Id) return Boolean;
5360 -- Return True if N has attribute Prefix
5362 function Is_Renaming (N : Node_Id) return Boolean;
5363 -- Return true if N names a renaming entity
5365 function Is_Valid_Renaming (N : Node_Id) return Boolean;
5366 -- For renamings, return False if the prefix of any dereference within
5367 -- the renamed object_name is a variable, or any expression within the
5368 -- renamed object_name contains references to variables or calls on
5369 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5371 ----------------
5372 -- Has_Prefix --
5373 ----------------
5375 function Has_Prefix (N : Node_Id) return Boolean is
5376 begin
5377 return
5378 Nkind_In (N,
5379 N_Attribute_Reference,
5380 N_Expanded_Name,
5381 N_Explicit_Dereference,
5382 N_Indexed_Component,
5383 N_Reference,
5384 N_Selected_Component,
5385 N_Slice);
5386 end Has_Prefix;
5388 -----------------
5389 -- Is_Renaming --
5390 -----------------
5392 function Is_Renaming (N : Node_Id) return Boolean is
5393 begin
5394 return Is_Entity_Name (N)
5395 and then Present (Renamed_Entity (Entity (N)));
5396 end Is_Renaming;
5398 -----------------------
5399 -- Is_Valid_Renaming --
5400 -----------------------
5402 function Is_Valid_Renaming (N : Node_Id) return Boolean is
5404 function Check_Renaming (N : Node_Id) return Boolean;
5405 -- Recursive function used to traverse all the prefixes of N
5407 function Check_Renaming (N : Node_Id) return Boolean is
5408 begin
5409 if Is_Renaming (N)
5410 and then not Check_Renaming (Renamed_Entity (Entity (N)))
5411 then
5412 return False;
5413 end if;
5415 if Nkind (N) = N_Indexed_Component then
5416 declare
5417 Indx : Node_Id;
5419 begin
5420 Indx := First (Expressions (N));
5421 while Present (Indx) loop
5422 if not Is_OK_Static_Expression (Indx) then
5423 return False;
5424 end if;
5426 Next_Index (Indx);
5427 end loop;
5428 end;
5429 end if;
5431 if Has_Prefix (N) then
5432 declare
5433 P : constant Node_Id := Prefix (N);
5435 begin
5436 if Nkind (N) = N_Explicit_Dereference
5437 and then Is_Variable (P)
5438 then
5439 return False;
5441 elsif Is_Entity_Name (P)
5442 and then Ekind (Entity (P)) = E_Function
5443 then
5444 return False;
5446 elsif Nkind (P) = N_Function_Call then
5447 return False;
5448 end if;
5450 -- Recursion to continue traversing the prefix of the
5451 -- renaming expression
5453 return Check_Renaming (P);
5454 end;
5455 end if;
5457 return True;
5458 end Check_Renaming;
5460 -- Start of processing for Is_Valid_Renaming
5462 begin
5463 return Check_Renaming (N);
5464 end Is_Valid_Renaming;
5466 -- Start of processing for Denotes_Same_Object
5468 begin
5469 -- Both names statically denote the same stand-alone object or parameter
5470 -- (RM 6.4.1(6.5/3))
5472 if Is_Entity_Name (Obj1)
5473 and then Is_Entity_Name (Obj2)
5474 and then Entity (Obj1) = Entity (Obj2)
5475 then
5476 return True;
5477 end if;
5479 -- For renamings, the prefix of any dereference within the renamed
5480 -- object_name is not a variable, and any expression within the
5481 -- renamed object_name contains no references to variables nor
5482 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5484 if Is_Renaming (Obj1) then
5485 if Is_Valid_Renaming (Obj1) then
5486 Obj1 := Renamed_Entity (Entity (Obj1));
5487 else
5488 return False;
5489 end if;
5490 end if;
5492 if Is_Renaming (Obj2) then
5493 if Is_Valid_Renaming (Obj2) then
5494 Obj2 := Renamed_Entity (Entity (Obj2));
5495 else
5496 return False;
5497 end if;
5498 end if;
5500 -- No match if not same node kind (such cases are handled by
5501 -- Denotes_Same_Prefix)
5503 if Nkind (Obj1) /= Nkind (Obj2) then
5504 return False;
5506 -- After handling valid renamings, one of the two names statically
5507 -- denoted a renaming declaration whose renamed object_name is known
5508 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5510 elsif Is_Entity_Name (Obj1) then
5511 if Is_Entity_Name (Obj2) then
5512 return Entity (Obj1) = Entity (Obj2);
5513 else
5514 return False;
5515 end if;
5517 -- Both names are selected_components, their prefixes are known to
5518 -- denote the same object, and their selector_names denote the same
5519 -- component (RM 6.4.1(6.6/3)).
5521 elsif Nkind (Obj1) = N_Selected_Component then
5522 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5523 and then
5524 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
5526 -- Both names are dereferences and the dereferenced names are known to
5527 -- denote the same object (RM 6.4.1(6.7/3))
5529 elsif Nkind (Obj1) = N_Explicit_Dereference then
5530 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
5532 -- Both names are indexed_components, their prefixes are known to denote
5533 -- the same object, and each of the pairs of corresponding index values
5534 -- are either both static expressions with the same static value or both
5535 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5537 elsif Nkind (Obj1) = N_Indexed_Component then
5538 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
5539 return False;
5540 else
5541 declare
5542 Indx1 : Node_Id;
5543 Indx2 : Node_Id;
5545 begin
5546 Indx1 := First (Expressions (Obj1));
5547 Indx2 := First (Expressions (Obj2));
5548 while Present (Indx1) loop
5550 -- Indexes must denote the same static value or same object
5552 if Is_OK_Static_Expression (Indx1) then
5553 if not Is_OK_Static_Expression (Indx2) then
5554 return False;
5556 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
5557 return False;
5558 end if;
5560 elsif not Denotes_Same_Object (Indx1, Indx2) then
5561 return False;
5562 end if;
5564 Next (Indx1);
5565 Next (Indx2);
5566 end loop;
5568 return True;
5569 end;
5570 end if;
5572 -- Both names are slices, their prefixes are known to denote the same
5573 -- object, and the two slices have statically matching index constraints
5574 -- (RM 6.4.1(6.9/3))
5576 elsif Nkind (Obj1) = N_Slice
5577 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
5578 then
5579 declare
5580 Lo1, Lo2, Hi1, Hi2 : Node_Id;
5582 begin
5583 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
5584 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
5586 -- Check whether bounds are statically identical. There is no
5587 -- attempt to detect partial overlap of slices.
5589 return Denotes_Same_Object (Lo1, Lo2)
5590 and then
5591 Denotes_Same_Object (Hi1, Hi2);
5592 end;
5594 -- In the recursion, literals appear as indexes
5596 elsif Nkind (Obj1) = N_Integer_Literal
5597 and then
5598 Nkind (Obj2) = N_Integer_Literal
5599 then
5600 return Intval (Obj1) = Intval (Obj2);
5602 else
5603 return False;
5604 end if;
5605 end Denotes_Same_Object;
5607 -------------------------
5608 -- Denotes_Same_Prefix --
5609 -------------------------
5611 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
5612 begin
5613 if Is_Entity_Name (A1) then
5614 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
5615 and then not Is_Access_Type (Etype (A1))
5616 then
5617 return Denotes_Same_Object (A1, Prefix (A2))
5618 or else Denotes_Same_Prefix (A1, Prefix (A2));
5619 else
5620 return False;
5621 end if;
5623 elsif Is_Entity_Name (A2) then
5624 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
5626 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
5627 and then
5628 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
5629 then
5630 declare
5631 Root1, Root2 : Node_Id;
5632 Depth1, Depth2 : Nat := 0;
5634 begin
5635 Root1 := Prefix (A1);
5636 while not Is_Entity_Name (Root1) loop
5637 if not Nkind_In
5638 (Root1, N_Selected_Component, N_Indexed_Component)
5639 then
5640 return False;
5641 else
5642 Root1 := Prefix (Root1);
5643 end if;
5645 Depth1 := Depth1 + 1;
5646 end loop;
5648 Root2 := Prefix (A2);
5649 while not Is_Entity_Name (Root2) loop
5650 if not Nkind_In (Root2, N_Selected_Component,
5651 N_Indexed_Component)
5652 then
5653 return False;
5654 else
5655 Root2 := Prefix (Root2);
5656 end if;
5658 Depth2 := Depth2 + 1;
5659 end loop;
5661 -- If both have the same depth and they do not denote the same
5662 -- object, they are disjoint and no warning is needed.
5664 if Depth1 = Depth2 then
5665 return False;
5667 elsif Depth1 > Depth2 then
5668 Root1 := Prefix (A1);
5669 for J in 1 .. Depth1 - Depth2 - 1 loop
5670 Root1 := Prefix (Root1);
5671 end loop;
5673 return Denotes_Same_Object (Root1, A2);
5675 else
5676 Root2 := Prefix (A2);
5677 for J in 1 .. Depth2 - Depth1 - 1 loop
5678 Root2 := Prefix (Root2);
5679 end loop;
5681 return Denotes_Same_Object (A1, Root2);
5682 end if;
5683 end;
5685 else
5686 return False;
5687 end if;
5688 end Denotes_Same_Prefix;
5690 ----------------------
5691 -- Denotes_Variable --
5692 ----------------------
5694 function Denotes_Variable (N : Node_Id) return Boolean is
5695 begin
5696 return Is_Variable (N) and then Paren_Count (N) = 0;
5697 end Denotes_Variable;
5699 -----------------------------
5700 -- Depends_On_Discriminant --
5701 -----------------------------
5703 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5704 L : Node_Id;
5705 H : Node_Id;
5707 begin
5708 Get_Index_Bounds (N, L, H);
5709 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5710 end Depends_On_Discriminant;
5712 -------------------------
5713 -- Designate_Same_Unit --
5714 -------------------------
5716 function Designate_Same_Unit
5717 (Name1 : Node_Id;
5718 Name2 : Node_Id) return Boolean
5720 K1 : constant Node_Kind := Nkind (Name1);
5721 K2 : constant Node_Kind := Nkind (Name2);
5723 function Prefix_Node (N : Node_Id) return Node_Id;
5724 -- Returns the parent unit name node of a defining program unit name
5725 -- or the prefix if N is a selected component or an expanded name.
5727 function Select_Node (N : Node_Id) return Node_Id;
5728 -- Returns the defining identifier node of a defining program unit
5729 -- name or the selector node if N is a selected component or an
5730 -- expanded name.
5732 -----------------
5733 -- Prefix_Node --
5734 -----------------
5736 function Prefix_Node (N : Node_Id) return Node_Id is
5737 begin
5738 if Nkind (N) = N_Defining_Program_Unit_Name then
5739 return Name (N);
5740 else
5741 return Prefix (N);
5742 end if;
5743 end Prefix_Node;
5745 -----------------
5746 -- Select_Node --
5747 -----------------
5749 function Select_Node (N : Node_Id) return Node_Id is
5750 begin
5751 if Nkind (N) = N_Defining_Program_Unit_Name then
5752 return Defining_Identifier (N);
5753 else
5754 return Selector_Name (N);
5755 end if;
5756 end Select_Node;
5758 -- Start of processing for Designate_Same_Unit
5760 begin
5761 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
5762 and then
5763 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
5764 then
5765 return Chars (Name1) = Chars (Name2);
5767 elsif Nkind_In (K1, N_Expanded_Name,
5768 N_Selected_Component,
5769 N_Defining_Program_Unit_Name)
5770 and then
5771 Nkind_In (K2, N_Expanded_Name,
5772 N_Selected_Component,
5773 N_Defining_Program_Unit_Name)
5774 then
5775 return
5776 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5777 and then
5778 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5780 else
5781 return False;
5782 end if;
5783 end Designate_Same_Unit;
5785 ------------------------------------------
5786 -- function Dynamic_Accessibility_Level --
5787 ------------------------------------------
5789 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5790 E : Entity_Id;
5791 Loc : constant Source_Ptr := Sloc (Expr);
5793 function Make_Level_Literal (Level : Uint) return Node_Id;
5794 -- Construct an integer literal representing an accessibility level
5795 -- with its type set to Natural.
5797 ------------------------
5798 -- Make_Level_Literal --
5799 ------------------------
5801 function Make_Level_Literal (Level : Uint) return Node_Id is
5802 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5803 begin
5804 Set_Etype (Result, Standard_Natural);
5805 return Result;
5806 end Make_Level_Literal;
5808 -- Start of processing for Dynamic_Accessibility_Level
5810 begin
5811 if Is_Entity_Name (Expr) then
5812 E := Entity (Expr);
5814 if Present (Renamed_Object (E)) then
5815 return Dynamic_Accessibility_Level (Renamed_Object (E));
5816 end if;
5818 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5819 if Present (Extra_Accessibility (E)) then
5820 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5821 end if;
5822 end if;
5823 end if;
5825 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5827 case Nkind (Expr) is
5829 -- For access discriminant, the level of the enclosing object
5831 when N_Selected_Component =>
5832 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5833 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5834 E_Anonymous_Access_Type
5835 then
5836 return Make_Level_Literal (Object_Access_Level (Expr));
5837 end if;
5839 when N_Attribute_Reference =>
5840 case Get_Attribute_Id (Attribute_Name (Expr)) is
5842 -- For X'Access, the level of the prefix X
5844 when Attribute_Access =>
5845 return Make_Level_Literal
5846 (Object_Access_Level (Prefix (Expr)));
5848 -- Treat the unchecked attributes as library-level
5850 when Attribute_Unchecked_Access
5851 | Attribute_Unrestricted_Access
5853 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5855 -- No other access-valued attributes
5857 when others =>
5858 raise Program_Error;
5859 end case;
5861 when N_Allocator =>
5863 -- Unimplemented: depends on context. As an actual parameter where
5864 -- formal type is anonymous, use
5865 -- Scope_Depth (Current_Scope) + 1.
5866 -- For other cases, see 3.10.2(14/3) and following. ???
5868 null;
5870 when N_Type_Conversion =>
5871 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5873 -- Handle type conversions introduced for a rename of an
5874 -- Ada 2012 stand-alone object of an anonymous access type.
5876 return Dynamic_Accessibility_Level (Expression (Expr));
5877 end if;
5879 when others =>
5880 null;
5881 end case;
5883 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5884 end Dynamic_Accessibility_Level;
5886 -----------------------------------
5887 -- Effective_Extra_Accessibility --
5888 -----------------------------------
5890 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5891 begin
5892 if Present (Renamed_Object (Id))
5893 and then Is_Entity_Name (Renamed_Object (Id))
5894 then
5895 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5896 else
5897 return Extra_Accessibility (Id);
5898 end if;
5899 end Effective_Extra_Accessibility;
5901 -----------------------------
5902 -- Effective_Reads_Enabled --
5903 -----------------------------
5905 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5906 begin
5907 return Has_Enabled_Property (Id, Name_Effective_Reads);
5908 end Effective_Reads_Enabled;
5910 ------------------------------
5911 -- Effective_Writes_Enabled --
5912 ------------------------------
5914 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5915 begin
5916 return Has_Enabled_Property (Id, Name_Effective_Writes);
5917 end Effective_Writes_Enabled;
5919 ------------------------------
5920 -- Enclosing_Comp_Unit_Node --
5921 ------------------------------
5923 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5924 Current_Node : Node_Id;
5926 begin
5927 Current_Node := N;
5928 while Present (Current_Node)
5929 and then Nkind (Current_Node) /= N_Compilation_Unit
5930 loop
5931 Current_Node := Parent (Current_Node);
5932 end loop;
5934 if Nkind (Current_Node) /= N_Compilation_Unit then
5935 return Empty;
5936 else
5937 return Current_Node;
5938 end if;
5939 end Enclosing_Comp_Unit_Node;
5941 --------------------------
5942 -- Enclosing_CPP_Parent --
5943 --------------------------
5945 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5946 Parent_Typ : Entity_Id := Typ;
5948 begin
5949 while not Is_CPP_Class (Parent_Typ)
5950 and then Etype (Parent_Typ) /= Parent_Typ
5951 loop
5952 Parent_Typ := Etype (Parent_Typ);
5954 if Is_Private_Type (Parent_Typ) then
5955 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5956 end if;
5957 end loop;
5959 pragma Assert (Is_CPP_Class (Parent_Typ));
5960 return Parent_Typ;
5961 end Enclosing_CPP_Parent;
5963 ---------------------------
5964 -- Enclosing_Declaration --
5965 ---------------------------
5967 function Enclosing_Declaration (N : Node_Id) return Node_Id is
5968 Decl : Node_Id := N;
5970 begin
5971 while Present (Decl)
5972 and then not (Nkind (Decl) in N_Declaration
5973 or else
5974 Nkind (Decl) in N_Later_Decl_Item)
5975 loop
5976 Decl := Parent (Decl);
5977 end loop;
5979 return Decl;
5980 end Enclosing_Declaration;
5982 ----------------------------
5983 -- Enclosing_Generic_Body --
5984 ----------------------------
5986 function Enclosing_Generic_Body
5987 (N : Node_Id) return Node_Id
5989 P : Node_Id;
5990 Decl : Node_Id;
5991 Spec : Node_Id;
5993 begin
5994 P := Parent (N);
5995 while Present (P) loop
5996 if Nkind (P) = N_Package_Body
5997 or else Nkind (P) = N_Subprogram_Body
5998 then
5999 Spec := Corresponding_Spec (P);
6001 if Present (Spec) then
6002 Decl := Unit_Declaration_Node (Spec);
6004 if Nkind (Decl) = N_Generic_Package_Declaration
6005 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6006 then
6007 return P;
6008 end if;
6009 end if;
6010 end if;
6012 P := Parent (P);
6013 end loop;
6015 return Empty;
6016 end Enclosing_Generic_Body;
6018 ----------------------------
6019 -- Enclosing_Generic_Unit --
6020 ----------------------------
6022 function Enclosing_Generic_Unit
6023 (N : Node_Id) return Node_Id
6025 P : Node_Id;
6026 Decl : Node_Id;
6027 Spec : Node_Id;
6029 begin
6030 P := Parent (N);
6031 while Present (P) loop
6032 if Nkind (P) = N_Generic_Package_Declaration
6033 or else Nkind (P) = N_Generic_Subprogram_Declaration
6034 then
6035 return P;
6037 elsif Nkind (P) = N_Package_Body
6038 or else Nkind (P) = N_Subprogram_Body
6039 then
6040 Spec := Corresponding_Spec (P);
6042 if Present (Spec) then
6043 Decl := Unit_Declaration_Node (Spec);
6045 if Nkind (Decl) = N_Generic_Package_Declaration
6046 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
6047 then
6048 return Decl;
6049 end if;
6050 end if;
6051 end if;
6053 P := Parent (P);
6054 end loop;
6056 return Empty;
6057 end Enclosing_Generic_Unit;
6059 -------------------------------
6060 -- Enclosing_Lib_Unit_Entity --
6061 -------------------------------
6063 function Enclosing_Lib_Unit_Entity
6064 (E : Entity_Id := Current_Scope) return Entity_Id
6066 Unit_Entity : Entity_Id;
6068 begin
6069 -- Look for enclosing library unit entity by following scope links.
6070 -- Equivalent to, but faster than indexing through the scope stack.
6072 Unit_Entity := E;
6073 while (Present (Scope (Unit_Entity))
6074 and then Scope (Unit_Entity) /= Standard_Standard)
6075 and not Is_Child_Unit (Unit_Entity)
6076 loop
6077 Unit_Entity := Scope (Unit_Entity);
6078 end loop;
6080 return Unit_Entity;
6081 end Enclosing_Lib_Unit_Entity;
6083 -----------------------------
6084 -- Enclosing_Lib_Unit_Node --
6085 -----------------------------
6087 function Enclosing_Lib_Unit_Node (N : Node_Id) return Node_Id is
6088 Encl_Unit : Node_Id;
6090 begin
6091 Encl_Unit := Enclosing_Comp_Unit_Node (N);
6092 while Present (Encl_Unit)
6093 and then Nkind (Unit (Encl_Unit)) = N_Subunit
6094 loop
6095 Encl_Unit := Library_Unit (Encl_Unit);
6096 end loop;
6098 pragma Assert (Nkind (Encl_Unit) = N_Compilation_Unit);
6099 return Encl_Unit;
6100 end Enclosing_Lib_Unit_Node;
6102 -----------------------
6103 -- Enclosing_Package --
6104 -----------------------
6106 function Enclosing_Package (E : Entity_Id) return Entity_Id is
6107 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6109 begin
6110 if Dynamic_Scope = Standard_Standard then
6111 return Standard_Standard;
6113 elsif Dynamic_Scope = Empty then
6114 return Empty;
6116 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
6117 E_Generic_Package)
6118 then
6119 return Dynamic_Scope;
6121 else
6122 return Enclosing_Package (Dynamic_Scope);
6123 end if;
6124 end Enclosing_Package;
6126 -------------------------------------
6127 -- Enclosing_Package_Or_Subprogram --
6128 -------------------------------------
6130 function Enclosing_Package_Or_Subprogram (E : Entity_Id) return Entity_Id is
6131 S : Entity_Id;
6133 begin
6134 S := Scope (E);
6135 while Present (S) loop
6136 if Is_Package_Or_Generic_Package (S)
6137 or else Ekind (S) = E_Package_Body
6138 then
6139 return S;
6141 elsif Is_Subprogram_Or_Generic_Subprogram (S)
6142 or else Ekind (S) = E_Subprogram_Body
6143 then
6144 return S;
6146 else
6147 S := Scope (S);
6148 end if;
6149 end loop;
6151 return Empty;
6152 end Enclosing_Package_Or_Subprogram;
6154 --------------------------
6155 -- Enclosing_Subprogram --
6156 --------------------------
6158 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
6159 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
6161 begin
6162 if Dynamic_Scope = Standard_Standard then
6163 return Empty;
6165 elsif Dynamic_Scope = Empty then
6166 return Empty;
6168 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
6169 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
6171 elsif Ekind (Dynamic_Scope) = E_Block
6172 or else Ekind (Dynamic_Scope) = E_Return_Statement
6173 then
6174 return Enclosing_Subprogram (Dynamic_Scope);
6176 elsif Ekind (Dynamic_Scope) = E_Task_Type then
6177 return Get_Task_Body_Procedure (Dynamic_Scope);
6179 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
6180 and then Present (Full_View (Dynamic_Scope))
6181 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
6182 then
6183 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
6185 -- No body is generated if the protected operation is eliminated
6187 elsif Convention (Dynamic_Scope) = Convention_Protected
6188 and then not Is_Eliminated (Dynamic_Scope)
6189 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
6190 then
6191 return Protected_Body_Subprogram (Dynamic_Scope);
6193 else
6194 return Dynamic_Scope;
6195 end if;
6196 end Enclosing_Subprogram;
6198 ------------------------
6199 -- Ensure_Freeze_Node --
6200 ------------------------
6202 procedure Ensure_Freeze_Node (E : Entity_Id) is
6203 FN : Node_Id;
6204 begin
6205 if No (Freeze_Node (E)) then
6206 FN := Make_Freeze_Entity (Sloc (E));
6207 Set_Has_Delayed_Freeze (E);
6208 Set_Freeze_Node (E, FN);
6209 Set_Access_Types_To_Process (FN, No_Elist);
6210 Set_TSS_Elist (FN, No_Elist);
6211 Set_Entity (FN, E);
6212 end if;
6213 end Ensure_Freeze_Node;
6215 ----------------
6216 -- Enter_Name --
6217 ----------------
6219 procedure Enter_Name (Def_Id : Entity_Id) is
6220 C : constant Entity_Id := Current_Entity (Def_Id);
6221 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
6222 S : constant Entity_Id := Current_Scope;
6224 begin
6225 Generate_Definition (Def_Id);
6227 -- Add new name to current scope declarations. Check for duplicate
6228 -- declaration, which may or may not be a genuine error.
6230 if Present (E) then
6232 -- Case of previous entity entered because of a missing declaration
6233 -- or else a bad subtype indication. Best is to use the new entity,
6234 -- and make the previous one invisible.
6236 if Etype (E) = Any_Type then
6237 Set_Is_Immediately_Visible (E, False);
6239 -- Case of renaming declaration constructed for package instances.
6240 -- if there is an explicit declaration with the same identifier,
6241 -- the renaming is not immediately visible any longer, but remains
6242 -- visible through selected component notation.
6244 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
6245 and then not Comes_From_Source (E)
6246 then
6247 Set_Is_Immediately_Visible (E, False);
6249 -- The new entity may be the package renaming, which has the same
6250 -- same name as a generic formal which has been seen already.
6252 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
6253 and then not Comes_From_Source (Def_Id)
6254 then
6255 Set_Is_Immediately_Visible (E, False);
6257 -- For a fat pointer corresponding to a remote access to subprogram,
6258 -- we use the same identifier as the RAS type, so that the proper
6259 -- name appears in the stub. This type is only retrieved through
6260 -- the RAS type and never by visibility, and is not added to the
6261 -- visibility list (see below).
6263 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
6264 and then Ekind (Def_Id) = E_Record_Type
6265 and then Present (Corresponding_Remote_Type (Def_Id))
6266 then
6267 null;
6269 -- Case of an implicit operation or derived literal. The new entity
6270 -- hides the implicit one, which is removed from all visibility,
6271 -- i.e. the entity list of its scope, and homonym chain of its name.
6273 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
6274 or else Is_Internal (E)
6275 then
6276 declare
6277 Decl : constant Node_Id := Parent (E);
6278 Prev : Entity_Id;
6279 Prev_Vis : Entity_Id;
6281 begin
6282 -- If E is an implicit declaration, it cannot be the first
6283 -- entity in the scope.
6285 Prev := First_Entity (Current_Scope);
6286 while Present (Prev) and then Next_Entity (Prev) /= E loop
6287 Next_Entity (Prev);
6288 end loop;
6290 if No (Prev) then
6292 -- If E is not on the entity chain of the current scope,
6293 -- it is an implicit declaration in the generic formal
6294 -- part of a generic subprogram. When analyzing the body,
6295 -- the generic formals are visible but not on the entity
6296 -- chain of the subprogram. The new entity will become
6297 -- the visible one in the body.
6299 pragma Assert
6300 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
6301 null;
6303 else
6304 Set_Next_Entity (Prev, Next_Entity (E));
6306 if No (Next_Entity (Prev)) then
6307 Set_Last_Entity (Current_Scope, Prev);
6308 end if;
6310 if E = Current_Entity (E) then
6311 Prev_Vis := Empty;
6313 else
6314 Prev_Vis := Current_Entity (E);
6315 while Homonym (Prev_Vis) /= E loop
6316 Prev_Vis := Homonym (Prev_Vis);
6317 end loop;
6318 end if;
6320 if Present (Prev_Vis) then
6322 -- Skip E in the visibility chain
6324 Set_Homonym (Prev_Vis, Homonym (E));
6326 else
6327 Set_Name_Entity_Id (Chars (E), Homonym (E));
6328 end if;
6329 end if;
6330 end;
6332 -- This section of code could use a comment ???
6334 elsif Present (Etype (E))
6335 and then Is_Concurrent_Type (Etype (E))
6336 and then E = Def_Id
6337 then
6338 return;
6340 -- If the homograph is a protected component renaming, it should not
6341 -- be hiding the current entity. Such renamings are treated as weak
6342 -- declarations.
6344 elsif Is_Prival (E) then
6345 Set_Is_Immediately_Visible (E, False);
6347 -- In this case the current entity is a protected component renaming.
6348 -- Perform minimal decoration by setting the scope and return since
6349 -- the prival should not be hiding other visible entities.
6351 elsif Is_Prival (Def_Id) then
6352 Set_Scope (Def_Id, Current_Scope);
6353 return;
6355 -- Analogous to privals, the discriminal generated for an entry index
6356 -- parameter acts as a weak declaration. Perform minimal decoration
6357 -- to avoid bogus errors.
6359 elsif Is_Discriminal (Def_Id)
6360 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
6361 then
6362 Set_Scope (Def_Id, Current_Scope);
6363 return;
6365 -- In the body or private part of an instance, a type extension may
6366 -- introduce a component with the same name as that of an actual. The
6367 -- legality rule is not enforced, but the semantics of the full type
6368 -- with two components of same name are not clear at this point???
6370 elsif In_Instance_Not_Visible then
6371 null;
6373 -- When compiling a package body, some child units may have become
6374 -- visible. They cannot conflict with local entities that hide them.
6376 elsif Is_Child_Unit (E)
6377 and then In_Open_Scopes (Scope (E))
6378 and then not Is_Immediately_Visible (E)
6379 then
6380 null;
6382 -- Conversely, with front-end inlining we may compile the parent body
6383 -- first, and a child unit subsequently. The context is now the
6384 -- parent spec, and body entities are not visible.
6386 elsif Is_Child_Unit (Def_Id)
6387 and then Is_Package_Body_Entity (E)
6388 and then not In_Package_Body (Current_Scope)
6389 then
6390 null;
6392 -- Case of genuine duplicate declaration
6394 else
6395 Error_Msg_Sloc := Sloc (E);
6397 -- If the previous declaration is an incomplete type declaration
6398 -- this may be an attempt to complete it with a private type. The
6399 -- following avoids confusing cascaded errors.
6401 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
6402 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
6403 then
6404 Error_Msg_N
6405 ("incomplete type cannot be completed with a private " &
6406 "declaration", Parent (Def_Id));
6407 Set_Is_Immediately_Visible (E, False);
6408 Set_Full_View (E, Def_Id);
6410 -- An inherited component of a record conflicts with a new
6411 -- discriminant. The discriminant is inserted first in the scope,
6412 -- but the error should be posted on it, not on the component.
6414 elsif Ekind (E) = E_Discriminant
6415 and then Present (Scope (Def_Id))
6416 and then Scope (Def_Id) /= Current_Scope
6417 then
6418 Error_Msg_Sloc := Sloc (Def_Id);
6419 Error_Msg_N ("& conflicts with declaration#", E);
6420 return;
6422 -- If the name of the unit appears in its own context clause, a
6423 -- dummy package with the name has already been created, and the
6424 -- error emitted. Try to continue quietly.
6426 elsif Error_Posted (E)
6427 and then Sloc (E) = No_Location
6428 and then Nkind (Parent (E)) = N_Package_Specification
6429 and then Current_Scope = Standard_Standard
6430 then
6431 Set_Scope (Def_Id, Current_Scope);
6432 return;
6434 else
6435 Error_Msg_N ("& conflicts with declaration#", Def_Id);
6437 -- Avoid cascaded messages with duplicate components in
6438 -- derived types.
6440 if Ekind_In (E, E_Component, E_Discriminant) then
6441 return;
6442 end if;
6443 end if;
6445 if Nkind (Parent (Parent (Def_Id))) =
6446 N_Generic_Subprogram_Declaration
6447 and then Def_Id =
6448 Defining_Entity (Specification (Parent (Parent (Def_Id))))
6449 then
6450 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
6451 end if;
6453 -- If entity is in standard, then we are in trouble, because it
6454 -- means that we have a library package with a duplicated name.
6455 -- That's hard to recover from, so abort.
6457 if S = Standard_Standard then
6458 raise Unrecoverable_Error;
6460 -- Otherwise we continue with the declaration. Having two
6461 -- identical declarations should not cause us too much trouble.
6463 else
6464 null;
6465 end if;
6466 end if;
6467 end if;
6469 -- If we fall through, declaration is OK, at least OK enough to continue
6471 -- If Def_Id is a discriminant or a record component we are in the midst
6472 -- of inheriting components in a derived record definition. Preserve
6473 -- their Ekind and Etype.
6475 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
6476 null;
6478 -- If a type is already set, leave it alone (happens when a type
6479 -- declaration is reanalyzed following a call to the optimizer).
6481 elsif Present (Etype (Def_Id)) then
6482 null;
6484 -- Otherwise, the kind E_Void insures that premature uses of the entity
6485 -- will be detected. Any_Type insures that no cascaded errors will occur
6487 else
6488 Set_Ekind (Def_Id, E_Void);
6489 Set_Etype (Def_Id, Any_Type);
6490 end if;
6492 -- Inherited discriminants and components in derived record types are
6493 -- immediately visible. Itypes are not.
6495 -- Unless the Itype is for a record type with a corresponding remote
6496 -- type (what is that about, it was not commented ???)
6498 if Ekind_In (Def_Id, E_Discriminant, E_Component)
6499 or else
6500 ((not Is_Record_Type (Def_Id)
6501 or else No (Corresponding_Remote_Type (Def_Id)))
6502 and then not Is_Itype (Def_Id))
6503 then
6504 Set_Is_Immediately_Visible (Def_Id);
6505 Set_Current_Entity (Def_Id);
6506 end if;
6508 Set_Homonym (Def_Id, C);
6509 Append_Entity (Def_Id, S);
6510 Set_Public_Status (Def_Id);
6512 -- Declaring a homonym is not allowed in SPARK ...
6514 if Present (C) and then Restriction_Check_Required (SPARK_05) then
6515 declare
6516 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
6517 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
6518 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
6520 begin
6521 -- ... unless the new declaration is in a subprogram, and the
6522 -- visible declaration is a variable declaration or a parameter
6523 -- specification outside that subprogram.
6525 if Present (Enclosing_Subp)
6526 and then Nkind_In (Parent (C), N_Object_Declaration,
6527 N_Parameter_Specification)
6528 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
6529 then
6530 null;
6532 -- ... or the new declaration is in a package, and the visible
6533 -- declaration occurs outside that package.
6535 elsif Present (Enclosing_Pack)
6536 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
6537 then
6538 null;
6540 -- ... or the new declaration is a component declaration in a
6541 -- record type definition.
6543 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
6544 null;
6546 -- Don't issue error for non-source entities
6548 elsif Comes_From_Source (Def_Id)
6549 and then Comes_From_Source (C)
6550 then
6551 Error_Msg_Sloc := Sloc (C);
6552 Check_SPARK_05_Restriction
6553 ("redeclaration of identifier &#", Def_Id);
6554 end if;
6555 end;
6556 end if;
6558 -- Warn if new entity hides an old one
6560 if Warn_On_Hiding and then Present (C)
6562 -- Don't warn for record components since they always have a well
6563 -- defined scope which does not confuse other uses. Note that in
6564 -- some cases, Ekind has not been set yet.
6566 and then Ekind (C) /= E_Component
6567 and then Ekind (C) /= E_Discriminant
6568 and then Nkind (Parent (C)) /= N_Component_Declaration
6569 and then Ekind (Def_Id) /= E_Component
6570 and then Ekind (Def_Id) /= E_Discriminant
6571 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
6573 -- Don't warn for one character variables. It is too common to use
6574 -- such variables as locals and will just cause too many false hits.
6576 and then Length_Of_Name (Chars (C)) /= 1
6578 -- Don't warn for non-source entities
6580 and then Comes_From_Source (C)
6581 and then Comes_From_Source (Def_Id)
6583 -- Don't warn unless entity in question is in extended main source
6585 and then In_Extended_Main_Source_Unit (Def_Id)
6587 -- Finally, the hidden entity must be either immediately visible or
6588 -- use visible (i.e. from a used package).
6590 and then
6591 (Is_Immediately_Visible (C)
6592 or else
6593 Is_Potentially_Use_Visible (C))
6594 then
6595 Error_Msg_Sloc := Sloc (C);
6596 Error_Msg_N ("declaration hides &#?h?", Def_Id);
6597 end if;
6598 end Enter_Name;
6600 ---------------
6601 -- Entity_Of --
6602 ---------------
6604 function Entity_Of (N : Node_Id) return Entity_Id is
6605 Id : Entity_Id;
6607 begin
6608 Id := Empty;
6610 if Is_Entity_Name (N) then
6611 Id := Entity (N);
6613 -- Follow a possible chain of renamings to reach the root renamed
6614 -- object.
6616 while Present (Id)
6617 and then Is_Object (Id)
6618 and then Present (Renamed_Object (Id))
6619 loop
6620 if Is_Entity_Name (Renamed_Object (Id)) then
6621 Id := Entity (Renamed_Object (Id));
6622 else
6623 Id := Empty;
6624 exit;
6625 end if;
6626 end loop;
6627 end if;
6629 return Id;
6630 end Entity_Of;
6632 --------------------------
6633 -- Explain_Limited_Type --
6634 --------------------------
6636 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
6637 C : Entity_Id;
6639 begin
6640 -- For array, component type must be limited
6642 if Is_Array_Type (T) then
6643 Error_Msg_Node_2 := T;
6644 Error_Msg_NE
6645 ("\component type& of type& is limited", N, Component_Type (T));
6646 Explain_Limited_Type (Component_Type (T), N);
6648 elsif Is_Record_Type (T) then
6650 -- No need for extra messages if explicit limited record
6652 if Is_Limited_Record (Base_Type (T)) then
6653 return;
6654 end if;
6656 -- Otherwise find a limited component. Check only components that
6657 -- come from source, or inherited components that appear in the
6658 -- source of the ancestor.
6660 C := First_Component (T);
6661 while Present (C) loop
6662 if Is_Limited_Type (Etype (C))
6663 and then
6664 (Comes_From_Source (C)
6665 or else
6666 (Present (Original_Record_Component (C))
6667 and then
6668 Comes_From_Source (Original_Record_Component (C))))
6669 then
6670 Error_Msg_Node_2 := T;
6671 Error_Msg_NE ("\component& of type& has limited type", N, C);
6672 Explain_Limited_Type (Etype (C), N);
6673 return;
6674 end if;
6676 Next_Component (C);
6677 end loop;
6679 -- The type may be declared explicitly limited, even if no component
6680 -- of it is limited, in which case we fall out of the loop.
6681 return;
6682 end if;
6683 end Explain_Limited_Type;
6685 ---------------------------------------
6686 -- Expression_Of_Expression_Function --
6687 ---------------------------------------
6689 function Expression_Of_Expression_Function
6690 (Subp : Entity_Id) return Node_Id
6692 Expr_Func : Node_Id;
6694 begin
6695 pragma Assert (Is_Expression_Function_Or_Completion (Subp));
6697 if Nkind (Original_Node (Subprogram_Spec (Subp))) =
6698 N_Expression_Function
6699 then
6700 Expr_Func := Original_Node (Subprogram_Spec (Subp));
6702 elsif Nkind (Original_Node (Subprogram_Body (Subp))) =
6703 N_Expression_Function
6704 then
6705 Expr_Func := Original_Node (Subprogram_Body (Subp));
6707 else
6708 pragma Assert (False);
6709 null;
6710 end if;
6712 return Original_Node (Expression (Expr_Func));
6713 end Expression_Of_Expression_Function;
6715 -------------------------------
6716 -- Extensions_Visible_Status --
6717 -------------------------------
6719 function Extensions_Visible_Status
6720 (Id : Entity_Id) return Extensions_Visible_Mode
6722 Arg : Node_Id;
6723 Decl : Node_Id;
6724 Expr : Node_Id;
6725 Prag : Node_Id;
6726 Subp : Entity_Id;
6728 begin
6729 -- When a formal parameter is subject to Extensions_Visible, the pragma
6730 -- is stored in the contract of related subprogram.
6732 if Is_Formal (Id) then
6733 Subp := Scope (Id);
6735 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
6736 Subp := Id;
6738 -- No other construct carries this pragma
6740 else
6741 return Extensions_Visible_None;
6742 end if;
6744 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
6746 -- In certain cases analysis may request the Extensions_Visible status
6747 -- of an expression function before the pragma has been analyzed yet.
6748 -- Inspect the declarative items after the expression function looking
6749 -- for the pragma (if any).
6751 if No (Prag) and then Is_Expression_Function (Subp) then
6752 Decl := Next (Unit_Declaration_Node (Subp));
6753 while Present (Decl) loop
6754 if Nkind (Decl) = N_Pragma
6755 and then Pragma_Name (Decl) = Name_Extensions_Visible
6756 then
6757 Prag := Decl;
6758 exit;
6760 -- A source construct ends the region where Extensions_Visible may
6761 -- appear, stop the traversal. An expanded expression function is
6762 -- no longer a source construct, but it must still be recognized.
6764 elsif Comes_From_Source (Decl)
6765 or else
6766 (Nkind_In (Decl, N_Subprogram_Body,
6767 N_Subprogram_Declaration)
6768 and then Is_Expression_Function (Defining_Entity (Decl)))
6769 then
6770 exit;
6771 end if;
6773 Next (Decl);
6774 end loop;
6775 end if;
6777 -- Extract the value from the Boolean expression (if any)
6779 if Present (Prag) then
6780 Arg := First (Pragma_Argument_Associations (Prag));
6782 if Present (Arg) then
6783 Expr := Get_Pragma_Arg (Arg);
6785 -- When the associated subprogram is an expression function, the
6786 -- argument of the pragma may not have been analyzed.
6788 if not Analyzed (Expr) then
6789 Preanalyze_And_Resolve (Expr, Standard_Boolean);
6790 end if;
6792 -- Guard against cascading errors when the argument of pragma
6793 -- Extensions_Visible is not a valid static Boolean expression.
6795 if Error_Posted (Expr) then
6796 return Extensions_Visible_None;
6798 elsif Is_True (Expr_Value (Expr)) then
6799 return Extensions_Visible_True;
6801 else
6802 return Extensions_Visible_False;
6803 end if;
6805 -- Otherwise the aspect or pragma defaults to True
6807 else
6808 return Extensions_Visible_True;
6809 end if;
6811 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6812 -- directly specified. In SPARK code, its value defaults to "False".
6814 elsif SPARK_Mode = On then
6815 return Extensions_Visible_False;
6817 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6818 -- "True".
6820 else
6821 return Extensions_Visible_True;
6822 end if;
6823 end Extensions_Visible_Status;
6825 -----------------
6826 -- Find_Actual --
6827 -----------------
6829 procedure Find_Actual
6830 (N : Node_Id;
6831 Formal : out Entity_Id;
6832 Call : out Node_Id)
6834 Context : constant Node_Id := Parent (N);
6835 Actual : Node_Id;
6836 Call_Nam : Node_Id;
6838 begin
6839 if Nkind_In (Context, N_Indexed_Component, N_Selected_Component)
6840 and then N = Prefix (Context)
6841 then
6842 Find_Actual (Context, Formal, Call);
6843 return;
6845 elsif Nkind (Context) = N_Parameter_Association
6846 and then N = Explicit_Actual_Parameter (Context)
6847 then
6848 Call := Parent (Context);
6850 elsif Nkind_In (Context, N_Entry_Call_Statement,
6851 N_Function_Call,
6852 N_Procedure_Call_Statement)
6853 then
6854 Call := Context;
6856 else
6857 Formal := Empty;
6858 Call := Empty;
6859 return;
6860 end if;
6862 -- If we have a call to a subprogram look for the parameter. Note that
6863 -- we exclude overloaded calls, since we don't know enough to be sure
6864 -- of giving the right answer in this case.
6866 if Nkind_In (Call, N_Entry_Call_Statement,
6867 N_Function_Call,
6868 N_Procedure_Call_Statement)
6869 then
6870 Call_Nam := Name (Call);
6872 -- A call to a protected or task entry appears as a selected
6873 -- component rather than an expanded name.
6875 if Nkind (Call_Nam) = N_Selected_Component then
6876 Call_Nam := Selector_Name (Call_Nam);
6877 end if;
6879 if Is_Entity_Name (Call_Nam)
6880 and then Present (Entity (Call_Nam))
6881 and then Is_Overloadable (Entity (Call_Nam))
6882 and then not Is_Overloaded (Call_Nam)
6883 then
6884 -- If node is name in call it is not an actual
6886 if N = Call_Nam then
6887 Formal := Empty;
6888 Call := Empty;
6889 return;
6890 end if;
6892 -- Fall here if we are definitely a parameter
6894 Actual := First_Actual (Call);
6895 Formal := First_Formal (Entity (Call_Nam));
6896 while Present (Formal) and then Present (Actual) loop
6897 if Actual = N then
6898 return;
6900 -- An actual that is the prefix in a prefixed call may have
6901 -- been rewritten in the call, after the deferred reference
6902 -- was collected. Check if sloc and kinds and names match.
6904 elsif Sloc (Actual) = Sloc (N)
6905 and then Nkind (Actual) = N_Identifier
6906 and then Nkind (Actual) = Nkind (N)
6907 and then Chars (Actual) = Chars (N)
6908 then
6909 return;
6911 else
6912 Actual := Next_Actual (Actual);
6913 Formal := Next_Formal (Formal);
6914 end if;
6915 end loop;
6916 end if;
6917 end if;
6919 -- Fall through here if we did not find matching actual
6921 Formal := Empty;
6922 Call := Empty;
6923 end Find_Actual;
6925 ---------------------------
6926 -- Find_Body_Discriminal --
6927 ---------------------------
6929 function Find_Body_Discriminal
6930 (Spec_Discriminant : Entity_Id) return Entity_Id
6932 Tsk : Entity_Id;
6933 Disc : Entity_Id;
6935 begin
6936 -- If expansion is suppressed, then the scope can be the concurrent type
6937 -- itself rather than a corresponding concurrent record type.
6939 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6940 Tsk := Scope (Spec_Discriminant);
6942 else
6943 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6945 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6946 end if;
6948 -- Find discriminant of original concurrent type, and use its current
6949 -- discriminal, which is the renaming within the task/protected body.
6951 Disc := First_Discriminant (Tsk);
6952 while Present (Disc) loop
6953 if Chars (Disc) = Chars (Spec_Discriminant) then
6954 return Discriminal (Disc);
6955 end if;
6957 Next_Discriminant (Disc);
6958 end loop;
6960 -- That loop should always succeed in finding a matching entry and
6961 -- returning. Fatal error if not.
6963 raise Program_Error;
6964 end Find_Body_Discriminal;
6966 -------------------------------------
6967 -- Find_Corresponding_Discriminant --
6968 -------------------------------------
6970 function Find_Corresponding_Discriminant
6971 (Id : Node_Id;
6972 Typ : Entity_Id) return Entity_Id
6974 Par_Disc : Entity_Id;
6975 Old_Disc : Entity_Id;
6976 New_Disc : Entity_Id;
6978 begin
6979 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6981 -- The original type may currently be private, and the discriminant
6982 -- only appear on its full view.
6984 if Is_Private_Type (Scope (Par_Disc))
6985 and then not Has_Discriminants (Scope (Par_Disc))
6986 and then Present (Full_View (Scope (Par_Disc)))
6987 then
6988 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6989 else
6990 Old_Disc := First_Discriminant (Scope (Par_Disc));
6991 end if;
6993 if Is_Class_Wide_Type (Typ) then
6994 New_Disc := First_Discriminant (Root_Type (Typ));
6995 else
6996 New_Disc := First_Discriminant (Typ);
6997 end if;
6999 while Present (Old_Disc) and then Present (New_Disc) loop
7000 if Old_Disc = Par_Disc then
7001 return New_Disc;
7002 end if;
7004 Next_Discriminant (Old_Disc);
7005 Next_Discriminant (New_Disc);
7006 end loop;
7008 -- Should always find it
7010 raise Program_Error;
7011 end Find_Corresponding_Discriminant;
7013 ----------------------------------
7014 -- Find_Enclosing_Iterator_Loop --
7015 ----------------------------------
7017 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
7018 Constr : Node_Id;
7019 S : Entity_Id;
7021 begin
7022 -- Traverse the scope chain looking for an iterator loop. Such loops are
7023 -- usually transformed into blocks, hence the use of Original_Node.
7025 S := Id;
7026 while Present (S) and then S /= Standard_Standard loop
7027 if Ekind (S) = E_Loop
7028 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
7029 then
7030 Constr := Original_Node (Label_Construct (Parent (S)));
7032 if Nkind (Constr) = N_Loop_Statement
7033 and then Present (Iteration_Scheme (Constr))
7034 and then Nkind (Iterator_Specification
7035 (Iteration_Scheme (Constr))) =
7036 N_Iterator_Specification
7037 then
7038 return S;
7039 end if;
7040 end if;
7042 S := Scope (S);
7043 end loop;
7045 return Empty;
7046 end Find_Enclosing_Iterator_Loop;
7048 ------------------------------------
7049 -- Find_Loop_In_Conditional_Block --
7050 ------------------------------------
7052 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
7053 Stmt : Node_Id;
7055 begin
7056 Stmt := N;
7058 if Nkind (Stmt) = N_If_Statement then
7059 Stmt := First (Then_Statements (Stmt));
7060 end if;
7062 pragma Assert (Nkind (Stmt) = N_Block_Statement);
7064 -- Inspect the statements of the conditional block. In general the loop
7065 -- should be the first statement in the statement sequence of the block,
7066 -- but the finalization machinery may have introduced extra object
7067 -- declarations.
7069 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
7070 while Present (Stmt) loop
7071 if Nkind (Stmt) = N_Loop_Statement then
7072 return Stmt;
7073 end if;
7075 Next (Stmt);
7076 end loop;
7078 -- The expansion of attribute 'Loop_Entry produced a malformed block
7080 raise Program_Error;
7081 end Find_Loop_In_Conditional_Block;
7083 --------------------------
7084 -- Find_Overlaid_Entity --
7085 --------------------------
7087 procedure Find_Overlaid_Entity
7088 (N : Node_Id;
7089 Ent : out Entity_Id;
7090 Off : out Boolean)
7092 Expr : Node_Id;
7094 begin
7095 -- We are looking for one of the two following forms:
7097 -- for X'Address use Y'Address
7099 -- or
7101 -- Const : constant Address := expr;
7102 -- ...
7103 -- for X'Address use Const;
7105 -- In the second case, the expr is either Y'Address, or recursively a
7106 -- constant that eventually references Y'Address.
7108 Ent := Empty;
7109 Off := False;
7111 if Nkind (N) = N_Attribute_Definition_Clause
7112 and then Chars (N) = Name_Address
7113 then
7114 Expr := Expression (N);
7116 -- This loop checks the form of the expression for Y'Address,
7117 -- using recursion to deal with intermediate constants.
7119 loop
7120 -- Check for Y'Address
7122 if Nkind (Expr) = N_Attribute_Reference
7123 and then Attribute_Name (Expr) = Name_Address
7124 then
7125 Expr := Prefix (Expr);
7126 exit;
7128 -- Check for Const where Const is a constant entity
7130 elsif Is_Entity_Name (Expr)
7131 and then Ekind (Entity (Expr)) = E_Constant
7132 then
7133 Expr := Constant_Value (Entity (Expr));
7135 -- Anything else does not need checking
7137 else
7138 return;
7139 end if;
7140 end loop;
7142 -- This loop checks the form of the prefix for an entity, using
7143 -- recursion to deal with intermediate components.
7145 loop
7146 -- Check for Y where Y is an entity
7148 if Is_Entity_Name (Expr) then
7149 Ent := Entity (Expr);
7150 return;
7152 -- Check for components
7154 elsif
7155 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
7156 then
7157 Expr := Prefix (Expr);
7158 Off := True;
7160 -- Anything else does not need checking
7162 else
7163 return;
7164 end if;
7165 end loop;
7166 end if;
7167 end Find_Overlaid_Entity;
7169 -------------------------
7170 -- Find_Parameter_Type --
7171 -------------------------
7173 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
7174 begin
7175 if Nkind (Param) /= N_Parameter_Specification then
7176 return Empty;
7178 -- For an access parameter, obtain the type from the formal entity
7179 -- itself, because access to subprogram nodes do not carry a type.
7180 -- Shouldn't we always use the formal entity ???
7182 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
7183 return Etype (Defining_Identifier (Param));
7185 else
7186 return Etype (Parameter_Type (Param));
7187 end if;
7188 end Find_Parameter_Type;
7190 -----------------------------------
7191 -- Find_Placement_In_State_Space --
7192 -----------------------------------
7194 procedure Find_Placement_In_State_Space
7195 (Item_Id : Entity_Id;
7196 Placement : out State_Space_Kind;
7197 Pack_Id : out Entity_Id)
7199 Context : Entity_Id;
7201 begin
7202 -- Assume that the item does not appear in the state space of a package
7204 Placement := Not_In_Package;
7205 Pack_Id := Empty;
7207 -- Climb the scope stack and examine the enclosing context
7209 Context := Scope (Item_Id);
7210 while Present (Context) and then Context /= Standard_Standard loop
7211 if Ekind (Context) = E_Package then
7212 Pack_Id := Context;
7214 -- A package body is a cut off point for the traversal as the item
7215 -- cannot be visible to the outside from this point on. Note that
7216 -- this test must be done first as a body is also classified as a
7217 -- private part.
7219 if In_Package_Body (Context) then
7220 Placement := Body_State_Space;
7221 return;
7223 -- The private part of a package is a cut off point for the
7224 -- traversal as the item cannot be visible to the outside from
7225 -- this point on.
7227 elsif In_Private_Part (Context) then
7228 Placement := Private_State_Space;
7229 return;
7231 -- When the item appears in the visible state space of a package,
7232 -- continue to climb the scope stack as this may not be the final
7233 -- state space.
7235 else
7236 Placement := Visible_State_Space;
7238 -- The visible state space of a child unit acts as the proper
7239 -- placement of an item.
7241 if Is_Child_Unit (Context) then
7242 return;
7243 end if;
7244 end if;
7246 -- The item or its enclosing package appear in a construct that has
7247 -- no state space.
7249 else
7250 Placement := Not_In_Package;
7251 return;
7252 end if;
7254 Context := Scope (Context);
7255 end loop;
7256 end Find_Placement_In_State_Space;
7258 ------------------------
7259 -- Find_Specific_Type --
7260 ------------------------
7262 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
7263 Typ : Entity_Id := Root_Type (CW);
7265 begin
7266 if Ekind (Typ) = E_Incomplete_Type then
7267 if From_Limited_With (Typ) then
7268 Typ := Non_Limited_View (Typ);
7269 else
7270 Typ := Full_View (Typ);
7271 end if;
7272 end if;
7274 if Is_Private_Type (Typ)
7275 and then not Is_Tagged_Type (Typ)
7276 and then Present (Full_View (Typ))
7277 then
7278 return Full_View (Typ);
7279 else
7280 return Typ;
7281 end if;
7282 end Find_Specific_Type;
7284 -----------------------------
7285 -- Find_Static_Alternative --
7286 -----------------------------
7288 function Find_Static_Alternative (N : Node_Id) return Node_Id is
7289 Expr : constant Node_Id := Expression (N);
7290 Val : constant Uint := Expr_Value (Expr);
7291 Alt : Node_Id;
7292 Choice : Node_Id;
7294 begin
7295 Alt := First (Alternatives (N));
7297 Search : loop
7298 if Nkind (Alt) /= N_Pragma then
7299 Choice := First (Discrete_Choices (Alt));
7300 while Present (Choice) loop
7302 -- Others choice, always matches
7304 if Nkind (Choice) = N_Others_Choice then
7305 exit Search;
7307 -- Range, check if value is in the range
7309 elsif Nkind (Choice) = N_Range then
7310 exit Search when
7311 Val >= Expr_Value (Low_Bound (Choice))
7312 and then
7313 Val <= Expr_Value (High_Bound (Choice));
7315 -- Choice is a subtype name. Note that we know it must
7316 -- be a static subtype, since otherwise it would have
7317 -- been diagnosed as illegal.
7319 elsif Is_Entity_Name (Choice)
7320 and then Is_Type (Entity (Choice))
7321 then
7322 exit Search when Is_In_Range (Expr, Etype (Choice),
7323 Assume_Valid => False);
7325 -- Choice is a subtype indication
7327 elsif Nkind (Choice) = N_Subtype_Indication then
7328 declare
7329 C : constant Node_Id := Constraint (Choice);
7330 R : constant Node_Id := Range_Expression (C);
7332 begin
7333 exit Search when
7334 Val >= Expr_Value (Low_Bound (R))
7335 and then
7336 Val <= Expr_Value (High_Bound (R));
7337 end;
7339 -- Choice is a simple expression
7341 else
7342 exit Search when Val = Expr_Value (Choice);
7343 end if;
7345 Next (Choice);
7346 end loop;
7347 end if;
7349 Next (Alt);
7350 pragma Assert (Present (Alt));
7351 end loop Search;
7353 -- The above loop *must* terminate by finding a match, since we know the
7354 -- case statement is valid, and the value of the expression is known at
7355 -- compile time. When we fall out of the loop, Alt points to the
7356 -- alternative that we know will be selected at run time.
7358 return Alt;
7359 end Find_Static_Alternative;
7361 ------------------
7362 -- First_Actual --
7363 ------------------
7365 function First_Actual (Node : Node_Id) return Node_Id is
7366 N : Node_Id;
7368 begin
7369 if No (Parameter_Associations (Node)) then
7370 return Empty;
7371 end if;
7373 N := First (Parameter_Associations (Node));
7375 if Nkind (N) = N_Parameter_Association then
7376 return First_Named_Actual (Node);
7377 else
7378 return N;
7379 end if;
7380 end First_Actual;
7382 -------------
7383 -- Fix_Msg --
7384 -------------
7386 function Fix_Msg (Id : Entity_Id; Msg : String) return String is
7387 Is_Task : constant Boolean :=
7388 Ekind_In (Id, E_Task_Body, E_Task_Type)
7389 or else Is_Single_Task_Object (Id);
7390 Msg_Last : constant Natural := Msg'Last;
7391 Msg_Index : Natural;
7392 Res : String (Msg'Range) := (others => ' ');
7393 Res_Index : Natural;
7395 begin
7396 -- Copy all characters from the input message Msg to result Res with
7397 -- suitable replacements.
7399 Msg_Index := Msg'First;
7400 Res_Index := Res'First;
7401 while Msg_Index <= Msg_Last loop
7403 -- Replace "subprogram" with a different word
7405 if Msg_Index <= Msg_Last - 10
7406 and then Msg (Msg_Index .. Msg_Index + 9) = "subprogram"
7407 then
7408 if Ekind_In (Id, E_Entry, E_Entry_Family) then
7409 Res (Res_Index .. Res_Index + 4) := "entry";
7410 Res_Index := Res_Index + 5;
7412 elsif Is_Task then
7413 Res (Res_Index .. Res_Index + 8) := "task type";
7414 Res_Index := Res_Index + 9;
7416 else
7417 Res (Res_Index .. Res_Index + 9) := "subprogram";
7418 Res_Index := Res_Index + 10;
7419 end if;
7421 Msg_Index := Msg_Index + 10;
7423 -- Replace "protected" with a different word
7425 elsif Msg_Index <= Msg_Last - 9
7426 and then Msg (Msg_Index .. Msg_Index + 8) = "protected"
7427 and then Is_Task
7428 then
7429 Res (Res_Index .. Res_Index + 3) := "task";
7430 Res_Index := Res_Index + 4;
7431 Msg_Index := Msg_Index + 9;
7433 -- Otherwise copy the character
7435 else
7436 Res (Res_Index) := Msg (Msg_Index);
7437 Msg_Index := Msg_Index + 1;
7438 Res_Index := Res_Index + 1;
7439 end if;
7440 end loop;
7442 return Res (Res'First .. Res_Index - 1);
7443 end Fix_Msg;
7445 -----------------------
7446 -- Gather_Components --
7447 -----------------------
7449 procedure Gather_Components
7450 (Typ : Entity_Id;
7451 Comp_List : Node_Id;
7452 Governed_By : List_Id;
7453 Into : Elist_Id;
7454 Report_Errors : out Boolean)
7456 Assoc : Node_Id;
7457 Variant : Node_Id;
7458 Discrete_Choice : Node_Id;
7459 Comp_Item : Node_Id;
7461 Discrim : Entity_Id;
7462 Discrim_Name : Node_Id;
7463 Discrim_Value : Node_Id;
7465 begin
7466 Report_Errors := False;
7468 if No (Comp_List) or else Null_Present (Comp_List) then
7469 return;
7471 elsif Present (Component_Items (Comp_List)) then
7472 Comp_Item := First (Component_Items (Comp_List));
7474 else
7475 Comp_Item := Empty;
7476 end if;
7478 while Present (Comp_Item) loop
7480 -- Skip the tag of a tagged record, the interface tags, as well
7481 -- as all items that are not user components (anonymous types,
7482 -- rep clauses, Parent field, controller field).
7484 if Nkind (Comp_Item) = N_Component_Declaration then
7485 declare
7486 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
7487 begin
7488 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
7489 Append_Elmt (Comp, Into);
7490 end if;
7491 end;
7492 end if;
7494 Next (Comp_Item);
7495 end loop;
7497 if No (Variant_Part (Comp_List)) then
7498 return;
7499 else
7500 Discrim_Name := Name (Variant_Part (Comp_List));
7501 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
7502 end if;
7504 -- Look for the discriminant that governs this variant part.
7505 -- The discriminant *must* be in the Governed_By List
7507 Assoc := First (Governed_By);
7508 Find_Constraint : loop
7509 Discrim := First (Choices (Assoc));
7510 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
7511 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
7512 and then
7513 Chars (Corresponding_Discriminant (Entity (Discrim))) =
7514 Chars (Discrim_Name))
7515 or else Chars (Original_Record_Component (Entity (Discrim)))
7516 = Chars (Discrim_Name);
7518 if No (Next (Assoc)) then
7519 if not Is_Constrained (Typ)
7520 and then Is_Derived_Type (Typ)
7521 and then Present (Stored_Constraint (Typ))
7522 then
7523 -- If the type is a tagged type with inherited discriminants,
7524 -- use the stored constraint on the parent in order to find
7525 -- the values of discriminants that are otherwise hidden by an
7526 -- explicit constraint. Renamed discriminants are handled in
7527 -- the code above.
7529 -- If several parent discriminants are renamed by a single
7530 -- discriminant of the derived type, the call to obtain the
7531 -- Corresponding_Discriminant field only retrieves the last
7532 -- of them. We recover the constraint on the others from the
7533 -- Stored_Constraint as well.
7535 declare
7536 D : Entity_Id;
7537 C : Elmt_Id;
7539 begin
7540 D := First_Discriminant (Etype (Typ));
7541 C := First_Elmt (Stored_Constraint (Typ));
7542 while Present (D) and then Present (C) loop
7543 if Chars (Discrim_Name) = Chars (D) then
7544 if Is_Entity_Name (Node (C))
7545 and then Entity (Node (C)) = Entity (Discrim)
7546 then
7547 -- D is renamed by Discrim, whose value is given in
7548 -- Assoc.
7550 null;
7552 else
7553 Assoc :=
7554 Make_Component_Association (Sloc (Typ),
7555 New_List
7556 (New_Occurrence_Of (D, Sloc (Typ))),
7557 Duplicate_Subexpr_No_Checks (Node (C)));
7558 end if;
7559 exit Find_Constraint;
7560 end if;
7562 Next_Discriminant (D);
7563 Next_Elmt (C);
7564 end loop;
7565 end;
7566 end if;
7567 end if;
7569 if No (Next (Assoc)) then
7570 Error_Msg_NE (" missing value for discriminant&",
7571 First (Governed_By), Discrim_Name);
7572 Report_Errors := True;
7573 return;
7574 end if;
7576 Next (Assoc);
7577 end loop Find_Constraint;
7579 Discrim_Value := Expression (Assoc);
7581 if not Is_OK_Static_Expression (Discrim_Value) then
7583 -- If the variant part is governed by a discriminant of the type
7584 -- this is an error. If the variant part and the discriminant are
7585 -- inherited from an ancestor this is legal (AI05-120) unless the
7586 -- components are being gathered for an aggregate, in which case
7587 -- the caller must check Report_Errors.
7589 if Scope (Original_Record_Component
7590 ((Entity (First (Choices (Assoc)))))) = Typ
7591 then
7592 Error_Msg_FE
7593 ("value for discriminant & must be static!",
7594 Discrim_Value, Discrim);
7595 Why_Not_Static (Discrim_Value);
7596 end if;
7598 Report_Errors := True;
7599 return;
7600 end if;
7602 Search_For_Discriminant_Value : declare
7603 Low : Node_Id;
7604 High : Node_Id;
7606 UI_High : Uint;
7607 UI_Low : Uint;
7608 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
7610 begin
7611 Find_Discrete_Value : while Present (Variant) loop
7612 Discrete_Choice := First (Discrete_Choices (Variant));
7613 while Present (Discrete_Choice) loop
7614 exit Find_Discrete_Value when
7615 Nkind (Discrete_Choice) = N_Others_Choice;
7617 Get_Index_Bounds (Discrete_Choice, Low, High);
7619 UI_Low := Expr_Value (Low);
7620 UI_High := Expr_Value (High);
7622 exit Find_Discrete_Value when
7623 UI_Low <= UI_Discrim_Value
7624 and then
7625 UI_High >= UI_Discrim_Value;
7627 Next (Discrete_Choice);
7628 end loop;
7630 Next_Non_Pragma (Variant);
7631 end loop Find_Discrete_Value;
7632 end Search_For_Discriminant_Value;
7634 -- The case statement must include a variant that corresponds to the
7635 -- value of the discriminant, unless the discriminant type has a
7636 -- static predicate. In that case the absence of an others_choice that
7637 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
7639 if No (Variant)
7640 and then not Has_Static_Predicate (Etype (Discrim_Name))
7641 then
7642 Error_Msg_NE
7643 ("value of discriminant & is out of range", Discrim_Value, Discrim);
7644 Report_Errors := True;
7645 return;
7646 end if;
7648 -- If we have found the corresponding choice, recursively add its
7649 -- components to the Into list. The nested components are part of
7650 -- the same record type.
7652 if Present (Variant) then
7653 Gather_Components
7654 (Typ, Component_List (Variant), Governed_By, Into, Report_Errors);
7655 end if;
7656 end Gather_Components;
7658 ------------------------
7659 -- Get_Actual_Subtype --
7660 ------------------------
7662 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
7663 Typ : constant Entity_Id := Etype (N);
7664 Utyp : Entity_Id := Underlying_Type (Typ);
7665 Decl : Node_Id;
7666 Atyp : Entity_Id;
7668 begin
7669 if No (Utyp) then
7670 Utyp := Typ;
7671 end if;
7673 -- If what we have is an identifier that references a subprogram
7674 -- formal, or a variable or constant object, then we get the actual
7675 -- subtype from the referenced entity if one has been built.
7677 if Nkind (N) = N_Identifier
7678 and then
7679 (Is_Formal (Entity (N))
7680 or else Ekind (Entity (N)) = E_Constant
7681 or else Ekind (Entity (N)) = E_Variable)
7682 and then Present (Actual_Subtype (Entity (N)))
7683 then
7684 return Actual_Subtype (Entity (N));
7686 -- Actual subtype of unchecked union is always itself. We never need
7687 -- the "real" actual subtype. If we did, we couldn't get it anyway
7688 -- because the discriminant is not available. The restrictions on
7689 -- Unchecked_Union are designed to make sure that this is OK.
7691 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
7692 return Typ;
7694 -- Here for the unconstrained case, we must find actual subtype
7695 -- No actual subtype is available, so we must build it on the fly.
7697 -- Checking the type, not the underlying type, for constrainedness
7698 -- seems to be necessary. Maybe all the tests should be on the type???
7700 elsif (not Is_Constrained (Typ))
7701 and then (Is_Array_Type (Utyp)
7702 or else (Is_Record_Type (Utyp)
7703 and then Has_Discriminants (Utyp)))
7704 and then not Has_Unknown_Discriminants (Utyp)
7705 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
7706 then
7707 -- Nothing to do if in spec expression (why not???)
7709 if In_Spec_Expression then
7710 return Typ;
7712 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
7714 -- If the type has no discriminants, there is no subtype to
7715 -- build, even if the underlying type is discriminated.
7717 return Typ;
7719 -- Else build the actual subtype
7721 else
7722 Decl := Build_Actual_Subtype (Typ, N);
7723 Atyp := Defining_Identifier (Decl);
7725 -- If Build_Actual_Subtype generated a new declaration then use it
7727 if Atyp /= Typ then
7729 -- The actual subtype is an Itype, so analyze the declaration,
7730 -- but do not attach it to the tree, to get the type defined.
7732 Set_Parent (Decl, N);
7733 Set_Is_Itype (Atyp);
7734 Analyze (Decl, Suppress => All_Checks);
7735 Set_Associated_Node_For_Itype (Atyp, N);
7736 Set_Has_Delayed_Freeze (Atyp, False);
7738 -- We need to freeze the actual subtype immediately. This is
7739 -- needed, because otherwise this Itype will not get frozen
7740 -- at all, and it is always safe to freeze on creation because
7741 -- any associated types must be frozen at this point.
7743 Freeze_Itype (Atyp, N);
7744 return Atyp;
7746 -- Otherwise we did not build a declaration, so return original
7748 else
7749 return Typ;
7750 end if;
7751 end if;
7753 -- For all remaining cases, the actual subtype is the same as
7754 -- the nominal type.
7756 else
7757 return Typ;
7758 end if;
7759 end Get_Actual_Subtype;
7761 -------------------------------------
7762 -- Get_Actual_Subtype_If_Available --
7763 -------------------------------------
7765 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
7766 Typ : constant Entity_Id := Etype (N);
7768 begin
7769 -- If what we have is an identifier that references a subprogram
7770 -- formal, or a variable or constant object, then we get the actual
7771 -- subtype from the referenced entity if one has been built.
7773 if Nkind (N) = N_Identifier
7774 and then
7775 (Is_Formal (Entity (N))
7776 or else Ekind (Entity (N)) = E_Constant
7777 or else Ekind (Entity (N)) = E_Variable)
7778 and then Present (Actual_Subtype (Entity (N)))
7779 then
7780 return Actual_Subtype (Entity (N));
7782 -- Otherwise the Etype of N is returned unchanged
7784 else
7785 return Typ;
7786 end if;
7787 end Get_Actual_Subtype_If_Available;
7789 ------------------------
7790 -- Get_Body_From_Stub --
7791 ------------------------
7793 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
7794 begin
7795 return Proper_Body (Unit (Library_Unit (N)));
7796 end Get_Body_From_Stub;
7798 ---------------------
7799 -- Get_Cursor_Type --
7800 ---------------------
7802 function Get_Cursor_Type
7803 (Aspect : Node_Id;
7804 Typ : Entity_Id) return Entity_Id
7806 Assoc : Node_Id;
7807 Func : Entity_Id;
7808 First_Op : Entity_Id;
7809 Cursor : Entity_Id;
7811 begin
7812 -- If error already detected, return
7814 if Error_Posted (Aspect) then
7815 return Any_Type;
7816 end if;
7818 -- The cursor type for an Iterable aspect is the return type of a
7819 -- non-overloaded First primitive operation. Locate association for
7820 -- First.
7822 Assoc := First (Component_Associations (Expression (Aspect)));
7823 First_Op := Any_Id;
7824 while Present (Assoc) loop
7825 if Chars (First (Choices (Assoc))) = Name_First then
7826 First_Op := Expression (Assoc);
7827 exit;
7828 end if;
7830 Next (Assoc);
7831 end loop;
7833 if First_Op = Any_Id then
7834 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
7835 return Any_Type;
7836 end if;
7838 Cursor := Any_Type;
7840 -- Locate function with desired name and profile in scope of type
7841 -- In the rare case where the type is an integer type, a base type
7842 -- is created for it, check that the base type of the first formal
7843 -- of First matches the base type of the domain.
7845 Func := First_Entity (Scope (Typ));
7846 while Present (Func) loop
7847 if Chars (Func) = Chars (First_Op)
7848 and then Ekind (Func) = E_Function
7849 and then Present (First_Formal (Func))
7850 and then Base_Type (Etype (First_Formal (Func))) = Base_Type (Typ)
7851 and then No (Next_Formal (First_Formal (Func)))
7852 then
7853 if Cursor /= Any_Type then
7854 Error_Msg_N
7855 ("Operation First for iterable type must be unique", Aspect);
7856 return Any_Type;
7857 else
7858 Cursor := Etype (Func);
7859 end if;
7860 end if;
7862 Next_Entity (Func);
7863 end loop;
7865 -- If not found, no way to resolve remaining primitives.
7867 if Cursor = Any_Type then
7868 Error_Msg_N
7869 ("No legal primitive operation First for Iterable type", Aspect);
7870 end if;
7872 return Cursor;
7873 end Get_Cursor_Type;
7875 function Get_Cursor_Type (Typ : Entity_Id) return Entity_Id is
7876 begin
7877 return Etype (Get_Iterable_Type_Primitive (Typ, Name_First));
7878 end Get_Cursor_Type;
7880 -------------------------------
7881 -- Get_Default_External_Name --
7882 -------------------------------
7884 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
7885 begin
7886 Get_Decoded_Name_String (Chars (E));
7888 if Opt.External_Name_Imp_Casing = Uppercase then
7889 Set_Casing (All_Upper_Case);
7890 else
7891 Set_Casing (All_Lower_Case);
7892 end if;
7894 return
7895 Make_String_Literal (Sloc (E),
7896 Strval => String_From_Name_Buffer);
7897 end Get_Default_External_Name;
7899 --------------------------
7900 -- Get_Enclosing_Object --
7901 --------------------------
7903 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
7904 begin
7905 if Is_Entity_Name (N) then
7906 return Entity (N);
7907 else
7908 case Nkind (N) is
7909 when N_Indexed_Component
7910 | N_Selected_Component
7911 | N_Slice
7913 -- If not generating code, a dereference may be left implicit.
7914 -- In thoses cases, return Empty.
7916 if Is_Access_Type (Etype (Prefix (N))) then
7917 return Empty;
7918 else
7919 return Get_Enclosing_Object (Prefix (N));
7920 end if;
7922 when N_Type_Conversion =>
7923 return Get_Enclosing_Object (Expression (N));
7925 when others =>
7926 return Empty;
7927 end case;
7928 end if;
7929 end Get_Enclosing_Object;
7931 ---------------------------
7932 -- Get_Enum_Lit_From_Pos --
7933 ---------------------------
7935 function Get_Enum_Lit_From_Pos
7936 (T : Entity_Id;
7937 Pos : Uint;
7938 Loc : Source_Ptr) return Node_Id
7940 Btyp : Entity_Id := Base_Type (T);
7941 Lit : Node_Id;
7942 LLoc : Source_Ptr;
7944 begin
7945 -- In the case where the literal is of type Character, Wide_Character
7946 -- or Wide_Wide_Character or of a type derived from them, there needs
7947 -- to be some special handling since there is no explicit chain of
7948 -- literals to search. Instead, an N_Character_Literal node is created
7949 -- with the appropriate Char_Code and Chars fields.
7951 if Is_Standard_Character_Type (T) then
7952 Set_Character_Literal_Name (UI_To_CC (Pos));
7954 return
7955 Make_Character_Literal (Loc,
7956 Chars => Name_Find,
7957 Char_Literal_Value => Pos);
7959 -- For all other cases, we have a complete table of literals, and
7960 -- we simply iterate through the chain of literal until the one
7961 -- with the desired position value is found.
7963 else
7964 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7965 Btyp := Full_View (Btyp);
7966 end if;
7968 Lit := First_Literal (Btyp);
7969 for J in 1 .. UI_To_Int (Pos) loop
7970 Next_Literal (Lit);
7972 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
7973 -- inside the loop to avoid calling Next_Literal on Empty.
7975 if No (Lit) then
7976 raise Constraint_Error;
7977 end if;
7978 end loop;
7980 -- Create a new node from Lit, with source location provided by Loc
7981 -- if not equal to No_Location, or by copying the source location of
7982 -- Lit otherwise.
7984 LLoc := Loc;
7986 if LLoc = No_Location then
7987 LLoc := Sloc (Lit);
7988 end if;
7990 return New_Occurrence_Of (Lit, LLoc);
7991 end if;
7992 end Get_Enum_Lit_From_Pos;
7994 ------------------------
7995 -- Get_Generic_Entity --
7996 ------------------------
7998 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7999 Ent : constant Entity_Id := Entity (Name (N));
8000 begin
8001 if Present (Renamed_Object (Ent)) then
8002 return Renamed_Object (Ent);
8003 else
8004 return Ent;
8005 end if;
8006 end Get_Generic_Entity;
8008 -------------------------------------
8009 -- Get_Incomplete_View_Of_Ancestor --
8010 -------------------------------------
8012 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
8013 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
8014 Par_Scope : Entity_Id;
8015 Par_Type : Entity_Id;
8017 begin
8018 -- The incomplete view of an ancestor is only relevant for private
8019 -- derived types in child units.
8021 if not Is_Derived_Type (E)
8022 or else not Is_Child_Unit (Cur_Unit)
8023 then
8024 return Empty;
8026 else
8027 Par_Scope := Scope (Cur_Unit);
8028 if No (Par_Scope) then
8029 return Empty;
8030 end if;
8032 Par_Type := Etype (Base_Type (E));
8034 -- Traverse list of ancestor types until we find one declared in
8035 -- a parent or grandparent unit (two levels seem sufficient).
8037 while Present (Par_Type) loop
8038 if Scope (Par_Type) = Par_Scope
8039 or else Scope (Par_Type) = Scope (Par_Scope)
8040 then
8041 return Par_Type;
8043 elsif not Is_Derived_Type (Par_Type) then
8044 return Empty;
8046 else
8047 Par_Type := Etype (Base_Type (Par_Type));
8048 end if;
8049 end loop;
8051 -- If none found, there is no relevant ancestor type.
8053 return Empty;
8054 end if;
8055 end Get_Incomplete_View_Of_Ancestor;
8057 ----------------------
8058 -- Get_Index_Bounds --
8059 ----------------------
8061 procedure Get_Index_Bounds
8062 (N : Node_Id;
8063 L : out Node_Id;
8064 H : out Node_Id;
8065 Use_Full_View : Boolean := False)
8067 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id;
8068 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
8069 -- Typ qualifies, the scalar range is obtained from the full view of the
8070 -- type.
8072 --------------------------
8073 -- Scalar_Range_Of_Type --
8074 --------------------------
8076 function Scalar_Range_Of_Type (Typ : Entity_Id) return Node_Id is
8077 T : Entity_Id := Typ;
8079 begin
8080 if Use_Full_View and then Present (Full_View (T)) then
8081 T := Full_View (T);
8082 end if;
8084 return Scalar_Range (T);
8085 end Scalar_Range_Of_Type;
8087 -- Local variables
8089 Kind : constant Node_Kind := Nkind (N);
8090 Rng : Node_Id;
8092 -- Start of processing for Get_Index_Bounds
8094 begin
8095 if Kind = N_Range then
8096 L := Low_Bound (N);
8097 H := High_Bound (N);
8099 elsif Kind = N_Subtype_Indication then
8100 Rng := Range_Expression (Constraint (N));
8102 if Rng = Error then
8103 L := Error;
8104 H := Error;
8105 return;
8107 else
8108 L := Low_Bound (Range_Expression (Constraint (N)));
8109 H := High_Bound (Range_Expression (Constraint (N)));
8110 end if;
8112 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
8113 Rng := Scalar_Range_Of_Type (Entity (N));
8115 if Error_Posted (Rng) then
8116 L := Error;
8117 H := Error;
8119 elsif Nkind (Rng) = N_Subtype_Indication then
8120 Get_Index_Bounds (Rng, L, H);
8122 else
8123 L := Low_Bound (Rng);
8124 H := High_Bound (Rng);
8125 end if;
8127 else
8128 -- N is an expression, indicating a range with one value
8130 L := N;
8131 H := N;
8132 end if;
8133 end Get_Index_Bounds;
8135 ---------------------------------
8136 -- Get_Iterable_Type_Primitive --
8137 ---------------------------------
8139 function Get_Iterable_Type_Primitive
8140 (Typ : Entity_Id;
8141 Nam : Name_Id) return Entity_Id
8143 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
8144 Assoc : Node_Id;
8146 begin
8147 if No (Funcs) then
8148 return Empty;
8150 else
8151 Assoc := First (Component_Associations (Funcs));
8152 while Present (Assoc) loop
8153 if Chars (First (Choices (Assoc))) = Nam then
8154 return Entity (Expression (Assoc));
8155 end if;
8157 Assoc := Next (Assoc);
8158 end loop;
8160 return Empty;
8161 end if;
8162 end Get_Iterable_Type_Primitive;
8164 ----------------------------------
8165 -- Get_Library_Unit_Name_string --
8166 ----------------------------------
8168 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
8169 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
8171 begin
8172 Get_Unit_Name_String (Unit_Name_Id);
8174 -- Remove seven last character (" (spec)" or " (body)")
8176 Name_Len := Name_Len - 7;
8177 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
8178 end Get_Library_Unit_Name_String;
8180 --------------------------
8181 -- Get_Max_Queue_Length --
8182 --------------------------
8184 function Get_Max_Queue_Length (Id : Entity_Id) return Uint is
8185 pragma Assert (Is_Entry (Id));
8186 Prag : constant Entity_Id := Get_Pragma (Id, Pragma_Max_Queue_Length);
8188 begin
8189 -- A value of 0 represents no maximum specified, and entries and entry
8190 -- families with no Max_Queue_Length aspect or pragma default to it.
8192 if not Present (Prag) then
8193 return Uint_0;
8194 end if;
8196 return Intval (Expression (First (Pragma_Argument_Associations (Prag))));
8197 end Get_Max_Queue_Length;
8199 ------------------------
8200 -- Get_Name_Entity_Id --
8201 ------------------------
8203 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
8204 begin
8205 return Entity_Id (Get_Name_Table_Int (Id));
8206 end Get_Name_Entity_Id;
8208 ------------------------------
8209 -- Get_Name_From_CTC_Pragma --
8210 ------------------------------
8212 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
8213 Arg : constant Node_Id :=
8214 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
8215 begin
8216 return Strval (Expr_Value_S (Arg));
8217 end Get_Name_From_CTC_Pragma;
8219 -----------------------
8220 -- Get_Parent_Entity --
8221 -----------------------
8223 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
8224 begin
8225 if Nkind (Unit) = N_Package_Body
8226 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
8227 then
8228 return Defining_Entity
8229 (Specification (Instance_Spec (Original_Node (Unit))));
8230 elsif Nkind (Unit) = N_Package_Instantiation then
8231 return Defining_Entity (Specification (Instance_Spec (Unit)));
8232 else
8233 return Defining_Entity (Unit);
8234 end if;
8235 end Get_Parent_Entity;
8237 -------------------
8238 -- Get_Pragma_Id --
8239 -------------------
8241 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
8242 begin
8243 return Get_Pragma_Id (Pragma_Name_Unmapped (N));
8244 end Get_Pragma_Id;
8246 ------------------------
8247 -- Get_Qualified_Name --
8248 ------------------------
8250 function Get_Qualified_Name
8251 (Id : Entity_Id;
8252 Suffix : Entity_Id := Empty) return Name_Id
8254 Suffix_Nam : Name_Id := No_Name;
8256 begin
8257 if Present (Suffix) then
8258 Suffix_Nam := Chars (Suffix);
8259 end if;
8261 return Get_Qualified_Name (Chars (Id), Suffix_Nam, Scope (Id));
8262 end Get_Qualified_Name;
8264 function Get_Qualified_Name
8265 (Nam : Name_Id;
8266 Suffix : Name_Id := No_Name;
8267 Scop : Entity_Id := Current_Scope) return Name_Id
8269 procedure Add_Scope (S : Entity_Id);
8270 -- Add the fully qualified form of scope S to the name buffer. The
8271 -- format is:
8272 -- s-1__s__
8274 ---------------
8275 -- Add_Scope --
8276 ---------------
8278 procedure Add_Scope (S : Entity_Id) is
8279 begin
8280 if S = Empty then
8281 null;
8283 elsif S = Standard_Standard then
8284 null;
8286 else
8287 Add_Scope (Scope (S));
8288 Get_Name_String_And_Append (Chars (S));
8289 Add_Str_To_Name_Buffer ("__");
8290 end if;
8291 end Add_Scope;
8293 -- Start of processing for Get_Qualified_Name
8295 begin
8296 Name_Len := 0;
8297 Add_Scope (Scop);
8299 -- Append the base name after all scopes have been chained
8301 Get_Name_String_And_Append (Nam);
8303 -- Append the suffix (if present)
8305 if Suffix /= No_Name then
8306 Add_Str_To_Name_Buffer ("__");
8307 Get_Name_String_And_Append (Suffix);
8308 end if;
8310 return Name_Find;
8311 end Get_Qualified_Name;
8313 -----------------------
8314 -- Get_Reason_String --
8315 -----------------------
8317 procedure Get_Reason_String (N : Node_Id) is
8318 begin
8319 if Nkind (N) = N_String_Literal then
8320 Store_String_Chars (Strval (N));
8322 elsif Nkind (N) = N_Op_Concat then
8323 Get_Reason_String (Left_Opnd (N));
8324 Get_Reason_String (Right_Opnd (N));
8326 -- If not of required form, error
8328 else
8329 Error_Msg_N
8330 ("Reason for pragma Warnings has wrong form", N);
8331 Error_Msg_N
8332 ("\must be string literal or concatenation of string literals", N);
8333 return;
8334 end if;
8335 end Get_Reason_String;
8337 --------------------------------
8338 -- Get_Reference_Discriminant --
8339 --------------------------------
8341 function Get_Reference_Discriminant (Typ : Entity_Id) return Entity_Id is
8342 D : Entity_Id;
8344 begin
8345 D := First_Discriminant (Typ);
8346 while Present (D) loop
8347 if Has_Implicit_Dereference (D) then
8348 return D;
8349 end if;
8350 Next_Discriminant (D);
8351 end loop;
8353 return Empty;
8354 end Get_Reference_Discriminant;
8356 ---------------------------
8357 -- Get_Referenced_Object --
8358 ---------------------------
8360 function Get_Referenced_Object (N : Node_Id) return Node_Id is
8361 R : Node_Id;
8363 begin
8364 R := N;
8365 while Is_Entity_Name (R)
8366 and then Present (Renamed_Object (Entity (R)))
8367 loop
8368 R := Renamed_Object (Entity (R));
8369 end loop;
8371 return R;
8372 end Get_Referenced_Object;
8374 ------------------------
8375 -- Get_Renamed_Entity --
8376 ------------------------
8378 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
8379 R : Entity_Id;
8381 begin
8382 R := E;
8383 while Present (Renamed_Entity (R)) loop
8384 R := Renamed_Entity (R);
8385 end loop;
8387 return R;
8388 end Get_Renamed_Entity;
8390 -----------------------
8391 -- Get_Return_Object --
8392 -----------------------
8394 function Get_Return_Object (N : Node_Id) return Entity_Id is
8395 Decl : Node_Id;
8397 begin
8398 Decl := First (Return_Object_Declarations (N));
8399 while Present (Decl) loop
8400 exit when Nkind (Decl) = N_Object_Declaration
8401 and then Is_Return_Object (Defining_Identifier (Decl));
8402 Next (Decl);
8403 end loop;
8405 pragma Assert (Present (Decl));
8406 return Defining_Identifier (Decl);
8407 end Get_Return_Object;
8409 ---------------------------
8410 -- Get_Subprogram_Entity --
8411 ---------------------------
8413 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
8414 Subp : Node_Id;
8415 Subp_Id : Entity_Id;
8417 begin
8418 if Nkind (Nod) = N_Accept_Statement then
8419 Subp := Entry_Direct_Name (Nod);
8421 elsif Nkind (Nod) = N_Slice then
8422 Subp := Prefix (Nod);
8424 else
8425 Subp := Name (Nod);
8426 end if;
8428 -- Strip the subprogram call
8430 loop
8431 if Nkind_In (Subp, N_Explicit_Dereference,
8432 N_Indexed_Component,
8433 N_Selected_Component)
8434 then
8435 Subp := Prefix (Subp);
8437 elsif Nkind_In (Subp, N_Type_Conversion,
8438 N_Unchecked_Type_Conversion)
8439 then
8440 Subp := Expression (Subp);
8442 else
8443 exit;
8444 end if;
8445 end loop;
8447 -- Extract the entity of the subprogram call
8449 if Is_Entity_Name (Subp) then
8450 Subp_Id := Entity (Subp);
8452 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
8453 Subp_Id := Directly_Designated_Type (Subp_Id);
8454 end if;
8456 if Is_Subprogram (Subp_Id) then
8457 return Subp_Id;
8458 else
8459 return Empty;
8460 end if;
8462 -- The search did not find a construct that denotes a subprogram
8464 else
8465 return Empty;
8466 end if;
8467 end Get_Subprogram_Entity;
8469 -----------------------------
8470 -- Get_Task_Body_Procedure --
8471 -----------------------------
8473 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
8474 begin
8475 -- Note: A task type may be the completion of a private type with
8476 -- discriminants. When performing elaboration checks on a task
8477 -- declaration, the current view of the type may be the private one,
8478 -- and the procedure that holds the body of the task is held in its
8479 -- underlying type.
8481 -- This is an odd function, why not have Task_Body_Procedure do
8482 -- the following digging???
8484 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
8485 end Get_Task_Body_Procedure;
8487 -------------------------
8488 -- Get_User_Defined_Eq --
8489 -------------------------
8491 function Get_User_Defined_Eq (E : Entity_Id) return Entity_Id is
8492 Prim : Elmt_Id;
8493 Op : Entity_Id;
8495 begin
8496 Prim := First_Elmt (Collect_Primitive_Operations (E));
8497 while Present (Prim) loop
8498 Op := Node (Prim);
8500 if Chars (Op) = Name_Op_Eq
8501 and then Etype (Op) = Standard_Boolean
8502 and then Etype (First_Formal (Op)) = E
8503 and then Etype (Next_Formal (First_Formal (Op))) = E
8504 then
8505 return Op;
8506 end if;
8508 Next_Elmt (Prim);
8509 end loop;
8511 return Empty;
8512 end Get_User_Defined_Eq;
8514 ---------------
8515 -- Get_Views --
8516 ---------------
8518 procedure Get_Views
8519 (Typ : Entity_Id;
8520 Priv_Typ : out Entity_Id;
8521 Full_Typ : out Entity_Id;
8522 Full_Base : out Entity_Id;
8523 CRec_Typ : out Entity_Id)
8525 IP_View : Entity_Id;
8527 begin
8528 -- Assume that none of the views can be recovered
8530 Priv_Typ := Empty;
8531 Full_Typ := Empty;
8532 Full_Base := Empty;
8533 CRec_Typ := Empty;
8535 -- The input type is the corresponding record type of a protected or a
8536 -- task type.
8538 if Ekind (Typ) = E_Record_Type
8539 and then Is_Concurrent_Record_Type (Typ)
8540 then
8541 CRec_Typ := Typ;
8542 Full_Typ := Corresponding_Concurrent_Type (CRec_Typ);
8543 Full_Base := Base_Type (Full_Typ);
8544 Priv_Typ := Incomplete_Or_Partial_View (Full_Typ);
8546 -- Otherwise the input type denotes an arbitrary type
8548 else
8549 IP_View := Incomplete_Or_Partial_View (Typ);
8551 -- The input type denotes the full view of a private type
8553 if Present (IP_View) then
8554 Priv_Typ := IP_View;
8555 Full_Typ := Typ;
8557 -- The input type is a private type
8559 elsif Is_Private_Type (Typ) then
8560 Priv_Typ := Typ;
8561 Full_Typ := Full_View (Priv_Typ);
8563 -- Otherwise the input type does not have any views
8565 else
8566 Full_Typ := Typ;
8567 end if;
8569 if Present (Full_Typ) then
8570 Full_Base := Base_Type (Full_Typ);
8572 if Ekind_In (Full_Typ, E_Protected_Type, E_Task_Type) then
8573 CRec_Typ := Corresponding_Record_Type (Full_Typ);
8574 end if;
8575 end if;
8576 end if;
8577 end Get_Views;
8579 -----------------------
8580 -- Has_Access_Values --
8581 -----------------------
8583 function Has_Access_Values (T : Entity_Id) return Boolean is
8584 Typ : constant Entity_Id := Underlying_Type (T);
8586 begin
8587 -- Case of a private type which is not completed yet. This can only
8588 -- happen in the case of a generic format type appearing directly, or
8589 -- as a component of the type to which this function is being applied
8590 -- at the top level. Return False in this case, since we certainly do
8591 -- not know that the type contains access types.
8593 if No (Typ) then
8594 return False;
8596 elsif Is_Access_Type (Typ) then
8597 return True;
8599 elsif Is_Array_Type (Typ) then
8600 return Has_Access_Values (Component_Type (Typ));
8602 elsif Is_Record_Type (Typ) then
8603 declare
8604 Comp : Entity_Id;
8606 begin
8607 -- Loop to Check components
8609 Comp := First_Component_Or_Discriminant (Typ);
8610 while Present (Comp) loop
8612 -- Check for access component, tag field does not count, even
8613 -- though it is implemented internally using an access type.
8615 if Has_Access_Values (Etype (Comp))
8616 and then Chars (Comp) /= Name_uTag
8617 then
8618 return True;
8619 end if;
8621 Next_Component_Or_Discriminant (Comp);
8622 end loop;
8623 end;
8625 return False;
8627 else
8628 return False;
8629 end if;
8630 end Has_Access_Values;
8632 ------------------------------
8633 -- Has_Compatible_Alignment --
8634 ------------------------------
8636 function Has_Compatible_Alignment
8637 (Obj : Entity_Id;
8638 Expr : Node_Id;
8639 Layout_Done : Boolean) return Alignment_Result
8641 function Has_Compatible_Alignment_Internal
8642 (Obj : Entity_Id;
8643 Expr : Node_Id;
8644 Layout_Done : Boolean;
8645 Default : Alignment_Result) return Alignment_Result;
8646 -- This is the internal recursive function that actually does the work.
8647 -- There is one additional parameter, which says what the result should
8648 -- be if no alignment information is found, and there is no definite
8649 -- indication of compatible alignments. At the outer level, this is set
8650 -- to Unknown, but for internal recursive calls in the case where types
8651 -- are known to be correct, it is set to Known_Compatible.
8653 ---------------------------------------
8654 -- Has_Compatible_Alignment_Internal --
8655 ---------------------------------------
8657 function Has_Compatible_Alignment_Internal
8658 (Obj : Entity_Id;
8659 Expr : Node_Id;
8660 Layout_Done : Boolean;
8661 Default : Alignment_Result) return Alignment_Result
8663 Result : Alignment_Result := Known_Compatible;
8664 -- Holds the current status of the result. Note that once a value of
8665 -- Known_Incompatible is set, it is sticky and does not get changed
8666 -- to Unknown (the value in Result only gets worse as we go along,
8667 -- never better).
8669 Offs : Uint := No_Uint;
8670 -- Set to a factor of the offset from the base object when Expr is a
8671 -- selected or indexed component, based on Component_Bit_Offset and
8672 -- Component_Size respectively. A negative value is used to represent
8673 -- a value which is not known at compile time.
8675 procedure Check_Prefix;
8676 -- Checks the prefix recursively in the case where the expression
8677 -- is an indexed or selected component.
8679 procedure Set_Result (R : Alignment_Result);
8680 -- If R represents a worse outcome (unknown instead of known
8681 -- compatible, or known incompatible), then set Result to R.
8683 ------------------
8684 -- Check_Prefix --
8685 ------------------
8687 procedure Check_Prefix is
8688 begin
8689 -- The subtlety here is that in doing a recursive call to check
8690 -- the prefix, we have to decide what to do in the case where we
8691 -- don't find any specific indication of an alignment problem.
8693 -- At the outer level, we normally set Unknown as the result in
8694 -- this case, since we can only set Known_Compatible if we really
8695 -- know that the alignment value is OK, but for the recursive
8696 -- call, in the case where the types match, and we have not
8697 -- specified a peculiar alignment for the object, we are only
8698 -- concerned about suspicious rep clauses, the default case does
8699 -- not affect us, since the compiler will, in the absence of such
8700 -- rep clauses, ensure that the alignment is correct.
8702 if Default = Known_Compatible
8703 or else
8704 (Etype (Obj) = Etype (Expr)
8705 and then (Unknown_Alignment (Obj)
8706 or else
8707 Alignment (Obj) = Alignment (Etype (Obj))))
8708 then
8709 Set_Result
8710 (Has_Compatible_Alignment_Internal
8711 (Obj, Prefix (Expr), Layout_Done, Known_Compatible));
8713 -- In all other cases, we need a full check on the prefix
8715 else
8716 Set_Result
8717 (Has_Compatible_Alignment_Internal
8718 (Obj, Prefix (Expr), Layout_Done, Unknown));
8719 end if;
8720 end Check_Prefix;
8722 ----------------
8723 -- Set_Result --
8724 ----------------
8726 procedure Set_Result (R : Alignment_Result) is
8727 begin
8728 if R > Result then
8729 Result := R;
8730 end if;
8731 end Set_Result;
8733 -- Start of processing for Has_Compatible_Alignment_Internal
8735 begin
8736 -- If Expr is a selected component, we must make sure there is no
8737 -- potentially troublesome component clause and that the record is
8738 -- not packed if the layout is not done.
8740 if Nkind (Expr) = N_Selected_Component then
8742 -- Packing generates unknown alignment if layout is not done
8744 if Is_Packed (Etype (Prefix (Expr))) and then not Layout_Done then
8745 Set_Result (Unknown);
8746 end if;
8748 -- Check prefix and component offset
8750 Check_Prefix;
8751 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
8753 -- If Expr is an indexed component, we must make sure there is no
8754 -- potentially troublesome Component_Size clause and that the array
8755 -- is not bit-packed if the layout is not done.
8757 elsif Nkind (Expr) = N_Indexed_Component then
8758 declare
8759 Typ : constant Entity_Id := Etype (Prefix (Expr));
8761 begin
8762 -- Packing generates unknown alignment if layout is not done
8764 if Is_Bit_Packed_Array (Typ) and then not Layout_Done then
8765 Set_Result (Unknown);
8766 end if;
8768 -- Check prefix and component offset (or at least size)
8770 Check_Prefix;
8771 Offs := Indexed_Component_Bit_Offset (Expr);
8772 if Offs = No_Uint then
8773 Offs := Component_Size (Typ);
8774 end if;
8775 end;
8776 end if;
8778 -- If we have a null offset, the result is entirely determined by
8779 -- the base object and has already been computed recursively.
8781 if Offs = Uint_0 then
8782 null;
8784 -- Case where we know the alignment of the object
8786 elsif Known_Alignment (Obj) then
8787 declare
8788 ObjA : constant Uint := Alignment (Obj);
8789 ExpA : Uint := No_Uint;
8790 SizA : Uint := No_Uint;
8792 begin
8793 -- If alignment of Obj is 1, then we are always OK
8795 if ObjA = 1 then
8796 Set_Result (Known_Compatible);
8798 -- Alignment of Obj is greater than 1, so we need to check
8800 else
8801 -- If we have an offset, see if it is compatible
8803 if Offs /= No_Uint and Offs > Uint_0 then
8804 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
8805 Set_Result (Known_Incompatible);
8806 end if;
8808 -- See if Expr is an object with known alignment
8810 elsif Is_Entity_Name (Expr)
8811 and then Known_Alignment (Entity (Expr))
8812 then
8813 ExpA := Alignment (Entity (Expr));
8815 -- Otherwise, we can use the alignment of the type of
8816 -- Expr given that we already checked for
8817 -- discombobulating rep clauses for the cases of indexed
8818 -- and selected components above.
8820 elsif Known_Alignment (Etype (Expr)) then
8821 ExpA := Alignment (Etype (Expr));
8823 -- Otherwise the alignment is unknown
8825 else
8826 Set_Result (Default);
8827 end if;
8829 -- If we got an alignment, see if it is acceptable
8831 if ExpA /= No_Uint and then ExpA < ObjA then
8832 Set_Result (Known_Incompatible);
8833 end if;
8835 -- If Expr is not a piece of a larger object, see if size
8836 -- is given. If so, check that it is not too small for the
8837 -- required alignment.
8839 if Offs /= No_Uint then
8840 null;
8842 -- See if Expr is an object with known size
8844 elsif Is_Entity_Name (Expr)
8845 and then Known_Static_Esize (Entity (Expr))
8846 then
8847 SizA := Esize (Entity (Expr));
8849 -- Otherwise, we check the object size of the Expr type
8851 elsif Known_Static_Esize (Etype (Expr)) then
8852 SizA := Esize (Etype (Expr));
8853 end if;
8855 -- If we got a size, see if it is a multiple of the Obj
8856 -- alignment, if not, then the alignment cannot be
8857 -- acceptable, since the size is always a multiple of the
8858 -- alignment.
8860 if SizA /= No_Uint then
8861 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
8862 Set_Result (Known_Incompatible);
8863 end if;
8864 end if;
8865 end if;
8866 end;
8868 -- If we do not know required alignment, any non-zero offset is a
8869 -- potential problem (but certainly may be OK, so result is unknown).
8871 elsif Offs /= No_Uint then
8872 Set_Result (Unknown);
8874 -- If we can't find the result by direct comparison of alignment
8875 -- values, then there is still one case that we can determine known
8876 -- result, and that is when we can determine that the types are the
8877 -- same, and no alignments are specified. Then we known that the
8878 -- alignments are compatible, even if we don't know the alignment
8879 -- value in the front end.
8881 elsif Etype (Obj) = Etype (Expr) then
8883 -- Types are the same, but we have to check for possible size
8884 -- and alignments on the Expr object that may make the alignment
8885 -- different, even though the types are the same.
8887 if Is_Entity_Name (Expr) then
8889 -- First check alignment of the Expr object. Any alignment less
8890 -- than Maximum_Alignment is worrisome since this is the case
8891 -- where we do not know the alignment of Obj.
8893 if Known_Alignment (Entity (Expr))
8894 and then UI_To_Int (Alignment (Entity (Expr))) <
8895 Ttypes.Maximum_Alignment
8896 then
8897 Set_Result (Unknown);
8899 -- Now check size of Expr object. Any size that is not an
8900 -- even multiple of Maximum_Alignment is also worrisome
8901 -- since it may cause the alignment of the object to be less
8902 -- than the alignment of the type.
8904 elsif Known_Static_Esize (Entity (Expr))
8905 and then
8906 (UI_To_Int (Esize (Entity (Expr))) mod
8907 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
8908 /= 0
8909 then
8910 Set_Result (Unknown);
8912 -- Otherwise same type is decisive
8914 else
8915 Set_Result (Known_Compatible);
8916 end if;
8917 end if;
8919 -- Another case to deal with is when there is an explicit size or
8920 -- alignment clause when the types are not the same. If so, then the
8921 -- result is Unknown. We don't need to do this test if the Default is
8922 -- Unknown, since that result will be set in any case.
8924 elsif Default /= Unknown
8925 and then (Has_Size_Clause (Etype (Expr))
8926 or else
8927 Has_Alignment_Clause (Etype (Expr)))
8928 then
8929 Set_Result (Unknown);
8931 -- If no indication found, set default
8933 else
8934 Set_Result (Default);
8935 end if;
8937 -- Return worst result found
8939 return Result;
8940 end Has_Compatible_Alignment_Internal;
8942 -- Start of processing for Has_Compatible_Alignment
8944 begin
8945 -- If Obj has no specified alignment, then set alignment from the type
8946 -- alignment. Perhaps we should always do this, but for sure we should
8947 -- do it when there is an address clause since we can do more if the
8948 -- alignment is known.
8950 if Unknown_Alignment (Obj) then
8951 Set_Alignment (Obj, Alignment (Etype (Obj)));
8952 end if;
8954 -- Now do the internal call that does all the work
8956 return
8957 Has_Compatible_Alignment_Internal (Obj, Expr, Layout_Done, Unknown);
8958 end Has_Compatible_Alignment;
8960 ----------------------
8961 -- Has_Declarations --
8962 ----------------------
8964 function Has_Declarations (N : Node_Id) return Boolean is
8965 begin
8966 return Nkind_In (Nkind (N), N_Accept_Statement,
8967 N_Block_Statement,
8968 N_Compilation_Unit_Aux,
8969 N_Entry_Body,
8970 N_Package_Body,
8971 N_Protected_Body,
8972 N_Subprogram_Body,
8973 N_Task_Body,
8974 N_Package_Specification);
8975 end Has_Declarations;
8977 ---------------------------------
8978 -- Has_Defaulted_Discriminants --
8979 ---------------------------------
8981 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
8982 begin
8983 return Has_Discriminants (Typ)
8984 and then Present (First_Discriminant (Typ))
8985 and then Present (Discriminant_Default_Value
8986 (First_Discriminant (Typ)));
8987 end Has_Defaulted_Discriminants;
8989 -------------------
8990 -- Has_Denormals --
8991 -------------------
8993 function Has_Denormals (E : Entity_Id) return Boolean is
8994 begin
8995 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
8996 end Has_Denormals;
8998 -------------------------------------------
8999 -- Has_Discriminant_Dependent_Constraint --
9000 -------------------------------------------
9002 function Has_Discriminant_Dependent_Constraint
9003 (Comp : Entity_Id) return Boolean
9005 Comp_Decl : constant Node_Id := Parent (Comp);
9006 Subt_Indic : Node_Id;
9007 Constr : Node_Id;
9008 Assn : Node_Id;
9010 begin
9011 -- Discriminants can't depend on discriminants
9013 if Ekind (Comp) = E_Discriminant then
9014 return False;
9016 else
9017 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
9019 if Nkind (Subt_Indic) = N_Subtype_Indication then
9020 Constr := Constraint (Subt_Indic);
9022 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
9023 Assn := First (Constraints (Constr));
9024 while Present (Assn) loop
9025 case Nkind (Assn) is
9026 when N_Identifier
9027 | N_Range
9028 | N_Subtype_Indication
9030 if Depends_On_Discriminant (Assn) then
9031 return True;
9032 end if;
9034 when N_Discriminant_Association =>
9035 if Depends_On_Discriminant (Expression (Assn)) then
9036 return True;
9037 end if;
9039 when others =>
9040 null;
9041 end case;
9043 Next (Assn);
9044 end loop;
9045 end if;
9046 end if;
9047 end if;
9049 return False;
9050 end Has_Discriminant_Dependent_Constraint;
9052 --------------------------------------
9053 -- Has_Effectively_Volatile_Profile --
9054 --------------------------------------
9056 function Has_Effectively_Volatile_Profile
9057 (Subp_Id : Entity_Id) return Boolean
9059 Formal : Entity_Id;
9061 begin
9062 -- Inspect the formal parameters looking for an effectively volatile
9063 -- type.
9065 Formal := First_Formal (Subp_Id);
9066 while Present (Formal) loop
9067 if Is_Effectively_Volatile (Etype (Formal)) then
9068 return True;
9069 end if;
9071 Next_Formal (Formal);
9072 end loop;
9074 -- Inspect the return type of functions
9076 if Ekind_In (Subp_Id, E_Function, E_Generic_Function)
9077 and then Is_Effectively_Volatile (Etype (Subp_Id))
9078 then
9079 return True;
9080 end if;
9082 return False;
9083 end Has_Effectively_Volatile_Profile;
9085 --------------------------
9086 -- Has_Enabled_Property --
9087 --------------------------
9089 function Has_Enabled_Property
9090 (Item_Id : Entity_Id;
9091 Property : Name_Id) return Boolean
9093 function Protected_Object_Has_Enabled_Property return Boolean;
9094 -- Determine whether a protected object denoted by Item_Id has the
9095 -- property enabled.
9097 function State_Has_Enabled_Property return Boolean;
9098 -- Determine whether a state denoted by Item_Id has the property enabled
9100 function Variable_Has_Enabled_Property return Boolean;
9101 -- Determine whether a variable denoted by Item_Id has the property
9102 -- enabled.
9104 -------------------------------------------
9105 -- Protected_Object_Has_Enabled_Property --
9106 -------------------------------------------
9108 function Protected_Object_Has_Enabled_Property return Boolean is
9109 Constits : constant Elist_Id := Part_Of_Constituents (Item_Id);
9110 Constit_Elmt : Elmt_Id;
9111 Constit_Id : Entity_Id;
9113 begin
9114 -- Protected objects always have the properties Async_Readers and
9115 -- Async_Writers (SPARK RM 7.1.2(16)).
9117 if Property = Name_Async_Readers
9118 or else Property = Name_Async_Writers
9119 then
9120 return True;
9122 -- Protected objects that have Part_Of components also inherit their
9123 -- properties Effective_Reads and Effective_Writes
9124 -- (SPARK RM 7.1.2(16)).
9126 elsif Present (Constits) then
9127 Constit_Elmt := First_Elmt (Constits);
9128 while Present (Constit_Elmt) loop
9129 Constit_Id := Node (Constit_Elmt);
9131 if Has_Enabled_Property (Constit_Id, Property) then
9132 return True;
9133 end if;
9135 Next_Elmt (Constit_Elmt);
9136 end loop;
9137 end if;
9139 return False;
9140 end Protected_Object_Has_Enabled_Property;
9142 --------------------------------
9143 -- State_Has_Enabled_Property --
9144 --------------------------------
9146 function State_Has_Enabled_Property return Boolean is
9147 Decl : constant Node_Id := Parent (Item_Id);
9148 Opt : Node_Id;
9149 Opt_Nam : Node_Id;
9150 Prop : Node_Id;
9151 Prop_Nam : Node_Id;
9152 Props : Node_Id;
9154 begin
9155 -- The declaration of an external abstract state appears as an
9156 -- extension aggregate. If this is not the case, properties can never
9157 -- be set.
9159 if Nkind (Decl) /= N_Extension_Aggregate then
9160 return False;
9161 end if;
9163 -- When External appears as a simple option, it automatically enables
9164 -- all properties.
9166 Opt := First (Expressions (Decl));
9167 while Present (Opt) loop
9168 if Nkind (Opt) = N_Identifier
9169 and then Chars (Opt) = Name_External
9170 then
9171 return True;
9172 end if;
9174 Next (Opt);
9175 end loop;
9177 -- When External specifies particular properties, inspect those and
9178 -- find the desired one (if any).
9180 Opt := First (Component_Associations (Decl));
9181 while Present (Opt) loop
9182 Opt_Nam := First (Choices (Opt));
9184 if Nkind (Opt_Nam) = N_Identifier
9185 and then Chars (Opt_Nam) = Name_External
9186 then
9187 Props := Expression (Opt);
9189 -- Multiple properties appear as an aggregate
9191 if Nkind (Props) = N_Aggregate then
9193 -- Simple property form
9195 Prop := First (Expressions (Props));
9196 while Present (Prop) loop
9197 if Chars (Prop) = Property then
9198 return True;
9199 end if;
9201 Next (Prop);
9202 end loop;
9204 -- Property with expression form
9206 Prop := First (Component_Associations (Props));
9207 while Present (Prop) loop
9208 Prop_Nam := First (Choices (Prop));
9210 -- The property can be represented in two ways:
9211 -- others => <value>
9212 -- <property> => <value>
9214 if Nkind (Prop_Nam) = N_Others_Choice
9215 or else (Nkind (Prop_Nam) = N_Identifier
9216 and then Chars (Prop_Nam) = Property)
9217 then
9218 return Is_True (Expr_Value (Expression (Prop)));
9219 end if;
9221 Next (Prop);
9222 end loop;
9224 -- Single property
9226 else
9227 return Chars (Props) = Property;
9228 end if;
9229 end if;
9231 Next (Opt);
9232 end loop;
9234 return False;
9235 end State_Has_Enabled_Property;
9237 -----------------------------------
9238 -- Variable_Has_Enabled_Property --
9239 -----------------------------------
9241 function Variable_Has_Enabled_Property return Boolean is
9242 function Is_Enabled (Prag : Node_Id) return Boolean;
9243 -- Determine whether property pragma Prag (if present) denotes an
9244 -- enabled property.
9246 ----------------
9247 -- Is_Enabled --
9248 ----------------
9250 function Is_Enabled (Prag : Node_Id) return Boolean is
9251 Arg1 : Node_Id;
9253 begin
9254 if Present (Prag) then
9255 Arg1 := First (Pragma_Argument_Associations (Prag));
9257 -- The pragma has an optional Boolean expression, the related
9258 -- property is enabled only when the expression evaluates to
9259 -- True.
9261 if Present (Arg1) then
9262 return Is_True (Expr_Value (Get_Pragma_Arg (Arg1)));
9264 -- Otherwise the lack of expression enables the property by
9265 -- default.
9267 else
9268 return True;
9269 end if;
9271 -- The property was never set in the first place
9273 else
9274 return False;
9275 end if;
9276 end Is_Enabled;
9278 -- Local variables
9280 AR : constant Node_Id :=
9281 Get_Pragma (Item_Id, Pragma_Async_Readers);
9282 AW : constant Node_Id :=
9283 Get_Pragma (Item_Id, Pragma_Async_Writers);
9284 ER : constant Node_Id :=
9285 Get_Pragma (Item_Id, Pragma_Effective_Reads);
9286 EW : constant Node_Id :=
9287 Get_Pragma (Item_Id, Pragma_Effective_Writes);
9289 -- Start of processing for Variable_Has_Enabled_Property
9291 begin
9292 -- A non-effectively volatile object can never possess external
9293 -- properties.
9295 if not Is_Effectively_Volatile (Item_Id) then
9296 return False;
9298 -- External properties related to variables come in two flavors -
9299 -- explicit and implicit. The explicit case is characterized by the
9300 -- presence of a property pragma with an optional Boolean flag. The
9301 -- property is enabled when the flag evaluates to True or the flag is
9302 -- missing altogether.
9304 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
9305 return True;
9307 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
9308 return True;
9310 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
9311 return True;
9313 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
9314 return True;
9316 -- The implicit case lacks all property pragmas
9318 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
9319 if Is_Protected_Type (Etype (Item_Id)) then
9320 return Protected_Object_Has_Enabled_Property;
9321 else
9322 return True;
9323 end if;
9325 else
9326 return False;
9327 end if;
9328 end Variable_Has_Enabled_Property;
9330 -- Start of processing for Has_Enabled_Property
9332 begin
9333 -- Abstract states and variables have a flexible scheme of specifying
9334 -- external properties.
9336 if Ekind (Item_Id) = E_Abstract_State then
9337 return State_Has_Enabled_Property;
9339 elsif Ekind (Item_Id) = E_Variable then
9340 return Variable_Has_Enabled_Property;
9342 -- By default, protected objects only have the properties Async_Readers
9343 -- and Async_Writers. If they have Part_Of components, they also inherit
9344 -- their properties Effective_Reads and Effective_Writes
9345 -- (SPARK RM 7.1.2(16)).
9347 elsif Ekind (Item_Id) = E_Protected_Object then
9348 return Protected_Object_Has_Enabled_Property;
9350 -- Otherwise a property is enabled when the related item is effectively
9351 -- volatile.
9353 else
9354 return Is_Effectively_Volatile (Item_Id);
9355 end if;
9356 end Has_Enabled_Property;
9358 -------------------------------------
9359 -- Has_Full_Default_Initialization --
9360 -------------------------------------
9362 function Has_Full_Default_Initialization (Typ : Entity_Id) return Boolean is
9363 Comp : Entity_Id;
9364 Prag : Node_Id;
9366 begin
9367 -- A type subject to pragma Default_Initial_Condition is fully default
9368 -- initialized when the pragma appears with a non-null argument. Since
9369 -- any type may act as the full view of a private type, this check must
9370 -- be performed prior to the specialized tests below.
9372 if Has_DIC (Typ) then
9373 Prag := Get_Pragma (Typ, Pragma_Default_Initial_Condition);
9374 pragma Assert (Present (Prag));
9376 return Is_Verifiable_DIC_Pragma (Prag);
9377 end if;
9379 -- A scalar type is fully default initialized if it is subject to aspect
9380 -- Default_Value.
9382 if Is_Scalar_Type (Typ) then
9383 return Has_Default_Aspect (Typ);
9385 -- An array type is fully default initialized if its element type is
9386 -- scalar and the array type carries aspect Default_Component_Value or
9387 -- the element type is fully default initialized.
9389 elsif Is_Array_Type (Typ) then
9390 return
9391 Has_Default_Aspect (Typ)
9392 or else Has_Full_Default_Initialization (Component_Type (Typ));
9394 -- A protected type, record type, or type extension is fully default
9395 -- initialized if all its components either carry an initialization
9396 -- expression or have a type that is fully default initialized. The
9397 -- parent type of a type extension must be fully default initialized.
9399 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
9401 -- Inspect all entities defined in the scope of the type, looking for
9402 -- uninitialized components.
9404 Comp := First_Entity (Typ);
9405 while Present (Comp) loop
9406 if Ekind (Comp) = E_Component
9407 and then Comes_From_Source (Comp)
9408 and then No (Expression (Parent (Comp)))
9409 and then not Has_Full_Default_Initialization (Etype (Comp))
9410 then
9411 return False;
9412 end if;
9414 Next_Entity (Comp);
9415 end loop;
9417 -- Ensure that the parent type of a type extension is fully default
9418 -- initialized.
9420 if Etype (Typ) /= Typ
9421 and then not Has_Full_Default_Initialization (Etype (Typ))
9422 then
9423 return False;
9424 end if;
9426 -- If we get here, then all components and parent portion are fully
9427 -- default initialized.
9429 return True;
9431 -- A task type is fully default initialized by default
9433 elsif Is_Task_Type (Typ) then
9434 return True;
9436 -- Otherwise the type is not fully default initialized
9438 else
9439 return False;
9440 end if;
9441 end Has_Full_Default_Initialization;
9443 --------------------
9444 -- Has_Infinities --
9445 --------------------
9447 function Has_Infinities (E : Entity_Id) return Boolean is
9448 begin
9449 return
9450 Is_Floating_Point_Type (E)
9451 and then Nkind (Scalar_Range (E)) = N_Range
9452 and then Includes_Infinities (Scalar_Range (E));
9453 end Has_Infinities;
9455 --------------------
9456 -- Has_Interfaces --
9457 --------------------
9459 function Has_Interfaces
9460 (T : Entity_Id;
9461 Use_Full_View : Boolean := True) return Boolean
9463 Typ : Entity_Id := Base_Type (T);
9465 begin
9466 -- Handle concurrent types
9468 if Is_Concurrent_Type (Typ) then
9469 Typ := Corresponding_Record_Type (Typ);
9470 end if;
9472 if not Present (Typ)
9473 or else not Is_Record_Type (Typ)
9474 or else not Is_Tagged_Type (Typ)
9475 then
9476 return False;
9477 end if;
9479 -- Handle private types
9481 if Use_Full_View and then Present (Full_View (Typ)) then
9482 Typ := Full_View (Typ);
9483 end if;
9485 -- Handle concurrent record types
9487 if Is_Concurrent_Record_Type (Typ)
9488 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
9489 then
9490 return True;
9491 end if;
9493 loop
9494 if Is_Interface (Typ)
9495 or else
9496 (Is_Record_Type (Typ)
9497 and then Present (Interfaces (Typ))
9498 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
9499 then
9500 return True;
9501 end if;
9503 exit when Etype (Typ) = Typ
9505 -- Handle private types
9507 or else (Present (Full_View (Etype (Typ)))
9508 and then Full_View (Etype (Typ)) = Typ)
9510 -- Protect frontend against wrong sources with cyclic derivations
9512 or else Etype (Typ) = T;
9514 -- Climb to the ancestor type handling private types
9516 if Present (Full_View (Etype (Typ))) then
9517 Typ := Full_View (Etype (Typ));
9518 else
9519 Typ := Etype (Typ);
9520 end if;
9521 end loop;
9523 return False;
9524 end Has_Interfaces;
9526 --------------------------
9527 -- Has_Max_Queue_Length --
9528 --------------------------
9530 function Has_Max_Queue_Length (Id : Entity_Id) return Boolean is
9531 begin
9532 return
9533 Ekind (Id) = E_Entry
9534 and then Present (Get_Pragma (Id, Pragma_Max_Queue_Length));
9535 end Has_Max_Queue_Length;
9537 ---------------------------------
9538 -- Has_No_Obvious_Side_Effects --
9539 ---------------------------------
9541 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
9542 begin
9543 -- For now handle literals, constants, and non-volatile variables and
9544 -- expressions combining these with operators or short circuit forms.
9546 if Nkind (N) in N_Numeric_Or_String_Literal then
9547 return True;
9549 elsif Nkind (N) = N_Character_Literal then
9550 return True;
9552 elsif Nkind (N) in N_Unary_Op then
9553 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
9555 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
9556 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
9557 and then
9558 Has_No_Obvious_Side_Effects (Right_Opnd (N));
9560 elsif Nkind (N) = N_Expression_With_Actions
9561 and then Is_Empty_List (Actions (N))
9562 then
9563 return Has_No_Obvious_Side_Effects (Expression (N));
9565 elsif Nkind (N) in N_Has_Entity then
9566 return Present (Entity (N))
9567 and then Ekind_In (Entity (N), E_Variable,
9568 E_Constant,
9569 E_Enumeration_Literal,
9570 E_In_Parameter,
9571 E_Out_Parameter,
9572 E_In_Out_Parameter)
9573 and then not Is_Volatile (Entity (N));
9575 else
9576 return False;
9577 end if;
9578 end Has_No_Obvious_Side_Effects;
9580 -----------------------------
9581 -- Has_Non_Null_Refinement --
9582 -----------------------------
9584 function Has_Non_Null_Refinement (Id : Entity_Id) return Boolean is
9585 Constits : Elist_Id;
9587 begin
9588 pragma Assert (Ekind (Id) = E_Abstract_State);
9589 Constits := Refinement_Constituents (Id);
9591 -- For a refinement to be non-null, the first constituent must be
9592 -- anything other than null.
9594 return
9595 Present (Constits)
9596 and then Nkind (Node (First_Elmt (Constits))) /= N_Null;
9597 end Has_Non_Null_Refinement;
9599 -------------------
9600 -- Has_Null_Body --
9601 -------------------
9603 function Has_Null_Body (Proc_Id : Entity_Id) return Boolean is
9604 Body_Id : Entity_Id;
9605 Decl : Node_Id;
9606 Spec : Node_Id;
9607 Stmt1 : Node_Id;
9608 Stmt2 : Node_Id;
9610 begin
9611 Spec := Parent (Proc_Id);
9612 Decl := Parent (Spec);
9614 -- Retrieve the entity of the procedure body (e.g. invariant proc).
9616 if Nkind (Spec) = N_Procedure_Specification
9617 and then Nkind (Decl) = N_Subprogram_Declaration
9618 then
9619 Body_Id := Corresponding_Body (Decl);
9621 -- The body acts as a spec
9623 else
9624 Body_Id := Proc_Id;
9625 end if;
9627 -- The body will be generated later
9629 if No (Body_Id) then
9630 return False;
9631 end if;
9633 Spec := Parent (Body_Id);
9634 Decl := Parent (Spec);
9636 pragma Assert
9637 (Nkind (Spec) = N_Procedure_Specification
9638 and then Nkind (Decl) = N_Subprogram_Body);
9640 Stmt1 := First (Statements (Handled_Statement_Sequence (Decl)));
9642 -- Look for a null statement followed by an optional return
9643 -- statement.
9645 if Nkind (Stmt1) = N_Null_Statement then
9646 Stmt2 := Next (Stmt1);
9648 if Present (Stmt2) then
9649 return Nkind (Stmt2) = N_Simple_Return_Statement;
9650 else
9651 return True;
9652 end if;
9653 end if;
9655 return False;
9656 end Has_Null_Body;
9658 ------------------------
9659 -- Has_Null_Exclusion --
9660 ------------------------
9662 function Has_Null_Exclusion (N : Node_Id) return Boolean is
9663 begin
9664 case Nkind (N) is
9665 when N_Access_Definition
9666 | N_Access_Function_Definition
9667 | N_Access_Procedure_Definition
9668 | N_Access_To_Object_Definition
9669 | N_Allocator
9670 | N_Derived_Type_Definition
9671 | N_Function_Specification
9672 | N_Subtype_Declaration
9674 return Null_Exclusion_Present (N);
9676 when N_Component_Definition
9677 | N_Formal_Object_Declaration
9678 | N_Object_Renaming_Declaration
9680 if Present (Subtype_Mark (N)) then
9681 return Null_Exclusion_Present (N);
9682 else pragma Assert (Present (Access_Definition (N)));
9683 return Null_Exclusion_Present (Access_Definition (N));
9684 end if;
9686 when N_Discriminant_Specification =>
9687 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
9688 return Null_Exclusion_Present (Discriminant_Type (N));
9689 else
9690 return Null_Exclusion_Present (N);
9691 end if;
9693 when N_Object_Declaration =>
9694 if Nkind (Object_Definition (N)) = N_Access_Definition then
9695 return Null_Exclusion_Present (Object_Definition (N));
9696 else
9697 return Null_Exclusion_Present (N);
9698 end if;
9700 when N_Parameter_Specification =>
9701 if Nkind (Parameter_Type (N)) = N_Access_Definition then
9702 return Null_Exclusion_Present (Parameter_Type (N));
9703 else
9704 return Null_Exclusion_Present (N);
9705 end if;
9707 when others =>
9708 return False;
9709 end case;
9710 end Has_Null_Exclusion;
9712 ------------------------
9713 -- Has_Null_Extension --
9714 ------------------------
9716 function Has_Null_Extension (T : Entity_Id) return Boolean is
9717 B : constant Entity_Id := Base_Type (T);
9718 Comps : Node_Id;
9719 Ext : Node_Id;
9721 begin
9722 if Nkind (Parent (B)) = N_Full_Type_Declaration
9723 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
9724 then
9725 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
9727 if Present (Ext) then
9728 if Null_Present (Ext) then
9729 return True;
9730 else
9731 Comps := Component_List (Ext);
9733 -- The null component list is rewritten during analysis to
9734 -- include the parent component. Any other component indicates
9735 -- that the extension was not originally null.
9737 return Null_Present (Comps)
9738 or else No (Next (First (Component_Items (Comps))));
9739 end if;
9740 else
9741 return False;
9742 end if;
9744 else
9745 return False;
9746 end if;
9747 end Has_Null_Extension;
9749 -------------------------
9750 -- Has_Null_Refinement --
9751 -------------------------
9753 function Has_Null_Refinement (Id : Entity_Id) return Boolean is
9754 Constits : Elist_Id;
9756 begin
9757 pragma Assert (Ekind (Id) = E_Abstract_State);
9758 Constits := Refinement_Constituents (Id);
9760 -- For a refinement to be null, the state's sole constituent must be a
9761 -- null.
9763 return
9764 Present (Constits)
9765 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
9766 end Has_Null_Refinement;
9768 -------------------------------
9769 -- Has_Overriding_Initialize --
9770 -------------------------------
9772 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
9773 BT : constant Entity_Id := Base_Type (T);
9774 P : Elmt_Id;
9776 begin
9777 if Is_Controlled (BT) then
9778 if Is_RTU (Scope (BT), Ada_Finalization) then
9779 return False;
9781 elsif Present (Primitive_Operations (BT)) then
9782 P := First_Elmt (Primitive_Operations (BT));
9783 while Present (P) loop
9784 declare
9785 Init : constant Entity_Id := Node (P);
9786 Formal : constant Entity_Id := First_Formal (Init);
9787 begin
9788 if Ekind (Init) = E_Procedure
9789 and then Chars (Init) = Name_Initialize
9790 and then Comes_From_Source (Init)
9791 and then Present (Formal)
9792 and then Etype (Formal) = BT
9793 and then No (Next_Formal (Formal))
9794 and then (Ada_Version < Ada_2012
9795 or else not Null_Present (Parent (Init)))
9796 then
9797 return True;
9798 end if;
9799 end;
9801 Next_Elmt (P);
9802 end loop;
9803 end if;
9805 -- Here if type itself does not have a non-null Initialize operation:
9806 -- check immediate ancestor.
9808 if Is_Derived_Type (BT)
9809 and then Has_Overriding_Initialize (Etype (BT))
9810 then
9811 return True;
9812 end if;
9813 end if;
9815 return False;
9816 end Has_Overriding_Initialize;
9818 --------------------------------------
9819 -- Has_Preelaborable_Initialization --
9820 --------------------------------------
9822 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
9823 Has_PE : Boolean;
9825 procedure Check_Components (E : Entity_Id);
9826 -- Check component/discriminant chain, sets Has_PE False if a component
9827 -- or discriminant does not meet the preelaborable initialization rules.
9829 ----------------------
9830 -- Check_Components --
9831 ----------------------
9833 procedure Check_Components (E : Entity_Id) is
9834 Ent : Entity_Id;
9835 Exp : Node_Id;
9837 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
9838 -- Returns True if and only if the expression denoted by N does not
9839 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
9841 ---------------------------------
9842 -- Is_Preelaborable_Expression --
9843 ---------------------------------
9845 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
9846 Exp : Node_Id;
9847 Assn : Node_Id;
9848 Choice : Node_Id;
9849 Comp_Type : Entity_Id;
9850 Is_Array_Aggr : Boolean;
9852 begin
9853 if Is_OK_Static_Expression (N) then
9854 return True;
9856 elsif Nkind (N) = N_Null then
9857 return True;
9859 -- Attributes are allowed in general, even if their prefix is a
9860 -- formal type. (It seems that certain attributes known not to be
9861 -- static might not be allowed, but there are no rules to prevent
9862 -- them.)
9864 elsif Nkind (N) = N_Attribute_Reference then
9865 return True;
9867 -- The name of a discriminant evaluated within its parent type is
9868 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9869 -- names that denote discriminals as well as discriminants to
9870 -- catch references occurring within init procs.
9872 elsif Is_Entity_Name (N)
9873 and then
9874 (Ekind (Entity (N)) = E_Discriminant
9875 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
9876 and then Present (Discriminal_Link (Entity (N)))))
9877 then
9878 return True;
9880 elsif Nkind (N) = N_Qualified_Expression then
9881 return Is_Preelaborable_Expression (Expression (N));
9883 -- For aggregates we have to check that each of the associations
9884 -- is preelaborable.
9886 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
9887 Is_Array_Aggr := Is_Array_Type (Etype (N));
9889 if Is_Array_Aggr then
9890 Comp_Type := Component_Type (Etype (N));
9891 end if;
9893 -- Check the ancestor part of extension aggregates, which must
9894 -- be either the name of a type that has preelaborable init or
9895 -- an expression that is preelaborable.
9897 if Nkind (N) = N_Extension_Aggregate then
9898 declare
9899 Anc_Part : constant Node_Id := Ancestor_Part (N);
9901 begin
9902 if Is_Entity_Name (Anc_Part)
9903 and then Is_Type (Entity (Anc_Part))
9904 then
9905 if not Has_Preelaborable_Initialization
9906 (Entity (Anc_Part))
9907 then
9908 return False;
9909 end if;
9911 elsif not Is_Preelaborable_Expression (Anc_Part) then
9912 return False;
9913 end if;
9914 end;
9915 end if;
9917 -- Check positional associations
9919 Exp := First (Expressions (N));
9920 while Present (Exp) loop
9921 if not Is_Preelaborable_Expression (Exp) then
9922 return False;
9923 end if;
9925 Next (Exp);
9926 end loop;
9928 -- Check named associations
9930 Assn := First (Component_Associations (N));
9931 while Present (Assn) loop
9932 Choice := First (Choices (Assn));
9933 while Present (Choice) loop
9934 if Is_Array_Aggr then
9935 if Nkind (Choice) = N_Others_Choice then
9936 null;
9938 elsif Nkind (Choice) = N_Range then
9939 if not Is_OK_Static_Range (Choice) then
9940 return False;
9941 end if;
9943 elsif not Is_OK_Static_Expression (Choice) then
9944 return False;
9945 end if;
9947 else
9948 Comp_Type := Etype (Choice);
9949 end if;
9951 Next (Choice);
9952 end loop;
9954 -- If the association has a <> at this point, then we have
9955 -- to check whether the component's type has preelaborable
9956 -- initialization. Note that this only occurs when the
9957 -- association's corresponding component does not have a
9958 -- default expression, the latter case having already been
9959 -- expanded as an expression for the association.
9961 if Box_Present (Assn) then
9962 if not Has_Preelaborable_Initialization (Comp_Type) then
9963 return False;
9964 end if;
9966 -- In the expression case we check whether the expression
9967 -- is preelaborable.
9969 elsif
9970 not Is_Preelaborable_Expression (Expression (Assn))
9971 then
9972 return False;
9973 end if;
9975 Next (Assn);
9976 end loop;
9978 -- If we get here then aggregate as a whole is preelaborable
9980 return True;
9982 -- All other cases are not preelaborable
9984 else
9985 return False;
9986 end if;
9987 end Is_Preelaborable_Expression;
9989 -- Start of processing for Check_Components
9991 begin
9992 -- Loop through entities of record or protected type
9994 Ent := E;
9995 while Present (Ent) loop
9997 -- We are interested only in components and discriminants
9999 Exp := Empty;
10001 case Ekind (Ent) is
10002 when E_Component =>
10004 -- Get default expression if any. If there is no declaration
10005 -- node, it means we have an internal entity. The parent and
10006 -- tag fields are examples of such entities. For such cases,
10007 -- we just test the type of the entity.
10009 if Present (Declaration_Node (Ent)) then
10010 Exp := Expression (Declaration_Node (Ent));
10011 end if;
10013 when E_Discriminant =>
10015 -- Note: for a renamed discriminant, the Declaration_Node
10016 -- may point to the one from the ancestor, and have a
10017 -- different expression, so use the proper attribute to
10018 -- retrieve the expression from the derived constraint.
10020 Exp := Discriminant_Default_Value (Ent);
10022 when others =>
10023 goto Check_Next_Entity;
10024 end case;
10026 -- A component has PI if it has no default expression and the
10027 -- component type has PI.
10029 if No (Exp) then
10030 if not Has_Preelaborable_Initialization (Etype (Ent)) then
10031 Has_PE := False;
10032 exit;
10033 end if;
10035 -- Require the default expression to be preelaborable
10037 elsif not Is_Preelaborable_Expression (Exp) then
10038 Has_PE := False;
10039 exit;
10040 end if;
10042 <<Check_Next_Entity>>
10043 Next_Entity (Ent);
10044 end loop;
10045 end Check_Components;
10047 -- Start of processing for Has_Preelaborable_Initialization
10049 begin
10050 -- Immediate return if already marked as known preelaborable init. This
10051 -- covers types for which this function has already been called once
10052 -- and returned True (in which case the result is cached), and also
10053 -- types to which a pragma Preelaborable_Initialization applies.
10055 if Known_To_Have_Preelab_Init (E) then
10056 return True;
10057 end if;
10059 -- If the type is a subtype representing a generic actual type, then
10060 -- test whether its base type has preelaborable initialization since
10061 -- the subtype representing the actual does not inherit this attribute
10062 -- from the actual or formal. (but maybe it should???)
10064 if Is_Generic_Actual_Type (E) then
10065 return Has_Preelaborable_Initialization (Base_Type (E));
10066 end if;
10068 -- All elementary types have preelaborable initialization
10070 if Is_Elementary_Type (E) then
10071 Has_PE := True;
10073 -- Array types have PI if the component type has PI
10075 elsif Is_Array_Type (E) then
10076 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
10078 -- A derived type has preelaborable initialization if its parent type
10079 -- has preelaborable initialization and (in the case of a derived record
10080 -- extension) if the non-inherited components all have preelaborable
10081 -- initialization. However, a user-defined controlled type with an
10082 -- overriding Initialize procedure does not have preelaborable
10083 -- initialization.
10085 elsif Is_Derived_Type (E) then
10087 -- If the derived type is a private extension then it doesn't have
10088 -- preelaborable initialization.
10090 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
10091 return False;
10092 end if;
10094 -- First check whether ancestor type has preelaborable initialization
10096 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
10098 -- If OK, check extension components (if any)
10100 if Has_PE and then Is_Record_Type (E) then
10101 Check_Components (First_Entity (E));
10102 end if;
10104 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
10105 -- with a user defined Initialize procedure does not have PI. If
10106 -- the type is untagged, the control primitives come from a component
10107 -- that has already been checked.
10109 if Has_PE
10110 and then Is_Controlled (E)
10111 and then Is_Tagged_Type (E)
10112 and then Has_Overriding_Initialize (E)
10113 then
10114 Has_PE := False;
10115 end if;
10117 -- Private types not derived from a type having preelaborable init and
10118 -- that are not marked with pragma Preelaborable_Initialization do not
10119 -- have preelaborable initialization.
10121 elsif Is_Private_Type (E) then
10122 return False;
10124 -- Record type has PI if it is non private and all components have PI
10126 elsif Is_Record_Type (E) then
10127 Has_PE := True;
10128 Check_Components (First_Entity (E));
10130 -- Protected types must not have entries, and components must meet
10131 -- same set of rules as for record components.
10133 elsif Is_Protected_Type (E) then
10134 if Has_Entries (E) then
10135 Has_PE := False;
10136 else
10137 Has_PE := True;
10138 Check_Components (First_Entity (E));
10139 Check_Components (First_Private_Entity (E));
10140 end if;
10142 -- Type System.Address always has preelaborable initialization
10144 elsif Is_RTE (E, RE_Address) then
10145 Has_PE := True;
10147 -- In all other cases, type does not have preelaborable initialization
10149 else
10150 return False;
10151 end if;
10153 -- If type has preelaborable initialization, cache result
10155 if Has_PE then
10156 Set_Known_To_Have_Preelab_Init (E);
10157 end if;
10159 return Has_PE;
10160 end Has_Preelaborable_Initialization;
10162 ---------------------------
10163 -- Has_Private_Component --
10164 ---------------------------
10166 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
10167 Btype : Entity_Id := Base_Type (Type_Id);
10168 Component : Entity_Id;
10170 begin
10171 if Error_Posted (Type_Id)
10172 or else Error_Posted (Btype)
10173 then
10174 return False;
10175 end if;
10177 if Is_Class_Wide_Type (Btype) then
10178 Btype := Root_Type (Btype);
10179 end if;
10181 if Is_Private_Type (Btype) then
10182 declare
10183 UT : constant Entity_Id := Underlying_Type (Btype);
10184 begin
10185 if No (UT) then
10186 if No (Full_View (Btype)) then
10187 return not Is_Generic_Type (Btype)
10188 and then
10189 not Is_Generic_Type (Root_Type (Btype));
10190 else
10191 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
10192 end if;
10193 else
10194 return not Is_Frozen (UT) and then Has_Private_Component (UT);
10195 end if;
10196 end;
10198 elsif Is_Array_Type (Btype) then
10199 return Has_Private_Component (Component_Type (Btype));
10201 elsif Is_Record_Type (Btype) then
10202 Component := First_Component (Btype);
10203 while Present (Component) loop
10204 if Has_Private_Component (Etype (Component)) then
10205 return True;
10206 end if;
10208 Next_Component (Component);
10209 end loop;
10211 return False;
10213 elsif Is_Protected_Type (Btype)
10214 and then Present (Corresponding_Record_Type (Btype))
10215 then
10216 return Has_Private_Component (Corresponding_Record_Type (Btype));
10218 else
10219 return False;
10220 end if;
10221 end Has_Private_Component;
10223 ----------------------
10224 -- Has_Signed_Zeros --
10225 ----------------------
10227 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
10228 begin
10229 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
10230 end Has_Signed_Zeros;
10232 ------------------------------
10233 -- Has_Significant_Contract --
10234 ------------------------------
10236 function Has_Significant_Contract (Subp_Id : Entity_Id) return Boolean is
10237 Subp_Nam : constant Name_Id := Chars (Subp_Id);
10239 begin
10240 -- _Finalizer procedure
10242 if Subp_Nam = Name_uFinalizer then
10243 return False;
10245 -- _Postconditions procedure
10247 elsif Subp_Nam = Name_uPostconditions then
10248 return False;
10250 -- Predicate function
10252 elsif Ekind (Subp_Id) = E_Function
10253 and then Is_Predicate_Function (Subp_Id)
10254 then
10255 return False;
10257 -- TSS subprogram
10259 elsif Get_TSS_Name (Subp_Id) /= TSS_Null then
10260 return False;
10262 else
10263 return True;
10264 end if;
10265 end Has_Significant_Contract;
10267 -----------------------------
10268 -- Has_Static_Array_Bounds --
10269 -----------------------------
10271 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
10272 Ndims : constant Nat := Number_Dimensions (Typ);
10274 Index : Node_Id;
10275 Low : Node_Id;
10276 High : Node_Id;
10278 begin
10279 -- Unconstrained types do not have static bounds
10281 if not Is_Constrained (Typ) then
10282 return False;
10283 end if;
10285 -- First treat string literals specially, as the lower bound and length
10286 -- of string literals are not stored like those of arrays.
10288 -- A string literal always has static bounds
10290 if Ekind (Typ) = E_String_Literal_Subtype then
10291 return True;
10292 end if;
10294 -- Treat all dimensions in turn
10296 Index := First_Index (Typ);
10297 for Indx in 1 .. Ndims loop
10299 -- In case of an illegal index which is not a discrete type, return
10300 -- that the type is not static.
10302 if not Is_Discrete_Type (Etype (Index))
10303 or else Etype (Index) = Any_Type
10304 then
10305 return False;
10306 end if;
10308 Get_Index_Bounds (Index, Low, High);
10310 if Error_Posted (Low) or else Error_Posted (High) then
10311 return False;
10312 end if;
10314 if Is_OK_Static_Expression (Low)
10315 and then
10316 Is_OK_Static_Expression (High)
10317 then
10318 null;
10319 else
10320 return False;
10321 end if;
10323 Next (Index);
10324 end loop;
10326 -- If we fall through the loop, all indexes matched
10328 return True;
10329 end Has_Static_Array_Bounds;
10331 ----------------
10332 -- Has_Stream --
10333 ----------------
10335 function Has_Stream (T : Entity_Id) return Boolean is
10336 E : Entity_Id;
10338 begin
10339 if No (T) then
10340 return False;
10342 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
10343 return True;
10345 elsif Is_Array_Type (T) then
10346 return Has_Stream (Component_Type (T));
10348 elsif Is_Record_Type (T) then
10349 E := First_Component (T);
10350 while Present (E) loop
10351 if Has_Stream (Etype (E)) then
10352 return True;
10353 else
10354 Next_Component (E);
10355 end if;
10356 end loop;
10358 return False;
10360 elsif Is_Private_Type (T) then
10361 return Has_Stream (Underlying_Type (T));
10363 else
10364 return False;
10365 end if;
10366 end Has_Stream;
10368 ----------------
10369 -- Has_Suffix --
10370 ----------------
10372 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
10373 begin
10374 Get_Name_String (Chars (E));
10375 return Name_Buffer (Name_Len) = Suffix;
10376 end Has_Suffix;
10378 ----------------
10379 -- Add_Suffix --
10380 ----------------
10382 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10383 begin
10384 Get_Name_String (Chars (E));
10385 Add_Char_To_Name_Buffer (Suffix);
10386 return Name_Find;
10387 end Add_Suffix;
10389 -------------------
10390 -- Remove_Suffix --
10391 -------------------
10393 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
10394 begin
10395 pragma Assert (Has_Suffix (E, Suffix));
10396 Get_Name_String (Chars (E));
10397 Name_Len := Name_Len - 1;
10398 return Name_Find;
10399 end Remove_Suffix;
10401 ----------------------------------
10402 -- Replace_Null_By_Null_Address --
10403 ----------------------------------
10405 procedure Replace_Null_By_Null_Address (N : Node_Id) is
10406 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id);
10407 -- Replace operand Op with a reference to Null_Address when the operand
10408 -- denotes a null Address. Other_Op denotes the other operand.
10410 --------------------------
10411 -- Replace_Null_Operand --
10412 --------------------------
10414 procedure Replace_Null_Operand (Op : Node_Id; Other_Op : Node_Id) is
10415 begin
10416 -- Check the type of the complementary operand since the N_Null node
10417 -- has not been decorated yet.
10419 if Nkind (Op) = N_Null
10420 and then Is_Descendant_Of_Address (Etype (Other_Op))
10421 then
10422 Rewrite (Op, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (Op)));
10423 end if;
10424 end Replace_Null_Operand;
10426 -- Start of processing for Replace_Null_By_Null_Address
10428 begin
10429 pragma Assert (Relaxed_RM_Semantics);
10430 pragma Assert (Nkind_In (N, N_Null,
10431 N_Op_Eq,
10432 N_Op_Ge,
10433 N_Op_Gt,
10434 N_Op_Le,
10435 N_Op_Lt,
10436 N_Op_Ne));
10438 if Nkind (N) = N_Null then
10439 Rewrite (N, New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
10441 else
10442 declare
10443 L : constant Node_Id := Left_Opnd (N);
10444 R : constant Node_Id := Right_Opnd (N);
10446 begin
10447 Replace_Null_Operand (L, Other_Op => R);
10448 Replace_Null_Operand (R, Other_Op => L);
10449 end;
10450 end if;
10451 end Replace_Null_By_Null_Address;
10453 --------------------------
10454 -- Has_Tagged_Component --
10455 --------------------------
10457 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
10458 Comp : Entity_Id;
10460 begin
10461 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
10462 return Has_Tagged_Component (Underlying_Type (Typ));
10464 elsif Is_Array_Type (Typ) then
10465 return Has_Tagged_Component (Component_Type (Typ));
10467 elsif Is_Tagged_Type (Typ) then
10468 return True;
10470 elsif Is_Record_Type (Typ) then
10471 Comp := First_Component (Typ);
10472 while Present (Comp) loop
10473 if Has_Tagged_Component (Etype (Comp)) then
10474 return True;
10475 end if;
10477 Next_Component (Comp);
10478 end loop;
10480 return False;
10482 else
10483 return False;
10484 end if;
10485 end Has_Tagged_Component;
10487 -----------------------------
10488 -- Has_Undefined_Reference --
10489 -----------------------------
10491 function Has_Undefined_Reference (Expr : Node_Id) return Boolean is
10492 Has_Undef_Ref : Boolean := False;
10493 -- Flag set when expression Expr contains at least one undefined
10494 -- reference.
10496 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result;
10497 -- Determine whether N denotes a reference and if it does, whether it is
10498 -- undefined.
10500 ----------------------------
10501 -- Is_Undefined_Reference --
10502 ----------------------------
10504 function Is_Undefined_Reference (N : Node_Id) return Traverse_Result is
10505 begin
10506 if Is_Entity_Name (N)
10507 and then Present (Entity (N))
10508 and then Entity (N) = Any_Id
10509 then
10510 Has_Undef_Ref := True;
10511 return Abandon;
10512 end if;
10514 return OK;
10515 end Is_Undefined_Reference;
10517 procedure Find_Undefined_References is
10518 new Traverse_Proc (Is_Undefined_Reference);
10520 -- Start of processing for Has_Undefined_Reference
10522 begin
10523 Find_Undefined_References (Expr);
10525 return Has_Undef_Ref;
10526 end Has_Undefined_Reference;
10528 ----------------------------
10529 -- Has_Volatile_Component --
10530 ----------------------------
10532 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
10533 Comp : Entity_Id;
10535 begin
10536 if Has_Volatile_Components (Typ) then
10537 return True;
10539 elsif Is_Array_Type (Typ) then
10540 return Is_Volatile (Component_Type (Typ));
10542 elsif Is_Record_Type (Typ) then
10543 Comp := First_Component (Typ);
10544 while Present (Comp) loop
10545 if Is_Volatile_Object (Comp) then
10546 return True;
10547 end if;
10549 Comp := Next_Component (Comp);
10550 end loop;
10551 end if;
10553 return False;
10554 end Has_Volatile_Component;
10556 -------------------------
10557 -- Implementation_Kind --
10558 -------------------------
10560 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
10561 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
10562 Arg : Node_Id;
10563 begin
10564 pragma Assert (Present (Impl_Prag));
10565 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
10566 return Chars (Get_Pragma_Arg (Arg));
10567 end Implementation_Kind;
10569 --------------------------
10570 -- Implements_Interface --
10571 --------------------------
10573 function Implements_Interface
10574 (Typ_Ent : Entity_Id;
10575 Iface_Ent : Entity_Id;
10576 Exclude_Parents : Boolean := False) return Boolean
10578 Ifaces_List : Elist_Id;
10579 Elmt : Elmt_Id;
10580 Iface : Entity_Id := Base_Type (Iface_Ent);
10581 Typ : Entity_Id := Base_Type (Typ_Ent);
10583 begin
10584 if Is_Class_Wide_Type (Typ) then
10585 Typ := Root_Type (Typ);
10586 end if;
10588 if not Has_Interfaces (Typ) then
10589 return False;
10590 end if;
10592 if Is_Class_Wide_Type (Iface) then
10593 Iface := Root_Type (Iface);
10594 end if;
10596 Collect_Interfaces (Typ, Ifaces_List);
10598 Elmt := First_Elmt (Ifaces_List);
10599 while Present (Elmt) loop
10600 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
10601 and then Exclude_Parents
10602 then
10603 null;
10605 elsif Node (Elmt) = Iface then
10606 return True;
10607 end if;
10609 Next_Elmt (Elmt);
10610 end loop;
10612 return False;
10613 end Implements_Interface;
10615 ------------------------------------
10616 -- In_Assertion_Expression_Pragma --
10617 ------------------------------------
10619 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
10620 Par : Node_Id;
10621 Prag : Node_Id := Empty;
10623 begin
10624 -- Climb the parent chain looking for an enclosing pragma
10626 Par := N;
10627 while Present (Par) loop
10628 if Nkind (Par) = N_Pragma then
10629 Prag := Par;
10630 exit;
10632 -- Precondition-like pragmas are expanded into if statements, check
10633 -- the original node instead.
10635 elsif Nkind (Original_Node (Par)) = N_Pragma then
10636 Prag := Original_Node (Par);
10637 exit;
10639 -- The expansion of attribute 'Old generates a constant to capture
10640 -- the result of the prefix. If the parent traversal reaches
10641 -- one of these constants, then the node technically came from a
10642 -- postcondition-like pragma. Note that the Ekind is not tested here
10643 -- because N may be the expression of an object declaration which is
10644 -- currently being analyzed. Such objects carry Ekind of E_Void.
10646 elsif Nkind (Par) = N_Object_Declaration
10647 and then Constant_Present (Par)
10648 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
10649 then
10650 return True;
10652 -- Prevent the search from going too far
10654 elsif Is_Body_Or_Package_Declaration (Par) then
10655 return False;
10656 end if;
10658 Par := Parent (Par);
10659 end loop;
10661 return
10662 Present (Prag)
10663 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
10664 end In_Assertion_Expression_Pragma;
10666 ----------------------
10667 -- In_Generic_Scope --
10668 ----------------------
10670 function In_Generic_Scope (E : Entity_Id) return Boolean is
10671 S : Entity_Id;
10673 begin
10674 S := Scope (E);
10675 while Present (S) and then S /= Standard_Standard loop
10676 if Is_Generic_Unit (S) then
10677 return True;
10678 end if;
10680 S := Scope (S);
10681 end loop;
10683 return False;
10684 end In_Generic_Scope;
10686 -----------------
10687 -- In_Instance --
10688 -----------------
10690 function In_Instance return Boolean is
10691 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
10692 S : Entity_Id;
10694 begin
10695 S := Current_Scope;
10696 while Present (S) and then S /= Standard_Standard loop
10697 if Ekind_In (S, E_Function, E_Package, E_Procedure)
10698 and then Is_Generic_Instance (S)
10699 then
10700 -- A child instance is always compiled in the context of a parent
10701 -- instance. Nevertheless, the actuals are not analyzed in an
10702 -- instance context. We detect this case by examining the current
10703 -- compilation unit, which must be a child instance, and checking
10704 -- that it is not currently on the scope stack.
10706 if Is_Child_Unit (Curr_Unit)
10707 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
10708 N_Package_Instantiation
10709 and then not In_Open_Scopes (Curr_Unit)
10710 then
10711 return False;
10712 else
10713 return True;
10714 end if;
10715 end if;
10717 S := Scope (S);
10718 end loop;
10720 return False;
10721 end In_Instance;
10723 ----------------------
10724 -- In_Instance_Body --
10725 ----------------------
10727 function In_Instance_Body return Boolean is
10728 S : Entity_Id;
10730 begin
10731 S := Current_Scope;
10732 while Present (S) and then S /= Standard_Standard loop
10733 if Ekind_In (S, E_Function, E_Procedure)
10734 and then Is_Generic_Instance (S)
10735 then
10736 return True;
10738 elsif Ekind (S) = E_Package
10739 and then In_Package_Body (S)
10740 and then Is_Generic_Instance (S)
10741 then
10742 return True;
10743 end if;
10745 S := Scope (S);
10746 end loop;
10748 return False;
10749 end In_Instance_Body;
10751 -----------------------------
10752 -- In_Instance_Not_Visible --
10753 -----------------------------
10755 function In_Instance_Not_Visible return Boolean is
10756 S : Entity_Id;
10758 begin
10759 S := Current_Scope;
10760 while Present (S) and then S /= Standard_Standard loop
10761 if Ekind_In (S, E_Function, E_Procedure)
10762 and then Is_Generic_Instance (S)
10763 then
10764 return True;
10766 elsif Ekind (S) = E_Package
10767 and then (In_Package_Body (S) or else In_Private_Part (S))
10768 and then Is_Generic_Instance (S)
10769 then
10770 return True;
10771 end if;
10773 S := Scope (S);
10774 end loop;
10776 return False;
10777 end In_Instance_Not_Visible;
10779 ------------------------------
10780 -- In_Instance_Visible_Part --
10781 ------------------------------
10783 function In_Instance_Visible_Part return Boolean is
10784 S : Entity_Id;
10786 begin
10787 S := Current_Scope;
10788 while Present (S) and then S /= Standard_Standard loop
10789 if Ekind (S) = E_Package
10790 and then Is_Generic_Instance (S)
10791 and then not In_Package_Body (S)
10792 and then not In_Private_Part (S)
10793 then
10794 return True;
10795 end if;
10797 S := Scope (S);
10798 end loop;
10800 return False;
10801 end In_Instance_Visible_Part;
10803 ---------------------
10804 -- In_Package_Body --
10805 ---------------------
10807 function In_Package_Body return Boolean is
10808 S : Entity_Id;
10810 begin
10811 S := Current_Scope;
10812 while Present (S) and then S /= Standard_Standard loop
10813 if Ekind (S) = E_Package and then In_Package_Body (S) then
10814 return True;
10815 else
10816 S := Scope (S);
10817 end if;
10818 end loop;
10820 return False;
10821 end In_Package_Body;
10823 --------------------------------
10824 -- In_Parameter_Specification --
10825 --------------------------------
10827 function In_Parameter_Specification (N : Node_Id) return Boolean is
10828 PN : Node_Id;
10830 begin
10831 PN := Parent (N);
10832 while Present (PN) loop
10833 if Nkind (PN) = N_Parameter_Specification then
10834 return True;
10835 end if;
10837 PN := Parent (PN);
10838 end loop;
10840 return False;
10841 end In_Parameter_Specification;
10843 --------------------------
10844 -- In_Pragma_Expression --
10845 --------------------------
10847 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
10848 P : Node_Id;
10849 begin
10850 P := Parent (N);
10851 loop
10852 if No (P) then
10853 return False;
10854 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
10855 return True;
10856 else
10857 P := Parent (P);
10858 end if;
10859 end loop;
10860 end In_Pragma_Expression;
10862 ---------------------------
10863 -- In_Pre_Post_Condition --
10864 ---------------------------
10866 function In_Pre_Post_Condition (N : Node_Id) return Boolean is
10867 Par : Node_Id;
10868 Prag : Node_Id := Empty;
10869 Prag_Id : Pragma_Id;
10871 begin
10872 -- Climb the parent chain looking for an enclosing pragma
10874 Par := N;
10875 while Present (Par) loop
10876 if Nkind (Par) = N_Pragma then
10877 Prag := Par;
10878 exit;
10880 -- Prevent the search from going too far
10882 elsif Is_Body_Or_Package_Declaration (Par) then
10883 exit;
10884 end if;
10886 Par := Parent (Par);
10887 end loop;
10889 if Present (Prag) then
10890 Prag_Id := Get_Pragma_Id (Prag);
10892 return
10893 Prag_Id = Pragma_Post
10894 or else Prag_Id = Pragma_Post_Class
10895 or else Prag_Id = Pragma_Postcondition
10896 or else Prag_Id = Pragma_Pre
10897 or else Prag_Id = Pragma_Pre_Class
10898 or else Prag_Id = Pragma_Precondition;
10900 -- Otherwise the node is not enclosed by a pre/postcondition pragma
10902 else
10903 return False;
10904 end if;
10905 end In_Pre_Post_Condition;
10907 -------------------------------------
10908 -- In_Reverse_Storage_Order_Object --
10909 -------------------------------------
10911 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
10912 Pref : Node_Id;
10913 Btyp : Entity_Id := Empty;
10915 begin
10916 -- Climb up indexed components
10918 Pref := N;
10919 loop
10920 case Nkind (Pref) is
10921 when N_Selected_Component =>
10922 Pref := Prefix (Pref);
10923 exit;
10925 when N_Indexed_Component =>
10926 Pref := Prefix (Pref);
10928 when others =>
10929 Pref := Empty;
10930 exit;
10931 end case;
10932 end loop;
10934 if Present (Pref) then
10935 Btyp := Base_Type (Etype (Pref));
10936 end if;
10938 return Present (Btyp)
10939 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
10940 and then Reverse_Storage_Order (Btyp);
10941 end In_Reverse_Storage_Order_Object;
10943 --------------------------------------
10944 -- In_Subprogram_Or_Concurrent_Unit --
10945 --------------------------------------
10947 function In_Subprogram_Or_Concurrent_Unit return Boolean is
10948 E : Entity_Id;
10949 K : Entity_Kind;
10951 begin
10952 -- Use scope chain to check successively outer scopes
10954 E := Current_Scope;
10955 loop
10956 K := Ekind (E);
10958 if K in Subprogram_Kind
10959 or else K in Concurrent_Kind
10960 or else K in Generic_Subprogram_Kind
10961 then
10962 return True;
10964 elsif E = Standard_Standard then
10965 return False;
10966 end if;
10968 E := Scope (E);
10969 end loop;
10970 end In_Subprogram_Or_Concurrent_Unit;
10972 ---------------------
10973 -- In_Visible_Part --
10974 ---------------------
10976 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
10977 begin
10978 return Is_Package_Or_Generic_Package (Scope_Id)
10979 and then In_Open_Scopes (Scope_Id)
10980 and then not In_Package_Body (Scope_Id)
10981 and then not In_Private_Part (Scope_Id);
10982 end In_Visible_Part;
10984 --------------------------------
10985 -- Incomplete_Or_Partial_View --
10986 --------------------------------
10988 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
10989 function Inspect_Decls
10990 (Decls : List_Id;
10991 Taft : Boolean := False) return Entity_Id;
10992 -- Check whether a declarative region contains the incomplete or partial
10993 -- view of Id.
10995 -------------------
10996 -- Inspect_Decls --
10997 -------------------
10999 function Inspect_Decls
11000 (Decls : List_Id;
11001 Taft : Boolean := False) return Entity_Id
11003 Decl : Node_Id;
11004 Match : Node_Id;
11006 begin
11007 Decl := First (Decls);
11008 while Present (Decl) loop
11009 Match := Empty;
11011 -- The partial view of a Taft-amendment type is an incomplete
11012 -- type.
11014 if Taft then
11015 if Nkind (Decl) = N_Incomplete_Type_Declaration then
11016 Match := Defining_Identifier (Decl);
11017 end if;
11019 -- Otherwise look for a private type whose full view matches the
11020 -- input type. Note that this checks full_type_declaration nodes
11021 -- to account for derivations from a private type where the type
11022 -- declaration hold the partial view and the full view is an
11023 -- itype.
11025 elsif Nkind_In (Decl, N_Full_Type_Declaration,
11026 N_Private_Extension_Declaration,
11027 N_Private_Type_Declaration)
11028 then
11029 Match := Defining_Identifier (Decl);
11030 end if;
11032 -- Guard against unanalyzed entities
11034 if Present (Match)
11035 and then Is_Type (Match)
11036 and then Present (Full_View (Match))
11037 and then Full_View (Match) = Id
11038 then
11039 return Match;
11040 end if;
11042 Next (Decl);
11043 end loop;
11045 return Empty;
11046 end Inspect_Decls;
11048 -- Local variables
11050 Prev : Entity_Id;
11052 -- Start of processing for Incomplete_Or_Partial_View
11054 begin
11055 -- Deferred constant or incomplete type case
11057 Prev := Current_Entity_In_Scope (Id);
11059 if Present (Prev)
11060 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
11061 and then Present (Full_View (Prev))
11062 and then Full_View (Prev) = Id
11063 then
11064 return Prev;
11065 end if;
11067 -- Private or Taft amendment type case
11069 declare
11070 Pkg : constant Entity_Id := Scope (Id);
11071 Pkg_Decl : Node_Id := Pkg;
11073 begin
11074 if Present (Pkg)
11075 and then Ekind_In (Pkg, E_Generic_Package, E_Package)
11076 then
11077 while Nkind (Pkg_Decl) /= N_Package_Specification loop
11078 Pkg_Decl := Parent (Pkg_Decl);
11079 end loop;
11081 -- It is knows that Typ has a private view, look for it in the
11082 -- visible declarations of the enclosing scope. A special case
11083 -- of this is when the two views have been exchanged - the full
11084 -- appears earlier than the private.
11086 if Has_Private_Declaration (Id) then
11087 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
11089 -- Exchanged view case, look in the private declarations
11091 if No (Prev) then
11092 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
11093 end if;
11095 return Prev;
11097 -- Otherwise if this is the package body, then Typ is a potential
11098 -- Taft amendment type. The incomplete view should be located in
11099 -- the private declarations of the enclosing scope.
11101 elsif In_Package_Body (Pkg) then
11102 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
11103 end if;
11104 end if;
11105 end;
11107 -- The type has no incomplete or private view
11109 return Empty;
11110 end Incomplete_Or_Partial_View;
11112 ----------------------------------
11113 -- Indexed_Component_Bit_Offset --
11114 ----------------------------------
11116 function Indexed_Component_Bit_Offset (N : Node_Id) return Uint is
11117 Exp : constant Node_Id := First (Expressions (N));
11118 Typ : constant Entity_Id := Etype (Prefix (N));
11119 Off : constant Uint := Component_Size (Typ);
11120 Ind : Node_Id;
11122 begin
11123 -- Return early if the component size is not known or variable
11125 if Off = No_Uint or else Off < Uint_0 then
11126 return No_Uint;
11127 end if;
11129 -- Deal with the degenerate case of an empty component
11131 if Off = Uint_0 then
11132 return Off;
11133 end if;
11135 -- Check that both the index value and the low bound are known
11137 if not Compile_Time_Known_Value (Exp) then
11138 return No_Uint;
11139 end if;
11141 Ind := First_Index (Typ);
11142 if No (Ind) then
11143 return No_Uint;
11144 end if;
11146 if Nkind (Ind) = N_Subtype_Indication then
11147 Ind := Constraint (Ind);
11149 if Nkind (Ind) = N_Range_Constraint then
11150 Ind := Range_Expression (Ind);
11151 end if;
11152 end if;
11154 if Nkind (Ind) /= N_Range
11155 or else not Compile_Time_Known_Value (Low_Bound (Ind))
11156 then
11157 return No_Uint;
11158 end if;
11160 -- Return the scaled offset
11162 return Off * (Expr_Value (Exp) - Expr_Value (Low_Bound ((Ind))));
11163 end Indexed_Component_Bit_Offset;
11165 ----------------------------
11166 -- Inherit_Rep_Item_Chain --
11167 ----------------------------
11169 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
11170 Item : Node_Id;
11171 Next_Item : Node_Id;
11173 begin
11174 -- There are several inheritance scenarios to consider depending on
11175 -- whether both types have rep item chains and whether the destination
11176 -- type already inherits part of the source type's rep item chain.
11178 -- 1) The source type lacks a rep item chain
11179 -- From_Typ ---> Empty
11181 -- Typ --------> Item (or Empty)
11183 -- In this case inheritance cannot take place because there are no items
11184 -- to inherit.
11186 -- 2) The destination type lacks a rep item chain
11187 -- From_Typ ---> Item ---> ...
11189 -- Typ --------> Empty
11191 -- Inheritance takes place by setting the First_Rep_Item of the
11192 -- destination type to the First_Rep_Item of the source type.
11193 -- From_Typ ---> Item ---> ...
11194 -- ^
11195 -- Typ -----------+
11197 -- 3.1) Both source and destination types have at least one rep item.
11198 -- The destination type does NOT inherit a rep item from the source
11199 -- type.
11200 -- From_Typ ---> Item ---> Item
11202 -- Typ --------> Item ---> Item
11204 -- Inheritance takes place by setting the Next_Rep_Item of the last item
11205 -- of the destination type to the First_Rep_Item of the source type.
11206 -- From_Typ -------------------> Item ---> Item
11207 -- ^
11208 -- Typ --------> Item ---> Item --+
11210 -- 3.2) Both source and destination types have at least one rep item.
11211 -- The destination type DOES inherit part of the rep item chain of the
11212 -- source type.
11213 -- From_Typ ---> Item ---> Item ---> Item
11214 -- ^
11215 -- Typ --------> Item ------+
11217 -- This rare case arises when the full view of a private extension must
11218 -- inherit the rep item chain from the full view of its parent type and
11219 -- the full view of the parent type contains extra rep items. Currently
11220 -- only invariants may lead to such form of inheritance.
11222 -- type From_Typ is tagged private
11223 -- with Type_Invariant'Class => Item_2;
11225 -- type Typ is new From_Typ with private
11226 -- with Type_Invariant => Item_4;
11228 -- At this point the rep item chains contain the following items
11230 -- From_Typ -----------> Item_2 ---> Item_3
11231 -- ^
11232 -- Typ --------> Item_4 --+
11234 -- The full views of both types may introduce extra invariants
11236 -- type From_Typ is tagged null record
11237 -- with Type_Invariant => Item_1;
11239 -- type Typ is new From_Typ with null record;
11241 -- The full view of Typ would have to inherit any new rep items added to
11242 -- the full view of From_Typ.
11244 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
11245 -- ^
11246 -- Typ --------> Item_4 --+
11248 -- To achieve this form of inheritance, the destination type must first
11249 -- sever the link between its own rep chain and that of the source type,
11250 -- then inheritance 3.1 takes place.
11252 -- Case 1: The source type lacks a rep item chain
11254 if No (First_Rep_Item (From_Typ)) then
11255 return;
11257 -- Case 2: The destination type lacks a rep item chain
11259 elsif No (First_Rep_Item (Typ)) then
11260 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11262 -- Case 3: Both the source and destination types have at least one rep
11263 -- item. Traverse the rep item chain of the destination type to find the
11264 -- last rep item.
11266 else
11267 Item := Empty;
11268 Next_Item := First_Rep_Item (Typ);
11269 while Present (Next_Item) loop
11271 -- Detect a link between the destination type's rep chain and that
11272 -- of the source type. There are two possibilities:
11274 -- Variant 1
11275 -- Next_Item
11276 -- V
11277 -- From_Typ ---> Item_1 --->
11278 -- ^
11279 -- Typ -----------+
11281 -- Item is Empty
11283 -- Variant 2
11284 -- Next_Item
11285 -- V
11286 -- From_Typ ---> Item_1 ---> Item_2 --->
11287 -- ^
11288 -- Typ --------> Item_3 ------+
11289 -- ^
11290 -- Item
11292 if Has_Rep_Item (From_Typ, Next_Item) then
11293 exit;
11294 end if;
11296 Item := Next_Item;
11297 Next_Item := Next_Rep_Item (Next_Item);
11298 end loop;
11300 -- Inherit the source type's rep item chain
11302 if Present (Item) then
11303 Set_Next_Rep_Item (Item, First_Rep_Item (From_Typ));
11304 else
11305 Set_First_Rep_Item (Typ, First_Rep_Item (From_Typ));
11306 end if;
11307 end if;
11308 end Inherit_Rep_Item_Chain;
11310 ---------------------------------
11311 -- Insert_Explicit_Dereference --
11312 ---------------------------------
11314 procedure Insert_Explicit_Dereference (N : Node_Id) is
11315 New_Prefix : constant Node_Id := Relocate_Node (N);
11316 Ent : Entity_Id := Empty;
11317 Pref : Node_Id;
11318 I : Interp_Index;
11319 It : Interp;
11320 T : Entity_Id;
11322 begin
11323 Save_Interps (N, New_Prefix);
11325 Rewrite (N,
11326 Make_Explicit_Dereference (Sloc (Parent (N)),
11327 Prefix => New_Prefix));
11329 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
11331 if Is_Overloaded (New_Prefix) then
11333 -- The dereference is also overloaded, and its interpretations are
11334 -- the designated types of the interpretations of the original node.
11336 Set_Etype (N, Any_Type);
11338 Get_First_Interp (New_Prefix, I, It);
11339 while Present (It.Nam) loop
11340 T := It.Typ;
11342 if Is_Access_Type (T) then
11343 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
11344 end if;
11346 Get_Next_Interp (I, It);
11347 end loop;
11349 End_Interp_List;
11351 else
11352 -- Prefix is unambiguous: mark the original prefix (which might
11353 -- Come_From_Source) as a reference, since the new (relocated) one
11354 -- won't be taken into account.
11356 if Is_Entity_Name (New_Prefix) then
11357 Ent := Entity (New_Prefix);
11358 Pref := New_Prefix;
11360 -- For a retrieval of a subcomponent of some composite object,
11361 -- retrieve the ultimate entity if there is one.
11363 elsif Nkind_In (New_Prefix, N_Selected_Component,
11364 N_Indexed_Component)
11365 then
11366 Pref := Prefix (New_Prefix);
11367 while Present (Pref)
11368 and then Nkind_In (Pref, N_Selected_Component,
11369 N_Indexed_Component)
11370 loop
11371 Pref := Prefix (Pref);
11372 end loop;
11374 if Present (Pref) and then Is_Entity_Name (Pref) then
11375 Ent := Entity (Pref);
11376 end if;
11377 end if;
11379 -- Place the reference on the entity node
11381 if Present (Ent) then
11382 Generate_Reference (Ent, Pref);
11383 end if;
11384 end if;
11385 end Insert_Explicit_Dereference;
11387 ------------------------------------------
11388 -- Inspect_Deferred_Constant_Completion --
11389 ------------------------------------------
11391 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
11392 Decl : Node_Id;
11394 begin
11395 Decl := First (Decls);
11396 while Present (Decl) loop
11398 -- Deferred constant signature
11400 if Nkind (Decl) = N_Object_Declaration
11401 and then Constant_Present (Decl)
11402 and then No (Expression (Decl))
11404 -- No need to check internally generated constants
11406 and then Comes_From_Source (Decl)
11408 -- The constant is not completed. A full object declaration or a
11409 -- pragma Import complete a deferred constant.
11411 and then not Has_Completion (Defining_Identifier (Decl))
11412 then
11413 Error_Msg_N
11414 ("constant declaration requires initialization expression",
11415 Defining_Identifier (Decl));
11416 end if;
11418 Decl := Next (Decl);
11419 end loop;
11420 end Inspect_Deferred_Constant_Completion;
11422 -----------------------------
11423 -- Install_Generic_Formals --
11424 -----------------------------
11426 procedure Install_Generic_Formals (Subp_Id : Entity_Id) is
11427 E : Entity_Id;
11429 begin
11430 pragma Assert (Is_Generic_Subprogram (Subp_Id));
11432 E := First_Entity (Subp_Id);
11433 while Present (E) loop
11434 Install_Entity (E);
11435 Next_Entity (E);
11436 end loop;
11437 end Install_Generic_Formals;
11439 -----------------------------
11440 -- Is_Actual_Out_Parameter --
11441 -----------------------------
11443 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
11444 Formal : Entity_Id;
11445 Call : Node_Id;
11446 begin
11447 Find_Actual (N, Formal, Call);
11448 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
11449 end Is_Actual_Out_Parameter;
11451 -------------------------
11452 -- Is_Actual_Parameter --
11453 -------------------------
11455 function Is_Actual_Parameter (N : Node_Id) return Boolean is
11456 PK : constant Node_Kind := Nkind (Parent (N));
11458 begin
11459 case PK is
11460 when N_Parameter_Association =>
11461 return N = Explicit_Actual_Parameter (Parent (N));
11463 when N_Subprogram_Call =>
11464 return Is_List_Member (N)
11465 and then
11466 List_Containing (N) = Parameter_Associations (Parent (N));
11468 when others =>
11469 return False;
11470 end case;
11471 end Is_Actual_Parameter;
11473 --------------------------------
11474 -- Is_Actual_Tagged_Parameter --
11475 --------------------------------
11477 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
11478 Formal : Entity_Id;
11479 Call : Node_Id;
11480 begin
11481 Find_Actual (N, Formal, Call);
11482 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
11483 end Is_Actual_Tagged_Parameter;
11485 ---------------------
11486 -- Is_Aliased_View --
11487 ---------------------
11489 function Is_Aliased_View (Obj : Node_Id) return Boolean is
11490 E : Entity_Id;
11492 begin
11493 if Is_Entity_Name (Obj) then
11494 E := Entity (Obj);
11496 return
11497 (Is_Object (E)
11498 and then
11499 (Is_Aliased (E)
11500 or else (Present (Renamed_Object (E))
11501 and then Is_Aliased_View (Renamed_Object (E)))))
11503 or else ((Is_Formal (E)
11504 or else Ekind_In (E, E_Generic_In_Out_Parameter,
11505 E_Generic_In_Parameter))
11506 and then Is_Tagged_Type (Etype (E)))
11508 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
11510 -- Current instance of type, either directly or as rewritten
11511 -- reference to the current object.
11513 or else (Is_Entity_Name (Original_Node (Obj))
11514 and then Present (Entity (Original_Node (Obj)))
11515 and then Is_Type (Entity (Original_Node (Obj))))
11517 or else (Is_Type (E) and then E = Current_Scope)
11519 or else (Is_Incomplete_Or_Private_Type (E)
11520 and then Full_View (E) = Current_Scope)
11522 -- Ada 2012 AI05-0053: the return object of an extended return
11523 -- statement is aliased if its type is immutably limited.
11525 or else (Is_Return_Object (E)
11526 and then Is_Limited_View (Etype (E)));
11528 elsif Nkind (Obj) = N_Selected_Component then
11529 return Is_Aliased (Entity (Selector_Name (Obj)));
11531 elsif Nkind (Obj) = N_Indexed_Component then
11532 return Has_Aliased_Components (Etype (Prefix (Obj)))
11533 or else
11534 (Is_Access_Type (Etype (Prefix (Obj)))
11535 and then Has_Aliased_Components
11536 (Designated_Type (Etype (Prefix (Obj)))));
11538 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
11539 return Is_Tagged_Type (Etype (Obj))
11540 and then Is_Aliased_View (Expression (Obj));
11542 elsif Nkind (Obj) = N_Explicit_Dereference then
11543 return Nkind (Original_Node (Obj)) /= N_Function_Call;
11545 else
11546 return False;
11547 end if;
11548 end Is_Aliased_View;
11550 -------------------------
11551 -- Is_Ancestor_Package --
11552 -------------------------
11554 function Is_Ancestor_Package
11555 (E1 : Entity_Id;
11556 E2 : Entity_Id) return Boolean
11558 Par : Entity_Id;
11560 begin
11561 Par := E2;
11562 while Present (Par) and then Par /= Standard_Standard loop
11563 if Par = E1 then
11564 return True;
11565 end if;
11567 Par := Scope (Par);
11568 end loop;
11570 return False;
11571 end Is_Ancestor_Package;
11573 ----------------------
11574 -- Is_Atomic_Object --
11575 ----------------------
11577 function Is_Atomic_Object (N : Node_Id) return Boolean is
11579 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
11580 -- Determines if given object has atomic components
11582 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
11583 -- If prefix is an implicit dereference, examine designated type
11585 ----------------------
11586 -- Is_Atomic_Prefix --
11587 ----------------------
11589 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
11590 begin
11591 if Is_Access_Type (Etype (N)) then
11592 return
11593 Has_Atomic_Components (Designated_Type (Etype (N)));
11594 else
11595 return Object_Has_Atomic_Components (N);
11596 end if;
11597 end Is_Atomic_Prefix;
11599 ----------------------------------
11600 -- Object_Has_Atomic_Components --
11601 ----------------------------------
11603 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
11604 begin
11605 if Has_Atomic_Components (Etype (N))
11606 or else Is_Atomic (Etype (N))
11607 then
11608 return True;
11610 elsif Is_Entity_Name (N)
11611 and then (Has_Atomic_Components (Entity (N))
11612 or else Is_Atomic (Entity (N)))
11613 then
11614 return True;
11616 elsif Nkind (N) = N_Selected_Component
11617 and then Is_Atomic (Entity (Selector_Name (N)))
11618 then
11619 return True;
11621 elsif Nkind (N) = N_Indexed_Component
11622 or else Nkind (N) = N_Selected_Component
11623 then
11624 return Is_Atomic_Prefix (Prefix (N));
11626 else
11627 return False;
11628 end if;
11629 end Object_Has_Atomic_Components;
11631 -- Start of processing for Is_Atomic_Object
11633 begin
11634 -- Predicate is not relevant to subprograms
11636 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
11637 return False;
11639 elsif Is_Atomic (Etype (N))
11640 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
11641 then
11642 return True;
11644 elsif Nkind (N) = N_Selected_Component
11645 and then Is_Atomic (Entity (Selector_Name (N)))
11646 then
11647 return True;
11649 elsif Nkind (N) = N_Indexed_Component
11650 or else Nkind (N) = N_Selected_Component
11651 then
11652 return Is_Atomic_Prefix (Prefix (N));
11654 else
11655 return False;
11656 end if;
11657 end Is_Atomic_Object;
11659 -----------------------------
11660 -- Is_Atomic_Or_VFA_Object --
11661 -----------------------------
11663 function Is_Atomic_Or_VFA_Object (N : Node_Id) return Boolean is
11664 begin
11665 return Is_Atomic_Object (N)
11666 or else (Is_Object_Reference (N)
11667 and then Is_Entity_Name (N)
11668 and then (Is_Volatile_Full_Access (Entity (N))
11669 or else
11670 Is_Volatile_Full_Access (Etype (Entity (N)))));
11671 end Is_Atomic_Or_VFA_Object;
11673 -------------------------
11674 -- Is_Attribute_Result --
11675 -------------------------
11677 function Is_Attribute_Result (N : Node_Id) return Boolean is
11678 begin
11679 return Nkind (N) = N_Attribute_Reference
11680 and then Attribute_Name (N) = Name_Result;
11681 end Is_Attribute_Result;
11683 -------------------------
11684 -- Is_Attribute_Update --
11685 -------------------------
11687 function Is_Attribute_Update (N : Node_Id) return Boolean is
11688 begin
11689 return Nkind (N) = N_Attribute_Reference
11690 and then Attribute_Name (N) = Name_Update;
11691 end Is_Attribute_Update;
11693 ------------------------------------
11694 -- Is_Body_Or_Package_Declaration --
11695 ------------------------------------
11697 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
11698 begin
11699 return Nkind_In (N, N_Entry_Body,
11700 N_Package_Body,
11701 N_Package_Declaration,
11702 N_Protected_Body,
11703 N_Subprogram_Body,
11704 N_Task_Body);
11705 end Is_Body_Or_Package_Declaration;
11707 -----------------------
11708 -- Is_Bounded_String --
11709 -----------------------
11711 function Is_Bounded_String (T : Entity_Id) return Boolean is
11712 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
11714 begin
11715 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
11716 -- Super_String, or one of the [Wide_]Wide_ versions. This will
11717 -- be True for all the Bounded_String types in instances of the
11718 -- Generic_Bounded_Length generics, and for types derived from those.
11720 return Present (Under)
11721 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
11722 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
11723 Is_RTE (Root_Type (Under), RO_WW_Super_String));
11724 end Is_Bounded_String;
11726 -------------------------
11727 -- Is_Child_Or_Sibling --
11728 -------------------------
11730 function Is_Child_Or_Sibling
11731 (Pack_1 : Entity_Id;
11732 Pack_2 : Entity_Id) return Boolean
11734 function Distance_From_Standard (Pack : Entity_Id) return Nat;
11735 -- Given an arbitrary package, return the number of "climbs" necessary
11736 -- to reach scope Standard_Standard.
11738 procedure Equalize_Depths
11739 (Pack : in out Entity_Id;
11740 Depth : in out Nat;
11741 Depth_To_Reach : Nat);
11742 -- Given an arbitrary package, its depth and a target depth to reach,
11743 -- climb the scope chain until the said depth is reached. The pointer
11744 -- to the package and its depth a modified during the climb.
11746 ----------------------------
11747 -- Distance_From_Standard --
11748 ----------------------------
11750 function Distance_From_Standard (Pack : Entity_Id) return Nat is
11751 Dist : Nat;
11752 Scop : Entity_Id;
11754 begin
11755 Dist := 0;
11756 Scop := Pack;
11757 while Present (Scop) and then Scop /= Standard_Standard loop
11758 Dist := Dist + 1;
11759 Scop := Scope (Scop);
11760 end loop;
11762 return Dist;
11763 end Distance_From_Standard;
11765 ---------------------
11766 -- Equalize_Depths --
11767 ---------------------
11769 procedure Equalize_Depths
11770 (Pack : in out Entity_Id;
11771 Depth : in out Nat;
11772 Depth_To_Reach : Nat)
11774 begin
11775 -- The package must be at a greater or equal depth
11777 if Depth < Depth_To_Reach then
11778 raise Program_Error;
11779 end if;
11781 -- Climb the scope chain until the desired depth is reached
11783 while Present (Pack) and then Depth /= Depth_To_Reach loop
11784 Pack := Scope (Pack);
11785 Depth := Depth - 1;
11786 end loop;
11787 end Equalize_Depths;
11789 -- Local variables
11791 P_1 : Entity_Id := Pack_1;
11792 P_1_Child : Boolean := False;
11793 P_1_Depth : Nat := Distance_From_Standard (P_1);
11794 P_2 : Entity_Id := Pack_2;
11795 P_2_Child : Boolean := False;
11796 P_2_Depth : Nat := Distance_From_Standard (P_2);
11798 -- Start of processing for Is_Child_Or_Sibling
11800 begin
11801 pragma Assert
11802 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
11804 -- Both packages denote the same entity, therefore they cannot be
11805 -- children or siblings.
11807 if P_1 = P_2 then
11808 return False;
11810 -- One of the packages is at a deeper level than the other. Note that
11811 -- both may still come from differen hierarchies.
11813 -- (root) P_2
11814 -- / \ :
11815 -- X P_2 or X
11816 -- : :
11817 -- P_1 P_1
11819 elsif P_1_Depth > P_2_Depth then
11820 Equalize_Depths
11821 (Pack => P_1,
11822 Depth => P_1_Depth,
11823 Depth_To_Reach => P_2_Depth);
11824 P_1_Child := True;
11826 -- (root) P_1
11827 -- / \ :
11828 -- P_1 X or X
11829 -- : :
11830 -- P_2 P_2
11832 elsif P_2_Depth > P_1_Depth then
11833 Equalize_Depths
11834 (Pack => P_2,
11835 Depth => P_2_Depth,
11836 Depth_To_Reach => P_1_Depth);
11837 P_2_Child := True;
11838 end if;
11840 -- At this stage the package pointers have been elevated to the same
11841 -- depth. If the related entities are the same, then one package is a
11842 -- potential child of the other:
11844 -- P_1
11845 -- :
11846 -- X became P_1 P_2 or vica versa
11847 -- :
11848 -- P_2
11850 if P_1 = P_2 then
11851 if P_1_Child then
11852 return Is_Child_Unit (Pack_1);
11854 else pragma Assert (P_2_Child);
11855 return Is_Child_Unit (Pack_2);
11856 end if;
11858 -- The packages may come from the same package chain or from entirely
11859 -- different hierarcies. To determine this, climb the scope stack until
11860 -- a common root is found.
11862 -- (root) (root 1) (root 2)
11863 -- / \ | |
11864 -- P_1 P_2 P_1 P_2
11866 else
11867 while Present (P_1) and then Present (P_2) loop
11869 -- The two packages may be siblings
11871 if P_1 = P_2 then
11872 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
11873 end if;
11875 P_1 := Scope (P_1);
11876 P_2 := Scope (P_2);
11877 end loop;
11878 end if;
11880 return False;
11881 end Is_Child_Or_Sibling;
11883 -----------------------------
11884 -- Is_Concurrent_Interface --
11885 -----------------------------
11887 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
11888 begin
11889 return Is_Interface (T)
11890 and then
11891 (Is_Protected_Interface (T)
11892 or else Is_Synchronized_Interface (T)
11893 or else Is_Task_Interface (T));
11894 end Is_Concurrent_Interface;
11896 -----------------------
11897 -- Is_Constant_Bound --
11898 -----------------------
11900 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
11901 begin
11902 if Compile_Time_Known_Value (Exp) then
11903 return True;
11905 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
11906 return Is_Constant_Object (Entity (Exp))
11907 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
11909 elsif Nkind (Exp) in N_Binary_Op then
11910 return Is_Constant_Bound (Left_Opnd (Exp))
11911 and then Is_Constant_Bound (Right_Opnd (Exp))
11912 and then Scope (Entity (Exp)) = Standard_Standard;
11914 else
11915 return False;
11916 end if;
11917 end Is_Constant_Bound;
11919 ---------------------------
11920 -- Is_Container_Element --
11921 ---------------------------
11923 function Is_Container_Element (Exp : Node_Id) return Boolean is
11924 Loc : constant Source_Ptr := Sloc (Exp);
11925 Pref : constant Node_Id := Prefix (Exp);
11927 Call : Node_Id;
11928 -- Call to an indexing aspect
11930 Cont_Typ : Entity_Id;
11931 -- The type of the container being accessed
11933 Elem_Typ : Entity_Id;
11934 -- Its element type
11936 Indexing : Entity_Id;
11937 Is_Const : Boolean;
11938 -- Indicates that constant indexing is used, and the element is thus
11939 -- a constant.
11941 Ref_Typ : Entity_Id;
11942 -- The reference type returned by the indexing operation
11944 begin
11945 -- If C is a container, in a context that imposes the element type of
11946 -- that container, the indexing notation C (X) is rewritten as:
11948 -- Indexing (C, X).Discr.all
11950 -- where Indexing is one of the indexing aspects of the container.
11951 -- If the context does not require a reference, the construct can be
11952 -- rewritten as
11954 -- Element (C, X)
11956 -- First, verify that the construct has the proper form
11958 if not Expander_Active then
11959 return False;
11961 elsif Nkind (Pref) /= N_Selected_Component then
11962 return False;
11964 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
11965 return False;
11967 else
11968 Call := Prefix (Pref);
11969 Ref_Typ := Etype (Call);
11970 end if;
11972 if not Has_Implicit_Dereference (Ref_Typ)
11973 or else No (First (Parameter_Associations (Call)))
11974 or else not Is_Entity_Name (Name (Call))
11975 then
11976 return False;
11977 end if;
11979 -- Retrieve type of container object, and its iterator aspects
11981 Cont_Typ := Etype (First (Parameter_Associations (Call)));
11982 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
11983 Is_Const := False;
11985 if No (Indexing) then
11987 -- Container should have at least one indexing operation
11989 return False;
11991 elsif Entity (Name (Call)) /= Entity (Indexing) then
11993 -- This may be a variable indexing operation
11995 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
11997 if No (Indexing)
11998 or else Entity (Name (Call)) /= Entity (Indexing)
11999 then
12000 return False;
12001 end if;
12003 else
12004 Is_Const := True;
12005 end if;
12007 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
12009 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
12010 return False;
12011 end if;
12013 -- Check that the expression is not the target of an assignment, in
12014 -- which case the rewriting is not possible.
12016 if not Is_Const then
12017 declare
12018 Par : Node_Id;
12020 begin
12021 Par := Exp;
12022 while Present (Par)
12023 loop
12024 if Nkind (Parent (Par)) = N_Assignment_Statement
12025 and then Par = Name (Parent (Par))
12026 then
12027 return False;
12029 -- A renaming produces a reference, and the transformation
12030 -- does not apply.
12032 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
12033 return False;
12035 elsif Nkind_In
12036 (Nkind (Parent (Par)), N_Function_Call,
12037 N_Procedure_Call_Statement,
12038 N_Entry_Call_Statement)
12039 then
12040 -- Check that the element is not part of an actual for an
12041 -- in-out parameter.
12043 declare
12044 F : Entity_Id;
12045 A : Node_Id;
12047 begin
12048 F := First_Formal (Entity (Name (Parent (Par))));
12049 A := First (Parameter_Associations (Parent (Par)));
12050 while Present (F) loop
12051 if A = Par and then Ekind (F) /= E_In_Parameter then
12052 return False;
12053 end if;
12055 Next_Formal (F);
12056 Next (A);
12057 end loop;
12058 end;
12060 -- E_In_Parameter in a call: element is not modified.
12062 exit;
12063 end if;
12065 Par := Parent (Par);
12066 end loop;
12067 end;
12068 end if;
12070 -- The expression has the proper form and the context requires the
12071 -- element type. Retrieve the Element function of the container and
12072 -- rewrite the construct as a call to it.
12074 declare
12075 Op : Elmt_Id;
12077 begin
12078 Op := First_Elmt (Primitive_Operations (Cont_Typ));
12079 while Present (Op) loop
12080 exit when Chars (Node (Op)) = Name_Element;
12081 Next_Elmt (Op);
12082 end loop;
12084 if No (Op) then
12085 return False;
12087 else
12088 Rewrite (Exp,
12089 Make_Function_Call (Loc,
12090 Name => New_Occurrence_Of (Node (Op), Loc),
12091 Parameter_Associations => Parameter_Associations (Call)));
12092 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
12093 return True;
12094 end if;
12095 end;
12096 end Is_Container_Element;
12098 ----------------------------
12099 -- Is_Contract_Annotation --
12100 ----------------------------
12102 function Is_Contract_Annotation (Item : Node_Id) return Boolean is
12103 begin
12104 return Is_Package_Contract_Annotation (Item)
12105 or else
12106 Is_Subprogram_Contract_Annotation (Item);
12107 end Is_Contract_Annotation;
12109 --------------------------------------
12110 -- Is_Controlling_Limited_Procedure --
12111 --------------------------------------
12113 function Is_Controlling_Limited_Procedure
12114 (Proc_Nam : Entity_Id) return Boolean
12116 Param_Typ : Entity_Id := Empty;
12118 begin
12119 if Ekind (Proc_Nam) = E_Procedure
12120 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
12121 then
12122 Param_Typ := Etype (Parameter_Type (First (
12123 Parameter_Specifications (Parent (Proc_Nam)))));
12125 -- In this case where an Itype was created, the procedure call has been
12126 -- rewritten.
12128 elsif Present (Associated_Node_For_Itype (Proc_Nam))
12129 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
12130 and then
12131 Present (Parameter_Associations
12132 (Associated_Node_For_Itype (Proc_Nam)))
12133 then
12134 Param_Typ :=
12135 Etype (First (Parameter_Associations
12136 (Associated_Node_For_Itype (Proc_Nam))));
12137 end if;
12139 if Present (Param_Typ) then
12140 return
12141 Is_Interface (Param_Typ)
12142 and then Is_Limited_Record (Param_Typ);
12143 end if;
12145 return False;
12146 end Is_Controlling_Limited_Procedure;
12148 -----------------------------
12149 -- Is_CPP_Constructor_Call --
12150 -----------------------------
12152 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
12153 begin
12154 return Nkind (N) = N_Function_Call
12155 and then Is_CPP_Class (Etype (Etype (N)))
12156 and then Is_Constructor (Entity (Name (N)))
12157 and then Is_Imported (Entity (Name (N)));
12158 end Is_CPP_Constructor_Call;
12160 -------------------------
12161 -- Is_Current_Instance --
12162 -------------------------
12164 function Is_Current_Instance (N : Node_Id) return Boolean is
12165 Typ : constant Entity_Id := Entity (N);
12166 P : Node_Id;
12168 begin
12169 -- Simplest case: entity is a concurrent type and we are currently
12170 -- inside the body. This will eventually be expanded into a
12171 -- call to Self (for tasks) or _object (for protected objects).
12173 if Is_Concurrent_Type (Typ) and then In_Open_Scopes (Typ) then
12174 return True;
12176 else
12177 -- Check whether the context is a (sub)type declaration for the
12178 -- type entity.
12180 P := Parent (N);
12181 while Present (P) loop
12182 if Nkind_In (P, N_Full_Type_Declaration,
12183 N_Private_Type_Declaration,
12184 N_Subtype_Declaration)
12185 and then Comes_From_Source (P)
12186 and then Defining_Entity (P) = Typ
12187 then
12188 return True;
12190 -- A subtype name may appear in an aspect specification for a
12191 -- Predicate_Failure aspect, for which we do not construct a
12192 -- wrapper procedure. The subtype will be replaced by the
12193 -- expression being tested when the corresponding predicate
12194 -- check is expanded.
12196 elsif Nkind (P) = N_Aspect_Specification
12197 and then Nkind (Parent (P)) = N_Subtype_Declaration
12198 then
12199 return True;
12201 elsif Nkind (P) = N_Pragma
12202 and then
12203 Get_Pragma_Id (P) = Pragma_Predicate_Failure
12204 then
12205 return True;
12206 end if;
12208 P := Parent (P);
12209 end loop;
12210 end if;
12212 -- In any other context this is not a current occurrence
12214 return False;
12215 end Is_Current_Instance;
12217 --------------------
12218 -- Is_Declaration --
12219 --------------------
12221 function Is_Declaration (N : Node_Id) return Boolean is
12222 begin
12223 return
12224 Is_Declaration_Other_Than_Renaming (N)
12225 or else Is_Renaming_Declaration (N);
12226 end Is_Declaration;
12228 ----------------------------------------
12229 -- Is_Declaration_Other_Than_Renaming --
12230 ----------------------------------------
12232 function Is_Declaration_Other_Than_Renaming (N : Node_Id) return Boolean is
12233 begin
12234 case Nkind (N) is
12235 when N_Abstract_Subprogram_Declaration
12236 | N_Exception_Declaration
12237 | N_Expression_Function
12238 | N_Full_Type_Declaration
12239 | N_Generic_Package_Declaration
12240 | N_Generic_Subprogram_Declaration
12241 | N_Number_Declaration
12242 | N_Object_Declaration
12243 | N_Package_Declaration
12244 | N_Private_Extension_Declaration
12245 | N_Private_Type_Declaration
12246 | N_Subprogram_Declaration
12247 | N_Subtype_Declaration
12249 return True;
12251 when others =>
12252 return False;
12253 end case;
12254 end Is_Declaration_Other_Than_Renaming;
12256 --------------------------------
12257 -- Is_Declared_Within_Variant --
12258 --------------------------------
12260 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
12261 Comp_Decl : constant Node_Id := Parent (Comp);
12262 Comp_List : constant Node_Id := Parent (Comp_Decl);
12263 begin
12264 return Nkind (Parent (Comp_List)) = N_Variant;
12265 end Is_Declared_Within_Variant;
12267 ----------------------------------------------
12268 -- Is_Dependent_Component_Of_Mutable_Object --
12269 ----------------------------------------------
12271 function Is_Dependent_Component_Of_Mutable_Object
12272 (Object : Node_Id) return Boolean
12274 P : Node_Id;
12275 Prefix_Type : Entity_Id;
12276 P_Aliased : Boolean := False;
12277 Comp : Entity_Id;
12279 Deref : Node_Id := Object;
12280 -- Dereference node, in something like X.all.Y(2)
12282 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
12284 begin
12285 -- Find the dereference node if any
12287 while Nkind_In (Deref, N_Indexed_Component,
12288 N_Selected_Component,
12289 N_Slice)
12290 loop
12291 Deref := Prefix (Deref);
12292 end loop;
12294 -- Ada 2005: If we have a component or slice of a dereference,
12295 -- something like X.all.Y (2), and the type of X is access-to-constant,
12296 -- Is_Variable will return False, because it is indeed a constant
12297 -- view. But it might be a view of a variable object, so we want the
12298 -- following condition to be True in that case.
12300 if Is_Variable (Object)
12301 or else (Ada_Version >= Ada_2005
12302 and then Nkind (Deref) = N_Explicit_Dereference)
12303 then
12304 if Nkind (Object) = N_Selected_Component then
12305 P := Prefix (Object);
12306 Prefix_Type := Etype (P);
12308 if Is_Entity_Name (P) then
12309 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
12310 Prefix_Type := Base_Type (Prefix_Type);
12311 end if;
12313 if Is_Aliased (Entity (P)) then
12314 P_Aliased := True;
12315 end if;
12317 -- A discriminant check on a selected component may be expanded
12318 -- into a dereference when removing side-effects. Recover the
12319 -- original node and its type, which may be unconstrained.
12321 elsif Nkind (P) = N_Explicit_Dereference
12322 and then not (Comes_From_Source (P))
12323 then
12324 P := Original_Node (P);
12325 Prefix_Type := Etype (P);
12327 else
12328 -- Check for prefix being an aliased component???
12330 null;
12332 end if;
12334 -- A heap object is constrained by its initial value
12336 -- Ada 2005 (AI-363): Always assume the object could be mutable in
12337 -- the dereferenced case, since the access value might denote an
12338 -- unconstrained aliased object, whereas in Ada 95 the designated
12339 -- object is guaranteed to be constrained. A worst-case assumption
12340 -- has to apply in Ada 2005 because we can't tell at compile
12341 -- time whether the object is "constrained by its initial value"
12342 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
12343 -- rules (these rules are acknowledged to need fixing).
12345 if Ada_Version < Ada_2005 then
12346 if Is_Access_Type (Prefix_Type)
12347 or else Nkind (P) = N_Explicit_Dereference
12348 then
12349 return False;
12350 end if;
12352 else pragma Assert (Ada_Version >= Ada_2005);
12353 if Is_Access_Type (Prefix_Type) then
12355 -- If the access type is pool-specific, and there is no
12356 -- constrained partial view of the designated type, then the
12357 -- designated object is known to be constrained.
12359 if Ekind (Prefix_Type) = E_Access_Type
12360 and then not Object_Type_Has_Constrained_Partial_View
12361 (Typ => Designated_Type (Prefix_Type),
12362 Scop => Current_Scope)
12363 then
12364 return False;
12366 -- Otherwise (general access type, or there is a constrained
12367 -- partial view of the designated type), we need to check
12368 -- based on the designated type.
12370 else
12371 Prefix_Type := Designated_Type (Prefix_Type);
12372 end if;
12373 end if;
12374 end if;
12376 Comp :=
12377 Original_Record_Component (Entity (Selector_Name (Object)));
12379 -- As per AI-0017, the renaming is illegal in a generic body, even
12380 -- if the subtype is indefinite.
12382 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
12384 if not Is_Constrained (Prefix_Type)
12385 and then (Is_Definite_Subtype (Prefix_Type)
12386 or else
12387 (Is_Generic_Type (Prefix_Type)
12388 and then Ekind (Current_Scope) = E_Generic_Package
12389 and then In_Package_Body (Current_Scope)))
12391 and then (Is_Declared_Within_Variant (Comp)
12392 or else Has_Discriminant_Dependent_Constraint (Comp))
12393 and then (not P_Aliased or else Ada_Version >= Ada_2005)
12394 then
12395 return True;
12397 -- If the prefix is of an access type at this point, then we want
12398 -- to return False, rather than calling this function recursively
12399 -- on the access object (which itself might be a discriminant-
12400 -- dependent component of some other object, but that isn't
12401 -- relevant to checking the object passed to us). This avoids
12402 -- issuing wrong errors when compiling with -gnatc, where there
12403 -- can be implicit dereferences that have not been expanded.
12405 elsif Is_Access_Type (Etype (Prefix (Object))) then
12406 return False;
12408 else
12409 return
12410 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
12411 end if;
12413 elsif Nkind (Object) = N_Indexed_Component
12414 or else Nkind (Object) = N_Slice
12415 then
12416 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
12418 -- A type conversion that Is_Variable is a view conversion:
12419 -- go back to the denoted object.
12421 elsif Nkind (Object) = N_Type_Conversion then
12422 return
12423 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
12424 end if;
12425 end if;
12427 return False;
12428 end Is_Dependent_Component_Of_Mutable_Object;
12430 ---------------------
12431 -- Is_Dereferenced --
12432 ---------------------
12434 function Is_Dereferenced (N : Node_Id) return Boolean is
12435 P : constant Node_Id := Parent (N);
12436 begin
12437 return Nkind_In (P, N_Selected_Component,
12438 N_Explicit_Dereference,
12439 N_Indexed_Component,
12440 N_Slice)
12441 and then Prefix (P) = N;
12442 end Is_Dereferenced;
12444 ----------------------
12445 -- Is_Descendant_Of --
12446 ----------------------
12448 function Is_Descendant_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
12449 T : Entity_Id;
12450 Etyp : Entity_Id;
12452 begin
12453 pragma Assert (Nkind (T1) in N_Entity);
12454 pragma Assert (Nkind (T2) in N_Entity);
12456 T := Base_Type (T1);
12458 -- Immediate return if the types match
12460 if T = T2 then
12461 return True;
12463 -- Comment needed here ???
12465 elsif Ekind (T) = E_Class_Wide_Type then
12466 return Etype (T) = T2;
12468 -- All other cases
12470 else
12471 loop
12472 Etyp := Etype (T);
12474 -- Done if we found the type we are looking for
12476 if Etyp = T2 then
12477 return True;
12479 -- Done if no more derivations to check
12481 elsif T = T1
12482 or else T = Etyp
12483 then
12484 return False;
12486 -- Following test catches error cases resulting from prev errors
12488 elsif No (Etyp) then
12489 return False;
12491 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
12492 return False;
12494 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
12495 return False;
12496 end if;
12498 T := Base_Type (Etyp);
12499 end loop;
12500 end if;
12501 end Is_Descendant_Of;
12503 ----------------------------------------
12504 -- Is_Descendant_Of_Suspension_Object --
12505 ----------------------------------------
12507 function Is_Descendant_Of_Suspension_Object
12508 (Typ : Entity_Id) return Boolean
12510 Cur_Typ : Entity_Id;
12511 Par_Typ : Entity_Id;
12513 begin
12514 -- Climb the type derivation chain checking each parent type against
12515 -- Suspension_Object.
12517 Cur_Typ := Base_Type (Typ);
12518 while Present (Cur_Typ) loop
12519 Par_Typ := Etype (Cur_Typ);
12521 -- The current type is a match
12523 if Is_Suspension_Object (Cur_Typ) then
12524 return True;
12526 -- Stop the traversal once the root of the derivation chain has been
12527 -- reached. In that case the current type is its own base type.
12529 elsif Cur_Typ = Par_Typ then
12530 exit;
12531 end if;
12533 Cur_Typ := Base_Type (Par_Typ);
12534 end loop;
12536 return False;
12537 end Is_Descendant_Of_Suspension_Object;
12539 ---------------------------------------------
12540 -- Is_Double_Precision_Floating_Point_Type --
12541 ---------------------------------------------
12543 function Is_Double_Precision_Floating_Point_Type
12544 (E : Entity_Id) return Boolean is
12545 begin
12546 return Is_Floating_Point_Type (E)
12547 and then Machine_Radix_Value (E) = Uint_2
12548 and then Machine_Mantissa_Value (E) = UI_From_Int (53)
12549 and then Machine_Emax_Value (E) = Uint_2 ** Uint_10
12550 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_10);
12551 end Is_Double_Precision_Floating_Point_Type;
12553 -----------------------------
12554 -- Is_Effectively_Volatile --
12555 -----------------------------
12557 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
12558 begin
12559 if Is_Type (Id) then
12561 -- An arbitrary type is effectively volatile when it is subject to
12562 -- pragma Atomic or Volatile.
12564 if Is_Volatile (Id) then
12565 return True;
12567 -- An array type is effectively volatile when it is subject to pragma
12568 -- Atomic_Components or Volatile_Components or its component type is
12569 -- effectively volatile.
12571 elsif Is_Array_Type (Id) then
12572 return
12573 Has_Volatile_Components (Id)
12574 or else
12575 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
12577 -- A protected type is always volatile
12579 elsif Is_Protected_Type (Id) then
12580 return True;
12582 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
12583 -- automatically volatile.
12585 elsif Is_Descendant_Of_Suspension_Object (Id) then
12586 return True;
12588 -- Otherwise the type is not effectively volatile
12590 else
12591 return False;
12592 end if;
12594 -- Otherwise Id denotes an object
12596 else
12597 return
12598 Is_Volatile (Id)
12599 or else Has_Volatile_Components (Id)
12600 or else Is_Effectively_Volatile (Etype (Id));
12601 end if;
12602 end Is_Effectively_Volatile;
12604 ------------------------------------
12605 -- Is_Effectively_Volatile_Object --
12606 ------------------------------------
12608 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
12609 begin
12610 if Is_Entity_Name (N) then
12611 return Is_Effectively_Volatile (Entity (N));
12613 elsif Nkind (N) = N_Indexed_Component then
12614 return Is_Effectively_Volatile_Object (Prefix (N));
12616 elsif Nkind (N) = N_Selected_Component then
12617 return
12618 Is_Effectively_Volatile_Object (Prefix (N))
12619 or else
12620 Is_Effectively_Volatile_Object (Selector_Name (N));
12622 else
12623 return False;
12624 end if;
12625 end Is_Effectively_Volatile_Object;
12627 -------------------
12628 -- Is_Entry_Body --
12629 -------------------
12631 function Is_Entry_Body (Id : Entity_Id) return Boolean is
12632 begin
12633 return
12634 Ekind_In (Id, E_Entry, E_Entry_Family)
12635 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Body;
12636 end Is_Entry_Body;
12638 --------------------------
12639 -- Is_Entry_Declaration --
12640 --------------------------
12642 function Is_Entry_Declaration (Id : Entity_Id) return Boolean is
12643 begin
12644 return
12645 Ekind_In (Id, E_Entry, E_Entry_Family)
12646 and then Nkind (Unit_Declaration_Node (Id)) = N_Entry_Declaration;
12647 end Is_Entry_Declaration;
12649 ------------------------------------
12650 -- Is_Expanded_Priority_Attribute --
12651 ------------------------------------
12653 function Is_Expanded_Priority_Attribute (E : Entity_Id) return Boolean is
12654 begin
12655 return
12656 Nkind (E) = N_Function_Call
12657 and then not Configurable_Run_Time_Mode
12658 and then (Entity (Name (E)) = RTE (RE_Get_Ceiling)
12659 or else Entity (Name (E)) = RTE (RO_PE_Get_Ceiling));
12660 end Is_Expanded_Priority_Attribute;
12662 ----------------------------
12663 -- Is_Expression_Function --
12664 ----------------------------
12666 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
12667 begin
12668 if Ekind_In (Subp, E_Function, E_Subprogram_Body) then
12669 return
12670 Nkind (Original_Node (Unit_Declaration_Node (Subp))) =
12671 N_Expression_Function;
12672 else
12673 return False;
12674 end if;
12675 end Is_Expression_Function;
12677 ------------------------------------------
12678 -- Is_Expression_Function_Or_Completion --
12679 ------------------------------------------
12681 function Is_Expression_Function_Or_Completion
12682 (Subp : Entity_Id) return Boolean
12684 Subp_Decl : Node_Id;
12686 begin
12687 if Ekind (Subp) = E_Function then
12688 Subp_Decl := Unit_Declaration_Node (Subp);
12690 -- The function declaration is either an expression function or is
12691 -- completed by an expression function body.
12693 return
12694 Is_Expression_Function (Subp)
12695 or else (Nkind (Subp_Decl) = N_Subprogram_Declaration
12696 and then Present (Corresponding_Body (Subp_Decl))
12697 and then Is_Expression_Function
12698 (Corresponding_Body (Subp_Decl)));
12700 elsif Ekind (Subp) = E_Subprogram_Body then
12701 return Is_Expression_Function (Subp);
12703 else
12704 return False;
12705 end if;
12706 end Is_Expression_Function_Or_Completion;
12708 -----------------------
12709 -- Is_EVF_Expression --
12710 -----------------------
12712 function Is_EVF_Expression (N : Node_Id) return Boolean is
12713 Orig_N : constant Node_Id := Original_Node (N);
12714 Alt : Node_Id;
12715 Expr : Node_Id;
12716 Id : Entity_Id;
12718 begin
12719 -- Detect a reference to a formal parameter of a specific tagged type
12720 -- whose related subprogram is subject to pragma Expresions_Visible with
12721 -- value "False".
12723 if Is_Entity_Name (N) and then Present (Entity (N)) then
12724 Id := Entity (N);
12726 return
12727 Is_Formal (Id)
12728 and then Is_Specific_Tagged_Type (Etype (Id))
12729 and then Extensions_Visible_Status (Id) =
12730 Extensions_Visible_False;
12732 -- A case expression is an EVF expression when it contains at least one
12733 -- EVF dependent_expression. Note that a case expression may have been
12734 -- expanded, hence the use of Original_Node.
12736 elsif Nkind (Orig_N) = N_Case_Expression then
12737 Alt := First (Alternatives (Orig_N));
12738 while Present (Alt) loop
12739 if Is_EVF_Expression (Expression (Alt)) then
12740 return True;
12741 end if;
12743 Next (Alt);
12744 end loop;
12746 -- An if expression is an EVF expression when it contains at least one
12747 -- EVF dependent_expression. Note that an if expression may have been
12748 -- expanded, hence the use of Original_Node.
12750 elsif Nkind (Orig_N) = N_If_Expression then
12751 Expr := Next (First (Expressions (Orig_N)));
12752 while Present (Expr) loop
12753 if Is_EVF_Expression (Expr) then
12754 return True;
12755 end if;
12757 Next (Expr);
12758 end loop;
12760 -- A qualified expression or a type conversion is an EVF expression when
12761 -- its operand is an EVF expression.
12763 elsif Nkind_In (N, N_Qualified_Expression,
12764 N_Unchecked_Type_Conversion,
12765 N_Type_Conversion)
12766 then
12767 return Is_EVF_Expression (Expression (N));
12769 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
12770 -- their prefix denotes an EVF expression.
12772 elsif Nkind (N) = N_Attribute_Reference
12773 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
12774 Name_Old,
12775 Name_Update)
12776 then
12777 return Is_EVF_Expression (Prefix (N));
12778 end if;
12780 return False;
12781 end Is_EVF_Expression;
12783 --------------
12784 -- Is_False --
12785 --------------
12787 function Is_False (U : Uint) return Boolean is
12788 begin
12789 return (U = 0);
12790 end Is_False;
12792 ---------------------------
12793 -- Is_Fixed_Model_Number --
12794 ---------------------------
12796 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
12797 S : constant Ureal := Small_Value (T);
12798 M : Urealp.Save_Mark;
12799 R : Boolean;
12800 begin
12801 M := Urealp.Mark;
12802 R := (U = UR_Trunc (U / S) * S);
12803 Urealp.Release (M);
12804 return R;
12805 end Is_Fixed_Model_Number;
12807 -------------------------------
12808 -- Is_Fully_Initialized_Type --
12809 -------------------------------
12811 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
12812 begin
12813 -- Scalar types
12815 if Is_Scalar_Type (Typ) then
12817 -- A scalar type with an aspect Default_Value is fully initialized
12819 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
12820 -- of a scalar type, but we don't take that into account here, since
12821 -- we don't want these to affect warnings.
12823 return Has_Default_Aspect (Typ);
12825 elsif Is_Access_Type (Typ) then
12826 return True;
12828 elsif Is_Array_Type (Typ) then
12829 if Is_Fully_Initialized_Type (Component_Type (Typ))
12830 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
12831 then
12832 return True;
12833 end if;
12835 -- An interesting case, if we have a constrained type one of whose
12836 -- bounds is known to be null, then there are no elements to be
12837 -- initialized, so all the elements are initialized.
12839 if Is_Constrained (Typ) then
12840 declare
12841 Indx : Node_Id;
12842 Indx_Typ : Entity_Id;
12843 Lbd, Hbd : Node_Id;
12845 begin
12846 Indx := First_Index (Typ);
12847 while Present (Indx) loop
12848 if Etype (Indx) = Any_Type then
12849 return False;
12851 -- If index is a range, use directly
12853 elsif Nkind (Indx) = N_Range then
12854 Lbd := Low_Bound (Indx);
12855 Hbd := High_Bound (Indx);
12857 else
12858 Indx_Typ := Etype (Indx);
12860 if Is_Private_Type (Indx_Typ) then
12861 Indx_Typ := Full_View (Indx_Typ);
12862 end if;
12864 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
12865 return False;
12866 else
12867 Lbd := Type_Low_Bound (Indx_Typ);
12868 Hbd := Type_High_Bound (Indx_Typ);
12869 end if;
12870 end if;
12872 if Compile_Time_Known_Value (Lbd)
12873 and then
12874 Compile_Time_Known_Value (Hbd)
12875 then
12876 if Expr_Value (Hbd) < Expr_Value (Lbd) then
12877 return True;
12878 end if;
12879 end if;
12881 Next_Index (Indx);
12882 end loop;
12883 end;
12884 end if;
12886 -- If no null indexes, then type is not fully initialized
12888 return False;
12890 -- Record types
12892 elsif Is_Record_Type (Typ) then
12893 if Has_Discriminants (Typ)
12894 and then
12895 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
12896 and then Is_Fully_Initialized_Variant (Typ)
12897 then
12898 return True;
12899 end if;
12901 -- We consider bounded string types to be fully initialized, because
12902 -- otherwise we get false alarms when the Data component is not
12903 -- default-initialized.
12905 if Is_Bounded_String (Typ) then
12906 return True;
12907 end if;
12909 -- Controlled records are considered to be fully initialized if
12910 -- there is a user defined Initialize routine. This may not be
12911 -- entirely correct, but as the spec notes, we are guessing here
12912 -- what is best from the point of view of issuing warnings.
12914 if Is_Controlled (Typ) then
12915 declare
12916 Utyp : constant Entity_Id := Underlying_Type (Typ);
12918 begin
12919 if Present (Utyp) then
12920 declare
12921 Init : constant Entity_Id :=
12922 (Find_Optional_Prim_Op
12923 (Underlying_Type (Typ), Name_Initialize));
12925 begin
12926 if Present (Init)
12927 and then Comes_From_Source (Init)
12928 and then not
12929 Is_Predefined_File_Name
12930 (File_Name (Get_Source_File_Index (Sloc (Init))))
12931 then
12932 return True;
12934 elsif Has_Null_Extension (Typ)
12935 and then
12936 Is_Fully_Initialized_Type
12937 (Etype (Base_Type (Typ)))
12938 then
12939 return True;
12940 end if;
12941 end;
12942 end if;
12943 end;
12944 end if;
12946 -- Otherwise see if all record components are initialized
12948 declare
12949 Ent : Entity_Id;
12951 begin
12952 Ent := First_Entity (Typ);
12953 while Present (Ent) loop
12954 if Ekind (Ent) = E_Component
12955 and then (No (Parent (Ent))
12956 or else No (Expression (Parent (Ent))))
12957 and then not Is_Fully_Initialized_Type (Etype (Ent))
12959 -- Special VM case for tag components, which need to be
12960 -- defined in this case, but are never initialized as VMs
12961 -- are using other dispatching mechanisms. Ignore this
12962 -- uninitialized case. Note that this applies both to the
12963 -- uTag entry and the main vtable pointer (CPP_Class case).
12965 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
12966 then
12967 return False;
12968 end if;
12970 Next_Entity (Ent);
12971 end loop;
12972 end;
12974 -- No uninitialized components, so type is fully initialized.
12975 -- Note that this catches the case of no components as well.
12977 return True;
12979 elsif Is_Concurrent_Type (Typ) then
12980 return True;
12982 elsif Is_Private_Type (Typ) then
12983 declare
12984 U : constant Entity_Id := Underlying_Type (Typ);
12986 begin
12987 if No (U) then
12988 return False;
12989 else
12990 return Is_Fully_Initialized_Type (U);
12991 end if;
12992 end;
12994 else
12995 return False;
12996 end if;
12997 end Is_Fully_Initialized_Type;
12999 ----------------------------------
13000 -- Is_Fully_Initialized_Variant --
13001 ----------------------------------
13003 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
13004 Loc : constant Source_Ptr := Sloc (Typ);
13005 Constraints : constant List_Id := New_List;
13006 Components : constant Elist_Id := New_Elmt_List;
13007 Comp_Elmt : Elmt_Id;
13008 Comp_Id : Node_Id;
13009 Comp_List : Node_Id;
13010 Discr : Entity_Id;
13011 Discr_Val : Node_Id;
13013 Report_Errors : Boolean;
13014 pragma Warnings (Off, Report_Errors);
13016 begin
13017 if Serious_Errors_Detected > 0 then
13018 return False;
13019 end if;
13021 if Is_Record_Type (Typ)
13022 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
13023 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
13024 then
13025 Comp_List := Component_List (Type_Definition (Parent (Typ)));
13027 Discr := First_Discriminant (Typ);
13028 while Present (Discr) loop
13029 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
13030 Discr_Val := Expression (Parent (Discr));
13032 if Present (Discr_Val)
13033 and then Is_OK_Static_Expression (Discr_Val)
13034 then
13035 Append_To (Constraints,
13036 Make_Component_Association (Loc,
13037 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
13038 Expression => New_Copy (Discr_Val)));
13039 else
13040 return False;
13041 end if;
13042 else
13043 return False;
13044 end if;
13046 Next_Discriminant (Discr);
13047 end loop;
13049 Gather_Components
13050 (Typ => Typ,
13051 Comp_List => Comp_List,
13052 Governed_By => Constraints,
13053 Into => Components,
13054 Report_Errors => Report_Errors);
13056 -- Check that each component present is fully initialized
13058 Comp_Elmt := First_Elmt (Components);
13059 while Present (Comp_Elmt) loop
13060 Comp_Id := Node (Comp_Elmt);
13062 if Ekind (Comp_Id) = E_Component
13063 and then (No (Parent (Comp_Id))
13064 or else No (Expression (Parent (Comp_Id))))
13065 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
13066 then
13067 return False;
13068 end if;
13070 Next_Elmt (Comp_Elmt);
13071 end loop;
13073 return True;
13075 elsif Is_Private_Type (Typ) then
13076 declare
13077 U : constant Entity_Id := Underlying_Type (Typ);
13079 begin
13080 if No (U) then
13081 return False;
13082 else
13083 return Is_Fully_Initialized_Variant (U);
13084 end if;
13085 end;
13087 else
13088 return False;
13089 end if;
13090 end Is_Fully_Initialized_Variant;
13092 ------------------------------------
13093 -- Is_Generic_Declaration_Or_Body --
13094 ------------------------------------
13096 function Is_Generic_Declaration_Or_Body (Decl : Node_Id) return Boolean is
13097 Spec_Decl : Node_Id;
13099 begin
13100 -- Package/subprogram body
13102 if Nkind_In (Decl, N_Package_Body, N_Subprogram_Body)
13103 and then Present (Corresponding_Spec (Decl))
13104 then
13105 Spec_Decl := Unit_Declaration_Node (Corresponding_Spec (Decl));
13107 -- Package/subprogram body stub
13109 elsif Nkind_In (Decl, N_Package_Body_Stub, N_Subprogram_Body_Stub)
13110 and then Present (Corresponding_Spec_Of_Stub (Decl))
13111 then
13112 Spec_Decl :=
13113 Unit_Declaration_Node (Corresponding_Spec_Of_Stub (Decl));
13115 -- All other cases
13117 else
13118 Spec_Decl := Decl;
13119 end if;
13121 -- Rather than inspecting the defining entity of the spec declaration,
13122 -- look at its Nkind. This takes care of the case where the analysis of
13123 -- a generic body modifies the Ekind of its spec to allow for recursive
13124 -- calls.
13126 return
13127 Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
13128 N_Generic_Subprogram_Declaration);
13129 end Is_Generic_Declaration_Or_Body;
13131 ----------------------------
13132 -- Is_Inherited_Operation --
13133 ----------------------------
13135 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
13136 pragma Assert (Is_Overloadable (E));
13137 Kind : constant Node_Kind := Nkind (Parent (E));
13138 begin
13139 return Kind = N_Full_Type_Declaration
13140 or else Kind = N_Private_Extension_Declaration
13141 or else Kind = N_Subtype_Declaration
13142 or else (Ekind (E) = E_Enumeration_Literal
13143 and then Is_Derived_Type (Etype (E)));
13144 end Is_Inherited_Operation;
13146 -------------------------------------
13147 -- Is_Inherited_Operation_For_Type --
13148 -------------------------------------
13150 function Is_Inherited_Operation_For_Type
13151 (E : Entity_Id;
13152 Typ : Entity_Id) return Boolean
13154 begin
13155 -- Check that the operation has been created by the type declaration
13157 return Is_Inherited_Operation (E)
13158 and then Defining_Identifier (Parent (E)) = Typ;
13159 end Is_Inherited_Operation_For_Type;
13161 --------------------------------------
13162 -- Is_Inlinable_Expression_Function --
13163 --------------------------------------
13165 function Is_Inlinable_Expression_Function
13166 (Subp : Entity_Id) return Boolean
13168 Return_Expr : Node_Id;
13170 begin
13171 if Is_Expression_Function_Or_Completion (Subp)
13172 and then Has_Pragma_Inline_Always (Subp)
13173 and then Needs_No_Actuals (Subp)
13174 and then No (Contract (Subp))
13175 and then not Is_Dispatching_Operation (Subp)
13176 and then Needs_Finalization (Etype (Subp))
13177 and then not Is_Class_Wide_Type (Etype (Subp))
13178 and then not (Has_Invariants (Etype (Subp)))
13179 and then Present (Subprogram_Body (Subp))
13180 and then Was_Expression_Function (Subprogram_Body (Subp))
13181 then
13182 Return_Expr := Expression_Of_Expression_Function (Subp);
13184 -- The returned object must not have a qualified expression and its
13185 -- nominal subtype must be statically compatible with the result
13186 -- subtype of the expression function.
13188 return
13189 Nkind (Return_Expr) = N_Identifier
13190 and then Etype (Return_Expr) = Etype (Subp);
13191 end if;
13193 return False;
13194 end Is_Inlinable_Expression_Function;
13196 -----------------
13197 -- Is_Iterator --
13198 -----------------
13200 function Is_Iterator (Typ : Entity_Id) return Boolean is
13201 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean;
13202 -- Determine whether type Iter_Typ is a predefined forward or reversible
13203 -- iterator.
13205 ----------------------
13206 -- Denotes_Iterator --
13207 ----------------------
13209 function Denotes_Iterator (Iter_Typ : Entity_Id) return Boolean is
13210 begin
13211 -- Check that the name matches, and that the ultimate ancestor is in
13212 -- a predefined unit, i.e the one that declares iterator interfaces.
13214 return
13215 Nam_In (Chars (Iter_Typ), Name_Forward_Iterator,
13216 Name_Reversible_Iterator)
13217 and then Is_Predefined_File_Name
13218 (Unit_File_Name (Get_Source_Unit (Root_Type (Iter_Typ))));
13219 end Denotes_Iterator;
13221 -- Local variables
13223 Iface_Elmt : Elmt_Id;
13224 Ifaces : Elist_Id;
13226 -- Start of processing for Is_Iterator
13228 begin
13229 -- The type may be a subtype of a descendant of the proper instance of
13230 -- the predefined interface type, so we must use the root type of the
13231 -- given type. The same is done for Is_Reversible_Iterator.
13233 if Is_Class_Wide_Type (Typ)
13234 and then Denotes_Iterator (Root_Type (Typ))
13235 then
13236 return True;
13238 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
13239 return False;
13241 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
13242 return True;
13244 else
13245 Collect_Interfaces (Typ, Ifaces);
13247 Iface_Elmt := First_Elmt (Ifaces);
13248 while Present (Iface_Elmt) loop
13249 if Denotes_Iterator (Node (Iface_Elmt)) then
13250 return True;
13251 end if;
13253 Next_Elmt (Iface_Elmt);
13254 end loop;
13256 return False;
13257 end if;
13258 end Is_Iterator;
13260 ----------------------------
13261 -- Is_Iterator_Over_Array --
13262 ----------------------------
13264 function Is_Iterator_Over_Array (N : Node_Id) return Boolean is
13265 Container : constant Node_Id := Name (N);
13266 Container_Typ : constant Entity_Id := Base_Type (Etype (Container));
13267 begin
13268 return Is_Array_Type (Container_Typ);
13269 end Is_Iterator_Over_Array;
13271 ------------
13272 -- Is_LHS --
13273 ------------
13275 -- We seem to have a lot of overlapping functions that do similar things
13276 -- (testing for left hand sides or lvalues???).
13278 function Is_LHS (N : Node_Id) return Is_LHS_Result is
13279 P : constant Node_Id := Parent (N);
13281 begin
13282 -- Return True if we are the left hand side of an assignment statement
13284 if Nkind (P) = N_Assignment_Statement then
13285 if Name (P) = N then
13286 return Yes;
13287 else
13288 return No;
13289 end if;
13291 -- Case of prefix of indexed or selected component or slice
13293 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
13294 and then N = Prefix (P)
13295 then
13296 -- Here we have the case where the parent P is N.Q or N(Q .. R).
13297 -- If P is an LHS, then N is also effectively an LHS, but there
13298 -- is an important exception. If N is of an access type, then
13299 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
13300 -- case this makes N.all a left hand side but not N itself.
13302 -- If we don't know the type yet, this is the case where we return
13303 -- Unknown, since the answer depends on the type which is unknown.
13305 if No (Etype (N)) then
13306 return Unknown;
13308 -- We have an Etype set, so we can check it
13310 elsif Is_Access_Type (Etype (N)) then
13311 return No;
13313 -- OK, not access type case, so just test whole expression
13315 else
13316 return Is_LHS (P);
13317 end if;
13319 -- All other cases are not left hand sides
13321 else
13322 return No;
13323 end if;
13324 end Is_LHS;
13326 -----------------------------
13327 -- Is_Library_Level_Entity --
13328 -----------------------------
13330 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
13331 begin
13332 -- The following is a small optimization, and it also properly handles
13333 -- discriminals, which in task bodies might appear in expressions before
13334 -- the corresponding procedure has been created, and which therefore do
13335 -- not have an assigned scope.
13337 if Is_Formal (E) then
13338 return False;
13339 end if;
13341 -- Normal test is simply that the enclosing dynamic scope is Standard
13343 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
13344 end Is_Library_Level_Entity;
13346 --------------------------------
13347 -- Is_Limited_Class_Wide_Type --
13348 --------------------------------
13350 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
13351 begin
13352 return
13353 Is_Class_Wide_Type (Typ)
13354 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
13355 end Is_Limited_Class_Wide_Type;
13357 ---------------------------------
13358 -- Is_Local_Variable_Reference --
13359 ---------------------------------
13361 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
13362 begin
13363 if not Is_Entity_Name (Expr) then
13364 return False;
13366 else
13367 declare
13368 Ent : constant Entity_Id := Entity (Expr);
13369 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
13370 begin
13371 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
13372 return False;
13373 else
13374 return Present (Sub) and then Sub = Current_Subprogram;
13375 end if;
13376 end;
13377 end if;
13378 end Is_Local_Variable_Reference;
13380 -----------------------
13381 -- Is_Name_Reference --
13382 -----------------------
13384 function Is_Name_Reference (N : Node_Id) return Boolean is
13385 begin
13386 if Is_Entity_Name (N) then
13387 return Present (Entity (N)) and then Is_Object (Entity (N));
13388 end if;
13390 case Nkind (N) is
13391 when N_Indexed_Component
13392 | N_Slice
13394 return
13395 Is_Name_Reference (Prefix (N))
13396 or else Is_Access_Type (Etype (Prefix (N)));
13398 -- Attributes 'Input, 'Old and 'Result produce objects
13400 when N_Attribute_Reference =>
13401 return
13402 Nam_In (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
13404 when N_Selected_Component =>
13405 return
13406 Is_Name_Reference (Selector_Name (N))
13407 and then
13408 (Is_Name_Reference (Prefix (N))
13409 or else Is_Access_Type (Etype (Prefix (N))));
13411 when N_Explicit_Dereference =>
13412 return True;
13414 -- A view conversion of a tagged name is a name reference
13416 when N_Type_Conversion =>
13417 return
13418 Is_Tagged_Type (Etype (Subtype_Mark (N)))
13419 and then Is_Tagged_Type (Etype (Expression (N)))
13420 and then Is_Name_Reference (Expression (N));
13422 -- An unchecked type conversion is considered to be a name if the
13423 -- operand is a name (this construction arises only as a result of
13424 -- expansion activities).
13426 when N_Unchecked_Type_Conversion =>
13427 return Is_Name_Reference (Expression (N));
13429 when others =>
13430 return False;
13431 end case;
13432 end Is_Name_Reference;
13434 ---------------------------------
13435 -- Is_Nontrivial_DIC_Procedure --
13436 ---------------------------------
13438 function Is_Nontrivial_DIC_Procedure (Id : Entity_Id) return Boolean is
13439 Body_Decl : Node_Id;
13440 Stmt : Node_Id;
13442 begin
13443 if Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id) then
13444 Body_Decl :=
13445 Unit_Declaration_Node
13446 (Corresponding_Body (Unit_Declaration_Node (Id)));
13448 -- The body of the Default_Initial_Condition procedure must contain
13449 -- at least one statement, otherwise the generation of the subprogram
13450 -- body failed.
13452 pragma Assert (Present (Handled_Statement_Sequence (Body_Decl)));
13454 -- To qualify as nontrivial, the first statement of the procedure
13455 -- must be a check in the form of an if statement. If the original
13456 -- Default_Initial_Condition expression was folded, then the first
13457 -- statement is not a check.
13459 Stmt := First (Statements (Handled_Statement_Sequence (Body_Decl)));
13461 return
13462 Nkind (Stmt) = N_If_Statement
13463 and then Nkind (Original_Node (Stmt)) = N_Pragma;
13464 end if;
13466 return False;
13467 end Is_Nontrivial_DIC_Procedure;
13469 -------------------------
13470 -- Is_Null_Record_Type --
13471 -------------------------
13473 function Is_Null_Record_Type (T : Entity_Id) return Boolean is
13474 Decl : constant Node_Id := Parent (T);
13475 begin
13476 return Nkind (Decl) = N_Full_Type_Declaration
13477 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
13478 and then
13479 (No (Component_List (Type_Definition (Decl)))
13480 or else Null_Present (Component_List (Type_Definition (Decl))));
13481 end Is_Null_Record_Type;
13483 -------------------------
13484 -- Is_Object_Reference --
13485 -------------------------
13487 function Is_Object_Reference (N : Node_Id) return Boolean is
13488 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
13489 -- Determine whether N is the name of an internally-generated renaming
13491 --------------------------------------
13492 -- Is_Internally_Generated_Renaming --
13493 --------------------------------------
13495 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
13496 P : Node_Id;
13498 begin
13499 P := N;
13500 while Present (P) loop
13501 if Nkind (P) = N_Object_Renaming_Declaration then
13502 return not Comes_From_Source (P);
13503 elsif Is_List_Member (P) then
13504 return False;
13505 end if;
13507 P := Parent (P);
13508 end loop;
13510 return False;
13511 end Is_Internally_Generated_Renaming;
13513 -- Start of processing for Is_Object_Reference
13515 begin
13516 if Is_Entity_Name (N) then
13517 return Present (Entity (N)) and then Is_Object (Entity (N));
13519 else
13520 case Nkind (N) is
13521 when N_Indexed_Component
13522 | N_Slice
13524 return
13525 Is_Object_Reference (Prefix (N))
13526 or else Is_Access_Type (Etype (Prefix (N)));
13528 -- In Ada 95, a function call is a constant object; a procedure
13529 -- call is not.
13531 when N_Function_Call =>
13532 return Etype (N) /= Standard_Void_Type;
13534 -- Attributes 'Input, 'Loop_Entry, 'Old, and 'Result produce
13535 -- objects.
13537 when N_Attribute_Reference =>
13538 return
13539 Nam_In (Attribute_Name (N), Name_Input,
13540 Name_Loop_Entry,
13541 Name_Old,
13542 Name_Result);
13544 when N_Selected_Component =>
13545 return
13546 Is_Object_Reference (Selector_Name (N))
13547 and then
13548 (Is_Object_Reference (Prefix (N))
13549 or else Is_Access_Type (Etype (Prefix (N))));
13551 when N_Explicit_Dereference =>
13552 return True;
13554 -- A view conversion of a tagged object is an object reference
13556 when N_Type_Conversion =>
13557 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
13558 and then Is_Tagged_Type (Etype (Expression (N)))
13559 and then Is_Object_Reference (Expression (N));
13561 -- An unchecked type conversion is considered to be an object if
13562 -- the operand is an object (this construction arises only as a
13563 -- result of expansion activities).
13565 when N_Unchecked_Type_Conversion =>
13566 return True;
13568 -- Allow string literals to act as objects as long as they appear
13569 -- in internally-generated renamings. The expansion of iterators
13570 -- may generate such renamings when the range involves a string
13571 -- literal.
13573 when N_String_Literal =>
13574 return Is_Internally_Generated_Renaming (Parent (N));
13576 -- AI05-0003: In Ada 2012 a qualified expression is a name.
13577 -- This allows disambiguation of function calls and the use
13578 -- of aggregates in more contexts.
13580 when N_Qualified_Expression =>
13581 if Ada_Version < Ada_2012 then
13582 return False;
13583 else
13584 return Is_Object_Reference (Expression (N))
13585 or else Nkind (Expression (N)) = N_Aggregate;
13586 end if;
13588 when others =>
13589 return False;
13590 end case;
13591 end if;
13592 end Is_Object_Reference;
13594 -----------------------------------
13595 -- Is_OK_Variable_For_Out_Formal --
13596 -----------------------------------
13598 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
13599 begin
13600 Note_Possible_Modification (AV, Sure => True);
13602 -- We must reject parenthesized variable names. Comes_From_Source is
13603 -- checked because there are currently cases where the compiler violates
13604 -- this rule (e.g. passing a task object to its controlled Initialize
13605 -- routine). This should be properly documented in sinfo???
13607 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
13608 return False;
13610 -- A variable is always allowed
13612 elsif Is_Variable (AV) then
13613 return True;
13615 -- Generalized indexing operations are rewritten as explicit
13616 -- dereferences, and it is only during resolution that we can
13617 -- check whether the context requires an access_to_variable type.
13619 elsif Nkind (AV) = N_Explicit_Dereference
13620 and then Ada_Version >= Ada_2012
13621 and then Nkind (Original_Node (AV)) = N_Indexed_Component
13622 and then Present (Etype (Original_Node (AV)))
13623 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
13624 then
13625 return not Is_Access_Constant (Etype (Prefix (AV)));
13627 -- Unchecked conversions are allowed only if they come from the
13628 -- generated code, which sometimes uses unchecked conversions for out
13629 -- parameters in cases where code generation is unaffected. We tell
13630 -- source unchecked conversions by seeing if they are rewrites of
13631 -- an original Unchecked_Conversion function call, or of an explicit
13632 -- conversion of a function call or an aggregate (as may happen in the
13633 -- expansion of a packed array aggregate).
13635 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
13636 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
13637 return False;
13639 elsif Comes_From_Source (AV)
13640 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
13641 then
13642 return False;
13644 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
13645 return Is_OK_Variable_For_Out_Formal (Expression (AV));
13647 else
13648 return True;
13649 end if;
13651 -- Normal type conversions are allowed if argument is a variable
13653 elsif Nkind (AV) = N_Type_Conversion then
13654 if Is_Variable (Expression (AV))
13655 and then Paren_Count (Expression (AV)) = 0
13656 then
13657 Note_Possible_Modification (Expression (AV), Sure => True);
13658 return True;
13660 -- We also allow a non-parenthesized expression that raises
13661 -- constraint error if it rewrites what used to be a variable
13663 elsif Raises_Constraint_Error (Expression (AV))
13664 and then Paren_Count (Expression (AV)) = 0
13665 and then Is_Variable (Original_Node (Expression (AV)))
13666 then
13667 return True;
13669 -- Type conversion of something other than a variable
13671 else
13672 return False;
13673 end if;
13675 -- If this node is rewritten, then test the original form, if that is
13676 -- OK, then we consider the rewritten node OK (for example, if the
13677 -- original node is a conversion, then Is_Variable will not be true
13678 -- but we still want to allow the conversion if it converts a variable).
13680 elsif Original_Node (AV) /= AV then
13682 -- In Ada 2012, the explicit dereference may be a rewritten call to a
13683 -- Reference function.
13685 if Ada_Version >= Ada_2012
13686 and then Nkind (Original_Node (AV)) = N_Function_Call
13687 and then
13688 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
13689 then
13691 -- Check that this is not a constant reference.
13693 return not Is_Access_Constant (Etype (Prefix (AV)));
13695 elsif Has_Implicit_Dereference (Etype (Original_Node (AV))) then
13696 return
13697 not Is_Access_Constant (Etype
13698 (Get_Reference_Discriminant (Etype (Original_Node (AV)))));
13700 else
13701 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
13702 end if;
13704 -- All other non-variables are rejected
13706 else
13707 return False;
13708 end if;
13709 end Is_OK_Variable_For_Out_Formal;
13711 ----------------------------
13712 -- Is_OK_Volatile_Context --
13713 ----------------------------
13715 function Is_OK_Volatile_Context
13716 (Context : Node_Id;
13717 Obj_Ref : Node_Id) return Boolean
13719 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean;
13720 -- Determine whether an arbitrary node denotes a call to a protected
13721 -- entry, function, or procedure in prefixed form where the prefix is
13722 -- Obj_Ref.
13724 function Within_Check (Nod : Node_Id) return Boolean;
13725 -- Determine whether an arbitrary node appears in a check node
13727 function Within_Subprogram_Call (Nod : Node_Id) return Boolean;
13728 -- Determine whether an arbitrary node appears in an entry, function, or
13729 -- procedure call.
13731 function Within_Volatile_Function (Id : Entity_Id) return Boolean;
13732 -- Determine whether an arbitrary entity appears in a volatile function
13734 ---------------------------------
13735 -- Is_Protected_Operation_Call --
13736 ---------------------------------
13738 function Is_Protected_Operation_Call (Nod : Node_Id) return Boolean is
13739 Pref : Node_Id;
13740 Subp : Node_Id;
13742 begin
13743 -- A call to a protected operations retains its selected component
13744 -- form as opposed to other prefixed calls that are transformed in
13745 -- expanded names.
13747 if Nkind (Nod) = N_Selected_Component then
13748 Pref := Prefix (Nod);
13749 Subp := Selector_Name (Nod);
13751 return
13752 Pref = Obj_Ref
13753 and then Present (Etype (Pref))
13754 and then Is_Protected_Type (Etype (Pref))
13755 and then Is_Entity_Name (Subp)
13756 and then Present (Entity (Subp))
13757 and then Ekind_In (Entity (Subp), E_Entry,
13758 E_Entry_Family,
13759 E_Function,
13760 E_Procedure);
13761 else
13762 return False;
13763 end if;
13764 end Is_Protected_Operation_Call;
13766 ------------------
13767 -- Within_Check --
13768 ------------------
13770 function Within_Check (Nod : Node_Id) return Boolean is
13771 Par : Node_Id;
13773 begin
13774 -- Climb the parent chain looking for a check node
13776 Par := Nod;
13777 while Present (Par) loop
13778 if Nkind (Par) in N_Raise_xxx_Error then
13779 return True;
13781 -- Prevent the search from going too far
13783 elsif Is_Body_Or_Package_Declaration (Par) then
13784 exit;
13785 end if;
13787 Par := Parent (Par);
13788 end loop;
13790 return False;
13791 end Within_Check;
13793 ----------------------------
13794 -- Within_Subprogram_Call --
13795 ----------------------------
13797 function Within_Subprogram_Call (Nod : Node_Id) return Boolean is
13798 Par : Node_Id;
13800 begin
13801 -- Climb the parent chain looking for a function or procedure call
13803 Par := Nod;
13804 while Present (Par) loop
13805 if Nkind_In (Par, N_Entry_Call_Statement,
13806 N_Function_Call,
13807 N_Procedure_Call_Statement)
13808 then
13809 return True;
13811 -- Prevent the search from going too far
13813 elsif Is_Body_Or_Package_Declaration (Par) then
13814 exit;
13815 end if;
13817 Par := Parent (Par);
13818 end loop;
13820 return False;
13821 end Within_Subprogram_Call;
13823 ------------------------------
13824 -- Within_Volatile_Function --
13825 ------------------------------
13827 function Within_Volatile_Function (Id : Entity_Id) return Boolean is
13828 Func_Id : Entity_Id;
13830 begin
13831 -- Traverse the scope stack looking for a [generic] function
13833 Func_Id := Id;
13834 while Present (Func_Id) and then Func_Id /= Standard_Standard loop
13835 if Ekind_In (Func_Id, E_Function, E_Generic_Function) then
13836 return Is_Volatile_Function (Func_Id);
13837 end if;
13839 Func_Id := Scope (Func_Id);
13840 end loop;
13842 return False;
13843 end Within_Volatile_Function;
13845 -- Local variables
13847 Obj_Id : Entity_Id;
13849 -- Start of processing for Is_OK_Volatile_Context
13851 begin
13852 -- The volatile object appears on either side of an assignment
13854 if Nkind (Context) = N_Assignment_Statement then
13855 return True;
13857 -- The volatile object is part of the initialization expression of
13858 -- another object.
13860 elsif Nkind (Context) = N_Object_Declaration
13861 and then Present (Expression (Context))
13862 and then Expression (Context) = Obj_Ref
13863 then
13864 Obj_Id := Defining_Entity (Context);
13866 -- The volatile object acts as the initialization expression of an
13867 -- extended return statement. This is valid context as long as the
13868 -- function is volatile.
13870 if Is_Return_Object (Obj_Id) then
13871 return Within_Volatile_Function (Obj_Id);
13873 -- Otherwise this is a normal object initialization
13875 else
13876 return True;
13877 end if;
13879 -- The volatile object acts as the name of a renaming declaration
13881 elsif Nkind (Context) = N_Object_Renaming_Declaration
13882 and then Name (Context) = Obj_Ref
13883 then
13884 return True;
13886 -- The volatile object appears as an actual parameter in a call to an
13887 -- instance of Unchecked_Conversion whose result is renamed.
13889 elsif Nkind (Context) = N_Function_Call
13890 and then Is_Entity_Name (Name (Context))
13891 and then Is_Unchecked_Conversion_Instance (Entity (Name (Context)))
13892 and then Nkind (Parent (Context)) = N_Object_Renaming_Declaration
13893 then
13894 return True;
13896 -- The volatile object is actually the prefix in a protected entry,
13897 -- function, or procedure call.
13899 elsif Is_Protected_Operation_Call (Context) then
13900 return True;
13902 -- The volatile object appears as the expression of a simple return
13903 -- statement that applies to a volatile function.
13905 elsif Nkind (Context) = N_Simple_Return_Statement
13906 and then Expression (Context) = Obj_Ref
13907 then
13908 return
13909 Within_Volatile_Function (Return_Statement_Entity (Context));
13911 -- The volatile object appears as the prefix of a name occurring in a
13912 -- non-interfering context.
13914 elsif Nkind_In (Context, N_Attribute_Reference,
13915 N_Explicit_Dereference,
13916 N_Indexed_Component,
13917 N_Selected_Component,
13918 N_Slice)
13919 and then Prefix (Context) = Obj_Ref
13920 and then Is_OK_Volatile_Context
13921 (Context => Parent (Context),
13922 Obj_Ref => Context)
13923 then
13924 return True;
13926 -- The volatile object appears as the prefix of attributes Address,
13927 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
13928 -- Storage_Size.
13930 elsif Nkind (Context) = N_Attribute_Reference
13931 and then Prefix (Context) = Obj_Ref
13932 and then Nam_In (Attribute_Name (Context), Name_Address,
13933 Name_Alignment,
13934 Name_Component_Size,
13935 Name_First_Bit,
13936 Name_Last_Bit,
13937 Name_Position,
13938 Name_Size,
13939 Name_Storage_Size)
13940 then
13941 return True;
13943 -- The volatile object appears as the expression of a type conversion
13944 -- occurring in a non-interfering context.
13946 elsif Nkind_In (Context, N_Type_Conversion,
13947 N_Unchecked_Type_Conversion)
13948 and then Expression (Context) = Obj_Ref
13949 and then Is_OK_Volatile_Context
13950 (Context => Parent (Context),
13951 Obj_Ref => Context)
13952 then
13953 return True;
13955 -- The volatile object appears as the expression in a delay statement
13957 elsif Nkind (Context) in N_Delay_Statement then
13958 return True;
13960 -- Allow references to volatile objects in various checks. This is not a
13961 -- direct SPARK 2014 requirement.
13963 elsif Within_Check (Context) then
13964 return True;
13966 -- Assume that references to effectively volatile objects that appear
13967 -- as actual parameters in a subprogram call are always legal. A full
13968 -- legality check is done when the actuals are resolved (see routine
13969 -- Resolve_Actuals).
13971 elsif Within_Subprogram_Call (Context) then
13972 return True;
13974 -- Otherwise the context is not suitable for an effectively volatile
13975 -- object.
13977 else
13978 return False;
13979 end if;
13980 end Is_OK_Volatile_Context;
13982 ------------------------------------
13983 -- Is_Package_Contract_Annotation --
13984 ------------------------------------
13986 function Is_Package_Contract_Annotation (Item : Node_Id) return Boolean is
13987 Nam : Name_Id;
13989 begin
13990 if Nkind (Item) = N_Aspect_Specification then
13991 Nam := Chars (Identifier (Item));
13993 else pragma Assert (Nkind (Item) = N_Pragma);
13994 Nam := Pragma_Name (Item);
13995 end if;
13997 return Nam = Name_Abstract_State
13998 or else Nam = Name_Initial_Condition
13999 or else Nam = Name_Initializes
14000 or else Nam = Name_Refined_State;
14001 end Is_Package_Contract_Annotation;
14003 -----------------------------------
14004 -- Is_Partially_Initialized_Type --
14005 -----------------------------------
14007 function Is_Partially_Initialized_Type
14008 (Typ : Entity_Id;
14009 Include_Implicit : Boolean := True) return Boolean
14011 begin
14012 if Is_Scalar_Type (Typ) then
14013 return False;
14015 elsif Is_Access_Type (Typ) then
14016 return Include_Implicit;
14018 elsif Is_Array_Type (Typ) then
14020 -- If component type is partially initialized, so is array type
14022 if Is_Partially_Initialized_Type
14023 (Component_Type (Typ), Include_Implicit)
14024 then
14025 return True;
14027 -- Otherwise we are only partially initialized if we are fully
14028 -- initialized (this is the empty array case, no point in us
14029 -- duplicating that code here).
14031 else
14032 return Is_Fully_Initialized_Type (Typ);
14033 end if;
14035 elsif Is_Record_Type (Typ) then
14037 -- A discriminated type is always partially initialized if in
14038 -- all mode
14040 if Has_Discriminants (Typ) and then Include_Implicit then
14041 return True;
14043 -- A tagged type is always partially initialized
14045 elsif Is_Tagged_Type (Typ) then
14046 return True;
14048 -- Case of non-discriminated record
14050 else
14051 declare
14052 Ent : Entity_Id;
14054 Component_Present : Boolean := False;
14055 -- Set True if at least one component is present. If no
14056 -- components are present, then record type is fully
14057 -- initialized (another odd case, like the null array).
14059 begin
14060 -- Loop through components
14062 Ent := First_Entity (Typ);
14063 while Present (Ent) loop
14064 if Ekind (Ent) = E_Component then
14065 Component_Present := True;
14067 -- If a component has an initialization expression then
14068 -- the enclosing record type is partially initialized
14070 if Present (Parent (Ent))
14071 and then Present (Expression (Parent (Ent)))
14072 then
14073 return True;
14075 -- If a component is of a type which is itself partially
14076 -- initialized, then the enclosing record type is also.
14078 elsif Is_Partially_Initialized_Type
14079 (Etype (Ent), Include_Implicit)
14080 then
14081 return True;
14082 end if;
14083 end if;
14085 Next_Entity (Ent);
14086 end loop;
14088 -- No initialized components found. If we found any components
14089 -- they were all uninitialized so the result is false.
14091 if Component_Present then
14092 return False;
14094 -- But if we found no components, then all the components are
14095 -- initialized so we consider the type to be initialized.
14097 else
14098 return True;
14099 end if;
14100 end;
14101 end if;
14103 -- Concurrent types are always fully initialized
14105 elsif Is_Concurrent_Type (Typ) then
14106 return True;
14108 -- For a private type, go to underlying type. If there is no underlying
14109 -- type then just assume this partially initialized. Not clear if this
14110 -- can happen in a non-error case, but no harm in testing for this.
14112 elsif Is_Private_Type (Typ) then
14113 declare
14114 U : constant Entity_Id := Underlying_Type (Typ);
14115 begin
14116 if No (U) then
14117 return True;
14118 else
14119 return Is_Partially_Initialized_Type (U, Include_Implicit);
14120 end if;
14121 end;
14123 -- For any other type (are there any?) assume partially initialized
14125 else
14126 return True;
14127 end if;
14128 end Is_Partially_Initialized_Type;
14130 ------------------------------------
14131 -- Is_Potentially_Persistent_Type --
14132 ------------------------------------
14134 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
14135 Comp : Entity_Id;
14136 Indx : Node_Id;
14138 begin
14139 -- For private type, test corresponding full type
14141 if Is_Private_Type (T) then
14142 return Is_Potentially_Persistent_Type (Full_View (T));
14144 -- Scalar types are potentially persistent
14146 elsif Is_Scalar_Type (T) then
14147 return True;
14149 -- Record type is potentially persistent if not tagged and the types of
14150 -- all it components are potentially persistent, and no component has
14151 -- an initialization expression.
14153 elsif Is_Record_Type (T)
14154 and then not Is_Tagged_Type (T)
14155 and then not Is_Partially_Initialized_Type (T)
14156 then
14157 Comp := First_Component (T);
14158 while Present (Comp) loop
14159 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
14160 return False;
14161 else
14162 Next_Entity (Comp);
14163 end if;
14164 end loop;
14166 return True;
14168 -- Array type is potentially persistent if its component type is
14169 -- potentially persistent and if all its constraints are static.
14171 elsif Is_Array_Type (T) then
14172 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
14173 return False;
14174 end if;
14176 Indx := First_Index (T);
14177 while Present (Indx) loop
14178 if not Is_OK_Static_Subtype (Etype (Indx)) then
14179 return False;
14180 else
14181 Next_Index (Indx);
14182 end if;
14183 end loop;
14185 return True;
14187 -- All other types are not potentially persistent
14189 else
14190 return False;
14191 end if;
14192 end Is_Potentially_Persistent_Type;
14194 --------------------------------
14195 -- Is_Potentially_Unevaluated --
14196 --------------------------------
14198 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
14199 Par : Node_Id;
14200 Expr : Node_Id;
14202 begin
14203 Expr := N;
14204 Par := Parent (N);
14206 -- A postcondition whose expression is a short-circuit is broken down
14207 -- into individual aspects for better exception reporting. The original
14208 -- short-circuit expression is rewritten as the second operand, and an
14209 -- occurrence of 'Old in that operand is potentially unevaluated.
14210 -- See Sem_ch13.adb for details of this transformation.
14212 if Nkind (Original_Node (Par)) = N_And_Then then
14213 return True;
14214 end if;
14216 while not Nkind_In (Par, N_If_Expression,
14217 N_Case_Expression,
14218 N_And_Then,
14219 N_Or_Else,
14220 N_In,
14221 N_Not_In)
14222 loop
14223 Expr := Par;
14224 Par := Parent (Par);
14226 -- If the context is not an expression, or if is the result of
14227 -- expansion of an enclosing construct (such as another attribute)
14228 -- the predicate does not apply.
14230 if Nkind (Par) not in N_Subexpr
14231 or else not Comes_From_Source (Par)
14232 then
14233 return False;
14234 end if;
14235 end loop;
14237 if Nkind (Par) = N_If_Expression then
14238 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
14240 elsif Nkind (Par) = N_Case_Expression then
14241 return Expr /= Expression (Par);
14243 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
14244 return Expr = Right_Opnd (Par);
14246 elsif Nkind_In (Par, N_In, N_Not_In) then
14247 return Expr /= Left_Opnd (Par);
14249 else
14250 return False;
14251 end if;
14252 end Is_Potentially_Unevaluated;
14254 ---------------------------------
14255 -- Is_Protected_Self_Reference --
14256 ---------------------------------
14258 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
14260 function In_Access_Definition (N : Node_Id) return Boolean;
14261 -- Returns true if N belongs to an access definition
14263 --------------------------
14264 -- In_Access_Definition --
14265 --------------------------
14267 function In_Access_Definition (N : Node_Id) return Boolean is
14268 P : Node_Id;
14270 begin
14271 P := Parent (N);
14272 while Present (P) loop
14273 if Nkind (P) = N_Access_Definition then
14274 return True;
14275 end if;
14277 P := Parent (P);
14278 end loop;
14280 return False;
14281 end In_Access_Definition;
14283 -- Start of processing for Is_Protected_Self_Reference
14285 begin
14286 -- Verify that prefix is analyzed and has the proper form. Note that
14287 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
14288 -- produce the address of an entity, do not analyze their prefix
14289 -- because they denote entities that are not necessarily visible.
14290 -- Neither of them can apply to a protected type.
14292 return Ada_Version >= Ada_2005
14293 and then Is_Entity_Name (N)
14294 and then Present (Entity (N))
14295 and then Is_Protected_Type (Entity (N))
14296 and then In_Open_Scopes (Entity (N))
14297 and then not In_Access_Definition (N);
14298 end Is_Protected_Self_Reference;
14300 -----------------------------
14301 -- Is_RCI_Pkg_Spec_Or_Body --
14302 -----------------------------
14304 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
14306 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
14307 -- Return True if the unit of Cunit is an RCI package declaration
14309 ---------------------------
14310 -- Is_RCI_Pkg_Decl_Cunit --
14311 ---------------------------
14313 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
14314 The_Unit : constant Node_Id := Unit (Cunit);
14316 begin
14317 if Nkind (The_Unit) /= N_Package_Declaration then
14318 return False;
14319 end if;
14321 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
14322 end Is_RCI_Pkg_Decl_Cunit;
14324 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
14326 begin
14327 return Is_RCI_Pkg_Decl_Cunit (Cunit)
14328 or else
14329 (Nkind (Unit (Cunit)) = N_Package_Body
14330 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
14331 end Is_RCI_Pkg_Spec_Or_Body;
14333 -----------------------------------------
14334 -- Is_Remote_Access_To_Class_Wide_Type --
14335 -----------------------------------------
14337 function Is_Remote_Access_To_Class_Wide_Type
14338 (E : Entity_Id) return Boolean
14340 begin
14341 -- A remote access to class-wide type is a general access to object type
14342 -- declared in the visible part of a Remote_Types or Remote_Call_
14343 -- Interface unit.
14345 return Ekind (E) = E_General_Access_Type
14346 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
14347 end Is_Remote_Access_To_Class_Wide_Type;
14349 -----------------------------------------
14350 -- Is_Remote_Access_To_Subprogram_Type --
14351 -----------------------------------------
14353 function Is_Remote_Access_To_Subprogram_Type
14354 (E : Entity_Id) return Boolean
14356 begin
14357 return (Ekind (E) = E_Access_Subprogram_Type
14358 or else (Ekind (E) = E_Record_Type
14359 and then Present (Corresponding_Remote_Type (E))))
14360 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
14361 end Is_Remote_Access_To_Subprogram_Type;
14363 --------------------
14364 -- Is_Remote_Call --
14365 --------------------
14367 function Is_Remote_Call (N : Node_Id) return Boolean is
14368 begin
14369 if Nkind (N) not in N_Subprogram_Call then
14371 -- An entry call cannot be remote
14373 return False;
14375 elsif Nkind (Name (N)) in N_Has_Entity
14376 and then Is_Remote_Call_Interface (Entity (Name (N)))
14377 then
14378 -- A subprogram declared in the spec of a RCI package is remote
14380 return True;
14382 elsif Nkind (Name (N)) = N_Explicit_Dereference
14383 and then Is_Remote_Access_To_Subprogram_Type
14384 (Etype (Prefix (Name (N))))
14385 then
14386 -- The dereference of a RAS is a remote call
14388 return True;
14390 elsif Present (Controlling_Argument (N))
14391 and then Is_Remote_Access_To_Class_Wide_Type
14392 (Etype (Controlling_Argument (N)))
14393 then
14394 -- Any primitive operation call with a controlling argument of
14395 -- a RACW type is a remote call.
14397 return True;
14398 end if;
14400 -- All other calls are local calls
14402 return False;
14403 end Is_Remote_Call;
14405 ----------------------
14406 -- Is_Renamed_Entry --
14407 ----------------------
14409 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
14410 Orig_Node : Node_Id := Empty;
14411 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
14413 function Is_Entry (Nam : Node_Id) return Boolean;
14414 -- Determine whether Nam is an entry. Traverse selectors if there are
14415 -- nested selected components.
14417 --------------
14418 -- Is_Entry --
14419 --------------
14421 function Is_Entry (Nam : Node_Id) return Boolean is
14422 begin
14423 if Nkind (Nam) = N_Selected_Component then
14424 return Is_Entry (Selector_Name (Nam));
14425 end if;
14427 return Ekind (Entity (Nam)) = E_Entry;
14428 end Is_Entry;
14430 -- Start of processing for Is_Renamed_Entry
14432 begin
14433 if Present (Alias (Proc_Nam)) then
14434 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
14435 end if;
14437 -- Look for a rewritten subprogram renaming declaration
14439 if Nkind (Subp_Decl) = N_Subprogram_Declaration
14440 and then Present (Original_Node (Subp_Decl))
14441 then
14442 Orig_Node := Original_Node (Subp_Decl);
14443 end if;
14445 -- The rewritten subprogram is actually an entry
14447 if Present (Orig_Node)
14448 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
14449 and then Is_Entry (Name (Orig_Node))
14450 then
14451 return True;
14452 end if;
14454 return False;
14455 end Is_Renamed_Entry;
14457 -----------------------------
14458 -- Is_Renaming_Declaration --
14459 -----------------------------
14461 function Is_Renaming_Declaration (N : Node_Id) return Boolean is
14462 begin
14463 case Nkind (N) is
14464 when N_Exception_Renaming_Declaration
14465 | N_Generic_Function_Renaming_Declaration
14466 | N_Generic_Package_Renaming_Declaration
14467 | N_Generic_Procedure_Renaming_Declaration
14468 | N_Object_Renaming_Declaration
14469 | N_Package_Renaming_Declaration
14470 | N_Subprogram_Renaming_Declaration
14472 return True;
14474 when others =>
14475 return False;
14476 end case;
14477 end Is_Renaming_Declaration;
14479 ----------------------------
14480 -- Is_Reversible_Iterator --
14481 ----------------------------
14483 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
14484 Ifaces_List : Elist_Id;
14485 Iface_Elmt : Elmt_Id;
14486 Iface : Entity_Id;
14488 begin
14489 if Is_Class_Wide_Type (Typ)
14490 and then Chars (Root_Type (Typ)) = Name_Reversible_Iterator
14491 and then Is_Predefined_File_Name
14492 (Unit_File_Name (Get_Source_Unit (Root_Type (Typ))))
14493 then
14494 return True;
14496 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
14497 return False;
14499 else
14500 Collect_Interfaces (Typ, Ifaces_List);
14502 Iface_Elmt := First_Elmt (Ifaces_List);
14503 while Present (Iface_Elmt) loop
14504 Iface := Node (Iface_Elmt);
14505 if Chars (Iface) = Name_Reversible_Iterator
14506 and then
14507 Is_Predefined_File_Name
14508 (Unit_File_Name (Get_Source_Unit (Iface)))
14509 then
14510 return True;
14511 end if;
14513 Next_Elmt (Iface_Elmt);
14514 end loop;
14515 end if;
14517 return False;
14518 end Is_Reversible_Iterator;
14520 ----------------------
14521 -- Is_Selector_Name --
14522 ----------------------
14524 function Is_Selector_Name (N : Node_Id) return Boolean is
14525 begin
14526 if not Is_List_Member (N) then
14527 declare
14528 P : constant Node_Id := Parent (N);
14529 begin
14530 return Nkind_In (P, N_Expanded_Name,
14531 N_Generic_Association,
14532 N_Parameter_Association,
14533 N_Selected_Component)
14534 and then Selector_Name (P) = N;
14535 end;
14537 else
14538 declare
14539 L : constant List_Id := List_Containing (N);
14540 P : constant Node_Id := Parent (L);
14541 begin
14542 return (Nkind (P) = N_Discriminant_Association
14543 and then Selector_Names (P) = L)
14544 or else
14545 (Nkind (P) = N_Component_Association
14546 and then Choices (P) = L);
14547 end;
14548 end if;
14549 end Is_Selector_Name;
14551 ---------------------------------
14552 -- Is_Single_Concurrent_Object --
14553 ---------------------------------
14555 function Is_Single_Concurrent_Object (Id : Entity_Id) return Boolean is
14556 begin
14557 return
14558 Is_Single_Protected_Object (Id) or else Is_Single_Task_Object (Id);
14559 end Is_Single_Concurrent_Object;
14561 -------------------------------
14562 -- Is_Single_Concurrent_Type --
14563 -------------------------------
14565 function Is_Single_Concurrent_Type (Id : Entity_Id) return Boolean is
14566 begin
14567 return
14568 Ekind_In (Id, E_Protected_Type, E_Task_Type)
14569 and then Is_Single_Concurrent_Type_Declaration
14570 (Declaration_Node (Id));
14571 end Is_Single_Concurrent_Type;
14573 -------------------------------------------
14574 -- Is_Single_Concurrent_Type_Declaration --
14575 -------------------------------------------
14577 function Is_Single_Concurrent_Type_Declaration
14578 (N : Node_Id) return Boolean
14580 begin
14581 return Nkind_In (Original_Node (N), N_Single_Protected_Declaration,
14582 N_Single_Task_Declaration);
14583 end Is_Single_Concurrent_Type_Declaration;
14585 ---------------------------------------------
14586 -- Is_Single_Precision_Floating_Point_Type --
14587 ---------------------------------------------
14589 function Is_Single_Precision_Floating_Point_Type
14590 (E : Entity_Id) return Boolean is
14591 begin
14592 return Is_Floating_Point_Type (E)
14593 and then Machine_Radix_Value (E) = Uint_2
14594 and then Machine_Mantissa_Value (E) = Uint_24
14595 and then Machine_Emax_Value (E) = Uint_2 ** Uint_7
14596 and then Machine_Emin_Value (E) = Uint_3 - (Uint_2 ** Uint_7);
14597 end Is_Single_Precision_Floating_Point_Type;
14599 --------------------------------
14600 -- Is_Single_Protected_Object --
14601 --------------------------------
14603 function Is_Single_Protected_Object (Id : Entity_Id) return Boolean is
14604 begin
14605 return
14606 Ekind (Id) = E_Variable
14607 and then Ekind (Etype (Id)) = E_Protected_Type
14608 and then Is_Single_Concurrent_Type (Etype (Id));
14609 end Is_Single_Protected_Object;
14611 ---------------------------
14612 -- Is_Single_Task_Object --
14613 ---------------------------
14615 function Is_Single_Task_Object (Id : Entity_Id) return Boolean is
14616 begin
14617 return
14618 Ekind (Id) = E_Variable
14619 and then Ekind (Etype (Id)) = E_Task_Type
14620 and then Is_Single_Concurrent_Type (Etype (Id));
14621 end Is_Single_Task_Object;
14623 -------------------------------------
14624 -- Is_SPARK_05_Initialization_Expr --
14625 -------------------------------------
14627 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
14628 Is_Ok : Boolean;
14629 Expr : Node_Id;
14630 Comp_Assn : Node_Id;
14631 Orig_N : constant Node_Id := Original_Node (N);
14633 begin
14634 Is_Ok := True;
14636 if not Comes_From_Source (Orig_N) then
14637 goto Done;
14638 end if;
14640 pragma Assert (Nkind (Orig_N) in N_Subexpr);
14642 case Nkind (Orig_N) is
14643 when N_Character_Literal
14644 | N_Integer_Literal
14645 | N_Real_Literal
14646 | N_String_Literal
14648 null;
14650 when N_Expanded_Name
14651 | N_Identifier
14653 if Is_Entity_Name (Orig_N)
14654 and then Present (Entity (Orig_N)) -- needed in some cases
14655 then
14656 case Ekind (Entity (Orig_N)) is
14657 when E_Constant
14658 | E_Enumeration_Literal
14659 | E_Named_Integer
14660 | E_Named_Real
14662 null;
14664 when others =>
14665 if Is_Type (Entity (Orig_N)) then
14666 null;
14667 else
14668 Is_Ok := False;
14669 end if;
14670 end case;
14671 end if;
14673 when N_Qualified_Expression
14674 | N_Type_Conversion
14676 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
14678 when N_Unary_Op =>
14679 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
14681 when N_Binary_Op
14682 | N_Membership_Test
14683 | N_Short_Circuit
14685 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
14686 and then
14687 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
14689 when N_Aggregate
14690 | N_Extension_Aggregate
14692 if Nkind (Orig_N) = N_Extension_Aggregate then
14693 Is_Ok :=
14694 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
14695 end if;
14697 Expr := First (Expressions (Orig_N));
14698 while Present (Expr) loop
14699 if not Is_SPARK_05_Initialization_Expr (Expr) then
14700 Is_Ok := False;
14701 goto Done;
14702 end if;
14704 Next (Expr);
14705 end loop;
14707 Comp_Assn := First (Component_Associations (Orig_N));
14708 while Present (Comp_Assn) loop
14709 Expr := Expression (Comp_Assn);
14711 -- Note: test for Present here needed for box assocation
14713 if Present (Expr)
14714 and then not Is_SPARK_05_Initialization_Expr (Expr)
14715 then
14716 Is_Ok := False;
14717 goto Done;
14718 end if;
14720 Next (Comp_Assn);
14721 end loop;
14723 when N_Attribute_Reference =>
14724 if Nkind (Prefix (Orig_N)) in N_Subexpr then
14725 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
14726 end if;
14728 Expr := First (Expressions (Orig_N));
14729 while Present (Expr) loop
14730 if not Is_SPARK_05_Initialization_Expr (Expr) then
14731 Is_Ok := False;
14732 goto Done;
14733 end if;
14735 Next (Expr);
14736 end loop;
14738 -- Selected components might be expanded named not yet resolved, so
14739 -- default on the safe side. (Eg on sparklex.ads)
14741 when N_Selected_Component =>
14742 null;
14744 when others =>
14745 Is_Ok := False;
14746 end case;
14748 <<Done>>
14749 return Is_Ok;
14750 end Is_SPARK_05_Initialization_Expr;
14752 ----------------------------------
14753 -- Is_SPARK_05_Object_Reference --
14754 ----------------------------------
14756 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
14757 begin
14758 if Is_Entity_Name (N) then
14759 return Present (Entity (N))
14760 and then
14761 (Ekind_In (Entity (N), E_Constant, E_Variable)
14762 or else Ekind (Entity (N)) in Formal_Kind);
14764 else
14765 case Nkind (N) is
14766 when N_Selected_Component =>
14767 return Is_SPARK_05_Object_Reference (Prefix (N));
14769 when others =>
14770 return False;
14771 end case;
14772 end if;
14773 end Is_SPARK_05_Object_Reference;
14775 -----------------------------
14776 -- Is_Specific_Tagged_Type --
14777 -----------------------------
14779 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
14780 Full_Typ : Entity_Id;
14782 begin
14783 -- Handle private types
14785 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
14786 Full_Typ := Full_View (Typ);
14787 else
14788 Full_Typ := Typ;
14789 end if;
14791 -- A specific tagged type is a non-class-wide tagged type
14793 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
14794 end Is_Specific_Tagged_Type;
14796 ------------------
14797 -- Is_Statement --
14798 ------------------
14800 function Is_Statement (N : Node_Id) return Boolean is
14801 begin
14802 return
14803 Nkind (N) in N_Statement_Other_Than_Procedure_Call
14804 or else Nkind (N) = N_Procedure_Call_Statement;
14805 end Is_Statement;
14807 ---------------------------------------
14808 -- Is_Subprogram_Contract_Annotation --
14809 ---------------------------------------
14811 function Is_Subprogram_Contract_Annotation
14812 (Item : Node_Id) return Boolean
14814 Nam : Name_Id;
14816 begin
14817 if Nkind (Item) = N_Aspect_Specification then
14818 Nam := Chars (Identifier (Item));
14820 else pragma Assert (Nkind (Item) = N_Pragma);
14821 Nam := Pragma_Name (Item);
14822 end if;
14824 return Nam = Name_Contract_Cases
14825 or else Nam = Name_Depends
14826 or else Nam = Name_Extensions_Visible
14827 or else Nam = Name_Global
14828 or else Nam = Name_Post
14829 or else Nam = Name_Post_Class
14830 or else Nam = Name_Postcondition
14831 or else Nam = Name_Pre
14832 or else Nam = Name_Pre_Class
14833 or else Nam = Name_Precondition
14834 or else Nam = Name_Refined_Depends
14835 or else Nam = Name_Refined_Global
14836 or else Nam = Name_Refined_Post
14837 or else Nam = Name_Test_Case;
14838 end Is_Subprogram_Contract_Annotation;
14840 --------------------------------------------------
14841 -- Is_Subprogram_Stub_Without_Prior_Declaration --
14842 --------------------------------------------------
14844 function Is_Subprogram_Stub_Without_Prior_Declaration
14845 (N : Node_Id) return Boolean
14847 begin
14848 -- A subprogram stub without prior declaration serves as declaration for
14849 -- the actual subprogram body. As such, it has an attached defining
14850 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
14852 return Nkind (N) = N_Subprogram_Body_Stub
14853 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
14854 end Is_Subprogram_Stub_Without_Prior_Declaration;
14856 --------------------------
14857 -- Is_Suspension_Object --
14858 --------------------------
14860 function Is_Suspension_Object (Id : Entity_Id) return Boolean is
14861 begin
14862 -- This approach does an exact name match rather than to rely on
14863 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
14864 -- front end at point where all auxiliary tables are locked and any
14865 -- modifications to them are treated as violations. Do not tamper with
14866 -- the tables, instead examine the Chars fields of all the scopes of Id.
14868 return
14869 Chars (Id) = Name_Suspension_Object
14870 and then Present (Scope (Id))
14871 and then Chars (Scope (Id)) = Name_Synchronous_Task_Control
14872 and then Present (Scope (Scope (Id)))
14873 and then Chars (Scope (Scope (Id))) = Name_Ada
14874 and then Present (Scope (Scope (Scope (Id))))
14875 and then Scope (Scope (Scope (Id))) = Standard_Standard;
14876 end Is_Suspension_Object;
14878 ----------------------------
14879 -- Is_Synchronized_Object --
14880 ----------------------------
14882 function Is_Synchronized_Object (Id : Entity_Id) return Boolean is
14883 Prag : Node_Id;
14885 begin
14886 if Is_Object (Id) then
14888 -- The object is synchronized if it is of a type that yields a
14889 -- synchronized object.
14891 if Yields_Synchronized_Object (Etype (Id)) then
14892 return True;
14894 -- The object is synchronized if it is atomic and Async_Writers is
14895 -- enabled.
14897 elsif Is_Atomic (Id) and then Async_Writers_Enabled (Id) then
14898 return True;
14900 -- A constant is a synchronized object by default
14902 elsif Ekind (Id) = E_Constant then
14903 return True;
14905 -- A variable is a synchronized object if it is subject to pragma
14906 -- Constant_After_Elaboration.
14908 elsif Ekind (Id) = E_Variable then
14909 Prag := Get_Pragma (Id, Pragma_Constant_After_Elaboration);
14911 return Present (Prag) and then Is_Enabled_Pragma (Prag);
14912 end if;
14913 end if;
14915 -- Otherwise the input is not an object or it does not qualify as a
14916 -- synchronized object.
14918 return False;
14919 end Is_Synchronized_Object;
14921 ---------------------------------
14922 -- Is_Synchronized_Tagged_Type --
14923 ---------------------------------
14925 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
14926 Kind : constant Entity_Kind := Ekind (Base_Type (E));
14928 begin
14929 -- A task or protected type derived from an interface is a tagged type.
14930 -- Such a tagged type is called a synchronized tagged type, as are
14931 -- synchronized interfaces and private extensions whose declaration
14932 -- includes the reserved word synchronized.
14934 return (Is_Tagged_Type (E)
14935 and then (Kind = E_Task_Type
14936 or else
14937 Kind = E_Protected_Type))
14938 or else
14939 (Is_Interface (E)
14940 and then Is_Synchronized_Interface (E))
14941 or else
14942 (Ekind (E) = E_Record_Type_With_Private
14943 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
14944 and then (Synchronized_Present (Parent (E))
14945 or else Is_Synchronized_Interface (Etype (E))));
14946 end Is_Synchronized_Tagged_Type;
14948 -----------------
14949 -- Is_Transfer --
14950 -----------------
14952 function Is_Transfer (N : Node_Id) return Boolean is
14953 Kind : constant Node_Kind := Nkind (N);
14955 begin
14956 if Kind = N_Simple_Return_Statement
14957 or else
14958 Kind = N_Extended_Return_Statement
14959 or else
14960 Kind = N_Goto_Statement
14961 or else
14962 Kind = N_Raise_Statement
14963 or else
14964 Kind = N_Requeue_Statement
14965 then
14966 return True;
14968 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
14969 and then No (Condition (N))
14970 then
14971 return True;
14973 elsif Kind = N_Procedure_Call_Statement
14974 and then Is_Entity_Name (Name (N))
14975 and then Present (Entity (Name (N)))
14976 and then No_Return (Entity (Name (N)))
14977 then
14978 return True;
14980 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
14981 return True;
14983 else
14984 return False;
14985 end if;
14986 end Is_Transfer;
14988 -------------
14989 -- Is_True --
14990 -------------
14992 function Is_True (U : Uint) return Boolean is
14993 begin
14994 return (U /= 0);
14995 end Is_True;
14997 --------------------------------------
14998 -- Is_Unchecked_Conversion_Instance --
14999 --------------------------------------
15001 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
15002 Par : Node_Id;
15004 begin
15005 -- Look for a function whose generic parent is the predefined intrinsic
15006 -- function Unchecked_Conversion, or for one that renames such an
15007 -- instance.
15009 if Ekind (Id) = E_Function then
15010 Par := Parent (Id);
15012 if Nkind (Par) = N_Function_Specification then
15013 Par := Generic_Parent (Par);
15015 if Present (Par) then
15016 return
15017 Chars (Par) = Name_Unchecked_Conversion
15018 and then Is_Intrinsic_Subprogram (Par)
15019 and then Is_Predefined_File_Name
15020 (Unit_File_Name (Get_Source_Unit (Par)));
15021 else
15022 return
15023 Present (Alias (Id))
15024 and then Is_Unchecked_Conversion_Instance (Alias (Id));
15025 end if;
15026 end if;
15027 end if;
15029 return False;
15030 end Is_Unchecked_Conversion_Instance;
15032 -------------------------------
15033 -- Is_Universal_Numeric_Type --
15034 -------------------------------
15036 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
15037 begin
15038 return T = Universal_Integer or else T = Universal_Real;
15039 end Is_Universal_Numeric_Type;
15041 ----------------------------
15042 -- Is_Variable_Size_Array --
15043 ----------------------------
15045 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
15046 Idx : Node_Id;
15048 begin
15049 pragma Assert (Is_Array_Type (E));
15051 -- Check if some index is initialized with a non-constant value
15053 Idx := First_Index (E);
15054 while Present (Idx) loop
15055 if Nkind (Idx) = N_Range then
15056 if not Is_Constant_Bound (Low_Bound (Idx))
15057 or else not Is_Constant_Bound (High_Bound (Idx))
15058 then
15059 return True;
15060 end if;
15061 end if;
15063 Idx := Next_Index (Idx);
15064 end loop;
15066 return False;
15067 end Is_Variable_Size_Array;
15069 -----------------------------
15070 -- Is_Variable_Size_Record --
15071 -----------------------------
15073 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
15074 Comp : Entity_Id;
15075 Comp_Typ : Entity_Id;
15077 begin
15078 pragma Assert (Is_Record_Type (E));
15080 Comp := First_Entity (E);
15081 while Present (Comp) loop
15082 Comp_Typ := Etype (Comp);
15084 -- Recursive call if the record type has discriminants
15086 if Is_Record_Type (Comp_Typ)
15087 and then Has_Discriminants (Comp_Typ)
15088 and then Is_Variable_Size_Record (Comp_Typ)
15089 then
15090 return True;
15092 elsif Is_Array_Type (Comp_Typ)
15093 and then Is_Variable_Size_Array (Comp_Typ)
15094 then
15095 return True;
15096 end if;
15098 Next_Entity (Comp);
15099 end loop;
15101 return False;
15102 end Is_Variable_Size_Record;
15104 -----------------
15105 -- Is_Variable --
15106 -----------------
15108 function Is_Variable
15109 (N : Node_Id;
15110 Use_Original_Node : Boolean := True) return Boolean
15112 Orig_Node : Node_Id;
15114 function In_Protected_Function (E : Entity_Id) return Boolean;
15115 -- Within a protected function, the private components of the enclosing
15116 -- protected type are constants. A function nested within a (protected)
15117 -- procedure is not itself protected. Within the body of a protected
15118 -- function the current instance of the protected type is a constant.
15120 function Is_Variable_Prefix (P : Node_Id) return Boolean;
15121 -- Prefixes can involve implicit dereferences, in which case we must
15122 -- test for the case of a reference of a constant access type, which can
15123 -- can never be a variable.
15125 ---------------------------
15126 -- In_Protected_Function --
15127 ---------------------------
15129 function In_Protected_Function (E : Entity_Id) return Boolean is
15130 Prot : Entity_Id;
15131 S : Entity_Id;
15133 begin
15134 -- E is the current instance of a type
15136 if Is_Type (E) then
15137 Prot := E;
15139 -- E is an object
15141 else
15142 Prot := Scope (E);
15143 end if;
15145 if not Is_Protected_Type (Prot) then
15146 return False;
15148 else
15149 S := Current_Scope;
15150 while Present (S) and then S /= Prot loop
15151 if Ekind (S) = E_Function and then Scope (S) = Prot then
15152 return True;
15153 end if;
15155 S := Scope (S);
15156 end loop;
15158 return False;
15159 end if;
15160 end In_Protected_Function;
15162 ------------------------
15163 -- Is_Variable_Prefix --
15164 ------------------------
15166 function Is_Variable_Prefix (P : Node_Id) return Boolean is
15167 begin
15168 if Is_Access_Type (Etype (P)) then
15169 return not Is_Access_Constant (Root_Type (Etype (P)));
15171 -- For the case of an indexed component whose prefix has a packed
15172 -- array type, the prefix has been rewritten into a type conversion.
15173 -- Determine variable-ness from the converted expression.
15175 elsif Nkind (P) = N_Type_Conversion
15176 and then not Comes_From_Source (P)
15177 and then Is_Array_Type (Etype (P))
15178 and then Is_Packed (Etype (P))
15179 then
15180 return Is_Variable (Expression (P));
15182 else
15183 return Is_Variable (P);
15184 end if;
15185 end Is_Variable_Prefix;
15187 -- Start of processing for Is_Variable
15189 begin
15190 -- Special check, allow x'Deref(expr) as a variable
15192 if Nkind (N) = N_Attribute_Reference
15193 and then Attribute_Name (N) = Name_Deref
15194 then
15195 return True;
15196 end if;
15198 -- Check if we perform the test on the original node since this may be a
15199 -- test of syntactic categories which must not be disturbed by whatever
15200 -- rewriting might have occurred. For example, an aggregate, which is
15201 -- certainly NOT a variable, could be turned into a variable by
15202 -- expansion.
15204 if Use_Original_Node then
15205 Orig_Node := Original_Node (N);
15206 else
15207 Orig_Node := N;
15208 end if;
15210 -- Definitely OK if Assignment_OK is set. Since this is something that
15211 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
15213 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
15214 return True;
15216 -- Normally we go to the original node, but there is one exception where
15217 -- we use the rewritten node, namely when it is an explicit dereference.
15218 -- The generated code may rewrite a prefix which is an access type with
15219 -- an explicit dereference. The dereference is a variable, even though
15220 -- the original node may not be (since it could be a constant of the
15221 -- access type).
15223 -- In Ada 2005 we have a further case to consider: the prefix may be a
15224 -- function call given in prefix notation. The original node appears to
15225 -- be a selected component, but we need to examine the call.
15227 elsif Nkind (N) = N_Explicit_Dereference
15228 and then Nkind (Orig_Node) /= N_Explicit_Dereference
15229 and then Present (Etype (Orig_Node))
15230 and then Is_Access_Type (Etype (Orig_Node))
15231 then
15232 -- Note that if the prefix is an explicit dereference that does not
15233 -- come from source, we must check for a rewritten function call in
15234 -- prefixed notation before other forms of rewriting, to prevent a
15235 -- compiler crash.
15237 return
15238 (Nkind (Orig_Node) = N_Function_Call
15239 and then not Is_Access_Constant (Etype (Prefix (N))))
15240 or else
15241 Is_Variable_Prefix (Original_Node (Prefix (N)));
15243 -- in Ada 2012, the dereference may have been added for a type with
15244 -- a declared implicit dereference aspect. Check that it is not an
15245 -- access to constant.
15247 elsif Nkind (N) = N_Explicit_Dereference
15248 and then Present (Etype (Orig_Node))
15249 and then Ada_Version >= Ada_2012
15250 and then Has_Implicit_Dereference (Etype (Orig_Node))
15251 then
15252 return not Is_Access_Constant (Etype (Prefix (N)));
15254 -- A function call is never a variable
15256 elsif Nkind (N) = N_Function_Call then
15257 return False;
15259 -- All remaining checks use the original node
15261 elsif Is_Entity_Name (Orig_Node)
15262 and then Present (Entity (Orig_Node))
15263 then
15264 declare
15265 E : constant Entity_Id := Entity (Orig_Node);
15266 K : constant Entity_Kind := Ekind (E);
15268 begin
15269 return (K = E_Variable
15270 and then Nkind (Parent (E)) /= N_Exception_Handler)
15271 or else (K = E_Component
15272 and then not In_Protected_Function (E))
15273 or else K = E_Out_Parameter
15274 or else K = E_In_Out_Parameter
15275 or else K = E_Generic_In_Out_Parameter
15277 -- Current instance of type. If this is a protected type, check
15278 -- we are not within the body of one of its protected functions.
15280 or else (Is_Type (E)
15281 and then In_Open_Scopes (E)
15282 and then not In_Protected_Function (E))
15284 or else (Is_Incomplete_Or_Private_Type (E)
15285 and then In_Open_Scopes (Full_View (E)));
15286 end;
15288 else
15289 case Nkind (Orig_Node) is
15290 when N_Indexed_Component
15291 | N_Slice
15293 return Is_Variable_Prefix (Prefix (Orig_Node));
15295 when N_Selected_Component =>
15296 return (Is_Variable (Selector_Name (Orig_Node))
15297 and then Is_Variable_Prefix (Prefix (Orig_Node)))
15298 or else
15299 (Nkind (N) = N_Expanded_Name
15300 and then Scope (Entity (N)) = Entity (Prefix (N)));
15302 -- For an explicit dereference, the type of the prefix cannot
15303 -- be an access to constant or an access to subprogram.
15305 when N_Explicit_Dereference =>
15306 declare
15307 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
15308 begin
15309 return Is_Access_Type (Typ)
15310 and then not Is_Access_Constant (Root_Type (Typ))
15311 and then Ekind (Typ) /= E_Access_Subprogram_Type;
15312 end;
15314 -- The type conversion is the case where we do not deal with the
15315 -- context dependent special case of an actual parameter. Thus
15316 -- the type conversion is only considered a variable for the
15317 -- purposes of this routine if the target type is tagged. However,
15318 -- a type conversion is considered to be a variable if it does not
15319 -- come from source (this deals for example with the conversions
15320 -- of expressions to their actual subtypes).
15322 when N_Type_Conversion =>
15323 return Is_Variable (Expression (Orig_Node))
15324 and then
15325 (not Comes_From_Source (Orig_Node)
15326 or else
15327 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
15328 and then
15329 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
15331 -- GNAT allows an unchecked type conversion as a variable. This
15332 -- only affects the generation of internal expanded code, since
15333 -- calls to instantiations of Unchecked_Conversion are never
15334 -- considered variables (since they are function calls).
15336 when N_Unchecked_Type_Conversion =>
15337 return Is_Variable (Expression (Orig_Node));
15339 when others =>
15340 return False;
15341 end case;
15342 end if;
15343 end Is_Variable;
15345 ------------------------------
15346 -- Is_Verifiable_DIC_Pragma --
15347 ------------------------------
15349 function Is_Verifiable_DIC_Pragma (Prag : Node_Id) return Boolean is
15350 Args : constant List_Id := Pragma_Argument_Associations (Prag);
15352 begin
15353 -- To qualify as verifiable, a DIC pragma must have a non-null argument
15355 return
15356 Present (Args)
15357 and then Nkind (Get_Pragma_Arg (First (Args))) /= N_Null;
15358 end Is_Verifiable_DIC_Pragma;
15360 ---------------------------
15361 -- Is_Visibly_Controlled --
15362 ---------------------------
15364 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
15365 Root : constant Entity_Id := Root_Type (T);
15366 begin
15367 return Chars (Scope (Root)) = Name_Finalization
15368 and then Chars (Scope (Scope (Root))) = Name_Ada
15369 and then Scope (Scope (Scope (Root))) = Standard_Standard;
15370 end Is_Visibly_Controlled;
15372 --------------------------
15373 -- Is_Volatile_Function --
15374 --------------------------
15376 function Is_Volatile_Function (Func_Id : Entity_Id) return Boolean is
15377 begin
15378 pragma Assert (Ekind_In (Func_Id, E_Function, E_Generic_Function));
15380 -- A function declared within a protected type is volatile
15382 if Is_Protected_Type (Scope (Func_Id)) then
15383 return True;
15385 -- An instance of Ada.Unchecked_Conversion is a volatile function if
15386 -- either the source or the target are effectively volatile.
15388 elsif Is_Unchecked_Conversion_Instance (Func_Id)
15389 and then Has_Effectively_Volatile_Profile (Func_Id)
15390 then
15391 return True;
15393 -- Otherwise the function is treated as volatile if it is subject to
15394 -- enabled pragma Volatile_Function.
15396 else
15397 return
15398 Is_Enabled_Pragma (Get_Pragma (Func_Id, Pragma_Volatile_Function));
15399 end if;
15400 end Is_Volatile_Function;
15402 ------------------------
15403 -- Is_Volatile_Object --
15404 ------------------------
15406 function Is_Volatile_Object (N : Node_Id) return Boolean is
15408 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
15409 -- If prefix is an implicit dereference, examine designated type
15411 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
15412 -- Determines if given object has volatile components
15414 ------------------------
15415 -- Is_Volatile_Prefix --
15416 ------------------------
15418 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
15419 Typ : constant Entity_Id := Etype (N);
15421 begin
15422 if Is_Access_Type (Typ) then
15423 declare
15424 Dtyp : constant Entity_Id := Designated_Type (Typ);
15426 begin
15427 return Is_Volatile (Dtyp)
15428 or else Has_Volatile_Components (Dtyp);
15429 end;
15431 else
15432 return Object_Has_Volatile_Components (N);
15433 end if;
15434 end Is_Volatile_Prefix;
15436 ------------------------------------
15437 -- Object_Has_Volatile_Components --
15438 ------------------------------------
15440 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
15441 Typ : constant Entity_Id := Etype (N);
15443 begin
15444 if Is_Volatile (Typ)
15445 or else Has_Volatile_Components (Typ)
15446 then
15447 return True;
15449 elsif Is_Entity_Name (N)
15450 and then (Has_Volatile_Components (Entity (N))
15451 or else Is_Volatile (Entity (N)))
15452 then
15453 return True;
15455 elsif Nkind (N) = N_Indexed_Component
15456 or else Nkind (N) = N_Selected_Component
15457 then
15458 return Is_Volatile_Prefix (Prefix (N));
15460 else
15461 return False;
15462 end if;
15463 end Object_Has_Volatile_Components;
15465 -- Start of processing for Is_Volatile_Object
15467 begin
15468 if Nkind (N) = N_Defining_Identifier then
15469 return Is_Volatile (N) or else Is_Volatile (Etype (N));
15471 elsif Nkind (N) = N_Expanded_Name then
15472 return Is_Volatile_Object (Entity (N));
15474 elsif Is_Volatile (Etype (N))
15475 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
15476 then
15477 return True;
15479 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
15480 and then Is_Volatile_Prefix (Prefix (N))
15481 then
15482 return True;
15484 elsif Nkind (N) = N_Selected_Component
15485 and then Is_Volatile (Entity (Selector_Name (N)))
15486 then
15487 return True;
15489 else
15490 return False;
15491 end if;
15492 end Is_Volatile_Object;
15494 ---------------------------
15495 -- Itype_Has_Declaration --
15496 ---------------------------
15498 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
15499 begin
15500 pragma Assert (Is_Itype (Id));
15501 return Present (Parent (Id))
15502 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
15503 N_Subtype_Declaration)
15504 and then Defining_Entity (Parent (Id)) = Id;
15505 end Itype_Has_Declaration;
15507 -------------------------
15508 -- Kill_Current_Values --
15509 -------------------------
15511 procedure Kill_Current_Values
15512 (Ent : Entity_Id;
15513 Last_Assignment_Only : Boolean := False)
15515 begin
15516 if Is_Assignable (Ent) then
15517 Set_Last_Assignment (Ent, Empty);
15518 end if;
15520 if Is_Object (Ent) then
15521 if not Last_Assignment_Only then
15522 Kill_Checks (Ent);
15523 Set_Current_Value (Ent, Empty);
15525 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
15526 -- for a constant. Once the constant is elaborated, its value is
15527 -- not changed, therefore the associated flags that describe the
15528 -- value should not be modified either.
15530 if Ekind (Ent) = E_Constant then
15531 null;
15533 -- Non-constant entities
15535 else
15536 if not Can_Never_Be_Null (Ent) then
15537 Set_Is_Known_Non_Null (Ent, False);
15538 end if;
15540 Set_Is_Known_Null (Ent, False);
15542 -- Reset the Is_Known_Valid flag unless the type is always
15543 -- valid. This does not apply to a loop parameter because its
15544 -- bounds are defined by the loop header and therefore always
15545 -- valid.
15547 if not Is_Known_Valid (Etype (Ent))
15548 and then Ekind (Ent) /= E_Loop_Parameter
15549 then
15550 Set_Is_Known_Valid (Ent, False);
15551 end if;
15552 end if;
15553 end if;
15554 end if;
15555 end Kill_Current_Values;
15557 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
15558 S : Entity_Id;
15560 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
15561 -- Clear current value for entity E and all entities chained to E
15563 ------------------------------------------
15564 -- Kill_Current_Values_For_Entity_Chain --
15565 ------------------------------------------
15567 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
15568 Ent : Entity_Id;
15569 begin
15570 Ent := E;
15571 while Present (Ent) loop
15572 Kill_Current_Values (Ent, Last_Assignment_Only);
15573 Next_Entity (Ent);
15574 end loop;
15575 end Kill_Current_Values_For_Entity_Chain;
15577 -- Start of processing for Kill_Current_Values
15579 begin
15580 -- Kill all saved checks, a special case of killing saved values
15582 if not Last_Assignment_Only then
15583 Kill_All_Checks;
15584 end if;
15586 -- Loop through relevant scopes, which includes the current scope and
15587 -- any parent scopes if the current scope is a block or a package.
15589 S := Current_Scope;
15590 Scope_Loop : loop
15592 -- Clear current values of all entities in current scope
15594 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
15596 -- If scope is a package, also clear current values of all private
15597 -- entities in the scope.
15599 if Is_Package_Or_Generic_Package (S)
15600 or else Is_Concurrent_Type (S)
15601 then
15602 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
15603 end if;
15605 -- If this is a not a subprogram, deal with parents
15607 if not Is_Subprogram (S) then
15608 S := Scope (S);
15609 exit Scope_Loop when S = Standard_Standard;
15610 else
15611 exit Scope_Loop;
15612 end if;
15613 end loop Scope_Loop;
15614 end Kill_Current_Values;
15616 --------------------------
15617 -- Kill_Size_Check_Code --
15618 --------------------------
15620 procedure Kill_Size_Check_Code (E : Entity_Id) is
15621 begin
15622 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
15623 and then Present (Size_Check_Code (E))
15624 then
15625 Remove (Size_Check_Code (E));
15626 Set_Size_Check_Code (E, Empty);
15627 end if;
15628 end Kill_Size_Check_Code;
15630 --------------------------
15631 -- Known_To_Be_Assigned --
15632 --------------------------
15634 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
15635 P : constant Node_Id := Parent (N);
15637 begin
15638 case Nkind (P) is
15640 -- Test left side of assignment
15642 when N_Assignment_Statement =>
15643 return N = Name (P);
15645 -- Function call arguments are never lvalues
15647 when N_Function_Call =>
15648 return False;
15650 -- Positional parameter for procedure or accept call
15652 when N_Accept_Statement
15653 | N_Procedure_Call_Statement
15655 declare
15656 Proc : Entity_Id;
15657 Form : Entity_Id;
15658 Act : Node_Id;
15660 begin
15661 Proc := Get_Subprogram_Entity (P);
15663 if No (Proc) then
15664 return False;
15665 end if;
15667 -- If we are not a list member, something is strange, so
15668 -- be conservative and return False.
15670 if not Is_List_Member (N) then
15671 return False;
15672 end if;
15674 -- We are going to find the right formal by stepping forward
15675 -- through the formals, as we step backwards in the actuals.
15677 Form := First_Formal (Proc);
15678 Act := N;
15679 loop
15680 -- If no formal, something is weird, so be conservative
15681 -- and return False.
15683 if No (Form) then
15684 return False;
15685 end if;
15687 Prev (Act);
15688 exit when No (Act);
15689 Next_Formal (Form);
15690 end loop;
15692 return Ekind (Form) /= E_In_Parameter;
15693 end;
15695 -- Named parameter for procedure or accept call
15697 when N_Parameter_Association =>
15698 declare
15699 Proc : Entity_Id;
15700 Form : Entity_Id;
15702 begin
15703 Proc := Get_Subprogram_Entity (Parent (P));
15705 if No (Proc) then
15706 return False;
15707 end if;
15709 -- Loop through formals to find the one that matches
15711 Form := First_Formal (Proc);
15712 loop
15713 -- If no matching formal, that's peculiar, some kind of
15714 -- previous error, so return False to be conservative.
15715 -- Actually this also happens in legal code in the case
15716 -- where P is a parameter association for an Extra_Formal???
15718 if No (Form) then
15719 return False;
15720 end if;
15722 -- Else test for match
15724 if Chars (Form) = Chars (Selector_Name (P)) then
15725 return Ekind (Form) /= E_In_Parameter;
15726 end if;
15728 Next_Formal (Form);
15729 end loop;
15730 end;
15732 -- Test for appearing in a conversion that itself appears
15733 -- in an lvalue context, since this should be an lvalue.
15735 when N_Type_Conversion =>
15736 return Known_To_Be_Assigned (P);
15738 -- All other references are definitely not known to be modifications
15740 when others =>
15741 return False;
15742 end case;
15743 end Known_To_Be_Assigned;
15745 ---------------------------
15746 -- Last_Source_Statement --
15747 ---------------------------
15749 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
15750 N : Node_Id;
15752 begin
15753 N := Last (Statements (HSS));
15754 while Present (N) loop
15755 exit when Comes_From_Source (N);
15756 Prev (N);
15757 end loop;
15759 return N;
15760 end Last_Source_Statement;
15762 ----------------------------------
15763 -- Matching_Static_Array_Bounds --
15764 ----------------------------------
15766 function Matching_Static_Array_Bounds
15767 (L_Typ : Node_Id;
15768 R_Typ : Node_Id) return Boolean
15770 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
15771 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
15773 L_Index : Node_Id;
15774 R_Index : Node_Id;
15775 L_Low : Node_Id;
15776 L_High : Node_Id;
15777 L_Len : Uint;
15778 R_Low : Node_Id;
15779 R_High : Node_Id;
15780 R_Len : Uint;
15782 begin
15783 if L_Ndims /= R_Ndims then
15784 return False;
15785 end if;
15787 -- Unconstrained types do not have static bounds
15789 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
15790 return False;
15791 end if;
15793 -- First treat specially the first dimension, as the lower bound and
15794 -- length of string literals are not stored like those of arrays.
15796 if Ekind (L_Typ) = E_String_Literal_Subtype then
15797 L_Low := String_Literal_Low_Bound (L_Typ);
15798 L_Len := String_Literal_Length (L_Typ);
15799 else
15800 L_Index := First_Index (L_Typ);
15801 Get_Index_Bounds (L_Index, L_Low, L_High);
15803 if Is_OK_Static_Expression (L_Low)
15804 and then
15805 Is_OK_Static_Expression (L_High)
15806 then
15807 if Expr_Value (L_High) < Expr_Value (L_Low) then
15808 L_Len := Uint_0;
15809 else
15810 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
15811 end if;
15812 else
15813 return False;
15814 end if;
15815 end if;
15817 if Ekind (R_Typ) = E_String_Literal_Subtype then
15818 R_Low := String_Literal_Low_Bound (R_Typ);
15819 R_Len := String_Literal_Length (R_Typ);
15820 else
15821 R_Index := First_Index (R_Typ);
15822 Get_Index_Bounds (R_Index, R_Low, R_High);
15824 if Is_OK_Static_Expression (R_Low)
15825 and then
15826 Is_OK_Static_Expression (R_High)
15827 then
15828 if Expr_Value (R_High) < Expr_Value (R_Low) then
15829 R_Len := Uint_0;
15830 else
15831 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
15832 end if;
15833 else
15834 return False;
15835 end if;
15836 end if;
15838 if (Is_OK_Static_Expression (L_Low)
15839 and then
15840 Is_OK_Static_Expression (R_Low))
15841 and then Expr_Value (L_Low) = Expr_Value (R_Low)
15842 and then L_Len = R_Len
15843 then
15844 null;
15845 else
15846 return False;
15847 end if;
15849 -- Then treat all other dimensions
15851 for Indx in 2 .. L_Ndims loop
15852 Next (L_Index);
15853 Next (R_Index);
15855 Get_Index_Bounds (L_Index, L_Low, L_High);
15856 Get_Index_Bounds (R_Index, R_Low, R_High);
15858 if (Is_OK_Static_Expression (L_Low) and then
15859 Is_OK_Static_Expression (L_High) and then
15860 Is_OK_Static_Expression (R_Low) and then
15861 Is_OK_Static_Expression (R_High))
15862 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
15863 and then
15864 Expr_Value (L_High) = Expr_Value (R_High))
15865 then
15866 null;
15867 else
15868 return False;
15869 end if;
15870 end loop;
15872 -- If we fall through the loop, all indexes matched
15874 return True;
15875 end Matching_Static_Array_Bounds;
15877 -------------------
15878 -- May_Be_Lvalue --
15879 -------------------
15881 function May_Be_Lvalue (N : Node_Id) return Boolean is
15882 P : constant Node_Id := Parent (N);
15884 begin
15885 case Nkind (P) is
15887 -- Test left side of assignment
15889 when N_Assignment_Statement =>
15890 return N = Name (P);
15892 -- Test prefix of component or attribute. Note that the prefix of an
15893 -- explicit or implicit dereference cannot be an l-value. In the case
15894 -- of a 'Read attribute, the reference can be an actual in the
15895 -- argument list of the attribute.
15897 when N_Attribute_Reference =>
15898 return (N = Prefix (P)
15899 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P)))
15900 or else
15901 Attribute_Name (P) = Name_Read;
15903 -- For an expanded name, the name is an lvalue if the expanded name
15904 -- is an lvalue, but the prefix is never an lvalue, since it is just
15905 -- the scope where the name is found.
15907 when N_Expanded_Name =>
15908 if N = Prefix (P) then
15909 return May_Be_Lvalue (P);
15910 else
15911 return False;
15912 end if;
15914 -- For a selected component A.B, A is certainly an lvalue if A.B is.
15915 -- B is a little interesting, if we have A.B := 3, there is some
15916 -- discussion as to whether B is an lvalue or not, we choose to say
15917 -- it is. Note however that A is not an lvalue if it is of an access
15918 -- type since this is an implicit dereference.
15920 when N_Selected_Component =>
15921 if N = Prefix (P)
15922 and then Present (Etype (N))
15923 and then Is_Access_Type (Etype (N))
15924 then
15925 return False;
15926 else
15927 return May_Be_Lvalue (P);
15928 end if;
15930 -- For an indexed component or slice, the index or slice bounds is
15931 -- never an lvalue. The prefix is an lvalue if the indexed component
15932 -- or slice is an lvalue, except if it is an access type, where we
15933 -- have an implicit dereference.
15935 when N_Indexed_Component
15936 | N_Slice
15938 if N /= Prefix (P)
15939 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
15940 then
15941 return False;
15942 else
15943 return May_Be_Lvalue (P);
15944 end if;
15946 -- Prefix of a reference is an lvalue if the reference is an lvalue
15948 when N_Reference =>
15949 return May_Be_Lvalue (P);
15951 -- Prefix of explicit dereference is never an lvalue
15953 when N_Explicit_Dereference =>
15954 return False;
15956 -- Positional parameter for subprogram, entry, or accept call.
15957 -- In older versions of Ada function call arguments are never
15958 -- lvalues. In Ada 2012 functions can have in-out parameters.
15960 when N_Accept_Statement
15961 | N_Entry_Call_Statement
15962 | N_Subprogram_Call
15964 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
15965 return False;
15966 end if;
15968 -- The following mechanism is clumsy and fragile. A single flag
15969 -- set in Resolve_Actuals would be preferable ???
15971 declare
15972 Proc : Entity_Id;
15973 Form : Entity_Id;
15974 Act : Node_Id;
15976 begin
15977 Proc := Get_Subprogram_Entity (P);
15979 if No (Proc) then
15980 return True;
15981 end if;
15983 -- If we are not a list member, something is strange, so be
15984 -- conservative and return True.
15986 if not Is_List_Member (N) then
15987 return True;
15988 end if;
15990 -- We are going to find the right formal by stepping forward
15991 -- through the formals, as we step backwards in the actuals.
15993 Form := First_Formal (Proc);
15994 Act := N;
15995 loop
15996 -- If no formal, something is weird, so be conservative and
15997 -- return True.
15999 if No (Form) then
16000 return True;
16001 end if;
16003 Prev (Act);
16004 exit when No (Act);
16005 Next_Formal (Form);
16006 end loop;
16008 return Ekind (Form) /= E_In_Parameter;
16009 end;
16011 -- Named parameter for procedure or accept call
16013 when N_Parameter_Association =>
16014 declare
16015 Proc : Entity_Id;
16016 Form : Entity_Id;
16018 begin
16019 Proc := Get_Subprogram_Entity (Parent (P));
16021 if No (Proc) then
16022 return True;
16023 end if;
16025 -- Loop through formals to find the one that matches
16027 Form := First_Formal (Proc);
16028 loop
16029 -- If no matching formal, that's peculiar, some kind of
16030 -- previous error, so return True to be conservative.
16031 -- Actually happens with legal code for an unresolved call
16032 -- where we may get the wrong homonym???
16034 if No (Form) then
16035 return True;
16036 end if;
16038 -- Else test for match
16040 if Chars (Form) = Chars (Selector_Name (P)) then
16041 return Ekind (Form) /= E_In_Parameter;
16042 end if;
16044 Next_Formal (Form);
16045 end loop;
16046 end;
16048 -- Test for appearing in a conversion that itself appears in an
16049 -- lvalue context, since this should be an lvalue.
16051 when N_Type_Conversion =>
16052 return May_Be_Lvalue (P);
16054 -- Test for appearance in object renaming declaration
16056 when N_Object_Renaming_Declaration =>
16057 return True;
16059 -- All other references are definitely not lvalues
16061 when others =>
16062 return False;
16063 end case;
16064 end May_Be_Lvalue;
16066 -----------------------
16067 -- Mark_Coextensions --
16068 -----------------------
16070 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
16071 Is_Dynamic : Boolean;
16072 -- Indicates whether the context causes nested coextensions to be
16073 -- dynamic or static
16075 function Mark_Allocator (N : Node_Id) return Traverse_Result;
16076 -- Recognize an allocator node and label it as a dynamic coextension
16078 --------------------
16079 -- Mark_Allocator --
16080 --------------------
16082 function Mark_Allocator (N : Node_Id) return Traverse_Result is
16083 begin
16084 if Nkind (N) = N_Allocator then
16085 if Is_Dynamic then
16086 Set_Is_Dynamic_Coextension (N);
16088 -- If the allocator expression is potentially dynamic, it may
16089 -- be expanded out of order and require dynamic allocation
16090 -- anyway, so we treat the coextension itself as dynamic.
16091 -- Potential optimization ???
16093 elsif Nkind (Expression (N)) = N_Qualified_Expression
16094 and then Nkind (Expression (Expression (N))) = N_Op_Concat
16095 then
16096 Set_Is_Dynamic_Coextension (N);
16097 else
16098 Set_Is_Static_Coextension (N);
16099 end if;
16100 end if;
16102 return OK;
16103 end Mark_Allocator;
16105 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
16107 -- Start of processing for Mark_Coextensions
16109 begin
16110 -- An allocator that appears on the right-hand side of an assignment is
16111 -- treated as a potentially dynamic coextension when the right-hand side
16112 -- is an allocator or a qualified expression.
16114 -- Obj := new ...'(new Coextension ...);
16116 if Nkind (Context_Nod) = N_Assignment_Statement then
16117 Is_Dynamic :=
16118 Nkind_In (Expression (Context_Nod), N_Allocator,
16119 N_Qualified_Expression);
16121 -- An allocator that appears within the expression of a simple return
16122 -- statement is treated as a potentially dynamic coextension when the
16123 -- expression is either aggregate, allocator, or qualified expression.
16125 -- return (new Coextension ...);
16126 -- return new ...'(new Coextension ...);
16128 elsif Nkind (Context_Nod) = N_Simple_Return_Statement then
16129 Is_Dynamic :=
16130 Nkind_In (Expression (Context_Nod), N_Aggregate,
16131 N_Allocator,
16132 N_Qualified_Expression);
16134 -- An alloctor that appears within the initialization expression of an
16135 -- object declaration is considered a potentially dynamic coextension
16136 -- when the initialization expression is an allocator or a qualified
16137 -- expression.
16139 -- Obj : ... := new ...'(new Coextension ...);
16141 -- A similar case arises when the object declaration is part of an
16142 -- extended return statement.
16144 -- return Obj : ... := new ...'(new Coextension ...);
16145 -- return Obj : ... := (new Coextension ...);
16147 elsif Nkind (Context_Nod) = N_Object_Declaration then
16148 Is_Dynamic :=
16149 Nkind_In (Root_Nod, N_Allocator, N_Qualified_Expression)
16150 or else
16151 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
16153 -- This routine should not be called with constructs that cannot contain
16154 -- coextensions.
16156 else
16157 raise Program_Error;
16158 end if;
16160 Mark_Allocators (Root_Nod);
16161 end Mark_Coextensions;
16163 ----------------------
16164 -- Needs_One_Actual --
16165 ----------------------
16167 function Needs_One_Actual (E : Entity_Id) return Boolean is
16168 Formal : Entity_Id;
16170 begin
16171 -- Ada 2005 or later, and formals present
16173 if Ada_Version >= Ada_2005
16174 and then Present (First_Formal (E))
16175 and then No (Default_Value (First_Formal (E)))
16176 then
16177 Formal := Next_Formal (First_Formal (E));
16178 while Present (Formal) loop
16179 if No (Default_Value (Formal)) then
16180 return False;
16181 end if;
16183 Next_Formal (Formal);
16184 end loop;
16186 return True;
16188 -- Ada 83/95 or no formals
16190 else
16191 return False;
16192 end if;
16193 end Needs_One_Actual;
16195 ------------------------
16196 -- New_Copy_List_Tree --
16197 ------------------------
16199 function New_Copy_List_Tree (List : List_Id) return List_Id is
16200 NL : List_Id;
16201 E : Node_Id;
16203 begin
16204 if List = No_List then
16205 return No_List;
16207 else
16208 NL := New_List;
16209 E := First (List);
16211 while Present (E) loop
16212 Append (New_Copy_Tree (E), NL);
16213 E := Next (E);
16214 end loop;
16216 return NL;
16217 end if;
16218 end New_Copy_List_Tree;
16220 -------------------
16221 -- New_Copy_Tree --
16222 -------------------
16224 function New_Copy_Tree
16225 (Source : Node_Id;
16226 Map : Elist_Id := No_Elist;
16227 New_Sloc : Source_Ptr := No_Location;
16228 New_Scope : Entity_Id := Empty) return Node_Id
16230 ------------------------------------
16231 -- Auxiliary Data and Subprograms --
16232 ------------------------------------
16234 use Atree.Unchecked_Access;
16235 use Atree_Private_Part;
16237 -- Our approach here requires a two pass traversal of the tree. The
16238 -- first pass visits all nodes that eventually will be copied looking
16239 -- for defining Itypes. If any defining Itypes are found, then they are
16240 -- copied, and an entry is added to the replacement map. In the second
16241 -- phase, the tree is copied, using the replacement map to replace any
16242 -- Itype references within the copied tree.
16244 -- The following hash tables are used if the Map supplied has more than
16245 -- hash threshold entries to speed up access to the map. If there are
16246 -- fewer entries, then the map is searched sequentially (because setting
16247 -- up a hash table for only a few entries takes more time than it saves.
16249 subtype NCT_Header_Num is Int range 0 .. 511;
16250 -- Defines range of headers in hash tables (512 headers)
16252 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
16253 -- Hash function used for hash operations
16255 ---------------
16256 -- NCT_Assoc --
16257 ---------------
16259 -- The hash table NCT_Assoc associates old entities in the table with
16260 -- their corresponding new entities (i.e. the pairs of entries presented
16261 -- in the original Map argument are Key-Element pairs).
16263 package NCT_Assoc is new Simple_HTable (
16264 Header_Num => NCT_Header_Num,
16265 Element => Entity_Id,
16266 No_Element => Empty,
16267 Key => Entity_Id,
16268 Hash => New_Copy_Hash,
16269 Equal => Types."=");
16271 ---------------------
16272 -- NCT_Itype_Assoc --
16273 ---------------------
16275 -- The hash table NCT_Itype_Assoc contains entries only for those old
16276 -- nodes which have a non-empty Associated_Node_For_Itype set. The key
16277 -- is the associated node, and the element is the new node itself (NOT
16278 -- the associated node for the new node).
16280 package NCT_Itype_Assoc is new Simple_HTable (
16281 Header_Num => NCT_Header_Num,
16282 Element => Entity_Id,
16283 No_Element => Empty,
16284 Key => Entity_Id,
16285 Hash => New_Copy_Hash,
16286 Equal => Types."=");
16288 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
16289 -- Called during second phase to map entities into their corresponding
16290 -- copies using the hash table. If the argument is not an entity, or is
16291 -- not in the hash table, then it is returned unchanged.
16293 procedure Build_NCT_Hash_Tables;
16294 -- Builds hash tables.
16296 function Copy_Elist_With_Replacement
16297 (Old_Elist : Elist_Id) return Elist_Id;
16298 -- Called during second phase to copy element list doing replacements
16300 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
16301 -- Called during the second phase to process a copied Itype. The actual
16302 -- copy happened during the first phase (so that we could make the entry
16303 -- in the mapping), but we still have to deal with the descendants of
16304 -- the copied Itype and copy them where necessary.
16306 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
16307 -- Called during second phase to copy list doing replacements
16309 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
16310 -- Called during second phase to copy node doing replacements
16312 procedure Visit_Elist (E : Elist_Id);
16313 -- Called during first phase to visit all elements of an Elist
16315 procedure Visit_Field (F : Union_Id; N : Node_Id);
16316 -- Visit a single field, recursing to call Visit_Node or Visit_List if
16317 -- the field is a syntactic descendant of the current node (i.e. its
16318 -- parent is Node N).
16320 procedure Visit_Itype (Old_Itype : Entity_Id);
16321 -- Called during first phase to visit subsidiary fields of a defining
16322 -- Itype, and also create a copy and make an entry in the replacement
16323 -- map for the new copy.
16325 procedure Visit_List (L : List_Id);
16326 -- Called during first phase to visit all elements of a List
16328 procedure Visit_Node (N : Node_Or_Entity_Id);
16329 -- Called during first phase to visit a node and all its subtrees
16331 -----------
16332 -- Assoc --
16333 -----------
16335 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
16336 Ent : Entity_Id;
16338 begin
16339 if Nkind (N) not in N_Entity then
16340 return N;
16342 else
16343 Ent := NCT_Assoc.Get (Entity_Id (N));
16345 if Present (Ent) then
16346 return Ent;
16347 end if;
16348 end if;
16350 return N;
16351 end Assoc;
16353 ---------------------------
16354 -- Build_NCT_Hash_Tables --
16355 ---------------------------
16357 procedure Build_NCT_Hash_Tables is
16358 Elmt : Elmt_Id;
16359 Ent : Entity_Id;
16361 begin
16362 if No (Map) then
16363 return;
16364 end if;
16366 Elmt := First_Elmt (Map);
16367 while Present (Elmt) loop
16368 Ent := Node (Elmt);
16370 -- Get new entity, and associate old and new
16372 Next_Elmt (Elmt);
16373 NCT_Assoc.Set (Ent, Node (Elmt));
16375 if Is_Type (Ent) then
16376 declare
16377 Anode : constant Entity_Id :=
16378 Associated_Node_For_Itype (Ent);
16380 begin
16381 if Present (Anode) then
16383 -- Enter a link between the associated node of the old
16384 -- Itype and the new Itype, for updating later when node
16385 -- is copied.
16387 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
16388 end if;
16389 end;
16390 end if;
16392 Next_Elmt (Elmt);
16393 end loop;
16394 end Build_NCT_Hash_Tables;
16396 ---------------------------------
16397 -- Copy_Elist_With_Replacement --
16398 ---------------------------------
16400 function Copy_Elist_With_Replacement
16401 (Old_Elist : Elist_Id) return Elist_Id
16403 M : Elmt_Id;
16404 New_Elist : Elist_Id;
16406 begin
16407 if No (Old_Elist) then
16408 return No_Elist;
16410 else
16411 New_Elist := New_Elmt_List;
16413 M := First_Elmt (Old_Elist);
16414 while Present (M) loop
16415 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
16416 Next_Elmt (M);
16417 end loop;
16418 end if;
16420 return New_Elist;
16421 end Copy_Elist_With_Replacement;
16423 ---------------------------------
16424 -- Copy_Itype_With_Replacement --
16425 ---------------------------------
16427 -- This routine exactly parallels its phase one analog Visit_Itype,
16429 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
16430 begin
16431 -- Translate Next_Entity, Scope, and Etype fields, in case they
16432 -- reference entities that have been mapped into copies.
16434 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
16435 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
16437 if Present (New_Scope) then
16438 Set_Scope (New_Itype, New_Scope);
16439 else
16440 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
16441 end if;
16443 -- Copy referenced fields
16445 if Is_Discrete_Type (New_Itype) then
16446 Set_Scalar_Range (New_Itype,
16447 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
16449 elsif Has_Discriminants (Base_Type (New_Itype)) then
16450 Set_Discriminant_Constraint (New_Itype,
16451 Copy_Elist_With_Replacement
16452 (Discriminant_Constraint (New_Itype)));
16454 elsif Is_Array_Type (New_Itype) then
16455 if Present (First_Index (New_Itype)) then
16456 Set_First_Index (New_Itype,
16457 First (Copy_List_With_Replacement
16458 (List_Containing (First_Index (New_Itype)))));
16459 end if;
16461 if Is_Packed (New_Itype) then
16462 Set_Packed_Array_Impl_Type (New_Itype,
16463 Copy_Node_With_Replacement
16464 (Packed_Array_Impl_Type (New_Itype)));
16465 end if;
16466 end if;
16467 end Copy_Itype_With_Replacement;
16469 --------------------------------
16470 -- Copy_List_With_Replacement --
16471 --------------------------------
16473 function Copy_List_With_Replacement
16474 (Old_List : List_Id) return List_Id
16476 New_List : List_Id;
16477 E : Node_Id;
16479 begin
16480 if Old_List = No_List then
16481 return No_List;
16483 else
16484 New_List := Empty_List;
16486 E := First (Old_List);
16487 while Present (E) loop
16488 Append (Copy_Node_With_Replacement (E), New_List);
16489 Next (E);
16490 end loop;
16492 return New_List;
16493 end if;
16494 end Copy_List_With_Replacement;
16496 --------------------------------
16497 -- Copy_Node_With_Replacement --
16498 --------------------------------
16500 function Copy_Node_With_Replacement
16501 (Old_Node : Node_Id) return Node_Id
16503 New_Node : Node_Id;
16505 procedure Adjust_Named_Associations
16506 (Old_Node : Node_Id;
16507 New_Node : Node_Id);
16508 -- If a call node has named associations, these are chained through
16509 -- the First_Named_Actual, Next_Named_Actual links. These must be
16510 -- propagated separately to the new parameter list, because these
16511 -- are not syntactic fields.
16513 function Copy_Field_With_Replacement
16514 (Field : Union_Id) return Union_Id;
16515 -- Given Field, which is a field of Old_Node, return a copy of it
16516 -- if it is a syntactic field (i.e. its parent is Node), setting
16517 -- the parent of the copy to poit to New_Node. Otherwise returns
16518 -- the field (possibly mapped if it is an entity).
16520 -------------------------------
16521 -- Adjust_Named_Associations --
16522 -------------------------------
16524 procedure Adjust_Named_Associations
16525 (Old_Node : Node_Id;
16526 New_Node : Node_Id)
16528 Old_E : Node_Id;
16529 New_E : Node_Id;
16531 Old_Next : Node_Id;
16532 New_Next : Node_Id;
16534 begin
16535 Old_E := First (Parameter_Associations (Old_Node));
16536 New_E := First (Parameter_Associations (New_Node));
16537 while Present (Old_E) loop
16538 if Nkind (Old_E) = N_Parameter_Association
16539 and then Present (Next_Named_Actual (Old_E))
16540 then
16541 if First_Named_Actual (Old_Node) =
16542 Explicit_Actual_Parameter (Old_E)
16543 then
16544 Set_First_Named_Actual
16545 (New_Node, Explicit_Actual_Parameter (New_E));
16546 end if;
16548 -- Now scan parameter list from the beginning, to locate
16549 -- next named actual, which can be out of order.
16551 Old_Next := First (Parameter_Associations (Old_Node));
16552 New_Next := First (Parameter_Associations (New_Node));
16553 while Nkind (Old_Next) /= N_Parameter_Association
16554 or else Explicit_Actual_Parameter (Old_Next) /=
16555 Next_Named_Actual (Old_E)
16556 loop
16557 Next (Old_Next);
16558 Next (New_Next);
16559 end loop;
16561 Set_Next_Named_Actual
16562 (New_E, Explicit_Actual_Parameter (New_Next));
16563 end if;
16565 Next (Old_E);
16566 Next (New_E);
16567 end loop;
16568 end Adjust_Named_Associations;
16570 ---------------------------------
16571 -- Copy_Field_With_Replacement --
16572 ---------------------------------
16574 function Copy_Field_With_Replacement
16575 (Field : Union_Id) return Union_Id
16577 begin
16578 if Field = Union_Id (Empty) then
16579 return Field;
16581 elsif Field in Node_Range then
16582 declare
16583 Old_N : constant Node_Id := Node_Id (Field);
16584 New_N : Node_Id;
16586 begin
16587 -- If syntactic field, as indicated by the parent pointer
16588 -- being set, then copy the referenced node recursively.
16590 if Parent (Old_N) = Old_Node then
16591 New_N := Copy_Node_With_Replacement (Old_N);
16593 if New_N /= Old_N then
16594 Set_Parent (New_N, New_Node);
16595 end if;
16597 -- For semantic fields, update possible entity reference
16598 -- from the replacement map.
16600 else
16601 New_N := Assoc (Old_N);
16602 end if;
16604 return Union_Id (New_N);
16605 end;
16607 elsif Field in List_Range then
16608 declare
16609 Old_L : constant List_Id := List_Id (Field);
16610 New_L : List_Id;
16612 begin
16613 -- If syntactic field, as indicated by the parent pointer,
16614 -- then recursively copy the entire referenced list.
16616 if Parent (Old_L) = Old_Node then
16617 New_L := Copy_List_With_Replacement (Old_L);
16618 Set_Parent (New_L, New_Node);
16620 -- For semantic list, just returned unchanged
16622 else
16623 New_L := Old_L;
16624 end if;
16626 return Union_Id (New_L);
16627 end;
16629 -- Anything other than a list or a node is returned unchanged
16631 else
16632 return Field;
16633 end if;
16634 end Copy_Field_With_Replacement;
16636 -- Start of processing for Copy_Node_With_Replacement
16638 begin
16639 if Old_Node <= Empty_Or_Error then
16640 return Old_Node;
16642 elsif Nkind (Old_Node) in N_Entity then
16643 return Assoc (Old_Node);
16645 else
16646 New_Node := New_Copy (Old_Node);
16648 -- If the node we are copying is the associated node of a
16649 -- previously copied Itype, then adjust the associated node
16650 -- of the copy of that Itype accordingly.
16652 declare
16653 Ent : constant Entity_Id := NCT_Itype_Assoc.Get (Old_Node);
16655 begin
16656 if Present (Ent) then
16657 Set_Associated_Node_For_Itype (Ent, New_Node);
16658 end if;
16659 end;
16661 -- Recursively copy descendants
16663 Set_Field1
16664 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
16665 Set_Field2
16666 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
16667 Set_Field3
16668 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
16669 Set_Field4
16670 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
16671 Set_Field5
16672 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
16674 -- Adjust Sloc of new node if necessary
16676 if New_Sloc /= No_Location then
16677 Set_Sloc (New_Node, New_Sloc);
16679 -- If we adjust the Sloc, then we are essentially making a
16680 -- completely new node, so the Comes_From_Source flag should
16681 -- be reset to the proper default value.
16683 Set_Comes_From_Source
16684 (New_Node, Default_Node.Comes_From_Source);
16685 end if;
16687 -- If the node is a call and has named associations, set the
16688 -- corresponding links in the copy.
16690 if Nkind_In (Old_Node, N_Entry_Call_Statement,
16691 N_Function_Call,
16692 N_Procedure_Call_Statement)
16693 and then Present (First_Named_Actual (Old_Node))
16694 then
16695 Adjust_Named_Associations (Old_Node, New_Node);
16696 end if;
16698 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
16699 -- The replacement mechanism applies to entities, and is not used
16700 -- here. Eventually we may need a more general graph-copying
16701 -- routine. For now, do a sequential search to find desired node.
16703 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
16704 and then Present (First_Real_Statement (Old_Node))
16705 then
16706 declare
16707 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
16708 N1, N2 : Node_Id;
16710 begin
16711 N1 := First (Statements (Old_Node));
16712 N2 := First (Statements (New_Node));
16714 while N1 /= Old_F loop
16715 Next (N1);
16716 Next (N2);
16717 end loop;
16719 Set_First_Real_Statement (New_Node, N2);
16720 end;
16721 end if;
16722 end if;
16724 -- All done, return copied node
16726 return New_Node;
16727 end Copy_Node_With_Replacement;
16729 -------------------
16730 -- New_Copy_Hash --
16731 -------------------
16733 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
16734 begin
16735 return Nat (E) mod (NCT_Header_Num'Last + 1);
16736 end New_Copy_Hash;
16738 -----------------
16739 -- Visit_Elist --
16740 -----------------
16742 procedure Visit_Elist (E : Elist_Id) is
16743 Elmt : Elmt_Id;
16744 begin
16745 if Present (E) then
16746 Elmt := First_Elmt (E);
16748 while Elmt /= No_Elmt loop
16749 Visit_Node (Node (Elmt));
16750 Next_Elmt (Elmt);
16751 end loop;
16752 end if;
16753 end Visit_Elist;
16755 -----------------
16756 -- Visit_Field --
16757 -----------------
16759 procedure Visit_Field (F : Union_Id; N : Node_Id) is
16760 begin
16761 if F = Union_Id (Empty) then
16762 return;
16764 elsif F in Node_Range then
16766 -- Copy node if it is syntactic, i.e. its parent pointer is
16767 -- set to point to the field that referenced it (certain
16768 -- Itypes will also meet this criterion, which is fine, since
16769 -- these are clearly Itypes that do need to be copied, since
16770 -- we are copying their parent.)
16772 if Parent (Node_Id (F)) = N then
16773 Visit_Node (Node_Id (F));
16774 return;
16776 -- Another case, if we are pointing to an Itype, then we want
16777 -- to copy it if its associated node is somewhere in the tree
16778 -- being copied.
16780 -- Note: the exclusion of self-referential copies is just an
16781 -- optimization, since the search of the already copied list
16782 -- would catch it, but it is a common case (Etype pointing to
16783 -- itself for an Itype that is a base type).
16785 elsif Nkind (Node_Id (F)) in N_Entity
16786 and then Is_Itype (Entity_Id (F))
16787 and then Node_Id (F) /= N
16788 then
16789 declare
16790 P : Node_Id;
16792 begin
16793 P := Associated_Node_For_Itype (Node_Id (F));
16794 while Present (P) loop
16795 if P = Source then
16796 Visit_Node (Node_Id (F));
16797 return;
16798 else
16799 P := Parent (P);
16800 end if;
16801 end loop;
16803 -- An Itype whose parent is not being copied definitely
16804 -- should NOT be copied, since it does not belong in any
16805 -- sense to the copied subtree.
16807 return;
16808 end;
16809 end if;
16811 elsif F in List_Range and then Parent (List_Id (F)) = N then
16812 Visit_List (List_Id (F));
16813 return;
16814 end if;
16815 end Visit_Field;
16817 -----------------
16818 -- Visit_Itype --
16819 -----------------
16821 procedure Visit_Itype (Old_Itype : Entity_Id) is
16822 New_Itype : Entity_Id;
16823 Ent : Entity_Id;
16825 begin
16826 -- Itypes that describe the designated type of access to subprograms
16827 -- have the structure of subprogram declarations, with signatures,
16828 -- etc. Either we duplicate the signatures completely, or choose to
16829 -- share such itypes, which is fine because their elaboration will
16830 -- have no side effects.
16832 if Ekind (Old_Itype) = E_Subprogram_Type then
16833 return;
16834 end if;
16836 New_Itype := New_Copy (Old_Itype);
16838 -- The new Itype has all the attributes of the old one, and we
16839 -- just copy the contents of the entity. However, the back-end
16840 -- needs different names for debugging purposes, so we create a
16841 -- new internal name for it in all cases.
16843 Set_Chars (New_Itype, New_Internal_Name ('T'));
16845 -- If our associated node is an entity that has already been copied,
16846 -- then set the associated node of the copy to point to the right
16847 -- copy. If we have copied an Itype that is itself the associated
16848 -- node of some previously copied Itype, then we set the right
16849 -- pointer in the other direction.
16851 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
16853 if Present (Ent) then
16854 Set_Associated_Node_For_Itype (New_Itype, Ent);
16855 end if;
16857 Ent := NCT_Itype_Assoc.Get (Old_Itype);
16859 if Present (Ent) then
16860 Set_Associated_Node_For_Itype (Ent, New_Itype);
16862 -- If the hash table has no association for this Itype and its
16863 -- associated node, enter one now.
16865 else
16866 NCT_Itype_Assoc.Set
16867 (Associated_Node_For_Itype (Old_Itype), New_Itype);
16868 end if;
16870 if Present (Freeze_Node (New_Itype)) then
16871 Set_Is_Frozen (New_Itype, False);
16872 Set_Freeze_Node (New_Itype, Empty);
16873 end if;
16875 -- Add new association to map
16877 NCT_Assoc.Set (Old_Itype, New_Itype);
16879 -- If a record subtype is simply copied, the entity list will be
16880 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
16882 if Ekind_In (Old_Itype, E_Class_Wide_Subtype, E_Record_Subtype) then
16883 Set_Cloned_Subtype (New_Itype, Old_Itype);
16884 end if;
16886 -- Visit descendants that eventually get copied
16888 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
16890 if Is_Discrete_Type (Old_Itype) then
16891 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
16893 elsif Has_Discriminants (Base_Type (Old_Itype)) then
16894 -- ??? This should involve call to Visit_Field
16895 Visit_Elist (Discriminant_Constraint (Old_Itype));
16897 elsif Is_Array_Type (Old_Itype) then
16898 if Present (First_Index (Old_Itype)) then
16899 Visit_Field
16900 (Union_Id (List_Containing (First_Index (Old_Itype))),
16901 Old_Itype);
16902 end if;
16904 if Is_Packed (Old_Itype) then
16905 Visit_Field
16906 (Union_Id (Packed_Array_Impl_Type (Old_Itype)), Old_Itype);
16907 end if;
16908 end if;
16909 end Visit_Itype;
16911 ----------------
16912 -- Visit_List --
16913 ----------------
16915 procedure Visit_List (L : List_Id) is
16916 N : Node_Id;
16917 begin
16918 if L /= No_List then
16919 N := First (L);
16921 while Present (N) loop
16922 Visit_Node (N);
16923 Next (N);
16924 end loop;
16925 end if;
16926 end Visit_List;
16928 ----------------
16929 -- Visit_Node --
16930 ----------------
16932 procedure Visit_Node (N : Node_Or_Entity_Id) is
16933 begin
16934 -- Handle case of an Itype, which must be copied
16936 if Nkind (N) in N_Entity and then Is_Itype (N) then
16938 -- Nothing to do if already in the list. This can happen with an
16939 -- Itype entity that appears more than once in the tree. Note that
16940 -- we do not want to visit descendants in this case.
16942 if Present (NCT_Assoc.Get (Entity_Id (N))) then
16943 return;
16944 end if;
16946 Visit_Itype (N);
16947 end if;
16949 -- Visit descendants
16951 Visit_Field (Field1 (N), N);
16952 Visit_Field (Field2 (N), N);
16953 Visit_Field (Field3 (N), N);
16954 Visit_Field (Field4 (N), N);
16955 Visit_Field (Field5 (N), N);
16956 end Visit_Node;
16958 -- Start of processing for New_Copy_Tree
16960 begin
16961 Build_NCT_Hash_Tables;
16963 -- Hash table set up if required, now start phase one by visiting top
16964 -- node (we will recursively visit the descendants).
16966 Visit_Node (Source);
16968 -- Now the second phase of the copy can start. First we process all the
16969 -- mapped entities, copying their descendants.
16971 declare
16972 Old_E : Entity_Id := Empty;
16973 New_E : Entity_Id;
16975 begin
16976 NCT_Assoc.Get_First (Old_E, New_E);
16977 while Present (New_E) loop
16978 if Is_Itype (New_E) then
16979 Copy_Itype_With_Replacement (New_E);
16980 end if;
16982 NCT_Assoc.Get_Next (Old_E, New_E);
16983 end loop;
16984 end;
16986 -- Now we can copy the actual tree
16988 declare
16989 Result : constant Node_Id := Copy_Node_With_Replacement (Source);
16991 begin
16992 NCT_Assoc.Reset;
16993 NCT_Itype_Assoc.Reset;
16995 return Result;
16996 end;
16997 end New_Copy_Tree;
16999 -------------------------
17000 -- New_External_Entity --
17001 -------------------------
17003 function New_External_Entity
17004 (Kind : Entity_Kind;
17005 Scope_Id : Entity_Id;
17006 Sloc_Value : Source_Ptr;
17007 Related_Id : Entity_Id;
17008 Suffix : Character;
17009 Suffix_Index : Nat := 0;
17010 Prefix : Character := ' ') return Entity_Id
17012 N : constant Entity_Id :=
17013 Make_Defining_Identifier (Sloc_Value,
17014 New_External_Name
17015 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
17017 begin
17018 Set_Ekind (N, Kind);
17019 Set_Is_Internal (N, True);
17020 Append_Entity (N, Scope_Id);
17021 Set_Public_Status (N);
17023 if Kind in Type_Kind then
17024 Init_Size_Align (N);
17025 end if;
17027 return N;
17028 end New_External_Entity;
17030 -------------------------
17031 -- New_Internal_Entity --
17032 -------------------------
17034 function New_Internal_Entity
17035 (Kind : Entity_Kind;
17036 Scope_Id : Entity_Id;
17037 Sloc_Value : Source_Ptr;
17038 Id_Char : Character) return Entity_Id
17040 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
17042 begin
17043 Set_Ekind (N, Kind);
17044 Set_Is_Internal (N, True);
17045 Append_Entity (N, Scope_Id);
17047 if Kind in Type_Kind then
17048 Init_Size_Align (N);
17049 end if;
17051 return N;
17052 end New_Internal_Entity;
17054 -----------------
17055 -- Next_Actual --
17056 -----------------
17058 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
17059 N : Node_Id;
17061 begin
17062 -- If we are pointing at a positional parameter, it is a member of a
17063 -- node list (the list of parameters), and the next parameter is the
17064 -- next node on the list, unless we hit a parameter association, then
17065 -- we shift to using the chain whose head is the First_Named_Actual in
17066 -- the parent, and then is threaded using the Next_Named_Actual of the
17067 -- Parameter_Association. All this fiddling is because the original node
17068 -- list is in the textual call order, and what we need is the
17069 -- declaration order.
17071 if Is_List_Member (Actual_Id) then
17072 N := Next (Actual_Id);
17074 if Nkind (N) = N_Parameter_Association then
17075 return First_Named_Actual (Parent (Actual_Id));
17076 else
17077 return N;
17078 end if;
17080 else
17081 return Next_Named_Actual (Parent (Actual_Id));
17082 end if;
17083 end Next_Actual;
17085 procedure Next_Actual (Actual_Id : in out Node_Id) is
17086 begin
17087 Actual_Id := Next_Actual (Actual_Id);
17088 end Next_Actual;
17090 ----------------------------------
17091 -- New_Requires_Transient_Scope --
17092 ----------------------------------
17094 function New_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
17095 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean;
17096 -- This is called for untagged records and protected types, with
17097 -- nondefaulted discriminants. Returns True if the size of function
17098 -- results is known at the call site, False otherwise. Returns False
17099 -- if there is a variant part that depends on the discriminants of
17100 -- this type, or if there is an array constrained by the discriminants
17101 -- of this type. ???Currently, this is overly conservative (the array
17102 -- could be nested inside some other record that is constrained by
17103 -- nondiscriminants). That is, the recursive calls are too conservative.
17105 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean;
17106 -- Returns True if Typ is a nonlimited record with defaulted
17107 -- discriminants whose max size makes it unsuitable for allocating on
17108 -- the primary stack.
17110 ------------------------------
17111 -- Caller_Known_Size_Record --
17112 ------------------------------
17114 function Caller_Known_Size_Record (Typ : Entity_Id) return Boolean is
17115 pragma Assert (Typ = Underlying_Type (Typ));
17117 begin
17118 if Has_Variant_Part (Typ) and then not Is_Definite_Subtype (Typ) then
17119 return False;
17120 end if;
17122 declare
17123 Comp : Entity_Id;
17125 begin
17126 Comp := First_Entity (Typ);
17127 while Present (Comp) loop
17129 -- Only look at E_Component entities. No need to look at
17130 -- E_Discriminant entities, and we must ignore internal
17131 -- subtypes generated for constrained components.
17133 if Ekind (Comp) = E_Component then
17134 declare
17135 Comp_Type : constant Entity_Id :=
17136 Underlying_Type (Etype (Comp));
17138 begin
17139 if Is_Record_Type (Comp_Type)
17140 or else
17141 Is_Protected_Type (Comp_Type)
17142 then
17143 if not Caller_Known_Size_Record (Comp_Type) then
17144 return False;
17145 end if;
17147 elsif Is_Array_Type (Comp_Type) then
17148 if Size_Depends_On_Discriminant (Comp_Type) then
17149 return False;
17150 end if;
17151 end if;
17152 end;
17153 end if;
17155 Next_Entity (Comp);
17156 end loop;
17157 end;
17159 return True;
17160 end Caller_Known_Size_Record;
17162 ------------------------------
17163 -- Large_Max_Size_Mutable --
17164 ------------------------------
17166 function Large_Max_Size_Mutable (Typ : Entity_Id) return Boolean is
17167 pragma Assert (Typ = Underlying_Type (Typ));
17169 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean;
17170 -- Returns true if the discrete type T has a large range
17172 ----------------------------
17173 -- Is_Large_Discrete_Type --
17174 ----------------------------
17176 function Is_Large_Discrete_Type (T : Entity_Id) return Boolean is
17177 Threshold : constant Int := 16;
17178 -- Arbitrary threshold above which we consider it "large". We want
17179 -- a fairly large threshold, because these large types really
17180 -- shouldn't have default discriminants in the first place, in
17181 -- most cases.
17183 begin
17184 return UI_To_Int (RM_Size (T)) > Threshold;
17185 end Is_Large_Discrete_Type;
17187 -- Start of processing for Large_Max_Size_Mutable
17189 begin
17190 if Is_Record_Type (Typ)
17191 and then not Is_Limited_View (Typ)
17192 and then Has_Defaulted_Discriminants (Typ)
17193 then
17194 -- Loop through the components, looking for an array whose upper
17195 -- bound(s) depends on discriminants, where both the subtype of
17196 -- the discriminant and the index subtype are too large.
17198 declare
17199 Comp : Entity_Id;
17201 begin
17202 Comp := First_Entity (Typ);
17203 while Present (Comp) loop
17204 if Ekind (Comp) = E_Component then
17205 declare
17206 Comp_Type : constant Entity_Id :=
17207 Underlying_Type (Etype (Comp));
17209 Hi : Node_Id;
17210 Indx : Node_Id;
17211 Ityp : Entity_Id;
17213 begin
17214 if Is_Array_Type (Comp_Type) then
17215 Indx := First_Index (Comp_Type);
17217 while Present (Indx) loop
17218 Ityp := Etype (Indx);
17219 Hi := Type_High_Bound (Ityp);
17221 if Nkind (Hi) = N_Identifier
17222 and then Ekind (Entity (Hi)) = E_Discriminant
17223 and then Is_Large_Discrete_Type (Ityp)
17224 and then Is_Large_Discrete_Type
17225 (Etype (Entity (Hi)))
17226 then
17227 return True;
17228 end if;
17230 Next_Index (Indx);
17231 end loop;
17232 end if;
17233 end;
17234 end if;
17236 Next_Entity (Comp);
17237 end loop;
17238 end;
17239 end if;
17241 return False;
17242 end Large_Max_Size_Mutable;
17244 -- Local declarations
17246 Typ : constant Entity_Id := Underlying_Type (Id);
17248 -- Start of processing for New_Requires_Transient_Scope
17250 begin
17251 -- This is a private type which is not completed yet. This can only
17252 -- happen in a default expression (of a formal parameter or of a
17253 -- record component). Do not expand transient scope in this case.
17255 if No (Typ) then
17256 return False;
17258 -- Do not expand transient scope for non-existent procedure return or
17259 -- string literal types.
17261 elsif Typ = Standard_Void_Type
17262 or else Ekind (Typ) = E_String_Literal_Subtype
17263 then
17264 return False;
17266 -- If Typ is a generic formal incomplete type, then we want to look at
17267 -- the actual type.
17269 elsif Ekind (Typ) = E_Record_Subtype
17270 and then Present (Cloned_Subtype (Typ))
17271 then
17272 return New_Requires_Transient_Scope (Cloned_Subtype (Typ));
17274 -- Functions returning specific tagged types may dispatch on result, so
17275 -- their returned value is allocated on the secondary stack, even in the
17276 -- definite case. We must treat nondispatching functions the same way,
17277 -- because access-to-function types can point at both, so the calling
17278 -- conventions must be compatible. Is_Tagged_Type includes controlled
17279 -- types and class-wide types. Controlled type temporaries need
17280 -- finalization.
17282 -- ???It's not clear why we need to return noncontrolled types with
17283 -- controlled components on the secondary stack.
17285 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
17286 return True;
17288 -- Untagged definite subtypes are known size. This includes all
17289 -- elementary [sub]types. Tasks are known size even if they have
17290 -- discriminants. So we return False here, with one exception:
17291 -- For a type like:
17292 -- type T (Last : Natural := 0) is
17293 -- X : String (1 .. Last);
17294 -- end record;
17295 -- we return True. That's because for "P(F(...));", where F returns T,
17296 -- we don't know the size of the result at the call site, so if we
17297 -- allocated it on the primary stack, we would have to allocate the
17298 -- maximum size, which is way too big.
17300 elsif Is_Definite_Subtype (Typ) or else Is_Task_Type (Typ) then
17301 return Large_Max_Size_Mutable (Typ);
17303 -- Indefinite (discriminated) untagged record or protected type
17305 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
17306 return not Caller_Known_Size_Record (Typ);
17308 -- Unconstrained array
17310 else
17311 pragma Assert (Is_Array_Type (Typ) and not Is_Definite_Subtype (Typ));
17312 return True;
17313 end if;
17314 end New_Requires_Transient_Scope;
17316 -----------------------
17317 -- Normalize_Actuals --
17318 -----------------------
17320 -- Chain actuals according to formals of subprogram. If there are no named
17321 -- associations, the chain is simply the list of Parameter Associations,
17322 -- since the order is the same as the declaration order. If there are named
17323 -- associations, then the First_Named_Actual field in the N_Function_Call
17324 -- or N_Procedure_Call_Statement node points to the Parameter_Association
17325 -- node for the parameter that comes first in declaration order. The
17326 -- remaining named parameters are then chained in declaration order using
17327 -- Next_Named_Actual.
17329 -- This routine also verifies that the number of actuals is compatible with
17330 -- the number and default values of formals, but performs no type checking
17331 -- (type checking is done by the caller).
17333 -- If the matching succeeds, Success is set to True and the caller proceeds
17334 -- with type-checking. If the match is unsuccessful, then Success is set to
17335 -- False, and the caller attempts a different interpretation, if there is
17336 -- one.
17338 -- If the flag Report is on, the call is not overloaded, and a failure to
17339 -- match can be reported here, rather than in the caller.
17341 procedure Normalize_Actuals
17342 (N : Node_Id;
17343 S : Entity_Id;
17344 Report : Boolean;
17345 Success : out Boolean)
17347 Actuals : constant List_Id := Parameter_Associations (N);
17348 Actual : Node_Id := Empty;
17349 Formal : Entity_Id;
17350 Last : Node_Id := Empty;
17351 First_Named : Node_Id := Empty;
17352 Found : Boolean;
17354 Formals_To_Match : Integer := 0;
17355 Actuals_To_Match : Integer := 0;
17357 procedure Chain (A : Node_Id);
17358 -- Add named actual at the proper place in the list, using the
17359 -- Next_Named_Actual link.
17361 function Reporting return Boolean;
17362 -- Determines if an error is to be reported. To report an error, we
17363 -- need Report to be True, and also we do not report errors caused
17364 -- by calls to init procs that occur within other init procs. Such
17365 -- errors must always be cascaded errors, since if all the types are
17366 -- declared correctly, the compiler will certainly build decent calls.
17368 -----------
17369 -- Chain --
17370 -----------
17372 procedure Chain (A : Node_Id) is
17373 begin
17374 if No (Last) then
17376 -- Call node points to first actual in list
17378 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
17380 else
17381 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
17382 end if;
17384 Last := A;
17385 Set_Next_Named_Actual (Last, Empty);
17386 end Chain;
17388 ---------------
17389 -- Reporting --
17390 ---------------
17392 function Reporting return Boolean is
17393 begin
17394 if not Report then
17395 return False;
17397 elsif not Within_Init_Proc then
17398 return True;
17400 elsif Is_Init_Proc (Entity (Name (N))) then
17401 return False;
17403 else
17404 return True;
17405 end if;
17406 end Reporting;
17408 -- Start of processing for Normalize_Actuals
17410 begin
17411 if Is_Access_Type (S) then
17413 -- The name in the call is a function call that returns an access
17414 -- to subprogram. The designated type has the list of formals.
17416 Formal := First_Formal (Designated_Type (S));
17417 else
17418 Formal := First_Formal (S);
17419 end if;
17421 while Present (Formal) loop
17422 Formals_To_Match := Formals_To_Match + 1;
17423 Next_Formal (Formal);
17424 end loop;
17426 -- Find if there is a named association, and verify that no positional
17427 -- associations appear after named ones.
17429 if Present (Actuals) then
17430 Actual := First (Actuals);
17431 end if;
17433 while Present (Actual)
17434 and then Nkind (Actual) /= N_Parameter_Association
17435 loop
17436 Actuals_To_Match := Actuals_To_Match + 1;
17437 Next (Actual);
17438 end loop;
17440 if No (Actual) and Actuals_To_Match = Formals_To_Match then
17442 -- Most common case: positional notation, no defaults
17444 Success := True;
17445 return;
17447 elsif Actuals_To_Match > Formals_To_Match then
17449 -- Too many actuals: will not work
17451 if Reporting then
17452 if Is_Entity_Name (Name (N)) then
17453 Error_Msg_N ("too many arguments in call to&", Name (N));
17454 else
17455 Error_Msg_N ("too many arguments in call", N);
17456 end if;
17457 end if;
17459 Success := False;
17460 return;
17461 end if;
17463 First_Named := Actual;
17465 while Present (Actual) loop
17466 if Nkind (Actual) /= N_Parameter_Association then
17467 Error_Msg_N
17468 ("positional parameters not allowed after named ones", Actual);
17469 Success := False;
17470 return;
17472 else
17473 Actuals_To_Match := Actuals_To_Match + 1;
17474 end if;
17476 Next (Actual);
17477 end loop;
17479 if Present (Actuals) then
17480 Actual := First (Actuals);
17481 end if;
17483 Formal := First_Formal (S);
17484 while Present (Formal) loop
17486 -- Match the formals in order. If the corresponding actual is
17487 -- positional, nothing to do. Else scan the list of named actuals
17488 -- to find the one with the right name.
17490 if Present (Actual)
17491 and then Nkind (Actual) /= N_Parameter_Association
17492 then
17493 Next (Actual);
17494 Actuals_To_Match := Actuals_To_Match - 1;
17495 Formals_To_Match := Formals_To_Match - 1;
17497 else
17498 -- For named parameters, search the list of actuals to find
17499 -- one that matches the next formal name.
17501 Actual := First_Named;
17502 Found := False;
17503 while Present (Actual) loop
17504 if Chars (Selector_Name (Actual)) = Chars (Formal) then
17505 Found := True;
17506 Chain (Actual);
17507 Actuals_To_Match := Actuals_To_Match - 1;
17508 Formals_To_Match := Formals_To_Match - 1;
17509 exit;
17510 end if;
17512 Next (Actual);
17513 end loop;
17515 if not Found then
17516 if Ekind (Formal) /= E_In_Parameter
17517 or else No (Default_Value (Formal))
17518 then
17519 if Reporting then
17520 if (Comes_From_Source (S)
17521 or else Sloc (S) = Standard_Location)
17522 and then Is_Overloadable (S)
17523 then
17524 if No (Actuals)
17525 and then
17526 Nkind_In (Parent (N), N_Procedure_Call_Statement,
17527 N_Function_Call,
17528 N_Parameter_Association)
17529 and then Ekind (S) /= E_Function
17530 then
17531 Set_Etype (N, Etype (S));
17533 else
17534 Error_Msg_Name_1 := Chars (S);
17535 Error_Msg_Sloc := Sloc (S);
17536 Error_Msg_NE
17537 ("missing argument for parameter & "
17538 & "in call to % declared #", N, Formal);
17539 end if;
17541 elsif Is_Overloadable (S) then
17542 Error_Msg_Name_1 := Chars (S);
17544 -- Point to type derivation that generated the
17545 -- operation.
17547 Error_Msg_Sloc := Sloc (Parent (S));
17549 Error_Msg_NE
17550 ("missing argument for parameter & "
17551 & "in call to % (inherited) #", N, Formal);
17553 else
17554 Error_Msg_NE
17555 ("missing argument for parameter &", N, Formal);
17556 end if;
17557 end if;
17559 Success := False;
17560 return;
17562 else
17563 Formals_To_Match := Formals_To_Match - 1;
17564 end if;
17565 end if;
17566 end if;
17568 Next_Formal (Formal);
17569 end loop;
17571 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
17572 Success := True;
17573 return;
17575 else
17576 if Reporting then
17578 -- Find some superfluous named actual that did not get
17579 -- attached to the list of associations.
17581 Actual := First (Actuals);
17582 while Present (Actual) loop
17583 if Nkind (Actual) = N_Parameter_Association
17584 and then Actual /= Last
17585 and then No (Next_Named_Actual (Actual))
17586 then
17587 -- A validity check may introduce a copy of a call that
17588 -- includes an extra actual (for example for an unrelated
17589 -- accessibility check). Check that the extra actual matches
17590 -- some extra formal, which must exist already because
17591 -- subprogram must be frozen at this point.
17593 if Present (Extra_Formals (S))
17594 and then not Comes_From_Source (Actual)
17595 and then Nkind (Actual) = N_Parameter_Association
17596 and then Chars (Extra_Formals (S)) =
17597 Chars (Selector_Name (Actual))
17598 then
17599 null;
17600 else
17601 Error_Msg_N
17602 ("unmatched actual & in call", Selector_Name (Actual));
17603 exit;
17604 end if;
17605 end if;
17607 Next (Actual);
17608 end loop;
17609 end if;
17611 Success := False;
17612 return;
17613 end if;
17614 end Normalize_Actuals;
17616 --------------------------------
17617 -- Note_Possible_Modification --
17618 --------------------------------
17620 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
17621 Modification_Comes_From_Source : constant Boolean :=
17622 Comes_From_Source (Parent (N));
17624 Ent : Entity_Id;
17625 Exp : Node_Id;
17627 begin
17628 -- Loop to find referenced entity, if there is one
17630 Exp := N;
17631 loop
17632 Ent := Empty;
17634 if Is_Entity_Name (Exp) then
17635 Ent := Entity (Exp);
17637 -- If the entity is missing, it is an undeclared identifier,
17638 -- and there is nothing to annotate.
17640 if No (Ent) then
17641 return;
17642 end if;
17644 elsif Nkind (Exp) = N_Explicit_Dereference then
17645 declare
17646 P : constant Node_Id := Prefix (Exp);
17648 begin
17649 -- In formal verification mode, keep track of all reads and
17650 -- writes through explicit dereferences.
17652 if GNATprove_Mode then
17653 SPARK_Specific.Generate_Dereference (N, 'm');
17654 end if;
17656 if Nkind (P) = N_Selected_Component
17657 and then Present (Entry_Formal (Entity (Selector_Name (P))))
17658 then
17659 -- Case of a reference to an entry formal
17661 Ent := Entry_Formal (Entity (Selector_Name (P)));
17663 elsif Nkind (P) = N_Identifier
17664 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
17665 and then Present (Expression (Parent (Entity (P))))
17666 and then Nkind (Expression (Parent (Entity (P)))) =
17667 N_Reference
17668 then
17669 -- Case of a reference to a value on which side effects have
17670 -- been removed.
17672 Exp := Prefix (Expression (Parent (Entity (P))));
17673 goto Continue;
17675 else
17676 return;
17677 end if;
17678 end;
17680 elsif Nkind_In (Exp, N_Type_Conversion,
17681 N_Unchecked_Type_Conversion)
17682 then
17683 Exp := Expression (Exp);
17684 goto Continue;
17686 elsif Nkind_In (Exp, N_Slice,
17687 N_Indexed_Component,
17688 N_Selected_Component)
17689 then
17690 -- Special check, if the prefix is an access type, then return
17691 -- since we are modifying the thing pointed to, not the prefix.
17692 -- When we are expanding, most usually the prefix is replaced
17693 -- by an explicit dereference, and this test is not needed, but
17694 -- in some cases (notably -gnatc mode and generics) when we do
17695 -- not do full expansion, we need this special test.
17697 if Is_Access_Type (Etype (Prefix (Exp))) then
17698 return;
17700 -- Otherwise go to prefix and keep going
17702 else
17703 Exp := Prefix (Exp);
17704 goto Continue;
17705 end if;
17707 -- All other cases, not a modification
17709 else
17710 return;
17711 end if;
17713 -- Now look for entity being referenced
17715 if Present (Ent) then
17716 if Is_Object (Ent) then
17717 if Comes_From_Source (Exp)
17718 or else Modification_Comes_From_Source
17719 then
17720 -- Give warning if pragma unmodified is given and we are
17721 -- sure this is a modification.
17723 if Has_Pragma_Unmodified (Ent) and then Sure then
17725 -- Note that the entity may be present only as a result
17726 -- of pragma Unused.
17728 if Has_Pragma_Unused (Ent) then
17729 Error_Msg_NE ("??pragma Unused given for &!", N, Ent);
17730 else
17731 Error_Msg_NE
17732 ("??pragma Unmodified given for &!", N, Ent);
17733 end if;
17734 end if;
17736 Set_Never_Set_In_Source (Ent, False);
17737 end if;
17739 Set_Is_True_Constant (Ent, False);
17740 Set_Current_Value (Ent, Empty);
17741 Set_Is_Known_Null (Ent, False);
17743 if not Can_Never_Be_Null (Ent) then
17744 Set_Is_Known_Non_Null (Ent, False);
17745 end if;
17747 -- Follow renaming chain
17749 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
17750 and then Present (Renamed_Object (Ent))
17751 then
17752 Exp := Renamed_Object (Ent);
17754 -- If the entity is the loop variable in an iteration over
17755 -- a container, retrieve container expression to indicate
17756 -- possible modification.
17758 if Present (Related_Expression (Ent))
17759 and then Nkind (Parent (Related_Expression (Ent))) =
17760 N_Iterator_Specification
17761 then
17762 Exp := Original_Node (Related_Expression (Ent));
17763 end if;
17765 goto Continue;
17767 -- The expression may be the renaming of a subcomponent of an
17768 -- array or container. The assignment to the subcomponent is
17769 -- a modification of the container.
17771 elsif Comes_From_Source (Original_Node (Exp))
17772 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
17773 N_Indexed_Component)
17774 then
17775 Exp := Prefix (Original_Node (Exp));
17776 goto Continue;
17777 end if;
17779 -- Generate a reference only if the assignment comes from
17780 -- source. This excludes, for example, calls to a dispatching
17781 -- assignment operation when the left-hand side is tagged. In
17782 -- GNATprove mode, we need those references also on generated
17783 -- code, as these are used to compute the local effects of
17784 -- subprograms.
17786 if Modification_Comes_From_Source or GNATprove_Mode then
17787 Generate_Reference (Ent, Exp, 'm');
17789 -- If the target of the assignment is the bound variable
17790 -- in an iterator, indicate that the corresponding array
17791 -- or container is also modified.
17793 if Ada_Version >= Ada_2012
17794 and then Nkind (Parent (Ent)) = N_Iterator_Specification
17795 then
17796 declare
17797 Domain : constant Node_Id := Name (Parent (Ent));
17799 begin
17800 -- TBD : in the full version of the construct, the
17801 -- domain of iteration can be given by an expression.
17803 if Is_Entity_Name (Domain) then
17804 Generate_Reference (Entity (Domain), Exp, 'm');
17805 Set_Is_True_Constant (Entity (Domain), False);
17806 Set_Never_Set_In_Source (Entity (Domain), False);
17807 end if;
17808 end;
17809 end if;
17810 end if;
17811 end if;
17813 Kill_Checks (Ent);
17815 -- If we are sure this is a modification from source, and we know
17816 -- this modifies a constant, then give an appropriate warning.
17818 if Sure
17819 and then Modification_Comes_From_Source
17820 and then Overlays_Constant (Ent)
17821 and then Address_Clause_Overlay_Warnings
17822 then
17823 declare
17824 Addr : constant Node_Id := Address_Clause (Ent);
17825 O_Ent : Entity_Id;
17826 Off : Boolean;
17828 begin
17829 Find_Overlaid_Entity (Addr, O_Ent, Off);
17831 Error_Msg_Sloc := Sloc (Addr);
17832 Error_Msg_NE
17833 ("??constant& may be modified via address clause#",
17834 N, O_Ent);
17835 end;
17836 end if;
17838 return;
17839 end if;
17841 <<Continue>>
17842 null;
17843 end loop;
17844 end Note_Possible_Modification;
17846 --------------------------------------
17847 -- Null_To_Null_Address_Convert_OK --
17848 --------------------------------------
17850 function Null_To_Null_Address_Convert_OK
17851 (N : Node_Id;
17852 Typ : Entity_Id := Empty) return Boolean
17854 begin
17855 if not Relaxed_RM_Semantics then
17856 return False;
17857 end if;
17859 if Nkind (N) = N_Null then
17860 return Present (Typ) and then Is_Descendant_Of_Address (Typ);
17862 elsif Nkind_In (N, N_Op_Eq, N_Op_Ge, N_Op_Gt, N_Op_Le, N_Op_Lt, N_Op_Ne)
17863 then
17864 declare
17865 L : constant Node_Id := Left_Opnd (N);
17866 R : constant Node_Id := Right_Opnd (N);
17868 begin
17869 -- We check the Etype of the complementary operand since the
17870 -- N_Null node is not decorated at this stage.
17872 return
17873 ((Nkind (L) = N_Null
17874 and then Is_Descendant_Of_Address (Etype (R)))
17875 or else
17876 (Nkind (R) = N_Null
17877 and then Is_Descendant_Of_Address (Etype (L))));
17878 end;
17879 end if;
17881 return False;
17882 end Null_To_Null_Address_Convert_OK;
17884 -------------------------
17885 -- Object_Access_Level --
17886 -------------------------
17888 -- Returns the static accessibility level of the view denoted by Obj. Note
17889 -- that the value returned is the result of a call to Scope_Depth. Only
17890 -- scope depths associated with dynamic scopes can actually be returned.
17891 -- Since only relative levels matter for accessibility checking, the fact
17892 -- that the distance between successive levels of accessibility is not
17893 -- always one is immaterial (invariant: if level(E2) is deeper than
17894 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
17896 function Object_Access_Level (Obj : Node_Id) return Uint is
17897 function Is_Interface_Conversion (N : Node_Id) return Boolean;
17898 -- Determine whether N is a construct of the form
17899 -- Some_Type (Operand._tag'Address)
17900 -- This construct appears in the context of dispatching calls.
17902 function Reference_To (Obj : Node_Id) return Node_Id;
17903 -- An explicit dereference is created when removing side-effects from
17904 -- expressions for constraint checking purposes. In this case a local
17905 -- access type is created for it. The correct access level is that of
17906 -- the original source node. We detect this case by noting that the
17907 -- prefix of the dereference is created by an object declaration whose
17908 -- initial expression is a reference.
17910 -----------------------------
17911 -- Is_Interface_Conversion --
17912 -----------------------------
17914 function Is_Interface_Conversion (N : Node_Id) return Boolean is
17915 begin
17916 return Nkind (N) = N_Unchecked_Type_Conversion
17917 and then Nkind (Expression (N)) = N_Attribute_Reference
17918 and then Attribute_Name (Expression (N)) = Name_Address;
17919 end Is_Interface_Conversion;
17921 ------------------
17922 -- Reference_To --
17923 ------------------
17925 function Reference_To (Obj : Node_Id) return Node_Id is
17926 Pref : constant Node_Id := Prefix (Obj);
17927 begin
17928 if Is_Entity_Name (Pref)
17929 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
17930 and then Present (Expression (Parent (Entity (Pref))))
17931 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
17932 then
17933 return (Prefix (Expression (Parent (Entity (Pref)))));
17934 else
17935 return Empty;
17936 end if;
17937 end Reference_To;
17939 -- Local variables
17941 E : Entity_Id;
17943 -- Start of processing for Object_Access_Level
17945 begin
17946 if Nkind (Obj) = N_Defining_Identifier
17947 or else Is_Entity_Name (Obj)
17948 then
17949 if Nkind (Obj) = N_Defining_Identifier then
17950 E := Obj;
17951 else
17952 E := Entity (Obj);
17953 end if;
17955 if Is_Prival (E) then
17956 E := Prival_Link (E);
17957 end if;
17959 -- If E is a type then it denotes a current instance. For this case
17960 -- we add one to the normal accessibility level of the type to ensure
17961 -- that current instances are treated as always being deeper than
17962 -- than the level of any visible named access type (see 3.10.2(21)).
17964 if Is_Type (E) then
17965 return Type_Access_Level (E) + 1;
17967 elsif Present (Renamed_Object (E)) then
17968 return Object_Access_Level (Renamed_Object (E));
17970 -- Similarly, if E is a component of the current instance of a
17971 -- protected type, any instance of it is assumed to be at a deeper
17972 -- level than the type. For a protected object (whose type is an
17973 -- anonymous protected type) its components are at the same level
17974 -- as the type itself.
17976 elsif not Is_Overloadable (E)
17977 and then Ekind (Scope (E)) = E_Protected_Type
17978 and then Comes_From_Source (Scope (E))
17979 then
17980 return Type_Access_Level (Scope (E)) + 1;
17982 else
17983 -- Aliased formals of functions take their access level from the
17984 -- point of call, i.e. require a dynamic check. For static check
17985 -- purposes, this is smaller than the level of the subprogram
17986 -- itself. For procedures the aliased makes no difference.
17988 if Is_Formal (E)
17989 and then Is_Aliased (E)
17990 and then Ekind (Scope (E)) = E_Function
17991 then
17992 return Type_Access_Level (Etype (E));
17994 else
17995 return Scope_Depth (Enclosing_Dynamic_Scope (E));
17996 end if;
17997 end if;
17999 elsif Nkind (Obj) = N_Selected_Component then
18000 if Is_Access_Type (Etype (Prefix (Obj))) then
18001 return Type_Access_Level (Etype (Prefix (Obj)));
18002 else
18003 return Object_Access_Level (Prefix (Obj));
18004 end if;
18006 elsif Nkind (Obj) = N_Indexed_Component then
18007 if Is_Access_Type (Etype (Prefix (Obj))) then
18008 return Type_Access_Level (Etype (Prefix (Obj)));
18009 else
18010 return Object_Access_Level (Prefix (Obj));
18011 end if;
18013 elsif Nkind (Obj) = N_Explicit_Dereference then
18015 -- If the prefix is a selected access discriminant then we make a
18016 -- recursive call on the prefix, which will in turn check the level
18017 -- of the prefix object of the selected discriminant.
18019 -- In Ada 2012, if the discriminant has implicit dereference and
18020 -- the context is a selected component, treat this as an object of
18021 -- unknown scope (see below). This is necessary in compile-only mode;
18022 -- otherwise expansion will already have transformed the prefix into
18023 -- a temporary.
18025 if Nkind (Prefix (Obj)) = N_Selected_Component
18026 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
18027 and then
18028 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
18029 and then
18030 (not Has_Implicit_Dereference
18031 (Entity (Selector_Name (Prefix (Obj))))
18032 or else Nkind (Parent (Obj)) /= N_Selected_Component)
18033 then
18034 return Object_Access_Level (Prefix (Obj));
18036 -- Detect an interface conversion in the context of a dispatching
18037 -- call. Use the original form of the conversion to find the access
18038 -- level of the operand.
18040 elsif Is_Interface (Etype (Obj))
18041 and then Is_Interface_Conversion (Prefix (Obj))
18042 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
18043 then
18044 return Object_Access_Level (Original_Node (Obj));
18046 elsif not Comes_From_Source (Obj) then
18047 declare
18048 Ref : constant Node_Id := Reference_To (Obj);
18049 begin
18050 if Present (Ref) then
18051 return Object_Access_Level (Ref);
18052 else
18053 return Type_Access_Level (Etype (Prefix (Obj)));
18054 end if;
18055 end;
18057 else
18058 return Type_Access_Level (Etype (Prefix (Obj)));
18059 end if;
18061 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
18062 return Object_Access_Level (Expression (Obj));
18064 elsif Nkind (Obj) = N_Function_Call then
18066 -- Function results are objects, so we get either the access level of
18067 -- the function or, in the case of an indirect call, the level of the
18068 -- access-to-subprogram type. (This code is used for Ada 95, but it
18069 -- looks wrong, because it seems that we should be checking the level
18070 -- of the call itself, even for Ada 95. However, using the Ada 2005
18071 -- version of the code causes regressions in several tests that are
18072 -- compiled with -gnat95. ???)
18074 if Ada_Version < Ada_2005 then
18075 if Is_Entity_Name (Name (Obj)) then
18076 return Subprogram_Access_Level (Entity (Name (Obj)));
18077 else
18078 return Type_Access_Level (Etype (Prefix (Name (Obj))));
18079 end if;
18081 -- For Ada 2005, the level of the result object of a function call is
18082 -- defined to be the level of the call's innermost enclosing master.
18083 -- We determine that by querying the depth of the innermost enclosing
18084 -- dynamic scope.
18086 else
18087 Return_Master_Scope_Depth_Of_Call : declare
18088 function Innermost_Master_Scope_Depth
18089 (N : Node_Id) return Uint;
18090 -- Returns the scope depth of the given node's innermost
18091 -- enclosing dynamic scope (effectively the accessibility
18092 -- level of the innermost enclosing master).
18094 ----------------------------------
18095 -- Innermost_Master_Scope_Depth --
18096 ----------------------------------
18098 function Innermost_Master_Scope_Depth
18099 (N : Node_Id) return Uint
18101 Node_Par : Node_Id := Parent (N);
18103 begin
18104 -- Locate the nearest enclosing node (by traversing Parents)
18105 -- that Defining_Entity can be applied to, and return the
18106 -- depth of that entity's nearest enclosing dynamic scope.
18108 while Present (Node_Par) loop
18109 case Nkind (Node_Par) is
18110 when N_Abstract_Subprogram_Declaration
18111 | N_Block_Statement
18112 | N_Body_Stub
18113 | N_Component_Declaration
18114 | N_Entry_Body
18115 | N_Entry_Declaration
18116 | N_Exception_Declaration
18117 | N_Formal_Object_Declaration
18118 | N_Formal_Package_Declaration
18119 | N_Formal_Subprogram_Declaration
18120 | N_Formal_Type_Declaration
18121 | N_Full_Type_Declaration
18122 | N_Function_Specification
18123 | N_Generic_Declaration
18124 | N_Generic_Instantiation
18125 | N_Implicit_Label_Declaration
18126 | N_Incomplete_Type_Declaration
18127 | N_Loop_Parameter_Specification
18128 | N_Number_Declaration
18129 | N_Object_Declaration
18130 | N_Package_Declaration
18131 | N_Package_Specification
18132 | N_Parameter_Specification
18133 | N_Private_Extension_Declaration
18134 | N_Private_Type_Declaration
18135 | N_Procedure_Specification
18136 | N_Proper_Body
18137 | N_Protected_Type_Declaration
18138 | N_Renaming_Declaration
18139 | N_Single_Protected_Declaration
18140 | N_Single_Task_Declaration
18141 | N_Subprogram_Declaration
18142 | N_Subtype_Declaration
18143 | N_Subunit
18144 | N_Task_Type_Declaration
18146 return Scope_Depth
18147 (Nearest_Dynamic_Scope
18148 (Defining_Entity (Node_Par)));
18150 when others =>
18151 null;
18152 end case;
18154 Node_Par := Parent (Node_Par);
18155 end loop;
18157 pragma Assert (False);
18159 -- Should never reach the following return
18161 return Scope_Depth (Current_Scope) + 1;
18162 end Innermost_Master_Scope_Depth;
18164 -- Start of processing for Return_Master_Scope_Depth_Of_Call
18166 begin
18167 return Innermost_Master_Scope_Depth (Obj);
18168 end Return_Master_Scope_Depth_Of_Call;
18169 end if;
18171 -- For convenience we handle qualified expressions, even though they
18172 -- aren't technically object names.
18174 elsif Nkind (Obj) = N_Qualified_Expression then
18175 return Object_Access_Level (Expression (Obj));
18177 -- Ditto for aggregates. They have the level of the temporary that
18178 -- will hold their value.
18180 elsif Nkind (Obj) = N_Aggregate then
18181 return Object_Access_Level (Current_Scope);
18183 -- Otherwise return the scope level of Standard. (If there are cases
18184 -- that fall through to this point they will be treated as having
18185 -- global accessibility for now. ???)
18187 else
18188 return Scope_Depth (Standard_Standard);
18189 end if;
18190 end Object_Access_Level;
18192 ----------------------------------
18193 -- Old_Requires_Transient_Scope --
18194 ----------------------------------
18196 function Old_Requires_Transient_Scope (Id : Entity_Id) return Boolean is
18197 Typ : constant Entity_Id := Underlying_Type (Id);
18199 begin
18200 -- This is a private type which is not completed yet. This can only
18201 -- happen in a default expression (of a formal parameter or of a
18202 -- record component). Do not expand transient scope in this case.
18204 if No (Typ) then
18205 return False;
18207 -- Do not expand transient scope for non-existent procedure return
18209 elsif Typ = Standard_Void_Type then
18210 return False;
18212 -- Elementary types do not require a transient scope
18214 elsif Is_Elementary_Type (Typ) then
18215 return False;
18217 -- Generally, indefinite subtypes require a transient scope, since the
18218 -- back end cannot generate temporaries, since this is not a valid type
18219 -- for declaring an object. It might be possible to relax this in the
18220 -- future, e.g. by declaring the maximum possible space for the type.
18222 elsif not Is_Definite_Subtype (Typ) then
18223 return True;
18225 -- Functions returning tagged types may dispatch on result so their
18226 -- returned value is allocated on the secondary stack. Controlled
18227 -- type temporaries need finalization.
18229 elsif Is_Tagged_Type (Typ) or else Has_Controlled_Component (Typ) then
18230 return True;
18232 -- Record type
18234 elsif Is_Record_Type (Typ) then
18235 declare
18236 Comp : Entity_Id;
18238 begin
18239 Comp := First_Entity (Typ);
18240 while Present (Comp) loop
18241 if Ekind (Comp) = E_Component then
18243 -- ???It's not clear we need a full recursive call to
18244 -- Old_Requires_Transient_Scope here. Note that the
18245 -- following can't happen.
18247 pragma Assert (Is_Definite_Subtype (Etype (Comp)));
18248 pragma Assert (not Has_Controlled_Component (Etype (Comp)));
18250 if Old_Requires_Transient_Scope (Etype (Comp)) then
18251 return True;
18252 end if;
18253 end if;
18255 Next_Entity (Comp);
18256 end loop;
18257 end;
18259 return False;
18261 -- String literal types never require transient scope
18263 elsif Ekind (Typ) = E_String_Literal_Subtype then
18264 return False;
18266 -- Array type. Note that we already know that this is a constrained
18267 -- array, since unconstrained arrays will fail the indefinite test.
18269 elsif Is_Array_Type (Typ) then
18271 -- If component type requires a transient scope, the array does too
18273 if Old_Requires_Transient_Scope (Component_Type (Typ)) then
18274 return True;
18276 -- Otherwise, we only need a transient scope if the size depends on
18277 -- the value of one or more discriminants.
18279 else
18280 return Size_Depends_On_Discriminant (Typ);
18281 end if;
18283 -- All other cases do not require a transient scope
18285 else
18286 pragma Assert (Is_Protected_Type (Typ) or else Is_Task_Type (Typ));
18287 return False;
18288 end if;
18289 end Old_Requires_Transient_Scope;
18291 ---------------------------------
18292 -- Original_Aspect_Pragma_Name --
18293 ---------------------------------
18295 function Original_Aspect_Pragma_Name (N : Node_Id) return Name_Id is
18296 Item : Node_Id;
18297 Item_Nam : Name_Id;
18299 begin
18300 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
18302 Item := N;
18304 -- The pragma was generated to emulate an aspect, use the original
18305 -- aspect specification.
18307 if Nkind (Item) = N_Pragma and then From_Aspect_Specification (Item) then
18308 Item := Corresponding_Aspect (Item);
18309 end if;
18311 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
18312 -- Post and Post_Class rewrite their pragma identifier to preserve the
18313 -- original name.
18314 -- ??? this is kludgey
18316 if Nkind (Item) = N_Pragma then
18317 Item_Nam := Chars (Original_Node (Pragma_Identifier (Item)));
18319 else
18320 pragma Assert (Nkind (Item) = N_Aspect_Specification);
18321 Item_Nam := Chars (Identifier (Item));
18322 end if;
18324 -- Deal with 'Class by converting the name to its _XXX form
18326 if Class_Present (Item) then
18327 if Item_Nam = Name_Invariant then
18328 Item_Nam := Name_uInvariant;
18330 elsif Item_Nam = Name_Post then
18331 Item_Nam := Name_uPost;
18333 elsif Item_Nam = Name_Pre then
18334 Item_Nam := Name_uPre;
18336 elsif Nam_In (Item_Nam, Name_Type_Invariant,
18337 Name_Type_Invariant_Class)
18338 then
18339 Item_Nam := Name_uType_Invariant;
18341 -- Nothing to do for other cases (e.g. a Check that derived from
18342 -- Pre_Class and has the flag set). Also we do nothing if the name
18343 -- is already in special _xxx form.
18345 end if;
18346 end if;
18348 return Item_Nam;
18349 end Original_Aspect_Pragma_Name;
18351 --------------------------------------
18352 -- Original_Corresponding_Operation --
18353 --------------------------------------
18355 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
18357 Typ : constant Entity_Id := Find_Dispatching_Type (S);
18359 begin
18360 -- If S is an inherited primitive S2 the original corresponding
18361 -- operation of S is the original corresponding operation of S2
18363 if Present (Alias (S))
18364 and then Find_Dispatching_Type (Alias (S)) /= Typ
18365 then
18366 return Original_Corresponding_Operation (Alias (S));
18368 -- If S overrides an inherited subprogram S2 the original corresponding
18369 -- operation of S is the original corresponding operation of S2
18371 elsif Present (Overridden_Operation (S)) then
18372 return Original_Corresponding_Operation (Overridden_Operation (S));
18374 -- otherwise it is S itself
18376 else
18377 return S;
18378 end if;
18379 end Original_Corresponding_Operation;
18381 -------------------
18382 -- Output_Entity --
18383 -------------------
18385 procedure Output_Entity (Id : Entity_Id) is
18386 Scop : Entity_Id;
18388 begin
18389 Scop := Scope (Id);
18391 -- The entity may lack a scope when it is in the process of being
18392 -- analyzed. Use the current scope as an approximation.
18394 if No (Scop) then
18395 Scop := Current_Scope;
18396 end if;
18398 Output_Name (Chars (Id), Scop);
18399 end Output_Entity;
18401 -----------------
18402 -- Output_Name --
18403 -----------------
18405 procedure Output_Name (Nam : Name_Id; Scop : Entity_Id := Current_Scope) is
18406 begin
18407 Write_Str
18408 (Get_Name_String
18409 (Get_Qualified_Name
18410 (Nam => Nam,
18411 Suffix => No_Name,
18412 Scop => Scop)));
18413 Write_Eol;
18414 end Output_Name;
18416 ----------------------
18417 -- Policy_In_Effect --
18418 ----------------------
18420 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
18421 function Policy_In_List (List : Node_Id) return Name_Id;
18422 -- Determine the mode of a policy in a N_Pragma list
18424 --------------------
18425 -- Policy_In_List --
18426 --------------------
18428 function Policy_In_List (List : Node_Id) return Name_Id is
18429 Arg1 : Node_Id;
18430 Arg2 : Node_Id;
18431 Prag : Node_Id;
18433 begin
18434 Prag := List;
18435 while Present (Prag) loop
18436 Arg1 := First (Pragma_Argument_Associations (Prag));
18437 Arg2 := Next (Arg1);
18439 Arg1 := Get_Pragma_Arg (Arg1);
18440 Arg2 := Get_Pragma_Arg (Arg2);
18442 -- The current Check_Policy pragma matches the requested policy or
18443 -- appears in the single argument form (Assertion, policy_id).
18445 if Nam_In (Chars (Arg1), Name_Assertion, Policy) then
18446 return Chars (Arg2);
18447 end if;
18449 Prag := Next_Pragma (Prag);
18450 end loop;
18452 return No_Name;
18453 end Policy_In_List;
18455 -- Local variables
18457 Kind : Name_Id;
18459 -- Start of processing for Policy_In_Effect
18461 begin
18462 if not Is_Valid_Assertion_Kind (Policy) then
18463 raise Program_Error;
18464 end if;
18466 -- Inspect all policy pragmas that appear within scopes (if any)
18468 Kind := Policy_In_List (Check_Policy_List);
18470 -- Inspect all configuration policy pragmas (if any)
18472 if Kind = No_Name then
18473 Kind := Policy_In_List (Check_Policy_List_Config);
18474 end if;
18476 -- The context lacks policy pragmas, determine the mode based on whether
18477 -- assertions are enabled at the configuration level. This ensures that
18478 -- the policy is preserved when analyzing generics.
18480 if Kind = No_Name then
18481 if Assertions_Enabled_Config then
18482 Kind := Name_Check;
18483 else
18484 Kind := Name_Ignore;
18485 end if;
18486 end if;
18488 return Kind;
18489 end Policy_In_Effect;
18491 ----------------------------------
18492 -- Predicate_Tests_On_Arguments --
18493 ----------------------------------
18495 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
18496 begin
18497 -- Always test predicates on indirect call
18499 if Ekind (Subp) = E_Subprogram_Type then
18500 return True;
18502 -- Do not test predicates on call to generated default Finalize, since
18503 -- we are not interested in whether something we are finalizing (and
18504 -- typically destroying) satisfies its predicates.
18506 elsif Chars (Subp) = Name_Finalize
18507 and then not Comes_From_Source (Subp)
18508 then
18509 return False;
18511 -- Do not test predicates on any internally generated routines
18513 elsif Is_Internal_Name (Chars (Subp)) then
18514 return False;
18516 -- Do not test predicates on call to Init_Proc, since if needed the
18517 -- predicate test will occur at some other point.
18519 elsif Is_Init_Proc (Subp) then
18520 return False;
18522 -- Do not test predicates on call to predicate function, since this
18523 -- would cause infinite recursion.
18525 elsif Ekind (Subp) = E_Function
18526 and then (Is_Predicate_Function (Subp)
18527 or else
18528 Is_Predicate_Function_M (Subp))
18529 then
18530 return False;
18532 -- For now, no other exceptions
18534 else
18535 return True;
18536 end if;
18537 end Predicate_Tests_On_Arguments;
18539 -----------------------
18540 -- Private_Component --
18541 -----------------------
18543 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
18544 Ancestor : constant Entity_Id := Base_Type (Type_Id);
18546 function Trace_Components
18547 (T : Entity_Id;
18548 Check : Boolean) return Entity_Id;
18549 -- Recursive function that does the work, and checks against circular
18550 -- definition for each subcomponent type.
18552 ----------------------
18553 -- Trace_Components --
18554 ----------------------
18556 function Trace_Components
18557 (T : Entity_Id;
18558 Check : Boolean) return Entity_Id
18560 Btype : constant Entity_Id := Base_Type (T);
18561 Component : Entity_Id;
18562 P : Entity_Id;
18563 Candidate : Entity_Id := Empty;
18565 begin
18566 if Check and then Btype = Ancestor then
18567 Error_Msg_N ("circular type definition", Type_Id);
18568 return Any_Type;
18569 end if;
18571 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
18572 if Present (Full_View (Btype))
18573 and then Is_Record_Type (Full_View (Btype))
18574 and then not Is_Frozen (Btype)
18575 then
18576 -- To indicate that the ancestor depends on a private type, the
18577 -- current Btype is sufficient. However, to check for circular
18578 -- definition we must recurse on the full view.
18580 Candidate := Trace_Components (Full_View (Btype), True);
18582 if Candidate = Any_Type then
18583 return Any_Type;
18584 else
18585 return Btype;
18586 end if;
18588 else
18589 return Btype;
18590 end if;
18592 elsif Is_Array_Type (Btype) then
18593 return Trace_Components (Component_Type (Btype), True);
18595 elsif Is_Record_Type (Btype) then
18596 Component := First_Entity (Btype);
18597 while Present (Component)
18598 and then Comes_From_Source (Component)
18599 loop
18600 -- Skip anonymous types generated by constrained components
18602 if not Is_Type (Component) then
18603 P := Trace_Components (Etype (Component), True);
18605 if Present (P) then
18606 if P = Any_Type then
18607 return P;
18608 else
18609 Candidate := P;
18610 end if;
18611 end if;
18612 end if;
18614 Next_Entity (Component);
18615 end loop;
18617 return Candidate;
18619 else
18620 return Empty;
18621 end if;
18622 end Trace_Components;
18624 -- Start of processing for Private_Component
18626 begin
18627 return Trace_Components (Type_Id, False);
18628 end Private_Component;
18630 ---------------------------
18631 -- Primitive_Names_Match --
18632 ---------------------------
18634 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
18635 function Non_Internal_Name (E : Entity_Id) return Name_Id;
18636 -- Given an internal name, returns the corresponding non-internal name
18638 ------------------------
18639 -- Non_Internal_Name --
18640 ------------------------
18642 function Non_Internal_Name (E : Entity_Id) return Name_Id is
18643 begin
18644 Get_Name_String (Chars (E));
18645 Name_Len := Name_Len - 1;
18646 return Name_Find;
18647 end Non_Internal_Name;
18649 -- Start of processing for Primitive_Names_Match
18651 begin
18652 pragma Assert (Present (E1) and then Present (E2));
18654 return Chars (E1) = Chars (E2)
18655 or else
18656 (not Is_Internal_Name (Chars (E1))
18657 and then Is_Internal_Name (Chars (E2))
18658 and then Non_Internal_Name (E2) = Chars (E1))
18659 or else
18660 (not Is_Internal_Name (Chars (E2))
18661 and then Is_Internal_Name (Chars (E1))
18662 and then Non_Internal_Name (E1) = Chars (E2))
18663 or else
18664 (Is_Predefined_Dispatching_Operation (E1)
18665 and then Is_Predefined_Dispatching_Operation (E2)
18666 and then Same_TSS (E1, E2))
18667 or else
18668 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
18669 end Primitive_Names_Match;
18671 -----------------------
18672 -- Process_End_Label --
18673 -----------------------
18675 procedure Process_End_Label
18676 (N : Node_Id;
18677 Typ : Character;
18678 Ent : Entity_Id)
18680 Loc : Source_Ptr;
18681 Nam : Node_Id;
18682 Scop : Entity_Id;
18684 Label_Ref : Boolean;
18685 -- Set True if reference to end label itself is required
18687 Endl : Node_Id;
18688 -- Gets set to the operator symbol or identifier that references the
18689 -- entity Ent. For the child unit case, this is the identifier from the
18690 -- designator. For other cases, this is simply Endl.
18692 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
18693 -- N is an identifier node that appears as a parent unit reference in
18694 -- the case where Ent is a child unit. This procedure generates an
18695 -- appropriate cross-reference entry. E is the corresponding entity.
18697 -------------------------
18698 -- Generate_Parent_Ref --
18699 -------------------------
18701 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
18702 begin
18703 -- If names do not match, something weird, skip reference
18705 if Chars (E) = Chars (N) then
18707 -- Generate the reference. We do NOT consider this as a reference
18708 -- for unreferenced symbol purposes.
18710 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
18712 if Style_Check then
18713 Style.Check_Identifier (N, E);
18714 end if;
18715 end if;
18716 end Generate_Parent_Ref;
18718 -- Start of processing for Process_End_Label
18720 begin
18721 -- If no node, ignore. This happens in some error situations, and
18722 -- also for some internally generated structures where no end label
18723 -- references are required in any case.
18725 if No (N) then
18726 return;
18727 end if;
18729 -- Nothing to do if no End_Label, happens for internally generated
18730 -- constructs where we don't want an end label reference anyway. Also
18731 -- nothing to do if Endl is a string literal, which means there was
18732 -- some prior error (bad operator symbol)
18734 Endl := End_Label (N);
18736 if No (Endl) or else Nkind (Endl) = N_String_Literal then
18737 return;
18738 end if;
18740 -- Reference node is not in extended main source unit
18742 if not In_Extended_Main_Source_Unit (N) then
18744 -- Generally we do not collect references except for the extended
18745 -- main source unit. The one exception is the 'e' entry for a
18746 -- package spec, where it is useful for a client to have the
18747 -- ending information to define scopes.
18749 if Typ /= 'e' then
18750 return;
18752 else
18753 Label_Ref := False;
18755 -- For this case, we can ignore any parent references, but we
18756 -- need the package name itself for the 'e' entry.
18758 if Nkind (Endl) = N_Designator then
18759 Endl := Identifier (Endl);
18760 end if;
18761 end if;
18763 -- Reference is in extended main source unit
18765 else
18766 Label_Ref := True;
18768 -- For designator, generate references for the parent entries
18770 if Nkind (Endl) = N_Designator then
18772 -- Generate references for the prefix if the END line comes from
18773 -- source (otherwise we do not need these references) We climb the
18774 -- scope stack to find the expected entities.
18776 if Comes_From_Source (Endl) then
18777 Nam := Name (Endl);
18778 Scop := Current_Scope;
18779 while Nkind (Nam) = N_Selected_Component loop
18780 Scop := Scope (Scop);
18781 exit when No (Scop);
18782 Generate_Parent_Ref (Selector_Name (Nam), Scop);
18783 Nam := Prefix (Nam);
18784 end loop;
18786 if Present (Scop) then
18787 Generate_Parent_Ref (Nam, Scope (Scop));
18788 end if;
18789 end if;
18791 Endl := Identifier (Endl);
18792 end if;
18793 end if;
18795 -- If the end label is not for the given entity, then either we have
18796 -- some previous error, or this is a generic instantiation for which
18797 -- we do not need to make a cross-reference in this case anyway. In
18798 -- either case we simply ignore the call.
18800 if Chars (Ent) /= Chars (Endl) then
18801 return;
18802 end if;
18804 -- If label was really there, then generate a normal reference and then
18805 -- adjust the location in the end label to point past the name (which
18806 -- should almost always be the semicolon).
18808 Loc := Sloc (Endl);
18810 if Comes_From_Source (Endl) then
18812 -- If a label reference is required, then do the style check and
18813 -- generate an l-type cross-reference entry for the label
18815 if Label_Ref then
18816 if Style_Check then
18817 Style.Check_Identifier (Endl, Ent);
18818 end if;
18820 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
18821 end if;
18823 -- Set the location to point past the label (normally this will
18824 -- mean the semicolon immediately following the label). This is
18825 -- done for the sake of the 'e' or 't' entry generated below.
18827 Get_Decoded_Name_String (Chars (Endl));
18828 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
18830 else
18831 -- In SPARK mode, no missing label is allowed for packages and
18832 -- subprogram bodies. Detect those cases by testing whether
18833 -- Process_End_Label was called for a body (Typ = 't') or a package.
18835 if Restriction_Check_Required (SPARK_05)
18836 and then (Typ = 't' or else Ekind (Ent) = E_Package)
18837 then
18838 Error_Msg_Node_1 := Endl;
18839 Check_SPARK_05_Restriction
18840 ("`END &` required", Endl, Force => True);
18841 end if;
18842 end if;
18844 -- Now generate the e/t reference
18846 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
18848 -- Restore Sloc, in case modified above, since we have an identifier
18849 -- and the normal Sloc should be left set in the tree.
18851 Set_Sloc (Endl, Loc);
18852 end Process_End_Label;
18854 --------------------------------
18855 -- Propagate_Concurrent_Flags --
18856 --------------------------------
18858 procedure Propagate_Concurrent_Flags
18859 (Typ : Entity_Id;
18860 Comp_Typ : Entity_Id)
18862 begin
18863 if Has_Task (Comp_Typ) then
18864 Set_Has_Task (Typ);
18865 end if;
18867 if Has_Protected (Comp_Typ) then
18868 Set_Has_Protected (Typ);
18869 end if;
18871 if Has_Timing_Event (Comp_Typ) then
18872 Set_Has_Timing_Event (Typ);
18873 end if;
18874 end Propagate_Concurrent_Flags;
18876 ------------------------------
18877 -- Propagate_DIC_Attributes --
18878 ------------------------------
18880 procedure Propagate_DIC_Attributes
18881 (Typ : Entity_Id;
18882 From_Typ : Entity_Id)
18884 DIC_Proc : Entity_Id;
18886 begin
18887 if Present (Typ) and then Present (From_Typ) then
18888 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
18890 -- Nothing to do if both the source and the destination denote the
18891 -- same type.
18893 if From_Typ = Typ then
18894 return;
18895 end if;
18897 DIC_Proc := DIC_Procedure (From_Typ);
18899 -- The setting of the attributes is intentionally conservative. This
18900 -- prevents accidental clobbering of enabled attributes.
18902 if Has_Inherited_DIC (From_Typ)
18903 and then not Has_Inherited_DIC (Typ)
18904 then
18905 Set_Has_Inherited_DIC (Typ);
18906 end if;
18908 if Has_Own_DIC (From_Typ) and then not Has_Own_DIC (Typ) then
18909 Set_Has_Own_DIC (Typ);
18910 end if;
18912 if Present (DIC_Proc) and then No (DIC_Procedure (Typ)) then
18913 Set_DIC_Procedure (Typ, DIC_Proc);
18914 end if;
18915 end if;
18916 end Propagate_DIC_Attributes;
18918 ------------------------------------
18919 -- Propagate_Invariant_Attributes --
18920 ------------------------------------
18922 procedure Propagate_Invariant_Attributes
18923 (Typ : Entity_Id;
18924 From_Typ : Entity_Id)
18926 Full_IP : Entity_Id;
18927 Part_IP : Entity_Id;
18929 begin
18930 if Present (Typ) and then Present (From_Typ) then
18931 pragma Assert (Is_Type (Typ) and then Is_Type (From_Typ));
18933 -- Nothing to do if both the source and the destination denote the
18934 -- same type.
18936 if From_Typ = Typ then
18937 return;
18938 end if;
18940 Full_IP := Invariant_Procedure (From_Typ);
18941 Part_IP := Partial_Invariant_Procedure (From_Typ);
18943 -- The setting of the attributes is intentionally conservative. This
18944 -- prevents accidental clobbering of enabled attributes.
18946 if Has_Inheritable_Invariants (From_Typ)
18947 and then not Has_Inheritable_Invariants (Typ)
18948 then
18949 Set_Has_Inheritable_Invariants (Typ, True);
18950 end if;
18952 if Has_Inherited_Invariants (From_Typ)
18953 and then not Has_Inherited_Invariants (Typ)
18954 then
18955 Set_Has_Inherited_Invariants (Typ, True);
18956 end if;
18958 if Has_Own_Invariants (From_Typ)
18959 and then not Has_Own_Invariants (Typ)
18960 then
18961 Set_Has_Own_Invariants (Typ, True);
18962 end if;
18964 if Present (Full_IP) and then No (Invariant_Procedure (Typ)) then
18965 Set_Invariant_Procedure (Typ, Full_IP);
18966 end if;
18968 if Present (Part_IP) and then No (Partial_Invariant_Procedure (Typ))
18969 then
18970 Set_Partial_Invariant_Procedure (Typ, Part_IP);
18971 end if;
18972 end if;
18973 end Propagate_Invariant_Attributes;
18975 ---------------------------------------
18976 -- Record_Possible_Part_Of_Reference --
18977 ---------------------------------------
18979 procedure Record_Possible_Part_Of_Reference
18980 (Var_Id : Entity_Id;
18981 Ref : Node_Id)
18983 Encap : constant Entity_Id := Encapsulating_State (Var_Id);
18984 Refs : Elist_Id;
18986 begin
18987 -- The variable is a constituent of a single protected/task type. Such
18988 -- a variable acts as a component of the type and must appear within a
18989 -- specific region (SPARK RM 9.3). Instead of recording the reference,
18990 -- verify its legality now.
18992 if Present (Encap) and then Is_Single_Concurrent_Object (Encap) then
18993 Check_Part_Of_Reference (Var_Id, Ref);
18995 -- The variable is subject to pragma Part_Of and may eventually become a
18996 -- constituent of a single protected/task type. Record the reference to
18997 -- verify its placement when the contract of the variable is analyzed.
18999 elsif Present (Get_Pragma (Var_Id, Pragma_Part_Of)) then
19000 Refs := Part_Of_References (Var_Id);
19002 if No (Refs) then
19003 Refs := New_Elmt_List;
19004 Set_Part_Of_References (Var_Id, Refs);
19005 end if;
19007 Append_Elmt (Ref, Refs);
19008 end if;
19009 end Record_Possible_Part_Of_Reference;
19011 ----------------
19012 -- Referenced --
19013 ----------------
19015 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
19016 Seen : Boolean := False;
19018 function Is_Reference (N : Node_Id) return Traverse_Result;
19019 -- Determine whether node N denotes a reference to Id. If this is the
19020 -- case, set global flag Seen to True and stop the traversal.
19022 ------------------
19023 -- Is_Reference --
19024 ------------------
19026 function Is_Reference (N : Node_Id) return Traverse_Result is
19027 begin
19028 if Is_Entity_Name (N)
19029 and then Present (Entity (N))
19030 and then Entity (N) = Id
19031 then
19032 Seen := True;
19033 return Abandon;
19034 else
19035 return OK;
19036 end if;
19037 end Is_Reference;
19039 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
19041 -- Start of processing for Referenced
19043 begin
19044 Inspect_Expression (Expr);
19045 return Seen;
19046 end Referenced;
19048 ------------------------------------
19049 -- References_Generic_Formal_Type --
19050 ------------------------------------
19052 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
19054 function Process (N : Node_Id) return Traverse_Result;
19055 -- Process one node in search for generic formal type
19057 -------------
19058 -- Process --
19059 -------------
19061 function Process (N : Node_Id) return Traverse_Result is
19062 begin
19063 if Nkind (N) in N_Has_Entity then
19064 declare
19065 E : constant Entity_Id := Entity (N);
19066 begin
19067 if Present (E) then
19068 if Is_Generic_Type (E) then
19069 return Abandon;
19070 elsif Present (Etype (E))
19071 and then Is_Generic_Type (Etype (E))
19072 then
19073 return Abandon;
19074 end if;
19075 end if;
19076 end;
19077 end if;
19079 return Atree.OK;
19080 end Process;
19082 function Traverse is new Traverse_Func (Process);
19083 -- Traverse tree to look for generic type
19085 begin
19086 if Inside_A_Generic then
19087 return Traverse (N) = Abandon;
19088 else
19089 return False;
19090 end if;
19091 end References_Generic_Formal_Type;
19093 --------------------
19094 -- Remove_Homonym --
19095 --------------------
19097 procedure Remove_Homonym (E : Entity_Id) is
19098 Prev : Entity_Id := Empty;
19099 H : Entity_Id;
19101 begin
19102 if E = Current_Entity (E) then
19103 if Present (Homonym (E)) then
19104 Set_Current_Entity (Homonym (E));
19105 else
19106 Set_Name_Entity_Id (Chars (E), Empty);
19107 end if;
19109 else
19110 H := Current_Entity (E);
19111 while Present (H) and then H /= E loop
19112 Prev := H;
19113 H := Homonym (H);
19114 end loop;
19116 -- If E is not on the homonym chain, nothing to do
19118 if Present (H) then
19119 Set_Homonym (Prev, Homonym (E));
19120 end if;
19121 end if;
19122 end Remove_Homonym;
19124 ------------------------------
19125 -- Remove_Overloaded_Entity --
19126 ------------------------------
19128 procedure Remove_Overloaded_Entity (Id : Entity_Id) is
19129 procedure Remove_Primitive_Of (Typ : Entity_Id);
19130 -- Remove primitive subprogram Id from the list of primitives that
19131 -- belong to type Typ.
19133 -------------------------
19134 -- Remove_Primitive_Of --
19135 -------------------------
19137 procedure Remove_Primitive_Of (Typ : Entity_Id) is
19138 Prims : Elist_Id;
19140 begin
19141 if Is_Tagged_Type (Typ) then
19142 Prims := Direct_Primitive_Operations (Typ);
19144 if Present (Prims) then
19145 Remove (Prims, Id);
19146 end if;
19147 end if;
19148 end Remove_Primitive_Of;
19150 -- Local variables
19152 Scop : constant Entity_Id := Scope (Id);
19153 Formal : Entity_Id;
19154 Prev_Id : Entity_Id;
19156 -- Start of processing for Remove_Overloaded_Entity
19158 begin
19159 -- Remove the entity from the homonym chain. When the entity is the
19160 -- head of the chain, associate the entry in the name table with its
19161 -- homonym effectively making it the new head of the chain.
19163 if Current_Entity (Id) = Id then
19164 Set_Name_Entity_Id (Chars (Id), Homonym (Id));
19166 -- Otherwise link the previous and next homonyms
19168 else
19169 Prev_Id := Current_Entity (Id);
19170 while Present (Prev_Id) and then Homonym (Prev_Id) /= Id loop
19171 Prev_Id := Homonym (Prev_Id);
19172 end loop;
19174 Set_Homonym (Prev_Id, Homonym (Id));
19175 end if;
19177 -- Remove the entity from the scope entity chain. When the entity is
19178 -- the head of the chain, set the next entity as the new head of the
19179 -- chain.
19181 if First_Entity (Scop) = Id then
19182 Prev_Id := Empty;
19183 Set_First_Entity (Scop, Next_Entity (Id));
19185 -- Otherwise the entity is either in the middle of the chain or it acts
19186 -- as its tail. Traverse and link the previous and next entities.
19188 else
19189 Prev_Id := First_Entity (Scop);
19190 while Present (Prev_Id) and then Next_Entity (Prev_Id) /= Id loop
19191 Next_Entity (Prev_Id);
19192 end loop;
19194 Set_Next_Entity (Prev_Id, Next_Entity (Id));
19195 end if;
19197 -- Handle the case where the entity acts as the tail of the scope entity
19198 -- chain.
19200 if Last_Entity (Scop) = Id then
19201 Set_Last_Entity (Scop, Prev_Id);
19202 end if;
19204 -- The entity denotes a primitive subprogram. Remove it from the list of
19205 -- primitives of the associated controlling type.
19207 if Ekind_In (Id, E_Function, E_Procedure) and then Is_Primitive (Id) then
19208 Formal := First_Formal (Id);
19209 while Present (Formal) loop
19210 if Is_Controlling_Formal (Formal) then
19211 Remove_Primitive_Of (Etype (Formal));
19212 exit;
19213 end if;
19215 Next_Formal (Formal);
19216 end loop;
19218 if Ekind (Id) = E_Function and then Has_Controlling_Result (Id) then
19219 Remove_Primitive_Of (Etype (Id));
19220 end if;
19221 end if;
19222 end Remove_Overloaded_Entity;
19224 ---------------------
19225 -- Rep_To_Pos_Flag --
19226 ---------------------
19228 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
19229 begin
19230 return New_Occurrence_Of
19231 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
19232 end Rep_To_Pos_Flag;
19234 --------------------
19235 -- Require_Entity --
19236 --------------------
19238 procedure Require_Entity (N : Node_Id) is
19239 begin
19240 if Is_Entity_Name (N) and then No (Entity (N)) then
19241 if Total_Errors_Detected /= 0 then
19242 Set_Entity (N, Any_Id);
19243 else
19244 raise Program_Error;
19245 end if;
19246 end if;
19247 end Require_Entity;
19249 ------------------------------
19250 -- Requires_Transient_Scope --
19251 ------------------------------
19253 -- A transient scope is required when variable-sized temporaries are
19254 -- allocated on the secondary stack, or when finalization actions must be
19255 -- generated before the next instruction.
19257 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
19258 Old_Result : constant Boolean := Old_Requires_Transient_Scope (Id);
19260 begin
19261 if Debug_Flag_QQ then
19262 return Old_Result;
19263 end if;
19265 declare
19266 New_Result : constant Boolean := New_Requires_Transient_Scope (Id);
19268 begin
19269 -- Assert that we're not putting things on the secondary stack if we
19270 -- didn't before; we are trying to AVOID secondary stack when
19271 -- possible.
19273 if not Old_Result then
19274 pragma Assert (not New_Result);
19275 null;
19276 end if;
19278 if New_Result /= Old_Result then
19279 Results_Differ (Id, Old_Result, New_Result);
19280 end if;
19282 return New_Result;
19283 end;
19284 end Requires_Transient_Scope;
19286 --------------------
19287 -- Results_Differ --
19288 --------------------
19290 procedure Results_Differ
19291 (Id : Entity_Id;
19292 Old_Val : Boolean;
19293 New_Val : Boolean)
19295 begin
19296 if False then -- False to disable; True for debugging
19297 Treepr.Print_Tree_Node (Id);
19299 if Old_Val = New_Val then
19300 raise Program_Error;
19301 end if;
19302 end if;
19303 end Results_Differ;
19305 --------------------------
19306 -- Reset_Analyzed_Flags --
19307 --------------------------
19309 procedure Reset_Analyzed_Flags (N : Node_Id) is
19310 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
19311 -- Function used to reset Analyzed flags in tree. Note that we do
19312 -- not reset Analyzed flags in entities, since there is no need to
19313 -- reanalyze entities, and indeed, it is wrong to do so, since it
19314 -- can result in generating auxiliary stuff more than once.
19316 --------------------
19317 -- Clear_Analyzed --
19318 --------------------
19320 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
19321 begin
19322 if Nkind (N) not in N_Entity then
19323 Set_Analyzed (N, False);
19324 end if;
19326 return OK;
19327 end Clear_Analyzed;
19329 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
19331 -- Start of processing for Reset_Analyzed_Flags
19333 begin
19334 Reset_Analyzed (N);
19335 end Reset_Analyzed_Flags;
19337 ------------------------
19338 -- Restore_SPARK_Mode --
19339 ------------------------
19341 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
19342 begin
19343 SPARK_Mode := Mode;
19344 end Restore_SPARK_Mode;
19346 --------------------------------
19347 -- Returns_Unconstrained_Type --
19348 --------------------------------
19350 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
19351 begin
19352 return Ekind (Subp) = E_Function
19353 and then not Is_Scalar_Type (Etype (Subp))
19354 and then not Is_Access_Type (Etype (Subp))
19355 and then not Is_Constrained (Etype (Subp));
19356 end Returns_Unconstrained_Type;
19358 ----------------------------
19359 -- Root_Type_Of_Full_View --
19360 ----------------------------
19362 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
19363 Rtyp : constant Entity_Id := Root_Type (T);
19365 begin
19366 -- The root type of the full view may itself be a private type. Keep
19367 -- looking for the ultimate derivation parent.
19369 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
19370 return Root_Type_Of_Full_View (Full_View (Rtyp));
19371 else
19372 return Rtyp;
19373 end if;
19374 end Root_Type_Of_Full_View;
19376 ---------------------------
19377 -- Safe_To_Capture_Value --
19378 ---------------------------
19380 function Safe_To_Capture_Value
19381 (N : Node_Id;
19382 Ent : Entity_Id;
19383 Cond : Boolean := False) return Boolean
19385 begin
19386 -- The only entities for which we track constant values are variables
19387 -- which are not renamings, constants, out parameters, and in out
19388 -- parameters, so check if we have this case.
19390 -- Note: it may seem odd to track constant values for constants, but in
19391 -- fact this routine is used for other purposes than simply capturing
19392 -- the value. In particular, the setting of Known[_Non]_Null.
19394 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
19395 or else
19396 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
19397 then
19398 null;
19400 -- For conditionals, we also allow loop parameters and all formals,
19401 -- including in parameters.
19403 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
19404 null;
19406 -- For all other cases, not just unsafe, but impossible to capture
19407 -- Current_Value, since the above are the only entities which have
19408 -- Current_Value fields.
19410 else
19411 return False;
19412 end if;
19414 -- Skip if volatile or aliased, since funny things might be going on in
19415 -- these cases which we cannot necessarily track. Also skip any variable
19416 -- for which an address clause is given, or whose address is taken. Also
19417 -- never capture value of library level variables (an attempt to do so
19418 -- can occur in the case of package elaboration code).
19420 if Treat_As_Volatile (Ent)
19421 or else Is_Aliased (Ent)
19422 or else Present (Address_Clause (Ent))
19423 or else Address_Taken (Ent)
19424 or else (Is_Library_Level_Entity (Ent)
19425 and then Ekind (Ent) = E_Variable)
19426 then
19427 return False;
19428 end if;
19430 -- OK, all above conditions are met. We also require that the scope of
19431 -- the reference be the same as the scope of the entity, not counting
19432 -- packages and blocks and loops.
19434 declare
19435 E_Scope : constant Entity_Id := Scope (Ent);
19436 R_Scope : Entity_Id;
19438 begin
19439 R_Scope := Current_Scope;
19440 while R_Scope /= Standard_Standard loop
19441 exit when R_Scope = E_Scope;
19443 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
19444 return False;
19445 else
19446 R_Scope := Scope (R_Scope);
19447 end if;
19448 end loop;
19449 end;
19451 -- We also require that the reference does not appear in a context
19452 -- where it is not sure to be executed (i.e. a conditional context
19453 -- or an exception handler). We skip this if Cond is True, since the
19454 -- capturing of values from conditional tests handles this ok.
19456 if Cond then
19457 return True;
19458 end if;
19460 declare
19461 Desc : Node_Id;
19462 P : Node_Id;
19464 begin
19465 Desc := N;
19467 -- Seems dubious that case expressions are not handled here ???
19469 P := Parent (N);
19470 while Present (P) loop
19471 if Nkind (P) = N_If_Statement
19472 or else Nkind (P) = N_Case_Statement
19473 or else (Nkind (P) in N_Short_Circuit
19474 and then Desc = Right_Opnd (P))
19475 or else (Nkind (P) = N_If_Expression
19476 and then Desc /= First (Expressions (P)))
19477 or else Nkind (P) = N_Exception_Handler
19478 or else Nkind (P) = N_Selective_Accept
19479 or else Nkind (P) = N_Conditional_Entry_Call
19480 or else Nkind (P) = N_Timed_Entry_Call
19481 or else Nkind (P) = N_Asynchronous_Select
19482 then
19483 return False;
19485 else
19486 Desc := P;
19487 P := Parent (P);
19489 -- A special Ada 2012 case: the original node may be part
19490 -- of the else_actions of a conditional expression, in which
19491 -- case it might not have been expanded yet, and appears in
19492 -- a non-syntactic list of actions. In that case it is clearly
19493 -- not safe to save a value.
19495 if No (P)
19496 and then Is_List_Member (Desc)
19497 and then No (Parent (List_Containing (Desc)))
19498 then
19499 return False;
19500 end if;
19501 end if;
19502 end loop;
19503 end;
19505 -- OK, looks safe to set value
19507 return True;
19508 end Safe_To_Capture_Value;
19510 ---------------
19511 -- Same_Name --
19512 ---------------
19514 function Same_Name (N1, N2 : Node_Id) return Boolean is
19515 K1 : constant Node_Kind := Nkind (N1);
19516 K2 : constant Node_Kind := Nkind (N2);
19518 begin
19519 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
19520 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
19521 then
19522 return Chars (N1) = Chars (N2);
19524 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
19525 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
19526 then
19527 return Same_Name (Selector_Name (N1), Selector_Name (N2))
19528 and then Same_Name (Prefix (N1), Prefix (N2));
19530 else
19531 return False;
19532 end if;
19533 end Same_Name;
19535 -----------------
19536 -- Same_Object --
19537 -----------------
19539 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
19540 N1 : constant Node_Id := Original_Node (Node1);
19541 N2 : constant Node_Id := Original_Node (Node2);
19542 -- We do the tests on original nodes, since we are most interested
19543 -- in the original source, not any expansion that got in the way.
19545 K1 : constant Node_Kind := Nkind (N1);
19546 K2 : constant Node_Kind := Nkind (N2);
19548 begin
19549 -- First case, both are entities with same entity
19551 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
19552 declare
19553 EN1 : constant Entity_Id := Entity (N1);
19554 EN2 : constant Entity_Id := Entity (N2);
19555 begin
19556 if Present (EN1) and then Present (EN2)
19557 and then (Ekind_In (EN1, E_Variable, E_Constant)
19558 or else Is_Formal (EN1))
19559 and then EN1 = EN2
19560 then
19561 return True;
19562 end if;
19563 end;
19564 end if;
19566 -- Second case, selected component with same selector, same record
19568 if K1 = N_Selected_Component
19569 and then K2 = N_Selected_Component
19570 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
19571 then
19572 return Same_Object (Prefix (N1), Prefix (N2));
19574 -- Third case, indexed component with same subscripts, same array
19576 elsif K1 = N_Indexed_Component
19577 and then K2 = N_Indexed_Component
19578 and then Same_Object (Prefix (N1), Prefix (N2))
19579 then
19580 declare
19581 E1, E2 : Node_Id;
19582 begin
19583 E1 := First (Expressions (N1));
19584 E2 := First (Expressions (N2));
19585 while Present (E1) loop
19586 if not Same_Value (E1, E2) then
19587 return False;
19588 else
19589 Next (E1);
19590 Next (E2);
19591 end if;
19592 end loop;
19594 return True;
19595 end;
19597 -- Fourth case, slice of same array with same bounds
19599 elsif K1 = N_Slice
19600 and then K2 = N_Slice
19601 and then Nkind (Discrete_Range (N1)) = N_Range
19602 and then Nkind (Discrete_Range (N2)) = N_Range
19603 and then Same_Value (Low_Bound (Discrete_Range (N1)),
19604 Low_Bound (Discrete_Range (N2)))
19605 and then Same_Value (High_Bound (Discrete_Range (N1)),
19606 High_Bound (Discrete_Range (N2)))
19607 then
19608 return Same_Name (Prefix (N1), Prefix (N2));
19610 -- All other cases, not clearly the same object
19612 else
19613 return False;
19614 end if;
19615 end Same_Object;
19617 ---------------
19618 -- Same_Type --
19619 ---------------
19621 function Same_Type (T1, T2 : Entity_Id) return Boolean is
19622 begin
19623 if T1 = T2 then
19624 return True;
19626 elsif not Is_Constrained (T1)
19627 and then not Is_Constrained (T2)
19628 and then Base_Type (T1) = Base_Type (T2)
19629 then
19630 return True;
19632 -- For now don't bother with case of identical constraints, to be
19633 -- fiddled with later on perhaps (this is only used for optimization
19634 -- purposes, so it is not critical to do a best possible job)
19636 else
19637 return False;
19638 end if;
19639 end Same_Type;
19641 ----------------
19642 -- Same_Value --
19643 ----------------
19645 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
19646 begin
19647 if Compile_Time_Known_Value (Node1)
19648 and then Compile_Time_Known_Value (Node2)
19649 and then Expr_Value (Node1) = Expr_Value (Node2)
19650 then
19651 return True;
19652 elsif Same_Object (Node1, Node2) then
19653 return True;
19654 else
19655 return False;
19656 end if;
19657 end Same_Value;
19659 -----------------------------
19660 -- Save_SPARK_Mode_And_Set --
19661 -----------------------------
19663 procedure Save_SPARK_Mode_And_Set
19664 (Context : Entity_Id;
19665 Mode : out SPARK_Mode_Type)
19667 begin
19668 -- Save the current mode in effect
19670 Mode := SPARK_Mode;
19672 -- Do not consider illegal or partially decorated constructs
19674 if Ekind (Context) = E_Void or else Error_Posted (Context) then
19675 null;
19677 elsif Present (SPARK_Pragma (Context)) then
19678 SPARK_Mode := Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Context));
19679 end if;
19680 end Save_SPARK_Mode_And_Set;
19682 -------------------------
19683 -- Scalar_Part_Present --
19684 -------------------------
19686 function Scalar_Part_Present (T : Entity_Id) return Boolean is
19687 C : Entity_Id;
19689 begin
19690 if Is_Scalar_Type (T) then
19691 return True;
19693 elsif Is_Array_Type (T) then
19694 return Scalar_Part_Present (Component_Type (T));
19696 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
19697 C := First_Component_Or_Discriminant (T);
19698 while Present (C) loop
19699 if Scalar_Part_Present (Etype (C)) then
19700 return True;
19701 else
19702 Next_Component_Or_Discriminant (C);
19703 end if;
19704 end loop;
19705 end if;
19707 return False;
19708 end Scalar_Part_Present;
19710 ------------------------
19711 -- Scope_Is_Transient --
19712 ------------------------
19714 function Scope_Is_Transient return Boolean is
19715 begin
19716 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
19717 end Scope_Is_Transient;
19719 ------------------
19720 -- Scope_Within --
19721 ------------------
19723 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
19724 Scop : Entity_Id;
19726 begin
19727 Scop := Scope1;
19728 while Scop /= Standard_Standard loop
19729 Scop := Scope (Scop);
19731 if Scop = Scope2 then
19732 return True;
19733 end if;
19734 end loop;
19736 return False;
19737 end Scope_Within;
19739 --------------------------
19740 -- Scope_Within_Or_Same --
19741 --------------------------
19743 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
19744 Scop : Entity_Id;
19746 begin
19747 Scop := Scope1;
19748 while Scop /= Standard_Standard loop
19749 if Scop = Scope2 then
19750 return True;
19751 else
19752 Scop := Scope (Scop);
19753 end if;
19754 end loop;
19756 return False;
19757 end Scope_Within_Or_Same;
19759 --------------------
19760 -- Set_Convention --
19761 --------------------
19763 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
19764 begin
19765 Basic_Set_Convention (E, Val);
19767 if Is_Type (E)
19768 and then Is_Access_Subprogram_Type (Base_Type (E))
19769 and then Has_Foreign_Convention (E)
19770 then
19772 -- A pragma Convention in an instance may apply to the subtype
19773 -- created for a formal, in which case we have already verified
19774 -- that conventions of actual and formal match and there is nothing
19775 -- to flag on the subtype.
19777 if In_Instance then
19778 null;
19779 else
19780 Set_Can_Use_Internal_Rep (E, False);
19781 end if;
19782 end if;
19784 -- If E is an object or component, and the type of E is an anonymous
19785 -- access type with no convention set, then also set the convention of
19786 -- the anonymous access type. We do not do this for anonymous protected
19787 -- types, since protected types always have the default convention.
19789 if Present (Etype (E))
19790 and then (Is_Object (E)
19791 or else Ekind (E) = E_Component
19793 -- Allow E_Void (happens for pragma Convention appearing
19794 -- in the middle of a record applying to a component)
19796 or else Ekind (E) = E_Void)
19797 then
19798 declare
19799 Typ : constant Entity_Id := Etype (E);
19801 begin
19802 if Ekind_In (Typ, E_Anonymous_Access_Type,
19803 E_Anonymous_Access_Subprogram_Type)
19804 and then not Has_Convention_Pragma (Typ)
19805 then
19806 Basic_Set_Convention (Typ, Val);
19807 Set_Has_Convention_Pragma (Typ);
19809 -- And for the access subprogram type, deal similarly with the
19810 -- designated E_Subprogram_Type if it is also internal (which
19811 -- it always is?)
19813 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
19814 declare
19815 Dtype : constant Entity_Id := Designated_Type (Typ);
19816 begin
19817 if Ekind (Dtype) = E_Subprogram_Type
19818 and then Is_Itype (Dtype)
19819 and then not Has_Convention_Pragma (Dtype)
19820 then
19821 Basic_Set_Convention (Dtype, Val);
19822 Set_Has_Convention_Pragma (Dtype);
19823 end if;
19824 end;
19825 end if;
19826 end if;
19827 end;
19828 end if;
19829 end Set_Convention;
19831 ------------------------
19832 -- Set_Current_Entity --
19833 ------------------------
19835 -- The given entity is to be set as the currently visible definition of its
19836 -- associated name (i.e. the Node_Id associated with its name). All we have
19837 -- to do is to get the name from the identifier, and then set the
19838 -- associated Node_Id to point to the given entity.
19840 procedure Set_Current_Entity (E : Entity_Id) is
19841 begin
19842 Set_Name_Entity_Id (Chars (E), E);
19843 end Set_Current_Entity;
19845 ---------------------------
19846 -- Set_Debug_Info_Needed --
19847 ---------------------------
19849 procedure Set_Debug_Info_Needed (T : Entity_Id) is
19851 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
19852 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
19853 -- Used to set debug info in a related node if not set already
19855 --------------------------------------
19856 -- Set_Debug_Info_Needed_If_Not_Set --
19857 --------------------------------------
19859 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
19860 begin
19861 if Present (E) and then not Needs_Debug_Info (E) then
19862 Set_Debug_Info_Needed (E);
19864 -- For a private type, indicate that the full view also needs
19865 -- debug information.
19867 if Is_Type (E)
19868 and then Is_Private_Type (E)
19869 and then Present (Full_View (E))
19870 then
19871 Set_Debug_Info_Needed (Full_View (E));
19872 end if;
19873 end if;
19874 end Set_Debug_Info_Needed_If_Not_Set;
19876 -- Start of processing for Set_Debug_Info_Needed
19878 begin
19879 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
19880 -- indicates that Debug_Info_Needed is never required for the entity.
19881 -- Nothing to do if entity comes from a predefined file. Library files
19882 -- are compiled without debug information, but inlined bodies of these
19883 -- routines may appear in user code, and debug information on them ends
19884 -- up complicating debugging the user code.
19886 if No (T)
19887 or else Debug_Info_Off (T)
19888 then
19889 return;
19891 elsif In_Inlined_Body
19892 and then Is_Predefined_File_Name
19893 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
19894 then
19895 Set_Needs_Debug_Info (T, False);
19896 end if;
19898 -- Set flag in entity itself. Note that we will go through the following
19899 -- circuitry even if the flag is already set on T. That's intentional,
19900 -- it makes sure that the flag will be set in subsidiary entities.
19902 Set_Needs_Debug_Info (T);
19904 -- Set flag on subsidiary entities if not set already
19906 if Is_Object (T) then
19907 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
19909 elsif Is_Type (T) then
19910 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
19912 if Is_Record_Type (T) then
19913 declare
19914 Ent : Entity_Id := First_Entity (T);
19915 begin
19916 while Present (Ent) loop
19917 Set_Debug_Info_Needed_If_Not_Set (Ent);
19918 Next_Entity (Ent);
19919 end loop;
19920 end;
19922 -- For a class wide subtype, we also need debug information
19923 -- for the equivalent type.
19925 if Ekind (T) = E_Class_Wide_Subtype then
19926 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
19927 end if;
19929 elsif Is_Array_Type (T) then
19930 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
19932 declare
19933 Indx : Node_Id := First_Index (T);
19934 begin
19935 while Present (Indx) loop
19936 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
19937 Indx := Next_Index (Indx);
19938 end loop;
19939 end;
19941 -- For a packed array type, we also need debug information for
19942 -- the type used to represent the packed array. Conversely, we
19943 -- also need it for the former if we need it for the latter.
19945 if Is_Packed (T) then
19946 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
19947 end if;
19949 if Is_Packed_Array_Impl_Type (T) then
19950 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
19951 end if;
19953 elsif Is_Access_Type (T) then
19954 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
19956 elsif Is_Private_Type (T) then
19957 declare
19958 FV : constant Entity_Id := Full_View (T);
19960 begin
19961 Set_Debug_Info_Needed_If_Not_Set (FV);
19963 -- If the full view is itself a derived private type, we need
19964 -- debug information on its underlying type.
19966 if Present (FV)
19967 and then Is_Private_Type (FV)
19968 and then Present (Underlying_Full_View (FV))
19969 then
19970 Set_Needs_Debug_Info (Underlying_Full_View (FV));
19971 end if;
19972 end;
19974 elsif Is_Protected_Type (T) then
19975 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
19977 elsif Is_Scalar_Type (T) then
19979 -- If the subrange bounds are materialized by dedicated constant
19980 -- objects, also include them in the debug info to make sure the
19981 -- debugger can properly use them.
19983 if Present (Scalar_Range (T))
19984 and then Nkind (Scalar_Range (T)) = N_Range
19985 then
19986 declare
19987 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
19988 High_Bnd : constant Node_Id := Type_High_Bound (T);
19990 begin
19991 if Is_Entity_Name (Low_Bnd) then
19992 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
19993 end if;
19995 if Is_Entity_Name (High_Bnd) then
19996 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
19997 end if;
19998 end;
19999 end if;
20000 end if;
20001 end if;
20002 end Set_Debug_Info_Needed;
20004 ----------------------------
20005 -- Set_Entity_With_Checks --
20006 ----------------------------
20008 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
20009 Val_Actual : Entity_Id;
20010 Nod : Node_Id;
20011 Post_Node : Node_Id;
20013 begin
20014 -- Unconditionally set the entity
20016 Set_Entity (N, Val);
20018 -- The node to post on is the selector in the case of an expanded name,
20019 -- and otherwise the node itself.
20021 if Nkind (N) = N_Expanded_Name then
20022 Post_Node := Selector_Name (N);
20023 else
20024 Post_Node := N;
20025 end if;
20027 -- Check for violation of No_Fixed_IO
20029 if Restriction_Check_Required (No_Fixed_IO)
20030 and then
20031 ((RTU_Loaded (Ada_Text_IO)
20032 and then (Is_RTE (Val, RE_Decimal_IO)
20033 or else
20034 Is_RTE (Val, RE_Fixed_IO)))
20036 or else
20037 (RTU_Loaded (Ada_Wide_Text_IO)
20038 and then (Is_RTE (Val, RO_WT_Decimal_IO)
20039 or else
20040 Is_RTE (Val, RO_WT_Fixed_IO)))
20042 or else
20043 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
20044 and then (Is_RTE (Val, RO_WW_Decimal_IO)
20045 or else
20046 Is_RTE (Val, RO_WW_Fixed_IO))))
20048 -- A special extra check, don't complain about a reference from within
20049 -- the Ada.Interrupts package itself!
20051 and then not In_Same_Extended_Unit (N, Val)
20052 then
20053 Check_Restriction (No_Fixed_IO, Post_Node);
20054 end if;
20056 -- Remaining checks are only done on source nodes. Note that we test
20057 -- for violation of No_Fixed_IO even on non-source nodes, because the
20058 -- cases for checking violations of this restriction are instantiations
20059 -- where the reference in the instance has Comes_From_Source False.
20061 if not Comes_From_Source (N) then
20062 return;
20063 end if;
20065 -- Check for violation of No_Abort_Statements, which is triggered by
20066 -- call to Ada.Task_Identification.Abort_Task.
20068 if Restriction_Check_Required (No_Abort_Statements)
20069 and then (Is_RTE (Val, RE_Abort_Task))
20071 -- A special extra check, don't complain about a reference from within
20072 -- the Ada.Task_Identification package itself!
20074 and then not In_Same_Extended_Unit (N, Val)
20075 then
20076 Check_Restriction (No_Abort_Statements, Post_Node);
20077 end if;
20079 if Val = Standard_Long_Long_Integer then
20080 Check_Restriction (No_Long_Long_Integers, Post_Node);
20081 end if;
20083 -- Check for violation of No_Dynamic_Attachment
20085 if Restriction_Check_Required (No_Dynamic_Attachment)
20086 and then RTU_Loaded (Ada_Interrupts)
20087 and then (Is_RTE (Val, RE_Is_Reserved) or else
20088 Is_RTE (Val, RE_Is_Attached) or else
20089 Is_RTE (Val, RE_Current_Handler) or else
20090 Is_RTE (Val, RE_Attach_Handler) or else
20091 Is_RTE (Val, RE_Exchange_Handler) or else
20092 Is_RTE (Val, RE_Detach_Handler) or else
20093 Is_RTE (Val, RE_Reference))
20095 -- A special extra check, don't complain about a reference from within
20096 -- the Ada.Interrupts package itself!
20098 and then not In_Same_Extended_Unit (N, Val)
20099 then
20100 Check_Restriction (No_Dynamic_Attachment, Post_Node);
20101 end if;
20103 -- Check for No_Implementation_Identifiers
20105 if Restriction_Check_Required (No_Implementation_Identifiers) then
20107 -- We have an implementation defined entity if it is marked as
20108 -- implementation defined, or is defined in a package marked as
20109 -- implementation defined. However, library packages themselves
20110 -- are excluded (we don't want to flag Interfaces itself, just
20111 -- the entities within it).
20113 if (Is_Implementation_Defined (Val)
20114 or else
20115 (Present (Scope (Val))
20116 and then Is_Implementation_Defined (Scope (Val))))
20117 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
20118 and then Is_Library_Level_Entity (Val))
20119 then
20120 Check_Restriction (No_Implementation_Identifiers, Post_Node);
20121 end if;
20122 end if;
20124 -- Do the style check
20126 if Style_Check
20127 and then not Suppress_Style_Checks (Val)
20128 and then not In_Instance
20129 then
20130 if Nkind (N) = N_Identifier then
20131 Nod := N;
20132 elsif Nkind (N) = N_Expanded_Name then
20133 Nod := Selector_Name (N);
20134 else
20135 return;
20136 end if;
20138 -- A special situation arises for derived operations, where we want
20139 -- to do the check against the parent (since the Sloc of the derived
20140 -- operation points to the derived type declaration itself).
20142 Val_Actual := Val;
20143 while not Comes_From_Source (Val_Actual)
20144 and then Nkind (Val_Actual) in N_Entity
20145 and then (Ekind (Val_Actual) = E_Enumeration_Literal
20146 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
20147 and then Present (Alias (Val_Actual))
20148 loop
20149 Val_Actual := Alias (Val_Actual);
20150 end loop;
20152 -- Renaming declarations for generic actuals do not come from source,
20153 -- and have a different name from that of the entity they rename, so
20154 -- there is no style check to perform here.
20156 if Chars (Nod) = Chars (Val_Actual) then
20157 Style.Check_Identifier (Nod, Val_Actual);
20158 end if;
20159 end if;
20161 Set_Entity (N, Val);
20162 end Set_Entity_With_Checks;
20164 ------------------------
20165 -- Set_Name_Entity_Id --
20166 ------------------------
20168 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
20169 begin
20170 Set_Name_Table_Int (Id, Int (Val));
20171 end Set_Name_Entity_Id;
20173 ---------------------
20174 -- Set_Next_Actual --
20175 ---------------------
20177 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
20178 begin
20179 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
20180 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
20181 end if;
20182 end Set_Next_Actual;
20184 ----------------------------------
20185 -- Set_Optimize_Alignment_Flags --
20186 ----------------------------------
20188 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
20189 begin
20190 if Optimize_Alignment = 'S' then
20191 Set_Optimize_Alignment_Space (E);
20192 elsif Optimize_Alignment = 'T' then
20193 Set_Optimize_Alignment_Time (E);
20194 end if;
20195 end Set_Optimize_Alignment_Flags;
20197 -----------------------
20198 -- Set_Public_Status --
20199 -----------------------
20201 procedure Set_Public_Status (Id : Entity_Id) is
20202 S : constant Entity_Id := Current_Scope;
20204 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
20205 -- Determines if E is defined within handled statement sequence or
20206 -- an if statement, returns True if so, False otherwise.
20208 ----------------------
20209 -- Within_HSS_Or_If --
20210 ----------------------
20212 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
20213 N : Node_Id;
20214 begin
20215 N := Declaration_Node (E);
20216 loop
20217 N := Parent (N);
20219 if No (N) then
20220 return False;
20222 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
20223 N_If_Statement)
20224 then
20225 return True;
20226 end if;
20227 end loop;
20228 end Within_HSS_Or_If;
20230 -- Start of processing for Set_Public_Status
20232 begin
20233 -- Everything in the scope of Standard is public
20235 if S = Standard_Standard then
20236 Set_Is_Public (Id);
20238 -- Entity is definitely not public if enclosing scope is not public
20240 elsif not Is_Public (S) then
20241 return;
20243 -- An object or function declaration that occurs in a handled sequence
20244 -- of statements or within an if statement is the declaration for a
20245 -- temporary object or local subprogram generated by the expander. It
20246 -- never needs to be made public and furthermore, making it public can
20247 -- cause back end problems.
20249 elsif Nkind_In (Parent (Id), N_Object_Declaration,
20250 N_Function_Specification)
20251 and then Within_HSS_Or_If (Id)
20252 then
20253 return;
20255 -- Entities in public packages or records are public
20257 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
20258 Set_Is_Public (Id);
20260 -- The bounds of an entry family declaration can generate object
20261 -- declarations that are visible to the back-end, e.g. in the
20262 -- the declaration of a composite type that contains tasks.
20264 elsif Is_Concurrent_Type (S)
20265 and then not Has_Completion (S)
20266 and then Nkind (Parent (Id)) = N_Object_Declaration
20267 then
20268 Set_Is_Public (Id);
20269 end if;
20270 end Set_Public_Status;
20272 -----------------------------
20273 -- Set_Referenced_Modified --
20274 -----------------------------
20276 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
20277 Pref : Node_Id;
20279 begin
20280 -- Deal with indexed or selected component where prefix is modified
20282 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
20283 Pref := Prefix (N);
20285 -- If prefix is access type, then it is the designated object that is
20286 -- being modified, which means we have no entity to set the flag on.
20288 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
20289 return;
20291 -- Otherwise chase the prefix
20293 else
20294 Set_Referenced_Modified (Pref, Out_Param);
20295 end if;
20297 -- Otherwise see if we have an entity name (only other case to process)
20299 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
20300 Set_Referenced_As_LHS (Entity (N), not Out_Param);
20301 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
20302 end if;
20303 end Set_Referenced_Modified;
20305 ----------------------------
20306 -- Set_Scope_Is_Transient --
20307 ----------------------------
20309 procedure Set_Scope_Is_Transient (V : Boolean := True) is
20310 begin
20311 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
20312 end Set_Scope_Is_Transient;
20314 -------------------
20315 -- Set_Size_Info --
20316 -------------------
20318 procedure Set_Size_Info (T1, T2 : Entity_Id) is
20319 begin
20320 -- We copy Esize, but not RM_Size, since in general RM_Size is
20321 -- subtype specific and does not get inherited by all subtypes.
20323 Set_Esize (T1, Esize (T2));
20324 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
20326 if Is_Discrete_Or_Fixed_Point_Type (T1)
20327 and then
20328 Is_Discrete_Or_Fixed_Point_Type (T2)
20329 then
20330 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
20331 end if;
20333 Set_Alignment (T1, Alignment (T2));
20334 end Set_Size_Info;
20336 --------------------
20337 -- Static_Boolean --
20338 --------------------
20340 function Static_Boolean (N : Node_Id) return Uint is
20341 begin
20342 Analyze_And_Resolve (N, Standard_Boolean);
20344 if N = Error
20345 or else Error_Posted (N)
20346 or else Etype (N) = Any_Type
20347 then
20348 return No_Uint;
20349 end if;
20351 if Is_OK_Static_Expression (N) then
20352 if not Raises_Constraint_Error (N) then
20353 return Expr_Value (N);
20354 else
20355 return No_Uint;
20356 end if;
20358 elsif Etype (N) = Any_Type then
20359 return No_Uint;
20361 else
20362 Flag_Non_Static_Expr
20363 ("static boolean expression required here", N);
20364 return No_Uint;
20365 end if;
20366 end Static_Boolean;
20368 --------------------
20369 -- Static_Integer --
20370 --------------------
20372 function Static_Integer (N : Node_Id) return Uint is
20373 begin
20374 Analyze_And_Resolve (N, Any_Integer);
20376 if N = Error
20377 or else Error_Posted (N)
20378 or else Etype (N) = Any_Type
20379 then
20380 return No_Uint;
20381 end if;
20383 if Is_OK_Static_Expression (N) then
20384 if not Raises_Constraint_Error (N) then
20385 return Expr_Value (N);
20386 else
20387 return No_Uint;
20388 end if;
20390 elsif Etype (N) = Any_Type then
20391 return No_Uint;
20393 else
20394 Flag_Non_Static_Expr
20395 ("static integer expression required here", N);
20396 return No_Uint;
20397 end if;
20398 end Static_Integer;
20400 --------------------------
20401 -- Statically_Different --
20402 --------------------------
20404 function Statically_Different (E1, E2 : Node_Id) return Boolean is
20405 R1 : constant Node_Id := Get_Referenced_Object (E1);
20406 R2 : constant Node_Id := Get_Referenced_Object (E2);
20407 begin
20408 return Is_Entity_Name (R1)
20409 and then Is_Entity_Name (R2)
20410 and then Entity (R1) /= Entity (R2)
20411 and then not Is_Formal (Entity (R1))
20412 and then not Is_Formal (Entity (R2));
20413 end Statically_Different;
20415 --------------------------------------
20416 -- Subject_To_Loop_Entry_Attributes --
20417 --------------------------------------
20419 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
20420 Stmt : Node_Id;
20422 begin
20423 Stmt := N;
20425 -- The expansion mechanism transform a loop subject to at least one
20426 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
20427 -- the conditional part.
20429 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
20430 and then Nkind (Original_Node (N)) = N_Loop_Statement
20431 then
20432 Stmt := Original_Node (N);
20433 end if;
20435 return
20436 Nkind (Stmt) = N_Loop_Statement
20437 and then Present (Identifier (Stmt))
20438 and then Present (Entity (Identifier (Stmt)))
20439 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
20440 end Subject_To_Loop_Entry_Attributes;
20442 -----------------------------
20443 -- Subprogram_Access_Level --
20444 -----------------------------
20446 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
20447 begin
20448 if Present (Alias (Subp)) then
20449 return Subprogram_Access_Level (Alias (Subp));
20450 else
20451 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
20452 end if;
20453 end Subprogram_Access_Level;
20455 -------------------------------
20456 -- Support_Atomic_Primitives --
20457 -------------------------------
20459 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
20460 Size : Int;
20462 begin
20463 -- Verify the alignment of Typ is known
20465 if not Known_Alignment (Typ) then
20466 return False;
20467 end if;
20469 if Known_Static_Esize (Typ) then
20470 Size := UI_To_Int (Esize (Typ));
20472 -- If the Esize (Object_Size) is unknown at compile time, look at the
20473 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
20475 elsif Known_Static_RM_Size (Typ) then
20476 Size := UI_To_Int (RM_Size (Typ));
20478 -- Otherwise, the size is considered to be unknown.
20480 else
20481 return False;
20482 end if;
20484 -- Check that the size of the component is 8, 16, 32, or 64 bits and
20485 -- that Typ is properly aligned.
20487 case Size is
20488 when 8 | 16 | 32 | 64 =>
20489 return Size = UI_To_Int (Alignment (Typ)) * 8;
20491 when others =>
20492 return False;
20493 end case;
20494 end Support_Atomic_Primitives;
20496 -----------------
20497 -- Trace_Scope --
20498 -----------------
20500 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
20501 begin
20502 if Debug_Flag_W then
20503 for J in 0 .. Scope_Stack.Last loop
20504 Write_Str (" ");
20505 end loop;
20507 Write_Str (Msg);
20508 Write_Name (Chars (E));
20509 Write_Str (" from ");
20510 Write_Location (Sloc (N));
20511 Write_Eol;
20512 end if;
20513 end Trace_Scope;
20515 -----------------------
20516 -- Transfer_Entities --
20517 -----------------------
20519 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
20520 procedure Set_Public_Status_Of (Id : Entity_Id);
20521 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
20522 -- Set_Public_Status. If successfull and Id denotes a record type, set
20523 -- the Is_Public attribute of its fields.
20525 --------------------------
20526 -- Set_Public_Status_Of --
20527 --------------------------
20529 procedure Set_Public_Status_Of (Id : Entity_Id) is
20530 Field : Entity_Id;
20532 begin
20533 if not Is_Public (Id) then
20534 Set_Public_Status (Id);
20536 -- When the input entity is a public record type, ensure that all
20537 -- its internal fields are also exposed to the linker. The fields
20538 -- of a class-wide type are never made public.
20540 if Is_Public (Id)
20541 and then Is_Record_Type (Id)
20542 and then not Is_Class_Wide_Type (Id)
20543 then
20544 Field := First_Entity (Id);
20545 while Present (Field) loop
20546 Set_Is_Public (Field);
20547 Next_Entity (Field);
20548 end loop;
20549 end if;
20550 end if;
20551 end Set_Public_Status_Of;
20553 -- Local variables
20555 Full_Id : Entity_Id;
20556 Id : Entity_Id;
20558 -- Start of processing for Transfer_Entities
20560 begin
20561 Id := First_Entity (From);
20563 if Present (Id) then
20565 -- Merge the entity chain of the source scope with that of the
20566 -- destination scope.
20568 if Present (Last_Entity (To)) then
20569 Set_Next_Entity (Last_Entity (To), Id);
20570 else
20571 Set_First_Entity (To, Id);
20572 end if;
20574 Set_Last_Entity (To, Last_Entity (From));
20576 -- Inspect the entities of the source scope and update their Scope
20577 -- attribute.
20579 while Present (Id) loop
20580 Set_Scope (Id, To);
20581 Set_Public_Status_Of (Id);
20583 -- Handle an internally generated full view for a private type
20585 if Is_Private_Type (Id)
20586 and then Present (Full_View (Id))
20587 and then Is_Itype (Full_View (Id))
20588 then
20589 Full_Id := Full_View (Id);
20591 Set_Scope (Full_Id, To);
20592 Set_Public_Status_Of (Full_Id);
20593 end if;
20595 Next_Entity (Id);
20596 end loop;
20598 Set_First_Entity (From, Empty);
20599 Set_Last_Entity (From, Empty);
20600 end if;
20601 end Transfer_Entities;
20603 -----------------------
20604 -- Type_Access_Level --
20605 -----------------------
20607 function Type_Access_Level (Typ : Entity_Id) return Uint is
20608 Btyp : Entity_Id;
20610 begin
20611 Btyp := Base_Type (Typ);
20613 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
20614 -- simply use the level where the type is declared. This is true for
20615 -- stand-alone object declarations, and for anonymous access types
20616 -- associated with components the level is the same as that of the
20617 -- enclosing composite type. However, special treatment is needed for
20618 -- the cases of access parameters, return objects of an anonymous access
20619 -- type, and, in Ada 95, access discriminants of limited types.
20621 if Is_Access_Type (Btyp) then
20622 if Ekind (Btyp) = E_Anonymous_Access_Type then
20624 -- If the type is a nonlocal anonymous access type (such as for
20625 -- an access parameter) we treat it as being declared at the
20626 -- library level to ensure that names such as X.all'access don't
20627 -- fail static accessibility checks.
20629 if not Is_Local_Anonymous_Access (Typ) then
20630 return Scope_Depth (Standard_Standard);
20632 -- If this is a return object, the accessibility level is that of
20633 -- the result subtype of the enclosing function. The test here is
20634 -- little complicated, because we have to account for extended
20635 -- return statements that have been rewritten as blocks, in which
20636 -- case we have to find and the Is_Return_Object attribute of the
20637 -- itype's associated object. It would be nice to find a way to
20638 -- simplify this test, but it doesn't seem worthwhile to add a new
20639 -- flag just for purposes of this test. ???
20641 elsif Ekind (Scope (Btyp)) = E_Return_Statement
20642 or else
20643 (Is_Itype (Btyp)
20644 and then Nkind (Associated_Node_For_Itype (Btyp)) =
20645 N_Object_Declaration
20646 and then Is_Return_Object
20647 (Defining_Identifier
20648 (Associated_Node_For_Itype (Btyp))))
20649 then
20650 declare
20651 Scop : Entity_Id;
20653 begin
20654 Scop := Scope (Scope (Btyp));
20655 while Present (Scop) loop
20656 exit when Ekind (Scop) = E_Function;
20657 Scop := Scope (Scop);
20658 end loop;
20660 -- Treat the return object's type as having the level of the
20661 -- function's result subtype (as per RM05-6.5(5.3/2)).
20663 return Type_Access_Level (Etype (Scop));
20664 end;
20665 end if;
20666 end if;
20668 Btyp := Root_Type (Btyp);
20670 -- The accessibility level of anonymous access types associated with
20671 -- discriminants is that of the current instance of the type, and
20672 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
20674 -- AI-402: access discriminants have accessibility based on the
20675 -- object rather than the type in Ada 2005, so the above paragraph
20676 -- doesn't apply.
20678 -- ??? Needs completion with rules from AI-416
20680 if Ada_Version <= Ada_95
20681 and then Ekind (Typ) = E_Anonymous_Access_Type
20682 and then Present (Associated_Node_For_Itype (Typ))
20683 and then Nkind (Associated_Node_For_Itype (Typ)) =
20684 N_Discriminant_Specification
20685 then
20686 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
20687 end if;
20688 end if;
20690 -- Return library level for a generic formal type. This is done because
20691 -- RM(10.3.2) says that "The statically deeper relationship does not
20692 -- apply to ... a descendant of a generic formal type". Rather than
20693 -- checking at each point where a static accessibility check is
20694 -- performed to see if we are dealing with a formal type, this rule is
20695 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
20696 -- return extreme values for a formal type; Deepest_Type_Access_Level
20697 -- returns Int'Last. By calling the appropriate function from among the
20698 -- two, we ensure that the static accessibility check will pass if we
20699 -- happen to run into a formal type. More specifically, we should call
20700 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
20701 -- call occurs as part of a static accessibility check and the error
20702 -- case is the case where the type's level is too shallow (as opposed
20703 -- to too deep).
20705 if Is_Generic_Type (Root_Type (Btyp)) then
20706 return Scope_Depth (Standard_Standard);
20707 end if;
20709 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
20710 end Type_Access_Level;
20712 ------------------------------------
20713 -- Type_Without_Stream_Operation --
20714 ------------------------------------
20716 function Type_Without_Stream_Operation
20717 (T : Entity_Id;
20718 Op : TSS_Name_Type := TSS_Null) return Entity_Id
20720 BT : constant Entity_Id := Base_Type (T);
20721 Op_Missing : Boolean;
20723 begin
20724 if not Restriction_Active (No_Default_Stream_Attributes) then
20725 return Empty;
20726 end if;
20728 if Is_Elementary_Type (T) then
20729 if Op = TSS_Null then
20730 Op_Missing :=
20731 No (TSS (BT, TSS_Stream_Read))
20732 or else No (TSS (BT, TSS_Stream_Write));
20734 else
20735 Op_Missing := No (TSS (BT, Op));
20736 end if;
20738 if Op_Missing then
20739 return T;
20740 else
20741 return Empty;
20742 end if;
20744 elsif Is_Array_Type (T) then
20745 return Type_Without_Stream_Operation (Component_Type (T), Op);
20747 elsif Is_Record_Type (T) then
20748 declare
20749 Comp : Entity_Id;
20750 C_Typ : Entity_Id;
20752 begin
20753 Comp := First_Component (T);
20754 while Present (Comp) loop
20755 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
20757 if Present (C_Typ) then
20758 return C_Typ;
20759 end if;
20761 Next_Component (Comp);
20762 end loop;
20764 return Empty;
20765 end;
20767 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
20768 return Type_Without_Stream_Operation (Full_View (T), Op);
20769 else
20770 return Empty;
20771 end if;
20772 end Type_Without_Stream_Operation;
20774 ----------------------------
20775 -- Unique_Defining_Entity --
20776 ----------------------------
20778 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
20779 begin
20780 return Unique_Entity (Defining_Entity (N));
20781 end Unique_Defining_Entity;
20783 -------------------
20784 -- Unique_Entity --
20785 -------------------
20787 function Unique_Entity (E : Entity_Id) return Entity_Id is
20788 U : Entity_Id := E;
20789 P : Node_Id;
20791 begin
20792 case Ekind (E) is
20793 when E_Constant =>
20794 if Present (Full_View (E)) then
20795 U := Full_View (E);
20796 end if;
20798 when Entry_Kind =>
20799 if Nkind (Parent (E)) = N_Entry_Body then
20800 declare
20801 Prot_Item : Entity_Id;
20802 Prot_Type : Entity_Id;
20804 begin
20805 if Ekind (E) = E_Entry then
20806 Prot_Type := Scope (E);
20808 -- Bodies of entry families are nested within an extra scope
20809 -- that contains an entry index declaration
20811 else
20812 Prot_Type := Scope (Scope (E));
20813 end if;
20815 pragma Assert (Ekind (Prot_Type) = E_Protected_Type);
20817 -- Traverse the entity list of the protected type and locate
20818 -- an entry declaration which matches the entry body.
20820 Prot_Item := First_Entity (Prot_Type);
20821 while Present (Prot_Item) loop
20822 if Ekind (Prot_Item) in Entry_Kind
20823 and then Corresponding_Body (Parent (Prot_Item)) = E
20824 then
20825 U := Prot_Item;
20826 exit;
20827 end if;
20829 Next_Entity (Prot_Item);
20830 end loop;
20831 end;
20832 end if;
20834 when Formal_Kind =>
20835 if Present (Spec_Entity (E)) then
20836 U := Spec_Entity (E);
20837 end if;
20839 when E_Package_Body =>
20840 P := Parent (E);
20842 if Nkind (P) = N_Defining_Program_Unit_Name then
20843 P := Parent (P);
20844 end if;
20846 if Nkind (P) = N_Package_Body
20847 and then Present (Corresponding_Spec (P))
20848 then
20849 U := Corresponding_Spec (P);
20851 elsif Nkind (P) = N_Package_Body_Stub
20852 and then Present (Corresponding_Spec_Of_Stub (P))
20853 then
20854 U := Corresponding_Spec_Of_Stub (P);
20855 end if;
20857 when E_Protected_Body =>
20858 P := Parent (E);
20860 if Nkind (P) = N_Protected_Body
20861 and then Present (Corresponding_Spec (P))
20862 then
20863 U := Corresponding_Spec (P);
20865 elsif Nkind (P) = N_Protected_Body_Stub
20866 and then Present (Corresponding_Spec_Of_Stub (P))
20867 then
20868 U := Corresponding_Spec_Of_Stub (P);
20870 if Is_Single_Protected_Object (U) then
20871 U := Etype (U);
20872 end if;
20873 end if;
20875 when E_Subprogram_Body =>
20876 P := Parent (E);
20878 if Nkind (P) = N_Defining_Program_Unit_Name then
20879 P := Parent (P);
20880 end if;
20882 P := Parent (P);
20884 if Nkind (P) = N_Subprogram_Body
20885 and then Present (Corresponding_Spec (P))
20886 then
20887 U := Corresponding_Spec (P);
20889 elsif Nkind (P) = N_Subprogram_Body_Stub
20890 and then Present (Corresponding_Spec_Of_Stub (P))
20891 then
20892 U := Corresponding_Spec_Of_Stub (P);
20894 elsif Nkind (P) = N_Subprogram_Renaming_Declaration then
20895 U := Corresponding_Spec (P);
20896 end if;
20898 when E_Task_Body =>
20899 P := Parent (E);
20901 if Nkind (P) = N_Task_Body
20902 and then Present (Corresponding_Spec (P))
20903 then
20904 U := Corresponding_Spec (P);
20906 elsif Nkind (P) = N_Task_Body_Stub
20907 and then Present (Corresponding_Spec_Of_Stub (P))
20908 then
20909 U := Corresponding_Spec_Of_Stub (P);
20911 if Is_Single_Task_Object (U) then
20912 U := Etype (U);
20913 end if;
20914 end if;
20916 when Type_Kind =>
20917 if Present (Full_View (E)) then
20918 U := Full_View (E);
20919 end if;
20921 when others =>
20922 null;
20923 end case;
20925 return U;
20926 end Unique_Entity;
20928 -----------------
20929 -- Unique_Name --
20930 -----------------
20932 function Unique_Name (E : Entity_Id) return String is
20934 -- Names in E_Subprogram_Body or E_Package_Body entities are not
20935 -- reliable, as they may not include the overloading suffix. Instead,
20936 -- when looking for the name of E or one of its enclosing scope, we get
20937 -- the name of the corresponding Unique_Entity.
20939 U : constant Entity_Id := Unique_Entity (E);
20941 function This_Name return String;
20943 ---------------
20944 -- This_Name --
20945 ---------------
20947 function This_Name return String is
20948 begin
20949 return Get_Name_String (Chars (U));
20950 end This_Name;
20952 -- Start of processing for Unique_Name
20954 begin
20955 if E = Standard_Standard
20956 or else Has_Fully_Qualified_Name (E)
20957 then
20958 return This_Name;
20960 elsif Ekind (E) = E_Enumeration_Literal then
20961 return Unique_Name (Etype (E)) & "__" & This_Name;
20963 else
20964 declare
20965 S : constant Entity_Id := Scope (U);
20966 pragma Assert (Present (S));
20968 begin
20969 -- Prefix names of predefined types with standard__, but leave
20970 -- names of user-defined packages and subprograms without prefix
20971 -- (even if technically they are nested in the Standard package).
20973 if S = Standard_Standard then
20974 if Ekind (U) = E_Package or else Is_Subprogram (U) then
20975 return This_Name;
20976 else
20977 return Unique_Name (S) & "__" & This_Name;
20978 end if;
20980 -- For intances of generic subprograms use the name of the related
20981 -- instace and skip the scope of its wrapper package.
20983 elsif Is_Wrapper_Package (S) then
20984 pragma Assert (Scope (S) = Scope (Related_Instance (S)));
20985 -- Wrapper package and the instantiation are in the same scope
20987 declare
20988 Enclosing_Name : constant String :=
20989 Unique_Name (Scope (S)) & "__" &
20990 Get_Name_String (Chars (Related_Instance (S)));
20992 begin
20993 if Is_Subprogram (U)
20994 and then not Is_Generic_Actual_Subprogram (U)
20995 then
20996 return Enclosing_Name;
20997 else
20998 return Enclosing_Name & "__" & This_Name;
20999 end if;
21000 end;
21002 else
21003 return Unique_Name (S) & "__" & This_Name;
21004 end if;
21005 end;
21006 end if;
21007 end Unique_Name;
21009 ---------------------
21010 -- Unit_Is_Visible --
21011 ---------------------
21013 function Unit_Is_Visible (U : Entity_Id) return Boolean is
21014 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
21015 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
21017 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
21018 -- For a child unit, check whether unit appears in a with_clause
21019 -- of a parent.
21021 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
21022 -- Scan the context clause of one compilation unit looking for a
21023 -- with_clause for the unit in question.
21025 ----------------------------
21026 -- Unit_In_Parent_Context --
21027 ----------------------------
21029 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
21030 begin
21031 if Unit_In_Context (Par_Unit) then
21032 return True;
21034 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
21035 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
21037 else
21038 return False;
21039 end if;
21040 end Unit_In_Parent_Context;
21042 ---------------------
21043 -- Unit_In_Context --
21044 ---------------------
21046 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
21047 Clause : Node_Id;
21049 begin
21050 Clause := First (Context_Items (Comp_Unit));
21051 while Present (Clause) loop
21052 if Nkind (Clause) = N_With_Clause then
21053 if Library_Unit (Clause) = U then
21054 return True;
21056 -- The with_clause may denote a renaming of the unit we are
21057 -- looking for, eg. Text_IO which renames Ada.Text_IO.
21059 elsif
21060 Renamed_Entity (Entity (Name (Clause))) =
21061 Defining_Entity (Unit (U))
21062 then
21063 return True;
21064 end if;
21065 end if;
21067 Next (Clause);
21068 end loop;
21070 return False;
21071 end Unit_In_Context;
21073 -- Start of processing for Unit_Is_Visible
21075 begin
21076 -- The currrent unit is directly visible
21078 if Curr = U then
21079 return True;
21081 elsif Unit_In_Context (Curr) then
21082 return True;
21084 -- If the current unit is a body, check the context of the spec
21086 elsif Nkind (Unit (Curr)) = N_Package_Body
21087 or else
21088 (Nkind (Unit (Curr)) = N_Subprogram_Body
21089 and then not Acts_As_Spec (Unit (Curr)))
21090 then
21091 if Unit_In_Context (Library_Unit (Curr)) then
21092 return True;
21093 end if;
21094 end if;
21096 -- If the spec is a child unit, examine the parents
21098 if Is_Child_Unit (Curr_Entity) then
21099 if Nkind (Unit (Curr)) in N_Unit_Body then
21100 return
21101 Unit_In_Parent_Context
21102 (Parent_Spec (Unit (Library_Unit (Curr))));
21103 else
21104 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
21105 end if;
21107 else
21108 return False;
21109 end if;
21110 end Unit_Is_Visible;
21112 ------------------------------
21113 -- Universal_Interpretation --
21114 ------------------------------
21116 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
21117 Index : Interp_Index;
21118 It : Interp;
21120 begin
21121 -- The argument may be a formal parameter of an operator or subprogram
21122 -- with multiple interpretations, or else an expression for an actual.
21124 if Nkind (Opnd) = N_Defining_Identifier
21125 or else not Is_Overloaded (Opnd)
21126 then
21127 if Etype (Opnd) = Universal_Integer
21128 or else Etype (Opnd) = Universal_Real
21129 then
21130 return Etype (Opnd);
21131 else
21132 return Empty;
21133 end if;
21135 else
21136 Get_First_Interp (Opnd, Index, It);
21137 while Present (It.Typ) loop
21138 if It.Typ = Universal_Integer
21139 or else It.Typ = Universal_Real
21140 then
21141 return It.Typ;
21142 end if;
21144 Get_Next_Interp (Index, It);
21145 end loop;
21147 return Empty;
21148 end if;
21149 end Universal_Interpretation;
21151 ---------------
21152 -- Unqualify --
21153 ---------------
21155 function Unqualify (Expr : Node_Id) return Node_Id is
21156 begin
21157 -- Recurse to handle unlikely case of multiple levels of qualification
21159 if Nkind (Expr) = N_Qualified_Expression then
21160 return Unqualify (Expression (Expr));
21162 -- Normal case, not a qualified expression
21164 else
21165 return Expr;
21166 end if;
21167 end Unqualify;
21169 -----------------------
21170 -- Visible_Ancestors --
21171 -----------------------
21173 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
21174 List_1 : Elist_Id;
21175 List_2 : Elist_Id;
21176 Elmt : Elmt_Id;
21178 begin
21179 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
21181 -- Collect all the parents and progenitors of Typ. If the full-view of
21182 -- private parents and progenitors is available then it is used to
21183 -- generate the list of visible ancestors; otherwise their partial
21184 -- view is added to the resulting list.
21186 Collect_Parents
21187 (T => Typ,
21188 List => List_1,
21189 Use_Full_View => True);
21191 Collect_Interfaces
21192 (T => Typ,
21193 Ifaces_List => List_2,
21194 Exclude_Parents => True,
21195 Use_Full_View => True);
21197 -- Join the two lists. Avoid duplications because an interface may
21198 -- simultaneously be parent and progenitor of a type.
21200 Elmt := First_Elmt (List_2);
21201 while Present (Elmt) loop
21202 Append_Unique_Elmt (Node (Elmt), List_1);
21203 Next_Elmt (Elmt);
21204 end loop;
21206 return List_1;
21207 end Visible_Ancestors;
21209 ----------------------
21210 -- Within_Init_Proc --
21211 ----------------------
21213 function Within_Init_Proc return Boolean is
21214 S : Entity_Id;
21216 begin
21217 S := Current_Scope;
21218 while not Is_Overloadable (S) loop
21219 if S = Standard_Standard then
21220 return False;
21221 else
21222 S := Scope (S);
21223 end if;
21224 end loop;
21226 return Is_Init_Proc (S);
21227 end Within_Init_Proc;
21229 ------------------
21230 -- Within_Scope --
21231 ------------------
21233 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
21234 begin
21235 return Scope_Within_Or_Same (Scope (E), S);
21236 end Within_Scope;
21238 ----------------
21239 -- Wrong_Type --
21240 ----------------
21242 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
21243 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
21244 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
21246 Matching_Field : Entity_Id;
21247 -- Entity to give a more precise suggestion on how to write a one-
21248 -- element positional aggregate.
21250 function Has_One_Matching_Field return Boolean;
21251 -- Determines if Expec_Type is a record type with a single component or
21252 -- discriminant whose type matches the found type or is one dimensional
21253 -- array whose component type matches the found type. In the case of
21254 -- one discriminant, we ignore the variant parts. That's not accurate,
21255 -- but good enough for the warning.
21257 ----------------------------
21258 -- Has_One_Matching_Field --
21259 ----------------------------
21261 function Has_One_Matching_Field return Boolean is
21262 E : Entity_Id;
21264 begin
21265 Matching_Field := Empty;
21267 if Is_Array_Type (Expec_Type)
21268 and then Number_Dimensions (Expec_Type) = 1
21269 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
21270 then
21271 -- Use type name if available. This excludes multidimensional
21272 -- arrays and anonymous arrays.
21274 if Comes_From_Source (Expec_Type) then
21275 Matching_Field := Expec_Type;
21277 -- For an assignment, use name of target
21279 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
21280 and then Is_Entity_Name (Name (Parent (Expr)))
21281 then
21282 Matching_Field := Entity (Name (Parent (Expr)));
21283 end if;
21285 return True;
21287 elsif not Is_Record_Type (Expec_Type) then
21288 return False;
21290 else
21291 E := First_Entity (Expec_Type);
21292 loop
21293 if No (E) then
21294 return False;
21296 elsif not Ekind_In (E, E_Discriminant, E_Component)
21297 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
21298 then
21299 Next_Entity (E);
21301 else
21302 exit;
21303 end if;
21304 end loop;
21306 if not Covers (Etype (E), Found_Type) then
21307 return False;
21309 elsif Present (Next_Entity (E))
21310 and then (Ekind (E) = E_Component
21311 or else Ekind (Next_Entity (E)) = E_Discriminant)
21312 then
21313 return False;
21315 else
21316 Matching_Field := E;
21317 return True;
21318 end if;
21319 end if;
21320 end Has_One_Matching_Field;
21322 -- Start of processing for Wrong_Type
21324 begin
21325 -- Don't output message if either type is Any_Type, or if a message
21326 -- has already been posted for this node. We need to do the latter
21327 -- check explicitly (it is ordinarily done in Errout), because we
21328 -- are using ! to force the output of the error messages.
21330 if Expec_Type = Any_Type
21331 or else Found_Type = Any_Type
21332 or else Error_Posted (Expr)
21333 then
21334 return;
21336 -- If one of the types is a Taft-Amendment type and the other it its
21337 -- completion, it must be an illegal use of a TAT in the spec, for
21338 -- which an error was already emitted. Avoid cascaded errors.
21340 elsif Is_Incomplete_Type (Expec_Type)
21341 and then Has_Completion_In_Body (Expec_Type)
21342 and then Full_View (Expec_Type) = Etype (Expr)
21343 then
21344 return;
21346 elsif Is_Incomplete_Type (Etype (Expr))
21347 and then Has_Completion_In_Body (Etype (Expr))
21348 and then Full_View (Etype (Expr)) = Expec_Type
21349 then
21350 return;
21352 -- In an instance, there is an ongoing problem with completion of
21353 -- type derived from private types. Their structure is what Gigi
21354 -- expects, but the Etype is the parent type rather than the
21355 -- derived private type itself. Do not flag error in this case. The
21356 -- private completion is an entity without a parent, like an Itype.
21357 -- Similarly, full and partial views may be incorrect in the instance.
21358 -- There is no simple way to insure that it is consistent ???
21360 -- A similar view discrepancy can happen in an inlined body, for the
21361 -- same reason: inserted body may be outside of the original package
21362 -- and only partial views are visible at the point of insertion.
21364 elsif In_Instance or else In_Inlined_Body then
21365 if Etype (Etype (Expr)) = Etype (Expected_Type)
21366 and then
21367 (Has_Private_Declaration (Expected_Type)
21368 or else Has_Private_Declaration (Etype (Expr)))
21369 and then No (Parent (Expected_Type))
21370 then
21371 return;
21373 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
21374 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
21375 then
21376 return;
21378 elsif Is_Private_Type (Expected_Type)
21379 and then Present (Full_View (Expected_Type))
21380 and then Covers (Full_View (Expected_Type), Etype (Expr))
21381 then
21382 return;
21384 -- Conversely, type of expression may be the private one
21386 elsif Is_Private_Type (Base_Type (Etype (Expr)))
21387 and then Full_View (Base_Type (Etype (Expr))) = Expected_Type
21388 then
21389 return;
21390 end if;
21391 end if;
21393 -- An interesting special check. If the expression is parenthesized
21394 -- and its type corresponds to the type of the sole component of the
21395 -- expected record type, or to the component type of the expected one
21396 -- dimensional array type, then assume we have a bad aggregate attempt.
21398 if Nkind (Expr) in N_Subexpr
21399 and then Paren_Count (Expr) /= 0
21400 and then Has_One_Matching_Field
21401 then
21402 Error_Msg_N ("positional aggregate cannot have one component", Expr);
21404 if Present (Matching_Field) then
21405 if Is_Array_Type (Expec_Type) then
21406 Error_Msg_NE
21407 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
21408 else
21409 Error_Msg_NE
21410 ("\write instead `& ='> ...`", Expr, Matching_Field);
21411 end if;
21412 end if;
21414 -- Another special check, if we are looking for a pool-specific access
21415 -- type and we found an E_Access_Attribute_Type, then we have the case
21416 -- of an Access attribute being used in a context which needs a pool-
21417 -- specific type, which is never allowed. The one extra check we make
21418 -- is that the expected designated type covers the Found_Type.
21420 elsif Is_Access_Type (Expec_Type)
21421 and then Ekind (Found_Type) = E_Access_Attribute_Type
21422 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
21423 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
21424 and then Covers
21425 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
21426 then
21427 Error_Msg_N -- CODEFIX
21428 ("result must be general access type!", Expr);
21429 Error_Msg_NE -- CODEFIX
21430 ("add ALL to }!", Expr, Expec_Type);
21432 -- Another special check, if the expected type is an integer type,
21433 -- but the expression is of type System.Address, and the parent is
21434 -- an addition or subtraction operation whose left operand is the
21435 -- expression in question and whose right operand is of an integral
21436 -- type, then this is an attempt at address arithmetic, so give
21437 -- appropriate message.
21439 elsif Is_Integer_Type (Expec_Type)
21440 and then Is_RTE (Found_Type, RE_Address)
21441 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
21442 and then Expr = Left_Opnd (Parent (Expr))
21443 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
21444 then
21445 Error_Msg_N
21446 ("address arithmetic not predefined in package System",
21447 Parent (Expr));
21448 Error_Msg_N
21449 ("\possible missing with/use of System.Storage_Elements",
21450 Parent (Expr));
21451 return;
21453 -- If the expected type is an anonymous access type, as for access
21454 -- parameters and discriminants, the error is on the designated types.
21456 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
21457 if Comes_From_Source (Expec_Type) then
21458 Error_Msg_NE ("expected}!", Expr, Expec_Type);
21459 else
21460 Error_Msg_NE
21461 ("expected an access type with designated}",
21462 Expr, Designated_Type (Expec_Type));
21463 end if;
21465 if Is_Access_Type (Found_Type)
21466 and then not Comes_From_Source (Found_Type)
21467 then
21468 Error_Msg_NE
21469 ("\\found an access type with designated}!",
21470 Expr, Designated_Type (Found_Type));
21471 else
21472 if From_Limited_With (Found_Type) then
21473 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
21474 Error_Msg_Qual_Level := 99;
21475 Error_Msg_NE -- CODEFIX
21476 ("\\missing `WITH &;", Expr, Scope (Found_Type));
21477 Error_Msg_Qual_Level := 0;
21478 else
21479 Error_Msg_NE ("found}!", Expr, Found_Type);
21480 end if;
21481 end if;
21483 -- Normal case of one type found, some other type expected
21485 else
21486 -- If the names of the two types are the same, see if some number
21487 -- of levels of qualification will help. Don't try more than three
21488 -- levels, and if we get to standard, it's no use (and probably
21489 -- represents an error in the compiler) Also do not bother with
21490 -- internal scope names.
21492 declare
21493 Expec_Scope : Entity_Id;
21494 Found_Scope : Entity_Id;
21496 begin
21497 Expec_Scope := Expec_Type;
21498 Found_Scope := Found_Type;
21500 for Levels in Nat range 0 .. 3 loop
21501 if Chars (Expec_Scope) /= Chars (Found_Scope) then
21502 Error_Msg_Qual_Level := Levels;
21503 exit;
21504 end if;
21506 Expec_Scope := Scope (Expec_Scope);
21507 Found_Scope := Scope (Found_Scope);
21509 exit when Expec_Scope = Standard_Standard
21510 or else Found_Scope = Standard_Standard
21511 or else not Comes_From_Source (Expec_Scope)
21512 or else not Comes_From_Source (Found_Scope);
21513 end loop;
21514 end;
21516 if Is_Record_Type (Expec_Type)
21517 and then Present (Corresponding_Remote_Type (Expec_Type))
21518 then
21519 Error_Msg_NE ("expected}!", Expr,
21520 Corresponding_Remote_Type (Expec_Type));
21521 else
21522 Error_Msg_NE ("expected}!", Expr, Expec_Type);
21523 end if;
21525 if Is_Entity_Name (Expr)
21526 and then Is_Package_Or_Generic_Package (Entity (Expr))
21527 then
21528 Error_Msg_N ("\\found package name!", Expr);
21530 elsif Is_Entity_Name (Expr)
21531 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
21532 then
21533 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
21534 Error_Msg_N
21535 ("found procedure name, possibly missing Access attribute!",
21536 Expr);
21537 else
21538 Error_Msg_N
21539 ("\\found procedure name instead of function!", Expr);
21540 end if;
21542 elsif Nkind (Expr) = N_Function_Call
21543 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
21544 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
21545 and then No (Parameter_Associations (Expr))
21546 then
21547 Error_Msg_N
21548 ("found function name, possibly missing Access attribute!",
21549 Expr);
21551 -- Catch common error: a prefix or infix operator which is not
21552 -- directly visible because the type isn't.
21554 elsif Nkind (Expr) in N_Op
21555 and then Is_Overloaded (Expr)
21556 and then not Is_Immediately_Visible (Expec_Type)
21557 and then not Is_Potentially_Use_Visible (Expec_Type)
21558 and then not In_Use (Expec_Type)
21559 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
21560 then
21561 Error_Msg_N
21562 ("operator of the type is not directly visible!", Expr);
21564 elsif Ekind (Found_Type) = E_Void
21565 and then Present (Parent (Found_Type))
21566 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
21567 then
21568 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
21570 else
21571 Error_Msg_NE ("\\found}!", Expr, Found_Type);
21572 end if;
21574 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
21575 -- of the same modular type, and (M1 and M2) = 0 was intended.
21577 if Expec_Type = Standard_Boolean
21578 and then Is_Modular_Integer_Type (Found_Type)
21579 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
21580 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
21581 then
21582 declare
21583 Op : constant Node_Id := Right_Opnd (Parent (Expr));
21584 L : constant Node_Id := Left_Opnd (Op);
21585 R : constant Node_Id := Right_Opnd (Op);
21587 begin
21588 -- The case for the message is when the left operand of the
21589 -- comparison is the same modular type, or when it is an
21590 -- integer literal (or other universal integer expression),
21591 -- which would have been typed as the modular type if the
21592 -- parens had been there.
21594 if (Etype (L) = Found_Type
21595 or else
21596 Etype (L) = Universal_Integer)
21597 and then Is_Integer_Type (Etype (R))
21598 then
21599 Error_Msg_N
21600 ("\\possible missing parens for modular operation", Expr);
21601 end if;
21602 end;
21603 end if;
21605 -- Reset error message qualification indication
21607 Error_Msg_Qual_Level := 0;
21608 end if;
21609 end Wrong_Type;
21611 --------------------------------
21612 -- Yields_Synchronized_Object --
21613 --------------------------------
21615 function Yields_Synchronized_Object (Typ : Entity_Id) return Boolean is
21616 Has_Sync_Comp : Boolean := False;
21617 Id : Entity_Id;
21619 begin
21620 -- An array type yields a synchronized object if its component type
21621 -- yields a synchronized object.
21623 if Is_Array_Type (Typ) then
21624 return Yields_Synchronized_Object (Component_Type (Typ));
21626 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
21627 -- yields a synchronized object by default.
21629 elsif Is_Descendant_Of_Suspension_Object (Typ) then
21630 return True;
21632 -- A protected type yields a synchronized object by default
21634 elsif Is_Protected_Type (Typ) then
21635 return True;
21637 -- A record type or type extension yields a synchronized object when its
21638 -- discriminants (if any) lack default values and all components are of
21639 -- a type that yelds a synchronized object.
21641 elsif Is_Record_Type (Typ) then
21643 -- Inspect all entities defined in the scope of the type, looking for
21644 -- components of a type that does not yeld a synchronized object or
21645 -- for discriminants with default values.
21647 Id := First_Entity (Typ);
21648 while Present (Id) loop
21649 if Comes_From_Source (Id) then
21650 if Ekind (Id) = E_Component then
21651 if Yields_Synchronized_Object (Etype (Id)) then
21652 Has_Sync_Comp := True;
21654 -- The component does not yield a synchronized object
21656 else
21657 return False;
21658 end if;
21660 elsif Ekind (Id) = E_Discriminant
21661 and then Present (Expression (Parent (Id)))
21662 then
21663 return False;
21664 end if;
21665 end if;
21667 Next_Entity (Id);
21668 end loop;
21670 -- Ensure that the parent type of a type extension yields a
21671 -- synchronized object.
21673 if Etype (Typ) /= Typ
21674 and then not Yields_Synchronized_Object (Etype (Typ))
21675 then
21676 return False;
21677 end if;
21679 -- If we get here, then all discriminants lack default values and all
21680 -- components are of a type that yields a synchronized object.
21682 return Has_Sync_Comp;
21684 -- A synchronized interface type yields a synchronized object by default
21686 elsif Is_Synchronized_Interface (Typ) then
21687 return True;
21689 -- A task type yelds a synchronized object by default
21691 elsif Is_Task_Type (Typ) then
21692 return True;
21694 -- Otherwise the type does not yield a synchronized object
21696 else
21697 return False;
21698 end if;
21699 end Yields_Synchronized_Object;
21701 ---------------------------
21702 -- Yields_Universal_Type --
21703 ---------------------------
21705 function Yields_Universal_Type (N : Node_Id) return Boolean is
21706 begin
21707 -- Integer and real literals are of a universal type
21709 if Nkind_In (N, N_Integer_Literal, N_Real_Literal) then
21710 return True;
21712 -- The values of certain attributes are of a universal type
21714 elsif Nkind (N) = N_Attribute_Reference then
21715 return
21716 Universal_Type_Attribute (Get_Attribute_Id (Attribute_Name (N)));
21718 -- ??? There are possibly other cases to consider
21720 else
21721 return False;
21722 end if;
21723 end Yields_Universal_Type;
21725 end Sem_Util;