2014-10-31 Ed Schonberg <schonberg@adacore.com>
[official-gcc.git] / gcc / ada / sem_util.adb
blob09afaaaafa54d491356510d183ef4e2d245f2800
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);
255 procedure Add_Classification;
256 -- Prepend Prag to the list of classifications
258 procedure Add_Contract_Test_Case;
259 -- Prepend Prag to the list of contract and test cases
261 procedure Add_Pre_Post_Condition;
262 -- Prepend Prag to the list of pre- and postconditions
264 ------------------------
265 -- Add_Classification --
266 ------------------------
268 procedure Add_Classification is
269 begin
270 Set_Next_Pragma (Prag, Classifications (Items));
271 Set_Classifications (Items, Prag);
272 end Add_Classification;
274 ----------------------------
275 -- Add_Contract_Test_Case --
276 ----------------------------
278 procedure Add_Contract_Test_Case is
279 begin
280 Set_Next_Pragma (Prag, Contract_Test_Cases (Items));
281 Set_Contract_Test_Cases (Items, Prag);
282 end Add_Contract_Test_Case;
284 ----------------------------
285 -- Add_Pre_Post_Condition --
286 ----------------------------
288 procedure Add_Pre_Post_Condition is
289 begin
290 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
291 Set_Pre_Post_Conditions (Items, Prag);
292 end Add_Pre_Post_Condition;
294 -- Local variables
296 Nam : Name_Id;
297 PPC : Node_Id;
299 -- Start of processing for Add_Contract_Item
301 begin
302 -- The related context must have a contract and the item to be added
303 -- must be a pragma.
305 pragma Assert (Present (Items));
306 pragma Assert (Nkind (Prag) = N_Pragma);
308 Nam := Original_Aspect_Name (Prag);
310 -- Contract items related to [generic] packages or instantiations. The
311 -- applicable pragmas are:
312 -- Abstract_States
313 -- Initial_Condition
314 -- Initializes
315 -- Part_Of (instantiation only)
317 if Ekind_In (Id, E_Generic_Package, E_Package) then
318 if Nam_In (Nam, Name_Abstract_State,
319 Name_Initial_Condition,
320 Name_Initializes)
321 then
322 Add_Classification;
324 -- Indicator Part_Of must be associated with a package instantiation
326 elsif Nam = Name_Part_Of and then Is_Generic_Instance (Id) then
327 Add_Classification;
329 -- The pragma is not a proper contract item
331 else
332 raise Program_Error;
333 end if;
335 -- Contract items related to package bodies. The applicable pragmas are:
336 -- Refined_States
338 elsif Ekind (Id) = E_Package_Body then
339 if Nam = Name_Refined_State then
340 Add_Classification;
342 -- The pragma is not a proper contract item
344 else
345 raise Program_Error;
346 end if;
348 -- Contract items related to subprogram or entry declarations. The
349 -- applicable pragmas are:
350 -- Contract_Cases
351 -- Depends
352 -- Extensions_Visible
353 -- Global
354 -- Post
355 -- Postcondition
356 -- Pre
357 -- Precondition
358 -- Test_Case
360 elsif Ekind_In (Id, E_Entry, E_Entry_Family)
361 or else Is_Generic_Subprogram (Id)
362 or else Is_Subprogram (Id)
363 then
364 if Nam_In (Nam, Name_Pre,
365 Name_Precondition,
366 Name_uPre,
367 Name_Post,
368 Name_Postcondition,
369 Name_uPost)
370 then
371 -- Before we add a precondition or postcondition to the list, make
372 -- sure we do not have a disallowed duplicate, which can happen if
373 -- we use a pragma for Pre[_Class] or Post[_Class] instead of the
374 -- corresponding aspect.
376 if not From_Aspect_Specification (Prag)
377 and then Nam_In (Nam, Name_Pre,
378 Name_uPre,
379 Name_Post,
380 Name_Post_Class)
381 then
382 PPC := Pre_Post_Conditions (Items);
383 while Present (PPC) loop
384 if not Split_PPC (PPC)
385 and then Original_Aspect_Name (PPC) = Nam
386 then
387 Error_Msg_Sloc := Sloc (PPC);
388 Error_Msg_NE
389 ("duplication of aspect for & given#", Prag, Id);
390 return;
391 end if;
393 PPC := Next_Pragma (PPC);
394 end loop;
395 end if;
397 Add_Pre_Post_Condition;
399 elsif Nam_In (Nam, Name_Contract_Cases, Name_Test_Case) then
400 Add_Contract_Test_Case;
402 elsif Nam_In (Nam, Name_Depends,
403 Name_Extensions_Visible,
404 Name_Global)
405 then
406 Add_Classification;
408 -- The pragma is not a proper contract item
410 else
411 raise Program_Error;
412 end if;
414 -- Contract items related to subprogram bodies. Applicable pragmas are:
415 -- Refined_Depends
416 -- Refined_Global
417 -- Refined_Post
419 elsif Ekind (Id) = E_Subprogram_Body then
420 if Nam_In (Nam, Name_Refined_Depends, Name_Refined_Global) then
421 Add_Classification;
423 elsif Nam = Name_Refined_Post then
424 Add_Pre_Post_Condition;
426 -- The pragma is not a proper contract item
428 else
429 raise Program_Error;
430 end if;
432 -- Contract items related to variables. Applicable pragmas are:
433 -- Async_Readers
434 -- Async_Writers
435 -- Effective_Reads
436 -- Effective_Writes
437 -- Part_Of
439 elsif Ekind (Id) = E_Variable then
440 if Nam_In (Nam, Name_Async_Readers,
441 Name_Async_Writers,
442 Name_Effective_Reads,
443 Name_Effective_Writes,
444 Name_Part_Of)
445 then
446 Add_Classification;
448 -- The pragma is not a proper contract item
450 else
451 raise Program_Error;
452 end if;
453 end if;
454 end Add_Contract_Item;
456 ----------------------------
457 -- Add_Global_Declaration --
458 ----------------------------
460 procedure Add_Global_Declaration (N : Node_Id) is
461 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
463 begin
464 if No (Declarations (Aux_Node)) then
465 Set_Declarations (Aux_Node, New_List);
466 end if;
468 Append_To (Declarations (Aux_Node), N);
469 Analyze (N);
470 end Add_Global_Declaration;
472 --------------------------------
473 -- Address_Integer_Convert_OK --
474 --------------------------------
476 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
477 begin
478 if Allow_Integer_Address
479 and then ((Is_Descendent_Of_Address (T1)
480 and then Is_Private_Type (T1)
481 and then Is_Integer_Type (T2))
482 or else
483 (Is_Descendent_Of_Address (T2)
484 and then Is_Private_Type (T2)
485 and then Is_Integer_Type (T1)))
486 then
487 return True;
488 else
489 return False;
490 end if;
491 end Address_Integer_Convert_OK;
493 -----------------
494 -- Addressable --
495 -----------------
497 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
499 function Addressable (V : Uint) return Boolean is
500 begin
501 return V = Uint_8 or else
502 V = Uint_16 or else
503 V = Uint_32 or else
504 V = Uint_64;
505 end Addressable;
507 function Addressable (V : Int) return Boolean is
508 begin
509 return V = 8 or else
510 V = 16 or else
511 V = 32 or else
512 V = 64;
513 end Addressable;
515 ---------------------------------
516 -- Aggregate_Constraint_Checks --
517 ---------------------------------
519 procedure Aggregate_Constraint_Checks
520 (Exp : Node_Id;
521 Check_Typ : Entity_Id)
523 Exp_Typ : constant Entity_Id := Etype (Exp);
525 begin
526 if Raises_Constraint_Error (Exp) then
527 return;
528 end if;
530 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
531 -- component's type to force the appropriate accessibility checks.
533 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
534 -- type to force the corresponding run-time check
536 if Is_Access_Type (Check_Typ)
537 and then ((Is_Local_Anonymous_Access (Check_Typ))
538 or else (Can_Never_Be_Null (Check_Typ)
539 and then not Can_Never_Be_Null (Exp_Typ)))
540 then
541 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
542 Analyze_And_Resolve (Exp, Check_Typ);
543 Check_Unset_Reference (Exp);
544 end if;
546 -- This is really expansion activity, so make sure that expansion is
547 -- on and is allowed. In GNATprove mode, we also want check flags to
548 -- be added in the tree, so that the formal verification can rely on
549 -- those to be present. In GNATprove mode for formal verification, some
550 -- treatment typically only done during expansion needs to be performed
551 -- on the tree, but it should not be applied inside generics. Otherwise,
552 -- this breaks the name resolution mechanism for generic instances.
554 if not Expander_Active
555 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
556 then
557 return;
558 end if;
560 -- First check if we have to insert discriminant checks
562 if Has_Discriminants (Exp_Typ) then
563 Apply_Discriminant_Check (Exp, Check_Typ);
565 -- Next emit length checks for array aggregates
567 elsif Is_Array_Type (Exp_Typ) then
568 Apply_Length_Check (Exp, Check_Typ);
570 -- Finally emit scalar and string checks. If we are dealing with a
571 -- scalar literal we need to check by hand because the Etype of
572 -- literals is not necessarily correct.
574 elsif Is_Scalar_Type (Exp_Typ)
575 and then Compile_Time_Known_Value (Exp)
576 then
577 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
578 Apply_Compile_Time_Constraint_Error
579 (Exp, "value not in range of}??", CE_Range_Check_Failed,
580 Ent => Base_Type (Check_Typ),
581 Typ => Base_Type (Check_Typ));
583 elsif Is_Out_Of_Range (Exp, Check_Typ) then
584 Apply_Compile_Time_Constraint_Error
585 (Exp, "value not in range of}??", CE_Range_Check_Failed,
586 Ent => Check_Typ,
587 Typ => Check_Typ);
589 elsif not Range_Checks_Suppressed (Check_Typ) then
590 Apply_Scalar_Range_Check (Exp, Check_Typ);
591 end if;
593 -- Verify that target type is also scalar, to prevent view anomalies
594 -- in instantiations.
596 elsif (Is_Scalar_Type (Exp_Typ)
597 or else Nkind (Exp) = N_String_Literal)
598 and then Is_Scalar_Type (Check_Typ)
599 and then Exp_Typ /= Check_Typ
600 then
601 if Is_Entity_Name (Exp)
602 and then Ekind (Entity (Exp)) = E_Constant
603 then
604 -- If expression is a constant, it is worthwhile checking whether
605 -- it is a bound of the type.
607 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
608 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
609 or else
610 (Is_Entity_Name (Type_High_Bound (Check_Typ))
611 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
612 then
613 return;
615 else
616 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
617 Analyze_And_Resolve (Exp, Check_Typ);
618 Check_Unset_Reference (Exp);
619 end if;
621 -- Could use a comment on this case ???
623 else
624 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
625 Analyze_And_Resolve (Exp, Check_Typ);
626 Check_Unset_Reference (Exp);
627 end if;
629 end if;
630 end Aggregate_Constraint_Checks;
632 -----------------------
633 -- Alignment_In_Bits --
634 -----------------------
636 function Alignment_In_Bits (E : Entity_Id) return Uint is
637 begin
638 return Alignment (E) * System_Storage_Unit;
639 end Alignment_In_Bits;
641 ---------------------------------
642 -- Append_Inherited_Subprogram --
643 ---------------------------------
645 procedure Append_Inherited_Subprogram (S : Entity_Id) is
646 Par : constant Entity_Id := Alias (S);
647 -- The parent subprogram
649 Scop : constant Entity_Id := Scope (Par);
650 -- The scope of definition of the parent subprogram
652 Typ : constant Entity_Id := Defining_Entity (Parent (S));
653 -- The derived type of which S is a primitive operation
655 Decl : Node_Id;
656 Next_E : Entity_Id;
658 begin
659 if Ekind (Current_Scope) = E_Package
660 and then In_Private_Part (Current_Scope)
661 and then Has_Private_Declaration (Typ)
662 and then Is_Tagged_Type (Typ)
663 and then Scop = Current_Scope
664 then
665 -- The inherited operation is available at the earliest place after
666 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
667 -- relevant for type extensions. If the parent operation appears
668 -- after the type extension, the operation is not visible.
670 Decl := First
671 (Visible_Declarations
672 (Package_Specification (Current_Scope)));
673 while Present (Decl) loop
674 if Nkind (Decl) = N_Private_Extension_Declaration
675 and then Defining_Entity (Decl) = Typ
676 then
677 if Sloc (Decl) > Sloc (Par) then
678 Next_E := Next_Entity (Par);
679 Set_Next_Entity (Par, S);
680 Set_Next_Entity (S, Next_E);
681 return;
683 else
684 exit;
685 end if;
686 end if;
688 Next (Decl);
689 end loop;
690 end if;
692 -- If partial view is not a type extension, or it appears before the
693 -- subprogram declaration, insert normally at end of entity list.
695 Append_Entity (S, Current_Scope);
696 end Append_Inherited_Subprogram;
698 -----------------------------------------
699 -- Apply_Compile_Time_Constraint_Error --
700 -----------------------------------------
702 procedure Apply_Compile_Time_Constraint_Error
703 (N : Node_Id;
704 Msg : String;
705 Reason : RT_Exception_Code;
706 Ent : Entity_Id := Empty;
707 Typ : Entity_Id := Empty;
708 Loc : Source_Ptr := No_Location;
709 Rep : Boolean := True;
710 Warn : Boolean := False)
712 Stat : constant Boolean := Is_Static_Expression (N);
713 R_Stat : constant Node_Id :=
714 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
715 Rtyp : Entity_Id;
717 begin
718 if No (Typ) then
719 Rtyp := Etype (N);
720 else
721 Rtyp := Typ;
722 end if;
724 Discard_Node
725 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
727 if not Rep then
728 return;
729 end if;
731 -- Now we replace the node by an N_Raise_Constraint_Error node
732 -- This does not need reanalyzing, so set it as analyzed now.
734 Rewrite (N, R_Stat);
735 Set_Analyzed (N, True);
737 Set_Etype (N, Rtyp);
738 Set_Raises_Constraint_Error (N);
740 -- Now deal with possible local raise handling
742 Possible_Local_Raise (N, Standard_Constraint_Error);
744 -- If the original expression was marked as static, the result is
745 -- still marked as static, but the Raises_Constraint_Error flag is
746 -- always set so that further static evaluation is not attempted.
748 if Stat then
749 Set_Is_Static_Expression (N);
750 end if;
751 end Apply_Compile_Time_Constraint_Error;
753 ---------------------------
754 -- Async_Readers_Enabled --
755 ---------------------------
757 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
758 begin
759 return Has_Enabled_Property (Id, Name_Async_Readers);
760 end Async_Readers_Enabled;
762 ---------------------------
763 -- Async_Writers_Enabled --
764 ---------------------------
766 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
767 begin
768 return Has_Enabled_Property (Id, Name_Async_Writers);
769 end Async_Writers_Enabled;
771 --------------------------------------
772 -- Available_Full_View_Of_Component --
773 --------------------------------------
775 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
776 ST : constant Entity_Id := Scope (T);
777 SCT : constant Entity_Id := Scope (Component_Type (T));
778 begin
779 return In_Open_Scopes (ST)
780 and then In_Open_Scopes (SCT)
781 and then Scope_Depth (ST) >= Scope_Depth (SCT);
782 end Available_Full_View_Of_Component;
784 -------------------
785 -- Bad_Attribute --
786 -------------------
788 procedure Bad_Attribute
789 (N : Node_Id;
790 Nam : Name_Id;
791 Warn : Boolean := False)
793 begin
794 Error_Msg_Warn := Warn;
795 Error_Msg_N ("unrecognized attribute&<<", N);
797 -- Check for possible misspelling
799 Error_Msg_Name_1 := First_Attribute_Name;
800 while Error_Msg_Name_1 <= Last_Attribute_Name loop
801 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
802 Error_Msg_N -- CODEFIX
803 ("\possible misspelling of %<<", N);
804 exit;
805 end if;
807 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
808 end loop;
809 end Bad_Attribute;
811 --------------------------------
812 -- Bad_Predicated_Subtype_Use --
813 --------------------------------
815 procedure Bad_Predicated_Subtype_Use
816 (Msg : String;
817 N : Node_Id;
818 Typ : Entity_Id;
819 Suggest_Static : Boolean := False)
821 Gen : Entity_Id;
823 begin
824 -- Avoid cascaded errors
826 if Error_Posted (N) then
827 return;
828 end if;
830 if Inside_A_Generic then
831 Gen := Current_Scope;
832 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
833 Gen := Scope (Gen);
834 end loop;
836 if No (Gen) then
837 return;
838 end if;
840 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
841 Set_No_Predicate_On_Actual (Typ);
842 end if;
844 elsif Has_Predicates (Typ) then
845 if Is_Generic_Actual_Type (Typ) then
847 -- The restriction on loop parameters is only that the type
848 -- should have no dynamic predicates.
850 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
851 and then not Has_Dynamic_Predicate_Aspect (Typ)
852 and then Is_OK_Static_Subtype (Typ)
853 then
854 return;
855 end if;
857 Gen := Current_Scope;
858 while not Is_Generic_Instance (Gen) loop
859 Gen := Scope (Gen);
860 end loop;
862 pragma Assert (Present (Gen));
864 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
865 Error_Msg_Warn := SPARK_Mode /= On;
866 Error_Msg_FE (Msg & "<<", N, Typ);
867 Error_Msg_F ("\Program_Error [<<", N);
869 Insert_Action (N,
870 Make_Raise_Program_Error (Sloc (N),
871 Reason => PE_Bad_Predicated_Generic_Type));
873 else
874 Error_Msg_FE (Msg & "<<", N, Typ);
875 end if;
877 else
878 Error_Msg_FE (Msg, N, Typ);
879 end if;
881 -- Emit an optional suggestion on how to remedy the error if the
882 -- context warrants it.
884 if Suggest_Static and then Has_Static_Predicate (Typ) then
885 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
886 end if;
887 end if;
888 end Bad_Predicated_Subtype_Use;
890 -----------------------------------------
891 -- Bad_Unordered_Enumeration_Reference --
892 -----------------------------------------
894 function Bad_Unordered_Enumeration_Reference
895 (N : Node_Id;
896 T : Entity_Id) return Boolean
898 begin
899 return Is_Enumeration_Type (T)
900 and then Comes_From_Source (N)
901 and then Warn_On_Unordered_Enumeration_Type
902 and then not Has_Pragma_Ordered (T)
903 and then not In_Same_Extended_Unit (N, T);
904 end Bad_Unordered_Enumeration_Reference;
906 --------------------------
907 -- Build_Actual_Subtype --
908 --------------------------
910 function Build_Actual_Subtype
911 (T : Entity_Id;
912 N : Node_Or_Entity_Id) return Node_Id
914 Loc : Source_Ptr;
915 -- Normally Sloc (N), but may point to corresponding body in some cases
917 Constraints : List_Id;
918 Decl : Node_Id;
919 Discr : Entity_Id;
920 Hi : Node_Id;
921 Lo : Node_Id;
922 Subt : Entity_Id;
923 Disc_Type : Entity_Id;
924 Obj : Node_Id;
926 begin
927 Loc := Sloc (N);
929 if Nkind (N) = N_Defining_Identifier then
930 Obj := New_Occurrence_Of (N, Loc);
932 -- If this is a formal parameter of a subprogram declaration, and
933 -- we are compiling the body, we want the declaration for the
934 -- actual subtype to carry the source position of the body, to
935 -- prevent anomalies in gdb when stepping through the code.
937 if Is_Formal (N) then
938 declare
939 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
940 begin
941 if Nkind (Decl) = N_Subprogram_Declaration
942 and then Present (Corresponding_Body (Decl))
943 then
944 Loc := Sloc (Corresponding_Body (Decl));
945 end if;
946 end;
947 end if;
949 else
950 Obj := N;
951 end if;
953 if Is_Array_Type (T) then
954 Constraints := New_List;
955 for J in 1 .. Number_Dimensions (T) loop
957 -- Build an array subtype declaration with the nominal subtype and
958 -- the bounds of the actual. Add the declaration in front of the
959 -- local declarations for the subprogram, for analysis before any
960 -- reference to the formal in the body.
962 Lo :=
963 Make_Attribute_Reference (Loc,
964 Prefix =>
965 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
966 Attribute_Name => Name_First,
967 Expressions => New_List (
968 Make_Integer_Literal (Loc, J)));
970 Hi :=
971 Make_Attribute_Reference (Loc,
972 Prefix =>
973 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
974 Attribute_Name => Name_Last,
975 Expressions => New_List (
976 Make_Integer_Literal (Loc, J)));
978 Append (Make_Range (Loc, Lo, Hi), Constraints);
979 end loop;
981 -- If the type has unknown discriminants there is no constrained
982 -- subtype to build. This is never called for a formal or for a
983 -- lhs, so returning the type is ok ???
985 elsif Has_Unknown_Discriminants (T) then
986 return T;
988 else
989 Constraints := New_List;
991 -- Type T is a generic derived type, inherit the discriminants from
992 -- the parent type.
994 if Is_Private_Type (T)
995 and then No (Full_View (T))
997 -- T was flagged as an error if it was declared as a formal
998 -- derived type with known discriminants. In this case there
999 -- is no need to look at the parent type since T already carries
1000 -- its own discriminants.
1002 and then not Error_Posted (T)
1003 then
1004 Disc_Type := Etype (Base_Type (T));
1005 else
1006 Disc_Type := T;
1007 end if;
1009 Discr := First_Discriminant (Disc_Type);
1010 while Present (Discr) loop
1011 Append_To (Constraints,
1012 Make_Selected_Component (Loc,
1013 Prefix =>
1014 Duplicate_Subexpr_No_Checks (Obj),
1015 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1016 Next_Discriminant (Discr);
1017 end loop;
1018 end if;
1020 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1021 Set_Is_Internal (Subt);
1023 Decl :=
1024 Make_Subtype_Declaration (Loc,
1025 Defining_Identifier => Subt,
1026 Subtype_Indication =>
1027 Make_Subtype_Indication (Loc,
1028 Subtype_Mark => New_Occurrence_Of (T, Loc),
1029 Constraint =>
1030 Make_Index_Or_Discriminant_Constraint (Loc,
1031 Constraints => Constraints)));
1033 Mark_Rewrite_Insertion (Decl);
1034 return Decl;
1035 end Build_Actual_Subtype;
1037 ---------------------------------------
1038 -- Build_Actual_Subtype_Of_Component --
1039 ---------------------------------------
1041 function Build_Actual_Subtype_Of_Component
1042 (T : Entity_Id;
1043 N : Node_Id) return Node_Id
1045 Loc : constant Source_Ptr := Sloc (N);
1046 P : constant Node_Id := Prefix (N);
1047 D : Elmt_Id;
1048 Id : Node_Id;
1049 Index_Typ : Entity_Id;
1051 Desig_Typ : Entity_Id;
1052 -- This is either a copy of T, or if T is an access type, then it is
1053 -- the directly designated type of this access type.
1055 function Build_Actual_Array_Constraint return List_Id;
1056 -- If one or more of the bounds of the component depends on
1057 -- discriminants, build actual constraint using the discriminants
1058 -- of the prefix.
1060 function Build_Actual_Record_Constraint return List_Id;
1061 -- Similar to previous one, for discriminated components constrained
1062 -- by the discriminant of the enclosing object.
1064 -----------------------------------
1065 -- Build_Actual_Array_Constraint --
1066 -----------------------------------
1068 function Build_Actual_Array_Constraint return List_Id is
1069 Constraints : constant List_Id := New_List;
1070 Indx : Node_Id;
1071 Hi : Node_Id;
1072 Lo : Node_Id;
1073 Old_Hi : Node_Id;
1074 Old_Lo : Node_Id;
1076 begin
1077 Indx := First_Index (Desig_Typ);
1078 while Present (Indx) loop
1079 Old_Lo := Type_Low_Bound (Etype (Indx));
1080 Old_Hi := Type_High_Bound (Etype (Indx));
1082 if Denotes_Discriminant (Old_Lo) then
1083 Lo :=
1084 Make_Selected_Component (Loc,
1085 Prefix => New_Copy_Tree (P),
1086 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1088 else
1089 Lo := New_Copy_Tree (Old_Lo);
1091 -- The new bound will be reanalyzed in the enclosing
1092 -- declaration. For literal bounds that come from a type
1093 -- declaration, the type of the context must be imposed, so
1094 -- insure that analysis will take place. For non-universal
1095 -- types this is not strictly necessary.
1097 Set_Analyzed (Lo, False);
1098 end if;
1100 if Denotes_Discriminant (Old_Hi) then
1101 Hi :=
1102 Make_Selected_Component (Loc,
1103 Prefix => New_Copy_Tree (P),
1104 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1106 else
1107 Hi := New_Copy_Tree (Old_Hi);
1108 Set_Analyzed (Hi, False);
1109 end if;
1111 Append (Make_Range (Loc, Lo, Hi), Constraints);
1112 Next_Index (Indx);
1113 end loop;
1115 return Constraints;
1116 end Build_Actual_Array_Constraint;
1118 ------------------------------------
1119 -- Build_Actual_Record_Constraint --
1120 ------------------------------------
1122 function Build_Actual_Record_Constraint return List_Id is
1123 Constraints : constant List_Id := New_List;
1124 D : Elmt_Id;
1125 D_Val : Node_Id;
1127 begin
1128 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1129 while Present (D) loop
1130 if Denotes_Discriminant (Node (D)) then
1131 D_Val := Make_Selected_Component (Loc,
1132 Prefix => New_Copy_Tree (P),
1133 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1135 else
1136 D_Val := New_Copy_Tree (Node (D));
1137 end if;
1139 Append (D_Val, Constraints);
1140 Next_Elmt (D);
1141 end loop;
1143 return Constraints;
1144 end Build_Actual_Record_Constraint;
1146 -- Start of processing for Build_Actual_Subtype_Of_Component
1148 begin
1149 -- Why the test for Spec_Expression mode here???
1151 if In_Spec_Expression then
1152 return Empty;
1154 -- More comments for the rest of this body would be good ???
1156 elsif Nkind (N) = N_Explicit_Dereference then
1157 if Is_Composite_Type (T)
1158 and then not Is_Constrained (T)
1159 and then not (Is_Class_Wide_Type (T)
1160 and then Is_Constrained (Root_Type (T)))
1161 and then not Has_Unknown_Discriminants (T)
1162 then
1163 -- If the type of the dereference is already constrained, it is an
1164 -- actual subtype.
1166 if Is_Array_Type (Etype (N))
1167 and then Is_Constrained (Etype (N))
1168 then
1169 return Empty;
1170 else
1171 Remove_Side_Effects (P);
1172 return Build_Actual_Subtype (T, N);
1173 end if;
1174 else
1175 return Empty;
1176 end if;
1177 end if;
1179 if Ekind (T) = E_Access_Subtype then
1180 Desig_Typ := Designated_Type (T);
1181 else
1182 Desig_Typ := T;
1183 end if;
1185 if Ekind (Desig_Typ) = E_Array_Subtype then
1186 Id := First_Index (Desig_Typ);
1187 while Present (Id) loop
1188 Index_Typ := Underlying_Type (Etype (Id));
1190 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1191 or else
1192 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1193 then
1194 Remove_Side_Effects (P);
1195 return
1196 Build_Component_Subtype
1197 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1198 end if;
1200 Next_Index (Id);
1201 end loop;
1203 elsif Is_Composite_Type (Desig_Typ)
1204 and then Has_Discriminants (Desig_Typ)
1205 and then not Has_Unknown_Discriminants (Desig_Typ)
1206 then
1207 if Is_Private_Type (Desig_Typ)
1208 and then No (Discriminant_Constraint (Desig_Typ))
1209 then
1210 Desig_Typ := Full_View (Desig_Typ);
1211 end if;
1213 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1214 while Present (D) loop
1215 if Denotes_Discriminant (Node (D)) then
1216 Remove_Side_Effects (P);
1217 return
1218 Build_Component_Subtype (
1219 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1220 end if;
1222 Next_Elmt (D);
1223 end loop;
1224 end if;
1226 -- If none of the above, the actual and nominal subtypes are the same
1228 return Empty;
1229 end Build_Actual_Subtype_Of_Component;
1231 -----------------------------
1232 -- Build_Component_Subtype --
1233 -----------------------------
1235 function Build_Component_Subtype
1236 (C : List_Id;
1237 Loc : Source_Ptr;
1238 T : Entity_Id) return Node_Id
1240 Subt : Entity_Id;
1241 Decl : Node_Id;
1243 begin
1244 -- Unchecked_Union components do not require component subtypes
1246 if Is_Unchecked_Union (T) then
1247 return Empty;
1248 end if;
1250 Subt := Make_Temporary (Loc, 'S');
1251 Set_Is_Internal (Subt);
1253 Decl :=
1254 Make_Subtype_Declaration (Loc,
1255 Defining_Identifier => Subt,
1256 Subtype_Indication =>
1257 Make_Subtype_Indication (Loc,
1258 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1259 Constraint =>
1260 Make_Index_Or_Discriminant_Constraint (Loc,
1261 Constraints => C)));
1263 Mark_Rewrite_Insertion (Decl);
1264 return Decl;
1265 end Build_Component_Subtype;
1267 ----------------------------------
1268 -- Build_Default_Init_Cond_Call --
1269 ----------------------------------
1271 function Build_Default_Init_Cond_Call
1272 (Loc : Source_Ptr;
1273 Obj_Id : Entity_Id;
1274 Typ : Entity_Id) return Node_Id
1276 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1277 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1279 begin
1280 return
1281 Make_Procedure_Call_Statement (Loc,
1282 Name => New_Occurrence_Of (Proc_Id, Loc),
1283 Parameter_Associations => New_List (
1284 Make_Unchecked_Type_Conversion (Loc,
1285 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1286 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1287 end Build_Default_Init_Cond_Call;
1289 ----------------------------------------------
1290 -- Build_Default_Init_Cond_Procedure_Bodies --
1291 ----------------------------------------------
1293 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1294 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1295 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1296 -- body of the procedure which verifies the assumption of the pragma at
1297 -- run time. The generated body is added after the type declaration.
1299 --------------------------------------------
1300 -- Build_Default_Init_Cond_Procedure_Body --
1301 --------------------------------------------
1303 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1304 Param_Id : Entity_Id;
1305 -- The entity of the sole formal parameter of the default initial
1306 -- condition procedure.
1308 procedure Replace_Type_Reference (N : Node_Id);
1309 -- Replace a single reference to type Typ with a reference to formal
1310 -- parameter Param_Id.
1312 ----------------------------
1313 -- Replace_Type_Reference --
1314 ----------------------------
1316 procedure Replace_Type_Reference (N : Node_Id) is
1317 begin
1318 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1319 end Replace_Type_Reference;
1321 procedure Replace_Type_References is
1322 new Replace_Type_References_Generic (Replace_Type_Reference);
1324 -- Local variables
1326 Loc : constant Source_Ptr := Sloc (Typ);
1327 Prag : constant Node_Id :=
1328 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1329 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1330 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1331 Body_Decl : Node_Id;
1332 Expr : Node_Id;
1333 Stmt : Node_Id;
1335 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1337 begin
1338 -- The procedure should be generated only for [sub]types subject to
1339 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1340 -- not get this specialized procedure.
1342 pragma Assert (Has_Default_Init_Cond (Typ));
1343 pragma Assert (Present (Prag));
1344 pragma Assert (Present (Proc_Id));
1346 -- Nothing to do if the body was already built
1348 if Present (Corresponding_Body (Spec_Decl)) then
1349 return;
1350 end if;
1352 Param_Id := First_Formal (Proc_Id);
1354 -- The pragma has an argument. Note that the argument is analyzed
1355 -- after all references to the current instance of the type are
1356 -- replaced.
1358 if Present (Pragma_Argument_Associations (Prag)) then
1359 Expr :=
1360 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1362 if Nkind (Expr) = N_Null then
1363 Stmt := Make_Null_Statement (Loc);
1365 -- Preserve the original argument of the pragma by replicating it.
1366 -- Replace all references to the current instance of the type with
1367 -- references to the formal parameter.
1369 else
1370 Expr := New_Copy_Tree (Expr);
1371 Replace_Type_References (Expr, Typ);
1373 -- Generate:
1374 -- pragma Check (Default_Initial_Condition, <Expr>);
1376 Stmt :=
1377 Make_Pragma (Loc,
1378 Pragma_Identifier =>
1379 Make_Identifier (Loc, Name_Check),
1381 Pragma_Argument_Associations => New_List (
1382 Make_Pragma_Argument_Association (Loc,
1383 Expression =>
1384 Make_Identifier (Loc,
1385 Chars => Name_Default_Initial_Condition)),
1386 Make_Pragma_Argument_Association (Loc,
1387 Expression => Expr)));
1388 end if;
1390 -- Otherwise the pragma appears without an argument
1392 else
1393 Stmt := Make_Null_Statement (Loc);
1394 end if;
1396 -- Generate:
1397 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1398 -- begin
1399 -- <Stmt>;
1400 -- end <Typ>Default_Init_Cond;
1402 Body_Decl :=
1403 Make_Subprogram_Body (Loc,
1404 Specification =>
1405 Copy_Separate_Tree (Specification (Spec_Decl)),
1406 Declarations => Empty_List,
1407 Handled_Statement_Sequence =>
1408 Make_Handled_Sequence_Of_Statements (Loc,
1409 Statements => New_List (Stmt)));
1411 -- Link the spec and body of the default initial condition procedure
1412 -- to prevent the generation of a duplicate body.
1414 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1415 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1417 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1418 end Build_Default_Init_Cond_Procedure_Body;
1420 -- Local variables
1422 Decl : Node_Id;
1423 Typ : Entity_Id;
1425 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1427 begin
1428 -- Inspect the private declarations looking for [sub]type declarations
1430 Decl := First (Priv_Decls);
1431 while Present (Decl) loop
1432 if Nkind_In (Decl, N_Full_Type_Declaration,
1433 N_Subtype_Declaration)
1434 then
1435 Typ := Defining_Entity (Decl);
1437 -- Guard against partially decorate types due to previous errors
1439 if Is_Type (Typ) then
1441 -- If the type is subject to pragma Default_Initial_Condition,
1442 -- generate the body of the internal procedure which verifies
1443 -- the assertion of the pragma at run time.
1445 if Has_Default_Init_Cond (Typ) then
1446 Build_Default_Init_Cond_Procedure_Body (Typ);
1448 -- A derived type inherits the default initial condition
1449 -- procedure from its parent type.
1451 elsif Has_Inherited_Default_Init_Cond (Typ) then
1452 Inherit_Default_Init_Cond_Procedure (Typ);
1453 end if;
1454 end if;
1455 end if;
1457 Next (Decl);
1458 end loop;
1459 end Build_Default_Init_Cond_Procedure_Bodies;
1461 ---------------------------------------------------
1462 -- Build_Default_Init_Cond_Procedure_Declaration --
1463 ---------------------------------------------------
1465 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1466 Loc : constant Source_Ptr := Sloc (Typ);
1467 Prag : constant Node_Id :=
1468 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1469 Proc_Id : Entity_Id;
1471 begin
1472 -- The procedure should be generated only for types subject to pragma
1473 -- Default_Initial_Condition. Types that inherit the pragma do not get
1474 -- this specialized procedure.
1476 pragma Assert (Has_Default_Init_Cond (Typ));
1477 pragma Assert (Present (Prag));
1479 -- Nothing to do if default initial condition procedure already built
1481 if Present (Default_Init_Cond_Procedure (Typ)) then
1482 return;
1483 end if;
1485 Proc_Id :=
1486 Make_Defining_Identifier (Loc,
1487 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1489 -- Associate default initial condition procedure with the private type
1491 Set_Ekind (Proc_Id, E_Procedure);
1492 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1493 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1495 -- Generate:
1496 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1498 Insert_After_And_Analyze (Prag,
1499 Make_Subprogram_Declaration (Loc,
1500 Specification =>
1501 Make_Procedure_Specification (Loc,
1502 Defining_Unit_Name => Proc_Id,
1503 Parameter_Specifications => New_List (
1504 Make_Parameter_Specification (Loc,
1505 Defining_Identifier => Make_Temporary (Loc, 'I'),
1506 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1507 end Build_Default_Init_Cond_Procedure_Declaration;
1509 ---------------------------
1510 -- Build_Default_Subtype --
1511 ---------------------------
1513 function Build_Default_Subtype
1514 (T : Entity_Id;
1515 N : Node_Id) return Entity_Id
1517 Loc : constant Source_Ptr := Sloc (N);
1518 Disc : Entity_Id;
1520 Bas : Entity_Id;
1521 -- The base type that is to be constrained by the defaults
1523 begin
1524 if not Has_Discriminants (T) or else Is_Constrained (T) then
1525 return T;
1526 end if;
1528 Bas := Base_Type (T);
1530 -- If T is non-private but its base type is private, this is the
1531 -- completion of a subtype declaration whose parent type is private
1532 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1533 -- are to be found in the full view of the base. Check that the private
1534 -- status of T and its base differ.
1536 if Is_Private_Type (Bas)
1537 and then not Is_Private_Type (T)
1538 and then Present (Full_View (Bas))
1539 then
1540 Bas := Full_View (Bas);
1541 end if;
1543 Disc := First_Discriminant (T);
1545 if No (Discriminant_Default_Value (Disc)) then
1546 return T;
1547 end if;
1549 declare
1550 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1551 Constraints : constant List_Id := New_List;
1552 Decl : Node_Id;
1554 begin
1555 while Present (Disc) loop
1556 Append_To (Constraints,
1557 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1558 Next_Discriminant (Disc);
1559 end loop;
1561 Decl :=
1562 Make_Subtype_Declaration (Loc,
1563 Defining_Identifier => Act,
1564 Subtype_Indication =>
1565 Make_Subtype_Indication (Loc,
1566 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1567 Constraint =>
1568 Make_Index_Or_Discriminant_Constraint (Loc,
1569 Constraints => Constraints)));
1571 Insert_Action (N, Decl);
1572 Analyze (Decl);
1573 return Act;
1574 end;
1575 end Build_Default_Subtype;
1577 --------------------------------------------
1578 -- Build_Discriminal_Subtype_Of_Component --
1579 --------------------------------------------
1581 function Build_Discriminal_Subtype_Of_Component
1582 (T : Entity_Id) return Node_Id
1584 Loc : constant Source_Ptr := Sloc (T);
1585 D : Elmt_Id;
1586 Id : Node_Id;
1588 function Build_Discriminal_Array_Constraint return List_Id;
1589 -- If one or more of the bounds of the component depends on
1590 -- discriminants, build actual constraint using the discriminants
1591 -- of the prefix.
1593 function Build_Discriminal_Record_Constraint return List_Id;
1594 -- Similar to previous one, for discriminated components constrained by
1595 -- the discriminant of the enclosing object.
1597 ----------------------------------------
1598 -- Build_Discriminal_Array_Constraint --
1599 ----------------------------------------
1601 function Build_Discriminal_Array_Constraint return List_Id is
1602 Constraints : constant List_Id := New_List;
1603 Indx : Node_Id;
1604 Hi : Node_Id;
1605 Lo : Node_Id;
1606 Old_Hi : Node_Id;
1607 Old_Lo : Node_Id;
1609 begin
1610 Indx := First_Index (T);
1611 while Present (Indx) loop
1612 Old_Lo := Type_Low_Bound (Etype (Indx));
1613 Old_Hi := Type_High_Bound (Etype (Indx));
1615 if Denotes_Discriminant (Old_Lo) then
1616 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1618 else
1619 Lo := New_Copy_Tree (Old_Lo);
1620 end if;
1622 if Denotes_Discriminant (Old_Hi) then
1623 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1625 else
1626 Hi := New_Copy_Tree (Old_Hi);
1627 end if;
1629 Append (Make_Range (Loc, Lo, Hi), Constraints);
1630 Next_Index (Indx);
1631 end loop;
1633 return Constraints;
1634 end Build_Discriminal_Array_Constraint;
1636 -----------------------------------------
1637 -- Build_Discriminal_Record_Constraint --
1638 -----------------------------------------
1640 function Build_Discriminal_Record_Constraint return List_Id is
1641 Constraints : constant List_Id := New_List;
1642 D : Elmt_Id;
1643 D_Val : Node_Id;
1645 begin
1646 D := First_Elmt (Discriminant_Constraint (T));
1647 while Present (D) loop
1648 if Denotes_Discriminant (Node (D)) then
1649 D_Val :=
1650 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1651 else
1652 D_Val := New_Copy_Tree (Node (D));
1653 end if;
1655 Append (D_Val, Constraints);
1656 Next_Elmt (D);
1657 end loop;
1659 return Constraints;
1660 end Build_Discriminal_Record_Constraint;
1662 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1664 begin
1665 if Ekind (T) = E_Array_Subtype then
1666 Id := First_Index (T);
1667 while Present (Id) loop
1668 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1669 or else
1670 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1671 then
1672 return Build_Component_Subtype
1673 (Build_Discriminal_Array_Constraint, Loc, T);
1674 end if;
1676 Next_Index (Id);
1677 end loop;
1679 elsif Ekind (T) = E_Record_Subtype
1680 and then Has_Discriminants (T)
1681 and then not Has_Unknown_Discriminants (T)
1682 then
1683 D := First_Elmt (Discriminant_Constraint (T));
1684 while Present (D) loop
1685 if Denotes_Discriminant (Node (D)) then
1686 return Build_Component_Subtype
1687 (Build_Discriminal_Record_Constraint, Loc, T);
1688 end if;
1690 Next_Elmt (D);
1691 end loop;
1692 end if;
1694 -- If none of the above, the actual and nominal subtypes are the same
1696 return Empty;
1697 end Build_Discriminal_Subtype_Of_Component;
1699 ------------------------------
1700 -- Build_Elaboration_Entity --
1701 ------------------------------
1703 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1704 Loc : constant Source_Ptr := Sloc (N);
1705 Decl : Node_Id;
1706 Elab_Ent : Entity_Id;
1708 procedure Set_Package_Name (Ent : Entity_Id);
1709 -- Given an entity, sets the fully qualified name of the entity in
1710 -- Name_Buffer, with components separated by double underscores. This
1711 -- is a recursive routine that climbs the scope chain to Standard.
1713 ----------------------
1714 -- Set_Package_Name --
1715 ----------------------
1717 procedure Set_Package_Name (Ent : Entity_Id) is
1718 begin
1719 if Scope (Ent) /= Standard_Standard then
1720 Set_Package_Name (Scope (Ent));
1722 declare
1723 Nam : constant String := Get_Name_String (Chars (Ent));
1724 begin
1725 Name_Buffer (Name_Len + 1) := '_';
1726 Name_Buffer (Name_Len + 2) := '_';
1727 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1728 Name_Len := Name_Len + Nam'Length + 2;
1729 end;
1731 else
1732 Get_Name_String (Chars (Ent));
1733 end if;
1734 end Set_Package_Name;
1736 -- Start of processing for Build_Elaboration_Entity
1738 begin
1739 -- Ignore call if already constructed
1741 if Present (Elaboration_Entity (Spec_Id)) then
1742 return;
1744 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1745 -- no role in analysis.
1747 elsif ASIS_Mode then
1748 return;
1750 -- See if we need elaboration entity. We always need it for the dynamic
1751 -- elaboration model, since it is needed to properly generate the PE
1752 -- exception for access before elaboration.
1754 elsif Dynamic_Elaboration_Checks then
1755 null;
1757 -- For the static model, we don't need the elaboration counter if this
1758 -- unit is sure to have no elaboration code, since that means there
1759 -- is no elaboration unit to be called. Note that we can't just decide
1760 -- after the fact by looking to see whether there was elaboration code,
1761 -- because that's too late to make this decision.
1763 elsif Restriction_Active (No_Elaboration_Code) then
1764 return;
1766 -- Similarly, for the static model, we can skip the elaboration counter
1767 -- if we have the No_Multiple_Elaboration restriction, since for the
1768 -- static model, that's the only purpose of the counter (to avoid
1769 -- multiple elaboration).
1771 elsif Restriction_Active (No_Multiple_Elaboration) then
1772 return;
1773 end if;
1775 -- Here we need the elaboration entity
1777 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1778 -- name with dots replaced by double underscore. We have to manually
1779 -- construct this name, since it will be elaborated in the outer scope,
1780 -- and thus will not have the unit name automatically prepended.
1782 Set_Package_Name (Spec_Id);
1783 Add_Str_To_Name_Buffer ("_E");
1785 -- Create elaboration counter
1787 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1788 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1790 Decl :=
1791 Make_Object_Declaration (Loc,
1792 Defining_Identifier => Elab_Ent,
1793 Object_Definition =>
1794 New_Occurrence_Of (Standard_Short_Integer, Loc),
1795 Expression => Make_Integer_Literal (Loc, Uint_0));
1797 Push_Scope (Standard_Standard);
1798 Add_Global_Declaration (Decl);
1799 Pop_Scope;
1801 -- Reset True_Constant indication, since we will indeed assign a value
1802 -- to the variable in the binder main. We also kill the Current_Value
1803 -- and Last_Assignment fields for the same reason.
1805 Set_Is_True_Constant (Elab_Ent, False);
1806 Set_Current_Value (Elab_Ent, Empty);
1807 Set_Last_Assignment (Elab_Ent, Empty);
1809 -- We do not want any further qualification of the name (if we did not
1810 -- do this, we would pick up the name of the generic package in the case
1811 -- of a library level generic instantiation).
1813 Set_Has_Qualified_Name (Elab_Ent);
1814 Set_Has_Fully_Qualified_Name (Elab_Ent);
1815 end Build_Elaboration_Entity;
1817 --------------------------------
1818 -- Build_Explicit_Dereference --
1819 --------------------------------
1821 procedure Build_Explicit_Dereference
1822 (Expr : Node_Id;
1823 Disc : Entity_Id)
1825 Loc : constant Source_Ptr := Sloc (Expr);
1827 begin
1828 -- An entity of a type with a reference aspect is overloaded with
1829 -- both interpretations: with and without the dereference. Now that
1830 -- the dereference is made explicit, set the type of the node properly,
1831 -- to prevent anomalies in the backend. Same if the expression is an
1832 -- overloaded function call whose return type has a reference aspect.
1834 if Is_Entity_Name (Expr) then
1835 Set_Etype (Expr, Etype (Entity (Expr)));
1837 elsif Nkind (Expr) = N_Function_Call then
1838 Set_Etype (Expr, Etype (Name (Expr)));
1839 end if;
1841 Set_Is_Overloaded (Expr, False);
1843 -- The expression will often be a generalized indexing that yields a
1844 -- container element that is then dereferenced, in which case the
1845 -- generalized indexing call is also non-overloaded.
1847 if Nkind (Expr) = N_Indexed_Component
1848 and then Present (Generalized_Indexing (Expr))
1849 then
1850 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1851 end if;
1853 Rewrite (Expr,
1854 Make_Explicit_Dereference (Loc,
1855 Prefix =>
1856 Make_Selected_Component (Loc,
1857 Prefix => Relocate_Node (Expr),
1858 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1859 Set_Etype (Prefix (Expr), Etype (Disc));
1860 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1861 end Build_Explicit_Dereference;
1863 -----------------------------------
1864 -- Cannot_Raise_Constraint_Error --
1865 -----------------------------------
1867 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1868 begin
1869 if Compile_Time_Known_Value (Expr) then
1870 return True;
1872 elsif Do_Range_Check (Expr) then
1873 return False;
1875 elsif Raises_Constraint_Error (Expr) then
1876 return False;
1878 else
1879 case Nkind (Expr) is
1880 when N_Identifier =>
1881 return True;
1883 when N_Expanded_Name =>
1884 return True;
1886 when N_Selected_Component =>
1887 return not Do_Discriminant_Check (Expr);
1889 when N_Attribute_Reference =>
1890 if Do_Overflow_Check (Expr) then
1891 return False;
1893 elsif No (Expressions (Expr)) then
1894 return True;
1896 else
1897 declare
1898 N : Node_Id;
1900 begin
1901 N := First (Expressions (Expr));
1902 while Present (N) loop
1903 if Cannot_Raise_Constraint_Error (N) then
1904 Next (N);
1905 else
1906 return False;
1907 end if;
1908 end loop;
1910 return True;
1911 end;
1912 end if;
1914 when N_Type_Conversion =>
1915 if Do_Overflow_Check (Expr)
1916 or else Do_Length_Check (Expr)
1917 or else Do_Tag_Check (Expr)
1918 then
1919 return False;
1920 else
1921 return Cannot_Raise_Constraint_Error (Expression (Expr));
1922 end if;
1924 when N_Unchecked_Type_Conversion =>
1925 return Cannot_Raise_Constraint_Error (Expression (Expr));
1927 when N_Unary_Op =>
1928 if Do_Overflow_Check (Expr) then
1929 return False;
1930 else
1931 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1932 end if;
1934 when N_Op_Divide |
1935 N_Op_Mod |
1936 N_Op_Rem
1938 if Do_Division_Check (Expr)
1939 or else
1940 Do_Overflow_Check (Expr)
1941 then
1942 return False;
1943 else
1944 return
1945 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1946 and then
1947 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1948 end if;
1950 when N_Op_Add |
1951 N_Op_And |
1952 N_Op_Concat |
1953 N_Op_Eq |
1954 N_Op_Expon |
1955 N_Op_Ge |
1956 N_Op_Gt |
1957 N_Op_Le |
1958 N_Op_Lt |
1959 N_Op_Multiply |
1960 N_Op_Ne |
1961 N_Op_Or |
1962 N_Op_Rotate_Left |
1963 N_Op_Rotate_Right |
1964 N_Op_Shift_Left |
1965 N_Op_Shift_Right |
1966 N_Op_Shift_Right_Arithmetic |
1967 N_Op_Subtract |
1968 N_Op_Xor
1970 if Do_Overflow_Check (Expr) then
1971 return False;
1972 else
1973 return
1974 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1975 and then
1976 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1977 end if;
1979 when others =>
1980 return False;
1981 end case;
1982 end if;
1983 end Cannot_Raise_Constraint_Error;
1985 -----------------------------------------
1986 -- Check_Dynamically_Tagged_Expression --
1987 -----------------------------------------
1989 procedure Check_Dynamically_Tagged_Expression
1990 (Expr : Node_Id;
1991 Typ : Entity_Id;
1992 Related_Nod : Node_Id)
1994 begin
1995 pragma Assert (Is_Tagged_Type (Typ));
1997 -- In order to avoid spurious errors when analyzing the expanded code,
1998 -- this check is done only for nodes that come from source and for
1999 -- actuals of generic instantiations.
2001 if (Comes_From_Source (Related_Nod)
2002 or else In_Generic_Actual (Expr))
2003 and then (Is_Class_Wide_Type (Etype (Expr))
2004 or else Is_Dynamically_Tagged (Expr))
2005 and then Is_Tagged_Type (Typ)
2006 and then not Is_Class_Wide_Type (Typ)
2007 then
2008 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2009 end if;
2010 end Check_Dynamically_Tagged_Expression;
2012 --------------------------
2013 -- Check_Fully_Declared --
2014 --------------------------
2016 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2017 begin
2018 if Ekind (T) = E_Incomplete_Type then
2020 -- Ada 2005 (AI-50217): If the type is available through a limited
2021 -- with_clause, verify that its full view has been analyzed.
2023 if From_Limited_With (T)
2024 and then Present (Non_Limited_View (T))
2025 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2026 then
2027 -- The non-limited view is fully declared
2029 null;
2031 else
2032 Error_Msg_NE
2033 ("premature usage of incomplete}", N, First_Subtype (T));
2034 end if;
2036 -- Need comments for these tests ???
2038 elsif Has_Private_Component (T)
2039 and then not Is_Generic_Type (Root_Type (T))
2040 and then not In_Spec_Expression
2041 then
2042 -- Special case: if T is the anonymous type created for a single
2043 -- task or protected object, use the name of the source object.
2045 if Is_Concurrent_Type (T)
2046 and then not Comes_From_Source (T)
2047 and then Nkind (N) = N_Object_Declaration
2048 then
2049 Error_Msg_NE
2050 ("type of& has incomplete component",
2051 N, Defining_Identifier (N));
2052 else
2053 Error_Msg_NE
2054 ("premature usage of incomplete}",
2055 N, First_Subtype (T));
2056 end if;
2057 end if;
2058 end Check_Fully_Declared;
2060 -------------------------------------
2061 -- Check_Function_Writable_Actuals --
2062 -------------------------------------
2064 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2065 Writable_Actuals_List : Elist_Id := No_Elist;
2066 Identifiers_List : Elist_Id := No_Elist;
2067 Error_Node : Node_Id := Empty;
2069 procedure Collect_Identifiers (N : Node_Id);
2070 -- In a single traversal of subtree N collect in Writable_Actuals_List
2071 -- all the actuals of functions with writable actuals, and in the list
2072 -- Identifiers_List collect all the identifiers that are not actuals of
2073 -- functions with writable actuals. If a writable actual is referenced
2074 -- twice as writable actual then Error_Node is set to reference its
2075 -- second occurrence, the error is reported, and the tree traversal
2076 -- is abandoned.
2078 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2079 -- Return the entity associated with the function call
2081 procedure Preanalyze_Without_Errors (N : Node_Id);
2082 -- Preanalyze N without reporting errors. Very dubious, you can't just
2083 -- go analyzing things more than once???
2085 -------------------------
2086 -- Collect_Identifiers --
2087 -------------------------
2089 procedure Collect_Identifiers (N : Node_Id) is
2091 function Check_Node (N : Node_Id) return Traverse_Result;
2092 -- Process a single node during the tree traversal to collect the
2093 -- writable actuals of functions and all the identifiers which are
2094 -- not writable actuals of functions.
2096 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2097 -- Returns True if List has a node whose Entity is Entity (N)
2099 -------------------------
2100 -- Check_Function_Call --
2101 -------------------------
2103 function Check_Node (N : Node_Id) return Traverse_Result is
2104 Is_Writable_Actual : Boolean := False;
2105 Id : Entity_Id;
2107 begin
2108 if Nkind (N) = N_Identifier then
2110 -- No analysis possible if the entity is not decorated
2112 if No (Entity (N)) then
2113 return Skip;
2115 -- Don't collect identifiers of packages, called functions, etc
2117 elsif Ekind_In (Entity (N), E_Package,
2118 E_Function,
2119 E_Procedure,
2120 E_Entry)
2121 then
2122 return Skip;
2124 -- Analyze if N is a writable actual of a function
2126 elsif Nkind (Parent (N)) = N_Function_Call then
2127 declare
2128 Call : constant Node_Id := Parent (N);
2129 Actual : Node_Id;
2130 Formal : Node_Id;
2132 begin
2133 Id := Get_Function_Id (Call);
2135 Formal := First_Formal (Id);
2136 Actual := First_Actual (Call);
2137 while Present (Actual) and then Present (Formal) loop
2138 if Actual = N then
2139 if Ekind_In (Formal, E_Out_Parameter,
2140 E_In_Out_Parameter)
2141 then
2142 Is_Writable_Actual := True;
2143 end if;
2145 exit;
2146 end if;
2148 Next_Formal (Formal);
2149 Next_Actual (Actual);
2150 end loop;
2151 end;
2152 end if;
2154 if Is_Writable_Actual then
2155 if Contains (Writable_Actuals_List, N) then
2156 Error_Msg_NE
2157 ("value may be affected by call to& "
2158 & "because order of evaluation is arbitrary", N, Id);
2159 Error_Node := N;
2160 return Abandon;
2161 end if;
2163 Append_New_Elmt (N, To => Writable_Actuals_List);
2165 else
2166 if Identifiers_List = No_Elist then
2167 Identifiers_List := New_Elmt_List;
2168 end if;
2170 Append_Unique_Elmt (N, Identifiers_List);
2171 end if;
2172 end if;
2174 return OK;
2175 end Check_Node;
2177 --------------
2178 -- Contains --
2179 --------------
2181 function Contains
2182 (List : Elist_Id;
2183 N : Node_Id) return Boolean
2185 pragma Assert (Nkind (N) in N_Has_Entity);
2187 Elmt : Elmt_Id;
2189 begin
2190 if List = No_Elist then
2191 return False;
2192 end if;
2194 Elmt := First_Elmt (List);
2195 while Present (Elmt) loop
2196 if Entity (Node (Elmt)) = Entity (N) then
2197 return True;
2198 else
2199 Next_Elmt (Elmt);
2200 end if;
2201 end loop;
2203 return False;
2204 end Contains;
2206 ------------------
2207 -- Do_Traversal --
2208 ------------------
2210 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2211 -- The traversal procedure
2213 -- Start of processing for Collect_Identifiers
2215 begin
2216 if Present (Error_Node) then
2217 return;
2218 end if;
2220 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2221 return;
2222 end if;
2224 Do_Traversal (N);
2225 end Collect_Identifiers;
2227 ---------------------
2228 -- Get_Function_Id --
2229 ---------------------
2231 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2232 Nam : constant Node_Id := Name (Call);
2233 Id : Entity_Id;
2235 begin
2236 if Nkind (Nam) = N_Explicit_Dereference then
2237 Id := Etype (Nam);
2238 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2240 elsif Nkind (Nam) = N_Selected_Component then
2241 Id := Entity (Selector_Name (Nam));
2243 elsif Nkind (Nam) = N_Indexed_Component then
2244 Id := Entity (Selector_Name (Prefix (Nam)));
2246 else
2247 Id := Entity (Nam);
2248 end if;
2250 return Id;
2251 end Get_Function_Id;
2253 ---------------------------
2254 -- Preanalyze_Expression --
2255 ---------------------------
2257 procedure Preanalyze_Without_Errors (N : Node_Id) is
2258 Status : constant Boolean := Get_Ignore_Errors;
2259 begin
2260 Set_Ignore_Errors (True);
2261 Preanalyze (N);
2262 Set_Ignore_Errors (Status);
2263 end Preanalyze_Without_Errors;
2265 -- Start of processing for Check_Function_Writable_Actuals
2267 begin
2268 -- The check only applies to Ada 2012 code, and only to constructs that
2269 -- have multiple constituents whose order of evaluation is not specified
2270 -- by the language.
2272 if Ada_Version < Ada_2012
2273 or else (not (Nkind (N) in N_Op)
2274 and then not (Nkind (N) in N_Membership_Test)
2275 and then not Nkind_In (N, N_Range,
2276 N_Aggregate,
2277 N_Extension_Aggregate,
2278 N_Full_Type_Declaration,
2279 N_Function_Call,
2280 N_Procedure_Call_Statement,
2281 N_Entry_Call_Statement))
2282 or else (Nkind (N) = N_Full_Type_Declaration
2283 and then not Is_Record_Type (Defining_Identifier (N)))
2285 -- In addition, this check only applies to source code, not to code
2286 -- generated by constraint checks.
2288 or else not Comes_From_Source (N)
2289 then
2290 return;
2291 end if;
2293 -- If a construct C has two or more direct constituents that are names
2294 -- or expressions whose evaluation may occur in an arbitrary order, at
2295 -- least one of which contains a function call with an in out or out
2296 -- parameter, then the construct is legal only if: for each name N that
2297 -- is passed as a parameter of mode in out or out to some inner function
2298 -- call C2 (not including the construct C itself), there is no other
2299 -- name anywhere within a direct constituent of the construct C other
2300 -- than the one containing C2, that is known to refer to the same
2301 -- object (RM 6.4.1(6.17/3)).
2303 case Nkind (N) is
2304 when N_Range =>
2305 Collect_Identifiers (Low_Bound (N));
2306 Collect_Identifiers (High_Bound (N));
2308 when N_Op | N_Membership_Test =>
2309 declare
2310 Expr : Node_Id;
2312 begin
2313 Collect_Identifiers (Left_Opnd (N));
2315 if Present (Right_Opnd (N)) then
2316 Collect_Identifiers (Right_Opnd (N));
2317 end if;
2319 if Nkind_In (N, N_In, N_Not_In)
2320 and then Present (Alternatives (N))
2321 then
2322 Expr := First (Alternatives (N));
2323 while Present (Expr) loop
2324 Collect_Identifiers (Expr);
2326 Next (Expr);
2327 end loop;
2328 end if;
2329 end;
2331 when N_Full_Type_Declaration =>
2332 declare
2333 function Get_Record_Part (N : Node_Id) return Node_Id;
2334 -- Return the record part of this record type definition
2336 function Get_Record_Part (N : Node_Id) return Node_Id is
2337 Type_Def : constant Node_Id := Type_Definition (N);
2338 begin
2339 if Nkind (Type_Def) = N_Derived_Type_Definition then
2340 return Record_Extension_Part (Type_Def);
2341 else
2342 return Type_Def;
2343 end if;
2344 end Get_Record_Part;
2346 Comp : Node_Id;
2347 Def_Id : Entity_Id := Defining_Identifier (N);
2348 Rec : Node_Id := Get_Record_Part (N);
2350 begin
2351 -- No need to perform any analysis if the record has no
2352 -- components
2354 if No (Rec) or else No (Component_List (Rec)) then
2355 return;
2356 end if;
2358 -- Collect the identifiers starting from the deepest
2359 -- derivation. Done to report the error in the deepest
2360 -- derivation.
2362 loop
2363 if Present (Component_List (Rec)) then
2364 Comp := First (Component_Items (Component_List (Rec)));
2365 while Present (Comp) loop
2366 if Nkind (Comp) = N_Component_Declaration
2367 and then Present (Expression (Comp))
2368 then
2369 Collect_Identifiers (Expression (Comp));
2370 end if;
2372 Next (Comp);
2373 end loop;
2374 end if;
2376 exit when No (Underlying_Type (Etype (Def_Id)))
2377 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2378 = Def_Id;
2380 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2381 Rec := Get_Record_Part (Parent (Def_Id));
2382 end loop;
2383 end;
2385 when N_Subprogram_Call |
2386 N_Entry_Call_Statement =>
2387 declare
2388 Id : constant Entity_Id := Get_Function_Id (N);
2389 Formal : Node_Id;
2390 Actual : Node_Id;
2392 begin
2393 Formal := First_Formal (Id);
2394 Actual := First_Actual (N);
2395 while Present (Actual) and then Present (Formal) loop
2396 if Ekind_In (Formal, E_Out_Parameter,
2397 E_In_Out_Parameter)
2398 then
2399 Collect_Identifiers (Actual);
2400 end if;
2402 Next_Formal (Formal);
2403 Next_Actual (Actual);
2404 end loop;
2405 end;
2407 when N_Aggregate |
2408 N_Extension_Aggregate =>
2409 declare
2410 Assoc : Node_Id;
2411 Choice : Node_Id;
2412 Comp_Expr : Node_Id;
2414 begin
2415 -- Handle the N_Others_Choice of array aggregates with static
2416 -- bounds. There is no need to perform this analysis in
2417 -- aggregates without static bounds since we cannot evaluate
2418 -- if the N_Others_Choice covers several elements. There is
2419 -- no need to handle the N_Others choice of record aggregates
2420 -- since at this stage it has been already expanded by
2421 -- Resolve_Record_Aggregate.
2423 if Is_Array_Type (Etype (N))
2424 and then Nkind (N) = N_Aggregate
2425 and then Present (Aggregate_Bounds (N))
2426 and then Compile_Time_Known_Bounds (Etype (N))
2427 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2429 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2430 then
2431 declare
2432 Count_Components : Uint := Uint_0;
2433 Num_Components : Uint;
2434 Others_Assoc : Node_Id;
2435 Others_Choice : Node_Id := Empty;
2436 Others_Box_Present : Boolean := False;
2438 begin
2439 -- Count positional associations
2441 if Present (Expressions (N)) then
2442 Comp_Expr := First (Expressions (N));
2443 while Present (Comp_Expr) loop
2444 Count_Components := Count_Components + 1;
2445 Next (Comp_Expr);
2446 end loop;
2447 end if;
2449 -- Count the rest of elements and locate the N_Others
2450 -- choice (if any)
2452 Assoc := First (Component_Associations (N));
2453 while Present (Assoc) loop
2454 Choice := First (Choices (Assoc));
2455 while Present (Choice) loop
2456 if Nkind (Choice) = N_Others_Choice then
2457 Others_Assoc := Assoc;
2458 Others_Choice := Choice;
2459 Others_Box_Present := Box_Present (Assoc);
2461 -- Count several components
2463 elsif Nkind_In (Choice, N_Range,
2464 N_Subtype_Indication)
2465 or else (Is_Entity_Name (Choice)
2466 and then Is_Type (Entity (Choice)))
2467 then
2468 declare
2469 L, H : Node_Id;
2470 begin
2471 Get_Index_Bounds (Choice, L, H);
2472 pragma Assert
2473 (Compile_Time_Known_Value (L)
2474 and then Compile_Time_Known_Value (H));
2475 Count_Components :=
2476 Count_Components
2477 + Expr_Value (H) - Expr_Value (L) + 1;
2478 end;
2480 -- Count single component. No other case available
2481 -- since we are handling an aggregate with static
2482 -- bounds.
2484 else
2485 pragma Assert (Is_OK_Static_Expression (Choice)
2486 or else Nkind (Choice) = N_Identifier
2487 or else Nkind (Choice) = N_Integer_Literal);
2489 Count_Components := Count_Components + 1;
2490 end if;
2492 Next (Choice);
2493 end loop;
2495 Next (Assoc);
2496 end loop;
2498 Num_Components :=
2499 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2500 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2502 pragma Assert (Count_Components <= Num_Components);
2504 -- Handle the N_Others choice if it covers several
2505 -- components
2507 if Present (Others_Choice)
2508 and then (Num_Components - Count_Components) > 1
2509 then
2510 if not Others_Box_Present then
2512 -- At this stage, if expansion is active, the
2513 -- expression of the others choice has not been
2514 -- analyzed. Hence we generate a duplicate and
2515 -- we analyze it silently to have available the
2516 -- minimum decoration required to collect the
2517 -- identifiers.
2519 if not Expander_Active then
2520 Comp_Expr := Expression (Others_Assoc);
2521 else
2522 Comp_Expr :=
2523 New_Copy_Tree (Expression (Others_Assoc));
2524 Preanalyze_Without_Errors (Comp_Expr);
2525 end if;
2527 Collect_Identifiers (Comp_Expr);
2529 if Writable_Actuals_List /= No_Elist then
2531 -- As suggested by Robert, at current stage we
2532 -- report occurrences of this case as warnings.
2534 Error_Msg_N
2535 ("writable function parameter may affect "
2536 & "value in other component because order "
2537 & "of evaluation is unspecified??",
2538 Node (First_Elmt (Writable_Actuals_List)));
2539 end if;
2540 end if;
2541 end if;
2542 end;
2543 end if;
2545 -- Handle ancestor part of extension aggregates
2547 if Nkind (N) = N_Extension_Aggregate then
2548 Collect_Identifiers (Ancestor_Part (N));
2549 end if;
2551 -- Handle positional associations
2553 if Present (Expressions (N)) then
2554 Comp_Expr := First (Expressions (N));
2555 while Present (Comp_Expr) loop
2556 if not Is_OK_Static_Expression (Comp_Expr) then
2557 Collect_Identifiers (Comp_Expr);
2558 end if;
2560 Next (Comp_Expr);
2561 end loop;
2562 end if;
2564 -- Handle discrete associations
2566 if Present (Component_Associations (N)) then
2567 Assoc := First (Component_Associations (N));
2568 while Present (Assoc) loop
2570 if not Box_Present (Assoc) then
2571 Choice := First (Choices (Assoc));
2572 while Present (Choice) loop
2574 -- For now we skip discriminants since it requires
2575 -- performing the analysis in two phases: first one
2576 -- analyzing discriminants and second one analyzing
2577 -- the rest of components since discriminants are
2578 -- evaluated prior to components: too much extra
2579 -- work to detect a corner case???
2581 if Nkind (Choice) in N_Has_Entity
2582 and then Present (Entity (Choice))
2583 and then Ekind (Entity (Choice)) = E_Discriminant
2584 then
2585 null;
2587 elsif Box_Present (Assoc) then
2588 null;
2590 else
2591 if not Analyzed (Expression (Assoc)) then
2592 Comp_Expr :=
2593 New_Copy_Tree (Expression (Assoc));
2594 Set_Parent (Comp_Expr, Parent (N));
2595 Preanalyze_Without_Errors (Comp_Expr);
2596 else
2597 Comp_Expr := Expression (Assoc);
2598 end if;
2600 Collect_Identifiers (Comp_Expr);
2601 end if;
2603 Next (Choice);
2604 end loop;
2605 end if;
2607 Next (Assoc);
2608 end loop;
2609 end if;
2610 end;
2612 when others =>
2613 return;
2614 end case;
2616 -- No further action needed if we already reported an error
2618 if Present (Error_Node) then
2619 return;
2620 end if;
2622 -- Check if some writable argument of a function is referenced
2624 if Writable_Actuals_List /= No_Elist
2625 and then Identifiers_List /= No_Elist
2626 then
2627 declare
2628 Elmt_1 : Elmt_Id;
2629 Elmt_2 : Elmt_Id;
2631 begin
2632 Elmt_1 := First_Elmt (Writable_Actuals_List);
2633 while Present (Elmt_1) loop
2634 Elmt_2 := First_Elmt (Identifiers_List);
2635 while Present (Elmt_2) loop
2636 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2637 case Nkind (Parent (Node (Elmt_2))) is
2638 when N_Aggregate |
2639 N_Component_Association |
2640 N_Component_Declaration =>
2641 Error_Msg_N
2642 ("value may be affected by call in other "
2643 & "component because they are evaluated "
2644 & "in unspecified order",
2645 Node (Elmt_2));
2647 when N_In | N_Not_In =>
2648 Error_Msg_N
2649 ("value may be affected by call in other "
2650 & "alternative because they are evaluated "
2651 & "in unspecified order",
2652 Node (Elmt_2));
2654 when others =>
2655 Error_Msg_N
2656 ("value of actual may be affected by call in "
2657 & "other actual because they are evaluated "
2658 & "in unspecified order",
2659 Node (Elmt_2));
2660 end case;
2661 end if;
2663 Next_Elmt (Elmt_2);
2664 end loop;
2666 Next_Elmt (Elmt_1);
2667 end loop;
2668 end;
2669 end if;
2670 end Check_Function_Writable_Actuals;
2672 --------------------------------
2673 -- Check_Implicit_Dereference --
2674 --------------------------------
2676 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2677 Disc : Entity_Id;
2678 Desig : Entity_Id;
2679 Nam : Node_Id;
2681 begin
2682 if Nkind (N) = N_Indexed_Component
2683 and then Present (Generalized_Indexing (N))
2684 then
2685 Nam := Generalized_Indexing (N);
2687 else
2688 Nam := N;
2689 end if;
2691 if Ada_Version < Ada_2012
2692 or else not Has_Implicit_Dereference (Base_Type (Typ))
2693 then
2694 return;
2696 elsif not Comes_From_Source (N)
2697 and then Nkind (N) /= N_Indexed_Component
2698 then
2699 return;
2701 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2702 null;
2704 else
2705 Disc := First_Discriminant (Typ);
2706 while Present (Disc) loop
2707 if Has_Implicit_Dereference (Disc) then
2708 Desig := Designated_Type (Etype (Disc));
2709 Add_One_Interp (Nam, Disc, Desig);
2711 -- If the node is a generalized indexing, add interpretation
2712 -- to that node as well, for subsequent resolution.
2714 if Nkind (N) = N_Indexed_Component then
2715 Add_One_Interp (N, Disc, Desig);
2716 end if;
2718 -- If the operation comes from a generic unit and the context
2719 -- is a selected component, the selector name may be global
2720 -- and set in the instance already. Remove the entity to
2721 -- force resolution of the selected component, and the
2722 -- generation of an explicit dereference if needed.
2724 if In_Instance
2725 and then Nkind (Parent (Nam)) = N_Selected_Component
2726 then
2727 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2728 end if;
2730 exit;
2731 end if;
2733 Next_Discriminant (Disc);
2734 end loop;
2735 end if;
2736 end Check_Implicit_Dereference;
2738 ----------------------------------
2739 -- Check_Internal_Protected_Use --
2740 ----------------------------------
2742 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2743 S : Entity_Id;
2744 Prot : Entity_Id;
2746 begin
2747 S := Current_Scope;
2748 while Present (S) loop
2749 if S = Standard_Standard then
2750 return;
2752 elsif Ekind (S) = E_Function
2753 and then Ekind (Scope (S)) = E_Protected_Type
2754 then
2755 Prot := Scope (S);
2756 exit;
2757 end if;
2759 S := Scope (S);
2760 end loop;
2762 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2764 -- An indirect function call (e.g. a callback within a protected
2765 -- function body) is not statically illegal. If the access type is
2766 -- anonymous and is the type of an access parameter, the scope of Nam
2767 -- will be the protected type, but it is not a protected operation.
2769 if Ekind (Nam) = E_Subprogram_Type
2770 and then
2771 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2772 then
2773 null;
2775 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2776 Error_Msg_N
2777 ("within protected function cannot use protected "
2778 & "procedure in renaming or as generic actual", N);
2780 elsif Nkind (N) = N_Attribute_Reference then
2781 Error_Msg_N
2782 ("within protected function cannot take access of "
2783 & " protected procedure", N);
2785 else
2786 Error_Msg_N
2787 ("within protected function, protected object is constant", N);
2788 Error_Msg_N
2789 ("\cannot call operation that may modify it", N);
2790 end if;
2791 end if;
2792 end Check_Internal_Protected_Use;
2794 ---------------------------------------
2795 -- Check_Later_Vs_Basic_Declarations --
2796 ---------------------------------------
2798 procedure Check_Later_Vs_Basic_Declarations
2799 (Decls : List_Id;
2800 During_Parsing : Boolean)
2802 Body_Sloc : Source_Ptr;
2803 Decl : Node_Id;
2805 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2806 -- Return whether Decl is considered as a declarative item.
2807 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2808 -- When During_Parsing is False, the semantics of SPARK is followed.
2810 -------------------------------
2811 -- Is_Later_Declarative_Item --
2812 -------------------------------
2814 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2815 begin
2816 if Nkind (Decl) in N_Later_Decl_Item then
2817 return True;
2819 elsif Nkind (Decl) = N_Pragma then
2820 return True;
2822 elsif During_Parsing then
2823 return False;
2825 -- In SPARK, a package declaration is not considered as a later
2826 -- declarative item.
2828 elsif Nkind (Decl) = N_Package_Declaration then
2829 return False;
2831 -- In SPARK, a renaming is considered as a later declarative item
2833 elsif Nkind (Decl) in N_Renaming_Declaration then
2834 return True;
2836 else
2837 return False;
2838 end if;
2839 end Is_Later_Declarative_Item;
2841 -- Start of Check_Later_Vs_Basic_Declarations
2843 begin
2844 Decl := First (Decls);
2846 -- Loop through sequence of basic declarative items
2848 Outer : while Present (Decl) loop
2849 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2850 and then Nkind (Decl) not in N_Body_Stub
2851 then
2852 Next (Decl);
2854 -- Once a body is encountered, we only allow later declarative
2855 -- items. The inner loop checks the rest of the list.
2857 else
2858 Body_Sloc := Sloc (Decl);
2860 Inner : while Present (Decl) loop
2861 if not Is_Later_Declarative_Item (Decl) then
2862 if During_Parsing then
2863 if Ada_Version = Ada_83 then
2864 Error_Msg_Sloc := Body_Sloc;
2865 Error_Msg_N
2866 ("(Ada 83) decl cannot appear after body#", Decl);
2867 end if;
2868 else
2869 Error_Msg_Sloc := Body_Sloc;
2870 Check_SPARK_05_Restriction
2871 ("decl cannot appear after body#", Decl);
2872 end if;
2873 end if;
2875 Next (Decl);
2876 end loop Inner;
2877 end if;
2878 end loop Outer;
2879 end Check_Later_Vs_Basic_Declarations;
2881 -------------------------
2882 -- Check_Nested_Access --
2883 -------------------------
2885 procedure Check_Nested_Access (Ent : Entity_Id) is
2886 Scop : constant Entity_Id := Current_Scope;
2887 Current_Subp : Entity_Id;
2888 Enclosing : Entity_Id;
2890 begin
2891 -- Currently only enabled for VM back-ends for efficiency, should we
2892 -- enable it more systematically ???
2894 -- Check for Is_Imported needs commenting below ???
2896 if VM_Target /= No_VM
2897 and then Ekind_In (Ent, E_Variable, E_Constant, E_Loop_Parameter)
2898 and then Scope (Ent) /= Empty
2899 and then not Is_Library_Level_Entity (Ent)
2900 and then not Is_Imported (Ent)
2901 then
2902 if Is_Subprogram (Scop)
2903 or else Is_Generic_Subprogram (Scop)
2904 or else Is_Entry (Scop)
2905 then
2906 Current_Subp := Scop;
2907 else
2908 Current_Subp := Current_Subprogram;
2909 end if;
2911 Enclosing := Enclosing_Subprogram (Ent);
2913 if Enclosing /= Empty and then Enclosing /= Current_Subp then
2914 Set_Has_Up_Level_Access (Ent, True);
2915 end if;
2916 end if;
2917 end Check_Nested_Access;
2919 ---------------------------
2920 -- Check_No_Hidden_State --
2921 ---------------------------
2923 procedure Check_No_Hidden_State (Id : Entity_Id) is
2924 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2925 -- Determine whether the entity of a package denoted by Pkg has a null
2926 -- abstract state.
2928 -----------------------------
2929 -- Has_Null_Abstract_State --
2930 -----------------------------
2932 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2933 States : constant Elist_Id := Abstract_States (Pkg);
2935 begin
2936 -- Check first available state of related package. A null abstract
2937 -- state always appears as the sole element of the state list.
2939 return
2940 Present (States)
2941 and then Is_Null_State (Node (First_Elmt (States)));
2942 end Has_Null_Abstract_State;
2944 -- Local variables
2946 Context : Entity_Id := Empty;
2947 Not_Visible : Boolean := False;
2948 Scop : Entity_Id;
2950 -- Start of processing for Check_No_Hidden_State
2952 begin
2953 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2955 -- Find the proper context where the object or state appears
2957 Scop := Scope (Id);
2958 while Present (Scop) loop
2959 Context := Scop;
2961 -- Keep track of the context's visibility
2963 Not_Visible := Not_Visible or else In_Private_Part (Context);
2965 -- Prevent the search from going too far
2967 if Context = Standard_Standard then
2968 return;
2970 -- Objects and states that appear immediately within a subprogram or
2971 -- inside a construct nested within a subprogram do not introduce a
2972 -- hidden state. They behave as local variable declarations.
2974 elsif Is_Subprogram (Context) then
2975 return;
2977 -- When examining a package body, use the entity of the spec as it
2978 -- carries the abstract state declarations.
2980 elsif Ekind (Context) = E_Package_Body then
2981 Context := Spec_Entity (Context);
2982 end if;
2984 -- Stop the traversal when a package subject to a null abstract state
2985 -- has been found.
2987 if Ekind_In (Context, E_Generic_Package, E_Package)
2988 and then Has_Null_Abstract_State (Context)
2989 then
2990 exit;
2991 end if;
2993 Scop := Scope (Scop);
2994 end loop;
2996 -- At this point we know that there is at least one package with a null
2997 -- abstract state in visibility. Emit an error message unconditionally
2998 -- if the entity being processed is a state because the placement of the
2999 -- related package is irrelevant. This is not the case for objects as
3000 -- the intermediate context matters.
3002 if Present (Context)
3003 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3004 then
3005 Error_Msg_N ("cannot introduce hidden state &", Id);
3006 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3007 end if;
3008 end Check_No_Hidden_State;
3010 ------------------------------------------
3011 -- Check_Potentially_Blocking_Operation --
3012 ------------------------------------------
3014 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3015 S : Entity_Id;
3017 begin
3018 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3019 -- When pragma Detect_Blocking is active, the run time will raise
3020 -- Program_Error. Here we only issue a warning, since we generally
3021 -- support the use of potentially blocking operations in the absence
3022 -- of the pragma.
3024 -- Indirect blocking through a subprogram call cannot be diagnosed
3025 -- statically without interprocedural analysis, so we do not attempt
3026 -- to do it here.
3028 S := Scope (Current_Scope);
3029 while Present (S) and then S /= Standard_Standard loop
3030 if Is_Protected_Type (S) then
3031 Error_Msg_N
3032 ("potentially blocking operation in protected operation??", N);
3033 return;
3034 end if;
3036 S := Scope (S);
3037 end loop;
3038 end Check_Potentially_Blocking_Operation;
3040 ---------------------------------
3041 -- Check_Result_And_Post_State --
3042 ---------------------------------
3044 procedure Check_Result_And_Post_State
3045 (Prag : Node_Id;
3046 Result_Seen : in out Boolean)
3048 procedure Check_Expression (Expr : Node_Id);
3049 -- Perform the 'Result and post-state checks on a given expression
3051 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3052 -- Attempt to find attribute 'Result in a subtree denoted by N
3054 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3055 -- Determine whether source node N denotes "True" or "False"
3057 function Mentions_Post_State (N : Node_Id) return Boolean;
3058 -- Determine whether a subtree denoted by N mentions any construct that
3059 -- denotes a post-state.
3061 procedure Check_Function_Result is
3062 new Traverse_Proc (Is_Function_Result);
3064 ----------------------
3065 -- Check_Expression --
3066 ----------------------
3068 procedure Check_Expression (Expr : Node_Id) is
3069 begin
3070 if not Is_Trivial_Boolean (Expr) then
3071 Check_Function_Result (Expr);
3073 if not Mentions_Post_State (Expr) then
3074 if Pragma_Name (Prag) = Name_Contract_Cases then
3075 Error_Msg_N
3076 ("contract case refers only to pre-state?T?", Expr);
3078 elsif Pragma_Name (Prag) = Name_Refined_Post then
3079 Error_Msg_N
3080 ("refined postcondition refers only to pre-state?T?",
3081 Prag);
3083 else
3084 Error_Msg_N
3085 ("postcondition refers only to pre-state?T?", Prag);
3086 end if;
3087 end if;
3088 end if;
3089 end Check_Expression;
3091 ------------------------
3092 -- Is_Function_Result --
3093 ------------------------
3095 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3096 begin
3097 if Is_Attribute_Result (N) then
3098 Result_Seen := True;
3099 return Abandon;
3101 -- Continue the traversal
3103 else
3104 return OK;
3105 end if;
3106 end Is_Function_Result;
3108 ------------------------
3109 -- Is_Trivial_Boolean --
3110 ------------------------
3112 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3113 begin
3114 return
3115 Comes_From_Source (N)
3116 and then Is_Entity_Name (N)
3117 and then (Entity (N) = Standard_True
3118 or else
3119 Entity (N) = Standard_False);
3120 end Is_Trivial_Boolean;
3122 -------------------------
3123 -- Mentions_Post_State --
3124 -------------------------
3126 function Mentions_Post_State (N : Node_Id) return Boolean is
3127 Post_State_Seen : Boolean := False;
3129 function Is_Post_State (N : Node_Id) return Traverse_Result;
3130 -- Attempt to find a construct that denotes a post-state. If this is
3131 -- the case, set flag Post_State_Seen.
3133 -------------------
3134 -- Is_Post_State --
3135 -------------------
3137 function Is_Post_State (N : Node_Id) return Traverse_Result is
3138 Ent : Entity_Id;
3140 begin
3141 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3142 Post_State_Seen := True;
3143 return Abandon;
3145 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3146 Ent := Entity (N);
3148 -- The entity may be modifiable through an implicit dereference
3150 if No (Ent)
3151 or else Ekind (Ent) in Assignable_Kind
3152 or else (Is_Access_Type (Etype (Ent))
3153 and then Nkind (Parent (N)) = N_Selected_Component)
3154 then
3155 Post_State_Seen := True;
3156 return Abandon;
3157 end if;
3159 elsif Nkind (N) = N_Attribute_Reference then
3160 if Attribute_Name (N) = Name_Old then
3161 return Skip;
3163 elsif Attribute_Name (N) = Name_Result then
3164 Post_State_Seen := True;
3165 return Abandon;
3166 end if;
3167 end if;
3169 return OK;
3170 end Is_Post_State;
3172 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3174 -- Start of processing for Mentions_Post_State
3176 begin
3177 Find_Post_State (N);
3179 return Post_State_Seen;
3180 end Mentions_Post_State;
3182 -- Local variables
3184 Expr : constant Node_Id :=
3185 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
3186 Nam : constant Name_Id := Pragma_Name (Prag);
3187 CCase : Node_Id;
3189 -- Start of processing for Check_Result_And_Post_State
3191 begin
3192 -- Examine all consequences
3194 if Nam = Name_Contract_Cases then
3195 CCase := First (Component_Associations (Expr));
3196 while Present (CCase) loop
3197 Check_Expression (Expression (CCase));
3199 Next (CCase);
3200 end loop;
3202 -- Examine the expression of a postcondition
3204 else pragma Assert (Nam_In (Nam, Name_Postcondition, Name_Refined_Post));
3205 Check_Expression (Expr);
3206 end if;
3207 end Check_Result_And_Post_State;
3209 ------------------------------
3210 -- Check_Unprotected_Access --
3211 ------------------------------
3213 procedure Check_Unprotected_Access
3214 (Context : Node_Id;
3215 Expr : Node_Id)
3217 Cont_Encl_Typ : Entity_Id;
3218 Pref_Encl_Typ : Entity_Id;
3220 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3221 -- Check whether Obj is a private component of a protected object.
3222 -- Return the protected type where the component resides, Empty
3223 -- otherwise.
3225 function Is_Public_Operation return Boolean;
3226 -- Verify that the enclosing operation is callable from outside the
3227 -- protected object, to minimize false positives.
3229 ------------------------------
3230 -- Enclosing_Protected_Type --
3231 ------------------------------
3233 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3234 begin
3235 if Is_Entity_Name (Obj) then
3236 declare
3237 Ent : Entity_Id := Entity (Obj);
3239 begin
3240 -- The object can be a renaming of a private component, use
3241 -- the original record component.
3243 if Is_Prival (Ent) then
3244 Ent := Prival_Link (Ent);
3245 end if;
3247 if Is_Protected_Type (Scope (Ent)) then
3248 return Scope (Ent);
3249 end if;
3250 end;
3251 end if;
3253 -- For indexed and selected components, recursively check the prefix
3255 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3256 return Enclosing_Protected_Type (Prefix (Obj));
3258 -- The object does not denote a protected component
3260 else
3261 return Empty;
3262 end if;
3263 end Enclosing_Protected_Type;
3265 -------------------------
3266 -- Is_Public_Operation --
3267 -------------------------
3269 function Is_Public_Operation return Boolean is
3270 S : Entity_Id;
3271 E : Entity_Id;
3273 begin
3274 S := Current_Scope;
3275 while Present (S) and then S /= Pref_Encl_Typ loop
3276 if Scope (S) = Pref_Encl_Typ then
3277 E := First_Entity (Pref_Encl_Typ);
3278 while Present (E)
3279 and then E /= First_Private_Entity (Pref_Encl_Typ)
3280 loop
3281 if E = S then
3282 return True;
3283 end if;
3285 Next_Entity (E);
3286 end loop;
3287 end if;
3289 S := Scope (S);
3290 end loop;
3292 return False;
3293 end Is_Public_Operation;
3295 -- Start of processing for Check_Unprotected_Access
3297 begin
3298 if Nkind (Expr) = N_Attribute_Reference
3299 and then Attribute_Name (Expr) = Name_Unchecked_Access
3300 then
3301 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3302 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3304 -- Check whether we are trying to export a protected component to a
3305 -- context with an equal or lower access level.
3307 if Present (Pref_Encl_Typ)
3308 and then No (Cont_Encl_Typ)
3309 and then Is_Public_Operation
3310 and then Scope_Depth (Pref_Encl_Typ) >=
3311 Object_Access_Level (Context)
3312 then
3313 Error_Msg_N
3314 ("??possible unprotected access to protected data", Expr);
3315 end if;
3316 end if;
3317 end Check_Unprotected_Access;
3319 ------------------------
3320 -- Collect_Interfaces --
3321 ------------------------
3323 procedure Collect_Interfaces
3324 (T : Entity_Id;
3325 Ifaces_List : out Elist_Id;
3326 Exclude_Parents : Boolean := False;
3327 Use_Full_View : Boolean := True)
3329 procedure Collect (Typ : Entity_Id);
3330 -- Subsidiary subprogram used to traverse the whole list
3331 -- of directly and indirectly implemented interfaces
3333 -------------
3334 -- Collect --
3335 -------------
3337 procedure Collect (Typ : Entity_Id) is
3338 Ancestor : Entity_Id;
3339 Full_T : Entity_Id;
3340 Id : Node_Id;
3341 Iface : Entity_Id;
3343 begin
3344 Full_T := Typ;
3346 -- Handle private types
3348 if Use_Full_View
3349 and then Is_Private_Type (Typ)
3350 and then Present (Full_View (Typ))
3351 then
3352 Full_T := Full_View (Typ);
3353 end if;
3355 -- Include the ancestor if we are generating the whole list of
3356 -- abstract interfaces.
3358 if Etype (Full_T) /= Typ
3360 -- Protect the frontend against wrong sources. For example:
3362 -- package P is
3363 -- type A is tagged null record;
3364 -- type B is new A with private;
3365 -- type C is new A with private;
3366 -- private
3367 -- type B is new C with null record;
3368 -- type C is new B with null record;
3369 -- end P;
3371 and then Etype (Full_T) /= T
3372 then
3373 Ancestor := Etype (Full_T);
3374 Collect (Ancestor);
3376 if Is_Interface (Ancestor) and then not Exclude_Parents then
3377 Append_Unique_Elmt (Ancestor, Ifaces_List);
3378 end if;
3379 end if;
3381 -- Traverse the graph of ancestor interfaces
3383 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3384 Id := First (Abstract_Interface_List (Full_T));
3385 while Present (Id) loop
3386 Iface := Etype (Id);
3388 -- Protect against wrong uses. For example:
3389 -- type I is interface;
3390 -- type O is tagged null record;
3391 -- type Wrong is new I and O with null record; -- ERROR
3393 if Is_Interface (Iface) then
3394 if Exclude_Parents
3395 and then Etype (T) /= T
3396 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3397 then
3398 null;
3399 else
3400 Collect (Iface);
3401 Append_Unique_Elmt (Iface, Ifaces_List);
3402 end if;
3403 end if;
3405 Next (Id);
3406 end loop;
3407 end if;
3408 end Collect;
3410 -- Start of processing for Collect_Interfaces
3412 begin
3413 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3414 Ifaces_List := New_Elmt_List;
3415 Collect (T);
3416 end Collect_Interfaces;
3418 ----------------------------------
3419 -- Collect_Interface_Components --
3420 ----------------------------------
3422 procedure Collect_Interface_Components
3423 (Tagged_Type : Entity_Id;
3424 Components_List : out Elist_Id)
3426 procedure Collect (Typ : Entity_Id);
3427 -- Subsidiary subprogram used to climb to the parents
3429 -------------
3430 -- Collect --
3431 -------------
3433 procedure Collect (Typ : Entity_Id) is
3434 Tag_Comp : Entity_Id;
3435 Parent_Typ : Entity_Id;
3437 begin
3438 -- Handle private types
3440 if Present (Full_View (Etype (Typ))) then
3441 Parent_Typ := Full_View (Etype (Typ));
3442 else
3443 Parent_Typ := Etype (Typ);
3444 end if;
3446 if Parent_Typ /= Typ
3448 -- Protect the frontend against wrong sources. For example:
3450 -- package P is
3451 -- type A is tagged null record;
3452 -- type B is new A with private;
3453 -- type C is new A with private;
3454 -- private
3455 -- type B is new C with null record;
3456 -- type C is new B with null record;
3457 -- end P;
3459 and then Parent_Typ /= Tagged_Type
3460 then
3461 Collect (Parent_Typ);
3462 end if;
3464 -- Collect the components containing tags of secondary dispatch
3465 -- tables.
3467 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3468 while Present (Tag_Comp) loop
3469 pragma Assert (Present (Related_Type (Tag_Comp)));
3470 Append_Elmt (Tag_Comp, Components_List);
3472 Tag_Comp := Next_Tag_Component (Tag_Comp);
3473 end loop;
3474 end Collect;
3476 -- Start of processing for Collect_Interface_Components
3478 begin
3479 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3480 and then Is_Tagged_Type (Tagged_Type));
3482 Components_List := New_Elmt_List;
3483 Collect (Tagged_Type);
3484 end Collect_Interface_Components;
3486 -----------------------------
3487 -- Collect_Interfaces_Info --
3488 -----------------------------
3490 procedure Collect_Interfaces_Info
3491 (T : Entity_Id;
3492 Ifaces_List : out Elist_Id;
3493 Components_List : out Elist_Id;
3494 Tags_List : out Elist_Id)
3496 Comps_List : Elist_Id;
3497 Comp_Elmt : Elmt_Id;
3498 Comp_Iface : Entity_Id;
3499 Iface_Elmt : Elmt_Id;
3500 Iface : Entity_Id;
3502 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3503 -- Search for the secondary tag associated with the interface type
3504 -- Iface that is implemented by T.
3506 ----------------
3507 -- Search_Tag --
3508 ----------------
3510 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3511 ADT : Elmt_Id;
3512 begin
3513 if not Is_CPP_Class (T) then
3514 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3515 else
3516 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3517 end if;
3519 while Present (ADT)
3520 and then Is_Tag (Node (ADT))
3521 and then Related_Type (Node (ADT)) /= Iface
3522 loop
3523 -- Skip secondary dispatch table referencing thunks to user
3524 -- defined primitives covered by this interface.
3526 pragma Assert (Has_Suffix (Node (ADT), 'P'));
3527 Next_Elmt (ADT);
3529 -- Skip secondary dispatch tables of Ada types
3531 if not Is_CPP_Class (T) then
3533 -- Skip secondary dispatch table referencing thunks to
3534 -- predefined primitives.
3536 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
3537 Next_Elmt (ADT);
3539 -- Skip secondary dispatch table referencing user-defined
3540 -- primitives covered by this interface.
3542 pragma Assert (Has_Suffix (Node (ADT), 'D'));
3543 Next_Elmt (ADT);
3545 -- Skip secondary dispatch table referencing predefined
3546 -- primitives.
3548 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
3549 Next_Elmt (ADT);
3550 end if;
3551 end loop;
3553 pragma Assert (Is_Tag (Node (ADT)));
3554 return Node (ADT);
3555 end Search_Tag;
3557 -- Start of processing for Collect_Interfaces_Info
3559 begin
3560 Collect_Interfaces (T, Ifaces_List);
3561 Collect_Interface_Components (T, Comps_List);
3563 -- Search for the record component and tag associated with each
3564 -- interface type of T.
3566 Components_List := New_Elmt_List;
3567 Tags_List := New_Elmt_List;
3569 Iface_Elmt := First_Elmt (Ifaces_List);
3570 while Present (Iface_Elmt) loop
3571 Iface := Node (Iface_Elmt);
3573 -- Associate the primary tag component and the primary dispatch table
3574 -- with all the interfaces that are parents of T
3576 if Is_Ancestor (Iface, T, Use_Full_View => True) then
3577 Append_Elmt (First_Tag_Component (T), Components_List);
3578 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
3580 -- Otherwise search for the tag component and secondary dispatch
3581 -- table of Iface
3583 else
3584 Comp_Elmt := First_Elmt (Comps_List);
3585 while Present (Comp_Elmt) loop
3586 Comp_Iface := Related_Type (Node (Comp_Elmt));
3588 if Comp_Iface = Iface
3589 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
3590 then
3591 Append_Elmt (Node (Comp_Elmt), Components_List);
3592 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
3593 exit;
3594 end if;
3596 Next_Elmt (Comp_Elmt);
3597 end loop;
3598 pragma Assert (Present (Comp_Elmt));
3599 end if;
3601 Next_Elmt (Iface_Elmt);
3602 end loop;
3603 end Collect_Interfaces_Info;
3605 ---------------------
3606 -- Collect_Parents --
3607 ---------------------
3609 procedure Collect_Parents
3610 (T : Entity_Id;
3611 List : out Elist_Id;
3612 Use_Full_View : Boolean := True)
3614 Current_Typ : Entity_Id := T;
3615 Parent_Typ : Entity_Id;
3617 begin
3618 List := New_Elmt_List;
3620 -- No action if the if the type has no parents
3622 if T = Etype (T) then
3623 return;
3624 end if;
3626 loop
3627 Parent_Typ := Etype (Current_Typ);
3629 if Is_Private_Type (Parent_Typ)
3630 and then Present (Full_View (Parent_Typ))
3631 and then Use_Full_View
3632 then
3633 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3634 end if;
3636 Append_Elmt (Parent_Typ, List);
3638 exit when Parent_Typ = Current_Typ;
3639 Current_Typ := Parent_Typ;
3640 end loop;
3641 end Collect_Parents;
3643 ----------------------------------
3644 -- Collect_Primitive_Operations --
3645 ----------------------------------
3647 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
3648 B_Type : constant Entity_Id := Base_Type (T);
3649 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
3650 B_Scope : Entity_Id := Scope (B_Type);
3651 Op_List : Elist_Id;
3652 Formal : Entity_Id;
3653 Is_Prim : Boolean;
3654 Is_Type_In_Pkg : Boolean;
3655 Formal_Derived : Boolean := False;
3656 Id : Entity_Id;
3658 function Match (E : Entity_Id) return Boolean;
3659 -- True if E's base type is B_Type, or E is of an anonymous access type
3660 -- and the base type of its designated type is B_Type.
3662 -----------
3663 -- Match --
3664 -----------
3666 function Match (E : Entity_Id) return Boolean is
3667 Etyp : Entity_Id := Etype (E);
3669 begin
3670 if Ekind (Etyp) = E_Anonymous_Access_Type then
3671 Etyp := Designated_Type (Etyp);
3672 end if;
3674 -- In Ada 2012 a primitive operation may have a formal of an
3675 -- incomplete view of the parent type.
3677 return Base_Type (Etyp) = B_Type
3678 or else
3679 (Ada_Version >= Ada_2012
3680 and then Ekind (Etyp) = E_Incomplete_Type
3681 and then Full_View (Etyp) = B_Type);
3682 end Match;
3684 -- Start of processing for Collect_Primitive_Operations
3686 begin
3687 -- For tagged types, the primitive operations are collected as they
3688 -- are declared, and held in an explicit list which is simply returned.
3690 if Is_Tagged_Type (B_Type) then
3691 return Primitive_Operations (B_Type);
3693 -- An untagged generic type that is a derived type inherits the
3694 -- primitive operations of its parent type. Other formal types only
3695 -- have predefined operators, which are not explicitly represented.
3697 elsif Is_Generic_Type (B_Type) then
3698 if Nkind (B_Decl) = N_Formal_Type_Declaration
3699 and then Nkind (Formal_Type_Definition (B_Decl)) =
3700 N_Formal_Derived_Type_Definition
3701 then
3702 Formal_Derived := True;
3703 else
3704 return New_Elmt_List;
3705 end if;
3706 end if;
3708 Op_List := New_Elmt_List;
3710 if B_Scope = Standard_Standard then
3711 if B_Type = Standard_String then
3712 Append_Elmt (Standard_Op_Concat, Op_List);
3714 elsif B_Type = Standard_Wide_String then
3715 Append_Elmt (Standard_Op_Concatw, Op_List);
3717 else
3718 null;
3719 end if;
3721 -- Locate the primitive subprograms of the type
3723 else
3724 -- The primitive operations appear after the base type, except
3725 -- if the derivation happens within the private part of B_Scope
3726 -- and the type is a private type, in which case both the type
3727 -- and some primitive operations may appear before the base
3728 -- type, and the list of candidates starts after the type.
3730 if In_Open_Scopes (B_Scope)
3731 and then Scope (T) = B_Scope
3732 and then In_Private_Part (B_Scope)
3733 then
3734 Id := Next_Entity (T);
3736 -- In Ada 2012, If the type has an incomplete partial view, there
3737 -- may be primitive operations declared before the full view, so
3738 -- we need to start scanning from the incomplete view, which is
3739 -- earlier on the entity chain.
3741 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
3742 and then Present (Incomplete_View (Parent (B_Type)))
3743 then
3744 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
3746 else
3747 Id := Next_Entity (B_Type);
3748 end if;
3750 -- Set flag if this is a type in a package spec
3752 Is_Type_In_Pkg :=
3753 Is_Package_Or_Generic_Package (B_Scope)
3754 and then
3755 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
3756 N_Package_Body;
3758 while Present (Id) loop
3760 -- Test whether the result type or any of the parameter types of
3761 -- each subprogram following the type match that type when the
3762 -- type is declared in a package spec, is a derived type, or the
3763 -- subprogram is marked as primitive. (The Is_Primitive test is
3764 -- needed to find primitives of nonderived types in declarative
3765 -- parts that happen to override the predefined "=" operator.)
3767 -- Note that generic formal subprograms are not considered to be
3768 -- primitive operations and thus are never inherited.
3770 if Is_Overloadable (Id)
3771 and then (Is_Type_In_Pkg
3772 or else Is_Derived_Type (B_Type)
3773 or else Is_Primitive (Id))
3774 and then Nkind (Parent (Parent (Id)))
3775 not in N_Formal_Subprogram_Declaration
3776 then
3777 Is_Prim := False;
3779 if Match (Id) then
3780 Is_Prim := True;
3782 else
3783 Formal := First_Formal (Id);
3784 while Present (Formal) loop
3785 if Match (Formal) then
3786 Is_Prim := True;
3787 exit;
3788 end if;
3790 Next_Formal (Formal);
3791 end loop;
3792 end if;
3794 -- For a formal derived type, the only primitives are the ones
3795 -- inherited from the parent type. Operations appearing in the
3796 -- package declaration are not primitive for it.
3798 if Is_Prim
3799 and then (not Formal_Derived or else Present (Alias (Id)))
3800 then
3801 -- In the special case of an equality operator aliased to
3802 -- an overriding dispatching equality belonging to the same
3803 -- type, we don't include it in the list of primitives.
3804 -- This avoids inheriting multiple equality operators when
3805 -- deriving from untagged private types whose full type is
3806 -- tagged, which can otherwise cause ambiguities. Note that
3807 -- this should only happen for this kind of untagged parent
3808 -- type, since normally dispatching operations are inherited
3809 -- using the type's Primitive_Operations list.
3811 if Chars (Id) = Name_Op_Eq
3812 and then Is_Dispatching_Operation (Id)
3813 and then Present (Alias (Id))
3814 and then Present (Overridden_Operation (Alias (Id)))
3815 and then Base_Type (Etype (First_Entity (Id))) =
3816 Base_Type (Etype (First_Entity (Alias (Id))))
3817 then
3818 null;
3820 -- Include the subprogram in the list of primitives
3822 else
3823 Append_Elmt (Id, Op_List);
3824 end if;
3825 end if;
3826 end if;
3828 Next_Entity (Id);
3830 -- For a type declared in System, some of its operations may
3831 -- appear in the target-specific extension to System.
3833 if No (Id)
3834 and then B_Scope = RTU_Entity (System)
3835 and then Present_System_Aux
3836 then
3837 B_Scope := System_Aux_Id;
3838 Id := First_Entity (System_Aux_Id);
3839 end if;
3840 end loop;
3841 end if;
3843 return Op_List;
3844 end Collect_Primitive_Operations;
3846 -----------------------------------
3847 -- Compile_Time_Constraint_Error --
3848 -----------------------------------
3850 function Compile_Time_Constraint_Error
3851 (N : Node_Id;
3852 Msg : String;
3853 Ent : Entity_Id := Empty;
3854 Loc : Source_Ptr := No_Location;
3855 Warn : Boolean := False) return Node_Id
3857 Msgc : String (1 .. Msg'Length + 3);
3858 -- Copy of message, with room for possible ?? or << and ! at end
3860 Msgl : Natural;
3861 Wmsg : Boolean;
3862 Eloc : Source_Ptr;
3864 -- Start of processing for Compile_Time_Constraint_Error
3866 begin
3867 -- If this is a warning, convert it into an error if we are in code
3868 -- subject to SPARK_Mode being set ON.
3870 Error_Msg_Warn := SPARK_Mode /= On;
3872 -- A static constraint error in an instance body is not a fatal error.
3873 -- we choose to inhibit the message altogether, because there is no
3874 -- obvious node (for now) on which to post it. On the other hand the
3875 -- offending node must be replaced with a constraint_error in any case.
3877 -- No messages are generated if we already posted an error on this node
3879 if not Error_Posted (N) then
3880 if Loc /= No_Location then
3881 Eloc := Loc;
3882 else
3883 Eloc := Sloc (N);
3884 end if;
3886 -- Copy message to Msgc, converting any ? in the message into
3887 -- < instead, so that we have an error in GNATprove mode.
3889 Msgl := Msg'Length;
3891 for J in 1 .. Msgl loop
3892 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
3893 Msgc (J) := '<';
3894 else
3895 Msgc (J) := Msg (J);
3896 end if;
3897 end loop;
3899 -- Message is a warning, even in Ada 95 case
3901 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
3902 Wmsg := True;
3904 -- In Ada 83, all messages are warnings. In the private part and
3905 -- the body of an instance, constraint_checks are only warnings.
3906 -- We also make this a warning if the Warn parameter is set.
3908 elsif Warn
3909 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
3910 then
3911 Msgl := Msgl + 1;
3912 Msgc (Msgl) := '<';
3913 Msgl := Msgl + 1;
3914 Msgc (Msgl) := '<';
3915 Wmsg := True;
3917 elsif In_Instance_Not_Visible then
3918 Msgl := Msgl + 1;
3919 Msgc (Msgl) := '<';
3920 Msgl := Msgl + 1;
3921 Msgc (Msgl) := '<';
3922 Wmsg := True;
3924 -- Otherwise we have a real error message (Ada 95 static case)
3925 -- and we make this an unconditional message. Note that in the
3926 -- warning case we do not make the message unconditional, it seems
3927 -- quite reasonable to delete messages like this (about exceptions
3928 -- that will be raised) in dead code.
3930 else
3931 Wmsg := False;
3932 Msgl := Msgl + 1;
3933 Msgc (Msgl) := '!';
3934 end if;
3936 -- One more test, skip the warning if the related expression is
3937 -- statically unevaluated, since we don't want to warn about what
3938 -- will happen when something is evaluated if it never will be
3939 -- evaluated.
3941 if not Is_Statically_Unevaluated (N) then
3942 Error_Msg_Warn := SPARK_Mode /= On;
3944 if Present (Ent) then
3945 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
3946 else
3947 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
3948 end if;
3950 if Wmsg then
3952 -- Check whether the context is an Init_Proc
3954 if Inside_Init_Proc then
3955 declare
3956 Conc_Typ : constant Entity_Id :=
3957 Corresponding_Concurrent_Type
3958 (Entity (Parameter_Type (First
3959 (Parameter_Specifications
3960 (Parent (Current_Scope))))));
3962 begin
3963 -- Don't complain if the corresponding concurrent type
3964 -- doesn't come from source (i.e. a single task/protected
3965 -- object).
3967 if Present (Conc_Typ)
3968 and then not Comes_From_Source (Conc_Typ)
3969 then
3970 Error_Msg_NEL
3971 ("\& [<<", N, Standard_Constraint_Error, Eloc);
3973 else
3974 if GNATprove_Mode then
3975 Error_Msg_NEL
3976 ("\& would have been raised for objects of this "
3977 & "type", N, Standard_Constraint_Error, Eloc);
3978 else
3979 Error_Msg_NEL
3980 ("\& will be raised for objects of this type??",
3981 N, Standard_Constraint_Error, Eloc);
3982 end if;
3983 end if;
3984 end;
3986 else
3987 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
3988 end if;
3990 else
3991 Error_Msg ("\static expression fails Constraint_Check", Eloc);
3992 Set_Error_Posted (N);
3993 end if;
3994 end if;
3995 end if;
3997 return N;
3998 end Compile_Time_Constraint_Error;
4000 -----------------------
4001 -- Conditional_Delay --
4002 -----------------------
4004 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4005 begin
4006 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4007 Set_Has_Delayed_Freeze (New_Ent);
4008 end if;
4009 end Conditional_Delay;
4011 ----------------------------
4012 -- Contains_Refined_State --
4013 ----------------------------
4015 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4016 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4017 -- Determine whether a dependency list mentions a state with a visible
4018 -- refinement.
4020 function Has_State_In_Global (List : Node_Id) return Boolean;
4021 -- Determine whether a global list mentions a state with a visible
4022 -- refinement.
4024 function Is_Refined_State (Item : Node_Id) return Boolean;
4025 -- Determine whether Item is a reference to an abstract state with a
4026 -- visible refinement.
4028 -----------------------------
4029 -- Has_State_In_Dependency --
4030 -----------------------------
4032 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4033 Clause : Node_Id;
4034 Output : Node_Id;
4036 begin
4037 -- A null dependency list does not mention any states
4039 if Nkind (List) = N_Null then
4040 return False;
4042 -- Dependency clauses appear as component associations of an
4043 -- aggregate.
4045 elsif Nkind (List) = N_Aggregate
4046 and then Present (Component_Associations (List))
4047 then
4048 Clause := First (Component_Associations (List));
4049 while Present (Clause) loop
4051 -- Inspect the outputs of a dependency clause
4053 Output := First (Choices (Clause));
4054 while Present (Output) loop
4055 if Is_Refined_State (Output) then
4056 return True;
4057 end if;
4059 Next (Output);
4060 end loop;
4062 -- Inspect the outputs of a dependency clause
4064 if Is_Refined_State (Expression (Clause)) then
4065 return True;
4066 end if;
4068 Next (Clause);
4069 end loop;
4071 -- If we get here, then none of the dependency clauses mention a
4072 -- state with visible refinement.
4074 return False;
4076 -- An illegal pragma managed to sneak in
4078 else
4079 raise Program_Error;
4080 end if;
4081 end Has_State_In_Dependency;
4083 -------------------------
4084 -- Has_State_In_Global --
4085 -------------------------
4087 function Has_State_In_Global (List : Node_Id) return Boolean is
4088 Item : Node_Id;
4090 begin
4091 -- A null global list does not mention any states
4093 if Nkind (List) = N_Null then
4094 return False;
4096 -- Simple global list or moded global list declaration
4098 elsif Nkind (List) = N_Aggregate then
4100 -- The declaration of a simple global list appear as a collection
4101 -- of expressions.
4103 if Present (Expressions (List)) then
4104 Item := First (Expressions (List));
4105 while Present (Item) loop
4106 if Is_Refined_State (Item) then
4107 return True;
4108 end if;
4110 Next (Item);
4111 end loop;
4113 -- The declaration of a moded global list appears as a collection
4114 -- of component associations where individual choices denote
4115 -- modes.
4117 else
4118 Item := First (Component_Associations (List));
4119 while Present (Item) loop
4120 if Has_State_In_Global (Expression (Item)) then
4121 return True;
4122 end if;
4124 Next (Item);
4125 end loop;
4126 end if;
4128 -- If we get here, then the simple/moded global list did not
4129 -- mention any states with a visible refinement.
4131 return False;
4133 -- Single global item declaration
4135 elsif Is_Entity_Name (List) then
4136 return Is_Refined_State (List);
4138 -- An illegal pragma managed to sneak in
4140 else
4141 raise Program_Error;
4142 end if;
4143 end Has_State_In_Global;
4145 ----------------------
4146 -- Is_Refined_State --
4147 ----------------------
4149 function Is_Refined_State (Item : Node_Id) return Boolean is
4150 Elmt : Node_Id;
4151 Item_Id : Entity_Id;
4153 begin
4154 if Nkind (Item) = N_Null then
4155 return False;
4157 -- States cannot be subject to attribute 'Result. This case arises
4158 -- in dependency relations.
4160 elsif Nkind (Item) = N_Attribute_Reference
4161 and then Attribute_Name (Item) = Name_Result
4162 then
4163 return False;
4165 -- Multiple items appear as an aggregate. This case arises in
4166 -- dependency relations.
4168 elsif Nkind (Item) = N_Aggregate
4169 and then Present (Expressions (Item))
4170 then
4171 Elmt := First (Expressions (Item));
4172 while Present (Elmt) loop
4173 if Is_Refined_State (Elmt) then
4174 return True;
4175 end if;
4177 Next (Elmt);
4178 end loop;
4180 -- If we get here, then none of the inputs or outputs reference a
4181 -- state with visible refinement.
4183 return False;
4185 -- Single item
4187 else
4188 Item_Id := Entity_Of (Item);
4190 return
4191 Present (Item_Id)
4192 and then Ekind (Item_Id) = E_Abstract_State
4193 and then Has_Visible_Refinement (Item_Id);
4194 end if;
4195 end Is_Refined_State;
4197 -- Local variables
4199 Arg : constant Node_Id :=
4200 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4201 Nam : constant Name_Id := Pragma_Name (Prag);
4203 -- Start of processing for Contains_Refined_State
4205 begin
4206 if Nam = Name_Depends then
4207 return Has_State_In_Dependency (Arg);
4209 else pragma Assert (Nam = Name_Global);
4210 return Has_State_In_Global (Arg);
4211 end if;
4212 end Contains_Refined_State;
4214 -------------------------
4215 -- Copy_Component_List --
4216 -------------------------
4218 function Copy_Component_List
4219 (R_Typ : Entity_Id;
4220 Loc : Source_Ptr) return List_Id
4222 Comp : Node_Id;
4223 Comps : constant List_Id := New_List;
4225 begin
4226 Comp := First_Component (Underlying_Type (R_Typ));
4227 while Present (Comp) loop
4228 if Comes_From_Source (Comp) then
4229 declare
4230 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4231 begin
4232 Append_To (Comps,
4233 Make_Component_Declaration (Loc,
4234 Defining_Identifier =>
4235 Make_Defining_Identifier (Loc, Chars (Comp)),
4236 Component_Definition =>
4237 New_Copy_Tree
4238 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4239 end;
4240 end if;
4242 Next_Component (Comp);
4243 end loop;
4245 return Comps;
4246 end Copy_Component_List;
4248 -------------------------
4249 -- Copy_Parameter_List --
4250 -------------------------
4252 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4253 Loc : constant Source_Ptr := Sloc (Subp_Id);
4254 Plist : List_Id;
4255 Formal : Entity_Id;
4257 begin
4258 if No (First_Formal (Subp_Id)) then
4259 return No_List;
4260 else
4261 Plist := New_List;
4262 Formal := First_Formal (Subp_Id);
4263 while Present (Formal) loop
4264 Append
4265 (Make_Parameter_Specification (Loc,
4266 Defining_Identifier =>
4267 Make_Defining_Identifier (Sloc (Formal),
4268 Chars => Chars (Formal)),
4269 In_Present => In_Present (Parent (Formal)),
4270 Out_Present => Out_Present (Parent (Formal)),
4271 Parameter_Type =>
4272 New_Occurrence_Of (Etype (Formal), Loc),
4273 Expression =>
4274 New_Copy_Tree (Expression (Parent (Formal)))),
4275 Plist);
4277 Next_Formal (Formal);
4278 end loop;
4279 end if;
4281 return Plist;
4282 end Copy_Parameter_List;
4284 --------------------------------
4285 -- Corresponding_Generic_Type --
4286 --------------------------------
4288 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4289 Inst : Entity_Id;
4290 Gen : Entity_Id;
4291 Typ : Entity_Id;
4293 begin
4294 if not Is_Generic_Actual_Type (T) then
4295 return Any_Type;
4297 -- If the actual is the actual of an enclosing instance, resolution
4298 -- was correct in the generic.
4300 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4301 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4302 and then
4303 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4304 then
4305 return Any_Type;
4307 else
4308 Inst := Scope (T);
4310 if Is_Wrapper_Package (Inst) then
4311 Inst := Related_Instance (Inst);
4312 end if;
4314 Gen :=
4315 Generic_Parent
4316 (Specification (Unit_Declaration_Node (Inst)));
4318 -- Generic actual has the same name as the corresponding formal
4320 Typ := First_Entity (Gen);
4321 while Present (Typ) loop
4322 if Chars (Typ) = Chars (T) then
4323 return Typ;
4324 end if;
4326 Next_Entity (Typ);
4327 end loop;
4329 return Any_Type;
4330 end if;
4331 end Corresponding_Generic_Type;
4333 --------------------
4334 -- Current_Entity --
4335 --------------------
4337 -- The currently visible definition for a given identifier is the
4338 -- one most chained at the start of the visibility chain, i.e. the
4339 -- one that is referenced by the Node_Id value of the name of the
4340 -- given identifier.
4342 function Current_Entity (N : Node_Id) return Entity_Id is
4343 begin
4344 return Get_Name_Entity_Id (Chars (N));
4345 end Current_Entity;
4347 -----------------------------
4348 -- Current_Entity_In_Scope --
4349 -----------------------------
4351 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4352 E : Entity_Id;
4353 CS : constant Entity_Id := Current_Scope;
4355 Transient_Case : constant Boolean := Scope_Is_Transient;
4357 begin
4358 E := Get_Name_Entity_Id (Chars (N));
4359 while Present (E)
4360 and then Scope (E) /= CS
4361 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4362 loop
4363 E := Homonym (E);
4364 end loop;
4366 return E;
4367 end Current_Entity_In_Scope;
4369 -------------------
4370 -- Current_Scope --
4371 -------------------
4373 function Current_Scope return Entity_Id is
4374 begin
4375 if Scope_Stack.Last = -1 then
4376 return Standard_Standard;
4377 else
4378 declare
4379 C : constant Entity_Id :=
4380 Scope_Stack.Table (Scope_Stack.Last).Entity;
4381 begin
4382 if Present (C) then
4383 return C;
4384 else
4385 return Standard_Standard;
4386 end if;
4387 end;
4388 end if;
4389 end Current_Scope;
4391 ------------------------
4392 -- Current_Subprogram --
4393 ------------------------
4395 function Current_Subprogram return Entity_Id is
4396 Scop : constant Entity_Id := Current_Scope;
4397 begin
4398 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
4399 return Scop;
4400 else
4401 return Enclosing_Subprogram (Scop);
4402 end if;
4403 end Current_Subprogram;
4405 ----------------------------------
4406 -- Deepest_Type_Access_Level --
4407 ----------------------------------
4409 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4410 begin
4411 if Ekind (Typ) = E_Anonymous_Access_Type
4412 and then not Is_Local_Anonymous_Access (Typ)
4413 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4414 then
4415 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4416 -- access type.
4418 return
4419 Scope_Depth (Enclosing_Dynamic_Scope
4420 (Defining_Identifier
4421 (Associated_Node_For_Itype (Typ))));
4423 -- For generic formal type, return Int'Last (infinite).
4424 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4426 elsif Is_Generic_Type (Root_Type (Typ)) then
4427 return UI_From_Int (Int'Last);
4429 else
4430 return Type_Access_Level (Typ);
4431 end if;
4432 end Deepest_Type_Access_Level;
4434 ---------------------
4435 -- Defining_Entity --
4436 ---------------------
4438 function Defining_Entity (N : Node_Id) return Entity_Id is
4439 K : constant Node_Kind := Nkind (N);
4440 Err : Entity_Id := Empty;
4442 begin
4443 case K is
4444 when
4445 N_Subprogram_Declaration |
4446 N_Abstract_Subprogram_Declaration |
4447 N_Subprogram_Body |
4448 N_Package_Declaration |
4449 N_Subprogram_Renaming_Declaration |
4450 N_Subprogram_Body_Stub |
4451 N_Generic_Subprogram_Declaration |
4452 N_Generic_Package_Declaration |
4453 N_Formal_Subprogram_Declaration |
4454 N_Expression_Function
4456 return Defining_Entity (Specification (N));
4458 when
4459 N_Component_Declaration |
4460 N_Defining_Program_Unit_Name |
4461 N_Discriminant_Specification |
4462 N_Entry_Body |
4463 N_Entry_Declaration |
4464 N_Entry_Index_Specification |
4465 N_Exception_Declaration |
4466 N_Exception_Renaming_Declaration |
4467 N_Formal_Object_Declaration |
4468 N_Formal_Package_Declaration |
4469 N_Formal_Type_Declaration |
4470 N_Full_Type_Declaration |
4471 N_Implicit_Label_Declaration |
4472 N_Incomplete_Type_Declaration |
4473 N_Loop_Parameter_Specification |
4474 N_Number_Declaration |
4475 N_Object_Declaration |
4476 N_Object_Renaming_Declaration |
4477 N_Package_Body_Stub |
4478 N_Parameter_Specification |
4479 N_Private_Extension_Declaration |
4480 N_Private_Type_Declaration |
4481 N_Protected_Body |
4482 N_Protected_Body_Stub |
4483 N_Protected_Type_Declaration |
4484 N_Single_Protected_Declaration |
4485 N_Single_Task_Declaration |
4486 N_Subtype_Declaration |
4487 N_Task_Body |
4488 N_Task_Body_Stub |
4489 N_Task_Type_Declaration
4491 return Defining_Identifier (N);
4493 when N_Subunit =>
4494 return Defining_Entity (Proper_Body (N));
4496 when
4497 N_Function_Instantiation |
4498 N_Function_Specification |
4499 N_Generic_Function_Renaming_Declaration |
4500 N_Generic_Package_Renaming_Declaration |
4501 N_Generic_Procedure_Renaming_Declaration |
4502 N_Package_Body |
4503 N_Package_Instantiation |
4504 N_Package_Renaming_Declaration |
4505 N_Package_Specification |
4506 N_Procedure_Instantiation |
4507 N_Procedure_Specification
4509 declare
4510 Nam : constant Node_Id := Defining_Unit_Name (N);
4512 begin
4513 if Nkind (Nam) in N_Entity then
4514 return Nam;
4516 -- For Error, make up a name and attach to declaration
4517 -- so we can continue semantic analysis
4519 elsif Nam = Error then
4520 Err := Make_Temporary (Sloc (N), 'T');
4521 Set_Defining_Unit_Name (N, Err);
4523 return Err;
4525 -- If not an entity, get defining identifier
4527 else
4528 return Defining_Identifier (Nam);
4529 end if;
4530 end;
4532 when
4533 N_Block_Statement |
4534 N_Loop_Statement
4536 return Entity (Identifier (N));
4538 when others =>
4539 raise Program_Error;
4541 end case;
4542 end Defining_Entity;
4544 --------------------------
4545 -- Denotes_Discriminant --
4546 --------------------------
4548 function Denotes_Discriminant
4549 (N : Node_Id;
4550 Check_Concurrent : Boolean := False) return Boolean
4552 E : Entity_Id;
4554 begin
4555 if not Is_Entity_Name (N) or else No (Entity (N)) then
4556 return False;
4557 else
4558 E := Entity (N);
4559 end if;
4561 -- If we are checking for a protected type, the discriminant may have
4562 -- been rewritten as the corresponding discriminal of the original type
4563 -- or of the corresponding concurrent record, depending on whether we
4564 -- are in the spec or body of the protected type.
4566 return Ekind (E) = E_Discriminant
4567 or else
4568 (Check_Concurrent
4569 and then Ekind (E) = E_In_Parameter
4570 and then Present (Discriminal_Link (E))
4571 and then
4572 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
4573 or else
4574 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
4576 end Denotes_Discriminant;
4578 -------------------------
4579 -- Denotes_Same_Object --
4580 -------------------------
4582 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
4583 Obj1 : Node_Id := A1;
4584 Obj2 : Node_Id := A2;
4586 function Has_Prefix (N : Node_Id) return Boolean;
4587 -- Return True if N has attribute Prefix
4589 function Is_Renaming (N : Node_Id) return Boolean;
4590 -- Return true if N names a renaming entity
4592 function Is_Valid_Renaming (N : Node_Id) return Boolean;
4593 -- For renamings, return False if the prefix of any dereference within
4594 -- the renamed object_name is a variable, or any expression within the
4595 -- renamed object_name contains references to variables or calls on
4596 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4598 ----------------
4599 -- Has_Prefix --
4600 ----------------
4602 function Has_Prefix (N : Node_Id) return Boolean is
4603 begin
4604 return
4605 Nkind_In (N,
4606 N_Attribute_Reference,
4607 N_Expanded_Name,
4608 N_Explicit_Dereference,
4609 N_Indexed_Component,
4610 N_Reference,
4611 N_Selected_Component,
4612 N_Slice);
4613 end Has_Prefix;
4615 -----------------
4616 -- Is_Renaming --
4617 -----------------
4619 function Is_Renaming (N : Node_Id) return Boolean is
4620 begin
4621 return Is_Entity_Name (N)
4622 and then Present (Renamed_Entity (Entity (N)));
4623 end Is_Renaming;
4625 -----------------------
4626 -- Is_Valid_Renaming --
4627 -----------------------
4629 function Is_Valid_Renaming (N : Node_Id) return Boolean is
4631 function Check_Renaming (N : Node_Id) return Boolean;
4632 -- Recursive function used to traverse all the prefixes of N
4634 function Check_Renaming (N : Node_Id) return Boolean is
4635 begin
4636 if Is_Renaming (N)
4637 and then not Check_Renaming (Renamed_Entity (Entity (N)))
4638 then
4639 return False;
4640 end if;
4642 if Nkind (N) = N_Indexed_Component then
4643 declare
4644 Indx : Node_Id;
4646 begin
4647 Indx := First (Expressions (N));
4648 while Present (Indx) loop
4649 if not Is_OK_Static_Expression (Indx) then
4650 return False;
4651 end if;
4653 Next_Index (Indx);
4654 end loop;
4655 end;
4656 end if;
4658 if Has_Prefix (N) then
4659 declare
4660 P : constant Node_Id := Prefix (N);
4662 begin
4663 if Nkind (N) = N_Explicit_Dereference
4664 and then Is_Variable (P)
4665 then
4666 return False;
4668 elsif Is_Entity_Name (P)
4669 and then Ekind (Entity (P)) = E_Function
4670 then
4671 return False;
4673 elsif Nkind (P) = N_Function_Call then
4674 return False;
4675 end if;
4677 -- Recursion to continue traversing the prefix of the
4678 -- renaming expression
4680 return Check_Renaming (P);
4681 end;
4682 end if;
4684 return True;
4685 end Check_Renaming;
4687 -- Start of processing for Is_Valid_Renaming
4689 begin
4690 return Check_Renaming (N);
4691 end Is_Valid_Renaming;
4693 -- Start of processing for Denotes_Same_Object
4695 begin
4696 -- Both names statically denote the same stand-alone object or parameter
4697 -- (RM 6.4.1(6.5/3))
4699 if Is_Entity_Name (Obj1)
4700 and then Is_Entity_Name (Obj2)
4701 and then Entity (Obj1) = Entity (Obj2)
4702 then
4703 return True;
4704 end if;
4706 -- For renamings, the prefix of any dereference within the renamed
4707 -- object_name is not a variable, and any expression within the
4708 -- renamed object_name contains no references to variables nor
4709 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4711 if Is_Renaming (Obj1) then
4712 if Is_Valid_Renaming (Obj1) then
4713 Obj1 := Renamed_Entity (Entity (Obj1));
4714 else
4715 return False;
4716 end if;
4717 end if;
4719 if Is_Renaming (Obj2) then
4720 if Is_Valid_Renaming (Obj2) then
4721 Obj2 := Renamed_Entity (Entity (Obj2));
4722 else
4723 return False;
4724 end if;
4725 end if;
4727 -- No match if not same node kind (such cases are handled by
4728 -- Denotes_Same_Prefix)
4730 if Nkind (Obj1) /= Nkind (Obj2) then
4731 return False;
4733 -- After handling valid renamings, one of the two names statically
4734 -- denoted a renaming declaration whose renamed object_name is known
4735 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4737 elsif Is_Entity_Name (Obj1) then
4738 if Is_Entity_Name (Obj2) then
4739 return Entity (Obj1) = Entity (Obj2);
4740 else
4741 return False;
4742 end if;
4744 -- Both names are selected_components, their prefixes are known to
4745 -- denote the same object, and their selector_names denote the same
4746 -- component (RM 6.4.1(6.6/3)
4748 elsif Nkind (Obj1) = N_Selected_Component then
4749 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4750 and then
4751 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
4753 -- Both names are dereferences and the dereferenced names are known to
4754 -- denote the same object (RM 6.4.1(6.7/3))
4756 elsif Nkind (Obj1) = N_Explicit_Dereference then
4757 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
4759 -- Both names are indexed_components, their prefixes are known to denote
4760 -- the same object, and each of the pairs of corresponding index values
4761 -- are either both static expressions with the same static value or both
4762 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4764 elsif Nkind (Obj1) = N_Indexed_Component then
4765 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
4766 return False;
4767 else
4768 declare
4769 Indx1 : Node_Id;
4770 Indx2 : Node_Id;
4772 begin
4773 Indx1 := First (Expressions (Obj1));
4774 Indx2 := First (Expressions (Obj2));
4775 while Present (Indx1) loop
4777 -- Indexes must denote the same static value or same object
4779 if Is_OK_Static_Expression (Indx1) then
4780 if not Is_OK_Static_Expression (Indx2) then
4781 return False;
4783 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
4784 return False;
4785 end if;
4787 elsif not Denotes_Same_Object (Indx1, Indx2) then
4788 return False;
4789 end if;
4791 Next (Indx1);
4792 Next (Indx2);
4793 end loop;
4795 return True;
4796 end;
4797 end if;
4799 -- Both names are slices, their prefixes are known to denote the same
4800 -- object, and the two slices have statically matching index constraints
4801 -- (RM 6.4.1(6.9/3))
4803 elsif Nkind (Obj1) = N_Slice
4804 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4805 then
4806 declare
4807 Lo1, Lo2, Hi1, Hi2 : Node_Id;
4809 begin
4810 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
4811 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
4813 -- Check whether bounds are statically identical. There is no
4814 -- attempt to detect partial overlap of slices.
4816 return Denotes_Same_Object (Lo1, Lo2)
4817 and then
4818 Denotes_Same_Object (Hi1, Hi2);
4819 end;
4821 -- In the recursion, literals appear as indexes
4823 elsif Nkind (Obj1) = N_Integer_Literal
4824 and then
4825 Nkind (Obj2) = N_Integer_Literal
4826 then
4827 return Intval (Obj1) = Intval (Obj2);
4829 else
4830 return False;
4831 end if;
4832 end Denotes_Same_Object;
4834 -------------------------
4835 -- Denotes_Same_Prefix --
4836 -------------------------
4838 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
4840 begin
4841 if Is_Entity_Name (A1) then
4842 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
4843 and then not Is_Access_Type (Etype (A1))
4844 then
4845 return Denotes_Same_Object (A1, Prefix (A2))
4846 or else Denotes_Same_Prefix (A1, Prefix (A2));
4847 else
4848 return False;
4849 end if;
4851 elsif Is_Entity_Name (A2) then
4852 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
4854 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
4855 and then
4856 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
4857 then
4858 declare
4859 Root1, Root2 : Node_Id;
4860 Depth1, Depth2 : Int := 0;
4862 begin
4863 Root1 := Prefix (A1);
4864 while not Is_Entity_Name (Root1) loop
4865 if not Nkind_In
4866 (Root1, N_Selected_Component, N_Indexed_Component)
4867 then
4868 return False;
4869 else
4870 Root1 := Prefix (Root1);
4871 end if;
4873 Depth1 := Depth1 + 1;
4874 end loop;
4876 Root2 := Prefix (A2);
4877 while not Is_Entity_Name (Root2) loop
4878 if not Nkind_In (Root2, N_Selected_Component,
4879 N_Indexed_Component)
4880 then
4881 return False;
4882 else
4883 Root2 := Prefix (Root2);
4884 end if;
4886 Depth2 := Depth2 + 1;
4887 end loop;
4889 -- If both have the same depth and they do not denote the same
4890 -- object, they are disjoint and no warning is needed.
4892 if Depth1 = Depth2 then
4893 return False;
4895 elsif Depth1 > Depth2 then
4896 Root1 := Prefix (A1);
4897 for J in 1 .. Depth1 - Depth2 - 1 loop
4898 Root1 := Prefix (Root1);
4899 end loop;
4901 return Denotes_Same_Object (Root1, A2);
4903 else
4904 Root2 := Prefix (A2);
4905 for J in 1 .. Depth2 - Depth1 - 1 loop
4906 Root2 := Prefix (Root2);
4907 end loop;
4909 return Denotes_Same_Object (A1, Root2);
4910 end if;
4911 end;
4913 else
4914 return False;
4915 end if;
4916 end Denotes_Same_Prefix;
4918 ----------------------
4919 -- Denotes_Variable --
4920 ----------------------
4922 function Denotes_Variable (N : Node_Id) return Boolean is
4923 begin
4924 return Is_Variable (N) and then Paren_Count (N) = 0;
4925 end Denotes_Variable;
4927 -----------------------------
4928 -- Depends_On_Discriminant --
4929 -----------------------------
4931 function Depends_On_Discriminant (N : Node_Id) return Boolean is
4932 L : Node_Id;
4933 H : Node_Id;
4935 begin
4936 Get_Index_Bounds (N, L, H);
4937 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
4938 end Depends_On_Discriminant;
4940 -------------------------
4941 -- Designate_Same_Unit --
4942 -------------------------
4944 function Designate_Same_Unit
4945 (Name1 : Node_Id;
4946 Name2 : Node_Id) return Boolean
4948 K1 : constant Node_Kind := Nkind (Name1);
4949 K2 : constant Node_Kind := Nkind (Name2);
4951 function Prefix_Node (N : Node_Id) return Node_Id;
4952 -- Returns the parent unit name node of a defining program unit name
4953 -- or the prefix if N is a selected component or an expanded name.
4955 function Select_Node (N : Node_Id) return Node_Id;
4956 -- Returns the defining identifier node of a defining program unit
4957 -- name or the selector node if N is a selected component or an
4958 -- expanded name.
4960 -----------------
4961 -- Prefix_Node --
4962 -----------------
4964 function Prefix_Node (N : Node_Id) return Node_Id is
4965 begin
4966 if Nkind (N) = N_Defining_Program_Unit_Name then
4967 return Name (N);
4968 else
4969 return Prefix (N);
4970 end if;
4971 end Prefix_Node;
4973 -----------------
4974 -- Select_Node --
4975 -----------------
4977 function Select_Node (N : Node_Id) return Node_Id is
4978 begin
4979 if Nkind (N) = N_Defining_Program_Unit_Name then
4980 return Defining_Identifier (N);
4981 else
4982 return Selector_Name (N);
4983 end if;
4984 end Select_Node;
4986 -- Start of processing for Designate_Next_Unit
4988 begin
4989 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
4990 and then
4991 (K2 = N_Identifier or else K2 = N_Defining_Identifier)
4992 then
4993 return Chars (Name1) = Chars (Name2);
4995 elsif
4996 (K1 = N_Expanded_Name or else
4997 K1 = N_Selected_Component or else
4998 K1 = N_Defining_Program_Unit_Name)
4999 and then
5000 (K2 = N_Expanded_Name or else
5001 K2 = N_Selected_Component or else
5002 K2 = N_Defining_Program_Unit_Name)
5003 then
5004 return
5005 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5006 and then
5007 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5009 else
5010 return False;
5011 end if;
5012 end Designate_Same_Unit;
5014 ------------------------------------------
5015 -- function Dynamic_Accessibility_Level --
5016 ------------------------------------------
5018 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5019 E : Entity_Id;
5020 Loc : constant Source_Ptr := Sloc (Expr);
5022 function Make_Level_Literal (Level : Uint) return Node_Id;
5023 -- Construct an integer literal representing an accessibility level
5024 -- with its type set to Natural.
5026 ------------------------
5027 -- Make_Level_Literal --
5028 ------------------------
5030 function Make_Level_Literal (Level : Uint) return Node_Id is
5031 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5032 begin
5033 Set_Etype (Result, Standard_Natural);
5034 return Result;
5035 end Make_Level_Literal;
5037 -- Start of processing for Dynamic_Accessibility_Level
5039 begin
5040 if Is_Entity_Name (Expr) then
5041 E := Entity (Expr);
5043 if Present (Renamed_Object (E)) then
5044 return Dynamic_Accessibility_Level (Renamed_Object (E));
5045 end if;
5047 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5048 if Present (Extra_Accessibility (E)) then
5049 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5050 end if;
5051 end if;
5052 end if;
5054 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5056 case Nkind (Expr) is
5058 -- For access discriminant, the level of the enclosing object
5060 when N_Selected_Component =>
5061 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5062 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5063 E_Anonymous_Access_Type
5064 then
5065 return Make_Level_Literal (Object_Access_Level (Expr));
5066 end if;
5068 when N_Attribute_Reference =>
5069 case Get_Attribute_Id (Attribute_Name (Expr)) is
5071 -- For X'Access, the level of the prefix X
5073 when Attribute_Access =>
5074 return Make_Level_Literal
5075 (Object_Access_Level (Prefix (Expr)));
5077 -- Treat the unchecked attributes as library-level
5079 when Attribute_Unchecked_Access |
5080 Attribute_Unrestricted_Access =>
5081 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5083 -- No other access-valued attributes
5085 when others =>
5086 raise Program_Error;
5087 end case;
5089 when N_Allocator =>
5091 -- Unimplemented: depends on context. As an actual parameter where
5092 -- formal type is anonymous, use
5093 -- Scope_Depth (Current_Scope) + 1.
5094 -- For other cases, see 3.10.2(14/3) and following. ???
5096 null;
5098 when N_Type_Conversion =>
5099 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5101 -- Handle type conversions introduced for a rename of an
5102 -- Ada 2012 stand-alone object of an anonymous access type.
5104 return Dynamic_Accessibility_Level (Expression (Expr));
5105 end if;
5107 when others =>
5108 null;
5109 end case;
5111 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5112 end Dynamic_Accessibility_Level;
5114 -----------------------------------
5115 -- Effective_Extra_Accessibility --
5116 -----------------------------------
5118 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5119 begin
5120 if Present (Renamed_Object (Id))
5121 and then Is_Entity_Name (Renamed_Object (Id))
5122 then
5123 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5124 else
5125 return Extra_Accessibility (Id);
5126 end if;
5127 end Effective_Extra_Accessibility;
5129 -----------------------------
5130 -- Effective_Reads_Enabled --
5131 -----------------------------
5133 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5134 begin
5135 return Has_Enabled_Property (Id, Name_Effective_Reads);
5136 end Effective_Reads_Enabled;
5138 ------------------------------
5139 -- Effective_Writes_Enabled --
5140 ------------------------------
5142 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5143 begin
5144 return Has_Enabled_Property (Id, Name_Effective_Writes);
5145 end Effective_Writes_Enabled;
5147 ------------------------------
5148 -- Enclosing_Comp_Unit_Node --
5149 ------------------------------
5151 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5152 Current_Node : Node_Id;
5154 begin
5155 Current_Node := N;
5156 while Present (Current_Node)
5157 and then Nkind (Current_Node) /= N_Compilation_Unit
5158 loop
5159 Current_Node := Parent (Current_Node);
5160 end loop;
5162 if Nkind (Current_Node) /= N_Compilation_Unit then
5163 return Empty;
5164 else
5165 return Current_Node;
5166 end if;
5167 end Enclosing_Comp_Unit_Node;
5169 --------------------------
5170 -- Enclosing_CPP_Parent --
5171 --------------------------
5173 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5174 Parent_Typ : Entity_Id := Typ;
5176 begin
5177 while not Is_CPP_Class (Parent_Typ)
5178 and then Etype (Parent_Typ) /= Parent_Typ
5179 loop
5180 Parent_Typ := Etype (Parent_Typ);
5182 if Is_Private_Type (Parent_Typ) then
5183 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5184 end if;
5185 end loop;
5187 pragma Assert (Is_CPP_Class (Parent_Typ));
5188 return Parent_Typ;
5189 end Enclosing_CPP_Parent;
5191 ----------------------------
5192 -- Enclosing_Generic_Body --
5193 ----------------------------
5195 function Enclosing_Generic_Body
5196 (N : Node_Id) return Node_Id
5198 P : Node_Id;
5199 Decl : Node_Id;
5200 Spec : Node_Id;
5202 begin
5203 P := Parent (N);
5204 while Present (P) loop
5205 if Nkind (P) = N_Package_Body
5206 or else Nkind (P) = N_Subprogram_Body
5207 then
5208 Spec := Corresponding_Spec (P);
5210 if Present (Spec) then
5211 Decl := Unit_Declaration_Node (Spec);
5213 if Nkind (Decl) = N_Generic_Package_Declaration
5214 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5215 then
5216 return P;
5217 end if;
5218 end if;
5219 end if;
5221 P := Parent (P);
5222 end loop;
5224 return Empty;
5225 end Enclosing_Generic_Body;
5227 ----------------------------
5228 -- Enclosing_Generic_Unit --
5229 ----------------------------
5231 function Enclosing_Generic_Unit
5232 (N : Node_Id) return Node_Id
5234 P : Node_Id;
5235 Decl : Node_Id;
5236 Spec : Node_Id;
5238 begin
5239 P := Parent (N);
5240 while Present (P) loop
5241 if Nkind (P) = N_Generic_Package_Declaration
5242 or else Nkind (P) = N_Generic_Subprogram_Declaration
5243 then
5244 return P;
5246 elsif Nkind (P) = N_Package_Body
5247 or else Nkind (P) = N_Subprogram_Body
5248 then
5249 Spec := Corresponding_Spec (P);
5251 if Present (Spec) then
5252 Decl := Unit_Declaration_Node (Spec);
5254 if Nkind (Decl) = N_Generic_Package_Declaration
5255 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5256 then
5257 return Decl;
5258 end if;
5259 end if;
5260 end if;
5262 P := Parent (P);
5263 end loop;
5265 return Empty;
5266 end Enclosing_Generic_Unit;
5268 -------------------------------
5269 -- Enclosing_Lib_Unit_Entity --
5270 -------------------------------
5272 function Enclosing_Lib_Unit_Entity
5273 (E : Entity_Id := Current_Scope) return Entity_Id
5275 Unit_Entity : Entity_Id;
5277 begin
5278 -- Look for enclosing library unit entity by following scope links.
5279 -- Equivalent to, but faster than indexing through the scope stack.
5281 Unit_Entity := E;
5282 while (Present (Scope (Unit_Entity))
5283 and then Scope (Unit_Entity) /= Standard_Standard)
5284 and not Is_Child_Unit (Unit_Entity)
5285 loop
5286 Unit_Entity := Scope (Unit_Entity);
5287 end loop;
5289 return Unit_Entity;
5290 end Enclosing_Lib_Unit_Entity;
5292 -----------------------
5293 -- Enclosing_Package --
5294 -----------------------
5296 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5297 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5299 begin
5300 if Dynamic_Scope = Standard_Standard then
5301 return Standard_Standard;
5303 elsif Dynamic_Scope = Empty then
5304 return Empty;
5306 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5307 E_Generic_Package)
5308 then
5309 return Dynamic_Scope;
5311 else
5312 return Enclosing_Package (Dynamic_Scope);
5313 end if;
5314 end Enclosing_Package;
5316 --------------------------
5317 -- Enclosing_Subprogram --
5318 --------------------------
5320 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5321 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5323 begin
5324 if Dynamic_Scope = Standard_Standard then
5325 return Empty;
5327 elsif Dynamic_Scope = Empty then
5328 return Empty;
5330 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5331 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5333 elsif Ekind (Dynamic_Scope) = E_Block
5334 or else Ekind (Dynamic_Scope) = E_Return_Statement
5335 then
5336 return Enclosing_Subprogram (Dynamic_Scope);
5338 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5339 return Get_Task_Body_Procedure (Dynamic_Scope);
5341 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5342 and then Present (Full_View (Dynamic_Scope))
5343 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5344 then
5345 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5347 -- No body is generated if the protected operation is eliminated
5349 elsif Convention (Dynamic_Scope) = Convention_Protected
5350 and then not Is_Eliminated (Dynamic_Scope)
5351 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5352 then
5353 return Protected_Body_Subprogram (Dynamic_Scope);
5355 else
5356 return Dynamic_Scope;
5357 end if;
5358 end Enclosing_Subprogram;
5360 ------------------------
5361 -- Ensure_Freeze_Node --
5362 ------------------------
5364 procedure Ensure_Freeze_Node (E : Entity_Id) is
5365 FN : Node_Id;
5366 begin
5367 if No (Freeze_Node (E)) then
5368 FN := Make_Freeze_Entity (Sloc (E));
5369 Set_Has_Delayed_Freeze (E);
5370 Set_Freeze_Node (E, FN);
5371 Set_Access_Types_To_Process (FN, No_Elist);
5372 Set_TSS_Elist (FN, No_Elist);
5373 Set_Entity (FN, E);
5374 end if;
5375 end Ensure_Freeze_Node;
5377 ----------------
5378 -- Enter_Name --
5379 ----------------
5381 procedure Enter_Name (Def_Id : Entity_Id) is
5382 C : constant Entity_Id := Current_Entity (Def_Id);
5383 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5384 S : constant Entity_Id := Current_Scope;
5386 begin
5387 Generate_Definition (Def_Id);
5389 -- Add new name to current scope declarations. Check for duplicate
5390 -- declaration, which may or may not be a genuine error.
5392 if Present (E) then
5394 -- Case of previous entity entered because of a missing declaration
5395 -- or else a bad subtype indication. Best is to use the new entity,
5396 -- and make the previous one invisible.
5398 if Etype (E) = Any_Type then
5399 Set_Is_Immediately_Visible (E, False);
5401 -- Case of renaming declaration constructed for package instances.
5402 -- if there is an explicit declaration with the same identifier,
5403 -- the renaming is not immediately visible any longer, but remains
5404 -- visible through selected component notation.
5406 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5407 and then not Comes_From_Source (E)
5408 then
5409 Set_Is_Immediately_Visible (E, False);
5411 -- The new entity may be the package renaming, which has the same
5412 -- same name as a generic formal which has been seen already.
5414 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5415 and then not Comes_From_Source (Def_Id)
5416 then
5417 Set_Is_Immediately_Visible (E, False);
5419 -- For a fat pointer corresponding to a remote access to subprogram,
5420 -- we use the same identifier as the RAS type, so that the proper
5421 -- name appears in the stub. This type is only retrieved through
5422 -- the RAS type and never by visibility, and is not added to the
5423 -- visibility list (see below).
5425 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
5426 and then Ekind (Def_Id) = E_Record_Type
5427 and then Present (Corresponding_Remote_Type (Def_Id))
5428 then
5429 null;
5431 -- Case of an implicit operation or derived literal. The new entity
5432 -- hides the implicit one, which is removed from all visibility,
5433 -- i.e. the entity list of its scope, and homonym chain of its name.
5435 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
5436 or else Is_Internal (E)
5437 then
5438 declare
5439 Prev : Entity_Id;
5440 Prev_Vis : Entity_Id;
5441 Decl : constant Node_Id := Parent (E);
5443 begin
5444 -- If E is an implicit declaration, it cannot be the first
5445 -- entity in the scope.
5447 Prev := First_Entity (Current_Scope);
5448 while Present (Prev) and then Next_Entity (Prev) /= E loop
5449 Next_Entity (Prev);
5450 end loop;
5452 if No (Prev) then
5454 -- If E is not on the entity chain of the current scope,
5455 -- it is an implicit declaration in the generic formal
5456 -- part of a generic subprogram. When analyzing the body,
5457 -- the generic formals are visible but not on the entity
5458 -- chain of the subprogram. The new entity will become
5459 -- the visible one in the body.
5461 pragma Assert
5462 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
5463 null;
5465 else
5466 Set_Next_Entity (Prev, Next_Entity (E));
5468 if No (Next_Entity (Prev)) then
5469 Set_Last_Entity (Current_Scope, Prev);
5470 end if;
5472 if E = Current_Entity (E) then
5473 Prev_Vis := Empty;
5475 else
5476 Prev_Vis := Current_Entity (E);
5477 while Homonym (Prev_Vis) /= E loop
5478 Prev_Vis := Homonym (Prev_Vis);
5479 end loop;
5480 end if;
5482 if Present (Prev_Vis) then
5484 -- Skip E in the visibility chain
5486 Set_Homonym (Prev_Vis, Homonym (E));
5488 else
5489 Set_Name_Entity_Id (Chars (E), Homonym (E));
5490 end if;
5491 end if;
5492 end;
5494 -- This section of code could use a comment ???
5496 elsif Present (Etype (E))
5497 and then Is_Concurrent_Type (Etype (E))
5498 and then E = Def_Id
5499 then
5500 return;
5502 -- If the homograph is a protected component renaming, it should not
5503 -- be hiding the current entity. Such renamings are treated as weak
5504 -- declarations.
5506 elsif Is_Prival (E) then
5507 Set_Is_Immediately_Visible (E, False);
5509 -- In this case the current entity is a protected component renaming.
5510 -- Perform minimal decoration by setting the scope and return since
5511 -- the prival should not be hiding other visible entities.
5513 elsif Is_Prival (Def_Id) then
5514 Set_Scope (Def_Id, Current_Scope);
5515 return;
5517 -- Analogous to privals, the discriminal generated for an entry index
5518 -- parameter acts as a weak declaration. Perform minimal decoration
5519 -- to avoid bogus errors.
5521 elsif Is_Discriminal (Def_Id)
5522 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
5523 then
5524 Set_Scope (Def_Id, Current_Scope);
5525 return;
5527 -- In the body or private part of an instance, a type extension may
5528 -- introduce a component with the same name as that of an actual. The
5529 -- legality rule is not enforced, but the semantics of the full type
5530 -- with two components of same name are not clear at this point???
5532 elsif In_Instance_Not_Visible then
5533 null;
5535 -- When compiling a package body, some child units may have become
5536 -- visible. They cannot conflict with local entities that hide them.
5538 elsif Is_Child_Unit (E)
5539 and then In_Open_Scopes (Scope (E))
5540 and then not Is_Immediately_Visible (E)
5541 then
5542 null;
5544 -- Conversely, with front-end inlining we may compile the parent body
5545 -- first, and a child unit subsequently. The context is now the
5546 -- parent spec, and body entities are not visible.
5548 elsif Is_Child_Unit (Def_Id)
5549 and then Is_Package_Body_Entity (E)
5550 and then not In_Package_Body (Current_Scope)
5551 then
5552 null;
5554 -- Case of genuine duplicate declaration
5556 else
5557 Error_Msg_Sloc := Sloc (E);
5559 -- If the previous declaration is an incomplete type declaration
5560 -- this may be an attempt to complete it with a private type. The
5561 -- following avoids confusing cascaded errors.
5563 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
5564 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
5565 then
5566 Error_Msg_N
5567 ("incomplete type cannot be completed with a private " &
5568 "declaration", Parent (Def_Id));
5569 Set_Is_Immediately_Visible (E, False);
5570 Set_Full_View (E, Def_Id);
5572 -- An inherited component of a record conflicts with a new
5573 -- discriminant. The discriminant is inserted first in the scope,
5574 -- but the error should be posted on it, not on the component.
5576 elsif Ekind (E) = E_Discriminant
5577 and then Present (Scope (Def_Id))
5578 and then Scope (Def_Id) /= Current_Scope
5579 then
5580 Error_Msg_Sloc := Sloc (Def_Id);
5581 Error_Msg_N ("& conflicts with declaration#", E);
5582 return;
5584 -- If the name of the unit appears in its own context clause, a
5585 -- dummy package with the name has already been created, and the
5586 -- error emitted. Try to continue quietly.
5588 elsif Error_Posted (E)
5589 and then Sloc (E) = No_Location
5590 and then Nkind (Parent (E)) = N_Package_Specification
5591 and then Current_Scope = Standard_Standard
5592 then
5593 Set_Scope (Def_Id, Current_Scope);
5594 return;
5596 else
5597 Error_Msg_N ("& conflicts with declaration#", Def_Id);
5599 -- Avoid cascaded messages with duplicate components in
5600 -- derived types.
5602 if Ekind_In (E, E_Component, E_Discriminant) then
5603 return;
5604 end if;
5605 end if;
5607 if Nkind (Parent (Parent (Def_Id))) =
5608 N_Generic_Subprogram_Declaration
5609 and then Def_Id =
5610 Defining_Entity (Specification (Parent (Parent (Def_Id))))
5611 then
5612 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
5613 end if;
5615 -- If entity is in standard, then we are in trouble, because it
5616 -- means that we have a library package with a duplicated name.
5617 -- That's hard to recover from, so abort.
5619 if S = Standard_Standard then
5620 raise Unrecoverable_Error;
5622 -- Otherwise we continue with the declaration. Having two
5623 -- identical declarations should not cause us too much trouble.
5625 else
5626 null;
5627 end if;
5628 end if;
5629 end if;
5631 -- If we fall through, declaration is OK, at least OK enough to continue
5633 -- If Def_Id is a discriminant or a record component we are in the midst
5634 -- of inheriting components in a derived record definition. Preserve
5635 -- their Ekind and Etype.
5637 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
5638 null;
5640 -- If a type is already set, leave it alone (happens when a type
5641 -- declaration is reanalyzed following a call to the optimizer).
5643 elsif Present (Etype (Def_Id)) then
5644 null;
5646 -- Otherwise, the kind E_Void insures that premature uses of the entity
5647 -- will be detected. Any_Type insures that no cascaded errors will occur
5649 else
5650 Set_Ekind (Def_Id, E_Void);
5651 Set_Etype (Def_Id, Any_Type);
5652 end if;
5654 -- Inherited discriminants and components in derived record types are
5655 -- immediately visible. Itypes are not.
5657 -- Unless the Itype is for a record type with a corresponding remote
5658 -- type (what is that about, it was not commented ???)
5660 if Ekind_In (Def_Id, E_Discriminant, E_Component)
5661 or else
5662 ((not Is_Record_Type (Def_Id)
5663 or else No (Corresponding_Remote_Type (Def_Id)))
5664 and then not Is_Itype (Def_Id))
5665 then
5666 Set_Is_Immediately_Visible (Def_Id);
5667 Set_Current_Entity (Def_Id);
5668 end if;
5670 Set_Homonym (Def_Id, C);
5671 Append_Entity (Def_Id, S);
5672 Set_Public_Status (Def_Id);
5674 -- Declaring a homonym is not allowed in SPARK ...
5676 if Present (C) and then Restriction_Check_Required (SPARK_05) then
5677 declare
5678 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
5679 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
5680 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
5682 begin
5683 -- ... unless the new declaration is in a subprogram, and the
5684 -- visible declaration is a variable declaration or a parameter
5685 -- specification outside that subprogram.
5687 if Present (Enclosing_Subp)
5688 and then Nkind_In (Parent (C), N_Object_Declaration,
5689 N_Parameter_Specification)
5690 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
5691 then
5692 null;
5694 -- ... or the new declaration is in a package, and the visible
5695 -- declaration occurs outside that package.
5697 elsif Present (Enclosing_Pack)
5698 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
5699 then
5700 null;
5702 -- ... or the new declaration is a component declaration in a
5703 -- record type definition.
5705 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
5706 null;
5708 -- Don't issue error for non-source entities
5710 elsif Comes_From_Source (Def_Id)
5711 and then Comes_From_Source (C)
5712 then
5713 Error_Msg_Sloc := Sloc (C);
5714 Check_SPARK_05_Restriction
5715 ("redeclaration of identifier &#", Def_Id);
5716 end if;
5717 end;
5718 end if;
5720 -- Warn if new entity hides an old one
5722 if Warn_On_Hiding and then Present (C)
5724 -- Don't warn for record components since they always have a well
5725 -- defined scope which does not confuse other uses. Note that in
5726 -- some cases, Ekind has not been set yet.
5728 and then Ekind (C) /= E_Component
5729 and then Ekind (C) /= E_Discriminant
5730 and then Nkind (Parent (C)) /= N_Component_Declaration
5731 and then Ekind (Def_Id) /= E_Component
5732 and then Ekind (Def_Id) /= E_Discriminant
5733 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
5735 -- Don't warn for one character variables. It is too common to use
5736 -- such variables as locals and will just cause too many false hits.
5738 and then Length_Of_Name (Chars (C)) /= 1
5740 -- Don't warn for non-source entities
5742 and then Comes_From_Source (C)
5743 and then Comes_From_Source (Def_Id)
5745 -- Don't warn unless entity in question is in extended main source
5747 and then In_Extended_Main_Source_Unit (Def_Id)
5749 -- Finally, the hidden entity must be either immediately visible or
5750 -- use visible (i.e. from a used package).
5752 and then
5753 (Is_Immediately_Visible (C)
5754 or else
5755 Is_Potentially_Use_Visible (C))
5756 then
5757 Error_Msg_Sloc := Sloc (C);
5758 Error_Msg_N ("declaration hides &#?h?", Def_Id);
5759 end if;
5760 end Enter_Name;
5762 ---------------
5763 -- Entity_Of --
5764 ---------------
5766 function Entity_Of (N : Node_Id) return Entity_Id is
5767 Id : Entity_Id;
5769 begin
5770 Id := Empty;
5772 if Is_Entity_Name (N) then
5773 Id := Entity (N);
5775 -- Follow a possible chain of renamings to reach the root renamed
5776 -- object.
5778 while Present (Id) and then Present (Renamed_Object (Id)) loop
5779 if Is_Entity_Name (Renamed_Object (Id)) then
5780 Id := Entity (Renamed_Object (Id));
5781 else
5782 Id := Empty;
5783 exit;
5784 end if;
5785 end loop;
5786 end if;
5788 return Id;
5789 end Entity_Of;
5791 --------------------------
5792 -- Explain_Limited_Type --
5793 --------------------------
5795 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
5796 C : Entity_Id;
5798 begin
5799 -- For array, component type must be limited
5801 if Is_Array_Type (T) then
5802 Error_Msg_Node_2 := T;
5803 Error_Msg_NE
5804 ("\component type& of type& is limited", N, Component_Type (T));
5805 Explain_Limited_Type (Component_Type (T), N);
5807 elsif Is_Record_Type (T) then
5809 -- No need for extra messages if explicit limited record
5811 if Is_Limited_Record (Base_Type (T)) then
5812 return;
5813 end if;
5815 -- Otherwise find a limited component. Check only components that
5816 -- come from source, or inherited components that appear in the
5817 -- source of the ancestor.
5819 C := First_Component (T);
5820 while Present (C) loop
5821 if Is_Limited_Type (Etype (C))
5822 and then
5823 (Comes_From_Source (C)
5824 or else
5825 (Present (Original_Record_Component (C))
5826 and then
5827 Comes_From_Source (Original_Record_Component (C))))
5828 then
5829 Error_Msg_Node_2 := T;
5830 Error_Msg_NE ("\component& of type& has limited type", N, C);
5831 Explain_Limited_Type (Etype (C), N);
5832 return;
5833 end if;
5835 Next_Component (C);
5836 end loop;
5838 -- The type may be declared explicitly limited, even if no component
5839 -- of it is limited, in which case we fall out of the loop.
5840 return;
5841 end if;
5842 end Explain_Limited_Type;
5844 -------------------------------
5845 -- Extensions_Visible_Status --
5846 -------------------------------
5848 function Extensions_Visible_Status
5849 (Id : Entity_Id) return Extensions_Visible_Mode
5851 Arg1 : Node_Id;
5852 Expr : Node_Id;
5853 Prag : Node_Id;
5854 Subp : Entity_Id;
5856 begin
5857 if SPARK_Mode = On then
5859 -- When a formal parameter is subject to Extensions_Visible, the
5860 -- pragma is stored in the contract of related subprogram.
5862 if Is_Formal (Id) then
5863 Subp := Scope (Id);
5865 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
5866 Subp := Id;
5868 -- No other construct carries this pragma
5870 else
5871 return Extensions_Visible_None;
5872 end if;
5874 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
5876 -- Extract the value from the Boolean expression (if any)
5878 if Present (Prag) then
5879 Arg1 := First (Pragma_Argument_Associations (Prag));
5881 -- The pragma appears with an argument
5883 if Present (Arg1) then
5884 Expr := Get_Pragma_Arg (Arg1);
5886 -- Guarg against cascading errors when the argument of pragma
5887 -- Extensions_Visible is not a valid static Boolean expression.
5889 if Error_Posted (Expr) then
5890 return Extensions_Visible_None;
5892 elsif Is_True (Expr_Value (Expr)) then
5893 return Extensions_Visible_True;
5895 else
5896 return Extensions_Visible_False;
5897 end if;
5899 -- Otherwise the pragma defaults to True
5901 else
5902 return Extensions_Visible_True;
5903 end if;
5905 -- Otherwise pragma Expresions_Visible is not inherited or directly
5906 -- specified, its value defaults to "False".
5908 else
5909 return Extensions_Visible_False;
5910 end if;
5912 -- When SPARK_Mode is disabled, all semantic checks related to pragma
5913 -- Extensions_Visible are disabled as well. Instead of saturating the
5914 -- code with "if SPARK_Mode /= Off then" checks, the predicate returns
5915 -- a default value.
5917 else
5918 return Extensions_Visible_None;
5919 end if;
5920 end Extensions_Visible_Status;
5922 -----------------
5923 -- Find_Actual --
5924 -----------------
5926 procedure Find_Actual
5927 (N : Node_Id;
5928 Formal : out Entity_Id;
5929 Call : out Node_Id)
5931 Parnt : constant Node_Id := Parent (N);
5932 Actual : Node_Id;
5934 begin
5935 if Nkind_In (Parnt, N_Indexed_Component, N_Selected_Component)
5936 and then N = Prefix (Parnt)
5937 then
5938 Find_Actual (Parnt, Formal, Call);
5939 return;
5941 elsif Nkind (Parnt) = N_Parameter_Association
5942 and then N = Explicit_Actual_Parameter (Parnt)
5943 then
5944 Call := Parent (Parnt);
5946 elsif Nkind (Parnt) in N_Subprogram_Call then
5947 Call := Parnt;
5949 else
5950 Formal := Empty;
5951 Call := Empty;
5952 return;
5953 end if;
5955 -- If we have a call to a subprogram look for the parameter. Note that
5956 -- we exclude overloaded calls, since we don't know enough to be sure
5957 -- of giving the right answer in this case.
5959 if Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
5960 and then Is_Entity_Name (Name (Call))
5961 and then Present (Entity (Name (Call)))
5962 and then Is_Overloadable (Entity (Name (Call)))
5963 and then not Is_Overloaded (Name (Call))
5964 then
5965 -- Fall here if we are definitely a parameter
5967 Actual := First_Actual (Call);
5968 Formal := First_Formal (Entity (Name (Call)));
5969 while Present (Formal) and then Present (Actual) loop
5970 if Actual = N then
5971 return;
5973 -- An actual that is the prefix in a prefixed call may have
5974 -- been rewritten in the call, after the deferred reference
5975 -- was collected. Check if sloc and kinds and names match.
5977 elsif Sloc (Actual) = Sloc (N)
5978 and then Nkind (Actual) = N_Identifier
5979 and then Nkind (Actual) = Nkind (N)
5980 and then Chars (Actual) = Chars (N)
5981 then
5982 return;
5984 else
5985 Actual := Next_Actual (Actual);
5986 Formal := Next_Formal (Formal);
5987 end if;
5988 end loop;
5989 end if;
5991 -- Fall through here if we did not find matching actual
5993 Formal := Empty;
5994 Call := Empty;
5995 end Find_Actual;
5997 ---------------------------
5998 -- Find_Body_Discriminal --
5999 ---------------------------
6001 function Find_Body_Discriminal
6002 (Spec_Discriminant : Entity_Id) return Entity_Id
6004 Tsk : Entity_Id;
6005 Disc : Entity_Id;
6007 begin
6008 -- If expansion is suppressed, then the scope can be the concurrent type
6009 -- itself rather than a corresponding concurrent record type.
6011 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6012 Tsk := Scope (Spec_Discriminant);
6014 else
6015 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6017 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6018 end if;
6020 -- Find discriminant of original concurrent type, and use its current
6021 -- discriminal, which is the renaming within the task/protected body.
6023 Disc := First_Discriminant (Tsk);
6024 while Present (Disc) loop
6025 if Chars (Disc) = Chars (Spec_Discriminant) then
6026 return Discriminal (Disc);
6027 end if;
6029 Next_Discriminant (Disc);
6030 end loop;
6032 -- That loop should always succeed in finding a matching entry and
6033 -- returning. Fatal error if not.
6035 raise Program_Error;
6036 end Find_Body_Discriminal;
6038 -------------------------------------
6039 -- Find_Corresponding_Discriminant --
6040 -------------------------------------
6042 function Find_Corresponding_Discriminant
6043 (Id : Node_Id;
6044 Typ : Entity_Id) return Entity_Id
6046 Par_Disc : Entity_Id;
6047 Old_Disc : Entity_Id;
6048 New_Disc : Entity_Id;
6050 begin
6051 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6053 -- The original type may currently be private, and the discriminant
6054 -- only appear on its full view.
6056 if Is_Private_Type (Scope (Par_Disc))
6057 and then not Has_Discriminants (Scope (Par_Disc))
6058 and then Present (Full_View (Scope (Par_Disc)))
6059 then
6060 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6061 else
6062 Old_Disc := First_Discriminant (Scope (Par_Disc));
6063 end if;
6065 if Is_Class_Wide_Type (Typ) then
6066 New_Disc := First_Discriminant (Root_Type (Typ));
6067 else
6068 New_Disc := First_Discriminant (Typ);
6069 end if;
6071 while Present (Old_Disc) and then Present (New_Disc) loop
6072 if Old_Disc = Par_Disc then
6073 return New_Disc;
6074 end if;
6076 Next_Discriminant (Old_Disc);
6077 Next_Discriminant (New_Disc);
6078 end loop;
6080 -- Should always find it
6082 raise Program_Error;
6083 end Find_Corresponding_Discriminant;
6085 ----------------------------------
6086 -- Find_Enclosing_Iterator_Loop --
6087 ----------------------------------
6089 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6090 Constr : Node_Id;
6091 S : Entity_Id;
6093 begin
6094 -- Traverse the scope chain looking for an iterator loop. Such loops are
6095 -- usually transformed into blocks, hence the use of Original_Node.
6097 S := Id;
6098 while Present (S) and then S /= Standard_Standard loop
6099 if Ekind (S) = E_Loop
6100 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6101 then
6102 Constr := Original_Node (Label_Construct (Parent (S)));
6104 if Nkind (Constr) = N_Loop_Statement
6105 and then Present (Iteration_Scheme (Constr))
6106 and then Nkind (Iterator_Specification
6107 (Iteration_Scheme (Constr))) =
6108 N_Iterator_Specification
6109 then
6110 return S;
6111 end if;
6112 end if;
6114 S := Scope (S);
6115 end loop;
6117 return Empty;
6118 end Find_Enclosing_Iterator_Loop;
6120 ------------------------------------
6121 -- Find_Loop_In_Conditional_Block --
6122 ------------------------------------
6124 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
6125 Stmt : Node_Id;
6127 begin
6128 Stmt := N;
6130 if Nkind (Stmt) = N_If_Statement then
6131 Stmt := First (Then_Statements (Stmt));
6132 end if;
6134 pragma Assert (Nkind (Stmt) = N_Block_Statement);
6136 -- Inspect the statements of the conditional block. In general the loop
6137 -- should be the first statement in the statement sequence of the block,
6138 -- but the finalization machinery may have introduced extra object
6139 -- declarations.
6141 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
6142 while Present (Stmt) loop
6143 if Nkind (Stmt) = N_Loop_Statement then
6144 return Stmt;
6145 end if;
6147 Next (Stmt);
6148 end loop;
6150 -- The expansion of attribute 'Loop_Entry produced a malformed block
6152 raise Program_Error;
6153 end Find_Loop_In_Conditional_Block;
6155 --------------------------
6156 -- Find_Overlaid_Entity --
6157 --------------------------
6159 procedure Find_Overlaid_Entity
6160 (N : Node_Id;
6161 Ent : out Entity_Id;
6162 Off : out Boolean)
6164 Expr : Node_Id;
6166 begin
6167 -- We are looking for one of the two following forms:
6169 -- for X'Address use Y'Address
6171 -- or
6173 -- Const : constant Address := expr;
6174 -- ...
6175 -- for X'Address use Const;
6177 -- In the second case, the expr is either Y'Address, or recursively a
6178 -- constant that eventually references Y'Address.
6180 Ent := Empty;
6181 Off := False;
6183 if Nkind (N) = N_Attribute_Definition_Clause
6184 and then Chars (N) = Name_Address
6185 then
6186 Expr := Expression (N);
6188 -- This loop checks the form of the expression for Y'Address,
6189 -- using recursion to deal with intermediate constants.
6191 loop
6192 -- Check for Y'Address
6194 if Nkind (Expr) = N_Attribute_Reference
6195 and then Attribute_Name (Expr) = Name_Address
6196 then
6197 Expr := Prefix (Expr);
6198 exit;
6200 -- Check for Const where Const is a constant entity
6202 elsif Is_Entity_Name (Expr)
6203 and then Ekind (Entity (Expr)) = E_Constant
6204 then
6205 Expr := Constant_Value (Entity (Expr));
6207 -- Anything else does not need checking
6209 else
6210 return;
6211 end if;
6212 end loop;
6214 -- This loop checks the form of the prefix for an entity, using
6215 -- recursion to deal with intermediate components.
6217 loop
6218 -- Check for Y where Y is an entity
6220 if Is_Entity_Name (Expr) then
6221 Ent := Entity (Expr);
6222 return;
6224 -- Check for components
6226 elsif
6227 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6228 then
6229 Expr := Prefix (Expr);
6230 Off := True;
6232 -- Anything else does not need checking
6234 else
6235 return;
6236 end if;
6237 end loop;
6238 end if;
6239 end Find_Overlaid_Entity;
6241 -------------------------
6242 -- Find_Parameter_Type --
6243 -------------------------
6245 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6246 begin
6247 if Nkind (Param) /= N_Parameter_Specification then
6248 return Empty;
6250 -- For an access parameter, obtain the type from the formal entity
6251 -- itself, because access to subprogram nodes do not carry a type.
6252 -- Shouldn't we always use the formal entity ???
6254 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6255 return Etype (Defining_Identifier (Param));
6257 else
6258 return Etype (Parameter_Type (Param));
6259 end if;
6260 end Find_Parameter_Type;
6262 -----------------------------------
6263 -- Find_Placement_In_State_Space --
6264 -----------------------------------
6266 procedure Find_Placement_In_State_Space
6267 (Item_Id : Entity_Id;
6268 Placement : out State_Space_Kind;
6269 Pack_Id : out Entity_Id)
6271 Context : Entity_Id;
6273 begin
6274 -- Assume that the item does not appear in the state space of a package
6276 Placement := Not_In_Package;
6277 Pack_Id := Empty;
6279 -- Climb the scope stack and examine the enclosing context
6281 Context := Scope (Item_Id);
6282 while Present (Context) and then Context /= Standard_Standard loop
6283 if Ekind (Context) = E_Package then
6284 Pack_Id := Context;
6286 -- A package body is a cut off point for the traversal as the item
6287 -- cannot be visible to the outside from this point on. Note that
6288 -- this test must be done first as a body is also classified as a
6289 -- private part.
6291 if In_Package_Body (Context) then
6292 Placement := Body_State_Space;
6293 return;
6295 -- The private part of a package is a cut off point for the
6296 -- traversal as the item cannot be visible to the outside from
6297 -- this point on.
6299 elsif In_Private_Part (Context) then
6300 Placement := Private_State_Space;
6301 return;
6303 -- When the item appears in the visible state space of a package,
6304 -- continue to climb the scope stack as this may not be the final
6305 -- state space.
6307 else
6308 Placement := Visible_State_Space;
6310 -- The visible state space of a child unit acts as the proper
6311 -- placement of an item.
6313 if Is_Child_Unit (Context) then
6314 return;
6315 end if;
6316 end if;
6318 -- The item or its enclosing package appear in a construct that has
6319 -- no state space.
6321 else
6322 Placement := Not_In_Package;
6323 return;
6324 end if;
6326 Context := Scope (Context);
6327 end loop;
6328 end Find_Placement_In_State_Space;
6330 ------------------------
6331 -- Find_Specific_Type --
6332 ------------------------
6334 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6335 Typ : Entity_Id := Root_Type (CW);
6337 begin
6338 if Ekind (Typ) = E_Incomplete_Type then
6339 if From_Limited_With (Typ) then
6340 Typ := Non_Limited_View (Typ);
6341 else
6342 Typ := Full_View (Typ);
6343 end if;
6344 end if;
6346 if Is_Private_Type (Typ)
6347 and then not Is_Tagged_Type (Typ)
6348 and then Present (Full_View (Typ))
6349 then
6350 return Full_View (Typ);
6351 else
6352 return Typ;
6353 end if;
6354 end Find_Specific_Type;
6356 -----------------------------
6357 -- Find_Static_Alternative --
6358 -----------------------------
6360 function Find_Static_Alternative (N : Node_Id) return Node_Id is
6361 Expr : constant Node_Id := Expression (N);
6362 Val : constant Uint := Expr_Value (Expr);
6363 Alt : Node_Id;
6364 Choice : Node_Id;
6366 begin
6367 Alt := First (Alternatives (N));
6369 Search : loop
6370 if Nkind (Alt) /= N_Pragma then
6371 Choice := First (Discrete_Choices (Alt));
6372 while Present (Choice) loop
6374 -- Others choice, always matches
6376 if Nkind (Choice) = N_Others_Choice then
6377 exit Search;
6379 -- Range, check if value is in the range
6381 elsif Nkind (Choice) = N_Range then
6382 exit Search when
6383 Val >= Expr_Value (Low_Bound (Choice))
6384 and then
6385 Val <= Expr_Value (High_Bound (Choice));
6387 -- Choice is a subtype name. Note that we know it must
6388 -- be a static subtype, since otherwise it would have
6389 -- been diagnosed as illegal.
6391 elsif Is_Entity_Name (Choice) and then Is_Type (Entity (Choice))
6392 then
6393 exit Search when Is_In_Range (Expr, Etype (Choice),
6394 Assume_Valid => False);
6396 -- Choice is a subtype indication
6398 elsif Nkind (Choice) = N_Subtype_Indication then
6399 declare
6400 C : constant Node_Id := Constraint (Choice);
6401 R : constant Node_Id := Range_Expression (C);
6403 begin
6404 exit Search when
6405 Val >= Expr_Value (Low_Bound (R))
6406 and then
6407 Val <= Expr_Value (High_Bound (R));
6408 end;
6410 -- Choice is a simple expression
6412 else
6413 exit Search when Val = Expr_Value (Choice);
6414 end if;
6416 Next (Choice);
6417 end loop;
6418 end if;
6420 Next (Alt);
6421 pragma Assert (Present (Alt));
6422 end loop Search;
6424 -- The above loop *must* terminate by finding a match, since
6425 -- we know the case statement is valid, and the value of the
6426 -- expression is known at compile time. When we fall out of
6427 -- the loop, Alt points to the alternative that we know will
6428 -- be selected at run time.
6430 return Alt;
6431 end Find_Static_Alternative;
6433 ------------------
6434 -- First_Actual --
6435 ------------------
6437 function First_Actual (Node : Node_Id) return Node_Id is
6438 N : Node_Id;
6440 begin
6441 if No (Parameter_Associations (Node)) then
6442 return Empty;
6443 end if;
6445 N := First (Parameter_Associations (Node));
6447 if Nkind (N) = N_Parameter_Association then
6448 return First_Named_Actual (Node);
6449 else
6450 return N;
6451 end if;
6452 end First_Actual;
6454 -----------------------
6455 -- Gather_Components --
6456 -----------------------
6458 procedure Gather_Components
6459 (Typ : Entity_Id;
6460 Comp_List : Node_Id;
6461 Governed_By : List_Id;
6462 Into : Elist_Id;
6463 Report_Errors : out Boolean)
6465 Assoc : Node_Id;
6466 Variant : Node_Id;
6467 Discrete_Choice : Node_Id;
6468 Comp_Item : Node_Id;
6470 Discrim : Entity_Id;
6471 Discrim_Name : Node_Id;
6472 Discrim_Value : Node_Id;
6474 begin
6475 Report_Errors := False;
6477 if No (Comp_List) or else Null_Present (Comp_List) then
6478 return;
6480 elsif Present (Component_Items (Comp_List)) then
6481 Comp_Item := First (Component_Items (Comp_List));
6483 else
6484 Comp_Item := Empty;
6485 end if;
6487 while Present (Comp_Item) loop
6489 -- Skip the tag of a tagged record, the interface tags, as well
6490 -- as all items that are not user components (anonymous types,
6491 -- rep clauses, Parent field, controller field).
6493 if Nkind (Comp_Item) = N_Component_Declaration then
6494 declare
6495 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
6496 begin
6497 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
6498 Append_Elmt (Comp, Into);
6499 end if;
6500 end;
6501 end if;
6503 Next (Comp_Item);
6504 end loop;
6506 if No (Variant_Part (Comp_List)) then
6507 return;
6508 else
6509 Discrim_Name := Name (Variant_Part (Comp_List));
6510 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
6511 end if;
6513 -- Look for the discriminant that governs this variant part.
6514 -- The discriminant *must* be in the Governed_By List
6516 Assoc := First (Governed_By);
6517 Find_Constraint : loop
6518 Discrim := First (Choices (Assoc));
6519 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
6520 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
6521 and then
6522 Chars (Corresponding_Discriminant (Entity (Discrim))) =
6523 Chars (Discrim_Name))
6524 or else Chars (Original_Record_Component (Entity (Discrim)))
6525 = Chars (Discrim_Name);
6527 if No (Next (Assoc)) then
6528 if not Is_Constrained (Typ)
6529 and then Is_Derived_Type (Typ)
6530 and then Present (Stored_Constraint (Typ))
6531 then
6532 -- If the type is a tagged type with inherited discriminants,
6533 -- use the stored constraint on the parent in order to find
6534 -- the values of discriminants that are otherwise hidden by an
6535 -- explicit constraint. Renamed discriminants are handled in
6536 -- the code above.
6538 -- If several parent discriminants are renamed by a single
6539 -- discriminant of the derived type, the call to obtain the
6540 -- Corresponding_Discriminant field only retrieves the last
6541 -- of them. We recover the constraint on the others from the
6542 -- Stored_Constraint as well.
6544 declare
6545 D : Entity_Id;
6546 C : Elmt_Id;
6548 begin
6549 D := First_Discriminant (Etype (Typ));
6550 C := First_Elmt (Stored_Constraint (Typ));
6551 while Present (D) and then Present (C) loop
6552 if Chars (Discrim_Name) = Chars (D) then
6553 if Is_Entity_Name (Node (C))
6554 and then Entity (Node (C)) = Entity (Discrim)
6555 then
6556 -- D is renamed by Discrim, whose value is given in
6557 -- Assoc.
6559 null;
6561 else
6562 Assoc :=
6563 Make_Component_Association (Sloc (Typ),
6564 New_List
6565 (New_Occurrence_Of (D, Sloc (Typ))),
6566 Duplicate_Subexpr_No_Checks (Node (C)));
6567 end if;
6568 exit Find_Constraint;
6569 end if;
6571 Next_Discriminant (D);
6572 Next_Elmt (C);
6573 end loop;
6574 end;
6575 end if;
6576 end if;
6578 if No (Next (Assoc)) then
6579 Error_Msg_NE (" missing value for discriminant&",
6580 First (Governed_By), Discrim_Name);
6581 Report_Errors := True;
6582 return;
6583 end if;
6585 Next (Assoc);
6586 end loop Find_Constraint;
6588 Discrim_Value := Expression (Assoc);
6590 if not Is_OK_Static_Expression (Discrim_Value) then
6591 Error_Msg_FE
6592 ("value for discriminant & must be static!",
6593 Discrim_Value, Discrim);
6594 Why_Not_Static (Discrim_Value);
6595 Report_Errors := True;
6596 return;
6597 end if;
6599 Search_For_Discriminant_Value : declare
6600 Low : Node_Id;
6601 High : Node_Id;
6603 UI_High : Uint;
6604 UI_Low : Uint;
6605 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
6607 begin
6608 Find_Discrete_Value : while Present (Variant) loop
6609 Discrete_Choice := First (Discrete_Choices (Variant));
6610 while Present (Discrete_Choice) loop
6611 exit Find_Discrete_Value when
6612 Nkind (Discrete_Choice) = N_Others_Choice;
6614 Get_Index_Bounds (Discrete_Choice, Low, High);
6616 UI_Low := Expr_Value (Low);
6617 UI_High := Expr_Value (High);
6619 exit Find_Discrete_Value when
6620 UI_Low <= UI_Discrim_Value
6621 and then
6622 UI_High >= UI_Discrim_Value;
6624 Next (Discrete_Choice);
6625 end loop;
6627 Next_Non_Pragma (Variant);
6628 end loop Find_Discrete_Value;
6629 end Search_For_Discriminant_Value;
6631 if No (Variant) then
6632 Error_Msg_NE
6633 ("value of discriminant & is out of range", Discrim_Value, Discrim);
6634 Report_Errors := True;
6635 return;
6636 end if;
6638 -- If we have found the corresponding choice, recursively add its
6639 -- components to the Into list.
6641 Gather_Components
6642 (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
6643 end Gather_Components;
6645 ------------------------
6646 -- Get_Actual_Subtype --
6647 ------------------------
6649 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
6650 Typ : constant Entity_Id := Etype (N);
6651 Utyp : Entity_Id := Underlying_Type (Typ);
6652 Decl : Node_Id;
6653 Atyp : Entity_Id;
6655 begin
6656 if No (Utyp) then
6657 Utyp := Typ;
6658 end if;
6660 -- If what we have is an identifier that references a subprogram
6661 -- formal, or a variable or constant object, then we get the actual
6662 -- subtype from the referenced entity if one has been built.
6664 if Nkind (N) = N_Identifier
6665 and then
6666 (Is_Formal (Entity (N))
6667 or else Ekind (Entity (N)) = E_Constant
6668 or else Ekind (Entity (N)) = E_Variable)
6669 and then Present (Actual_Subtype (Entity (N)))
6670 then
6671 return Actual_Subtype (Entity (N));
6673 -- Actual subtype of unchecked union is always itself. We never need
6674 -- the "real" actual subtype. If we did, we couldn't get it anyway
6675 -- because the discriminant is not available. The restrictions on
6676 -- Unchecked_Union are designed to make sure that this is OK.
6678 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
6679 return Typ;
6681 -- Here for the unconstrained case, we must find actual subtype
6682 -- No actual subtype is available, so we must build it on the fly.
6684 -- Checking the type, not the underlying type, for constrainedness
6685 -- seems to be necessary. Maybe all the tests should be on the type???
6687 elsif (not Is_Constrained (Typ))
6688 and then (Is_Array_Type (Utyp)
6689 or else (Is_Record_Type (Utyp)
6690 and then Has_Discriminants (Utyp)))
6691 and then not Has_Unknown_Discriminants (Utyp)
6692 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
6693 then
6694 -- Nothing to do if in spec expression (why not???)
6696 if In_Spec_Expression then
6697 return Typ;
6699 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
6701 -- If the type has no discriminants, there is no subtype to
6702 -- build, even if the underlying type is discriminated.
6704 return Typ;
6706 -- Else build the actual subtype
6708 else
6709 Decl := Build_Actual_Subtype (Typ, N);
6710 Atyp := Defining_Identifier (Decl);
6712 -- If Build_Actual_Subtype generated a new declaration then use it
6714 if Atyp /= Typ then
6716 -- The actual subtype is an Itype, so analyze the declaration,
6717 -- but do not attach it to the tree, to get the type defined.
6719 Set_Parent (Decl, N);
6720 Set_Is_Itype (Atyp);
6721 Analyze (Decl, Suppress => All_Checks);
6722 Set_Associated_Node_For_Itype (Atyp, N);
6723 Set_Has_Delayed_Freeze (Atyp, False);
6725 -- We need to freeze the actual subtype immediately. This is
6726 -- needed, because otherwise this Itype will not get frozen
6727 -- at all, and it is always safe to freeze on creation because
6728 -- any associated types must be frozen at this point.
6730 Freeze_Itype (Atyp, N);
6731 return Atyp;
6733 -- Otherwise we did not build a declaration, so return original
6735 else
6736 return Typ;
6737 end if;
6738 end if;
6740 -- For all remaining cases, the actual subtype is the same as
6741 -- the nominal type.
6743 else
6744 return Typ;
6745 end if;
6746 end Get_Actual_Subtype;
6748 -------------------------------------
6749 -- Get_Actual_Subtype_If_Available --
6750 -------------------------------------
6752 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
6753 Typ : constant Entity_Id := Etype (N);
6755 begin
6756 -- If what we have is an identifier that references a subprogram
6757 -- formal, or a variable or constant object, then we get the actual
6758 -- subtype from the referenced entity if one has been built.
6760 if Nkind (N) = N_Identifier
6761 and then
6762 (Is_Formal (Entity (N))
6763 or else Ekind (Entity (N)) = E_Constant
6764 or else Ekind (Entity (N)) = E_Variable)
6765 and then Present (Actual_Subtype (Entity (N)))
6766 then
6767 return Actual_Subtype (Entity (N));
6769 -- Otherwise the Etype of N is returned unchanged
6771 else
6772 return Typ;
6773 end if;
6774 end Get_Actual_Subtype_If_Available;
6776 ------------------------
6777 -- Get_Body_From_Stub --
6778 ------------------------
6780 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
6781 begin
6782 return Proper_Body (Unit (Library_Unit (N)));
6783 end Get_Body_From_Stub;
6785 ---------------------
6786 -- Get_Cursor_Type --
6787 ---------------------
6789 function Get_Cursor_Type
6790 (Aspect : Node_Id;
6791 Typ : Entity_Id) return Entity_Id
6793 Assoc : Node_Id;
6794 Func : Entity_Id;
6795 First_Op : Entity_Id;
6796 Cursor : Entity_Id;
6798 begin
6799 -- If error already detected, return
6801 if Error_Posted (Aspect) then
6802 return Any_Type;
6803 end if;
6805 -- The cursor type for an Iterable aspect is the return type of a
6806 -- non-overloaded First primitive operation. Locate association for
6807 -- First.
6809 Assoc := First (Component_Associations (Expression (Aspect)));
6810 First_Op := Any_Id;
6811 while Present (Assoc) loop
6812 if Chars (First (Choices (Assoc))) = Name_First then
6813 First_Op := Expression (Assoc);
6814 exit;
6815 end if;
6817 Next (Assoc);
6818 end loop;
6820 if First_Op = Any_Id then
6821 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
6822 return Any_Type;
6823 end if;
6825 Cursor := Any_Type;
6827 -- Locate function with desired name and profile in scope of type
6829 Func := First_Entity (Scope (Typ));
6830 while Present (Func) loop
6831 if Chars (Func) = Chars (First_Op)
6832 and then Ekind (Func) = E_Function
6833 and then Present (First_Formal (Func))
6834 and then Etype (First_Formal (Func)) = Typ
6835 and then No (Next_Formal (First_Formal (Func)))
6836 then
6837 if Cursor /= Any_Type then
6838 Error_Msg_N
6839 ("Operation First for iterable type must be unique", Aspect);
6840 return Any_Type;
6841 else
6842 Cursor := Etype (Func);
6843 end if;
6844 end if;
6846 Next_Entity (Func);
6847 end loop;
6849 -- If not found, no way to resolve remaining primitives.
6851 if Cursor = Any_Type then
6852 Error_Msg_N
6853 ("No legal primitive operation First for Iterable type", Aspect);
6854 end if;
6856 return Cursor;
6857 end Get_Cursor_Type;
6859 -------------------------------
6860 -- Get_Default_External_Name --
6861 -------------------------------
6863 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
6864 begin
6865 Get_Decoded_Name_String (Chars (E));
6867 if Opt.External_Name_Imp_Casing = Uppercase then
6868 Set_Casing (All_Upper_Case);
6869 else
6870 Set_Casing (All_Lower_Case);
6871 end if;
6873 return
6874 Make_String_Literal (Sloc (E),
6875 Strval => String_From_Name_Buffer);
6876 end Get_Default_External_Name;
6878 --------------------------
6879 -- Get_Enclosing_Object --
6880 --------------------------
6882 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
6883 begin
6884 if Is_Entity_Name (N) then
6885 return Entity (N);
6886 else
6887 case Nkind (N) is
6888 when N_Indexed_Component |
6889 N_Slice |
6890 N_Selected_Component =>
6892 -- If not generating code, a dereference may be left implicit.
6893 -- In thoses cases, return Empty.
6895 if Is_Access_Type (Etype (Prefix (N))) then
6896 return Empty;
6897 else
6898 return Get_Enclosing_Object (Prefix (N));
6899 end if;
6901 when N_Type_Conversion =>
6902 return Get_Enclosing_Object (Expression (N));
6904 when others =>
6905 return Empty;
6906 end case;
6907 end if;
6908 end Get_Enclosing_Object;
6910 ---------------------------
6911 -- Get_Enum_Lit_From_Pos --
6912 ---------------------------
6914 function Get_Enum_Lit_From_Pos
6915 (T : Entity_Id;
6916 Pos : Uint;
6917 Loc : Source_Ptr) return Node_Id
6919 Btyp : Entity_Id := Base_Type (T);
6920 Lit : Node_Id;
6922 begin
6923 -- In the case where the literal is of type Character, Wide_Character
6924 -- or Wide_Wide_Character or of a type derived from them, there needs
6925 -- to be some special handling since there is no explicit chain of
6926 -- literals to search. Instead, an N_Character_Literal node is created
6927 -- with the appropriate Char_Code and Chars fields.
6929 if Is_Standard_Character_Type (T) then
6930 Set_Character_Literal_Name (UI_To_CC (Pos));
6931 return
6932 Make_Character_Literal (Loc,
6933 Chars => Name_Find,
6934 Char_Literal_Value => Pos);
6936 -- For all other cases, we have a complete table of literals, and
6937 -- we simply iterate through the chain of literal until the one
6938 -- with the desired position value is found.
6940 else
6941 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
6942 Btyp := Full_View (Btyp);
6943 end if;
6945 Lit := First_Literal (Btyp);
6946 for J in 1 .. UI_To_Int (Pos) loop
6947 Next_Literal (Lit);
6948 end loop;
6950 return New_Occurrence_Of (Lit, Loc);
6951 end if;
6952 end Get_Enum_Lit_From_Pos;
6954 ---------------------------------
6955 -- Get_Ensures_From_CTC_Pragma --
6956 ---------------------------------
6958 function Get_Ensures_From_CTC_Pragma (N : Node_Id) return Node_Id is
6959 Args : constant List_Id := Pragma_Argument_Associations (N);
6960 Res : Node_Id;
6962 begin
6963 if List_Length (Args) = 4 then
6964 Res := Pick (Args, 4);
6966 elsif List_Length (Args) = 3 then
6967 Res := Pick (Args, 3);
6969 if Chars (Res) /= Name_Ensures then
6970 Res := Empty;
6971 end if;
6973 else
6974 Res := Empty;
6975 end if;
6977 return Res;
6978 end Get_Ensures_From_CTC_Pragma;
6980 ------------------------
6981 -- Get_Generic_Entity --
6982 ------------------------
6984 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
6985 Ent : constant Entity_Id := Entity (Name (N));
6986 begin
6987 if Present (Renamed_Object (Ent)) then
6988 return Renamed_Object (Ent);
6989 else
6990 return Ent;
6991 end if;
6992 end Get_Generic_Entity;
6994 -------------------------------------
6995 -- Get_Incomplete_View_Of_Ancestor --
6996 -------------------------------------
6998 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
6999 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7000 Par_Scope : Entity_Id;
7001 Par_Type : Entity_Id;
7003 begin
7004 -- The incomplete view of an ancestor is only relevant for private
7005 -- derived types in child units.
7007 if not Is_Derived_Type (E)
7008 or else not Is_Child_Unit (Cur_Unit)
7009 then
7010 return Empty;
7012 else
7013 Par_Scope := Scope (Cur_Unit);
7014 if No (Par_Scope) then
7015 return Empty;
7016 end if;
7018 Par_Type := Etype (Base_Type (E));
7020 -- Traverse list of ancestor types until we find one declared in
7021 -- a parent or grandparent unit (two levels seem sufficient).
7023 while Present (Par_Type) loop
7024 if Scope (Par_Type) = Par_Scope
7025 or else Scope (Par_Type) = Scope (Par_Scope)
7026 then
7027 return Par_Type;
7029 elsif not Is_Derived_Type (Par_Type) then
7030 return Empty;
7032 else
7033 Par_Type := Etype (Base_Type (Par_Type));
7034 end if;
7035 end loop;
7037 -- If none found, there is no relevant ancestor type.
7039 return Empty;
7040 end if;
7041 end Get_Incomplete_View_Of_Ancestor;
7043 ----------------------
7044 -- Get_Index_Bounds --
7045 ----------------------
7047 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
7048 Kind : constant Node_Kind := Nkind (N);
7049 R : Node_Id;
7051 begin
7052 if Kind = N_Range then
7053 L := Low_Bound (N);
7054 H := High_Bound (N);
7056 elsif Kind = N_Subtype_Indication then
7057 R := Range_Expression (Constraint (N));
7059 if R = Error then
7060 L := Error;
7061 H := Error;
7062 return;
7064 else
7065 L := Low_Bound (Range_Expression (Constraint (N)));
7066 H := High_Bound (Range_Expression (Constraint (N)));
7067 end if;
7069 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
7070 if Error_Posted (Scalar_Range (Entity (N))) then
7071 L := Error;
7072 H := Error;
7074 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
7075 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
7077 else
7078 L := Low_Bound (Scalar_Range (Entity (N)));
7079 H := High_Bound (Scalar_Range (Entity (N)));
7080 end if;
7082 else
7083 -- N is an expression, indicating a range with one value
7085 L := N;
7086 H := N;
7087 end if;
7088 end Get_Index_Bounds;
7090 ---------------------------------
7091 -- Get_Iterable_Type_Primitive --
7092 ---------------------------------
7094 function Get_Iterable_Type_Primitive
7095 (Typ : Entity_Id;
7096 Nam : Name_Id) return Entity_Id
7098 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
7099 Assoc : Node_Id;
7101 begin
7102 if No (Funcs) then
7103 return Empty;
7105 else
7106 Assoc := First (Component_Associations (Funcs));
7107 while Present (Assoc) loop
7108 if Chars (First (Choices (Assoc))) = Nam then
7109 return Entity (Expression (Assoc));
7110 end if;
7112 Assoc := Next (Assoc);
7113 end loop;
7115 return Empty;
7116 end if;
7117 end Get_Iterable_Type_Primitive;
7119 ----------------------------------
7120 -- Get_Library_Unit_Name_string --
7121 ----------------------------------
7123 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
7124 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
7126 begin
7127 Get_Unit_Name_String (Unit_Name_Id);
7129 -- Remove seven last character (" (spec)" or " (body)")
7131 Name_Len := Name_Len - 7;
7132 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
7133 end Get_Library_Unit_Name_String;
7135 ------------------------
7136 -- Get_Name_Entity_Id --
7137 ------------------------
7139 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
7140 begin
7141 return Entity_Id (Get_Name_Table_Info (Id));
7142 end Get_Name_Entity_Id;
7144 ------------------------------
7145 -- Get_Name_From_CTC_Pragma --
7146 ------------------------------
7148 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
7149 Arg : constant Node_Id :=
7150 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
7151 begin
7152 return Strval (Expr_Value_S (Arg));
7153 end Get_Name_From_CTC_Pragma;
7155 -----------------------
7156 -- Get_Parent_Entity --
7157 -----------------------
7159 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
7160 begin
7161 if Nkind (Unit) = N_Package_Body
7162 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
7163 then
7164 return Defining_Entity
7165 (Specification (Instance_Spec (Original_Node (Unit))));
7166 elsif Nkind (Unit) = N_Package_Instantiation then
7167 return Defining_Entity (Specification (Instance_Spec (Unit)));
7168 else
7169 return Defining_Entity (Unit);
7170 end if;
7171 end Get_Parent_Entity;
7172 -------------------
7173 -- Get_Pragma_Id --
7174 -------------------
7176 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
7177 begin
7178 return Get_Pragma_Id (Pragma_Name (N));
7179 end Get_Pragma_Id;
7181 -----------------------
7182 -- Get_Reason_String --
7183 -----------------------
7185 procedure Get_Reason_String (N : Node_Id) is
7186 begin
7187 if Nkind (N) = N_String_Literal then
7188 Store_String_Chars (Strval (N));
7190 elsif Nkind (N) = N_Op_Concat then
7191 Get_Reason_String (Left_Opnd (N));
7192 Get_Reason_String (Right_Opnd (N));
7194 -- If not of required form, error
7196 else
7197 Error_Msg_N
7198 ("Reason for pragma Warnings has wrong form", N);
7199 Error_Msg_N
7200 ("\must be string literal or concatenation of string literals", N);
7201 return;
7202 end if;
7203 end Get_Reason_String;
7205 ---------------------------
7206 -- Get_Referenced_Object --
7207 ---------------------------
7209 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7210 R : Node_Id;
7212 begin
7213 R := N;
7214 while Is_Entity_Name (R)
7215 and then Present (Renamed_Object (Entity (R)))
7216 loop
7217 R := Renamed_Object (Entity (R));
7218 end loop;
7220 return R;
7221 end Get_Referenced_Object;
7223 ------------------------
7224 -- Get_Renamed_Entity --
7225 ------------------------
7227 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7228 R : Entity_Id;
7230 begin
7231 R := E;
7232 while Present (Renamed_Entity (R)) loop
7233 R := Renamed_Entity (R);
7234 end loop;
7236 return R;
7237 end Get_Renamed_Entity;
7239 ----------------------------------
7240 -- Get_Requires_From_CTC_Pragma --
7241 ----------------------------------
7243 function Get_Requires_From_CTC_Pragma (N : Node_Id) return Node_Id is
7244 Args : constant List_Id := Pragma_Argument_Associations (N);
7245 Res : Node_Id;
7247 begin
7248 if List_Length (Args) >= 3 then
7249 Res := Pick (Args, 3);
7251 if Chars (Res) /= Name_Requires then
7252 Res := Empty;
7253 end if;
7255 else
7256 Res := Empty;
7257 end if;
7259 return Res;
7260 end Get_Requires_From_CTC_Pragma;
7262 -------------------------
7263 -- Get_Subprogram_Body --
7264 -------------------------
7266 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
7267 Decl : Node_Id;
7269 begin
7270 Decl := Unit_Declaration_Node (E);
7272 if Nkind (Decl) = N_Subprogram_Body then
7273 return Decl;
7275 -- The below comment is bad, because it is possible for
7276 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7278 else -- Nkind (Decl) = N_Subprogram_Declaration
7280 if Present (Corresponding_Body (Decl)) then
7281 return Unit_Declaration_Node (Corresponding_Body (Decl));
7283 -- Imported subprogram case
7285 else
7286 return Empty;
7287 end if;
7288 end if;
7289 end Get_Subprogram_Body;
7291 ---------------------------
7292 -- Get_Subprogram_Entity --
7293 ---------------------------
7295 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7296 Subp : Node_Id;
7297 Subp_Id : Entity_Id;
7299 begin
7300 if Nkind (Nod) = N_Accept_Statement then
7301 Subp := Entry_Direct_Name (Nod);
7303 elsif Nkind (Nod) = N_Slice then
7304 Subp := Prefix (Nod);
7306 else
7307 Subp := Name (Nod);
7308 end if;
7310 -- Strip the subprogram call
7312 loop
7313 if Nkind_In (Subp, N_Explicit_Dereference,
7314 N_Indexed_Component,
7315 N_Selected_Component)
7316 then
7317 Subp := Prefix (Subp);
7319 elsif Nkind_In (Subp, N_Type_Conversion,
7320 N_Unchecked_Type_Conversion)
7321 then
7322 Subp := Expression (Subp);
7324 else
7325 exit;
7326 end if;
7327 end loop;
7329 -- Extract the entity of the subprogram call
7331 if Is_Entity_Name (Subp) then
7332 Subp_Id := Entity (Subp);
7334 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
7335 Subp_Id := Directly_Designated_Type (Subp_Id);
7336 end if;
7338 if Is_Subprogram (Subp_Id) then
7339 return Subp_Id;
7340 else
7341 return Empty;
7342 end if;
7344 -- The search did not find a construct that denotes a subprogram
7346 else
7347 return Empty;
7348 end if;
7349 end Get_Subprogram_Entity;
7351 -----------------------------
7352 -- Get_Task_Body_Procedure --
7353 -----------------------------
7355 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
7356 begin
7357 -- Note: A task type may be the completion of a private type with
7358 -- discriminants. When performing elaboration checks on a task
7359 -- declaration, the current view of the type may be the private one,
7360 -- and the procedure that holds the body of the task is held in its
7361 -- underlying type.
7363 -- This is an odd function, why not have Task_Body_Procedure do
7364 -- the following digging???
7366 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
7367 end Get_Task_Body_Procedure;
7369 -----------------------
7370 -- Has_Access_Values --
7371 -----------------------
7373 function Has_Access_Values (T : Entity_Id) return Boolean is
7374 Typ : constant Entity_Id := Underlying_Type (T);
7376 begin
7377 -- Case of a private type which is not completed yet. This can only
7378 -- happen in the case of a generic format type appearing directly, or
7379 -- as a component of the type to which this function is being applied
7380 -- at the top level. Return False in this case, since we certainly do
7381 -- not know that the type contains access types.
7383 if No (Typ) then
7384 return False;
7386 elsif Is_Access_Type (Typ) then
7387 return True;
7389 elsif Is_Array_Type (Typ) then
7390 return Has_Access_Values (Component_Type (Typ));
7392 elsif Is_Record_Type (Typ) then
7393 declare
7394 Comp : Entity_Id;
7396 begin
7397 -- Loop to Check components
7399 Comp := First_Component_Or_Discriminant (Typ);
7400 while Present (Comp) loop
7402 -- Check for access component, tag field does not count, even
7403 -- though it is implemented internally using an access type.
7405 if Has_Access_Values (Etype (Comp))
7406 and then Chars (Comp) /= Name_uTag
7407 then
7408 return True;
7409 end if;
7411 Next_Component_Or_Discriminant (Comp);
7412 end loop;
7413 end;
7415 return False;
7417 else
7418 return False;
7419 end if;
7420 end Has_Access_Values;
7422 ------------------------------
7423 -- Has_Compatible_Alignment --
7424 ------------------------------
7426 function Has_Compatible_Alignment
7427 (Obj : Entity_Id;
7428 Expr : Node_Id) return Alignment_Result
7430 function Has_Compatible_Alignment_Internal
7431 (Obj : Entity_Id;
7432 Expr : Node_Id;
7433 Default : Alignment_Result) return Alignment_Result;
7434 -- This is the internal recursive function that actually does the work.
7435 -- There is one additional parameter, which says what the result should
7436 -- be if no alignment information is found, and there is no definite
7437 -- indication of compatible alignments. At the outer level, this is set
7438 -- to Unknown, but for internal recursive calls in the case where types
7439 -- are known to be correct, it is set to Known_Compatible.
7441 ---------------------------------------
7442 -- Has_Compatible_Alignment_Internal --
7443 ---------------------------------------
7445 function Has_Compatible_Alignment_Internal
7446 (Obj : Entity_Id;
7447 Expr : Node_Id;
7448 Default : Alignment_Result) return Alignment_Result
7450 Result : Alignment_Result := Known_Compatible;
7451 -- Holds the current status of the result. Note that once a value of
7452 -- Known_Incompatible is set, it is sticky and does not get changed
7453 -- to Unknown (the value in Result only gets worse as we go along,
7454 -- never better).
7456 Offs : Uint := No_Uint;
7457 -- Set to a factor of the offset from the base object when Expr is a
7458 -- selected or indexed component, based on Component_Bit_Offset and
7459 -- Component_Size respectively. A negative value is used to represent
7460 -- a value which is not known at compile time.
7462 procedure Check_Prefix;
7463 -- Checks the prefix recursively in the case where the expression
7464 -- is an indexed or selected component.
7466 procedure Set_Result (R : Alignment_Result);
7467 -- If R represents a worse outcome (unknown instead of known
7468 -- compatible, or known incompatible), then set Result to R.
7470 ------------------
7471 -- Check_Prefix --
7472 ------------------
7474 procedure Check_Prefix is
7475 begin
7476 -- The subtlety here is that in doing a recursive call to check
7477 -- the prefix, we have to decide what to do in the case where we
7478 -- don't find any specific indication of an alignment problem.
7480 -- At the outer level, we normally set Unknown as the result in
7481 -- this case, since we can only set Known_Compatible if we really
7482 -- know that the alignment value is OK, but for the recursive
7483 -- call, in the case where the types match, and we have not
7484 -- specified a peculiar alignment for the object, we are only
7485 -- concerned about suspicious rep clauses, the default case does
7486 -- not affect us, since the compiler will, in the absence of such
7487 -- rep clauses, ensure that the alignment is correct.
7489 if Default = Known_Compatible
7490 or else
7491 (Etype (Obj) = Etype (Expr)
7492 and then (Unknown_Alignment (Obj)
7493 or else
7494 Alignment (Obj) = Alignment (Etype (Obj))))
7495 then
7496 Set_Result
7497 (Has_Compatible_Alignment_Internal
7498 (Obj, Prefix (Expr), Known_Compatible));
7500 -- In all other cases, we need a full check on the prefix
7502 else
7503 Set_Result
7504 (Has_Compatible_Alignment_Internal
7505 (Obj, Prefix (Expr), Unknown));
7506 end if;
7507 end Check_Prefix;
7509 ----------------
7510 -- Set_Result --
7511 ----------------
7513 procedure Set_Result (R : Alignment_Result) is
7514 begin
7515 if R > Result then
7516 Result := R;
7517 end if;
7518 end Set_Result;
7520 -- Start of processing for Has_Compatible_Alignment_Internal
7522 begin
7523 -- If Expr is a selected component, we must make sure there is no
7524 -- potentially troublesome component clause, and that the record is
7525 -- not packed.
7527 if Nkind (Expr) = N_Selected_Component then
7529 -- Packed record always generate unknown alignment
7531 if Is_Packed (Etype (Prefix (Expr))) then
7532 Set_Result (Unknown);
7533 end if;
7535 -- Check prefix and component offset
7537 Check_Prefix;
7538 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
7540 -- If Expr is an indexed component, we must make sure there is no
7541 -- potentially troublesome Component_Size clause and that the array
7542 -- is not bit-packed.
7544 elsif Nkind (Expr) = N_Indexed_Component then
7545 declare
7546 Typ : constant Entity_Id := Etype (Prefix (Expr));
7547 Ind : constant Node_Id := First_Index (Typ);
7549 begin
7550 -- Bit packed array always generates unknown alignment
7552 if Is_Bit_Packed_Array (Typ) then
7553 Set_Result (Unknown);
7554 end if;
7556 -- Check prefix and component offset
7558 Check_Prefix;
7559 Offs := Component_Size (Typ);
7561 -- Small optimization: compute the full offset when possible
7563 if Offs /= No_Uint
7564 and then Offs > Uint_0
7565 and then Present (Ind)
7566 and then Nkind (Ind) = N_Range
7567 and then Compile_Time_Known_Value (Low_Bound (Ind))
7568 and then Compile_Time_Known_Value (First (Expressions (Expr)))
7569 then
7570 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
7571 - Expr_Value (Low_Bound ((Ind))));
7572 end if;
7573 end;
7574 end if;
7576 -- If we have a null offset, the result is entirely determined by
7577 -- the base object and has already been computed recursively.
7579 if Offs = Uint_0 then
7580 null;
7582 -- Case where we know the alignment of the object
7584 elsif Known_Alignment (Obj) then
7585 declare
7586 ObjA : constant Uint := Alignment (Obj);
7587 ExpA : Uint := No_Uint;
7588 SizA : Uint := No_Uint;
7590 begin
7591 -- If alignment of Obj is 1, then we are always OK
7593 if ObjA = 1 then
7594 Set_Result (Known_Compatible);
7596 -- Alignment of Obj is greater than 1, so we need to check
7598 else
7599 -- If we have an offset, see if it is compatible
7601 if Offs /= No_Uint and Offs > Uint_0 then
7602 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
7603 Set_Result (Known_Incompatible);
7604 end if;
7606 -- See if Expr is an object with known alignment
7608 elsif Is_Entity_Name (Expr)
7609 and then Known_Alignment (Entity (Expr))
7610 then
7611 ExpA := Alignment (Entity (Expr));
7613 -- Otherwise, we can use the alignment of the type of
7614 -- Expr given that we already checked for
7615 -- discombobulating rep clauses for the cases of indexed
7616 -- and selected components above.
7618 elsif Known_Alignment (Etype (Expr)) then
7619 ExpA := Alignment (Etype (Expr));
7621 -- Otherwise the alignment is unknown
7623 else
7624 Set_Result (Default);
7625 end if;
7627 -- If we got an alignment, see if it is acceptable
7629 if ExpA /= No_Uint and then ExpA < ObjA then
7630 Set_Result (Known_Incompatible);
7631 end if;
7633 -- If Expr is not a piece of a larger object, see if size
7634 -- is given. If so, check that it is not too small for the
7635 -- required alignment.
7637 if Offs /= No_Uint then
7638 null;
7640 -- See if Expr is an object with known size
7642 elsif Is_Entity_Name (Expr)
7643 and then Known_Static_Esize (Entity (Expr))
7644 then
7645 SizA := Esize (Entity (Expr));
7647 -- Otherwise, we check the object size of the Expr type
7649 elsif Known_Static_Esize (Etype (Expr)) then
7650 SizA := Esize (Etype (Expr));
7651 end if;
7653 -- If we got a size, see if it is a multiple of the Obj
7654 -- alignment, if not, then the alignment cannot be
7655 -- acceptable, since the size is always a multiple of the
7656 -- alignment.
7658 if SizA /= No_Uint then
7659 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
7660 Set_Result (Known_Incompatible);
7661 end if;
7662 end if;
7663 end if;
7664 end;
7666 -- If we do not know required alignment, any non-zero offset is a
7667 -- potential problem (but certainly may be OK, so result is unknown).
7669 elsif Offs /= No_Uint then
7670 Set_Result (Unknown);
7672 -- If we can't find the result by direct comparison of alignment
7673 -- values, then there is still one case that we can determine known
7674 -- result, and that is when we can determine that the types are the
7675 -- same, and no alignments are specified. Then we known that the
7676 -- alignments are compatible, even if we don't know the alignment
7677 -- value in the front end.
7679 elsif Etype (Obj) = Etype (Expr) then
7681 -- Types are the same, but we have to check for possible size
7682 -- and alignments on the Expr object that may make the alignment
7683 -- different, even though the types are the same.
7685 if Is_Entity_Name (Expr) then
7687 -- First check alignment of the Expr object. Any alignment less
7688 -- than Maximum_Alignment is worrisome since this is the case
7689 -- where we do not know the alignment of Obj.
7691 if Known_Alignment (Entity (Expr))
7692 and then UI_To_Int (Alignment (Entity (Expr))) <
7693 Ttypes.Maximum_Alignment
7694 then
7695 Set_Result (Unknown);
7697 -- Now check size of Expr object. Any size that is not an
7698 -- even multiple of Maximum_Alignment is also worrisome
7699 -- since it may cause the alignment of the object to be less
7700 -- than the alignment of the type.
7702 elsif Known_Static_Esize (Entity (Expr))
7703 and then
7704 (UI_To_Int (Esize (Entity (Expr))) mod
7705 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
7706 /= 0
7707 then
7708 Set_Result (Unknown);
7710 -- Otherwise same type is decisive
7712 else
7713 Set_Result (Known_Compatible);
7714 end if;
7715 end if;
7717 -- Another case to deal with is when there is an explicit size or
7718 -- alignment clause when the types are not the same. If so, then the
7719 -- result is Unknown. We don't need to do this test if the Default is
7720 -- Unknown, since that result will be set in any case.
7722 elsif Default /= Unknown
7723 and then (Has_Size_Clause (Etype (Expr))
7724 or else
7725 Has_Alignment_Clause (Etype (Expr)))
7726 then
7727 Set_Result (Unknown);
7729 -- If no indication found, set default
7731 else
7732 Set_Result (Default);
7733 end if;
7735 -- Return worst result found
7737 return Result;
7738 end Has_Compatible_Alignment_Internal;
7740 -- Start of processing for Has_Compatible_Alignment
7742 begin
7743 -- If Obj has no specified alignment, then set alignment from the type
7744 -- alignment. Perhaps we should always do this, but for sure we should
7745 -- do it when there is an address clause since we can do more if the
7746 -- alignment is known.
7748 if Unknown_Alignment (Obj) then
7749 Set_Alignment (Obj, Alignment (Etype (Obj)));
7750 end if;
7752 -- Now do the internal call that does all the work
7754 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
7755 end Has_Compatible_Alignment;
7757 ----------------------
7758 -- Has_Declarations --
7759 ----------------------
7761 function Has_Declarations (N : Node_Id) return Boolean is
7762 begin
7763 return Nkind_In (Nkind (N), N_Accept_Statement,
7764 N_Block_Statement,
7765 N_Compilation_Unit_Aux,
7766 N_Entry_Body,
7767 N_Package_Body,
7768 N_Protected_Body,
7769 N_Subprogram_Body,
7770 N_Task_Body,
7771 N_Package_Specification);
7772 end Has_Declarations;
7774 ---------------------------------
7775 -- Has_Defaulted_Discriminants --
7776 ---------------------------------
7778 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
7779 begin
7780 return Has_Discriminants (Typ)
7781 and then Present (First_Discriminant (Typ))
7782 and then Present (Discriminant_Default_Value
7783 (First_Discriminant (Typ)));
7784 end Has_Defaulted_Discriminants;
7786 -------------------
7787 -- Has_Denormals --
7788 -------------------
7790 function Has_Denormals (E : Entity_Id) return Boolean is
7791 begin
7792 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
7793 end Has_Denormals;
7795 -------------------------------------------
7796 -- Has_Discriminant_Dependent_Constraint --
7797 -------------------------------------------
7799 function Has_Discriminant_Dependent_Constraint
7800 (Comp : Entity_Id) return Boolean
7802 Comp_Decl : constant Node_Id := Parent (Comp);
7803 Subt_Indic : Node_Id;
7804 Constr : Node_Id;
7805 Assn : Node_Id;
7807 begin
7808 -- Discriminants can't depend on discriminants
7810 if Ekind (Comp) = E_Discriminant then
7811 return False;
7813 else
7814 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
7816 if Nkind (Subt_Indic) = N_Subtype_Indication then
7817 Constr := Constraint (Subt_Indic);
7819 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
7820 Assn := First (Constraints (Constr));
7821 while Present (Assn) loop
7822 case Nkind (Assn) is
7823 when N_Subtype_Indication |
7824 N_Range |
7825 N_Identifier
7827 if Depends_On_Discriminant (Assn) then
7828 return True;
7829 end if;
7831 when N_Discriminant_Association =>
7832 if Depends_On_Discriminant (Expression (Assn)) then
7833 return True;
7834 end if;
7836 when others =>
7837 null;
7838 end case;
7840 Next (Assn);
7841 end loop;
7842 end if;
7843 end if;
7844 end if;
7846 return False;
7847 end Has_Discriminant_Dependent_Constraint;
7849 --------------------------
7850 -- Has_Enabled_Property --
7851 --------------------------
7853 function Has_Enabled_Property
7854 (Item_Id : Entity_Id;
7855 Property : Name_Id) return Boolean
7857 function State_Has_Enabled_Property return Boolean;
7858 -- Determine whether a state denoted by Item_Id has the property enabled
7860 function Variable_Has_Enabled_Property return Boolean;
7861 -- Determine whether a variable denoted by Item_Id has the property
7862 -- enabled.
7864 --------------------------------
7865 -- State_Has_Enabled_Property --
7866 --------------------------------
7868 function State_Has_Enabled_Property return Boolean is
7869 Decl : constant Node_Id := Parent (Item_Id);
7870 Opt : Node_Id;
7871 Opt_Nam : Node_Id;
7872 Prop : Node_Id;
7873 Prop_Nam : Node_Id;
7874 Props : Node_Id;
7876 begin
7877 -- The declaration of an external abstract state appears as an
7878 -- extension aggregate. If this is not the case, properties can never
7879 -- be set.
7881 if Nkind (Decl) /= N_Extension_Aggregate then
7882 return False;
7883 end if;
7885 -- When External appears as a simple option, it automatically enables
7886 -- all properties.
7888 Opt := First (Expressions (Decl));
7889 while Present (Opt) loop
7890 if Nkind (Opt) = N_Identifier
7891 and then Chars (Opt) = Name_External
7892 then
7893 return True;
7894 end if;
7896 Next (Opt);
7897 end loop;
7899 -- When External specifies particular properties, inspect those and
7900 -- find the desired one (if any).
7902 Opt := First (Component_Associations (Decl));
7903 while Present (Opt) loop
7904 Opt_Nam := First (Choices (Opt));
7906 if Nkind (Opt_Nam) = N_Identifier
7907 and then Chars (Opt_Nam) = Name_External
7908 then
7909 Props := Expression (Opt);
7911 -- Multiple properties appear as an aggregate
7913 if Nkind (Props) = N_Aggregate then
7915 -- Simple property form
7917 Prop := First (Expressions (Props));
7918 while Present (Prop) loop
7919 if Chars (Prop) = Property then
7920 return True;
7921 end if;
7923 Next (Prop);
7924 end loop;
7926 -- Property with expression form
7928 Prop := First (Component_Associations (Props));
7929 while Present (Prop) loop
7930 Prop_Nam := First (Choices (Prop));
7932 -- The property can be represented in two ways:
7933 -- others => <value>
7934 -- <property> => <value>
7936 if Nkind (Prop_Nam) = N_Others_Choice
7937 or else (Nkind (Prop_Nam) = N_Identifier
7938 and then Chars (Prop_Nam) = Property)
7939 then
7940 return Is_True (Expr_Value (Expression (Prop)));
7941 end if;
7943 Next (Prop);
7944 end loop;
7946 -- Single property
7948 else
7949 return Chars (Props) = Property;
7950 end if;
7951 end if;
7953 Next (Opt);
7954 end loop;
7956 return False;
7957 end State_Has_Enabled_Property;
7959 -----------------------------------
7960 -- Variable_Has_Enabled_Property --
7961 -----------------------------------
7963 function Variable_Has_Enabled_Property return Boolean is
7964 function Is_Enabled (Prag : Node_Id) return Boolean;
7965 -- Determine whether property pragma Prag (if present) denotes an
7966 -- enabled property.
7968 ----------------
7969 -- Is_Enabled --
7970 ----------------
7972 function Is_Enabled (Prag : Node_Id) return Boolean is
7973 Arg2 : Node_Id;
7975 begin
7976 if Present (Prag) then
7977 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
7979 -- The pragma has an optional Boolean expression, the related
7980 -- property is enabled only when the expression evaluates to
7981 -- True.
7983 if Present (Arg2) then
7984 return Is_True (Expr_Value (Get_Pragma_Arg (Arg2)));
7986 -- Otherwise the lack of expression enables the property by
7987 -- default.
7989 else
7990 return True;
7991 end if;
7993 -- The property was never set in the first place
7995 else
7996 return False;
7997 end if;
7998 end Is_Enabled;
8000 -- Local variables
8002 AR : constant Node_Id :=
8003 Get_Pragma (Item_Id, Pragma_Async_Readers);
8004 AW : constant Node_Id :=
8005 Get_Pragma (Item_Id, Pragma_Async_Writers);
8006 ER : constant Node_Id :=
8007 Get_Pragma (Item_Id, Pragma_Effective_Reads);
8008 EW : constant Node_Id :=
8009 Get_Pragma (Item_Id, Pragma_Effective_Writes);
8011 -- Start of processing for Variable_Has_Enabled_Property
8013 begin
8014 -- A non-effectively volatile object can never possess external
8015 -- properties.
8017 if not Is_Effectively_Volatile (Item_Id) then
8018 return False;
8020 -- External properties related to variables come in two flavors -
8021 -- explicit and implicit. The explicit case is characterized by the
8022 -- presence of a property pragma with an optional Boolean flag. The
8023 -- property is enabled when the flag evaluates to True or the flag is
8024 -- missing altogether.
8026 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
8027 return True;
8029 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
8030 return True;
8032 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
8033 return True;
8035 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
8036 return True;
8038 -- The implicit case lacks all property pragmas
8040 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
8041 return True;
8043 else
8044 return False;
8045 end if;
8046 end Variable_Has_Enabled_Property;
8048 -- Start of processing for Has_Enabled_Property
8050 begin
8051 -- Abstract states and variables have a flexible scheme of specifying
8052 -- external properties.
8054 if Ekind (Item_Id) = E_Abstract_State then
8055 return State_Has_Enabled_Property;
8057 elsif Ekind (Item_Id) = E_Variable then
8058 return Variable_Has_Enabled_Property;
8060 -- Otherwise a property is enabled when the related item is effectively
8061 -- volatile.
8063 else
8064 return Is_Effectively_Volatile (Item_Id);
8065 end if;
8066 end Has_Enabled_Property;
8068 --------------------
8069 -- Has_Infinities --
8070 --------------------
8072 function Has_Infinities (E : Entity_Id) return Boolean is
8073 begin
8074 return
8075 Is_Floating_Point_Type (E)
8076 and then Nkind (Scalar_Range (E)) = N_Range
8077 and then Includes_Infinities (Scalar_Range (E));
8078 end Has_Infinities;
8080 --------------------
8081 -- Has_Interfaces --
8082 --------------------
8084 function Has_Interfaces
8085 (T : Entity_Id;
8086 Use_Full_View : Boolean := True) return Boolean
8088 Typ : Entity_Id := Base_Type (T);
8090 begin
8091 -- Handle concurrent types
8093 if Is_Concurrent_Type (Typ) then
8094 Typ := Corresponding_Record_Type (Typ);
8095 end if;
8097 if not Present (Typ)
8098 or else not Is_Record_Type (Typ)
8099 or else not Is_Tagged_Type (Typ)
8100 then
8101 return False;
8102 end if;
8104 -- Handle private types
8106 if Use_Full_View and then Present (Full_View (Typ)) then
8107 Typ := Full_View (Typ);
8108 end if;
8110 -- Handle concurrent record types
8112 if Is_Concurrent_Record_Type (Typ)
8113 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
8114 then
8115 return True;
8116 end if;
8118 loop
8119 if Is_Interface (Typ)
8120 or else
8121 (Is_Record_Type (Typ)
8122 and then Present (Interfaces (Typ))
8123 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
8124 then
8125 return True;
8126 end if;
8128 exit when Etype (Typ) = Typ
8130 -- Handle private types
8132 or else (Present (Full_View (Etype (Typ)))
8133 and then Full_View (Etype (Typ)) = Typ)
8135 -- Protect frontend against wrong sources with cyclic derivations
8137 or else Etype (Typ) = T;
8139 -- Climb to the ancestor type handling private types
8141 if Present (Full_View (Etype (Typ))) then
8142 Typ := Full_View (Etype (Typ));
8143 else
8144 Typ := Etype (Typ);
8145 end if;
8146 end loop;
8148 return False;
8149 end Has_Interfaces;
8151 ---------------------------------
8152 -- Has_No_Obvious_Side_Effects --
8153 ---------------------------------
8155 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
8156 begin
8157 -- For now, just handle literals, constants, and non-volatile
8158 -- variables and expressions combining these with operators or
8159 -- short circuit forms.
8161 if Nkind (N) in N_Numeric_Or_String_Literal then
8162 return True;
8164 elsif Nkind (N) = N_Character_Literal then
8165 return True;
8167 elsif Nkind (N) in N_Unary_Op then
8168 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
8170 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
8171 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
8172 and then
8173 Has_No_Obvious_Side_Effects (Right_Opnd (N));
8175 elsif Nkind (N) = N_Expression_With_Actions
8176 and then Is_Empty_List (Actions (N))
8177 then
8178 return Has_No_Obvious_Side_Effects (Expression (N));
8180 elsif Nkind (N) in N_Has_Entity then
8181 return Present (Entity (N))
8182 and then Ekind_In (Entity (N), E_Variable,
8183 E_Constant,
8184 E_Enumeration_Literal,
8185 E_In_Parameter,
8186 E_Out_Parameter,
8187 E_In_Out_Parameter)
8188 and then not Is_Volatile (Entity (N));
8190 else
8191 return False;
8192 end if;
8193 end Has_No_Obvious_Side_Effects;
8195 ------------------------
8196 -- Has_Null_Exclusion --
8197 ------------------------
8199 function Has_Null_Exclusion (N : Node_Id) return Boolean is
8200 begin
8201 case Nkind (N) is
8202 when N_Access_Definition |
8203 N_Access_Function_Definition |
8204 N_Access_Procedure_Definition |
8205 N_Access_To_Object_Definition |
8206 N_Allocator |
8207 N_Derived_Type_Definition |
8208 N_Function_Specification |
8209 N_Subtype_Declaration =>
8210 return Null_Exclusion_Present (N);
8212 when N_Component_Definition |
8213 N_Formal_Object_Declaration |
8214 N_Object_Renaming_Declaration =>
8215 if Present (Subtype_Mark (N)) then
8216 return Null_Exclusion_Present (N);
8217 else pragma Assert (Present (Access_Definition (N)));
8218 return Null_Exclusion_Present (Access_Definition (N));
8219 end if;
8221 when N_Discriminant_Specification =>
8222 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
8223 return Null_Exclusion_Present (Discriminant_Type (N));
8224 else
8225 return Null_Exclusion_Present (N);
8226 end if;
8228 when N_Object_Declaration =>
8229 if Nkind (Object_Definition (N)) = N_Access_Definition then
8230 return Null_Exclusion_Present (Object_Definition (N));
8231 else
8232 return Null_Exclusion_Present (N);
8233 end if;
8235 when N_Parameter_Specification =>
8236 if Nkind (Parameter_Type (N)) = N_Access_Definition then
8237 return Null_Exclusion_Present (Parameter_Type (N));
8238 else
8239 return Null_Exclusion_Present (N);
8240 end if;
8242 when others =>
8243 return False;
8245 end case;
8246 end Has_Null_Exclusion;
8248 ------------------------
8249 -- Has_Null_Extension --
8250 ------------------------
8252 function Has_Null_Extension (T : Entity_Id) return Boolean is
8253 B : constant Entity_Id := Base_Type (T);
8254 Comps : Node_Id;
8255 Ext : Node_Id;
8257 begin
8258 if Nkind (Parent (B)) = N_Full_Type_Declaration
8259 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
8260 then
8261 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
8263 if Present (Ext) then
8264 if Null_Present (Ext) then
8265 return True;
8266 else
8267 Comps := Component_List (Ext);
8269 -- The null component list is rewritten during analysis to
8270 -- include the parent component. Any other component indicates
8271 -- that the extension was not originally null.
8273 return Null_Present (Comps)
8274 or else No (Next (First (Component_Items (Comps))));
8275 end if;
8276 else
8277 return False;
8278 end if;
8280 else
8281 return False;
8282 end if;
8283 end Has_Null_Extension;
8285 -------------------------------
8286 -- Has_Overriding_Initialize --
8287 -------------------------------
8289 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
8290 BT : constant Entity_Id := Base_Type (T);
8291 P : Elmt_Id;
8293 begin
8294 if Is_Controlled (BT) then
8295 if Is_RTU (Scope (BT), Ada_Finalization) then
8296 return False;
8298 elsif Present (Primitive_Operations (BT)) then
8299 P := First_Elmt (Primitive_Operations (BT));
8300 while Present (P) loop
8301 declare
8302 Init : constant Entity_Id := Node (P);
8303 Formal : constant Entity_Id := First_Formal (Init);
8304 begin
8305 if Ekind (Init) = E_Procedure
8306 and then Chars (Init) = Name_Initialize
8307 and then Comes_From_Source (Init)
8308 and then Present (Formal)
8309 and then Etype (Formal) = BT
8310 and then No (Next_Formal (Formal))
8311 and then (Ada_Version < Ada_2012
8312 or else not Null_Present (Parent (Init)))
8313 then
8314 return True;
8315 end if;
8316 end;
8318 Next_Elmt (P);
8319 end loop;
8320 end if;
8322 -- Here if type itself does not have a non-null Initialize operation:
8323 -- check immediate ancestor.
8325 if Is_Derived_Type (BT)
8326 and then Has_Overriding_Initialize (Etype (BT))
8327 then
8328 return True;
8329 end if;
8330 end if;
8332 return False;
8333 end Has_Overriding_Initialize;
8335 --------------------------------------
8336 -- Has_Preelaborable_Initialization --
8337 --------------------------------------
8339 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
8340 Has_PE : Boolean;
8342 procedure Check_Components (E : Entity_Id);
8343 -- Check component/discriminant chain, sets Has_PE False if a component
8344 -- or discriminant does not meet the preelaborable initialization rules.
8346 ----------------------
8347 -- Check_Components --
8348 ----------------------
8350 procedure Check_Components (E : Entity_Id) is
8351 Ent : Entity_Id;
8352 Exp : Node_Id;
8354 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
8355 -- Returns True if and only if the expression denoted by N does not
8356 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8358 ---------------------------------
8359 -- Is_Preelaborable_Expression --
8360 ---------------------------------
8362 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
8363 Exp : Node_Id;
8364 Assn : Node_Id;
8365 Choice : Node_Id;
8366 Comp_Type : Entity_Id;
8367 Is_Array_Aggr : Boolean;
8369 begin
8370 if Is_OK_Static_Expression (N) then
8371 return True;
8373 elsif Nkind (N) = N_Null then
8374 return True;
8376 -- Attributes are allowed in general, even if their prefix is a
8377 -- formal type. (It seems that certain attributes known not to be
8378 -- static might not be allowed, but there are no rules to prevent
8379 -- them.)
8381 elsif Nkind (N) = N_Attribute_Reference then
8382 return True;
8384 -- The name of a discriminant evaluated within its parent type is
8385 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8386 -- names that denote discriminals as well as discriminants to
8387 -- catch references occurring within init procs.
8389 elsif Is_Entity_Name (N)
8390 and then
8391 (Ekind (Entity (N)) = E_Discriminant
8392 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
8393 and then Present (Discriminal_Link (Entity (N)))))
8394 then
8395 return True;
8397 elsif Nkind (N) = N_Qualified_Expression then
8398 return Is_Preelaborable_Expression (Expression (N));
8400 -- For aggregates we have to check that each of the associations
8401 -- is preelaborable.
8403 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
8404 Is_Array_Aggr := Is_Array_Type (Etype (N));
8406 if Is_Array_Aggr then
8407 Comp_Type := Component_Type (Etype (N));
8408 end if;
8410 -- Check the ancestor part of extension aggregates, which must
8411 -- be either the name of a type that has preelaborable init or
8412 -- an expression that is preelaborable.
8414 if Nkind (N) = N_Extension_Aggregate then
8415 declare
8416 Anc_Part : constant Node_Id := Ancestor_Part (N);
8418 begin
8419 if Is_Entity_Name (Anc_Part)
8420 and then Is_Type (Entity (Anc_Part))
8421 then
8422 if not Has_Preelaborable_Initialization
8423 (Entity (Anc_Part))
8424 then
8425 return False;
8426 end if;
8428 elsif not Is_Preelaborable_Expression (Anc_Part) then
8429 return False;
8430 end if;
8431 end;
8432 end if;
8434 -- Check positional associations
8436 Exp := First (Expressions (N));
8437 while Present (Exp) loop
8438 if not Is_Preelaborable_Expression (Exp) then
8439 return False;
8440 end if;
8442 Next (Exp);
8443 end loop;
8445 -- Check named associations
8447 Assn := First (Component_Associations (N));
8448 while Present (Assn) loop
8449 Choice := First (Choices (Assn));
8450 while Present (Choice) loop
8451 if Is_Array_Aggr then
8452 if Nkind (Choice) = N_Others_Choice then
8453 null;
8455 elsif Nkind (Choice) = N_Range then
8456 if not Is_OK_Static_Range (Choice) then
8457 return False;
8458 end if;
8460 elsif not Is_OK_Static_Expression (Choice) then
8461 return False;
8462 end if;
8464 else
8465 Comp_Type := Etype (Choice);
8466 end if;
8468 Next (Choice);
8469 end loop;
8471 -- If the association has a <> at this point, then we have
8472 -- to check whether the component's type has preelaborable
8473 -- initialization. Note that this only occurs when the
8474 -- association's corresponding component does not have a
8475 -- default expression, the latter case having already been
8476 -- expanded as an expression for the association.
8478 if Box_Present (Assn) then
8479 if not Has_Preelaborable_Initialization (Comp_Type) then
8480 return False;
8481 end if;
8483 -- In the expression case we check whether the expression
8484 -- is preelaborable.
8486 elsif
8487 not Is_Preelaborable_Expression (Expression (Assn))
8488 then
8489 return False;
8490 end if;
8492 Next (Assn);
8493 end loop;
8495 -- If we get here then aggregate as a whole is preelaborable
8497 return True;
8499 -- All other cases are not preelaborable
8501 else
8502 return False;
8503 end if;
8504 end Is_Preelaborable_Expression;
8506 -- Start of processing for Check_Components
8508 begin
8509 -- Loop through entities of record or protected type
8511 Ent := E;
8512 while Present (Ent) loop
8514 -- We are interested only in components and discriminants
8516 Exp := Empty;
8518 case Ekind (Ent) is
8519 when E_Component =>
8521 -- Get default expression if any. If there is no declaration
8522 -- node, it means we have an internal entity. The parent and
8523 -- tag fields are examples of such entities. For such cases,
8524 -- we just test the type of the entity.
8526 if Present (Declaration_Node (Ent)) then
8527 Exp := Expression (Declaration_Node (Ent));
8528 end if;
8530 when E_Discriminant =>
8532 -- Note: for a renamed discriminant, the Declaration_Node
8533 -- may point to the one from the ancestor, and have a
8534 -- different expression, so use the proper attribute to
8535 -- retrieve the expression from the derived constraint.
8537 Exp := Discriminant_Default_Value (Ent);
8539 when others =>
8540 goto Check_Next_Entity;
8541 end case;
8543 -- A component has PI if it has no default expression and the
8544 -- component type has PI.
8546 if No (Exp) then
8547 if not Has_Preelaborable_Initialization (Etype (Ent)) then
8548 Has_PE := False;
8549 exit;
8550 end if;
8552 -- Require the default expression to be preelaborable
8554 elsif not Is_Preelaborable_Expression (Exp) then
8555 Has_PE := False;
8556 exit;
8557 end if;
8559 <<Check_Next_Entity>>
8560 Next_Entity (Ent);
8561 end loop;
8562 end Check_Components;
8564 -- Start of processing for Has_Preelaborable_Initialization
8566 begin
8567 -- Immediate return if already marked as known preelaborable init. This
8568 -- covers types for which this function has already been called once
8569 -- and returned True (in which case the result is cached), and also
8570 -- types to which a pragma Preelaborable_Initialization applies.
8572 if Known_To_Have_Preelab_Init (E) then
8573 return True;
8574 end if;
8576 -- If the type is a subtype representing a generic actual type, then
8577 -- test whether its base type has preelaborable initialization since
8578 -- the subtype representing the actual does not inherit this attribute
8579 -- from the actual or formal. (but maybe it should???)
8581 if Is_Generic_Actual_Type (E) then
8582 return Has_Preelaborable_Initialization (Base_Type (E));
8583 end if;
8585 -- All elementary types have preelaborable initialization
8587 if Is_Elementary_Type (E) then
8588 Has_PE := True;
8590 -- Array types have PI if the component type has PI
8592 elsif Is_Array_Type (E) then
8593 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
8595 -- A derived type has preelaborable initialization if its parent type
8596 -- has preelaborable initialization and (in the case of a derived record
8597 -- extension) if the non-inherited components all have preelaborable
8598 -- initialization. However, a user-defined controlled type with an
8599 -- overriding Initialize procedure does not have preelaborable
8600 -- initialization.
8602 elsif Is_Derived_Type (E) then
8604 -- If the derived type is a private extension then it doesn't have
8605 -- preelaborable initialization.
8607 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
8608 return False;
8609 end if;
8611 -- First check whether ancestor type has preelaborable initialization
8613 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
8615 -- If OK, check extension components (if any)
8617 if Has_PE and then Is_Record_Type (E) then
8618 Check_Components (First_Entity (E));
8619 end if;
8621 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8622 -- with a user defined Initialize procedure does not have PI. If
8623 -- the type is untagged, the control primitives come from a component
8624 -- that has already been checked.
8626 if Has_PE
8627 and then Is_Controlled (E)
8628 and then Is_Tagged_Type (E)
8629 and then Has_Overriding_Initialize (E)
8630 then
8631 Has_PE := False;
8632 end if;
8634 -- Private types not derived from a type having preelaborable init and
8635 -- that are not marked with pragma Preelaborable_Initialization do not
8636 -- have preelaborable initialization.
8638 elsif Is_Private_Type (E) then
8639 return False;
8641 -- Record type has PI if it is non private and all components have PI
8643 elsif Is_Record_Type (E) then
8644 Has_PE := True;
8645 Check_Components (First_Entity (E));
8647 -- Protected types must not have entries, and components must meet
8648 -- same set of rules as for record components.
8650 elsif Is_Protected_Type (E) then
8651 if Has_Entries (E) then
8652 Has_PE := False;
8653 else
8654 Has_PE := True;
8655 Check_Components (First_Entity (E));
8656 Check_Components (First_Private_Entity (E));
8657 end if;
8659 -- Type System.Address always has preelaborable initialization
8661 elsif Is_RTE (E, RE_Address) then
8662 Has_PE := True;
8664 -- In all other cases, type does not have preelaborable initialization
8666 else
8667 return False;
8668 end if;
8670 -- If type has preelaborable initialization, cache result
8672 if Has_PE then
8673 Set_Known_To_Have_Preelab_Init (E);
8674 end if;
8676 return Has_PE;
8677 end Has_Preelaborable_Initialization;
8679 ---------------------------
8680 -- Has_Private_Component --
8681 ---------------------------
8683 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
8684 Btype : Entity_Id := Base_Type (Type_Id);
8685 Component : Entity_Id;
8687 begin
8688 if Error_Posted (Type_Id)
8689 or else Error_Posted (Btype)
8690 then
8691 return False;
8692 end if;
8694 if Is_Class_Wide_Type (Btype) then
8695 Btype := Root_Type (Btype);
8696 end if;
8698 if Is_Private_Type (Btype) then
8699 declare
8700 UT : constant Entity_Id := Underlying_Type (Btype);
8701 begin
8702 if No (UT) then
8703 if No (Full_View (Btype)) then
8704 return not Is_Generic_Type (Btype)
8705 and then
8706 not Is_Generic_Type (Root_Type (Btype));
8707 else
8708 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
8709 end if;
8710 else
8711 return not Is_Frozen (UT) and then Has_Private_Component (UT);
8712 end if;
8713 end;
8715 elsif Is_Array_Type (Btype) then
8716 return Has_Private_Component (Component_Type (Btype));
8718 elsif Is_Record_Type (Btype) then
8719 Component := First_Component (Btype);
8720 while Present (Component) loop
8721 if Has_Private_Component (Etype (Component)) then
8722 return True;
8723 end if;
8725 Next_Component (Component);
8726 end loop;
8728 return False;
8730 elsif Is_Protected_Type (Btype)
8731 and then Present (Corresponding_Record_Type (Btype))
8732 then
8733 return Has_Private_Component (Corresponding_Record_Type (Btype));
8735 else
8736 return False;
8737 end if;
8738 end Has_Private_Component;
8740 ----------------------
8741 -- Has_Signed_Zeros --
8742 ----------------------
8744 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
8745 begin
8746 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
8747 end Has_Signed_Zeros;
8749 -----------------------------
8750 -- Has_Static_Array_Bounds --
8751 -----------------------------
8753 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
8754 Ndims : constant Nat := Number_Dimensions (Typ);
8756 Index : Node_Id;
8757 Low : Node_Id;
8758 High : Node_Id;
8760 begin
8761 -- Unconstrained types do not have static bounds
8763 if not Is_Constrained (Typ) then
8764 return False;
8765 end if;
8767 -- First treat string literals specially, as the lower bound and length
8768 -- of string literals are not stored like those of arrays.
8770 -- A string literal always has static bounds
8772 if Ekind (Typ) = E_String_Literal_Subtype then
8773 return True;
8774 end if;
8776 -- Treat all dimensions in turn
8778 Index := First_Index (Typ);
8779 for Indx in 1 .. Ndims loop
8781 -- In case of an illegal index which is not a discrete type, return
8782 -- that the type is not static.
8784 if not Is_Discrete_Type (Etype (Index))
8785 or else Etype (Index) = Any_Type
8786 then
8787 return False;
8788 end if;
8790 Get_Index_Bounds (Index, Low, High);
8792 if Error_Posted (Low) or else Error_Posted (High) then
8793 return False;
8794 end if;
8796 if Is_OK_Static_Expression (Low)
8797 and then
8798 Is_OK_Static_Expression (High)
8799 then
8800 null;
8801 else
8802 return False;
8803 end if;
8805 Next (Index);
8806 end loop;
8808 -- If we fall through the loop, all indexes matched
8810 return True;
8811 end Has_Static_Array_Bounds;
8813 ----------------
8814 -- Has_Stream --
8815 ----------------
8817 function Has_Stream (T : Entity_Id) return Boolean is
8818 E : Entity_Id;
8820 begin
8821 if No (T) then
8822 return False;
8824 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
8825 return True;
8827 elsif Is_Array_Type (T) then
8828 return Has_Stream (Component_Type (T));
8830 elsif Is_Record_Type (T) then
8831 E := First_Component (T);
8832 while Present (E) loop
8833 if Has_Stream (Etype (E)) then
8834 return True;
8835 else
8836 Next_Component (E);
8837 end if;
8838 end loop;
8840 return False;
8842 elsif Is_Private_Type (T) then
8843 return Has_Stream (Underlying_Type (T));
8845 else
8846 return False;
8847 end if;
8848 end Has_Stream;
8850 ----------------
8851 -- Has_Suffix --
8852 ----------------
8854 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
8855 begin
8856 Get_Name_String (Chars (E));
8857 return Name_Buffer (Name_Len) = Suffix;
8858 end Has_Suffix;
8860 ----------------
8861 -- Add_Suffix --
8862 ----------------
8864 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8865 begin
8866 Get_Name_String (Chars (E));
8867 Add_Char_To_Name_Buffer (Suffix);
8868 return Name_Find;
8869 end Add_Suffix;
8871 -------------------
8872 -- Remove_Suffix --
8873 -------------------
8875 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8876 begin
8877 pragma Assert (Has_Suffix (E, Suffix));
8878 Get_Name_String (Chars (E));
8879 Name_Len := Name_Len - 1;
8880 return Name_Find;
8881 end Remove_Suffix;
8883 --------------------------
8884 -- Has_Tagged_Component --
8885 --------------------------
8887 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
8888 Comp : Entity_Id;
8890 begin
8891 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
8892 return Has_Tagged_Component (Underlying_Type (Typ));
8894 elsif Is_Array_Type (Typ) then
8895 return Has_Tagged_Component (Component_Type (Typ));
8897 elsif Is_Tagged_Type (Typ) then
8898 return True;
8900 elsif Is_Record_Type (Typ) then
8901 Comp := First_Component (Typ);
8902 while Present (Comp) loop
8903 if Has_Tagged_Component (Etype (Comp)) then
8904 return True;
8905 end if;
8907 Next_Component (Comp);
8908 end loop;
8910 return False;
8912 else
8913 return False;
8914 end if;
8915 end Has_Tagged_Component;
8917 ----------------------------
8918 -- Has_Volatile_Component --
8919 ----------------------------
8921 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
8922 Comp : Entity_Id;
8924 begin
8925 if Has_Volatile_Components (Typ) then
8926 return True;
8928 elsif Is_Array_Type (Typ) then
8929 return Is_Volatile (Component_Type (Typ));
8931 elsif Is_Record_Type (Typ) then
8932 Comp := First_Component (Typ);
8933 while Present (Comp) loop
8934 if Is_Volatile_Object (Comp) then
8935 return True;
8936 end if;
8938 Comp := Next_Component (Comp);
8939 end loop;
8940 end if;
8942 return False;
8943 end Has_Volatile_Component;
8945 -------------------------
8946 -- Implementation_Kind --
8947 -------------------------
8949 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
8950 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
8951 Arg : Node_Id;
8952 begin
8953 pragma Assert (Present (Impl_Prag));
8954 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
8955 return Chars (Get_Pragma_Arg (Arg));
8956 end Implementation_Kind;
8958 --------------------------
8959 -- Implements_Interface --
8960 --------------------------
8962 function Implements_Interface
8963 (Typ_Ent : Entity_Id;
8964 Iface_Ent : Entity_Id;
8965 Exclude_Parents : Boolean := False) return Boolean
8967 Ifaces_List : Elist_Id;
8968 Elmt : Elmt_Id;
8969 Iface : Entity_Id := Base_Type (Iface_Ent);
8970 Typ : Entity_Id := Base_Type (Typ_Ent);
8972 begin
8973 if Is_Class_Wide_Type (Typ) then
8974 Typ := Root_Type (Typ);
8975 end if;
8977 if not Has_Interfaces (Typ) then
8978 return False;
8979 end if;
8981 if Is_Class_Wide_Type (Iface) then
8982 Iface := Root_Type (Iface);
8983 end if;
8985 Collect_Interfaces (Typ, Ifaces_List);
8987 Elmt := First_Elmt (Ifaces_List);
8988 while Present (Elmt) loop
8989 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
8990 and then Exclude_Parents
8991 then
8992 null;
8994 elsif Node (Elmt) = Iface then
8995 return True;
8996 end if;
8998 Next_Elmt (Elmt);
8999 end loop;
9001 return False;
9002 end Implements_Interface;
9004 ------------------------------------
9005 -- In_Assertion_Expression_Pragma --
9006 ------------------------------------
9008 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
9009 Par : Node_Id;
9010 Prag : Node_Id := Empty;
9012 begin
9013 -- Climb the parent chain looking for an enclosing pragma
9015 Par := N;
9016 while Present (Par) loop
9017 if Nkind (Par) = N_Pragma then
9018 Prag := Par;
9019 exit;
9021 -- Precondition-like pragmas are expanded into if statements, check
9022 -- the original node instead.
9024 elsif Nkind (Original_Node (Par)) = N_Pragma then
9025 Prag := Original_Node (Par);
9026 exit;
9028 -- The expansion of attribute 'Old generates a constant to capture
9029 -- the result of the prefix. If the parent traversal reaches
9030 -- one of these constants, then the node technically came from a
9031 -- postcondition-like pragma. Note that the Ekind is not tested here
9032 -- because N may be the expression of an object declaration which is
9033 -- currently being analyzed. Such objects carry Ekind of E_Void.
9035 elsif Nkind (Par) = N_Object_Declaration
9036 and then Constant_Present (Par)
9037 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
9038 then
9039 return True;
9041 -- Prevent the search from going too far
9043 elsif Is_Body_Or_Package_Declaration (Par) then
9044 return False;
9045 end if;
9047 Par := Parent (Par);
9048 end loop;
9050 return
9051 Present (Prag)
9052 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
9053 end In_Assertion_Expression_Pragma;
9055 -----------------
9056 -- In_Instance --
9057 -----------------
9059 function In_Instance return Boolean is
9060 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9061 S : Entity_Id;
9063 begin
9064 S := Current_Scope;
9065 while Present (S) and then S /= Standard_Standard loop
9066 if Ekind_In (S, E_Function, E_Package, E_Procedure)
9067 and then Is_Generic_Instance (S)
9068 then
9069 -- A child instance is always compiled in the context of a parent
9070 -- instance. Nevertheless, the actuals are not analyzed in an
9071 -- instance context. We detect this case by examining the current
9072 -- compilation unit, which must be a child instance, and checking
9073 -- that it is not currently on the scope stack.
9075 if Is_Child_Unit (Curr_Unit)
9076 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9077 N_Package_Instantiation
9078 and then not In_Open_Scopes (Curr_Unit)
9079 then
9080 return False;
9081 else
9082 return True;
9083 end if;
9084 end if;
9086 S := Scope (S);
9087 end loop;
9089 return False;
9090 end In_Instance;
9092 ----------------------
9093 -- In_Instance_Body --
9094 ----------------------
9096 function In_Instance_Body return Boolean is
9097 S : Entity_Id;
9099 begin
9100 S := Current_Scope;
9101 while Present (S) and then S /= Standard_Standard loop
9102 if Ekind_In (S, E_Function, E_Procedure)
9103 and then Is_Generic_Instance (S)
9104 then
9105 return True;
9107 elsif Ekind (S) = E_Package
9108 and then In_Package_Body (S)
9109 and then Is_Generic_Instance (S)
9110 then
9111 return True;
9112 end if;
9114 S := Scope (S);
9115 end loop;
9117 return False;
9118 end In_Instance_Body;
9120 -----------------------------
9121 -- In_Instance_Not_Visible --
9122 -----------------------------
9124 function In_Instance_Not_Visible return Boolean is
9125 S : Entity_Id;
9127 begin
9128 S := Current_Scope;
9129 while Present (S) and then S /= Standard_Standard loop
9130 if Ekind_In (S, E_Function, E_Procedure)
9131 and then Is_Generic_Instance (S)
9132 then
9133 return True;
9135 elsif Ekind (S) = E_Package
9136 and then (In_Package_Body (S) or else In_Private_Part (S))
9137 and then Is_Generic_Instance (S)
9138 then
9139 return True;
9140 end if;
9142 S := Scope (S);
9143 end loop;
9145 return False;
9146 end In_Instance_Not_Visible;
9148 ------------------------------
9149 -- In_Instance_Visible_Part --
9150 ------------------------------
9152 function In_Instance_Visible_Part return Boolean is
9153 S : Entity_Id;
9155 begin
9156 S := Current_Scope;
9157 while Present (S) and then S /= Standard_Standard loop
9158 if Ekind (S) = E_Package
9159 and then Is_Generic_Instance (S)
9160 and then not In_Package_Body (S)
9161 and then not In_Private_Part (S)
9162 then
9163 return True;
9164 end if;
9166 S := Scope (S);
9167 end loop;
9169 return False;
9170 end In_Instance_Visible_Part;
9172 ---------------------
9173 -- In_Package_Body --
9174 ---------------------
9176 function In_Package_Body return Boolean is
9177 S : Entity_Id;
9179 begin
9180 S := Current_Scope;
9181 while Present (S) and then S /= Standard_Standard loop
9182 if Ekind (S) = E_Package and then In_Package_Body (S) then
9183 return True;
9184 else
9185 S := Scope (S);
9186 end if;
9187 end loop;
9189 return False;
9190 end In_Package_Body;
9192 --------------------------------
9193 -- In_Parameter_Specification --
9194 --------------------------------
9196 function In_Parameter_Specification (N : Node_Id) return Boolean is
9197 PN : Node_Id;
9199 begin
9200 PN := Parent (N);
9201 while Present (PN) loop
9202 if Nkind (PN) = N_Parameter_Specification then
9203 return True;
9204 end if;
9206 PN := Parent (PN);
9207 end loop;
9209 return False;
9210 end In_Parameter_Specification;
9212 --------------------------
9213 -- In_Pragma_Expression --
9214 --------------------------
9216 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
9217 P : Node_Id;
9218 begin
9219 P := Parent (N);
9220 loop
9221 if No (P) then
9222 return False;
9223 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
9224 return True;
9225 else
9226 P := Parent (P);
9227 end if;
9228 end loop;
9229 end In_Pragma_Expression;
9231 -------------------------------------
9232 -- In_Reverse_Storage_Order_Object --
9233 -------------------------------------
9235 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
9236 Pref : Node_Id;
9237 Btyp : Entity_Id := Empty;
9239 begin
9240 -- Climb up indexed components
9242 Pref := N;
9243 loop
9244 case Nkind (Pref) is
9245 when N_Selected_Component =>
9246 Pref := Prefix (Pref);
9247 exit;
9249 when N_Indexed_Component =>
9250 Pref := Prefix (Pref);
9252 when others =>
9253 Pref := Empty;
9254 exit;
9255 end case;
9256 end loop;
9258 if Present (Pref) then
9259 Btyp := Base_Type (Etype (Pref));
9260 end if;
9262 return Present (Btyp)
9263 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
9264 and then Reverse_Storage_Order (Btyp);
9265 end In_Reverse_Storage_Order_Object;
9267 --------------------------------------
9268 -- In_Subprogram_Or_Concurrent_Unit --
9269 --------------------------------------
9271 function In_Subprogram_Or_Concurrent_Unit return Boolean is
9272 E : Entity_Id;
9273 K : Entity_Kind;
9275 begin
9276 -- Use scope chain to check successively outer scopes
9278 E := Current_Scope;
9279 loop
9280 K := Ekind (E);
9282 if K in Subprogram_Kind
9283 or else K in Concurrent_Kind
9284 or else K in Generic_Subprogram_Kind
9285 then
9286 return True;
9288 elsif E = Standard_Standard then
9289 return False;
9290 end if;
9292 E := Scope (E);
9293 end loop;
9294 end In_Subprogram_Or_Concurrent_Unit;
9296 ---------------------
9297 -- In_Visible_Part --
9298 ---------------------
9300 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
9301 begin
9302 return Is_Package_Or_Generic_Package (Scope_Id)
9303 and then In_Open_Scopes (Scope_Id)
9304 and then not In_Package_Body (Scope_Id)
9305 and then not In_Private_Part (Scope_Id);
9306 end In_Visible_Part;
9308 --------------------------------
9309 -- Incomplete_Or_Private_View --
9310 --------------------------------
9312 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
9313 function Inspect_Decls
9314 (Decls : List_Id;
9315 Taft : Boolean := False) return Entity_Id;
9316 -- Check whether a declarative region contains the incomplete or private
9317 -- view of Typ.
9319 -------------------
9320 -- Inspect_Decls --
9321 -------------------
9323 function Inspect_Decls
9324 (Decls : List_Id;
9325 Taft : Boolean := False) return Entity_Id
9327 Decl : Node_Id;
9328 Match : Node_Id;
9330 begin
9331 Decl := First (Decls);
9332 while Present (Decl) loop
9333 Match := Empty;
9335 if Taft then
9336 if Nkind (Decl) = N_Incomplete_Type_Declaration then
9337 Match := Defining_Identifier (Decl);
9338 end if;
9340 else
9341 if Nkind_In (Decl, N_Private_Extension_Declaration,
9342 N_Private_Type_Declaration)
9343 then
9344 Match := Defining_Identifier (Decl);
9345 end if;
9346 end if;
9348 if Present (Match)
9349 and then Present (Full_View (Match))
9350 and then Full_View (Match) = Typ
9351 then
9352 return Match;
9353 end if;
9355 Next (Decl);
9356 end loop;
9358 return Empty;
9359 end Inspect_Decls;
9361 -- Local variables
9363 Prev : Entity_Id;
9365 -- Start of processing for Incomplete_Or_Partial_View
9367 begin
9368 -- Incomplete type case
9370 Prev := Current_Entity_In_Scope (Typ);
9372 if Present (Prev)
9373 and then Is_Incomplete_Type (Prev)
9374 and then Present (Full_View (Prev))
9375 and then Full_View (Prev) = Typ
9376 then
9377 return Prev;
9378 end if;
9380 -- Private or Taft amendment type case
9382 declare
9383 Pkg : constant Entity_Id := Scope (Typ);
9384 Pkg_Decl : Node_Id := Pkg;
9386 begin
9387 if Ekind (Pkg) = E_Package then
9388 while Nkind (Pkg_Decl) /= N_Package_Specification loop
9389 Pkg_Decl := Parent (Pkg_Decl);
9390 end loop;
9392 -- It is knows that Typ has a private view, look for it in the
9393 -- visible declarations of the enclosing scope. A special case
9394 -- of this is when the two views have been exchanged - the full
9395 -- appears earlier than the private.
9397 if Has_Private_Declaration (Typ) then
9398 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
9400 -- Exchanged view case, look in the private declarations
9402 if No (Prev) then
9403 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
9404 end if;
9406 return Prev;
9408 -- Otherwise if this is the package body, then Typ is a potential
9409 -- Taft amendment type. The incomplete view should be located in
9410 -- the private declarations of the enclosing scope.
9412 elsif In_Package_Body (Pkg) then
9413 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
9414 end if;
9415 end if;
9416 end;
9418 -- The type has no incomplete or private view
9420 return Empty;
9421 end Incomplete_Or_Private_View;
9423 -----------------------------------------
9424 -- Inherit_Default_Init_Cond_Procedure --
9425 -----------------------------------------
9427 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
9428 Par_Typ : constant Entity_Id := Etype (Typ);
9430 begin
9431 -- A derived type inherits the default initial condition procedure of
9432 -- its parent type.
9434 if No (Default_Init_Cond_Procedure (Typ)) then
9435 Set_Default_Init_Cond_Procedure
9436 (Typ, Default_Init_Cond_Procedure (Par_Typ));
9437 end if;
9438 end Inherit_Default_Init_Cond_Procedure;
9440 ----------------------------
9441 -- Inherit_Rep_Item_Chain --
9442 ----------------------------
9444 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
9445 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
9446 Item : Node_Id := Empty;
9447 Last_Item : Node_Id := Empty;
9449 begin
9450 -- Reach the end of the destination type's chain (if any) and capture
9451 -- the last item.
9453 Item := First_Rep_Item (Typ);
9454 while Present (Item) loop
9456 -- Do not inherit a chain that has been inherited already
9458 if Item = From_Item then
9459 return;
9460 end if;
9462 Last_Item := Item;
9463 Item := Next_Rep_Item (Item);
9464 end loop;
9466 -- When the destination type has a rep item chain, the chain of the
9467 -- source type is appended to it.
9469 if Present (Last_Item) then
9470 Set_Next_Rep_Item (Last_Item, From_Item);
9472 -- Otherwise the destination type directly inherits the rep item chain
9473 -- of the source type (if any).
9475 else
9476 Set_First_Rep_Item (Typ, From_Item);
9477 end if;
9478 end Inherit_Rep_Item_Chain;
9480 ---------------------------------
9481 -- Inherit_Subprogram_Contract --
9482 ---------------------------------
9484 procedure Inherit_Subprogram_Contract
9485 (Subp : Entity_Id;
9486 From_Subp : Entity_Id)
9488 procedure Inherit_Pragma (Prag_Id : Pragma_Id);
9489 -- Propagate a pragma denoted by Prag_Id from From_Subp's contract to
9490 -- Subp's contract.
9492 --------------------
9493 -- Inherit_Pragma --
9494 --------------------
9496 procedure Inherit_Pragma (Prag_Id : Pragma_Id) is
9497 Prag : constant Node_Id := Get_Pragma (From_Subp, Prag_Id);
9498 New_Prag : Node_Id;
9500 begin
9501 -- A pragma cannot be part of more than one First_Pragma/Next_Pragma
9502 -- chains, therefore the node must be replicated. The new pragma is
9503 -- flagged is inherited for distrinction purposes.
9505 if Present (Prag) then
9506 New_Prag := New_Copy_Tree (Prag);
9507 Set_Is_Inherited (New_Prag);
9509 Add_Contract_Item (New_Prag, Subp);
9510 end if;
9511 end Inherit_Pragma;
9513 -- Start of processing for Inherit_Subprogram_Contract
9515 begin
9516 -- Inheritance is carried out only when both entities are subprograms
9517 -- with contracts.
9519 if Is_Subprogram_Or_Generic_Subprogram (Subp)
9520 and then Is_Subprogram_Or_Generic_Subprogram (From_Subp)
9521 and then Present (Contract (Subp))
9522 and then Present (Contract (From_Subp))
9523 then
9524 Inherit_Pragma (Pragma_Extensions_Visible);
9525 end if;
9526 end Inherit_Subprogram_Contract;
9528 ---------------------------------
9529 -- Insert_Explicit_Dereference --
9530 ---------------------------------
9532 procedure Insert_Explicit_Dereference (N : Node_Id) is
9533 New_Prefix : constant Node_Id := Relocate_Node (N);
9534 Ent : Entity_Id := Empty;
9535 Pref : Node_Id;
9536 I : Interp_Index;
9537 It : Interp;
9538 T : Entity_Id;
9540 begin
9541 Save_Interps (N, New_Prefix);
9543 Rewrite (N,
9544 Make_Explicit_Dereference (Sloc (Parent (N)),
9545 Prefix => New_Prefix));
9547 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
9549 if Is_Overloaded (New_Prefix) then
9551 -- The dereference is also overloaded, and its interpretations are
9552 -- the designated types of the interpretations of the original node.
9554 Set_Etype (N, Any_Type);
9556 Get_First_Interp (New_Prefix, I, It);
9557 while Present (It.Nam) loop
9558 T := It.Typ;
9560 if Is_Access_Type (T) then
9561 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
9562 end if;
9564 Get_Next_Interp (I, It);
9565 end loop;
9567 End_Interp_List;
9569 else
9570 -- Prefix is unambiguous: mark the original prefix (which might
9571 -- Come_From_Source) as a reference, since the new (relocated) one
9572 -- won't be taken into account.
9574 if Is_Entity_Name (New_Prefix) then
9575 Ent := Entity (New_Prefix);
9576 Pref := New_Prefix;
9578 -- For a retrieval of a subcomponent of some composite object,
9579 -- retrieve the ultimate entity if there is one.
9581 elsif Nkind_In (New_Prefix, N_Selected_Component,
9582 N_Indexed_Component)
9583 then
9584 Pref := Prefix (New_Prefix);
9585 while Present (Pref)
9586 and then Nkind_In (Pref, N_Selected_Component,
9587 N_Indexed_Component)
9588 loop
9589 Pref := Prefix (Pref);
9590 end loop;
9592 if Present (Pref) and then Is_Entity_Name (Pref) then
9593 Ent := Entity (Pref);
9594 end if;
9595 end if;
9597 -- Place the reference on the entity node
9599 if Present (Ent) then
9600 Generate_Reference (Ent, Pref);
9601 end if;
9602 end if;
9603 end Insert_Explicit_Dereference;
9605 ------------------------------------------
9606 -- Inspect_Deferred_Constant_Completion --
9607 ------------------------------------------
9609 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
9610 Decl : Node_Id;
9612 begin
9613 Decl := First (Decls);
9614 while Present (Decl) loop
9616 -- Deferred constant signature
9618 if Nkind (Decl) = N_Object_Declaration
9619 and then Constant_Present (Decl)
9620 and then No (Expression (Decl))
9622 -- No need to check internally generated constants
9624 and then Comes_From_Source (Decl)
9626 -- The constant is not completed. A full object declaration or a
9627 -- pragma Import complete a deferred constant.
9629 and then not Has_Completion (Defining_Identifier (Decl))
9630 then
9631 Error_Msg_N
9632 ("constant declaration requires initialization expression",
9633 Defining_Identifier (Decl));
9634 end if;
9636 Decl := Next (Decl);
9637 end loop;
9638 end Inspect_Deferred_Constant_Completion;
9640 -----------------------------
9641 -- Is_Actual_Out_Parameter --
9642 -----------------------------
9644 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
9645 Formal : Entity_Id;
9646 Call : Node_Id;
9647 begin
9648 Find_Actual (N, Formal, Call);
9649 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
9650 end Is_Actual_Out_Parameter;
9652 -------------------------
9653 -- Is_Actual_Parameter --
9654 -------------------------
9656 function Is_Actual_Parameter (N : Node_Id) return Boolean is
9657 PK : constant Node_Kind := Nkind (Parent (N));
9659 begin
9660 case PK is
9661 when N_Parameter_Association =>
9662 return N = Explicit_Actual_Parameter (Parent (N));
9664 when N_Subprogram_Call =>
9665 return Is_List_Member (N)
9666 and then
9667 List_Containing (N) = Parameter_Associations (Parent (N));
9669 when others =>
9670 return False;
9671 end case;
9672 end Is_Actual_Parameter;
9674 --------------------------------
9675 -- Is_Actual_Tagged_Parameter --
9676 --------------------------------
9678 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
9679 Formal : Entity_Id;
9680 Call : Node_Id;
9681 begin
9682 Find_Actual (N, Formal, Call);
9683 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
9684 end Is_Actual_Tagged_Parameter;
9686 ---------------------
9687 -- Is_Aliased_View --
9688 ---------------------
9690 function Is_Aliased_View (Obj : Node_Id) return Boolean is
9691 E : Entity_Id;
9693 begin
9694 if Is_Entity_Name (Obj) then
9695 E := Entity (Obj);
9697 return
9698 (Is_Object (E)
9699 and then
9700 (Is_Aliased (E)
9701 or else (Present (Renamed_Object (E))
9702 and then Is_Aliased_View (Renamed_Object (E)))))
9704 or else ((Is_Formal (E)
9705 or else Ekind_In (E, E_Generic_In_Out_Parameter,
9706 E_Generic_In_Parameter))
9707 and then Is_Tagged_Type (Etype (E)))
9709 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
9711 -- Current instance of type, either directly or as rewritten
9712 -- reference to the current object.
9714 or else (Is_Entity_Name (Original_Node (Obj))
9715 and then Present (Entity (Original_Node (Obj)))
9716 and then Is_Type (Entity (Original_Node (Obj))))
9718 or else (Is_Type (E) and then E = Current_Scope)
9720 or else (Is_Incomplete_Or_Private_Type (E)
9721 and then Full_View (E) = Current_Scope)
9723 -- Ada 2012 AI05-0053: the return object of an extended return
9724 -- statement is aliased if its type is immutably limited.
9726 or else (Is_Return_Object (E)
9727 and then Is_Limited_View (Etype (E)));
9729 elsif Nkind (Obj) = N_Selected_Component then
9730 return Is_Aliased (Entity (Selector_Name (Obj)));
9732 elsif Nkind (Obj) = N_Indexed_Component then
9733 return Has_Aliased_Components (Etype (Prefix (Obj)))
9734 or else
9735 (Is_Access_Type (Etype (Prefix (Obj)))
9736 and then Has_Aliased_Components
9737 (Designated_Type (Etype (Prefix (Obj)))));
9739 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
9740 return Is_Tagged_Type (Etype (Obj))
9741 and then Is_Aliased_View (Expression (Obj));
9743 elsif Nkind (Obj) = N_Explicit_Dereference then
9744 return Nkind (Original_Node (Obj)) /= N_Function_Call;
9746 else
9747 return False;
9748 end if;
9749 end Is_Aliased_View;
9751 -------------------------
9752 -- Is_Ancestor_Package --
9753 -------------------------
9755 function Is_Ancestor_Package
9756 (E1 : Entity_Id;
9757 E2 : Entity_Id) return Boolean
9759 Par : Entity_Id;
9761 begin
9762 Par := E2;
9763 while Present (Par) and then Par /= Standard_Standard loop
9764 if Par = E1 then
9765 return True;
9766 end if;
9768 Par := Scope (Par);
9769 end loop;
9771 return False;
9772 end Is_Ancestor_Package;
9774 ----------------------
9775 -- Is_Atomic_Object --
9776 ----------------------
9778 function Is_Atomic_Object (N : Node_Id) return Boolean is
9780 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
9781 -- Determines if given object has atomic components
9783 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
9784 -- If prefix is an implicit dereference, examine designated type
9786 ----------------------
9787 -- Is_Atomic_Prefix --
9788 ----------------------
9790 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
9791 begin
9792 if Is_Access_Type (Etype (N)) then
9793 return
9794 Has_Atomic_Components (Designated_Type (Etype (N)));
9795 else
9796 return Object_Has_Atomic_Components (N);
9797 end if;
9798 end Is_Atomic_Prefix;
9800 ----------------------------------
9801 -- Object_Has_Atomic_Components --
9802 ----------------------------------
9804 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
9805 begin
9806 if Has_Atomic_Components (Etype (N))
9807 or else Is_Atomic (Etype (N))
9808 then
9809 return True;
9811 elsif Is_Entity_Name (N)
9812 and then (Has_Atomic_Components (Entity (N))
9813 or else Is_Atomic (Entity (N)))
9814 then
9815 return True;
9817 elsif Nkind (N) = N_Selected_Component
9818 and then Is_Atomic (Entity (Selector_Name (N)))
9819 then
9820 return True;
9822 elsif Nkind (N) = N_Indexed_Component
9823 or else Nkind (N) = N_Selected_Component
9824 then
9825 return Is_Atomic_Prefix (Prefix (N));
9827 else
9828 return False;
9829 end if;
9830 end Object_Has_Atomic_Components;
9832 -- Start of processing for Is_Atomic_Object
9834 begin
9835 -- Predicate is not relevant to subprograms
9837 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
9838 return False;
9840 elsif Is_Atomic (Etype (N))
9841 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
9842 then
9843 return True;
9845 elsif Nkind (N) = N_Selected_Component
9846 and then Is_Atomic (Entity (Selector_Name (N)))
9847 then
9848 return True;
9850 elsif Nkind (N) = N_Indexed_Component
9851 or else Nkind (N) = N_Selected_Component
9852 then
9853 return Is_Atomic_Prefix (Prefix (N));
9855 else
9856 return False;
9857 end if;
9858 end Is_Atomic_Object;
9860 -------------------------
9861 -- Is_Attribute_Result --
9862 -------------------------
9864 function Is_Attribute_Result (N : Node_Id) return Boolean is
9865 begin
9866 return Nkind (N) = N_Attribute_Reference
9867 and then Attribute_Name (N) = Name_Result;
9868 end Is_Attribute_Result;
9870 ------------------------------------
9871 -- Is_Body_Or_Package_Declaration --
9872 ------------------------------------
9874 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
9875 begin
9876 return Nkind_In (N, N_Entry_Body,
9877 N_Package_Body,
9878 N_Package_Declaration,
9879 N_Protected_Body,
9880 N_Subprogram_Body,
9881 N_Task_Body);
9882 end Is_Body_Or_Package_Declaration;
9884 -----------------------
9885 -- Is_Bounded_String --
9886 -----------------------
9888 function Is_Bounded_String (T : Entity_Id) return Boolean is
9889 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
9891 begin
9892 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9893 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9894 -- be True for all the Bounded_String types in instances of the
9895 -- Generic_Bounded_Length generics, and for types derived from those.
9897 return Present (Under)
9898 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
9899 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
9900 Is_RTE (Root_Type (Under), RO_WW_Super_String));
9901 end Is_Bounded_String;
9903 -------------------------
9904 -- Is_Child_Or_Sibling --
9905 -------------------------
9907 function Is_Child_Or_Sibling
9908 (Pack_1 : Entity_Id;
9909 Pack_2 : Entity_Id) return Boolean
9911 function Distance_From_Standard (Pack : Entity_Id) return Nat;
9912 -- Given an arbitrary package, return the number of "climbs" necessary
9913 -- to reach scope Standard_Standard.
9915 procedure Equalize_Depths
9916 (Pack : in out Entity_Id;
9917 Depth : in out Nat;
9918 Depth_To_Reach : Nat);
9919 -- Given an arbitrary package, its depth and a target depth to reach,
9920 -- climb the scope chain until the said depth is reached. The pointer
9921 -- to the package and its depth a modified during the climb.
9923 ----------------------------
9924 -- Distance_From_Standard --
9925 ----------------------------
9927 function Distance_From_Standard (Pack : Entity_Id) return Nat is
9928 Dist : Nat;
9929 Scop : Entity_Id;
9931 begin
9932 Dist := 0;
9933 Scop := Pack;
9934 while Present (Scop) and then Scop /= Standard_Standard loop
9935 Dist := Dist + 1;
9936 Scop := Scope (Scop);
9937 end loop;
9939 return Dist;
9940 end Distance_From_Standard;
9942 ---------------------
9943 -- Equalize_Depths --
9944 ---------------------
9946 procedure Equalize_Depths
9947 (Pack : in out Entity_Id;
9948 Depth : in out Nat;
9949 Depth_To_Reach : Nat)
9951 begin
9952 -- The package must be at a greater or equal depth
9954 if Depth < Depth_To_Reach then
9955 raise Program_Error;
9956 end if;
9958 -- Climb the scope chain until the desired depth is reached
9960 while Present (Pack) and then Depth /= Depth_To_Reach loop
9961 Pack := Scope (Pack);
9962 Depth := Depth - 1;
9963 end loop;
9964 end Equalize_Depths;
9966 -- Local variables
9968 P_1 : Entity_Id := Pack_1;
9969 P_1_Child : Boolean := False;
9970 P_1_Depth : Nat := Distance_From_Standard (P_1);
9971 P_2 : Entity_Id := Pack_2;
9972 P_2_Child : Boolean := False;
9973 P_2_Depth : Nat := Distance_From_Standard (P_2);
9975 -- Start of processing for Is_Child_Or_Sibling
9977 begin
9978 pragma Assert
9979 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
9981 -- Both packages denote the same entity, therefore they cannot be
9982 -- children or siblings.
9984 if P_1 = P_2 then
9985 return False;
9987 -- One of the packages is at a deeper level than the other. Note that
9988 -- both may still come from differen hierarchies.
9990 -- (root) P_2
9991 -- / \ :
9992 -- X P_2 or X
9993 -- : :
9994 -- P_1 P_1
9996 elsif P_1_Depth > P_2_Depth then
9997 Equalize_Depths
9998 (Pack => P_1,
9999 Depth => P_1_Depth,
10000 Depth_To_Reach => P_2_Depth);
10001 P_1_Child := True;
10003 -- (root) P_1
10004 -- / \ :
10005 -- P_1 X or X
10006 -- : :
10007 -- P_2 P_2
10009 elsif P_2_Depth > P_1_Depth then
10010 Equalize_Depths
10011 (Pack => P_2,
10012 Depth => P_2_Depth,
10013 Depth_To_Reach => P_1_Depth);
10014 P_2_Child := True;
10015 end if;
10017 -- At this stage the package pointers have been elevated to the same
10018 -- depth. If the related entities are the same, then one package is a
10019 -- potential child of the other:
10021 -- P_1
10022 -- :
10023 -- X became P_1 P_2 or vica versa
10024 -- :
10025 -- P_2
10027 if P_1 = P_2 then
10028 if P_1_Child then
10029 return Is_Child_Unit (Pack_1);
10031 else pragma Assert (P_2_Child);
10032 return Is_Child_Unit (Pack_2);
10033 end if;
10035 -- The packages may come from the same package chain or from entirely
10036 -- different hierarcies. To determine this, climb the scope stack until
10037 -- a common root is found.
10039 -- (root) (root 1) (root 2)
10040 -- / \ | |
10041 -- P_1 P_2 P_1 P_2
10043 else
10044 while Present (P_1) and then Present (P_2) loop
10046 -- The two packages may be siblings
10048 if P_1 = P_2 then
10049 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
10050 end if;
10052 P_1 := Scope (P_1);
10053 P_2 := Scope (P_2);
10054 end loop;
10055 end if;
10057 return False;
10058 end Is_Child_Or_Sibling;
10060 -----------------------------
10061 -- Is_Concurrent_Interface --
10062 -----------------------------
10064 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
10065 begin
10066 return Is_Interface (T)
10067 and then
10068 (Is_Protected_Interface (T)
10069 or else Is_Synchronized_Interface (T)
10070 or else Is_Task_Interface (T));
10071 end Is_Concurrent_Interface;
10073 ---------------------------
10074 -- Is_Container_Element --
10075 ---------------------------
10077 function Is_Container_Element (Exp : Node_Id) return Boolean is
10078 Loc : constant Source_Ptr := Sloc (Exp);
10079 Pref : constant Node_Id := Prefix (Exp);
10081 Call : Node_Id;
10082 -- Call to an indexing aspect
10084 Cont_Typ : Entity_Id;
10085 -- The type of the container being accessed
10087 Elem_Typ : Entity_Id;
10088 -- Its element type
10090 Indexing : Entity_Id;
10091 Is_Const : Boolean;
10092 -- Indicates that constant indexing is used, and the element is thus
10093 -- a constant.
10095 Ref_Typ : Entity_Id;
10096 -- The reference type returned by the indexing operation
10098 begin
10099 -- If C is a container, in a context that imposes the element type of
10100 -- that container, the indexing notation C (X) is rewritten as:
10102 -- Indexing (C, X).Discr.all
10104 -- where Indexing is one of the indexing aspects of the container.
10105 -- If the context does not require a reference, the construct can be
10106 -- rewritten as
10108 -- Element (C, X)
10110 -- First, verify that the construct has the proper form
10112 if not Expander_Active then
10113 return False;
10115 elsif Nkind (Pref) /= N_Selected_Component then
10116 return False;
10118 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
10119 return False;
10121 else
10122 Call := Prefix (Pref);
10123 Ref_Typ := Etype (Call);
10124 end if;
10126 if not Has_Implicit_Dereference (Ref_Typ)
10127 or else No (First (Parameter_Associations (Call)))
10128 or else not Is_Entity_Name (Name (Call))
10129 then
10130 return False;
10131 end if;
10133 -- Retrieve type of container object, and its iterator aspects
10135 Cont_Typ := Etype (First (Parameter_Associations (Call)));
10136 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
10137 Is_Const := False;
10139 if No (Indexing) then
10141 -- Container should have at least one indexing operation
10143 return False;
10145 elsif Entity (Name (Call)) /= Entity (Indexing) then
10147 -- This may be a variable indexing operation
10149 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
10151 if No (Indexing)
10152 or else Entity (Name (Call)) /= Entity (Indexing)
10153 then
10154 return False;
10155 end if;
10157 else
10158 Is_Const := True;
10159 end if;
10161 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
10163 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
10164 return False;
10165 end if;
10167 -- Check that the expression is not the target of an assignment, in
10168 -- which case the rewriting is not possible.
10170 if not Is_Const then
10171 declare
10172 Par : Node_Id;
10174 begin
10175 Par := Exp;
10176 while Present (Par)
10177 loop
10178 if Nkind (Parent (Par)) = N_Assignment_Statement
10179 and then Par = Name (Parent (Par))
10180 then
10181 return False;
10183 -- A renaming produces a reference, and the transformation
10184 -- does not apply.
10186 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
10187 return False;
10189 elsif Nkind_In
10190 (Nkind (Parent (Par)), N_Function_Call,
10191 N_Procedure_Call_Statement,
10192 N_Entry_Call_Statement)
10193 then
10194 -- Check that the element is not part of an actual for an
10195 -- in-out parameter.
10197 declare
10198 F : Entity_Id;
10199 A : Node_Id;
10201 begin
10202 F := First_Formal (Entity (Name (Parent (Par))));
10203 A := First (Parameter_Associations (Parent (Par)));
10204 while Present (F) loop
10205 if A = Par and then Ekind (F) /= E_In_Parameter then
10206 return False;
10207 end if;
10209 Next_Formal (F);
10210 Next (A);
10211 end loop;
10212 end;
10214 -- E_In_Parameter in a call: element is not modified.
10216 exit;
10217 end if;
10219 Par := Parent (Par);
10220 end loop;
10221 end;
10222 end if;
10224 -- The expression has the proper form and the context requires the
10225 -- element type. Retrieve the Element function of the container and
10226 -- rewrite the construct as a call to it.
10228 declare
10229 Op : Elmt_Id;
10231 begin
10232 Op := First_Elmt (Primitive_Operations (Cont_Typ));
10233 while Present (Op) loop
10234 exit when Chars (Node (Op)) = Name_Element;
10235 Next_Elmt (Op);
10236 end loop;
10238 if No (Op) then
10239 return False;
10241 else
10242 Rewrite (Exp,
10243 Make_Function_Call (Loc,
10244 Name => New_Occurrence_Of (Node (Op), Loc),
10245 Parameter_Associations => Parameter_Associations (Call)));
10246 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
10247 return True;
10248 end if;
10249 end;
10250 end Is_Container_Element;
10252 -----------------------
10253 -- Is_Constant_Bound --
10254 -----------------------
10256 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
10257 begin
10258 if Compile_Time_Known_Value (Exp) then
10259 return True;
10261 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10262 return Is_Constant_Object (Entity (Exp))
10263 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10265 elsif Nkind (Exp) in N_Binary_Op then
10266 return Is_Constant_Bound (Left_Opnd (Exp))
10267 and then Is_Constant_Bound (Right_Opnd (Exp))
10268 and then Scope (Entity (Exp)) = Standard_Standard;
10270 else
10271 return False;
10272 end if;
10273 end Is_Constant_Bound;
10275 --------------------------------------
10276 -- Is_Controlling_Limited_Procedure --
10277 --------------------------------------
10279 function Is_Controlling_Limited_Procedure
10280 (Proc_Nam : Entity_Id) return Boolean
10282 Param_Typ : Entity_Id := Empty;
10284 begin
10285 if Ekind (Proc_Nam) = E_Procedure
10286 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
10287 then
10288 Param_Typ := Etype (Parameter_Type (First (
10289 Parameter_Specifications (Parent (Proc_Nam)))));
10291 -- In this case where an Itype was created, the procedure call has been
10292 -- rewritten.
10294 elsif Present (Associated_Node_For_Itype (Proc_Nam))
10295 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
10296 and then
10297 Present (Parameter_Associations
10298 (Associated_Node_For_Itype (Proc_Nam)))
10299 then
10300 Param_Typ :=
10301 Etype (First (Parameter_Associations
10302 (Associated_Node_For_Itype (Proc_Nam))));
10303 end if;
10305 if Present (Param_Typ) then
10306 return
10307 Is_Interface (Param_Typ)
10308 and then Is_Limited_Record (Param_Typ);
10309 end if;
10311 return False;
10312 end Is_Controlling_Limited_Procedure;
10314 -----------------------------
10315 -- Is_CPP_Constructor_Call --
10316 -----------------------------
10318 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
10319 begin
10320 return Nkind (N) = N_Function_Call
10321 and then Is_CPP_Class (Etype (Etype (N)))
10322 and then Is_Constructor (Entity (Name (N)))
10323 and then Is_Imported (Entity (Name (N)));
10324 end Is_CPP_Constructor_Call;
10326 -----------------
10327 -- Is_Delegate --
10328 -----------------
10330 function Is_Delegate (T : Entity_Id) return Boolean is
10331 Desig_Type : Entity_Id;
10333 begin
10334 if VM_Target /= CLI_Target then
10335 return False;
10336 end if;
10338 -- Access-to-subprograms are delegates in CIL
10340 if Ekind (T) = E_Access_Subprogram_Type then
10341 return True;
10342 end if;
10344 if not Is_Access_Type (T) then
10346 -- A delegate is a managed pointer. If no designated type is defined
10347 -- it means that it's not a delegate.
10349 return False;
10350 end if;
10352 Desig_Type := Etype (Directly_Designated_Type (T));
10354 if not Is_Tagged_Type (Desig_Type) then
10355 return False;
10356 end if;
10358 -- Test if the type is inherited from [mscorlib]System.Delegate
10360 while Etype (Desig_Type) /= Desig_Type loop
10361 if Chars (Scope (Desig_Type)) /= No_Name
10362 and then Is_Imported (Scope (Desig_Type))
10363 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
10364 then
10365 return True;
10366 end if;
10368 Desig_Type := Etype (Desig_Type);
10369 end loop;
10371 return False;
10372 end Is_Delegate;
10374 ----------------------------------------------
10375 -- Is_Dependent_Component_Of_Mutable_Object --
10376 ----------------------------------------------
10378 function Is_Dependent_Component_Of_Mutable_Object
10379 (Object : Node_Id) return Boolean
10381 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
10382 -- Returns True if and only if Comp is declared within a variant part
10384 --------------------------------
10385 -- Is_Declared_Within_Variant --
10386 --------------------------------
10388 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
10389 Comp_Decl : constant Node_Id := Parent (Comp);
10390 Comp_List : constant Node_Id := Parent (Comp_Decl);
10391 begin
10392 return Nkind (Parent (Comp_List)) = N_Variant;
10393 end Is_Declared_Within_Variant;
10395 P : Node_Id;
10396 Prefix_Type : Entity_Id;
10397 P_Aliased : Boolean := False;
10398 Comp : Entity_Id;
10400 Deref : Node_Id := Object;
10401 -- Dereference node, in something like X.all.Y(2)
10403 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10405 begin
10406 -- Find the dereference node if any
10408 while Nkind_In (Deref, N_Indexed_Component,
10409 N_Selected_Component,
10410 N_Slice)
10411 loop
10412 Deref := Prefix (Deref);
10413 end loop;
10415 -- Ada 2005: If we have a component or slice of a dereference,
10416 -- something like X.all.Y (2), and the type of X is access-to-constant,
10417 -- Is_Variable will return False, because it is indeed a constant
10418 -- view. But it might be a view of a variable object, so we want the
10419 -- following condition to be True in that case.
10421 if Is_Variable (Object)
10422 or else (Ada_Version >= Ada_2005
10423 and then Nkind (Deref) = N_Explicit_Dereference)
10424 then
10425 if Nkind (Object) = N_Selected_Component then
10426 P := Prefix (Object);
10427 Prefix_Type := Etype (P);
10429 if Is_Entity_Name (P) then
10430 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
10431 Prefix_Type := Base_Type (Prefix_Type);
10432 end if;
10434 if Is_Aliased (Entity (P)) then
10435 P_Aliased := True;
10436 end if;
10438 -- A discriminant check on a selected component may be expanded
10439 -- into a dereference when removing side-effects. Recover the
10440 -- original node and its type, which may be unconstrained.
10442 elsif Nkind (P) = N_Explicit_Dereference
10443 and then not (Comes_From_Source (P))
10444 then
10445 P := Original_Node (P);
10446 Prefix_Type := Etype (P);
10448 else
10449 -- Check for prefix being an aliased component???
10451 null;
10453 end if;
10455 -- A heap object is constrained by its initial value
10457 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10458 -- the dereferenced case, since the access value might denote an
10459 -- unconstrained aliased object, whereas in Ada 95 the designated
10460 -- object is guaranteed to be constrained. A worst-case assumption
10461 -- has to apply in Ada 2005 because we can't tell at compile
10462 -- time whether the object is "constrained by its initial value"
10463 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10464 -- rules (these rules are acknowledged to need fixing).
10466 if Ada_Version < Ada_2005 then
10467 if Is_Access_Type (Prefix_Type)
10468 or else Nkind (P) = N_Explicit_Dereference
10469 then
10470 return False;
10471 end if;
10473 else pragma Assert (Ada_Version >= Ada_2005);
10474 if Is_Access_Type (Prefix_Type) then
10476 -- If the access type is pool-specific, and there is no
10477 -- constrained partial view of the designated type, then the
10478 -- designated object is known to be constrained.
10480 if Ekind (Prefix_Type) = E_Access_Type
10481 and then not Object_Type_Has_Constrained_Partial_View
10482 (Typ => Designated_Type (Prefix_Type),
10483 Scop => Current_Scope)
10484 then
10485 return False;
10487 -- Otherwise (general access type, or there is a constrained
10488 -- partial view of the designated type), we need to check
10489 -- based on the designated type.
10491 else
10492 Prefix_Type := Designated_Type (Prefix_Type);
10493 end if;
10494 end if;
10495 end if;
10497 Comp :=
10498 Original_Record_Component (Entity (Selector_Name (Object)));
10500 -- As per AI-0017, the renaming is illegal in a generic body, even
10501 -- if the subtype is indefinite.
10503 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10505 if not Is_Constrained (Prefix_Type)
10506 and then (not Is_Indefinite_Subtype (Prefix_Type)
10507 or else
10508 (Is_Generic_Type (Prefix_Type)
10509 and then Ekind (Current_Scope) = E_Generic_Package
10510 and then In_Package_Body (Current_Scope)))
10512 and then (Is_Declared_Within_Variant (Comp)
10513 or else Has_Discriminant_Dependent_Constraint (Comp))
10514 and then (not P_Aliased or else Ada_Version >= Ada_2005)
10515 then
10516 return True;
10518 -- If the prefix is of an access type at this point, then we want
10519 -- to return False, rather than calling this function recursively
10520 -- on the access object (which itself might be a discriminant-
10521 -- dependent component of some other object, but that isn't
10522 -- relevant to checking the object passed to us). This avoids
10523 -- issuing wrong errors when compiling with -gnatc, where there
10524 -- can be implicit dereferences that have not been expanded.
10526 elsif Is_Access_Type (Etype (Prefix (Object))) then
10527 return False;
10529 else
10530 return
10531 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10532 end if;
10534 elsif Nkind (Object) = N_Indexed_Component
10535 or else Nkind (Object) = N_Slice
10536 then
10537 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10539 -- A type conversion that Is_Variable is a view conversion:
10540 -- go back to the denoted object.
10542 elsif Nkind (Object) = N_Type_Conversion then
10543 return
10544 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
10545 end if;
10546 end if;
10548 return False;
10549 end Is_Dependent_Component_Of_Mutable_Object;
10551 ---------------------
10552 -- Is_Dereferenced --
10553 ---------------------
10555 function Is_Dereferenced (N : Node_Id) return Boolean is
10556 P : constant Node_Id := Parent (N);
10557 begin
10558 return Nkind_In (P, N_Selected_Component,
10559 N_Explicit_Dereference,
10560 N_Indexed_Component,
10561 N_Slice)
10562 and then Prefix (P) = N;
10563 end Is_Dereferenced;
10565 ----------------------
10566 -- Is_Descendent_Of --
10567 ----------------------
10569 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
10570 T : Entity_Id;
10571 Etyp : Entity_Id;
10573 begin
10574 pragma Assert (Nkind (T1) in N_Entity);
10575 pragma Assert (Nkind (T2) in N_Entity);
10577 T := Base_Type (T1);
10579 -- Immediate return if the types match
10581 if T = T2 then
10582 return True;
10584 -- Comment needed here ???
10586 elsif Ekind (T) = E_Class_Wide_Type then
10587 return Etype (T) = T2;
10589 -- All other cases
10591 else
10592 loop
10593 Etyp := Etype (T);
10595 -- Done if we found the type we are looking for
10597 if Etyp = T2 then
10598 return True;
10600 -- Done if no more derivations to check
10602 elsif T = T1
10603 or else T = Etyp
10604 then
10605 return False;
10607 -- Following test catches error cases resulting from prev errors
10609 elsif No (Etyp) then
10610 return False;
10612 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
10613 return False;
10615 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
10616 return False;
10617 end if;
10619 T := Base_Type (Etyp);
10620 end loop;
10621 end if;
10622 end Is_Descendent_Of;
10624 -----------------------------
10625 -- Is_Effectively_Volatile --
10626 -----------------------------
10628 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
10629 begin
10630 if Is_Type (Id) then
10632 -- An arbitrary type is effectively volatile when it is subject to
10633 -- pragma Atomic or Volatile.
10635 if Is_Volatile (Id) then
10636 return True;
10638 -- An array type is effectively volatile when it is subject to pragma
10639 -- Atomic_Components or Volatile_Components or its compolent type is
10640 -- effectively volatile.
10642 elsif Is_Array_Type (Id) then
10643 return
10644 Has_Volatile_Components (Id)
10645 or else
10646 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
10648 else
10649 return False;
10650 end if;
10652 -- Otherwise Id denotes an object
10654 else
10655 return
10656 Is_Volatile (Id)
10657 or else Has_Volatile_Components (Id)
10658 or else Is_Effectively_Volatile (Etype (Id));
10659 end if;
10660 end Is_Effectively_Volatile;
10662 ------------------------------------
10663 -- Is_Effectively_Volatile_Object --
10664 ------------------------------------
10666 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
10667 begin
10668 if Is_Entity_Name (N) then
10669 return Is_Effectively_Volatile (Entity (N));
10671 elsif Nkind (N) = N_Expanded_Name then
10672 return Is_Effectively_Volatile (Entity (N));
10674 elsif Nkind (N) = N_Indexed_Component then
10675 return Is_Effectively_Volatile_Object (Prefix (N));
10677 elsif Nkind (N) = N_Selected_Component then
10678 return
10679 Is_Effectively_Volatile_Object (Prefix (N))
10680 or else
10681 Is_Effectively_Volatile_Object (Selector_Name (N));
10683 else
10684 return False;
10685 end if;
10686 end Is_Effectively_Volatile_Object;
10688 ----------------------------
10689 -- Is_Expression_Function --
10690 ----------------------------
10692 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
10693 Decl : Node_Id;
10695 begin
10696 if Ekind (Subp) /= E_Function then
10697 return False;
10699 else
10700 Decl := Unit_Declaration_Node (Subp);
10701 return Nkind (Decl) = N_Subprogram_Declaration
10702 and then
10703 (Nkind (Original_Node (Decl)) = N_Expression_Function
10704 or else
10705 (Present (Corresponding_Body (Decl))
10706 and then
10707 Nkind (Original_Node
10708 (Unit_Declaration_Node
10709 (Corresponding_Body (Decl)))) =
10710 N_Expression_Function));
10711 end if;
10712 end Is_Expression_Function;
10714 -----------------------
10715 -- Is_EVF_Expression --
10716 -----------------------
10718 function Is_EVF_Expression (N : Node_Id) return Boolean is
10719 Orig_N : constant Node_Id := Original_Node (N);
10720 Alt : Node_Id;
10721 Expr : Node_Id;
10722 Id : Entity_Id;
10724 begin
10725 -- Detect a reference to a formal parameter of a specific tagged type
10726 -- whose related subprogram is subject to pragma Expresions_Visible with
10727 -- value "False".
10729 if Is_Entity_Name (N) and then Present (Entity (N)) then
10730 Id := Entity (N);
10732 return
10733 Is_Formal (Id)
10734 and then Is_Specific_Tagged_Type (Etype (Id))
10735 and then Extensions_Visible_Status (Id) =
10736 Extensions_Visible_False;
10738 -- A case expression is an EVF expression when it contains at least one
10739 -- EVF dependent_expression. Note that a case expression may have been
10740 -- expanded, hence the use of Original_Node.
10742 elsif Nkind (Orig_N) = N_Case_Expression then
10743 Alt := First (Alternatives (Orig_N));
10744 while Present (Alt) loop
10745 if Is_EVF_Expression (Expression (Alt)) then
10746 return True;
10747 end if;
10749 Next (Alt);
10750 end loop;
10752 -- An if expression is an EVF expression when it contains at least one
10753 -- EVF dependent_expression. Note that an if expression may have been
10754 -- expanded, hence the use of Original_Node.
10756 elsif Nkind (Orig_N) = N_If_Expression then
10757 Expr := Next (First (Expressions (Orig_N)));
10758 while Present (Expr) loop
10759 if Is_EVF_Expression (Expr) then
10760 return True;
10761 end if;
10763 Next (Expr);
10764 end loop;
10766 -- A qualified expression or a type conversion is an EVF expression when
10767 -- its operand is an EVF expression.
10769 elsif Nkind_In (N, N_Qualified_Expression,
10770 N_Unchecked_Type_Conversion,
10771 N_Type_Conversion)
10772 then
10773 return Is_EVF_Expression (Expression (N));
10774 end if;
10776 return False;
10777 end Is_EVF_Expression;
10779 --------------
10780 -- Is_False --
10781 --------------
10783 function Is_False (U : Uint) return Boolean is
10784 begin
10785 return (U = 0);
10786 end Is_False;
10788 ---------------------------
10789 -- Is_Fixed_Model_Number --
10790 ---------------------------
10792 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
10793 S : constant Ureal := Small_Value (T);
10794 M : Urealp.Save_Mark;
10795 R : Boolean;
10796 begin
10797 M := Urealp.Mark;
10798 R := (U = UR_Trunc (U / S) * S);
10799 Urealp.Release (M);
10800 return R;
10801 end Is_Fixed_Model_Number;
10803 -------------------------------
10804 -- Is_Fully_Initialized_Type --
10805 -------------------------------
10807 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
10808 begin
10809 -- Scalar types
10811 if Is_Scalar_Type (Typ) then
10813 -- A scalar type with an aspect Default_Value is fully initialized
10815 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
10816 -- of a scalar type, but we don't take that into account here, since
10817 -- we don't want these to affect warnings.
10819 return Has_Default_Aspect (Typ);
10821 elsif Is_Access_Type (Typ) then
10822 return True;
10824 elsif Is_Array_Type (Typ) then
10825 if Is_Fully_Initialized_Type (Component_Type (Typ))
10826 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
10827 then
10828 return True;
10829 end if;
10831 -- An interesting case, if we have a constrained type one of whose
10832 -- bounds is known to be null, then there are no elements to be
10833 -- initialized, so all the elements are initialized.
10835 if Is_Constrained (Typ) then
10836 declare
10837 Indx : Node_Id;
10838 Indx_Typ : Entity_Id;
10839 Lbd, Hbd : Node_Id;
10841 begin
10842 Indx := First_Index (Typ);
10843 while Present (Indx) loop
10844 if Etype (Indx) = Any_Type then
10845 return False;
10847 -- If index is a range, use directly
10849 elsif Nkind (Indx) = N_Range then
10850 Lbd := Low_Bound (Indx);
10851 Hbd := High_Bound (Indx);
10853 else
10854 Indx_Typ := Etype (Indx);
10856 if Is_Private_Type (Indx_Typ) then
10857 Indx_Typ := Full_View (Indx_Typ);
10858 end if;
10860 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
10861 return False;
10862 else
10863 Lbd := Type_Low_Bound (Indx_Typ);
10864 Hbd := Type_High_Bound (Indx_Typ);
10865 end if;
10866 end if;
10868 if Compile_Time_Known_Value (Lbd)
10869 and then
10870 Compile_Time_Known_Value (Hbd)
10871 then
10872 if Expr_Value (Hbd) < Expr_Value (Lbd) then
10873 return True;
10874 end if;
10875 end if;
10877 Next_Index (Indx);
10878 end loop;
10879 end;
10880 end if;
10882 -- If no null indexes, then type is not fully initialized
10884 return False;
10886 -- Record types
10888 elsif Is_Record_Type (Typ) then
10889 if Has_Discriminants (Typ)
10890 and then
10891 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
10892 and then Is_Fully_Initialized_Variant (Typ)
10893 then
10894 return True;
10895 end if;
10897 -- We consider bounded string types to be fully initialized, because
10898 -- otherwise we get false alarms when the Data component is not
10899 -- default-initialized.
10901 if Is_Bounded_String (Typ) then
10902 return True;
10903 end if;
10905 -- Controlled records are considered to be fully initialized if
10906 -- there is a user defined Initialize routine. This may not be
10907 -- entirely correct, but as the spec notes, we are guessing here
10908 -- what is best from the point of view of issuing warnings.
10910 if Is_Controlled (Typ) then
10911 declare
10912 Utyp : constant Entity_Id := Underlying_Type (Typ);
10914 begin
10915 if Present (Utyp) then
10916 declare
10917 Init : constant Entity_Id :=
10918 (Find_Prim_Op
10919 (Underlying_Type (Typ), Name_Initialize));
10921 begin
10922 if Present (Init)
10923 and then Comes_From_Source (Init)
10924 and then not
10925 Is_Predefined_File_Name
10926 (File_Name (Get_Source_File_Index (Sloc (Init))))
10927 then
10928 return True;
10930 elsif Has_Null_Extension (Typ)
10931 and then
10932 Is_Fully_Initialized_Type
10933 (Etype (Base_Type (Typ)))
10934 then
10935 return True;
10936 end if;
10937 end;
10938 end if;
10939 end;
10940 end if;
10942 -- Otherwise see if all record components are initialized
10944 declare
10945 Ent : Entity_Id;
10947 begin
10948 Ent := First_Entity (Typ);
10949 while Present (Ent) loop
10950 if Ekind (Ent) = E_Component
10951 and then (No (Parent (Ent))
10952 or else No (Expression (Parent (Ent))))
10953 and then not Is_Fully_Initialized_Type (Etype (Ent))
10955 -- Special VM case for tag components, which need to be
10956 -- defined in this case, but are never initialized as VMs
10957 -- are using other dispatching mechanisms. Ignore this
10958 -- uninitialized case. Note that this applies both to the
10959 -- uTag entry and the main vtable pointer (CPP_Class case).
10961 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
10962 then
10963 return False;
10964 end if;
10966 Next_Entity (Ent);
10967 end loop;
10968 end;
10970 -- No uninitialized components, so type is fully initialized.
10971 -- Note that this catches the case of no components as well.
10973 return True;
10975 elsif Is_Concurrent_Type (Typ) then
10976 return True;
10978 elsif Is_Private_Type (Typ) then
10979 declare
10980 U : constant Entity_Id := Underlying_Type (Typ);
10982 begin
10983 if No (U) then
10984 return False;
10985 else
10986 return Is_Fully_Initialized_Type (U);
10987 end if;
10988 end;
10990 else
10991 return False;
10992 end if;
10993 end Is_Fully_Initialized_Type;
10995 ----------------------------------
10996 -- Is_Fully_Initialized_Variant --
10997 ----------------------------------
10999 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
11000 Loc : constant Source_Ptr := Sloc (Typ);
11001 Constraints : constant List_Id := New_List;
11002 Components : constant Elist_Id := New_Elmt_List;
11003 Comp_Elmt : Elmt_Id;
11004 Comp_Id : Node_Id;
11005 Comp_List : Node_Id;
11006 Discr : Entity_Id;
11007 Discr_Val : Node_Id;
11009 Report_Errors : Boolean;
11010 pragma Warnings (Off, Report_Errors);
11012 begin
11013 if Serious_Errors_Detected > 0 then
11014 return False;
11015 end if;
11017 if Is_Record_Type (Typ)
11018 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11019 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
11020 then
11021 Comp_List := Component_List (Type_Definition (Parent (Typ)));
11023 Discr := First_Discriminant (Typ);
11024 while Present (Discr) loop
11025 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
11026 Discr_Val := Expression (Parent (Discr));
11028 if Present (Discr_Val)
11029 and then Is_OK_Static_Expression (Discr_Val)
11030 then
11031 Append_To (Constraints,
11032 Make_Component_Association (Loc,
11033 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
11034 Expression => New_Copy (Discr_Val)));
11035 else
11036 return False;
11037 end if;
11038 else
11039 return False;
11040 end if;
11042 Next_Discriminant (Discr);
11043 end loop;
11045 Gather_Components
11046 (Typ => Typ,
11047 Comp_List => Comp_List,
11048 Governed_By => Constraints,
11049 Into => Components,
11050 Report_Errors => Report_Errors);
11052 -- Check that each component present is fully initialized
11054 Comp_Elmt := First_Elmt (Components);
11055 while Present (Comp_Elmt) loop
11056 Comp_Id := Node (Comp_Elmt);
11058 if Ekind (Comp_Id) = E_Component
11059 and then (No (Parent (Comp_Id))
11060 or else No (Expression (Parent (Comp_Id))))
11061 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
11062 then
11063 return False;
11064 end if;
11066 Next_Elmt (Comp_Elmt);
11067 end loop;
11069 return True;
11071 elsif Is_Private_Type (Typ) then
11072 declare
11073 U : constant Entity_Id := Underlying_Type (Typ);
11075 begin
11076 if No (U) then
11077 return False;
11078 else
11079 return Is_Fully_Initialized_Variant (U);
11080 end if;
11081 end;
11083 else
11084 return False;
11085 end if;
11086 end Is_Fully_Initialized_Variant;
11088 ----------------------------
11089 -- Is_Inherited_Operation --
11090 ----------------------------
11092 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
11093 pragma Assert (Is_Overloadable (E));
11094 Kind : constant Node_Kind := Nkind (Parent (E));
11095 begin
11096 return Kind = N_Full_Type_Declaration
11097 or else Kind = N_Private_Extension_Declaration
11098 or else Kind = N_Subtype_Declaration
11099 or else (Ekind (E) = E_Enumeration_Literal
11100 and then Is_Derived_Type (Etype (E)));
11101 end Is_Inherited_Operation;
11103 -------------------------------------
11104 -- Is_Inherited_Operation_For_Type --
11105 -------------------------------------
11107 function Is_Inherited_Operation_For_Type
11108 (E : Entity_Id;
11109 Typ : Entity_Id) return Boolean
11111 begin
11112 -- Check that the operation has been created by the type declaration
11114 return Is_Inherited_Operation (E)
11115 and then Defining_Identifier (Parent (E)) = Typ;
11116 end Is_Inherited_Operation_For_Type;
11118 -----------------
11119 -- Is_Iterator --
11120 -----------------
11122 function Is_Iterator (Typ : Entity_Id) return Boolean is
11123 Ifaces_List : Elist_Id;
11124 Iface_Elmt : Elmt_Id;
11125 Iface : Entity_Id;
11127 begin
11128 if Is_Class_Wide_Type (Typ)
11129 and then Nam_In (Chars (Etype (Typ)), Name_Forward_Iterator,
11130 Name_Reversible_Iterator)
11131 and then
11132 Is_Predefined_File_Name
11133 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
11134 then
11135 return True;
11137 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
11138 return False;
11140 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
11141 return True;
11143 else
11144 Collect_Interfaces (Typ, Ifaces_List);
11146 Iface_Elmt := First_Elmt (Ifaces_List);
11147 while Present (Iface_Elmt) loop
11148 Iface := Node (Iface_Elmt);
11149 if Chars (Iface) = Name_Forward_Iterator
11150 and then
11151 Is_Predefined_File_Name
11152 (Unit_File_Name (Get_Source_Unit (Iface)))
11153 then
11154 return True;
11155 end if;
11157 Next_Elmt (Iface_Elmt);
11158 end loop;
11160 return False;
11161 end if;
11162 end Is_Iterator;
11164 ------------
11165 -- Is_LHS --
11166 ------------
11168 -- We seem to have a lot of overlapping functions that do similar things
11169 -- (testing for left hand sides or lvalues???).
11171 function Is_LHS (N : Node_Id) return Is_LHS_Result is
11172 P : constant Node_Id := Parent (N);
11174 begin
11175 -- Return True if we are the left hand side of an assignment statement
11177 if Nkind (P) = N_Assignment_Statement then
11178 if Name (P) = N then
11179 return Yes;
11180 else
11181 return No;
11182 end if;
11184 -- Case of prefix of indexed or selected component or slice
11186 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
11187 and then N = Prefix (P)
11188 then
11189 -- Here we have the case where the parent P is N.Q or N(Q .. R).
11190 -- If P is an LHS, then N is also effectively an LHS, but there
11191 -- is an important exception. If N is of an access type, then
11192 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
11193 -- case this makes N.all a left hand side but not N itself.
11195 -- If we don't know the type yet, this is the case where we return
11196 -- Unknown, since the answer depends on the type which is unknown.
11198 if No (Etype (N)) then
11199 return Unknown;
11201 -- We have an Etype set, so we can check it
11203 elsif Is_Access_Type (Etype (N)) then
11204 return No;
11206 -- OK, not access type case, so just test whole expression
11208 else
11209 return Is_LHS (P);
11210 end if;
11212 -- All other cases are not left hand sides
11214 else
11215 return No;
11216 end if;
11217 end Is_LHS;
11219 -----------------------------
11220 -- Is_Library_Level_Entity --
11221 -----------------------------
11223 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
11224 begin
11225 -- The following is a small optimization, and it also properly handles
11226 -- discriminals, which in task bodies might appear in expressions before
11227 -- the corresponding procedure has been created, and which therefore do
11228 -- not have an assigned scope.
11230 if Is_Formal (E) then
11231 return False;
11232 end if;
11234 -- Normal test is simply that the enclosing dynamic scope is Standard
11236 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
11237 end Is_Library_Level_Entity;
11239 --------------------------------
11240 -- Is_Limited_Class_Wide_Type --
11241 --------------------------------
11243 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
11244 begin
11245 return
11246 Is_Class_Wide_Type (Typ)
11247 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
11248 end Is_Limited_Class_Wide_Type;
11250 ---------------------------------
11251 -- Is_Local_Variable_Reference --
11252 ---------------------------------
11254 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
11255 begin
11256 if not Is_Entity_Name (Expr) then
11257 return False;
11259 else
11260 declare
11261 Ent : constant Entity_Id := Entity (Expr);
11262 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
11263 begin
11264 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
11265 return False;
11266 else
11267 return Present (Sub) and then Sub = Current_Subprogram;
11268 end if;
11269 end;
11270 end if;
11271 end Is_Local_Variable_Reference;
11273 -------------------------
11274 -- Is_Object_Reference --
11275 -------------------------
11277 function Is_Object_Reference (N : Node_Id) return Boolean is
11279 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
11280 -- Determine whether N is the name of an internally-generated renaming
11282 --------------------------------------
11283 -- Is_Internally_Generated_Renaming --
11284 --------------------------------------
11286 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
11287 P : Node_Id;
11289 begin
11290 P := N;
11291 while Present (P) loop
11292 if Nkind (P) = N_Object_Renaming_Declaration then
11293 return not Comes_From_Source (P);
11294 elsif Is_List_Member (P) then
11295 return False;
11296 end if;
11298 P := Parent (P);
11299 end loop;
11301 return False;
11302 end Is_Internally_Generated_Renaming;
11304 -- Start of processing for Is_Object_Reference
11306 begin
11307 if Is_Entity_Name (N) then
11308 return Present (Entity (N)) and then Is_Object (Entity (N));
11310 else
11311 case Nkind (N) is
11312 when N_Indexed_Component | N_Slice =>
11313 return
11314 Is_Object_Reference (Prefix (N))
11315 or else Is_Access_Type (Etype (Prefix (N)));
11317 -- In Ada 95, a function call is a constant object; a procedure
11318 -- call is not.
11320 when N_Function_Call =>
11321 return Etype (N) /= Standard_Void_Type;
11323 -- Attributes 'Input, 'Old and 'Result produce objects
11325 when N_Attribute_Reference =>
11326 return
11327 Nam_In
11328 (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
11330 when N_Selected_Component =>
11331 return
11332 Is_Object_Reference (Selector_Name (N))
11333 and then
11334 (Is_Object_Reference (Prefix (N))
11335 or else Is_Access_Type (Etype (Prefix (N))));
11337 when N_Explicit_Dereference =>
11338 return True;
11340 -- A view conversion of a tagged object is an object reference
11342 when N_Type_Conversion =>
11343 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
11344 and then Is_Tagged_Type (Etype (Expression (N)))
11345 and then Is_Object_Reference (Expression (N));
11347 -- An unchecked type conversion is considered to be an object if
11348 -- the operand is an object (this construction arises only as a
11349 -- result of expansion activities).
11351 when N_Unchecked_Type_Conversion =>
11352 return True;
11354 -- Allow string literals to act as objects as long as they appear
11355 -- in internally-generated renamings. The expansion of iterators
11356 -- may generate such renamings when the range involves a string
11357 -- literal.
11359 when N_String_Literal =>
11360 return Is_Internally_Generated_Renaming (Parent (N));
11362 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11363 -- This allows disambiguation of function calls and the use
11364 -- of aggregates in more contexts.
11366 when N_Qualified_Expression =>
11367 if Ada_Version < Ada_2012 then
11368 return False;
11369 else
11370 return Is_Object_Reference (Expression (N))
11371 or else Nkind (Expression (N)) = N_Aggregate;
11372 end if;
11374 when others =>
11375 return False;
11376 end case;
11377 end if;
11378 end Is_Object_Reference;
11380 -----------------------------------
11381 -- Is_OK_Variable_For_Out_Formal --
11382 -----------------------------------
11384 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
11385 begin
11386 Note_Possible_Modification (AV, Sure => True);
11388 -- We must reject parenthesized variable names. Comes_From_Source is
11389 -- checked because there are currently cases where the compiler violates
11390 -- this rule (e.g. passing a task object to its controlled Initialize
11391 -- routine). This should be properly documented in sinfo???
11393 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
11394 return False;
11396 -- A variable is always allowed
11398 elsif Is_Variable (AV) then
11399 return True;
11401 -- Unchecked conversions are allowed only if they come from the
11402 -- generated code, which sometimes uses unchecked conversions for out
11403 -- parameters in cases where code generation is unaffected. We tell
11404 -- source unchecked conversions by seeing if they are rewrites of
11405 -- an original Unchecked_Conversion function call, or of an explicit
11406 -- conversion of a function call or an aggregate (as may happen in the
11407 -- expansion of a packed array aggregate).
11409 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
11410 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
11411 return False;
11413 elsif Comes_From_Source (AV)
11414 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
11415 then
11416 return False;
11418 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
11419 return Is_OK_Variable_For_Out_Formal (Expression (AV));
11421 else
11422 return True;
11423 end if;
11425 -- Normal type conversions are allowed if argument is a variable
11427 elsif Nkind (AV) = N_Type_Conversion then
11428 if Is_Variable (Expression (AV))
11429 and then Paren_Count (Expression (AV)) = 0
11430 then
11431 Note_Possible_Modification (Expression (AV), Sure => True);
11432 return True;
11434 -- We also allow a non-parenthesized expression that raises
11435 -- constraint error if it rewrites what used to be a variable
11437 elsif Raises_Constraint_Error (Expression (AV))
11438 and then Paren_Count (Expression (AV)) = 0
11439 and then Is_Variable (Original_Node (Expression (AV)))
11440 then
11441 return True;
11443 -- Type conversion of something other than a variable
11445 else
11446 return False;
11447 end if;
11449 -- If this node is rewritten, then test the original form, if that is
11450 -- OK, then we consider the rewritten node OK (for example, if the
11451 -- original node is a conversion, then Is_Variable will not be true
11452 -- but we still want to allow the conversion if it converts a variable).
11454 elsif Original_Node (AV) /= AV then
11456 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11457 -- Reference function.
11459 if Ada_Version >= Ada_2012
11460 and then Nkind (Original_Node (AV)) = N_Function_Call
11461 and then
11462 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
11463 then
11464 return True;
11466 else
11467 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
11468 end if;
11470 -- All other non-variables are rejected
11472 else
11473 return False;
11474 end if;
11475 end Is_OK_Variable_For_Out_Formal;
11477 -----------------------------------
11478 -- Is_Partially_Initialized_Type --
11479 -----------------------------------
11481 function Is_Partially_Initialized_Type
11482 (Typ : Entity_Id;
11483 Include_Implicit : Boolean := True) return Boolean
11485 begin
11486 if Is_Scalar_Type (Typ) then
11487 return False;
11489 elsif Is_Access_Type (Typ) then
11490 return Include_Implicit;
11492 elsif Is_Array_Type (Typ) then
11494 -- If component type is partially initialized, so is array type
11496 if Is_Partially_Initialized_Type
11497 (Component_Type (Typ), Include_Implicit)
11498 then
11499 return True;
11501 -- Otherwise we are only partially initialized if we are fully
11502 -- initialized (this is the empty array case, no point in us
11503 -- duplicating that code here).
11505 else
11506 return Is_Fully_Initialized_Type (Typ);
11507 end if;
11509 elsif Is_Record_Type (Typ) then
11511 -- A discriminated type is always partially initialized if in
11512 -- all mode
11514 if Has_Discriminants (Typ) and then Include_Implicit then
11515 return True;
11517 -- A tagged type is always partially initialized
11519 elsif Is_Tagged_Type (Typ) then
11520 return True;
11522 -- Case of non-discriminated record
11524 else
11525 declare
11526 Ent : Entity_Id;
11528 Component_Present : Boolean := False;
11529 -- Set True if at least one component is present. If no
11530 -- components are present, then record type is fully
11531 -- initialized (another odd case, like the null array).
11533 begin
11534 -- Loop through components
11536 Ent := First_Entity (Typ);
11537 while Present (Ent) loop
11538 if Ekind (Ent) = E_Component then
11539 Component_Present := True;
11541 -- If a component has an initialization expression then
11542 -- the enclosing record type is partially initialized
11544 if Present (Parent (Ent))
11545 and then Present (Expression (Parent (Ent)))
11546 then
11547 return True;
11549 -- If a component is of a type which is itself partially
11550 -- initialized, then the enclosing record type is also.
11552 elsif Is_Partially_Initialized_Type
11553 (Etype (Ent), Include_Implicit)
11554 then
11555 return True;
11556 end if;
11557 end if;
11559 Next_Entity (Ent);
11560 end loop;
11562 -- No initialized components found. If we found any components
11563 -- they were all uninitialized so the result is false.
11565 if Component_Present then
11566 return False;
11568 -- But if we found no components, then all the components are
11569 -- initialized so we consider the type to be initialized.
11571 else
11572 return True;
11573 end if;
11574 end;
11575 end if;
11577 -- Concurrent types are always fully initialized
11579 elsif Is_Concurrent_Type (Typ) then
11580 return True;
11582 -- For a private type, go to underlying type. If there is no underlying
11583 -- type then just assume this partially initialized. Not clear if this
11584 -- can happen in a non-error case, but no harm in testing for this.
11586 elsif Is_Private_Type (Typ) then
11587 declare
11588 U : constant Entity_Id := Underlying_Type (Typ);
11589 begin
11590 if No (U) then
11591 return True;
11592 else
11593 return Is_Partially_Initialized_Type (U, Include_Implicit);
11594 end if;
11595 end;
11597 -- For any other type (are there any?) assume partially initialized
11599 else
11600 return True;
11601 end if;
11602 end Is_Partially_Initialized_Type;
11604 ------------------------------------
11605 -- Is_Potentially_Persistent_Type --
11606 ------------------------------------
11608 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
11609 Comp : Entity_Id;
11610 Indx : Node_Id;
11612 begin
11613 -- For private type, test corresponding full type
11615 if Is_Private_Type (T) then
11616 return Is_Potentially_Persistent_Type (Full_View (T));
11618 -- Scalar types are potentially persistent
11620 elsif Is_Scalar_Type (T) then
11621 return True;
11623 -- Record type is potentially persistent if not tagged and the types of
11624 -- all it components are potentially persistent, and no component has
11625 -- an initialization expression.
11627 elsif Is_Record_Type (T)
11628 and then not Is_Tagged_Type (T)
11629 and then not Is_Partially_Initialized_Type (T)
11630 then
11631 Comp := First_Component (T);
11632 while Present (Comp) loop
11633 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
11634 return False;
11635 else
11636 Next_Entity (Comp);
11637 end if;
11638 end loop;
11640 return True;
11642 -- Array type is potentially persistent if its component type is
11643 -- potentially persistent and if all its constraints are static.
11645 elsif Is_Array_Type (T) then
11646 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
11647 return False;
11648 end if;
11650 Indx := First_Index (T);
11651 while Present (Indx) loop
11652 if not Is_OK_Static_Subtype (Etype (Indx)) then
11653 return False;
11654 else
11655 Next_Index (Indx);
11656 end if;
11657 end loop;
11659 return True;
11661 -- All other types are not potentially persistent
11663 else
11664 return False;
11665 end if;
11666 end Is_Potentially_Persistent_Type;
11668 --------------------------------
11669 -- Is_Potentially_Unevaluated --
11670 --------------------------------
11672 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
11673 Par : Node_Id;
11674 Expr : Node_Id;
11676 begin
11677 Expr := N;
11678 Par := Parent (N);
11680 -- A postcondition whose expression is a short-circuit is broken down
11681 -- into individual aspects for better exception reporting. The original
11682 -- short-circuit expression is rewritten as the second operand, and an
11683 -- occurrence of 'Old in that operand is potentially unevaluated.
11684 -- See Sem_ch13.adb for details of this transformation.
11686 if Nkind (Original_Node (Par)) = N_And_Then then
11687 return True;
11688 end if;
11690 while not Nkind_In (Par, N_If_Expression,
11691 N_Case_Expression,
11692 N_And_Then,
11693 N_Or_Else,
11694 N_In,
11695 N_Not_In)
11696 loop
11697 Expr := Par;
11698 Par := Parent (Par);
11700 -- If the context is not an expression, or if is the result of
11701 -- expansion of an enclosing construct (such as another attribute)
11702 -- the predicate does not apply.
11704 if Nkind (Par) not in N_Subexpr
11705 or else not Comes_From_Source (Par)
11706 then
11707 return False;
11708 end if;
11709 end loop;
11711 if Nkind (Par) = N_If_Expression then
11712 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
11714 elsif Nkind (Par) = N_Case_Expression then
11715 return Expr /= Expression (Par);
11717 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
11718 return Expr = Right_Opnd (Par);
11720 elsif Nkind_In (Par, N_In, N_Not_In) then
11721 return Expr /= Left_Opnd (Par);
11723 else
11724 return False;
11725 end if;
11726 end Is_Potentially_Unevaluated;
11728 ---------------------------------
11729 -- Is_Protected_Self_Reference --
11730 ---------------------------------
11732 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
11734 function In_Access_Definition (N : Node_Id) return Boolean;
11735 -- Returns true if N belongs to an access definition
11737 --------------------------
11738 -- In_Access_Definition --
11739 --------------------------
11741 function In_Access_Definition (N : Node_Id) return Boolean is
11742 P : Node_Id;
11744 begin
11745 P := Parent (N);
11746 while Present (P) loop
11747 if Nkind (P) = N_Access_Definition then
11748 return True;
11749 end if;
11751 P := Parent (P);
11752 end loop;
11754 return False;
11755 end In_Access_Definition;
11757 -- Start of processing for Is_Protected_Self_Reference
11759 begin
11760 -- Verify that prefix is analyzed and has the proper form. Note that
11761 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
11762 -- which also produce the address of an entity, do not analyze their
11763 -- prefix because they denote entities that are not necessarily visible.
11764 -- Neither of them can apply to a protected type.
11766 return Ada_Version >= Ada_2005
11767 and then Is_Entity_Name (N)
11768 and then Present (Entity (N))
11769 and then Is_Protected_Type (Entity (N))
11770 and then In_Open_Scopes (Entity (N))
11771 and then not In_Access_Definition (N);
11772 end Is_Protected_Self_Reference;
11774 -----------------------------
11775 -- Is_RCI_Pkg_Spec_Or_Body --
11776 -----------------------------
11778 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
11780 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
11781 -- Return True if the unit of Cunit is an RCI package declaration
11783 ---------------------------
11784 -- Is_RCI_Pkg_Decl_Cunit --
11785 ---------------------------
11787 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
11788 The_Unit : constant Node_Id := Unit (Cunit);
11790 begin
11791 if Nkind (The_Unit) /= N_Package_Declaration then
11792 return False;
11793 end if;
11795 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
11796 end Is_RCI_Pkg_Decl_Cunit;
11798 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
11800 begin
11801 return Is_RCI_Pkg_Decl_Cunit (Cunit)
11802 or else
11803 (Nkind (Unit (Cunit)) = N_Package_Body
11804 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
11805 end Is_RCI_Pkg_Spec_Or_Body;
11807 -----------------------------------------
11808 -- Is_Remote_Access_To_Class_Wide_Type --
11809 -----------------------------------------
11811 function Is_Remote_Access_To_Class_Wide_Type
11812 (E : Entity_Id) return Boolean
11814 begin
11815 -- A remote access to class-wide type is a general access to object type
11816 -- declared in the visible part of a Remote_Types or Remote_Call_
11817 -- Interface unit.
11819 return Ekind (E) = E_General_Access_Type
11820 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
11821 end Is_Remote_Access_To_Class_Wide_Type;
11823 -----------------------------------------
11824 -- Is_Remote_Access_To_Subprogram_Type --
11825 -----------------------------------------
11827 function Is_Remote_Access_To_Subprogram_Type
11828 (E : Entity_Id) return Boolean
11830 begin
11831 return (Ekind (E) = E_Access_Subprogram_Type
11832 or else (Ekind (E) = E_Record_Type
11833 and then Present (Corresponding_Remote_Type (E))))
11834 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
11835 end Is_Remote_Access_To_Subprogram_Type;
11837 --------------------
11838 -- Is_Remote_Call --
11839 --------------------
11841 function Is_Remote_Call (N : Node_Id) return Boolean is
11842 begin
11843 if Nkind (N) not in N_Subprogram_Call then
11845 -- An entry call cannot be remote
11847 return False;
11849 elsif Nkind (Name (N)) in N_Has_Entity
11850 and then Is_Remote_Call_Interface (Entity (Name (N)))
11851 then
11852 -- A subprogram declared in the spec of a RCI package is remote
11854 return True;
11856 elsif Nkind (Name (N)) = N_Explicit_Dereference
11857 and then Is_Remote_Access_To_Subprogram_Type
11858 (Etype (Prefix (Name (N))))
11859 then
11860 -- The dereference of a RAS is a remote call
11862 return True;
11864 elsif Present (Controlling_Argument (N))
11865 and then Is_Remote_Access_To_Class_Wide_Type
11866 (Etype (Controlling_Argument (N)))
11867 then
11868 -- Any primitive operation call with a controlling argument of
11869 -- a RACW type is a remote call.
11871 return True;
11872 end if;
11874 -- All other calls are local calls
11876 return False;
11877 end Is_Remote_Call;
11879 ----------------------
11880 -- Is_Renamed_Entry --
11881 ----------------------
11883 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
11884 Orig_Node : Node_Id := Empty;
11885 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
11887 function Is_Entry (Nam : Node_Id) return Boolean;
11888 -- Determine whether Nam is an entry. Traverse selectors if there are
11889 -- nested selected components.
11891 --------------
11892 -- Is_Entry --
11893 --------------
11895 function Is_Entry (Nam : Node_Id) return Boolean is
11896 begin
11897 if Nkind (Nam) = N_Selected_Component then
11898 return Is_Entry (Selector_Name (Nam));
11899 end if;
11901 return Ekind (Entity (Nam)) = E_Entry;
11902 end Is_Entry;
11904 -- Start of processing for Is_Renamed_Entry
11906 begin
11907 if Present (Alias (Proc_Nam)) then
11908 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
11909 end if;
11911 -- Look for a rewritten subprogram renaming declaration
11913 if Nkind (Subp_Decl) = N_Subprogram_Declaration
11914 and then Present (Original_Node (Subp_Decl))
11915 then
11916 Orig_Node := Original_Node (Subp_Decl);
11917 end if;
11919 -- The rewritten subprogram is actually an entry
11921 if Present (Orig_Node)
11922 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
11923 and then Is_Entry (Name (Orig_Node))
11924 then
11925 return True;
11926 end if;
11928 return False;
11929 end Is_Renamed_Entry;
11931 ----------------------------
11932 -- Is_Reversible_Iterator --
11933 ----------------------------
11935 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
11936 Ifaces_List : Elist_Id;
11937 Iface_Elmt : Elmt_Id;
11938 Iface : Entity_Id;
11940 begin
11941 if Is_Class_Wide_Type (Typ)
11942 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
11943 and then Is_Predefined_File_Name
11944 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
11945 then
11946 return True;
11948 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
11949 return False;
11951 else
11952 Collect_Interfaces (Typ, Ifaces_List);
11954 Iface_Elmt := First_Elmt (Ifaces_List);
11955 while Present (Iface_Elmt) loop
11956 Iface := Node (Iface_Elmt);
11957 if Chars (Iface) = Name_Reversible_Iterator
11958 and then
11959 Is_Predefined_File_Name
11960 (Unit_File_Name (Get_Source_Unit (Iface)))
11961 then
11962 return True;
11963 end if;
11965 Next_Elmt (Iface_Elmt);
11966 end loop;
11967 end if;
11969 return False;
11970 end Is_Reversible_Iterator;
11972 ----------------------
11973 -- Is_Selector_Name --
11974 ----------------------
11976 function Is_Selector_Name (N : Node_Id) return Boolean is
11977 begin
11978 if not Is_List_Member (N) then
11979 declare
11980 P : constant Node_Id := Parent (N);
11981 begin
11982 return Nkind_In (P, N_Expanded_Name,
11983 N_Generic_Association,
11984 N_Parameter_Association,
11985 N_Selected_Component)
11986 and then Selector_Name (P) = N;
11987 end;
11989 else
11990 declare
11991 L : constant List_Id := List_Containing (N);
11992 P : constant Node_Id := Parent (L);
11993 begin
11994 return (Nkind (P) = N_Discriminant_Association
11995 and then Selector_Names (P) = L)
11996 or else
11997 (Nkind (P) = N_Component_Association
11998 and then Choices (P) = L);
11999 end;
12000 end if;
12001 end Is_Selector_Name;
12003 -------------------------------------
12004 -- Is_SPARK_05_Initialization_Expr --
12005 -------------------------------------
12007 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
12008 Is_Ok : Boolean;
12009 Expr : Node_Id;
12010 Comp_Assn : Node_Id;
12011 Orig_N : constant Node_Id := Original_Node (N);
12013 begin
12014 Is_Ok := True;
12016 if not Comes_From_Source (Orig_N) then
12017 goto Done;
12018 end if;
12020 pragma Assert (Nkind (Orig_N) in N_Subexpr);
12022 case Nkind (Orig_N) is
12023 when N_Character_Literal |
12024 N_Integer_Literal |
12025 N_Real_Literal |
12026 N_String_Literal =>
12027 null;
12029 when N_Identifier |
12030 N_Expanded_Name =>
12031 if Is_Entity_Name (Orig_N)
12032 and then Present (Entity (Orig_N)) -- needed in some cases
12033 then
12034 case Ekind (Entity (Orig_N)) is
12035 when E_Constant |
12036 E_Enumeration_Literal |
12037 E_Named_Integer |
12038 E_Named_Real =>
12039 null;
12040 when others =>
12041 if Is_Type (Entity (Orig_N)) then
12042 null;
12043 else
12044 Is_Ok := False;
12045 end if;
12046 end case;
12047 end if;
12049 when N_Qualified_Expression |
12050 N_Type_Conversion =>
12051 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
12053 when N_Unary_Op =>
12054 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12056 when N_Binary_Op |
12057 N_Short_Circuit |
12058 N_Membership_Test =>
12059 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
12060 and then
12061 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12063 when N_Aggregate |
12064 N_Extension_Aggregate =>
12065 if Nkind (Orig_N) = N_Extension_Aggregate then
12066 Is_Ok :=
12067 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
12068 end if;
12070 Expr := First (Expressions (Orig_N));
12071 while Present (Expr) loop
12072 if not Is_SPARK_05_Initialization_Expr (Expr) then
12073 Is_Ok := False;
12074 goto Done;
12075 end if;
12077 Next (Expr);
12078 end loop;
12080 Comp_Assn := First (Component_Associations (Orig_N));
12081 while Present (Comp_Assn) loop
12082 Expr := Expression (Comp_Assn);
12084 -- Note: test for Present here needed for box assocation
12086 if Present (Expr)
12087 and then not Is_SPARK_05_Initialization_Expr (Expr)
12088 then
12089 Is_Ok := False;
12090 goto Done;
12091 end if;
12093 Next (Comp_Assn);
12094 end loop;
12096 when N_Attribute_Reference =>
12097 if Nkind (Prefix (Orig_N)) in N_Subexpr then
12098 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
12099 end if;
12101 Expr := First (Expressions (Orig_N));
12102 while Present (Expr) loop
12103 if not Is_SPARK_05_Initialization_Expr (Expr) then
12104 Is_Ok := False;
12105 goto Done;
12106 end if;
12108 Next (Expr);
12109 end loop;
12111 -- Selected components might be expanded named not yet resolved, so
12112 -- default on the safe side. (Eg on sparklex.ads)
12114 when N_Selected_Component =>
12115 null;
12117 when others =>
12118 Is_Ok := False;
12119 end case;
12121 <<Done>>
12122 return Is_Ok;
12123 end Is_SPARK_05_Initialization_Expr;
12125 ----------------------------------
12126 -- Is_SPARK_05_Object_Reference --
12127 ----------------------------------
12129 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
12130 begin
12131 if Is_Entity_Name (N) then
12132 return Present (Entity (N))
12133 and then
12134 (Ekind_In (Entity (N), E_Constant, E_Variable)
12135 or else Ekind (Entity (N)) in Formal_Kind);
12137 else
12138 case Nkind (N) is
12139 when N_Selected_Component =>
12140 return Is_SPARK_05_Object_Reference (Prefix (N));
12142 when others =>
12143 return False;
12144 end case;
12145 end if;
12146 end Is_SPARK_05_Object_Reference;
12148 -----------------------------
12149 -- Is_Specific_Tagged_Type --
12150 -----------------------------
12152 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
12153 Full_Typ : Entity_Id;
12155 begin
12156 -- Handle private types
12158 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
12159 Full_Typ := Full_View (Typ);
12160 else
12161 Full_Typ := Typ;
12162 end if;
12164 -- A specific tagged type is a non-class-wide tagged type
12166 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
12167 end Is_Specific_Tagged_Type;
12169 ------------------
12170 -- Is_Statement --
12171 ------------------
12173 function Is_Statement (N : Node_Id) return Boolean is
12174 begin
12175 return
12176 Nkind (N) in N_Statement_Other_Than_Procedure_Call
12177 or else Nkind (N) = N_Procedure_Call_Statement;
12178 end Is_Statement;
12180 --------------------------------------------------
12181 -- Is_Subprogram_Stub_Without_Prior_Declaration --
12182 --------------------------------------------------
12184 function Is_Subprogram_Stub_Without_Prior_Declaration
12185 (N : Node_Id) return Boolean
12187 begin
12188 -- A subprogram stub without prior declaration serves as declaration for
12189 -- the actual subprogram body. As such, it has an attached defining
12190 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
12192 return Nkind (N) = N_Subprogram_Body_Stub
12193 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
12194 end Is_Subprogram_Stub_Without_Prior_Declaration;
12196 ---------------------------------
12197 -- Is_Synchronized_Tagged_Type --
12198 ---------------------------------
12200 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
12201 Kind : constant Entity_Kind := Ekind (Base_Type (E));
12203 begin
12204 -- A task or protected type derived from an interface is a tagged type.
12205 -- Such a tagged type is called a synchronized tagged type, as are
12206 -- synchronized interfaces and private extensions whose declaration
12207 -- includes the reserved word synchronized.
12209 return (Is_Tagged_Type (E)
12210 and then (Kind = E_Task_Type
12211 or else
12212 Kind = E_Protected_Type))
12213 or else
12214 (Is_Interface (E)
12215 and then Is_Synchronized_Interface (E))
12216 or else
12217 (Ekind (E) = E_Record_Type_With_Private
12218 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
12219 and then (Synchronized_Present (Parent (E))
12220 or else Is_Synchronized_Interface (Etype (E))));
12221 end Is_Synchronized_Tagged_Type;
12223 -----------------
12224 -- Is_Transfer --
12225 -----------------
12227 function Is_Transfer (N : Node_Id) return Boolean is
12228 Kind : constant Node_Kind := Nkind (N);
12230 begin
12231 if Kind = N_Simple_Return_Statement
12232 or else
12233 Kind = N_Extended_Return_Statement
12234 or else
12235 Kind = N_Goto_Statement
12236 or else
12237 Kind = N_Raise_Statement
12238 or else
12239 Kind = N_Requeue_Statement
12240 then
12241 return True;
12243 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
12244 and then No (Condition (N))
12245 then
12246 return True;
12248 elsif Kind = N_Procedure_Call_Statement
12249 and then Is_Entity_Name (Name (N))
12250 and then Present (Entity (Name (N)))
12251 and then No_Return (Entity (Name (N)))
12252 then
12253 return True;
12255 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
12256 return True;
12258 else
12259 return False;
12260 end if;
12261 end Is_Transfer;
12263 -------------
12264 -- Is_True --
12265 -------------
12267 function Is_True (U : Uint) return Boolean is
12268 begin
12269 return (U /= 0);
12270 end Is_True;
12272 --------------------------------------
12273 -- Is_Unchecked_Conversion_Instance --
12274 --------------------------------------
12276 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
12277 Gen_Par : Entity_Id;
12279 begin
12280 -- Look for a function whose generic parent is the predefined intrinsic
12281 -- function Unchecked_Conversion.
12283 if Ekind (Id) = E_Function then
12284 Gen_Par := Generic_Parent (Parent (Id));
12286 return
12287 Present (Gen_Par)
12288 and then Chars (Gen_Par) = Name_Unchecked_Conversion
12289 and then Is_Intrinsic_Subprogram (Gen_Par)
12290 and then Is_Predefined_File_Name
12291 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
12292 end if;
12294 return False;
12295 end Is_Unchecked_Conversion_Instance;
12297 -------------------------------
12298 -- Is_Universal_Numeric_Type --
12299 -------------------------------
12301 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
12302 begin
12303 return T = Universal_Integer or else T = Universal_Real;
12304 end Is_Universal_Numeric_Type;
12306 -------------------
12307 -- Is_Value_Type --
12308 -------------------
12310 function Is_Value_Type (T : Entity_Id) return Boolean is
12311 begin
12312 return VM_Target = CLI_Target
12313 and then Nkind (T) in N_Has_Chars
12314 and then Chars (T) /= No_Name
12315 and then Get_Name_String (Chars (T)) = "valuetype";
12316 end Is_Value_Type;
12318 ----------------------------
12319 -- Is_Variable_Size_Array --
12320 ----------------------------
12322 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
12323 Idx : Node_Id;
12325 begin
12326 pragma Assert (Is_Array_Type (E));
12328 -- Check if some index is initialized with a non-constant value
12330 Idx := First_Index (E);
12331 while Present (Idx) loop
12332 if Nkind (Idx) = N_Range then
12333 if not Is_Constant_Bound (Low_Bound (Idx))
12334 or else not Is_Constant_Bound (High_Bound (Idx))
12335 then
12336 return True;
12337 end if;
12338 end if;
12340 Idx := Next_Index (Idx);
12341 end loop;
12343 return False;
12344 end Is_Variable_Size_Array;
12346 -----------------------------
12347 -- Is_Variable_Size_Record --
12348 -----------------------------
12350 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
12351 Comp : Entity_Id;
12352 Comp_Typ : Entity_Id;
12354 begin
12355 pragma Assert (Is_Record_Type (E));
12357 Comp := First_Entity (E);
12358 while Present (Comp) loop
12359 Comp_Typ := Etype (Comp);
12361 -- Recursive call if the record type has discriminants
12363 if Is_Record_Type (Comp_Typ)
12364 and then Has_Discriminants (Comp_Typ)
12365 and then Is_Variable_Size_Record (Comp_Typ)
12366 then
12367 return True;
12369 elsif Is_Array_Type (Comp_Typ)
12370 and then Is_Variable_Size_Array (Comp_Typ)
12371 then
12372 return True;
12373 end if;
12375 Next_Entity (Comp);
12376 end loop;
12378 return False;
12379 end Is_Variable_Size_Record;
12381 -----------------
12382 -- Is_Variable --
12383 -----------------
12385 function Is_Variable
12386 (N : Node_Id;
12387 Use_Original_Node : Boolean := True) return Boolean
12389 Orig_Node : Node_Id;
12391 function In_Protected_Function (E : Entity_Id) return Boolean;
12392 -- Within a protected function, the private components of the enclosing
12393 -- protected type are constants. A function nested within a (protected)
12394 -- procedure is not itself protected. Within the body of a protected
12395 -- function the current instance of the protected type is a constant.
12397 function Is_Variable_Prefix (P : Node_Id) return Boolean;
12398 -- Prefixes can involve implicit dereferences, in which case we must
12399 -- test for the case of a reference of a constant access type, which can
12400 -- can never be a variable.
12402 ---------------------------
12403 -- In_Protected_Function --
12404 ---------------------------
12406 function In_Protected_Function (E : Entity_Id) return Boolean is
12407 Prot : Entity_Id;
12408 S : Entity_Id;
12410 begin
12411 -- E is the current instance of a type
12413 if Is_Type (E) then
12414 Prot := E;
12416 -- E is an object
12418 else
12419 Prot := Scope (E);
12420 end if;
12422 if not Is_Protected_Type (Prot) then
12423 return False;
12425 else
12426 S := Current_Scope;
12427 while Present (S) and then S /= Prot loop
12428 if Ekind (S) = E_Function and then Scope (S) = Prot then
12429 return True;
12430 end if;
12432 S := Scope (S);
12433 end loop;
12435 return False;
12436 end if;
12437 end In_Protected_Function;
12439 ------------------------
12440 -- Is_Variable_Prefix --
12441 ------------------------
12443 function Is_Variable_Prefix (P : Node_Id) return Boolean is
12444 begin
12445 if Is_Access_Type (Etype (P)) then
12446 return not Is_Access_Constant (Root_Type (Etype (P)));
12448 -- For the case of an indexed component whose prefix has a packed
12449 -- array type, the prefix has been rewritten into a type conversion.
12450 -- Determine variable-ness from the converted expression.
12452 elsif Nkind (P) = N_Type_Conversion
12453 and then not Comes_From_Source (P)
12454 and then Is_Array_Type (Etype (P))
12455 and then Is_Packed (Etype (P))
12456 then
12457 return Is_Variable (Expression (P));
12459 else
12460 return Is_Variable (P);
12461 end if;
12462 end Is_Variable_Prefix;
12464 -- Start of processing for Is_Variable
12466 begin
12467 -- Check if we perform the test on the original node since this may be a
12468 -- test of syntactic categories which must not be disturbed by whatever
12469 -- rewriting might have occurred. For example, an aggregate, which is
12470 -- certainly NOT a variable, could be turned into a variable by
12471 -- expansion.
12473 if Use_Original_Node then
12474 Orig_Node := Original_Node (N);
12475 else
12476 Orig_Node := N;
12477 end if;
12479 -- Definitely OK if Assignment_OK is set. Since this is something that
12480 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12482 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
12483 return True;
12485 -- Normally we go to the original node, but there is one exception where
12486 -- we use the rewritten node, namely when it is an explicit dereference.
12487 -- The generated code may rewrite a prefix which is an access type with
12488 -- an explicit dereference. The dereference is a variable, even though
12489 -- the original node may not be (since it could be a constant of the
12490 -- access type).
12492 -- In Ada 2005 we have a further case to consider: the prefix may be a
12493 -- function call given in prefix notation. The original node appears to
12494 -- be a selected component, but we need to examine the call.
12496 elsif Nkind (N) = N_Explicit_Dereference
12497 and then Nkind (Orig_Node) /= N_Explicit_Dereference
12498 and then Present (Etype (Orig_Node))
12499 and then Is_Access_Type (Etype (Orig_Node))
12500 then
12501 -- Note that if the prefix is an explicit dereference that does not
12502 -- come from source, we must check for a rewritten function call in
12503 -- prefixed notation before other forms of rewriting, to prevent a
12504 -- compiler crash.
12506 return
12507 (Nkind (Orig_Node) = N_Function_Call
12508 and then not Is_Access_Constant (Etype (Prefix (N))))
12509 or else
12510 Is_Variable_Prefix (Original_Node (Prefix (N)));
12512 -- in Ada 2012, the dereference may have been added for a type with
12513 -- a declared implicit dereference aspect.
12515 elsif Nkind (N) = N_Explicit_Dereference
12516 and then Present (Etype (Orig_Node))
12517 and then Ada_Version >= Ada_2012
12518 and then Has_Implicit_Dereference (Etype (Orig_Node))
12519 then
12520 return True;
12522 -- A function call is never a variable
12524 elsif Nkind (N) = N_Function_Call then
12525 return False;
12527 -- All remaining checks use the original node
12529 elsif Is_Entity_Name (Orig_Node)
12530 and then Present (Entity (Orig_Node))
12531 then
12532 declare
12533 E : constant Entity_Id := Entity (Orig_Node);
12534 K : constant Entity_Kind := Ekind (E);
12536 begin
12537 return (K = E_Variable
12538 and then Nkind (Parent (E)) /= N_Exception_Handler)
12539 or else (K = E_Component
12540 and then not In_Protected_Function (E))
12541 or else K = E_Out_Parameter
12542 or else K = E_In_Out_Parameter
12543 or else K = E_Generic_In_Out_Parameter
12545 -- Current instance of type. If this is a protected type, check
12546 -- we are not within the body of one of its protected functions.
12548 or else (Is_Type (E)
12549 and then In_Open_Scopes (E)
12550 and then not In_Protected_Function (E))
12552 or else (Is_Incomplete_Or_Private_Type (E)
12553 and then In_Open_Scopes (Full_View (E)));
12554 end;
12556 else
12557 case Nkind (Orig_Node) is
12558 when N_Indexed_Component | N_Slice =>
12559 return Is_Variable_Prefix (Prefix (Orig_Node));
12561 when N_Selected_Component =>
12562 return (Is_Variable (Selector_Name (Orig_Node))
12563 and then Is_Variable_Prefix (Prefix (Orig_Node)))
12564 or else
12565 (Nkind (N) = N_Expanded_Name
12566 and then Scope (Entity (N)) = Entity (Prefix (N)));
12568 -- For an explicit dereference, the type of the prefix cannot
12569 -- be an access to constant or an access to subprogram.
12571 when N_Explicit_Dereference =>
12572 declare
12573 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
12574 begin
12575 return Is_Access_Type (Typ)
12576 and then not Is_Access_Constant (Root_Type (Typ))
12577 and then Ekind (Typ) /= E_Access_Subprogram_Type;
12578 end;
12580 -- The type conversion is the case where we do not deal with the
12581 -- context dependent special case of an actual parameter. Thus
12582 -- the type conversion is only considered a variable for the
12583 -- purposes of this routine if the target type is tagged. However,
12584 -- a type conversion is considered to be a variable if it does not
12585 -- come from source (this deals for example with the conversions
12586 -- of expressions to their actual subtypes).
12588 when N_Type_Conversion =>
12589 return Is_Variable (Expression (Orig_Node))
12590 and then
12591 (not Comes_From_Source (Orig_Node)
12592 or else
12593 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
12594 and then
12595 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
12597 -- GNAT allows an unchecked type conversion as a variable. This
12598 -- only affects the generation of internal expanded code, since
12599 -- calls to instantiations of Unchecked_Conversion are never
12600 -- considered variables (since they are function calls).
12602 when N_Unchecked_Type_Conversion =>
12603 return Is_Variable (Expression (Orig_Node));
12605 when others =>
12606 return False;
12607 end case;
12608 end if;
12609 end Is_Variable;
12611 ---------------------------
12612 -- Is_Visibly_Controlled --
12613 ---------------------------
12615 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
12616 Root : constant Entity_Id := Root_Type (T);
12617 begin
12618 return Chars (Scope (Root)) = Name_Finalization
12619 and then Chars (Scope (Scope (Root))) = Name_Ada
12620 and then Scope (Scope (Scope (Root))) = Standard_Standard;
12621 end Is_Visibly_Controlled;
12623 ------------------------
12624 -- Is_Volatile_Object --
12625 ------------------------
12627 function Is_Volatile_Object (N : Node_Id) return Boolean is
12629 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
12630 -- If prefix is an implicit dereference, examine designated type
12632 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
12633 -- Determines if given object has volatile components
12635 ------------------------
12636 -- Is_Volatile_Prefix --
12637 ------------------------
12639 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
12640 Typ : constant Entity_Id := Etype (N);
12642 begin
12643 if Is_Access_Type (Typ) then
12644 declare
12645 Dtyp : constant Entity_Id := Designated_Type (Typ);
12647 begin
12648 return Is_Volatile (Dtyp)
12649 or else Has_Volatile_Components (Dtyp);
12650 end;
12652 else
12653 return Object_Has_Volatile_Components (N);
12654 end if;
12655 end Is_Volatile_Prefix;
12657 ------------------------------------
12658 -- Object_Has_Volatile_Components --
12659 ------------------------------------
12661 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
12662 Typ : constant Entity_Id := Etype (N);
12664 begin
12665 if Is_Volatile (Typ)
12666 or else Has_Volatile_Components (Typ)
12667 then
12668 return True;
12670 elsif Is_Entity_Name (N)
12671 and then (Has_Volatile_Components (Entity (N))
12672 or else Is_Volatile (Entity (N)))
12673 then
12674 return True;
12676 elsif Nkind (N) = N_Indexed_Component
12677 or else Nkind (N) = N_Selected_Component
12678 then
12679 return Is_Volatile_Prefix (Prefix (N));
12681 else
12682 return False;
12683 end if;
12684 end Object_Has_Volatile_Components;
12686 -- Start of processing for Is_Volatile_Object
12688 begin
12689 if Nkind (N) = N_Defining_Identifier then
12690 return Is_Volatile (N) or else Is_Volatile (Etype (N));
12692 elsif Nkind (N) = N_Expanded_Name then
12693 return Is_Volatile_Object (Entity (N));
12695 elsif Is_Volatile (Etype (N))
12696 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
12697 then
12698 return True;
12700 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
12701 and then Is_Volatile_Prefix (Prefix (N))
12702 then
12703 return True;
12705 elsif Nkind (N) = N_Selected_Component
12706 and then Is_Volatile (Entity (Selector_Name (N)))
12707 then
12708 return True;
12710 else
12711 return False;
12712 end if;
12713 end Is_Volatile_Object;
12715 ---------------------------
12716 -- Itype_Has_Declaration --
12717 ---------------------------
12719 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
12720 begin
12721 pragma Assert (Is_Itype (Id));
12722 return Present (Parent (Id))
12723 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
12724 N_Subtype_Declaration)
12725 and then Defining_Entity (Parent (Id)) = Id;
12726 end Itype_Has_Declaration;
12728 -------------------------
12729 -- Kill_Current_Values --
12730 -------------------------
12732 procedure Kill_Current_Values
12733 (Ent : Entity_Id;
12734 Last_Assignment_Only : Boolean := False)
12736 begin
12737 if Is_Assignable (Ent) then
12738 Set_Last_Assignment (Ent, Empty);
12739 end if;
12741 if Is_Object (Ent) then
12742 if not Last_Assignment_Only then
12743 Kill_Checks (Ent);
12744 Set_Current_Value (Ent, Empty);
12746 if not Can_Never_Be_Null (Ent) then
12747 Set_Is_Known_Non_Null (Ent, False);
12748 end if;
12750 Set_Is_Known_Null (Ent, False);
12752 -- Reset Is_Known_Valid unless type is always valid, or if we have
12753 -- a loop parameter (loop parameters are always valid, since their
12754 -- bounds are defined by the bounds given in the loop header).
12756 if not Is_Known_Valid (Etype (Ent))
12757 and then Ekind (Ent) /= E_Loop_Parameter
12758 then
12759 Set_Is_Known_Valid (Ent, False);
12760 end if;
12761 end if;
12762 end if;
12763 end Kill_Current_Values;
12765 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
12766 S : Entity_Id;
12768 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
12769 -- Clear current value for entity E and all entities chained to E
12771 ------------------------------------------
12772 -- Kill_Current_Values_For_Entity_Chain --
12773 ------------------------------------------
12775 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
12776 Ent : Entity_Id;
12777 begin
12778 Ent := E;
12779 while Present (Ent) loop
12780 Kill_Current_Values (Ent, Last_Assignment_Only);
12781 Next_Entity (Ent);
12782 end loop;
12783 end Kill_Current_Values_For_Entity_Chain;
12785 -- Start of processing for Kill_Current_Values
12787 begin
12788 -- Kill all saved checks, a special case of killing saved values
12790 if not Last_Assignment_Only then
12791 Kill_All_Checks;
12792 end if;
12794 -- Loop through relevant scopes, which includes the current scope and
12795 -- any parent scopes if the current scope is a block or a package.
12797 S := Current_Scope;
12798 Scope_Loop : loop
12800 -- Clear current values of all entities in current scope
12802 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
12804 -- If scope is a package, also clear current values of all private
12805 -- entities in the scope.
12807 if Is_Package_Or_Generic_Package (S)
12808 or else Is_Concurrent_Type (S)
12809 then
12810 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
12811 end if;
12813 -- If this is a not a subprogram, deal with parents
12815 if not Is_Subprogram (S) then
12816 S := Scope (S);
12817 exit Scope_Loop when S = Standard_Standard;
12818 else
12819 exit Scope_Loop;
12820 end if;
12821 end loop Scope_Loop;
12822 end Kill_Current_Values;
12824 --------------------------
12825 -- Kill_Size_Check_Code --
12826 --------------------------
12828 procedure Kill_Size_Check_Code (E : Entity_Id) is
12829 begin
12830 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12831 and then Present (Size_Check_Code (E))
12832 then
12833 Remove (Size_Check_Code (E));
12834 Set_Size_Check_Code (E, Empty);
12835 end if;
12836 end Kill_Size_Check_Code;
12838 --------------------------
12839 -- Known_To_Be_Assigned --
12840 --------------------------
12842 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
12843 P : constant Node_Id := Parent (N);
12845 begin
12846 case Nkind (P) is
12848 -- Test left side of assignment
12850 when N_Assignment_Statement =>
12851 return N = Name (P);
12853 -- Function call arguments are never lvalues
12855 when N_Function_Call =>
12856 return False;
12858 -- Positional parameter for procedure or accept call
12860 when N_Procedure_Call_Statement |
12861 N_Accept_Statement
12863 declare
12864 Proc : Entity_Id;
12865 Form : Entity_Id;
12866 Act : Node_Id;
12868 begin
12869 Proc := Get_Subprogram_Entity (P);
12871 if No (Proc) then
12872 return False;
12873 end if;
12875 -- If we are not a list member, something is strange, so
12876 -- be conservative and return False.
12878 if not Is_List_Member (N) then
12879 return False;
12880 end if;
12882 -- We are going to find the right formal by stepping forward
12883 -- through the formals, as we step backwards in the actuals.
12885 Form := First_Formal (Proc);
12886 Act := N;
12887 loop
12888 -- If no formal, something is weird, so be conservative
12889 -- and return False.
12891 if No (Form) then
12892 return False;
12893 end if;
12895 Prev (Act);
12896 exit when No (Act);
12897 Next_Formal (Form);
12898 end loop;
12900 return Ekind (Form) /= E_In_Parameter;
12901 end;
12903 -- Named parameter for procedure or accept call
12905 when N_Parameter_Association =>
12906 declare
12907 Proc : Entity_Id;
12908 Form : Entity_Id;
12910 begin
12911 Proc := Get_Subprogram_Entity (Parent (P));
12913 if No (Proc) then
12914 return False;
12915 end if;
12917 -- Loop through formals to find the one that matches
12919 Form := First_Formal (Proc);
12920 loop
12921 -- If no matching formal, that's peculiar, some kind of
12922 -- previous error, so return False to be conservative.
12923 -- Actually this also happens in legal code in the case
12924 -- where P is a parameter association for an Extra_Formal???
12926 if No (Form) then
12927 return False;
12928 end if;
12930 -- Else test for match
12932 if Chars (Form) = Chars (Selector_Name (P)) then
12933 return Ekind (Form) /= E_In_Parameter;
12934 end if;
12936 Next_Formal (Form);
12937 end loop;
12938 end;
12940 -- Test for appearing in a conversion that itself appears
12941 -- in an lvalue context, since this should be an lvalue.
12943 when N_Type_Conversion =>
12944 return Known_To_Be_Assigned (P);
12946 -- All other references are definitely not known to be modifications
12948 when others =>
12949 return False;
12951 end case;
12952 end Known_To_Be_Assigned;
12954 ---------------------------
12955 -- Last_Source_Statement --
12956 ---------------------------
12958 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
12959 N : Node_Id;
12961 begin
12962 N := Last (Statements (HSS));
12963 while Present (N) loop
12964 exit when Comes_From_Source (N);
12965 Prev (N);
12966 end loop;
12968 return N;
12969 end Last_Source_Statement;
12971 ----------------------------------
12972 -- Matching_Static_Array_Bounds --
12973 ----------------------------------
12975 function Matching_Static_Array_Bounds
12976 (L_Typ : Node_Id;
12977 R_Typ : Node_Id) return Boolean
12979 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
12980 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
12982 L_Index : Node_Id;
12983 R_Index : Node_Id;
12984 L_Low : Node_Id;
12985 L_High : Node_Id;
12986 L_Len : Uint;
12987 R_Low : Node_Id;
12988 R_High : Node_Id;
12989 R_Len : Uint;
12991 begin
12992 if L_Ndims /= R_Ndims then
12993 return False;
12994 end if;
12996 -- Unconstrained types do not have static bounds
12998 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
12999 return False;
13000 end if;
13002 -- First treat specially the first dimension, as the lower bound and
13003 -- length of string literals are not stored like those of arrays.
13005 if Ekind (L_Typ) = E_String_Literal_Subtype then
13006 L_Low := String_Literal_Low_Bound (L_Typ);
13007 L_Len := String_Literal_Length (L_Typ);
13008 else
13009 L_Index := First_Index (L_Typ);
13010 Get_Index_Bounds (L_Index, L_Low, L_High);
13012 if Is_OK_Static_Expression (L_Low)
13013 and then
13014 Is_OK_Static_Expression (L_High)
13015 then
13016 if Expr_Value (L_High) < Expr_Value (L_Low) then
13017 L_Len := Uint_0;
13018 else
13019 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
13020 end if;
13021 else
13022 return False;
13023 end if;
13024 end if;
13026 if Ekind (R_Typ) = E_String_Literal_Subtype then
13027 R_Low := String_Literal_Low_Bound (R_Typ);
13028 R_Len := String_Literal_Length (R_Typ);
13029 else
13030 R_Index := First_Index (R_Typ);
13031 Get_Index_Bounds (R_Index, R_Low, R_High);
13033 if Is_OK_Static_Expression (R_Low)
13034 and then
13035 Is_OK_Static_Expression (R_High)
13036 then
13037 if Expr_Value (R_High) < Expr_Value (R_Low) then
13038 R_Len := Uint_0;
13039 else
13040 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
13041 end if;
13042 else
13043 return False;
13044 end if;
13045 end if;
13047 if (Is_OK_Static_Expression (L_Low)
13048 and then
13049 Is_OK_Static_Expression (R_Low))
13050 and then Expr_Value (L_Low) = Expr_Value (R_Low)
13051 and then L_Len = R_Len
13052 then
13053 null;
13054 else
13055 return False;
13056 end if;
13058 -- Then treat all other dimensions
13060 for Indx in 2 .. L_Ndims loop
13061 Next (L_Index);
13062 Next (R_Index);
13064 Get_Index_Bounds (L_Index, L_Low, L_High);
13065 Get_Index_Bounds (R_Index, R_Low, R_High);
13067 if (Is_OK_Static_Expression (L_Low) and then
13068 Is_OK_Static_Expression (L_High) and then
13069 Is_OK_Static_Expression (R_Low) and then
13070 Is_OK_Static_Expression (R_High))
13071 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
13072 and then
13073 Expr_Value (L_High) = Expr_Value (R_High))
13074 then
13075 null;
13076 else
13077 return False;
13078 end if;
13079 end loop;
13081 -- If we fall through the loop, all indexes matched
13083 return True;
13084 end Matching_Static_Array_Bounds;
13086 -------------------
13087 -- May_Be_Lvalue --
13088 -------------------
13090 function May_Be_Lvalue (N : Node_Id) return Boolean is
13091 P : constant Node_Id := Parent (N);
13093 begin
13094 case Nkind (P) is
13096 -- Test left side of assignment
13098 when N_Assignment_Statement =>
13099 return N = Name (P);
13101 -- Test prefix of component or attribute. Note that the prefix of an
13102 -- explicit or implicit dereference cannot be an l-value.
13104 when N_Attribute_Reference =>
13105 return N = Prefix (P)
13106 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
13108 -- For an expanded name, the name is an lvalue if the expanded name
13109 -- is an lvalue, but the prefix is never an lvalue, since it is just
13110 -- the scope where the name is found.
13112 when N_Expanded_Name =>
13113 if N = Prefix (P) then
13114 return May_Be_Lvalue (P);
13115 else
13116 return False;
13117 end if;
13119 -- For a selected component A.B, A is certainly an lvalue if A.B is.
13120 -- B is a little interesting, if we have A.B := 3, there is some
13121 -- discussion as to whether B is an lvalue or not, we choose to say
13122 -- it is. Note however that A is not an lvalue if it is of an access
13123 -- type since this is an implicit dereference.
13125 when N_Selected_Component =>
13126 if N = Prefix (P)
13127 and then Present (Etype (N))
13128 and then Is_Access_Type (Etype (N))
13129 then
13130 return False;
13131 else
13132 return May_Be_Lvalue (P);
13133 end if;
13135 -- For an indexed component or slice, the index or slice bounds is
13136 -- never an lvalue. The prefix is an lvalue if the indexed component
13137 -- or slice is an lvalue, except if it is an access type, where we
13138 -- have an implicit dereference.
13140 when N_Indexed_Component | N_Slice =>
13141 if N /= Prefix (P)
13142 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
13143 then
13144 return False;
13145 else
13146 return May_Be_Lvalue (P);
13147 end if;
13149 -- Prefix of a reference is an lvalue if the reference is an lvalue
13151 when N_Reference =>
13152 return May_Be_Lvalue (P);
13154 -- Prefix of explicit dereference is never an lvalue
13156 when N_Explicit_Dereference =>
13157 return False;
13159 -- Positional parameter for subprogram, entry, or accept call.
13160 -- In older versions of Ada function call arguments are never
13161 -- lvalues. In Ada 2012 functions can have in-out parameters.
13163 when N_Subprogram_Call |
13164 N_Entry_Call_Statement |
13165 N_Accept_Statement
13167 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
13168 return False;
13169 end if;
13171 -- The following mechanism is clumsy and fragile. A single flag
13172 -- set in Resolve_Actuals would be preferable ???
13174 declare
13175 Proc : Entity_Id;
13176 Form : Entity_Id;
13177 Act : Node_Id;
13179 begin
13180 Proc := Get_Subprogram_Entity (P);
13182 if No (Proc) then
13183 return True;
13184 end if;
13186 -- If we are not a list member, something is strange, so be
13187 -- conservative and return True.
13189 if not Is_List_Member (N) then
13190 return True;
13191 end if;
13193 -- We are going to find the right formal by stepping forward
13194 -- through the formals, as we step backwards in the actuals.
13196 Form := First_Formal (Proc);
13197 Act := N;
13198 loop
13199 -- If no formal, something is weird, so be conservative and
13200 -- return True.
13202 if No (Form) then
13203 return True;
13204 end if;
13206 Prev (Act);
13207 exit when No (Act);
13208 Next_Formal (Form);
13209 end loop;
13211 return Ekind (Form) /= E_In_Parameter;
13212 end;
13214 -- Named parameter for procedure or accept call
13216 when N_Parameter_Association =>
13217 declare
13218 Proc : Entity_Id;
13219 Form : Entity_Id;
13221 begin
13222 Proc := Get_Subprogram_Entity (Parent (P));
13224 if No (Proc) then
13225 return True;
13226 end if;
13228 -- Loop through formals to find the one that matches
13230 Form := First_Formal (Proc);
13231 loop
13232 -- If no matching formal, that's peculiar, some kind of
13233 -- previous error, so return True to be conservative.
13234 -- Actually happens with legal code for an unresolved call
13235 -- where we may get the wrong homonym???
13237 if No (Form) then
13238 return True;
13239 end if;
13241 -- Else test for match
13243 if Chars (Form) = Chars (Selector_Name (P)) then
13244 return Ekind (Form) /= E_In_Parameter;
13245 end if;
13247 Next_Formal (Form);
13248 end loop;
13249 end;
13251 -- Test for appearing in a conversion that itself appears in an
13252 -- lvalue context, since this should be an lvalue.
13254 when N_Type_Conversion =>
13255 return May_Be_Lvalue (P);
13257 -- Test for appearance in object renaming declaration
13259 when N_Object_Renaming_Declaration =>
13260 return True;
13262 -- All other references are definitely not lvalues
13264 when others =>
13265 return False;
13267 end case;
13268 end May_Be_Lvalue;
13270 -----------------------
13271 -- Mark_Coextensions --
13272 -----------------------
13274 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
13275 Is_Dynamic : Boolean;
13276 -- Indicates whether the context causes nested coextensions to be
13277 -- dynamic or static
13279 function Mark_Allocator (N : Node_Id) return Traverse_Result;
13280 -- Recognize an allocator node and label it as a dynamic coextension
13282 --------------------
13283 -- Mark_Allocator --
13284 --------------------
13286 function Mark_Allocator (N : Node_Id) return Traverse_Result is
13287 begin
13288 if Nkind (N) = N_Allocator then
13289 if Is_Dynamic then
13290 Set_Is_Dynamic_Coextension (N);
13292 -- If the allocator expression is potentially dynamic, it may
13293 -- be expanded out of order and require dynamic allocation
13294 -- anyway, so we treat the coextension itself as dynamic.
13295 -- Potential optimization ???
13297 elsif Nkind (Expression (N)) = N_Qualified_Expression
13298 and then Nkind (Expression (Expression (N))) = N_Op_Concat
13299 then
13300 Set_Is_Dynamic_Coextension (N);
13301 else
13302 Set_Is_Static_Coextension (N);
13303 end if;
13304 end if;
13306 return OK;
13307 end Mark_Allocator;
13309 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
13311 -- Start of processing Mark_Coextensions
13313 begin
13314 case Nkind (Context_Nod) is
13316 -- Comment here ???
13318 when N_Assignment_Statement =>
13319 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
13321 -- An allocator that is a component of a returned aggregate
13322 -- must be dynamic.
13324 when N_Simple_Return_Statement =>
13325 declare
13326 Expr : constant Node_Id := Expression (Context_Nod);
13327 begin
13328 Is_Dynamic :=
13329 Nkind (Expr) = N_Allocator
13330 or else
13331 (Nkind (Expr) = N_Qualified_Expression
13332 and then Nkind (Expression (Expr)) = N_Aggregate);
13333 end;
13335 -- An alloctor within an object declaration in an extended return
13336 -- statement is of necessity dynamic.
13338 when N_Object_Declaration =>
13339 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
13340 or else
13341 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
13343 -- This routine should not be called for constructs which may not
13344 -- contain coextensions.
13346 when others =>
13347 raise Program_Error;
13348 end case;
13350 Mark_Allocators (Root_Nod);
13351 end Mark_Coextensions;
13353 -----------------
13354 -- Must_Inline --
13355 -----------------
13357 function Must_Inline (Subp : Entity_Id) return Boolean is
13358 begin
13359 return
13360 (Optimization_Level = 0
13362 -- AAMP and VM targets have no support for inlining in the backend.
13363 -- Hence we do as much inlining as possible in the front end.
13365 or else AAMP_On_Target
13366 or else VM_Target /= No_VM)
13367 and then Has_Pragma_Inline (Subp)
13368 and then (Has_Pragma_Inline_Always (Subp) or else Front_End_Inlining);
13369 end Must_Inline;
13371 ----------------------
13372 -- Needs_One_Actual --
13373 ----------------------
13375 function Needs_One_Actual (E : Entity_Id) return Boolean is
13376 Formal : Entity_Id;
13378 begin
13379 -- Ada 2005 or later, and formals present
13381 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
13382 Formal := Next_Formal (First_Formal (E));
13383 while Present (Formal) loop
13384 if No (Default_Value (Formal)) then
13385 return False;
13386 end if;
13388 Next_Formal (Formal);
13389 end loop;
13391 return True;
13393 -- Ada 83/95 or no formals
13395 else
13396 return False;
13397 end if;
13398 end Needs_One_Actual;
13400 ------------------------
13401 -- New_Copy_List_Tree --
13402 ------------------------
13404 function New_Copy_List_Tree (List : List_Id) return List_Id is
13405 NL : List_Id;
13406 E : Node_Id;
13408 begin
13409 if List = No_List then
13410 return No_List;
13412 else
13413 NL := New_List;
13414 E := First (List);
13416 while Present (E) loop
13417 Append (New_Copy_Tree (E), NL);
13418 E := Next (E);
13419 end loop;
13421 return NL;
13422 end if;
13423 end New_Copy_List_Tree;
13425 --------------------------------------------------
13426 -- New_Copy_Tree Auxiliary Data and Subprograms --
13427 --------------------------------------------------
13429 use Atree.Unchecked_Access;
13430 use Atree_Private_Part;
13432 -- Our approach here requires a two pass traversal of the tree. The
13433 -- first pass visits all nodes that eventually will be copied looking
13434 -- for defining Itypes. If any defining Itypes are found, then they are
13435 -- copied, and an entry is added to the replacement map. In the second
13436 -- phase, the tree is copied, using the replacement map to replace any
13437 -- Itype references within the copied tree.
13439 -- The following hash tables are used if the Map supplied has more
13440 -- than hash threshold entries to speed up access to the map. If
13441 -- there are fewer entries, then the map is searched sequentially
13442 -- (because setting up a hash table for only a few entries takes
13443 -- more time than it saves.
13445 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
13446 -- Hash function used for hash operations
13448 -------------------
13449 -- New_Copy_Hash --
13450 -------------------
13452 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
13453 begin
13454 return Nat (E) mod (NCT_Header_Num'Last + 1);
13455 end New_Copy_Hash;
13457 ---------------
13458 -- NCT_Assoc --
13459 ---------------
13461 -- The hash table NCT_Assoc associates old entities in the table
13462 -- with their corresponding new entities (i.e. the pairs of entries
13463 -- presented in the original Map argument are Key-Element pairs).
13465 package NCT_Assoc is new Simple_HTable (
13466 Header_Num => NCT_Header_Num,
13467 Element => Entity_Id,
13468 No_Element => Empty,
13469 Key => Entity_Id,
13470 Hash => New_Copy_Hash,
13471 Equal => Types."=");
13473 ---------------------
13474 -- NCT_Itype_Assoc --
13475 ---------------------
13477 -- The hash table NCT_Itype_Assoc contains entries only for those
13478 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13479 -- The key is the associated node, and the element is the new node
13480 -- itself (NOT the associated node for the new node).
13482 package NCT_Itype_Assoc is new Simple_HTable (
13483 Header_Num => NCT_Header_Num,
13484 Element => Entity_Id,
13485 No_Element => Empty,
13486 Key => Entity_Id,
13487 Hash => New_Copy_Hash,
13488 Equal => Types."=");
13490 -------------------
13491 -- New_Copy_Tree --
13492 -------------------
13494 function New_Copy_Tree
13495 (Source : Node_Id;
13496 Map : Elist_Id := No_Elist;
13497 New_Sloc : Source_Ptr := No_Location;
13498 New_Scope : Entity_Id := Empty) return Node_Id
13500 Actual_Map : Elist_Id := Map;
13501 -- This is the actual map for the copy. It is initialized with the
13502 -- given elements, and then enlarged as required for Itypes that are
13503 -- copied during the first phase of the copy operation. The visit
13504 -- procedures add elements to this map as Itypes are encountered.
13505 -- The reason we cannot use Map directly, is that it may well be
13506 -- (and normally is) initialized to No_Elist, and if we have mapped
13507 -- entities, we have to reset it to point to a real Elist.
13509 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
13510 -- Called during second phase to map entities into their corresponding
13511 -- copies using Actual_Map. If the argument is not an entity, or is not
13512 -- in Actual_Map, then it is returned unchanged.
13514 procedure Build_NCT_Hash_Tables;
13515 -- Builds hash tables (number of elements >= threshold value)
13517 function Copy_Elist_With_Replacement
13518 (Old_Elist : Elist_Id) return Elist_Id;
13519 -- Called during second phase to copy element list doing replacements
13521 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
13522 -- Called during the second phase to process a copied Itype. The actual
13523 -- copy happened during the first phase (so that we could make the entry
13524 -- in the mapping), but we still have to deal with the descendents of
13525 -- the copied Itype and copy them where necessary.
13527 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
13528 -- Called during second phase to copy list doing replacements
13530 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
13531 -- Called during second phase to copy node doing replacements
13533 procedure Visit_Elist (E : Elist_Id);
13534 -- Called during first phase to visit all elements of an Elist
13536 procedure Visit_Field (F : Union_Id; N : Node_Id);
13537 -- Visit a single field, recursing to call Visit_Node or Visit_List
13538 -- if the field is a syntactic descendent of the current node (i.e.
13539 -- its parent is Node N).
13541 procedure Visit_Itype (Old_Itype : Entity_Id);
13542 -- Called during first phase to visit subsidiary fields of a defining
13543 -- Itype, and also create a copy and make an entry in the replacement
13544 -- map for the new copy.
13546 procedure Visit_List (L : List_Id);
13547 -- Called during first phase to visit all elements of a List
13549 procedure Visit_Node (N : Node_Or_Entity_Id);
13550 -- Called during first phase to visit a node and all its subtrees
13552 -----------
13553 -- Assoc --
13554 -----------
13556 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
13557 E : Elmt_Id;
13558 Ent : Entity_Id;
13560 begin
13561 if not Has_Extension (N) or else No (Actual_Map) then
13562 return N;
13564 elsif NCT_Hash_Tables_Used then
13565 Ent := NCT_Assoc.Get (Entity_Id (N));
13567 if Present (Ent) then
13568 return Ent;
13569 else
13570 return N;
13571 end if;
13573 -- No hash table used, do serial search
13575 else
13576 E := First_Elmt (Actual_Map);
13577 while Present (E) loop
13578 if Node (E) = N then
13579 return Node (Next_Elmt (E));
13580 else
13581 E := Next_Elmt (Next_Elmt (E));
13582 end if;
13583 end loop;
13584 end if;
13586 return N;
13587 end Assoc;
13589 ---------------------------
13590 -- Build_NCT_Hash_Tables --
13591 ---------------------------
13593 procedure Build_NCT_Hash_Tables is
13594 Elmt : Elmt_Id;
13595 Ent : Entity_Id;
13596 begin
13597 if NCT_Hash_Table_Setup then
13598 NCT_Assoc.Reset;
13599 NCT_Itype_Assoc.Reset;
13600 end if;
13602 Elmt := First_Elmt (Actual_Map);
13603 while Present (Elmt) loop
13604 Ent := Node (Elmt);
13606 -- Get new entity, and associate old and new
13608 Next_Elmt (Elmt);
13609 NCT_Assoc.Set (Ent, Node (Elmt));
13611 if Is_Type (Ent) then
13612 declare
13613 Anode : constant Entity_Id :=
13614 Associated_Node_For_Itype (Ent);
13616 begin
13617 if Present (Anode) then
13619 -- Enter a link between the associated node of the
13620 -- old Itype and the new Itype, for updating later
13621 -- when node is copied.
13623 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
13624 end if;
13625 end;
13626 end if;
13628 Next_Elmt (Elmt);
13629 end loop;
13631 NCT_Hash_Tables_Used := True;
13632 NCT_Hash_Table_Setup := True;
13633 end Build_NCT_Hash_Tables;
13635 ---------------------------------
13636 -- Copy_Elist_With_Replacement --
13637 ---------------------------------
13639 function Copy_Elist_With_Replacement
13640 (Old_Elist : Elist_Id) return Elist_Id
13642 M : Elmt_Id;
13643 New_Elist : Elist_Id;
13645 begin
13646 if No (Old_Elist) then
13647 return No_Elist;
13649 else
13650 New_Elist := New_Elmt_List;
13652 M := First_Elmt (Old_Elist);
13653 while Present (M) loop
13654 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
13655 Next_Elmt (M);
13656 end loop;
13657 end if;
13659 return New_Elist;
13660 end Copy_Elist_With_Replacement;
13662 ---------------------------------
13663 -- Copy_Itype_With_Replacement --
13664 ---------------------------------
13666 -- This routine exactly parallels its phase one analog Visit_Itype,
13668 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
13669 begin
13670 -- Translate Next_Entity, Scope and Etype fields, in case they
13671 -- reference entities that have been mapped into copies.
13673 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
13674 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
13676 if Present (New_Scope) then
13677 Set_Scope (New_Itype, New_Scope);
13678 else
13679 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
13680 end if;
13682 -- Copy referenced fields
13684 if Is_Discrete_Type (New_Itype) then
13685 Set_Scalar_Range (New_Itype,
13686 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
13688 elsif Has_Discriminants (Base_Type (New_Itype)) then
13689 Set_Discriminant_Constraint (New_Itype,
13690 Copy_Elist_With_Replacement
13691 (Discriminant_Constraint (New_Itype)));
13693 elsif Is_Array_Type (New_Itype) then
13694 if Present (First_Index (New_Itype)) then
13695 Set_First_Index (New_Itype,
13696 First (Copy_List_With_Replacement
13697 (List_Containing (First_Index (New_Itype)))));
13698 end if;
13700 if Is_Packed (New_Itype) then
13701 Set_Packed_Array_Impl_Type (New_Itype,
13702 Copy_Node_With_Replacement
13703 (Packed_Array_Impl_Type (New_Itype)));
13704 end if;
13705 end if;
13706 end Copy_Itype_With_Replacement;
13708 --------------------------------
13709 -- Copy_List_With_Replacement --
13710 --------------------------------
13712 function Copy_List_With_Replacement
13713 (Old_List : List_Id) return List_Id
13715 New_List : List_Id;
13716 E : Node_Id;
13718 begin
13719 if Old_List = No_List then
13720 return No_List;
13722 else
13723 New_List := Empty_List;
13725 E := First (Old_List);
13726 while Present (E) loop
13727 Append (Copy_Node_With_Replacement (E), New_List);
13728 Next (E);
13729 end loop;
13731 return New_List;
13732 end if;
13733 end Copy_List_With_Replacement;
13735 --------------------------------
13736 -- Copy_Node_With_Replacement --
13737 --------------------------------
13739 function Copy_Node_With_Replacement
13740 (Old_Node : Node_Id) return Node_Id
13742 New_Node : Node_Id;
13744 procedure Adjust_Named_Associations
13745 (Old_Node : Node_Id;
13746 New_Node : Node_Id);
13747 -- If a call node has named associations, these are chained through
13748 -- the First_Named_Actual, Next_Named_Actual links. These must be
13749 -- propagated separately to the new parameter list, because these
13750 -- are not syntactic fields.
13752 function Copy_Field_With_Replacement
13753 (Field : Union_Id) return Union_Id;
13754 -- Given Field, which is a field of Old_Node, return a copy of it
13755 -- if it is a syntactic field (i.e. its parent is Node), setting
13756 -- the parent of the copy to poit to New_Node. Otherwise returns
13757 -- the field (possibly mapped if it is an entity).
13759 -------------------------------
13760 -- Adjust_Named_Associations --
13761 -------------------------------
13763 procedure Adjust_Named_Associations
13764 (Old_Node : Node_Id;
13765 New_Node : Node_Id)
13767 Old_E : Node_Id;
13768 New_E : Node_Id;
13770 Old_Next : Node_Id;
13771 New_Next : Node_Id;
13773 begin
13774 Old_E := First (Parameter_Associations (Old_Node));
13775 New_E := First (Parameter_Associations (New_Node));
13776 while Present (Old_E) loop
13777 if Nkind (Old_E) = N_Parameter_Association
13778 and then Present (Next_Named_Actual (Old_E))
13779 then
13780 if First_Named_Actual (Old_Node)
13781 = Explicit_Actual_Parameter (Old_E)
13782 then
13783 Set_First_Named_Actual
13784 (New_Node, Explicit_Actual_Parameter (New_E));
13785 end if;
13787 -- Now scan parameter list from the beginning,to locate
13788 -- next named actual, which can be out of order.
13790 Old_Next := First (Parameter_Associations (Old_Node));
13791 New_Next := First (Parameter_Associations (New_Node));
13793 while Nkind (Old_Next) /= N_Parameter_Association
13794 or else Explicit_Actual_Parameter (Old_Next)
13795 /= Next_Named_Actual (Old_E)
13796 loop
13797 Next (Old_Next);
13798 Next (New_Next);
13799 end loop;
13801 Set_Next_Named_Actual
13802 (New_E, Explicit_Actual_Parameter (New_Next));
13803 end if;
13805 Next (Old_E);
13806 Next (New_E);
13807 end loop;
13808 end Adjust_Named_Associations;
13810 ---------------------------------
13811 -- Copy_Field_With_Replacement --
13812 ---------------------------------
13814 function Copy_Field_With_Replacement
13815 (Field : Union_Id) return Union_Id
13817 begin
13818 if Field = Union_Id (Empty) then
13819 return Field;
13821 elsif Field in Node_Range then
13822 declare
13823 Old_N : constant Node_Id := Node_Id (Field);
13824 New_N : Node_Id;
13826 begin
13827 -- If syntactic field, as indicated by the parent pointer
13828 -- being set, then copy the referenced node recursively.
13830 if Parent (Old_N) = Old_Node then
13831 New_N := Copy_Node_With_Replacement (Old_N);
13833 if New_N /= Old_N then
13834 Set_Parent (New_N, New_Node);
13835 end if;
13837 -- For semantic fields, update possible entity reference
13838 -- from the replacement map.
13840 else
13841 New_N := Assoc (Old_N);
13842 end if;
13844 return Union_Id (New_N);
13845 end;
13847 elsif Field in List_Range then
13848 declare
13849 Old_L : constant List_Id := List_Id (Field);
13850 New_L : List_Id;
13852 begin
13853 -- If syntactic field, as indicated by the parent pointer,
13854 -- then recursively copy the entire referenced list.
13856 if Parent (Old_L) = Old_Node then
13857 New_L := Copy_List_With_Replacement (Old_L);
13858 Set_Parent (New_L, New_Node);
13860 -- For semantic list, just returned unchanged
13862 else
13863 New_L := Old_L;
13864 end if;
13866 return Union_Id (New_L);
13867 end;
13869 -- Anything other than a list or a node is returned unchanged
13871 else
13872 return Field;
13873 end if;
13874 end Copy_Field_With_Replacement;
13876 -- Start of processing for Copy_Node_With_Replacement
13878 begin
13879 if Old_Node <= Empty_Or_Error then
13880 return Old_Node;
13882 elsif Has_Extension (Old_Node) then
13883 return Assoc (Old_Node);
13885 else
13886 New_Node := New_Copy (Old_Node);
13888 -- If the node we are copying is the associated node of a
13889 -- previously copied Itype, then adjust the associated node
13890 -- of the copy of that Itype accordingly.
13892 if Present (Actual_Map) then
13893 declare
13894 E : Elmt_Id;
13895 Ent : Entity_Id;
13897 begin
13898 -- Case of hash table used
13900 if NCT_Hash_Tables_Used then
13901 Ent := NCT_Itype_Assoc.Get (Old_Node);
13903 if Present (Ent) then
13904 Set_Associated_Node_For_Itype (Ent, New_Node);
13905 end if;
13907 -- Case of no hash table used
13909 else
13910 E := First_Elmt (Actual_Map);
13911 while Present (E) loop
13912 if Is_Itype (Node (E))
13913 and then
13914 Old_Node = Associated_Node_For_Itype (Node (E))
13915 then
13916 Set_Associated_Node_For_Itype
13917 (Node (Next_Elmt (E)), New_Node);
13918 end if;
13920 E := Next_Elmt (Next_Elmt (E));
13921 end loop;
13922 end if;
13923 end;
13924 end if;
13926 -- Recursively copy descendents
13928 Set_Field1
13929 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
13930 Set_Field2
13931 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
13932 Set_Field3
13933 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
13934 Set_Field4
13935 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
13936 Set_Field5
13937 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
13939 -- Adjust Sloc of new node if necessary
13941 if New_Sloc /= No_Location then
13942 Set_Sloc (New_Node, New_Sloc);
13944 -- If we adjust the Sloc, then we are essentially making
13945 -- a completely new node, so the Comes_From_Source flag
13946 -- should be reset to the proper default value.
13948 Nodes.Table (New_Node).Comes_From_Source :=
13949 Default_Node.Comes_From_Source;
13950 end if;
13952 -- If the node is call and has named associations,
13953 -- set the corresponding links in the copy.
13955 if (Nkind (Old_Node) = N_Function_Call
13956 or else Nkind (Old_Node) = N_Entry_Call_Statement
13957 or else
13958 Nkind (Old_Node) = N_Procedure_Call_Statement)
13959 and then Present (First_Named_Actual (Old_Node))
13960 then
13961 Adjust_Named_Associations (Old_Node, New_Node);
13962 end if;
13964 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
13965 -- The replacement mechanism applies to entities, and is not used
13966 -- here. Eventually we may need a more general graph-copying
13967 -- routine. For now, do a sequential search to find desired node.
13969 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
13970 and then Present (First_Real_Statement (Old_Node))
13971 then
13972 declare
13973 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
13974 N1, N2 : Node_Id;
13976 begin
13977 N1 := First (Statements (Old_Node));
13978 N2 := First (Statements (New_Node));
13980 while N1 /= Old_F loop
13981 Next (N1);
13982 Next (N2);
13983 end loop;
13985 Set_First_Real_Statement (New_Node, N2);
13986 end;
13987 end if;
13988 end if;
13990 -- All done, return copied node
13992 return New_Node;
13993 end Copy_Node_With_Replacement;
13995 -----------------
13996 -- Visit_Elist --
13997 -----------------
13999 procedure Visit_Elist (E : Elist_Id) is
14000 Elmt : Elmt_Id;
14001 begin
14002 if Present (E) then
14003 Elmt := First_Elmt (E);
14005 while Elmt /= No_Elmt loop
14006 Visit_Node (Node (Elmt));
14007 Next_Elmt (Elmt);
14008 end loop;
14009 end if;
14010 end Visit_Elist;
14012 -----------------
14013 -- Visit_Field --
14014 -----------------
14016 procedure Visit_Field (F : Union_Id; N : Node_Id) is
14017 begin
14018 if F = Union_Id (Empty) then
14019 return;
14021 elsif F in Node_Range then
14023 -- Copy node if it is syntactic, i.e. its parent pointer is
14024 -- set to point to the field that referenced it (certain
14025 -- Itypes will also meet this criterion, which is fine, since
14026 -- these are clearly Itypes that do need to be copied, since
14027 -- we are copying their parent.)
14029 if Parent (Node_Id (F)) = N then
14030 Visit_Node (Node_Id (F));
14031 return;
14033 -- Another case, if we are pointing to an Itype, then we want
14034 -- to copy it if its associated node is somewhere in the tree
14035 -- being copied.
14037 -- Note: the exclusion of self-referential copies is just an
14038 -- optimization, since the search of the already copied list
14039 -- would catch it, but it is a common case (Etype pointing
14040 -- to itself for an Itype that is a base type).
14042 elsif Has_Extension (Node_Id (F))
14043 and then Is_Itype (Entity_Id (F))
14044 and then Node_Id (F) /= N
14045 then
14046 declare
14047 P : Node_Id;
14049 begin
14050 P := Associated_Node_For_Itype (Node_Id (F));
14051 while Present (P) loop
14052 if P = Source then
14053 Visit_Node (Node_Id (F));
14054 return;
14055 else
14056 P := Parent (P);
14057 end if;
14058 end loop;
14060 -- An Itype whose parent is not being copied definitely
14061 -- should NOT be copied, since it does not belong in any
14062 -- sense to the copied subtree.
14064 return;
14065 end;
14066 end if;
14068 elsif F in List_Range and then Parent (List_Id (F)) = N then
14069 Visit_List (List_Id (F));
14070 return;
14071 end if;
14072 end Visit_Field;
14074 -----------------
14075 -- Visit_Itype --
14076 -----------------
14078 procedure Visit_Itype (Old_Itype : Entity_Id) is
14079 New_Itype : Entity_Id;
14080 E : Elmt_Id;
14081 Ent : Entity_Id;
14083 begin
14084 -- Itypes that describe the designated type of access to subprograms
14085 -- have the structure of subprogram declarations, with signatures,
14086 -- etc. Either we duplicate the signatures completely, or choose to
14087 -- share such itypes, which is fine because their elaboration will
14088 -- have no side effects.
14090 if Ekind (Old_Itype) = E_Subprogram_Type then
14091 return;
14092 end if;
14094 New_Itype := New_Copy (Old_Itype);
14096 -- The new Itype has all the attributes of the old one, and
14097 -- we just copy the contents of the entity. However, the back-end
14098 -- needs different names for debugging purposes, so we create a
14099 -- new internal name for it in all cases.
14101 Set_Chars (New_Itype, New_Internal_Name ('T'));
14103 -- If our associated node is an entity that has already been copied,
14104 -- then set the associated node of the copy to point to the right
14105 -- copy. If we have copied an Itype that is itself the associated
14106 -- node of some previously copied Itype, then we set the right
14107 -- pointer in the other direction.
14109 if Present (Actual_Map) then
14111 -- Case of hash tables used
14113 if NCT_Hash_Tables_Used then
14115 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
14117 if Present (Ent) then
14118 Set_Associated_Node_For_Itype (New_Itype, Ent);
14119 end if;
14121 Ent := NCT_Itype_Assoc.Get (Old_Itype);
14122 if Present (Ent) then
14123 Set_Associated_Node_For_Itype (Ent, New_Itype);
14125 -- If the hash table has no association for this Itype and
14126 -- its associated node, enter one now.
14128 else
14129 NCT_Itype_Assoc.Set
14130 (Associated_Node_For_Itype (Old_Itype), New_Itype);
14131 end if;
14133 -- Case of hash tables not used
14135 else
14136 E := First_Elmt (Actual_Map);
14137 while Present (E) loop
14138 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
14139 Set_Associated_Node_For_Itype
14140 (New_Itype, Node (Next_Elmt (E)));
14141 end if;
14143 if Is_Type (Node (E))
14144 and then Old_Itype = Associated_Node_For_Itype (Node (E))
14145 then
14146 Set_Associated_Node_For_Itype
14147 (Node (Next_Elmt (E)), New_Itype);
14148 end if;
14150 E := Next_Elmt (Next_Elmt (E));
14151 end loop;
14152 end if;
14153 end if;
14155 if Present (Freeze_Node (New_Itype)) then
14156 Set_Is_Frozen (New_Itype, False);
14157 Set_Freeze_Node (New_Itype, Empty);
14158 end if;
14160 -- Add new association to map
14162 if No (Actual_Map) then
14163 Actual_Map := New_Elmt_List;
14164 end if;
14166 Append_Elmt (Old_Itype, Actual_Map);
14167 Append_Elmt (New_Itype, Actual_Map);
14169 if NCT_Hash_Tables_Used then
14170 NCT_Assoc.Set (Old_Itype, New_Itype);
14172 else
14173 NCT_Table_Entries := NCT_Table_Entries + 1;
14175 if NCT_Table_Entries > NCT_Hash_Threshold then
14176 Build_NCT_Hash_Tables;
14177 end if;
14178 end if;
14180 -- If a record subtype is simply copied, the entity list will be
14181 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
14183 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
14184 Set_Cloned_Subtype (New_Itype, Old_Itype);
14185 end if;
14187 -- Visit descendents that eventually get copied
14189 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
14191 if Is_Discrete_Type (Old_Itype) then
14192 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
14194 elsif Has_Discriminants (Base_Type (Old_Itype)) then
14195 -- ??? This should involve call to Visit_Field
14196 Visit_Elist (Discriminant_Constraint (Old_Itype));
14198 elsif Is_Array_Type (Old_Itype) then
14199 if Present (First_Index (Old_Itype)) then
14200 Visit_Field (Union_Id (List_Containing
14201 (First_Index (Old_Itype))),
14202 Old_Itype);
14203 end if;
14205 if Is_Packed (Old_Itype) then
14206 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
14207 Old_Itype);
14208 end if;
14209 end if;
14210 end Visit_Itype;
14212 ----------------
14213 -- Visit_List --
14214 ----------------
14216 procedure Visit_List (L : List_Id) is
14217 N : Node_Id;
14218 begin
14219 if L /= No_List then
14220 N := First (L);
14222 while Present (N) loop
14223 Visit_Node (N);
14224 Next (N);
14225 end loop;
14226 end if;
14227 end Visit_List;
14229 ----------------
14230 -- Visit_Node --
14231 ----------------
14233 procedure Visit_Node (N : Node_Or_Entity_Id) is
14235 -- Start of processing for Visit_Node
14237 begin
14238 -- Handle case of an Itype, which must be copied
14240 if Has_Extension (N) and then Is_Itype (N) then
14242 -- Nothing to do if already in the list. This can happen with an
14243 -- Itype entity that appears more than once in the tree.
14244 -- Note that we do not want to visit descendents in this case.
14246 -- Test for already in list when hash table is used
14248 if NCT_Hash_Tables_Used then
14249 if Present (NCT_Assoc.Get (Entity_Id (N))) then
14250 return;
14251 end if;
14253 -- Test for already in list when hash table not used
14255 else
14256 declare
14257 E : Elmt_Id;
14258 begin
14259 if Present (Actual_Map) then
14260 E := First_Elmt (Actual_Map);
14261 while Present (E) loop
14262 if Node (E) = N then
14263 return;
14264 else
14265 E := Next_Elmt (Next_Elmt (E));
14266 end if;
14267 end loop;
14268 end if;
14269 end;
14270 end if;
14272 Visit_Itype (N);
14273 end if;
14275 -- Visit descendents
14277 Visit_Field (Field1 (N), N);
14278 Visit_Field (Field2 (N), N);
14279 Visit_Field (Field3 (N), N);
14280 Visit_Field (Field4 (N), N);
14281 Visit_Field (Field5 (N), N);
14282 end Visit_Node;
14284 -- Start of processing for New_Copy_Tree
14286 begin
14287 Actual_Map := Map;
14289 -- See if we should use hash table
14291 if No (Actual_Map) then
14292 NCT_Hash_Tables_Used := False;
14294 else
14295 declare
14296 Elmt : Elmt_Id;
14298 begin
14299 NCT_Table_Entries := 0;
14301 Elmt := First_Elmt (Actual_Map);
14302 while Present (Elmt) loop
14303 NCT_Table_Entries := NCT_Table_Entries + 1;
14304 Next_Elmt (Elmt);
14305 Next_Elmt (Elmt);
14306 end loop;
14308 if NCT_Table_Entries > NCT_Hash_Threshold then
14309 Build_NCT_Hash_Tables;
14310 else
14311 NCT_Hash_Tables_Used := False;
14312 end if;
14313 end;
14314 end if;
14316 -- Hash table set up if required, now start phase one by visiting
14317 -- top node (we will recursively visit the descendents).
14319 Visit_Node (Source);
14321 -- Now the second phase of the copy can start. First we process
14322 -- all the mapped entities, copying their descendents.
14324 if Present (Actual_Map) then
14325 declare
14326 Elmt : Elmt_Id;
14327 New_Itype : Entity_Id;
14328 begin
14329 Elmt := First_Elmt (Actual_Map);
14330 while Present (Elmt) loop
14331 Next_Elmt (Elmt);
14332 New_Itype := Node (Elmt);
14333 Copy_Itype_With_Replacement (New_Itype);
14334 Next_Elmt (Elmt);
14335 end loop;
14336 end;
14337 end if;
14339 -- Now we can copy the actual tree
14341 return Copy_Node_With_Replacement (Source);
14342 end New_Copy_Tree;
14344 -------------------------
14345 -- New_External_Entity --
14346 -------------------------
14348 function New_External_Entity
14349 (Kind : Entity_Kind;
14350 Scope_Id : Entity_Id;
14351 Sloc_Value : Source_Ptr;
14352 Related_Id : Entity_Id;
14353 Suffix : Character;
14354 Suffix_Index : Nat := 0;
14355 Prefix : Character := ' ') return Entity_Id
14357 N : constant Entity_Id :=
14358 Make_Defining_Identifier (Sloc_Value,
14359 New_External_Name
14360 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
14362 begin
14363 Set_Ekind (N, Kind);
14364 Set_Is_Internal (N, True);
14365 Append_Entity (N, Scope_Id);
14366 Set_Public_Status (N);
14368 if Kind in Type_Kind then
14369 Init_Size_Align (N);
14370 end if;
14372 return N;
14373 end New_External_Entity;
14375 -------------------------
14376 -- New_Internal_Entity --
14377 -------------------------
14379 function New_Internal_Entity
14380 (Kind : Entity_Kind;
14381 Scope_Id : Entity_Id;
14382 Sloc_Value : Source_Ptr;
14383 Id_Char : Character) return Entity_Id
14385 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
14387 begin
14388 Set_Ekind (N, Kind);
14389 Set_Is_Internal (N, True);
14390 Append_Entity (N, Scope_Id);
14392 if Kind in Type_Kind then
14393 Init_Size_Align (N);
14394 end if;
14396 return N;
14397 end New_Internal_Entity;
14399 -----------------
14400 -- Next_Actual --
14401 -----------------
14403 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
14404 N : Node_Id;
14406 begin
14407 -- If we are pointing at a positional parameter, it is a member of a
14408 -- node list (the list of parameters), and the next parameter is the
14409 -- next node on the list, unless we hit a parameter association, then
14410 -- we shift to using the chain whose head is the First_Named_Actual in
14411 -- the parent, and then is threaded using the Next_Named_Actual of the
14412 -- Parameter_Association. All this fiddling is because the original node
14413 -- list is in the textual call order, and what we need is the
14414 -- declaration order.
14416 if Is_List_Member (Actual_Id) then
14417 N := Next (Actual_Id);
14419 if Nkind (N) = N_Parameter_Association then
14420 return First_Named_Actual (Parent (Actual_Id));
14421 else
14422 return N;
14423 end if;
14425 else
14426 return Next_Named_Actual (Parent (Actual_Id));
14427 end if;
14428 end Next_Actual;
14430 procedure Next_Actual (Actual_Id : in out Node_Id) is
14431 begin
14432 Actual_Id := Next_Actual (Actual_Id);
14433 end Next_Actual;
14435 -----------------------
14436 -- Normalize_Actuals --
14437 -----------------------
14439 -- Chain actuals according to formals of subprogram. If there are no named
14440 -- associations, the chain is simply the list of Parameter Associations,
14441 -- since the order is the same as the declaration order. If there are named
14442 -- associations, then the First_Named_Actual field in the N_Function_Call
14443 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14444 -- node for the parameter that comes first in declaration order. The
14445 -- remaining named parameters are then chained in declaration order using
14446 -- Next_Named_Actual.
14448 -- This routine also verifies that the number of actuals is compatible with
14449 -- the number and default values of formals, but performs no type checking
14450 -- (type checking is done by the caller).
14452 -- If the matching succeeds, Success is set to True and the caller proceeds
14453 -- with type-checking. If the match is unsuccessful, then Success is set to
14454 -- False, and the caller attempts a different interpretation, if there is
14455 -- one.
14457 -- If the flag Report is on, the call is not overloaded, and a failure to
14458 -- match can be reported here, rather than in the caller.
14460 procedure Normalize_Actuals
14461 (N : Node_Id;
14462 S : Entity_Id;
14463 Report : Boolean;
14464 Success : out Boolean)
14466 Actuals : constant List_Id := Parameter_Associations (N);
14467 Actual : Node_Id := Empty;
14468 Formal : Entity_Id;
14469 Last : Node_Id := Empty;
14470 First_Named : Node_Id := Empty;
14471 Found : Boolean;
14473 Formals_To_Match : Integer := 0;
14474 Actuals_To_Match : Integer := 0;
14476 procedure Chain (A : Node_Id);
14477 -- Add named actual at the proper place in the list, using the
14478 -- Next_Named_Actual link.
14480 function Reporting return Boolean;
14481 -- Determines if an error is to be reported. To report an error, we
14482 -- need Report to be True, and also we do not report errors caused
14483 -- by calls to init procs that occur within other init procs. Such
14484 -- errors must always be cascaded errors, since if all the types are
14485 -- declared correctly, the compiler will certainly build decent calls.
14487 -----------
14488 -- Chain --
14489 -----------
14491 procedure Chain (A : Node_Id) is
14492 begin
14493 if No (Last) then
14495 -- Call node points to first actual in list
14497 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
14499 else
14500 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
14501 end if;
14503 Last := A;
14504 Set_Next_Named_Actual (Last, Empty);
14505 end Chain;
14507 ---------------
14508 -- Reporting --
14509 ---------------
14511 function Reporting return Boolean is
14512 begin
14513 if not Report then
14514 return False;
14516 elsif not Within_Init_Proc then
14517 return True;
14519 elsif Is_Init_Proc (Entity (Name (N))) then
14520 return False;
14522 else
14523 return True;
14524 end if;
14525 end Reporting;
14527 -- Start of processing for Normalize_Actuals
14529 begin
14530 if Is_Access_Type (S) then
14532 -- The name in the call is a function call that returns an access
14533 -- to subprogram. The designated type has the list of formals.
14535 Formal := First_Formal (Designated_Type (S));
14536 else
14537 Formal := First_Formal (S);
14538 end if;
14540 while Present (Formal) loop
14541 Formals_To_Match := Formals_To_Match + 1;
14542 Next_Formal (Formal);
14543 end loop;
14545 -- Find if there is a named association, and verify that no positional
14546 -- associations appear after named ones.
14548 if Present (Actuals) then
14549 Actual := First (Actuals);
14550 end if;
14552 while Present (Actual)
14553 and then Nkind (Actual) /= N_Parameter_Association
14554 loop
14555 Actuals_To_Match := Actuals_To_Match + 1;
14556 Next (Actual);
14557 end loop;
14559 if No (Actual) and Actuals_To_Match = Formals_To_Match then
14561 -- Most common case: positional notation, no defaults
14563 Success := True;
14564 return;
14566 elsif Actuals_To_Match > Formals_To_Match then
14568 -- Too many actuals: will not work
14570 if Reporting then
14571 if Is_Entity_Name (Name (N)) then
14572 Error_Msg_N ("too many arguments in call to&", Name (N));
14573 else
14574 Error_Msg_N ("too many arguments in call", N);
14575 end if;
14576 end if;
14578 Success := False;
14579 return;
14580 end if;
14582 First_Named := Actual;
14584 while Present (Actual) loop
14585 if Nkind (Actual) /= N_Parameter_Association then
14586 Error_Msg_N
14587 ("positional parameters not allowed after named ones", Actual);
14588 Success := False;
14589 return;
14591 else
14592 Actuals_To_Match := Actuals_To_Match + 1;
14593 end if;
14595 Next (Actual);
14596 end loop;
14598 if Present (Actuals) then
14599 Actual := First (Actuals);
14600 end if;
14602 Formal := First_Formal (S);
14603 while Present (Formal) loop
14605 -- Match the formals in order. If the corresponding actual is
14606 -- positional, nothing to do. Else scan the list of named actuals
14607 -- to find the one with the right name.
14609 if Present (Actual)
14610 and then Nkind (Actual) /= N_Parameter_Association
14611 then
14612 Next (Actual);
14613 Actuals_To_Match := Actuals_To_Match - 1;
14614 Formals_To_Match := Formals_To_Match - 1;
14616 else
14617 -- For named parameters, search the list of actuals to find
14618 -- one that matches the next formal name.
14620 Actual := First_Named;
14621 Found := False;
14622 while Present (Actual) loop
14623 if Chars (Selector_Name (Actual)) = Chars (Formal) then
14624 Found := True;
14625 Chain (Actual);
14626 Actuals_To_Match := Actuals_To_Match - 1;
14627 Formals_To_Match := Formals_To_Match - 1;
14628 exit;
14629 end if;
14631 Next (Actual);
14632 end loop;
14634 if not Found then
14635 if Ekind (Formal) /= E_In_Parameter
14636 or else No (Default_Value (Formal))
14637 then
14638 if Reporting then
14639 if (Comes_From_Source (S)
14640 or else Sloc (S) = Standard_Location)
14641 and then Is_Overloadable (S)
14642 then
14643 if No (Actuals)
14644 and then
14645 Nkind_In (Parent (N), N_Procedure_Call_Statement,
14646 N_Function_Call,
14647 N_Parameter_Association)
14648 and then Ekind (S) /= E_Function
14649 then
14650 Set_Etype (N, Etype (S));
14652 else
14653 Error_Msg_Name_1 := Chars (S);
14654 Error_Msg_Sloc := Sloc (S);
14655 Error_Msg_NE
14656 ("missing argument for parameter & "
14657 & "in call to % declared #", N, Formal);
14658 end if;
14660 elsif Is_Overloadable (S) then
14661 Error_Msg_Name_1 := Chars (S);
14663 -- Point to type derivation that generated the
14664 -- operation.
14666 Error_Msg_Sloc := Sloc (Parent (S));
14668 Error_Msg_NE
14669 ("missing argument for parameter & "
14670 & "in call to % (inherited) #", N, Formal);
14672 else
14673 Error_Msg_NE
14674 ("missing argument for parameter &", N, Formal);
14675 end if;
14676 end if;
14678 Success := False;
14679 return;
14681 else
14682 Formals_To_Match := Formals_To_Match - 1;
14683 end if;
14684 end if;
14685 end if;
14687 Next_Formal (Formal);
14688 end loop;
14690 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
14691 Success := True;
14692 return;
14694 else
14695 if Reporting then
14697 -- Find some superfluous named actual that did not get
14698 -- attached to the list of associations.
14700 Actual := First (Actuals);
14701 while Present (Actual) loop
14702 if Nkind (Actual) = N_Parameter_Association
14703 and then Actual /= Last
14704 and then No (Next_Named_Actual (Actual))
14705 then
14706 Error_Msg_N ("unmatched actual & in call",
14707 Selector_Name (Actual));
14708 exit;
14709 end if;
14711 Next (Actual);
14712 end loop;
14713 end if;
14715 Success := False;
14716 return;
14717 end if;
14718 end Normalize_Actuals;
14720 --------------------------------
14721 -- Note_Possible_Modification --
14722 --------------------------------
14724 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
14725 Modification_Comes_From_Source : constant Boolean :=
14726 Comes_From_Source (Parent (N));
14728 Ent : Entity_Id;
14729 Exp : Node_Id;
14731 begin
14732 -- Loop to find referenced entity, if there is one
14734 Exp := N;
14735 loop
14736 Ent := Empty;
14738 if Is_Entity_Name (Exp) then
14739 Ent := Entity (Exp);
14741 -- If the entity is missing, it is an undeclared identifier,
14742 -- and there is nothing to annotate.
14744 if No (Ent) then
14745 return;
14746 end if;
14748 elsif Nkind (Exp) = N_Explicit_Dereference then
14749 declare
14750 P : constant Node_Id := Prefix (Exp);
14752 begin
14753 -- In formal verification mode, keep track of all reads and
14754 -- writes through explicit dereferences.
14756 if GNATprove_Mode then
14757 SPARK_Specific.Generate_Dereference (N, 'm');
14758 end if;
14760 if Nkind (P) = N_Selected_Component
14761 and then Present (Entry_Formal (Entity (Selector_Name (P))))
14762 then
14763 -- Case of a reference to an entry formal
14765 Ent := Entry_Formal (Entity (Selector_Name (P)));
14767 elsif Nkind (P) = N_Identifier
14768 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
14769 and then Present (Expression (Parent (Entity (P))))
14770 and then Nkind (Expression (Parent (Entity (P)))) =
14771 N_Reference
14772 then
14773 -- Case of a reference to a value on which side effects have
14774 -- been removed.
14776 Exp := Prefix (Expression (Parent (Entity (P))));
14777 goto Continue;
14779 else
14780 return;
14781 end if;
14782 end;
14784 elsif Nkind_In (Exp, N_Type_Conversion,
14785 N_Unchecked_Type_Conversion)
14786 then
14787 Exp := Expression (Exp);
14788 goto Continue;
14790 elsif Nkind_In (Exp, N_Slice,
14791 N_Indexed_Component,
14792 N_Selected_Component)
14793 then
14794 -- Special check, if the prefix is an access type, then return
14795 -- since we are modifying the thing pointed to, not the prefix.
14796 -- When we are expanding, most usually the prefix is replaced
14797 -- by an explicit dereference, and this test is not needed, but
14798 -- in some cases (notably -gnatc mode and generics) when we do
14799 -- not do full expansion, we need this special test.
14801 if Is_Access_Type (Etype (Prefix (Exp))) then
14802 return;
14804 -- Otherwise go to prefix and keep going
14806 else
14807 Exp := Prefix (Exp);
14808 goto Continue;
14809 end if;
14811 -- All other cases, not a modification
14813 else
14814 return;
14815 end if;
14817 -- Now look for entity being referenced
14819 if Present (Ent) then
14820 if Is_Object (Ent) then
14821 if Comes_From_Source (Exp)
14822 or else Modification_Comes_From_Source
14823 then
14824 -- Give warning if pragma unmodified given and we are
14825 -- sure this is a modification.
14827 if Has_Pragma_Unmodified (Ent) and then Sure then
14828 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
14829 end if;
14831 Set_Never_Set_In_Source (Ent, False);
14832 end if;
14834 Set_Is_True_Constant (Ent, False);
14835 Set_Current_Value (Ent, Empty);
14836 Set_Is_Known_Null (Ent, False);
14838 if not Can_Never_Be_Null (Ent) then
14839 Set_Is_Known_Non_Null (Ent, False);
14840 end if;
14842 -- Follow renaming chain
14844 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
14845 and then Present (Renamed_Object (Ent))
14846 then
14847 Exp := Renamed_Object (Ent);
14849 -- If the entity is the loop variable in an iteration over
14850 -- a container, retrieve container expression to indicate
14851 -- possible modificastion.
14853 if Present (Related_Expression (Ent))
14854 and then Nkind (Parent (Related_Expression (Ent))) =
14855 N_Iterator_Specification
14856 then
14857 Exp := Original_Node (Related_Expression (Ent));
14858 end if;
14860 goto Continue;
14862 -- The expression may be the renaming of a subcomponent of an
14863 -- array or container. The assignment to the subcomponent is
14864 -- a modification of the container.
14866 elsif Comes_From_Source (Original_Node (Exp))
14867 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
14868 N_Indexed_Component)
14869 then
14870 Exp := Prefix (Original_Node (Exp));
14871 goto Continue;
14872 end if;
14874 -- Generate a reference only if the assignment comes from
14875 -- source. This excludes, for example, calls to a dispatching
14876 -- assignment operation when the left-hand side is tagged. In
14877 -- GNATprove mode, we need those references also on generated
14878 -- code, as these are used to compute the local effects of
14879 -- subprograms.
14881 if Modification_Comes_From_Source or GNATprove_Mode then
14882 Generate_Reference (Ent, Exp, 'm');
14884 -- If the target of the assignment is the bound variable
14885 -- in an iterator, indicate that the corresponding array
14886 -- or container is also modified.
14888 if Ada_Version >= Ada_2012
14889 and then Nkind (Parent (Ent)) = N_Iterator_Specification
14890 then
14891 declare
14892 Domain : constant Node_Id := Name (Parent (Ent));
14894 begin
14895 -- TBD : in the full version of the construct, the
14896 -- domain of iteration can be given by an expression.
14898 if Is_Entity_Name (Domain) then
14899 Generate_Reference (Entity (Domain), Exp, 'm');
14900 Set_Is_True_Constant (Entity (Domain), False);
14901 Set_Never_Set_In_Source (Entity (Domain), False);
14902 end if;
14903 end;
14904 end if;
14905 end if;
14907 Check_Nested_Access (Ent);
14908 end if;
14910 Kill_Checks (Ent);
14912 -- If we are sure this is a modification from source, and we know
14913 -- this modifies a constant, then give an appropriate warning.
14915 if Overlays_Constant (Ent)
14916 and then (Modification_Comes_From_Source and Sure)
14917 then
14918 declare
14919 A : constant Node_Id := Address_Clause (Ent);
14920 begin
14921 if Present (A) then
14922 declare
14923 Exp : constant Node_Id := Expression (A);
14924 begin
14925 if Nkind (Exp) = N_Attribute_Reference
14926 and then Attribute_Name (Exp) = Name_Address
14927 and then Is_Entity_Name (Prefix (Exp))
14928 then
14929 Error_Msg_Sloc := Sloc (A);
14930 Error_Msg_NE
14931 ("constant& may be modified via address "
14932 & "clause#??", N, Entity (Prefix (Exp)));
14933 end if;
14934 end;
14935 end if;
14936 end;
14937 end if;
14939 return;
14940 end if;
14942 <<Continue>>
14943 null;
14944 end loop;
14945 end Note_Possible_Modification;
14947 -------------------------
14948 -- Object_Access_Level --
14949 -------------------------
14951 -- Returns the static accessibility level of the view denoted by Obj. Note
14952 -- that the value returned is the result of a call to Scope_Depth. Only
14953 -- scope depths associated with dynamic scopes can actually be returned.
14954 -- Since only relative levels matter for accessibility checking, the fact
14955 -- that the distance between successive levels of accessibility is not
14956 -- always one is immaterial (invariant: if level(E2) is deeper than
14957 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
14959 function Object_Access_Level (Obj : Node_Id) return Uint is
14960 function Is_Interface_Conversion (N : Node_Id) return Boolean;
14961 -- Determine whether N is a construct of the form
14962 -- Some_Type (Operand._tag'Address)
14963 -- This construct appears in the context of dispatching calls.
14965 function Reference_To (Obj : Node_Id) return Node_Id;
14966 -- An explicit dereference is created when removing side-effects from
14967 -- expressions for constraint checking purposes. In this case a local
14968 -- access type is created for it. The correct access level is that of
14969 -- the original source node. We detect this case by noting that the
14970 -- prefix of the dereference is created by an object declaration whose
14971 -- initial expression is a reference.
14973 -----------------------------
14974 -- Is_Interface_Conversion --
14975 -----------------------------
14977 function Is_Interface_Conversion (N : Node_Id) return Boolean is
14978 begin
14979 return Nkind (N) = N_Unchecked_Type_Conversion
14980 and then Nkind (Expression (N)) = N_Attribute_Reference
14981 and then Attribute_Name (Expression (N)) = Name_Address;
14982 end Is_Interface_Conversion;
14984 ------------------
14985 -- Reference_To --
14986 ------------------
14988 function Reference_To (Obj : Node_Id) return Node_Id is
14989 Pref : constant Node_Id := Prefix (Obj);
14990 begin
14991 if Is_Entity_Name (Pref)
14992 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
14993 and then Present (Expression (Parent (Entity (Pref))))
14994 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
14995 then
14996 return (Prefix (Expression (Parent (Entity (Pref)))));
14997 else
14998 return Empty;
14999 end if;
15000 end Reference_To;
15002 -- Local variables
15004 E : Entity_Id;
15006 -- Start of processing for Object_Access_Level
15008 begin
15009 if Nkind (Obj) = N_Defining_Identifier
15010 or else Is_Entity_Name (Obj)
15011 then
15012 if Nkind (Obj) = N_Defining_Identifier then
15013 E := Obj;
15014 else
15015 E := Entity (Obj);
15016 end if;
15018 if Is_Prival (E) then
15019 E := Prival_Link (E);
15020 end if;
15022 -- If E is a type then it denotes a current instance. For this case
15023 -- we add one to the normal accessibility level of the type to ensure
15024 -- that current instances are treated as always being deeper than
15025 -- than the level of any visible named access type (see 3.10.2(21)).
15027 if Is_Type (E) then
15028 return Type_Access_Level (E) + 1;
15030 elsif Present (Renamed_Object (E)) then
15031 return Object_Access_Level (Renamed_Object (E));
15033 -- Similarly, if E is a component of the current instance of a
15034 -- protected type, any instance of it is assumed to be at a deeper
15035 -- level than the type. For a protected object (whose type is an
15036 -- anonymous protected type) its components are at the same level
15037 -- as the type itself.
15039 elsif not Is_Overloadable (E)
15040 and then Ekind (Scope (E)) = E_Protected_Type
15041 and then Comes_From_Source (Scope (E))
15042 then
15043 return Type_Access_Level (Scope (E)) + 1;
15045 else
15046 -- Aliased formals take their access level from the point of call.
15047 -- This is smaller than the level of the subprogram itself.
15049 if Is_Formal (E) and then Is_Aliased (E) then
15050 return Type_Access_Level (Etype (E));
15052 else
15053 return Scope_Depth (Enclosing_Dynamic_Scope (E));
15054 end if;
15055 end if;
15057 elsif Nkind (Obj) = N_Selected_Component then
15058 if Is_Access_Type (Etype (Prefix (Obj))) then
15059 return Type_Access_Level (Etype (Prefix (Obj)));
15060 else
15061 return Object_Access_Level (Prefix (Obj));
15062 end if;
15064 elsif Nkind (Obj) = N_Indexed_Component then
15065 if Is_Access_Type (Etype (Prefix (Obj))) then
15066 return Type_Access_Level (Etype (Prefix (Obj)));
15067 else
15068 return Object_Access_Level (Prefix (Obj));
15069 end if;
15071 elsif Nkind (Obj) = N_Explicit_Dereference then
15073 -- If the prefix is a selected access discriminant then we make a
15074 -- recursive call on the prefix, which will in turn check the level
15075 -- of the prefix object of the selected discriminant.
15077 if Nkind (Prefix (Obj)) = N_Selected_Component
15078 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
15079 and then
15080 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
15081 then
15082 return Object_Access_Level (Prefix (Obj));
15084 -- Detect an interface conversion in the context of a dispatching
15085 -- call. Use the original form of the conversion to find the access
15086 -- level of the operand.
15088 elsif Is_Interface (Etype (Obj))
15089 and then Is_Interface_Conversion (Prefix (Obj))
15090 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
15091 then
15092 return Object_Access_Level (Original_Node (Obj));
15094 elsif not Comes_From_Source (Obj) then
15095 declare
15096 Ref : constant Node_Id := Reference_To (Obj);
15097 begin
15098 if Present (Ref) then
15099 return Object_Access_Level (Ref);
15100 else
15101 return Type_Access_Level (Etype (Prefix (Obj)));
15102 end if;
15103 end;
15105 else
15106 return Type_Access_Level (Etype (Prefix (Obj)));
15107 end if;
15109 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
15110 return Object_Access_Level (Expression (Obj));
15112 elsif Nkind (Obj) = N_Function_Call then
15114 -- Function results are objects, so we get either the access level of
15115 -- the function or, in the case of an indirect call, the level of the
15116 -- access-to-subprogram type. (This code is used for Ada 95, but it
15117 -- looks wrong, because it seems that we should be checking the level
15118 -- of the call itself, even for Ada 95. However, using the Ada 2005
15119 -- version of the code causes regressions in several tests that are
15120 -- compiled with -gnat95. ???)
15122 if Ada_Version < Ada_2005 then
15123 if Is_Entity_Name (Name (Obj)) then
15124 return Subprogram_Access_Level (Entity (Name (Obj)));
15125 else
15126 return Type_Access_Level (Etype (Prefix (Name (Obj))));
15127 end if;
15129 -- For Ada 2005, the level of the result object of a function call is
15130 -- defined to be the level of the call's innermost enclosing master.
15131 -- We determine that by querying the depth of the innermost enclosing
15132 -- dynamic scope.
15134 else
15135 Return_Master_Scope_Depth_Of_Call : declare
15137 function Innermost_Master_Scope_Depth
15138 (N : Node_Id) return Uint;
15139 -- Returns the scope depth of the given node's innermost
15140 -- enclosing dynamic scope (effectively the accessibility
15141 -- level of the innermost enclosing master).
15143 ----------------------------------
15144 -- Innermost_Master_Scope_Depth --
15145 ----------------------------------
15147 function Innermost_Master_Scope_Depth
15148 (N : Node_Id) return Uint
15150 Node_Par : Node_Id := Parent (N);
15152 begin
15153 -- Locate the nearest enclosing node (by traversing Parents)
15154 -- that Defining_Entity can be applied to, and return the
15155 -- depth of that entity's nearest enclosing dynamic scope.
15157 while Present (Node_Par) loop
15158 case Nkind (Node_Par) is
15159 when N_Component_Declaration |
15160 N_Entry_Declaration |
15161 N_Formal_Object_Declaration |
15162 N_Formal_Type_Declaration |
15163 N_Full_Type_Declaration |
15164 N_Incomplete_Type_Declaration |
15165 N_Loop_Parameter_Specification |
15166 N_Object_Declaration |
15167 N_Protected_Type_Declaration |
15168 N_Private_Extension_Declaration |
15169 N_Private_Type_Declaration |
15170 N_Subtype_Declaration |
15171 N_Function_Specification |
15172 N_Procedure_Specification |
15173 N_Task_Type_Declaration |
15174 N_Body_Stub |
15175 N_Generic_Instantiation |
15176 N_Proper_Body |
15177 N_Implicit_Label_Declaration |
15178 N_Package_Declaration |
15179 N_Single_Task_Declaration |
15180 N_Subprogram_Declaration |
15181 N_Generic_Declaration |
15182 N_Renaming_Declaration |
15183 N_Block_Statement |
15184 N_Formal_Subprogram_Declaration |
15185 N_Abstract_Subprogram_Declaration |
15186 N_Entry_Body |
15187 N_Exception_Declaration |
15188 N_Formal_Package_Declaration |
15189 N_Number_Declaration |
15190 N_Package_Specification |
15191 N_Parameter_Specification |
15192 N_Single_Protected_Declaration |
15193 N_Subunit =>
15195 return Scope_Depth
15196 (Nearest_Dynamic_Scope
15197 (Defining_Entity (Node_Par)));
15199 when others =>
15200 null;
15201 end case;
15203 Node_Par := Parent (Node_Par);
15204 end loop;
15206 pragma Assert (False);
15208 -- Should never reach the following return
15210 return Scope_Depth (Current_Scope) + 1;
15211 end Innermost_Master_Scope_Depth;
15213 -- Start of processing for Return_Master_Scope_Depth_Of_Call
15215 begin
15216 return Innermost_Master_Scope_Depth (Obj);
15217 end Return_Master_Scope_Depth_Of_Call;
15218 end if;
15220 -- For convenience we handle qualified expressions, even though they
15221 -- aren't technically object names.
15223 elsif Nkind (Obj) = N_Qualified_Expression then
15224 return Object_Access_Level (Expression (Obj));
15226 -- Ditto for aggregates. They have the level of the temporary that
15227 -- will hold their value.
15229 elsif Nkind (Obj) = N_Aggregate then
15230 return Object_Access_Level (Current_Scope);
15232 -- Otherwise return the scope level of Standard. (If there are cases
15233 -- that fall through to this point they will be treated as having
15234 -- global accessibility for now. ???)
15236 else
15237 return Scope_Depth (Standard_Standard);
15238 end if;
15239 end Object_Access_Level;
15241 --------------------------
15242 -- Original_Aspect_Name --
15243 --------------------------
15245 function Original_Aspect_Name (N : Node_Id) return Name_Id is
15246 Pras : Node_Id;
15247 Name : Name_Id;
15249 begin
15250 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
15251 Pras := N;
15253 if Is_Rewrite_Substitution (Pras)
15254 and then Nkind (Original_Node (Pras)) = N_Pragma
15255 then
15256 Pras := Original_Node (Pras);
15257 end if;
15259 -- Case where we came from aspect specication
15261 if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
15262 Pras := Corresponding_Aspect (Pras);
15263 end if;
15265 -- Get name from aspect or pragma
15267 if Nkind (Pras) = N_Pragma then
15268 Name := Pragma_Name (Pras);
15269 else
15270 Name := Chars (Identifier (Pras));
15271 end if;
15273 -- Deal with 'Class
15275 if Class_Present (Pras) then
15276 case Name is
15278 -- Names that need converting to special _xxx form
15280 when Name_Pre |
15281 Name_Pre_Class =>
15282 Name := Name_uPre;
15284 when Name_Post |
15285 Name_Post_Class =>
15286 Name := Name_uPost;
15288 when Name_Invariant =>
15289 Name := Name_uInvariant;
15291 when Name_Type_Invariant |
15292 Name_Type_Invariant_Class =>
15293 Name := Name_uType_Invariant;
15295 -- Nothing to do for other cases (e.g. a Check that derived
15296 -- from Pre_Class and has the flag set). Also we do nothing
15297 -- if the name is already in special _xxx form.
15299 when others =>
15300 null;
15301 end case;
15302 end if;
15304 return Name;
15305 end Original_Aspect_Name;
15307 --------------------------------------
15308 -- Original_Corresponding_Operation --
15309 --------------------------------------
15311 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
15313 Typ : constant Entity_Id := Find_Dispatching_Type (S);
15315 begin
15316 -- If S is an inherited primitive S2 the original corresponding
15317 -- operation of S is the original corresponding operation of S2
15319 if Present (Alias (S))
15320 and then Find_Dispatching_Type (Alias (S)) /= Typ
15321 then
15322 return Original_Corresponding_Operation (Alias (S));
15324 -- If S overrides an inherited subprogram S2 the original corresponding
15325 -- operation of S is the original corresponding operation of S2
15327 elsif Present (Overridden_Operation (S)) then
15328 return Original_Corresponding_Operation (Overridden_Operation (S));
15330 -- otherwise it is S itself
15332 else
15333 return S;
15334 end if;
15335 end Original_Corresponding_Operation;
15337 ----------------------------------
15338 -- Predicate_Tests_On_Arguments --
15339 ----------------------------------
15341 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
15342 begin
15343 -- Always test predicates on indirect call
15345 if Ekind (Subp) = E_Subprogram_Type then
15346 return True;
15348 -- Do not test predicates on call to generated default Finalize, since
15349 -- we are not interested in whether something we are finalizing (and
15350 -- typically destroying) satisfies its predicates.
15352 elsif Chars (Subp) = Name_Finalize
15353 and then not Comes_From_Source (Subp)
15354 then
15355 return False;
15357 -- Do not test predicates on any internally generated routines
15359 elsif Is_Internal_Name (Chars (Subp)) then
15360 return False;
15362 -- Do not test predicates on call to Init_Proc, since if needed the
15363 -- predicate test will occur at some other point.
15365 elsif Is_Init_Proc (Subp) then
15366 return False;
15368 -- Do not test predicates on call to predicate function, since this
15369 -- would cause infinite recursion.
15371 elsif Ekind (Subp) = E_Function
15372 and then (Is_Predicate_Function (Subp)
15373 or else
15374 Is_Predicate_Function_M (Subp))
15375 then
15376 return False;
15378 -- For now, no other exceptions
15380 else
15381 return True;
15382 end if;
15383 end Predicate_Tests_On_Arguments;
15385 -----------------------
15386 -- Private_Component --
15387 -----------------------
15389 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
15390 Ancestor : constant Entity_Id := Base_Type (Type_Id);
15392 function Trace_Components
15393 (T : Entity_Id;
15394 Check : Boolean) return Entity_Id;
15395 -- Recursive function that does the work, and checks against circular
15396 -- definition for each subcomponent type.
15398 ----------------------
15399 -- Trace_Components --
15400 ----------------------
15402 function Trace_Components
15403 (T : Entity_Id;
15404 Check : Boolean) return Entity_Id
15406 Btype : constant Entity_Id := Base_Type (T);
15407 Component : Entity_Id;
15408 P : Entity_Id;
15409 Candidate : Entity_Id := Empty;
15411 begin
15412 if Check and then Btype = Ancestor then
15413 Error_Msg_N ("circular type definition", Type_Id);
15414 return Any_Type;
15415 end if;
15417 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
15418 if Present (Full_View (Btype))
15419 and then Is_Record_Type (Full_View (Btype))
15420 and then not Is_Frozen (Btype)
15421 then
15422 -- To indicate that the ancestor depends on a private type, the
15423 -- current Btype is sufficient. However, to check for circular
15424 -- definition we must recurse on the full view.
15426 Candidate := Trace_Components (Full_View (Btype), True);
15428 if Candidate = Any_Type then
15429 return Any_Type;
15430 else
15431 return Btype;
15432 end if;
15434 else
15435 return Btype;
15436 end if;
15438 elsif Is_Array_Type (Btype) then
15439 return Trace_Components (Component_Type (Btype), True);
15441 elsif Is_Record_Type (Btype) then
15442 Component := First_Entity (Btype);
15443 while Present (Component)
15444 and then Comes_From_Source (Component)
15445 loop
15446 -- Skip anonymous types generated by constrained components
15448 if not Is_Type (Component) then
15449 P := Trace_Components (Etype (Component), True);
15451 if Present (P) then
15452 if P = Any_Type then
15453 return P;
15454 else
15455 Candidate := P;
15456 end if;
15457 end if;
15458 end if;
15460 Next_Entity (Component);
15461 end loop;
15463 return Candidate;
15465 else
15466 return Empty;
15467 end if;
15468 end Trace_Components;
15470 -- Start of processing for Private_Component
15472 begin
15473 return Trace_Components (Type_Id, False);
15474 end Private_Component;
15476 ---------------------------
15477 -- Primitive_Names_Match --
15478 ---------------------------
15480 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
15482 function Non_Internal_Name (E : Entity_Id) return Name_Id;
15483 -- Given an internal name, returns the corresponding non-internal name
15485 ------------------------
15486 -- Non_Internal_Name --
15487 ------------------------
15489 function Non_Internal_Name (E : Entity_Id) return Name_Id is
15490 begin
15491 Get_Name_String (Chars (E));
15492 Name_Len := Name_Len - 1;
15493 return Name_Find;
15494 end Non_Internal_Name;
15496 -- Start of processing for Primitive_Names_Match
15498 begin
15499 pragma Assert (Present (E1) and then Present (E2));
15501 return Chars (E1) = Chars (E2)
15502 or else
15503 (not Is_Internal_Name (Chars (E1))
15504 and then Is_Internal_Name (Chars (E2))
15505 and then Non_Internal_Name (E2) = Chars (E1))
15506 or else
15507 (not Is_Internal_Name (Chars (E2))
15508 and then Is_Internal_Name (Chars (E1))
15509 and then Non_Internal_Name (E1) = Chars (E2))
15510 or else
15511 (Is_Predefined_Dispatching_Operation (E1)
15512 and then Is_Predefined_Dispatching_Operation (E2)
15513 and then Same_TSS (E1, E2))
15514 or else
15515 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
15516 end Primitive_Names_Match;
15518 -----------------------
15519 -- Process_End_Label --
15520 -----------------------
15522 procedure Process_End_Label
15523 (N : Node_Id;
15524 Typ : Character;
15525 Ent : Entity_Id)
15527 Loc : Source_Ptr;
15528 Nam : Node_Id;
15529 Scop : Entity_Id;
15531 Label_Ref : Boolean;
15532 -- Set True if reference to end label itself is required
15534 Endl : Node_Id;
15535 -- Gets set to the operator symbol or identifier that references the
15536 -- entity Ent. For the child unit case, this is the identifier from the
15537 -- designator. For other cases, this is simply Endl.
15539 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
15540 -- N is an identifier node that appears as a parent unit reference in
15541 -- the case where Ent is a child unit. This procedure generates an
15542 -- appropriate cross-reference entry. E is the corresponding entity.
15544 -------------------------
15545 -- Generate_Parent_Ref --
15546 -------------------------
15548 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
15549 begin
15550 -- If names do not match, something weird, skip reference
15552 if Chars (E) = Chars (N) then
15554 -- Generate the reference. We do NOT consider this as a reference
15555 -- for unreferenced symbol purposes.
15557 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
15559 if Style_Check then
15560 Style.Check_Identifier (N, E);
15561 end if;
15562 end if;
15563 end Generate_Parent_Ref;
15565 -- Start of processing for Process_End_Label
15567 begin
15568 -- If no node, ignore. This happens in some error situations, and
15569 -- also for some internally generated structures where no end label
15570 -- references are required in any case.
15572 if No (N) then
15573 return;
15574 end if;
15576 -- Nothing to do if no End_Label, happens for internally generated
15577 -- constructs where we don't want an end label reference anyway. Also
15578 -- nothing to do if Endl is a string literal, which means there was
15579 -- some prior error (bad operator symbol)
15581 Endl := End_Label (N);
15583 if No (Endl) or else Nkind (Endl) = N_String_Literal then
15584 return;
15585 end if;
15587 -- Reference node is not in extended main source unit
15589 if not In_Extended_Main_Source_Unit (N) then
15591 -- Generally we do not collect references except for the extended
15592 -- main source unit. The one exception is the 'e' entry for a
15593 -- package spec, where it is useful for a client to have the
15594 -- ending information to define scopes.
15596 if Typ /= 'e' then
15597 return;
15599 else
15600 Label_Ref := False;
15602 -- For this case, we can ignore any parent references, but we
15603 -- need the package name itself for the 'e' entry.
15605 if Nkind (Endl) = N_Designator then
15606 Endl := Identifier (Endl);
15607 end if;
15608 end if;
15610 -- Reference is in extended main source unit
15612 else
15613 Label_Ref := True;
15615 -- For designator, generate references for the parent entries
15617 if Nkind (Endl) = N_Designator then
15619 -- Generate references for the prefix if the END line comes from
15620 -- source (otherwise we do not need these references) We climb the
15621 -- scope stack to find the expected entities.
15623 if Comes_From_Source (Endl) then
15624 Nam := Name (Endl);
15625 Scop := Current_Scope;
15626 while Nkind (Nam) = N_Selected_Component loop
15627 Scop := Scope (Scop);
15628 exit when No (Scop);
15629 Generate_Parent_Ref (Selector_Name (Nam), Scop);
15630 Nam := Prefix (Nam);
15631 end loop;
15633 if Present (Scop) then
15634 Generate_Parent_Ref (Nam, Scope (Scop));
15635 end if;
15636 end if;
15638 Endl := Identifier (Endl);
15639 end if;
15640 end if;
15642 -- If the end label is not for the given entity, then either we have
15643 -- some previous error, or this is a generic instantiation for which
15644 -- we do not need to make a cross-reference in this case anyway. In
15645 -- either case we simply ignore the call.
15647 if Chars (Ent) /= Chars (Endl) then
15648 return;
15649 end if;
15651 -- If label was really there, then generate a normal reference and then
15652 -- adjust the location in the end label to point past the name (which
15653 -- should almost always be the semicolon).
15655 Loc := Sloc (Endl);
15657 if Comes_From_Source (Endl) then
15659 -- If a label reference is required, then do the style check and
15660 -- generate an l-type cross-reference entry for the label
15662 if Label_Ref then
15663 if Style_Check then
15664 Style.Check_Identifier (Endl, Ent);
15665 end if;
15667 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
15668 end if;
15670 -- Set the location to point past the label (normally this will
15671 -- mean the semicolon immediately following the label). This is
15672 -- done for the sake of the 'e' or 't' entry generated below.
15674 Get_Decoded_Name_String (Chars (Endl));
15675 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
15677 else
15678 -- In SPARK mode, no missing label is allowed for packages and
15679 -- subprogram bodies. Detect those cases by testing whether
15680 -- Process_End_Label was called for a body (Typ = 't') or a package.
15682 if Restriction_Check_Required (SPARK_05)
15683 and then (Typ = 't' or else Ekind (Ent) = E_Package)
15684 then
15685 Error_Msg_Node_1 := Endl;
15686 Check_SPARK_05_Restriction
15687 ("`END &` required", Endl, Force => True);
15688 end if;
15689 end if;
15691 -- Now generate the e/t reference
15693 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
15695 -- Restore Sloc, in case modified above, since we have an identifier
15696 -- and the normal Sloc should be left set in the tree.
15698 Set_Sloc (Endl, Loc);
15699 end Process_End_Label;
15701 ----------------
15702 -- Referenced --
15703 ----------------
15705 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
15706 Seen : Boolean := False;
15708 function Is_Reference (N : Node_Id) return Traverse_Result;
15709 -- Determine whether node N denotes a reference to Id. If this is the
15710 -- case, set global flag Seen to True and stop the traversal.
15712 ------------------
15713 -- Is_Reference --
15714 ------------------
15716 function Is_Reference (N : Node_Id) return Traverse_Result is
15717 begin
15718 if Is_Entity_Name (N)
15719 and then Present (Entity (N))
15720 and then Entity (N) = Id
15721 then
15722 Seen := True;
15723 return Abandon;
15724 else
15725 return OK;
15726 end if;
15727 end Is_Reference;
15729 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
15731 -- Start of processing for Referenced
15733 begin
15734 Inspect_Expression (Expr);
15735 return Seen;
15736 end Referenced;
15738 ------------------------------------
15739 -- References_Generic_Formal_Type --
15740 ------------------------------------
15742 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
15744 function Process (N : Node_Id) return Traverse_Result;
15745 -- Process one node in search for generic formal type
15747 -------------
15748 -- Process --
15749 -------------
15751 function Process (N : Node_Id) return Traverse_Result is
15752 begin
15753 if Nkind (N) in N_Has_Entity then
15754 declare
15755 E : constant Entity_Id := Entity (N);
15756 begin
15757 if Present (E) then
15758 if Is_Generic_Type (E) then
15759 return Abandon;
15760 elsif Present (Etype (E))
15761 and then Is_Generic_Type (Etype (E))
15762 then
15763 return Abandon;
15764 end if;
15765 end if;
15766 end;
15767 end if;
15769 return Atree.OK;
15770 end Process;
15772 function Traverse is new Traverse_Func (Process);
15773 -- Traverse tree to look for generic type
15775 begin
15776 if Inside_A_Generic then
15777 return Traverse (N) = Abandon;
15778 else
15779 return False;
15780 end if;
15781 end References_Generic_Formal_Type;
15783 --------------------
15784 -- Remove_Homonym --
15785 --------------------
15787 procedure Remove_Homonym (E : Entity_Id) is
15788 Prev : Entity_Id := Empty;
15789 H : Entity_Id;
15791 begin
15792 if E = Current_Entity (E) then
15793 if Present (Homonym (E)) then
15794 Set_Current_Entity (Homonym (E));
15795 else
15796 Set_Name_Entity_Id (Chars (E), Empty);
15797 end if;
15799 else
15800 H := Current_Entity (E);
15801 while Present (H) and then H /= E loop
15802 Prev := H;
15803 H := Homonym (H);
15804 end loop;
15806 -- If E is not on the homonym chain, nothing to do
15808 if Present (H) then
15809 Set_Homonym (Prev, Homonym (E));
15810 end if;
15811 end if;
15812 end Remove_Homonym;
15814 ---------------------
15815 -- Rep_To_Pos_Flag --
15816 ---------------------
15818 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
15819 begin
15820 return New_Occurrence_Of
15821 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
15822 end Rep_To_Pos_Flag;
15824 --------------------
15825 -- Require_Entity --
15826 --------------------
15828 procedure Require_Entity (N : Node_Id) is
15829 begin
15830 if Is_Entity_Name (N) and then No (Entity (N)) then
15831 if Total_Errors_Detected /= 0 then
15832 Set_Entity (N, Any_Id);
15833 else
15834 raise Program_Error;
15835 end if;
15836 end if;
15837 end Require_Entity;
15839 -------------------------------
15840 -- Requires_State_Refinement --
15841 -------------------------------
15843 function Requires_State_Refinement
15844 (Spec_Id : Entity_Id;
15845 Body_Id : Entity_Id) return Boolean
15847 function Mode_Is_Off (Prag : Node_Id) return Boolean;
15848 -- Given pragma SPARK_Mode, determine whether the mode is Off
15850 -----------------
15851 -- Mode_Is_Off --
15852 -----------------
15854 function Mode_Is_Off (Prag : Node_Id) return Boolean is
15855 Mode : Node_Id;
15857 begin
15858 -- The default SPARK mode is On
15860 if No (Prag) then
15861 return False;
15862 end if;
15864 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
15866 -- Then the pragma lacks an argument, the default mode is On
15868 if No (Mode) then
15869 return False;
15870 else
15871 return Chars (Mode) = Name_Off;
15872 end if;
15873 end Mode_Is_Off;
15875 -- Start of processing for Requires_State_Refinement
15877 begin
15878 -- A package that does not define at least one abstract state cannot
15879 -- possibly require refinement.
15881 if No (Abstract_States (Spec_Id)) then
15882 return False;
15884 -- The package instroduces a single null state which does not merit
15885 -- refinement.
15887 elsif Has_Null_Abstract_State (Spec_Id) then
15888 return False;
15890 -- Check whether the package body is subject to pragma SPARK_Mode. If
15891 -- it is and the mode is Off, the package body is considered to be in
15892 -- regular Ada and does not require refinement.
15894 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
15895 return False;
15897 -- The body's SPARK_Mode may be inherited from a similar pragma that
15898 -- appears in the private declarations of the spec. The pragma we are
15899 -- interested appears as the second entry in SPARK_Pragma.
15901 elsif Present (SPARK_Pragma (Spec_Id))
15902 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
15903 then
15904 return False;
15906 -- The spec defines at least one abstract state and the body has no way
15907 -- of circumventing the refinement.
15909 else
15910 return True;
15911 end if;
15912 end Requires_State_Refinement;
15914 ------------------------------
15915 -- Requires_Transient_Scope --
15916 ------------------------------
15918 -- A transient scope is required when variable-sized temporaries are
15919 -- allocated in the primary or secondary stack, or when finalization
15920 -- actions must be generated before the next instruction.
15922 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
15923 Typ : constant Entity_Id := Underlying_Type (Id);
15925 -- Start of processing for Requires_Transient_Scope
15927 begin
15928 -- This is a private type which is not completed yet. This can only
15929 -- happen in a default expression (of a formal parameter or of a
15930 -- record component). Do not expand transient scope in this case
15932 if No (Typ) then
15933 return False;
15935 -- Do not expand transient scope for non-existent procedure return
15937 elsif Typ = Standard_Void_Type then
15938 return False;
15940 -- Elementary types do not require a transient scope
15942 elsif Is_Elementary_Type (Typ) then
15943 return False;
15945 -- Generally, indefinite subtypes require a transient scope, since the
15946 -- back end cannot generate temporaries, since this is not a valid type
15947 -- for declaring an object. It might be possible to relax this in the
15948 -- future, e.g. by declaring the maximum possible space for the type.
15950 elsif Is_Indefinite_Subtype (Typ) then
15951 return True;
15953 -- Functions returning tagged types may dispatch on result so their
15954 -- returned value is allocated on the secondary stack. Controlled
15955 -- type temporaries need finalization.
15957 elsif Is_Tagged_Type (Typ)
15958 or else Has_Controlled_Component (Typ)
15959 then
15960 return not Is_Value_Type (Typ);
15962 -- Record type
15964 elsif Is_Record_Type (Typ) then
15965 declare
15966 Comp : Entity_Id;
15967 begin
15968 Comp := First_Entity (Typ);
15969 while Present (Comp) loop
15970 if Ekind (Comp) = E_Component
15971 and then Requires_Transient_Scope (Etype (Comp))
15972 then
15973 return True;
15974 else
15975 Next_Entity (Comp);
15976 end if;
15977 end loop;
15978 end;
15980 return False;
15982 -- String literal types never require transient scope
15984 elsif Ekind (Typ) = E_String_Literal_Subtype then
15985 return False;
15987 -- Array type. Note that we already know that this is a constrained
15988 -- array, since unconstrained arrays will fail the indefinite test.
15990 elsif Is_Array_Type (Typ) then
15992 -- If component type requires a transient scope, the array does too
15994 if Requires_Transient_Scope (Component_Type (Typ)) then
15995 return True;
15997 -- Otherwise, we only need a transient scope if the size depends on
15998 -- the value of one or more discriminants.
16000 else
16001 return Size_Depends_On_Discriminant (Typ);
16002 end if;
16004 -- All other cases do not require a transient scope
16006 else
16007 return False;
16008 end if;
16009 end Requires_Transient_Scope;
16011 --------------------------
16012 -- Reset_Analyzed_Flags --
16013 --------------------------
16015 procedure Reset_Analyzed_Flags (N : Node_Id) is
16017 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
16018 -- Function used to reset Analyzed flags in tree. Note that we do
16019 -- not reset Analyzed flags in entities, since there is no need to
16020 -- reanalyze entities, and indeed, it is wrong to do so, since it
16021 -- can result in generating auxiliary stuff more than once.
16023 --------------------
16024 -- Clear_Analyzed --
16025 --------------------
16027 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
16028 begin
16029 if not Has_Extension (N) then
16030 Set_Analyzed (N, False);
16031 end if;
16033 return OK;
16034 end Clear_Analyzed;
16036 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
16038 -- Start of processing for Reset_Analyzed_Flags
16040 begin
16041 Reset_Analyzed (N);
16042 end Reset_Analyzed_Flags;
16044 ------------------------
16045 -- Restore_SPARK_Mode --
16046 ------------------------
16048 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
16049 begin
16050 SPARK_Mode := Mode;
16051 end Restore_SPARK_Mode;
16053 --------------------------------
16054 -- Returns_Unconstrained_Type --
16055 --------------------------------
16057 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
16058 begin
16059 return Ekind (Subp) = E_Function
16060 and then not Is_Scalar_Type (Etype (Subp))
16061 and then not Is_Access_Type (Etype (Subp))
16062 and then not Is_Constrained (Etype (Subp));
16063 end Returns_Unconstrained_Type;
16065 ----------------------------
16066 -- Root_Type_Of_Full_View --
16067 ----------------------------
16069 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
16070 Rtyp : constant Entity_Id := Root_Type (T);
16072 begin
16073 -- The root type of the full view may itself be a private type. Keep
16074 -- looking for the ultimate derivation parent.
16076 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
16077 return Root_Type_Of_Full_View (Full_View (Rtyp));
16078 else
16079 return Rtyp;
16080 end if;
16081 end Root_Type_Of_Full_View;
16083 ---------------------------
16084 -- Safe_To_Capture_Value --
16085 ---------------------------
16087 function Safe_To_Capture_Value
16088 (N : Node_Id;
16089 Ent : Entity_Id;
16090 Cond : Boolean := False) return Boolean
16092 begin
16093 -- The only entities for which we track constant values are variables
16094 -- which are not renamings, constants, out parameters, and in out
16095 -- parameters, so check if we have this case.
16097 -- Note: it may seem odd to track constant values for constants, but in
16098 -- fact this routine is used for other purposes than simply capturing
16099 -- the value. In particular, the setting of Known[_Non]_Null.
16101 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
16102 or else
16103 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
16104 then
16105 null;
16107 -- For conditionals, we also allow loop parameters and all formals,
16108 -- including in parameters.
16110 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
16111 null;
16113 -- For all other cases, not just unsafe, but impossible to capture
16114 -- Current_Value, since the above are the only entities which have
16115 -- Current_Value fields.
16117 else
16118 return False;
16119 end if;
16121 -- Skip if volatile or aliased, since funny things might be going on in
16122 -- these cases which we cannot necessarily track. Also skip any variable
16123 -- for which an address clause is given, or whose address is taken. Also
16124 -- never capture value of library level variables (an attempt to do so
16125 -- can occur in the case of package elaboration code).
16127 if Treat_As_Volatile (Ent)
16128 or else Is_Aliased (Ent)
16129 or else Present (Address_Clause (Ent))
16130 or else Address_Taken (Ent)
16131 or else (Is_Library_Level_Entity (Ent)
16132 and then Ekind (Ent) = E_Variable)
16133 then
16134 return False;
16135 end if;
16137 -- OK, all above conditions are met. We also require that the scope of
16138 -- the reference be the same as the scope of the entity, not counting
16139 -- packages and blocks and loops.
16141 declare
16142 E_Scope : constant Entity_Id := Scope (Ent);
16143 R_Scope : Entity_Id;
16145 begin
16146 R_Scope := Current_Scope;
16147 while R_Scope /= Standard_Standard loop
16148 exit when R_Scope = E_Scope;
16150 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
16151 return False;
16152 else
16153 R_Scope := Scope (R_Scope);
16154 end if;
16155 end loop;
16156 end;
16158 -- We also require that the reference does not appear in a context
16159 -- where it is not sure to be executed (i.e. a conditional context
16160 -- or an exception handler). We skip this if Cond is True, since the
16161 -- capturing of values from conditional tests handles this ok.
16163 if Cond then
16164 return True;
16165 end if;
16167 declare
16168 Desc : Node_Id;
16169 P : Node_Id;
16171 begin
16172 Desc := N;
16174 -- Seems dubious that case expressions are not handled here ???
16176 P := Parent (N);
16177 while Present (P) loop
16178 if Nkind (P) = N_If_Statement
16179 or else Nkind (P) = N_Case_Statement
16180 or else (Nkind (P) in N_Short_Circuit
16181 and then Desc = Right_Opnd (P))
16182 or else (Nkind (P) = N_If_Expression
16183 and then Desc /= First (Expressions (P)))
16184 or else Nkind (P) = N_Exception_Handler
16185 or else Nkind (P) = N_Selective_Accept
16186 or else Nkind (P) = N_Conditional_Entry_Call
16187 or else Nkind (P) = N_Timed_Entry_Call
16188 or else Nkind (P) = N_Asynchronous_Select
16189 then
16190 return False;
16192 else
16193 Desc := P;
16194 P := Parent (P);
16196 -- A special Ada 2012 case: the original node may be part
16197 -- of the else_actions of a conditional expression, in which
16198 -- case it might not have been expanded yet, and appears in
16199 -- a non-syntactic list of actions. In that case it is clearly
16200 -- not safe to save a value.
16202 if No (P)
16203 and then Is_List_Member (Desc)
16204 and then No (Parent (List_Containing (Desc)))
16205 then
16206 return False;
16207 end if;
16208 end if;
16209 end loop;
16210 end;
16212 -- OK, looks safe to set value
16214 return True;
16215 end Safe_To_Capture_Value;
16217 ---------------
16218 -- Same_Name --
16219 ---------------
16221 function Same_Name (N1, N2 : Node_Id) return Boolean is
16222 K1 : constant Node_Kind := Nkind (N1);
16223 K2 : constant Node_Kind := Nkind (N2);
16225 begin
16226 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
16227 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
16228 then
16229 return Chars (N1) = Chars (N2);
16231 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
16232 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
16233 then
16234 return Same_Name (Selector_Name (N1), Selector_Name (N2))
16235 and then Same_Name (Prefix (N1), Prefix (N2));
16237 else
16238 return False;
16239 end if;
16240 end Same_Name;
16242 -----------------
16243 -- Same_Object --
16244 -----------------
16246 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
16247 N1 : constant Node_Id := Original_Node (Node1);
16248 N2 : constant Node_Id := Original_Node (Node2);
16249 -- We do the tests on original nodes, since we are most interested
16250 -- in the original source, not any expansion that got in the way.
16252 K1 : constant Node_Kind := Nkind (N1);
16253 K2 : constant Node_Kind := Nkind (N2);
16255 begin
16256 -- First case, both are entities with same entity
16258 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
16259 declare
16260 EN1 : constant Entity_Id := Entity (N1);
16261 EN2 : constant Entity_Id := Entity (N2);
16262 begin
16263 if Present (EN1) and then Present (EN2)
16264 and then (Ekind_In (EN1, E_Variable, E_Constant)
16265 or else Is_Formal (EN1))
16266 and then EN1 = EN2
16267 then
16268 return True;
16269 end if;
16270 end;
16271 end if;
16273 -- Second case, selected component with same selector, same record
16275 if K1 = N_Selected_Component
16276 and then K2 = N_Selected_Component
16277 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
16278 then
16279 return Same_Object (Prefix (N1), Prefix (N2));
16281 -- Third case, indexed component with same subscripts, same array
16283 elsif K1 = N_Indexed_Component
16284 and then K2 = N_Indexed_Component
16285 and then Same_Object (Prefix (N1), Prefix (N2))
16286 then
16287 declare
16288 E1, E2 : Node_Id;
16289 begin
16290 E1 := First (Expressions (N1));
16291 E2 := First (Expressions (N2));
16292 while Present (E1) loop
16293 if not Same_Value (E1, E2) then
16294 return False;
16295 else
16296 Next (E1);
16297 Next (E2);
16298 end if;
16299 end loop;
16301 return True;
16302 end;
16304 -- Fourth case, slice of same array with same bounds
16306 elsif K1 = N_Slice
16307 and then K2 = N_Slice
16308 and then Nkind (Discrete_Range (N1)) = N_Range
16309 and then Nkind (Discrete_Range (N2)) = N_Range
16310 and then Same_Value (Low_Bound (Discrete_Range (N1)),
16311 Low_Bound (Discrete_Range (N2)))
16312 and then Same_Value (High_Bound (Discrete_Range (N1)),
16313 High_Bound (Discrete_Range (N2)))
16314 then
16315 return Same_Name (Prefix (N1), Prefix (N2));
16317 -- All other cases, not clearly the same object
16319 else
16320 return False;
16321 end if;
16322 end Same_Object;
16324 ---------------
16325 -- Same_Type --
16326 ---------------
16328 function Same_Type (T1, T2 : Entity_Id) return Boolean is
16329 begin
16330 if T1 = T2 then
16331 return True;
16333 elsif not Is_Constrained (T1)
16334 and then not Is_Constrained (T2)
16335 and then Base_Type (T1) = Base_Type (T2)
16336 then
16337 return True;
16339 -- For now don't bother with case of identical constraints, to be
16340 -- fiddled with later on perhaps (this is only used for optimization
16341 -- purposes, so it is not critical to do a best possible job)
16343 else
16344 return False;
16345 end if;
16346 end Same_Type;
16348 ----------------
16349 -- Same_Value --
16350 ----------------
16352 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
16353 begin
16354 if Compile_Time_Known_Value (Node1)
16355 and then Compile_Time_Known_Value (Node2)
16356 and then Expr_Value (Node1) = Expr_Value (Node2)
16357 then
16358 return True;
16359 elsif Same_Object (Node1, Node2) then
16360 return True;
16361 else
16362 return False;
16363 end if;
16364 end Same_Value;
16366 -----------------------------
16367 -- Save_SPARK_Mode_And_Set --
16368 -----------------------------
16370 procedure Save_SPARK_Mode_And_Set
16371 (Context : Entity_Id;
16372 Mode : out SPARK_Mode_Type)
16374 begin
16375 -- Save the current mode in effect
16377 Mode := SPARK_Mode;
16379 -- Do not consider illegal or partially decorated constructs
16381 if Ekind (Context) = E_Void or else Error_Posted (Context) then
16382 null;
16384 elsif Present (SPARK_Pragma (Context)) then
16385 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
16386 end if;
16387 end Save_SPARK_Mode_And_Set;
16389 -------------------------
16390 -- Scalar_Part_Present --
16391 -------------------------
16393 function Scalar_Part_Present (T : Entity_Id) return Boolean is
16394 C : Entity_Id;
16396 begin
16397 if Is_Scalar_Type (T) then
16398 return True;
16400 elsif Is_Array_Type (T) then
16401 return Scalar_Part_Present (Component_Type (T));
16403 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
16404 C := First_Component_Or_Discriminant (T);
16405 while Present (C) loop
16406 if Scalar_Part_Present (Etype (C)) then
16407 return True;
16408 else
16409 Next_Component_Or_Discriminant (C);
16410 end if;
16411 end loop;
16412 end if;
16414 return False;
16415 end Scalar_Part_Present;
16417 ------------------------
16418 -- Scope_Is_Transient --
16419 ------------------------
16421 function Scope_Is_Transient return Boolean is
16422 begin
16423 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
16424 end Scope_Is_Transient;
16426 ------------------
16427 -- Scope_Within --
16428 ------------------
16430 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
16431 Scop : Entity_Id;
16433 begin
16434 Scop := Scope1;
16435 while Scop /= Standard_Standard loop
16436 Scop := Scope (Scop);
16438 if Scop = Scope2 then
16439 return True;
16440 end if;
16441 end loop;
16443 return False;
16444 end Scope_Within;
16446 --------------------------
16447 -- Scope_Within_Or_Same --
16448 --------------------------
16450 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
16451 Scop : Entity_Id;
16453 begin
16454 Scop := Scope1;
16455 while Scop /= Standard_Standard loop
16456 if Scop = Scope2 then
16457 return True;
16458 else
16459 Scop := Scope (Scop);
16460 end if;
16461 end loop;
16463 return False;
16464 end Scope_Within_Or_Same;
16466 --------------------
16467 -- Set_Convention --
16468 --------------------
16470 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
16471 begin
16472 Basic_Set_Convention (E, Val);
16474 if Is_Type (E)
16475 and then Is_Access_Subprogram_Type (Base_Type (E))
16476 and then Has_Foreign_Convention (E)
16477 then
16478 Set_Can_Use_Internal_Rep (E, False);
16479 end if;
16481 -- If E is an object or component, and the type of E is an anonymous
16482 -- access type with no convention set, then also set the convention of
16483 -- the anonymous access type. We do not do this for anonymous protected
16484 -- types, since protected types always have the default convention.
16486 if Present (Etype (E))
16487 and then (Is_Object (E)
16488 or else Ekind (E) = E_Component
16490 -- Allow E_Void (happens for pragma Convention appearing
16491 -- in the middle of a record applying to a component)
16493 or else Ekind (E) = E_Void)
16494 then
16495 declare
16496 Typ : constant Entity_Id := Etype (E);
16498 begin
16499 if Ekind_In (Typ, E_Anonymous_Access_Type,
16500 E_Anonymous_Access_Subprogram_Type)
16501 and then not Has_Convention_Pragma (Typ)
16502 then
16503 Basic_Set_Convention (Typ, Val);
16504 Set_Has_Convention_Pragma (Typ);
16506 -- And for the access subprogram type, deal similarly with the
16507 -- designated E_Subprogram_Type if it is also internal (which
16508 -- it always is?)
16510 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
16511 declare
16512 Dtype : constant Entity_Id := Designated_Type (Typ);
16513 begin
16514 if Ekind (Dtype) = E_Subprogram_Type
16515 and then Is_Itype (Dtype)
16516 and then not Has_Convention_Pragma (Dtype)
16517 then
16518 Basic_Set_Convention (Dtype, Val);
16519 Set_Has_Convention_Pragma (Dtype);
16520 end if;
16521 end;
16522 end if;
16523 end if;
16524 end;
16525 end if;
16526 end Set_Convention;
16528 ------------------------
16529 -- Set_Current_Entity --
16530 ------------------------
16532 -- The given entity is to be set as the currently visible definition of its
16533 -- associated name (i.e. the Node_Id associated with its name). All we have
16534 -- to do is to get the name from the identifier, and then set the
16535 -- associated Node_Id to point to the given entity.
16537 procedure Set_Current_Entity (E : Entity_Id) is
16538 begin
16539 Set_Name_Entity_Id (Chars (E), E);
16540 end Set_Current_Entity;
16542 ---------------------------
16543 -- Set_Debug_Info_Needed --
16544 ---------------------------
16546 procedure Set_Debug_Info_Needed (T : Entity_Id) is
16548 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
16549 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
16550 -- Used to set debug info in a related node if not set already
16552 --------------------------------------
16553 -- Set_Debug_Info_Needed_If_Not_Set --
16554 --------------------------------------
16556 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
16557 begin
16558 if Present (E) and then not Needs_Debug_Info (E) then
16559 Set_Debug_Info_Needed (E);
16561 -- For a private type, indicate that the full view also needs
16562 -- debug information.
16564 if Is_Type (E)
16565 and then Is_Private_Type (E)
16566 and then Present (Full_View (E))
16567 then
16568 Set_Debug_Info_Needed (Full_View (E));
16569 end if;
16570 end if;
16571 end Set_Debug_Info_Needed_If_Not_Set;
16573 -- Start of processing for Set_Debug_Info_Needed
16575 begin
16576 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16577 -- indicates that Debug_Info_Needed is never required for the entity.
16578 -- Nothing to do if entity comes from a predefined file. Library files
16579 -- are compiled without debug information, but inlined bodies of these
16580 -- routines may appear in user code, and debug information on them ends
16581 -- up complicating debugging the user code.
16583 if No (T)
16584 or else Debug_Info_Off (T)
16585 then
16586 return;
16588 elsif In_Inlined_Body
16589 and then Is_Predefined_File_Name
16590 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
16591 then
16592 Set_Needs_Debug_Info (T, False);
16593 end if;
16595 -- Set flag in entity itself. Note that we will go through the following
16596 -- circuitry even if the flag is already set on T. That's intentional,
16597 -- it makes sure that the flag will be set in subsidiary entities.
16599 Set_Needs_Debug_Info (T);
16601 -- Set flag on subsidiary entities if not set already
16603 if Is_Object (T) then
16604 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
16606 elsif Is_Type (T) then
16607 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
16609 if Is_Record_Type (T) then
16610 declare
16611 Ent : Entity_Id := First_Entity (T);
16612 begin
16613 while Present (Ent) loop
16614 Set_Debug_Info_Needed_If_Not_Set (Ent);
16615 Next_Entity (Ent);
16616 end loop;
16617 end;
16619 -- For a class wide subtype, we also need debug information
16620 -- for the equivalent type.
16622 if Ekind (T) = E_Class_Wide_Subtype then
16623 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
16624 end if;
16626 elsif Is_Array_Type (T) then
16627 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
16629 declare
16630 Indx : Node_Id := First_Index (T);
16631 begin
16632 while Present (Indx) loop
16633 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
16634 Indx := Next_Index (Indx);
16635 end loop;
16636 end;
16638 -- For a packed array type, we also need debug information for
16639 -- the type used to represent the packed array. Conversely, we
16640 -- also need it for the former if we need it for the latter.
16642 if Is_Packed (T) then
16643 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
16644 end if;
16646 if Is_Packed_Array_Impl_Type (T) then
16647 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
16648 end if;
16650 elsif Is_Access_Type (T) then
16651 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
16653 elsif Is_Private_Type (T) then
16654 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
16656 elsif Is_Protected_Type (T) then
16657 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
16659 elsif Is_Scalar_Type (T) then
16661 -- If the subrange bounds are materialized by dedicated constant
16662 -- objects, also include them in the debug info to make sure the
16663 -- debugger can properly use them.
16665 if Present (Scalar_Range (T))
16666 and then Nkind (Scalar_Range (T)) = N_Range
16667 then
16668 declare
16669 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
16670 High_Bnd : constant Node_Id := Type_High_Bound (T);
16672 begin
16673 if Is_Entity_Name (Low_Bnd) then
16674 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
16675 end if;
16677 if Is_Entity_Name (High_Bnd) then
16678 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
16679 end if;
16680 end;
16681 end if;
16682 end if;
16683 end if;
16684 end Set_Debug_Info_Needed;
16686 ----------------------------
16687 -- Set_Entity_With_Checks --
16688 ----------------------------
16690 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
16691 Val_Actual : Entity_Id;
16692 Nod : Node_Id;
16693 Post_Node : Node_Id;
16695 begin
16696 -- Unconditionally set the entity
16698 Set_Entity (N, Val);
16700 -- The node to post on is the selector in the case of an expanded name,
16701 -- and otherwise the node itself.
16703 if Nkind (N) = N_Expanded_Name then
16704 Post_Node := Selector_Name (N);
16705 else
16706 Post_Node := N;
16707 end if;
16709 -- Check for violation of No_Fixed_IO
16711 if Restriction_Check_Required (No_Fixed_IO)
16712 and then
16713 ((RTU_Loaded (Ada_Text_IO)
16714 and then (Is_RTE (Val, RE_Decimal_IO)
16715 or else
16716 Is_RTE (Val, RE_Fixed_IO)))
16718 or else
16719 (RTU_Loaded (Ada_Wide_Text_IO)
16720 and then (Is_RTE (Val, RO_WT_Decimal_IO)
16721 or else
16722 Is_RTE (Val, RO_WT_Fixed_IO)))
16724 or else
16725 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
16726 and then (Is_RTE (Val, RO_WW_Decimal_IO)
16727 or else
16728 Is_RTE (Val, RO_WW_Fixed_IO))))
16730 -- A special extra check, don't complain about a reference from within
16731 -- the Ada.Interrupts package itself!
16733 and then not In_Same_Extended_Unit (N, Val)
16734 then
16735 Check_Restriction (No_Fixed_IO, Post_Node);
16736 end if;
16738 -- Remaining checks are only done on source nodes. Note that we test
16739 -- for violation of No_Fixed_IO even on non-source nodes, because the
16740 -- cases for checking violations of this restriction are instantiations
16741 -- where the reference in the instance has Comes_From_Source False.
16743 if not Comes_From_Source (N) then
16744 return;
16745 end if;
16747 -- Check for violation of No_Abort_Statements, which is triggered by
16748 -- call to Ada.Task_Identification.Abort_Task.
16750 if Restriction_Check_Required (No_Abort_Statements)
16751 and then (Is_RTE (Val, RE_Abort_Task))
16753 -- A special extra check, don't complain about a reference from within
16754 -- the Ada.Task_Identification package itself!
16756 and then not In_Same_Extended_Unit (N, Val)
16757 then
16758 Check_Restriction (No_Abort_Statements, Post_Node);
16759 end if;
16761 if Val = Standard_Long_Long_Integer then
16762 Check_Restriction (No_Long_Long_Integers, Post_Node);
16763 end if;
16765 -- Check for violation of No_Dynamic_Attachment
16767 if Restriction_Check_Required (No_Dynamic_Attachment)
16768 and then RTU_Loaded (Ada_Interrupts)
16769 and then (Is_RTE (Val, RE_Is_Reserved) or else
16770 Is_RTE (Val, RE_Is_Attached) or else
16771 Is_RTE (Val, RE_Current_Handler) or else
16772 Is_RTE (Val, RE_Attach_Handler) or else
16773 Is_RTE (Val, RE_Exchange_Handler) or else
16774 Is_RTE (Val, RE_Detach_Handler) or else
16775 Is_RTE (Val, RE_Reference))
16777 -- A special extra check, don't complain about a reference from within
16778 -- the Ada.Interrupts package itself!
16780 and then not In_Same_Extended_Unit (N, Val)
16781 then
16782 Check_Restriction (No_Dynamic_Attachment, Post_Node);
16783 end if;
16785 -- Check for No_Implementation_Identifiers
16787 if Restriction_Check_Required (No_Implementation_Identifiers) then
16789 -- We have an implementation defined entity if it is marked as
16790 -- implementation defined, or is defined in a package marked as
16791 -- implementation defined. However, library packages themselves
16792 -- are excluded (we don't want to flag Interfaces itself, just
16793 -- the entities within it).
16795 if (Is_Implementation_Defined (Val)
16796 or else
16797 (Present (Scope (Val))
16798 and then Is_Implementation_Defined (Scope (Val))))
16799 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
16800 and then Is_Library_Level_Entity (Val))
16801 then
16802 Check_Restriction (No_Implementation_Identifiers, Post_Node);
16803 end if;
16804 end if;
16806 -- Do the style check
16808 if Style_Check
16809 and then not Suppress_Style_Checks (Val)
16810 and then not In_Instance
16811 then
16812 if Nkind (N) = N_Identifier then
16813 Nod := N;
16814 elsif Nkind (N) = N_Expanded_Name then
16815 Nod := Selector_Name (N);
16816 else
16817 return;
16818 end if;
16820 -- A special situation arises for derived operations, where we want
16821 -- to do the check against the parent (since the Sloc of the derived
16822 -- operation points to the derived type declaration itself).
16824 Val_Actual := Val;
16825 while not Comes_From_Source (Val_Actual)
16826 and then Nkind (Val_Actual) in N_Entity
16827 and then (Ekind (Val_Actual) = E_Enumeration_Literal
16828 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
16829 and then Present (Alias (Val_Actual))
16830 loop
16831 Val_Actual := Alias (Val_Actual);
16832 end loop;
16834 -- Renaming declarations for generic actuals do not come from source,
16835 -- and have a different name from that of the entity they rename, so
16836 -- there is no style check to perform here.
16838 if Chars (Nod) = Chars (Val_Actual) then
16839 Style.Check_Identifier (Nod, Val_Actual);
16840 end if;
16841 end if;
16843 Set_Entity (N, Val);
16844 end Set_Entity_With_Checks;
16846 ------------------------
16847 -- Set_Name_Entity_Id --
16848 ------------------------
16850 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
16851 begin
16852 Set_Name_Table_Info (Id, Int (Val));
16853 end Set_Name_Entity_Id;
16855 ---------------------
16856 -- Set_Next_Actual --
16857 ---------------------
16859 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
16860 begin
16861 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
16862 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
16863 end if;
16864 end Set_Next_Actual;
16866 ----------------------------------
16867 -- Set_Optimize_Alignment_Flags --
16868 ----------------------------------
16870 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
16871 begin
16872 if Optimize_Alignment = 'S' then
16873 Set_Optimize_Alignment_Space (E);
16874 elsif Optimize_Alignment = 'T' then
16875 Set_Optimize_Alignment_Time (E);
16876 end if;
16877 end Set_Optimize_Alignment_Flags;
16879 -----------------------
16880 -- Set_Public_Status --
16881 -----------------------
16883 procedure Set_Public_Status (Id : Entity_Id) is
16884 S : constant Entity_Id := Current_Scope;
16886 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
16887 -- Determines if E is defined within handled statement sequence or
16888 -- an if statement, returns True if so, False otherwise.
16890 ----------------------
16891 -- Within_HSS_Or_If --
16892 ----------------------
16894 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
16895 N : Node_Id;
16896 begin
16897 N := Declaration_Node (E);
16898 loop
16899 N := Parent (N);
16901 if No (N) then
16902 return False;
16904 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
16905 N_If_Statement)
16906 then
16907 return True;
16908 end if;
16909 end loop;
16910 end Within_HSS_Or_If;
16912 -- Start of processing for Set_Public_Status
16914 begin
16915 -- Everything in the scope of Standard is public
16917 if S = Standard_Standard then
16918 Set_Is_Public (Id);
16920 -- Entity is definitely not public if enclosing scope is not public
16922 elsif not Is_Public (S) then
16923 return;
16925 -- An object or function declaration that occurs in a handled sequence
16926 -- of statements or within an if statement is the declaration for a
16927 -- temporary object or local subprogram generated by the expander. It
16928 -- never needs to be made public and furthermore, making it public can
16929 -- cause back end problems.
16931 elsif Nkind_In (Parent (Id), N_Object_Declaration,
16932 N_Function_Specification)
16933 and then Within_HSS_Or_If (Id)
16934 then
16935 return;
16937 -- Entities in public packages or records are public
16939 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
16940 Set_Is_Public (Id);
16942 -- The bounds of an entry family declaration can generate object
16943 -- declarations that are visible to the back-end, e.g. in the
16944 -- the declaration of a composite type that contains tasks.
16946 elsif Is_Concurrent_Type (S)
16947 and then not Has_Completion (S)
16948 and then Nkind (Parent (Id)) = N_Object_Declaration
16949 then
16950 Set_Is_Public (Id);
16951 end if;
16952 end Set_Public_Status;
16954 -----------------------------
16955 -- Set_Referenced_Modified --
16956 -----------------------------
16958 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
16959 Pref : Node_Id;
16961 begin
16962 -- Deal with indexed or selected component where prefix is modified
16964 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
16965 Pref := Prefix (N);
16967 -- If prefix is access type, then it is the designated object that is
16968 -- being modified, which means we have no entity to set the flag on.
16970 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
16971 return;
16973 -- Otherwise chase the prefix
16975 else
16976 Set_Referenced_Modified (Pref, Out_Param);
16977 end if;
16979 -- Otherwise see if we have an entity name (only other case to process)
16981 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16982 Set_Referenced_As_LHS (Entity (N), not Out_Param);
16983 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
16984 end if;
16985 end Set_Referenced_Modified;
16987 ----------------------------
16988 -- Set_Scope_Is_Transient --
16989 ----------------------------
16991 procedure Set_Scope_Is_Transient (V : Boolean := True) is
16992 begin
16993 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
16994 end Set_Scope_Is_Transient;
16996 -------------------
16997 -- Set_Size_Info --
16998 -------------------
17000 procedure Set_Size_Info (T1, T2 : Entity_Id) is
17001 begin
17002 -- We copy Esize, but not RM_Size, since in general RM_Size is
17003 -- subtype specific and does not get inherited by all subtypes.
17005 Set_Esize (T1, Esize (T2));
17006 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
17008 if Is_Discrete_Or_Fixed_Point_Type (T1)
17009 and then
17010 Is_Discrete_Or_Fixed_Point_Type (T2)
17011 then
17012 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
17013 end if;
17015 Set_Alignment (T1, Alignment (T2));
17016 end Set_Size_Info;
17018 --------------------
17019 -- Static_Boolean --
17020 --------------------
17022 function Static_Boolean (N : Node_Id) return Uint is
17023 begin
17024 Analyze_And_Resolve (N, Standard_Boolean);
17026 if N = Error
17027 or else Error_Posted (N)
17028 or else Etype (N) = Any_Type
17029 then
17030 return No_Uint;
17031 end if;
17033 if Is_OK_Static_Expression (N) then
17034 if not Raises_Constraint_Error (N) then
17035 return Expr_Value (N);
17036 else
17037 return No_Uint;
17038 end if;
17040 elsif Etype (N) = Any_Type then
17041 return No_Uint;
17043 else
17044 Flag_Non_Static_Expr
17045 ("static boolean expression required here", N);
17046 return No_Uint;
17047 end if;
17048 end Static_Boolean;
17050 --------------------
17051 -- Static_Integer --
17052 --------------------
17054 function Static_Integer (N : Node_Id) return Uint is
17055 begin
17056 Analyze_And_Resolve (N, Any_Integer);
17058 if N = Error
17059 or else Error_Posted (N)
17060 or else Etype (N) = Any_Type
17061 then
17062 return No_Uint;
17063 end if;
17065 if Is_OK_Static_Expression (N) then
17066 if not Raises_Constraint_Error (N) then
17067 return Expr_Value (N);
17068 else
17069 return No_Uint;
17070 end if;
17072 elsif Etype (N) = Any_Type then
17073 return No_Uint;
17075 else
17076 Flag_Non_Static_Expr
17077 ("static integer expression required here", N);
17078 return No_Uint;
17079 end if;
17080 end Static_Integer;
17082 --------------------------
17083 -- Statically_Different --
17084 --------------------------
17086 function Statically_Different (E1, E2 : Node_Id) return Boolean is
17087 R1 : constant Node_Id := Get_Referenced_Object (E1);
17088 R2 : constant Node_Id := Get_Referenced_Object (E2);
17089 begin
17090 return Is_Entity_Name (R1)
17091 and then Is_Entity_Name (R2)
17092 and then Entity (R1) /= Entity (R2)
17093 and then not Is_Formal (Entity (R1))
17094 and then not Is_Formal (Entity (R2));
17095 end Statically_Different;
17097 --------------------------------------
17098 -- Subject_To_Loop_Entry_Attributes --
17099 --------------------------------------
17101 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
17102 Stmt : Node_Id;
17104 begin
17105 Stmt := N;
17107 -- The expansion mechanism transform a loop subject to at least one
17108 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
17109 -- the conditional part.
17111 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
17112 and then Nkind (Original_Node (N)) = N_Loop_Statement
17113 then
17114 Stmt := Original_Node (N);
17115 end if;
17117 return
17118 Nkind (Stmt) = N_Loop_Statement
17119 and then Present (Identifier (Stmt))
17120 and then Present (Entity (Identifier (Stmt)))
17121 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
17122 end Subject_To_Loop_Entry_Attributes;
17124 -----------------------------
17125 -- Subprogram_Access_Level --
17126 -----------------------------
17128 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
17129 begin
17130 if Present (Alias (Subp)) then
17131 return Subprogram_Access_Level (Alias (Subp));
17132 else
17133 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
17134 end if;
17135 end Subprogram_Access_Level;
17137 -------------------------------
17138 -- Support_Atomic_Primitives --
17139 -------------------------------
17141 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
17142 Size : Int;
17144 begin
17145 -- Verify the alignment of Typ is known
17147 if not Known_Alignment (Typ) then
17148 return False;
17149 end if;
17151 if Known_Static_Esize (Typ) then
17152 Size := UI_To_Int (Esize (Typ));
17154 -- If the Esize (Object_Size) is unknown at compile time, look at the
17155 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
17157 elsif Known_Static_RM_Size (Typ) then
17158 Size := UI_To_Int (RM_Size (Typ));
17160 -- Otherwise, the size is considered to be unknown.
17162 else
17163 return False;
17164 end if;
17166 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
17167 -- Typ is properly aligned.
17169 case Size is
17170 when 8 | 16 | 32 | 64 =>
17171 return Size = UI_To_Int (Alignment (Typ)) * 8;
17172 when others =>
17173 return False;
17174 end case;
17175 end Support_Atomic_Primitives;
17177 -----------------
17178 -- Trace_Scope --
17179 -----------------
17181 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
17182 begin
17183 if Debug_Flag_W then
17184 for J in 0 .. Scope_Stack.Last loop
17185 Write_Str (" ");
17186 end loop;
17188 Write_Str (Msg);
17189 Write_Name (Chars (E));
17190 Write_Str (" from ");
17191 Write_Location (Sloc (N));
17192 Write_Eol;
17193 end if;
17194 end Trace_Scope;
17196 -----------------------
17197 -- Transfer_Entities --
17198 -----------------------
17200 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
17201 Ent : Entity_Id := First_Entity (From);
17203 begin
17204 if No (Ent) then
17205 return;
17206 end if;
17208 if (Last_Entity (To)) = Empty then
17209 Set_First_Entity (To, Ent);
17210 else
17211 Set_Next_Entity (Last_Entity (To), Ent);
17212 end if;
17214 Set_Last_Entity (To, Last_Entity (From));
17216 while Present (Ent) loop
17217 Set_Scope (Ent, To);
17219 if not Is_Public (Ent) then
17220 Set_Public_Status (Ent);
17222 if Is_Public (Ent) and then Ekind (Ent) = E_Record_Subtype then
17224 -- The components of the propagated Itype must also be public
17226 declare
17227 Comp : Entity_Id;
17228 begin
17229 Comp := First_Entity (Ent);
17230 while Present (Comp) loop
17231 Set_Is_Public (Comp);
17232 Next_Entity (Comp);
17233 end loop;
17234 end;
17235 end if;
17236 end if;
17238 Next_Entity (Ent);
17239 end loop;
17241 Set_First_Entity (From, Empty);
17242 Set_Last_Entity (From, Empty);
17243 end Transfer_Entities;
17245 -----------------------
17246 -- Type_Access_Level --
17247 -----------------------
17249 function Type_Access_Level (Typ : Entity_Id) return Uint is
17250 Btyp : Entity_Id;
17252 begin
17253 Btyp := Base_Type (Typ);
17255 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
17256 -- simply use the level where the type is declared. This is true for
17257 -- stand-alone object declarations, and for anonymous access types
17258 -- associated with components the level is the same as that of the
17259 -- enclosing composite type. However, special treatment is needed for
17260 -- the cases of access parameters, return objects of an anonymous access
17261 -- type, and, in Ada 95, access discriminants of limited types.
17263 if Is_Access_Type (Btyp) then
17264 if Ekind (Btyp) = E_Anonymous_Access_Type then
17266 -- If the type is a nonlocal anonymous access type (such as for
17267 -- an access parameter) we treat it as being declared at the
17268 -- library level to ensure that names such as X.all'access don't
17269 -- fail static accessibility checks.
17271 if not Is_Local_Anonymous_Access (Typ) then
17272 return Scope_Depth (Standard_Standard);
17274 -- If this is a return object, the accessibility level is that of
17275 -- the result subtype of the enclosing function. The test here is
17276 -- little complicated, because we have to account for extended
17277 -- return statements that have been rewritten as blocks, in which
17278 -- case we have to find and the Is_Return_Object attribute of the
17279 -- itype's associated object. It would be nice to find a way to
17280 -- simplify this test, but it doesn't seem worthwhile to add a new
17281 -- flag just for purposes of this test. ???
17283 elsif Ekind (Scope (Btyp)) = E_Return_Statement
17284 or else
17285 (Is_Itype (Btyp)
17286 and then Nkind (Associated_Node_For_Itype (Btyp)) =
17287 N_Object_Declaration
17288 and then Is_Return_Object
17289 (Defining_Identifier
17290 (Associated_Node_For_Itype (Btyp))))
17291 then
17292 declare
17293 Scop : Entity_Id;
17295 begin
17296 Scop := Scope (Scope (Btyp));
17297 while Present (Scop) loop
17298 exit when Ekind (Scop) = E_Function;
17299 Scop := Scope (Scop);
17300 end loop;
17302 -- Treat the return object's type as having the level of the
17303 -- function's result subtype (as per RM05-6.5(5.3/2)).
17305 return Type_Access_Level (Etype (Scop));
17306 end;
17307 end if;
17308 end if;
17310 Btyp := Root_Type (Btyp);
17312 -- The accessibility level of anonymous access types associated with
17313 -- discriminants is that of the current instance of the type, and
17314 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
17316 -- AI-402: access discriminants have accessibility based on the
17317 -- object rather than the type in Ada 2005, so the above paragraph
17318 -- doesn't apply.
17320 -- ??? Needs completion with rules from AI-416
17322 if Ada_Version <= Ada_95
17323 and then Ekind (Typ) = E_Anonymous_Access_Type
17324 and then Present (Associated_Node_For_Itype (Typ))
17325 and then Nkind (Associated_Node_For_Itype (Typ)) =
17326 N_Discriminant_Specification
17327 then
17328 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
17329 end if;
17330 end if;
17332 -- Return library level for a generic formal type. This is done because
17333 -- RM(10.3.2) says that "The statically deeper relationship does not
17334 -- apply to ... a descendant of a generic formal type". Rather than
17335 -- checking at each point where a static accessibility check is
17336 -- performed to see if we are dealing with a formal type, this rule is
17337 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
17338 -- return extreme values for a formal type; Deepest_Type_Access_Level
17339 -- returns Int'Last. By calling the appropriate function from among the
17340 -- two, we ensure that the static accessibility check will pass if we
17341 -- happen to run into a formal type. More specifically, we should call
17342 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
17343 -- call occurs as part of a static accessibility check and the error
17344 -- case is the case where the type's level is too shallow (as opposed
17345 -- to too deep).
17347 if Is_Generic_Type (Root_Type (Btyp)) then
17348 return Scope_Depth (Standard_Standard);
17349 end if;
17351 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
17352 end Type_Access_Level;
17354 ------------------------------------
17355 -- Type_Without_Stream_Operation --
17356 ------------------------------------
17358 function Type_Without_Stream_Operation
17359 (T : Entity_Id;
17360 Op : TSS_Name_Type := TSS_Null) return Entity_Id
17362 BT : constant Entity_Id := Base_Type (T);
17363 Op_Missing : Boolean;
17365 begin
17366 if not Restriction_Active (No_Default_Stream_Attributes) then
17367 return Empty;
17368 end if;
17370 if Is_Elementary_Type (T) then
17371 if Op = TSS_Null then
17372 Op_Missing :=
17373 No (TSS (BT, TSS_Stream_Read))
17374 or else No (TSS (BT, TSS_Stream_Write));
17376 else
17377 Op_Missing := No (TSS (BT, Op));
17378 end if;
17380 if Op_Missing then
17381 return T;
17382 else
17383 return Empty;
17384 end if;
17386 elsif Is_Array_Type (T) then
17387 return Type_Without_Stream_Operation (Component_Type (T), Op);
17389 elsif Is_Record_Type (T) then
17390 declare
17391 Comp : Entity_Id;
17392 C_Typ : Entity_Id;
17394 begin
17395 Comp := First_Component (T);
17396 while Present (Comp) loop
17397 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
17399 if Present (C_Typ) then
17400 return C_Typ;
17401 end if;
17403 Next_Component (Comp);
17404 end loop;
17406 return Empty;
17407 end;
17409 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
17410 return Type_Without_Stream_Operation (Full_View (T), Op);
17411 else
17412 return Empty;
17413 end if;
17414 end Type_Without_Stream_Operation;
17416 ----------------------------
17417 -- Unique_Defining_Entity --
17418 ----------------------------
17420 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
17421 begin
17422 return Unique_Entity (Defining_Entity (N));
17423 end Unique_Defining_Entity;
17425 -------------------
17426 -- Unique_Entity --
17427 -------------------
17429 function Unique_Entity (E : Entity_Id) return Entity_Id is
17430 U : Entity_Id := E;
17431 P : Node_Id;
17433 begin
17434 case Ekind (E) is
17435 when E_Constant =>
17436 if Present (Full_View (E)) then
17437 U := Full_View (E);
17438 end if;
17440 when Type_Kind =>
17441 if Present (Full_View (E)) then
17442 U := Full_View (E);
17443 end if;
17445 when E_Package_Body =>
17446 P := Parent (E);
17448 if Nkind (P) = N_Defining_Program_Unit_Name then
17449 P := Parent (P);
17450 end if;
17452 U := Corresponding_Spec (P);
17454 when E_Subprogram_Body =>
17455 P := Parent (E);
17457 if Nkind (P) = N_Defining_Program_Unit_Name then
17458 P := Parent (P);
17459 end if;
17461 P := Parent (P);
17463 if Nkind (P) = N_Subprogram_Body_Stub then
17464 if Present (Library_Unit (P)) then
17466 -- Get to the function or procedure (generic) entity through
17467 -- the body entity.
17469 U :=
17470 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
17471 end if;
17472 else
17473 U := Corresponding_Spec (P);
17474 end if;
17476 when Formal_Kind =>
17477 if Present (Spec_Entity (E)) then
17478 U := Spec_Entity (E);
17479 end if;
17481 when others =>
17482 null;
17483 end case;
17485 return U;
17486 end Unique_Entity;
17488 -----------------
17489 -- Unique_Name --
17490 -----------------
17492 function Unique_Name (E : Entity_Id) return String is
17494 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17495 -- reliable, as they may not include the overloading suffix. Instead,
17496 -- when looking for the name of E or one of its enclosing scope, we get
17497 -- the name of the corresponding Unique_Entity.
17499 function Get_Scoped_Name (E : Entity_Id) return String;
17500 -- Return the name of E prefixed by all the names of the scopes to which
17501 -- E belongs, except for Standard.
17503 ---------------------
17504 -- Get_Scoped_Name --
17505 ---------------------
17507 function Get_Scoped_Name (E : Entity_Id) return String is
17508 Name : constant String := Get_Name_String (Chars (E));
17509 begin
17510 if Has_Fully_Qualified_Name (E)
17511 or else Scope (E) = Standard_Standard
17512 then
17513 return Name;
17514 else
17515 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
17516 end if;
17517 end Get_Scoped_Name;
17519 -- Start of processing for Unique_Name
17521 begin
17522 if E = Standard_Standard then
17523 return Get_Name_String (Name_Standard);
17525 elsif Scope (E) = Standard_Standard
17526 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
17527 then
17528 return Get_Name_String (Name_Standard) & "__" &
17529 Get_Name_String (Chars (E));
17531 elsif Ekind (E) = E_Enumeration_Literal then
17532 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
17534 else
17535 return Get_Scoped_Name (Unique_Entity (E));
17536 end if;
17537 end Unique_Name;
17539 ---------------------
17540 -- Unit_Is_Visible --
17541 ---------------------
17543 function Unit_Is_Visible (U : Entity_Id) return Boolean is
17544 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
17545 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
17547 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
17548 -- For a child unit, check whether unit appears in a with_clause
17549 -- of a parent.
17551 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
17552 -- Scan the context clause of one compilation unit looking for a
17553 -- with_clause for the unit in question.
17555 ----------------------------
17556 -- Unit_In_Parent_Context --
17557 ----------------------------
17559 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
17560 begin
17561 if Unit_In_Context (Par_Unit) then
17562 return True;
17564 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
17565 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
17567 else
17568 return False;
17569 end if;
17570 end Unit_In_Parent_Context;
17572 ---------------------
17573 -- Unit_In_Context --
17574 ---------------------
17576 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
17577 Clause : Node_Id;
17579 begin
17580 Clause := First (Context_Items (Comp_Unit));
17581 while Present (Clause) loop
17582 if Nkind (Clause) = N_With_Clause then
17583 if Library_Unit (Clause) = U then
17584 return True;
17586 -- The with_clause may denote a renaming of the unit we are
17587 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17589 elsif
17590 Renamed_Entity (Entity (Name (Clause))) =
17591 Defining_Entity (Unit (U))
17592 then
17593 return True;
17594 end if;
17595 end if;
17597 Next (Clause);
17598 end loop;
17600 return False;
17601 end Unit_In_Context;
17603 -- Start of processing for Unit_Is_Visible
17605 begin
17606 -- The currrent unit is directly visible
17608 if Curr = U then
17609 return True;
17611 elsif Unit_In_Context (Curr) then
17612 return True;
17614 -- If the current unit is a body, check the context of the spec
17616 elsif Nkind (Unit (Curr)) = N_Package_Body
17617 or else
17618 (Nkind (Unit (Curr)) = N_Subprogram_Body
17619 and then not Acts_As_Spec (Unit (Curr)))
17620 then
17621 if Unit_In_Context (Library_Unit (Curr)) then
17622 return True;
17623 end if;
17624 end if;
17626 -- If the spec is a child unit, examine the parents
17628 if Is_Child_Unit (Curr_Entity) then
17629 if Nkind (Unit (Curr)) in N_Unit_Body then
17630 return
17631 Unit_In_Parent_Context
17632 (Parent_Spec (Unit (Library_Unit (Curr))));
17633 else
17634 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
17635 end if;
17637 else
17638 return False;
17639 end if;
17640 end Unit_Is_Visible;
17642 ------------------------------
17643 -- Universal_Interpretation --
17644 ------------------------------
17646 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
17647 Index : Interp_Index;
17648 It : Interp;
17650 begin
17651 -- The argument may be a formal parameter of an operator or subprogram
17652 -- with multiple interpretations, or else an expression for an actual.
17654 if Nkind (Opnd) = N_Defining_Identifier
17655 or else not Is_Overloaded (Opnd)
17656 then
17657 if Etype (Opnd) = Universal_Integer
17658 or else Etype (Opnd) = Universal_Real
17659 then
17660 return Etype (Opnd);
17661 else
17662 return Empty;
17663 end if;
17665 else
17666 Get_First_Interp (Opnd, Index, It);
17667 while Present (It.Typ) loop
17668 if It.Typ = Universal_Integer
17669 or else It.Typ = Universal_Real
17670 then
17671 return It.Typ;
17672 end if;
17674 Get_Next_Interp (Index, It);
17675 end loop;
17677 return Empty;
17678 end if;
17679 end Universal_Interpretation;
17681 ---------------
17682 -- Unqualify --
17683 ---------------
17685 function Unqualify (Expr : Node_Id) return Node_Id is
17686 begin
17687 -- Recurse to handle unlikely case of multiple levels of qualification
17689 if Nkind (Expr) = N_Qualified_Expression then
17690 return Unqualify (Expression (Expr));
17692 -- Normal case, not a qualified expression
17694 else
17695 return Expr;
17696 end if;
17697 end Unqualify;
17699 -----------------------
17700 -- Visible_Ancestors --
17701 -----------------------
17703 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
17704 List_1 : Elist_Id;
17705 List_2 : Elist_Id;
17706 Elmt : Elmt_Id;
17708 begin
17709 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
17711 -- Collect all the parents and progenitors of Typ. If the full-view of
17712 -- private parents and progenitors is available then it is used to
17713 -- generate the list of visible ancestors; otherwise their partial
17714 -- view is added to the resulting list.
17716 Collect_Parents
17717 (T => Typ,
17718 List => List_1,
17719 Use_Full_View => True);
17721 Collect_Interfaces
17722 (T => Typ,
17723 Ifaces_List => List_2,
17724 Exclude_Parents => True,
17725 Use_Full_View => True);
17727 -- Join the two lists. Avoid duplications because an interface may
17728 -- simultaneously be parent and progenitor of a type.
17730 Elmt := First_Elmt (List_2);
17731 while Present (Elmt) loop
17732 Append_Unique_Elmt (Node (Elmt), List_1);
17733 Next_Elmt (Elmt);
17734 end loop;
17736 return List_1;
17737 end Visible_Ancestors;
17739 ----------------------
17740 -- Within_Init_Proc --
17741 ----------------------
17743 function Within_Init_Proc return Boolean is
17744 S : Entity_Id;
17746 begin
17747 S := Current_Scope;
17748 while not Is_Overloadable (S) loop
17749 if S = Standard_Standard then
17750 return False;
17751 else
17752 S := Scope (S);
17753 end if;
17754 end loop;
17756 return Is_Init_Proc (S);
17757 end Within_Init_Proc;
17759 ------------------
17760 -- Within_Scope --
17761 ------------------
17763 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
17764 SE : Entity_Id;
17765 begin
17766 SE := Scope (E);
17767 loop
17768 if SE = S then
17769 return True;
17770 elsif SE = Standard_Standard then
17771 return False;
17772 else
17773 SE := Scope (SE);
17774 end if;
17775 end loop;
17776 end Within_Scope;
17778 ----------------
17779 -- Wrong_Type --
17780 ----------------
17782 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
17783 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
17784 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
17786 Matching_Field : Entity_Id;
17787 -- Entity to give a more precise suggestion on how to write a one-
17788 -- element positional aggregate.
17790 function Has_One_Matching_Field return Boolean;
17791 -- Determines if Expec_Type is a record type with a single component or
17792 -- discriminant whose type matches the found type or is one dimensional
17793 -- array whose component type matches the found type. In the case of
17794 -- one discriminant, we ignore the variant parts. That's not accurate,
17795 -- but good enough for the warning.
17797 ----------------------------
17798 -- Has_One_Matching_Field --
17799 ----------------------------
17801 function Has_One_Matching_Field return Boolean is
17802 E : Entity_Id;
17804 begin
17805 Matching_Field := Empty;
17807 if Is_Array_Type (Expec_Type)
17808 and then Number_Dimensions (Expec_Type) = 1
17809 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
17810 then
17811 -- Use type name if available. This excludes multidimensional
17812 -- arrays and anonymous arrays.
17814 if Comes_From_Source (Expec_Type) then
17815 Matching_Field := Expec_Type;
17817 -- For an assignment, use name of target
17819 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
17820 and then Is_Entity_Name (Name (Parent (Expr)))
17821 then
17822 Matching_Field := Entity (Name (Parent (Expr)));
17823 end if;
17825 return True;
17827 elsif not Is_Record_Type (Expec_Type) then
17828 return False;
17830 else
17831 E := First_Entity (Expec_Type);
17832 loop
17833 if No (E) then
17834 return False;
17836 elsif not Ekind_In (E, E_Discriminant, E_Component)
17837 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
17838 then
17839 Next_Entity (E);
17841 else
17842 exit;
17843 end if;
17844 end loop;
17846 if not Covers (Etype (E), Found_Type) then
17847 return False;
17849 elsif Present (Next_Entity (E))
17850 and then (Ekind (E) = E_Component
17851 or else Ekind (Next_Entity (E)) = E_Discriminant)
17852 then
17853 return False;
17855 else
17856 Matching_Field := E;
17857 return True;
17858 end if;
17859 end if;
17860 end Has_One_Matching_Field;
17862 -- Start of processing for Wrong_Type
17864 begin
17865 -- Don't output message if either type is Any_Type, or if a message
17866 -- has already been posted for this node. We need to do the latter
17867 -- check explicitly (it is ordinarily done in Errout), because we
17868 -- are using ! to force the output of the error messages.
17870 if Expec_Type = Any_Type
17871 or else Found_Type = Any_Type
17872 or else Error_Posted (Expr)
17873 then
17874 return;
17876 -- If one of the types is a Taft-Amendment type and the other it its
17877 -- completion, it must be an illegal use of a TAT in the spec, for
17878 -- which an error was already emitted. Avoid cascaded errors.
17880 elsif Is_Incomplete_Type (Expec_Type)
17881 and then Has_Completion_In_Body (Expec_Type)
17882 and then Full_View (Expec_Type) = Etype (Expr)
17883 then
17884 return;
17886 elsif Is_Incomplete_Type (Etype (Expr))
17887 and then Has_Completion_In_Body (Etype (Expr))
17888 and then Full_View (Etype (Expr)) = Expec_Type
17889 then
17890 return;
17892 -- In an instance, there is an ongoing problem with completion of
17893 -- type derived from private types. Their structure is what Gigi
17894 -- expects, but the Etype is the parent type rather than the
17895 -- derived private type itself. Do not flag error in this case. The
17896 -- private completion is an entity without a parent, like an Itype.
17897 -- Similarly, full and partial views may be incorrect in the instance.
17898 -- There is no simple way to insure that it is consistent ???
17900 -- A similar view discrepancy can happen in an inlined body, for the
17901 -- same reason: inserted body may be outside of the original package
17902 -- and only partial views are visible at the point of insertion.
17904 elsif In_Instance or else In_Inlined_Body then
17905 if Etype (Etype (Expr)) = Etype (Expected_Type)
17906 and then
17907 (Has_Private_Declaration (Expected_Type)
17908 or else Has_Private_Declaration (Etype (Expr)))
17909 and then No (Parent (Expected_Type))
17910 then
17911 return;
17913 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
17914 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
17915 then
17916 return;
17918 elsif Is_Private_Type (Expected_Type)
17919 and then Present (Full_View (Expected_Type))
17920 and then Covers (Full_View (Expected_Type), Etype (Expr))
17921 then
17922 return;
17923 end if;
17924 end if;
17926 -- An interesting special check. If the expression is parenthesized
17927 -- and its type corresponds to the type of the sole component of the
17928 -- expected record type, or to the component type of the expected one
17929 -- dimensional array type, then assume we have a bad aggregate attempt.
17931 if Nkind (Expr) in N_Subexpr
17932 and then Paren_Count (Expr) /= 0
17933 and then Has_One_Matching_Field
17934 then
17935 Error_Msg_N ("positional aggregate cannot have one component", Expr);
17936 if Present (Matching_Field) then
17937 if Is_Array_Type (Expec_Type) then
17938 Error_Msg_NE
17939 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
17941 else
17942 Error_Msg_NE
17943 ("\write instead `& ='> ...`", Expr, Matching_Field);
17944 end if;
17945 end if;
17947 -- Another special check, if we are looking for a pool-specific access
17948 -- type and we found an E_Access_Attribute_Type, then we have the case
17949 -- of an Access attribute being used in a context which needs a pool-
17950 -- specific type, which is never allowed. The one extra check we make
17951 -- is that the expected designated type covers the Found_Type.
17953 elsif Is_Access_Type (Expec_Type)
17954 and then Ekind (Found_Type) = E_Access_Attribute_Type
17955 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
17956 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
17957 and then Covers
17958 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
17959 then
17960 Error_Msg_N -- CODEFIX
17961 ("result must be general access type!", Expr);
17962 Error_Msg_NE -- CODEFIX
17963 ("add ALL to }!", Expr, Expec_Type);
17965 -- Another special check, if the expected type is an integer type,
17966 -- but the expression is of type System.Address, and the parent is
17967 -- an addition or subtraction operation whose left operand is the
17968 -- expression in question and whose right operand is of an integral
17969 -- type, then this is an attempt at address arithmetic, so give
17970 -- appropriate message.
17972 elsif Is_Integer_Type (Expec_Type)
17973 and then Is_RTE (Found_Type, RE_Address)
17974 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
17975 and then Expr = Left_Opnd (Parent (Expr))
17976 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
17977 then
17978 Error_Msg_N
17979 ("address arithmetic not predefined in package System",
17980 Parent (Expr));
17981 Error_Msg_N
17982 ("\possible missing with/use of System.Storage_Elements",
17983 Parent (Expr));
17984 return;
17986 -- If the expected type is an anonymous access type, as for access
17987 -- parameters and discriminants, the error is on the designated types.
17989 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
17990 if Comes_From_Source (Expec_Type) then
17991 Error_Msg_NE ("expected}!", Expr, Expec_Type);
17992 else
17993 Error_Msg_NE
17994 ("expected an access type with designated}",
17995 Expr, Designated_Type (Expec_Type));
17996 end if;
17998 if Is_Access_Type (Found_Type)
17999 and then not Comes_From_Source (Found_Type)
18000 then
18001 Error_Msg_NE
18002 ("\\found an access type with designated}!",
18003 Expr, Designated_Type (Found_Type));
18004 else
18005 if From_Limited_With (Found_Type) then
18006 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
18007 Error_Msg_Qual_Level := 99;
18008 Error_Msg_NE -- CODEFIX
18009 ("\\missing `WITH &;", Expr, Scope (Found_Type));
18010 Error_Msg_Qual_Level := 0;
18011 else
18012 Error_Msg_NE ("found}!", Expr, Found_Type);
18013 end if;
18014 end if;
18016 -- Normal case of one type found, some other type expected
18018 else
18019 -- If the names of the two types are the same, see if some number
18020 -- of levels of qualification will help. Don't try more than three
18021 -- levels, and if we get to standard, it's no use (and probably
18022 -- represents an error in the compiler) Also do not bother with
18023 -- internal scope names.
18025 declare
18026 Expec_Scope : Entity_Id;
18027 Found_Scope : Entity_Id;
18029 begin
18030 Expec_Scope := Expec_Type;
18031 Found_Scope := Found_Type;
18033 for Levels in Int range 0 .. 3 loop
18034 if Chars (Expec_Scope) /= Chars (Found_Scope) then
18035 Error_Msg_Qual_Level := Levels;
18036 exit;
18037 end if;
18039 Expec_Scope := Scope (Expec_Scope);
18040 Found_Scope := Scope (Found_Scope);
18042 exit when Expec_Scope = Standard_Standard
18043 or else Found_Scope = Standard_Standard
18044 or else not Comes_From_Source (Expec_Scope)
18045 or else not Comes_From_Source (Found_Scope);
18046 end loop;
18047 end;
18049 if Is_Record_Type (Expec_Type)
18050 and then Present (Corresponding_Remote_Type (Expec_Type))
18051 then
18052 Error_Msg_NE ("expected}!", Expr,
18053 Corresponding_Remote_Type (Expec_Type));
18054 else
18055 Error_Msg_NE ("expected}!", Expr, Expec_Type);
18056 end if;
18058 if Is_Entity_Name (Expr)
18059 and then Is_Package_Or_Generic_Package (Entity (Expr))
18060 then
18061 Error_Msg_N ("\\found package name!", Expr);
18063 elsif Is_Entity_Name (Expr)
18064 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
18065 then
18066 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
18067 Error_Msg_N
18068 ("found procedure name, possibly missing Access attribute!",
18069 Expr);
18070 else
18071 Error_Msg_N
18072 ("\\found procedure name instead of function!", Expr);
18073 end if;
18075 elsif Nkind (Expr) = N_Function_Call
18076 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
18077 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
18078 and then No (Parameter_Associations (Expr))
18079 then
18080 Error_Msg_N
18081 ("found function name, possibly missing Access attribute!",
18082 Expr);
18084 -- Catch common error: a prefix or infix operator which is not
18085 -- directly visible because the type isn't.
18087 elsif Nkind (Expr) in N_Op
18088 and then Is_Overloaded (Expr)
18089 and then not Is_Immediately_Visible (Expec_Type)
18090 and then not Is_Potentially_Use_Visible (Expec_Type)
18091 and then not In_Use (Expec_Type)
18092 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
18093 then
18094 Error_Msg_N
18095 ("operator of the type is not directly visible!", Expr);
18097 elsif Ekind (Found_Type) = E_Void
18098 and then Present (Parent (Found_Type))
18099 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
18100 then
18101 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
18103 else
18104 Error_Msg_NE ("\\found}!", Expr, Found_Type);
18105 end if;
18107 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
18108 -- of the same modular type, and (M1 and M2) = 0 was intended.
18110 if Expec_Type = Standard_Boolean
18111 and then Is_Modular_Integer_Type (Found_Type)
18112 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
18113 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
18114 then
18115 declare
18116 Op : constant Node_Id := Right_Opnd (Parent (Expr));
18117 L : constant Node_Id := Left_Opnd (Op);
18118 R : constant Node_Id := Right_Opnd (Op);
18120 begin
18121 -- The case for the message is when the left operand of the
18122 -- comparison is the same modular type, or when it is an
18123 -- integer literal (or other universal integer expression),
18124 -- which would have been typed as the modular type if the
18125 -- parens had been there.
18127 if (Etype (L) = Found_Type
18128 or else
18129 Etype (L) = Universal_Integer)
18130 and then Is_Integer_Type (Etype (R))
18131 then
18132 Error_Msg_N
18133 ("\\possible missing parens for modular operation", Expr);
18134 end if;
18135 end;
18136 end if;
18138 -- Reset error message qualification indication
18140 Error_Msg_Qual_Level := 0;
18141 end if;
18142 end Wrong_Type;
18144 end Sem_Util;