2014-09-15 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
[official-gcc.git] / gcc / ada / sem_util.adb
blob01c16244621bb13ec5d2d764f05ae34c2ffb52a0
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-2014, 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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
38 with Lib; use Lib;
39 with Lib.Xref; use Lib.Xref;
40 with Namet.Sp; use Namet.Sp;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
43 with Output; use Output;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
47 with Sem; use Sem;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Attr; use Sem_Attr;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Ch13; use Sem_Ch13;
52 with Sem_Disp; use Sem_Disp;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Prag; use Sem_Prag;
55 with Sem_Res; use Sem_Res;
56 with Sem_Warn; use Sem_Warn;
57 with Sem_Type; use Sem_Type;
58 with Sinfo; use Sinfo;
59 with Sinput; use Sinput;
60 with Stand; use Stand;
61 with Style;
62 with Stringt; use Stringt;
63 with Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Ttypes; use Ttypes;
66 with Uname; use Uname;
68 with GNAT.HTable; use GNAT.HTable;
70 package body Sem_Util is
72 ----------------------------------------
73 -- Global_Variables for New_Copy_Tree --
74 ----------------------------------------
76 -- These global variables are used by New_Copy_Tree. See description of the
77 -- body of this subprogram for details. Global variables can be safely used
78 -- by New_Copy_Tree, since there is no case of a recursive call from the
79 -- processing inside New_Copy_Tree.
81 NCT_Hash_Threshold : constant := 20;
82 -- If there are more than this number of pairs of entries in the map, then
83 -- Hash_Tables_Used will be set, and the hash tables will be initialized
84 -- and used for the searches.
86 NCT_Hash_Tables_Used : Boolean := False;
87 -- Set to True if hash tables are in use
89 NCT_Table_Entries : Nat := 0;
90 -- Count entries in table to see if threshold is reached
92 NCT_Hash_Table_Setup : Boolean := False;
93 -- Set to True if hash table contains data. We set this True if we setup
94 -- the hash table with data, and leave it set permanently from then on,
95 -- this is a signal that second and subsequent users of the hash table
96 -- must clear the old entries before reuse.
98 subtype NCT_Header_Num is Int range 0 .. 511;
99 -- Defines range of headers in hash tables (512 headers)
101 -----------------------
102 -- Local Subprograms --
103 -----------------------
105 function Build_Component_Subtype
106 (C : List_Id;
107 Loc : Source_Ptr;
108 T : Entity_Id) return Node_Id;
109 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
110 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
111 -- Loc is the source location, T is the original subtype.
113 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
114 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
115 -- with discriminants whose default values are static, examine only the
116 -- components in the selected variant to determine whether all of them
117 -- have a default.
119 function Has_Enabled_Property
120 (Item_Id : Entity_Id;
121 Property : Name_Id) return Boolean;
122 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
123 -- Determine whether an abstract state or a variable denoted by entity
124 -- Item_Id has enabled property Property.
126 function Has_Null_Extension (T : Entity_Id) return Boolean;
127 -- T is a derived tagged type. Check whether the type extension is null.
128 -- If the parent type is fully initialized, T can be treated as such.
130 ------------------------------
131 -- Abstract_Interface_List --
132 ------------------------------
134 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
135 Nod : Node_Id;
137 begin
138 if Is_Concurrent_Type (Typ) then
140 -- If we are dealing with a synchronized subtype, go to the base
141 -- type, whose declaration has the interface list.
143 -- Shouldn't this be Declaration_Node???
145 Nod := Parent (Base_Type (Typ));
147 if Nkind (Nod) = N_Full_Type_Declaration then
148 return Empty_List;
149 end if;
151 elsif Ekind (Typ) = E_Record_Type_With_Private then
152 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
153 Nod := Type_Definition (Parent (Typ));
155 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
156 if Present (Full_View (Typ))
157 and then
158 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
159 then
160 Nod := Type_Definition (Parent (Full_View (Typ)));
162 -- If the full-view is not available we cannot do anything else
163 -- here (the source has errors).
165 else
166 return Empty_List;
167 end if;
169 -- Support for generic formals with interfaces is still missing ???
171 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
172 return Empty_List;
174 else
175 pragma Assert
176 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
177 Nod := Parent (Typ);
178 end if;
180 elsif Ekind (Typ) = E_Record_Subtype then
181 Nod := Type_Definition (Parent (Etype (Typ)));
183 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
185 -- Recurse, because parent may still be a private extension. Also
186 -- note that the full view of the subtype or the full view of its
187 -- base type may (both) be unavailable.
189 return Abstract_Interface_List (Etype (Typ));
191 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
192 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
193 Nod := Formal_Type_Definition (Parent (Typ));
194 else
195 Nod := Type_Definition (Parent (Typ));
196 end if;
197 end if;
199 return Interface_List (Nod);
200 end Abstract_Interface_List;
202 --------------------------------
203 -- Add_Access_Type_To_Process --
204 --------------------------------
206 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
207 L : Elist_Id;
209 begin
210 Ensure_Freeze_Node (E);
211 L := Access_Types_To_Process (Freeze_Node (E));
213 if No (L) then
214 L := New_Elmt_List;
215 Set_Access_Types_To_Process (Freeze_Node (E), L);
216 end if;
218 Append_Elmt (A, L);
219 end Add_Access_Type_To_Process;
221 --------------------------
222 -- Add_Block_Identifier --
223 --------------------------
225 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
226 Loc : constant Source_Ptr := Sloc (N);
228 begin
229 pragma Assert (Nkind (N) = N_Block_Statement);
231 -- The block already has a label, return its entity
233 if Present (Identifier (N)) then
234 Id := Entity (Identifier (N));
236 -- Create a new block label and set its attributes
238 else
239 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
240 Set_Etype (Id, Standard_Void_Type);
241 Set_Parent (Id, N);
243 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
244 Set_Block_Node (Id, Identifier (N));
245 end if;
246 end Add_Block_Identifier;
248 -----------------------
249 -- Add_Contract_Item --
250 -----------------------
252 procedure Add_Contract_Item (Prag : Node_Id; Id : Entity_Id) is
253 Items : constant Node_Id := Contract (Id);
254 Nam : Name_Id;
255 N : Node_Id;
257 begin
258 -- The related context must have a contract and the item to be added
259 -- must be a pragma.
261 pragma Assert (Present (Items));
262 pragma Assert (Nkind (Prag) = N_Pragma);
264 Nam := Original_Aspect_Name (Prag);
266 -- Contract items related to [generic] packages or instantiations. The
267 -- applicable pragmas are:
268 -- Abstract_States
269 -- Initial_Condition
270 -- Initializes
271 -- Part_Of (instantiation only)
273 if Ekind_In (Id, E_Generic_Package, E_Package) then
274 if Nam_In (Nam, Name_Abstract_State,
275 Name_Initial_Condition,
276 Name_Initializes)
277 then
278 Set_Next_Pragma (Prag, Classifications (Items));
279 Set_Classifications (Items, Prag);
281 -- Indicator Part_Of must be associated with a package instantiation
283 elsif Nam = Name_Part_Of and then Is_Generic_Instance (Id) then
284 Set_Next_Pragma (Prag, Classifications (Items));
285 Set_Classifications (Items, Prag);
287 -- The pragma is not a proper contract item
289 else
290 raise Program_Error;
291 end if;
293 -- Contract items related to package bodies. The applicable pragmas are:
294 -- Refined_States
296 elsif Ekind (Id) = E_Package_Body then
297 if Nam = Name_Refined_State then
298 Set_Next_Pragma (Prag, Classifications (Items));
299 Set_Classifications (Items, Prag);
301 -- The pragma is not a proper contract item
303 else
304 raise Program_Error;
305 end if;
307 -- Contract items related to subprogram or entry declarations. The
308 -- applicable pragmas are:
309 -- Contract_Cases
310 -- Depends
311 -- Global
312 -- Post
313 -- Postcondition
314 -- Pre
315 -- Precondition
316 -- Test_Case
318 elsif Ekind_In (Id, E_Entry, E_Entry_Family)
319 or else Is_Generic_Subprogram (Id)
320 or else Is_Subprogram (Id)
321 then
322 if Nam_In (Nam, Name_Precondition,
323 Name_Postcondition,
324 Name_Pre,
325 Name_Post,
326 Name_uPre,
327 Name_uPost)
328 then
329 -- Before we add a precondition or postcondition to the list,
330 -- make sure we do not have a disallowed duplicate, which can
331 -- happen if we use a pragma for Pre[_Class] or Post[_Class]
332 -- instead of the corresponding aspect.
334 if not From_Aspect_Specification (Prag)
335 and then Nam_In (Nam, Name_Pre_Class,
336 Name_Pre,
337 Name_uPre,
338 Name_Post_Class,
339 Name_Post,
340 Name_uPost)
341 then
342 N := Pre_Post_Conditions (Items);
343 while Present (N) loop
344 if not Split_PPC (N)
345 and then Original_Aspect_Name (N) = Nam
346 then
347 Error_Msg_Sloc := Sloc (N);
348 Error_Msg_NE
349 ("duplication of aspect for & given#", Prag, Id);
350 return;
351 else
352 N := Next_Pragma (N);
353 end if;
354 end loop;
355 end if;
357 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
358 Set_Pre_Post_Conditions (Items, Prag);
360 elsif Nam_In (Nam, Name_Contract_Cases, Name_Test_Case) then
361 Set_Next_Pragma (Prag, Contract_Test_Cases (Items));
362 Set_Contract_Test_Cases (Items, Prag);
364 elsif Nam_In (Nam, Name_Depends, Name_Global) then
365 Set_Next_Pragma (Prag, Classifications (Items));
366 Set_Classifications (Items, Prag);
368 -- The pragma is not a proper contract item
370 else
371 raise Program_Error;
372 end if;
374 -- Contract items related to subprogram bodies. The applicable pragmas
375 -- are:
376 -- Refined_Depends
377 -- Refined_Global
378 -- Refined_Post
380 elsif Ekind (Id) = E_Subprogram_Body then
381 if Nam = Name_Refined_Post then
382 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
383 Set_Pre_Post_Conditions (Items, Prag);
385 elsif Nam_In (Nam, Name_Refined_Depends, Name_Refined_Global) then
386 Set_Next_Pragma (Prag, Classifications (Items));
387 Set_Classifications (Items, Prag);
389 -- The pragma is not a proper contract item
391 else
392 raise Program_Error;
393 end if;
395 -- Contract items related to variables. The applicable pragmas are:
396 -- Async_Readers
397 -- Async_Writers
398 -- Effective_Reads
399 -- Effective_Writes
400 -- Part_Of
402 elsif Ekind (Id) = E_Variable then
403 if Nam_In (Nam, Name_Async_Readers,
404 Name_Async_Writers,
405 Name_Effective_Reads,
406 Name_Effective_Writes,
407 Name_Part_Of)
408 then
409 Set_Next_Pragma (Prag, Classifications (Items));
410 Set_Classifications (Items, Prag);
412 -- The pragma is not a proper contract item
414 else
415 raise Program_Error;
416 end if;
417 end if;
418 end Add_Contract_Item;
420 ----------------------------
421 -- Add_Global_Declaration --
422 ----------------------------
424 procedure Add_Global_Declaration (N : Node_Id) is
425 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
427 begin
428 if No (Declarations (Aux_Node)) then
429 Set_Declarations (Aux_Node, New_List);
430 end if;
432 Append_To (Declarations (Aux_Node), N);
433 Analyze (N);
434 end Add_Global_Declaration;
436 --------------------------------
437 -- Address_Integer_Convert_OK --
438 --------------------------------
440 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
441 begin
442 if Allow_Integer_Address
443 and then ((Is_Descendent_Of_Address (T1)
444 and then Is_Private_Type (T1)
445 and then Is_Integer_Type (T2))
446 or else
447 (Is_Descendent_Of_Address (T2)
448 and then Is_Private_Type (T2)
449 and then Is_Integer_Type (T1)))
450 then
451 return True;
452 else
453 return False;
454 end if;
455 end Address_Integer_Convert_OK;
457 -----------------
458 -- Addressable --
459 -----------------
461 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
463 function Addressable (V : Uint) return Boolean is
464 begin
465 return V = Uint_8 or else
466 V = Uint_16 or else
467 V = Uint_32 or else
468 V = Uint_64;
469 end Addressable;
471 function Addressable (V : Int) return Boolean is
472 begin
473 return V = 8 or else
474 V = 16 or else
475 V = 32 or else
476 V = 64;
477 end Addressable;
479 ---------------------------------
480 -- Aggregate_Constraint_Checks --
481 ---------------------------------
483 procedure Aggregate_Constraint_Checks
484 (Exp : Node_Id;
485 Check_Typ : Entity_Id)
487 Exp_Typ : constant Entity_Id := Etype (Exp);
489 begin
490 if Raises_Constraint_Error (Exp) then
491 return;
492 end if;
494 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
495 -- component's type to force the appropriate accessibility checks.
497 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
498 -- type to force the corresponding run-time check
500 if Is_Access_Type (Check_Typ)
501 and then ((Is_Local_Anonymous_Access (Check_Typ))
502 or else (Can_Never_Be_Null (Check_Typ)
503 and then not Can_Never_Be_Null (Exp_Typ)))
504 then
505 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
506 Analyze_And_Resolve (Exp, Check_Typ);
507 Check_Unset_Reference (Exp);
508 end if;
510 -- This is really expansion activity, so make sure that expansion is
511 -- on and is allowed. In GNATprove mode, we also want check flags to
512 -- be added in the tree, so that the formal verification can rely on
513 -- those to be present. In GNATprove mode for formal verification, some
514 -- treatment typically only done during expansion needs to be performed
515 -- on the tree, but it should not be applied inside generics. Otherwise,
516 -- this breaks the name resolution mechanism for generic instances.
518 if not Expander_Active
519 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
520 then
521 return;
522 end if;
524 -- First check if we have to insert discriminant checks
526 if Has_Discriminants (Exp_Typ) then
527 Apply_Discriminant_Check (Exp, Check_Typ);
529 -- Next emit length checks for array aggregates
531 elsif Is_Array_Type (Exp_Typ) then
532 Apply_Length_Check (Exp, Check_Typ);
534 -- Finally emit scalar and string checks. If we are dealing with a
535 -- scalar literal we need to check by hand because the Etype of
536 -- literals is not necessarily correct.
538 elsif Is_Scalar_Type (Exp_Typ)
539 and then Compile_Time_Known_Value (Exp)
540 then
541 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
542 Apply_Compile_Time_Constraint_Error
543 (Exp, "value not in range of}??", CE_Range_Check_Failed,
544 Ent => Base_Type (Check_Typ),
545 Typ => Base_Type (Check_Typ));
547 elsif Is_Out_Of_Range (Exp, Check_Typ) then
548 Apply_Compile_Time_Constraint_Error
549 (Exp, "value not in range of}??", CE_Range_Check_Failed,
550 Ent => Check_Typ,
551 Typ => Check_Typ);
553 elsif not Range_Checks_Suppressed (Check_Typ) then
554 Apply_Scalar_Range_Check (Exp, Check_Typ);
555 end if;
557 -- Verify that target type is also scalar, to prevent view anomalies
558 -- in instantiations.
560 elsif (Is_Scalar_Type (Exp_Typ)
561 or else Nkind (Exp) = N_String_Literal)
562 and then Is_Scalar_Type (Check_Typ)
563 and then Exp_Typ /= Check_Typ
564 then
565 if Is_Entity_Name (Exp)
566 and then Ekind (Entity (Exp)) = E_Constant
567 then
568 -- If expression is a constant, it is worthwhile checking whether
569 -- it is a bound of the type.
571 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
572 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
573 or else
574 (Is_Entity_Name (Type_High_Bound (Check_Typ))
575 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
576 then
577 return;
579 else
580 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
581 Analyze_And_Resolve (Exp, Check_Typ);
582 Check_Unset_Reference (Exp);
583 end if;
585 -- Could use a comment on this case ???
587 else
588 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
589 Analyze_And_Resolve (Exp, Check_Typ);
590 Check_Unset_Reference (Exp);
591 end if;
593 end if;
594 end Aggregate_Constraint_Checks;
596 -----------------------
597 -- Alignment_In_Bits --
598 -----------------------
600 function Alignment_In_Bits (E : Entity_Id) return Uint is
601 begin
602 return Alignment (E) * System_Storage_Unit;
603 end Alignment_In_Bits;
605 ---------------------------------
606 -- Append_Inherited_Subprogram --
607 ---------------------------------
609 procedure Append_Inherited_Subprogram (S : Entity_Id) is
610 Par : constant Entity_Id := Alias (S);
611 -- The parent subprogram
613 Scop : constant Entity_Id := Scope (Par);
614 -- The scope of definition of the parent subprogram
616 Typ : constant Entity_Id := Defining_Entity (Parent (S));
617 -- The derived type of which S is a primitive operation
619 Decl : Node_Id;
620 Next_E : Entity_Id;
622 begin
623 if Ekind (Current_Scope) = E_Package
624 and then In_Private_Part (Current_Scope)
625 and then Has_Private_Declaration (Typ)
626 and then Is_Tagged_Type (Typ)
627 and then Scop = Current_Scope
628 then
629 -- The inherited operation is available at the earliest place after
630 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
631 -- relevant for type extensions. If the parent operation appears
632 -- after the type extension, the operation is not visible.
634 Decl := First
635 (Visible_Declarations
636 (Package_Specification (Current_Scope)));
637 while Present (Decl) loop
638 if Nkind (Decl) = N_Private_Extension_Declaration
639 and then Defining_Entity (Decl) = Typ
640 then
641 if Sloc (Decl) > Sloc (Par) then
642 Next_E := Next_Entity (Par);
643 Set_Next_Entity (Par, S);
644 Set_Next_Entity (S, Next_E);
645 return;
647 else
648 exit;
649 end if;
650 end if;
652 Next (Decl);
653 end loop;
654 end if;
656 -- If partial view is not a type extension, or it appears before the
657 -- subprogram declaration, insert normally at end of entity list.
659 Append_Entity (S, Current_Scope);
660 end Append_Inherited_Subprogram;
662 -----------------------------------------
663 -- Apply_Compile_Time_Constraint_Error --
664 -----------------------------------------
666 procedure Apply_Compile_Time_Constraint_Error
667 (N : Node_Id;
668 Msg : String;
669 Reason : RT_Exception_Code;
670 Ent : Entity_Id := Empty;
671 Typ : Entity_Id := Empty;
672 Loc : Source_Ptr := No_Location;
673 Rep : Boolean := True;
674 Warn : Boolean := False)
676 Stat : constant Boolean := Is_Static_Expression (N);
677 R_Stat : constant Node_Id :=
678 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
679 Rtyp : Entity_Id;
681 begin
682 if No (Typ) then
683 Rtyp := Etype (N);
684 else
685 Rtyp := Typ;
686 end if;
688 Discard_Node
689 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
691 if not Rep then
692 return;
693 end if;
695 -- Now we replace the node by an N_Raise_Constraint_Error node
696 -- This does not need reanalyzing, so set it as analyzed now.
698 Rewrite (N, R_Stat);
699 Set_Analyzed (N, True);
701 Set_Etype (N, Rtyp);
702 Set_Raises_Constraint_Error (N);
704 -- Now deal with possible local raise handling
706 Possible_Local_Raise (N, Standard_Constraint_Error);
708 -- If the original expression was marked as static, the result is
709 -- still marked as static, but the Raises_Constraint_Error flag is
710 -- always set so that further static evaluation is not attempted.
712 if Stat then
713 Set_Is_Static_Expression (N);
714 end if;
715 end Apply_Compile_Time_Constraint_Error;
717 ---------------------------
718 -- Async_Readers_Enabled --
719 ---------------------------
721 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
722 begin
723 return Has_Enabled_Property (Id, Name_Async_Readers);
724 end Async_Readers_Enabled;
726 ---------------------------
727 -- Async_Writers_Enabled --
728 ---------------------------
730 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
731 begin
732 return Has_Enabled_Property (Id, Name_Async_Writers);
733 end Async_Writers_Enabled;
735 --------------------------------------
736 -- Available_Full_View_Of_Component --
737 --------------------------------------
739 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
740 ST : constant Entity_Id := Scope (T);
741 SCT : constant Entity_Id := Scope (Component_Type (T));
742 begin
743 return In_Open_Scopes (ST)
744 and then In_Open_Scopes (SCT)
745 and then Scope_Depth (ST) >= Scope_Depth (SCT);
746 end Available_Full_View_Of_Component;
748 -------------------
749 -- Bad_Attribute --
750 -------------------
752 procedure Bad_Attribute
753 (N : Node_Id;
754 Nam : Name_Id;
755 Warn : Boolean := False)
757 begin
758 Error_Msg_Warn := Warn;
759 Error_Msg_N ("unrecognized attribute&<<", N);
761 -- Check for possible misspelling
763 Error_Msg_Name_1 := First_Attribute_Name;
764 while Error_Msg_Name_1 <= Last_Attribute_Name loop
765 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
766 Error_Msg_N -- CODEFIX
767 ("\possible misspelling of %<<", N);
768 exit;
769 end if;
771 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
772 end loop;
773 end Bad_Attribute;
775 --------------------------------
776 -- Bad_Predicated_Subtype_Use --
777 --------------------------------
779 procedure Bad_Predicated_Subtype_Use
780 (Msg : String;
781 N : Node_Id;
782 Typ : Entity_Id;
783 Suggest_Static : Boolean := False)
785 Gen : Entity_Id;
787 begin
788 -- Avoid cascaded errors
790 if Error_Posted (N) then
791 return;
792 end if;
794 if Inside_A_Generic then
795 Gen := Current_Scope;
796 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
797 Gen := Scope (Gen);
798 end loop;
800 if No (Gen) then
801 return;
802 end if;
804 if Is_Generic_Formal (Typ)
805 and then Is_Discrete_Type (Typ)
806 then
807 Set_No_Predicate_On_Actual (Typ);
808 end if;
810 elsif Has_Predicates (Typ) then
811 if Is_Generic_Actual_Type (Typ) then
813 -- The restriction on loop parameters is only that the type
814 -- should have no dynamic predicates.
816 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
817 and then not Has_Dynamic_Predicate_Aspect (Typ)
818 and then Is_OK_Static_Subtype (Typ)
819 then
820 return;
821 end if;
823 Gen := Current_Scope;
824 while not Is_Generic_Instance (Gen) loop
825 Gen := Scope (Gen);
826 end loop;
828 pragma Assert (Present (Gen));
830 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
831 Error_Msg_Warn := SPARK_Mode /= On;
832 Error_Msg_FE (Msg & "<<", N, Typ);
833 Error_Msg_F ("\Program_Error [<<", N);
835 Insert_Action (N,
836 Make_Raise_Program_Error (Sloc (N),
837 Reason => PE_Bad_Predicated_Generic_Type));
839 else
840 Error_Msg_FE (Msg & "<<", N, Typ);
841 end if;
843 else
844 Error_Msg_FE (Msg, N, Typ);
845 end if;
847 -- Emit an optional suggestion on how to remedy the error if the
848 -- context warrants it.
850 if Suggest_Static and then Has_Static_Predicate (Typ) then
851 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
852 end if;
853 end if;
854 end Bad_Predicated_Subtype_Use;
856 -----------------------------------------
857 -- Bad_Unordered_Enumeration_Reference --
858 -----------------------------------------
860 function Bad_Unordered_Enumeration_Reference
861 (N : Node_Id;
862 T : Entity_Id) return Boolean
864 begin
865 return Is_Enumeration_Type (T)
866 and then Comes_From_Source (N)
867 and then Warn_On_Unordered_Enumeration_Type
868 and then not Has_Pragma_Ordered (T)
869 and then not In_Same_Extended_Unit (N, T);
870 end Bad_Unordered_Enumeration_Reference;
872 --------------------------
873 -- Build_Actual_Subtype --
874 --------------------------
876 function Build_Actual_Subtype
877 (T : Entity_Id;
878 N : Node_Or_Entity_Id) return Node_Id
880 Loc : Source_Ptr;
881 -- Normally Sloc (N), but may point to corresponding body in some cases
883 Constraints : List_Id;
884 Decl : Node_Id;
885 Discr : Entity_Id;
886 Hi : Node_Id;
887 Lo : Node_Id;
888 Subt : Entity_Id;
889 Disc_Type : Entity_Id;
890 Obj : Node_Id;
892 begin
893 Loc := Sloc (N);
895 if Nkind (N) = N_Defining_Identifier then
896 Obj := New_Occurrence_Of (N, Loc);
898 -- If this is a formal parameter of a subprogram declaration, and
899 -- we are compiling the body, we want the declaration for the
900 -- actual subtype to carry the source position of the body, to
901 -- prevent anomalies in gdb when stepping through the code.
903 if Is_Formal (N) then
904 declare
905 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
906 begin
907 if Nkind (Decl) = N_Subprogram_Declaration
908 and then Present (Corresponding_Body (Decl))
909 then
910 Loc := Sloc (Corresponding_Body (Decl));
911 end if;
912 end;
913 end if;
915 else
916 Obj := N;
917 end if;
919 if Is_Array_Type (T) then
920 Constraints := New_List;
921 for J in 1 .. Number_Dimensions (T) loop
923 -- Build an array subtype declaration with the nominal subtype and
924 -- the bounds of the actual. Add the declaration in front of the
925 -- local declarations for the subprogram, for analysis before any
926 -- reference to the formal in the body.
928 Lo :=
929 Make_Attribute_Reference (Loc,
930 Prefix =>
931 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
932 Attribute_Name => Name_First,
933 Expressions => New_List (
934 Make_Integer_Literal (Loc, J)));
936 Hi :=
937 Make_Attribute_Reference (Loc,
938 Prefix =>
939 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
940 Attribute_Name => Name_Last,
941 Expressions => New_List (
942 Make_Integer_Literal (Loc, J)));
944 Append (Make_Range (Loc, Lo, Hi), Constraints);
945 end loop;
947 -- If the type has unknown discriminants there is no constrained
948 -- subtype to build. This is never called for a formal or for a
949 -- lhs, so returning the type is ok ???
951 elsif Has_Unknown_Discriminants (T) then
952 return T;
954 else
955 Constraints := New_List;
957 -- Type T is a generic derived type, inherit the discriminants from
958 -- the parent type.
960 if Is_Private_Type (T)
961 and then No (Full_View (T))
963 -- T was flagged as an error if it was declared as a formal
964 -- derived type with known discriminants. In this case there
965 -- is no need to look at the parent type since T already carries
966 -- its own discriminants.
968 and then not Error_Posted (T)
969 then
970 Disc_Type := Etype (Base_Type (T));
971 else
972 Disc_Type := T;
973 end if;
975 Discr := First_Discriminant (Disc_Type);
976 while Present (Discr) loop
977 Append_To (Constraints,
978 Make_Selected_Component (Loc,
979 Prefix =>
980 Duplicate_Subexpr_No_Checks (Obj),
981 Selector_Name => New_Occurrence_Of (Discr, Loc)));
982 Next_Discriminant (Discr);
983 end loop;
984 end if;
986 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
987 Set_Is_Internal (Subt);
989 Decl :=
990 Make_Subtype_Declaration (Loc,
991 Defining_Identifier => Subt,
992 Subtype_Indication =>
993 Make_Subtype_Indication (Loc,
994 Subtype_Mark => New_Occurrence_Of (T, Loc),
995 Constraint =>
996 Make_Index_Or_Discriminant_Constraint (Loc,
997 Constraints => Constraints)));
999 Mark_Rewrite_Insertion (Decl);
1000 return Decl;
1001 end Build_Actual_Subtype;
1003 ---------------------------------------
1004 -- Build_Actual_Subtype_Of_Component --
1005 ---------------------------------------
1007 function Build_Actual_Subtype_Of_Component
1008 (T : Entity_Id;
1009 N : Node_Id) return Node_Id
1011 Loc : constant Source_Ptr := Sloc (N);
1012 P : constant Node_Id := Prefix (N);
1013 D : Elmt_Id;
1014 Id : Node_Id;
1015 Index_Typ : Entity_Id;
1017 Desig_Typ : Entity_Id;
1018 -- This is either a copy of T, or if T is an access type, then it is
1019 -- the directly designated type of this access type.
1021 function Build_Actual_Array_Constraint return List_Id;
1022 -- If one or more of the bounds of the component depends on
1023 -- discriminants, build actual constraint using the discriminants
1024 -- of the prefix.
1026 function Build_Actual_Record_Constraint return List_Id;
1027 -- Similar to previous one, for discriminated components constrained
1028 -- by the discriminant of the enclosing object.
1030 -----------------------------------
1031 -- Build_Actual_Array_Constraint --
1032 -----------------------------------
1034 function Build_Actual_Array_Constraint return List_Id is
1035 Constraints : constant List_Id := New_List;
1036 Indx : Node_Id;
1037 Hi : Node_Id;
1038 Lo : Node_Id;
1039 Old_Hi : Node_Id;
1040 Old_Lo : Node_Id;
1042 begin
1043 Indx := First_Index (Desig_Typ);
1044 while Present (Indx) loop
1045 Old_Lo := Type_Low_Bound (Etype (Indx));
1046 Old_Hi := Type_High_Bound (Etype (Indx));
1048 if Denotes_Discriminant (Old_Lo) then
1049 Lo :=
1050 Make_Selected_Component (Loc,
1051 Prefix => New_Copy_Tree (P),
1052 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1054 else
1055 Lo := New_Copy_Tree (Old_Lo);
1057 -- The new bound will be reanalyzed in the enclosing
1058 -- declaration. For literal bounds that come from a type
1059 -- declaration, the type of the context must be imposed, so
1060 -- insure that analysis will take place. For non-universal
1061 -- types this is not strictly necessary.
1063 Set_Analyzed (Lo, False);
1064 end if;
1066 if Denotes_Discriminant (Old_Hi) then
1067 Hi :=
1068 Make_Selected_Component (Loc,
1069 Prefix => New_Copy_Tree (P),
1070 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1072 else
1073 Hi := New_Copy_Tree (Old_Hi);
1074 Set_Analyzed (Hi, False);
1075 end if;
1077 Append (Make_Range (Loc, Lo, Hi), Constraints);
1078 Next_Index (Indx);
1079 end loop;
1081 return Constraints;
1082 end Build_Actual_Array_Constraint;
1084 ------------------------------------
1085 -- Build_Actual_Record_Constraint --
1086 ------------------------------------
1088 function Build_Actual_Record_Constraint return List_Id is
1089 Constraints : constant List_Id := New_List;
1090 D : Elmt_Id;
1091 D_Val : Node_Id;
1093 begin
1094 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1095 while Present (D) loop
1096 if Denotes_Discriminant (Node (D)) then
1097 D_Val := Make_Selected_Component (Loc,
1098 Prefix => New_Copy_Tree (P),
1099 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1101 else
1102 D_Val := New_Copy_Tree (Node (D));
1103 end if;
1105 Append (D_Val, Constraints);
1106 Next_Elmt (D);
1107 end loop;
1109 return Constraints;
1110 end Build_Actual_Record_Constraint;
1112 -- Start of processing for Build_Actual_Subtype_Of_Component
1114 begin
1115 -- Why the test for Spec_Expression mode here???
1117 if In_Spec_Expression then
1118 return Empty;
1120 -- More comments for the rest of this body would be good ???
1122 elsif Nkind (N) = N_Explicit_Dereference then
1123 if Is_Composite_Type (T)
1124 and then not Is_Constrained (T)
1125 and then not (Is_Class_Wide_Type (T)
1126 and then Is_Constrained (Root_Type (T)))
1127 and then not Has_Unknown_Discriminants (T)
1128 then
1129 -- If the type of the dereference is already constrained, it is an
1130 -- actual subtype.
1132 if Is_Array_Type (Etype (N))
1133 and then Is_Constrained (Etype (N))
1134 then
1135 return Empty;
1136 else
1137 Remove_Side_Effects (P);
1138 return Build_Actual_Subtype (T, N);
1139 end if;
1140 else
1141 return Empty;
1142 end if;
1143 end if;
1145 if Ekind (T) = E_Access_Subtype then
1146 Desig_Typ := Designated_Type (T);
1147 else
1148 Desig_Typ := T;
1149 end if;
1151 if Ekind (Desig_Typ) = E_Array_Subtype then
1152 Id := First_Index (Desig_Typ);
1153 while Present (Id) loop
1154 Index_Typ := Underlying_Type (Etype (Id));
1156 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1157 or else
1158 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1159 then
1160 Remove_Side_Effects (P);
1161 return
1162 Build_Component_Subtype
1163 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1164 end if;
1166 Next_Index (Id);
1167 end loop;
1169 elsif Is_Composite_Type (Desig_Typ)
1170 and then Has_Discriminants (Desig_Typ)
1171 and then not Has_Unknown_Discriminants (Desig_Typ)
1172 then
1173 if Is_Private_Type (Desig_Typ)
1174 and then No (Discriminant_Constraint (Desig_Typ))
1175 then
1176 Desig_Typ := Full_View (Desig_Typ);
1177 end if;
1179 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1180 while Present (D) loop
1181 if Denotes_Discriminant (Node (D)) then
1182 Remove_Side_Effects (P);
1183 return
1184 Build_Component_Subtype (
1185 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1186 end if;
1188 Next_Elmt (D);
1189 end loop;
1190 end if;
1192 -- If none of the above, the actual and nominal subtypes are the same
1194 return Empty;
1195 end Build_Actual_Subtype_Of_Component;
1197 -----------------------------
1198 -- Build_Component_Subtype --
1199 -----------------------------
1201 function Build_Component_Subtype
1202 (C : List_Id;
1203 Loc : Source_Ptr;
1204 T : Entity_Id) return Node_Id
1206 Subt : Entity_Id;
1207 Decl : Node_Id;
1209 begin
1210 -- Unchecked_Union components do not require component subtypes
1212 if Is_Unchecked_Union (T) then
1213 return Empty;
1214 end if;
1216 Subt := Make_Temporary (Loc, 'S');
1217 Set_Is_Internal (Subt);
1219 Decl :=
1220 Make_Subtype_Declaration (Loc,
1221 Defining_Identifier => Subt,
1222 Subtype_Indication =>
1223 Make_Subtype_Indication (Loc,
1224 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1225 Constraint =>
1226 Make_Index_Or_Discriminant_Constraint (Loc,
1227 Constraints => C)));
1229 Mark_Rewrite_Insertion (Decl);
1230 return Decl;
1231 end Build_Component_Subtype;
1233 ----------------------------------
1234 -- Build_Default_Init_Cond_Call --
1235 ----------------------------------
1237 function Build_Default_Init_Cond_Call
1238 (Loc : Source_Ptr;
1239 Obj_Id : Entity_Id;
1240 Typ : Entity_Id) return Node_Id
1242 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1243 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1245 begin
1246 return
1247 Make_Procedure_Call_Statement (Loc,
1248 Name => New_Occurrence_Of (Proc_Id, Loc),
1249 Parameter_Associations => New_List (
1250 Make_Type_Conversion (Loc,
1251 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1252 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1253 end Build_Default_Init_Cond_Call;
1255 ----------------------------------------------
1256 -- Build_Default_Init_Cond_Procedure_Bodies --
1257 ----------------------------------------------
1259 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1260 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1261 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1262 -- body of the procedure which verifies the assumption of the pragma at
1263 -- run time. The generated body is added after the type declaration.
1265 --------------------------------------------
1266 -- Build_Default_Init_Cond_Procedure_Body --
1267 --------------------------------------------
1269 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1270 Param_Id : Entity_Id;
1271 -- The entity of the sole formal parameter of the default initial
1272 -- condition procedure.
1274 procedure Replace_Type_Reference (N : Node_Id);
1275 -- Replace a single reference to type Typ with a reference to formal
1276 -- parameter Param_Id.
1278 ----------------------------
1279 -- Replace_Type_Reference --
1280 ----------------------------
1282 procedure Replace_Type_Reference (N : Node_Id) is
1283 begin
1284 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1285 end Replace_Type_Reference;
1287 procedure Replace_Type_References is
1288 new Replace_Type_References_Generic (Replace_Type_Reference);
1290 -- Local variables
1292 Loc : constant Source_Ptr := Sloc (Typ);
1293 Prag : constant Node_Id :=
1294 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1295 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1296 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1297 Body_Decl : Node_Id;
1298 Expr : Node_Id;
1299 Stmt : Node_Id;
1301 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1303 begin
1304 -- The procedure should be generated only for [sub]types subject to
1305 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1306 -- not get this specialized procedure.
1308 pragma Assert (Has_Default_Init_Cond (Typ));
1309 pragma Assert (Present (Prag));
1310 pragma Assert (Present (Proc_Id));
1312 -- Nothing to do if the body was already built
1314 if Present (Corresponding_Body (Spec_Decl)) then
1315 return;
1316 end if;
1318 Param_Id := First_Formal (Proc_Id);
1320 -- The pragma has an argument. Note that the argument is analyzed
1321 -- after all references to the current instance of the type are
1322 -- replaced.
1324 if Present (Pragma_Argument_Associations (Prag)) then
1325 Expr :=
1326 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1328 if Nkind (Expr) = N_Null then
1329 Stmt := Make_Null_Statement (Loc);
1331 -- Preserve the original argument of the pragma by replicating it.
1332 -- Replace all references to the current instance of the type with
1333 -- references to the formal parameter.
1335 else
1336 Expr := New_Copy_Tree (Expr);
1337 Replace_Type_References (Expr, Typ);
1339 -- Generate:
1340 -- pragma Check (Default_Initial_Condition, <Expr>);
1342 Stmt :=
1343 Make_Pragma (Loc,
1344 Pragma_Identifier =>
1345 Make_Identifier (Loc, Name_Check),
1347 Pragma_Argument_Associations => New_List (
1348 Make_Pragma_Argument_Association (Loc,
1349 Expression =>
1350 Make_Identifier (Loc,
1351 Chars => Name_Default_Initial_Condition)),
1352 Make_Pragma_Argument_Association (Loc,
1353 Expression => Expr)));
1354 end if;
1356 -- Otherwise the pragma appears without an argument
1358 else
1359 Stmt := Make_Null_Statement (Loc);
1360 end if;
1362 -- Generate:
1363 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1364 -- begin
1365 -- <Stmt>;
1366 -- end <Typ>Default_Init_Cond;
1368 Body_Decl :=
1369 Make_Subprogram_Body (Loc,
1370 Specification =>
1371 Copy_Separate_Tree (Specification (Spec_Decl)),
1372 Declarations => Empty_List,
1373 Handled_Statement_Sequence =>
1374 Make_Handled_Sequence_Of_Statements (Loc,
1375 Statements => New_List (Stmt)));
1377 -- Link the spec and body of the default initial condition procedure
1378 -- to prevent the generation of a duplicate body.
1380 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1381 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1383 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1384 end Build_Default_Init_Cond_Procedure_Body;
1386 -- Local variables
1388 Decl : Node_Id;
1389 Typ : Entity_Id;
1391 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1393 begin
1394 -- Inspect the private declarations looking for [sub]type declarations
1396 Decl := First (Priv_Decls);
1397 while Present (Decl) loop
1398 if Nkind_In (Decl, N_Full_Type_Declaration,
1399 N_Subtype_Declaration)
1400 then
1401 Typ := Defining_Entity (Decl);
1403 -- Guard against partially decorate types due to previous errors
1405 if Is_Type (Typ) then
1407 -- If the type is subject to pragma Default_Initial_Condition,
1408 -- generate the body of the internal procedure which verifies
1409 -- the assertion of the pragma at run time.
1411 if Has_Default_Init_Cond (Typ) then
1412 Build_Default_Init_Cond_Procedure_Body (Typ);
1414 -- A derived type inherits the default initial condition
1415 -- procedure from its parent type.
1417 elsif Has_Inherited_Default_Init_Cond (Typ) then
1418 Inherit_Default_Init_Cond_Procedure (Typ);
1419 end if;
1420 end if;
1421 end if;
1423 Next (Decl);
1424 end loop;
1425 end Build_Default_Init_Cond_Procedure_Bodies;
1427 ---------------------------------------------------
1428 -- Build_Default_Init_Cond_Procedure_Declaration --
1429 ---------------------------------------------------
1431 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1432 Loc : constant Source_Ptr := Sloc (Typ);
1433 Prag : constant Node_Id :=
1434 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1435 Proc_Id : Entity_Id;
1437 begin
1438 -- The procedure should be generated only for types subject to pragma
1439 -- Default_Initial_Condition. Types that inherit the pragma do not get
1440 -- this specialized procedure.
1442 pragma Assert (Has_Default_Init_Cond (Typ));
1443 pragma Assert (Present (Prag));
1445 Proc_Id :=
1446 Make_Defining_Identifier (Loc,
1447 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1449 -- Associate default initial condition procedure with the private type
1451 Set_Ekind (Proc_Id, E_Procedure);
1452 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1453 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1455 -- Generate:
1456 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1458 Insert_After_And_Analyze (Prag,
1459 Make_Subprogram_Declaration (Loc,
1460 Specification =>
1461 Make_Procedure_Specification (Loc,
1462 Defining_Unit_Name => Proc_Id,
1463 Parameter_Specifications => New_List (
1464 Make_Parameter_Specification (Loc,
1465 Defining_Identifier => Make_Temporary (Loc, 'I'),
1466 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1467 end Build_Default_Init_Cond_Procedure_Declaration;
1469 ---------------------------
1470 -- Build_Default_Subtype --
1471 ---------------------------
1473 function Build_Default_Subtype
1474 (T : Entity_Id;
1475 N : Node_Id) return Entity_Id
1477 Loc : constant Source_Ptr := Sloc (N);
1478 Disc : Entity_Id;
1480 Bas : Entity_Id;
1481 -- The base type that is to be constrained by the defaults
1483 begin
1484 if not Has_Discriminants (T) or else Is_Constrained (T) then
1485 return T;
1486 end if;
1488 Bas := Base_Type (T);
1490 -- If T is non-private but its base type is private, this is the
1491 -- completion of a subtype declaration whose parent type is private
1492 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1493 -- are to be found in the full view of the base. Check that the private
1494 -- status of T and its base differ.
1496 if Is_Private_Type (Bas)
1497 and then not Is_Private_Type (T)
1498 and then Present (Full_View (Bas))
1499 then
1500 Bas := Full_View (Bas);
1501 end if;
1503 Disc := First_Discriminant (T);
1505 if No (Discriminant_Default_Value (Disc)) then
1506 return T;
1507 end if;
1509 declare
1510 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1511 Constraints : constant List_Id := New_List;
1512 Decl : Node_Id;
1514 begin
1515 while Present (Disc) loop
1516 Append_To (Constraints,
1517 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1518 Next_Discriminant (Disc);
1519 end loop;
1521 Decl :=
1522 Make_Subtype_Declaration (Loc,
1523 Defining_Identifier => Act,
1524 Subtype_Indication =>
1525 Make_Subtype_Indication (Loc,
1526 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1527 Constraint =>
1528 Make_Index_Or_Discriminant_Constraint (Loc,
1529 Constraints => Constraints)));
1531 Insert_Action (N, Decl);
1532 Analyze (Decl);
1533 return Act;
1534 end;
1535 end Build_Default_Subtype;
1537 --------------------------------------------
1538 -- Build_Discriminal_Subtype_Of_Component --
1539 --------------------------------------------
1541 function Build_Discriminal_Subtype_Of_Component
1542 (T : Entity_Id) return Node_Id
1544 Loc : constant Source_Ptr := Sloc (T);
1545 D : Elmt_Id;
1546 Id : Node_Id;
1548 function Build_Discriminal_Array_Constraint return List_Id;
1549 -- If one or more of the bounds of the component depends on
1550 -- discriminants, build actual constraint using the discriminants
1551 -- of the prefix.
1553 function Build_Discriminal_Record_Constraint return List_Id;
1554 -- Similar to previous one, for discriminated components constrained by
1555 -- the discriminant of the enclosing object.
1557 ----------------------------------------
1558 -- Build_Discriminal_Array_Constraint --
1559 ----------------------------------------
1561 function Build_Discriminal_Array_Constraint return List_Id is
1562 Constraints : constant List_Id := New_List;
1563 Indx : Node_Id;
1564 Hi : Node_Id;
1565 Lo : Node_Id;
1566 Old_Hi : Node_Id;
1567 Old_Lo : Node_Id;
1569 begin
1570 Indx := First_Index (T);
1571 while Present (Indx) loop
1572 Old_Lo := Type_Low_Bound (Etype (Indx));
1573 Old_Hi := Type_High_Bound (Etype (Indx));
1575 if Denotes_Discriminant (Old_Lo) then
1576 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1578 else
1579 Lo := New_Copy_Tree (Old_Lo);
1580 end if;
1582 if Denotes_Discriminant (Old_Hi) then
1583 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1585 else
1586 Hi := New_Copy_Tree (Old_Hi);
1587 end if;
1589 Append (Make_Range (Loc, Lo, Hi), Constraints);
1590 Next_Index (Indx);
1591 end loop;
1593 return Constraints;
1594 end Build_Discriminal_Array_Constraint;
1596 -----------------------------------------
1597 -- Build_Discriminal_Record_Constraint --
1598 -----------------------------------------
1600 function Build_Discriminal_Record_Constraint return List_Id is
1601 Constraints : constant List_Id := New_List;
1602 D : Elmt_Id;
1603 D_Val : Node_Id;
1605 begin
1606 D := First_Elmt (Discriminant_Constraint (T));
1607 while Present (D) loop
1608 if Denotes_Discriminant (Node (D)) then
1609 D_Val :=
1610 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1611 else
1612 D_Val := New_Copy_Tree (Node (D));
1613 end if;
1615 Append (D_Val, Constraints);
1616 Next_Elmt (D);
1617 end loop;
1619 return Constraints;
1620 end Build_Discriminal_Record_Constraint;
1622 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1624 begin
1625 if Ekind (T) = E_Array_Subtype then
1626 Id := First_Index (T);
1627 while Present (Id) loop
1628 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1629 or else
1630 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1631 then
1632 return Build_Component_Subtype
1633 (Build_Discriminal_Array_Constraint, Loc, T);
1634 end if;
1636 Next_Index (Id);
1637 end loop;
1639 elsif Ekind (T) = E_Record_Subtype
1640 and then Has_Discriminants (T)
1641 and then not Has_Unknown_Discriminants (T)
1642 then
1643 D := First_Elmt (Discriminant_Constraint (T));
1644 while Present (D) loop
1645 if Denotes_Discriminant (Node (D)) then
1646 return Build_Component_Subtype
1647 (Build_Discriminal_Record_Constraint, Loc, T);
1648 end if;
1650 Next_Elmt (D);
1651 end loop;
1652 end if;
1654 -- If none of the above, the actual and nominal subtypes are the same
1656 return Empty;
1657 end Build_Discriminal_Subtype_Of_Component;
1659 ------------------------------
1660 -- Build_Elaboration_Entity --
1661 ------------------------------
1663 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1664 Loc : constant Source_Ptr := Sloc (N);
1665 Decl : Node_Id;
1666 Elab_Ent : Entity_Id;
1668 procedure Set_Package_Name (Ent : Entity_Id);
1669 -- Given an entity, sets the fully qualified name of the entity in
1670 -- Name_Buffer, with components separated by double underscores. This
1671 -- is a recursive routine that climbs the scope chain to Standard.
1673 ----------------------
1674 -- Set_Package_Name --
1675 ----------------------
1677 procedure Set_Package_Name (Ent : Entity_Id) is
1678 begin
1679 if Scope (Ent) /= Standard_Standard then
1680 Set_Package_Name (Scope (Ent));
1682 declare
1683 Nam : constant String := Get_Name_String (Chars (Ent));
1684 begin
1685 Name_Buffer (Name_Len + 1) := '_';
1686 Name_Buffer (Name_Len + 2) := '_';
1687 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1688 Name_Len := Name_Len + Nam'Length + 2;
1689 end;
1691 else
1692 Get_Name_String (Chars (Ent));
1693 end if;
1694 end Set_Package_Name;
1696 -- Start of processing for Build_Elaboration_Entity
1698 begin
1699 -- Ignore call if already constructed
1701 if Present (Elaboration_Entity (Spec_Id)) then
1702 return;
1704 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1705 -- no role in analysis.
1707 elsif ASIS_Mode then
1708 return;
1710 -- See if we need elaboration entity. We always need it for the dynamic
1711 -- elaboration model, since it is needed to properly generate the PE
1712 -- exception for access before elaboration.
1714 elsif Dynamic_Elaboration_Checks then
1715 null;
1717 -- For the static model, we don't need the elaboration counter if this
1718 -- unit is sure to have no elaboration code, since that means there
1719 -- is no elaboration unit to be called. Note that we can't just decide
1720 -- after the fact by looking to see whether there was elaboration code,
1721 -- because that's too late to make this decision.
1723 elsif Restriction_Active (No_Elaboration_Code) then
1724 return;
1726 -- Similarly, for the static model, we can skip the elaboration counter
1727 -- if we have the No_Multiple_Elaboration restriction, since for the
1728 -- static model, that's the only purpose of the counter (to avoid
1729 -- multiple elaboration).
1731 elsif Restriction_Active (No_Multiple_Elaboration) then
1732 return;
1733 end if;
1735 -- Here we need the elaboration entity
1737 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1738 -- name with dots replaced by double underscore. We have to manually
1739 -- construct this name, since it will be elaborated in the outer scope,
1740 -- and thus will not have the unit name automatically prepended.
1742 Set_Package_Name (Spec_Id);
1743 Add_Str_To_Name_Buffer ("_E");
1745 -- Create elaboration counter
1747 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1748 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1750 Decl :=
1751 Make_Object_Declaration (Loc,
1752 Defining_Identifier => Elab_Ent,
1753 Object_Definition =>
1754 New_Occurrence_Of (Standard_Short_Integer, Loc),
1755 Expression => Make_Integer_Literal (Loc, Uint_0));
1757 Push_Scope (Standard_Standard);
1758 Add_Global_Declaration (Decl);
1759 Pop_Scope;
1761 -- Reset True_Constant indication, since we will indeed assign a value
1762 -- to the variable in the binder main. We also kill the Current_Value
1763 -- and Last_Assignment fields for the same reason.
1765 Set_Is_True_Constant (Elab_Ent, False);
1766 Set_Current_Value (Elab_Ent, Empty);
1767 Set_Last_Assignment (Elab_Ent, Empty);
1769 -- We do not want any further qualification of the name (if we did not
1770 -- do this, we would pick up the name of the generic package in the case
1771 -- of a library level generic instantiation).
1773 Set_Has_Qualified_Name (Elab_Ent);
1774 Set_Has_Fully_Qualified_Name (Elab_Ent);
1775 end Build_Elaboration_Entity;
1777 --------------------------------
1778 -- Build_Explicit_Dereference --
1779 --------------------------------
1781 procedure Build_Explicit_Dereference
1782 (Expr : Node_Id;
1783 Disc : Entity_Id)
1785 Loc : constant Source_Ptr := Sloc (Expr);
1787 begin
1788 -- An entity of a type with a reference aspect is overloaded with
1789 -- both interpretations: with and without the dereference. Now that
1790 -- the dereference is made explicit, set the type of the node properly,
1791 -- to prevent anomalies in the backend. Same if the expression is an
1792 -- overloaded function call whose return type has a reference aspect.
1794 if Is_Entity_Name (Expr) then
1795 Set_Etype (Expr, Etype (Entity (Expr)));
1797 elsif Nkind (Expr) = N_Function_Call then
1798 Set_Etype (Expr, Etype (Name (Expr)));
1799 end if;
1801 Set_Is_Overloaded (Expr, False);
1803 -- The expression will often be a generalized indexing that yields a
1804 -- container element that is then dereferenced, in which case the
1805 -- generalized indexing call is also non-overloaded.
1807 if Nkind (Expr) = N_Indexed_Component
1808 and then Present (Generalized_Indexing (Expr))
1809 then
1810 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1811 end if;
1813 Rewrite (Expr,
1814 Make_Explicit_Dereference (Loc,
1815 Prefix =>
1816 Make_Selected_Component (Loc,
1817 Prefix => Relocate_Node (Expr),
1818 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1819 Set_Etype (Prefix (Expr), Etype (Disc));
1820 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1821 end Build_Explicit_Dereference;
1823 -----------------------------------
1824 -- Cannot_Raise_Constraint_Error --
1825 -----------------------------------
1827 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1828 begin
1829 if Compile_Time_Known_Value (Expr) then
1830 return True;
1832 elsif Do_Range_Check (Expr) then
1833 return False;
1835 elsif Raises_Constraint_Error (Expr) then
1836 return False;
1838 else
1839 case Nkind (Expr) is
1840 when N_Identifier =>
1841 return True;
1843 when N_Expanded_Name =>
1844 return True;
1846 when N_Selected_Component =>
1847 return not Do_Discriminant_Check (Expr);
1849 when N_Attribute_Reference =>
1850 if Do_Overflow_Check (Expr) then
1851 return False;
1853 elsif No (Expressions (Expr)) then
1854 return True;
1856 else
1857 declare
1858 N : Node_Id;
1860 begin
1861 N := First (Expressions (Expr));
1862 while Present (N) loop
1863 if Cannot_Raise_Constraint_Error (N) then
1864 Next (N);
1865 else
1866 return False;
1867 end if;
1868 end loop;
1870 return True;
1871 end;
1872 end if;
1874 when N_Type_Conversion =>
1875 if Do_Overflow_Check (Expr)
1876 or else Do_Length_Check (Expr)
1877 or else Do_Tag_Check (Expr)
1878 then
1879 return False;
1880 else
1881 return Cannot_Raise_Constraint_Error (Expression (Expr));
1882 end if;
1884 when N_Unchecked_Type_Conversion =>
1885 return Cannot_Raise_Constraint_Error (Expression (Expr));
1887 when N_Unary_Op =>
1888 if Do_Overflow_Check (Expr) then
1889 return False;
1890 else
1891 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1892 end if;
1894 when N_Op_Divide |
1895 N_Op_Mod |
1896 N_Op_Rem
1898 if Do_Division_Check (Expr)
1899 or else
1900 Do_Overflow_Check (Expr)
1901 then
1902 return False;
1903 else
1904 return
1905 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1906 and then
1907 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1908 end if;
1910 when N_Op_Add |
1911 N_Op_And |
1912 N_Op_Concat |
1913 N_Op_Eq |
1914 N_Op_Expon |
1915 N_Op_Ge |
1916 N_Op_Gt |
1917 N_Op_Le |
1918 N_Op_Lt |
1919 N_Op_Multiply |
1920 N_Op_Ne |
1921 N_Op_Or |
1922 N_Op_Rotate_Left |
1923 N_Op_Rotate_Right |
1924 N_Op_Shift_Left |
1925 N_Op_Shift_Right |
1926 N_Op_Shift_Right_Arithmetic |
1927 N_Op_Subtract |
1928 N_Op_Xor
1930 if Do_Overflow_Check (Expr) then
1931 return False;
1932 else
1933 return
1934 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1935 and then
1936 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1937 end if;
1939 when others =>
1940 return False;
1941 end case;
1942 end if;
1943 end Cannot_Raise_Constraint_Error;
1945 -----------------------------------------
1946 -- Check_Dynamically_Tagged_Expression --
1947 -----------------------------------------
1949 procedure Check_Dynamically_Tagged_Expression
1950 (Expr : Node_Id;
1951 Typ : Entity_Id;
1952 Related_Nod : Node_Id)
1954 begin
1955 pragma Assert (Is_Tagged_Type (Typ));
1957 -- In order to avoid spurious errors when analyzing the expanded code,
1958 -- this check is done only for nodes that come from source and for
1959 -- actuals of generic instantiations.
1961 if (Comes_From_Source (Related_Nod)
1962 or else In_Generic_Actual (Expr))
1963 and then (Is_Class_Wide_Type (Etype (Expr))
1964 or else Is_Dynamically_Tagged (Expr))
1965 and then Is_Tagged_Type (Typ)
1966 and then not Is_Class_Wide_Type (Typ)
1967 then
1968 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1969 end if;
1970 end Check_Dynamically_Tagged_Expression;
1972 --------------------------
1973 -- Check_Fully_Declared --
1974 --------------------------
1976 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1977 begin
1978 if Ekind (T) = E_Incomplete_Type then
1980 -- Ada 2005 (AI-50217): If the type is available through a limited
1981 -- with_clause, verify that its full view has been analyzed.
1983 if From_Limited_With (T)
1984 and then Present (Non_Limited_View (T))
1985 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1986 then
1987 -- The non-limited view is fully declared
1988 null;
1990 else
1991 Error_Msg_NE
1992 ("premature usage of incomplete}", N, First_Subtype (T));
1993 end if;
1995 -- Need comments for these tests ???
1997 elsif Has_Private_Component (T)
1998 and then not Is_Generic_Type (Root_Type (T))
1999 and then not In_Spec_Expression
2000 then
2001 -- Special case: if T is the anonymous type created for a single
2002 -- task or protected object, use the name of the source object.
2004 if Is_Concurrent_Type (T)
2005 and then not Comes_From_Source (T)
2006 and then Nkind (N) = N_Object_Declaration
2007 then
2008 Error_Msg_NE
2009 ("type of& has incomplete component",
2010 N, Defining_Identifier (N));
2011 else
2012 Error_Msg_NE
2013 ("premature usage of incomplete}",
2014 N, First_Subtype (T));
2015 end if;
2016 end if;
2017 end Check_Fully_Declared;
2019 -------------------------------------
2020 -- Check_Function_Writable_Actuals --
2021 -------------------------------------
2023 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2024 Writable_Actuals_List : Elist_Id := No_Elist;
2025 Identifiers_List : Elist_Id := No_Elist;
2026 Error_Node : Node_Id := Empty;
2028 procedure Collect_Identifiers (N : Node_Id);
2029 -- In a single traversal of subtree N collect in Writable_Actuals_List
2030 -- all the actuals of functions with writable actuals, and in the list
2031 -- Identifiers_List collect all the identifiers that are not actuals of
2032 -- functions with writable actuals. If a writable actual is referenced
2033 -- twice as writable actual then Error_Node is set to reference its
2034 -- second occurrence, the error is reported, and the tree traversal
2035 -- is abandoned.
2037 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2038 -- Return the entity associated with the function call
2040 procedure Preanalyze_Without_Errors (N : Node_Id);
2041 -- Preanalyze N without reporting errors. Very dubious, you can't just
2042 -- go analyzing things more than once???
2044 -------------------------
2045 -- Collect_Identifiers --
2046 -------------------------
2048 procedure Collect_Identifiers (N : Node_Id) is
2050 function Check_Node (N : Node_Id) return Traverse_Result;
2051 -- Process a single node during the tree traversal to collect the
2052 -- writable actuals of functions and all the identifiers which are
2053 -- not writable actuals of functions.
2055 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2056 -- Returns True if List has a node whose Entity is Entity (N)
2058 -------------------------
2059 -- Check_Function_Call --
2060 -------------------------
2062 function Check_Node (N : Node_Id) return Traverse_Result is
2063 Is_Writable_Actual : Boolean := False;
2064 Id : Entity_Id;
2066 begin
2067 if Nkind (N) = N_Identifier then
2069 -- No analysis possible if the entity is not decorated
2071 if No (Entity (N)) then
2072 return Skip;
2074 -- Don't collect identifiers of packages, called functions, etc
2076 elsif Ekind_In (Entity (N), E_Package,
2077 E_Function,
2078 E_Procedure,
2079 E_Entry)
2080 then
2081 return Skip;
2083 -- Analyze if N is a writable actual of a function
2085 elsif Nkind (Parent (N)) = N_Function_Call then
2086 declare
2087 Call : constant Node_Id := Parent (N);
2088 Actual : Node_Id;
2089 Formal : Node_Id;
2091 begin
2092 Id := Get_Function_Id (Call);
2094 Formal := First_Formal (Id);
2095 Actual := First_Actual (Call);
2096 while Present (Actual) and then Present (Formal) loop
2097 if Actual = N then
2098 if Ekind_In (Formal, E_Out_Parameter,
2099 E_In_Out_Parameter)
2100 then
2101 Is_Writable_Actual := True;
2102 end if;
2104 exit;
2105 end if;
2107 Next_Formal (Formal);
2108 Next_Actual (Actual);
2109 end loop;
2110 end;
2111 end if;
2113 if Is_Writable_Actual then
2114 if Contains (Writable_Actuals_List, N) then
2115 Error_Msg_NE
2116 ("value may be affected by call to& "
2117 & "because order of evaluation is arbitrary", N, Id);
2118 Error_Node := N;
2119 return Abandon;
2120 end if;
2122 Append_New_Elmt (N, To => Writable_Actuals_List);
2124 else
2125 if Identifiers_List = No_Elist then
2126 Identifiers_List := New_Elmt_List;
2127 end if;
2129 Append_Unique_Elmt (N, Identifiers_List);
2130 end if;
2131 end if;
2133 return OK;
2134 end Check_Node;
2136 --------------
2137 -- Contains --
2138 --------------
2140 function Contains
2141 (List : Elist_Id;
2142 N : Node_Id) return Boolean
2144 pragma Assert (Nkind (N) in N_Has_Entity);
2146 Elmt : Elmt_Id;
2148 begin
2149 if List = No_Elist then
2150 return False;
2151 end if;
2153 Elmt := First_Elmt (List);
2154 while Present (Elmt) loop
2155 if Entity (Node (Elmt)) = Entity (N) then
2156 return True;
2157 else
2158 Next_Elmt (Elmt);
2159 end if;
2160 end loop;
2162 return False;
2163 end Contains;
2165 ------------------
2166 -- Do_Traversal --
2167 ------------------
2169 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2170 -- The traversal procedure
2172 -- Start of processing for Collect_Identifiers
2174 begin
2175 if Present (Error_Node) then
2176 return;
2177 end if;
2179 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2180 return;
2181 end if;
2183 Do_Traversal (N);
2184 end Collect_Identifiers;
2186 ---------------------
2187 -- Get_Function_Id --
2188 ---------------------
2190 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2191 Nam : constant Node_Id := Name (Call);
2192 Id : Entity_Id;
2194 begin
2195 if Nkind (Nam) = N_Explicit_Dereference then
2196 Id := Etype (Nam);
2197 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2199 elsif Nkind (Nam) = N_Selected_Component then
2200 Id := Entity (Selector_Name (Nam));
2202 elsif Nkind (Nam) = N_Indexed_Component then
2203 Id := Entity (Selector_Name (Prefix (Nam)));
2205 else
2206 Id := Entity (Nam);
2207 end if;
2209 return Id;
2210 end Get_Function_Id;
2212 ---------------------------
2213 -- Preanalyze_Expression --
2214 ---------------------------
2216 procedure Preanalyze_Without_Errors (N : Node_Id) is
2217 Status : constant Boolean := Get_Ignore_Errors;
2218 begin
2219 Set_Ignore_Errors (True);
2220 Preanalyze (N);
2221 Set_Ignore_Errors (Status);
2222 end Preanalyze_Without_Errors;
2224 -- Start of processing for Check_Function_Writable_Actuals
2226 begin
2227 -- The check only applies to Ada 2012 code, and only to constructs that
2228 -- have multiple constituents whose order of evaluation is not specified
2229 -- by the language.
2231 if Ada_Version < Ada_2012
2232 or else (not (Nkind (N) in N_Op)
2233 and then not (Nkind (N) in N_Membership_Test)
2234 and then not Nkind_In (N, N_Range,
2235 N_Aggregate,
2236 N_Extension_Aggregate,
2237 N_Full_Type_Declaration,
2238 N_Function_Call,
2239 N_Procedure_Call_Statement,
2240 N_Entry_Call_Statement))
2241 or else (Nkind (N) = N_Full_Type_Declaration
2242 and then not Is_Record_Type (Defining_Identifier (N)))
2244 -- In addition, this check only applies to source code, not to code
2245 -- generated by constraint checks.
2247 or else not Comes_From_Source (N)
2248 then
2249 return;
2250 end if;
2252 -- If a construct C has two or more direct constituents that are names
2253 -- or expressions whose evaluation may occur in an arbitrary order, at
2254 -- least one of which contains a function call with an in out or out
2255 -- parameter, then the construct is legal only if: for each name N that
2256 -- is passed as a parameter of mode in out or out to some inner function
2257 -- call C2 (not including the construct C itself), there is no other
2258 -- name anywhere within a direct constituent of the construct C other
2259 -- than the one containing C2, that is known to refer to the same
2260 -- object (RM 6.4.1(6.17/3)).
2262 case Nkind (N) is
2263 when N_Range =>
2264 Collect_Identifiers (Low_Bound (N));
2265 Collect_Identifiers (High_Bound (N));
2267 when N_Op | N_Membership_Test =>
2268 declare
2269 Expr : Node_Id;
2271 begin
2272 Collect_Identifiers (Left_Opnd (N));
2274 if Present (Right_Opnd (N)) then
2275 Collect_Identifiers (Right_Opnd (N));
2276 end if;
2278 if Nkind_In (N, N_In, N_Not_In)
2279 and then Present (Alternatives (N))
2280 then
2281 Expr := First (Alternatives (N));
2282 while Present (Expr) loop
2283 Collect_Identifiers (Expr);
2285 Next (Expr);
2286 end loop;
2287 end if;
2288 end;
2290 when N_Full_Type_Declaration =>
2291 declare
2292 function Get_Record_Part (N : Node_Id) return Node_Id;
2293 -- Return the record part of this record type definition
2295 function Get_Record_Part (N : Node_Id) return Node_Id is
2296 Type_Def : constant Node_Id := Type_Definition (N);
2297 begin
2298 if Nkind (Type_Def) = N_Derived_Type_Definition then
2299 return Record_Extension_Part (Type_Def);
2300 else
2301 return Type_Def;
2302 end if;
2303 end Get_Record_Part;
2305 Comp : Node_Id;
2306 Def_Id : Entity_Id := Defining_Identifier (N);
2307 Rec : Node_Id := Get_Record_Part (N);
2309 begin
2310 -- No need to perform any analysis if the record has no
2311 -- components
2313 if No (Rec) or else No (Component_List (Rec)) then
2314 return;
2315 end if;
2317 -- Collect the identifiers starting from the deepest
2318 -- derivation. Done to report the error in the deepest
2319 -- derivation.
2321 loop
2322 if Present (Component_List (Rec)) then
2323 Comp := First (Component_Items (Component_List (Rec)));
2324 while Present (Comp) loop
2325 if Nkind (Comp) = N_Component_Declaration
2326 and then Present (Expression (Comp))
2327 then
2328 Collect_Identifiers (Expression (Comp));
2329 end if;
2331 Next (Comp);
2332 end loop;
2333 end if;
2335 exit when No (Underlying_Type (Etype (Def_Id)))
2336 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2337 = Def_Id;
2339 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2340 Rec := Get_Record_Part (Parent (Def_Id));
2341 end loop;
2342 end;
2344 when N_Subprogram_Call |
2345 N_Entry_Call_Statement =>
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 =>
2368 declare
2369 Assoc : Node_Id;
2370 Choice : Node_Id;
2371 Comp_Expr : Node_Id;
2373 begin
2374 -- Handle the N_Others_Choice of array aggregates with static
2375 -- bounds. There is no need to perform this analysis in
2376 -- aggregates without static bounds since we cannot evaluate
2377 -- if the N_Others_Choice covers several elements. There is
2378 -- no need to handle the N_Others choice of record aggregates
2379 -- since at this stage it has been already expanded by
2380 -- Resolve_Record_Aggregate.
2382 if Is_Array_Type (Etype (N))
2383 and then Nkind (N) = N_Aggregate
2384 and then Present (Aggregate_Bounds (N))
2385 and then Compile_Time_Known_Bounds (Etype (N))
2386 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2388 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2389 then
2390 declare
2391 Count_Components : Uint := Uint_0;
2392 Num_Components : Uint;
2393 Others_Assoc : Node_Id;
2394 Others_Choice : Node_Id := Empty;
2395 Others_Box_Present : Boolean := False;
2397 begin
2398 -- Count positional associations
2400 if Present (Expressions (N)) then
2401 Comp_Expr := First (Expressions (N));
2402 while Present (Comp_Expr) loop
2403 Count_Components := Count_Components + 1;
2404 Next (Comp_Expr);
2405 end loop;
2406 end if;
2408 -- Count the rest of elements and locate the N_Others
2409 -- choice (if any)
2411 Assoc := First (Component_Associations (N));
2412 while Present (Assoc) loop
2413 Choice := First (Choices (Assoc));
2414 while Present (Choice) loop
2415 if Nkind (Choice) = N_Others_Choice then
2416 Others_Assoc := Assoc;
2417 Others_Choice := Choice;
2418 Others_Box_Present := Box_Present (Assoc);
2420 -- Count several components
2422 elsif Nkind_In (Choice, N_Range,
2423 N_Subtype_Indication)
2424 or else (Is_Entity_Name (Choice)
2425 and then Is_Type (Entity (Choice)))
2426 then
2427 declare
2428 L, H : Node_Id;
2429 begin
2430 Get_Index_Bounds (Choice, L, H);
2431 pragma Assert
2432 (Compile_Time_Known_Value (L)
2433 and then Compile_Time_Known_Value (H));
2434 Count_Components :=
2435 Count_Components
2436 + Expr_Value (H) - Expr_Value (L) + 1;
2437 end;
2439 -- Count single component. No other case available
2440 -- since we are handling an aggregate with static
2441 -- bounds.
2443 else
2444 pragma Assert (Is_OK_Static_Expression (Choice)
2445 or else Nkind (Choice) = N_Identifier
2446 or else Nkind (Choice) = N_Integer_Literal);
2448 Count_Components := Count_Components + 1;
2449 end if;
2451 Next (Choice);
2452 end loop;
2454 Next (Assoc);
2455 end loop;
2457 Num_Components :=
2458 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2459 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2461 pragma Assert (Count_Components <= Num_Components);
2463 -- Handle the N_Others choice if it covers several
2464 -- components
2466 if Present (Others_Choice)
2467 and then (Num_Components - Count_Components) > 1
2468 then
2469 if not Others_Box_Present then
2471 -- At this stage, if expansion is active, the
2472 -- expression of the others choice has not been
2473 -- analyzed. Hence we generate a duplicate and
2474 -- we analyze it silently to have available the
2475 -- minimum decoration required to collect the
2476 -- identifiers.
2478 if not Expander_Active then
2479 Comp_Expr := Expression (Others_Assoc);
2480 else
2481 Comp_Expr :=
2482 New_Copy_Tree (Expression (Others_Assoc));
2483 Preanalyze_Without_Errors (Comp_Expr);
2484 end if;
2486 Collect_Identifiers (Comp_Expr);
2488 if Writable_Actuals_List /= No_Elist then
2490 -- As suggested by Robert, at current stage we
2491 -- report occurrences of this case as warnings.
2493 Error_Msg_N
2494 ("writable function parameter may affect "
2495 & "value in other component because order "
2496 & "of evaluation is unspecified??",
2497 Node (First_Elmt (Writable_Actuals_List)));
2498 end if;
2499 end if;
2500 end if;
2501 end;
2502 end if;
2504 -- Handle ancestor part of extension aggregates
2506 if Nkind (N) = N_Extension_Aggregate then
2507 Collect_Identifiers (Ancestor_Part (N));
2508 end if;
2510 -- Handle positional associations
2512 if Present (Expressions (N)) then
2513 Comp_Expr := First (Expressions (N));
2514 while Present (Comp_Expr) loop
2515 if not Is_OK_Static_Expression (Comp_Expr) then
2516 Collect_Identifiers (Comp_Expr);
2517 end if;
2519 Next (Comp_Expr);
2520 end loop;
2521 end if;
2523 -- Handle discrete associations
2525 if Present (Component_Associations (N)) then
2526 Assoc := First (Component_Associations (N));
2527 while Present (Assoc) loop
2529 if not Box_Present (Assoc) then
2530 Choice := First (Choices (Assoc));
2531 while Present (Choice) loop
2533 -- For now we skip discriminants since it requires
2534 -- performing the analysis in two phases: first one
2535 -- analyzing discriminants and second one analyzing
2536 -- the rest of components since discriminants are
2537 -- evaluated prior to components: too much extra
2538 -- work to detect a corner case???
2540 if Nkind (Choice) in N_Has_Entity
2541 and then Present (Entity (Choice))
2542 and then Ekind (Entity (Choice)) = E_Discriminant
2543 then
2544 null;
2546 elsif Box_Present (Assoc) then
2547 null;
2549 else
2550 if not Analyzed (Expression (Assoc)) then
2551 Comp_Expr :=
2552 New_Copy_Tree (Expression (Assoc));
2553 Set_Parent (Comp_Expr, Parent (N));
2554 Preanalyze_Without_Errors (Comp_Expr);
2555 else
2556 Comp_Expr := Expression (Assoc);
2557 end if;
2559 Collect_Identifiers (Comp_Expr);
2560 end if;
2562 Next (Choice);
2563 end loop;
2564 end if;
2566 Next (Assoc);
2567 end loop;
2568 end if;
2569 end;
2571 when others =>
2572 return;
2573 end case;
2575 -- No further action needed if we already reported an error
2577 if Present (Error_Node) then
2578 return;
2579 end if;
2581 -- Check if some writable argument of a function is referenced
2583 if Writable_Actuals_List /= No_Elist
2584 and then Identifiers_List /= No_Elist
2585 then
2586 declare
2587 Elmt_1 : Elmt_Id;
2588 Elmt_2 : Elmt_Id;
2590 begin
2591 Elmt_1 := First_Elmt (Writable_Actuals_List);
2592 while Present (Elmt_1) loop
2593 Elmt_2 := First_Elmt (Identifiers_List);
2594 while Present (Elmt_2) loop
2595 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2596 case Nkind (Parent (Node (Elmt_2))) is
2597 when N_Aggregate |
2598 N_Component_Association |
2599 N_Component_Declaration =>
2600 Error_Msg_N
2601 ("value may be affected by call in other "
2602 & "component because they are evaluated "
2603 & "in unspecified order",
2604 Node (Elmt_2));
2606 when N_In | N_Not_In =>
2607 Error_Msg_N
2608 ("value may be affected by call in other "
2609 & "alternative because they are evaluated "
2610 & "in unspecified order",
2611 Node (Elmt_2));
2613 when others =>
2614 Error_Msg_N
2615 ("value of actual may be affected by call in "
2616 & "other actual because they are evaluated "
2617 & "in unspecified order",
2618 Node (Elmt_2));
2619 end case;
2620 end if;
2622 Next_Elmt (Elmt_2);
2623 end loop;
2625 Next_Elmt (Elmt_1);
2626 end loop;
2627 end;
2628 end if;
2629 end Check_Function_Writable_Actuals;
2631 --------------------------------
2632 -- Check_Implicit_Dereference --
2633 --------------------------------
2635 procedure Check_Implicit_Dereference (Nam : Node_Id; Typ : Entity_Id) is
2636 Disc : Entity_Id;
2637 Desig : Entity_Id;
2639 begin
2640 if Ada_Version < Ada_2012
2641 or else not Has_Implicit_Dereference (Base_Type (Typ))
2642 then
2643 return;
2645 elsif not Comes_From_Source (Nam) then
2646 return;
2648 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2649 null;
2651 else
2652 Disc := First_Discriminant (Typ);
2653 while Present (Disc) loop
2654 if Has_Implicit_Dereference (Disc) then
2655 Desig := Designated_Type (Etype (Disc));
2656 Add_One_Interp (Nam, Disc, Desig);
2657 exit;
2658 end if;
2660 Next_Discriminant (Disc);
2661 end loop;
2662 end if;
2663 end Check_Implicit_Dereference;
2665 ----------------------------------
2666 -- Check_Internal_Protected_Use --
2667 ----------------------------------
2669 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2670 S : Entity_Id;
2671 Prot : Entity_Id;
2673 begin
2674 S := Current_Scope;
2675 while Present (S) loop
2676 if S = Standard_Standard then
2677 return;
2679 elsif Ekind (S) = E_Function
2680 and then Ekind (Scope (S)) = E_Protected_Type
2681 then
2682 Prot := Scope (S);
2683 exit;
2684 end if;
2686 S := Scope (S);
2687 end loop;
2689 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2691 -- An indirect function call (e.g. a callback within a protected
2692 -- function body) is not statically illegal. If the access type is
2693 -- anonymous and is the type of an access parameter, the scope of Nam
2694 -- will be the protected type, but it is not a protected operation.
2696 if Ekind (Nam) = E_Subprogram_Type
2697 and then
2698 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2699 then
2700 null;
2702 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2703 Error_Msg_N
2704 ("within protected function cannot use protected "
2705 & "procedure in renaming or as generic actual", N);
2707 elsif Nkind (N) = N_Attribute_Reference then
2708 Error_Msg_N
2709 ("within protected function cannot take access of "
2710 & " protected procedure", N);
2712 else
2713 Error_Msg_N
2714 ("within protected function, protected object is constant", N);
2715 Error_Msg_N
2716 ("\cannot call operation that may modify it", N);
2717 end if;
2718 end if;
2719 end Check_Internal_Protected_Use;
2721 ---------------------------------------
2722 -- Check_Later_Vs_Basic_Declarations --
2723 ---------------------------------------
2725 procedure Check_Later_Vs_Basic_Declarations
2726 (Decls : List_Id;
2727 During_Parsing : Boolean)
2729 Body_Sloc : Source_Ptr;
2730 Decl : Node_Id;
2732 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2733 -- Return whether Decl is considered as a declarative item.
2734 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2735 -- When During_Parsing is False, the semantics of SPARK is followed.
2737 -------------------------------
2738 -- Is_Later_Declarative_Item --
2739 -------------------------------
2741 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2742 begin
2743 if Nkind (Decl) in N_Later_Decl_Item then
2744 return True;
2746 elsif Nkind (Decl) = N_Pragma then
2747 return True;
2749 elsif During_Parsing then
2750 return False;
2752 -- In SPARK, a package declaration is not considered as a later
2753 -- declarative item.
2755 elsif Nkind (Decl) = N_Package_Declaration then
2756 return False;
2758 -- In SPARK, a renaming is considered as a later declarative item
2760 elsif Nkind (Decl) in N_Renaming_Declaration then
2761 return True;
2763 else
2764 return False;
2765 end if;
2766 end Is_Later_Declarative_Item;
2768 -- Start of Check_Later_Vs_Basic_Declarations
2770 begin
2771 Decl := First (Decls);
2773 -- Loop through sequence of basic declarative items
2775 Outer : while Present (Decl) loop
2776 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2777 and then Nkind (Decl) not in N_Body_Stub
2778 then
2779 Next (Decl);
2781 -- Once a body is encountered, we only allow later declarative
2782 -- items. The inner loop checks the rest of the list.
2784 else
2785 Body_Sloc := Sloc (Decl);
2787 Inner : while Present (Decl) loop
2788 if not Is_Later_Declarative_Item (Decl) then
2789 if During_Parsing then
2790 if Ada_Version = Ada_83 then
2791 Error_Msg_Sloc := Body_Sloc;
2792 Error_Msg_N
2793 ("(Ada 83) decl cannot appear after body#", Decl);
2794 end if;
2795 else
2796 Error_Msg_Sloc := Body_Sloc;
2797 Check_SPARK_05_Restriction
2798 ("decl cannot appear after body#", Decl);
2799 end if;
2800 end if;
2802 Next (Decl);
2803 end loop Inner;
2804 end if;
2805 end loop Outer;
2806 end Check_Later_Vs_Basic_Declarations;
2808 -------------------------
2809 -- Check_Nested_Access --
2810 -------------------------
2812 procedure Check_Nested_Access (Ent : Entity_Id) is
2813 Scop : constant Entity_Id := Current_Scope;
2814 Current_Subp : Entity_Id;
2815 Enclosing : Entity_Id;
2817 begin
2818 -- Currently only enabled for VM back-ends for efficiency, should we
2819 -- enable it more systematically ???
2821 -- Check for Is_Imported needs commenting below ???
2823 if VM_Target /= No_VM
2824 and then Ekind_In (Ent, E_Variable, E_Constant, E_Loop_Parameter)
2825 and then Scope (Ent) /= Empty
2826 and then not Is_Library_Level_Entity (Ent)
2827 and then not Is_Imported (Ent)
2828 then
2829 if Is_Subprogram (Scop)
2830 or else Is_Generic_Subprogram (Scop)
2831 or else Is_Entry (Scop)
2832 then
2833 Current_Subp := Scop;
2834 else
2835 Current_Subp := Current_Subprogram;
2836 end if;
2838 Enclosing := Enclosing_Subprogram (Ent);
2840 if Enclosing /= Empty and then Enclosing /= Current_Subp then
2841 Set_Has_Up_Level_Access (Ent, True);
2842 end if;
2843 end if;
2844 end Check_Nested_Access;
2846 ---------------------------
2847 -- Check_No_Hidden_State --
2848 ---------------------------
2850 procedure Check_No_Hidden_State (Id : Entity_Id) is
2851 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2852 -- Determine whether the entity of a package denoted by Pkg has a null
2853 -- abstract state.
2855 -----------------------------
2856 -- Has_Null_Abstract_State --
2857 -----------------------------
2859 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2860 States : constant Elist_Id := Abstract_States (Pkg);
2862 begin
2863 -- Check first available state of related package. A null abstract
2864 -- state always appears as the sole element of the state list.
2866 return
2867 Present (States)
2868 and then Is_Null_State (Node (First_Elmt (States)));
2869 end Has_Null_Abstract_State;
2871 -- Local variables
2873 Context : Entity_Id := Empty;
2874 Not_Visible : Boolean := False;
2875 Scop : Entity_Id;
2877 -- Start of processing for Check_No_Hidden_State
2879 begin
2880 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2882 -- Find the proper context where the object or state appears
2884 Scop := Scope (Id);
2885 while Present (Scop) loop
2886 Context := Scop;
2888 -- Keep track of the context's visibility
2890 Not_Visible := Not_Visible or else In_Private_Part (Context);
2892 -- Prevent the search from going too far
2894 if Context = Standard_Standard then
2895 return;
2897 -- Objects and states that appear immediately within a subprogram or
2898 -- inside a construct nested within a subprogram do not introduce a
2899 -- hidden state. They behave as local variable declarations.
2901 elsif Is_Subprogram (Context) then
2902 return;
2904 -- When examining a package body, use the entity of the spec as it
2905 -- carries the abstract state declarations.
2907 elsif Ekind (Context) = E_Package_Body then
2908 Context := Spec_Entity (Context);
2909 end if;
2911 -- Stop the traversal when a package subject to a null abstract state
2912 -- has been found.
2914 if Ekind_In (Context, E_Generic_Package, E_Package)
2915 and then Has_Null_Abstract_State (Context)
2916 then
2917 exit;
2918 end if;
2920 Scop := Scope (Scop);
2921 end loop;
2923 -- At this point we know that there is at least one package with a null
2924 -- abstract state in visibility. Emit an error message unconditionally
2925 -- if the entity being processed is a state because the placement of the
2926 -- related package is irrelevant. This is not the case for objects as
2927 -- the intermediate context matters.
2929 if Present (Context)
2930 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
2931 then
2932 Error_Msg_N ("cannot introduce hidden state &", Id);
2933 Error_Msg_NE ("\package & has null abstract state", Id, Context);
2934 end if;
2935 end Check_No_Hidden_State;
2937 ------------------------------------------
2938 -- Check_Potentially_Blocking_Operation --
2939 ------------------------------------------
2941 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
2942 S : Entity_Id;
2944 begin
2945 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2946 -- When pragma Detect_Blocking is active, the run time will raise
2947 -- Program_Error. Here we only issue a warning, since we generally
2948 -- support the use of potentially blocking operations in the absence
2949 -- of the pragma.
2951 -- Indirect blocking through a subprogram call cannot be diagnosed
2952 -- statically without interprocedural analysis, so we do not attempt
2953 -- to do it here.
2955 S := Scope (Current_Scope);
2956 while Present (S) and then S /= Standard_Standard loop
2957 if Is_Protected_Type (S) then
2958 Error_Msg_N
2959 ("potentially blocking operation in protected operation??", N);
2960 return;
2961 end if;
2963 S := Scope (S);
2964 end loop;
2965 end Check_Potentially_Blocking_Operation;
2967 ---------------------------------
2968 -- Check_Result_And_Post_State --
2969 ---------------------------------
2971 procedure Check_Result_And_Post_State
2972 (Prag : Node_Id;
2973 Result_Seen : in out Boolean)
2975 procedure Check_Expression (Expr : Node_Id);
2976 -- Perform the 'Result and post-state checks on a given expression
2978 function Is_Function_Result (N : Node_Id) return Traverse_Result;
2979 -- Attempt to find attribute 'Result in a subtree denoted by N
2981 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
2982 -- Determine whether source node N denotes "True" or "False"
2984 function Mentions_Post_State (N : Node_Id) return Boolean;
2985 -- Determine whether a subtree denoted by N mentions any construct that
2986 -- denotes a post-state.
2988 procedure Check_Function_Result is
2989 new Traverse_Proc (Is_Function_Result);
2991 ----------------------
2992 -- Check_Expression --
2993 ----------------------
2995 procedure Check_Expression (Expr : Node_Id) is
2996 begin
2997 if not Is_Trivial_Boolean (Expr) then
2998 Check_Function_Result (Expr);
3000 if not Mentions_Post_State (Expr) then
3001 if Pragma_Name (Prag) = Name_Contract_Cases then
3002 Error_Msg_N
3003 ("contract case refers only to pre-state?T?", Expr);
3005 elsif Pragma_Name (Prag) = Name_Refined_Post then
3006 Error_Msg_N
3007 ("refined postcondition refers only to pre-state?T?",
3008 Prag);
3010 else
3011 Error_Msg_N
3012 ("postcondition refers only to pre-state?T?", Prag);
3013 end if;
3014 end if;
3015 end if;
3016 end Check_Expression;
3018 ------------------------
3019 -- Is_Function_Result --
3020 ------------------------
3022 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3023 begin
3024 if Is_Attribute_Result (N) then
3025 Result_Seen := True;
3026 return Abandon;
3028 -- Continue the traversal
3030 else
3031 return OK;
3032 end if;
3033 end Is_Function_Result;
3035 ------------------------
3036 -- Is_Trivial_Boolean --
3037 ------------------------
3039 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3040 begin
3041 return
3042 Comes_From_Source (N)
3043 and then Is_Entity_Name (N)
3044 and then (Entity (N) = Standard_True
3045 or else Entity (N) = Standard_False);
3046 end Is_Trivial_Boolean;
3048 -------------------------
3049 -- Mentions_Post_State --
3050 -------------------------
3052 function Mentions_Post_State (N : Node_Id) return Boolean is
3053 Post_State_Seen : Boolean := False;
3055 function Is_Post_State (N : Node_Id) return Traverse_Result;
3056 -- Attempt to find a construct that denotes a post-state. If this is
3057 -- the case, set flag Post_State_Seen.
3059 -------------------
3060 -- Is_Post_State --
3061 -------------------
3063 function Is_Post_State (N : Node_Id) return Traverse_Result is
3064 Ent : Entity_Id;
3066 begin
3067 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3068 Post_State_Seen := True;
3069 return Abandon;
3071 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3072 Ent := Entity (N);
3074 -- The entity may be modifiable through an implicit dereference
3076 if No (Ent)
3077 or else Ekind (Ent) in Assignable_Kind
3078 or else (Is_Access_Type (Etype (Ent))
3079 and then Nkind (Parent (N)) = N_Selected_Component)
3080 then
3081 Post_State_Seen := True;
3082 return Abandon;
3083 end if;
3085 elsif Nkind (N) = N_Attribute_Reference then
3086 if Attribute_Name (N) = Name_Old then
3087 return Skip;
3089 elsif Attribute_Name (N) = Name_Result then
3090 Post_State_Seen := True;
3091 return Abandon;
3092 end if;
3093 end if;
3095 return OK;
3096 end Is_Post_State;
3098 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3100 -- Start of processing for Mentions_Post_State
3102 begin
3103 Find_Post_State (N);
3105 return Post_State_Seen;
3106 end Mentions_Post_State;
3108 -- Local variables
3110 Expr : constant Node_Id :=
3111 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
3112 Nam : constant Name_Id := Pragma_Name (Prag);
3113 CCase : Node_Id;
3115 -- Start of processing for Check_Result_And_Post_State
3117 begin
3118 -- Examine all consequences
3120 if Nam = Name_Contract_Cases then
3121 CCase := First (Component_Associations (Expr));
3122 while Present (CCase) loop
3123 Check_Expression (Expression (CCase));
3125 Next (CCase);
3126 end loop;
3128 -- Examine the expression of a postcondition
3130 else pragma Assert (Nam_In (Nam, Name_Postcondition, Name_Refined_Post));
3131 Check_Expression (Expr);
3132 end if;
3133 end Check_Result_And_Post_State;
3135 ------------------------------
3136 -- Check_Unprotected_Access --
3137 ------------------------------
3139 procedure Check_Unprotected_Access
3140 (Context : Node_Id;
3141 Expr : Node_Id)
3143 Cont_Encl_Typ : Entity_Id;
3144 Pref_Encl_Typ : Entity_Id;
3146 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3147 -- Check whether Obj is a private component of a protected object.
3148 -- Return the protected type where the component resides, Empty
3149 -- otherwise.
3151 function Is_Public_Operation return Boolean;
3152 -- Verify that the enclosing operation is callable from outside the
3153 -- protected object, to minimize false positives.
3155 ------------------------------
3156 -- Enclosing_Protected_Type --
3157 ------------------------------
3159 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3160 begin
3161 if Is_Entity_Name (Obj) then
3162 declare
3163 Ent : Entity_Id := Entity (Obj);
3165 begin
3166 -- The object can be a renaming of a private component, use
3167 -- the original record component.
3169 if Is_Prival (Ent) then
3170 Ent := Prival_Link (Ent);
3171 end if;
3173 if Is_Protected_Type (Scope (Ent)) then
3174 return Scope (Ent);
3175 end if;
3176 end;
3177 end if;
3179 -- For indexed and selected components, recursively check the prefix
3181 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3182 return Enclosing_Protected_Type (Prefix (Obj));
3184 -- The object does not denote a protected component
3186 else
3187 return Empty;
3188 end if;
3189 end Enclosing_Protected_Type;
3191 -------------------------
3192 -- Is_Public_Operation --
3193 -------------------------
3195 function Is_Public_Operation return Boolean is
3196 S : Entity_Id;
3197 E : Entity_Id;
3199 begin
3200 S := Current_Scope;
3201 while Present (S) and then S /= Pref_Encl_Typ loop
3202 if Scope (S) = Pref_Encl_Typ then
3203 E := First_Entity (Pref_Encl_Typ);
3204 while Present (E)
3205 and then E /= First_Private_Entity (Pref_Encl_Typ)
3206 loop
3207 if E = S then
3208 return True;
3209 end if;
3211 Next_Entity (E);
3212 end loop;
3213 end if;
3215 S := Scope (S);
3216 end loop;
3218 return False;
3219 end Is_Public_Operation;
3221 -- Start of processing for Check_Unprotected_Access
3223 begin
3224 if Nkind (Expr) = N_Attribute_Reference
3225 and then Attribute_Name (Expr) = Name_Unchecked_Access
3226 then
3227 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3228 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3230 -- Check whether we are trying to export a protected component to a
3231 -- context with an equal or lower access level.
3233 if Present (Pref_Encl_Typ)
3234 and then No (Cont_Encl_Typ)
3235 and then Is_Public_Operation
3236 and then Scope_Depth (Pref_Encl_Typ) >=
3237 Object_Access_Level (Context)
3238 then
3239 Error_Msg_N
3240 ("??possible unprotected access to protected data", Expr);
3241 end if;
3242 end if;
3243 end Check_Unprotected_Access;
3245 ------------------------
3246 -- Collect_Interfaces --
3247 ------------------------
3249 procedure Collect_Interfaces
3250 (T : Entity_Id;
3251 Ifaces_List : out Elist_Id;
3252 Exclude_Parents : Boolean := False;
3253 Use_Full_View : Boolean := True)
3255 procedure Collect (Typ : Entity_Id);
3256 -- Subsidiary subprogram used to traverse the whole list
3257 -- of directly and indirectly implemented interfaces
3259 -------------
3260 -- Collect --
3261 -------------
3263 procedure Collect (Typ : Entity_Id) is
3264 Ancestor : Entity_Id;
3265 Full_T : Entity_Id;
3266 Id : Node_Id;
3267 Iface : Entity_Id;
3269 begin
3270 Full_T := Typ;
3272 -- Handle private types
3274 if Use_Full_View
3275 and then Is_Private_Type (Typ)
3276 and then Present (Full_View (Typ))
3277 then
3278 Full_T := Full_View (Typ);
3279 end if;
3281 -- Include the ancestor if we are generating the whole list of
3282 -- abstract interfaces.
3284 if Etype (Full_T) /= Typ
3286 -- Protect the frontend against wrong sources. For example:
3288 -- package P is
3289 -- type A is tagged null record;
3290 -- type B is new A with private;
3291 -- type C is new A with private;
3292 -- private
3293 -- type B is new C with null record;
3294 -- type C is new B with null record;
3295 -- end P;
3297 and then Etype (Full_T) /= T
3298 then
3299 Ancestor := Etype (Full_T);
3300 Collect (Ancestor);
3302 if Is_Interface (Ancestor) and then not Exclude_Parents then
3303 Append_Unique_Elmt (Ancestor, Ifaces_List);
3304 end if;
3305 end if;
3307 -- Traverse the graph of ancestor interfaces
3309 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3310 Id := First (Abstract_Interface_List (Full_T));
3311 while Present (Id) loop
3312 Iface := Etype (Id);
3314 -- Protect against wrong uses. For example:
3315 -- type I is interface;
3316 -- type O is tagged null record;
3317 -- type Wrong is new I and O with null record; -- ERROR
3319 if Is_Interface (Iface) then
3320 if Exclude_Parents
3321 and then Etype (T) /= T
3322 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3323 then
3324 null;
3325 else
3326 Collect (Iface);
3327 Append_Unique_Elmt (Iface, Ifaces_List);
3328 end if;
3329 end if;
3331 Next (Id);
3332 end loop;
3333 end if;
3334 end Collect;
3336 -- Start of processing for Collect_Interfaces
3338 begin
3339 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3340 Ifaces_List := New_Elmt_List;
3341 Collect (T);
3342 end Collect_Interfaces;
3344 ----------------------------------
3345 -- Collect_Interface_Components --
3346 ----------------------------------
3348 procedure Collect_Interface_Components
3349 (Tagged_Type : Entity_Id;
3350 Components_List : out Elist_Id)
3352 procedure Collect (Typ : Entity_Id);
3353 -- Subsidiary subprogram used to climb to the parents
3355 -------------
3356 -- Collect --
3357 -------------
3359 procedure Collect (Typ : Entity_Id) is
3360 Tag_Comp : Entity_Id;
3361 Parent_Typ : Entity_Id;
3363 begin
3364 -- Handle private types
3366 if Present (Full_View (Etype (Typ))) then
3367 Parent_Typ := Full_View (Etype (Typ));
3368 else
3369 Parent_Typ := Etype (Typ);
3370 end if;
3372 if Parent_Typ /= Typ
3374 -- Protect the frontend against wrong sources. For example:
3376 -- package P is
3377 -- type A is tagged null record;
3378 -- type B is new A with private;
3379 -- type C is new A with private;
3380 -- private
3381 -- type B is new C with null record;
3382 -- type C is new B with null record;
3383 -- end P;
3385 and then Parent_Typ /= Tagged_Type
3386 then
3387 Collect (Parent_Typ);
3388 end if;
3390 -- Collect the components containing tags of secondary dispatch
3391 -- tables.
3393 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3394 while Present (Tag_Comp) loop
3395 pragma Assert (Present (Related_Type (Tag_Comp)));
3396 Append_Elmt (Tag_Comp, Components_List);
3398 Tag_Comp := Next_Tag_Component (Tag_Comp);
3399 end loop;
3400 end Collect;
3402 -- Start of processing for Collect_Interface_Components
3404 begin
3405 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3406 and then Is_Tagged_Type (Tagged_Type));
3408 Components_List := New_Elmt_List;
3409 Collect (Tagged_Type);
3410 end Collect_Interface_Components;
3412 -----------------------------
3413 -- Collect_Interfaces_Info --
3414 -----------------------------
3416 procedure Collect_Interfaces_Info
3417 (T : Entity_Id;
3418 Ifaces_List : out Elist_Id;
3419 Components_List : out Elist_Id;
3420 Tags_List : out Elist_Id)
3422 Comps_List : Elist_Id;
3423 Comp_Elmt : Elmt_Id;
3424 Comp_Iface : Entity_Id;
3425 Iface_Elmt : Elmt_Id;
3426 Iface : Entity_Id;
3428 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3429 -- Search for the secondary tag associated with the interface type
3430 -- Iface that is implemented by T.
3432 ----------------
3433 -- Search_Tag --
3434 ----------------
3436 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3437 ADT : Elmt_Id;
3438 begin
3439 if not Is_CPP_Class (T) then
3440 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3441 else
3442 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3443 end if;
3445 while Present (ADT)
3446 and then Is_Tag (Node (ADT))
3447 and then Related_Type (Node (ADT)) /= Iface
3448 loop
3449 -- Skip secondary dispatch table referencing thunks to user
3450 -- defined primitives covered by this interface.
3452 pragma Assert (Has_Suffix (Node (ADT), 'P'));
3453 Next_Elmt (ADT);
3455 -- Skip secondary dispatch tables of Ada types
3457 if not Is_CPP_Class (T) then
3459 -- Skip secondary dispatch table referencing thunks to
3460 -- predefined primitives.
3462 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
3463 Next_Elmt (ADT);
3465 -- Skip secondary dispatch table referencing user-defined
3466 -- primitives covered by this interface.
3468 pragma Assert (Has_Suffix (Node (ADT), 'D'));
3469 Next_Elmt (ADT);
3471 -- Skip secondary dispatch table referencing predefined
3472 -- primitives.
3474 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
3475 Next_Elmt (ADT);
3476 end if;
3477 end loop;
3479 pragma Assert (Is_Tag (Node (ADT)));
3480 return Node (ADT);
3481 end Search_Tag;
3483 -- Start of processing for Collect_Interfaces_Info
3485 begin
3486 Collect_Interfaces (T, Ifaces_List);
3487 Collect_Interface_Components (T, Comps_List);
3489 -- Search for the record component and tag associated with each
3490 -- interface type of T.
3492 Components_List := New_Elmt_List;
3493 Tags_List := New_Elmt_List;
3495 Iface_Elmt := First_Elmt (Ifaces_List);
3496 while Present (Iface_Elmt) loop
3497 Iface := Node (Iface_Elmt);
3499 -- Associate the primary tag component and the primary dispatch table
3500 -- with all the interfaces that are parents of T
3502 if Is_Ancestor (Iface, T, Use_Full_View => True) then
3503 Append_Elmt (First_Tag_Component (T), Components_List);
3504 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
3506 -- Otherwise search for the tag component and secondary dispatch
3507 -- table of Iface
3509 else
3510 Comp_Elmt := First_Elmt (Comps_List);
3511 while Present (Comp_Elmt) loop
3512 Comp_Iface := Related_Type (Node (Comp_Elmt));
3514 if Comp_Iface = Iface
3515 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
3516 then
3517 Append_Elmt (Node (Comp_Elmt), Components_List);
3518 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
3519 exit;
3520 end if;
3522 Next_Elmt (Comp_Elmt);
3523 end loop;
3524 pragma Assert (Present (Comp_Elmt));
3525 end if;
3527 Next_Elmt (Iface_Elmt);
3528 end loop;
3529 end Collect_Interfaces_Info;
3531 ---------------------
3532 -- Collect_Parents --
3533 ---------------------
3535 procedure Collect_Parents
3536 (T : Entity_Id;
3537 List : out Elist_Id;
3538 Use_Full_View : Boolean := True)
3540 Current_Typ : Entity_Id := T;
3541 Parent_Typ : Entity_Id;
3543 begin
3544 List := New_Elmt_List;
3546 -- No action if the if the type has no parents
3548 if T = Etype (T) then
3549 return;
3550 end if;
3552 loop
3553 Parent_Typ := Etype (Current_Typ);
3555 if Is_Private_Type (Parent_Typ)
3556 and then Present (Full_View (Parent_Typ))
3557 and then Use_Full_View
3558 then
3559 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3560 end if;
3562 Append_Elmt (Parent_Typ, List);
3564 exit when Parent_Typ = Current_Typ;
3565 Current_Typ := Parent_Typ;
3566 end loop;
3567 end Collect_Parents;
3569 ----------------------------------
3570 -- Collect_Primitive_Operations --
3571 ----------------------------------
3573 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
3574 B_Type : constant Entity_Id := Base_Type (T);
3575 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
3576 B_Scope : Entity_Id := Scope (B_Type);
3577 Op_List : Elist_Id;
3578 Formal : Entity_Id;
3579 Is_Prim : Boolean;
3580 Is_Type_In_Pkg : Boolean;
3581 Formal_Derived : Boolean := False;
3582 Id : Entity_Id;
3584 function Match (E : Entity_Id) return Boolean;
3585 -- True if E's base type is B_Type, or E is of an anonymous access type
3586 -- and the base type of its designated type is B_Type.
3588 -----------
3589 -- Match --
3590 -----------
3592 function Match (E : Entity_Id) return Boolean is
3593 Etyp : Entity_Id := Etype (E);
3595 begin
3596 if Ekind (Etyp) = E_Anonymous_Access_Type then
3597 Etyp := Designated_Type (Etyp);
3598 end if;
3600 -- In Ada 2012 a primitive operation may have a formal of an
3601 -- incomplete view of the parent type.
3603 return Base_Type (Etyp) = B_Type
3604 or else
3605 (Ada_Version >= Ada_2012
3606 and then Ekind (Etyp) = E_Incomplete_Type
3607 and then Full_View (Etyp) = B_Type);
3608 end Match;
3610 -- Start of processing for Collect_Primitive_Operations
3612 begin
3613 -- For tagged types, the primitive operations are collected as they
3614 -- are declared, and held in an explicit list which is simply returned.
3616 if Is_Tagged_Type (B_Type) then
3617 return Primitive_Operations (B_Type);
3619 -- An untagged generic type that is a derived type inherits the
3620 -- primitive operations of its parent type. Other formal types only
3621 -- have predefined operators, which are not explicitly represented.
3623 elsif Is_Generic_Type (B_Type) then
3624 if Nkind (B_Decl) = N_Formal_Type_Declaration
3625 and then Nkind (Formal_Type_Definition (B_Decl)) =
3626 N_Formal_Derived_Type_Definition
3627 then
3628 Formal_Derived := True;
3629 else
3630 return New_Elmt_List;
3631 end if;
3632 end if;
3634 Op_List := New_Elmt_List;
3636 if B_Scope = Standard_Standard then
3637 if B_Type = Standard_String then
3638 Append_Elmt (Standard_Op_Concat, Op_List);
3640 elsif B_Type = Standard_Wide_String then
3641 Append_Elmt (Standard_Op_Concatw, Op_List);
3643 else
3644 null;
3645 end if;
3647 -- Locate the primitive subprograms of the type
3649 else
3650 -- The primitive operations appear after the base type, except
3651 -- if the derivation happens within the private part of B_Scope
3652 -- and the type is a private type, in which case both the type
3653 -- and some primitive operations may appear before the base
3654 -- type, and the list of candidates starts after the type.
3656 if In_Open_Scopes (B_Scope)
3657 and then Scope (T) = B_Scope
3658 and then In_Private_Part (B_Scope)
3659 then
3660 Id := Next_Entity (T);
3662 -- In Ada 2012, If the type has an incomplete partial view, there
3663 -- may be primitive operations declared before the full view, so
3664 -- we need to start scanning from the incomplete view, which is
3665 -- earlier on the entity chain.
3667 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
3668 and then Present (Incomplete_View (Parent (B_Type)))
3669 then
3670 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
3672 else
3673 Id := Next_Entity (B_Type);
3674 end if;
3676 -- Set flag if this is a type in a package spec
3678 Is_Type_In_Pkg :=
3679 Is_Package_Or_Generic_Package (B_Scope)
3680 and then
3681 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
3682 N_Package_Body;
3684 while Present (Id) loop
3686 -- Test whether the result type or any of the parameter types of
3687 -- each subprogram following the type match that type when the
3688 -- type is declared in a package spec, is a derived type, or the
3689 -- subprogram is marked as primitive. (The Is_Primitive test is
3690 -- needed to find primitives of nonderived types in declarative
3691 -- parts that happen to override the predefined "=" operator.)
3693 -- Note that generic formal subprograms are not considered to be
3694 -- primitive operations and thus are never inherited.
3696 if Is_Overloadable (Id)
3697 and then (Is_Type_In_Pkg
3698 or else Is_Derived_Type (B_Type)
3699 or else Is_Primitive (Id))
3700 and then Nkind (Parent (Parent (Id)))
3701 not in N_Formal_Subprogram_Declaration
3702 then
3703 Is_Prim := False;
3705 if Match (Id) then
3706 Is_Prim := True;
3708 else
3709 Formal := First_Formal (Id);
3710 while Present (Formal) loop
3711 if Match (Formal) then
3712 Is_Prim := True;
3713 exit;
3714 end if;
3716 Next_Formal (Formal);
3717 end loop;
3718 end if;
3720 -- For a formal derived type, the only primitives are the ones
3721 -- inherited from the parent type. Operations appearing in the
3722 -- package declaration are not primitive for it.
3724 if Is_Prim
3725 and then (not Formal_Derived or else Present (Alias (Id)))
3726 then
3727 -- In the special case of an equality operator aliased to
3728 -- an overriding dispatching equality belonging to the same
3729 -- type, we don't include it in the list of primitives.
3730 -- This avoids inheriting multiple equality operators when
3731 -- deriving from untagged private types whose full type is
3732 -- tagged, which can otherwise cause ambiguities. Note that
3733 -- this should only happen for this kind of untagged parent
3734 -- type, since normally dispatching operations are inherited
3735 -- using the type's Primitive_Operations list.
3737 if Chars (Id) = Name_Op_Eq
3738 and then Is_Dispatching_Operation (Id)
3739 and then Present (Alias (Id))
3740 and then Present (Overridden_Operation (Alias (Id)))
3741 and then Base_Type (Etype (First_Entity (Id))) =
3742 Base_Type (Etype (First_Entity (Alias (Id))))
3743 then
3744 null;
3746 -- Include the subprogram in the list of primitives
3748 else
3749 Append_Elmt (Id, Op_List);
3750 end if;
3751 end if;
3752 end if;
3754 Next_Entity (Id);
3756 -- For a type declared in System, some of its operations may
3757 -- appear in the target-specific extension to System.
3759 if No (Id)
3760 and then B_Scope = RTU_Entity (System)
3761 and then Present_System_Aux
3762 then
3763 B_Scope := System_Aux_Id;
3764 Id := First_Entity (System_Aux_Id);
3765 end if;
3766 end loop;
3767 end if;
3769 return Op_List;
3770 end Collect_Primitive_Operations;
3772 -----------------------------------
3773 -- Compile_Time_Constraint_Error --
3774 -----------------------------------
3776 function Compile_Time_Constraint_Error
3777 (N : Node_Id;
3778 Msg : String;
3779 Ent : Entity_Id := Empty;
3780 Loc : Source_Ptr := No_Location;
3781 Warn : Boolean := False) return Node_Id
3783 Msgc : String (1 .. Msg'Length + 3);
3784 -- Copy of message, with room for possible ?? or << and ! at end
3786 Msgl : Natural;
3787 Wmsg : Boolean;
3788 Eloc : Source_Ptr;
3790 -- Start of processing for Compile_Time_Constraint_Error
3792 begin
3793 -- If this is a warning, convert it into an error if we are in code
3794 -- subject to SPARK_Mode being set ON.
3796 Error_Msg_Warn := SPARK_Mode /= On;
3798 -- A static constraint error in an instance body is not a fatal error.
3799 -- we choose to inhibit the message altogether, because there is no
3800 -- obvious node (for now) on which to post it. On the other hand the
3801 -- offending node must be replaced with a constraint_error in any case.
3803 -- No messages are generated if we already posted an error on this node
3805 if not Error_Posted (N) then
3806 if Loc /= No_Location then
3807 Eloc := Loc;
3808 else
3809 Eloc := Sloc (N);
3810 end if;
3812 -- Copy message to Msgc, converting any ? in the message into
3813 -- < instead, so that we have an error in GNATprove mode.
3815 Msgl := Msg'Length;
3817 for J in 1 .. Msgl loop
3818 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
3819 Msgc (J) := '<';
3820 else
3821 Msgc (J) := Msg (J);
3822 end if;
3823 end loop;
3825 -- Message is a warning, even in Ada 95 case
3827 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
3828 Wmsg := True;
3830 -- In Ada 83, all messages are warnings. In the private part and
3831 -- the body of an instance, constraint_checks are only warnings.
3832 -- We also make this a warning if the Warn parameter is set.
3834 elsif Warn
3835 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
3836 then
3837 Msgl := Msgl + 1;
3838 Msgc (Msgl) := '<';
3839 Msgl := Msgl + 1;
3840 Msgc (Msgl) := '<';
3841 Wmsg := True;
3843 elsif In_Instance_Not_Visible then
3844 Msgl := Msgl + 1;
3845 Msgc (Msgl) := '<';
3846 Msgl := Msgl + 1;
3847 Msgc (Msgl) := '<';
3848 Wmsg := True;
3850 -- Otherwise we have a real error message (Ada 95 static case)
3851 -- and we make this an unconditional message. Note that in the
3852 -- warning case we do not make the message unconditional, it seems
3853 -- quite reasonable to delete messages like this (about exceptions
3854 -- that will be raised) in dead code.
3856 else
3857 Wmsg := False;
3858 Msgl := Msgl + 1;
3859 Msgc (Msgl) := '!';
3860 end if;
3862 -- One more test, skip the warning if the related expression is
3863 -- statically unevaluated, since we don't want to warn about what
3864 -- will happen when something is evaluated if it never will be
3865 -- evaluated.
3867 if not Is_Statically_Unevaluated (N) then
3868 Error_Msg_Warn := SPARK_Mode /= On;
3870 if Present (Ent) then
3871 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
3872 else
3873 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
3874 end if;
3876 if Wmsg then
3878 -- Check whether the context is an Init_Proc
3880 if Inside_Init_Proc then
3881 declare
3882 Conc_Typ : constant Entity_Id :=
3883 Corresponding_Concurrent_Type
3884 (Entity (Parameter_Type (First
3885 (Parameter_Specifications
3886 (Parent (Current_Scope))))));
3888 begin
3889 -- Don't complain if the corresponding concurrent type
3890 -- doesn't come from source (i.e. a single task/protected
3891 -- object).
3893 if Present (Conc_Typ)
3894 and then not Comes_From_Source (Conc_Typ)
3895 then
3896 Error_Msg_NEL
3897 ("\& [<<", N, Standard_Constraint_Error, Eloc);
3899 else
3900 if GNATprove_Mode then
3901 Error_Msg_NEL
3902 ("\& would have been raised for objects of this "
3903 & "type", N, Standard_Constraint_Error, Eloc);
3904 else
3905 Error_Msg_NEL
3906 ("\& will be raised for objects of this type??",
3907 N, Standard_Constraint_Error, Eloc);
3908 end if;
3909 end if;
3910 end;
3912 else
3913 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
3914 end if;
3916 else
3917 Error_Msg ("\static expression fails Constraint_Check", Eloc);
3918 Set_Error_Posted (N);
3919 end if;
3920 end if;
3921 end if;
3923 return N;
3924 end Compile_Time_Constraint_Error;
3926 -----------------------
3927 -- Conditional_Delay --
3928 -----------------------
3930 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
3931 begin
3932 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
3933 Set_Has_Delayed_Freeze (New_Ent);
3934 end if;
3935 end Conditional_Delay;
3937 ----------------------------
3938 -- Contains_Refined_State --
3939 ----------------------------
3941 function Contains_Refined_State (Prag : Node_Id) return Boolean is
3942 function Has_State_In_Dependency (List : Node_Id) return Boolean;
3943 -- Determine whether a dependency list mentions a state with a visible
3944 -- refinement.
3946 function Has_State_In_Global (List : Node_Id) return Boolean;
3947 -- Determine whether a global list mentions a state with a visible
3948 -- refinement.
3950 function Is_Refined_State (Item : Node_Id) return Boolean;
3951 -- Determine whether Item is a reference to an abstract state with a
3952 -- visible refinement.
3954 -----------------------------
3955 -- Has_State_In_Dependency --
3956 -----------------------------
3958 function Has_State_In_Dependency (List : Node_Id) return Boolean is
3959 Clause : Node_Id;
3960 Output : Node_Id;
3962 begin
3963 -- A null dependency list does not mention any states
3965 if Nkind (List) = N_Null then
3966 return False;
3968 -- Dependency clauses appear as component associations of an
3969 -- aggregate.
3971 elsif Nkind (List) = N_Aggregate
3972 and then Present (Component_Associations (List))
3973 then
3974 Clause := First (Component_Associations (List));
3975 while Present (Clause) loop
3977 -- Inspect the outputs of a dependency clause
3979 Output := First (Choices (Clause));
3980 while Present (Output) loop
3981 if Is_Refined_State (Output) then
3982 return True;
3983 end if;
3985 Next (Output);
3986 end loop;
3988 -- Inspect the outputs of a dependency clause
3990 if Is_Refined_State (Expression (Clause)) then
3991 return True;
3992 end if;
3994 Next (Clause);
3995 end loop;
3997 -- If we get here, then none of the dependency clauses mention a
3998 -- state with visible refinement.
4000 return False;
4002 -- An illegal pragma managed to sneak in
4004 else
4005 raise Program_Error;
4006 end if;
4007 end Has_State_In_Dependency;
4009 -------------------------
4010 -- Has_State_In_Global --
4011 -------------------------
4013 function Has_State_In_Global (List : Node_Id) return Boolean is
4014 Item : Node_Id;
4016 begin
4017 -- A null global list does not mention any states
4019 if Nkind (List) = N_Null then
4020 return False;
4022 -- Simple global list or moded global list declaration
4024 elsif Nkind (List) = N_Aggregate then
4026 -- The declaration of a simple global list appear as a collection
4027 -- of expressions.
4029 if Present (Expressions (List)) then
4030 Item := First (Expressions (List));
4031 while Present (Item) loop
4032 if Is_Refined_State (Item) then
4033 return True;
4034 end if;
4036 Next (Item);
4037 end loop;
4039 -- The declaration of a moded global list appears as a collection
4040 -- of component associations where individual choices denote
4041 -- modes.
4043 else
4044 Item := First (Component_Associations (List));
4045 while Present (Item) loop
4046 if Has_State_In_Global (Expression (Item)) then
4047 return True;
4048 end if;
4050 Next (Item);
4051 end loop;
4052 end if;
4054 -- If we get here, then the simple/moded global list did not
4055 -- mention any states with a visible refinement.
4057 return False;
4059 -- Single global item declaration
4061 elsif Is_Entity_Name (List) then
4062 return Is_Refined_State (List);
4064 -- An illegal pragma managed to sneak in
4066 else
4067 raise Program_Error;
4068 end if;
4069 end Has_State_In_Global;
4071 ----------------------
4072 -- Is_Refined_State --
4073 ----------------------
4075 function Is_Refined_State (Item : Node_Id) return Boolean is
4076 Elmt : Node_Id;
4077 Item_Id : Entity_Id;
4079 begin
4080 if Nkind (Item) = N_Null then
4081 return False;
4083 -- States cannot be subject to attribute 'Result. This case arises
4084 -- in dependency relations.
4086 elsif Nkind (Item) = N_Attribute_Reference
4087 and then Attribute_Name (Item) = Name_Result
4088 then
4089 return False;
4091 -- Multiple items appear as an aggregate. This case arises in
4092 -- dependency relations.
4094 elsif Nkind (Item) = N_Aggregate
4095 and then Present (Expressions (Item))
4096 then
4097 Elmt := First (Expressions (Item));
4098 while Present (Elmt) loop
4099 if Is_Refined_State (Elmt) then
4100 return True;
4101 end if;
4103 Next (Elmt);
4104 end loop;
4106 -- If we get here, then none of the inputs or outputs reference a
4107 -- state with visible refinement.
4109 return False;
4111 -- Single item
4113 else
4114 Item_Id := Entity_Of (Item);
4116 return
4117 Present (Item_Id)
4118 and then Ekind (Item_Id) = E_Abstract_State
4119 and then Has_Visible_Refinement (Item_Id);
4120 end if;
4121 end Is_Refined_State;
4123 -- Local variables
4125 Arg : constant Node_Id :=
4126 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4127 Nam : constant Name_Id := Pragma_Name (Prag);
4129 -- Start of processing for Contains_Refined_State
4131 begin
4132 if Nam = Name_Depends then
4133 return Has_State_In_Dependency (Arg);
4135 else pragma Assert (Nam = Name_Global);
4136 return Has_State_In_Global (Arg);
4137 end if;
4138 end Contains_Refined_State;
4140 -------------------------
4141 -- Copy_Component_List --
4142 -------------------------
4144 function Copy_Component_List
4145 (R_Typ : Entity_Id;
4146 Loc : Source_Ptr) return List_Id
4148 Comp : Node_Id;
4149 Comps : constant List_Id := New_List;
4151 begin
4152 Comp := First_Component (Underlying_Type (R_Typ));
4153 while Present (Comp) loop
4154 if Comes_From_Source (Comp) then
4155 declare
4156 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4157 begin
4158 Append_To (Comps,
4159 Make_Component_Declaration (Loc,
4160 Defining_Identifier =>
4161 Make_Defining_Identifier (Loc, Chars (Comp)),
4162 Component_Definition =>
4163 New_Copy_Tree
4164 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4165 end;
4166 end if;
4168 Next_Component (Comp);
4169 end loop;
4171 return Comps;
4172 end Copy_Component_List;
4174 -------------------------
4175 -- Copy_Parameter_List --
4176 -------------------------
4178 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4179 Loc : constant Source_Ptr := Sloc (Subp_Id);
4180 Plist : List_Id;
4181 Formal : Entity_Id;
4183 begin
4184 if No (First_Formal (Subp_Id)) then
4185 return No_List;
4186 else
4187 Plist := New_List;
4188 Formal := First_Formal (Subp_Id);
4189 while Present (Formal) loop
4190 Append
4191 (Make_Parameter_Specification (Loc,
4192 Defining_Identifier =>
4193 Make_Defining_Identifier (Sloc (Formal),
4194 Chars => Chars (Formal)),
4195 In_Present => In_Present (Parent (Formal)),
4196 Out_Present => Out_Present (Parent (Formal)),
4197 Parameter_Type =>
4198 New_Occurrence_Of (Etype (Formal), Loc),
4199 Expression =>
4200 New_Copy_Tree (Expression (Parent (Formal)))),
4201 Plist);
4203 Next_Formal (Formal);
4204 end loop;
4205 end if;
4207 return Plist;
4208 end Copy_Parameter_List;
4210 --------------------------------
4211 -- Corresponding_Generic_Type --
4212 --------------------------------
4214 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4215 Inst : Entity_Id;
4216 Gen : Entity_Id;
4217 Typ : Entity_Id;
4219 begin
4220 if not Is_Generic_Actual_Type (T) then
4221 return Any_Type;
4223 -- If the actual is the actual of an enclosing instance, resolution
4224 -- was correct in the generic.
4226 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4227 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4228 and then
4229 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4230 then
4231 return Any_Type;
4233 else
4234 Inst := Scope (T);
4236 if Is_Wrapper_Package (Inst) then
4237 Inst := Related_Instance (Inst);
4238 end if;
4240 Gen :=
4241 Generic_Parent
4242 (Specification (Unit_Declaration_Node (Inst)));
4244 -- Generic actual has the same name as the corresponding formal
4246 Typ := First_Entity (Gen);
4247 while Present (Typ) loop
4248 if Chars (Typ) = Chars (T) then
4249 return Typ;
4250 end if;
4252 Next_Entity (Typ);
4253 end loop;
4255 return Any_Type;
4256 end if;
4257 end Corresponding_Generic_Type;
4259 --------------------
4260 -- Current_Entity --
4261 --------------------
4263 -- The currently visible definition for a given identifier is the
4264 -- one most chained at the start of the visibility chain, i.e. the
4265 -- one that is referenced by the Node_Id value of the name of the
4266 -- given identifier.
4268 function Current_Entity (N : Node_Id) return Entity_Id is
4269 begin
4270 return Get_Name_Entity_Id (Chars (N));
4271 end Current_Entity;
4273 -----------------------------
4274 -- Current_Entity_In_Scope --
4275 -----------------------------
4277 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4278 E : Entity_Id;
4279 CS : constant Entity_Id := Current_Scope;
4281 Transient_Case : constant Boolean := Scope_Is_Transient;
4283 begin
4284 E := Get_Name_Entity_Id (Chars (N));
4285 while Present (E)
4286 and then Scope (E) /= CS
4287 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4288 loop
4289 E := Homonym (E);
4290 end loop;
4292 return E;
4293 end Current_Entity_In_Scope;
4295 -------------------
4296 -- Current_Scope --
4297 -------------------
4299 function Current_Scope return Entity_Id is
4300 begin
4301 if Scope_Stack.Last = -1 then
4302 return Standard_Standard;
4303 else
4304 declare
4305 C : constant Entity_Id :=
4306 Scope_Stack.Table (Scope_Stack.Last).Entity;
4307 begin
4308 if Present (C) then
4309 return C;
4310 else
4311 return Standard_Standard;
4312 end if;
4313 end;
4314 end if;
4315 end Current_Scope;
4317 ------------------------
4318 -- Current_Subprogram --
4319 ------------------------
4321 function Current_Subprogram return Entity_Id is
4322 Scop : constant Entity_Id := Current_Scope;
4323 begin
4324 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
4325 return Scop;
4326 else
4327 return Enclosing_Subprogram (Scop);
4328 end if;
4329 end Current_Subprogram;
4331 ----------------------------------
4332 -- Deepest_Type_Access_Level --
4333 ----------------------------------
4335 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4336 begin
4337 if Ekind (Typ) = E_Anonymous_Access_Type
4338 and then not Is_Local_Anonymous_Access (Typ)
4339 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4340 then
4341 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4342 -- access type.
4344 return
4345 Scope_Depth (Enclosing_Dynamic_Scope
4346 (Defining_Identifier
4347 (Associated_Node_For_Itype (Typ))));
4349 -- For generic formal type, return Int'Last (infinite).
4350 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4352 elsif Is_Generic_Type (Root_Type (Typ)) then
4353 return UI_From_Int (Int'Last);
4355 else
4356 return Type_Access_Level (Typ);
4357 end if;
4358 end Deepest_Type_Access_Level;
4360 ---------------------
4361 -- Defining_Entity --
4362 ---------------------
4364 function Defining_Entity (N : Node_Id) return Entity_Id is
4365 K : constant Node_Kind := Nkind (N);
4366 Err : Entity_Id := Empty;
4368 begin
4369 case K is
4370 when
4371 N_Subprogram_Declaration |
4372 N_Abstract_Subprogram_Declaration |
4373 N_Subprogram_Body |
4374 N_Package_Declaration |
4375 N_Subprogram_Renaming_Declaration |
4376 N_Subprogram_Body_Stub |
4377 N_Generic_Subprogram_Declaration |
4378 N_Generic_Package_Declaration |
4379 N_Formal_Subprogram_Declaration |
4380 N_Expression_Function
4382 return Defining_Entity (Specification (N));
4384 when
4385 N_Component_Declaration |
4386 N_Defining_Program_Unit_Name |
4387 N_Discriminant_Specification |
4388 N_Entry_Body |
4389 N_Entry_Declaration |
4390 N_Entry_Index_Specification |
4391 N_Exception_Declaration |
4392 N_Exception_Renaming_Declaration |
4393 N_Formal_Object_Declaration |
4394 N_Formal_Package_Declaration |
4395 N_Formal_Type_Declaration |
4396 N_Full_Type_Declaration |
4397 N_Implicit_Label_Declaration |
4398 N_Incomplete_Type_Declaration |
4399 N_Loop_Parameter_Specification |
4400 N_Number_Declaration |
4401 N_Object_Declaration |
4402 N_Object_Renaming_Declaration |
4403 N_Package_Body_Stub |
4404 N_Parameter_Specification |
4405 N_Private_Extension_Declaration |
4406 N_Private_Type_Declaration |
4407 N_Protected_Body |
4408 N_Protected_Body_Stub |
4409 N_Protected_Type_Declaration |
4410 N_Single_Protected_Declaration |
4411 N_Single_Task_Declaration |
4412 N_Subtype_Declaration |
4413 N_Task_Body |
4414 N_Task_Body_Stub |
4415 N_Task_Type_Declaration
4417 return Defining_Identifier (N);
4419 when N_Subunit =>
4420 return Defining_Entity (Proper_Body (N));
4422 when
4423 N_Function_Instantiation |
4424 N_Function_Specification |
4425 N_Generic_Function_Renaming_Declaration |
4426 N_Generic_Package_Renaming_Declaration |
4427 N_Generic_Procedure_Renaming_Declaration |
4428 N_Package_Body |
4429 N_Package_Instantiation |
4430 N_Package_Renaming_Declaration |
4431 N_Package_Specification |
4432 N_Procedure_Instantiation |
4433 N_Procedure_Specification
4435 declare
4436 Nam : constant Node_Id := Defining_Unit_Name (N);
4438 begin
4439 if Nkind (Nam) in N_Entity then
4440 return Nam;
4442 -- For Error, make up a name and attach to declaration
4443 -- so we can continue semantic analysis
4445 elsif Nam = Error then
4446 Err := Make_Temporary (Sloc (N), 'T');
4447 Set_Defining_Unit_Name (N, Err);
4449 return Err;
4451 -- If not an entity, get defining identifier
4453 else
4454 return Defining_Identifier (Nam);
4455 end if;
4456 end;
4458 when
4459 N_Block_Statement |
4460 N_Loop_Statement
4462 return Entity (Identifier (N));
4464 when others =>
4465 raise Program_Error;
4467 end case;
4468 end Defining_Entity;
4470 --------------------------
4471 -- Denotes_Discriminant --
4472 --------------------------
4474 function Denotes_Discriminant
4475 (N : Node_Id;
4476 Check_Concurrent : Boolean := False) return Boolean
4478 E : Entity_Id;
4480 begin
4481 if not Is_Entity_Name (N) or else No (Entity (N)) then
4482 return False;
4483 else
4484 E := Entity (N);
4485 end if;
4487 -- If we are checking for a protected type, the discriminant may have
4488 -- been rewritten as the corresponding discriminal of the original type
4489 -- or of the corresponding concurrent record, depending on whether we
4490 -- are in the spec or body of the protected type.
4492 return Ekind (E) = E_Discriminant
4493 or else
4494 (Check_Concurrent
4495 and then Ekind (E) = E_In_Parameter
4496 and then Present (Discriminal_Link (E))
4497 and then
4498 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
4499 or else
4500 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
4502 end Denotes_Discriminant;
4504 -------------------------
4505 -- Denotes_Same_Object --
4506 -------------------------
4508 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
4509 Obj1 : Node_Id := A1;
4510 Obj2 : Node_Id := A2;
4512 function Has_Prefix (N : Node_Id) return Boolean;
4513 -- Return True if N has attribute Prefix
4515 function Is_Renaming (N : Node_Id) return Boolean;
4516 -- Return true if N names a renaming entity
4518 function Is_Valid_Renaming (N : Node_Id) return Boolean;
4519 -- For renamings, return False if the prefix of any dereference within
4520 -- the renamed object_name is a variable, or any expression within the
4521 -- renamed object_name contains references to variables or calls on
4522 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4524 ----------------
4525 -- Has_Prefix --
4526 ----------------
4528 function Has_Prefix (N : Node_Id) return Boolean is
4529 begin
4530 return
4531 Nkind_In (N,
4532 N_Attribute_Reference,
4533 N_Expanded_Name,
4534 N_Explicit_Dereference,
4535 N_Indexed_Component,
4536 N_Reference,
4537 N_Selected_Component,
4538 N_Slice);
4539 end Has_Prefix;
4541 -----------------
4542 -- Is_Renaming --
4543 -----------------
4545 function Is_Renaming (N : Node_Id) return Boolean is
4546 begin
4547 return Is_Entity_Name (N)
4548 and then Present (Renamed_Entity (Entity (N)));
4549 end Is_Renaming;
4551 -----------------------
4552 -- Is_Valid_Renaming --
4553 -----------------------
4555 function Is_Valid_Renaming (N : Node_Id) return Boolean is
4557 function Check_Renaming (N : Node_Id) return Boolean;
4558 -- Recursive function used to traverse all the prefixes of N
4560 function Check_Renaming (N : Node_Id) return Boolean is
4561 begin
4562 if Is_Renaming (N)
4563 and then not Check_Renaming (Renamed_Entity (Entity (N)))
4564 then
4565 return False;
4566 end if;
4568 if Nkind (N) = N_Indexed_Component then
4569 declare
4570 Indx : Node_Id;
4572 begin
4573 Indx := First (Expressions (N));
4574 while Present (Indx) loop
4575 if not Is_OK_Static_Expression (Indx) then
4576 return False;
4577 end if;
4579 Next_Index (Indx);
4580 end loop;
4581 end;
4582 end if;
4584 if Has_Prefix (N) then
4585 declare
4586 P : constant Node_Id := Prefix (N);
4588 begin
4589 if Nkind (N) = N_Explicit_Dereference
4590 and then Is_Variable (P)
4591 then
4592 return False;
4594 elsif Is_Entity_Name (P)
4595 and then Ekind (Entity (P)) = E_Function
4596 then
4597 return False;
4599 elsif Nkind (P) = N_Function_Call then
4600 return False;
4601 end if;
4603 -- Recursion to continue traversing the prefix of the
4604 -- renaming expression
4606 return Check_Renaming (P);
4607 end;
4608 end if;
4610 return True;
4611 end Check_Renaming;
4613 -- Start of processing for Is_Valid_Renaming
4615 begin
4616 return Check_Renaming (N);
4617 end Is_Valid_Renaming;
4619 -- Start of processing for Denotes_Same_Object
4621 begin
4622 -- Both names statically denote the same stand-alone object or parameter
4623 -- (RM 6.4.1(6.5/3))
4625 if Is_Entity_Name (Obj1)
4626 and then Is_Entity_Name (Obj2)
4627 and then Entity (Obj1) = Entity (Obj2)
4628 then
4629 return True;
4630 end if;
4632 -- For renamings, the prefix of any dereference within the renamed
4633 -- object_name is not a variable, and any expression within the
4634 -- renamed object_name contains no references to variables nor
4635 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4637 if Is_Renaming (Obj1) then
4638 if Is_Valid_Renaming (Obj1) then
4639 Obj1 := Renamed_Entity (Entity (Obj1));
4640 else
4641 return False;
4642 end if;
4643 end if;
4645 if Is_Renaming (Obj2) then
4646 if Is_Valid_Renaming (Obj2) then
4647 Obj2 := Renamed_Entity (Entity (Obj2));
4648 else
4649 return False;
4650 end if;
4651 end if;
4653 -- No match if not same node kind (such cases are handled by
4654 -- Denotes_Same_Prefix)
4656 if Nkind (Obj1) /= Nkind (Obj2) then
4657 return False;
4659 -- After handling valid renamings, one of the two names statically
4660 -- denoted a renaming declaration whose renamed object_name is known
4661 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4663 elsif Is_Entity_Name (Obj1) then
4664 if Is_Entity_Name (Obj2) then
4665 return Entity (Obj1) = Entity (Obj2);
4666 else
4667 return False;
4668 end if;
4670 -- Both names are selected_components, their prefixes are known to
4671 -- denote the same object, and their selector_names denote the same
4672 -- component (RM 6.4.1(6.6/3)
4674 elsif Nkind (Obj1) = N_Selected_Component then
4675 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4676 and then
4677 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
4679 -- Both names are dereferences and the dereferenced names are known to
4680 -- denote the same object (RM 6.4.1(6.7/3))
4682 elsif Nkind (Obj1) = N_Explicit_Dereference then
4683 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
4685 -- Both names are indexed_components, their prefixes are known to denote
4686 -- the same object, and each of the pairs of corresponding index values
4687 -- are either both static expressions with the same static value or both
4688 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4690 elsif Nkind (Obj1) = N_Indexed_Component then
4691 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
4692 return False;
4693 else
4694 declare
4695 Indx1 : Node_Id;
4696 Indx2 : Node_Id;
4698 begin
4699 Indx1 := First (Expressions (Obj1));
4700 Indx2 := First (Expressions (Obj2));
4701 while Present (Indx1) loop
4703 -- Indexes must denote the same static value or same object
4705 if Is_OK_Static_Expression (Indx1) then
4706 if not Is_OK_Static_Expression (Indx2) then
4707 return False;
4709 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
4710 return False;
4711 end if;
4713 elsif not Denotes_Same_Object (Indx1, Indx2) then
4714 return False;
4715 end if;
4717 Next (Indx1);
4718 Next (Indx2);
4719 end loop;
4721 return True;
4722 end;
4723 end if;
4725 -- Both names are slices, their prefixes are known to denote the same
4726 -- object, and the two slices have statically matching index constraints
4727 -- (RM 6.4.1(6.9/3))
4729 elsif Nkind (Obj1) = N_Slice
4730 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4731 then
4732 declare
4733 Lo1, Lo2, Hi1, Hi2 : Node_Id;
4735 begin
4736 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
4737 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
4739 -- Check whether bounds are statically identical. There is no
4740 -- attempt to detect partial overlap of slices.
4742 return Denotes_Same_Object (Lo1, Lo2)
4743 and then Denotes_Same_Object (Hi1, Hi2);
4744 end;
4746 -- In the recursion, literals appear as indexes
4748 elsif Nkind (Obj1) = N_Integer_Literal
4749 and then
4750 Nkind (Obj2) = N_Integer_Literal
4751 then
4752 return Intval (Obj1) = Intval (Obj2);
4754 else
4755 return False;
4756 end if;
4757 end Denotes_Same_Object;
4759 -------------------------
4760 -- Denotes_Same_Prefix --
4761 -------------------------
4763 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
4765 begin
4766 if Is_Entity_Name (A1) then
4767 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
4768 and then not Is_Access_Type (Etype (A1))
4769 then
4770 return Denotes_Same_Object (A1, Prefix (A2))
4771 or else Denotes_Same_Prefix (A1, Prefix (A2));
4772 else
4773 return False;
4774 end if;
4776 elsif Is_Entity_Name (A2) then
4777 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
4779 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
4780 and then
4781 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
4782 then
4783 declare
4784 Root1, Root2 : Node_Id;
4785 Depth1, Depth2 : Int := 0;
4787 begin
4788 Root1 := Prefix (A1);
4789 while not Is_Entity_Name (Root1) loop
4790 if not Nkind_In
4791 (Root1, N_Selected_Component, N_Indexed_Component)
4792 then
4793 return False;
4794 else
4795 Root1 := Prefix (Root1);
4796 end if;
4798 Depth1 := Depth1 + 1;
4799 end loop;
4801 Root2 := Prefix (A2);
4802 while not Is_Entity_Name (Root2) loop
4803 if not Nkind_In
4804 (Root2, N_Selected_Component, N_Indexed_Component)
4805 then
4806 return False;
4807 else
4808 Root2 := Prefix (Root2);
4809 end if;
4811 Depth2 := Depth2 + 1;
4812 end loop;
4814 -- If both have the same depth and they do not denote the same
4815 -- object, they are disjoint and no warning is needed.
4817 if Depth1 = Depth2 then
4818 return False;
4820 elsif Depth1 > Depth2 then
4821 Root1 := Prefix (A1);
4822 for I in 1 .. Depth1 - Depth2 - 1 loop
4823 Root1 := Prefix (Root1);
4824 end loop;
4826 return Denotes_Same_Object (Root1, A2);
4828 else
4829 Root2 := Prefix (A2);
4830 for I in 1 .. Depth2 - Depth1 - 1 loop
4831 Root2 := Prefix (Root2);
4832 end loop;
4834 return Denotes_Same_Object (A1, Root2);
4835 end if;
4836 end;
4838 else
4839 return False;
4840 end if;
4841 end Denotes_Same_Prefix;
4843 ----------------------
4844 -- Denotes_Variable --
4845 ----------------------
4847 function Denotes_Variable (N : Node_Id) return Boolean is
4848 begin
4849 return Is_Variable (N) and then Paren_Count (N) = 0;
4850 end Denotes_Variable;
4852 -----------------------------
4853 -- Depends_On_Discriminant --
4854 -----------------------------
4856 function Depends_On_Discriminant (N : Node_Id) return Boolean is
4857 L : Node_Id;
4858 H : Node_Id;
4860 begin
4861 Get_Index_Bounds (N, L, H);
4862 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
4863 end Depends_On_Discriminant;
4865 -------------------------
4866 -- Designate_Same_Unit --
4867 -------------------------
4869 function Designate_Same_Unit
4870 (Name1 : Node_Id;
4871 Name2 : Node_Id) return Boolean
4873 K1 : constant Node_Kind := Nkind (Name1);
4874 K2 : constant Node_Kind := Nkind (Name2);
4876 function Prefix_Node (N : Node_Id) return Node_Id;
4877 -- Returns the parent unit name node of a defining program unit name
4878 -- or the prefix if N is a selected component or an expanded name.
4880 function Select_Node (N : Node_Id) return Node_Id;
4881 -- Returns the defining identifier node of a defining program unit
4882 -- name or the selector node if N is a selected component or an
4883 -- expanded name.
4885 -----------------
4886 -- Prefix_Node --
4887 -----------------
4889 function Prefix_Node (N : Node_Id) return Node_Id is
4890 begin
4891 if Nkind (N) = N_Defining_Program_Unit_Name then
4892 return Name (N);
4894 else
4895 return Prefix (N);
4896 end if;
4897 end Prefix_Node;
4899 -----------------
4900 -- Select_Node --
4901 -----------------
4903 function Select_Node (N : Node_Id) return Node_Id is
4904 begin
4905 if Nkind (N) = N_Defining_Program_Unit_Name then
4906 return Defining_Identifier (N);
4908 else
4909 return Selector_Name (N);
4910 end if;
4911 end Select_Node;
4913 -- Start of processing for Designate_Next_Unit
4915 begin
4916 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
4917 and then
4918 (K2 = N_Identifier or else K2 = N_Defining_Identifier)
4919 then
4920 return Chars (Name1) = Chars (Name2);
4922 elsif
4923 (K1 = N_Expanded_Name or else
4924 K1 = N_Selected_Component or else
4925 K1 = N_Defining_Program_Unit_Name)
4926 and then
4927 (K2 = N_Expanded_Name or else
4928 K2 = N_Selected_Component or else
4929 K2 = N_Defining_Program_Unit_Name)
4930 then
4931 return
4932 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
4933 and then
4934 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
4936 else
4937 return False;
4938 end if;
4939 end Designate_Same_Unit;
4941 ------------------------------------------
4942 -- function Dynamic_Accessibility_Level --
4943 ------------------------------------------
4945 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
4946 E : Entity_Id;
4947 Loc : constant Source_Ptr := Sloc (Expr);
4949 function Make_Level_Literal (Level : Uint) return Node_Id;
4950 -- Construct an integer literal representing an accessibility level
4951 -- with its type set to Natural.
4953 ------------------------
4954 -- Make_Level_Literal --
4955 ------------------------
4957 function Make_Level_Literal (Level : Uint) return Node_Id is
4958 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
4959 begin
4960 Set_Etype (Result, Standard_Natural);
4961 return Result;
4962 end Make_Level_Literal;
4964 -- Start of processing for Dynamic_Accessibility_Level
4966 begin
4967 if Is_Entity_Name (Expr) then
4968 E := Entity (Expr);
4970 if Present (Renamed_Object (E)) then
4971 return Dynamic_Accessibility_Level (Renamed_Object (E));
4972 end if;
4974 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
4975 if Present (Extra_Accessibility (E)) then
4976 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
4977 end if;
4978 end if;
4979 end if;
4981 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4983 case Nkind (Expr) is
4985 -- For access discriminant, the level of the enclosing object
4987 when N_Selected_Component =>
4988 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
4989 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
4990 E_Anonymous_Access_Type
4991 then
4992 return Make_Level_Literal (Object_Access_Level (Expr));
4993 end if;
4995 when N_Attribute_Reference =>
4996 case Get_Attribute_Id (Attribute_Name (Expr)) is
4998 -- For X'Access, the level of the prefix X
5000 when Attribute_Access =>
5001 return Make_Level_Literal
5002 (Object_Access_Level (Prefix (Expr)));
5004 -- Treat the unchecked attributes as library-level
5006 when Attribute_Unchecked_Access |
5007 Attribute_Unrestricted_Access =>
5008 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5010 -- No other access-valued attributes
5012 when others =>
5013 raise Program_Error;
5014 end case;
5016 when N_Allocator =>
5018 -- Unimplemented: depends on context. As an actual parameter where
5019 -- formal type is anonymous, use
5020 -- Scope_Depth (Current_Scope) + 1.
5021 -- For other cases, see 3.10.2(14/3) and following. ???
5023 null;
5025 when N_Type_Conversion =>
5026 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5028 -- Handle type conversions introduced for a rename of an
5029 -- Ada 2012 stand-alone object of an anonymous access type.
5031 return Dynamic_Accessibility_Level (Expression (Expr));
5032 end if;
5034 when others =>
5035 null;
5036 end case;
5038 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5039 end Dynamic_Accessibility_Level;
5041 -----------------------------------
5042 -- Effective_Extra_Accessibility --
5043 -----------------------------------
5045 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5046 begin
5047 if Present (Renamed_Object (Id))
5048 and then Is_Entity_Name (Renamed_Object (Id))
5049 then
5050 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5051 else
5052 return Extra_Accessibility (Id);
5053 end if;
5054 end Effective_Extra_Accessibility;
5056 -----------------------------
5057 -- Effective_Reads_Enabled --
5058 -----------------------------
5060 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5061 begin
5062 return Has_Enabled_Property (Id, Name_Effective_Reads);
5063 end Effective_Reads_Enabled;
5065 ------------------------------
5066 -- Effective_Writes_Enabled --
5067 ------------------------------
5069 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5070 begin
5071 return Has_Enabled_Property (Id, Name_Effective_Writes);
5072 end Effective_Writes_Enabled;
5074 ------------------------------
5075 -- Enclosing_Comp_Unit_Node --
5076 ------------------------------
5078 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5079 Current_Node : Node_Id;
5081 begin
5082 Current_Node := N;
5083 while Present (Current_Node)
5084 and then Nkind (Current_Node) /= N_Compilation_Unit
5085 loop
5086 Current_Node := Parent (Current_Node);
5087 end loop;
5089 if Nkind (Current_Node) /= N_Compilation_Unit then
5090 return Empty;
5091 else
5092 return Current_Node;
5093 end if;
5094 end Enclosing_Comp_Unit_Node;
5096 --------------------------
5097 -- Enclosing_CPP_Parent --
5098 --------------------------
5100 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5101 Parent_Typ : Entity_Id := Typ;
5103 begin
5104 while not Is_CPP_Class (Parent_Typ)
5105 and then Etype (Parent_Typ) /= Parent_Typ
5106 loop
5107 Parent_Typ := Etype (Parent_Typ);
5109 if Is_Private_Type (Parent_Typ) then
5110 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5111 end if;
5112 end loop;
5114 pragma Assert (Is_CPP_Class (Parent_Typ));
5115 return Parent_Typ;
5116 end Enclosing_CPP_Parent;
5118 ----------------------------
5119 -- Enclosing_Generic_Body --
5120 ----------------------------
5122 function Enclosing_Generic_Body
5123 (N : Node_Id) return Node_Id
5125 P : Node_Id;
5126 Decl : Node_Id;
5127 Spec : Node_Id;
5129 begin
5130 P := Parent (N);
5131 while Present (P) loop
5132 if Nkind (P) = N_Package_Body
5133 or else Nkind (P) = N_Subprogram_Body
5134 then
5135 Spec := Corresponding_Spec (P);
5137 if Present (Spec) then
5138 Decl := Unit_Declaration_Node (Spec);
5140 if Nkind (Decl) = N_Generic_Package_Declaration
5141 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5142 then
5143 return P;
5144 end if;
5145 end if;
5146 end if;
5148 P := Parent (P);
5149 end loop;
5151 return Empty;
5152 end Enclosing_Generic_Body;
5154 ----------------------------
5155 -- Enclosing_Generic_Unit --
5156 ----------------------------
5158 function Enclosing_Generic_Unit
5159 (N : Node_Id) return Node_Id
5161 P : Node_Id;
5162 Decl : Node_Id;
5163 Spec : Node_Id;
5165 begin
5166 P := Parent (N);
5167 while Present (P) loop
5168 if Nkind (P) = N_Generic_Package_Declaration
5169 or else Nkind (P) = N_Generic_Subprogram_Declaration
5170 then
5171 return P;
5173 elsif Nkind (P) = N_Package_Body
5174 or else Nkind (P) = N_Subprogram_Body
5175 then
5176 Spec := Corresponding_Spec (P);
5178 if Present (Spec) then
5179 Decl := Unit_Declaration_Node (Spec);
5181 if Nkind (Decl) = N_Generic_Package_Declaration
5182 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5183 then
5184 return Decl;
5185 end if;
5186 end if;
5187 end if;
5189 P := Parent (P);
5190 end loop;
5192 return Empty;
5193 end Enclosing_Generic_Unit;
5195 -------------------------------
5196 -- Enclosing_Lib_Unit_Entity --
5197 -------------------------------
5199 function Enclosing_Lib_Unit_Entity
5200 (E : Entity_Id := Current_Scope) return Entity_Id
5202 Unit_Entity : Entity_Id;
5204 begin
5205 -- Look for enclosing library unit entity by following scope links.
5206 -- Equivalent to, but faster than indexing through the scope stack.
5208 Unit_Entity := E;
5209 while (Present (Scope (Unit_Entity))
5210 and then Scope (Unit_Entity) /= Standard_Standard)
5211 and not Is_Child_Unit (Unit_Entity)
5212 loop
5213 Unit_Entity := Scope (Unit_Entity);
5214 end loop;
5216 return Unit_Entity;
5217 end Enclosing_Lib_Unit_Entity;
5219 -----------------------
5220 -- Enclosing_Package --
5221 -----------------------
5223 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5224 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5226 begin
5227 if Dynamic_Scope = Standard_Standard then
5228 return Standard_Standard;
5230 elsif Dynamic_Scope = Empty then
5231 return Empty;
5233 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5234 E_Generic_Package)
5235 then
5236 return Dynamic_Scope;
5238 else
5239 return Enclosing_Package (Dynamic_Scope);
5240 end if;
5241 end Enclosing_Package;
5243 --------------------------
5244 -- Enclosing_Subprogram --
5245 --------------------------
5247 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5248 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5250 begin
5251 if Dynamic_Scope = Standard_Standard then
5252 return Empty;
5254 elsif Dynamic_Scope = Empty then
5255 return Empty;
5257 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5258 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5260 elsif Ekind (Dynamic_Scope) = E_Block
5261 or else Ekind (Dynamic_Scope) = E_Return_Statement
5262 then
5263 return Enclosing_Subprogram (Dynamic_Scope);
5265 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5266 return Get_Task_Body_Procedure (Dynamic_Scope);
5268 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5269 and then Present (Full_View (Dynamic_Scope))
5270 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5271 then
5272 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5274 -- No body is generated if the protected operation is eliminated
5276 elsif Convention (Dynamic_Scope) = Convention_Protected
5277 and then not Is_Eliminated (Dynamic_Scope)
5278 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5279 then
5280 return Protected_Body_Subprogram (Dynamic_Scope);
5282 else
5283 return Dynamic_Scope;
5284 end if;
5285 end Enclosing_Subprogram;
5287 ------------------------
5288 -- Ensure_Freeze_Node --
5289 ------------------------
5291 procedure Ensure_Freeze_Node (E : Entity_Id) is
5292 FN : Node_Id;
5293 begin
5294 if No (Freeze_Node (E)) then
5295 FN := Make_Freeze_Entity (Sloc (E));
5296 Set_Has_Delayed_Freeze (E);
5297 Set_Freeze_Node (E, FN);
5298 Set_Access_Types_To_Process (FN, No_Elist);
5299 Set_TSS_Elist (FN, No_Elist);
5300 Set_Entity (FN, E);
5301 end if;
5302 end Ensure_Freeze_Node;
5304 ----------------
5305 -- Enter_Name --
5306 ----------------
5308 procedure Enter_Name (Def_Id : Entity_Id) is
5309 C : constant Entity_Id := Current_Entity (Def_Id);
5310 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5311 S : constant Entity_Id := Current_Scope;
5313 begin
5314 Generate_Definition (Def_Id);
5316 -- Add new name to current scope declarations. Check for duplicate
5317 -- declaration, which may or may not be a genuine error.
5319 if Present (E) then
5321 -- Case of previous entity entered because of a missing declaration
5322 -- or else a bad subtype indication. Best is to use the new entity,
5323 -- and make the previous one invisible.
5325 if Etype (E) = Any_Type then
5326 Set_Is_Immediately_Visible (E, False);
5328 -- Case of renaming declaration constructed for package instances.
5329 -- if there is an explicit declaration with the same identifier,
5330 -- the renaming is not immediately visible any longer, but remains
5331 -- visible through selected component notation.
5333 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5334 and then not Comes_From_Source (E)
5335 then
5336 Set_Is_Immediately_Visible (E, False);
5338 -- The new entity may be the package renaming, which has the same
5339 -- same name as a generic formal which has been seen already.
5341 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5342 and then not Comes_From_Source (Def_Id)
5343 then
5344 Set_Is_Immediately_Visible (E, False);
5346 -- For a fat pointer corresponding to a remote access to subprogram,
5347 -- we use the same identifier as the RAS type, so that the proper
5348 -- name appears in the stub. This type is only retrieved through
5349 -- the RAS type and never by visibility, and is not added to the
5350 -- visibility list (see below).
5352 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
5353 and then Ekind (Def_Id) = E_Record_Type
5354 and then Present (Corresponding_Remote_Type (Def_Id))
5355 then
5356 null;
5358 -- Case of an implicit operation or derived literal. The new entity
5359 -- hides the implicit one, which is removed from all visibility,
5360 -- i.e. the entity list of its scope, and homonym chain of its name.
5362 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
5363 or else Is_Internal (E)
5364 then
5365 declare
5366 Prev : Entity_Id;
5367 Prev_Vis : Entity_Id;
5368 Decl : constant Node_Id := Parent (E);
5370 begin
5371 -- If E is an implicit declaration, it cannot be the first
5372 -- entity in the scope.
5374 Prev := First_Entity (Current_Scope);
5375 while Present (Prev) and then Next_Entity (Prev) /= E loop
5376 Next_Entity (Prev);
5377 end loop;
5379 if No (Prev) then
5381 -- If E is not on the entity chain of the current scope,
5382 -- it is an implicit declaration in the generic formal
5383 -- part of a generic subprogram. When analyzing the body,
5384 -- the generic formals are visible but not on the entity
5385 -- chain of the subprogram. The new entity will become
5386 -- the visible one in the body.
5388 pragma Assert
5389 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
5390 null;
5392 else
5393 Set_Next_Entity (Prev, Next_Entity (E));
5395 if No (Next_Entity (Prev)) then
5396 Set_Last_Entity (Current_Scope, Prev);
5397 end if;
5399 if E = Current_Entity (E) then
5400 Prev_Vis := Empty;
5402 else
5403 Prev_Vis := Current_Entity (E);
5404 while Homonym (Prev_Vis) /= E loop
5405 Prev_Vis := Homonym (Prev_Vis);
5406 end loop;
5407 end if;
5409 if Present (Prev_Vis) then
5411 -- Skip E in the visibility chain
5413 Set_Homonym (Prev_Vis, Homonym (E));
5415 else
5416 Set_Name_Entity_Id (Chars (E), Homonym (E));
5417 end if;
5418 end if;
5419 end;
5421 -- This section of code could use a comment ???
5423 elsif Present (Etype (E))
5424 and then Is_Concurrent_Type (Etype (E))
5425 and then E = Def_Id
5426 then
5427 return;
5429 -- If the homograph is a protected component renaming, it should not
5430 -- be hiding the current entity. Such renamings are treated as weak
5431 -- declarations.
5433 elsif Is_Prival (E) then
5434 Set_Is_Immediately_Visible (E, False);
5436 -- In this case the current entity is a protected component renaming.
5437 -- Perform minimal decoration by setting the scope and return since
5438 -- the prival should not be hiding other visible entities.
5440 elsif Is_Prival (Def_Id) then
5441 Set_Scope (Def_Id, Current_Scope);
5442 return;
5444 -- Analogous to privals, the discriminal generated for an entry index
5445 -- parameter acts as a weak declaration. Perform minimal decoration
5446 -- to avoid bogus errors.
5448 elsif Is_Discriminal (Def_Id)
5449 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
5450 then
5451 Set_Scope (Def_Id, Current_Scope);
5452 return;
5454 -- In the body or private part of an instance, a type extension may
5455 -- introduce a component with the same name as that of an actual. The
5456 -- legality rule is not enforced, but the semantics of the full type
5457 -- with two components of same name are not clear at this point???
5459 elsif In_Instance_Not_Visible then
5460 null;
5462 -- When compiling a package body, some child units may have become
5463 -- visible. They cannot conflict with local entities that hide them.
5465 elsif Is_Child_Unit (E)
5466 and then In_Open_Scopes (Scope (E))
5467 and then not Is_Immediately_Visible (E)
5468 then
5469 null;
5471 -- Conversely, with front-end inlining we may compile the parent body
5472 -- first, and a child unit subsequently. The context is now the
5473 -- parent spec, and body entities are not visible.
5475 elsif Is_Child_Unit (Def_Id)
5476 and then Is_Package_Body_Entity (E)
5477 and then not In_Package_Body (Current_Scope)
5478 then
5479 null;
5481 -- Case of genuine duplicate declaration
5483 else
5484 Error_Msg_Sloc := Sloc (E);
5486 -- If the previous declaration is an incomplete type declaration
5487 -- this may be an attempt to complete it with a private type. The
5488 -- following avoids confusing cascaded errors.
5490 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
5491 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
5492 then
5493 Error_Msg_N
5494 ("incomplete type cannot be completed with a private " &
5495 "declaration", Parent (Def_Id));
5496 Set_Is_Immediately_Visible (E, False);
5497 Set_Full_View (E, Def_Id);
5499 -- An inherited component of a record conflicts with a new
5500 -- discriminant. The discriminant is inserted first in the scope,
5501 -- but the error should be posted on it, not on the component.
5503 elsif Ekind (E) = E_Discriminant
5504 and then Present (Scope (Def_Id))
5505 and then Scope (Def_Id) /= Current_Scope
5506 then
5507 Error_Msg_Sloc := Sloc (Def_Id);
5508 Error_Msg_N ("& conflicts with declaration#", E);
5509 return;
5511 -- If the name of the unit appears in its own context clause, a
5512 -- dummy package with the name has already been created, and the
5513 -- error emitted. Try to continue quietly.
5515 elsif Error_Posted (E)
5516 and then Sloc (E) = No_Location
5517 and then Nkind (Parent (E)) = N_Package_Specification
5518 and then Current_Scope = Standard_Standard
5519 then
5520 Set_Scope (Def_Id, Current_Scope);
5521 return;
5523 else
5524 Error_Msg_N ("& conflicts with declaration#", Def_Id);
5526 -- Avoid cascaded messages with duplicate components in
5527 -- derived types.
5529 if Ekind_In (E, E_Component, E_Discriminant) then
5530 return;
5531 end if;
5532 end if;
5534 if Nkind (Parent (Parent (Def_Id))) =
5535 N_Generic_Subprogram_Declaration
5536 and then Def_Id =
5537 Defining_Entity (Specification (Parent (Parent (Def_Id))))
5538 then
5539 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
5540 end if;
5542 -- If entity is in standard, then we are in trouble, because it
5543 -- means that we have a library package with a duplicated name.
5544 -- That's hard to recover from, so abort.
5546 if S = Standard_Standard then
5547 raise Unrecoverable_Error;
5549 -- Otherwise we continue with the declaration. Having two
5550 -- identical declarations should not cause us too much trouble.
5552 else
5553 null;
5554 end if;
5555 end if;
5556 end if;
5558 -- If we fall through, declaration is OK, at least OK enough to continue
5560 -- If Def_Id is a discriminant or a record component we are in the midst
5561 -- of inheriting components in a derived record definition. Preserve
5562 -- their Ekind and Etype.
5564 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
5565 null;
5567 -- If a type is already set, leave it alone (happens when a type
5568 -- declaration is reanalyzed following a call to the optimizer).
5570 elsif Present (Etype (Def_Id)) then
5571 null;
5573 -- Otherwise, the kind E_Void insures that premature uses of the entity
5574 -- will be detected. Any_Type insures that no cascaded errors will occur
5576 else
5577 Set_Ekind (Def_Id, E_Void);
5578 Set_Etype (Def_Id, Any_Type);
5579 end if;
5581 -- Inherited discriminants and components in derived record types are
5582 -- immediately visible. Itypes are not.
5584 -- Unless the Itype is for a record type with a corresponding remote
5585 -- type (what is that about, it was not commented ???)
5587 if Ekind_In (Def_Id, E_Discriminant, E_Component)
5588 or else
5589 ((not Is_Record_Type (Def_Id)
5590 or else No (Corresponding_Remote_Type (Def_Id)))
5591 and then not Is_Itype (Def_Id))
5592 then
5593 Set_Is_Immediately_Visible (Def_Id);
5594 Set_Current_Entity (Def_Id);
5595 end if;
5597 Set_Homonym (Def_Id, C);
5598 Append_Entity (Def_Id, S);
5599 Set_Public_Status (Def_Id);
5601 -- Declaring a homonym is not allowed in SPARK ...
5603 if Present (C) and then Restriction_Check_Required (SPARK_05) then
5604 declare
5605 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
5606 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
5607 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
5609 begin
5610 -- ... unless the new declaration is in a subprogram, and the
5611 -- visible declaration is a variable declaration or a parameter
5612 -- specification outside that subprogram.
5614 if Present (Enclosing_Subp)
5615 and then Nkind_In (Parent (C), N_Object_Declaration,
5616 N_Parameter_Specification)
5617 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
5618 then
5619 null;
5621 -- ... or the new declaration is in a package, and the visible
5622 -- declaration occurs outside that package.
5624 elsif Present (Enclosing_Pack)
5625 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
5626 then
5627 null;
5629 -- ... or the new declaration is a component declaration in a
5630 -- record type definition.
5632 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
5633 null;
5635 -- Don't issue error for non-source entities
5637 elsif Comes_From_Source (Def_Id)
5638 and then Comes_From_Source (C)
5639 then
5640 Error_Msg_Sloc := Sloc (C);
5641 Check_SPARK_05_Restriction
5642 ("redeclaration of identifier &#", Def_Id);
5643 end if;
5644 end;
5645 end if;
5647 -- Warn if new entity hides an old one
5649 if Warn_On_Hiding and then Present (C)
5651 -- Don't warn for record components since they always have a well
5652 -- defined scope which does not confuse other uses. Note that in
5653 -- some cases, Ekind has not been set yet.
5655 and then Ekind (C) /= E_Component
5656 and then Ekind (C) /= E_Discriminant
5657 and then Nkind (Parent (C)) /= N_Component_Declaration
5658 and then Ekind (Def_Id) /= E_Component
5659 and then Ekind (Def_Id) /= E_Discriminant
5660 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
5662 -- Don't warn for one character variables. It is too common to use
5663 -- such variables as locals and will just cause too many false hits.
5665 and then Length_Of_Name (Chars (C)) /= 1
5667 -- Don't warn for non-source entities
5669 and then Comes_From_Source (C)
5670 and then Comes_From_Source (Def_Id)
5672 -- Don't warn unless entity in question is in extended main source
5674 and then In_Extended_Main_Source_Unit (Def_Id)
5676 -- Finally, the hidden entity must be either immediately visible or
5677 -- use visible (i.e. from a used package).
5679 and then
5680 (Is_Immediately_Visible (C)
5681 or else
5682 Is_Potentially_Use_Visible (C))
5683 then
5684 Error_Msg_Sloc := Sloc (C);
5685 Error_Msg_N ("declaration hides &#?h?", Def_Id);
5686 end if;
5687 end Enter_Name;
5689 ---------------
5690 -- Entity_Of --
5691 ---------------
5693 function Entity_Of (N : Node_Id) return Entity_Id is
5694 Id : Entity_Id;
5696 begin
5697 Id := Empty;
5699 if Is_Entity_Name (N) then
5700 Id := Entity (N);
5702 -- Follow a possible chain of renamings to reach the root renamed
5703 -- object.
5705 while Present (Id) and then Present (Renamed_Object (Id)) loop
5706 if Is_Entity_Name (Renamed_Object (Id)) then
5707 Id := Entity (Renamed_Object (Id));
5708 else
5709 Id := Empty;
5710 exit;
5711 end if;
5712 end loop;
5713 end if;
5715 return Id;
5716 end Entity_Of;
5718 --------------------------
5719 -- Explain_Limited_Type --
5720 --------------------------
5722 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
5723 C : Entity_Id;
5725 begin
5726 -- For array, component type must be limited
5728 if Is_Array_Type (T) then
5729 Error_Msg_Node_2 := T;
5730 Error_Msg_NE
5731 ("\component type& of type& is limited", N, Component_Type (T));
5732 Explain_Limited_Type (Component_Type (T), N);
5734 elsif Is_Record_Type (T) then
5736 -- No need for extra messages if explicit limited record
5738 if Is_Limited_Record (Base_Type (T)) then
5739 return;
5740 end if;
5742 -- Otherwise find a limited component. Check only components that
5743 -- come from source, or inherited components that appear in the
5744 -- source of the ancestor.
5746 C := First_Component (T);
5747 while Present (C) loop
5748 if Is_Limited_Type (Etype (C))
5749 and then
5750 (Comes_From_Source (C)
5751 or else
5752 (Present (Original_Record_Component (C))
5753 and then
5754 Comes_From_Source (Original_Record_Component (C))))
5755 then
5756 Error_Msg_Node_2 := T;
5757 Error_Msg_NE ("\component& of type& has limited type", N, C);
5758 Explain_Limited_Type (Etype (C), N);
5759 return;
5760 end if;
5762 Next_Component (C);
5763 end loop;
5765 -- The type may be declared explicitly limited, even if no component
5766 -- of it is limited, in which case we fall out of the loop.
5767 return;
5768 end if;
5769 end Explain_Limited_Type;
5771 -----------------
5772 -- Find_Actual --
5773 -----------------
5775 procedure Find_Actual
5776 (N : Node_Id;
5777 Formal : out Entity_Id;
5778 Call : out Node_Id)
5780 Parnt : constant Node_Id := Parent (N);
5781 Actual : Node_Id;
5783 begin
5784 if Nkind_In (Parnt, N_Indexed_Component, N_Selected_Component)
5785 and then N = Prefix (Parnt)
5786 then
5787 Find_Actual (Parnt, Formal, Call);
5788 return;
5790 elsif Nkind (Parnt) = N_Parameter_Association
5791 and then N = Explicit_Actual_Parameter (Parnt)
5792 then
5793 Call := Parent (Parnt);
5795 elsif Nkind (Parnt) in N_Subprogram_Call then
5796 Call := Parnt;
5798 else
5799 Formal := Empty;
5800 Call := Empty;
5801 return;
5802 end if;
5804 -- If we have a call to a subprogram look for the parameter. Note that
5805 -- we exclude overloaded calls, since we don't know enough to be sure
5806 -- of giving the right answer in this case.
5808 if Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
5809 and then Is_Entity_Name (Name (Call))
5810 and then Present (Entity (Name (Call)))
5811 and then Is_Overloadable (Entity (Name (Call)))
5812 and then not Is_Overloaded (Name (Call))
5813 then
5814 -- Fall here if we are definitely a parameter
5816 Actual := First_Actual (Call);
5817 Formal := First_Formal (Entity (Name (Call)));
5818 while Present (Formal) and then Present (Actual) loop
5819 if Actual = N then
5820 return;
5822 -- An actual that is the prefix in a prefixed call may have
5823 -- been rewritten in the call, after the deferred reference
5824 -- was collected. Check if sloc and kinds and names match.
5826 elsif Sloc (Actual) = Sloc (N)
5827 and then Nkind (Actual) = N_Identifier
5828 and then Nkind (Actual) = Nkind (N)
5829 and then Chars (Actual) = Chars (N)
5830 then
5831 return;
5833 else
5834 Actual := Next_Actual (Actual);
5835 Formal := Next_Formal (Formal);
5836 end if;
5837 end loop;
5838 end if;
5840 -- Fall through here if we did not find matching actual
5842 Formal := Empty;
5843 Call := Empty;
5844 end Find_Actual;
5846 ---------------------------
5847 -- Find_Body_Discriminal --
5848 ---------------------------
5850 function Find_Body_Discriminal
5851 (Spec_Discriminant : Entity_Id) return Entity_Id
5853 Tsk : Entity_Id;
5854 Disc : Entity_Id;
5856 begin
5857 -- If expansion is suppressed, then the scope can be the concurrent type
5858 -- itself rather than a corresponding concurrent record type.
5860 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
5861 Tsk := Scope (Spec_Discriminant);
5863 else
5864 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
5866 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
5867 end if;
5869 -- Find discriminant of original concurrent type, and use its current
5870 -- discriminal, which is the renaming within the task/protected body.
5872 Disc := First_Discriminant (Tsk);
5873 while Present (Disc) loop
5874 if Chars (Disc) = Chars (Spec_Discriminant) then
5875 return Discriminal (Disc);
5876 end if;
5878 Next_Discriminant (Disc);
5879 end loop;
5881 -- That loop should always succeed in finding a matching entry and
5882 -- returning. Fatal error if not.
5884 raise Program_Error;
5885 end Find_Body_Discriminal;
5887 -------------------------------------
5888 -- Find_Corresponding_Discriminant --
5889 -------------------------------------
5891 function Find_Corresponding_Discriminant
5892 (Id : Node_Id;
5893 Typ : Entity_Id) return Entity_Id
5895 Par_Disc : Entity_Id;
5896 Old_Disc : Entity_Id;
5897 New_Disc : Entity_Id;
5899 begin
5900 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
5902 -- The original type may currently be private, and the discriminant
5903 -- only appear on its full view.
5905 if Is_Private_Type (Scope (Par_Disc))
5906 and then not Has_Discriminants (Scope (Par_Disc))
5907 and then Present (Full_View (Scope (Par_Disc)))
5908 then
5909 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
5910 else
5911 Old_Disc := First_Discriminant (Scope (Par_Disc));
5912 end if;
5914 if Is_Class_Wide_Type (Typ) then
5915 New_Disc := First_Discriminant (Root_Type (Typ));
5916 else
5917 New_Disc := First_Discriminant (Typ);
5918 end if;
5920 while Present (Old_Disc) and then Present (New_Disc) loop
5921 if Old_Disc = Par_Disc then
5922 return New_Disc;
5923 end if;
5925 Next_Discriminant (Old_Disc);
5926 Next_Discriminant (New_Disc);
5927 end loop;
5929 -- Should always find it
5931 raise Program_Error;
5932 end Find_Corresponding_Discriminant;
5934 ----------------------------------
5935 -- Find_Enclosing_Iterator_Loop --
5936 ----------------------------------
5938 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
5939 Constr : Node_Id;
5940 S : Entity_Id;
5942 begin
5943 -- Traverse the scope chain looking for an iterator loop. Such loops are
5944 -- usually transformed into blocks, hence the use of Original_Node.
5946 S := Id;
5947 while Present (S) and then S /= Standard_Standard loop
5948 if Ekind (S) = E_Loop
5949 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
5950 then
5951 Constr := Original_Node (Label_Construct (Parent (S)));
5953 if Nkind (Constr) = N_Loop_Statement
5954 and then Present (Iteration_Scheme (Constr))
5955 and then Nkind (Iterator_Specification
5956 (Iteration_Scheme (Constr))) =
5957 N_Iterator_Specification
5958 then
5959 return S;
5960 end if;
5961 end if;
5963 S := Scope (S);
5964 end loop;
5966 return Empty;
5967 end Find_Enclosing_Iterator_Loop;
5969 ------------------------------------
5970 -- Find_Loop_In_Conditional_Block --
5971 ------------------------------------
5973 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
5974 Stmt : Node_Id;
5976 begin
5977 Stmt := N;
5979 if Nkind (Stmt) = N_If_Statement then
5980 Stmt := First (Then_Statements (Stmt));
5981 end if;
5983 pragma Assert (Nkind (Stmt) = N_Block_Statement);
5985 -- Inspect the statements of the conditional block. In general the loop
5986 -- should be the first statement in the statement sequence of the block,
5987 -- but the finalization machinery may have introduced extra object
5988 -- declarations.
5990 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
5991 while Present (Stmt) loop
5992 if Nkind (Stmt) = N_Loop_Statement then
5993 return Stmt;
5994 end if;
5996 Next (Stmt);
5997 end loop;
5999 -- The expansion of attribute 'Loop_Entry produced a malformed block
6001 raise Program_Error;
6002 end Find_Loop_In_Conditional_Block;
6004 --------------------------
6005 -- Find_Overlaid_Entity --
6006 --------------------------
6008 procedure Find_Overlaid_Entity
6009 (N : Node_Id;
6010 Ent : out Entity_Id;
6011 Off : out Boolean)
6013 Expr : Node_Id;
6015 begin
6016 -- We are looking for one of the two following forms:
6018 -- for X'Address use Y'Address
6020 -- or
6022 -- Const : constant Address := expr;
6023 -- ...
6024 -- for X'Address use Const;
6026 -- In the second case, the expr is either Y'Address, or recursively a
6027 -- constant that eventually references Y'Address.
6029 Ent := Empty;
6030 Off := False;
6032 if Nkind (N) = N_Attribute_Definition_Clause
6033 and then Chars (N) = Name_Address
6034 then
6035 Expr := Expression (N);
6037 -- This loop checks the form of the expression for Y'Address,
6038 -- using recursion to deal with intermediate constants.
6040 loop
6041 -- Check for Y'Address
6043 if Nkind (Expr) = N_Attribute_Reference
6044 and then Attribute_Name (Expr) = Name_Address
6045 then
6046 Expr := Prefix (Expr);
6047 exit;
6049 -- Check for Const where Const is a constant entity
6051 elsif Is_Entity_Name (Expr)
6052 and then Ekind (Entity (Expr)) = E_Constant
6053 then
6054 Expr := Constant_Value (Entity (Expr));
6056 -- Anything else does not need checking
6058 else
6059 return;
6060 end if;
6061 end loop;
6063 -- This loop checks the form of the prefix for an entity, using
6064 -- recursion to deal with intermediate components.
6066 loop
6067 -- Check for Y where Y is an entity
6069 if Is_Entity_Name (Expr) then
6070 Ent := Entity (Expr);
6071 return;
6073 -- Check for components
6075 elsif
6076 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6077 then
6078 Expr := Prefix (Expr);
6079 Off := True;
6081 -- Anything else does not need checking
6083 else
6084 return;
6085 end if;
6086 end loop;
6087 end if;
6088 end Find_Overlaid_Entity;
6090 -------------------------
6091 -- Find_Parameter_Type --
6092 -------------------------
6094 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6095 begin
6096 if Nkind (Param) /= N_Parameter_Specification then
6097 return Empty;
6099 -- For an access parameter, obtain the type from the formal entity
6100 -- itself, because access to subprogram nodes do not carry a type.
6101 -- Shouldn't we always use the formal entity ???
6103 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6104 return Etype (Defining_Identifier (Param));
6106 else
6107 return Etype (Parameter_Type (Param));
6108 end if;
6109 end Find_Parameter_Type;
6111 -----------------------------------
6112 -- Find_Placement_In_State_Space --
6113 -----------------------------------
6115 procedure Find_Placement_In_State_Space
6116 (Item_Id : Entity_Id;
6117 Placement : out State_Space_Kind;
6118 Pack_Id : out Entity_Id)
6120 Context : Entity_Id;
6122 begin
6123 -- Assume that the item does not appear in the state space of a package
6125 Placement := Not_In_Package;
6126 Pack_Id := Empty;
6128 -- Climb the scope stack and examine the enclosing context
6130 Context := Scope (Item_Id);
6131 while Present (Context) and then Context /= Standard_Standard loop
6132 if Ekind (Context) = E_Package then
6133 Pack_Id := Context;
6135 -- A package body is a cut off point for the traversal as the item
6136 -- cannot be visible to the outside from this point on. Note that
6137 -- this test must be done first as a body is also classified as a
6138 -- private part.
6140 if In_Package_Body (Context) then
6141 Placement := Body_State_Space;
6142 return;
6144 -- The private part of a package is a cut off point for the
6145 -- traversal as the item cannot be visible to the outside from
6146 -- this point on.
6148 elsif In_Private_Part (Context) then
6149 Placement := Private_State_Space;
6150 return;
6152 -- When the item appears in the visible state space of a package,
6153 -- continue to climb the scope stack as this may not be the final
6154 -- state space.
6156 else
6157 Placement := Visible_State_Space;
6159 -- The visible state space of a child unit acts as the proper
6160 -- placement of an item.
6162 if Is_Child_Unit (Context) then
6163 return;
6164 end if;
6165 end if;
6167 -- The item or its enclosing package appear in a construct that has
6168 -- no state space.
6170 else
6171 Placement := Not_In_Package;
6172 return;
6173 end if;
6175 Context := Scope (Context);
6176 end loop;
6177 end Find_Placement_In_State_Space;
6179 ------------------------
6180 -- Find_Specific_Type --
6181 ------------------------
6183 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6184 Typ : Entity_Id := Root_Type (CW);
6186 begin
6187 if Ekind (Typ) = E_Incomplete_Type then
6188 if From_Limited_With (Typ) then
6189 Typ := Non_Limited_View (Typ);
6190 else
6191 Typ := Full_View (Typ);
6192 end if;
6193 end if;
6195 if Is_Private_Type (Typ)
6196 and then not Is_Tagged_Type (Typ)
6197 and then Present (Full_View (Typ))
6198 then
6199 return Full_View (Typ);
6200 else
6201 return Typ;
6202 end if;
6203 end Find_Specific_Type;
6205 -----------------------------
6206 -- Find_Static_Alternative --
6207 -----------------------------
6209 function Find_Static_Alternative (N : Node_Id) return Node_Id is
6210 Expr : constant Node_Id := Expression (N);
6211 Val : constant Uint := Expr_Value (Expr);
6212 Alt : Node_Id;
6213 Choice : Node_Id;
6215 begin
6216 Alt := First (Alternatives (N));
6218 Search : loop
6219 if Nkind (Alt) /= N_Pragma then
6220 Choice := First (Discrete_Choices (Alt));
6221 while Present (Choice) loop
6223 -- Others choice, always matches
6225 if Nkind (Choice) = N_Others_Choice then
6226 exit Search;
6228 -- Range, check if value is in the range
6230 elsif Nkind (Choice) = N_Range then
6231 exit Search when
6232 Val >= Expr_Value (Low_Bound (Choice))
6233 and then
6234 Val <= Expr_Value (High_Bound (Choice));
6236 -- Choice is a subtype name. Note that we know it must
6237 -- be a static subtype, since otherwise it would have
6238 -- been diagnosed as illegal.
6240 elsif Is_Entity_Name (Choice) and then Is_Type (Entity (Choice))
6241 then
6242 exit Search when Is_In_Range (Expr, Etype (Choice),
6243 Assume_Valid => False);
6245 -- Choice is a subtype indication
6247 elsif Nkind (Choice) = N_Subtype_Indication then
6248 declare
6249 C : constant Node_Id := Constraint (Choice);
6250 R : constant Node_Id := Range_Expression (C);
6252 begin
6253 exit Search when
6254 Val >= Expr_Value (Low_Bound (R))
6255 and then
6256 Val <= Expr_Value (High_Bound (R));
6257 end;
6259 -- Choice is a simple expression
6261 else
6262 exit Search when Val = Expr_Value (Choice);
6263 end if;
6265 Next (Choice);
6266 end loop;
6267 end if;
6269 Next (Alt);
6270 pragma Assert (Present (Alt));
6271 end loop Search;
6273 -- The above loop *must* terminate by finding a match, since
6274 -- we know the case statement is valid, and the value of the
6275 -- expression is known at compile time. When we fall out of
6276 -- the loop, Alt points to the alternative that we know will
6277 -- be selected at run time.
6279 return Alt;
6280 end Find_Static_Alternative;
6282 ------------------
6283 -- First_Actual --
6284 ------------------
6286 function First_Actual (Node : Node_Id) return Node_Id is
6287 N : Node_Id;
6289 begin
6290 if No (Parameter_Associations (Node)) then
6291 return Empty;
6292 end if;
6294 N := First (Parameter_Associations (Node));
6296 if Nkind (N) = N_Parameter_Association then
6297 return First_Named_Actual (Node);
6298 else
6299 return N;
6300 end if;
6301 end First_Actual;
6303 -----------------------
6304 -- Gather_Components --
6305 -----------------------
6307 procedure Gather_Components
6308 (Typ : Entity_Id;
6309 Comp_List : Node_Id;
6310 Governed_By : List_Id;
6311 Into : Elist_Id;
6312 Report_Errors : out Boolean)
6314 Assoc : Node_Id;
6315 Variant : Node_Id;
6316 Discrete_Choice : Node_Id;
6317 Comp_Item : Node_Id;
6319 Discrim : Entity_Id;
6320 Discrim_Name : Node_Id;
6321 Discrim_Value : Node_Id;
6323 begin
6324 Report_Errors := False;
6326 if No (Comp_List) or else Null_Present (Comp_List) then
6327 return;
6329 elsif Present (Component_Items (Comp_List)) then
6330 Comp_Item := First (Component_Items (Comp_List));
6332 else
6333 Comp_Item := Empty;
6334 end if;
6336 while Present (Comp_Item) loop
6338 -- Skip the tag of a tagged record, the interface tags, as well
6339 -- as all items that are not user components (anonymous types,
6340 -- rep clauses, Parent field, controller field).
6342 if Nkind (Comp_Item) = N_Component_Declaration then
6343 declare
6344 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
6345 begin
6346 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
6347 Append_Elmt (Comp, Into);
6348 end if;
6349 end;
6350 end if;
6352 Next (Comp_Item);
6353 end loop;
6355 if No (Variant_Part (Comp_List)) then
6356 return;
6357 else
6358 Discrim_Name := Name (Variant_Part (Comp_List));
6359 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
6360 end if;
6362 -- Look for the discriminant that governs this variant part.
6363 -- The discriminant *must* be in the Governed_By List
6365 Assoc := First (Governed_By);
6366 Find_Constraint : loop
6367 Discrim := First (Choices (Assoc));
6368 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
6369 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
6370 and then
6371 Chars (Corresponding_Discriminant (Entity (Discrim))) =
6372 Chars (Discrim_Name))
6373 or else Chars (Original_Record_Component (Entity (Discrim)))
6374 = Chars (Discrim_Name);
6376 if No (Next (Assoc)) then
6377 if not Is_Constrained (Typ)
6378 and then Is_Derived_Type (Typ)
6379 and then Present (Stored_Constraint (Typ))
6380 then
6381 -- If the type is a tagged type with inherited discriminants,
6382 -- use the stored constraint on the parent in order to find
6383 -- the values of discriminants that are otherwise hidden by an
6384 -- explicit constraint. Renamed discriminants are handled in
6385 -- the code above.
6387 -- If several parent discriminants are renamed by a single
6388 -- discriminant of the derived type, the call to obtain the
6389 -- Corresponding_Discriminant field only retrieves the last
6390 -- of them. We recover the constraint on the others from the
6391 -- Stored_Constraint as well.
6393 declare
6394 D : Entity_Id;
6395 C : Elmt_Id;
6397 begin
6398 D := First_Discriminant (Etype (Typ));
6399 C := First_Elmt (Stored_Constraint (Typ));
6400 while Present (D) and then Present (C) loop
6401 if Chars (Discrim_Name) = Chars (D) then
6402 if Is_Entity_Name (Node (C))
6403 and then Entity (Node (C)) = Entity (Discrim)
6404 then
6405 -- D is renamed by Discrim, whose value is given in
6406 -- Assoc.
6408 null;
6410 else
6411 Assoc :=
6412 Make_Component_Association (Sloc (Typ),
6413 New_List
6414 (New_Occurrence_Of (D, Sloc (Typ))),
6415 Duplicate_Subexpr_No_Checks (Node (C)));
6416 end if;
6417 exit Find_Constraint;
6418 end if;
6420 Next_Discriminant (D);
6421 Next_Elmt (C);
6422 end loop;
6423 end;
6424 end if;
6425 end if;
6427 if No (Next (Assoc)) then
6428 Error_Msg_NE (" missing value for discriminant&",
6429 First (Governed_By), Discrim_Name);
6430 Report_Errors := True;
6431 return;
6432 end if;
6434 Next (Assoc);
6435 end loop Find_Constraint;
6437 Discrim_Value := Expression (Assoc);
6439 if not Is_OK_Static_Expression (Discrim_Value) then
6440 Error_Msg_FE
6441 ("value for discriminant & must be static!",
6442 Discrim_Value, Discrim);
6443 Why_Not_Static (Discrim_Value);
6444 Report_Errors := True;
6445 return;
6446 end if;
6448 Search_For_Discriminant_Value : declare
6449 Low : Node_Id;
6450 High : Node_Id;
6452 UI_High : Uint;
6453 UI_Low : Uint;
6454 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
6456 begin
6457 Find_Discrete_Value : while Present (Variant) loop
6458 Discrete_Choice := First (Discrete_Choices (Variant));
6459 while Present (Discrete_Choice) loop
6460 exit Find_Discrete_Value when
6461 Nkind (Discrete_Choice) = N_Others_Choice;
6463 Get_Index_Bounds (Discrete_Choice, Low, High);
6465 UI_Low := Expr_Value (Low);
6466 UI_High := Expr_Value (High);
6468 exit Find_Discrete_Value when
6469 UI_Low <= UI_Discrim_Value
6470 and then
6471 UI_High >= UI_Discrim_Value;
6473 Next (Discrete_Choice);
6474 end loop;
6476 Next_Non_Pragma (Variant);
6477 end loop Find_Discrete_Value;
6478 end Search_For_Discriminant_Value;
6480 if No (Variant) then
6481 Error_Msg_NE
6482 ("value of discriminant & is out of range", Discrim_Value, Discrim);
6483 Report_Errors := True;
6484 return;
6485 end if;
6487 -- If we have found the corresponding choice, recursively add its
6488 -- components to the Into list.
6490 Gather_Components
6491 (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
6492 end Gather_Components;
6494 ------------------------
6495 -- Get_Actual_Subtype --
6496 ------------------------
6498 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
6499 Typ : constant Entity_Id := Etype (N);
6500 Utyp : Entity_Id := Underlying_Type (Typ);
6501 Decl : Node_Id;
6502 Atyp : Entity_Id;
6504 begin
6505 if No (Utyp) then
6506 Utyp := Typ;
6507 end if;
6509 -- If what we have is an identifier that references a subprogram
6510 -- formal, or a variable or constant object, then we get the actual
6511 -- subtype from the referenced entity if one has been built.
6513 if Nkind (N) = N_Identifier
6514 and then
6515 (Is_Formal (Entity (N))
6516 or else Ekind (Entity (N)) = E_Constant
6517 or else Ekind (Entity (N)) = E_Variable)
6518 and then Present (Actual_Subtype (Entity (N)))
6519 then
6520 return Actual_Subtype (Entity (N));
6522 -- Actual subtype of unchecked union is always itself. We never need
6523 -- the "real" actual subtype. If we did, we couldn't get it anyway
6524 -- because the discriminant is not available. The restrictions on
6525 -- Unchecked_Union are designed to make sure that this is OK.
6527 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
6528 return Typ;
6530 -- Here for the unconstrained case, we must find actual subtype
6531 -- No actual subtype is available, so we must build it on the fly.
6533 -- Checking the type, not the underlying type, for constrainedness
6534 -- seems to be necessary. Maybe all the tests should be on the type???
6536 elsif (not Is_Constrained (Typ))
6537 and then (Is_Array_Type (Utyp)
6538 or else (Is_Record_Type (Utyp)
6539 and then Has_Discriminants (Utyp)))
6540 and then not Has_Unknown_Discriminants (Utyp)
6541 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
6542 then
6543 -- Nothing to do if in spec expression (why not???)
6545 if In_Spec_Expression then
6546 return Typ;
6548 elsif Is_Private_Type (Typ)
6549 and then not Has_Discriminants (Typ)
6550 then
6551 -- If the type has no discriminants, there is no subtype to
6552 -- build, even if the underlying type is discriminated.
6554 return Typ;
6556 -- Else build the actual subtype
6558 else
6559 Decl := Build_Actual_Subtype (Typ, N);
6560 Atyp := Defining_Identifier (Decl);
6562 -- If Build_Actual_Subtype generated a new declaration then use it
6564 if Atyp /= Typ then
6566 -- The actual subtype is an Itype, so analyze the declaration,
6567 -- but do not attach it to the tree, to get the type defined.
6569 Set_Parent (Decl, N);
6570 Set_Is_Itype (Atyp);
6571 Analyze (Decl, Suppress => All_Checks);
6572 Set_Associated_Node_For_Itype (Atyp, N);
6573 Set_Has_Delayed_Freeze (Atyp, False);
6575 -- We need to freeze the actual subtype immediately. This is
6576 -- needed, because otherwise this Itype will not get frozen
6577 -- at all, and it is always safe to freeze on creation because
6578 -- any associated types must be frozen at this point.
6580 Freeze_Itype (Atyp, N);
6581 return Atyp;
6583 -- Otherwise we did not build a declaration, so return original
6585 else
6586 return Typ;
6587 end if;
6588 end if;
6590 -- For all remaining cases, the actual subtype is the same as
6591 -- the nominal type.
6593 else
6594 return Typ;
6595 end if;
6596 end Get_Actual_Subtype;
6598 -------------------------------------
6599 -- Get_Actual_Subtype_If_Available --
6600 -------------------------------------
6602 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
6603 Typ : constant Entity_Id := Etype (N);
6605 begin
6606 -- If what we have is an identifier that references a subprogram
6607 -- formal, or a variable or constant object, then we get the actual
6608 -- subtype from the referenced entity if one has been built.
6610 if Nkind (N) = N_Identifier
6611 and then
6612 (Is_Formal (Entity (N))
6613 or else Ekind (Entity (N)) = E_Constant
6614 or else Ekind (Entity (N)) = E_Variable)
6615 and then Present (Actual_Subtype (Entity (N)))
6616 then
6617 return Actual_Subtype (Entity (N));
6619 -- Otherwise the Etype of N is returned unchanged
6621 else
6622 return Typ;
6623 end if;
6624 end Get_Actual_Subtype_If_Available;
6626 ------------------------
6627 -- Get_Body_From_Stub --
6628 ------------------------
6630 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
6631 begin
6632 return Proper_Body (Unit (Library_Unit (N)));
6633 end Get_Body_From_Stub;
6635 ---------------------
6636 -- Get_Cursor_Type --
6637 ---------------------
6639 function Get_Cursor_Type
6640 (Aspect : Node_Id;
6641 Typ : Entity_Id) return Entity_Id
6643 Assoc : Node_Id;
6644 Func : Entity_Id;
6645 First_Op : Entity_Id;
6646 Cursor : Entity_Id;
6648 begin
6649 -- If error already detected, return
6651 if Error_Posted (Aspect) then
6652 return Any_Type;
6653 end if;
6655 -- The cursor type for an Iterable aspect is the return type of a
6656 -- non-overloaded First primitive operation. Locate association for
6657 -- First.
6659 Assoc := First (Component_Associations (Expression (Aspect)));
6660 First_Op := Any_Id;
6661 while Present (Assoc) loop
6662 if Chars (First (Choices (Assoc))) = Name_First then
6663 First_Op := Expression (Assoc);
6664 exit;
6665 end if;
6667 Next (Assoc);
6668 end loop;
6670 if First_Op = Any_Id then
6671 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
6672 return Any_Type;
6673 end if;
6675 Cursor := Any_Type;
6677 -- Locate function with desired name and profile in scope of type
6679 Func := First_Entity (Scope (Typ));
6680 while Present (Func) loop
6681 if Chars (Func) = Chars (First_Op)
6682 and then Ekind (Func) = E_Function
6683 and then Present (First_Formal (Func))
6684 and then Etype (First_Formal (Func)) = Typ
6685 and then No (Next_Formal (First_Formal (Func)))
6686 then
6687 if Cursor /= Any_Type then
6688 Error_Msg_N
6689 ("Operation First for iterable type must be unique", Aspect);
6690 return Any_Type;
6691 else
6692 Cursor := Etype (Func);
6693 end if;
6694 end if;
6696 Next_Entity (Func);
6697 end loop;
6699 -- If not found, no way to resolve remaining primitives.
6701 if Cursor = Any_Type then
6702 Error_Msg_N
6703 ("No legal primitive operation First for Iterable type", Aspect);
6704 end if;
6706 return Cursor;
6707 end Get_Cursor_Type;
6709 -------------------------------
6710 -- Get_Default_External_Name --
6711 -------------------------------
6713 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
6714 begin
6715 Get_Decoded_Name_String (Chars (E));
6717 if Opt.External_Name_Imp_Casing = Uppercase then
6718 Set_Casing (All_Upper_Case);
6719 else
6720 Set_Casing (All_Lower_Case);
6721 end if;
6723 return
6724 Make_String_Literal (Sloc (E),
6725 Strval => String_From_Name_Buffer);
6726 end Get_Default_External_Name;
6728 --------------------------
6729 -- Get_Enclosing_Object --
6730 --------------------------
6732 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
6733 begin
6734 if Is_Entity_Name (N) then
6735 return Entity (N);
6736 else
6737 case Nkind (N) is
6738 when N_Indexed_Component |
6739 N_Slice |
6740 N_Selected_Component =>
6742 -- If not generating code, a dereference may be left implicit.
6743 -- In thoses cases, return Empty.
6745 if Is_Access_Type (Etype (Prefix (N))) then
6746 return Empty;
6747 else
6748 return Get_Enclosing_Object (Prefix (N));
6749 end if;
6751 when N_Type_Conversion =>
6752 return Get_Enclosing_Object (Expression (N));
6754 when others =>
6755 return Empty;
6756 end case;
6757 end if;
6758 end Get_Enclosing_Object;
6760 ---------------------------
6761 -- Get_Enum_Lit_From_Pos --
6762 ---------------------------
6764 function Get_Enum_Lit_From_Pos
6765 (T : Entity_Id;
6766 Pos : Uint;
6767 Loc : Source_Ptr) return Node_Id
6769 Btyp : Entity_Id := Base_Type (T);
6770 Lit : Node_Id;
6772 begin
6773 -- In the case where the literal is of type Character, Wide_Character
6774 -- or Wide_Wide_Character or of a type derived from them, there needs
6775 -- to be some special handling since there is no explicit chain of
6776 -- literals to search. Instead, an N_Character_Literal node is created
6777 -- with the appropriate Char_Code and Chars fields.
6779 if Is_Standard_Character_Type (T) then
6780 Set_Character_Literal_Name (UI_To_CC (Pos));
6781 return
6782 Make_Character_Literal (Loc,
6783 Chars => Name_Find,
6784 Char_Literal_Value => Pos);
6786 -- For all other cases, we have a complete table of literals, and
6787 -- we simply iterate through the chain of literal until the one
6788 -- with the desired position value is found.
6791 else
6792 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
6793 Btyp := Full_View (Btyp);
6794 end if;
6796 Lit := First_Literal (Btyp);
6797 for J in 1 .. UI_To_Int (Pos) loop
6798 Next_Literal (Lit);
6799 end loop;
6801 return New_Occurrence_Of (Lit, Loc);
6802 end if;
6803 end Get_Enum_Lit_From_Pos;
6805 ---------------------------------
6806 -- Get_Ensures_From_CTC_Pragma --
6807 ---------------------------------
6809 function Get_Ensures_From_CTC_Pragma (N : Node_Id) return Node_Id is
6810 Args : constant List_Id := Pragma_Argument_Associations (N);
6811 Res : Node_Id;
6813 begin
6814 if List_Length (Args) = 4 then
6815 Res := Pick (Args, 4);
6817 elsif List_Length (Args) = 3 then
6818 Res := Pick (Args, 3);
6820 if Chars (Res) /= Name_Ensures then
6821 Res := Empty;
6822 end if;
6824 else
6825 Res := Empty;
6826 end if;
6828 return Res;
6829 end Get_Ensures_From_CTC_Pragma;
6831 ------------------------
6832 -- Get_Generic_Entity --
6833 ------------------------
6835 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
6836 Ent : constant Entity_Id := Entity (Name (N));
6837 begin
6838 if Present (Renamed_Object (Ent)) then
6839 return Renamed_Object (Ent);
6840 else
6841 return Ent;
6842 end if;
6843 end Get_Generic_Entity;
6845 -------------------------------------
6846 -- Get_Incomplete_View_Of_Ancestor --
6847 -------------------------------------
6849 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
6850 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
6851 Par_Scope : Entity_Id;
6852 Par_Type : Entity_Id;
6854 begin
6855 -- The incomplete view of an ancestor is only relevant for private
6856 -- derived types in child units.
6858 if not Is_Derived_Type (E)
6859 or else not Is_Child_Unit (Cur_Unit)
6860 then
6861 return Empty;
6863 else
6864 Par_Scope := Scope (Cur_Unit);
6865 if No (Par_Scope) then
6866 return Empty;
6867 end if;
6869 Par_Type := Etype (Base_Type (E));
6871 -- Traverse list of ancestor types until we find one declared in
6872 -- a parent or grandparent unit (two levels seem sufficient).
6874 while Present (Par_Type) loop
6875 if Scope (Par_Type) = Par_Scope
6876 or else Scope (Par_Type) = Scope (Par_Scope)
6877 then
6878 return Par_Type;
6880 elsif not Is_Derived_Type (Par_Type) then
6881 return Empty;
6883 else
6884 Par_Type := Etype (Base_Type (Par_Type));
6885 end if;
6886 end loop;
6888 -- If none found, there is no relevant ancestor type.
6890 return Empty;
6891 end if;
6892 end Get_Incomplete_View_Of_Ancestor;
6894 ----------------------
6895 -- Get_Index_Bounds --
6896 ----------------------
6898 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
6899 Kind : constant Node_Kind := Nkind (N);
6900 R : Node_Id;
6902 begin
6903 if Kind = N_Range then
6904 L := Low_Bound (N);
6905 H := High_Bound (N);
6907 elsif Kind = N_Subtype_Indication then
6908 R := Range_Expression (Constraint (N));
6910 if R = Error then
6911 L := Error;
6912 H := Error;
6913 return;
6915 else
6916 L := Low_Bound (Range_Expression (Constraint (N)));
6917 H := High_Bound (Range_Expression (Constraint (N)));
6918 end if;
6920 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
6921 if Error_Posted (Scalar_Range (Entity (N))) then
6922 L := Error;
6923 H := Error;
6925 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
6926 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
6928 else
6929 L := Low_Bound (Scalar_Range (Entity (N)));
6930 H := High_Bound (Scalar_Range (Entity (N)));
6931 end if;
6933 else
6934 -- N is an expression, indicating a range with one value
6936 L := N;
6937 H := N;
6938 end if;
6939 end Get_Index_Bounds;
6941 ---------------------------------
6942 -- Get_Iterable_Type_Primitive --
6943 ---------------------------------
6945 function Get_Iterable_Type_Primitive
6946 (Typ : Entity_Id;
6947 Nam : Name_Id) return Entity_Id
6949 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
6950 Assoc : Node_Id;
6952 begin
6953 if No (Funcs) then
6954 return Empty;
6956 else
6957 Assoc := First (Component_Associations (Funcs));
6958 while Present (Assoc) loop
6959 if Chars (First (Choices (Assoc))) = Nam then
6960 return Entity (Expression (Assoc));
6961 end if;
6963 Assoc := Next (Assoc);
6964 end loop;
6966 return Empty;
6967 end if;
6968 end Get_Iterable_Type_Primitive;
6970 ----------------------------------
6971 -- Get_Library_Unit_Name_string --
6972 ----------------------------------
6974 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
6975 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
6977 begin
6978 Get_Unit_Name_String (Unit_Name_Id);
6980 -- Remove seven last character (" (spec)" or " (body)")
6982 Name_Len := Name_Len - 7;
6983 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
6984 end Get_Library_Unit_Name_String;
6986 ------------------------
6987 -- Get_Name_Entity_Id --
6988 ------------------------
6990 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
6991 begin
6992 return Entity_Id (Get_Name_Table_Info (Id));
6993 end Get_Name_Entity_Id;
6995 ------------------------------
6996 -- Get_Name_From_CTC_Pragma --
6997 ------------------------------
6999 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
7000 Arg : constant Node_Id :=
7001 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
7002 begin
7003 return Strval (Expr_Value_S (Arg));
7004 end Get_Name_From_CTC_Pragma;
7006 -----------------------
7007 -- Get_Parent_Entity --
7008 -----------------------
7010 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
7011 begin
7012 if Nkind (Unit) = N_Package_Body
7013 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
7014 then
7015 return Defining_Entity
7016 (Specification (Instance_Spec (Original_Node (Unit))));
7017 elsif Nkind (Unit) = N_Package_Instantiation then
7018 return Defining_Entity (Specification (Instance_Spec (Unit)));
7019 else
7020 return Defining_Entity (Unit);
7021 end if;
7022 end Get_Parent_Entity;
7023 -------------------
7024 -- Get_Pragma_Id --
7025 -------------------
7027 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
7028 begin
7029 return Get_Pragma_Id (Pragma_Name (N));
7030 end Get_Pragma_Id;
7032 -----------------------
7033 -- Get_Reason_String --
7034 -----------------------
7036 procedure Get_Reason_String (N : Node_Id) is
7037 begin
7038 if Nkind (N) = N_String_Literal then
7039 Store_String_Chars (Strval (N));
7041 elsif Nkind (N) = N_Op_Concat then
7042 Get_Reason_String (Left_Opnd (N));
7043 Get_Reason_String (Right_Opnd (N));
7045 -- If not of required form, error
7047 else
7048 Error_Msg_N
7049 ("Reason for pragma Warnings has wrong form", N);
7050 Error_Msg_N
7051 ("\must be string literal or concatenation of string literals", N);
7052 return;
7053 end if;
7054 end Get_Reason_String;
7056 ---------------------------
7057 -- Get_Referenced_Object --
7058 ---------------------------
7060 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7061 R : Node_Id;
7063 begin
7064 R := N;
7065 while Is_Entity_Name (R)
7066 and then Present (Renamed_Object (Entity (R)))
7067 loop
7068 R := Renamed_Object (Entity (R));
7069 end loop;
7071 return R;
7072 end Get_Referenced_Object;
7074 ------------------------
7075 -- Get_Renamed_Entity --
7076 ------------------------
7078 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7079 R : Entity_Id;
7081 begin
7082 R := E;
7083 while Present (Renamed_Entity (R)) loop
7084 R := Renamed_Entity (R);
7085 end loop;
7087 return R;
7088 end Get_Renamed_Entity;
7090 ----------------------------------
7091 -- Get_Requires_From_CTC_Pragma --
7092 ----------------------------------
7094 function Get_Requires_From_CTC_Pragma (N : Node_Id) return Node_Id is
7095 Args : constant List_Id := Pragma_Argument_Associations (N);
7096 Res : Node_Id;
7098 begin
7099 if List_Length (Args) >= 3 then
7100 Res := Pick (Args, 3);
7102 if Chars (Res) /= Name_Requires then
7103 Res := Empty;
7104 end if;
7106 else
7107 Res := Empty;
7108 end if;
7110 return Res;
7111 end Get_Requires_From_CTC_Pragma;
7113 -------------------------
7114 -- Get_Subprogram_Body --
7115 -------------------------
7117 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
7118 Decl : Node_Id;
7120 begin
7121 Decl := Unit_Declaration_Node (E);
7123 if Nkind (Decl) = N_Subprogram_Body then
7124 return Decl;
7126 -- The below comment is bad, because it is possible for
7127 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7129 else -- Nkind (Decl) = N_Subprogram_Declaration
7131 if Present (Corresponding_Body (Decl)) then
7132 return Unit_Declaration_Node (Corresponding_Body (Decl));
7134 -- Imported subprogram case
7136 else
7137 return Empty;
7138 end if;
7139 end if;
7140 end Get_Subprogram_Body;
7142 ---------------------------
7143 -- Get_Subprogram_Entity --
7144 ---------------------------
7146 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7147 Subp : Node_Id;
7148 Subp_Id : Entity_Id;
7150 begin
7151 if Nkind (Nod) = N_Accept_Statement then
7152 Subp := Entry_Direct_Name (Nod);
7154 elsif Nkind (Nod) = N_Slice then
7155 Subp := Prefix (Nod);
7157 else
7158 Subp := Name (Nod);
7159 end if;
7161 -- Strip the subprogram call
7163 loop
7164 if Nkind_In (Subp, N_Explicit_Dereference,
7165 N_Indexed_Component,
7166 N_Selected_Component)
7167 then
7168 Subp := Prefix (Subp);
7170 elsif Nkind_In (Subp, N_Type_Conversion,
7171 N_Unchecked_Type_Conversion)
7172 then
7173 Subp := Expression (Subp);
7175 else
7176 exit;
7177 end if;
7178 end loop;
7180 -- Extract the entity of the subprogram call
7182 if Is_Entity_Name (Subp) then
7183 Subp_Id := Entity (Subp);
7185 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
7186 Subp_Id := Directly_Designated_Type (Subp_Id);
7187 end if;
7189 if Is_Subprogram (Subp_Id) then
7190 return Subp_Id;
7191 else
7192 return Empty;
7193 end if;
7195 -- The search did not find a construct that denotes a subprogram
7197 else
7198 return Empty;
7199 end if;
7200 end Get_Subprogram_Entity;
7202 -----------------------------
7203 -- Get_Task_Body_Procedure --
7204 -----------------------------
7206 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
7207 begin
7208 -- Note: A task type may be the completion of a private type with
7209 -- discriminants. When performing elaboration checks on a task
7210 -- declaration, the current view of the type may be the private one,
7211 -- and the procedure that holds the body of the task is held in its
7212 -- underlying type.
7214 -- This is an odd function, why not have Task_Body_Procedure do
7215 -- the following digging???
7217 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
7218 end Get_Task_Body_Procedure;
7220 -----------------------
7221 -- Has_Access_Values --
7222 -----------------------
7224 function Has_Access_Values (T : Entity_Id) return Boolean is
7225 Typ : constant Entity_Id := Underlying_Type (T);
7227 begin
7228 -- Case of a private type which is not completed yet. This can only
7229 -- happen in the case of a generic format type appearing directly, or
7230 -- as a component of the type to which this function is being applied
7231 -- at the top level. Return False in this case, since we certainly do
7232 -- not know that the type contains access types.
7234 if No (Typ) then
7235 return False;
7237 elsif Is_Access_Type (Typ) then
7238 return True;
7240 elsif Is_Array_Type (Typ) then
7241 return Has_Access_Values (Component_Type (Typ));
7243 elsif Is_Record_Type (Typ) then
7244 declare
7245 Comp : Entity_Id;
7247 begin
7248 -- Loop to Check components
7250 Comp := First_Component_Or_Discriminant (Typ);
7251 while Present (Comp) loop
7253 -- Check for access component, tag field does not count, even
7254 -- though it is implemented internally using an access type.
7256 if Has_Access_Values (Etype (Comp))
7257 and then Chars (Comp) /= Name_uTag
7258 then
7259 return True;
7260 end if;
7262 Next_Component_Or_Discriminant (Comp);
7263 end loop;
7264 end;
7266 return False;
7268 else
7269 return False;
7270 end if;
7271 end Has_Access_Values;
7273 ------------------------------
7274 -- Has_Compatible_Alignment --
7275 ------------------------------
7277 function Has_Compatible_Alignment
7278 (Obj : Entity_Id;
7279 Expr : Node_Id) return Alignment_Result
7281 function Has_Compatible_Alignment_Internal
7282 (Obj : Entity_Id;
7283 Expr : Node_Id;
7284 Default : Alignment_Result) return Alignment_Result;
7285 -- This is the internal recursive function that actually does the work.
7286 -- There is one additional parameter, which says what the result should
7287 -- be if no alignment information is found, and there is no definite
7288 -- indication of compatible alignments. At the outer level, this is set
7289 -- to Unknown, but for internal recursive calls in the case where types
7290 -- are known to be correct, it is set to Known_Compatible.
7292 ---------------------------------------
7293 -- Has_Compatible_Alignment_Internal --
7294 ---------------------------------------
7296 function Has_Compatible_Alignment_Internal
7297 (Obj : Entity_Id;
7298 Expr : Node_Id;
7299 Default : Alignment_Result) return Alignment_Result
7301 Result : Alignment_Result := Known_Compatible;
7302 -- Holds the current status of the result. Note that once a value of
7303 -- Known_Incompatible is set, it is sticky and does not get changed
7304 -- to Unknown (the value in Result only gets worse as we go along,
7305 -- never better).
7307 Offs : Uint := No_Uint;
7308 -- Set to a factor of the offset from the base object when Expr is a
7309 -- selected or indexed component, based on Component_Bit_Offset and
7310 -- Component_Size respectively. A negative value is used to represent
7311 -- a value which is not known at compile time.
7313 procedure Check_Prefix;
7314 -- Checks the prefix recursively in the case where the expression
7315 -- is an indexed or selected component.
7317 procedure Set_Result (R : Alignment_Result);
7318 -- If R represents a worse outcome (unknown instead of known
7319 -- compatible, or known incompatible), then set Result to R.
7321 ------------------
7322 -- Check_Prefix --
7323 ------------------
7325 procedure Check_Prefix is
7326 begin
7327 -- The subtlety here is that in doing a recursive call to check
7328 -- the prefix, we have to decide what to do in the case where we
7329 -- don't find any specific indication of an alignment problem.
7331 -- At the outer level, we normally set Unknown as the result in
7332 -- this case, since we can only set Known_Compatible if we really
7333 -- know that the alignment value is OK, but for the recursive
7334 -- call, in the case where the types match, and we have not
7335 -- specified a peculiar alignment for the object, we are only
7336 -- concerned about suspicious rep clauses, the default case does
7337 -- not affect us, since the compiler will, in the absence of such
7338 -- rep clauses, ensure that the alignment is correct.
7340 if Default = Known_Compatible
7341 or else
7342 (Etype (Obj) = Etype (Expr)
7343 and then (Unknown_Alignment (Obj)
7344 or else
7345 Alignment (Obj) = Alignment (Etype (Obj))))
7346 then
7347 Set_Result
7348 (Has_Compatible_Alignment_Internal
7349 (Obj, Prefix (Expr), Known_Compatible));
7351 -- In all other cases, we need a full check on the prefix
7353 else
7354 Set_Result
7355 (Has_Compatible_Alignment_Internal
7356 (Obj, Prefix (Expr), Unknown));
7357 end if;
7358 end Check_Prefix;
7360 ----------------
7361 -- Set_Result --
7362 ----------------
7364 procedure Set_Result (R : Alignment_Result) is
7365 begin
7366 if R > Result then
7367 Result := R;
7368 end if;
7369 end Set_Result;
7371 -- Start of processing for Has_Compatible_Alignment_Internal
7373 begin
7374 -- If Expr is a selected component, we must make sure there is no
7375 -- potentially troublesome component clause, and that the record is
7376 -- not packed.
7378 if Nkind (Expr) = N_Selected_Component then
7380 -- Packed record always generate unknown alignment
7382 if Is_Packed (Etype (Prefix (Expr))) then
7383 Set_Result (Unknown);
7384 end if;
7386 -- Check prefix and component offset
7388 Check_Prefix;
7389 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
7391 -- If Expr is an indexed component, we must make sure there is no
7392 -- potentially troublesome Component_Size clause and that the array
7393 -- is not bit-packed.
7395 elsif Nkind (Expr) = N_Indexed_Component then
7396 declare
7397 Typ : constant Entity_Id := Etype (Prefix (Expr));
7398 Ind : constant Node_Id := First_Index (Typ);
7400 begin
7401 -- Bit packed array always generates unknown alignment
7403 if Is_Bit_Packed_Array (Typ) then
7404 Set_Result (Unknown);
7405 end if;
7407 -- Check prefix and component offset
7409 Check_Prefix;
7410 Offs := Component_Size (Typ);
7412 -- Small optimization: compute the full offset when possible
7414 if Offs /= No_Uint
7415 and then Offs > Uint_0
7416 and then Present (Ind)
7417 and then Nkind (Ind) = N_Range
7418 and then Compile_Time_Known_Value (Low_Bound (Ind))
7419 and then Compile_Time_Known_Value (First (Expressions (Expr)))
7420 then
7421 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
7422 - Expr_Value (Low_Bound ((Ind))));
7423 end if;
7424 end;
7425 end if;
7427 -- If we have a null offset, the result is entirely determined by
7428 -- the base object and has already been computed recursively.
7430 if Offs = Uint_0 then
7431 null;
7433 -- Case where we know the alignment of the object
7435 elsif Known_Alignment (Obj) then
7436 declare
7437 ObjA : constant Uint := Alignment (Obj);
7438 ExpA : Uint := No_Uint;
7439 SizA : Uint := No_Uint;
7441 begin
7442 -- If alignment of Obj is 1, then we are always OK
7444 if ObjA = 1 then
7445 Set_Result (Known_Compatible);
7447 -- Alignment of Obj is greater than 1, so we need to check
7449 else
7450 -- If we have an offset, see if it is compatible
7452 if Offs /= No_Uint and Offs > Uint_0 then
7453 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
7454 Set_Result (Known_Incompatible);
7455 end if;
7457 -- See if Expr is an object with known alignment
7459 elsif Is_Entity_Name (Expr)
7460 and then Known_Alignment (Entity (Expr))
7461 then
7462 ExpA := Alignment (Entity (Expr));
7464 -- Otherwise, we can use the alignment of the type of
7465 -- Expr given that we already checked for
7466 -- discombobulating rep clauses for the cases of indexed
7467 -- and selected components above.
7469 elsif Known_Alignment (Etype (Expr)) then
7470 ExpA := Alignment (Etype (Expr));
7472 -- Otherwise the alignment is unknown
7474 else
7475 Set_Result (Default);
7476 end if;
7478 -- If we got an alignment, see if it is acceptable
7480 if ExpA /= No_Uint and then ExpA < ObjA then
7481 Set_Result (Known_Incompatible);
7482 end if;
7484 -- If Expr is not a piece of a larger object, see if size
7485 -- is given. If so, check that it is not too small for the
7486 -- required alignment.
7488 if Offs /= No_Uint then
7489 null;
7491 -- See if Expr is an object with known size
7493 elsif Is_Entity_Name (Expr)
7494 and then Known_Static_Esize (Entity (Expr))
7495 then
7496 SizA := Esize (Entity (Expr));
7498 -- Otherwise, we check the object size of the Expr type
7500 elsif Known_Static_Esize (Etype (Expr)) then
7501 SizA := Esize (Etype (Expr));
7502 end if;
7504 -- If we got a size, see if it is a multiple of the Obj
7505 -- alignment, if not, then the alignment cannot be
7506 -- acceptable, since the size is always a multiple of the
7507 -- alignment.
7509 if SizA /= No_Uint then
7510 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
7511 Set_Result (Known_Incompatible);
7512 end if;
7513 end if;
7514 end if;
7515 end;
7517 -- If we do not know required alignment, any non-zero offset is a
7518 -- potential problem (but certainly may be OK, so result is unknown).
7520 elsif Offs /= No_Uint then
7521 Set_Result (Unknown);
7523 -- If we can't find the result by direct comparison of alignment
7524 -- values, then there is still one case that we can determine known
7525 -- result, and that is when we can determine that the types are the
7526 -- same, and no alignments are specified. Then we known that the
7527 -- alignments are compatible, even if we don't know the alignment
7528 -- value in the front end.
7530 elsif Etype (Obj) = Etype (Expr) then
7532 -- Types are the same, but we have to check for possible size
7533 -- and alignments on the Expr object that may make the alignment
7534 -- different, even though the types are the same.
7536 if Is_Entity_Name (Expr) then
7538 -- First check alignment of the Expr object. Any alignment less
7539 -- than Maximum_Alignment is worrisome since this is the case
7540 -- where we do not know the alignment of Obj.
7542 if Known_Alignment (Entity (Expr))
7543 and then UI_To_Int (Alignment (Entity (Expr))) <
7544 Ttypes.Maximum_Alignment
7545 then
7546 Set_Result (Unknown);
7548 -- Now check size of Expr object. Any size that is not an
7549 -- even multiple of Maximum_Alignment is also worrisome
7550 -- since it may cause the alignment of the object to be less
7551 -- than the alignment of the type.
7553 elsif Known_Static_Esize (Entity (Expr))
7554 and then
7555 (UI_To_Int (Esize (Entity (Expr))) mod
7556 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
7557 /= 0
7558 then
7559 Set_Result (Unknown);
7561 -- Otherwise same type is decisive
7563 else
7564 Set_Result (Known_Compatible);
7565 end if;
7566 end if;
7568 -- Another case to deal with is when there is an explicit size or
7569 -- alignment clause when the types are not the same. If so, then the
7570 -- result is Unknown. We don't need to do this test if the Default is
7571 -- Unknown, since that result will be set in any case.
7573 elsif Default /= Unknown
7574 and then (Has_Size_Clause (Etype (Expr))
7575 or else
7576 Has_Alignment_Clause (Etype (Expr)))
7577 then
7578 Set_Result (Unknown);
7580 -- If no indication found, set default
7582 else
7583 Set_Result (Default);
7584 end if;
7586 -- Return worst result found
7588 return Result;
7589 end Has_Compatible_Alignment_Internal;
7591 -- Start of processing for Has_Compatible_Alignment
7593 begin
7594 -- If Obj has no specified alignment, then set alignment from the type
7595 -- alignment. Perhaps we should always do this, but for sure we should
7596 -- do it when there is an address clause since we can do more if the
7597 -- alignment is known.
7599 if Unknown_Alignment (Obj) then
7600 Set_Alignment (Obj, Alignment (Etype (Obj)));
7601 end if;
7603 -- Now do the internal call that does all the work
7605 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
7606 end Has_Compatible_Alignment;
7608 ----------------------
7609 -- Has_Declarations --
7610 ----------------------
7612 function Has_Declarations (N : Node_Id) return Boolean is
7613 begin
7614 return Nkind_In (Nkind (N), N_Accept_Statement,
7615 N_Block_Statement,
7616 N_Compilation_Unit_Aux,
7617 N_Entry_Body,
7618 N_Package_Body,
7619 N_Protected_Body,
7620 N_Subprogram_Body,
7621 N_Task_Body,
7622 N_Package_Specification);
7623 end Has_Declarations;
7625 ---------------------------------
7626 -- Has_Defaulted_Discriminants --
7627 ---------------------------------
7629 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
7630 begin
7631 return Has_Discriminants (Typ)
7632 and then Present (First_Discriminant (Typ))
7633 and then Present (Discriminant_Default_Value
7634 (First_Discriminant (Typ)));
7635 end Has_Defaulted_Discriminants;
7637 -------------------
7638 -- Has_Denormals --
7639 -------------------
7641 function Has_Denormals (E : Entity_Id) return Boolean is
7642 begin
7643 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
7644 end Has_Denormals;
7646 -------------------------------------------
7647 -- Has_Discriminant_Dependent_Constraint --
7648 -------------------------------------------
7650 function Has_Discriminant_Dependent_Constraint
7651 (Comp : Entity_Id) return Boolean
7653 Comp_Decl : constant Node_Id := Parent (Comp);
7654 Subt_Indic : Node_Id;
7655 Constr : Node_Id;
7656 Assn : Node_Id;
7658 begin
7659 -- Discriminants can't depend on discriminants
7661 if Ekind (Comp) = E_Discriminant then
7662 return False;
7664 else
7665 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
7667 if Nkind (Subt_Indic) = N_Subtype_Indication then
7668 Constr := Constraint (Subt_Indic);
7670 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
7671 Assn := First (Constraints (Constr));
7672 while Present (Assn) loop
7673 case Nkind (Assn) is
7674 when N_Subtype_Indication |
7675 N_Range |
7676 N_Identifier
7678 if Depends_On_Discriminant (Assn) then
7679 return True;
7680 end if;
7682 when N_Discriminant_Association =>
7683 if Depends_On_Discriminant (Expression (Assn)) then
7684 return True;
7685 end if;
7687 when others =>
7688 null;
7689 end case;
7691 Next (Assn);
7692 end loop;
7693 end if;
7694 end if;
7695 end if;
7697 return False;
7698 end Has_Discriminant_Dependent_Constraint;
7700 --------------------------
7701 -- Has_Enabled_Property --
7702 --------------------------
7704 function Has_Enabled_Property
7705 (Item_Id : Entity_Id;
7706 Property : Name_Id) return Boolean
7708 function State_Has_Enabled_Property return Boolean;
7709 -- Determine whether a state denoted by Item_Id has the property enabled
7711 function Variable_Has_Enabled_Property return Boolean;
7712 -- Determine whether a variable denoted by Item_Id has the property
7713 -- enabled.
7715 --------------------------------
7716 -- State_Has_Enabled_Property --
7717 --------------------------------
7719 function State_Has_Enabled_Property return Boolean is
7720 Decl : constant Node_Id := Parent (Item_Id);
7721 Opt : Node_Id;
7722 Opt_Nam : Node_Id;
7723 Prop : Node_Id;
7724 Prop_Nam : Node_Id;
7725 Props : Node_Id;
7727 begin
7728 -- The declaration of an external abstract state appears as an
7729 -- extension aggregate. If this is not the case, properties can never
7730 -- be set.
7732 if Nkind (Decl) /= N_Extension_Aggregate then
7733 return False;
7734 end if;
7736 -- When External appears as a simple option, it automatically enables
7737 -- all properties.
7739 Opt := First (Expressions (Decl));
7740 while Present (Opt) loop
7741 if Nkind (Opt) = N_Identifier
7742 and then Chars (Opt) = Name_External
7743 then
7744 return True;
7745 end if;
7747 Next (Opt);
7748 end loop;
7750 -- When External specifies particular properties, inspect those and
7751 -- find the desired one (if any).
7753 Opt := First (Component_Associations (Decl));
7754 while Present (Opt) loop
7755 Opt_Nam := First (Choices (Opt));
7757 if Nkind (Opt_Nam) = N_Identifier
7758 and then Chars (Opt_Nam) = Name_External
7759 then
7760 Props := Expression (Opt);
7762 -- Multiple properties appear as an aggregate
7764 if Nkind (Props) = N_Aggregate then
7766 -- Simple property form
7768 Prop := First (Expressions (Props));
7769 while Present (Prop) loop
7770 if Chars (Prop) = Property then
7771 return True;
7772 end if;
7774 Next (Prop);
7775 end loop;
7777 -- Property with expression form
7779 Prop := First (Component_Associations (Props));
7780 while Present (Prop) loop
7781 Prop_Nam := First (Choices (Prop));
7783 -- The property can be represented in two ways:
7784 -- others => <value>
7785 -- <property> => <value>
7787 if Nkind (Prop_Nam) = N_Others_Choice
7788 or else (Nkind (Prop_Nam) = N_Identifier
7789 and then Chars (Prop_Nam) = Property)
7790 then
7791 return Is_True (Expr_Value (Expression (Prop)));
7792 end if;
7794 Next (Prop);
7795 end loop;
7797 -- Single property
7799 else
7800 return Chars (Props) = Property;
7801 end if;
7802 end if;
7804 Next (Opt);
7805 end loop;
7807 return False;
7808 end State_Has_Enabled_Property;
7810 -----------------------------------
7811 -- Variable_Has_Enabled_Property --
7812 -----------------------------------
7814 function Variable_Has_Enabled_Property return Boolean is
7815 function Is_Enabled (Prag : Node_Id) return Boolean;
7816 -- Determine whether property pragma Prag (if present) denotes an
7817 -- enabled property.
7819 ----------------
7820 -- Is_Enabled --
7821 ----------------
7823 function Is_Enabled (Prag : Node_Id) return Boolean is
7824 Arg2 : Node_Id;
7826 begin
7827 if Present (Prag) then
7828 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
7830 -- The pragma has an optional Boolean expression, the related
7831 -- property is enabled only when the expression evaluates to
7832 -- True.
7834 if Present (Arg2) then
7835 return Is_True (Expr_Value (Get_Pragma_Arg (Arg2)));
7837 -- Otherwise the lack of expression enables the property by
7838 -- default.
7840 else
7841 return True;
7842 end if;
7844 -- The property was never set in the first place
7846 else
7847 return False;
7848 end if;
7849 end Is_Enabled;
7851 -- Local variables
7853 AR : constant Node_Id :=
7854 Get_Pragma (Item_Id, Pragma_Async_Readers);
7855 AW : constant Node_Id :=
7856 Get_Pragma (Item_Id, Pragma_Async_Writers);
7857 ER : constant Node_Id :=
7858 Get_Pragma (Item_Id, Pragma_Effective_Reads);
7859 EW : constant Node_Id :=
7860 Get_Pragma (Item_Id, Pragma_Effective_Writes);
7862 -- Start of processing for Variable_Has_Enabled_Property
7864 begin
7865 -- A non-effectively volatile object can never possess external
7866 -- properties.
7868 if not Is_Effectively_Volatile (Item_Id) then
7869 return False;
7871 -- External properties related to variables come in two flavors -
7872 -- explicit and implicit. The explicit case is characterized by the
7873 -- presence of a property pragma with an optional Boolean flag. The
7874 -- property is enabled when the flag evaluates to True or the flag is
7875 -- missing altogether.
7877 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
7878 return True;
7880 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
7881 return True;
7883 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
7884 return True;
7886 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
7887 return True;
7889 -- The implicit case lacks all property pragmas
7891 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
7892 return True;
7894 else
7895 return False;
7896 end if;
7897 end Variable_Has_Enabled_Property;
7899 -- Start of processing for Has_Enabled_Property
7901 begin
7902 -- Abstract states and variables have a flexible scheme of specifying
7903 -- external properties.
7905 if Ekind (Item_Id) = E_Abstract_State then
7906 return State_Has_Enabled_Property;
7908 elsif Ekind (Item_Id) = E_Variable then
7909 return Variable_Has_Enabled_Property;
7911 -- Otherwise a property is enabled when the related item is effectively
7912 -- volatile.
7914 else
7915 return Is_Effectively_Volatile (Item_Id);
7916 end if;
7917 end Has_Enabled_Property;
7919 --------------------
7920 -- Has_Infinities --
7921 --------------------
7923 function Has_Infinities (E : Entity_Id) return Boolean is
7924 begin
7925 return
7926 Is_Floating_Point_Type (E)
7927 and then Nkind (Scalar_Range (E)) = N_Range
7928 and then Includes_Infinities (Scalar_Range (E));
7929 end Has_Infinities;
7931 --------------------
7932 -- Has_Interfaces --
7933 --------------------
7935 function Has_Interfaces
7936 (T : Entity_Id;
7937 Use_Full_View : Boolean := True) return Boolean
7939 Typ : Entity_Id := Base_Type (T);
7941 begin
7942 -- Handle concurrent types
7944 if Is_Concurrent_Type (Typ) then
7945 Typ := Corresponding_Record_Type (Typ);
7946 end if;
7948 if not Present (Typ)
7949 or else not Is_Record_Type (Typ)
7950 or else not Is_Tagged_Type (Typ)
7951 then
7952 return False;
7953 end if;
7955 -- Handle private types
7957 if Use_Full_View and then Present (Full_View (Typ)) then
7958 Typ := Full_View (Typ);
7959 end if;
7961 -- Handle concurrent record types
7963 if Is_Concurrent_Record_Type (Typ)
7964 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
7965 then
7966 return True;
7967 end if;
7969 loop
7970 if Is_Interface (Typ)
7971 or else
7972 (Is_Record_Type (Typ)
7973 and then Present (Interfaces (Typ))
7974 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
7975 then
7976 return True;
7977 end if;
7979 exit when Etype (Typ) = Typ
7981 -- Handle private types
7983 or else (Present (Full_View (Etype (Typ)))
7984 and then Full_View (Etype (Typ)) = Typ)
7986 -- Protect frontend against wrong sources with cyclic derivations
7988 or else Etype (Typ) = T;
7990 -- Climb to the ancestor type handling private types
7992 if Present (Full_View (Etype (Typ))) then
7993 Typ := Full_View (Etype (Typ));
7994 else
7995 Typ := Etype (Typ);
7996 end if;
7997 end loop;
7999 return False;
8000 end Has_Interfaces;
8002 ---------------------------------
8003 -- Has_No_Obvious_Side_Effects --
8004 ---------------------------------
8006 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
8007 begin
8008 -- For now, just handle literals, constants, and non-volatile
8009 -- variables and expressions combining these with operators or
8010 -- short circuit forms.
8012 if Nkind (N) in N_Numeric_Or_String_Literal then
8013 return True;
8015 elsif Nkind (N) = N_Character_Literal then
8016 return True;
8018 elsif Nkind (N) in N_Unary_Op then
8019 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
8021 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
8022 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
8023 and then
8024 Has_No_Obvious_Side_Effects (Right_Opnd (N));
8026 elsif Nkind (N) = N_Expression_With_Actions
8027 and then Is_Empty_List (Actions (N))
8028 then
8029 return Has_No_Obvious_Side_Effects (Expression (N));
8031 elsif Nkind (N) in N_Has_Entity then
8032 return Present (Entity (N))
8033 and then Ekind_In (Entity (N), E_Variable,
8034 E_Constant,
8035 E_Enumeration_Literal,
8036 E_In_Parameter,
8037 E_Out_Parameter,
8038 E_In_Out_Parameter)
8039 and then not Is_Volatile (Entity (N));
8041 else
8042 return False;
8043 end if;
8044 end Has_No_Obvious_Side_Effects;
8046 ------------------------
8047 -- Has_Null_Exclusion --
8048 ------------------------
8050 function Has_Null_Exclusion (N : Node_Id) return Boolean is
8051 begin
8052 case Nkind (N) is
8053 when N_Access_Definition |
8054 N_Access_Function_Definition |
8055 N_Access_Procedure_Definition |
8056 N_Access_To_Object_Definition |
8057 N_Allocator |
8058 N_Derived_Type_Definition |
8059 N_Function_Specification |
8060 N_Subtype_Declaration =>
8061 return Null_Exclusion_Present (N);
8063 when N_Component_Definition |
8064 N_Formal_Object_Declaration |
8065 N_Object_Renaming_Declaration =>
8066 if Present (Subtype_Mark (N)) then
8067 return Null_Exclusion_Present (N);
8068 else pragma Assert (Present (Access_Definition (N)));
8069 return Null_Exclusion_Present (Access_Definition (N));
8070 end if;
8072 when N_Discriminant_Specification =>
8073 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
8074 return Null_Exclusion_Present (Discriminant_Type (N));
8075 else
8076 return Null_Exclusion_Present (N);
8077 end if;
8079 when N_Object_Declaration =>
8080 if Nkind (Object_Definition (N)) = N_Access_Definition then
8081 return Null_Exclusion_Present (Object_Definition (N));
8082 else
8083 return Null_Exclusion_Present (N);
8084 end if;
8086 when N_Parameter_Specification =>
8087 if Nkind (Parameter_Type (N)) = N_Access_Definition then
8088 return Null_Exclusion_Present (Parameter_Type (N));
8089 else
8090 return Null_Exclusion_Present (N);
8091 end if;
8093 when others =>
8094 return False;
8096 end case;
8097 end Has_Null_Exclusion;
8099 ------------------------
8100 -- Has_Null_Extension --
8101 ------------------------
8103 function Has_Null_Extension (T : Entity_Id) return Boolean is
8104 B : constant Entity_Id := Base_Type (T);
8105 Comps : Node_Id;
8106 Ext : Node_Id;
8108 begin
8109 if Nkind (Parent (B)) = N_Full_Type_Declaration
8110 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
8111 then
8112 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
8114 if Present (Ext) then
8115 if Null_Present (Ext) then
8116 return True;
8117 else
8118 Comps := Component_List (Ext);
8120 -- The null component list is rewritten during analysis to
8121 -- include the parent component. Any other component indicates
8122 -- that the extension was not originally null.
8124 return Null_Present (Comps)
8125 or else No (Next (First (Component_Items (Comps))));
8126 end if;
8127 else
8128 return False;
8129 end if;
8131 else
8132 return False;
8133 end if;
8134 end Has_Null_Extension;
8136 -------------------------------
8137 -- Has_Overriding_Initialize --
8138 -------------------------------
8140 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
8141 BT : constant Entity_Id := Base_Type (T);
8142 P : Elmt_Id;
8144 begin
8145 if Is_Controlled (BT) then
8146 if Is_RTU (Scope (BT), Ada_Finalization) then
8147 return False;
8149 elsif Present (Primitive_Operations (BT)) then
8150 P := First_Elmt (Primitive_Operations (BT));
8151 while Present (P) loop
8152 declare
8153 Init : constant Entity_Id := Node (P);
8154 Formal : constant Entity_Id := First_Formal (Init);
8155 begin
8156 if Ekind (Init) = E_Procedure
8157 and then Chars (Init) = Name_Initialize
8158 and then Comes_From_Source (Init)
8159 and then Present (Formal)
8160 and then Etype (Formal) = BT
8161 and then No (Next_Formal (Formal))
8162 and then (Ada_Version < Ada_2012
8163 or else not Null_Present (Parent (Init)))
8164 then
8165 return True;
8166 end if;
8167 end;
8169 Next_Elmt (P);
8170 end loop;
8171 end if;
8173 -- Here if type itself does not have a non-null Initialize operation:
8174 -- check immediate ancestor.
8176 if Is_Derived_Type (BT)
8177 and then Has_Overriding_Initialize (Etype (BT))
8178 then
8179 return True;
8180 end if;
8181 end if;
8183 return False;
8184 end Has_Overriding_Initialize;
8186 --------------------------------------
8187 -- Has_Preelaborable_Initialization --
8188 --------------------------------------
8190 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
8191 Has_PE : Boolean;
8193 procedure Check_Components (E : Entity_Id);
8194 -- Check component/discriminant chain, sets Has_PE False if a component
8195 -- or discriminant does not meet the preelaborable initialization rules.
8197 ----------------------
8198 -- Check_Components --
8199 ----------------------
8201 procedure Check_Components (E : Entity_Id) is
8202 Ent : Entity_Id;
8203 Exp : Node_Id;
8205 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
8206 -- Returns True if and only if the expression denoted by N does not
8207 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8209 ---------------------------------
8210 -- Is_Preelaborable_Expression --
8211 ---------------------------------
8213 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
8214 Exp : Node_Id;
8215 Assn : Node_Id;
8216 Choice : Node_Id;
8217 Comp_Type : Entity_Id;
8218 Is_Array_Aggr : Boolean;
8220 begin
8221 if Is_OK_Static_Expression (N) then
8222 return True;
8224 elsif Nkind (N) = N_Null then
8225 return True;
8227 -- Attributes are allowed in general, even if their prefix is a
8228 -- formal type. (It seems that certain attributes known not to be
8229 -- static might not be allowed, but there are no rules to prevent
8230 -- them.)
8232 elsif Nkind (N) = N_Attribute_Reference then
8233 return True;
8235 -- The name of a discriminant evaluated within its parent type is
8236 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8237 -- names that denote discriminals as well as discriminants to
8238 -- catch references occurring within init procs.
8240 elsif Is_Entity_Name (N)
8241 and then
8242 (Ekind (Entity (N)) = E_Discriminant
8243 or else
8244 ((Ekind (Entity (N)) = E_Constant
8245 or else Ekind (Entity (N)) = E_In_Parameter)
8246 and then Present (Discriminal_Link (Entity (N)))))
8247 then
8248 return True;
8250 elsif Nkind (N) = N_Qualified_Expression then
8251 return Is_Preelaborable_Expression (Expression (N));
8253 -- For aggregates we have to check that each of the associations
8254 -- is preelaborable.
8256 elsif Nkind (N) = N_Aggregate
8257 or else Nkind (N) = N_Extension_Aggregate
8258 then
8259 Is_Array_Aggr := Is_Array_Type (Etype (N));
8261 if Is_Array_Aggr then
8262 Comp_Type := Component_Type (Etype (N));
8263 end if;
8265 -- Check the ancestor part of extension aggregates, which must
8266 -- be either the name of a type that has preelaborable init or
8267 -- an expression that is preelaborable.
8269 if Nkind (N) = N_Extension_Aggregate then
8270 declare
8271 Anc_Part : constant Node_Id := Ancestor_Part (N);
8273 begin
8274 if Is_Entity_Name (Anc_Part)
8275 and then Is_Type (Entity (Anc_Part))
8276 then
8277 if not Has_Preelaborable_Initialization
8278 (Entity (Anc_Part))
8279 then
8280 return False;
8281 end if;
8283 elsif not Is_Preelaborable_Expression (Anc_Part) then
8284 return False;
8285 end if;
8286 end;
8287 end if;
8289 -- Check positional associations
8291 Exp := First (Expressions (N));
8292 while Present (Exp) loop
8293 if not Is_Preelaborable_Expression (Exp) then
8294 return False;
8295 end if;
8297 Next (Exp);
8298 end loop;
8300 -- Check named associations
8302 Assn := First (Component_Associations (N));
8303 while Present (Assn) loop
8304 Choice := First (Choices (Assn));
8305 while Present (Choice) loop
8306 if Is_Array_Aggr then
8307 if Nkind (Choice) = N_Others_Choice then
8308 null;
8310 elsif Nkind (Choice) = N_Range then
8311 if not Is_OK_Static_Range (Choice) then
8312 return False;
8313 end if;
8315 elsif not Is_OK_Static_Expression (Choice) then
8316 return False;
8317 end if;
8319 else
8320 Comp_Type := Etype (Choice);
8321 end if;
8323 Next (Choice);
8324 end loop;
8326 -- If the association has a <> at this point, then we have
8327 -- to check whether the component's type has preelaborable
8328 -- initialization. Note that this only occurs when the
8329 -- association's corresponding component does not have a
8330 -- default expression, the latter case having already been
8331 -- expanded as an expression for the association.
8333 if Box_Present (Assn) then
8334 if not Has_Preelaborable_Initialization (Comp_Type) then
8335 return False;
8336 end if;
8338 -- In the expression case we check whether the expression
8339 -- is preelaborable.
8341 elsif
8342 not Is_Preelaborable_Expression (Expression (Assn))
8343 then
8344 return False;
8345 end if;
8347 Next (Assn);
8348 end loop;
8350 -- If we get here then aggregate as a whole is preelaborable
8352 return True;
8354 -- All other cases are not preelaborable
8356 else
8357 return False;
8358 end if;
8359 end Is_Preelaborable_Expression;
8361 -- Start of processing for Check_Components
8363 begin
8364 -- Loop through entities of record or protected type
8366 Ent := E;
8367 while Present (Ent) loop
8369 -- We are interested only in components and discriminants
8371 Exp := Empty;
8373 case Ekind (Ent) is
8374 when E_Component =>
8376 -- Get default expression if any. If there is no declaration
8377 -- node, it means we have an internal entity. The parent and
8378 -- tag fields are examples of such entities. For such cases,
8379 -- we just test the type of the entity.
8381 if Present (Declaration_Node (Ent)) then
8382 Exp := Expression (Declaration_Node (Ent));
8383 end if;
8385 when E_Discriminant =>
8387 -- Note: for a renamed discriminant, the Declaration_Node
8388 -- may point to the one from the ancestor, and have a
8389 -- different expression, so use the proper attribute to
8390 -- retrieve the expression from the derived constraint.
8392 Exp := Discriminant_Default_Value (Ent);
8394 when others =>
8395 goto Check_Next_Entity;
8396 end case;
8398 -- A component has PI if it has no default expression and the
8399 -- component type has PI.
8401 if No (Exp) then
8402 if not Has_Preelaborable_Initialization (Etype (Ent)) then
8403 Has_PE := False;
8404 exit;
8405 end if;
8407 -- Require the default expression to be preelaborable
8409 elsif not Is_Preelaborable_Expression (Exp) then
8410 Has_PE := False;
8411 exit;
8412 end if;
8414 <<Check_Next_Entity>>
8415 Next_Entity (Ent);
8416 end loop;
8417 end Check_Components;
8419 -- Start of processing for Has_Preelaborable_Initialization
8421 begin
8422 -- Immediate return if already marked as known preelaborable init. This
8423 -- covers types for which this function has already been called once
8424 -- and returned True (in which case the result is cached), and also
8425 -- types to which a pragma Preelaborable_Initialization applies.
8427 if Known_To_Have_Preelab_Init (E) then
8428 return True;
8429 end if;
8431 -- If the type is a subtype representing a generic actual type, then
8432 -- test whether its base type has preelaborable initialization since
8433 -- the subtype representing the actual does not inherit this attribute
8434 -- from the actual or formal. (but maybe it should???)
8436 if Is_Generic_Actual_Type (E) then
8437 return Has_Preelaborable_Initialization (Base_Type (E));
8438 end if;
8440 -- All elementary types have preelaborable initialization
8442 if Is_Elementary_Type (E) then
8443 Has_PE := True;
8445 -- Array types have PI if the component type has PI
8447 elsif Is_Array_Type (E) then
8448 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
8450 -- A derived type has preelaborable initialization if its parent type
8451 -- has preelaborable initialization and (in the case of a derived record
8452 -- extension) if the non-inherited components all have preelaborable
8453 -- initialization. However, a user-defined controlled type with an
8454 -- overriding Initialize procedure does not have preelaborable
8455 -- initialization.
8457 elsif Is_Derived_Type (E) then
8459 -- If the derived type is a private extension then it doesn't have
8460 -- preelaborable initialization.
8462 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
8463 return False;
8464 end if;
8466 -- First check whether ancestor type has preelaborable initialization
8468 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
8470 -- If OK, check extension components (if any)
8472 if Has_PE and then Is_Record_Type (E) then
8473 Check_Components (First_Entity (E));
8474 end if;
8476 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8477 -- with a user defined Initialize procedure does not have PI. If
8478 -- the type is untagged, the control primitives come from a component
8479 -- that has already been checked.
8481 if Has_PE
8482 and then Is_Controlled (E)
8483 and then Is_Tagged_Type (E)
8484 and then Has_Overriding_Initialize (E)
8485 then
8486 Has_PE := False;
8487 end if;
8489 -- Private types not derived from a type having preelaborable init and
8490 -- that are not marked with pragma Preelaborable_Initialization do not
8491 -- have preelaborable initialization.
8493 elsif Is_Private_Type (E) then
8494 return False;
8496 -- Record type has PI if it is non private and all components have PI
8498 elsif Is_Record_Type (E) then
8499 Has_PE := True;
8500 Check_Components (First_Entity (E));
8502 -- Protected types must not have entries, and components must meet
8503 -- same set of rules as for record components.
8505 elsif Is_Protected_Type (E) then
8506 if Has_Entries (E) then
8507 Has_PE := False;
8508 else
8509 Has_PE := True;
8510 Check_Components (First_Entity (E));
8511 Check_Components (First_Private_Entity (E));
8512 end if;
8514 -- Type System.Address always has preelaborable initialization
8516 elsif Is_RTE (E, RE_Address) then
8517 Has_PE := True;
8519 -- In all other cases, type does not have preelaborable initialization
8521 else
8522 return False;
8523 end if;
8525 -- If type has preelaborable initialization, cache result
8527 if Has_PE then
8528 Set_Known_To_Have_Preelab_Init (E);
8529 end if;
8531 return Has_PE;
8532 end Has_Preelaborable_Initialization;
8534 ---------------------------
8535 -- Has_Private_Component --
8536 ---------------------------
8538 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
8539 Btype : Entity_Id := Base_Type (Type_Id);
8540 Component : Entity_Id;
8542 begin
8543 if Error_Posted (Type_Id)
8544 or else Error_Posted (Btype)
8545 then
8546 return False;
8547 end if;
8549 if Is_Class_Wide_Type (Btype) then
8550 Btype := Root_Type (Btype);
8551 end if;
8553 if Is_Private_Type (Btype) then
8554 declare
8555 UT : constant Entity_Id := Underlying_Type (Btype);
8556 begin
8557 if No (UT) then
8558 if No (Full_View (Btype)) then
8559 return not Is_Generic_Type (Btype)
8560 and then not Is_Generic_Type (Root_Type (Btype));
8561 else
8562 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
8563 end if;
8564 else
8565 return not Is_Frozen (UT) and then Has_Private_Component (UT);
8566 end if;
8567 end;
8569 elsif Is_Array_Type (Btype) then
8570 return Has_Private_Component (Component_Type (Btype));
8572 elsif Is_Record_Type (Btype) then
8573 Component := First_Component (Btype);
8574 while Present (Component) loop
8575 if Has_Private_Component (Etype (Component)) then
8576 return True;
8577 end if;
8579 Next_Component (Component);
8580 end loop;
8582 return False;
8584 elsif Is_Protected_Type (Btype)
8585 and then Present (Corresponding_Record_Type (Btype))
8586 then
8587 return Has_Private_Component (Corresponding_Record_Type (Btype));
8589 else
8590 return False;
8591 end if;
8592 end Has_Private_Component;
8594 ----------------------
8595 -- Has_Signed_Zeros --
8596 ----------------------
8598 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
8599 begin
8600 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
8601 end Has_Signed_Zeros;
8603 -----------------------------
8604 -- Has_Static_Array_Bounds --
8605 -----------------------------
8607 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
8608 Ndims : constant Nat := Number_Dimensions (Typ);
8610 Index : Node_Id;
8611 Low : Node_Id;
8612 High : Node_Id;
8614 begin
8615 -- Unconstrained types do not have static bounds
8617 if not Is_Constrained (Typ) then
8618 return False;
8619 end if;
8621 -- First treat string literals specially, as the lower bound and length
8622 -- of string literals are not stored like those of arrays.
8624 -- A string literal always has static bounds
8626 if Ekind (Typ) = E_String_Literal_Subtype then
8627 return True;
8628 end if;
8630 -- Treat all dimensions in turn
8632 Index := First_Index (Typ);
8633 for Indx in 1 .. Ndims loop
8635 -- In case of an illegal index which is not a discrete type, return
8636 -- that the type is not static.
8638 if not Is_Discrete_Type (Etype (Index))
8639 or else Etype (Index) = Any_Type
8640 then
8641 return False;
8642 end if;
8644 Get_Index_Bounds (Index, Low, High);
8646 if Error_Posted (Low) or else Error_Posted (High) then
8647 return False;
8648 end if;
8650 if Is_OK_Static_Expression (Low)
8651 and then
8652 Is_OK_Static_Expression (High)
8653 then
8654 null;
8655 else
8656 return False;
8657 end if;
8659 Next (Index);
8660 end loop;
8662 -- If we fall through the loop, all indexes matched
8664 return True;
8665 end Has_Static_Array_Bounds;
8667 ----------------
8668 -- Has_Stream --
8669 ----------------
8671 function Has_Stream (T : Entity_Id) return Boolean is
8672 E : Entity_Id;
8674 begin
8675 if No (T) then
8676 return False;
8678 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
8679 return True;
8681 elsif Is_Array_Type (T) then
8682 return Has_Stream (Component_Type (T));
8684 elsif Is_Record_Type (T) then
8685 E := First_Component (T);
8686 while Present (E) loop
8687 if Has_Stream (Etype (E)) then
8688 return True;
8689 else
8690 Next_Component (E);
8691 end if;
8692 end loop;
8694 return False;
8696 elsif Is_Private_Type (T) then
8697 return Has_Stream (Underlying_Type (T));
8699 else
8700 return False;
8701 end if;
8702 end Has_Stream;
8704 ----------------
8705 -- Has_Suffix --
8706 ----------------
8708 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
8709 begin
8710 Get_Name_String (Chars (E));
8711 return Name_Buffer (Name_Len) = Suffix;
8712 end Has_Suffix;
8714 ----------------
8715 -- Add_Suffix --
8716 ----------------
8718 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8719 begin
8720 Get_Name_String (Chars (E));
8721 Add_Char_To_Name_Buffer (Suffix);
8722 return Name_Find;
8723 end Add_Suffix;
8725 -------------------
8726 -- Remove_Suffix --
8727 -------------------
8729 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8730 begin
8731 pragma Assert (Has_Suffix (E, Suffix));
8732 Get_Name_String (Chars (E));
8733 Name_Len := Name_Len - 1;
8734 return Name_Find;
8735 end Remove_Suffix;
8737 --------------------------
8738 -- Has_Tagged_Component --
8739 --------------------------
8741 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
8742 Comp : Entity_Id;
8744 begin
8745 if Is_Private_Type (Typ)
8746 and then Present (Underlying_Type (Typ))
8747 then
8748 return Has_Tagged_Component (Underlying_Type (Typ));
8750 elsif Is_Array_Type (Typ) then
8751 return Has_Tagged_Component (Component_Type (Typ));
8753 elsif Is_Tagged_Type (Typ) then
8754 return True;
8756 elsif Is_Record_Type (Typ) then
8757 Comp := First_Component (Typ);
8758 while Present (Comp) loop
8759 if Has_Tagged_Component (Etype (Comp)) then
8760 return True;
8761 end if;
8763 Next_Component (Comp);
8764 end loop;
8766 return False;
8768 else
8769 return False;
8770 end if;
8771 end Has_Tagged_Component;
8773 ----------------------------
8774 -- Has_Volatile_Component --
8775 ----------------------------
8777 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
8778 Comp : Entity_Id;
8780 begin
8781 if Has_Volatile_Components (Typ) then
8782 return True;
8784 elsif Is_Array_Type (Typ) then
8785 return Is_Volatile (Component_Type (Typ));
8787 elsif Is_Record_Type (Typ) then
8788 Comp := First_Component (Typ);
8789 while Present (Comp) loop
8790 if Is_Volatile_Object (Comp) then
8791 return True;
8792 end if;
8794 Comp := Next_Component (Comp);
8795 end loop;
8796 end if;
8798 return False;
8799 end Has_Volatile_Component;
8801 -------------------------
8802 -- Implementation_Kind --
8803 -------------------------
8805 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
8806 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
8807 Arg : Node_Id;
8808 begin
8809 pragma Assert (Present (Impl_Prag));
8810 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
8811 return Chars (Get_Pragma_Arg (Arg));
8812 end Implementation_Kind;
8814 --------------------------
8815 -- Implements_Interface --
8816 --------------------------
8818 function Implements_Interface
8819 (Typ_Ent : Entity_Id;
8820 Iface_Ent : Entity_Id;
8821 Exclude_Parents : Boolean := False) return Boolean
8823 Ifaces_List : Elist_Id;
8824 Elmt : Elmt_Id;
8825 Iface : Entity_Id := Base_Type (Iface_Ent);
8826 Typ : Entity_Id := Base_Type (Typ_Ent);
8828 begin
8829 if Is_Class_Wide_Type (Typ) then
8830 Typ := Root_Type (Typ);
8831 end if;
8833 if not Has_Interfaces (Typ) then
8834 return False;
8835 end if;
8837 if Is_Class_Wide_Type (Iface) then
8838 Iface := Root_Type (Iface);
8839 end if;
8841 Collect_Interfaces (Typ, Ifaces_List);
8843 Elmt := First_Elmt (Ifaces_List);
8844 while Present (Elmt) loop
8845 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
8846 and then Exclude_Parents
8847 then
8848 null;
8850 elsif Node (Elmt) = Iface then
8851 return True;
8852 end if;
8854 Next_Elmt (Elmt);
8855 end loop;
8857 return False;
8858 end Implements_Interface;
8860 ------------------------------------
8861 -- In_Assertion_Expression_Pragma --
8862 ------------------------------------
8864 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
8865 Par : Node_Id;
8866 Prag : Node_Id := Empty;
8868 begin
8869 -- Climb the parent chain looking for an enclosing pragma
8871 Par := N;
8872 while Present (Par) loop
8873 if Nkind (Par) = N_Pragma then
8874 Prag := Par;
8875 exit;
8877 -- Precondition-like pragmas are expanded into if statements, check
8878 -- the original node instead.
8880 elsif Nkind (Original_Node (Par)) = N_Pragma then
8881 Prag := Original_Node (Par);
8882 exit;
8884 -- The expansion of attribute 'Old generates a constant to capture
8885 -- the result of the prefix. If the parent traversal reaches
8886 -- one of these constants, then the node technically came from a
8887 -- postcondition-like pragma. Note that the Ekind is not tested here
8888 -- because N may be the expression of an object declaration which is
8889 -- currently being analyzed. Such objects carry Ekind of E_Void.
8891 elsif Nkind (Par) = N_Object_Declaration
8892 and then Constant_Present (Par)
8893 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
8894 then
8895 return True;
8897 -- Prevent the search from going too far
8899 elsif Is_Body_Or_Package_Declaration (Par) then
8900 return False;
8901 end if;
8903 Par := Parent (Par);
8904 end loop;
8906 return
8907 Present (Prag)
8908 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
8909 end In_Assertion_Expression_Pragma;
8911 -----------------
8912 -- In_Instance --
8913 -----------------
8915 function In_Instance return Boolean is
8916 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
8917 S : Entity_Id;
8919 begin
8920 S := Current_Scope;
8921 while Present (S) and then S /= Standard_Standard loop
8922 if (Ekind (S) = E_Function
8923 or else Ekind (S) = E_Package
8924 or else Ekind (S) = E_Procedure)
8925 and then Is_Generic_Instance (S)
8926 then
8927 -- A child instance is always compiled in the context of a parent
8928 -- instance. Nevertheless, the actuals are not analyzed in an
8929 -- instance context. We detect this case by examining the current
8930 -- compilation unit, which must be a child instance, and checking
8931 -- that it is not currently on the scope stack.
8933 if Is_Child_Unit (Curr_Unit)
8934 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
8935 N_Package_Instantiation
8936 and then not In_Open_Scopes (Curr_Unit)
8937 then
8938 return False;
8939 else
8940 return True;
8941 end if;
8942 end if;
8944 S := Scope (S);
8945 end loop;
8947 return False;
8948 end In_Instance;
8950 ----------------------
8951 -- In_Instance_Body --
8952 ----------------------
8954 function In_Instance_Body return Boolean is
8955 S : Entity_Id;
8957 begin
8958 S := Current_Scope;
8959 while Present (S) and then S /= Standard_Standard loop
8960 if Ekind_In (S, E_Function, E_Procedure)
8961 and then Is_Generic_Instance (S)
8962 then
8963 return True;
8965 elsif Ekind (S) = E_Package
8966 and then In_Package_Body (S)
8967 and then Is_Generic_Instance (S)
8968 then
8969 return True;
8970 end if;
8972 S := Scope (S);
8973 end loop;
8975 return False;
8976 end In_Instance_Body;
8978 -----------------------------
8979 -- In_Instance_Not_Visible --
8980 -----------------------------
8982 function In_Instance_Not_Visible return Boolean is
8983 S : Entity_Id;
8985 begin
8986 S := Current_Scope;
8987 while Present (S) and then S /= Standard_Standard loop
8988 if Ekind_In (S, E_Function, E_Procedure)
8989 and then Is_Generic_Instance (S)
8990 then
8991 return True;
8993 elsif Ekind (S) = E_Package
8994 and then (In_Package_Body (S) or else In_Private_Part (S))
8995 and then Is_Generic_Instance (S)
8996 then
8997 return True;
8998 end if;
9000 S := Scope (S);
9001 end loop;
9003 return False;
9004 end In_Instance_Not_Visible;
9006 ------------------------------
9007 -- In_Instance_Visible_Part --
9008 ------------------------------
9010 function In_Instance_Visible_Part return Boolean is
9011 S : Entity_Id;
9013 begin
9014 S := Current_Scope;
9015 while Present (S) and then S /= Standard_Standard loop
9016 if Ekind (S) = E_Package
9017 and then Is_Generic_Instance (S)
9018 and then not In_Package_Body (S)
9019 and then not In_Private_Part (S)
9020 then
9021 return True;
9022 end if;
9024 S := Scope (S);
9025 end loop;
9027 return False;
9028 end In_Instance_Visible_Part;
9030 ---------------------
9031 -- In_Package_Body --
9032 ---------------------
9034 function In_Package_Body return Boolean is
9035 S : Entity_Id;
9037 begin
9038 S := Current_Scope;
9039 while Present (S) and then S /= Standard_Standard loop
9040 if Ekind (S) = E_Package and then In_Package_Body (S) then
9041 return True;
9042 else
9043 S := Scope (S);
9044 end if;
9045 end loop;
9047 return False;
9048 end In_Package_Body;
9050 --------------------------------
9051 -- In_Parameter_Specification --
9052 --------------------------------
9054 function In_Parameter_Specification (N : Node_Id) return Boolean is
9055 PN : Node_Id;
9057 begin
9058 PN := Parent (N);
9059 while Present (PN) loop
9060 if Nkind (PN) = N_Parameter_Specification then
9061 return True;
9062 end if;
9064 PN := Parent (PN);
9065 end loop;
9067 return False;
9068 end In_Parameter_Specification;
9070 --------------------------
9071 -- In_Pragma_Expression --
9072 --------------------------
9074 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
9075 P : Node_Id;
9076 begin
9077 P := Parent (N);
9078 loop
9079 if No (P) then
9080 return False;
9081 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
9082 return True;
9083 else
9084 P := Parent (P);
9085 end if;
9086 end loop;
9087 end In_Pragma_Expression;
9089 -------------------------------------
9090 -- In_Reverse_Storage_Order_Object --
9091 -------------------------------------
9093 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
9094 Pref : Node_Id;
9095 Btyp : Entity_Id := Empty;
9097 begin
9098 -- Climb up indexed components
9100 Pref := N;
9101 loop
9102 case Nkind (Pref) is
9103 when N_Selected_Component =>
9104 Pref := Prefix (Pref);
9105 exit;
9107 when N_Indexed_Component =>
9108 Pref := Prefix (Pref);
9110 when others =>
9111 Pref := Empty;
9112 exit;
9113 end case;
9114 end loop;
9116 if Present (Pref) then
9117 Btyp := Base_Type (Etype (Pref));
9118 end if;
9120 return Present (Btyp)
9121 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
9122 and then Reverse_Storage_Order (Btyp);
9123 end In_Reverse_Storage_Order_Object;
9125 --------------------------------------
9126 -- In_Subprogram_Or_Concurrent_Unit --
9127 --------------------------------------
9129 function In_Subprogram_Or_Concurrent_Unit return Boolean is
9130 E : Entity_Id;
9131 K : Entity_Kind;
9133 begin
9134 -- Use scope chain to check successively outer scopes
9136 E := Current_Scope;
9137 loop
9138 K := Ekind (E);
9140 if K in Subprogram_Kind
9141 or else K in Concurrent_Kind
9142 or else K in Generic_Subprogram_Kind
9143 then
9144 return True;
9146 elsif E = Standard_Standard then
9147 return False;
9148 end if;
9150 E := Scope (E);
9151 end loop;
9152 end In_Subprogram_Or_Concurrent_Unit;
9154 ---------------------
9155 -- In_Visible_Part --
9156 ---------------------
9158 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
9159 begin
9160 return Is_Package_Or_Generic_Package (Scope_Id)
9161 and then In_Open_Scopes (Scope_Id)
9162 and then not In_Package_Body (Scope_Id)
9163 and then not In_Private_Part (Scope_Id);
9164 end In_Visible_Part;
9166 --------------------------------
9167 -- Incomplete_Or_Private_View --
9168 --------------------------------
9170 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
9171 function Inspect_Decls
9172 (Decls : List_Id;
9173 Taft : Boolean := False) return Entity_Id;
9174 -- Check whether a declarative region contains the incomplete or private
9175 -- view of Typ.
9177 -------------------
9178 -- Inspect_Decls --
9179 -------------------
9181 function Inspect_Decls
9182 (Decls : List_Id;
9183 Taft : Boolean := False) return Entity_Id
9185 Decl : Node_Id;
9186 Match : Node_Id;
9188 begin
9189 Decl := First (Decls);
9190 while Present (Decl) loop
9191 Match := Empty;
9193 if Taft then
9194 if Nkind (Decl) = N_Incomplete_Type_Declaration then
9195 Match := Defining_Identifier (Decl);
9196 end if;
9198 else
9199 if Nkind_In (Decl, N_Private_Extension_Declaration,
9200 N_Private_Type_Declaration)
9201 then
9202 Match := Defining_Identifier (Decl);
9203 end if;
9204 end if;
9206 if Present (Match)
9207 and then Present (Full_View (Match))
9208 and then Full_View (Match) = Typ
9209 then
9210 return Match;
9211 end if;
9213 Next (Decl);
9214 end loop;
9216 return Empty;
9217 end Inspect_Decls;
9219 -- Local variables
9221 Prev : Entity_Id;
9223 -- Start of processing for Incomplete_Or_Partial_View
9225 begin
9226 -- Incomplete type case
9228 Prev := Current_Entity_In_Scope (Typ);
9230 if Present (Prev)
9231 and then Is_Incomplete_Type (Prev)
9232 and then Present (Full_View (Prev))
9233 and then Full_View (Prev) = Typ
9234 then
9235 return Prev;
9236 end if;
9238 -- Private or Taft amendment type case
9240 declare
9241 Pkg : constant Entity_Id := Scope (Typ);
9242 Pkg_Decl : Node_Id := Pkg;
9244 begin
9245 if Ekind (Pkg) = E_Package then
9246 while Nkind (Pkg_Decl) /= N_Package_Specification loop
9247 Pkg_Decl := Parent (Pkg_Decl);
9248 end loop;
9250 -- It is knows that Typ has a private view, look for it in the
9251 -- visible declarations of the enclosing scope. A special case
9252 -- of this is when the two views have been exchanged - the full
9253 -- appears earlier than the private.
9255 if Has_Private_Declaration (Typ) then
9256 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
9258 -- Exchanged view case, look in the private declarations
9260 if No (Prev) then
9261 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
9262 end if;
9264 return Prev;
9266 -- Otherwise if this is the package body, then Typ is a potential
9267 -- Taft amendment type. The incomplete view should be located in
9268 -- the private declarations of the enclosing scope.
9270 elsif In_Package_Body (Pkg) then
9271 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
9272 end if;
9273 end if;
9274 end;
9276 -- The type has no incomplete or private view
9278 return Empty;
9279 end Incomplete_Or_Private_View;
9281 -----------------------------------------
9282 -- Inherit_Default_Init_Cond_Procedure --
9283 -----------------------------------------
9285 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
9286 Par_Typ : constant Entity_Id := Etype (Typ);
9288 begin
9289 -- A derived type inherits the default initial condition procedure of
9290 -- its parent type.
9292 if No (Default_Init_Cond_Procedure (Typ)) then
9293 Set_Default_Init_Cond_Procedure
9294 (Typ, Default_Init_Cond_Procedure (Par_Typ));
9295 end if;
9296 end Inherit_Default_Init_Cond_Procedure;
9298 ---------------------------------
9299 -- Insert_Explicit_Dereference --
9300 ---------------------------------
9302 procedure Insert_Explicit_Dereference (N : Node_Id) is
9303 New_Prefix : constant Node_Id := Relocate_Node (N);
9304 Ent : Entity_Id := Empty;
9305 Pref : Node_Id;
9306 I : Interp_Index;
9307 It : Interp;
9308 T : Entity_Id;
9310 begin
9311 Save_Interps (N, New_Prefix);
9313 Rewrite (N,
9314 Make_Explicit_Dereference (Sloc (Parent (N)),
9315 Prefix => New_Prefix));
9317 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
9319 if Is_Overloaded (New_Prefix) then
9321 -- The dereference is also overloaded, and its interpretations are
9322 -- the designated types of the interpretations of the original node.
9324 Set_Etype (N, Any_Type);
9326 Get_First_Interp (New_Prefix, I, It);
9327 while Present (It.Nam) loop
9328 T := It.Typ;
9330 if Is_Access_Type (T) then
9331 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
9332 end if;
9334 Get_Next_Interp (I, It);
9335 end loop;
9337 End_Interp_List;
9339 else
9340 -- Prefix is unambiguous: mark the original prefix (which might
9341 -- Come_From_Source) as a reference, since the new (relocated) one
9342 -- won't be taken into account.
9344 if Is_Entity_Name (New_Prefix) then
9345 Ent := Entity (New_Prefix);
9346 Pref := New_Prefix;
9348 -- For a retrieval of a subcomponent of some composite object,
9349 -- retrieve the ultimate entity if there is one.
9351 elsif Nkind_In (New_Prefix, N_Selected_Component,
9352 N_Indexed_Component)
9353 then
9354 Pref := Prefix (New_Prefix);
9355 while Present (Pref)
9356 and then Nkind_In (Pref, N_Selected_Component,
9357 N_Indexed_Component)
9358 loop
9359 Pref := Prefix (Pref);
9360 end loop;
9362 if Present (Pref) and then Is_Entity_Name (Pref) then
9363 Ent := Entity (Pref);
9364 end if;
9365 end if;
9367 -- Place the reference on the entity node
9369 if Present (Ent) then
9370 Generate_Reference (Ent, Pref);
9371 end if;
9372 end if;
9373 end Insert_Explicit_Dereference;
9375 ------------------------------------------
9376 -- Inspect_Deferred_Constant_Completion --
9377 ------------------------------------------
9379 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
9380 Decl : Node_Id;
9382 begin
9383 Decl := First (Decls);
9384 while Present (Decl) loop
9386 -- Deferred constant signature
9388 if Nkind (Decl) = N_Object_Declaration
9389 and then Constant_Present (Decl)
9390 and then No (Expression (Decl))
9392 -- No need to check internally generated constants
9394 and then Comes_From_Source (Decl)
9396 -- The constant is not completed. A full object declaration or a
9397 -- pragma Import complete a deferred constant.
9399 and then not Has_Completion (Defining_Identifier (Decl))
9400 then
9401 Error_Msg_N
9402 ("constant declaration requires initialization expression",
9403 Defining_Identifier (Decl));
9404 end if;
9406 Decl := Next (Decl);
9407 end loop;
9408 end Inspect_Deferred_Constant_Completion;
9410 -----------------------------
9411 -- Is_Actual_Out_Parameter --
9412 -----------------------------
9414 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
9415 Formal : Entity_Id;
9416 Call : Node_Id;
9417 begin
9418 Find_Actual (N, Formal, Call);
9419 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
9420 end Is_Actual_Out_Parameter;
9422 -------------------------
9423 -- Is_Actual_Parameter --
9424 -------------------------
9426 function Is_Actual_Parameter (N : Node_Id) return Boolean is
9427 PK : constant Node_Kind := Nkind (Parent (N));
9429 begin
9430 case PK is
9431 when N_Parameter_Association =>
9432 return N = Explicit_Actual_Parameter (Parent (N));
9434 when N_Subprogram_Call =>
9435 return Is_List_Member (N)
9436 and then
9437 List_Containing (N) = Parameter_Associations (Parent (N));
9439 when others =>
9440 return False;
9441 end case;
9442 end Is_Actual_Parameter;
9444 --------------------------------
9445 -- Is_Actual_Tagged_Parameter --
9446 --------------------------------
9448 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
9449 Formal : Entity_Id;
9450 Call : Node_Id;
9451 begin
9452 Find_Actual (N, Formal, Call);
9453 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
9454 end Is_Actual_Tagged_Parameter;
9456 ---------------------
9457 -- Is_Aliased_View --
9458 ---------------------
9460 function Is_Aliased_View (Obj : Node_Id) return Boolean is
9461 E : Entity_Id;
9463 begin
9464 if Is_Entity_Name (Obj) then
9465 E := Entity (Obj);
9467 return
9468 (Is_Object (E)
9469 and then
9470 (Is_Aliased (E)
9471 or else (Present (Renamed_Object (E))
9472 and then Is_Aliased_View (Renamed_Object (E)))))
9474 or else ((Is_Formal (E)
9475 or else Ekind (E) = E_Generic_In_Out_Parameter
9476 or else Ekind (E) = E_Generic_In_Parameter)
9477 and then Is_Tagged_Type (Etype (E)))
9479 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
9481 -- Current instance of type, either directly or as rewritten
9482 -- reference to the current object.
9484 or else (Is_Entity_Name (Original_Node (Obj))
9485 and then Present (Entity (Original_Node (Obj)))
9486 and then Is_Type (Entity (Original_Node (Obj))))
9488 or else (Is_Type (E) and then E = Current_Scope)
9490 or else (Is_Incomplete_Or_Private_Type (E)
9491 and then Full_View (E) = Current_Scope)
9493 -- Ada 2012 AI05-0053: the return object of an extended return
9494 -- statement is aliased if its type is immutably limited.
9496 or else (Is_Return_Object (E)
9497 and then Is_Limited_View (Etype (E)));
9499 elsif Nkind (Obj) = N_Selected_Component then
9500 return Is_Aliased (Entity (Selector_Name (Obj)));
9502 elsif Nkind (Obj) = N_Indexed_Component then
9503 return Has_Aliased_Components (Etype (Prefix (Obj)))
9504 or else
9505 (Is_Access_Type (Etype (Prefix (Obj)))
9506 and then Has_Aliased_Components
9507 (Designated_Type (Etype (Prefix (Obj)))));
9509 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
9510 return Is_Tagged_Type (Etype (Obj))
9511 and then Is_Aliased_View (Expression (Obj));
9513 elsif Nkind (Obj) = N_Explicit_Dereference then
9514 return Nkind (Original_Node (Obj)) /= N_Function_Call;
9516 else
9517 return False;
9518 end if;
9519 end Is_Aliased_View;
9521 -------------------------
9522 -- Is_Ancestor_Package --
9523 -------------------------
9525 function Is_Ancestor_Package
9526 (E1 : Entity_Id;
9527 E2 : Entity_Id) return Boolean
9529 Par : Entity_Id;
9531 begin
9532 Par := E2;
9533 while Present (Par) and then Par /= Standard_Standard loop
9534 if Par = E1 then
9535 return True;
9536 end if;
9538 Par := Scope (Par);
9539 end loop;
9541 return False;
9542 end Is_Ancestor_Package;
9544 ----------------------
9545 -- Is_Atomic_Object --
9546 ----------------------
9548 function Is_Atomic_Object (N : Node_Id) return Boolean is
9550 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
9551 -- Determines if given object has atomic components
9553 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
9554 -- If prefix is an implicit dereference, examine designated type
9556 ----------------------
9557 -- Is_Atomic_Prefix --
9558 ----------------------
9560 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
9561 begin
9562 if Is_Access_Type (Etype (N)) then
9563 return
9564 Has_Atomic_Components (Designated_Type (Etype (N)));
9565 else
9566 return Object_Has_Atomic_Components (N);
9567 end if;
9568 end Is_Atomic_Prefix;
9570 ----------------------------------
9571 -- Object_Has_Atomic_Components --
9572 ----------------------------------
9574 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
9575 begin
9576 if Has_Atomic_Components (Etype (N))
9577 or else Is_Atomic (Etype (N))
9578 then
9579 return True;
9581 elsif Is_Entity_Name (N)
9582 and then (Has_Atomic_Components (Entity (N))
9583 or else Is_Atomic (Entity (N)))
9584 then
9585 return True;
9587 elsif Nkind (N) = N_Selected_Component
9588 and then Is_Atomic (Entity (Selector_Name (N)))
9589 then
9590 return True;
9592 elsif Nkind (N) = N_Indexed_Component
9593 or else Nkind (N) = N_Selected_Component
9594 then
9595 return Is_Atomic_Prefix (Prefix (N));
9597 else
9598 return False;
9599 end if;
9600 end Object_Has_Atomic_Components;
9602 -- Start of processing for Is_Atomic_Object
9604 begin
9605 -- Predicate is not relevant to subprograms
9607 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
9608 return False;
9610 elsif Is_Atomic (Etype (N))
9611 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
9612 then
9613 return True;
9615 elsif Nkind (N) = N_Selected_Component
9616 and then Is_Atomic (Entity (Selector_Name (N)))
9617 then
9618 return True;
9620 elsif Nkind (N) = N_Indexed_Component
9621 or else Nkind (N) = N_Selected_Component
9622 then
9623 return Is_Atomic_Prefix (Prefix (N));
9625 else
9626 return False;
9627 end if;
9628 end Is_Atomic_Object;
9630 -------------------------
9631 -- Is_Attribute_Result --
9632 -------------------------
9634 function Is_Attribute_Result (N : Node_Id) return Boolean is
9635 begin
9636 return Nkind (N) = N_Attribute_Reference
9637 and then Attribute_Name (N) = Name_Result;
9638 end Is_Attribute_Result;
9640 ------------------------------------
9641 -- Is_Body_Or_Package_Declaration --
9642 ------------------------------------
9644 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
9645 begin
9646 return Nkind_In (N, N_Entry_Body,
9647 N_Package_Body,
9648 N_Package_Declaration,
9649 N_Protected_Body,
9650 N_Subprogram_Body,
9651 N_Task_Body);
9652 end Is_Body_Or_Package_Declaration;
9654 -----------------------
9655 -- Is_Bounded_String --
9656 -----------------------
9658 function Is_Bounded_String (T : Entity_Id) return Boolean is
9659 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
9661 begin
9662 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9663 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9664 -- be True for all the Bounded_String types in instances of the
9665 -- Generic_Bounded_Length generics, and for types derived from those.
9667 return Present (Under)
9668 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
9669 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
9670 Is_RTE (Root_Type (Under), RO_WW_Super_String));
9671 end Is_Bounded_String;
9673 -------------------------
9674 -- Is_Child_Or_Sibling --
9675 -------------------------
9677 function Is_Child_Or_Sibling
9678 (Pack_1 : Entity_Id;
9679 Pack_2 : Entity_Id) return Boolean
9681 function Distance_From_Standard (Pack : Entity_Id) return Nat;
9682 -- Given an arbitrary package, return the number of "climbs" necessary
9683 -- to reach scope Standard_Standard.
9685 procedure Equalize_Depths
9686 (Pack : in out Entity_Id;
9687 Depth : in out Nat;
9688 Depth_To_Reach : Nat);
9689 -- Given an arbitrary package, its depth and a target depth to reach,
9690 -- climb the scope chain until the said depth is reached. The pointer
9691 -- to the package and its depth a modified during the climb.
9693 ----------------------------
9694 -- Distance_From_Standard --
9695 ----------------------------
9697 function Distance_From_Standard (Pack : Entity_Id) return Nat is
9698 Dist : Nat;
9699 Scop : Entity_Id;
9701 begin
9702 Dist := 0;
9703 Scop := Pack;
9704 while Present (Scop) and then Scop /= Standard_Standard loop
9705 Dist := Dist + 1;
9706 Scop := Scope (Scop);
9707 end loop;
9709 return Dist;
9710 end Distance_From_Standard;
9712 ---------------------
9713 -- Equalize_Depths --
9714 ---------------------
9716 procedure Equalize_Depths
9717 (Pack : in out Entity_Id;
9718 Depth : in out Nat;
9719 Depth_To_Reach : Nat)
9721 begin
9722 -- The package must be at a greater or equal depth
9724 if Depth < Depth_To_Reach then
9725 raise Program_Error;
9726 end if;
9728 -- Climb the scope chain until the desired depth is reached
9730 while Present (Pack) and then Depth /= Depth_To_Reach loop
9731 Pack := Scope (Pack);
9732 Depth := Depth - 1;
9733 end loop;
9734 end Equalize_Depths;
9736 -- Local variables
9738 P_1 : Entity_Id := Pack_1;
9739 P_1_Child : Boolean := False;
9740 P_1_Depth : Nat := Distance_From_Standard (P_1);
9741 P_2 : Entity_Id := Pack_2;
9742 P_2_Child : Boolean := False;
9743 P_2_Depth : Nat := Distance_From_Standard (P_2);
9745 -- Start of processing for Is_Child_Or_Sibling
9747 begin
9748 pragma Assert
9749 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
9751 -- Both packages denote the same entity, therefore they cannot be
9752 -- children or siblings.
9754 if P_1 = P_2 then
9755 return False;
9757 -- One of the packages is at a deeper level than the other. Note that
9758 -- both may still come from differen hierarchies.
9760 -- (root) P_2
9761 -- / \ :
9762 -- X P_2 or X
9763 -- : :
9764 -- P_1 P_1
9766 elsif P_1_Depth > P_2_Depth then
9767 Equalize_Depths
9768 (Pack => P_1,
9769 Depth => P_1_Depth,
9770 Depth_To_Reach => P_2_Depth);
9771 P_1_Child := True;
9773 -- (root) P_1
9774 -- / \ :
9775 -- P_1 X or X
9776 -- : :
9777 -- P_2 P_2
9779 elsif P_2_Depth > P_1_Depth then
9780 Equalize_Depths
9781 (Pack => P_2,
9782 Depth => P_2_Depth,
9783 Depth_To_Reach => P_1_Depth);
9784 P_2_Child := True;
9785 end if;
9787 -- At this stage the package pointers have been elevated to the same
9788 -- depth. If the related entities are the same, then one package is a
9789 -- potential child of the other:
9791 -- P_1
9792 -- :
9793 -- X became P_1 P_2 or vica versa
9794 -- :
9795 -- P_2
9797 if P_1 = P_2 then
9798 if P_1_Child then
9799 return Is_Child_Unit (Pack_1);
9801 else pragma Assert (P_2_Child);
9802 return Is_Child_Unit (Pack_2);
9803 end if;
9805 -- The packages may come from the same package chain or from entirely
9806 -- different hierarcies. To determine this, climb the scope stack until
9807 -- a common root is found.
9809 -- (root) (root 1) (root 2)
9810 -- / \ | |
9811 -- P_1 P_2 P_1 P_2
9813 else
9814 while Present (P_1) and then Present (P_2) loop
9816 -- The two packages may be siblings
9818 if P_1 = P_2 then
9819 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
9820 end if;
9822 P_1 := Scope (P_1);
9823 P_2 := Scope (P_2);
9824 end loop;
9825 end if;
9827 return False;
9828 end Is_Child_Or_Sibling;
9830 -----------------------------
9831 -- Is_Concurrent_Interface --
9832 -----------------------------
9834 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
9835 begin
9836 return Is_Interface (T)
9837 and then
9838 (Is_Protected_Interface (T)
9839 or else Is_Synchronized_Interface (T)
9840 or else Is_Task_Interface (T));
9841 end Is_Concurrent_Interface;
9843 ---------------------------
9844 -- Is_Container_Element --
9845 ---------------------------
9847 function Is_Container_Element (Exp : Node_Id) return Boolean is
9848 Loc : constant Source_Ptr := Sloc (Exp);
9849 Pref : constant Node_Id := Prefix (Exp);
9851 Call : Node_Id;
9852 -- Call to an indexing aspect
9854 Cont_Typ : Entity_Id;
9855 -- The type of the container being accessed
9857 Elem_Typ : Entity_Id;
9858 -- Its element type
9860 Indexing : Entity_Id;
9861 Is_Const : Boolean;
9862 -- Indicates that constant indexing is used, and the element is thus
9863 -- a constant.
9865 Ref_Typ : Entity_Id;
9866 -- The reference type returned by the indexing operation
9868 begin
9869 -- If C is a container, in a context that imposes the element type of
9870 -- that container, the indexing notation C (X) is rewritten as:
9872 -- Indexing (C, X).Discr.all
9874 -- where Indexing is one of the indexing aspects of the container.
9875 -- If the context does not require a reference, the construct can be
9876 -- rewritten as
9878 -- Element (C, X)
9880 -- First, verify that the construct has the proper form
9882 if not Expander_Active then
9883 return False;
9885 elsif Nkind (Pref) /= N_Selected_Component then
9886 return False;
9888 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
9889 return False;
9891 else
9892 Call := Prefix (Pref);
9893 Ref_Typ := Etype (Call);
9894 end if;
9896 if not Has_Implicit_Dereference (Ref_Typ)
9897 or else No (First (Parameter_Associations (Call)))
9898 or else not Is_Entity_Name (Name (Call))
9899 then
9900 return False;
9901 end if;
9903 -- Retrieve type of container object, and its iterator aspects
9905 Cont_Typ := Etype (First (Parameter_Associations (Call)));
9906 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
9907 Is_Const := False;
9909 if No (Indexing) then
9911 -- Container should have at least one indexing operation
9913 return False;
9915 elsif Entity (Name (Call)) /= Entity (Indexing) then
9917 -- This may be a variable indexing operation
9919 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
9921 if No (Indexing)
9922 or else Entity (Name (Call)) /= Entity (Indexing)
9923 then
9924 return False;
9925 end if;
9927 else
9928 Is_Const := True;
9929 end if;
9931 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
9933 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
9934 return False;
9935 end if;
9937 -- Check that the expression is not the target of an assignment, in
9938 -- which case the rewriting is not possible.
9940 if not Is_Const then
9941 declare
9942 Par : Node_Id;
9944 begin
9945 Par := Exp;
9946 while Present (Par)
9947 loop
9948 if Nkind (Parent (Par)) = N_Assignment_Statement
9949 and then Par = Name (Parent (Par))
9950 then
9951 return False;
9953 -- A renaming produces a reference, and the transformation
9954 -- does not apply.
9956 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
9957 return False;
9959 elsif Nkind_In
9960 (Nkind (Parent (Par)), N_Function_Call,
9961 N_Procedure_Call_Statement,
9962 N_Entry_Call_Statement)
9963 then
9964 -- Check that the element is not part of an actual for an
9965 -- in-out parameter.
9967 declare
9968 F : Entity_Id;
9969 A : Node_Id;
9971 begin
9972 F := First_Formal (Entity (Name (Parent (Par))));
9973 A := First (Parameter_Associations (Parent (Par)));
9974 while Present (F) loop
9975 if A = Par and then Ekind (F) /= E_In_Parameter then
9976 return False;
9977 end if;
9979 Next_Formal (F);
9980 Next (A);
9981 end loop;
9982 end;
9984 -- E_In_Parameter in a call: element is not modified.
9986 exit;
9987 end if;
9989 Par := Parent (Par);
9990 end loop;
9991 end;
9992 end if;
9994 -- The expression has the proper form and the context requires the
9995 -- element type. Retrieve the Element function of the container and
9996 -- rewrite the construct as a call to it.
9998 declare
9999 Op : Elmt_Id;
10001 begin
10002 Op := First_Elmt (Primitive_Operations (Cont_Typ));
10003 while Present (Op) loop
10004 exit when Chars (Node (Op)) = Name_Element;
10005 Next_Elmt (Op);
10006 end loop;
10008 if No (Op) then
10009 return False;
10011 else
10012 Rewrite (Exp,
10013 Make_Function_Call (Loc,
10014 Name => New_Occurrence_Of (Node (Op), Loc),
10015 Parameter_Associations => Parameter_Associations (Call)));
10016 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
10017 return True;
10018 end if;
10019 end;
10020 end Is_Container_Element;
10022 -----------------------
10023 -- Is_Constant_Bound --
10024 -----------------------
10026 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
10027 begin
10028 if Compile_Time_Known_Value (Exp) then
10029 return True;
10031 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10032 return Is_Constant_Object (Entity (Exp))
10033 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10035 elsif Nkind (Exp) in N_Binary_Op then
10036 return Is_Constant_Bound (Left_Opnd (Exp))
10037 and then Is_Constant_Bound (Right_Opnd (Exp))
10038 and then Scope (Entity (Exp)) = Standard_Standard;
10040 else
10041 return False;
10042 end if;
10043 end Is_Constant_Bound;
10045 --------------------------------------
10046 -- Is_Controlling_Limited_Procedure --
10047 --------------------------------------
10049 function Is_Controlling_Limited_Procedure
10050 (Proc_Nam : Entity_Id) return Boolean
10052 Param_Typ : Entity_Id := Empty;
10054 begin
10055 if Ekind (Proc_Nam) = E_Procedure
10056 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
10057 then
10058 Param_Typ := Etype (Parameter_Type (First (
10059 Parameter_Specifications (Parent (Proc_Nam)))));
10061 -- In this case where an Itype was created, the procedure call has been
10062 -- rewritten.
10064 elsif Present (Associated_Node_For_Itype (Proc_Nam))
10065 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
10066 and then
10067 Present (Parameter_Associations
10068 (Associated_Node_For_Itype (Proc_Nam)))
10069 then
10070 Param_Typ :=
10071 Etype (First (Parameter_Associations
10072 (Associated_Node_For_Itype (Proc_Nam))));
10073 end if;
10075 if Present (Param_Typ) then
10076 return
10077 Is_Interface (Param_Typ)
10078 and then Is_Limited_Record (Param_Typ);
10079 end if;
10081 return False;
10082 end Is_Controlling_Limited_Procedure;
10084 -----------------------------
10085 -- Is_CPP_Constructor_Call --
10086 -----------------------------
10088 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
10089 begin
10090 return Nkind (N) = N_Function_Call
10091 and then Is_CPP_Class (Etype (Etype (N)))
10092 and then Is_Constructor (Entity (Name (N)))
10093 and then Is_Imported (Entity (Name (N)));
10094 end Is_CPP_Constructor_Call;
10096 -----------------
10097 -- Is_Delegate --
10098 -----------------
10100 function Is_Delegate (T : Entity_Id) return Boolean is
10101 Desig_Type : Entity_Id;
10103 begin
10104 if VM_Target /= CLI_Target then
10105 return False;
10106 end if;
10108 -- Access-to-subprograms are delegates in CIL
10110 if Ekind (T) = E_Access_Subprogram_Type then
10111 return True;
10112 end if;
10114 if not Is_Access_Type (T) then
10116 -- A delegate is a managed pointer. If no designated type is defined
10117 -- it means that it's not a delegate.
10119 return False;
10120 end if;
10122 Desig_Type := Etype (Directly_Designated_Type (T));
10124 if not Is_Tagged_Type (Desig_Type) then
10125 return False;
10126 end if;
10128 -- Test if the type is inherited from [mscorlib]System.Delegate
10130 while Etype (Desig_Type) /= Desig_Type loop
10131 if Chars (Scope (Desig_Type)) /= No_Name
10132 and then Is_Imported (Scope (Desig_Type))
10133 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
10134 then
10135 return True;
10136 end if;
10138 Desig_Type := Etype (Desig_Type);
10139 end loop;
10141 return False;
10142 end Is_Delegate;
10144 ----------------------------------------------
10145 -- Is_Dependent_Component_Of_Mutable_Object --
10146 ----------------------------------------------
10148 function Is_Dependent_Component_Of_Mutable_Object
10149 (Object : Node_Id) return Boolean
10151 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
10152 -- Returns True if and only if Comp is declared within a variant part
10154 --------------------------------
10155 -- Is_Declared_Within_Variant --
10156 --------------------------------
10158 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
10159 Comp_Decl : constant Node_Id := Parent (Comp);
10160 Comp_List : constant Node_Id := Parent (Comp_Decl);
10161 begin
10162 return Nkind (Parent (Comp_List)) = N_Variant;
10163 end Is_Declared_Within_Variant;
10165 P : Node_Id;
10166 Prefix_Type : Entity_Id;
10167 P_Aliased : Boolean := False;
10168 Comp : Entity_Id;
10170 Deref : Node_Id := Object;
10171 -- Dereference node, in something like X.all.Y(2)
10173 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10175 begin
10176 -- Find the dereference node if any
10178 while Nkind_In (Deref, N_Indexed_Component,
10179 N_Selected_Component,
10180 N_Slice)
10181 loop
10182 Deref := Prefix (Deref);
10183 end loop;
10185 -- Ada 2005: If we have a component or slice of a dereference,
10186 -- something like X.all.Y (2), and the type of X is access-to-constant,
10187 -- Is_Variable will return False, because it is indeed a constant
10188 -- view. But it might be a view of a variable object, so we want the
10189 -- following condition to be True in that case.
10191 if Is_Variable (Object)
10192 or else (Ada_Version >= Ada_2005
10193 and then Nkind (Deref) = N_Explicit_Dereference)
10194 then
10195 if Nkind (Object) = N_Selected_Component then
10196 P := Prefix (Object);
10197 Prefix_Type := Etype (P);
10199 if Is_Entity_Name (P) then
10200 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
10201 Prefix_Type := Base_Type (Prefix_Type);
10202 end if;
10204 if Is_Aliased (Entity (P)) then
10205 P_Aliased := True;
10206 end if;
10208 -- A discriminant check on a selected component may be expanded
10209 -- into a dereference when removing side-effects. Recover the
10210 -- original node and its type, which may be unconstrained.
10212 elsif Nkind (P) = N_Explicit_Dereference
10213 and then not (Comes_From_Source (P))
10214 then
10215 P := Original_Node (P);
10216 Prefix_Type := Etype (P);
10218 else
10219 -- Check for prefix being an aliased component???
10221 null;
10223 end if;
10225 -- A heap object is constrained by its initial value
10227 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10228 -- the dereferenced case, since the access value might denote an
10229 -- unconstrained aliased object, whereas in Ada 95 the designated
10230 -- object is guaranteed to be constrained. A worst-case assumption
10231 -- has to apply in Ada 2005 because we can't tell at compile
10232 -- time whether the object is "constrained by its initial value"
10233 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10234 -- rules (these rules are acknowledged to need fixing).
10236 if Ada_Version < Ada_2005 then
10237 if Is_Access_Type (Prefix_Type)
10238 or else Nkind (P) = N_Explicit_Dereference
10239 then
10240 return False;
10241 end if;
10243 else pragma Assert (Ada_Version >= Ada_2005);
10244 if Is_Access_Type (Prefix_Type) then
10246 -- If the access type is pool-specific, and there is no
10247 -- constrained partial view of the designated type, then the
10248 -- designated object is known to be constrained.
10250 if Ekind (Prefix_Type) = E_Access_Type
10251 and then not Object_Type_Has_Constrained_Partial_View
10252 (Typ => Designated_Type (Prefix_Type),
10253 Scop => Current_Scope)
10254 then
10255 return False;
10257 -- Otherwise (general access type, or there is a constrained
10258 -- partial view of the designated type), we need to check
10259 -- based on the designated type.
10261 else
10262 Prefix_Type := Designated_Type (Prefix_Type);
10263 end if;
10264 end if;
10265 end if;
10267 Comp :=
10268 Original_Record_Component (Entity (Selector_Name (Object)));
10270 -- As per AI-0017, the renaming is illegal in a generic body, even
10271 -- if the subtype is indefinite.
10273 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10275 if not Is_Constrained (Prefix_Type)
10276 and then (not Is_Indefinite_Subtype (Prefix_Type)
10277 or else
10278 (Is_Generic_Type (Prefix_Type)
10279 and then Ekind (Current_Scope) = E_Generic_Package
10280 and then In_Package_Body (Current_Scope)))
10282 and then (Is_Declared_Within_Variant (Comp)
10283 or else Has_Discriminant_Dependent_Constraint (Comp))
10284 and then (not P_Aliased or else Ada_Version >= Ada_2005)
10285 then
10286 return True;
10288 -- If the prefix is of an access type at this point, then we want
10289 -- to return False, rather than calling this function recursively
10290 -- on the access object (which itself might be a discriminant-
10291 -- dependent component of some other object, but that isn't
10292 -- relevant to checking the object passed to us). This avoids
10293 -- issuing wrong errors when compiling with -gnatc, where there
10294 -- can be implicit dereferences that have not been expanded.
10296 elsif Is_Access_Type (Etype (Prefix (Object))) then
10297 return False;
10299 else
10300 return
10301 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10302 end if;
10304 elsif Nkind (Object) = N_Indexed_Component
10305 or else Nkind (Object) = N_Slice
10306 then
10307 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10309 -- A type conversion that Is_Variable is a view conversion:
10310 -- go back to the denoted object.
10312 elsif Nkind (Object) = N_Type_Conversion then
10313 return
10314 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
10315 end if;
10316 end if;
10318 return False;
10319 end Is_Dependent_Component_Of_Mutable_Object;
10321 ---------------------
10322 -- Is_Dereferenced --
10323 ---------------------
10325 function Is_Dereferenced (N : Node_Id) return Boolean is
10326 P : constant Node_Id := Parent (N);
10327 begin
10328 return Nkind_In (P, N_Selected_Component,
10329 N_Explicit_Dereference,
10330 N_Indexed_Component,
10331 N_Slice)
10332 and then Prefix (P) = N;
10333 end Is_Dereferenced;
10335 ----------------------
10336 -- Is_Descendent_Of --
10337 ----------------------
10339 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
10340 T : Entity_Id;
10341 Etyp : Entity_Id;
10343 begin
10344 pragma Assert (Nkind (T1) in N_Entity);
10345 pragma Assert (Nkind (T2) in N_Entity);
10347 T := Base_Type (T1);
10349 -- Immediate return if the types match
10351 if T = T2 then
10352 return True;
10354 -- Comment needed here ???
10356 elsif Ekind (T) = E_Class_Wide_Type then
10357 return Etype (T) = T2;
10359 -- All other cases
10361 else
10362 loop
10363 Etyp := Etype (T);
10365 -- Done if we found the type we are looking for
10367 if Etyp = T2 then
10368 return True;
10370 -- Done if no more derivations to check
10372 elsif T = T1
10373 or else T = Etyp
10374 then
10375 return False;
10377 -- Following test catches error cases resulting from prev errors
10379 elsif No (Etyp) then
10380 return False;
10382 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
10383 return False;
10385 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
10386 return False;
10387 end if;
10389 T := Base_Type (Etyp);
10390 end loop;
10391 end if;
10392 end Is_Descendent_Of;
10394 -----------------------------
10395 -- Is_Effectively_Volatile --
10396 -----------------------------
10398 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
10399 begin
10400 if Is_Type (Id) then
10402 -- An arbitrary type is effectively volatile when it is subject to
10403 -- pragma Atomic or Volatile.
10405 if Is_Volatile (Id) then
10406 return True;
10408 -- An array type is effectively volatile when it is subject to pragma
10409 -- Atomic_Components or Volatile_Components or its compolent type is
10410 -- effectively volatile.
10412 elsif Is_Array_Type (Id) then
10413 return
10414 Has_Volatile_Components (Id)
10415 or else
10416 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
10418 else
10419 return False;
10420 end if;
10422 -- Otherwise Id denotes an object
10424 else
10425 return
10426 Is_Volatile (Id)
10427 or else Has_Volatile_Components (Id)
10428 or else Is_Effectively_Volatile (Etype (Id));
10429 end if;
10430 end Is_Effectively_Volatile;
10432 ------------------------------------
10433 -- Is_Effectively_Volatile_Object --
10434 ------------------------------------
10436 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
10437 begin
10438 if Is_Entity_Name (N) then
10439 return Is_Effectively_Volatile (Entity (N));
10441 elsif Nkind (N) = N_Expanded_Name then
10442 return Is_Effectively_Volatile (Entity (N));
10444 elsif Nkind (N) = N_Indexed_Component then
10445 return Is_Effectively_Volatile_Object (Prefix (N));
10447 elsif Nkind (N) = N_Selected_Component then
10448 return
10449 Is_Effectively_Volatile_Object (Prefix (N))
10450 or else
10451 Is_Effectively_Volatile_Object (Selector_Name (N));
10453 else
10454 return False;
10455 end if;
10456 end Is_Effectively_Volatile_Object;
10458 ----------------------------
10459 -- Is_Expression_Function --
10460 ----------------------------
10462 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
10463 Decl : Node_Id;
10465 begin
10466 if Ekind (Subp) /= E_Function then
10467 return False;
10469 else
10470 Decl := Unit_Declaration_Node (Subp);
10471 return Nkind (Decl) = N_Subprogram_Declaration
10472 and then
10473 (Nkind (Original_Node (Decl)) = N_Expression_Function
10474 or else
10475 (Present (Corresponding_Body (Decl))
10476 and then
10477 Nkind (Original_Node
10478 (Unit_Declaration_Node
10479 (Corresponding_Body (Decl)))) =
10480 N_Expression_Function));
10481 end if;
10482 end Is_Expression_Function;
10484 --------------
10485 -- Is_False --
10486 --------------
10488 function Is_False (U : Uint) return Boolean is
10489 begin
10490 return (U = 0);
10491 end Is_False;
10493 ---------------------------
10494 -- Is_Fixed_Model_Number --
10495 ---------------------------
10497 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
10498 S : constant Ureal := Small_Value (T);
10499 M : Urealp.Save_Mark;
10500 R : Boolean;
10501 begin
10502 M := Urealp.Mark;
10503 R := (U = UR_Trunc (U / S) * S);
10504 Urealp.Release (M);
10505 return R;
10506 end Is_Fixed_Model_Number;
10508 -------------------------------
10509 -- Is_Fully_Initialized_Type --
10510 -------------------------------
10512 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
10513 begin
10514 -- In Ada2012, a scalar type with an aspect Default_Value
10515 -- is fully initialized.
10517 if Is_Scalar_Type (Typ) then
10518 return Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ);
10520 elsif Is_Access_Type (Typ) then
10521 return True;
10523 elsif Is_Array_Type (Typ) then
10524 if Is_Fully_Initialized_Type (Component_Type (Typ))
10525 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
10526 then
10527 return True;
10528 end if;
10530 -- An interesting case, if we have a constrained type one of whose
10531 -- bounds is known to be null, then there are no elements to be
10532 -- initialized, so all the elements are initialized.
10534 if Is_Constrained (Typ) then
10535 declare
10536 Indx : Node_Id;
10537 Indx_Typ : Entity_Id;
10538 Lbd, Hbd : Node_Id;
10540 begin
10541 Indx := First_Index (Typ);
10542 while Present (Indx) loop
10543 if Etype (Indx) = Any_Type then
10544 return False;
10546 -- If index is a range, use directly
10548 elsif Nkind (Indx) = N_Range then
10549 Lbd := Low_Bound (Indx);
10550 Hbd := High_Bound (Indx);
10552 else
10553 Indx_Typ := Etype (Indx);
10555 if Is_Private_Type (Indx_Typ) then
10556 Indx_Typ := Full_View (Indx_Typ);
10557 end if;
10559 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
10560 return False;
10561 else
10562 Lbd := Type_Low_Bound (Indx_Typ);
10563 Hbd := Type_High_Bound (Indx_Typ);
10564 end if;
10565 end if;
10567 if Compile_Time_Known_Value (Lbd)
10568 and then
10569 Compile_Time_Known_Value (Hbd)
10570 then
10571 if Expr_Value (Hbd) < Expr_Value (Lbd) then
10572 return True;
10573 end if;
10574 end if;
10576 Next_Index (Indx);
10577 end loop;
10578 end;
10579 end if;
10581 -- If no null indexes, then type is not fully initialized
10583 return False;
10585 -- Record types
10587 elsif Is_Record_Type (Typ) then
10588 if Has_Discriminants (Typ)
10589 and then
10590 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
10591 and then Is_Fully_Initialized_Variant (Typ)
10592 then
10593 return True;
10594 end if;
10596 -- We consider bounded string types to be fully initialized, because
10597 -- otherwise we get false alarms when the Data component is not
10598 -- default-initialized.
10600 if Is_Bounded_String (Typ) then
10601 return True;
10602 end if;
10604 -- Controlled records are considered to be fully initialized if
10605 -- there is a user defined Initialize routine. This may not be
10606 -- entirely correct, but as the spec notes, we are guessing here
10607 -- what is best from the point of view of issuing warnings.
10609 if Is_Controlled (Typ) then
10610 declare
10611 Utyp : constant Entity_Id := Underlying_Type (Typ);
10613 begin
10614 if Present (Utyp) then
10615 declare
10616 Init : constant Entity_Id :=
10617 (Find_Prim_Op
10618 (Underlying_Type (Typ), Name_Initialize));
10620 begin
10621 if Present (Init)
10622 and then Comes_From_Source (Init)
10623 and then not
10624 Is_Predefined_File_Name
10625 (File_Name (Get_Source_File_Index (Sloc (Init))))
10626 then
10627 return True;
10629 elsif Has_Null_Extension (Typ)
10630 and then
10631 Is_Fully_Initialized_Type
10632 (Etype (Base_Type (Typ)))
10633 then
10634 return True;
10635 end if;
10636 end;
10637 end if;
10638 end;
10639 end if;
10641 -- Otherwise see if all record components are initialized
10643 declare
10644 Ent : Entity_Id;
10646 begin
10647 Ent := First_Entity (Typ);
10648 while Present (Ent) loop
10649 if Ekind (Ent) = E_Component
10650 and then (No (Parent (Ent))
10651 or else No (Expression (Parent (Ent))))
10652 and then not Is_Fully_Initialized_Type (Etype (Ent))
10654 -- Special VM case for tag components, which need to be
10655 -- defined in this case, but are never initialized as VMs
10656 -- are using other dispatching mechanisms. Ignore this
10657 -- uninitialized case. Note that this applies both to the
10658 -- uTag entry and the main vtable pointer (CPP_Class case).
10660 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
10661 then
10662 return False;
10663 end if;
10665 Next_Entity (Ent);
10666 end loop;
10667 end;
10669 -- No uninitialized components, so type is fully initialized.
10670 -- Note that this catches the case of no components as well.
10672 return True;
10674 elsif Is_Concurrent_Type (Typ) then
10675 return True;
10677 elsif Is_Private_Type (Typ) then
10678 declare
10679 U : constant Entity_Id := Underlying_Type (Typ);
10681 begin
10682 if No (U) then
10683 return False;
10684 else
10685 return Is_Fully_Initialized_Type (U);
10686 end if;
10687 end;
10689 else
10690 return False;
10691 end if;
10692 end Is_Fully_Initialized_Type;
10694 ----------------------------------
10695 -- Is_Fully_Initialized_Variant --
10696 ----------------------------------
10698 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
10699 Loc : constant Source_Ptr := Sloc (Typ);
10700 Constraints : constant List_Id := New_List;
10701 Components : constant Elist_Id := New_Elmt_List;
10702 Comp_Elmt : Elmt_Id;
10703 Comp_Id : Node_Id;
10704 Comp_List : Node_Id;
10705 Discr : Entity_Id;
10706 Discr_Val : Node_Id;
10708 Report_Errors : Boolean;
10709 pragma Warnings (Off, Report_Errors);
10711 begin
10712 if Serious_Errors_Detected > 0 then
10713 return False;
10714 end if;
10716 if Is_Record_Type (Typ)
10717 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
10718 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
10719 then
10720 Comp_List := Component_List (Type_Definition (Parent (Typ)));
10722 Discr := First_Discriminant (Typ);
10723 while Present (Discr) loop
10724 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
10725 Discr_Val := Expression (Parent (Discr));
10727 if Present (Discr_Val)
10728 and then Is_OK_Static_Expression (Discr_Val)
10729 then
10730 Append_To (Constraints,
10731 Make_Component_Association (Loc,
10732 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
10733 Expression => New_Copy (Discr_Val)));
10734 else
10735 return False;
10736 end if;
10737 else
10738 return False;
10739 end if;
10741 Next_Discriminant (Discr);
10742 end loop;
10744 Gather_Components
10745 (Typ => Typ,
10746 Comp_List => Comp_List,
10747 Governed_By => Constraints,
10748 Into => Components,
10749 Report_Errors => Report_Errors);
10751 -- Check that each component present is fully initialized
10753 Comp_Elmt := First_Elmt (Components);
10754 while Present (Comp_Elmt) loop
10755 Comp_Id := Node (Comp_Elmt);
10757 if Ekind (Comp_Id) = E_Component
10758 and then (No (Parent (Comp_Id))
10759 or else No (Expression (Parent (Comp_Id))))
10760 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
10761 then
10762 return False;
10763 end if;
10765 Next_Elmt (Comp_Elmt);
10766 end loop;
10768 return True;
10770 elsif Is_Private_Type (Typ) then
10771 declare
10772 U : constant Entity_Id := Underlying_Type (Typ);
10774 begin
10775 if No (U) then
10776 return False;
10777 else
10778 return Is_Fully_Initialized_Variant (U);
10779 end if;
10780 end;
10782 else
10783 return False;
10784 end if;
10785 end Is_Fully_Initialized_Variant;
10787 ----------------------------
10788 -- Is_Inherited_Operation --
10789 ----------------------------
10791 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
10792 pragma Assert (Is_Overloadable (E));
10793 Kind : constant Node_Kind := Nkind (Parent (E));
10794 begin
10795 return Kind = N_Full_Type_Declaration
10796 or else Kind = N_Private_Extension_Declaration
10797 or else Kind = N_Subtype_Declaration
10798 or else (Ekind (E) = E_Enumeration_Literal
10799 and then Is_Derived_Type (Etype (E)));
10800 end Is_Inherited_Operation;
10802 -------------------------------------
10803 -- Is_Inherited_Operation_For_Type --
10804 -------------------------------------
10806 function Is_Inherited_Operation_For_Type
10807 (E : Entity_Id;
10808 Typ : Entity_Id) return Boolean
10810 begin
10811 -- Check that the operation has been created by the type declaration
10813 return Is_Inherited_Operation (E)
10814 and then Defining_Identifier (Parent (E)) = Typ;
10815 end Is_Inherited_Operation_For_Type;
10817 -----------------
10818 -- Is_Iterator --
10819 -----------------
10821 function Is_Iterator (Typ : Entity_Id) return Boolean is
10822 Ifaces_List : Elist_Id;
10823 Iface_Elmt : Elmt_Id;
10824 Iface : Entity_Id;
10826 begin
10827 if Is_Class_Wide_Type (Typ)
10828 and then Nam_In (Chars (Etype (Typ)), Name_Forward_Iterator,
10829 Name_Reversible_Iterator)
10830 and then
10831 Is_Predefined_File_Name
10832 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
10833 then
10834 return True;
10836 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
10837 return False;
10839 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
10840 return True;
10842 else
10843 Collect_Interfaces (Typ, Ifaces_List);
10845 Iface_Elmt := First_Elmt (Ifaces_List);
10846 while Present (Iface_Elmt) loop
10847 Iface := Node (Iface_Elmt);
10848 if Chars (Iface) = Name_Forward_Iterator
10849 and then
10850 Is_Predefined_File_Name
10851 (Unit_File_Name (Get_Source_Unit (Iface)))
10852 then
10853 return True;
10854 end if;
10856 Next_Elmt (Iface_Elmt);
10857 end loop;
10859 return False;
10860 end if;
10861 end Is_Iterator;
10863 ------------
10864 -- Is_LHS --
10865 ------------
10867 -- We seem to have a lot of overlapping functions that do similar things
10868 -- (testing for left hand sides or lvalues???).
10870 function Is_LHS (N : Node_Id) return Is_LHS_Result is
10871 P : constant Node_Id := Parent (N);
10873 begin
10874 -- Return True if we are the left hand side of an assignment statement
10876 if Nkind (P) = N_Assignment_Statement then
10877 if Name (P) = N then
10878 return Yes;
10879 else
10880 return No;
10881 end if;
10883 -- Case of prefix of indexed or selected component or slice
10885 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
10886 and then N = Prefix (P)
10887 then
10888 -- Here we have the case where the parent P is N.Q or N(Q .. R).
10889 -- If P is an LHS, then N is also effectively an LHS, but there
10890 -- is an important exception. If N is of an access type, then
10891 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
10892 -- case this makes N.all a left hand side but not N itself.
10894 -- If we don't know the type yet, this is the case where we return
10895 -- Unknown, since the answer depends on the type which is unknown.
10897 if No (Etype (N)) then
10898 return Unknown;
10900 -- We have an Etype set, so we can check it
10902 elsif Is_Access_Type (Etype (N)) then
10903 return No;
10905 -- OK, not access type case, so just test whole expression
10907 else
10908 return Is_LHS (P);
10909 end if;
10911 -- All other cases are not left hand sides
10913 else
10914 return No;
10915 end if;
10916 end Is_LHS;
10918 -----------------------------
10919 -- Is_Library_Level_Entity --
10920 -----------------------------
10922 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
10923 begin
10924 -- The following is a small optimization, and it also properly handles
10925 -- discriminals, which in task bodies might appear in expressions before
10926 -- the corresponding procedure has been created, and which therefore do
10927 -- not have an assigned scope.
10929 if Is_Formal (E) then
10930 return False;
10931 end if;
10933 -- Normal test is simply that the enclosing dynamic scope is Standard
10935 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
10936 end Is_Library_Level_Entity;
10938 --------------------------------
10939 -- Is_Limited_Class_Wide_Type --
10940 --------------------------------
10942 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
10943 begin
10944 return
10945 Is_Class_Wide_Type (Typ)
10946 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
10947 end Is_Limited_Class_Wide_Type;
10949 ---------------------------------
10950 -- Is_Local_Variable_Reference --
10951 ---------------------------------
10953 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
10954 begin
10955 if not Is_Entity_Name (Expr) then
10956 return False;
10958 else
10959 declare
10960 Ent : constant Entity_Id := Entity (Expr);
10961 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
10962 begin
10963 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
10964 return False;
10965 else
10966 return Present (Sub) and then Sub = Current_Subprogram;
10967 end if;
10968 end;
10969 end if;
10970 end Is_Local_Variable_Reference;
10972 -------------------------
10973 -- Is_Object_Reference --
10974 -------------------------
10976 function Is_Object_Reference (N : Node_Id) return Boolean is
10978 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
10979 -- Determine whether N is the name of an internally-generated renaming
10981 --------------------------------------
10982 -- Is_Internally_Generated_Renaming --
10983 --------------------------------------
10985 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
10986 P : Node_Id;
10988 begin
10989 P := N;
10990 while Present (P) loop
10991 if Nkind (P) = N_Object_Renaming_Declaration then
10992 return not Comes_From_Source (P);
10993 elsif Is_List_Member (P) then
10994 return False;
10995 end if;
10997 P := Parent (P);
10998 end loop;
11000 return False;
11001 end Is_Internally_Generated_Renaming;
11003 -- Start of processing for Is_Object_Reference
11005 begin
11006 if Is_Entity_Name (N) then
11007 return Present (Entity (N)) and then Is_Object (Entity (N));
11009 else
11010 case Nkind (N) is
11011 when N_Indexed_Component | N_Slice =>
11012 return
11013 Is_Object_Reference (Prefix (N))
11014 or else Is_Access_Type (Etype (Prefix (N)));
11016 -- In Ada 95, a function call is a constant object; a procedure
11017 -- call is not.
11019 when N_Function_Call =>
11020 return Etype (N) /= Standard_Void_Type;
11022 -- Attributes 'Input, 'Old and 'Result produce objects
11024 when N_Attribute_Reference =>
11025 return
11026 Nam_In
11027 (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
11029 when N_Selected_Component =>
11030 return
11031 Is_Object_Reference (Selector_Name (N))
11032 and then
11033 (Is_Object_Reference (Prefix (N))
11034 or else Is_Access_Type (Etype (Prefix (N))));
11036 when N_Explicit_Dereference =>
11037 return True;
11039 -- A view conversion of a tagged object is an object reference
11041 when N_Type_Conversion =>
11042 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
11043 and then Is_Tagged_Type (Etype (Expression (N)))
11044 and then Is_Object_Reference (Expression (N));
11046 -- An unchecked type conversion is considered to be an object if
11047 -- the operand is an object (this construction arises only as a
11048 -- result of expansion activities).
11050 when N_Unchecked_Type_Conversion =>
11051 return True;
11053 -- Allow string literals to act as objects as long as they appear
11054 -- in internally-generated renamings. The expansion of iterators
11055 -- may generate such renamings when the range involves a string
11056 -- literal.
11058 when N_String_Literal =>
11059 return Is_Internally_Generated_Renaming (Parent (N));
11061 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11062 -- This allows disambiguation of function calls and the use
11063 -- of aggregates in more contexts.
11065 when N_Qualified_Expression =>
11066 if Ada_Version < Ada_2012 then
11067 return False;
11068 else
11069 return Is_Object_Reference (Expression (N))
11070 or else Nkind (Expression (N)) = N_Aggregate;
11071 end if;
11073 when others =>
11074 return False;
11075 end case;
11076 end if;
11077 end Is_Object_Reference;
11079 -----------------------------------
11080 -- Is_OK_Variable_For_Out_Formal --
11081 -----------------------------------
11083 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
11084 begin
11085 Note_Possible_Modification (AV, Sure => True);
11087 -- We must reject parenthesized variable names. Comes_From_Source is
11088 -- checked because there are currently cases where the compiler violates
11089 -- this rule (e.g. passing a task object to its controlled Initialize
11090 -- routine). This should be properly documented in sinfo???
11092 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
11093 return False;
11095 -- A variable is always allowed
11097 elsif Is_Variable (AV) then
11098 return True;
11100 -- Unchecked conversions are allowed only if they come from the
11101 -- generated code, which sometimes uses unchecked conversions for out
11102 -- parameters in cases where code generation is unaffected. We tell
11103 -- source unchecked conversions by seeing if they are rewrites of
11104 -- an original Unchecked_Conversion function call, or of an explicit
11105 -- conversion of a function call or an aggregate (as may happen in the
11106 -- expansion of a packed array aggregate).
11108 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
11109 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
11110 return False;
11112 elsif Comes_From_Source (AV)
11113 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
11114 then
11115 return False;
11117 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
11118 return Is_OK_Variable_For_Out_Formal (Expression (AV));
11120 else
11121 return True;
11122 end if;
11124 -- Normal type conversions are allowed if argument is a variable
11126 elsif Nkind (AV) = N_Type_Conversion then
11127 if Is_Variable (Expression (AV))
11128 and then Paren_Count (Expression (AV)) = 0
11129 then
11130 Note_Possible_Modification (Expression (AV), Sure => True);
11131 return True;
11133 -- We also allow a non-parenthesized expression that raises
11134 -- constraint error if it rewrites what used to be a variable
11136 elsif Raises_Constraint_Error (Expression (AV))
11137 and then Paren_Count (Expression (AV)) = 0
11138 and then Is_Variable (Original_Node (Expression (AV)))
11139 then
11140 return True;
11142 -- Type conversion of something other than a variable
11144 else
11145 return False;
11146 end if;
11148 -- If this node is rewritten, then test the original form, if that is
11149 -- OK, then we consider the rewritten node OK (for example, if the
11150 -- original node is a conversion, then Is_Variable will not be true
11151 -- but we still want to allow the conversion if it converts a variable).
11153 elsif Original_Node (AV) /= AV then
11155 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11156 -- Reference function.
11158 if Ada_Version >= Ada_2012
11159 and then Nkind (Original_Node (AV)) = N_Function_Call
11160 and then
11161 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
11162 then
11163 return True;
11165 else
11166 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
11167 end if;
11169 -- All other non-variables are rejected
11171 else
11172 return False;
11173 end if;
11174 end Is_OK_Variable_For_Out_Formal;
11176 -----------------------------------
11177 -- Is_Partially_Initialized_Type --
11178 -----------------------------------
11180 function Is_Partially_Initialized_Type
11181 (Typ : Entity_Id;
11182 Include_Implicit : Boolean := True) return Boolean
11184 begin
11185 if Is_Scalar_Type (Typ) then
11186 return False;
11188 elsif Is_Access_Type (Typ) then
11189 return Include_Implicit;
11191 elsif Is_Array_Type (Typ) then
11193 -- If component type is partially initialized, so is array type
11195 if Is_Partially_Initialized_Type
11196 (Component_Type (Typ), Include_Implicit)
11197 then
11198 return True;
11200 -- Otherwise we are only partially initialized if we are fully
11201 -- initialized (this is the empty array case, no point in us
11202 -- duplicating that code here).
11204 else
11205 return Is_Fully_Initialized_Type (Typ);
11206 end if;
11208 elsif Is_Record_Type (Typ) then
11210 -- A discriminated type is always partially initialized if in
11211 -- all mode
11213 if Has_Discriminants (Typ) and then Include_Implicit then
11214 return True;
11216 -- A tagged type is always partially initialized
11218 elsif Is_Tagged_Type (Typ) then
11219 return True;
11221 -- Case of non-discriminated record
11223 else
11224 declare
11225 Ent : Entity_Id;
11227 Component_Present : Boolean := False;
11228 -- Set True if at least one component is present. If no
11229 -- components are present, then record type is fully
11230 -- initialized (another odd case, like the null array).
11232 begin
11233 -- Loop through components
11235 Ent := First_Entity (Typ);
11236 while Present (Ent) loop
11237 if Ekind (Ent) = E_Component then
11238 Component_Present := True;
11240 -- If a component has an initialization expression then
11241 -- the enclosing record type is partially initialized
11243 if Present (Parent (Ent))
11244 and then Present (Expression (Parent (Ent)))
11245 then
11246 return True;
11248 -- If a component is of a type which is itself partially
11249 -- initialized, then the enclosing record type is also.
11251 elsif Is_Partially_Initialized_Type
11252 (Etype (Ent), Include_Implicit)
11253 then
11254 return True;
11255 end if;
11256 end if;
11258 Next_Entity (Ent);
11259 end loop;
11261 -- No initialized components found. If we found any components
11262 -- they were all uninitialized so the result is false.
11264 if Component_Present then
11265 return False;
11267 -- But if we found no components, then all the components are
11268 -- initialized so we consider the type to be initialized.
11270 else
11271 return True;
11272 end if;
11273 end;
11274 end if;
11276 -- Concurrent types are always fully initialized
11278 elsif Is_Concurrent_Type (Typ) then
11279 return True;
11281 -- For a private type, go to underlying type. If there is no underlying
11282 -- type then just assume this partially initialized. Not clear if this
11283 -- can happen in a non-error case, but no harm in testing for this.
11285 elsif Is_Private_Type (Typ) then
11286 declare
11287 U : constant Entity_Id := Underlying_Type (Typ);
11288 begin
11289 if No (U) then
11290 return True;
11291 else
11292 return Is_Partially_Initialized_Type (U, Include_Implicit);
11293 end if;
11294 end;
11296 -- For any other type (are there any?) assume partially initialized
11298 else
11299 return True;
11300 end if;
11301 end Is_Partially_Initialized_Type;
11303 ------------------------------------
11304 -- Is_Potentially_Persistent_Type --
11305 ------------------------------------
11307 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
11308 Comp : Entity_Id;
11309 Indx : Node_Id;
11311 begin
11312 -- For private type, test corresponding full type
11314 if Is_Private_Type (T) then
11315 return Is_Potentially_Persistent_Type (Full_View (T));
11317 -- Scalar types are potentially persistent
11319 elsif Is_Scalar_Type (T) then
11320 return True;
11322 -- Record type is potentially persistent if not tagged and the types of
11323 -- all it components are potentially persistent, and no component has
11324 -- an initialization expression.
11326 elsif Is_Record_Type (T)
11327 and then not Is_Tagged_Type (T)
11328 and then not Is_Partially_Initialized_Type (T)
11329 then
11330 Comp := First_Component (T);
11331 while Present (Comp) loop
11332 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
11333 return False;
11334 else
11335 Next_Entity (Comp);
11336 end if;
11337 end loop;
11339 return True;
11341 -- Array type is potentially persistent if its component type is
11342 -- potentially persistent and if all its constraints are static.
11344 elsif Is_Array_Type (T) then
11345 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
11346 return False;
11347 end if;
11349 Indx := First_Index (T);
11350 while Present (Indx) loop
11351 if not Is_OK_Static_Subtype (Etype (Indx)) then
11352 return False;
11353 else
11354 Next_Index (Indx);
11355 end if;
11356 end loop;
11358 return True;
11360 -- All other types are not potentially persistent
11362 else
11363 return False;
11364 end if;
11365 end Is_Potentially_Persistent_Type;
11367 --------------------------------
11368 -- Is_Potentially_Unevaluated --
11369 --------------------------------
11371 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
11372 Par : Node_Id;
11373 Expr : Node_Id;
11375 begin
11376 Expr := N;
11377 Par := Parent (N);
11379 -- A postcondition whose expression is a short-circuit is broken down
11380 -- into individual aspects for better exception reporting. The original
11381 -- short-circuit expression is rewritten as the second operand, and an
11382 -- occurrence of 'Old in that operand is potentially unevaluated.
11383 -- See Sem_ch13.adb for details of this transformation.
11385 if Nkind (Original_Node (Par)) = N_And_Then then
11386 return True;
11387 end if;
11389 while not Nkind_In (Par, N_If_Expression,
11390 N_Case_Expression,
11391 N_And_Then,
11392 N_Or_Else,
11393 N_In,
11394 N_Not_In)
11395 loop
11396 Expr := Par;
11397 Par := Parent (Par);
11399 -- If the context is not an expression, or if is the result of
11400 -- expansion of an enclosing construct (such as another attribute)
11401 -- the predicate does not apply.
11403 if Nkind (Par) not in N_Subexpr
11404 or else not Comes_From_Source (Par)
11405 then
11406 return False;
11407 end if;
11408 end loop;
11410 if Nkind (Par) = N_If_Expression then
11411 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
11413 elsif Nkind (Par) = N_Case_Expression then
11414 return Expr /= Expression (Par);
11416 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
11417 return Expr = Right_Opnd (Par);
11419 elsif Nkind_In (Par, N_In, N_Not_In) then
11420 return Expr /= Left_Opnd (Par);
11422 else
11423 return False;
11424 end if;
11425 end Is_Potentially_Unevaluated;
11427 ---------------------------------
11428 -- Is_Protected_Self_Reference --
11429 ---------------------------------
11431 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
11433 function In_Access_Definition (N : Node_Id) return Boolean;
11434 -- Returns true if N belongs to an access definition
11436 --------------------------
11437 -- In_Access_Definition --
11438 --------------------------
11440 function In_Access_Definition (N : Node_Id) return Boolean is
11441 P : Node_Id;
11443 begin
11444 P := Parent (N);
11445 while Present (P) loop
11446 if Nkind (P) = N_Access_Definition then
11447 return True;
11448 end if;
11450 P := Parent (P);
11451 end loop;
11453 return False;
11454 end In_Access_Definition;
11456 -- Start of processing for Is_Protected_Self_Reference
11458 begin
11459 -- Verify that prefix is analyzed and has the proper form. Note that
11460 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
11461 -- which also produce the address of an entity, do not analyze their
11462 -- prefix because they denote entities that are not necessarily visible.
11463 -- Neither of them can apply to a protected type.
11465 return Ada_Version >= Ada_2005
11466 and then Is_Entity_Name (N)
11467 and then Present (Entity (N))
11468 and then Is_Protected_Type (Entity (N))
11469 and then In_Open_Scopes (Entity (N))
11470 and then not In_Access_Definition (N);
11471 end Is_Protected_Self_Reference;
11473 -----------------------------
11474 -- Is_RCI_Pkg_Spec_Or_Body --
11475 -----------------------------
11477 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
11479 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
11480 -- Return True if the unit of Cunit is an RCI package declaration
11482 ---------------------------
11483 -- Is_RCI_Pkg_Decl_Cunit --
11484 ---------------------------
11486 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
11487 The_Unit : constant Node_Id := Unit (Cunit);
11489 begin
11490 if Nkind (The_Unit) /= N_Package_Declaration then
11491 return False;
11492 end if;
11494 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
11495 end Is_RCI_Pkg_Decl_Cunit;
11497 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
11499 begin
11500 return Is_RCI_Pkg_Decl_Cunit (Cunit)
11501 or else
11502 (Nkind (Unit (Cunit)) = N_Package_Body
11503 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
11504 end Is_RCI_Pkg_Spec_Or_Body;
11506 -----------------------------------------
11507 -- Is_Remote_Access_To_Class_Wide_Type --
11508 -----------------------------------------
11510 function Is_Remote_Access_To_Class_Wide_Type
11511 (E : Entity_Id) return Boolean
11513 begin
11514 -- A remote access to class-wide type is a general access to object type
11515 -- declared in the visible part of a Remote_Types or Remote_Call_
11516 -- Interface unit.
11518 return Ekind (E) = E_General_Access_Type
11519 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
11520 end Is_Remote_Access_To_Class_Wide_Type;
11522 -----------------------------------------
11523 -- Is_Remote_Access_To_Subprogram_Type --
11524 -----------------------------------------
11526 function Is_Remote_Access_To_Subprogram_Type
11527 (E : Entity_Id) return Boolean
11529 begin
11530 return (Ekind (E) = E_Access_Subprogram_Type
11531 or else (Ekind (E) = E_Record_Type
11532 and then Present (Corresponding_Remote_Type (E))))
11533 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
11534 end Is_Remote_Access_To_Subprogram_Type;
11536 --------------------
11537 -- Is_Remote_Call --
11538 --------------------
11540 function Is_Remote_Call (N : Node_Id) return Boolean is
11541 begin
11542 if Nkind (N) not in N_Subprogram_Call then
11544 -- An entry call cannot be remote
11546 return False;
11548 elsif Nkind (Name (N)) in N_Has_Entity
11549 and then Is_Remote_Call_Interface (Entity (Name (N)))
11550 then
11551 -- A subprogram declared in the spec of a RCI package is remote
11553 return True;
11555 elsif Nkind (Name (N)) = N_Explicit_Dereference
11556 and then Is_Remote_Access_To_Subprogram_Type
11557 (Etype (Prefix (Name (N))))
11558 then
11559 -- The dereference of a RAS is a remote call
11561 return True;
11563 elsif Present (Controlling_Argument (N))
11564 and then Is_Remote_Access_To_Class_Wide_Type
11565 (Etype (Controlling_Argument (N)))
11566 then
11567 -- Any primitive operation call with a controlling argument of
11568 -- a RACW type is a remote call.
11570 return True;
11571 end if;
11573 -- All other calls are local calls
11575 return False;
11576 end Is_Remote_Call;
11578 ----------------------
11579 -- Is_Renamed_Entry --
11580 ----------------------
11582 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
11583 Orig_Node : Node_Id := Empty;
11584 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
11586 function Is_Entry (Nam : Node_Id) return Boolean;
11587 -- Determine whether Nam is an entry. Traverse selectors if there are
11588 -- nested selected components.
11590 --------------
11591 -- Is_Entry --
11592 --------------
11594 function Is_Entry (Nam : Node_Id) return Boolean is
11595 begin
11596 if Nkind (Nam) = N_Selected_Component then
11597 return Is_Entry (Selector_Name (Nam));
11598 end if;
11600 return Ekind (Entity (Nam)) = E_Entry;
11601 end Is_Entry;
11603 -- Start of processing for Is_Renamed_Entry
11605 begin
11606 if Present (Alias (Proc_Nam)) then
11607 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
11608 end if;
11610 -- Look for a rewritten subprogram renaming declaration
11612 if Nkind (Subp_Decl) = N_Subprogram_Declaration
11613 and then Present (Original_Node (Subp_Decl))
11614 then
11615 Orig_Node := Original_Node (Subp_Decl);
11616 end if;
11618 -- The rewritten subprogram is actually an entry
11620 if Present (Orig_Node)
11621 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
11622 and then Is_Entry (Name (Orig_Node))
11623 then
11624 return True;
11625 end if;
11627 return False;
11628 end Is_Renamed_Entry;
11630 ----------------------------
11631 -- Is_Reversible_Iterator --
11632 ----------------------------
11634 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
11635 Ifaces_List : Elist_Id;
11636 Iface_Elmt : Elmt_Id;
11637 Iface : Entity_Id;
11639 begin
11640 if Is_Class_Wide_Type (Typ)
11641 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
11642 and then Is_Predefined_File_Name
11643 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
11644 then
11645 return True;
11647 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
11648 return False;
11650 else
11651 Collect_Interfaces (Typ, Ifaces_List);
11653 Iface_Elmt := First_Elmt (Ifaces_List);
11654 while Present (Iface_Elmt) loop
11655 Iface := Node (Iface_Elmt);
11656 if Chars (Iface) = Name_Reversible_Iterator
11657 and then
11658 Is_Predefined_File_Name
11659 (Unit_File_Name (Get_Source_Unit (Iface)))
11660 then
11661 return True;
11662 end if;
11664 Next_Elmt (Iface_Elmt);
11665 end loop;
11666 end if;
11668 return False;
11669 end Is_Reversible_Iterator;
11671 ----------------------
11672 -- Is_Selector_Name --
11673 ----------------------
11675 function Is_Selector_Name (N : Node_Id) return Boolean is
11676 begin
11677 if not Is_List_Member (N) then
11678 declare
11679 P : constant Node_Id := Parent (N);
11680 begin
11681 return Nkind_In (P, N_Expanded_Name,
11682 N_Generic_Association,
11683 N_Parameter_Association,
11684 N_Selected_Component)
11685 and then Selector_Name (P) = N;
11686 end;
11688 else
11689 declare
11690 L : constant List_Id := List_Containing (N);
11691 P : constant Node_Id := Parent (L);
11692 begin
11693 return (Nkind (P) = N_Discriminant_Association
11694 and then Selector_Names (P) = L)
11695 or else
11696 (Nkind (P) = N_Component_Association
11697 and then Choices (P) = L);
11698 end;
11699 end if;
11700 end Is_Selector_Name;
11702 -------------------------------------
11703 -- Is_SPARK_05_Initialization_Expr --
11704 -------------------------------------
11706 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
11707 Is_Ok : Boolean;
11708 Expr : Node_Id;
11709 Comp_Assn : Node_Id;
11710 Orig_N : constant Node_Id := Original_Node (N);
11712 begin
11713 Is_Ok := True;
11715 if not Comes_From_Source (Orig_N) then
11716 goto Done;
11717 end if;
11719 pragma Assert (Nkind (Orig_N) in N_Subexpr);
11721 case Nkind (Orig_N) is
11722 when N_Character_Literal |
11723 N_Integer_Literal |
11724 N_Real_Literal |
11725 N_String_Literal =>
11726 null;
11728 when N_Identifier |
11729 N_Expanded_Name =>
11730 if Is_Entity_Name (Orig_N)
11731 and then Present (Entity (Orig_N)) -- needed in some cases
11732 then
11733 case Ekind (Entity (Orig_N)) is
11734 when E_Constant |
11735 E_Enumeration_Literal |
11736 E_Named_Integer |
11737 E_Named_Real =>
11738 null;
11739 when others =>
11740 if Is_Type (Entity (Orig_N)) then
11741 null;
11742 else
11743 Is_Ok := False;
11744 end if;
11745 end case;
11746 end if;
11748 when N_Qualified_Expression |
11749 N_Type_Conversion =>
11750 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
11752 when N_Unary_Op =>
11753 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
11755 when N_Binary_Op |
11756 N_Short_Circuit |
11757 N_Membership_Test =>
11758 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
11759 and then
11760 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
11762 when N_Aggregate |
11763 N_Extension_Aggregate =>
11764 if Nkind (Orig_N) = N_Extension_Aggregate then
11765 Is_Ok :=
11766 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
11767 end if;
11769 Expr := First (Expressions (Orig_N));
11770 while Present (Expr) loop
11771 if not Is_SPARK_05_Initialization_Expr (Expr) then
11772 Is_Ok := False;
11773 goto Done;
11774 end if;
11776 Next (Expr);
11777 end loop;
11779 Comp_Assn := First (Component_Associations (Orig_N));
11780 while Present (Comp_Assn) loop
11781 Expr := Expression (Comp_Assn);
11782 if Present (Expr) -- needed for box association
11783 and then not Is_SPARK_05_Initialization_Expr (Expr)
11784 then
11785 Is_Ok := False;
11786 goto Done;
11787 end if;
11789 Next (Comp_Assn);
11790 end loop;
11792 when N_Attribute_Reference =>
11793 if Nkind (Prefix (Orig_N)) in N_Subexpr then
11794 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
11795 end if;
11797 Expr := First (Expressions (Orig_N));
11798 while Present (Expr) loop
11799 if not Is_SPARK_05_Initialization_Expr (Expr) then
11800 Is_Ok := False;
11801 goto Done;
11802 end if;
11804 Next (Expr);
11805 end loop;
11807 -- Selected components might be expanded named not yet resolved, so
11808 -- default on the safe side. (Eg on sparklex.ads)
11810 when N_Selected_Component =>
11811 null;
11813 when others =>
11814 Is_Ok := False;
11815 end case;
11817 <<Done>>
11818 return Is_Ok;
11819 end Is_SPARK_05_Initialization_Expr;
11821 ----------------------------------
11822 -- Is_SPARK_05_Object_Reference --
11823 ----------------------------------
11825 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
11826 begin
11827 if Is_Entity_Name (N) then
11828 return Present (Entity (N))
11829 and then
11830 (Ekind_In (Entity (N), E_Constant, E_Variable)
11831 or else Ekind (Entity (N)) in Formal_Kind);
11833 else
11834 case Nkind (N) is
11835 when N_Selected_Component =>
11836 return Is_SPARK_05_Object_Reference (Prefix (N));
11838 when others =>
11839 return False;
11840 end case;
11841 end if;
11842 end Is_SPARK_05_Object_Reference;
11844 ------------------
11845 -- Is_Statement --
11846 ------------------
11848 function Is_Statement (N : Node_Id) return Boolean is
11849 begin
11850 return
11851 Nkind (N) in N_Statement_Other_Than_Procedure_Call
11852 or else Nkind (N) = N_Procedure_Call_Statement;
11853 end Is_Statement;
11855 --------------------------------------------------
11856 -- Is_Subprogram_Stub_Without_Prior_Declaration --
11857 --------------------------------------------------
11859 function Is_Subprogram_Stub_Without_Prior_Declaration
11860 (N : Node_Id) return Boolean
11862 begin
11863 -- A subprogram stub without prior declaration serves as declaration for
11864 -- the actual subprogram body. As such, it has an attached defining
11865 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
11867 return Nkind (N) = N_Subprogram_Body_Stub
11868 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
11869 end Is_Subprogram_Stub_Without_Prior_Declaration;
11871 ---------------------------------
11872 -- Is_Synchronized_Tagged_Type --
11873 ---------------------------------
11875 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
11876 Kind : constant Entity_Kind := Ekind (Base_Type (E));
11878 begin
11879 -- A task or protected type derived from an interface is a tagged type.
11880 -- Such a tagged type is called a synchronized tagged type, as are
11881 -- synchronized interfaces and private extensions whose declaration
11882 -- includes the reserved word synchronized.
11884 return (Is_Tagged_Type (E)
11885 and then (Kind = E_Task_Type
11886 or else Kind = E_Protected_Type))
11887 or else
11888 (Is_Interface (E)
11889 and then Is_Synchronized_Interface (E))
11890 or else
11891 (Ekind (E) = E_Record_Type_With_Private
11892 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
11893 and then (Synchronized_Present (Parent (E))
11894 or else Is_Synchronized_Interface (Etype (E))));
11895 end Is_Synchronized_Tagged_Type;
11897 -----------------
11898 -- Is_Transfer --
11899 -----------------
11901 function Is_Transfer (N : Node_Id) return Boolean is
11902 Kind : constant Node_Kind := Nkind (N);
11904 begin
11905 if Kind = N_Simple_Return_Statement
11906 or else
11907 Kind = N_Extended_Return_Statement
11908 or else
11909 Kind = N_Goto_Statement
11910 or else
11911 Kind = N_Raise_Statement
11912 or else
11913 Kind = N_Requeue_Statement
11914 then
11915 return True;
11917 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
11918 and then No (Condition (N))
11919 then
11920 return True;
11922 elsif Kind = N_Procedure_Call_Statement
11923 and then Is_Entity_Name (Name (N))
11924 and then Present (Entity (Name (N)))
11925 and then No_Return (Entity (Name (N)))
11926 then
11927 return True;
11929 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
11930 return True;
11932 else
11933 return False;
11934 end if;
11935 end Is_Transfer;
11937 -------------
11938 -- Is_True --
11939 -------------
11941 function Is_True (U : Uint) return Boolean is
11942 begin
11943 return (U /= 0);
11944 end Is_True;
11946 --------------------------------------
11947 -- Is_Unchecked_Conversion_Instance --
11948 --------------------------------------
11950 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
11951 Gen_Par : Entity_Id;
11953 begin
11954 -- Look for a function whose generic parent is the predefined intrinsic
11955 -- function Unchecked_Conversion.
11957 if Ekind (Id) = E_Function then
11958 Gen_Par := Generic_Parent (Parent (Id));
11960 return
11961 Present (Gen_Par)
11962 and then Chars (Gen_Par) = Name_Unchecked_Conversion
11963 and then Is_Intrinsic_Subprogram (Gen_Par)
11964 and then Is_Predefined_File_Name
11965 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
11966 end if;
11968 return False;
11969 end Is_Unchecked_Conversion_Instance;
11971 -------------------------------
11972 -- Is_Universal_Numeric_Type --
11973 -------------------------------
11975 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
11976 begin
11977 return T = Universal_Integer or else T = Universal_Real;
11978 end Is_Universal_Numeric_Type;
11980 -------------------
11981 -- Is_Value_Type --
11982 -------------------
11984 function Is_Value_Type (T : Entity_Id) return Boolean is
11985 begin
11986 return VM_Target = CLI_Target
11987 and then Nkind (T) in N_Has_Chars
11988 and then Chars (T) /= No_Name
11989 and then Get_Name_String (Chars (T)) = "valuetype";
11990 end Is_Value_Type;
11992 ----------------------------
11993 -- Is_Variable_Size_Array --
11994 ----------------------------
11996 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
11997 Idx : Node_Id;
11999 begin
12000 pragma Assert (Is_Array_Type (E));
12002 -- Check if some index is initialized with a non-constant value
12004 Idx := First_Index (E);
12005 while Present (Idx) loop
12006 if Nkind (Idx) = N_Range then
12007 if not Is_Constant_Bound (Low_Bound (Idx))
12008 or else not Is_Constant_Bound (High_Bound (Idx))
12009 then
12010 return True;
12011 end if;
12012 end if;
12014 Idx := Next_Index (Idx);
12015 end loop;
12017 return False;
12018 end Is_Variable_Size_Array;
12020 -----------------------------
12021 -- Is_Variable_Size_Record --
12022 -----------------------------
12024 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
12025 Comp : Entity_Id;
12026 Comp_Typ : Entity_Id;
12028 begin
12029 pragma Assert (Is_Record_Type (E));
12031 Comp := First_Entity (E);
12032 while Present (Comp) loop
12033 Comp_Typ := Etype (Comp);
12035 -- Recursive call if the record type has discriminants
12037 if Is_Record_Type (Comp_Typ)
12038 and then Has_Discriminants (Comp_Typ)
12039 and then Is_Variable_Size_Record (Comp_Typ)
12040 then
12041 return True;
12043 elsif Is_Array_Type (Comp_Typ)
12044 and then Is_Variable_Size_Array (Comp_Typ)
12045 then
12046 return True;
12047 end if;
12049 Next_Entity (Comp);
12050 end loop;
12052 return False;
12053 end Is_Variable_Size_Record;
12055 -----------------
12056 -- Is_Variable --
12057 -----------------
12059 function Is_Variable
12060 (N : Node_Id;
12061 Use_Original_Node : Boolean := True) return Boolean
12063 Orig_Node : Node_Id;
12065 function In_Protected_Function (E : Entity_Id) return Boolean;
12066 -- Within a protected function, the private components of the enclosing
12067 -- protected type are constants. A function nested within a (protected)
12068 -- procedure is not itself protected. Within the body of a protected
12069 -- function the current instance of the protected type is a constant.
12071 function Is_Variable_Prefix (P : Node_Id) return Boolean;
12072 -- Prefixes can involve implicit dereferences, in which case we must
12073 -- test for the case of a reference of a constant access type, which can
12074 -- can never be a variable.
12076 ---------------------------
12077 -- In_Protected_Function --
12078 ---------------------------
12080 function In_Protected_Function (E : Entity_Id) return Boolean is
12081 Prot : Entity_Id;
12082 S : Entity_Id;
12084 begin
12085 -- E is the current instance of a type
12087 if Is_Type (E) then
12088 Prot := E;
12090 -- E is an object
12092 else
12093 Prot := Scope (E);
12094 end if;
12096 if not Is_Protected_Type (Prot) then
12097 return False;
12099 else
12100 S := Current_Scope;
12101 while Present (S) and then S /= Prot loop
12102 if Ekind (S) = E_Function and then Scope (S) = Prot then
12103 return True;
12104 end if;
12106 S := Scope (S);
12107 end loop;
12109 return False;
12110 end if;
12111 end In_Protected_Function;
12113 ------------------------
12114 -- Is_Variable_Prefix --
12115 ------------------------
12117 function Is_Variable_Prefix (P : Node_Id) return Boolean is
12118 begin
12119 if Is_Access_Type (Etype (P)) then
12120 return not Is_Access_Constant (Root_Type (Etype (P)));
12122 -- For the case of an indexed component whose prefix has a packed
12123 -- array type, the prefix has been rewritten into a type conversion.
12124 -- Determine variable-ness from the converted expression.
12126 elsif Nkind (P) = N_Type_Conversion
12127 and then not Comes_From_Source (P)
12128 and then Is_Array_Type (Etype (P))
12129 and then Is_Packed (Etype (P))
12130 then
12131 return Is_Variable (Expression (P));
12133 else
12134 return Is_Variable (P);
12135 end if;
12136 end Is_Variable_Prefix;
12138 -- Start of processing for Is_Variable
12140 begin
12141 -- Check if we perform the test on the original node since this may be a
12142 -- test of syntactic categories which must not be disturbed by whatever
12143 -- rewriting might have occurred. For example, an aggregate, which is
12144 -- certainly NOT a variable, could be turned into a variable by
12145 -- expansion.
12147 if Use_Original_Node then
12148 Orig_Node := Original_Node (N);
12149 else
12150 Orig_Node := N;
12151 end if;
12153 -- Definitely OK if Assignment_OK is set. Since this is something that
12154 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12156 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
12157 return True;
12159 -- Normally we go to the original node, but there is one exception where
12160 -- we use the rewritten node, namely when it is an explicit dereference.
12161 -- The generated code may rewrite a prefix which is an access type with
12162 -- an explicit dereference. The dereference is a variable, even though
12163 -- the original node may not be (since it could be a constant of the
12164 -- access type).
12166 -- In Ada 2005 we have a further case to consider: the prefix may be a
12167 -- function call given in prefix notation. The original node appears to
12168 -- be a selected component, but we need to examine the call.
12170 elsif Nkind (N) = N_Explicit_Dereference
12171 and then Nkind (Orig_Node) /= N_Explicit_Dereference
12172 and then Present (Etype (Orig_Node))
12173 and then Is_Access_Type (Etype (Orig_Node))
12174 then
12175 -- Note that if the prefix is an explicit dereference that does not
12176 -- come from source, we must check for a rewritten function call in
12177 -- prefixed notation before other forms of rewriting, to prevent a
12178 -- compiler crash.
12180 return
12181 (Nkind (Orig_Node) = N_Function_Call
12182 and then not Is_Access_Constant (Etype (Prefix (N))))
12183 or else
12184 Is_Variable_Prefix (Original_Node (Prefix (N)));
12186 -- in Ada 2012, the dereference may have been added for a type with
12187 -- a declared implicit dereference aspect.
12189 elsif Nkind (N) = N_Explicit_Dereference
12190 and then Present (Etype (Orig_Node))
12191 and then Ada_Version >= Ada_2012
12192 and then Has_Implicit_Dereference (Etype (Orig_Node))
12193 then
12194 return True;
12196 -- A function call is never a variable
12198 elsif Nkind (N) = N_Function_Call then
12199 return False;
12201 -- All remaining checks use the original node
12203 elsif Is_Entity_Name (Orig_Node)
12204 and then Present (Entity (Orig_Node))
12205 then
12206 declare
12207 E : constant Entity_Id := Entity (Orig_Node);
12208 K : constant Entity_Kind := Ekind (E);
12210 begin
12211 return (K = E_Variable
12212 and then Nkind (Parent (E)) /= N_Exception_Handler)
12213 or else (K = E_Component
12214 and then not In_Protected_Function (E))
12215 or else K = E_Out_Parameter
12216 or else K = E_In_Out_Parameter
12217 or else K = E_Generic_In_Out_Parameter
12219 -- Current instance of type. If this is a protected type, check
12220 -- we are not within the body of one of its protected functions.
12222 or else (Is_Type (E)
12223 and then In_Open_Scopes (E)
12224 and then not In_Protected_Function (E))
12226 or else (Is_Incomplete_Or_Private_Type (E)
12227 and then In_Open_Scopes (Full_View (E)));
12228 end;
12230 else
12231 case Nkind (Orig_Node) is
12232 when N_Indexed_Component | N_Slice =>
12233 return Is_Variable_Prefix (Prefix (Orig_Node));
12235 when N_Selected_Component =>
12236 return (Is_Variable (Selector_Name (Orig_Node))
12237 and then Is_Variable_Prefix (Prefix (Orig_Node)))
12238 or else
12239 (Nkind (N) = N_Expanded_Name
12240 and then Scope (Entity (N)) = Entity (Prefix (N)));
12242 -- For an explicit dereference, the type of the prefix cannot
12243 -- be an access to constant or an access to subprogram.
12245 when N_Explicit_Dereference =>
12246 declare
12247 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
12248 begin
12249 return Is_Access_Type (Typ)
12250 and then not Is_Access_Constant (Root_Type (Typ))
12251 and then Ekind (Typ) /= E_Access_Subprogram_Type;
12252 end;
12254 -- The type conversion is the case where we do not deal with the
12255 -- context dependent special case of an actual parameter. Thus
12256 -- the type conversion is only considered a variable for the
12257 -- purposes of this routine if the target type is tagged. However,
12258 -- a type conversion is considered to be a variable if it does not
12259 -- come from source (this deals for example with the conversions
12260 -- of expressions to their actual subtypes).
12262 when N_Type_Conversion =>
12263 return Is_Variable (Expression (Orig_Node))
12264 and then
12265 (not Comes_From_Source (Orig_Node)
12266 or else
12267 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
12268 and then
12269 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
12271 -- GNAT allows an unchecked type conversion as a variable. This
12272 -- only affects the generation of internal expanded code, since
12273 -- calls to instantiations of Unchecked_Conversion are never
12274 -- considered variables (since they are function calls).
12276 when N_Unchecked_Type_Conversion =>
12277 return Is_Variable (Expression (Orig_Node));
12279 when others =>
12280 return False;
12281 end case;
12282 end if;
12283 end Is_Variable;
12285 ---------------------------
12286 -- Is_Visibly_Controlled --
12287 ---------------------------
12289 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
12290 Root : constant Entity_Id := Root_Type (T);
12291 begin
12292 return Chars (Scope (Root)) = Name_Finalization
12293 and then Chars (Scope (Scope (Root))) = Name_Ada
12294 and then Scope (Scope (Scope (Root))) = Standard_Standard;
12295 end Is_Visibly_Controlled;
12297 ------------------------
12298 -- Is_Volatile_Object --
12299 ------------------------
12301 function Is_Volatile_Object (N : Node_Id) return Boolean is
12303 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
12304 -- If prefix is an implicit dereference, examine designated type
12306 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
12307 -- Determines if given object has volatile components
12309 ------------------------
12310 -- Is_Volatile_Prefix --
12311 ------------------------
12313 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
12314 Typ : constant Entity_Id := Etype (N);
12316 begin
12317 if Is_Access_Type (Typ) then
12318 declare
12319 Dtyp : constant Entity_Id := Designated_Type (Typ);
12321 begin
12322 return Is_Volatile (Dtyp)
12323 or else Has_Volatile_Components (Dtyp);
12324 end;
12326 else
12327 return Object_Has_Volatile_Components (N);
12328 end if;
12329 end Is_Volatile_Prefix;
12331 ------------------------------------
12332 -- Object_Has_Volatile_Components --
12333 ------------------------------------
12335 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
12336 Typ : constant Entity_Id := Etype (N);
12338 begin
12339 if Is_Volatile (Typ)
12340 or else Has_Volatile_Components (Typ)
12341 then
12342 return True;
12344 elsif Is_Entity_Name (N)
12345 and then (Has_Volatile_Components (Entity (N))
12346 or else Is_Volatile (Entity (N)))
12347 then
12348 return True;
12350 elsif Nkind (N) = N_Indexed_Component
12351 or else Nkind (N) = N_Selected_Component
12352 then
12353 return Is_Volatile_Prefix (Prefix (N));
12355 else
12356 return False;
12357 end if;
12358 end Object_Has_Volatile_Components;
12360 -- Start of processing for Is_Volatile_Object
12362 begin
12363 if Nkind (N) = N_Defining_Identifier then
12364 return Is_Volatile (N) or else Is_Volatile (Etype (N));
12366 elsif Nkind (N) = N_Expanded_Name then
12367 return Is_Volatile_Object (Entity (N));
12369 elsif Is_Volatile (Etype (N))
12370 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
12371 then
12372 return True;
12374 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
12375 and then Is_Volatile_Prefix (Prefix (N))
12376 then
12377 return True;
12379 elsif Nkind (N) = N_Selected_Component
12380 and then Is_Volatile (Entity (Selector_Name (N)))
12381 then
12382 return True;
12384 else
12385 return False;
12386 end if;
12387 end Is_Volatile_Object;
12389 ---------------------------
12390 -- Itype_Has_Declaration --
12391 ---------------------------
12393 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
12394 begin
12395 pragma Assert (Is_Itype (Id));
12396 return Present (Parent (Id))
12397 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
12398 N_Subtype_Declaration)
12399 and then Defining_Entity (Parent (Id)) = Id;
12400 end Itype_Has_Declaration;
12402 -------------------------
12403 -- Kill_Current_Values --
12404 -------------------------
12406 procedure Kill_Current_Values
12407 (Ent : Entity_Id;
12408 Last_Assignment_Only : Boolean := False)
12410 begin
12411 if Is_Assignable (Ent) then
12412 Set_Last_Assignment (Ent, Empty);
12413 end if;
12415 if Is_Object (Ent) then
12416 if not Last_Assignment_Only then
12417 Kill_Checks (Ent);
12418 Set_Current_Value (Ent, Empty);
12420 if not Can_Never_Be_Null (Ent) then
12421 Set_Is_Known_Non_Null (Ent, False);
12422 end if;
12424 Set_Is_Known_Null (Ent, False);
12426 -- Reset Is_Known_Valid unless type is always valid, or if we have
12427 -- a loop parameter (loop parameters are always valid, since their
12428 -- bounds are defined by the bounds given in the loop header).
12430 if not Is_Known_Valid (Etype (Ent))
12431 and then Ekind (Ent) /= E_Loop_Parameter
12432 then
12433 Set_Is_Known_Valid (Ent, False);
12434 end if;
12435 end if;
12436 end if;
12437 end Kill_Current_Values;
12439 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
12440 S : Entity_Id;
12442 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
12443 -- Clear current value for entity E and all entities chained to E
12445 ------------------------------------------
12446 -- Kill_Current_Values_For_Entity_Chain --
12447 ------------------------------------------
12449 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
12450 Ent : Entity_Id;
12451 begin
12452 Ent := E;
12453 while Present (Ent) loop
12454 Kill_Current_Values (Ent, Last_Assignment_Only);
12455 Next_Entity (Ent);
12456 end loop;
12457 end Kill_Current_Values_For_Entity_Chain;
12459 -- Start of processing for Kill_Current_Values
12461 begin
12462 -- Kill all saved checks, a special case of killing saved values
12464 if not Last_Assignment_Only then
12465 Kill_All_Checks;
12466 end if;
12468 -- Loop through relevant scopes, which includes the current scope and
12469 -- any parent scopes if the current scope is a block or a package.
12471 S := Current_Scope;
12472 Scope_Loop : loop
12474 -- Clear current values of all entities in current scope
12476 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
12478 -- If scope is a package, also clear current values of all private
12479 -- entities in the scope.
12481 if Is_Package_Or_Generic_Package (S)
12482 or else Is_Concurrent_Type (S)
12483 then
12484 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
12485 end if;
12487 -- If this is a not a subprogram, deal with parents
12489 if not Is_Subprogram (S) then
12490 S := Scope (S);
12491 exit Scope_Loop when S = Standard_Standard;
12492 else
12493 exit Scope_Loop;
12494 end if;
12495 end loop Scope_Loop;
12496 end Kill_Current_Values;
12498 --------------------------
12499 -- Kill_Size_Check_Code --
12500 --------------------------
12502 procedure Kill_Size_Check_Code (E : Entity_Id) is
12503 begin
12504 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12505 and then Present (Size_Check_Code (E))
12506 then
12507 Remove (Size_Check_Code (E));
12508 Set_Size_Check_Code (E, Empty);
12509 end if;
12510 end Kill_Size_Check_Code;
12512 --------------------------
12513 -- Known_To_Be_Assigned --
12514 --------------------------
12516 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
12517 P : constant Node_Id := Parent (N);
12519 begin
12520 case Nkind (P) is
12522 -- Test left side of assignment
12524 when N_Assignment_Statement =>
12525 return N = Name (P);
12527 -- Function call arguments are never lvalues
12529 when N_Function_Call =>
12530 return False;
12532 -- Positional parameter for procedure or accept call
12534 when N_Procedure_Call_Statement |
12535 N_Accept_Statement
12537 declare
12538 Proc : Entity_Id;
12539 Form : Entity_Id;
12540 Act : Node_Id;
12542 begin
12543 Proc := Get_Subprogram_Entity (P);
12545 if No (Proc) then
12546 return False;
12547 end if;
12549 -- If we are not a list member, something is strange, so
12550 -- be conservative and return False.
12552 if not Is_List_Member (N) then
12553 return False;
12554 end if;
12556 -- We are going to find the right formal by stepping forward
12557 -- through the formals, as we step backwards in the actuals.
12559 Form := First_Formal (Proc);
12560 Act := N;
12561 loop
12562 -- If no formal, something is weird, so be conservative
12563 -- and return False.
12565 if No (Form) then
12566 return False;
12567 end if;
12569 Prev (Act);
12570 exit when No (Act);
12571 Next_Formal (Form);
12572 end loop;
12574 return Ekind (Form) /= E_In_Parameter;
12575 end;
12577 -- Named parameter for procedure or accept call
12579 when N_Parameter_Association =>
12580 declare
12581 Proc : Entity_Id;
12582 Form : Entity_Id;
12584 begin
12585 Proc := Get_Subprogram_Entity (Parent (P));
12587 if No (Proc) then
12588 return False;
12589 end if;
12591 -- Loop through formals to find the one that matches
12593 Form := First_Formal (Proc);
12594 loop
12595 -- If no matching formal, that's peculiar, some kind of
12596 -- previous error, so return False to be conservative.
12597 -- Actually this also happens in legal code in the case
12598 -- where P is a parameter association for an Extra_Formal???
12600 if No (Form) then
12601 return False;
12602 end if;
12604 -- Else test for match
12606 if Chars (Form) = Chars (Selector_Name (P)) then
12607 return Ekind (Form) /= E_In_Parameter;
12608 end if;
12610 Next_Formal (Form);
12611 end loop;
12612 end;
12614 -- Test for appearing in a conversion that itself appears
12615 -- in an lvalue context, since this should be an lvalue.
12617 when N_Type_Conversion =>
12618 return Known_To_Be_Assigned (P);
12620 -- All other references are definitely not known to be modifications
12622 when others =>
12623 return False;
12625 end case;
12626 end Known_To_Be_Assigned;
12628 ---------------------------
12629 -- Last_Source_Statement --
12630 ---------------------------
12632 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
12633 N : Node_Id;
12635 begin
12636 N := Last (Statements (HSS));
12637 while Present (N) loop
12638 exit when Comes_From_Source (N);
12639 Prev (N);
12640 end loop;
12642 return N;
12643 end Last_Source_Statement;
12645 ----------------------------------
12646 -- Matching_Static_Array_Bounds --
12647 ----------------------------------
12649 function Matching_Static_Array_Bounds
12650 (L_Typ : Node_Id;
12651 R_Typ : Node_Id) return Boolean
12653 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
12654 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
12656 L_Index : Node_Id;
12657 R_Index : Node_Id;
12658 L_Low : Node_Id;
12659 L_High : Node_Id;
12660 L_Len : Uint;
12661 R_Low : Node_Id;
12662 R_High : Node_Id;
12663 R_Len : Uint;
12665 begin
12666 if L_Ndims /= R_Ndims then
12667 return False;
12668 end if;
12670 -- Unconstrained types do not have static bounds
12672 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
12673 return False;
12674 end if;
12676 -- First treat specially the first dimension, as the lower bound and
12677 -- length of string literals are not stored like those of arrays.
12679 if Ekind (L_Typ) = E_String_Literal_Subtype then
12680 L_Low := String_Literal_Low_Bound (L_Typ);
12681 L_Len := String_Literal_Length (L_Typ);
12682 else
12683 L_Index := First_Index (L_Typ);
12684 Get_Index_Bounds (L_Index, L_Low, L_High);
12686 if Is_OK_Static_Expression (L_Low)
12687 and then
12688 Is_OK_Static_Expression (L_High)
12689 then
12690 if Expr_Value (L_High) < Expr_Value (L_Low) then
12691 L_Len := Uint_0;
12692 else
12693 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
12694 end if;
12695 else
12696 return False;
12697 end if;
12698 end if;
12700 if Ekind (R_Typ) = E_String_Literal_Subtype then
12701 R_Low := String_Literal_Low_Bound (R_Typ);
12702 R_Len := String_Literal_Length (R_Typ);
12703 else
12704 R_Index := First_Index (R_Typ);
12705 Get_Index_Bounds (R_Index, R_Low, R_High);
12707 if Is_OK_Static_Expression (R_Low)
12708 and then
12709 Is_OK_Static_Expression (R_High)
12710 then
12711 if Expr_Value (R_High) < Expr_Value (R_Low) then
12712 R_Len := Uint_0;
12713 else
12714 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
12715 end if;
12716 else
12717 return False;
12718 end if;
12719 end if;
12721 if (Is_OK_Static_Expression (L_Low)
12722 and then
12723 Is_OK_Static_Expression (R_Low))
12724 and then Expr_Value (L_Low) = Expr_Value (R_Low)
12725 and then L_Len = R_Len
12726 then
12727 null;
12728 else
12729 return False;
12730 end if;
12732 -- Then treat all other dimensions
12734 for Indx in 2 .. L_Ndims loop
12735 Next (L_Index);
12736 Next (R_Index);
12738 Get_Index_Bounds (L_Index, L_Low, L_High);
12739 Get_Index_Bounds (R_Index, R_Low, R_High);
12741 if (Is_OK_Static_Expression (L_Low) and then
12742 Is_OK_Static_Expression (L_High) and then
12743 Is_OK_Static_Expression (R_Low) and then
12744 Is_OK_Static_Expression (R_High))
12745 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
12746 and then
12747 Expr_Value (L_High) = Expr_Value (R_High))
12748 then
12749 null;
12750 else
12751 return False;
12752 end if;
12753 end loop;
12755 -- If we fall through the loop, all indexes matched
12757 return True;
12758 end Matching_Static_Array_Bounds;
12760 -------------------
12761 -- May_Be_Lvalue --
12762 -------------------
12764 function May_Be_Lvalue (N : Node_Id) return Boolean is
12765 P : constant Node_Id := Parent (N);
12767 begin
12768 case Nkind (P) is
12770 -- Test left side of assignment
12772 when N_Assignment_Statement =>
12773 return N = Name (P);
12775 -- Test prefix of component or attribute. Note that the prefix of an
12776 -- explicit or implicit dereference cannot be an l-value.
12778 when N_Attribute_Reference =>
12779 return N = Prefix (P)
12780 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
12782 -- For an expanded name, the name is an lvalue if the expanded name
12783 -- is an lvalue, but the prefix is never an lvalue, since it is just
12784 -- the scope where the name is found.
12786 when N_Expanded_Name =>
12787 if N = Prefix (P) then
12788 return May_Be_Lvalue (P);
12789 else
12790 return False;
12791 end if;
12793 -- For a selected component A.B, A is certainly an lvalue if A.B is.
12794 -- B is a little interesting, if we have A.B := 3, there is some
12795 -- discussion as to whether B is an lvalue or not, we choose to say
12796 -- it is. Note however that A is not an lvalue if it is of an access
12797 -- type since this is an implicit dereference.
12799 when N_Selected_Component =>
12800 if N = Prefix (P)
12801 and then Present (Etype (N))
12802 and then Is_Access_Type (Etype (N))
12803 then
12804 return False;
12805 else
12806 return May_Be_Lvalue (P);
12807 end if;
12809 -- For an indexed component or slice, the index or slice bounds is
12810 -- never an lvalue. The prefix is an lvalue if the indexed component
12811 -- or slice is an lvalue, except if it is an access type, where we
12812 -- have an implicit dereference.
12814 when N_Indexed_Component | N_Slice =>
12815 if N /= Prefix (P)
12816 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
12817 then
12818 return False;
12819 else
12820 return May_Be_Lvalue (P);
12821 end if;
12823 -- Prefix of a reference is an lvalue if the reference is an lvalue
12825 when N_Reference =>
12826 return May_Be_Lvalue (P);
12828 -- Prefix of explicit dereference is never an lvalue
12830 when N_Explicit_Dereference =>
12831 return False;
12833 -- Positional parameter for subprogram, entry, or accept call.
12834 -- In older versions of Ada function call arguments are never
12835 -- lvalues. In Ada 2012 functions can have in-out parameters.
12837 when N_Subprogram_Call |
12838 N_Entry_Call_Statement |
12839 N_Accept_Statement
12841 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
12842 return False;
12843 end if;
12845 -- The following mechanism is clumsy and fragile. A single flag
12846 -- set in Resolve_Actuals would be preferable ???
12848 declare
12849 Proc : Entity_Id;
12850 Form : Entity_Id;
12851 Act : Node_Id;
12853 begin
12854 Proc := Get_Subprogram_Entity (P);
12856 if No (Proc) then
12857 return True;
12858 end if;
12860 -- If we are not a list member, something is strange, so be
12861 -- conservative and return True.
12863 if not Is_List_Member (N) then
12864 return True;
12865 end if;
12867 -- We are going to find the right formal by stepping forward
12868 -- through the formals, as we step backwards in the actuals.
12870 Form := First_Formal (Proc);
12871 Act := N;
12872 loop
12873 -- If no formal, something is weird, so be conservative and
12874 -- return True.
12876 if No (Form) then
12877 return True;
12878 end if;
12880 Prev (Act);
12881 exit when No (Act);
12882 Next_Formal (Form);
12883 end loop;
12885 return Ekind (Form) /= E_In_Parameter;
12886 end;
12888 -- Named parameter for procedure or accept call
12890 when N_Parameter_Association =>
12891 declare
12892 Proc : Entity_Id;
12893 Form : Entity_Id;
12895 begin
12896 Proc := Get_Subprogram_Entity (Parent (P));
12898 if No (Proc) then
12899 return True;
12900 end if;
12902 -- Loop through formals to find the one that matches
12904 Form := First_Formal (Proc);
12905 loop
12906 -- If no matching formal, that's peculiar, some kind of
12907 -- previous error, so return True to be conservative.
12908 -- Actually happens with legal code for an unresolved call
12909 -- where we may get the wrong homonym???
12911 if No (Form) then
12912 return True;
12913 end if;
12915 -- Else test for match
12917 if Chars (Form) = Chars (Selector_Name (P)) then
12918 return Ekind (Form) /= E_In_Parameter;
12919 end if;
12921 Next_Formal (Form);
12922 end loop;
12923 end;
12925 -- Test for appearing in a conversion that itself appears in an
12926 -- lvalue context, since this should be an lvalue.
12928 when N_Type_Conversion =>
12929 return May_Be_Lvalue (P);
12931 -- Test for appearance in object renaming declaration
12933 when N_Object_Renaming_Declaration =>
12934 return True;
12936 -- All other references are definitely not lvalues
12938 when others =>
12939 return False;
12941 end case;
12942 end May_Be_Lvalue;
12944 -----------------------
12945 -- Mark_Coextensions --
12946 -----------------------
12948 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
12949 Is_Dynamic : Boolean;
12950 -- Indicates whether the context causes nested coextensions to be
12951 -- dynamic or static
12953 function Mark_Allocator (N : Node_Id) return Traverse_Result;
12954 -- Recognize an allocator node and label it as a dynamic coextension
12956 --------------------
12957 -- Mark_Allocator --
12958 --------------------
12960 function Mark_Allocator (N : Node_Id) return Traverse_Result is
12961 begin
12962 if Nkind (N) = N_Allocator then
12963 if Is_Dynamic then
12964 Set_Is_Dynamic_Coextension (N);
12966 -- If the allocator expression is potentially dynamic, it may
12967 -- be expanded out of order and require dynamic allocation
12968 -- anyway, so we treat the coextension itself as dynamic.
12969 -- Potential optimization ???
12971 elsif Nkind (Expression (N)) = N_Qualified_Expression
12972 and then Nkind (Expression (Expression (N))) = N_Op_Concat
12973 then
12974 Set_Is_Dynamic_Coextension (N);
12975 else
12976 Set_Is_Static_Coextension (N);
12977 end if;
12978 end if;
12980 return OK;
12981 end Mark_Allocator;
12983 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
12985 -- Start of processing Mark_Coextensions
12987 begin
12988 case Nkind (Context_Nod) is
12990 -- Comment here ???
12992 when N_Assignment_Statement =>
12993 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
12995 -- An allocator that is a component of a returned aggregate
12996 -- must be dynamic.
12998 when N_Simple_Return_Statement =>
12999 declare
13000 Expr : constant Node_Id := Expression (Context_Nod);
13001 begin
13002 Is_Dynamic :=
13003 Nkind (Expr) = N_Allocator
13004 or else
13005 (Nkind (Expr) = N_Qualified_Expression
13006 and then Nkind (Expression (Expr)) = N_Aggregate);
13007 end;
13009 -- An alloctor within an object declaration in an extended return
13010 -- statement is of necessity dynamic.
13012 when N_Object_Declaration =>
13013 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
13014 or else
13015 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
13017 -- This routine should not be called for constructs which may not
13018 -- contain coextensions.
13020 when others =>
13021 raise Program_Error;
13022 end case;
13024 Mark_Allocators (Root_Nod);
13025 end Mark_Coextensions;
13027 -----------------
13028 -- Must_Inline --
13029 -----------------
13031 function Must_Inline (Subp : Entity_Id) return Boolean is
13032 begin
13033 return
13034 (Optimization_Level = 0
13036 -- AAMP and VM targets have no support for inlining in the backend.
13037 -- Hence we do as much inlining as possible in the front end.
13039 or else AAMP_On_Target
13040 or else VM_Target /= No_VM)
13041 and then Has_Pragma_Inline (Subp)
13042 and then (Has_Pragma_Inline_Always (Subp) or else Front_End_Inlining);
13043 end Must_Inline;
13045 ----------------------
13046 -- Needs_One_Actual --
13047 ----------------------
13049 function Needs_One_Actual (E : Entity_Id) return Boolean is
13050 Formal : Entity_Id;
13052 begin
13053 -- Ada 2005 or later, and formals present
13055 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
13056 Formal := Next_Formal (First_Formal (E));
13057 while Present (Formal) loop
13058 if No (Default_Value (Formal)) then
13059 return False;
13060 end if;
13062 Next_Formal (Formal);
13063 end loop;
13065 return True;
13067 -- Ada 83/95 or no formals
13069 else
13070 return False;
13071 end if;
13072 end Needs_One_Actual;
13074 ------------------------
13075 -- New_Copy_List_Tree --
13076 ------------------------
13078 function New_Copy_List_Tree (List : List_Id) return List_Id is
13079 NL : List_Id;
13080 E : Node_Id;
13082 begin
13083 if List = No_List then
13084 return No_List;
13086 else
13087 NL := New_List;
13088 E := First (List);
13090 while Present (E) loop
13091 Append (New_Copy_Tree (E), NL);
13092 E := Next (E);
13093 end loop;
13095 return NL;
13096 end if;
13097 end New_Copy_List_Tree;
13099 -------------------
13100 -- New_Copy_Tree --
13101 -------------------
13103 use Atree.Unchecked_Access;
13104 use Atree_Private_Part;
13106 -- Our approach here requires a two pass traversal of the tree. The
13107 -- first pass visits all nodes that eventually will be copied looking
13108 -- for defining Itypes. If any defining Itypes are found, then they are
13109 -- copied, and an entry is added to the replacement map. In the second
13110 -- phase, the tree is copied, using the replacement map to replace any
13111 -- Itype references within the copied tree.
13113 -- The following hash tables are used if the Map supplied has more
13114 -- than hash threshold entries to speed up access to the map. If
13115 -- there are fewer entries, then the map is searched sequentially
13116 -- (because setting up a hash table for only a few entries takes
13117 -- more time than it saves.
13119 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
13120 -- Hash function used for hash operations
13122 -------------------
13123 -- New_Copy_Hash --
13124 -------------------
13126 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
13127 begin
13128 return Nat (E) mod (NCT_Header_Num'Last + 1);
13129 end New_Copy_Hash;
13131 ---------------
13132 -- NCT_Assoc --
13133 ---------------
13135 -- The hash table NCT_Assoc associates old entities in the table
13136 -- with their corresponding new entities (i.e. the pairs of entries
13137 -- presented in the original Map argument are Key-Element pairs).
13139 package NCT_Assoc is new Simple_HTable (
13140 Header_Num => NCT_Header_Num,
13141 Element => Entity_Id,
13142 No_Element => Empty,
13143 Key => Entity_Id,
13144 Hash => New_Copy_Hash,
13145 Equal => Types."=");
13147 ---------------------
13148 -- NCT_Itype_Assoc --
13149 ---------------------
13151 -- The hash table NCT_Itype_Assoc contains entries only for those
13152 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13153 -- The key is the associated node, and the element is the new node
13154 -- itself (NOT the associated node for the new node).
13156 package NCT_Itype_Assoc is new Simple_HTable (
13157 Header_Num => NCT_Header_Num,
13158 Element => Entity_Id,
13159 No_Element => Empty,
13160 Key => Entity_Id,
13161 Hash => New_Copy_Hash,
13162 Equal => Types."=");
13164 -- Start of processing for New_Copy_Tree function
13166 function New_Copy_Tree
13167 (Source : Node_Id;
13168 Map : Elist_Id := No_Elist;
13169 New_Sloc : Source_Ptr := No_Location;
13170 New_Scope : Entity_Id := Empty) return Node_Id
13172 Actual_Map : Elist_Id := Map;
13173 -- This is the actual map for the copy. It is initialized with the
13174 -- given elements, and then enlarged as required for Itypes that are
13175 -- copied during the first phase of the copy operation. The visit
13176 -- procedures add elements to this map as Itypes are encountered.
13177 -- The reason we cannot use Map directly, is that it may well be
13178 -- (and normally is) initialized to No_Elist, and if we have mapped
13179 -- entities, we have to reset it to point to a real Elist.
13181 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
13182 -- Called during second phase to map entities into their corresponding
13183 -- copies using Actual_Map. If the argument is not an entity, or is not
13184 -- in Actual_Map, then it is returned unchanged.
13186 procedure Build_NCT_Hash_Tables;
13187 -- Builds hash tables (number of elements >= threshold value)
13189 function Copy_Elist_With_Replacement
13190 (Old_Elist : Elist_Id) return Elist_Id;
13191 -- Called during second phase to copy element list doing replacements
13193 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
13194 -- Called during the second phase to process a copied Itype. The actual
13195 -- copy happened during the first phase (so that we could make the entry
13196 -- in the mapping), but we still have to deal with the descendents of
13197 -- the copied Itype and copy them where necessary.
13199 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
13200 -- Called during second phase to copy list doing replacements
13202 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
13203 -- Called during second phase to copy node doing replacements
13205 procedure Visit_Elist (E : Elist_Id);
13206 -- Called during first phase to visit all elements of an Elist
13208 procedure Visit_Field (F : Union_Id; N : Node_Id);
13209 -- Visit a single field, recursing to call Visit_Node or Visit_List
13210 -- if the field is a syntactic descendent of the current node (i.e.
13211 -- its parent is Node N).
13213 procedure Visit_Itype (Old_Itype : Entity_Id);
13214 -- Called during first phase to visit subsidiary fields of a defining
13215 -- Itype, and also create a copy and make an entry in the replacement
13216 -- map for the new copy.
13218 procedure Visit_List (L : List_Id);
13219 -- Called during first phase to visit all elements of a List
13221 procedure Visit_Node (N : Node_Or_Entity_Id);
13222 -- Called during first phase to visit a node and all its subtrees
13224 -----------
13225 -- Assoc --
13226 -----------
13228 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
13229 E : Elmt_Id;
13230 Ent : Entity_Id;
13232 begin
13233 if not Has_Extension (N) or else No (Actual_Map) then
13234 return N;
13236 elsif NCT_Hash_Tables_Used then
13237 Ent := NCT_Assoc.Get (Entity_Id (N));
13239 if Present (Ent) then
13240 return Ent;
13241 else
13242 return N;
13243 end if;
13245 -- No hash table used, do serial search
13247 else
13248 E := First_Elmt (Actual_Map);
13249 while Present (E) loop
13250 if Node (E) = N then
13251 return Node (Next_Elmt (E));
13252 else
13253 E := Next_Elmt (Next_Elmt (E));
13254 end if;
13255 end loop;
13256 end if;
13258 return N;
13259 end Assoc;
13261 ---------------------------
13262 -- Build_NCT_Hash_Tables --
13263 ---------------------------
13265 procedure Build_NCT_Hash_Tables is
13266 Elmt : Elmt_Id;
13267 Ent : Entity_Id;
13268 begin
13269 if NCT_Hash_Table_Setup then
13270 NCT_Assoc.Reset;
13271 NCT_Itype_Assoc.Reset;
13272 end if;
13274 Elmt := First_Elmt (Actual_Map);
13275 while Present (Elmt) loop
13276 Ent := Node (Elmt);
13278 -- Get new entity, and associate old and new
13280 Next_Elmt (Elmt);
13281 NCT_Assoc.Set (Ent, Node (Elmt));
13283 if Is_Type (Ent) then
13284 declare
13285 Anode : constant Entity_Id :=
13286 Associated_Node_For_Itype (Ent);
13288 begin
13289 if Present (Anode) then
13291 -- Enter a link between the associated node of the
13292 -- old Itype and the new Itype, for updating later
13293 -- when node is copied.
13295 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
13296 end if;
13297 end;
13298 end if;
13300 Next_Elmt (Elmt);
13301 end loop;
13303 NCT_Hash_Tables_Used := True;
13304 NCT_Hash_Table_Setup := True;
13305 end Build_NCT_Hash_Tables;
13307 ---------------------------------
13308 -- Copy_Elist_With_Replacement --
13309 ---------------------------------
13311 function Copy_Elist_With_Replacement
13312 (Old_Elist : Elist_Id) return Elist_Id
13314 M : Elmt_Id;
13315 New_Elist : Elist_Id;
13317 begin
13318 if No (Old_Elist) then
13319 return No_Elist;
13321 else
13322 New_Elist := New_Elmt_List;
13324 M := First_Elmt (Old_Elist);
13325 while Present (M) loop
13326 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
13327 Next_Elmt (M);
13328 end loop;
13329 end if;
13331 return New_Elist;
13332 end Copy_Elist_With_Replacement;
13334 ---------------------------------
13335 -- Copy_Itype_With_Replacement --
13336 ---------------------------------
13338 -- This routine exactly parallels its phase one analog Visit_Itype,
13340 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
13341 begin
13342 -- Translate Next_Entity, Scope and Etype fields, in case they
13343 -- reference entities that have been mapped into copies.
13345 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
13346 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
13348 if Present (New_Scope) then
13349 Set_Scope (New_Itype, New_Scope);
13350 else
13351 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
13352 end if;
13354 -- Copy referenced fields
13356 if Is_Discrete_Type (New_Itype) then
13357 Set_Scalar_Range (New_Itype,
13358 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
13360 elsif Has_Discriminants (Base_Type (New_Itype)) then
13361 Set_Discriminant_Constraint (New_Itype,
13362 Copy_Elist_With_Replacement
13363 (Discriminant_Constraint (New_Itype)));
13365 elsif Is_Array_Type (New_Itype) then
13366 if Present (First_Index (New_Itype)) then
13367 Set_First_Index (New_Itype,
13368 First (Copy_List_With_Replacement
13369 (List_Containing (First_Index (New_Itype)))));
13370 end if;
13372 if Is_Packed (New_Itype) then
13373 Set_Packed_Array_Impl_Type (New_Itype,
13374 Copy_Node_With_Replacement
13375 (Packed_Array_Impl_Type (New_Itype)));
13376 end if;
13377 end if;
13378 end Copy_Itype_With_Replacement;
13380 --------------------------------
13381 -- Copy_List_With_Replacement --
13382 --------------------------------
13384 function Copy_List_With_Replacement
13385 (Old_List : List_Id) return List_Id
13387 New_List : List_Id;
13388 E : Node_Id;
13390 begin
13391 if Old_List = No_List then
13392 return No_List;
13394 else
13395 New_List := Empty_List;
13397 E := First (Old_List);
13398 while Present (E) loop
13399 Append (Copy_Node_With_Replacement (E), New_List);
13400 Next (E);
13401 end loop;
13403 return New_List;
13404 end if;
13405 end Copy_List_With_Replacement;
13407 --------------------------------
13408 -- Copy_Node_With_Replacement --
13409 --------------------------------
13411 function Copy_Node_With_Replacement
13412 (Old_Node : Node_Id) return Node_Id
13414 New_Node : Node_Id;
13416 procedure Adjust_Named_Associations
13417 (Old_Node : Node_Id;
13418 New_Node : Node_Id);
13419 -- If a call node has named associations, these are chained through
13420 -- the First_Named_Actual, Next_Named_Actual links. These must be
13421 -- propagated separately to the new parameter list, because these
13422 -- are not syntactic fields.
13424 function Copy_Field_With_Replacement
13425 (Field : Union_Id) return Union_Id;
13426 -- Given Field, which is a field of Old_Node, return a copy of it
13427 -- if it is a syntactic field (i.e. its parent is Node), setting
13428 -- the parent of the copy to poit to New_Node. Otherwise returns
13429 -- the field (possibly mapped if it is an entity).
13431 -------------------------------
13432 -- Adjust_Named_Associations --
13433 -------------------------------
13435 procedure Adjust_Named_Associations
13436 (Old_Node : Node_Id;
13437 New_Node : Node_Id)
13439 Old_E : Node_Id;
13440 New_E : Node_Id;
13442 Old_Next : Node_Id;
13443 New_Next : Node_Id;
13445 begin
13446 Old_E := First (Parameter_Associations (Old_Node));
13447 New_E := First (Parameter_Associations (New_Node));
13448 while Present (Old_E) loop
13449 if Nkind (Old_E) = N_Parameter_Association
13450 and then Present (Next_Named_Actual (Old_E))
13451 then
13452 if First_Named_Actual (Old_Node)
13453 = Explicit_Actual_Parameter (Old_E)
13454 then
13455 Set_First_Named_Actual
13456 (New_Node, Explicit_Actual_Parameter (New_E));
13457 end if;
13459 -- Now scan parameter list from the beginning,to locate
13460 -- next named actual, which can be out of order.
13462 Old_Next := First (Parameter_Associations (Old_Node));
13463 New_Next := First (Parameter_Associations (New_Node));
13465 while Nkind (Old_Next) /= N_Parameter_Association
13466 or else Explicit_Actual_Parameter (Old_Next)
13467 /= Next_Named_Actual (Old_E)
13468 loop
13469 Next (Old_Next);
13470 Next (New_Next);
13471 end loop;
13473 Set_Next_Named_Actual
13474 (New_E, Explicit_Actual_Parameter (New_Next));
13475 end if;
13477 Next (Old_E);
13478 Next (New_E);
13479 end loop;
13480 end Adjust_Named_Associations;
13482 ---------------------------------
13483 -- Copy_Field_With_Replacement --
13484 ---------------------------------
13486 function Copy_Field_With_Replacement
13487 (Field : Union_Id) return Union_Id
13489 begin
13490 if Field = Union_Id (Empty) then
13491 return Field;
13493 elsif Field in Node_Range then
13494 declare
13495 Old_N : constant Node_Id := Node_Id (Field);
13496 New_N : Node_Id;
13498 begin
13499 -- If syntactic field, as indicated by the parent pointer
13500 -- being set, then copy the referenced node recursively.
13502 if Parent (Old_N) = Old_Node then
13503 New_N := Copy_Node_With_Replacement (Old_N);
13505 if New_N /= Old_N then
13506 Set_Parent (New_N, New_Node);
13507 end if;
13509 -- For semantic fields, update possible entity reference
13510 -- from the replacement map.
13512 else
13513 New_N := Assoc (Old_N);
13514 end if;
13516 return Union_Id (New_N);
13517 end;
13519 elsif Field in List_Range then
13520 declare
13521 Old_L : constant List_Id := List_Id (Field);
13522 New_L : List_Id;
13524 begin
13525 -- If syntactic field, as indicated by the parent pointer,
13526 -- then recursively copy the entire referenced list.
13528 if Parent (Old_L) = Old_Node then
13529 New_L := Copy_List_With_Replacement (Old_L);
13530 Set_Parent (New_L, New_Node);
13532 -- For semantic list, just returned unchanged
13534 else
13535 New_L := Old_L;
13536 end if;
13538 return Union_Id (New_L);
13539 end;
13541 -- Anything other than a list or a node is returned unchanged
13543 else
13544 return Field;
13545 end if;
13546 end Copy_Field_With_Replacement;
13548 -- Start of processing for Copy_Node_With_Replacement
13550 begin
13551 if Old_Node <= Empty_Or_Error then
13552 return Old_Node;
13554 elsif Has_Extension (Old_Node) then
13555 return Assoc (Old_Node);
13557 else
13558 New_Node := New_Copy (Old_Node);
13560 -- If the node we are copying is the associated node of a
13561 -- previously copied Itype, then adjust the associated node
13562 -- of the copy of that Itype accordingly.
13564 if Present (Actual_Map) then
13565 declare
13566 E : Elmt_Id;
13567 Ent : Entity_Id;
13569 begin
13570 -- Case of hash table used
13572 if NCT_Hash_Tables_Used then
13573 Ent := NCT_Itype_Assoc.Get (Old_Node);
13575 if Present (Ent) then
13576 Set_Associated_Node_For_Itype (Ent, New_Node);
13577 end if;
13579 -- Case of no hash table used
13581 else
13582 E := First_Elmt (Actual_Map);
13583 while Present (E) loop
13584 if Is_Itype (Node (E))
13585 and then
13586 Old_Node = Associated_Node_For_Itype (Node (E))
13587 then
13588 Set_Associated_Node_For_Itype
13589 (Node (Next_Elmt (E)), New_Node);
13590 end if;
13592 E := Next_Elmt (Next_Elmt (E));
13593 end loop;
13594 end if;
13595 end;
13596 end if;
13598 -- Recursively copy descendents
13600 Set_Field1
13601 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
13602 Set_Field2
13603 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
13604 Set_Field3
13605 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
13606 Set_Field4
13607 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
13608 Set_Field5
13609 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
13611 -- Adjust Sloc of new node if necessary
13613 if New_Sloc /= No_Location then
13614 Set_Sloc (New_Node, New_Sloc);
13616 -- If we adjust the Sloc, then we are essentially making
13617 -- a completely new node, so the Comes_From_Source flag
13618 -- should be reset to the proper default value.
13620 Nodes.Table (New_Node).Comes_From_Source :=
13621 Default_Node.Comes_From_Source;
13622 end if;
13624 -- If the node is call and has named associations,
13625 -- set the corresponding links in the copy.
13627 if (Nkind (Old_Node) = N_Function_Call
13628 or else Nkind (Old_Node) = N_Entry_Call_Statement
13629 or else
13630 Nkind (Old_Node) = N_Procedure_Call_Statement)
13631 and then Present (First_Named_Actual (Old_Node))
13632 then
13633 Adjust_Named_Associations (Old_Node, New_Node);
13634 end if;
13636 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
13637 -- The replacement mechanism applies to entities, and is not used
13638 -- here. Eventually we may need a more general graph-copying
13639 -- routine. For now, do a sequential search to find desired node.
13641 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
13642 and then Present (First_Real_Statement (Old_Node))
13643 then
13644 declare
13645 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
13646 N1, N2 : Node_Id;
13648 begin
13649 N1 := First (Statements (Old_Node));
13650 N2 := First (Statements (New_Node));
13652 while N1 /= Old_F loop
13653 Next (N1);
13654 Next (N2);
13655 end loop;
13657 Set_First_Real_Statement (New_Node, N2);
13658 end;
13659 end if;
13660 end if;
13662 -- All done, return copied node
13664 return New_Node;
13665 end Copy_Node_With_Replacement;
13667 -----------------
13668 -- Visit_Elist --
13669 -----------------
13671 procedure Visit_Elist (E : Elist_Id) is
13672 Elmt : Elmt_Id;
13673 begin
13674 if Present (E) then
13675 Elmt := First_Elmt (E);
13677 while Elmt /= No_Elmt loop
13678 Visit_Node (Node (Elmt));
13679 Next_Elmt (Elmt);
13680 end loop;
13681 end if;
13682 end Visit_Elist;
13684 -----------------
13685 -- Visit_Field --
13686 -----------------
13688 procedure Visit_Field (F : Union_Id; N : Node_Id) is
13689 begin
13690 if F = Union_Id (Empty) then
13691 return;
13693 elsif F in Node_Range then
13695 -- Copy node if it is syntactic, i.e. its parent pointer is
13696 -- set to point to the field that referenced it (certain
13697 -- Itypes will also meet this criterion, which is fine, since
13698 -- these are clearly Itypes that do need to be copied, since
13699 -- we are copying their parent.)
13701 if Parent (Node_Id (F)) = N then
13702 Visit_Node (Node_Id (F));
13703 return;
13705 -- Another case, if we are pointing to an Itype, then we want
13706 -- to copy it if its associated node is somewhere in the tree
13707 -- being copied.
13709 -- Note: the exclusion of self-referential copies is just an
13710 -- optimization, since the search of the already copied list
13711 -- would catch it, but it is a common case (Etype pointing
13712 -- to itself for an Itype that is a base type).
13714 elsif Has_Extension (Node_Id (F))
13715 and then Is_Itype (Entity_Id (F))
13716 and then Node_Id (F) /= N
13717 then
13718 declare
13719 P : Node_Id;
13721 begin
13722 P := Associated_Node_For_Itype (Node_Id (F));
13723 while Present (P) loop
13724 if P = Source then
13725 Visit_Node (Node_Id (F));
13726 return;
13727 else
13728 P := Parent (P);
13729 end if;
13730 end loop;
13732 -- An Itype whose parent is not being copied definitely
13733 -- should NOT be copied, since it does not belong in any
13734 -- sense to the copied subtree.
13736 return;
13737 end;
13738 end if;
13740 elsif F in List_Range and then Parent (List_Id (F)) = N then
13741 Visit_List (List_Id (F));
13742 return;
13743 end if;
13744 end Visit_Field;
13746 -----------------
13747 -- Visit_Itype --
13748 -----------------
13750 procedure Visit_Itype (Old_Itype : Entity_Id) is
13751 New_Itype : Entity_Id;
13752 E : Elmt_Id;
13753 Ent : Entity_Id;
13755 begin
13756 -- Itypes that describe the designated type of access to subprograms
13757 -- have the structure of subprogram declarations, with signatures,
13758 -- etc. Either we duplicate the signatures completely, or choose to
13759 -- share such itypes, which is fine because their elaboration will
13760 -- have no side effects.
13762 if Ekind (Old_Itype) = E_Subprogram_Type then
13763 return;
13764 end if;
13766 New_Itype := New_Copy (Old_Itype);
13768 -- The new Itype has all the attributes of the old one, and
13769 -- we just copy the contents of the entity. However, the back-end
13770 -- needs different names for debugging purposes, so we create a
13771 -- new internal name for it in all cases.
13773 Set_Chars (New_Itype, New_Internal_Name ('T'));
13775 -- If our associated node is an entity that has already been copied,
13776 -- then set the associated node of the copy to point to the right
13777 -- copy. If we have copied an Itype that is itself the associated
13778 -- node of some previously copied Itype, then we set the right
13779 -- pointer in the other direction.
13781 if Present (Actual_Map) then
13783 -- Case of hash tables used
13785 if NCT_Hash_Tables_Used then
13787 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
13789 if Present (Ent) then
13790 Set_Associated_Node_For_Itype (New_Itype, Ent);
13791 end if;
13793 Ent := NCT_Itype_Assoc.Get (Old_Itype);
13794 if Present (Ent) then
13795 Set_Associated_Node_For_Itype (Ent, New_Itype);
13797 -- If the hash table has no association for this Itype and
13798 -- its associated node, enter one now.
13800 else
13801 NCT_Itype_Assoc.Set
13802 (Associated_Node_For_Itype (Old_Itype), New_Itype);
13803 end if;
13805 -- Case of hash tables not used
13807 else
13808 E := First_Elmt (Actual_Map);
13809 while Present (E) loop
13810 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
13811 Set_Associated_Node_For_Itype
13812 (New_Itype, Node (Next_Elmt (E)));
13813 end if;
13815 if Is_Type (Node (E))
13816 and then Old_Itype = Associated_Node_For_Itype (Node (E))
13817 then
13818 Set_Associated_Node_For_Itype
13819 (Node (Next_Elmt (E)), New_Itype);
13820 end if;
13822 E := Next_Elmt (Next_Elmt (E));
13823 end loop;
13824 end if;
13825 end if;
13827 if Present (Freeze_Node (New_Itype)) then
13828 Set_Is_Frozen (New_Itype, False);
13829 Set_Freeze_Node (New_Itype, Empty);
13830 end if;
13832 -- Add new association to map
13834 if No (Actual_Map) then
13835 Actual_Map := New_Elmt_List;
13836 end if;
13838 Append_Elmt (Old_Itype, Actual_Map);
13839 Append_Elmt (New_Itype, Actual_Map);
13841 if NCT_Hash_Tables_Used then
13842 NCT_Assoc.Set (Old_Itype, New_Itype);
13844 else
13845 NCT_Table_Entries := NCT_Table_Entries + 1;
13847 if NCT_Table_Entries > NCT_Hash_Threshold then
13848 Build_NCT_Hash_Tables;
13849 end if;
13850 end if;
13852 -- If a record subtype is simply copied, the entity list will be
13853 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
13855 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
13856 Set_Cloned_Subtype (New_Itype, Old_Itype);
13857 end if;
13859 -- Visit descendents that eventually get copied
13861 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
13863 if Is_Discrete_Type (Old_Itype) then
13864 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
13866 elsif Has_Discriminants (Base_Type (Old_Itype)) then
13867 -- ??? This should involve call to Visit_Field
13868 Visit_Elist (Discriminant_Constraint (Old_Itype));
13870 elsif Is_Array_Type (Old_Itype) then
13871 if Present (First_Index (Old_Itype)) then
13872 Visit_Field (Union_Id (List_Containing
13873 (First_Index (Old_Itype))),
13874 Old_Itype);
13875 end if;
13877 if Is_Packed (Old_Itype) then
13878 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
13879 Old_Itype);
13880 end if;
13881 end if;
13882 end Visit_Itype;
13884 ----------------
13885 -- Visit_List --
13886 ----------------
13888 procedure Visit_List (L : List_Id) is
13889 N : Node_Id;
13890 begin
13891 if L /= No_List then
13892 N := First (L);
13894 while Present (N) loop
13895 Visit_Node (N);
13896 Next (N);
13897 end loop;
13898 end if;
13899 end Visit_List;
13901 ----------------
13902 -- Visit_Node --
13903 ----------------
13905 procedure Visit_Node (N : Node_Or_Entity_Id) is
13907 -- Start of processing for Visit_Node
13909 begin
13910 -- Handle case of an Itype, which must be copied
13912 if Has_Extension (N) and then Is_Itype (N) then
13914 -- Nothing to do if already in the list. This can happen with an
13915 -- Itype entity that appears more than once in the tree.
13916 -- Note that we do not want to visit descendents in this case.
13918 -- Test for already in list when hash table is used
13920 if NCT_Hash_Tables_Used then
13921 if Present (NCT_Assoc.Get (Entity_Id (N))) then
13922 return;
13923 end if;
13925 -- Test for already in list when hash table not used
13927 else
13928 declare
13929 E : Elmt_Id;
13930 begin
13931 if Present (Actual_Map) then
13932 E := First_Elmt (Actual_Map);
13933 while Present (E) loop
13934 if Node (E) = N then
13935 return;
13936 else
13937 E := Next_Elmt (Next_Elmt (E));
13938 end if;
13939 end loop;
13940 end if;
13941 end;
13942 end if;
13944 Visit_Itype (N);
13945 end if;
13947 -- Visit descendents
13949 Visit_Field (Field1 (N), N);
13950 Visit_Field (Field2 (N), N);
13951 Visit_Field (Field3 (N), N);
13952 Visit_Field (Field4 (N), N);
13953 Visit_Field (Field5 (N), N);
13954 end Visit_Node;
13956 -- Start of processing for New_Copy_Tree
13958 begin
13959 Actual_Map := Map;
13961 -- See if we should use hash table
13963 if No (Actual_Map) then
13964 NCT_Hash_Tables_Used := False;
13966 else
13967 declare
13968 Elmt : Elmt_Id;
13970 begin
13971 NCT_Table_Entries := 0;
13973 Elmt := First_Elmt (Actual_Map);
13974 while Present (Elmt) loop
13975 NCT_Table_Entries := NCT_Table_Entries + 1;
13976 Next_Elmt (Elmt);
13977 Next_Elmt (Elmt);
13978 end loop;
13980 if NCT_Table_Entries > NCT_Hash_Threshold then
13981 Build_NCT_Hash_Tables;
13982 else
13983 NCT_Hash_Tables_Used := False;
13984 end if;
13985 end;
13986 end if;
13988 -- Hash table set up if required, now start phase one by visiting
13989 -- top node (we will recursively visit the descendents).
13991 Visit_Node (Source);
13993 -- Now the second phase of the copy can start. First we process
13994 -- all the mapped entities, copying their descendents.
13996 if Present (Actual_Map) then
13997 declare
13998 Elmt : Elmt_Id;
13999 New_Itype : Entity_Id;
14000 begin
14001 Elmt := First_Elmt (Actual_Map);
14002 while Present (Elmt) loop
14003 Next_Elmt (Elmt);
14004 New_Itype := Node (Elmt);
14005 Copy_Itype_With_Replacement (New_Itype);
14006 Next_Elmt (Elmt);
14007 end loop;
14008 end;
14009 end if;
14011 -- Now we can copy the actual tree
14013 return Copy_Node_With_Replacement (Source);
14014 end New_Copy_Tree;
14016 -------------------------
14017 -- New_External_Entity --
14018 -------------------------
14020 function New_External_Entity
14021 (Kind : Entity_Kind;
14022 Scope_Id : Entity_Id;
14023 Sloc_Value : Source_Ptr;
14024 Related_Id : Entity_Id;
14025 Suffix : Character;
14026 Suffix_Index : Nat := 0;
14027 Prefix : Character := ' ') return Entity_Id
14029 N : constant Entity_Id :=
14030 Make_Defining_Identifier (Sloc_Value,
14031 New_External_Name
14032 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
14034 begin
14035 Set_Ekind (N, Kind);
14036 Set_Is_Internal (N, True);
14037 Append_Entity (N, Scope_Id);
14038 Set_Public_Status (N);
14040 if Kind in Type_Kind then
14041 Init_Size_Align (N);
14042 end if;
14044 return N;
14045 end New_External_Entity;
14047 -------------------------
14048 -- New_Internal_Entity --
14049 -------------------------
14051 function New_Internal_Entity
14052 (Kind : Entity_Kind;
14053 Scope_Id : Entity_Id;
14054 Sloc_Value : Source_Ptr;
14055 Id_Char : Character) return Entity_Id
14057 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
14059 begin
14060 Set_Ekind (N, Kind);
14061 Set_Is_Internal (N, True);
14062 Append_Entity (N, Scope_Id);
14064 if Kind in Type_Kind then
14065 Init_Size_Align (N);
14066 end if;
14068 return N;
14069 end New_Internal_Entity;
14071 -----------------
14072 -- Next_Actual --
14073 -----------------
14075 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
14076 N : Node_Id;
14078 begin
14079 -- If we are pointing at a positional parameter, it is a member of a
14080 -- node list (the list of parameters), and the next parameter is the
14081 -- next node on the list, unless we hit a parameter association, then
14082 -- we shift to using the chain whose head is the First_Named_Actual in
14083 -- the parent, and then is threaded using the Next_Named_Actual of the
14084 -- Parameter_Association. All this fiddling is because the original node
14085 -- list is in the textual call order, and what we need is the
14086 -- declaration order.
14088 if Is_List_Member (Actual_Id) then
14089 N := Next (Actual_Id);
14091 if Nkind (N) = N_Parameter_Association then
14092 return First_Named_Actual (Parent (Actual_Id));
14093 else
14094 return N;
14095 end if;
14097 else
14098 return Next_Named_Actual (Parent (Actual_Id));
14099 end if;
14100 end Next_Actual;
14102 procedure Next_Actual (Actual_Id : in out Node_Id) is
14103 begin
14104 Actual_Id := Next_Actual (Actual_Id);
14105 end Next_Actual;
14107 -----------------------
14108 -- Normalize_Actuals --
14109 -----------------------
14111 -- Chain actuals according to formals of subprogram. If there are no named
14112 -- associations, the chain is simply the list of Parameter Associations,
14113 -- since the order is the same as the declaration order. If there are named
14114 -- associations, then the First_Named_Actual field in the N_Function_Call
14115 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14116 -- node for the parameter that comes first in declaration order. The
14117 -- remaining named parameters are then chained in declaration order using
14118 -- Next_Named_Actual.
14120 -- This routine also verifies that the number of actuals is compatible with
14121 -- the number and default values of formals, but performs no type checking
14122 -- (type checking is done by the caller).
14124 -- If the matching succeeds, Success is set to True and the caller proceeds
14125 -- with type-checking. If the match is unsuccessful, then Success is set to
14126 -- False, and the caller attempts a different interpretation, if there is
14127 -- one.
14129 -- If the flag Report is on, the call is not overloaded, and a failure to
14130 -- match can be reported here, rather than in the caller.
14132 procedure Normalize_Actuals
14133 (N : Node_Id;
14134 S : Entity_Id;
14135 Report : Boolean;
14136 Success : out Boolean)
14138 Actuals : constant List_Id := Parameter_Associations (N);
14139 Actual : Node_Id := Empty;
14140 Formal : Entity_Id;
14141 Last : Node_Id := Empty;
14142 First_Named : Node_Id := Empty;
14143 Found : Boolean;
14145 Formals_To_Match : Integer := 0;
14146 Actuals_To_Match : Integer := 0;
14148 procedure Chain (A : Node_Id);
14149 -- Add named actual at the proper place in the list, using the
14150 -- Next_Named_Actual link.
14152 function Reporting return Boolean;
14153 -- Determines if an error is to be reported. To report an error, we
14154 -- need Report to be True, and also we do not report errors caused
14155 -- by calls to init procs that occur within other init procs. Such
14156 -- errors must always be cascaded errors, since if all the types are
14157 -- declared correctly, the compiler will certainly build decent calls.
14159 -----------
14160 -- Chain --
14161 -----------
14163 procedure Chain (A : Node_Id) is
14164 begin
14165 if No (Last) then
14167 -- Call node points to first actual in list
14169 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
14171 else
14172 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
14173 end if;
14175 Last := A;
14176 Set_Next_Named_Actual (Last, Empty);
14177 end Chain;
14179 ---------------
14180 -- Reporting --
14181 ---------------
14183 function Reporting return Boolean is
14184 begin
14185 if not Report then
14186 return False;
14188 elsif not Within_Init_Proc then
14189 return True;
14191 elsif Is_Init_Proc (Entity (Name (N))) then
14192 return False;
14194 else
14195 return True;
14196 end if;
14197 end Reporting;
14199 -- Start of processing for Normalize_Actuals
14201 begin
14202 if Is_Access_Type (S) then
14204 -- The name in the call is a function call that returns an access
14205 -- to subprogram. The designated type has the list of formals.
14207 Formal := First_Formal (Designated_Type (S));
14208 else
14209 Formal := First_Formal (S);
14210 end if;
14212 while Present (Formal) loop
14213 Formals_To_Match := Formals_To_Match + 1;
14214 Next_Formal (Formal);
14215 end loop;
14217 -- Find if there is a named association, and verify that no positional
14218 -- associations appear after named ones.
14220 if Present (Actuals) then
14221 Actual := First (Actuals);
14222 end if;
14224 while Present (Actual)
14225 and then Nkind (Actual) /= N_Parameter_Association
14226 loop
14227 Actuals_To_Match := Actuals_To_Match + 1;
14228 Next (Actual);
14229 end loop;
14231 if No (Actual) and Actuals_To_Match = Formals_To_Match then
14233 -- Most common case: positional notation, no defaults
14235 Success := True;
14236 return;
14238 elsif Actuals_To_Match > Formals_To_Match then
14240 -- Too many actuals: will not work
14242 if Reporting then
14243 if Is_Entity_Name (Name (N)) then
14244 Error_Msg_N ("too many arguments in call to&", Name (N));
14245 else
14246 Error_Msg_N ("too many arguments in call", N);
14247 end if;
14248 end if;
14250 Success := False;
14251 return;
14252 end if;
14254 First_Named := Actual;
14256 while Present (Actual) loop
14257 if Nkind (Actual) /= N_Parameter_Association then
14258 Error_Msg_N
14259 ("positional parameters not allowed after named ones", Actual);
14260 Success := False;
14261 return;
14263 else
14264 Actuals_To_Match := Actuals_To_Match + 1;
14265 end if;
14267 Next (Actual);
14268 end loop;
14270 if Present (Actuals) then
14271 Actual := First (Actuals);
14272 end if;
14274 Formal := First_Formal (S);
14275 while Present (Formal) loop
14277 -- Match the formals in order. If the corresponding actual is
14278 -- positional, nothing to do. Else scan the list of named actuals
14279 -- to find the one with the right name.
14281 if Present (Actual)
14282 and then Nkind (Actual) /= N_Parameter_Association
14283 then
14284 Next (Actual);
14285 Actuals_To_Match := Actuals_To_Match - 1;
14286 Formals_To_Match := Formals_To_Match - 1;
14288 else
14289 -- For named parameters, search the list of actuals to find
14290 -- one that matches the next formal name.
14292 Actual := First_Named;
14293 Found := False;
14294 while Present (Actual) loop
14295 if Chars (Selector_Name (Actual)) = Chars (Formal) then
14296 Found := True;
14297 Chain (Actual);
14298 Actuals_To_Match := Actuals_To_Match - 1;
14299 Formals_To_Match := Formals_To_Match - 1;
14300 exit;
14301 end if;
14303 Next (Actual);
14304 end loop;
14306 if not Found then
14307 if Ekind (Formal) /= E_In_Parameter
14308 or else No (Default_Value (Formal))
14309 then
14310 if Reporting then
14311 if (Comes_From_Source (S)
14312 or else Sloc (S) = Standard_Location)
14313 and then Is_Overloadable (S)
14314 then
14315 if No (Actuals)
14316 and then
14317 Nkind_In (Parent (N), N_Procedure_Call_Statement,
14318 N_Function_Call,
14319 N_Parameter_Association)
14320 and then Ekind (S) /= E_Function
14321 then
14322 Set_Etype (N, Etype (S));
14324 else
14325 Error_Msg_Name_1 := Chars (S);
14326 Error_Msg_Sloc := Sloc (S);
14327 Error_Msg_NE
14328 ("missing argument for parameter & " &
14329 "in call to % declared #", N, Formal);
14330 end if;
14332 elsif Is_Overloadable (S) then
14333 Error_Msg_Name_1 := Chars (S);
14335 -- Point to type derivation that generated the
14336 -- operation.
14338 Error_Msg_Sloc := Sloc (Parent (S));
14340 Error_Msg_NE
14341 ("missing argument for parameter & " &
14342 "in call to % (inherited) #", N, Formal);
14344 else
14345 Error_Msg_NE
14346 ("missing argument for parameter &", N, Formal);
14347 end if;
14348 end if;
14350 Success := False;
14351 return;
14353 else
14354 Formals_To_Match := Formals_To_Match - 1;
14355 end if;
14356 end if;
14357 end if;
14359 Next_Formal (Formal);
14360 end loop;
14362 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
14363 Success := True;
14364 return;
14366 else
14367 if Reporting then
14369 -- Find some superfluous named actual that did not get
14370 -- attached to the list of associations.
14372 Actual := First (Actuals);
14373 while Present (Actual) loop
14374 if Nkind (Actual) = N_Parameter_Association
14375 and then Actual /= Last
14376 and then No (Next_Named_Actual (Actual))
14377 then
14378 Error_Msg_N ("unmatched actual & in call",
14379 Selector_Name (Actual));
14380 exit;
14381 end if;
14383 Next (Actual);
14384 end loop;
14385 end if;
14387 Success := False;
14388 return;
14389 end if;
14390 end Normalize_Actuals;
14392 --------------------------------
14393 -- Note_Possible_Modification --
14394 --------------------------------
14396 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
14397 Modification_Comes_From_Source : constant Boolean :=
14398 Comes_From_Source (Parent (N));
14400 Ent : Entity_Id;
14401 Exp : Node_Id;
14403 begin
14404 -- Loop to find referenced entity, if there is one
14406 Exp := N;
14407 loop
14408 Ent := Empty;
14410 if Is_Entity_Name (Exp) then
14411 Ent := Entity (Exp);
14413 -- If the entity is missing, it is an undeclared identifier,
14414 -- and there is nothing to annotate.
14416 if No (Ent) then
14417 return;
14418 end if;
14420 elsif Nkind (Exp) = N_Explicit_Dereference then
14421 declare
14422 P : constant Node_Id := Prefix (Exp);
14424 begin
14425 -- In formal verification mode, keep track of all reads and
14426 -- writes through explicit dereferences.
14428 if GNATprove_Mode then
14429 SPARK_Specific.Generate_Dereference (N, 'm');
14430 end if;
14432 if Nkind (P) = N_Selected_Component
14433 and then Present (Entry_Formal (Entity (Selector_Name (P))))
14434 then
14435 -- Case of a reference to an entry formal
14437 Ent := Entry_Formal (Entity (Selector_Name (P)));
14439 elsif Nkind (P) = N_Identifier
14440 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
14441 and then Present (Expression (Parent (Entity (P))))
14442 and then Nkind (Expression (Parent (Entity (P)))) =
14443 N_Reference
14444 then
14445 -- Case of a reference to a value on which side effects have
14446 -- been removed.
14448 Exp := Prefix (Expression (Parent (Entity (P))));
14449 goto Continue;
14451 else
14452 return;
14453 end if;
14454 end;
14456 elsif Nkind_In (Exp, N_Type_Conversion,
14457 N_Unchecked_Type_Conversion)
14458 then
14459 Exp := Expression (Exp);
14460 goto Continue;
14462 elsif Nkind_In (Exp, N_Slice,
14463 N_Indexed_Component,
14464 N_Selected_Component)
14465 then
14466 -- Special check, if the prefix is an access type, then return
14467 -- since we are modifying the thing pointed to, not the prefix.
14468 -- When we are expanding, most usually the prefix is replaced
14469 -- by an explicit dereference, and this test is not needed, but
14470 -- in some cases (notably -gnatc mode and generics) when we do
14471 -- not do full expansion, we need this special test.
14473 if Is_Access_Type (Etype (Prefix (Exp))) then
14474 return;
14476 -- Otherwise go to prefix and keep going
14478 else
14479 Exp := Prefix (Exp);
14480 goto Continue;
14481 end if;
14483 -- All other cases, not a modification
14485 else
14486 return;
14487 end if;
14489 -- Now look for entity being referenced
14491 if Present (Ent) then
14492 if Is_Object (Ent) then
14493 if Comes_From_Source (Exp)
14494 or else Modification_Comes_From_Source
14495 then
14496 -- Give warning if pragma unmodified given and we are
14497 -- sure this is a modification.
14499 if Has_Pragma_Unmodified (Ent) and then Sure then
14500 Error_Msg_NE
14501 ("??pragma Unmodified given for &!", N, Ent);
14502 end if;
14504 Set_Never_Set_In_Source (Ent, False);
14505 end if;
14507 Set_Is_True_Constant (Ent, False);
14508 Set_Current_Value (Ent, Empty);
14509 Set_Is_Known_Null (Ent, False);
14511 if not Can_Never_Be_Null (Ent) then
14512 Set_Is_Known_Non_Null (Ent, False);
14513 end if;
14515 -- Follow renaming chain
14517 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
14518 and then Present (Renamed_Object (Ent))
14519 then
14520 Exp := Renamed_Object (Ent);
14522 -- If the entity is the loop variable in an iteration over
14523 -- a container, retrieve container expression to indicate
14524 -- possible modificastion.
14526 if Present (Related_Expression (Ent))
14527 and then Nkind (Parent (Related_Expression (Ent))) =
14528 N_Iterator_Specification
14529 then
14530 Exp := Original_Node (Related_Expression (Ent));
14531 end if;
14533 goto Continue;
14535 -- The expression may be the renaming of a subcomponent of an
14536 -- array or container. The assignment to the subcomponent is
14537 -- a modification of the container.
14539 elsif Comes_From_Source (Original_Node (Exp))
14540 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
14541 N_Indexed_Component)
14542 then
14543 Exp := Prefix (Original_Node (Exp));
14544 goto Continue;
14545 end if;
14547 -- Generate a reference only if the assignment comes from
14548 -- source. This excludes, for example, calls to a dispatching
14549 -- assignment operation when the left-hand side is tagged. In
14550 -- GNATprove mode, we need those references also on generated
14551 -- code, as these are used to compute the local effects of
14552 -- subprograms.
14554 if Modification_Comes_From_Source or GNATprove_Mode then
14555 Generate_Reference (Ent, Exp, 'm');
14557 -- If the target of the assignment is the bound variable
14558 -- in an iterator, indicate that the corresponding array
14559 -- or container is also modified.
14561 if Ada_Version >= Ada_2012
14562 and then Nkind (Parent (Ent)) = N_Iterator_Specification
14563 then
14564 declare
14565 Domain : constant Node_Id := Name (Parent (Ent));
14567 begin
14568 -- TBD : in the full version of the construct, the
14569 -- domain of iteration can be given by an expression.
14571 if Is_Entity_Name (Domain) then
14572 Generate_Reference (Entity (Domain), Exp, 'm');
14573 Set_Is_True_Constant (Entity (Domain), False);
14574 Set_Never_Set_In_Source (Entity (Domain), False);
14575 end if;
14576 end;
14577 end if;
14578 end if;
14580 Check_Nested_Access (Ent);
14581 end if;
14583 Kill_Checks (Ent);
14585 -- If we are sure this is a modification from source, and we know
14586 -- this modifies a constant, then give an appropriate warning.
14588 if Overlays_Constant (Ent)
14589 and then (Modification_Comes_From_Source and Sure)
14590 then
14591 declare
14592 A : constant Node_Id := Address_Clause (Ent);
14593 begin
14594 if Present (A) then
14595 declare
14596 Exp : constant Node_Id := Expression (A);
14597 begin
14598 if Nkind (Exp) = N_Attribute_Reference
14599 and then Attribute_Name (Exp) = Name_Address
14600 and then Is_Entity_Name (Prefix (Exp))
14601 then
14602 Error_Msg_Sloc := Sloc (A);
14603 Error_Msg_NE
14604 ("constant& may be modified via address "
14605 & "clause#??", N, Entity (Prefix (Exp)));
14606 end if;
14607 end;
14608 end if;
14609 end;
14610 end if;
14612 return;
14613 end if;
14615 <<Continue>>
14616 null;
14617 end loop;
14618 end Note_Possible_Modification;
14620 -------------------------
14621 -- Object_Access_Level --
14622 -------------------------
14624 -- Returns the static accessibility level of the view denoted by Obj. Note
14625 -- that the value returned is the result of a call to Scope_Depth. Only
14626 -- scope depths associated with dynamic scopes can actually be returned.
14627 -- Since only relative levels matter for accessibility checking, the fact
14628 -- that the distance between successive levels of accessibility is not
14629 -- always one is immaterial (invariant: if level(E2) is deeper than
14630 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
14632 function Object_Access_Level (Obj : Node_Id) return Uint is
14633 function Is_Interface_Conversion (N : Node_Id) return Boolean;
14634 -- Determine whether N is a construct of the form
14635 -- Some_Type (Operand._tag'Address)
14636 -- This construct appears in the context of dispatching calls.
14638 function Reference_To (Obj : Node_Id) return Node_Id;
14639 -- An explicit dereference is created when removing side-effects from
14640 -- expressions for constraint checking purposes. In this case a local
14641 -- access type is created for it. The correct access level is that of
14642 -- the original source node. We detect this case by noting that the
14643 -- prefix of the dereference is created by an object declaration whose
14644 -- initial expression is a reference.
14646 -----------------------------
14647 -- Is_Interface_Conversion --
14648 -----------------------------
14650 function Is_Interface_Conversion (N : Node_Id) return Boolean is
14651 begin
14652 return Nkind (N) = N_Unchecked_Type_Conversion
14653 and then Nkind (Expression (N)) = N_Attribute_Reference
14654 and then Attribute_Name (Expression (N)) = Name_Address;
14655 end Is_Interface_Conversion;
14657 ------------------
14658 -- Reference_To --
14659 ------------------
14661 function Reference_To (Obj : Node_Id) return Node_Id is
14662 Pref : constant Node_Id := Prefix (Obj);
14663 begin
14664 if Is_Entity_Name (Pref)
14665 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
14666 and then Present (Expression (Parent (Entity (Pref))))
14667 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
14668 then
14669 return (Prefix (Expression (Parent (Entity (Pref)))));
14670 else
14671 return Empty;
14672 end if;
14673 end Reference_To;
14675 -- Local variables
14677 E : Entity_Id;
14679 -- Start of processing for Object_Access_Level
14681 begin
14682 if Nkind (Obj) = N_Defining_Identifier
14683 or else Is_Entity_Name (Obj)
14684 then
14685 if Nkind (Obj) = N_Defining_Identifier then
14686 E := Obj;
14687 else
14688 E := Entity (Obj);
14689 end if;
14691 if Is_Prival (E) then
14692 E := Prival_Link (E);
14693 end if;
14695 -- If E is a type then it denotes a current instance. For this case
14696 -- we add one to the normal accessibility level of the type to ensure
14697 -- that current instances are treated as always being deeper than
14698 -- than the level of any visible named access type (see 3.10.2(21)).
14700 if Is_Type (E) then
14701 return Type_Access_Level (E) + 1;
14703 elsif Present (Renamed_Object (E)) then
14704 return Object_Access_Level (Renamed_Object (E));
14706 -- Similarly, if E is a component of the current instance of a
14707 -- protected type, any instance of it is assumed to be at a deeper
14708 -- level than the type. For a protected object (whose type is an
14709 -- anonymous protected type) its components are at the same level
14710 -- as the type itself.
14712 elsif not Is_Overloadable (E)
14713 and then Ekind (Scope (E)) = E_Protected_Type
14714 and then Comes_From_Source (Scope (E))
14715 then
14716 return Type_Access_Level (Scope (E)) + 1;
14718 else
14719 -- Aliased formals take their access level from the point of call.
14720 -- This is smaller than the level of the subprogram itself.
14722 if Is_Formal (E) and then Is_Aliased (E) then
14723 return Type_Access_Level (Etype (E));
14725 else
14726 return Scope_Depth (Enclosing_Dynamic_Scope (E));
14727 end if;
14728 end if;
14730 elsif Nkind (Obj) = N_Selected_Component then
14731 if Is_Access_Type (Etype (Prefix (Obj))) then
14732 return Type_Access_Level (Etype (Prefix (Obj)));
14733 else
14734 return Object_Access_Level (Prefix (Obj));
14735 end if;
14737 elsif Nkind (Obj) = N_Indexed_Component then
14738 if Is_Access_Type (Etype (Prefix (Obj))) then
14739 return Type_Access_Level (Etype (Prefix (Obj)));
14740 else
14741 return Object_Access_Level (Prefix (Obj));
14742 end if;
14744 elsif Nkind (Obj) = N_Explicit_Dereference then
14746 -- If the prefix is a selected access discriminant then we make a
14747 -- recursive call on the prefix, which will in turn check the level
14748 -- of the prefix object of the selected discriminant.
14750 if Nkind (Prefix (Obj)) = N_Selected_Component
14751 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
14752 and then
14753 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
14754 then
14755 return Object_Access_Level (Prefix (Obj));
14757 -- Detect an interface conversion in the context of a dispatching
14758 -- call. Use the original form of the conversion to find the access
14759 -- level of the operand.
14761 elsif Is_Interface (Etype (Obj))
14762 and then Is_Interface_Conversion (Prefix (Obj))
14763 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
14764 then
14765 return Object_Access_Level (Original_Node (Obj));
14767 elsif not Comes_From_Source (Obj) then
14768 declare
14769 Ref : constant Node_Id := Reference_To (Obj);
14770 begin
14771 if Present (Ref) then
14772 return Object_Access_Level (Ref);
14773 else
14774 return Type_Access_Level (Etype (Prefix (Obj)));
14775 end if;
14776 end;
14778 else
14779 return Type_Access_Level (Etype (Prefix (Obj)));
14780 end if;
14782 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
14783 return Object_Access_Level (Expression (Obj));
14785 elsif Nkind (Obj) = N_Function_Call then
14787 -- Function results are objects, so we get either the access level of
14788 -- the function or, in the case of an indirect call, the level of the
14789 -- access-to-subprogram type. (This code is used for Ada 95, but it
14790 -- looks wrong, because it seems that we should be checking the level
14791 -- of the call itself, even for Ada 95. However, using the Ada 2005
14792 -- version of the code causes regressions in several tests that are
14793 -- compiled with -gnat95. ???)
14795 if Ada_Version < Ada_2005 then
14796 if Is_Entity_Name (Name (Obj)) then
14797 return Subprogram_Access_Level (Entity (Name (Obj)));
14798 else
14799 return Type_Access_Level (Etype (Prefix (Name (Obj))));
14800 end if;
14802 -- For Ada 2005, the level of the result object of a function call is
14803 -- defined to be the level of the call's innermost enclosing master.
14804 -- We determine that by querying the depth of the innermost enclosing
14805 -- dynamic scope.
14807 else
14808 Return_Master_Scope_Depth_Of_Call : declare
14810 function Innermost_Master_Scope_Depth
14811 (N : Node_Id) return Uint;
14812 -- Returns the scope depth of the given node's innermost
14813 -- enclosing dynamic scope (effectively the accessibility
14814 -- level of the innermost enclosing master).
14816 ----------------------------------
14817 -- Innermost_Master_Scope_Depth --
14818 ----------------------------------
14820 function Innermost_Master_Scope_Depth
14821 (N : Node_Id) return Uint
14823 Node_Par : Node_Id := Parent (N);
14825 begin
14826 -- Locate the nearest enclosing node (by traversing Parents)
14827 -- that Defining_Entity can be applied to, and return the
14828 -- depth of that entity's nearest enclosing dynamic scope.
14830 while Present (Node_Par) loop
14831 case Nkind (Node_Par) is
14832 when N_Component_Declaration |
14833 N_Entry_Declaration |
14834 N_Formal_Object_Declaration |
14835 N_Formal_Type_Declaration |
14836 N_Full_Type_Declaration |
14837 N_Incomplete_Type_Declaration |
14838 N_Loop_Parameter_Specification |
14839 N_Object_Declaration |
14840 N_Protected_Type_Declaration |
14841 N_Private_Extension_Declaration |
14842 N_Private_Type_Declaration |
14843 N_Subtype_Declaration |
14844 N_Function_Specification |
14845 N_Procedure_Specification |
14846 N_Task_Type_Declaration |
14847 N_Body_Stub |
14848 N_Generic_Instantiation |
14849 N_Proper_Body |
14850 N_Implicit_Label_Declaration |
14851 N_Package_Declaration |
14852 N_Single_Task_Declaration |
14853 N_Subprogram_Declaration |
14854 N_Generic_Declaration |
14855 N_Renaming_Declaration |
14856 N_Block_Statement |
14857 N_Formal_Subprogram_Declaration |
14858 N_Abstract_Subprogram_Declaration |
14859 N_Entry_Body |
14860 N_Exception_Declaration |
14861 N_Formal_Package_Declaration |
14862 N_Number_Declaration |
14863 N_Package_Specification |
14864 N_Parameter_Specification |
14865 N_Single_Protected_Declaration |
14866 N_Subunit =>
14868 return Scope_Depth
14869 (Nearest_Dynamic_Scope
14870 (Defining_Entity (Node_Par)));
14872 when others =>
14873 null;
14874 end case;
14876 Node_Par := Parent (Node_Par);
14877 end loop;
14879 pragma Assert (False);
14881 -- Should never reach the following return
14883 return Scope_Depth (Current_Scope) + 1;
14884 end Innermost_Master_Scope_Depth;
14886 -- Start of processing for Return_Master_Scope_Depth_Of_Call
14888 begin
14889 return Innermost_Master_Scope_Depth (Obj);
14890 end Return_Master_Scope_Depth_Of_Call;
14891 end if;
14893 -- For convenience we handle qualified expressions, even though they
14894 -- aren't technically object names.
14896 elsif Nkind (Obj) = N_Qualified_Expression then
14897 return Object_Access_Level (Expression (Obj));
14899 -- Ditto for aggregates. They have the level of the temporary that
14900 -- will hold their value.
14902 elsif Nkind (Obj) = N_Aggregate then
14903 return Object_Access_Level (Current_Scope);
14905 -- Otherwise return the scope level of Standard. (If there are cases
14906 -- that fall through to this point they will be treated as having
14907 -- global accessibility for now. ???)
14909 else
14910 return Scope_Depth (Standard_Standard);
14911 end if;
14912 end Object_Access_Level;
14914 --------------------------
14915 -- Original_Aspect_Name --
14916 --------------------------
14918 function Original_Aspect_Name (N : Node_Id) return Name_Id is
14919 Pras : Node_Id;
14920 Name : Name_Id;
14922 begin
14923 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
14924 Pras := N;
14926 if Is_Rewrite_Substitution (Pras)
14927 and then Nkind (Original_Node (Pras)) = N_Pragma
14928 then
14929 Pras := Original_Node (Pras);
14930 end if;
14932 -- Case where we came from aspect specication
14934 if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
14935 Pras := Corresponding_Aspect (Pras);
14936 end if;
14938 -- Get name from aspect or pragma
14940 if Nkind (Pras) = N_Pragma then
14941 Name := Pragma_Name (Pras);
14942 else
14943 Name := Chars (Identifier (Pras));
14944 end if;
14946 -- Deal with 'Class
14948 if Class_Present (Pras) then
14949 case Name is
14951 -- Names that need converting to special _xxx form
14953 when Name_Pre |
14954 Name_Pre_Class =>
14955 Name := Name_uPre;
14957 when Name_Post |
14958 Name_Post_Class =>
14959 Name := Name_uPost;
14961 when Name_Invariant =>
14962 Name := Name_uInvariant;
14964 when Name_Type_Invariant |
14965 Name_Type_Invariant_Class =>
14966 Name := Name_uType_Invariant;
14968 -- Nothing to do for other cases (e.g. a Check that derived
14969 -- from Pre_Class and has the flag set). Also we do nothing
14970 -- if the name is already in special _xxx form.
14972 when others =>
14973 null;
14974 end case;
14975 end if;
14977 return Name;
14978 end Original_Aspect_Name;
14980 --------------------------------------
14981 -- Original_Corresponding_Operation --
14982 --------------------------------------
14984 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
14986 Typ : constant Entity_Id := Find_Dispatching_Type (S);
14988 begin
14989 -- If S is an inherited primitive S2 the original corresponding
14990 -- operation of S is the original corresponding operation of S2
14992 if Present (Alias (S))
14993 and then Find_Dispatching_Type (Alias (S)) /= Typ
14994 then
14995 return Original_Corresponding_Operation (Alias (S));
14997 -- If S overrides an inherited subprogram S2 the original corresponding
14998 -- operation of S is the original corresponding operation of S2
15000 elsif Present (Overridden_Operation (S)) then
15001 return Original_Corresponding_Operation (Overridden_Operation (S));
15003 -- otherwise it is S itself
15005 else
15006 return S;
15007 end if;
15008 end Original_Corresponding_Operation;
15010 ----------------------------------
15011 -- Predicate_Tests_On_Arguments --
15012 ----------------------------------
15014 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
15015 begin
15016 -- Always test predicates on indirect call
15018 if Ekind (Subp) = E_Subprogram_Type then
15019 return True;
15021 -- Do not test predicates on call to generated default Finalize, since
15022 -- we are not interested in whether something we are finalizing (and
15023 -- typically destroying) satisfies its predicates.
15025 elsif Chars (Subp) = Name_Finalize
15026 and then not Comes_From_Source (Subp)
15027 then
15028 return False;
15030 -- Do not test predicates on any internally generated routines
15032 elsif Is_Internal_Name (Chars (Subp)) then
15033 return False;
15035 -- Do not test predicates on call to Init_Proc, since if needed the
15036 -- predicate test will occur at some other point.
15038 elsif Is_Init_Proc (Subp) then
15039 return False;
15041 -- Do not test predicates on call to predicate function, since this
15042 -- would cause infinite recursion.
15044 elsif Ekind (Subp) = E_Function
15045 and then (Is_Predicate_Function (Subp)
15046 or else
15047 Is_Predicate_Function_M (Subp))
15048 then
15049 return False;
15051 -- For now, no other exceptions
15053 else
15054 return True;
15055 end if;
15056 end Predicate_Tests_On_Arguments;
15058 -----------------------
15059 -- Private_Component --
15060 -----------------------
15062 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
15063 Ancestor : constant Entity_Id := Base_Type (Type_Id);
15065 function Trace_Components
15066 (T : Entity_Id;
15067 Check : Boolean) return Entity_Id;
15068 -- Recursive function that does the work, and checks against circular
15069 -- definition for each subcomponent type.
15071 ----------------------
15072 -- Trace_Components --
15073 ----------------------
15075 function Trace_Components
15076 (T : Entity_Id;
15077 Check : Boolean) return Entity_Id
15079 Btype : constant Entity_Id := Base_Type (T);
15080 Component : Entity_Id;
15081 P : Entity_Id;
15082 Candidate : Entity_Id := Empty;
15084 begin
15085 if Check and then Btype = Ancestor then
15086 Error_Msg_N ("circular type definition", Type_Id);
15087 return Any_Type;
15088 end if;
15090 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
15091 if Present (Full_View (Btype))
15092 and then Is_Record_Type (Full_View (Btype))
15093 and then not Is_Frozen (Btype)
15094 then
15095 -- To indicate that the ancestor depends on a private type, the
15096 -- current Btype is sufficient. However, to check for circular
15097 -- definition we must recurse on the full view.
15099 Candidate := Trace_Components (Full_View (Btype), True);
15101 if Candidate = Any_Type then
15102 return Any_Type;
15103 else
15104 return Btype;
15105 end if;
15107 else
15108 return Btype;
15109 end if;
15111 elsif Is_Array_Type (Btype) then
15112 return Trace_Components (Component_Type (Btype), True);
15114 elsif Is_Record_Type (Btype) then
15115 Component := First_Entity (Btype);
15116 while Present (Component)
15117 and then Comes_From_Source (Component)
15118 loop
15119 -- Skip anonymous types generated by constrained components
15121 if not Is_Type (Component) then
15122 P := Trace_Components (Etype (Component), True);
15124 if Present (P) then
15125 if P = Any_Type then
15126 return P;
15127 else
15128 Candidate := P;
15129 end if;
15130 end if;
15131 end if;
15133 Next_Entity (Component);
15134 end loop;
15136 return Candidate;
15138 else
15139 return Empty;
15140 end if;
15141 end Trace_Components;
15143 -- Start of processing for Private_Component
15145 begin
15146 return Trace_Components (Type_Id, False);
15147 end Private_Component;
15149 ---------------------------
15150 -- Primitive_Names_Match --
15151 ---------------------------
15153 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
15155 function Non_Internal_Name (E : Entity_Id) return Name_Id;
15156 -- Given an internal name, returns the corresponding non-internal name
15158 ------------------------
15159 -- Non_Internal_Name --
15160 ------------------------
15162 function Non_Internal_Name (E : Entity_Id) return Name_Id is
15163 begin
15164 Get_Name_String (Chars (E));
15165 Name_Len := Name_Len - 1;
15166 return Name_Find;
15167 end Non_Internal_Name;
15169 -- Start of processing for Primitive_Names_Match
15171 begin
15172 pragma Assert (Present (E1) and then Present (E2));
15174 return Chars (E1) = Chars (E2)
15175 or else
15176 (not Is_Internal_Name (Chars (E1))
15177 and then Is_Internal_Name (Chars (E2))
15178 and then Non_Internal_Name (E2) = Chars (E1))
15179 or else
15180 (not Is_Internal_Name (Chars (E2))
15181 and then Is_Internal_Name (Chars (E1))
15182 and then Non_Internal_Name (E1) = Chars (E2))
15183 or else
15184 (Is_Predefined_Dispatching_Operation (E1)
15185 and then Is_Predefined_Dispatching_Operation (E2)
15186 and then Same_TSS (E1, E2))
15187 or else
15188 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
15189 end Primitive_Names_Match;
15191 -----------------------
15192 -- Process_End_Label --
15193 -----------------------
15195 procedure Process_End_Label
15196 (N : Node_Id;
15197 Typ : Character;
15198 Ent : Entity_Id)
15200 Loc : Source_Ptr;
15201 Nam : Node_Id;
15202 Scop : Entity_Id;
15204 Label_Ref : Boolean;
15205 -- Set True if reference to end label itself is required
15207 Endl : Node_Id;
15208 -- Gets set to the operator symbol or identifier that references the
15209 -- entity Ent. For the child unit case, this is the identifier from the
15210 -- designator. For other cases, this is simply Endl.
15212 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
15213 -- N is an identifier node that appears as a parent unit reference in
15214 -- the case where Ent is a child unit. This procedure generates an
15215 -- appropriate cross-reference entry. E is the corresponding entity.
15217 -------------------------
15218 -- Generate_Parent_Ref --
15219 -------------------------
15221 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
15222 begin
15223 -- If names do not match, something weird, skip reference
15225 if Chars (E) = Chars (N) then
15227 -- Generate the reference. We do NOT consider this as a reference
15228 -- for unreferenced symbol purposes.
15230 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
15232 if Style_Check then
15233 Style.Check_Identifier (N, E);
15234 end if;
15235 end if;
15236 end Generate_Parent_Ref;
15238 -- Start of processing for Process_End_Label
15240 begin
15241 -- If no node, ignore. This happens in some error situations, and
15242 -- also for some internally generated structures where no end label
15243 -- references are required in any case.
15245 if No (N) then
15246 return;
15247 end if;
15249 -- Nothing to do if no End_Label, happens for internally generated
15250 -- constructs where we don't want an end label reference anyway. Also
15251 -- nothing to do if Endl is a string literal, which means there was
15252 -- some prior error (bad operator symbol)
15254 Endl := End_Label (N);
15256 if No (Endl) or else Nkind (Endl) = N_String_Literal then
15257 return;
15258 end if;
15260 -- Reference node is not in extended main source unit
15262 if not In_Extended_Main_Source_Unit (N) then
15264 -- Generally we do not collect references except for the extended
15265 -- main source unit. The one exception is the 'e' entry for a
15266 -- package spec, where it is useful for a client to have the
15267 -- ending information to define scopes.
15269 if Typ /= 'e' then
15270 return;
15272 else
15273 Label_Ref := False;
15275 -- For this case, we can ignore any parent references, but we
15276 -- need the package name itself for the 'e' entry.
15278 if Nkind (Endl) = N_Designator then
15279 Endl := Identifier (Endl);
15280 end if;
15281 end if;
15283 -- Reference is in extended main source unit
15285 else
15286 Label_Ref := True;
15288 -- For designator, generate references for the parent entries
15290 if Nkind (Endl) = N_Designator then
15292 -- Generate references for the prefix if the END line comes from
15293 -- source (otherwise we do not need these references) We climb the
15294 -- scope stack to find the expected entities.
15296 if Comes_From_Source (Endl) then
15297 Nam := Name (Endl);
15298 Scop := Current_Scope;
15299 while Nkind (Nam) = N_Selected_Component loop
15300 Scop := Scope (Scop);
15301 exit when No (Scop);
15302 Generate_Parent_Ref (Selector_Name (Nam), Scop);
15303 Nam := Prefix (Nam);
15304 end loop;
15306 if Present (Scop) then
15307 Generate_Parent_Ref (Nam, Scope (Scop));
15308 end if;
15309 end if;
15311 Endl := Identifier (Endl);
15312 end if;
15313 end if;
15315 -- If the end label is not for the given entity, then either we have
15316 -- some previous error, or this is a generic instantiation for which
15317 -- we do not need to make a cross-reference in this case anyway. In
15318 -- either case we simply ignore the call.
15320 if Chars (Ent) /= Chars (Endl) then
15321 return;
15322 end if;
15324 -- If label was really there, then generate a normal reference and then
15325 -- adjust the location in the end label to point past the name (which
15326 -- should almost always be the semicolon).
15328 Loc := Sloc (Endl);
15330 if Comes_From_Source (Endl) then
15332 -- If a label reference is required, then do the style check and
15333 -- generate an l-type cross-reference entry for the label
15335 if Label_Ref then
15336 if Style_Check then
15337 Style.Check_Identifier (Endl, Ent);
15338 end if;
15340 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
15341 end if;
15343 -- Set the location to point past the label (normally this will
15344 -- mean the semicolon immediately following the label). This is
15345 -- done for the sake of the 'e' or 't' entry generated below.
15347 Get_Decoded_Name_String (Chars (Endl));
15348 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
15350 else
15351 -- In SPARK mode, no missing label is allowed for packages and
15352 -- subprogram bodies. Detect those cases by testing whether
15353 -- Process_End_Label was called for a body (Typ = 't') or a package.
15355 if Restriction_Check_Required (SPARK_05)
15356 and then (Typ = 't' or else Ekind (Ent) = E_Package)
15357 then
15358 Error_Msg_Node_1 := Endl;
15359 Check_SPARK_05_Restriction
15360 ("`END &` required", Endl, Force => True);
15361 end if;
15362 end if;
15364 -- Now generate the e/t reference
15366 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
15368 -- Restore Sloc, in case modified above, since we have an identifier
15369 -- and the normal Sloc should be left set in the tree.
15371 Set_Sloc (Endl, Loc);
15372 end Process_End_Label;
15374 ----------------
15375 -- Referenced --
15376 ----------------
15378 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
15379 Seen : Boolean := False;
15381 function Is_Reference (N : Node_Id) return Traverse_Result;
15382 -- Determine whether node N denotes a reference to Id. If this is the
15383 -- case, set global flag Seen to True and stop the traversal.
15385 ------------------
15386 -- Is_Reference --
15387 ------------------
15389 function Is_Reference (N : Node_Id) return Traverse_Result is
15390 begin
15391 if Is_Entity_Name (N)
15392 and then Present (Entity (N))
15393 and then Entity (N) = Id
15394 then
15395 Seen := True;
15396 return Abandon;
15397 else
15398 return OK;
15399 end if;
15400 end Is_Reference;
15402 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
15404 -- Start of processing for Referenced
15406 begin
15407 Inspect_Expression (Expr);
15408 return Seen;
15409 end Referenced;
15411 ------------------------------------
15412 -- References_Generic_Formal_Type --
15413 ------------------------------------
15415 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
15417 function Process (N : Node_Id) return Traverse_Result;
15418 -- Process one node in search for generic formal type
15420 -------------
15421 -- Process --
15422 -------------
15424 function Process (N : Node_Id) return Traverse_Result is
15425 begin
15426 if Nkind (N) in N_Has_Entity then
15427 declare
15428 E : constant Entity_Id := Entity (N);
15429 begin
15430 if Present (E) then
15431 if Is_Generic_Type (E) then
15432 return Abandon;
15433 elsif Present (Etype (E))
15434 and then Is_Generic_Type (Etype (E))
15435 then
15436 return Abandon;
15437 end if;
15438 end if;
15439 end;
15440 end if;
15442 return Atree.OK;
15443 end Process;
15445 function Traverse is new Traverse_Func (Process);
15446 -- Traverse tree to look for generic type
15448 begin
15449 if Inside_A_Generic then
15450 return Traverse (N) = Abandon;
15451 else
15452 return False;
15453 end if;
15454 end References_Generic_Formal_Type;
15456 --------------------
15457 -- Remove_Homonym --
15458 --------------------
15460 procedure Remove_Homonym (E : Entity_Id) is
15461 Prev : Entity_Id := Empty;
15462 H : Entity_Id;
15464 begin
15465 if E = Current_Entity (E) then
15466 if Present (Homonym (E)) then
15467 Set_Current_Entity (Homonym (E));
15468 else
15469 Set_Name_Entity_Id (Chars (E), Empty);
15470 end if;
15472 else
15473 H := Current_Entity (E);
15474 while Present (H) and then H /= E loop
15475 Prev := H;
15476 H := Homonym (H);
15477 end loop;
15479 -- If E is not on the homonym chain, nothing to do
15481 if Present (H) then
15482 Set_Homonym (Prev, Homonym (E));
15483 end if;
15484 end if;
15485 end Remove_Homonym;
15487 ---------------------
15488 -- Rep_To_Pos_Flag --
15489 ---------------------
15491 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
15492 begin
15493 return New_Occurrence_Of
15494 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
15495 end Rep_To_Pos_Flag;
15497 --------------------
15498 -- Require_Entity --
15499 --------------------
15501 procedure Require_Entity (N : Node_Id) is
15502 begin
15503 if Is_Entity_Name (N) and then No (Entity (N)) then
15504 if Total_Errors_Detected /= 0 then
15505 Set_Entity (N, Any_Id);
15506 else
15507 raise Program_Error;
15508 end if;
15509 end if;
15510 end Require_Entity;
15512 -------------------------------
15513 -- Requires_State_Refinement --
15514 -------------------------------
15516 function Requires_State_Refinement
15517 (Spec_Id : Entity_Id;
15518 Body_Id : Entity_Id) return Boolean
15520 function Mode_Is_Off (Prag : Node_Id) return Boolean;
15521 -- Given pragma SPARK_Mode, determine whether the mode is Off
15523 -----------------
15524 -- Mode_Is_Off --
15525 -----------------
15527 function Mode_Is_Off (Prag : Node_Id) return Boolean is
15528 Mode : Node_Id;
15530 begin
15531 -- The default SPARK mode is On
15533 if No (Prag) then
15534 return False;
15535 end if;
15537 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
15539 -- Then the pragma lacks an argument, the default mode is On
15541 if No (Mode) then
15542 return False;
15543 else
15544 return Chars (Mode) = Name_Off;
15545 end if;
15546 end Mode_Is_Off;
15548 -- Start of processing for Requires_State_Refinement
15550 begin
15551 -- A package that does not define at least one abstract state cannot
15552 -- possibly require refinement.
15554 if No (Abstract_States (Spec_Id)) then
15555 return False;
15557 -- The package instroduces a single null state which does not merit
15558 -- refinement.
15560 elsif Has_Null_Abstract_State (Spec_Id) then
15561 return False;
15563 -- Check whether the package body is subject to pragma SPARK_Mode. If
15564 -- it is and the mode is Off, the package body is considered to be in
15565 -- regular Ada and does not require refinement.
15567 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
15568 return False;
15570 -- The body's SPARK_Mode may be inherited from a similar pragma that
15571 -- appears in the private declarations of the spec. The pragma we are
15572 -- interested appears as the second entry in SPARK_Pragma.
15574 elsif Present (SPARK_Pragma (Spec_Id))
15575 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
15576 then
15577 return False;
15579 -- The spec defines at least one abstract state and the body has no way
15580 -- of circumventing the refinement.
15582 else
15583 return True;
15584 end if;
15585 end Requires_State_Refinement;
15587 ------------------------------
15588 -- Requires_Transient_Scope --
15589 ------------------------------
15591 -- A transient scope is required when variable-sized temporaries are
15592 -- allocated in the primary or secondary stack, or when finalization
15593 -- actions must be generated before the next instruction.
15595 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
15596 Typ : constant Entity_Id := Underlying_Type (Id);
15598 -- Start of processing for Requires_Transient_Scope
15600 begin
15601 -- This is a private type which is not completed yet. This can only
15602 -- happen in a default expression (of a formal parameter or of a
15603 -- record component). Do not expand transient scope in this case
15605 if No (Typ) then
15606 return False;
15608 -- Do not expand transient scope for non-existent procedure return
15610 elsif Typ = Standard_Void_Type then
15611 return False;
15613 -- Elementary types do not require a transient scope
15615 elsif Is_Elementary_Type (Typ) then
15616 return False;
15618 -- Generally, indefinite subtypes require a transient scope, since the
15619 -- back end cannot generate temporaries, since this is not a valid type
15620 -- for declaring an object. It might be possible to relax this in the
15621 -- future, e.g. by declaring the maximum possible space for the type.
15623 elsif Is_Indefinite_Subtype (Typ) then
15624 return True;
15626 -- Functions returning tagged types may dispatch on result so their
15627 -- returned value is allocated on the secondary stack. Controlled
15628 -- type temporaries need finalization.
15630 elsif Is_Tagged_Type (Typ)
15631 or else Has_Controlled_Component (Typ)
15632 then
15633 return not Is_Value_Type (Typ);
15635 -- Record type
15637 elsif Is_Record_Type (Typ) then
15638 declare
15639 Comp : Entity_Id;
15640 begin
15641 Comp := First_Entity (Typ);
15642 while Present (Comp) loop
15643 if Ekind (Comp) = E_Component
15644 and then Requires_Transient_Scope (Etype (Comp))
15645 then
15646 return True;
15647 else
15648 Next_Entity (Comp);
15649 end if;
15650 end loop;
15651 end;
15653 return False;
15655 -- String literal types never require transient scope
15657 elsif Ekind (Typ) = E_String_Literal_Subtype then
15658 return False;
15660 -- Array type. Note that we already know that this is a constrained
15661 -- array, since unconstrained arrays will fail the indefinite test.
15663 elsif Is_Array_Type (Typ) then
15665 -- If component type requires a transient scope, the array does too
15667 if Requires_Transient_Scope (Component_Type (Typ)) then
15668 return True;
15670 -- Otherwise, we only need a transient scope if the size depends on
15671 -- the value of one or more discriminants.
15673 else
15674 return Size_Depends_On_Discriminant (Typ);
15675 end if;
15677 -- All other cases do not require a transient scope
15679 else
15680 return False;
15681 end if;
15682 end Requires_Transient_Scope;
15684 --------------------------
15685 -- Reset_Analyzed_Flags --
15686 --------------------------
15688 procedure Reset_Analyzed_Flags (N : Node_Id) is
15690 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
15691 -- Function used to reset Analyzed flags in tree. Note that we do
15692 -- not reset Analyzed flags in entities, since there is no need to
15693 -- reanalyze entities, and indeed, it is wrong to do so, since it
15694 -- can result in generating auxiliary stuff more than once.
15696 --------------------
15697 -- Clear_Analyzed --
15698 --------------------
15700 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
15701 begin
15702 if not Has_Extension (N) then
15703 Set_Analyzed (N, False);
15704 end if;
15706 return OK;
15707 end Clear_Analyzed;
15709 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
15711 -- Start of processing for Reset_Analyzed_Flags
15713 begin
15714 Reset_Analyzed (N);
15715 end Reset_Analyzed_Flags;
15717 ------------------------
15718 -- Restore_SPARK_Mode --
15719 ------------------------
15721 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
15722 begin
15723 SPARK_Mode := Mode;
15724 end Restore_SPARK_Mode;
15726 --------------------------------
15727 -- Returns_Unconstrained_Type --
15728 --------------------------------
15730 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
15731 begin
15732 return Ekind (Subp) = E_Function
15733 and then not Is_Scalar_Type (Etype (Subp))
15734 and then not Is_Access_Type (Etype (Subp))
15735 and then not Is_Constrained (Etype (Subp));
15736 end Returns_Unconstrained_Type;
15738 ----------------------------
15739 -- Root_Type_Of_Full_View --
15740 ----------------------------
15742 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
15743 Rtyp : constant Entity_Id := Root_Type (T);
15745 begin
15746 -- The root type of the full view may itself be a private type. Keep
15747 -- looking for the ultimate derivation parent.
15749 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
15750 return Root_Type_Of_Full_View (Full_View (Rtyp));
15751 else
15752 return Rtyp;
15753 end if;
15754 end Root_Type_Of_Full_View;
15756 ---------------------------
15757 -- Safe_To_Capture_Value --
15758 ---------------------------
15760 function Safe_To_Capture_Value
15761 (N : Node_Id;
15762 Ent : Entity_Id;
15763 Cond : Boolean := False) return Boolean
15765 begin
15766 -- The only entities for which we track constant values are variables
15767 -- which are not renamings, constants, out parameters, and in out
15768 -- parameters, so check if we have this case.
15770 -- Note: it may seem odd to track constant values for constants, but in
15771 -- fact this routine is used for other purposes than simply capturing
15772 -- the value. In particular, the setting of Known[_Non]_Null.
15774 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
15775 or else
15776 Ekind (Ent) = E_Constant
15777 or else
15778 Ekind (Ent) = E_Out_Parameter
15779 or else
15780 Ekind (Ent) = E_In_Out_Parameter
15781 then
15782 null;
15784 -- For conditionals, we also allow loop parameters and all formals,
15785 -- including in parameters.
15787 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
15788 null;
15790 -- For all other cases, not just unsafe, but impossible to capture
15791 -- Current_Value, since the above are the only entities which have
15792 -- Current_Value fields.
15794 else
15795 return False;
15796 end if;
15798 -- Skip if volatile or aliased, since funny things might be going on in
15799 -- these cases which we cannot necessarily track. Also skip any variable
15800 -- for which an address clause is given, or whose address is taken. Also
15801 -- never capture value of library level variables (an attempt to do so
15802 -- can occur in the case of package elaboration code).
15804 if Treat_As_Volatile (Ent)
15805 or else Is_Aliased (Ent)
15806 or else Present (Address_Clause (Ent))
15807 or else Address_Taken (Ent)
15808 or else (Is_Library_Level_Entity (Ent)
15809 and then Ekind (Ent) = E_Variable)
15810 then
15811 return False;
15812 end if;
15814 -- OK, all above conditions are met. We also require that the scope of
15815 -- the reference be the same as the scope of the entity, not counting
15816 -- packages and blocks and loops.
15818 declare
15819 E_Scope : constant Entity_Id := Scope (Ent);
15820 R_Scope : Entity_Id;
15822 begin
15823 R_Scope := Current_Scope;
15824 while R_Scope /= Standard_Standard loop
15825 exit when R_Scope = E_Scope;
15827 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
15828 return False;
15829 else
15830 R_Scope := Scope (R_Scope);
15831 end if;
15832 end loop;
15833 end;
15835 -- We also require that the reference does not appear in a context
15836 -- where it is not sure to be executed (i.e. a conditional context
15837 -- or an exception handler). We skip this if Cond is True, since the
15838 -- capturing of values from conditional tests handles this ok.
15840 if Cond then
15841 return True;
15842 end if;
15844 declare
15845 Desc : Node_Id;
15846 P : Node_Id;
15848 begin
15849 Desc := N;
15851 -- Seems dubious that case expressions are not handled here ???
15853 P := Parent (N);
15854 while Present (P) loop
15855 if Nkind (P) = N_If_Statement
15856 or else Nkind (P) = N_Case_Statement
15857 or else (Nkind (P) in N_Short_Circuit
15858 and then Desc = Right_Opnd (P))
15859 or else (Nkind (P) = N_If_Expression
15860 and then Desc /= First (Expressions (P)))
15861 or else Nkind (P) = N_Exception_Handler
15862 or else Nkind (P) = N_Selective_Accept
15863 or else Nkind (P) = N_Conditional_Entry_Call
15864 or else Nkind (P) = N_Timed_Entry_Call
15865 or else Nkind (P) = N_Asynchronous_Select
15866 then
15867 return False;
15869 else
15870 Desc := P;
15871 P := Parent (P);
15873 -- A special Ada 2012 case: the original node may be part
15874 -- of the else_actions of a conditional expression, in which
15875 -- case it might not have been expanded yet, and appears in
15876 -- a non-syntactic list of actions. In that case it is clearly
15877 -- not safe to save a value.
15879 if No (P)
15880 and then Is_List_Member (Desc)
15881 and then No (Parent (List_Containing (Desc)))
15882 then
15883 return False;
15884 end if;
15885 end if;
15886 end loop;
15887 end;
15889 -- OK, looks safe to set value
15891 return True;
15892 end Safe_To_Capture_Value;
15894 ---------------
15895 -- Same_Name --
15896 ---------------
15898 function Same_Name (N1, N2 : Node_Id) return Boolean is
15899 K1 : constant Node_Kind := Nkind (N1);
15900 K2 : constant Node_Kind := Nkind (N2);
15902 begin
15903 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
15904 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
15905 then
15906 return Chars (N1) = Chars (N2);
15908 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
15909 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
15910 then
15911 return Same_Name (Selector_Name (N1), Selector_Name (N2))
15912 and then Same_Name (Prefix (N1), Prefix (N2));
15914 else
15915 return False;
15916 end if;
15917 end Same_Name;
15919 -----------------
15920 -- Same_Object --
15921 -----------------
15923 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
15924 N1 : constant Node_Id := Original_Node (Node1);
15925 N2 : constant Node_Id := Original_Node (Node2);
15926 -- We do the tests on original nodes, since we are most interested
15927 -- in the original source, not any expansion that got in the way.
15929 K1 : constant Node_Kind := Nkind (N1);
15930 K2 : constant Node_Kind := Nkind (N2);
15932 begin
15933 -- First case, both are entities with same entity
15935 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
15936 declare
15937 EN1 : constant Entity_Id := Entity (N1);
15938 EN2 : constant Entity_Id := Entity (N2);
15939 begin
15940 if Present (EN1) and then Present (EN2)
15941 and then (Ekind_In (EN1, E_Variable, E_Constant)
15942 or else Is_Formal (EN1))
15943 and then EN1 = EN2
15944 then
15945 return True;
15946 end if;
15947 end;
15948 end if;
15950 -- Second case, selected component with same selector, same record
15952 if K1 = N_Selected_Component
15953 and then K2 = N_Selected_Component
15954 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
15955 then
15956 return Same_Object (Prefix (N1), Prefix (N2));
15958 -- Third case, indexed component with same subscripts, same array
15960 elsif K1 = N_Indexed_Component
15961 and then K2 = N_Indexed_Component
15962 and then Same_Object (Prefix (N1), Prefix (N2))
15963 then
15964 declare
15965 E1, E2 : Node_Id;
15966 begin
15967 E1 := First (Expressions (N1));
15968 E2 := First (Expressions (N2));
15969 while Present (E1) loop
15970 if not Same_Value (E1, E2) then
15971 return False;
15972 else
15973 Next (E1);
15974 Next (E2);
15975 end if;
15976 end loop;
15978 return True;
15979 end;
15981 -- Fourth case, slice of same array with same bounds
15983 elsif K1 = N_Slice
15984 and then K2 = N_Slice
15985 and then Nkind (Discrete_Range (N1)) = N_Range
15986 and then Nkind (Discrete_Range (N2)) = N_Range
15987 and then Same_Value (Low_Bound (Discrete_Range (N1)),
15988 Low_Bound (Discrete_Range (N2)))
15989 and then Same_Value (High_Bound (Discrete_Range (N1)),
15990 High_Bound (Discrete_Range (N2)))
15991 then
15992 return Same_Name (Prefix (N1), Prefix (N2));
15994 -- All other cases, not clearly the same object
15996 else
15997 return False;
15998 end if;
15999 end Same_Object;
16001 ---------------
16002 -- Same_Type --
16003 ---------------
16005 function Same_Type (T1, T2 : Entity_Id) return Boolean is
16006 begin
16007 if T1 = T2 then
16008 return True;
16010 elsif not Is_Constrained (T1)
16011 and then not Is_Constrained (T2)
16012 and then Base_Type (T1) = Base_Type (T2)
16013 then
16014 return True;
16016 -- For now don't bother with case of identical constraints, to be
16017 -- fiddled with later on perhaps (this is only used for optimization
16018 -- purposes, so it is not critical to do a best possible job)
16020 else
16021 return False;
16022 end if;
16023 end Same_Type;
16025 ----------------
16026 -- Same_Value --
16027 ----------------
16029 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
16030 begin
16031 if Compile_Time_Known_Value (Node1)
16032 and then Compile_Time_Known_Value (Node2)
16033 and then Expr_Value (Node1) = Expr_Value (Node2)
16034 then
16035 return True;
16036 elsif Same_Object (Node1, Node2) then
16037 return True;
16038 else
16039 return False;
16040 end if;
16041 end Same_Value;
16043 -----------------------------
16044 -- Save_SPARK_Mode_And_Set --
16045 -----------------------------
16047 procedure Save_SPARK_Mode_And_Set
16048 (Context : Entity_Id;
16049 Mode : out SPARK_Mode_Type)
16051 begin
16052 -- Save the current mode in effect
16054 Mode := SPARK_Mode;
16056 -- Do not consider illegal or partially decorated constructs
16058 if Ekind (Context) = E_Void or else Error_Posted (Context) then
16059 null;
16061 elsif Present (SPARK_Pragma (Context)) then
16062 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
16063 end if;
16064 end Save_SPARK_Mode_And_Set;
16066 -------------------------
16067 -- Scalar_Part_Present --
16068 -------------------------
16070 function Scalar_Part_Present (T : Entity_Id) return Boolean is
16071 C : Entity_Id;
16073 begin
16074 if Is_Scalar_Type (T) then
16075 return True;
16077 elsif Is_Array_Type (T) then
16078 return Scalar_Part_Present (Component_Type (T));
16080 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
16081 C := First_Component_Or_Discriminant (T);
16082 while Present (C) loop
16083 if Scalar_Part_Present (Etype (C)) then
16084 return True;
16085 else
16086 Next_Component_Or_Discriminant (C);
16087 end if;
16088 end loop;
16089 end if;
16091 return False;
16092 end Scalar_Part_Present;
16094 ------------------------
16095 -- Scope_Is_Transient --
16096 ------------------------
16098 function Scope_Is_Transient return Boolean is
16099 begin
16100 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
16101 end Scope_Is_Transient;
16103 ------------------
16104 -- Scope_Within --
16105 ------------------
16107 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
16108 Scop : Entity_Id;
16110 begin
16111 Scop := Scope1;
16112 while Scop /= Standard_Standard loop
16113 Scop := Scope (Scop);
16115 if Scop = Scope2 then
16116 return True;
16117 end if;
16118 end loop;
16120 return False;
16121 end Scope_Within;
16123 --------------------------
16124 -- Scope_Within_Or_Same --
16125 --------------------------
16127 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
16128 Scop : Entity_Id;
16130 begin
16131 Scop := Scope1;
16132 while Scop /= Standard_Standard loop
16133 if Scop = Scope2 then
16134 return True;
16135 else
16136 Scop := Scope (Scop);
16137 end if;
16138 end loop;
16140 return False;
16141 end Scope_Within_Or_Same;
16143 --------------------
16144 -- Set_Convention --
16145 --------------------
16147 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
16148 begin
16149 Basic_Set_Convention (E, Val);
16151 if Is_Type (E)
16152 and then Is_Access_Subprogram_Type (Base_Type (E))
16153 and then Has_Foreign_Convention (E)
16154 then
16155 Set_Can_Use_Internal_Rep (E, False);
16156 end if;
16158 -- If E is an object or component, and the type of E is an anonymous
16159 -- access type with no convention set, then also set the convention of
16160 -- the anonymous access type. We do not do this for anonymous protected
16161 -- types, since protected types always have the default convention.
16163 if Present (Etype (E))
16164 and then (Is_Object (E)
16165 or else Ekind (E) = E_Component
16167 -- Allow E_Void (happens for pragma Convention appearing
16168 -- in the middle of a record applying to a component)
16170 or else Ekind (E) = E_Void)
16171 then
16172 declare
16173 Typ : constant Entity_Id := Etype (E);
16175 begin
16176 if Ekind_In (Typ, E_Anonymous_Access_Type,
16177 E_Anonymous_Access_Subprogram_Type)
16178 and then not Has_Convention_Pragma (Typ)
16179 then
16180 Basic_Set_Convention (Typ, Val);
16181 Set_Has_Convention_Pragma (Typ);
16183 -- And for the access subprogram type, deal similarly with the
16184 -- designated E_Subprogram_Type if it is also internal (which
16185 -- it always is?)
16187 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
16188 declare
16189 Dtype : constant Entity_Id := Designated_Type (Typ);
16190 begin
16191 if Ekind (Dtype) = E_Subprogram_Type
16192 and then Is_Itype (Dtype)
16193 and then not Has_Convention_Pragma (Dtype)
16194 then
16195 Basic_Set_Convention (Dtype, Val);
16196 Set_Has_Convention_Pragma (Dtype);
16197 end if;
16198 end;
16199 end if;
16200 end if;
16201 end;
16202 end if;
16203 end Set_Convention;
16205 ------------------------
16206 -- Set_Current_Entity --
16207 ------------------------
16209 -- The given entity is to be set as the currently visible definition of its
16210 -- associated name (i.e. the Node_Id associated with its name). All we have
16211 -- to do is to get the name from the identifier, and then set the
16212 -- associated Node_Id to point to the given entity.
16214 procedure Set_Current_Entity (E : Entity_Id) is
16215 begin
16216 Set_Name_Entity_Id (Chars (E), E);
16217 end Set_Current_Entity;
16219 ---------------------------
16220 -- Set_Debug_Info_Needed --
16221 ---------------------------
16223 procedure Set_Debug_Info_Needed (T : Entity_Id) is
16225 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
16226 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
16227 -- Used to set debug info in a related node if not set already
16229 --------------------------------------
16230 -- Set_Debug_Info_Needed_If_Not_Set --
16231 --------------------------------------
16233 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
16234 begin
16235 if Present (E) and then not Needs_Debug_Info (E) then
16236 Set_Debug_Info_Needed (E);
16238 -- For a private type, indicate that the full view also needs
16239 -- debug information.
16241 if Is_Type (E)
16242 and then Is_Private_Type (E)
16243 and then Present (Full_View (E))
16244 then
16245 Set_Debug_Info_Needed (Full_View (E));
16246 end if;
16247 end if;
16248 end Set_Debug_Info_Needed_If_Not_Set;
16250 -- Start of processing for Set_Debug_Info_Needed
16252 begin
16253 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16254 -- indicates that Debug_Info_Needed is never required for the entity.
16256 if No (T)
16257 or else Debug_Info_Off (T)
16258 then
16259 return;
16260 end if;
16262 -- Set flag in entity itself. Note that we will go through the following
16263 -- circuitry even if the flag is already set on T. That's intentional,
16264 -- it makes sure that the flag will be set in subsidiary entities.
16266 Set_Needs_Debug_Info (T);
16268 -- Set flag on subsidiary entities if not set already
16270 if Is_Object (T) then
16271 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
16273 elsif Is_Type (T) then
16274 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
16276 if Is_Record_Type (T) then
16277 declare
16278 Ent : Entity_Id := First_Entity (T);
16279 begin
16280 while Present (Ent) loop
16281 Set_Debug_Info_Needed_If_Not_Set (Ent);
16282 Next_Entity (Ent);
16283 end loop;
16284 end;
16286 -- For a class wide subtype, we also need debug information
16287 -- for the equivalent type.
16289 if Ekind (T) = E_Class_Wide_Subtype then
16290 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
16291 end if;
16293 elsif Is_Array_Type (T) then
16294 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
16296 declare
16297 Indx : Node_Id := First_Index (T);
16298 begin
16299 while Present (Indx) loop
16300 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
16301 Indx := Next_Index (Indx);
16302 end loop;
16303 end;
16305 -- For a packed array type, we also need debug information for
16306 -- the type used to represent the packed array. Conversely, we
16307 -- also need it for the former if we need it for the latter.
16309 if Is_Packed (T) then
16310 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
16311 end if;
16313 if Is_Packed_Array_Impl_Type (T) then
16314 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
16315 end if;
16317 elsif Is_Access_Type (T) then
16318 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
16320 elsif Is_Private_Type (T) then
16321 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
16323 elsif Is_Protected_Type (T) then
16324 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
16326 elsif Is_Scalar_Type (T) then
16328 -- If the subrange bounds are materialized by dedicated constant
16329 -- objects, also include them in the debug info to make sure the
16330 -- debugger can properly use them.
16332 if Present (Scalar_Range (T))
16333 and then Nkind (Scalar_Range (T)) = N_Range
16334 then
16335 declare
16336 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
16337 High_Bnd : constant Node_Id := Type_High_Bound (T);
16339 begin
16340 if Is_Entity_Name (Low_Bnd) then
16341 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
16342 end if;
16344 if Is_Entity_Name (High_Bnd) then
16345 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
16346 end if;
16347 end;
16348 end if;
16349 end if;
16350 end if;
16351 end Set_Debug_Info_Needed;
16353 ----------------------------
16354 -- Set_Entity_With_Checks --
16355 ----------------------------
16357 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
16358 Val_Actual : Entity_Id;
16359 Nod : Node_Id;
16360 Post_Node : Node_Id;
16362 begin
16363 -- Unconditionally set the entity
16365 Set_Entity (N, Val);
16367 -- The node to post on is the selector in the case of an expanded name,
16368 -- and otherwise the node itself.
16370 if Nkind (N) = N_Expanded_Name then
16371 Post_Node := Selector_Name (N);
16372 else
16373 Post_Node := N;
16374 end if;
16376 -- Check for violation of No_Fixed_IO
16378 if Restriction_Check_Required (No_Fixed_IO)
16379 and then
16380 ((RTU_Loaded (Ada_Text_IO)
16381 and then (Is_RTE (Val, RE_Decimal_IO)
16382 or else
16383 Is_RTE (Val, RE_Fixed_IO)))
16385 or else
16386 (RTU_Loaded (Ada_Wide_Text_IO)
16387 and then (Is_RTE (Val, RO_WT_Decimal_IO)
16388 or else
16389 Is_RTE (Val, RO_WT_Fixed_IO)))
16391 or else
16392 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
16393 and then (Is_RTE (Val, RO_WW_Decimal_IO)
16394 or else
16395 Is_RTE (Val, RO_WW_Fixed_IO))))
16397 -- A special extra check, don't complain about a reference from within
16398 -- the Ada.Interrupts package itself!
16400 and then not In_Same_Extended_Unit (N, Val)
16401 then
16402 Check_Restriction (No_Fixed_IO, Post_Node);
16403 end if;
16405 -- Remaining checks are only done on source nodes. Note that we test
16406 -- for violation of No_Fixed_IO even on non-source nodes, because the
16407 -- cases for checking violations of this restriction are instantiations
16408 -- where the reference in the instance has Comes_From_Source False.
16410 if not Comes_From_Source (N) then
16411 return;
16412 end if;
16414 -- Check for violation of No_Abort_Statements, which is triggered by
16415 -- call to Ada.Task_Identification.Abort_Task.
16417 if Restriction_Check_Required (No_Abort_Statements)
16418 and then (Is_RTE (Val, RE_Abort_Task))
16420 -- A special extra check, don't complain about a reference from within
16421 -- the Ada.Task_Identification package itself!
16423 and then not In_Same_Extended_Unit (N, Val)
16424 then
16425 Check_Restriction (No_Abort_Statements, Post_Node);
16426 end if;
16428 if Val = Standard_Long_Long_Integer then
16429 Check_Restriction (No_Long_Long_Integers, Post_Node);
16430 end if;
16432 -- Check for violation of No_Dynamic_Attachment
16434 if Restriction_Check_Required (No_Dynamic_Attachment)
16435 and then RTU_Loaded (Ada_Interrupts)
16436 and then (Is_RTE (Val, RE_Is_Reserved) or else
16437 Is_RTE (Val, RE_Is_Attached) or else
16438 Is_RTE (Val, RE_Current_Handler) or else
16439 Is_RTE (Val, RE_Attach_Handler) or else
16440 Is_RTE (Val, RE_Exchange_Handler) or else
16441 Is_RTE (Val, RE_Detach_Handler) or else
16442 Is_RTE (Val, RE_Reference))
16444 -- A special extra check, don't complain about a reference from within
16445 -- the Ada.Interrupts package itself!
16447 and then not In_Same_Extended_Unit (N, Val)
16448 then
16449 Check_Restriction (No_Dynamic_Attachment, Post_Node);
16450 end if;
16452 -- Check for No_Implementation_Identifiers
16454 if Restriction_Check_Required (No_Implementation_Identifiers) then
16456 -- We have an implementation defined entity if it is marked as
16457 -- implementation defined, or is defined in a package marked as
16458 -- implementation defined. However, library packages themselves
16459 -- are excluded (we don't want to flag Interfaces itself, just
16460 -- the entities within it).
16462 if (Is_Implementation_Defined (Val)
16463 or else
16464 Is_Implementation_Defined (Scope (Val)))
16465 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
16466 and then Is_Library_Level_Entity (Val))
16467 then
16468 Check_Restriction (No_Implementation_Identifiers, Post_Node);
16469 end if;
16470 end if;
16472 -- Do the style check
16474 if Style_Check
16475 and then not Suppress_Style_Checks (Val)
16476 and then not In_Instance
16477 then
16478 if Nkind (N) = N_Identifier then
16479 Nod := N;
16480 elsif Nkind (N) = N_Expanded_Name then
16481 Nod := Selector_Name (N);
16482 else
16483 return;
16484 end if;
16486 -- A special situation arises for derived operations, where we want
16487 -- to do the check against the parent (since the Sloc of the derived
16488 -- operation points to the derived type declaration itself).
16490 Val_Actual := Val;
16491 while not Comes_From_Source (Val_Actual)
16492 and then Nkind (Val_Actual) in N_Entity
16493 and then (Ekind (Val_Actual) = E_Enumeration_Literal
16494 or else Is_Subprogram (Val_Actual)
16495 or else Is_Generic_Subprogram (Val_Actual))
16496 and then Present (Alias (Val_Actual))
16497 loop
16498 Val_Actual := Alias (Val_Actual);
16499 end loop;
16501 -- Renaming declarations for generic actuals do not come from source,
16502 -- and have a different name from that of the entity they rename, so
16503 -- there is no style check to perform here.
16505 if Chars (Nod) = Chars (Val_Actual) then
16506 Style.Check_Identifier (Nod, Val_Actual);
16507 end if;
16508 end if;
16510 Set_Entity (N, Val);
16511 end Set_Entity_With_Checks;
16513 ------------------------
16514 -- Set_Name_Entity_Id --
16515 ------------------------
16517 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
16518 begin
16519 Set_Name_Table_Info (Id, Int (Val));
16520 end Set_Name_Entity_Id;
16522 ---------------------
16523 -- Set_Next_Actual --
16524 ---------------------
16526 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
16527 begin
16528 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
16529 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
16530 end if;
16531 end Set_Next_Actual;
16533 ----------------------------------
16534 -- Set_Optimize_Alignment_Flags --
16535 ----------------------------------
16537 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
16538 begin
16539 if Optimize_Alignment = 'S' then
16540 Set_Optimize_Alignment_Space (E);
16541 elsif Optimize_Alignment = 'T' then
16542 Set_Optimize_Alignment_Time (E);
16543 end if;
16544 end Set_Optimize_Alignment_Flags;
16546 -----------------------
16547 -- Set_Public_Status --
16548 -----------------------
16550 procedure Set_Public_Status (Id : Entity_Id) is
16551 S : constant Entity_Id := Current_Scope;
16553 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
16554 -- Determines if E is defined within handled statement sequence or
16555 -- an if statement, returns True if so, False otherwise.
16557 ----------------------
16558 -- Within_HSS_Or_If --
16559 ----------------------
16561 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
16562 N : Node_Id;
16563 begin
16564 N := Declaration_Node (E);
16565 loop
16566 N := Parent (N);
16568 if No (N) then
16569 return False;
16571 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
16572 N_If_Statement)
16573 then
16574 return True;
16575 end if;
16576 end loop;
16577 end Within_HSS_Or_If;
16579 -- Start of processing for Set_Public_Status
16581 begin
16582 -- Everything in the scope of Standard is public
16584 if S = Standard_Standard then
16585 Set_Is_Public (Id);
16587 -- Entity is definitely not public if enclosing scope is not public
16589 elsif not Is_Public (S) then
16590 return;
16592 -- An object or function declaration that occurs in a handled sequence
16593 -- of statements or within an if statement is the declaration for a
16594 -- temporary object or local subprogram generated by the expander. It
16595 -- never needs to be made public and furthermore, making it public can
16596 -- cause back end problems.
16598 elsif Nkind_In (Parent (Id), N_Object_Declaration,
16599 N_Function_Specification)
16600 and then Within_HSS_Or_If (Id)
16601 then
16602 return;
16604 -- Entities in public packages or records are public
16606 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
16607 Set_Is_Public (Id);
16609 -- The bounds of an entry family declaration can generate object
16610 -- declarations that are visible to the back-end, e.g. in the
16611 -- the declaration of a composite type that contains tasks.
16613 elsif Is_Concurrent_Type (S)
16614 and then not Has_Completion (S)
16615 and then Nkind (Parent (Id)) = N_Object_Declaration
16616 then
16617 Set_Is_Public (Id);
16618 end if;
16619 end Set_Public_Status;
16621 -----------------------------
16622 -- Set_Referenced_Modified --
16623 -----------------------------
16625 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
16626 Pref : Node_Id;
16628 begin
16629 -- Deal with indexed or selected component where prefix is modified
16631 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
16632 Pref := Prefix (N);
16634 -- If prefix is access type, then it is the designated object that is
16635 -- being modified, which means we have no entity to set the flag on.
16637 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
16638 return;
16640 -- Otherwise chase the prefix
16642 else
16643 Set_Referenced_Modified (Pref, Out_Param);
16644 end if;
16646 -- Otherwise see if we have an entity name (only other case to process)
16648 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16649 Set_Referenced_As_LHS (Entity (N), not Out_Param);
16650 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
16651 end if;
16652 end Set_Referenced_Modified;
16654 ----------------------------
16655 -- Set_Scope_Is_Transient --
16656 ----------------------------
16658 procedure Set_Scope_Is_Transient (V : Boolean := True) is
16659 begin
16660 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
16661 end Set_Scope_Is_Transient;
16663 -------------------
16664 -- Set_Size_Info --
16665 -------------------
16667 procedure Set_Size_Info (T1, T2 : Entity_Id) is
16668 begin
16669 -- We copy Esize, but not RM_Size, since in general RM_Size is
16670 -- subtype specific and does not get inherited by all subtypes.
16672 Set_Esize (T1, Esize (T2));
16673 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
16675 if Is_Discrete_Or_Fixed_Point_Type (T1)
16676 and then
16677 Is_Discrete_Or_Fixed_Point_Type (T2)
16678 then
16679 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
16680 end if;
16682 Set_Alignment (T1, Alignment (T2));
16683 end Set_Size_Info;
16685 --------------------
16686 -- Static_Boolean --
16687 --------------------
16689 function Static_Boolean (N : Node_Id) return Uint is
16690 begin
16691 Analyze_And_Resolve (N, Standard_Boolean);
16693 if N = Error
16694 or else Error_Posted (N)
16695 or else Etype (N) = Any_Type
16696 then
16697 return No_Uint;
16698 end if;
16700 if Is_OK_Static_Expression (N) then
16701 if not Raises_Constraint_Error (N) then
16702 return Expr_Value (N);
16703 else
16704 return No_Uint;
16705 end if;
16707 elsif Etype (N) = Any_Type then
16708 return No_Uint;
16710 else
16711 Flag_Non_Static_Expr
16712 ("static boolean expression required here", N);
16713 return No_Uint;
16714 end if;
16715 end Static_Boolean;
16717 --------------------
16718 -- Static_Integer --
16719 --------------------
16721 function Static_Integer (N : Node_Id) return Uint is
16722 begin
16723 Analyze_And_Resolve (N, Any_Integer);
16725 if N = Error
16726 or else Error_Posted (N)
16727 or else Etype (N) = Any_Type
16728 then
16729 return No_Uint;
16730 end if;
16732 if Is_OK_Static_Expression (N) then
16733 if not Raises_Constraint_Error (N) then
16734 return Expr_Value (N);
16735 else
16736 return No_Uint;
16737 end if;
16739 elsif Etype (N) = Any_Type then
16740 return No_Uint;
16742 else
16743 Flag_Non_Static_Expr
16744 ("static integer expression required here", N);
16745 return No_Uint;
16746 end if;
16747 end Static_Integer;
16749 --------------------------
16750 -- Statically_Different --
16751 --------------------------
16753 function Statically_Different (E1, E2 : Node_Id) return Boolean is
16754 R1 : constant Node_Id := Get_Referenced_Object (E1);
16755 R2 : constant Node_Id := Get_Referenced_Object (E2);
16756 begin
16757 return Is_Entity_Name (R1)
16758 and then Is_Entity_Name (R2)
16759 and then Entity (R1) /= Entity (R2)
16760 and then not Is_Formal (Entity (R1))
16761 and then not Is_Formal (Entity (R2));
16762 end Statically_Different;
16764 --------------------------------------
16765 -- Subject_To_Loop_Entry_Attributes --
16766 --------------------------------------
16768 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
16769 Stmt : Node_Id;
16771 begin
16772 Stmt := N;
16774 -- The expansion mechanism transform a loop subject to at least one
16775 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
16776 -- the conditional part.
16778 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
16779 and then Nkind (Original_Node (N)) = N_Loop_Statement
16780 then
16781 Stmt := Original_Node (N);
16782 end if;
16784 return
16785 Nkind (Stmt) = N_Loop_Statement
16786 and then Present (Identifier (Stmt))
16787 and then Present (Entity (Identifier (Stmt)))
16788 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
16789 end Subject_To_Loop_Entry_Attributes;
16791 -----------------------------
16792 -- Subprogram_Access_Level --
16793 -----------------------------
16795 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
16796 begin
16797 if Present (Alias (Subp)) then
16798 return Subprogram_Access_Level (Alias (Subp));
16799 else
16800 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
16801 end if;
16802 end Subprogram_Access_Level;
16804 -------------------------------
16805 -- Support_Atomic_Primitives --
16806 -------------------------------
16808 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
16809 Size : Int;
16811 begin
16812 -- Verify the alignment of Typ is known
16814 if not Known_Alignment (Typ) then
16815 return False;
16816 end if;
16818 if Known_Static_Esize (Typ) then
16819 Size := UI_To_Int (Esize (Typ));
16821 -- If the Esize (Object_Size) is unknown at compile time, look at the
16822 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
16824 elsif Known_Static_RM_Size (Typ) then
16825 Size := UI_To_Int (RM_Size (Typ));
16827 -- Otherwise, the size is considered to be unknown.
16829 else
16830 return False;
16831 end if;
16833 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
16834 -- Typ is properly aligned.
16836 case Size is
16837 when 8 | 16 | 32 | 64 =>
16838 return Size = UI_To_Int (Alignment (Typ)) * 8;
16839 when others =>
16840 return False;
16841 end case;
16842 end Support_Atomic_Primitives;
16844 -----------------
16845 -- Trace_Scope --
16846 -----------------
16848 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
16849 begin
16850 if Debug_Flag_W then
16851 for J in 0 .. Scope_Stack.Last loop
16852 Write_Str (" ");
16853 end loop;
16855 Write_Str (Msg);
16856 Write_Name (Chars (E));
16857 Write_Str (" from ");
16858 Write_Location (Sloc (N));
16859 Write_Eol;
16860 end if;
16861 end Trace_Scope;
16863 -----------------------
16864 -- Transfer_Entities --
16865 -----------------------
16867 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
16868 Ent : Entity_Id := First_Entity (From);
16870 begin
16871 if No (Ent) then
16872 return;
16873 end if;
16875 if (Last_Entity (To)) = Empty then
16876 Set_First_Entity (To, Ent);
16877 else
16878 Set_Next_Entity (Last_Entity (To), Ent);
16879 end if;
16881 Set_Last_Entity (To, Last_Entity (From));
16883 while Present (Ent) loop
16884 Set_Scope (Ent, To);
16886 if not Is_Public (Ent) then
16887 Set_Public_Status (Ent);
16889 if Is_Public (Ent) and then Ekind (Ent) = E_Record_Subtype then
16891 -- The components of the propagated Itype must also be public
16893 declare
16894 Comp : Entity_Id;
16895 begin
16896 Comp := First_Entity (Ent);
16897 while Present (Comp) loop
16898 Set_Is_Public (Comp);
16899 Next_Entity (Comp);
16900 end loop;
16901 end;
16902 end if;
16903 end if;
16905 Next_Entity (Ent);
16906 end loop;
16908 Set_First_Entity (From, Empty);
16909 Set_Last_Entity (From, Empty);
16910 end Transfer_Entities;
16912 -----------------------
16913 -- Type_Access_Level --
16914 -----------------------
16916 function Type_Access_Level (Typ : Entity_Id) return Uint is
16917 Btyp : Entity_Id;
16919 begin
16920 Btyp := Base_Type (Typ);
16922 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
16923 -- simply use the level where the type is declared. This is true for
16924 -- stand-alone object declarations, and for anonymous access types
16925 -- associated with components the level is the same as that of the
16926 -- enclosing composite type. However, special treatment is needed for
16927 -- the cases of access parameters, return objects of an anonymous access
16928 -- type, and, in Ada 95, access discriminants of limited types.
16930 if Is_Access_Type (Btyp) then
16931 if Ekind (Btyp) = E_Anonymous_Access_Type then
16933 -- If the type is a nonlocal anonymous access type (such as for
16934 -- an access parameter) we treat it as being declared at the
16935 -- library level to ensure that names such as X.all'access don't
16936 -- fail static accessibility checks.
16938 if not Is_Local_Anonymous_Access (Typ) then
16939 return Scope_Depth (Standard_Standard);
16941 -- If this is a return object, the accessibility level is that of
16942 -- the result subtype of the enclosing function. The test here is
16943 -- little complicated, because we have to account for extended
16944 -- return statements that have been rewritten as blocks, in which
16945 -- case we have to find and the Is_Return_Object attribute of the
16946 -- itype's associated object. It would be nice to find a way to
16947 -- simplify this test, but it doesn't seem worthwhile to add a new
16948 -- flag just for purposes of this test. ???
16950 elsif Ekind (Scope (Btyp)) = E_Return_Statement
16951 or else
16952 (Is_Itype (Btyp)
16953 and then Nkind (Associated_Node_For_Itype (Btyp)) =
16954 N_Object_Declaration
16955 and then Is_Return_Object
16956 (Defining_Identifier
16957 (Associated_Node_For_Itype (Btyp))))
16958 then
16959 declare
16960 Scop : Entity_Id;
16962 begin
16963 Scop := Scope (Scope (Btyp));
16964 while Present (Scop) loop
16965 exit when Ekind (Scop) = E_Function;
16966 Scop := Scope (Scop);
16967 end loop;
16969 -- Treat the return object's type as having the level of the
16970 -- function's result subtype (as per RM05-6.5(5.3/2)).
16972 return Type_Access_Level (Etype (Scop));
16973 end;
16974 end if;
16975 end if;
16977 Btyp := Root_Type (Btyp);
16979 -- The accessibility level of anonymous access types associated with
16980 -- discriminants is that of the current instance of the type, and
16981 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
16983 -- AI-402: access discriminants have accessibility based on the
16984 -- object rather than the type in Ada 2005, so the above paragraph
16985 -- doesn't apply.
16987 -- ??? Needs completion with rules from AI-416
16989 if Ada_Version <= Ada_95
16990 and then Ekind (Typ) = E_Anonymous_Access_Type
16991 and then Present (Associated_Node_For_Itype (Typ))
16992 and then Nkind (Associated_Node_For_Itype (Typ)) =
16993 N_Discriminant_Specification
16994 then
16995 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
16996 end if;
16997 end if;
16999 -- Return library level for a generic formal type. This is done because
17000 -- RM(10.3.2) says that "The statically deeper relationship does not
17001 -- apply to ... a descendant of a generic formal type". Rather than
17002 -- checking at each point where a static accessibility check is
17003 -- performed to see if we are dealing with a formal type, this rule is
17004 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
17005 -- return extreme values for a formal type; Deepest_Type_Access_Level
17006 -- returns Int'Last. By calling the appropriate function from among the
17007 -- two, we ensure that the static accessibility check will pass if we
17008 -- happen to run into a formal type. More specifically, we should call
17009 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
17010 -- call occurs as part of a static accessibility check and the error
17011 -- case is the case where the type's level is too shallow (as opposed
17012 -- to too deep).
17014 if Is_Generic_Type (Root_Type (Btyp)) then
17015 return Scope_Depth (Standard_Standard);
17016 end if;
17018 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
17019 end Type_Access_Level;
17021 ------------------------------------
17022 -- Type_Without_Stream_Operation --
17023 ------------------------------------
17025 function Type_Without_Stream_Operation
17026 (T : Entity_Id;
17027 Op : TSS_Name_Type := TSS_Null) return Entity_Id
17029 BT : constant Entity_Id := Base_Type (T);
17030 Op_Missing : Boolean;
17032 begin
17033 if not Restriction_Active (No_Default_Stream_Attributes) then
17034 return Empty;
17035 end if;
17037 if Is_Elementary_Type (T) then
17038 if Op = TSS_Null then
17039 Op_Missing :=
17040 No (TSS (BT, TSS_Stream_Read))
17041 or else No (TSS (BT, TSS_Stream_Write));
17043 else
17044 Op_Missing := No (TSS (BT, Op));
17045 end if;
17047 if Op_Missing then
17048 return T;
17049 else
17050 return Empty;
17051 end if;
17053 elsif Is_Array_Type (T) then
17054 return Type_Without_Stream_Operation (Component_Type (T), Op);
17056 elsif Is_Record_Type (T) then
17057 declare
17058 Comp : Entity_Id;
17059 C_Typ : Entity_Id;
17061 begin
17062 Comp := First_Component (T);
17063 while Present (Comp) loop
17064 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
17066 if Present (C_Typ) then
17067 return C_Typ;
17068 end if;
17070 Next_Component (Comp);
17071 end loop;
17073 return Empty;
17074 end;
17076 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
17077 return Type_Without_Stream_Operation (Full_View (T), Op);
17078 else
17079 return Empty;
17080 end if;
17081 end Type_Without_Stream_Operation;
17083 ----------------------------
17084 -- Unique_Defining_Entity --
17085 ----------------------------
17087 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
17088 begin
17089 return Unique_Entity (Defining_Entity (N));
17090 end Unique_Defining_Entity;
17092 -------------------
17093 -- Unique_Entity --
17094 -------------------
17096 function Unique_Entity (E : Entity_Id) return Entity_Id is
17097 U : Entity_Id := E;
17098 P : Node_Id;
17100 begin
17101 case Ekind (E) is
17102 when E_Constant =>
17103 if Present (Full_View (E)) then
17104 U := Full_View (E);
17105 end if;
17107 when Type_Kind =>
17108 if Present (Full_View (E)) then
17109 U := Full_View (E);
17110 end if;
17112 when E_Package_Body =>
17113 P := Parent (E);
17115 if Nkind (P) = N_Defining_Program_Unit_Name then
17116 P := Parent (P);
17117 end if;
17119 U := Corresponding_Spec (P);
17121 when E_Subprogram_Body =>
17122 P := Parent (E);
17124 if Nkind (P) = N_Defining_Program_Unit_Name then
17125 P := Parent (P);
17126 end if;
17128 P := Parent (P);
17130 if Nkind (P) = N_Subprogram_Body_Stub then
17131 if Present (Library_Unit (P)) then
17133 -- Get to the function or procedure (generic) entity through
17134 -- the body entity.
17136 U :=
17137 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
17138 end if;
17139 else
17140 U := Corresponding_Spec (P);
17141 end if;
17143 when Formal_Kind =>
17144 if Present (Spec_Entity (E)) then
17145 U := Spec_Entity (E);
17146 end if;
17148 when others =>
17149 null;
17150 end case;
17152 return U;
17153 end Unique_Entity;
17155 -----------------
17156 -- Unique_Name --
17157 -----------------
17159 function Unique_Name (E : Entity_Id) return String is
17161 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17162 -- reliable, as they may not include the overloading suffix. Instead,
17163 -- when looking for the name of E or one of its enclosing scope, we get
17164 -- the name of the corresponding Unique_Entity.
17166 function Get_Scoped_Name (E : Entity_Id) return String;
17167 -- Return the name of E prefixed by all the names of the scopes to which
17168 -- E belongs, except for Standard.
17170 ---------------------
17171 -- Get_Scoped_Name --
17172 ---------------------
17174 function Get_Scoped_Name (E : Entity_Id) return String is
17175 Name : constant String := Get_Name_String (Chars (E));
17176 begin
17177 if Has_Fully_Qualified_Name (E)
17178 or else Scope (E) = Standard_Standard
17179 then
17180 return Name;
17181 else
17182 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
17183 end if;
17184 end Get_Scoped_Name;
17186 -- Start of processing for Unique_Name
17188 begin
17189 if E = Standard_Standard then
17190 return Get_Name_String (Name_Standard);
17192 elsif Scope (E) = Standard_Standard
17193 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
17194 then
17195 return Get_Name_String (Name_Standard) & "__" &
17196 Get_Name_String (Chars (E));
17198 elsif Ekind (E) = E_Enumeration_Literal then
17199 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
17201 else
17202 return Get_Scoped_Name (Unique_Entity (E));
17203 end if;
17204 end Unique_Name;
17206 ---------------------
17207 -- Unit_Is_Visible --
17208 ---------------------
17210 function Unit_Is_Visible (U : Entity_Id) return Boolean is
17211 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
17212 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
17214 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
17215 -- For a child unit, check whether unit appears in a with_clause
17216 -- of a parent.
17218 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
17219 -- Scan the context clause of one compilation unit looking for a
17220 -- with_clause for the unit in question.
17222 ----------------------------
17223 -- Unit_In_Parent_Context --
17224 ----------------------------
17226 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
17227 begin
17228 if Unit_In_Context (Par_Unit) then
17229 return True;
17231 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
17232 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
17234 else
17235 return False;
17236 end if;
17237 end Unit_In_Parent_Context;
17239 ---------------------
17240 -- Unit_In_Context --
17241 ---------------------
17243 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
17244 Clause : Node_Id;
17246 begin
17247 Clause := First (Context_Items (Comp_Unit));
17248 while Present (Clause) loop
17249 if Nkind (Clause) = N_With_Clause then
17250 if Library_Unit (Clause) = U then
17251 return True;
17253 -- The with_clause may denote a renaming of the unit we are
17254 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17256 elsif
17257 Renamed_Entity (Entity (Name (Clause))) =
17258 Defining_Entity (Unit (U))
17259 then
17260 return True;
17261 end if;
17262 end if;
17264 Next (Clause);
17265 end loop;
17267 return False;
17268 end Unit_In_Context;
17270 -- Start of processing for Unit_Is_Visible
17272 begin
17273 -- The currrent unit is directly visible
17275 if Curr = U then
17276 return True;
17278 elsif Unit_In_Context (Curr) then
17279 return True;
17281 -- If the current unit is a body, check the context of the spec
17283 elsif Nkind (Unit (Curr)) = N_Package_Body
17284 or else
17285 (Nkind (Unit (Curr)) = N_Subprogram_Body
17286 and then not Acts_As_Spec (Unit (Curr)))
17287 then
17288 if Unit_In_Context (Library_Unit (Curr)) then
17289 return True;
17290 end if;
17291 end if;
17293 -- If the spec is a child unit, examine the parents
17295 if Is_Child_Unit (Curr_Entity) then
17296 if Nkind (Unit (Curr)) in N_Unit_Body then
17297 return
17298 Unit_In_Parent_Context
17299 (Parent_Spec (Unit (Library_Unit (Curr))));
17300 else
17301 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
17302 end if;
17304 else
17305 return False;
17306 end if;
17307 end Unit_Is_Visible;
17309 ------------------------------
17310 -- Universal_Interpretation --
17311 ------------------------------
17313 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
17314 Index : Interp_Index;
17315 It : Interp;
17317 begin
17318 -- The argument may be a formal parameter of an operator or subprogram
17319 -- with multiple interpretations, or else an expression for an actual.
17321 if Nkind (Opnd) = N_Defining_Identifier
17322 or else not Is_Overloaded (Opnd)
17323 then
17324 if Etype (Opnd) = Universal_Integer
17325 or else Etype (Opnd) = Universal_Real
17326 then
17327 return Etype (Opnd);
17328 else
17329 return Empty;
17330 end if;
17332 else
17333 Get_First_Interp (Opnd, Index, It);
17334 while Present (It.Typ) loop
17335 if It.Typ = Universal_Integer
17336 or else It.Typ = Universal_Real
17337 then
17338 return It.Typ;
17339 end if;
17341 Get_Next_Interp (Index, It);
17342 end loop;
17344 return Empty;
17345 end if;
17346 end Universal_Interpretation;
17348 ---------------
17349 -- Unqualify --
17350 ---------------
17352 function Unqualify (Expr : Node_Id) return Node_Id is
17353 begin
17354 -- Recurse to handle unlikely case of multiple levels of qualification
17356 if Nkind (Expr) = N_Qualified_Expression then
17357 return Unqualify (Expression (Expr));
17359 -- Normal case, not a qualified expression
17361 else
17362 return Expr;
17363 end if;
17364 end Unqualify;
17366 -----------------------
17367 -- Visible_Ancestors --
17368 -----------------------
17370 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
17371 List_1 : Elist_Id;
17372 List_2 : Elist_Id;
17373 Elmt : Elmt_Id;
17375 begin
17376 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
17378 -- Collect all the parents and progenitors of Typ. If the full-view of
17379 -- private parents and progenitors is available then it is used to
17380 -- generate the list of visible ancestors; otherwise their partial
17381 -- view is added to the resulting list.
17383 Collect_Parents
17384 (T => Typ,
17385 List => List_1,
17386 Use_Full_View => True);
17388 Collect_Interfaces
17389 (T => Typ,
17390 Ifaces_List => List_2,
17391 Exclude_Parents => True,
17392 Use_Full_View => True);
17394 -- Join the two lists. Avoid duplications because an interface may
17395 -- simultaneously be parent and progenitor of a type.
17397 Elmt := First_Elmt (List_2);
17398 while Present (Elmt) loop
17399 Append_Unique_Elmt (Node (Elmt), List_1);
17400 Next_Elmt (Elmt);
17401 end loop;
17403 return List_1;
17404 end Visible_Ancestors;
17406 ----------------------
17407 -- Within_Init_Proc --
17408 ----------------------
17410 function Within_Init_Proc return Boolean is
17411 S : Entity_Id;
17413 begin
17414 S := Current_Scope;
17415 while not Is_Overloadable (S) loop
17416 if S = Standard_Standard then
17417 return False;
17418 else
17419 S := Scope (S);
17420 end if;
17421 end loop;
17423 return Is_Init_Proc (S);
17424 end Within_Init_Proc;
17426 ------------------
17427 -- Within_Scope --
17428 ------------------
17430 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
17431 SE : Entity_Id;
17432 begin
17433 SE := Scope (E);
17434 loop
17435 if SE = S then
17436 return True;
17437 elsif SE = Standard_Standard then
17438 return False;
17439 else
17440 SE := Scope (SE);
17441 end if;
17442 end loop;
17443 end Within_Scope;
17445 ----------------
17446 -- Wrong_Type --
17447 ----------------
17449 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
17450 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
17451 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
17453 Matching_Field : Entity_Id;
17454 -- Entity to give a more precise suggestion on how to write a one-
17455 -- element positional aggregate.
17457 function Has_One_Matching_Field return Boolean;
17458 -- Determines if Expec_Type is a record type with a single component or
17459 -- discriminant whose type matches the found type or is one dimensional
17460 -- array whose component type matches the found type. In the case of
17461 -- one discriminant, we ignore the variant parts. That's not accurate,
17462 -- but good enough for the warning.
17464 ----------------------------
17465 -- Has_One_Matching_Field --
17466 ----------------------------
17468 function Has_One_Matching_Field return Boolean is
17469 E : Entity_Id;
17471 begin
17472 Matching_Field := Empty;
17474 if Is_Array_Type (Expec_Type)
17475 and then Number_Dimensions (Expec_Type) = 1
17476 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
17477 then
17478 -- Use type name if available. This excludes multidimensional
17479 -- arrays and anonymous arrays.
17481 if Comes_From_Source (Expec_Type) then
17482 Matching_Field := Expec_Type;
17484 -- For an assignment, use name of target
17486 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
17487 and then Is_Entity_Name (Name (Parent (Expr)))
17488 then
17489 Matching_Field := Entity (Name (Parent (Expr)));
17490 end if;
17492 return True;
17494 elsif not Is_Record_Type (Expec_Type) then
17495 return False;
17497 else
17498 E := First_Entity (Expec_Type);
17499 loop
17500 if No (E) then
17501 return False;
17503 elsif not Ekind_In (E, E_Discriminant, E_Component)
17504 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
17505 then
17506 Next_Entity (E);
17508 else
17509 exit;
17510 end if;
17511 end loop;
17513 if not Covers (Etype (E), Found_Type) then
17514 return False;
17516 elsif Present (Next_Entity (E))
17517 and then (Ekind (E) = E_Component
17518 or else Ekind (Next_Entity (E)) = E_Discriminant)
17519 then
17520 return False;
17522 else
17523 Matching_Field := E;
17524 return True;
17525 end if;
17526 end if;
17527 end Has_One_Matching_Field;
17529 -- Start of processing for Wrong_Type
17531 begin
17532 -- Don't output message if either type is Any_Type, or if a message
17533 -- has already been posted for this node. We need to do the latter
17534 -- check explicitly (it is ordinarily done in Errout), because we
17535 -- are using ! to force the output of the error messages.
17537 if Expec_Type = Any_Type
17538 or else Found_Type = Any_Type
17539 or else Error_Posted (Expr)
17540 then
17541 return;
17543 -- If one of the types is a Taft-Amendment type and the other it its
17544 -- completion, it must be an illegal use of a TAT in the spec, for
17545 -- which an error was already emitted. Avoid cascaded errors.
17547 elsif Is_Incomplete_Type (Expec_Type)
17548 and then Has_Completion_In_Body (Expec_Type)
17549 and then Full_View (Expec_Type) = Etype (Expr)
17550 then
17551 return;
17553 elsif Is_Incomplete_Type (Etype (Expr))
17554 and then Has_Completion_In_Body (Etype (Expr))
17555 and then Full_View (Etype (Expr)) = Expec_Type
17556 then
17557 return;
17559 -- In an instance, there is an ongoing problem with completion of
17560 -- type derived from private types. Their structure is what Gigi
17561 -- expects, but the Etype is the parent type rather than the
17562 -- derived private type itself. Do not flag error in this case. The
17563 -- private completion is an entity without a parent, like an Itype.
17564 -- Similarly, full and partial views may be incorrect in the instance.
17565 -- There is no simple way to insure that it is consistent ???
17567 -- A similar view discrepancy can happen in an inlined body, for the
17568 -- same reason: inserted body may be outside of the original package
17569 -- and only partial views are visible at the point of insertion.
17571 elsif In_Instance or else In_Inlined_Body then
17572 if Etype (Etype (Expr)) = Etype (Expected_Type)
17573 and then
17574 (Has_Private_Declaration (Expected_Type)
17575 or else Has_Private_Declaration (Etype (Expr)))
17576 and then No (Parent (Expected_Type))
17577 then
17578 return;
17580 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
17581 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
17582 then
17583 return;
17585 elsif Is_Private_Type (Expected_Type)
17586 and then Present (Full_View (Expected_Type))
17587 and then Covers (Full_View (Expected_Type), Etype (Expr))
17588 then
17589 return;
17590 end if;
17591 end if;
17593 -- An interesting special check. If the expression is parenthesized
17594 -- and its type corresponds to the type of the sole component of the
17595 -- expected record type, or to the component type of the expected one
17596 -- dimensional array type, then assume we have a bad aggregate attempt.
17598 if Nkind (Expr) in N_Subexpr
17599 and then Paren_Count (Expr) /= 0
17600 and then Has_One_Matching_Field
17601 then
17602 Error_Msg_N ("positional aggregate cannot have one component", Expr);
17603 if Present (Matching_Field) then
17604 if Is_Array_Type (Expec_Type) then
17605 Error_Msg_NE
17606 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
17608 else
17609 Error_Msg_NE
17610 ("\write instead `& ='> ...`", Expr, Matching_Field);
17611 end if;
17612 end if;
17614 -- Another special check, if we are looking for a pool-specific access
17615 -- type and we found an E_Access_Attribute_Type, then we have the case
17616 -- of an Access attribute being used in a context which needs a pool-
17617 -- specific type, which is never allowed. The one extra check we make
17618 -- is that the expected designated type covers the Found_Type.
17620 elsif Is_Access_Type (Expec_Type)
17621 and then Ekind (Found_Type) = E_Access_Attribute_Type
17622 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
17623 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
17624 and then Covers
17625 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
17626 then
17627 Error_Msg_N -- CODEFIX
17628 ("result must be general access type!", Expr);
17629 Error_Msg_NE -- CODEFIX
17630 ("add ALL to }!", Expr, Expec_Type);
17632 -- Another special check, if the expected type is an integer type,
17633 -- but the expression is of type System.Address, and the parent is
17634 -- an addition or subtraction operation whose left operand is the
17635 -- expression in question and whose right operand is of an integral
17636 -- type, then this is an attempt at address arithmetic, so give
17637 -- appropriate message.
17639 elsif Is_Integer_Type (Expec_Type)
17640 and then Is_RTE (Found_Type, RE_Address)
17641 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
17642 and then Expr = Left_Opnd (Parent (Expr))
17643 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
17644 then
17645 Error_Msg_N
17646 ("address arithmetic not predefined in package System",
17647 Parent (Expr));
17648 Error_Msg_N
17649 ("\possible missing with/use of System.Storage_Elements",
17650 Parent (Expr));
17651 return;
17653 -- If the expected type is an anonymous access type, as for access
17654 -- parameters and discriminants, the error is on the designated types.
17656 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
17657 if Comes_From_Source (Expec_Type) then
17658 Error_Msg_NE ("expected}!", Expr, Expec_Type);
17659 else
17660 Error_Msg_NE
17661 ("expected an access type with designated}",
17662 Expr, Designated_Type (Expec_Type));
17663 end if;
17665 if Is_Access_Type (Found_Type)
17666 and then not Comes_From_Source (Found_Type)
17667 then
17668 Error_Msg_NE
17669 ("\\found an access type with designated}!",
17670 Expr, Designated_Type (Found_Type));
17671 else
17672 if From_Limited_With (Found_Type) then
17673 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
17674 Error_Msg_Qual_Level := 99;
17675 Error_Msg_NE -- CODEFIX
17676 ("\\missing `WITH &;", Expr, Scope (Found_Type));
17677 Error_Msg_Qual_Level := 0;
17678 else
17679 Error_Msg_NE ("found}!", Expr, Found_Type);
17680 end if;
17681 end if;
17683 -- Normal case of one type found, some other type expected
17685 else
17686 -- If the names of the two types are the same, see if some number
17687 -- of levels of qualification will help. Don't try more than three
17688 -- levels, and if we get to standard, it's no use (and probably
17689 -- represents an error in the compiler) Also do not bother with
17690 -- internal scope names.
17692 declare
17693 Expec_Scope : Entity_Id;
17694 Found_Scope : Entity_Id;
17696 begin
17697 Expec_Scope := Expec_Type;
17698 Found_Scope := Found_Type;
17700 for Levels in Int range 0 .. 3 loop
17701 if Chars (Expec_Scope) /= Chars (Found_Scope) then
17702 Error_Msg_Qual_Level := Levels;
17703 exit;
17704 end if;
17706 Expec_Scope := Scope (Expec_Scope);
17707 Found_Scope := Scope (Found_Scope);
17709 exit when Expec_Scope = Standard_Standard
17710 or else Found_Scope = Standard_Standard
17711 or else not Comes_From_Source (Expec_Scope)
17712 or else not Comes_From_Source (Found_Scope);
17713 end loop;
17714 end;
17716 if Is_Record_Type (Expec_Type)
17717 and then Present (Corresponding_Remote_Type (Expec_Type))
17718 then
17719 Error_Msg_NE ("expected}!", Expr,
17720 Corresponding_Remote_Type (Expec_Type));
17721 else
17722 Error_Msg_NE ("expected}!", Expr, Expec_Type);
17723 end if;
17725 if Is_Entity_Name (Expr)
17726 and then Is_Package_Or_Generic_Package (Entity (Expr))
17727 then
17728 Error_Msg_N ("\\found package name!", Expr);
17730 elsif Is_Entity_Name (Expr)
17731 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
17732 then
17733 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
17734 Error_Msg_N
17735 ("found procedure name, possibly missing Access attribute!",
17736 Expr);
17737 else
17738 Error_Msg_N
17739 ("\\found procedure name instead of function!", Expr);
17740 end if;
17742 elsif Nkind (Expr) = N_Function_Call
17743 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
17744 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
17745 and then No (Parameter_Associations (Expr))
17746 then
17747 Error_Msg_N
17748 ("found function name, possibly missing Access attribute!",
17749 Expr);
17751 -- Catch common error: a prefix or infix operator which is not
17752 -- directly visible because the type isn't.
17754 elsif Nkind (Expr) in N_Op
17755 and then Is_Overloaded (Expr)
17756 and then not Is_Immediately_Visible (Expec_Type)
17757 and then not Is_Potentially_Use_Visible (Expec_Type)
17758 and then not In_Use (Expec_Type)
17759 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
17760 then
17761 Error_Msg_N
17762 ("operator of the type is not directly visible!", Expr);
17764 elsif Ekind (Found_Type) = E_Void
17765 and then Present (Parent (Found_Type))
17766 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
17767 then
17768 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
17770 else
17771 Error_Msg_NE ("\\found}!", Expr, Found_Type);
17772 end if;
17774 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
17775 -- of the same modular type, and (M1 and M2) = 0 was intended.
17777 if Expec_Type = Standard_Boolean
17778 and then Is_Modular_Integer_Type (Found_Type)
17779 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
17780 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
17781 then
17782 declare
17783 Op : constant Node_Id := Right_Opnd (Parent (Expr));
17784 L : constant Node_Id := Left_Opnd (Op);
17785 R : constant Node_Id := Right_Opnd (Op);
17786 begin
17787 -- The case for the message is when the left operand of the
17788 -- comparison is the same modular type, or when it is an
17789 -- integer literal (or other universal integer expression),
17790 -- which would have been typed as the modular type if the
17791 -- parens had been there.
17793 if (Etype (L) = Found_Type
17794 or else
17795 Etype (L) = Universal_Integer)
17796 and then Is_Integer_Type (Etype (R))
17797 then
17798 Error_Msg_N
17799 ("\\possible missing parens for modular operation", Expr);
17800 end if;
17801 end;
17802 end if;
17804 -- Reset error message qualification indication
17806 Error_Msg_Qual_Level := 0;
17807 end if;
17808 end Wrong_Type;
17810 end Sem_Util;