PR testsuite/64850
[official-gcc.git] / gcc / ada / sem_util.adb
bloba8767b850c3baa25769f1a1c1ba0debbea5f1dbd
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-2015, 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 Has_Enabled_Property
114 (Item_Id : Entity_Id;
115 Property : Name_Id) return Boolean;
116 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
117 -- Determine whether an abstract state or a variable denoted by entity
118 -- Item_Id has enabled property Property.
120 function Has_Null_Extension (T : Entity_Id) return Boolean;
121 -- T is a derived tagged type. Check whether the type extension is null.
122 -- If the parent type is fully initialized, T can be treated as such.
124 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
125 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
126 -- with discriminants whose default values are static, examine only the
127 -- components in the selected variant to determine whether all of them
128 -- have a default.
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 Warn_On_Unordered_Enumeration_Type
901 and then not Is_Generic_Type (T)
902 and then Comes_From_Source (N)
903 and then not Has_Pragma_Ordered (T)
904 and then not In_Same_Extended_Unit (N, T);
905 end Bad_Unordered_Enumeration_Reference;
907 --------------------------
908 -- Build_Actual_Subtype --
909 --------------------------
911 function Build_Actual_Subtype
912 (T : Entity_Id;
913 N : Node_Or_Entity_Id) return Node_Id
915 Loc : Source_Ptr;
916 -- Normally Sloc (N), but may point to corresponding body in some cases
918 Constraints : List_Id;
919 Decl : Node_Id;
920 Discr : Entity_Id;
921 Hi : Node_Id;
922 Lo : Node_Id;
923 Subt : Entity_Id;
924 Disc_Type : Entity_Id;
925 Obj : Node_Id;
927 begin
928 Loc := Sloc (N);
930 if Nkind (N) = N_Defining_Identifier then
931 Obj := New_Occurrence_Of (N, Loc);
933 -- If this is a formal parameter of a subprogram declaration, and
934 -- we are compiling the body, we want the declaration for the
935 -- actual subtype to carry the source position of the body, to
936 -- prevent anomalies in gdb when stepping through the code.
938 if Is_Formal (N) then
939 declare
940 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
941 begin
942 if Nkind (Decl) = N_Subprogram_Declaration
943 and then Present (Corresponding_Body (Decl))
944 then
945 Loc := Sloc (Corresponding_Body (Decl));
946 end if;
947 end;
948 end if;
950 else
951 Obj := N;
952 end if;
954 if Is_Array_Type (T) then
955 Constraints := New_List;
956 for J in 1 .. Number_Dimensions (T) loop
958 -- Build an array subtype declaration with the nominal subtype and
959 -- the bounds of the actual. Add the declaration in front of the
960 -- local declarations for the subprogram, for analysis before any
961 -- reference to the formal in the body.
963 Lo :=
964 Make_Attribute_Reference (Loc,
965 Prefix =>
966 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
967 Attribute_Name => Name_First,
968 Expressions => New_List (
969 Make_Integer_Literal (Loc, J)));
971 Hi :=
972 Make_Attribute_Reference (Loc,
973 Prefix =>
974 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
975 Attribute_Name => Name_Last,
976 Expressions => New_List (
977 Make_Integer_Literal (Loc, J)));
979 Append (Make_Range (Loc, Lo, Hi), Constraints);
980 end loop;
982 -- If the type has unknown discriminants there is no constrained
983 -- subtype to build. This is never called for a formal or for a
984 -- lhs, so returning the type is ok ???
986 elsif Has_Unknown_Discriminants (T) then
987 return T;
989 else
990 Constraints := New_List;
992 -- Type T is a generic derived type, inherit the discriminants from
993 -- the parent type.
995 if Is_Private_Type (T)
996 and then No (Full_View (T))
998 -- T was flagged as an error if it was declared as a formal
999 -- derived type with known discriminants. In this case there
1000 -- is no need to look at the parent type since T already carries
1001 -- its own discriminants.
1003 and then not Error_Posted (T)
1004 then
1005 Disc_Type := Etype (Base_Type (T));
1006 else
1007 Disc_Type := T;
1008 end if;
1010 Discr := First_Discriminant (Disc_Type);
1011 while Present (Discr) loop
1012 Append_To (Constraints,
1013 Make_Selected_Component (Loc,
1014 Prefix =>
1015 Duplicate_Subexpr_No_Checks (Obj),
1016 Selector_Name => New_Occurrence_Of (Discr, Loc)));
1017 Next_Discriminant (Discr);
1018 end loop;
1019 end if;
1021 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
1022 Set_Is_Internal (Subt);
1024 Decl :=
1025 Make_Subtype_Declaration (Loc,
1026 Defining_Identifier => Subt,
1027 Subtype_Indication =>
1028 Make_Subtype_Indication (Loc,
1029 Subtype_Mark => New_Occurrence_Of (T, Loc),
1030 Constraint =>
1031 Make_Index_Or_Discriminant_Constraint (Loc,
1032 Constraints => Constraints)));
1034 Mark_Rewrite_Insertion (Decl);
1035 return Decl;
1036 end Build_Actual_Subtype;
1038 ---------------------------------------
1039 -- Build_Actual_Subtype_Of_Component --
1040 ---------------------------------------
1042 function Build_Actual_Subtype_Of_Component
1043 (T : Entity_Id;
1044 N : Node_Id) return Node_Id
1046 Loc : constant Source_Ptr := Sloc (N);
1047 P : constant Node_Id := Prefix (N);
1048 D : Elmt_Id;
1049 Id : Node_Id;
1050 Index_Typ : Entity_Id;
1052 Desig_Typ : Entity_Id;
1053 -- This is either a copy of T, or if T is an access type, then it is
1054 -- the directly designated type of this access type.
1056 function Build_Actual_Array_Constraint return List_Id;
1057 -- If one or more of the bounds of the component depends on
1058 -- discriminants, build actual constraint using the discriminants
1059 -- of the prefix.
1061 function Build_Actual_Record_Constraint return List_Id;
1062 -- Similar to previous one, for discriminated components constrained
1063 -- by the discriminant of the enclosing object.
1065 -----------------------------------
1066 -- Build_Actual_Array_Constraint --
1067 -----------------------------------
1069 function Build_Actual_Array_Constraint return List_Id is
1070 Constraints : constant List_Id := New_List;
1071 Indx : Node_Id;
1072 Hi : Node_Id;
1073 Lo : Node_Id;
1074 Old_Hi : Node_Id;
1075 Old_Lo : Node_Id;
1077 begin
1078 Indx := First_Index (Desig_Typ);
1079 while Present (Indx) loop
1080 Old_Lo := Type_Low_Bound (Etype (Indx));
1081 Old_Hi := Type_High_Bound (Etype (Indx));
1083 if Denotes_Discriminant (Old_Lo) then
1084 Lo :=
1085 Make_Selected_Component (Loc,
1086 Prefix => New_Copy_Tree (P),
1087 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1089 else
1090 Lo := New_Copy_Tree (Old_Lo);
1092 -- The new bound will be reanalyzed in the enclosing
1093 -- declaration. For literal bounds that come from a type
1094 -- declaration, the type of the context must be imposed, so
1095 -- insure that analysis will take place. For non-universal
1096 -- types this is not strictly necessary.
1098 Set_Analyzed (Lo, False);
1099 end if;
1101 if Denotes_Discriminant (Old_Hi) then
1102 Hi :=
1103 Make_Selected_Component (Loc,
1104 Prefix => New_Copy_Tree (P),
1105 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1107 else
1108 Hi := New_Copy_Tree (Old_Hi);
1109 Set_Analyzed (Hi, False);
1110 end if;
1112 Append (Make_Range (Loc, Lo, Hi), Constraints);
1113 Next_Index (Indx);
1114 end loop;
1116 return Constraints;
1117 end Build_Actual_Array_Constraint;
1119 ------------------------------------
1120 -- Build_Actual_Record_Constraint --
1121 ------------------------------------
1123 function Build_Actual_Record_Constraint return List_Id is
1124 Constraints : constant List_Id := New_List;
1125 D : Elmt_Id;
1126 D_Val : Node_Id;
1128 begin
1129 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1130 while Present (D) loop
1131 if Denotes_Discriminant (Node (D)) then
1132 D_Val := Make_Selected_Component (Loc,
1133 Prefix => New_Copy_Tree (P),
1134 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1136 else
1137 D_Val := New_Copy_Tree (Node (D));
1138 end if;
1140 Append (D_Val, Constraints);
1141 Next_Elmt (D);
1142 end loop;
1144 return Constraints;
1145 end Build_Actual_Record_Constraint;
1147 -- Start of processing for Build_Actual_Subtype_Of_Component
1149 begin
1150 -- Why the test for Spec_Expression mode here???
1152 if In_Spec_Expression then
1153 return Empty;
1155 -- More comments for the rest of this body would be good ???
1157 elsif Nkind (N) = N_Explicit_Dereference then
1158 if Is_Composite_Type (T)
1159 and then not Is_Constrained (T)
1160 and then not (Is_Class_Wide_Type (T)
1161 and then Is_Constrained (Root_Type (T)))
1162 and then not Has_Unknown_Discriminants (T)
1163 then
1164 -- If the type of the dereference is already constrained, it is an
1165 -- actual subtype.
1167 if Is_Array_Type (Etype (N))
1168 and then Is_Constrained (Etype (N))
1169 then
1170 return Empty;
1171 else
1172 Remove_Side_Effects (P);
1173 return Build_Actual_Subtype (T, N);
1174 end if;
1175 else
1176 return Empty;
1177 end if;
1178 end if;
1180 if Ekind (T) = E_Access_Subtype then
1181 Desig_Typ := Designated_Type (T);
1182 else
1183 Desig_Typ := T;
1184 end if;
1186 if Ekind (Desig_Typ) = E_Array_Subtype then
1187 Id := First_Index (Desig_Typ);
1188 while Present (Id) loop
1189 Index_Typ := Underlying_Type (Etype (Id));
1191 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1192 or else
1193 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1194 then
1195 Remove_Side_Effects (P);
1196 return
1197 Build_Component_Subtype
1198 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1199 end if;
1201 Next_Index (Id);
1202 end loop;
1204 elsif Is_Composite_Type (Desig_Typ)
1205 and then Has_Discriminants (Desig_Typ)
1206 and then not Has_Unknown_Discriminants (Desig_Typ)
1207 then
1208 if Is_Private_Type (Desig_Typ)
1209 and then No (Discriminant_Constraint (Desig_Typ))
1210 then
1211 Desig_Typ := Full_View (Desig_Typ);
1212 end if;
1214 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1215 while Present (D) loop
1216 if Denotes_Discriminant (Node (D)) then
1217 Remove_Side_Effects (P);
1218 return
1219 Build_Component_Subtype (
1220 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1221 end if;
1223 Next_Elmt (D);
1224 end loop;
1225 end if;
1227 -- If none of the above, the actual and nominal subtypes are the same
1229 return Empty;
1230 end Build_Actual_Subtype_Of_Component;
1232 -----------------------------
1233 -- Build_Component_Subtype --
1234 -----------------------------
1236 function Build_Component_Subtype
1237 (C : List_Id;
1238 Loc : Source_Ptr;
1239 T : Entity_Id) return Node_Id
1241 Subt : Entity_Id;
1242 Decl : Node_Id;
1244 begin
1245 -- Unchecked_Union components do not require component subtypes
1247 if Is_Unchecked_Union (T) then
1248 return Empty;
1249 end if;
1251 Subt := Make_Temporary (Loc, 'S');
1252 Set_Is_Internal (Subt);
1254 Decl :=
1255 Make_Subtype_Declaration (Loc,
1256 Defining_Identifier => Subt,
1257 Subtype_Indication =>
1258 Make_Subtype_Indication (Loc,
1259 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1260 Constraint =>
1261 Make_Index_Or_Discriminant_Constraint (Loc,
1262 Constraints => C)));
1264 Mark_Rewrite_Insertion (Decl);
1265 return Decl;
1266 end Build_Component_Subtype;
1268 ----------------------------------
1269 -- Build_Default_Init_Cond_Call --
1270 ----------------------------------
1272 function Build_Default_Init_Cond_Call
1273 (Loc : Source_Ptr;
1274 Obj_Id : Entity_Id;
1275 Typ : Entity_Id) return Node_Id
1277 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1278 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1280 begin
1281 return
1282 Make_Procedure_Call_Statement (Loc,
1283 Name => New_Occurrence_Of (Proc_Id, Loc),
1284 Parameter_Associations => New_List (
1285 Make_Unchecked_Type_Conversion (Loc,
1286 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1287 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1288 end Build_Default_Init_Cond_Call;
1290 ----------------------------------------------
1291 -- Build_Default_Init_Cond_Procedure_Bodies --
1292 ----------------------------------------------
1294 procedure Build_Default_Init_Cond_Procedure_Bodies (Priv_Decls : List_Id) is
1295 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id);
1296 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1297 -- body of the procedure which verifies the assumption of the pragma at
1298 -- run time. The generated body is added after the type declaration.
1300 --------------------------------------------
1301 -- Build_Default_Init_Cond_Procedure_Body --
1302 --------------------------------------------
1304 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1305 Param_Id : Entity_Id;
1306 -- The entity of the sole formal parameter of the default initial
1307 -- condition procedure.
1309 procedure Replace_Type_Reference (N : Node_Id);
1310 -- Replace a single reference to type Typ with a reference to formal
1311 -- parameter Param_Id.
1313 ----------------------------
1314 -- Replace_Type_Reference --
1315 ----------------------------
1317 procedure Replace_Type_Reference (N : Node_Id) is
1318 begin
1319 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1320 end Replace_Type_Reference;
1322 procedure Replace_Type_References is
1323 new Replace_Type_References_Generic (Replace_Type_Reference);
1325 -- Local variables
1327 Loc : constant Source_Ptr := Sloc (Typ);
1328 Prag : constant Node_Id :=
1329 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1330 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1331 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1332 Body_Decl : Node_Id;
1333 Expr : Node_Id;
1334 Stmt : Node_Id;
1336 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1338 begin
1339 -- The procedure should be generated only for [sub]types subject to
1340 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1341 -- not get this specialized procedure.
1343 pragma Assert (Has_Default_Init_Cond (Typ));
1344 pragma Assert (Present (Prag));
1345 pragma Assert (Present (Proc_Id));
1347 -- Nothing to do if the body was already built
1349 if Present (Corresponding_Body (Spec_Decl)) then
1350 return;
1351 end if;
1353 Param_Id := First_Formal (Proc_Id);
1355 -- The pragma has an argument. Note that the argument is analyzed
1356 -- after all references to the current instance of the type are
1357 -- replaced.
1359 if Present (Pragma_Argument_Associations (Prag)) then
1360 Expr :=
1361 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1363 if Nkind (Expr) = N_Null then
1364 Stmt := Make_Null_Statement (Loc);
1366 -- Preserve the original argument of the pragma by replicating it.
1367 -- Replace all references to the current instance of the type with
1368 -- references to the formal parameter.
1370 else
1371 Expr := New_Copy_Tree (Expr);
1372 Replace_Type_References (Expr, Typ);
1374 -- Generate:
1375 -- pragma Check (Default_Initial_Condition, <Expr>);
1377 Stmt :=
1378 Make_Pragma (Loc,
1379 Pragma_Identifier =>
1380 Make_Identifier (Loc, Name_Check),
1382 Pragma_Argument_Associations => New_List (
1383 Make_Pragma_Argument_Association (Loc,
1384 Expression =>
1385 Make_Identifier (Loc,
1386 Chars => Name_Default_Initial_Condition)),
1387 Make_Pragma_Argument_Association (Loc,
1388 Expression => Expr)));
1389 end if;
1391 -- Otherwise the pragma appears without an argument
1393 else
1394 Stmt := Make_Null_Statement (Loc);
1395 end if;
1397 -- Generate:
1398 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1399 -- begin
1400 -- <Stmt>;
1401 -- end <Typ>Default_Init_Cond;
1403 Body_Decl :=
1404 Make_Subprogram_Body (Loc,
1405 Specification =>
1406 Copy_Separate_Tree (Specification (Spec_Decl)),
1407 Declarations => Empty_List,
1408 Handled_Statement_Sequence =>
1409 Make_Handled_Sequence_Of_Statements (Loc,
1410 Statements => New_List (Stmt)));
1412 -- Link the spec and body of the default initial condition procedure
1413 -- to prevent the generation of a duplicate body.
1415 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1416 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1418 Insert_After_And_Analyze (Declaration_Node (Typ), Body_Decl);
1419 end Build_Default_Init_Cond_Procedure_Body;
1421 -- Local variables
1423 Decl : Node_Id;
1424 Typ : Entity_Id;
1426 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1428 begin
1429 -- Inspect the private declarations looking for [sub]type declarations
1431 Decl := First (Priv_Decls);
1432 while Present (Decl) loop
1433 if Nkind_In (Decl, N_Full_Type_Declaration,
1434 N_Subtype_Declaration)
1435 then
1436 Typ := Defining_Entity (Decl);
1438 -- Guard against partially decorate types due to previous errors
1440 if Is_Type (Typ) then
1442 -- If the type is subject to pragma Default_Initial_Condition,
1443 -- generate the body of the internal procedure which verifies
1444 -- the assertion of the pragma at run time.
1446 if Has_Default_Init_Cond (Typ) then
1447 Build_Default_Init_Cond_Procedure_Body (Typ);
1449 -- A derived type inherits the default initial condition
1450 -- procedure from its parent type.
1452 elsif Has_Inherited_Default_Init_Cond (Typ) then
1453 Inherit_Default_Init_Cond_Procedure (Typ);
1454 end if;
1455 end if;
1456 end if;
1458 Next (Decl);
1459 end loop;
1460 end Build_Default_Init_Cond_Procedure_Bodies;
1462 ---------------------------------------------------
1463 -- Build_Default_Init_Cond_Procedure_Declaration --
1464 ---------------------------------------------------
1466 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1467 Loc : constant Source_Ptr := Sloc (Typ);
1468 Prag : constant Node_Id :=
1469 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1470 Proc_Id : Entity_Id;
1472 begin
1473 -- The procedure should be generated only for types subject to pragma
1474 -- Default_Initial_Condition. Types that inherit the pragma do not get
1475 -- this specialized procedure.
1477 pragma Assert (Has_Default_Init_Cond (Typ));
1478 pragma Assert (Present (Prag));
1480 -- Nothing to do if default initial condition procedure already built
1482 if Present (Default_Init_Cond_Procedure (Typ)) then
1483 return;
1484 end if;
1486 Proc_Id :=
1487 Make_Defining_Identifier (Loc,
1488 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1490 -- Associate default initial condition procedure with the private type
1492 Set_Ekind (Proc_Id, E_Procedure);
1493 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1494 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1496 -- Generate:
1497 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1499 Insert_After_And_Analyze (Prag,
1500 Make_Subprogram_Declaration (Loc,
1501 Specification =>
1502 Make_Procedure_Specification (Loc,
1503 Defining_Unit_Name => Proc_Id,
1504 Parameter_Specifications => New_List (
1505 Make_Parameter_Specification (Loc,
1506 Defining_Identifier => Make_Temporary (Loc, 'I'),
1507 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1508 end Build_Default_Init_Cond_Procedure_Declaration;
1510 ---------------------------
1511 -- Build_Default_Subtype --
1512 ---------------------------
1514 function Build_Default_Subtype
1515 (T : Entity_Id;
1516 N : Node_Id) return Entity_Id
1518 Loc : constant Source_Ptr := Sloc (N);
1519 Disc : Entity_Id;
1521 Bas : Entity_Id;
1522 -- The base type that is to be constrained by the defaults
1524 begin
1525 if not Has_Discriminants (T) or else Is_Constrained (T) then
1526 return T;
1527 end if;
1529 Bas := Base_Type (T);
1531 -- If T is non-private but its base type is private, this is the
1532 -- completion of a subtype declaration whose parent type is private
1533 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1534 -- are to be found in the full view of the base. Check that the private
1535 -- status of T and its base differ.
1537 if Is_Private_Type (Bas)
1538 and then not Is_Private_Type (T)
1539 and then Present (Full_View (Bas))
1540 then
1541 Bas := Full_View (Bas);
1542 end if;
1544 Disc := First_Discriminant (T);
1546 if No (Discriminant_Default_Value (Disc)) then
1547 return T;
1548 end if;
1550 declare
1551 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1552 Constraints : constant List_Id := New_List;
1553 Decl : Node_Id;
1555 begin
1556 while Present (Disc) loop
1557 Append_To (Constraints,
1558 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1559 Next_Discriminant (Disc);
1560 end loop;
1562 Decl :=
1563 Make_Subtype_Declaration (Loc,
1564 Defining_Identifier => Act,
1565 Subtype_Indication =>
1566 Make_Subtype_Indication (Loc,
1567 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1568 Constraint =>
1569 Make_Index_Or_Discriminant_Constraint (Loc,
1570 Constraints => Constraints)));
1572 Insert_Action (N, Decl);
1573 Analyze (Decl);
1574 return Act;
1575 end;
1576 end Build_Default_Subtype;
1578 --------------------------------------------
1579 -- Build_Discriminal_Subtype_Of_Component --
1580 --------------------------------------------
1582 function Build_Discriminal_Subtype_Of_Component
1583 (T : Entity_Id) return Node_Id
1585 Loc : constant Source_Ptr := Sloc (T);
1586 D : Elmt_Id;
1587 Id : Node_Id;
1589 function Build_Discriminal_Array_Constraint return List_Id;
1590 -- If one or more of the bounds of the component depends on
1591 -- discriminants, build actual constraint using the discriminants
1592 -- of the prefix.
1594 function Build_Discriminal_Record_Constraint return List_Id;
1595 -- Similar to previous one, for discriminated components constrained by
1596 -- the discriminant of the enclosing object.
1598 ----------------------------------------
1599 -- Build_Discriminal_Array_Constraint --
1600 ----------------------------------------
1602 function Build_Discriminal_Array_Constraint return List_Id is
1603 Constraints : constant List_Id := New_List;
1604 Indx : Node_Id;
1605 Hi : Node_Id;
1606 Lo : Node_Id;
1607 Old_Hi : Node_Id;
1608 Old_Lo : Node_Id;
1610 begin
1611 Indx := First_Index (T);
1612 while Present (Indx) loop
1613 Old_Lo := Type_Low_Bound (Etype (Indx));
1614 Old_Hi := Type_High_Bound (Etype (Indx));
1616 if Denotes_Discriminant (Old_Lo) then
1617 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1619 else
1620 Lo := New_Copy_Tree (Old_Lo);
1621 end if;
1623 if Denotes_Discriminant (Old_Hi) then
1624 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1626 else
1627 Hi := New_Copy_Tree (Old_Hi);
1628 end if;
1630 Append (Make_Range (Loc, Lo, Hi), Constraints);
1631 Next_Index (Indx);
1632 end loop;
1634 return Constraints;
1635 end Build_Discriminal_Array_Constraint;
1637 -----------------------------------------
1638 -- Build_Discriminal_Record_Constraint --
1639 -----------------------------------------
1641 function Build_Discriminal_Record_Constraint return List_Id is
1642 Constraints : constant List_Id := New_List;
1643 D : Elmt_Id;
1644 D_Val : Node_Id;
1646 begin
1647 D := First_Elmt (Discriminant_Constraint (T));
1648 while Present (D) loop
1649 if Denotes_Discriminant (Node (D)) then
1650 D_Val :=
1651 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1652 else
1653 D_Val := New_Copy_Tree (Node (D));
1654 end if;
1656 Append (D_Val, Constraints);
1657 Next_Elmt (D);
1658 end loop;
1660 return Constraints;
1661 end Build_Discriminal_Record_Constraint;
1663 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1665 begin
1666 if Ekind (T) = E_Array_Subtype then
1667 Id := First_Index (T);
1668 while Present (Id) loop
1669 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1670 or else
1671 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1672 then
1673 return Build_Component_Subtype
1674 (Build_Discriminal_Array_Constraint, Loc, T);
1675 end if;
1677 Next_Index (Id);
1678 end loop;
1680 elsif Ekind (T) = E_Record_Subtype
1681 and then Has_Discriminants (T)
1682 and then not Has_Unknown_Discriminants (T)
1683 then
1684 D := First_Elmt (Discriminant_Constraint (T));
1685 while Present (D) loop
1686 if Denotes_Discriminant (Node (D)) then
1687 return Build_Component_Subtype
1688 (Build_Discriminal_Record_Constraint, Loc, T);
1689 end if;
1691 Next_Elmt (D);
1692 end loop;
1693 end if;
1695 -- If none of the above, the actual and nominal subtypes are the same
1697 return Empty;
1698 end Build_Discriminal_Subtype_Of_Component;
1700 ------------------------------
1701 -- Build_Elaboration_Entity --
1702 ------------------------------
1704 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1705 Loc : constant Source_Ptr := Sloc (N);
1706 Decl : Node_Id;
1707 Elab_Ent : Entity_Id;
1709 procedure Set_Package_Name (Ent : Entity_Id);
1710 -- Given an entity, sets the fully qualified name of the entity in
1711 -- Name_Buffer, with components separated by double underscores. This
1712 -- is a recursive routine that climbs the scope chain to Standard.
1714 ----------------------
1715 -- Set_Package_Name --
1716 ----------------------
1718 procedure Set_Package_Name (Ent : Entity_Id) is
1719 begin
1720 if Scope (Ent) /= Standard_Standard then
1721 Set_Package_Name (Scope (Ent));
1723 declare
1724 Nam : constant String := Get_Name_String (Chars (Ent));
1725 begin
1726 Name_Buffer (Name_Len + 1) := '_';
1727 Name_Buffer (Name_Len + 2) := '_';
1728 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1729 Name_Len := Name_Len + Nam'Length + 2;
1730 end;
1732 else
1733 Get_Name_String (Chars (Ent));
1734 end if;
1735 end Set_Package_Name;
1737 -- Start of processing for Build_Elaboration_Entity
1739 begin
1740 -- Ignore call if already constructed
1742 if Present (Elaboration_Entity (Spec_Id)) then
1743 return;
1745 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1746 -- no role in analysis.
1748 elsif ASIS_Mode then
1749 return;
1751 -- See if we need elaboration entity. We always need it for the dynamic
1752 -- elaboration model, since it is needed to properly generate the PE
1753 -- exception for access before elaboration.
1755 elsif Dynamic_Elaboration_Checks then
1756 null;
1758 -- For the static model, we don't need the elaboration counter if this
1759 -- unit is sure to have no elaboration code, since that means there
1760 -- is no elaboration unit to be called. Note that we can't just decide
1761 -- after the fact by looking to see whether there was elaboration code,
1762 -- because that's too late to make this decision.
1764 elsif Restriction_Active (No_Elaboration_Code) then
1765 return;
1767 -- Similarly, for the static model, we can skip the elaboration counter
1768 -- if we have the No_Multiple_Elaboration restriction, since for the
1769 -- static model, that's the only purpose of the counter (to avoid
1770 -- multiple elaboration).
1772 elsif Restriction_Active (No_Multiple_Elaboration) then
1773 return;
1774 end if;
1776 -- Here we need the elaboration entity
1778 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1779 -- name with dots replaced by double underscore. We have to manually
1780 -- construct this name, since it will be elaborated in the outer scope,
1781 -- and thus will not have the unit name automatically prepended.
1783 Set_Package_Name (Spec_Id);
1784 Add_Str_To_Name_Buffer ("_E");
1786 -- Create elaboration counter
1788 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1789 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1791 Decl :=
1792 Make_Object_Declaration (Loc,
1793 Defining_Identifier => Elab_Ent,
1794 Object_Definition =>
1795 New_Occurrence_Of (Standard_Short_Integer, Loc),
1796 Expression => Make_Integer_Literal (Loc, Uint_0));
1798 Push_Scope (Standard_Standard);
1799 Add_Global_Declaration (Decl);
1800 Pop_Scope;
1802 -- Reset True_Constant indication, since we will indeed assign a value
1803 -- to the variable in the binder main. We also kill the Current_Value
1804 -- and Last_Assignment fields for the same reason.
1806 Set_Is_True_Constant (Elab_Ent, False);
1807 Set_Current_Value (Elab_Ent, Empty);
1808 Set_Last_Assignment (Elab_Ent, Empty);
1810 -- We do not want any further qualification of the name (if we did not
1811 -- do this, we would pick up the name of the generic package in the case
1812 -- of a library level generic instantiation).
1814 Set_Has_Qualified_Name (Elab_Ent);
1815 Set_Has_Fully_Qualified_Name (Elab_Ent);
1816 end Build_Elaboration_Entity;
1818 --------------------------------
1819 -- Build_Explicit_Dereference --
1820 --------------------------------
1822 procedure Build_Explicit_Dereference
1823 (Expr : Node_Id;
1824 Disc : Entity_Id)
1826 Loc : constant Source_Ptr := Sloc (Expr);
1828 begin
1829 -- An entity of a type with a reference aspect is overloaded with
1830 -- both interpretations: with and without the dereference. Now that
1831 -- the dereference is made explicit, set the type of the node properly,
1832 -- to prevent anomalies in the backend. Same if the expression is an
1833 -- overloaded function call whose return type has a reference aspect.
1835 if Is_Entity_Name (Expr) then
1836 Set_Etype (Expr, Etype (Entity (Expr)));
1838 elsif Nkind (Expr) = N_Function_Call then
1839 Set_Etype (Expr, Etype (Name (Expr)));
1840 end if;
1842 Set_Is_Overloaded (Expr, False);
1844 -- The expression will often be a generalized indexing that yields a
1845 -- container element that is then dereferenced, in which case the
1846 -- generalized indexing call is also non-overloaded.
1848 if Nkind (Expr) = N_Indexed_Component
1849 and then Present (Generalized_Indexing (Expr))
1850 then
1851 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1852 end if;
1854 Rewrite (Expr,
1855 Make_Explicit_Dereference (Loc,
1856 Prefix =>
1857 Make_Selected_Component (Loc,
1858 Prefix => Relocate_Node (Expr),
1859 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1860 Set_Etype (Prefix (Expr), Etype (Disc));
1861 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1862 end Build_Explicit_Dereference;
1864 -----------------------------------
1865 -- Cannot_Raise_Constraint_Error --
1866 -----------------------------------
1868 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1869 begin
1870 if Compile_Time_Known_Value (Expr) then
1871 return True;
1873 elsif Do_Range_Check (Expr) then
1874 return False;
1876 elsif Raises_Constraint_Error (Expr) then
1877 return False;
1879 else
1880 case Nkind (Expr) is
1881 when N_Identifier =>
1882 return True;
1884 when N_Expanded_Name =>
1885 return True;
1887 when N_Selected_Component =>
1888 return not Do_Discriminant_Check (Expr);
1890 when N_Attribute_Reference =>
1891 if Do_Overflow_Check (Expr) then
1892 return False;
1894 elsif No (Expressions (Expr)) then
1895 return True;
1897 else
1898 declare
1899 N : Node_Id;
1901 begin
1902 N := First (Expressions (Expr));
1903 while Present (N) loop
1904 if Cannot_Raise_Constraint_Error (N) then
1905 Next (N);
1906 else
1907 return False;
1908 end if;
1909 end loop;
1911 return True;
1912 end;
1913 end if;
1915 when N_Type_Conversion =>
1916 if Do_Overflow_Check (Expr)
1917 or else Do_Length_Check (Expr)
1918 or else Do_Tag_Check (Expr)
1919 then
1920 return False;
1921 else
1922 return Cannot_Raise_Constraint_Error (Expression (Expr));
1923 end if;
1925 when N_Unchecked_Type_Conversion =>
1926 return Cannot_Raise_Constraint_Error (Expression (Expr));
1928 when N_Unary_Op =>
1929 if Do_Overflow_Check (Expr) then
1930 return False;
1931 else
1932 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1933 end if;
1935 when N_Op_Divide |
1936 N_Op_Mod |
1937 N_Op_Rem
1939 if Do_Division_Check (Expr)
1940 or else
1941 Do_Overflow_Check (Expr)
1942 then
1943 return False;
1944 else
1945 return
1946 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1947 and then
1948 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1949 end if;
1951 when N_Op_Add |
1952 N_Op_And |
1953 N_Op_Concat |
1954 N_Op_Eq |
1955 N_Op_Expon |
1956 N_Op_Ge |
1957 N_Op_Gt |
1958 N_Op_Le |
1959 N_Op_Lt |
1960 N_Op_Multiply |
1961 N_Op_Ne |
1962 N_Op_Or |
1963 N_Op_Rotate_Left |
1964 N_Op_Rotate_Right |
1965 N_Op_Shift_Left |
1966 N_Op_Shift_Right |
1967 N_Op_Shift_Right_Arithmetic |
1968 N_Op_Subtract |
1969 N_Op_Xor
1971 if Do_Overflow_Check (Expr) then
1972 return False;
1973 else
1974 return
1975 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1976 and then
1977 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1978 end if;
1980 when others =>
1981 return False;
1982 end case;
1983 end if;
1984 end Cannot_Raise_Constraint_Error;
1986 -----------------------------------------
1987 -- Check_Dynamically_Tagged_Expression --
1988 -----------------------------------------
1990 procedure Check_Dynamically_Tagged_Expression
1991 (Expr : Node_Id;
1992 Typ : Entity_Id;
1993 Related_Nod : Node_Id)
1995 begin
1996 pragma Assert (Is_Tagged_Type (Typ));
1998 -- In order to avoid spurious errors when analyzing the expanded code,
1999 -- this check is done only for nodes that come from source and for
2000 -- actuals of generic instantiations.
2002 if (Comes_From_Source (Related_Nod)
2003 or else In_Generic_Actual (Expr))
2004 and then (Is_Class_Wide_Type (Etype (Expr))
2005 or else Is_Dynamically_Tagged (Expr))
2006 and then Is_Tagged_Type (Typ)
2007 and then not Is_Class_Wide_Type (Typ)
2008 then
2009 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
2010 end if;
2011 end Check_Dynamically_Tagged_Expression;
2013 --------------------------
2014 -- Check_Fully_Declared --
2015 --------------------------
2017 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
2018 begin
2019 if Ekind (T) = E_Incomplete_Type then
2021 -- Ada 2005 (AI-50217): If the type is available through a limited
2022 -- with_clause, verify that its full view has been analyzed.
2024 if From_Limited_With (T)
2025 and then Present (Non_Limited_View (T))
2026 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
2027 then
2028 -- The non-limited view is fully declared
2030 null;
2032 else
2033 Error_Msg_NE
2034 ("premature usage of incomplete}", N, First_Subtype (T));
2035 end if;
2037 -- Need comments for these tests ???
2039 elsif Has_Private_Component (T)
2040 and then not Is_Generic_Type (Root_Type (T))
2041 and then not In_Spec_Expression
2042 then
2043 -- Special case: if T is the anonymous type created for a single
2044 -- task or protected object, use the name of the source object.
2046 if Is_Concurrent_Type (T)
2047 and then not Comes_From_Source (T)
2048 and then Nkind (N) = N_Object_Declaration
2049 then
2050 Error_Msg_NE
2051 ("type of& has incomplete component",
2052 N, Defining_Identifier (N));
2053 else
2054 Error_Msg_NE
2055 ("premature usage of incomplete}",
2056 N, First_Subtype (T));
2057 end if;
2058 end if;
2059 end Check_Fully_Declared;
2061 -------------------------------------
2062 -- Check_Function_Writable_Actuals --
2063 -------------------------------------
2065 procedure Check_Function_Writable_Actuals (N : Node_Id) is
2066 Writable_Actuals_List : Elist_Id := No_Elist;
2067 Identifiers_List : Elist_Id := No_Elist;
2068 Error_Node : Node_Id := Empty;
2070 procedure Collect_Identifiers (N : Node_Id);
2071 -- In a single traversal of subtree N collect in Writable_Actuals_List
2072 -- all the actuals of functions with writable actuals, and in the list
2073 -- Identifiers_List collect all the identifiers that are not actuals of
2074 -- functions with writable actuals. If a writable actual is referenced
2075 -- twice as writable actual then Error_Node is set to reference its
2076 -- second occurrence, the error is reported, and the tree traversal
2077 -- is abandoned.
2079 function Get_Function_Id (Call : Node_Id) return Entity_Id;
2080 -- Return the entity associated with the function call
2082 procedure Preanalyze_Without_Errors (N : Node_Id);
2083 -- Preanalyze N without reporting errors. Very dubious, you can't just
2084 -- go analyzing things more than once???
2086 -------------------------
2087 -- Collect_Identifiers --
2088 -------------------------
2090 procedure Collect_Identifiers (N : Node_Id) is
2092 function Check_Node (N : Node_Id) return Traverse_Result;
2093 -- Process a single node during the tree traversal to collect the
2094 -- writable actuals of functions and all the identifiers which are
2095 -- not writable actuals of functions.
2097 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2098 -- Returns True if List has a node whose Entity is Entity (N)
2100 -------------------------
2101 -- Check_Function_Call --
2102 -------------------------
2104 function Check_Node (N : Node_Id) return Traverse_Result is
2105 Is_Writable_Actual : Boolean := False;
2106 Id : Entity_Id;
2108 begin
2109 if Nkind (N) = N_Identifier then
2111 -- No analysis possible if the entity is not decorated
2113 if No (Entity (N)) then
2114 return Skip;
2116 -- Don't collect identifiers of packages, called functions, etc
2118 elsif Ekind_In (Entity (N), E_Package,
2119 E_Function,
2120 E_Procedure,
2121 E_Entry)
2122 then
2123 return Skip;
2125 -- Analyze if N is a writable actual of a function
2127 elsif Nkind (Parent (N)) = N_Function_Call then
2128 declare
2129 Call : constant Node_Id := Parent (N);
2130 Actual : Node_Id;
2131 Formal : Node_Id;
2133 begin
2134 Id := Get_Function_Id (Call);
2136 -- In case of previous error, no check is possible
2138 if No (Id) then
2139 return Abandon;
2140 end if;
2142 Formal := First_Formal (Id);
2143 Actual := First_Actual (Call);
2144 while Present (Actual) and then Present (Formal) loop
2145 if Actual = N then
2146 if Ekind_In (Formal, E_Out_Parameter,
2147 E_In_Out_Parameter)
2148 then
2149 Is_Writable_Actual := True;
2150 end if;
2152 exit;
2153 end if;
2155 Next_Formal (Formal);
2156 Next_Actual (Actual);
2157 end loop;
2158 end;
2159 end if;
2161 if Is_Writable_Actual then
2162 if Contains (Writable_Actuals_List, N) then
2163 Error_Msg_NE
2164 ("value may be affected by call to& "
2165 & "because order of evaluation is arbitrary", N, Id);
2166 Error_Node := N;
2167 return Abandon;
2168 end if;
2170 Append_New_Elmt (N, To => Writable_Actuals_List);
2172 else
2173 if Identifiers_List = No_Elist then
2174 Identifiers_List := New_Elmt_List;
2175 end if;
2177 Append_Unique_Elmt (N, Identifiers_List);
2178 end if;
2179 end if;
2181 return OK;
2182 end Check_Node;
2184 --------------
2185 -- Contains --
2186 --------------
2188 function Contains
2189 (List : Elist_Id;
2190 N : Node_Id) return Boolean
2192 pragma Assert (Nkind (N) in N_Has_Entity);
2194 Elmt : Elmt_Id;
2196 begin
2197 if List = No_Elist then
2198 return False;
2199 end if;
2201 Elmt := First_Elmt (List);
2202 while Present (Elmt) loop
2203 if Entity (Node (Elmt)) = Entity (N) then
2204 return True;
2205 else
2206 Next_Elmt (Elmt);
2207 end if;
2208 end loop;
2210 return False;
2211 end Contains;
2213 ------------------
2214 -- Do_Traversal --
2215 ------------------
2217 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2218 -- The traversal procedure
2220 -- Start of processing for Collect_Identifiers
2222 begin
2223 if Present (Error_Node) then
2224 return;
2225 end if;
2227 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2228 return;
2229 end if;
2231 Do_Traversal (N);
2232 end Collect_Identifiers;
2234 ---------------------
2235 -- Get_Function_Id --
2236 ---------------------
2238 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2239 Nam : constant Node_Id := Name (Call);
2240 Id : Entity_Id;
2242 begin
2243 if Nkind (Nam) = N_Explicit_Dereference then
2244 Id := Etype (Nam);
2245 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2247 elsif Nkind (Nam) = N_Selected_Component then
2248 Id := Entity (Selector_Name (Nam));
2250 elsif Nkind (Nam) = N_Indexed_Component then
2251 Id := Entity (Selector_Name (Prefix (Nam)));
2253 else
2254 Id := Entity (Nam);
2255 end if;
2257 return Id;
2258 end Get_Function_Id;
2260 ---------------------------
2261 -- Preanalyze_Expression --
2262 ---------------------------
2264 procedure Preanalyze_Without_Errors (N : Node_Id) is
2265 Status : constant Boolean := Get_Ignore_Errors;
2266 begin
2267 Set_Ignore_Errors (True);
2268 Preanalyze (N);
2269 Set_Ignore_Errors (Status);
2270 end Preanalyze_Without_Errors;
2272 -- Start of processing for Check_Function_Writable_Actuals
2274 begin
2275 -- The check only applies to Ada 2012 code, and only to constructs that
2276 -- have multiple constituents whose order of evaluation is not specified
2277 -- by the language.
2279 if Ada_Version < Ada_2012
2280 or else (not (Nkind (N) in N_Op)
2281 and then not (Nkind (N) in N_Membership_Test)
2282 and then not Nkind_In (N, N_Range,
2283 N_Aggregate,
2284 N_Extension_Aggregate,
2285 N_Full_Type_Declaration,
2286 N_Function_Call,
2287 N_Procedure_Call_Statement,
2288 N_Entry_Call_Statement))
2289 or else (Nkind (N) = N_Full_Type_Declaration
2290 and then not Is_Record_Type (Defining_Identifier (N)))
2292 -- In addition, this check only applies to source code, not to code
2293 -- generated by constraint checks.
2295 or else not Comes_From_Source (N)
2296 then
2297 return;
2298 end if;
2300 -- If a construct C has two or more direct constituents that are names
2301 -- or expressions whose evaluation may occur in an arbitrary order, at
2302 -- least one of which contains a function call with an in out or out
2303 -- parameter, then the construct is legal only if: for each name N that
2304 -- is passed as a parameter of mode in out or out to some inner function
2305 -- call C2 (not including the construct C itself), there is no other
2306 -- name anywhere within a direct constituent of the construct C other
2307 -- than the one containing C2, that is known to refer to the same
2308 -- object (RM 6.4.1(6.17/3)).
2310 case Nkind (N) is
2311 when N_Range =>
2312 Collect_Identifiers (Low_Bound (N));
2313 Collect_Identifiers (High_Bound (N));
2315 when N_Op | N_Membership_Test =>
2316 declare
2317 Expr : Node_Id;
2319 begin
2320 Collect_Identifiers (Left_Opnd (N));
2322 if Present (Right_Opnd (N)) then
2323 Collect_Identifiers (Right_Opnd (N));
2324 end if;
2326 if Nkind_In (N, N_In, N_Not_In)
2327 and then Present (Alternatives (N))
2328 then
2329 Expr := First (Alternatives (N));
2330 while Present (Expr) loop
2331 Collect_Identifiers (Expr);
2333 Next (Expr);
2334 end loop;
2335 end if;
2336 end;
2338 when N_Full_Type_Declaration =>
2339 declare
2340 function Get_Record_Part (N : Node_Id) return Node_Id;
2341 -- Return the record part of this record type definition
2343 function Get_Record_Part (N : Node_Id) return Node_Id is
2344 Type_Def : constant Node_Id := Type_Definition (N);
2345 begin
2346 if Nkind (Type_Def) = N_Derived_Type_Definition then
2347 return Record_Extension_Part (Type_Def);
2348 else
2349 return Type_Def;
2350 end if;
2351 end Get_Record_Part;
2353 Comp : Node_Id;
2354 Def_Id : Entity_Id := Defining_Identifier (N);
2355 Rec : Node_Id := Get_Record_Part (N);
2357 begin
2358 -- No need to perform any analysis if the record has no
2359 -- components
2361 if No (Rec) or else No (Component_List (Rec)) then
2362 return;
2363 end if;
2365 -- Collect the identifiers starting from the deepest
2366 -- derivation. Done to report the error in the deepest
2367 -- derivation.
2369 loop
2370 if Present (Component_List (Rec)) then
2371 Comp := First (Component_Items (Component_List (Rec)));
2372 while Present (Comp) loop
2373 if Nkind (Comp) = N_Component_Declaration
2374 and then Present (Expression (Comp))
2375 then
2376 Collect_Identifiers (Expression (Comp));
2377 end if;
2379 Next (Comp);
2380 end loop;
2381 end if;
2383 exit when No (Underlying_Type (Etype (Def_Id)))
2384 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2385 = Def_Id;
2387 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2388 Rec := Get_Record_Part (Parent (Def_Id));
2389 end loop;
2390 end;
2392 when N_Subprogram_Call |
2393 N_Entry_Call_Statement =>
2394 declare
2395 Id : constant Entity_Id := Get_Function_Id (N);
2396 Formal : Node_Id;
2397 Actual : Node_Id;
2399 begin
2400 Formal := First_Formal (Id);
2401 Actual := First_Actual (N);
2402 while Present (Actual) and then Present (Formal) loop
2403 if Ekind_In (Formal, E_Out_Parameter,
2404 E_In_Out_Parameter)
2405 then
2406 Collect_Identifiers (Actual);
2407 end if;
2409 Next_Formal (Formal);
2410 Next_Actual (Actual);
2411 end loop;
2412 end;
2414 when N_Aggregate |
2415 N_Extension_Aggregate =>
2416 declare
2417 Assoc : Node_Id;
2418 Choice : Node_Id;
2419 Comp_Expr : Node_Id;
2421 begin
2422 -- Handle the N_Others_Choice of array aggregates with static
2423 -- bounds. There is no need to perform this analysis in
2424 -- aggregates without static bounds since we cannot evaluate
2425 -- if the N_Others_Choice covers several elements. There is
2426 -- no need to handle the N_Others choice of record aggregates
2427 -- since at this stage it has been already expanded by
2428 -- Resolve_Record_Aggregate.
2430 if Is_Array_Type (Etype (N))
2431 and then Nkind (N) = N_Aggregate
2432 and then Present (Aggregate_Bounds (N))
2433 and then Compile_Time_Known_Bounds (Etype (N))
2434 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2436 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2437 then
2438 declare
2439 Count_Components : Uint := Uint_0;
2440 Num_Components : Uint;
2441 Others_Assoc : Node_Id;
2442 Others_Choice : Node_Id := Empty;
2443 Others_Box_Present : Boolean := False;
2445 begin
2446 -- Count positional associations
2448 if Present (Expressions (N)) then
2449 Comp_Expr := First (Expressions (N));
2450 while Present (Comp_Expr) loop
2451 Count_Components := Count_Components + 1;
2452 Next (Comp_Expr);
2453 end loop;
2454 end if;
2456 -- Count the rest of elements and locate the N_Others
2457 -- choice (if any)
2459 Assoc := First (Component_Associations (N));
2460 while Present (Assoc) loop
2461 Choice := First (Choices (Assoc));
2462 while Present (Choice) loop
2463 if Nkind (Choice) = N_Others_Choice then
2464 Others_Assoc := Assoc;
2465 Others_Choice := Choice;
2466 Others_Box_Present := Box_Present (Assoc);
2468 -- Count several components
2470 elsif Nkind_In (Choice, N_Range,
2471 N_Subtype_Indication)
2472 or else (Is_Entity_Name (Choice)
2473 and then Is_Type (Entity (Choice)))
2474 then
2475 declare
2476 L, H : Node_Id;
2477 begin
2478 Get_Index_Bounds (Choice, L, H);
2479 pragma Assert
2480 (Compile_Time_Known_Value (L)
2481 and then Compile_Time_Known_Value (H));
2482 Count_Components :=
2483 Count_Components
2484 + Expr_Value (H) - Expr_Value (L) + 1;
2485 end;
2487 -- Count single component. No other case available
2488 -- since we are handling an aggregate with static
2489 -- bounds.
2491 else
2492 pragma Assert (Is_OK_Static_Expression (Choice)
2493 or else Nkind (Choice) = N_Identifier
2494 or else Nkind (Choice) = N_Integer_Literal);
2496 Count_Components := Count_Components + 1;
2497 end if;
2499 Next (Choice);
2500 end loop;
2502 Next (Assoc);
2503 end loop;
2505 Num_Components :=
2506 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2507 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2509 pragma Assert (Count_Components <= Num_Components);
2511 -- Handle the N_Others choice if it covers several
2512 -- components
2514 if Present (Others_Choice)
2515 and then (Num_Components - Count_Components) > 1
2516 then
2517 if not Others_Box_Present then
2519 -- At this stage, if expansion is active, the
2520 -- expression of the others choice has not been
2521 -- analyzed. Hence we generate a duplicate and
2522 -- we analyze it silently to have available the
2523 -- minimum decoration required to collect the
2524 -- identifiers.
2526 if not Expander_Active then
2527 Comp_Expr := Expression (Others_Assoc);
2528 else
2529 Comp_Expr :=
2530 New_Copy_Tree (Expression (Others_Assoc));
2531 Preanalyze_Without_Errors (Comp_Expr);
2532 end if;
2534 Collect_Identifiers (Comp_Expr);
2536 if Writable_Actuals_List /= No_Elist then
2538 -- As suggested by Robert, at current stage we
2539 -- report occurrences of this case as warnings.
2541 Error_Msg_N
2542 ("writable function parameter may affect "
2543 & "value in other component because order "
2544 & "of evaluation is unspecified??",
2545 Node (First_Elmt (Writable_Actuals_List)));
2546 end if;
2547 end if;
2548 end if;
2549 end;
2550 end if;
2552 -- Handle ancestor part of extension aggregates
2554 if Nkind (N) = N_Extension_Aggregate then
2555 Collect_Identifiers (Ancestor_Part (N));
2556 end if;
2558 -- Handle positional associations
2560 if Present (Expressions (N)) then
2561 Comp_Expr := First (Expressions (N));
2562 while Present (Comp_Expr) loop
2563 if not Is_OK_Static_Expression (Comp_Expr) then
2564 Collect_Identifiers (Comp_Expr);
2565 end if;
2567 Next (Comp_Expr);
2568 end loop;
2569 end if;
2571 -- Handle discrete associations
2573 if Present (Component_Associations (N)) then
2574 Assoc := First (Component_Associations (N));
2575 while Present (Assoc) loop
2577 if not Box_Present (Assoc) then
2578 Choice := First (Choices (Assoc));
2579 while Present (Choice) loop
2581 -- For now we skip discriminants since it requires
2582 -- performing the analysis in two phases: first one
2583 -- analyzing discriminants and second one analyzing
2584 -- the rest of components since discriminants are
2585 -- evaluated prior to components: too much extra
2586 -- work to detect a corner case???
2588 if Nkind (Choice) in N_Has_Entity
2589 and then Present (Entity (Choice))
2590 and then Ekind (Entity (Choice)) = E_Discriminant
2591 then
2592 null;
2594 elsif Box_Present (Assoc) then
2595 null;
2597 else
2598 if not Analyzed (Expression (Assoc)) then
2599 Comp_Expr :=
2600 New_Copy_Tree (Expression (Assoc));
2601 Set_Parent (Comp_Expr, Parent (N));
2602 Preanalyze_Without_Errors (Comp_Expr);
2603 else
2604 Comp_Expr := Expression (Assoc);
2605 end if;
2607 Collect_Identifiers (Comp_Expr);
2608 end if;
2610 Next (Choice);
2611 end loop;
2612 end if;
2614 Next (Assoc);
2615 end loop;
2616 end if;
2617 end;
2619 when others =>
2620 return;
2621 end case;
2623 -- No further action needed if we already reported an error
2625 if Present (Error_Node) then
2626 return;
2627 end if;
2629 -- Check if some writable argument of a function is referenced
2631 if Writable_Actuals_List /= No_Elist
2632 and then Identifiers_List /= No_Elist
2633 then
2634 declare
2635 Elmt_1 : Elmt_Id;
2636 Elmt_2 : Elmt_Id;
2638 begin
2639 Elmt_1 := First_Elmt (Writable_Actuals_List);
2640 while Present (Elmt_1) loop
2641 Elmt_2 := First_Elmt (Identifiers_List);
2642 while Present (Elmt_2) loop
2643 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2644 case Nkind (Parent (Node (Elmt_2))) is
2645 when N_Aggregate |
2646 N_Component_Association |
2647 N_Component_Declaration =>
2648 Error_Msg_N
2649 ("value may be affected by call in other "
2650 & "component because they are evaluated "
2651 & "in unspecified order",
2652 Node (Elmt_2));
2654 when N_In | N_Not_In =>
2655 Error_Msg_N
2656 ("value may be affected by call in other "
2657 & "alternative because they are evaluated "
2658 & "in unspecified order",
2659 Node (Elmt_2));
2661 when others =>
2662 Error_Msg_N
2663 ("value of actual may be affected by call in "
2664 & "other actual because they are evaluated "
2665 & "in unspecified order",
2666 Node (Elmt_2));
2667 end case;
2668 end if;
2670 Next_Elmt (Elmt_2);
2671 end loop;
2673 Next_Elmt (Elmt_1);
2674 end loop;
2675 end;
2676 end if;
2677 end Check_Function_Writable_Actuals;
2679 --------------------------------
2680 -- Check_Implicit_Dereference --
2681 --------------------------------
2683 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2684 Disc : Entity_Id;
2685 Desig : Entity_Id;
2686 Nam : Node_Id;
2688 begin
2689 if Nkind (N) = N_Indexed_Component
2690 and then Present (Generalized_Indexing (N))
2691 then
2692 Nam := Generalized_Indexing (N);
2693 else
2694 Nam := N;
2695 end if;
2697 if Ada_Version < Ada_2012
2698 or else not Has_Implicit_Dereference (Base_Type (Typ))
2699 then
2700 return;
2702 elsif not Comes_From_Source (N)
2703 and then Nkind (N) /= N_Indexed_Component
2704 then
2705 return;
2707 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2708 null;
2710 else
2711 Disc := First_Discriminant (Typ);
2712 while Present (Disc) loop
2713 if Has_Implicit_Dereference (Disc) then
2714 Desig := Designated_Type (Etype (Disc));
2715 Add_One_Interp (Nam, Disc, Desig);
2717 -- If the node is a generalized indexing, add interpretation
2718 -- to that node as well, for subsequent resolution.
2720 if Nkind (N) = N_Indexed_Component then
2721 Add_One_Interp (N, Disc, Desig);
2722 end if;
2724 -- If the operation comes from a generic unit and the context
2725 -- is a selected component, the selector name may be global
2726 -- and set in the instance already. Remove the entity to
2727 -- force resolution of the selected component, and the
2728 -- generation of an explicit dereference if needed.
2730 if In_Instance
2731 and then Nkind (Parent (Nam)) = N_Selected_Component
2732 then
2733 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2734 end if;
2736 exit;
2737 end if;
2739 Next_Discriminant (Disc);
2740 end loop;
2741 end if;
2742 end Check_Implicit_Dereference;
2744 ----------------------------------
2745 -- Check_Internal_Protected_Use --
2746 ----------------------------------
2748 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2749 S : Entity_Id;
2750 Prot : Entity_Id;
2752 begin
2753 S := Current_Scope;
2754 while Present (S) loop
2755 if S = Standard_Standard then
2756 return;
2758 elsif Ekind (S) = E_Function
2759 and then Ekind (Scope (S)) = E_Protected_Type
2760 then
2761 Prot := Scope (S);
2762 exit;
2763 end if;
2765 S := Scope (S);
2766 end loop;
2768 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2770 -- An indirect function call (e.g. a callback within a protected
2771 -- function body) is not statically illegal. If the access type is
2772 -- anonymous and is the type of an access parameter, the scope of Nam
2773 -- will be the protected type, but it is not a protected operation.
2775 if Ekind (Nam) = E_Subprogram_Type
2776 and then
2777 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2778 then
2779 null;
2781 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2782 Error_Msg_N
2783 ("within protected function cannot use protected "
2784 & "procedure in renaming or as generic actual", N);
2786 elsif Nkind (N) = N_Attribute_Reference then
2787 Error_Msg_N
2788 ("within protected function cannot take access of "
2789 & " protected procedure", N);
2791 else
2792 Error_Msg_N
2793 ("within protected function, protected object is constant", N);
2794 Error_Msg_N
2795 ("\cannot call operation that may modify it", N);
2796 end if;
2797 end if;
2798 end Check_Internal_Protected_Use;
2800 ---------------------------------------
2801 -- Check_Later_Vs_Basic_Declarations --
2802 ---------------------------------------
2804 procedure Check_Later_Vs_Basic_Declarations
2805 (Decls : List_Id;
2806 During_Parsing : Boolean)
2808 Body_Sloc : Source_Ptr;
2809 Decl : Node_Id;
2811 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2812 -- Return whether Decl is considered as a declarative item.
2813 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2814 -- When During_Parsing is False, the semantics of SPARK is followed.
2816 -------------------------------
2817 -- Is_Later_Declarative_Item --
2818 -------------------------------
2820 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2821 begin
2822 if Nkind (Decl) in N_Later_Decl_Item then
2823 return True;
2825 elsif Nkind (Decl) = N_Pragma then
2826 return True;
2828 elsif During_Parsing then
2829 return False;
2831 -- In SPARK, a package declaration is not considered as a later
2832 -- declarative item.
2834 elsif Nkind (Decl) = N_Package_Declaration then
2835 return False;
2837 -- In SPARK, a renaming is considered as a later declarative item
2839 elsif Nkind (Decl) in N_Renaming_Declaration then
2840 return True;
2842 else
2843 return False;
2844 end if;
2845 end Is_Later_Declarative_Item;
2847 -- Start of Check_Later_Vs_Basic_Declarations
2849 begin
2850 Decl := First (Decls);
2852 -- Loop through sequence of basic declarative items
2854 Outer : while Present (Decl) loop
2855 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2856 and then Nkind (Decl) not in N_Body_Stub
2857 then
2858 Next (Decl);
2860 -- Once a body is encountered, we only allow later declarative
2861 -- items. The inner loop checks the rest of the list.
2863 else
2864 Body_Sloc := Sloc (Decl);
2866 Inner : while Present (Decl) loop
2867 if not Is_Later_Declarative_Item (Decl) then
2868 if During_Parsing then
2869 if Ada_Version = Ada_83 then
2870 Error_Msg_Sloc := Body_Sloc;
2871 Error_Msg_N
2872 ("(Ada 83) decl cannot appear after body#", Decl);
2873 end if;
2874 else
2875 Error_Msg_Sloc := Body_Sloc;
2876 Check_SPARK_05_Restriction
2877 ("decl cannot appear after body#", Decl);
2878 end if;
2879 end if;
2881 Next (Decl);
2882 end loop Inner;
2883 end if;
2884 end loop Outer;
2885 end Check_Later_Vs_Basic_Declarations;
2887 -------------------------
2888 -- Check_Nested_Access --
2889 -------------------------
2891 procedure Check_Nested_Access (Ent : Entity_Id) is
2892 Scop : constant Entity_Id := Current_Scope;
2893 Current_Subp : Entity_Id;
2894 Enclosing : Entity_Id;
2896 begin
2897 -- Currently only enabled for VM back-ends for efficiency, should we
2898 -- enable it more systematically ???
2900 -- Check for Is_Imported needs commenting below ???
2902 if VM_Target /= No_VM
2903 and then Ekind_In (Ent, E_Variable, E_Constant, E_Loop_Parameter)
2904 and then Scope (Ent) /= Empty
2905 and then not Is_Library_Level_Entity (Ent)
2906 and then not Is_Imported (Ent)
2907 then
2908 if Is_Subprogram (Scop)
2909 or else Is_Generic_Subprogram (Scop)
2910 or else Is_Entry (Scop)
2911 then
2912 Current_Subp := Scop;
2913 else
2914 Current_Subp := Current_Subprogram;
2915 end if;
2917 Enclosing := Enclosing_Subprogram (Ent);
2919 if Enclosing /= Empty and then Enclosing /= Current_Subp then
2920 Set_Has_Up_Level_Access (Ent, True);
2921 end if;
2922 end if;
2923 end Check_Nested_Access;
2925 ---------------------------
2926 -- Check_No_Hidden_State --
2927 ---------------------------
2929 procedure Check_No_Hidden_State (Id : Entity_Id) is
2930 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2931 -- Determine whether the entity of a package denoted by Pkg has a null
2932 -- abstract state.
2934 -----------------------------
2935 -- Has_Null_Abstract_State --
2936 -----------------------------
2938 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2939 States : constant Elist_Id := Abstract_States (Pkg);
2941 begin
2942 -- Check first available state of related package. A null abstract
2943 -- state always appears as the sole element of the state list.
2945 return
2946 Present (States)
2947 and then Is_Null_State (Node (First_Elmt (States)));
2948 end Has_Null_Abstract_State;
2950 -- Local variables
2952 Context : Entity_Id := Empty;
2953 Not_Visible : Boolean := False;
2954 Scop : Entity_Id;
2956 -- Start of processing for Check_No_Hidden_State
2958 begin
2959 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2961 -- Find the proper context where the object or state appears
2963 Scop := Scope (Id);
2964 while Present (Scop) loop
2965 Context := Scop;
2967 -- Keep track of the context's visibility
2969 Not_Visible := Not_Visible or else In_Private_Part (Context);
2971 -- Prevent the search from going too far
2973 if Context = Standard_Standard then
2974 return;
2976 -- Objects and states that appear immediately within a subprogram or
2977 -- inside a construct nested within a subprogram do not introduce a
2978 -- hidden state. They behave as local variable declarations.
2980 elsif Is_Subprogram (Context) then
2981 return;
2983 -- When examining a package body, use the entity of the spec as it
2984 -- carries the abstract state declarations.
2986 elsif Ekind (Context) = E_Package_Body then
2987 Context := Spec_Entity (Context);
2988 end if;
2990 -- Stop the traversal when a package subject to a null abstract state
2991 -- has been found.
2993 if Ekind_In (Context, E_Generic_Package, E_Package)
2994 and then Has_Null_Abstract_State (Context)
2995 then
2996 exit;
2997 end if;
2999 Scop := Scope (Scop);
3000 end loop;
3002 -- At this point we know that there is at least one package with a null
3003 -- abstract state in visibility. Emit an error message unconditionally
3004 -- if the entity being processed is a state because the placement of the
3005 -- related package is irrelevant. This is not the case for objects as
3006 -- the intermediate context matters.
3008 if Present (Context)
3009 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3010 then
3011 Error_Msg_N ("cannot introduce hidden state &", Id);
3012 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3013 end if;
3014 end Check_No_Hidden_State;
3016 ------------------------------------------
3017 -- Check_Potentially_Blocking_Operation --
3018 ------------------------------------------
3020 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3021 S : Entity_Id;
3023 begin
3024 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3025 -- When pragma Detect_Blocking is active, the run time will raise
3026 -- Program_Error. Here we only issue a warning, since we generally
3027 -- support the use of potentially blocking operations in the absence
3028 -- of the pragma.
3030 -- Indirect blocking through a subprogram call cannot be diagnosed
3031 -- statically without interprocedural analysis, so we do not attempt
3032 -- to do it here.
3034 S := Scope (Current_Scope);
3035 while Present (S) and then S /= Standard_Standard loop
3036 if Is_Protected_Type (S) then
3037 Error_Msg_N
3038 ("potentially blocking operation in protected operation??", N);
3039 return;
3040 end if;
3042 S := Scope (S);
3043 end loop;
3044 end Check_Potentially_Blocking_Operation;
3046 ---------------------------------
3047 -- Check_Result_And_Post_State --
3048 ---------------------------------
3050 procedure Check_Result_And_Post_State
3051 (Prag : Node_Id;
3052 Result_Seen : in out Boolean)
3054 procedure Check_Expression (Expr : Node_Id);
3055 -- Perform the 'Result and post-state checks on a given expression
3057 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3058 -- Attempt to find attribute 'Result in a subtree denoted by N
3060 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3061 -- Determine whether source node N denotes "True" or "False"
3063 function Mentions_Post_State (N : Node_Id) return Boolean;
3064 -- Determine whether a subtree denoted by N mentions any construct that
3065 -- denotes a post-state.
3067 procedure Check_Function_Result is
3068 new Traverse_Proc (Is_Function_Result);
3070 ----------------------
3071 -- Check_Expression --
3072 ----------------------
3074 procedure Check_Expression (Expr : Node_Id) is
3075 begin
3076 if not Is_Trivial_Boolean (Expr) then
3077 Check_Function_Result (Expr);
3079 if not Mentions_Post_State (Expr) then
3080 if Pragma_Name (Prag) = Name_Contract_Cases then
3081 Error_Msg_N
3082 ("contract case refers only to pre-state?T?", Expr);
3084 elsif Pragma_Name (Prag) = Name_Refined_Post then
3085 Error_Msg_N
3086 ("refined postcondition refers only to pre-state?T?",
3087 Prag);
3089 else
3090 Error_Msg_N
3091 ("postcondition refers only to pre-state?T?", Prag);
3092 end if;
3093 end if;
3094 end if;
3095 end Check_Expression;
3097 ------------------------
3098 -- Is_Function_Result --
3099 ------------------------
3101 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3102 begin
3103 if Is_Attribute_Result (N) then
3104 Result_Seen := True;
3105 return Abandon;
3107 -- Continue the traversal
3109 else
3110 return OK;
3111 end if;
3112 end Is_Function_Result;
3114 ------------------------
3115 -- Is_Trivial_Boolean --
3116 ------------------------
3118 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3119 begin
3120 return
3121 Comes_From_Source (N)
3122 and then Is_Entity_Name (N)
3123 and then (Entity (N) = Standard_True
3124 or else
3125 Entity (N) = Standard_False);
3126 end Is_Trivial_Boolean;
3128 -------------------------
3129 -- Mentions_Post_State --
3130 -------------------------
3132 function Mentions_Post_State (N : Node_Id) return Boolean is
3133 Post_State_Seen : Boolean := False;
3135 function Is_Post_State (N : Node_Id) return Traverse_Result;
3136 -- Attempt to find a construct that denotes a post-state. If this is
3137 -- the case, set flag Post_State_Seen.
3139 -------------------
3140 -- Is_Post_State --
3141 -------------------
3143 function Is_Post_State (N : Node_Id) return Traverse_Result is
3144 Ent : Entity_Id;
3146 begin
3147 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3148 Post_State_Seen := True;
3149 return Abandon;
3151 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3152 Ent := Entity (N);
3154 -- The entity may be modifiable through an implicit dereference
3156 if No (Ent)
3157 or else Ekind (Ent) in Assignable_Kind
3158 or else (Is_Access_Type (Etype (Ent))
3159 and then Nkind (Parent (N)) = N_Selected_Component)
3160 then
3161 Post_State_Seen := True;
3162 return Abandon;
3163 end if;
3165 elsif Nkind (N) = N_Attribute_Reference then
3166 if Attribute_Name (N) = Name_Old then
3167 return Skip;
3169 elsif Attribute_Name (N) = Name_Result then
3170 Post_State_Seen := True;
3171 return Abandon;
3172 end if;
3173 end if;
3175 return OK;
3176 end Is_Post_State;
3178 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3180 -- Start of processing for Mentions_Post_State
3182 begin
3183 Find_Post_State (N);
3185 return Post_State_Seen;
3186 end Mentions_Post_State;
3188 -- Local variables
3190 Expr : constant Node_Id :=
3191 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
3192 Nam : constant Name_Id := Pragma_Name (Prag);
3193 CCase : Node_Id;
3195 -- Start of processing for Check_Result_And_Post_State
3197 begin
3198 -- Examine all consequences
3200 if Nam = Name_Contract_Cases then
3201 CCase := First (Component_Associations (Expr));
3202 while Present (CCase) loop
3203 Check_Expression (Expression (CCase));
3205 Next (CCase);
3206 end loop;
3208 -- Examine the expression of a postcondition
3210 else pragma Assert (Nam_In (Nam, Name_Postcondition, Name_Refined_Post));
3211 Check_Expression (Expr);
3212 end if;
3213 end Check_Result_And_Post_State;
3215 ------------------------------
3216 -- Check_Unprotected_Access --
3217 ------------------------------
3219 procedure Check_Unprotected_Access
3220 (Context : Node_Id;
3221 Expr : Node_Id)
3223 Cont_Encl_Typ : Entity_Id;
3224 Pref_Encl_Typ : Entity_Id;
3226 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3227 -- Check whether Obj is a private component of a protected object.
3228 -- Return the protected type where the component resides, Empty
3229 -- otherwise.
3231 function Is_Public_Operation return Boolean;
3232 -- Verify that the enclosing operation is callable from outside the
3233 -- protected object, to minimize false positives.
3235 ------------------------------
3236 -- Enclosing_Protected_Type --
3237 ------------------------------
3239 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3240 begin
3241 if Is_Entity_Name (Obj) then
3242 declare
3243 Ent : Entity_Id := Entity (Obj);
3245 begin
3246 -- The object can be a renaming of a private component, use
3247 -- the original record component.
3249 if Is_Prival (Ent) then
3250 Ent := Prival_Link (Ent);
3251 end if;
3253 if Is_Protected_Type (Scope (Ent)) then
3254 return Scope (Ent);
3255 end if;
3256 end;
3257 end if;
3259 -- For indexed and selected components, recursively check the prefix
3261 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3262 return Enclosing_Protected_Type (Prefix (Obj));
3264 -- The object does not denote a protected component
3266 else
3267 return Empty;
3268 end if;
3269 end Enclosing_Protected_Type;
3271 -------------------------
3272 -- Is_Public_Operation --
3273 -------------------------
3275 function Is_Public_Operation return Boolean is
3276 S : Entity_Id;
3277 E : Entity_Id;
3279 begin
3280 S := Current_Scope;
3281 while Present (S) and then S /= Pref_Encl_Typ loop
3282 if Scope (S) = Pref_Encl_Typ then
3283 E := First_Entity (Pref_Encl_Typ);
3284 while Present (E)
3285 and then E /= First_Private_Entity (Pref_Encl_Typ)
3286 loop
3287 if E = S then
3288 return True;
3289 end if;
3291 Next_Entity (E);
3292 end loop;
3293 end if;
3295 S := Scope (S);
3296 end loop;
3298 return False;
3299 end Is_Public_Operation;
3301 -- Start of processing for Check_Unprotected_Access
3303 begin
3304 if Nkind (Expr) = N_Attribute_Reference
3305 and then Attribute_Name (Expr) = Name_Unchecked_Access
3306 then
3307 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3308 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3310 -- Check whether we are trying to export a protected component to a
3311 -- context with an equal or lower access level.
3313 if Present (Pref_Encl_Typ)
3314 and then No (Cont_Encl_Typ)
3315 and then Is_Public_Operation
3316 and then Scope_Depth (Pref_Encl_Typ) >=
3317 Object_Access_Level (Context)
3318 then
3319 Error_Msg_N
3320 ("??possible unprotected access to protected data", Expr);
3321 end if;
3322 end if;
3323 end Check_Unprotected_Access;
3325 ------------------------
3326 -- Collect_Interfaces --
3327 ------------------------
3329 procedure Collect_Interfaces
3330 (T : Entity_Id;
3331 Ifaces_List : out Elist_Id;
3332 Exclude_Parents : Boolean := False;
3333 Use_Full_View : Boolean := True)
3335 procedure Collect (Typ : Entity_Id);
3336 -- Subsidiary subprogram used to traverse the whole list
3337 -- of directly and indirectly implemented interfaces
3339 -------------
3340 -- Collect --
3341 -------------
3343 procedure Collect (Typ : Entity_Id) is
3344 Ancestor : Entity_Id;
3345 Full_T : Entity_Id;
3346 Id : Node_Id;
3347 Iface : Entity_Id;
3349 begin
3350 Full_T := Typ;
3352 -- Handle private types
3354 if Use_Full_View
3355 and then Is_Private_Type (Typ)
3356 and then Present (Full_View (Typ))
3357 then
3358 Full_T := Full_View (Typ);
3359 end if;
3361 -- Include the ancestor if we are generating the whole list of
3362 -- abstract interfaces.
3364 if Etype (Full_T) /= Typ
3366 -- Protect the frontend against wrong sources. For example:
3368 -- package P is
3369 -- type A is tagged null record;
3370 -- type B is new A with private;
3371 -- type C is new A with private;
3372 -- private
3373 -- type B is new C with null record;
3374 -- type C is new B with null record;
3375 -- end P;
3377 and then Etype (Full_T) /= T
3378 then
3379 Ancestor := Etype (Full_T);
3380 Collect (Ancestor);
3382 if Is_Interface (Ancestor) and then not Exclude_Parents then
3383 Append_Unique_Elmt (Ancestor, Ifaces_List);
3384 end if;
3385 end if;
3387 -- Traverse the graph of ancestor interfaces
3389 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3390 Id := First (Abstract_Interface_List (Full_T));
3391 while Present (Id) loop
3392 Iface := Etype (Id);
3394 -- Protect against wrong uses. For example:
3395 -- type I is interface;
3396 -- type O is tagged null record;
3397 -- type Wrong is new I and O with null record; -- ERROR
3399 if Is_Interface (Iface) then
3400 if Exclude_Parents
3401 and then Etype (T) /= T
3402 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3403 then
3404 null;
3405 else
3406 Collect (Iface);
3407 Append_Unique_Elmt (Iface, Ifaces_List);
3408 end if;
3409 end if;
3411 Next (Id);
3412 end loop;
3413 end if;
3414 end Collect;
3416 -- Start of processing for Collect_Interfaces
3418 begin
3419 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3420 Ifaces_List := New_Elmt_List;
3421 Collect (T);
3422 end Collect_Interfaces;
3424 ----------------------------------
3425 -- Collect_Interface_Components --
3426 ----------------------------------
3428 procedure Collect_Interface_Components
3429 (Tagged_Type : Entity_Id;
3430 Components_List : out Elist_Id)
3432 procedure Collect (Typ : Entity_Id);
3433 -- Subsidiary subprogram used to climb to the parents
3435 -------------
3436 -- Collect --
3437 -------------
3439 procedure Collect (Typ : Entity_Id) is
3440 Tag_Comp : Entity_Id;
3441 Parent_Typ : Entity_Id;
3443 begin
3444 -- Handle private types
3446 if Present (Full_View (Etype (Typ))) then
3447 Parent_Typ := Full_View (Etype (Typ));
3448 else
3449 Parent_Typ := Etype (Typ);
3450 end if;
3452 if Parent_Typ /= Typ
3454 -- Protect the frontend against wrong sources. For example:
3456 -- package P is
3457 -- type A is tagged null record;
3458 -- type B is new A with private;
3459 -- type C is new A with private;
3460 -- private
3461 -- type B is new C with null record;
3462 -- type C is new B with null record;
3463 -- end P;
3465 and then Parent_Typ /= Tagged_Type
3466 then
3467 Collect (Parent_Typ);
3468 end if;
3470 -- Collect the components containing tags of secondary dispatch
3471 -- tables.
3473 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3474 while Present (Tag_Comp) loop
3475 pragma Assert (Present (Related_Type (Tag_Comp)));
3476 Append_Elmt (Tag_Comp, Components_List);
3478 Tag_Comp := Next_Tag_Component (Tag_Comp);
3479 end loop;
3480 end Collect;
3482 -- Start of processing for Collect_Interface_Components
3484 begin
3485 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3486 and then Is_Tagged_Type (Tagged_Type));
3488 Components_List := New_Elmt_List;
3489 Collect (Tagged_Type);
3490 end Collect_Interface_Components;
3492 -----------------------------
3493 -- Collect_Interfaces_Info --
3494 -----------------------------
3496 procedure Collect_Interfaces_Info
3497 (T : Entity_Id;
3498 Ifaces_List : out Elist_Id;
3499 Components_List : out Elist_Id;
3500 Tags_List : out Elist_Id)
3502 Comps_List : Elist_Id;
3503 Comp_Elmt : Elmt_Id;
3504 Comp_Iface : Entity_Id;
3505 Iface_Elmt : Elmt_Id;
3506 Iface : Entity_Id;
3508 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3509 -- Search for the secondary tag associated with the interface type
3510 -- Iface that is implemented by T.
3512 ----------------
3513 -- Search_Tag --
3514 ----------------
3516 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3517 ADT : Elmt_Id;
3518 begin
3519 if not Is_CPP_Class (T) then
3520 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3521 else
3522 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3523 end if;
3525 while Present (ADT)
3526 and then Is_Tag (Node (ADT))
3527 and then Related_Type (Node (ADT)) /= Iface
3528 loop
3529 -- Skip secondary dispatch table referencing thunks to user
3530 -- defined primitives covered by this interface.
3532 pragma Assert (Has_Suffix (Node (ADT), 'P'));
3533 Next_Elmt (ADT);
3535 -- Skip secondary dispatch tables of Ada types
3537 if not Is_CPP_Class (T) then
3539 -- Skip secondary dispatch table referencing thunks to
3540 -- predefined primitives.
3542 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
3543 Next_Elmt (ADT);
3545 -- Skip secondary dispatch table referencing user-defined
3546 -- primitives covered by this interface.
3548 pragma Assert (Has_Suffix (Node (ADT), 'D'));
3549 Next_Elmt (ADT);
3551 -- Skip secondary dispatch table referencing predefined
3552 -- primitives.
3554 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
3555 Next_Elmt (ADT);
3556 end if;
3557 end loop;
3559 pragma Assert (Is_Tag (Node (ADT)));
3560 return Node (ADT);
3561 end Search_Tag;
3563 -- Start of processing for Collect_Interfaces_Info
3565 begin
3566 Collect_Interfaces (T, Ifaces_List);
3567 Collect_Interface_Components (T, Comps_List);
3569 -- Search for the record component and tag associated with each
3570 -- interface type of T.
3572 Components_List := New_Elmt_List;
3573 Tags_List := New_Elmt_List;
3575 Iface_Elmt := First_Elmt (Ifaces_List);
3576 while Present (Iface_Elmt) loop
3577 Iface := Node (Iface_Elmt);
3579 -- Associate the primary tag component and the primary dispatch table
3580 -- with all the interfaces that are parents of T
3582 if Is_Ancestor (Iface, T, Use_Full_View => True) then
3583 Append_Elmt (First_Tag_Component (T), Components_List);
3584 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
3586 -- Otherwise search for the tag component and secondary dispatch
3587 -- table of Iface
3589 else
3590 Comp_Elmt := First_Elmt (Comps_List);
3591 while Present (Comp_Elmt) loop
3592 Comp_Iface := Related_Type (Node (Comp_Elmt));
3594 if Comp_Iface = Iface
3595 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
3596 then
3597 Append_Elmt (Node (Comp_Elmt), Components_List);
3598 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
3599 exit;
3600 end if;
3602 Next_Elmt (Comp_Elmt);
3603 end loop;
3604 pragma Assert (Present (Comp_Elmt));
3605 end if;
3607 Next_Elmt (Iface_Elmt);
3608 end loop;
3609 end Collect_Interfaces_Info;
3611 ---------------------
3612 -- Collect_Parents --
3613 ---------------------
3615 procedure Collect_Parents
3616 (T : Entity_Id;
3617 List : out Elist_Id;
3618 Use_Full_View : Boolean := True)
3620 Current_Typ : Entity_Id := T;
3621 Parent_Typ : Entity_Id;
3623 begin
3624 List := New_Elmt_List;
3626 -- No action if the if the type has no parents
3628 if T = Etype (T) then
3629 return;
3630 end if;
3632 loop
3633 Parent_Typ := Etype (Current_Typ);
3635 if Is_Private_Type (Parent_Typ)
3636 and then Present (Full_View (Parent_Typ))
3637 and then Use_Full_View
3638 then
3639 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3640 end if;
3642 Append_Elmt (Parent_Typ, List);
3644 exit when Parent_Typ = Current_Typ;
3645 Current_Typ := Parent_Typ;
3646 end loop;
3647 end Collect_Parents;
3649 ----------------------------------
3650 -- Collect_Primitive_Operations --
3651 ----------------------------------
3653 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
3654 B_Type : constant Entity_Id := Base_Type (T);
3655 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
3656 B_Scope : Entity_Id := Scope (B_Type);
3657 Op_List : Elist_Id;
3658 Formal : Entity_Id;
3659 Is_Prim : Boolean;
3660 Is_Type_In_Pkg : Boolean;
3661 Formal_Derived : Boolean := False;
3662 Id : Entity_Id;
3664 function Match (E : Entity_Id) return Boolean;
3665 -- True if E's base type is B_Type, or E is of an anonymous access type
3666 -- and the base type of its designated type is B_Type.
3668 -----------
3669 -- Match --
3670 -----------
3672 function Match (E : Entity_Id) return Boolean is
3673 Etyp : Entity_Id := Etype (E);
3675 begin
3676 if Ekind (Etyp) = E_Anonymous_Access_Type then
3677 Etyp := Designated_Type (Etyp);
3678 end if;
3680 -- In Ada 2012 a primitive operation may have a formal of an
3681 -- incomplete view of the parent type.
3683 return Base_Type (Etyp) = B_Type
3684 or else
3685 (Ada_Version >= Ada_2012
3686 and then Ekind (Etyp) = E_Incomplete_Type
3687 and then Full_View (Etyp) = B_Type);
3688 end Match;
3690 -- Start of processing for Collect_Primitive_Operations
3692 begin
3693 -- For tagged types, the primitive operations are collected as they
3694 -- are declared, and held in an explicit list which is simply returned.
3696 if Is_Tagged_Type (B_Type) then
3697 return Primitive_Operations (B_Type);
3699 -- An untagged generic type that is a derived type inherits the
3700 -- primitive operations of its parent type. Other formal types only
3701 -- have predefined operators, which are not explicitly represented.
3703 elsif Is_Generic_Type (B_Type) then
3704 if Nkind (B_Decl) = N_Formal_Type_Declaration
3705 and then Nkind (Formal_Type_Definition (B_Decl)) =
3706 N_Formal_Derived_Type_Definition
3707 then
3708 Formal_Derived := True;
3709 else
3710 return New_Elmt_List;
3711 end if;
3712 end if;
3714 Op_List := New_Elmt_List;
3716 if B_Scope = Standard_Standard then
3717 if B_Type = Standard_String then
3718 Append_Elmt (Standard_Op_Concat, Op_List);
3720 elsif B_Type = Standard_Wide_String then
3721 Append_Elmt (Standard_Op_Concatw, Op_List);
3723 else
3724 null;
3725 end if;
3727 -- Locate the primitive subprograms of the type
3729 else
3730 -- The primitive operations appear after the base type, except
3731 -- if the derivation happens within the private part of B_Scope
3732 -- and the type is a private type, in which case both the type
3733 -- and some primitive operations may appear before the base
3734 -- type, and the list of candidates starts after the type.
3736 if In_Open_Scopes (B_Scope)
3737 and then Scope (T) = B_Scope
3738 and then In_Private_Part (B_Scope)
3739 then
3740 Id := Next_Entity (T);
3742 -- In Ada 2012, If the type has an incomplete partial view, there
3743 -- may be primitive operations declared before the full view, so
3744 -- we need to start scanning from the incomplete view, which is
3745 -- earlier on the entity chain.
3747 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
3748 and then Present (Incomplete_View (Parent (B_Type)))
3749 then
3750 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
3752 else
3753 Id := Next_Entity (B_Type);
3754 end if;
3756 -- Set flag if this is a type in a package spec
3758 Is_Type_In_Pkg :=
3759 Is_Package_Or_Generic_Package (B_Scope)
3760 and then
3761 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
3762 N_Package_Body;
3764 while Present (Id) loop
3766 -- Test whether the result type or any of the parameter types of
3767 -- each subprogram following the type match that type when the
3768 -- type is declared in a package spec, is a derived type, or the
3769 -- subprogram is marked as primitive. (The Is_Primitive test is
3770 -- needed to find primitives of nonderived types in declarative
3771 -- parts that happen to override the predefined "=" operator.)
3773 -- Note that generic formal subprograms are not considered to be
3774 -- primitive operations and thus are never inherited.
3776 if Is_Overloadable (Id)
3777 and then (Is_Type_In_Pkg
3778 or else Is_Derived_Type (B_Type)
3779 or else Is_Primitive (Id))
3780 and then Nkind (Parent (Parent (Id)))
3781 not in N_Formal_Subprogram_Declaration
3782 then
3783 Is_Prim := False;
3785 if Match (Id) then
3786 Is_Prim := True;
3788 else
3789 Formal := First_Formal (Id);
3790 while Present (Formal) loop
3791 if Match (Formal) then
3792 Is_Prim := True;
3793 exit;
3794 end if;
3796 Next_Formal (Formal);
3797 end loop;
3798 end if;
3800 -- For a formal derived type, the only primitives are the ones
3801 -- inherited from the parent type. Operations appearing in the
3802 -- package declaration are not primitive for it.
3804 if Is_Prim
3805 and then (not Formal_Derived or else Present (Alias (Id)))
3806 then
3807 -- In the special case of an equality operator aliased to
3808 -- an overriding dispatching equality belonging to the same
3809 -- type, we don't include it in the list of primitives.
3810 -- This avoids inheriting multiple equality operators when
3811 -- deriving from untagged private types whose full type is
3812 -- tagged, which can otherwise cause ambiguities. Note that
3813 -- this should only happen for this kind of untagged parent
3814 -- type, since normally dispatching operations are inherited
3815 -- using the type's Primitive_Operations list.
3817 if Chars (Id) = Name_Op_Eq
3818 and then Is_Dispatching_Operation (Id)
3819 and then Present (Alias (Id))
3820 and then Present (Overridden_Operation (Alias (Id)))
3821 and then Base_Type (Etype (First_Entity (Id))) =
3822 Base_Type (Etype (First_Entity (Alias (Id))))
3823 then
3824 null;
3826 -- Include the subprogram in the list of primitives
3828 else
3829 Append_Elmt (Id, Op_List);
3830 end if;
3831 end if;
3832 end if;
3834 Next_Entity (Id);
3836 -- For a type declared in System, some of its operations may
3837 -- appear in the target-specific extension to System.
3839 if No (Id)
3840 and then B_Scope = RTU_Entity (System)
3841 and then Present_System_Aux
3842 then
3843 B_Scope := System_Aux_Id;
3844 Id := First_Entity (System_Aux_Id);
3845 end if;
3846 end loop;
3847 end if;
3849 return Op_List;
3850 end Collect_Primitive_Operations;
3852 -----------------------------------
3853 -- Compile_Time_Constraint_Error --
3854 -----------------------------------
3856 function Compile_Time_Constraint_Error
3857 (N : Node_Id;
3858 Msg : String;
3859 Ent : Entity_Id := Empty;
3860 Loc : Source_Ptr := No_Location;
3861 Warn : Boolean := False) return Node_Id
3863 Msgc : String (1 .. Msg'Length + 3);
3864 -- Copy of message, with room for possible ?? or << and ! at end
3866 Msgl : Natural;
3867 Wmsg : Boolean;
3868 Eloc : Source_Ptr;
3870 -- Start of processing for Compile_Time_Constraint_Error
3872 begin
3873 -- If this is a warning, convert it into an error if we are in code
3874 -- subject to SPARK_Mode being set ON.
3876 Error_Msg_Warn := SPARK_Mode /= On;
3878 -- A static constraint error in an instance body is not a fatal error.
3879 -- we choose to inhibit the message altogether, because there is no
3880 -- obvious node (for now) on which to post it. On the other hand the
3881 -- offending node must be replaced with a constraint_error in any case.
3883 -- No messages are generated if we already posted an error on this node
3885 if not Error_Posted (N) then
3886 if Loc /= No_Location then
3887 Eloc := Loc;
3888 else
3889 Eloc := Sloc (N);
3890 end if;
3892 -- Copy message to Msgc, converting any ? in the message into
3893 -- < instead, so that we have an error in GNATprove mode.
3895 Msgl := Msg'Length;
3897 for J in 1 .. Msgl loop
3898 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
3899 Msgc (J) := '<';
3900 else
3901 Msgc (J) := Msg (J);
3902 end if;
3903 end loop;
3905 -- Message is a warning, even in Ada 95 case
3907 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
3908 Wmsg := True;
3910 -- In Ada 83, all messages are warnings. In the private part and
3911 -- the body of an instance, constraint_checks are only warnings.
3912 -- We also make this a warning if the Warn parameter is set.
3914 elsif Warn
3915 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
3916 then
3917 Msgl := Msgl + 1;
3918 Msgc (Msgl) := '<';
3919 Msgl := Msgl + 1;
3920 Msgc (Msgl) := '<';
3921 Wmsg := True;
3923 elsif In_Instance_Not_Visible then
3924 Msgl := Msgl + 1;
3925 Msgc (Msgl) := '<';
3926 Msgl := Msgl + 1;
3927 Msgc (Msgl) := '<';
3928 Wmsg := True;
3930 -- Otherwise we have a real error message (Ada 95 static case)
3931 -- and we make this an unconditional message. Note that in the
3932 -- warning case we do not make the message unconditional, it seems
3933 -- quite reasonable to delete messages like this (about exceptions
3934 -- that will be raised) in dead code.
3936 else
3937 Wmsg := False;
3938 Msgl := Msgl + 1;
3939 Msgc (Msgl) := '!';
3940 end if;
3942 -- One more test, skip the warning if the related expression is
3943 -- statically unevaluated, since we don't want to warn about what
3944 -- will happen when something is evaluated if it never will be
3945 -- evaluated.
3947 if not Is_Statically_Unevaluated (N) then
3948 Error_Msg_Warn := SPARK_Mode /= On;
3950 if Present (Ent) then
3951 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
3952 else
3953 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
3954 end if;
3956 if Wmsg then
3958 -- Check whether the context is an Init_Proc
3960 if Inside_Init_Proc then
3961 declare
3962 Conc_Typ : constant Entity_Id :=
3963 Corresponding_Concurrent_Type
3964 (Entity (Parameter_Type (First
3965 (Parameter_Specifications
3966 (Parent (Current_Scope))))));
3968 begin
3969 -- Don't complain if the corresponding concurrent type
3970 -- doesn't come from source (i.e. a single task/protected
3971 -- object).
3973 if Present (Conc_Typ)
3974 and then not Comes_From_Source (Conc_Typ)
3975 then
3976 Error_Msg_NEL
3977 ("\& [<<", N, Standard_Constraint_Error, Eloc);
3979 else
3980 if GNATprove_Mode then
3981 Error_Msg_NEL
3982 ("\& would have been raised for objects of this "
3983 & "type", N, Standard_Constraint_Error, Eloc);
3984 else
3985 Error_Msg_NEL
3986 ("\& will be raised for objects of this type??",
3987 N, Standard_Constraint_Error, Eloc);
3988 end if;
3989 end if;
3990 end;
3992 else
3993 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
3994 end if;
3996 else
3997 Error_Msg ("\static expression fails Constraint_Check", Eloc);
3998 Set_Error_Posted (N);
3999 end if;
4000 end if;
4001 end if;
4003 return N;
4004 end Compile_Time_Constraint_Error;
4006 -----------------------
4007 -- Conditional_Delay --
4008 -----------------------
4010 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4011 begin
4012 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4013 Set_Has_Delayed_Freeze (New_Ent);
4014 end if;
4015 end Conditional_Delay;
4017 ----------------------------
4018 -- Contains_Refined_State --
4019 ----------------------------
4021 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4022 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4023 -- Determine whether a dependency list mentions a state with a visible
4024 -- refinement.
4026 function Has_State_In_Global (List : Node_Id) return Boolean;
4027 -- Determine whether a global list mentions a state with a visible
4028 -- refinement.
4030 function Is_Refined_State (Item : Node_Id) return Boolean;
4031 -- Determine whether Item is a reference to an abstract state with a
4032 -- visible refinement.
4034 -----------------------------
4035 -- Has_State_In_Dependency --
4036 -----------------------------
4038 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4039 Clause : Node_Id;
4040 Output : Node_Id;
4042 begin
4043 -- A null dependency list does not mention any states
4045 if Nkind (List) = N_Null then
4046 return False;
4048 -- Dependency clauses appear as component associations of an
4049 -- aggregate.
4051 elsif Nkind (List) = N_Aggregate
4052 and then Present (Component_Associations (List))
4053 then
4054 Clause := First (Component_Associations (List));
4055 while Present (Clause) loop
4057 -- Inspect the outputs of a dependency clause
4059 Output := First (Choices (Clause));
4060 while Present (Output) loop
4061 if Is_Refined_State (Output) then
4062 return True;
4063 end if;
4065 Next (Output);
4066 end loop;
4068 -- Inspect the outputs of a dependency clause
4070 if Is_Refined_State (Expression (Clause)) then
4071 return True;
4072 end if;
4074 Next (Clause);
4075 end loop;
4077 -- If we get here, then none of the dependency clauses mention a
4078 -- state with visible refinement.
4080 return False;
4082 -- An illegal pragma managed to sneak in
4084 else
4085 raise Program_Error;
4086 end if;
4087 end Has_State_In_Dependency;
4089 -------------------------
4090 -- Has_State_In_Global --
4091 -------------------------
4093 function Has_State_In_Global (List : Node_Id) return Boolean is
4094 Item : Node_Id;
4096 begin
4097 -- A null global list does not mention any states
4099 if Nkind (List) = N_Null then
4100 return False;
4102 -- Simple global list or moded global list declaration
4104 elsif Nkind (List) = N_Aggregate then
4106 -- The declaration of a simple global list appear as a collection
4107 -- of expressions.
4109 if Present (Expressions (List)) then
4110 Item := First (Expressions (List));
4111 while Present (Item) loop
4112 if Is_Refined_State (Item) then
4113 return True;
4114 end if;
4116 Next (Item);
4117 end loop;
4119 -- The declaration of a moded global list appears as a collection
4120 -- of component associations where individual choices denote
4121 -- modes.
4123 else
4124 Item := First (Component_Associations (List));
4125 while Present (Item) loop
4126 if Has_State_In_Global (Expression (Item)) then
4127 return True;
4128 end if;
4130 Next (Item);
4131 end loop;
4132 end if;
4134 -- If we get here, then the simple/moded global list did not
4135 -- mention any states with a visible refinement.
4137 return False;
4139 -- Single global item declaration
4141 elsif Is_Entity_Name (List) then
4142 return Is_Refined_State (List);
4144 -- An illegal pragma managed to sneak in
4146 else
4147 raise Program_Error;
4148 end if;
4149 end Has_State_In_Global;
4151 ----------------------
4152 -- Is_Refined_State --
4153 ----------------------
4155 function Is_Refined_State (Item : Node_Id) return Boolean is
4156 Elmt : Node_Id;
4157 Item_Id : Entity_Id;
4159 begin
4160 if Nkind (Item) = N_Null then
4161 return False;
4163 -- States cannot be subject to attribute 'Result. This case arises
4164 -- in dependency relations.
4166 elsif Nkind (Item) = N_Attribute_Reference
4167 and then Attribute_Name (Item) = Name_Result
4168 then
4169 return False;
4171 -- Multiple items appear as an aggregate. This case arises in
4172 -- dependency relations.
4174 elsif Nkind (Item) = N_Aggregate
4175 and then Present (Expressions (Item))
4176 then
4177 Elmt := First (Expressions (Item));
4178 while Present (Elmt) loop
4179 if Is_Refined_State (Elmt) then
4180 return True;
4181 end if;
4183 Next (Elmt);
4184 end loop;
4186 -- If we get here, then none of the inputs or outputs reference a
4187 -- state with visible refinement.
4189 return False;
4191 -- Single item
4193 else
4194 Item_Id := Entity_Of (Item);
4196 return
4197 Present (Item_Id)
4198 and then Ekind (Item_Id) = E_Abstract_State
4199 and then Has_Visible_Refinement (Item_Id);
4200 end if;
4201 end Is_Refined_State;
4203 -- Local variables
4205 Arg : constant Node_Id :=
4206 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4207 Nam : constant Name_Id := Pragma_Name (Prag);
4209 -- Start of processing for Contains_Refined_State
4211 begin
4212 if Nam = Name_Depends then
4213 return Has_State_In_Dependency (Arg);
4215 else pragma Assert (Nam = Name_Global);
4216 return Has_State_In_Global (Arg);
4217 end if;
4218 end Contains_Refined_State;
4220 -------------------------
4221 -- Copy_Component_List --
4222 -------------------------
4224 function Copy_Component_List
4225 (R_Typ : Entity_Id;
4226 Loc : Source_Ptr) return List_Id
4228 Comp : Node_Id;
4229 Comps : constant List_Id := New_List;
4231 begin
4232 Comp := First_Component (Underlying_Type (R_Typ));
4233 while Present (Comp) loop
4234 if Comes_From_Source (Comp) then
4235 declare
4236 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4237 begin
4238 Append_To (Comps,
4239 Make_Component_Declaration (Loc,
4240 Defining_Identifier =>
4241 Make_Defining_Identifier (Loc, Chars (Comp)),
4242 Component_Definition =>
4243 New_Copy_Tree
4244 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4245 end;
4246 end if;
4248 Next_Component (Comp);
4249 end loop;
4251 return Comps;
4252 end Copy_Component_List;
4254 -------------------------
4255 -- Copy_Parameter_List --
4256 -------------------------
4258 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4259 Loc : constant Source_Ptr := Sloc (Subp_Id);
4260 Plist : List_Id;
4261 Formal : Entity_Id;
4263 begin
4264 if No (First_Formal (Subp_Id)) then
4265 return No_List;
4266 else
4267 Plist := New_List;
4268 Formal := First_Formal (Subp_Id);
4269 while Present (Formal) loop
4270 Append
4271 (Make_Parameter_Specification (Loc,
4272 Defining_Identifier =>
4273 Make_Defining_Identifier (Sloc (Formal),
4274 Chars => Chars (Formal)),
4275 In_Present => In_Present (Parent (Formal)),
4276 Out_Present => Out_Present (Parent (Formal)),
4277 Parameter_Type =>
4278 New_Occurrence_Of (Etype (Formal), Loc),
4279 Expression =>
4280 New_Copy_Tree (Expression (Parent (Formal)))),
4281 Plist);
4283 Next_Formal (Formal);
4284 end loop;
4285 end if;
4287 return Plist;
4288 end Copy_Parameter_List;
4290 --------------------------------
4291 -- Corresponding_Generic_Type --
4292 --------------------------------
4294 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4295 Inst : Entity_Id;
4296 Gen : Entity_Id;
4297 Typ : Entity_Id;
4299 begin
4300 if not Is_Generic_Actual_Type (T) then
4301 return Any_Type;
4303 -- If the actual is the actual of an enclosing instance, resolution
4304 -- was correct in the generic.
4306 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4307 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4308 and then
4309 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4310 then
4311 return Any_Type;
4313 else
4314 Inst := Scope (T);
4316 if Is_Wrapper_Package (Inst) then
4317 Inst := Related_Instance (Inst);
4318 end if;
4320 Gen :=
4321 Generic_Parent
4322 (Specification (Unit_Declaration_Node (Inst)));
4324 -- Generic actual has the same name as the corresponding formal
4326 Typ := First_Entity (Gen);
4327 while Present (Typ) loop
4328 if Chars (Typ) = Chars (T) then
4329 return Typ;
4330 end if;
4332 Next_Entity (Typ);
4333 end loop;
4335 return Any_Type;
4336 end if;
4337 end Corresponding_Generic_Type;
4339 --------------------
4340 -- Current_Entity --
4341 --------------------
4343 -- The currently visible definition for a given identifier is the
4344 -- one most chained at the start of the visibility chain, i.e. the
4345 -- one that is referenced by the Node_Id value of the name of the
4346 -- given identifier.
4348 function Current_Entity (N : Node_Id) return Entity_Id is
4349 begin
4350 return Get_Name_Entity_Id (Chars (N));
4351 end Current_Entity;
4353 -----------------------------
4354 -- Current_Entity_In_Scope --
4355 -----------------------------
4357 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4358 E : Entity_Id;
4359 CS : constant Entity_Id := Current_Scope;
4361 Transient_Case : constant Boolean := Scope_Is_Transient;
4363 begin
4364 E := Get_Name_Entity_Id (Chars (N));
4365 while Present (E)
4366 and then Scope (E) /= CS
4367 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4368 loop
4369 E := Homonym (E);
4370 end loop;
4372 return E;
4373 end Current_Entity_In_Scope;
4375 -------------------
4376 -- Current_Scope --
4377 -------------------
4379 function Current_Scope return Entity_Id is
4380 begin
4381 if Scope_Stack.Last = -1 then
4382 return Standard_Standard;
4383 else
4384 declare
4385 C : constant Entity_Id :=
4386 Scope_Stack.Table (Scope_Stack.Last).Entity;
4387 begin
4388 if Present (C) then
4389 return C;
4390 else
4391 return Standard_Standard;
4392 end if;
4393 end;
4394 end if;
4395 end Current_Scope;
4397 ------------------------
4398 -- Current_Subprogram --
4399 ------------------------
4401 function Current_Subprogram return Entity_Id is
4402 Scop : constant Entity_Id := Current_Scope;
4403 begin
4404 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
4405 return Scop;
4406 else
4407 return Enclosing_Subprogram (Scop);
4408 end if;
4409 end Current_Subprogram;
4411 ----------------------------------
4412 -- Deepest_Type_Access_Level --
4413 ----------------------------------
4415 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4416 begin
4417 if Ekind (Typ) = E_Anonymous_Access_Type
4418 and then not Is_Local_Anonymous_Access (Typ)
4419 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4420 then
4421 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4422 -- access type.
4424 return
4425 Scope_Depth (Enclosing_Dynamic_Scope
4426 (Defining_Identifier
4427 (Associated_Node_For_Itype (Typ))));
4429 -- For generic formal type, return Int'Last (infinite).
4430 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4432 elsif Is_Generic_Type (Root_Type (Typ)) then
4433 return UI_From_Int (Int'Last);
4435 else
4436 return Type_Access_Level (Typ);
4437 end if;
4438 end Deepest_Type_Access_Level;
4440 ---------------------
4441 -- Defining_Entity --
4442 ---------------------
4444 function Defining_Entity (N : Node_Id) return Entity_Id is
4445 K : constant Node_Kind := Nkind (N);
4446 Err : Entity_Id := Empty;
4448 begin
4449 case K is
4450 when
4451 N_Subprogram_Declaration |
4452 N_Abstract_Subprogram_Declaration |
4453 N_Subprogram_Body |
4454 N_Package_Declaration |
4455 N_Subprogram_Renaming_Declaration |
4456 N_Subprogram_Body_Stub |
4457 N_Generic_Subprogram_Declaration |
4458 N_Generic_Package_Declaration |
4459 N_Formal_Subprogram_Declaration |
4460 N_Expression_Function
4462 return Defining_Entity (Specification (N));
4464 when
4465 N_Component_Declaration |
4466 N_Defining_Program_Unit_Name |
4467 N_Discriminant_Specification |
4468 N_Entry_Body |
4469 N_Entry_Declaration |
4470 N_Entry_Index_Specification |
4471 N_Exception_Declaration |
4472 N_Exception_Renaming_Declaration |
4473 N_Formal_Object_Declaration |
4474 N_Formal_Package_Declaration |
4475 N_Formal_Type_Declaration |
4476 N_Full_Type_Declaration |
4477 N_Implicit_Label_Declaration |
4478 N_Incomplete_Type_Declaration |
4479 N_Loop_Parameter_Specification |
4480 N_Number_Declaration |
4481 N_Object_Declaration |
4482 N_Object_Renaming_Declaration |
4483 N_Package_Body_Stub |
4484 N_Parameter_Specification |
4485 N_Private_Extension_Declaration |
4486 N_Private_Type_Declaration |
4487 N_Protected_Body |
4488 N_Protected_Body_Stub |
4489 N_Protected_Type_Declaration |
4490 N_Single_Protected_Declaration |
4491 N_Single_Task_Declaration |
4492 N_Subtype_Declaration |
4493 N_Task_Body |
4494 N_Task_Body_Stub |
4495 N_Task_Type_Declaration
4497 return Defining_Identifier (N);
4499 when N_Subunit =>
4500 return Defining_Entity (Proper_Body (N));
4502 when
4503 N_Function_Instantiation |
4504 N_Function_Specification |
4505 N_Generic_Function_Renaming_Declaration |
4506 N_Generic_Package_Renaming_Declaration |
4507 N_Generic_Procedure_Renaming_Declaration |
4508 N_Package_Body |
4509 N_Package_Instantiation |
4510 N_Package_Renaming_Declaration |
4511 N_Package_Specification |
4512 N_Procedure_Instantiation |
4513 N_Procedure_Specification
4515 declare
4516 Nam : constant Node_Id := Defining_Unit_Name (N);
4518 begin
4519 if Nkind (Nam) in N_Entity then
4520 return Nam;
4522 -- For Error, make up a name and attach to declaration
4523 -- so we can continue semantic analysis
4525 elsif Nam = Error then
4526 Err := Make_Temporary (Sloc (N), 'T');
4527 Set_Defining_Unit_Name (N, Err);
4529 return Err;
4531 -- If not an entity, get defining identifier
4533 else
4534 return Defining_Identifier (Nam);
4535 end if;
4536 end;
4538 when
4539 N_Block_Statement |
4540 N_Loop_Statement
4542 return Entity (Identifier (N));
4544 when others =>
4545 raise Program_Error;
4547 end case;
4548 end Defining_Entity;
4550 --------------------------
4551 -- Denotes_Discriminant --
4552 --------------------------
4554 function Denotes_Discriminant
4555 (N : Node_Id;
4556 Check_Concurrent : Boolean := False) return Boolean
4558 E : Entity_Id;
4560 begin
4561 if not Is_Entity_Name (N) or else No (Entity (N)) then
4562 return False;
4563 else
4564 E := Entity (N);
4565 end if;
4567 -- If we are checking for a protected type, the discriminant may have
4568 -- been rewritten as the corresponding discriminal of the original type
4569 -- or of the corresponding concurrent record, depending on whether we
4570 -- are in the spec or body of the protected type.
4572 return Ekind (E) = E_Discriminant
4573 or else
4574 (Check_Concurrent
4575 and then Ekind (E) = E_In_Parameter
4576 and then Present (Discriminal_Link (E))
4577 and then
4578 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
4579 or else
4580 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
4582 end Denotes_Discriminant;
4584 -------------------------
4585 -- Denotes_Same_Object --
4586 -------------------------
4588 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
4589 Obj1 : Node_Id := A1;
4590 Obj2 : Node_Id := A2;
4592 function Has_Prefix (N : Node_Id) return Boolean;
4593 -- Return True if N has attribute Prefix
4595 function Is_Renaming (N : Node_Id) return Boolean;
4596 -- Return true if N names a renaming entity
4598 function Is_Valid_Renaming (N : Node_Id) return Boolean;
4599 -- For renamings, return False if the prefix of any dereference within
4600 -- the renamed object_name is a variable, or any expression within the
4601 -- renamed object_name contains references to variables or calls on
4602 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4604 ----------------
4605 -- Has_Prefix --
4606 ----------------
4608 function Has_Prefix (N : Node_Id) return Boolean is
4609 begin
4610 return
4611 Nkind_In (N,
4612 N_Attribute_Reference,
4613 N_Expanded_Name,
4614 N_Explicit_Dereference,
4615 N_Indexed_Component,
4616 N_Reference,
4617 N_Selected_Component,
4618 N_Slice);
4619 end Has_Prefix;
4621 -----------------
4622 -- Is_Renaming --
4623 -----------------
4625 function Is_Renaming (N : Node_Id) return Boolean is
4626 begin
4627 return Is_Entity_Name (N)
4628 and then Present (Renamed_Entity (Entity (N)));
4629 end Is_Renaming;
4631 -----------------------
4632 -- Is_Valid_Renaming --
4633 -----------------------
4635 function Is_Valid_Renaming (N : Node_Id) return Boolean is
4637 function Check_Renaming (N : Node_Id) return Boolean;
4638 -- Recursive function used to traverse all the prefixes of N
4640 function Check_Renaming (N : Node_Id) return Boolean is
4641 begin
4642 if Is_Renaming (N)
4643 and then not Check_Renaming (Renamed_Entity (Entity (N)))
4644 then
4645 return False;
4646 end if;
4648 if Nkind (N) = N_Indexed_Component then
4649 declare
4650 Indx : Node_Id;
4652 begin
4653 Indx := First (Expressions (N));
4654 while Present (Indx) loop
4655 if not Is_OK_Static_Expression (Indx) then
4656 return False;
4657 end if;
4659 Next_Index (Indx);
4660 end loop;
4661 end;
4662 end if;
4664 if Has_Prefix (N) then
4665 declare
4666 P : constant Node_Id := Prefix (N);
4668 begin
4669 if Nkind (N) = N_Explicit_Dereference
4670 and then Is_Variable (P)
4671 then
4672 return False;
4674 elsif Is_Entity_Name (P)
4675 and then Ekind (Entity (P)) = E_Function
4676 then
4677 return False;
4679 elsif Nkind (P) = N_Function_Call then
4680 return False;
4681 end if;
4683 -- Recursion to continue traversing the prefix of the
4684 -- renaming expression
4686 return Check_Renaming (P);
4687 end;
4688 end if;
4690 return True;
4691 end Check_Renaming;
4693 -- Start of processing for Is_Valid_Renaming
4695 begin
4696 return Check_Renaming (N);
4697 end Is_Valid_Renaming;
4699 -- Start of processing for Denotes_Same_Object
4701 begin
4702 -- Both names statically denote the same stand-alone object or parameter
4703 -- (RM 6.4.1(6.5/3))
4705 if Is_Entity_Name (Obj1)
4706 and then Is_Entity_Name (Obj2)
4707 and then Entity (Obj1) = Entity (Obj2)
4708 then
4709 return True;
4710 end if;
4712 -- For renamings, the prefix of any dereference within the renamed
4713 -- object_name is not a variable, and any expression within the
4714 -- renamed object_name contains no references to variables nor
4715 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4717 if Is_Renaming (Obj1) then
4718 if Is_Valid_Renaming (Obj1) then
4719 Obj1 := Renamed_Entity (Entity (Obj1));
4720 else
4721 return False;
4722 end if;
4723 end if;
4725 if Is_Renaming (Obj2) then
4726 if Is_Valid_Renaming (Obj2) then
4727 Obj2 := Renamed_Entity (Entity (Obj2));
4728 else
4729 return False;
4730 end if;
4731 end if;
4733 -- No match if not same node kind (such cases are handled by
4734 -- Denotes_Same_Prefix)
4736 if Nkind (Obj1) /= Nkind (Obj2) then
4737 return False;
4739 -- After handling valid renamings, one of the two names statically
4740 -- denoted a renaming declaration whose renamed object_name is known
4741 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4743 elsif Is_Entity_Name (Obj1) then
4744 if Is_Entity_Name (Obj2) then
4745 return Entity (Obj1) = Entity (Obj2);
4746 else
4747 return False;
4748 end if;
4750 -- Both names are selected_components, their prefixes are known to
4751 -- denote the same object, and their selector_names denote the same
4752 -- component (RM 6.4.1(6.6/3)
4754 elsif Nkind (Obj1) = N_Selected_Component then
4755 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4756 and then
4757 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
4759 -- Both names are dereferences and the dereferenced names are known to
4760 -- denote the same object (RM 6.4.1(6.7/3))
4762 elsif Nkind (Obj1) = N_Explicit_Dereference then
4763 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
4765 -- Both names are indexed_components, their prefixes are known to denote
4766 -- the same object, and each of the pairs of corresponding index values
4767 -- are either both static expressions with the same static value or both
4768 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4770 elsif Nkind (Obj1) = N_Indexed_Component then
4771 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
4772 return False;
4773 else
4774 declare
4775 Indx1 : Node_Id;
4776 Indx2 : Node_Id;
4778 begin
4779 Indx1 := First (Expressions (Obj1));
4780 Indx2 := First (Expressions (Obj2));
4781 while Present (Indx1) loop
4783 -- Indexes must denote the same static value or same object
4785 if Is_OK_Static_Expression (Indx1) then
4786 if not Is_OK_Static_Expression (Indx2) then
4787 return False;
4789 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
4790 return False;
4791 end if;
4793 elsif not Denotes_Same_Object (Indx1, Indx2) then
4794 return False;
4795 end if;
4797 Next (Indx1);
4798 Next (Indx2);
4799 end loop;
4801 return True;
4802 end;
4803 end if;
4805 -- Both names are slices, their prefixes are known to denote the same
4806 -- object, and the two slices have statically matching index constraints
4807 -- (RM 6.4.1(6.9/3))
4809 elsif Nkind (Obj1) = N_Slice
4810 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4811 then
4812 declare
4813 Lo1, Lo2, Hi1, Hi2 : Node_Id;
4815 begin
4816 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
4817 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
4819 -- Check whether bounds are statically identical. There is no
4820 -- attempt to detect partial overlap of slices.
4822 return Denotes_Same_Object (Lo1, Lo2)
4823 and then
4824 Denotes_Same_Object (Hi1, Hi2);
4825 end;
4827 -- In the recursion, literals appear as indexes
4829 elsif Nkind (Obj1) = N_Integer_Literal
4830 and then
4831 Nkind (Obj2) = N_Integer_Literal
4832 then
4833 return Intval (Obj1) = Intval (Obj2);
4835 else
4836 return False;
4837 end if;
4838 end Denotes_Same_Object;
4840 -------------------------
4841 -- Denotes_Same_Prefix --
4842 -------------------------
4844 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
4846 begin
4847 if Is_Entity_Name (A1) then
4848 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
4849 and then not Is_Access_Type (Etype (A1))
4850 then
4851 return Denotes_Same_Object (A1, Prefix (A2))
4852 or else Denotes_Same_Prefix (A1, Prefix (A2));
4853 else
4854 return False;
4855 end if;
4857 elsif Is_Entity_Name (A2) then
4858 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
4860 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
4861 and then
4862 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
4863 then
4864 declare
4865 Root1, Root2 : Node_Id;
4866 Depth1, Depth2 : Int := 0;
4868 begin
4869 Root1 := Prefix (A1);
4870 while not Is_Entity_Name (Root1) loop
4871 if not Nkind_In
4872 (Root1, N_Selected_Component, N_Indexed_Component)
4873 then
4874 return False;
4875 else
4876 Root1 := Prefix (Root1);
4877 end if;
4879 Depth1 := Depth1 + 1;
4880 end loop;
4882 Root2 := Prefix (A2);
4883 while not Is_Entity_Name (Root2) loop
4884 if not Nkind_In (Root2, N_Selected_Component,
4885 N_Indexed_Component)
4886 then
4887 return False;
4888 else
4889 Root2 := Prefix (Root2);
4890 end if;
4892 Depth2 := Depth2 + 1;
4893 end loop;
4895 -- If both have the same depth and they do not denote the same
4896 -- object, they are disjoint and no warning is needed.
4898 if Depth1 = Depth2 then
4899 return False;
4901 elsif Depth1 > Depth2 then
4902 Root1 := Prefix (A1);
4903 for J in 1 .. Depth1 - Depth2 - 1 loop
4904 Root1 := Prefix (Root1);
4905 end loop;
4907 return Denotes_Same_Object (Root1, A2);
4909 else
4910 Root2 := Prefix (A2);
4911 for J in 1 .. Depth2 - Depth1 - 1 loop
4912 Root2 := Prefix (Root2);
4913 end loop;
4915 return Denotes_Same_Object (A1, Root2);
4916 end if;
4917 end;
4919 else
4920 return False;
4921 end if;
4922 end Denotes_Same_Prefix;
4924 ----------------------
4925 -- Denotes_Variable --
4926 ----------------------
4928 function Denotes_Variable (N : Node_Id) return Boolean is
4929 begin
4930 return Is_Variable (N) and then Paren_Count (N) = 0;
4931 end Denotes_Variable;
4933 -----------------------------
4934 -- Depends_On_Discriminant --
4935 -----------------------------
4937 function Depends_On_Discriminant (N : Node_Id) return Boolean is
4938 L : Node_Id;
4939 H : Node_Id;
4941 begin
4942 Get_Index_Bounds (N, L, H);
4943 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
4944 end Depends_On_Discriminant;
4946 -------------------------
4947 -- Designate_Same_Unit --
4948 -------------------------
4950 function Designate_Same_Unit
4951 (Name1 : Node_Id;
4952 Name2 : Node_Id) return Boolean
4954 K1 : constant Node_Kind := Nkind (Name1);
4955 K2 : constant Node_Kind := Nkind (Name2);
4957 function Prefix_Node (N : Node_Id) return Node_Id;
4958 -- Returns the parent unit name node of a defining program unit name
4959 -- or the prefix if N is a selected component or an expanded name.
4961 function Select_Node (N : Node_Id) return Node_Id;
4962 -- Returns the defining identifier node of a defining program unit
4963 -- name or the selector node if N is a selected component or an
4964 -- expanded name.
4966 -----------------
4967 -- Prefix_Node --
4968 -----------------
4970 function Prefix_Node (N : Node_Id) return Node_Id is
4971 begin
4972 if Nkind (N) = N_Defining_Program_Unit_Name then
4973 return Name (N);
4974 else
4975 return Prefix (N);
4976 end if;
4977 end Prefix_Node;
4979 -----------------
4980 -- Select_Node --
4981 -----------------
4983 function Select_Node (N : Node_Id) return Node_Id is
4984 begin
4985 if Nkind (N) = N_Defining_Program_Unit_Name then
4986 return Defining_Identifier (N);
4987 else
4988 return Selector_Name (N);
4989 end if;
4990 end Select_Node;
4992 -- Start of processing for Designate_Same_Unit
4994 begin
4995 if Nkind_In (K1, N_Identifier, N_Defining_Identifier)
4996 and then
4997 Nkind_In (K2, N_Identifier, N_Defining_Identifier)
4998 then
4999 return Chars (Name1) = Chars (Name2);
5001 elsif Nkind_In (K1, N_Expanded_Name,
5002 N_Selected_Component,
5003 N_Defining_Program_Unit_Name)
5004 and then
5005 Nkind_In (K2, N_Expanded_Name,
5006 N_Selected_Component,
5007 N_Defining_Program_Unit_Name)
5008 then
5009 return
5010 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5011 and then
5012 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5014 else
5015 return False;
5016 end if;
5017 end Designate_Same_Unit;
5019 ------------------------------------------
5020 -- function Dynamic_Accessibility_Level --
5021 ------------------------------------------
5023 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5024 E : Entity_Id;
5025 Loc : constant Source_Ptr := Sloc (Expr);
5027 function Make_Level_Literal (Level : Uint) return Node_Id;
5028 -- Construct an integer literal representing an accessibility level
5029 -- with its type set to Natural.
5031 ------------------------
5032 -- Make_Level_Literal --
5033 ------------------------
5035 function Make_Level_Literal (Level : Uint) return Node_Id is
5036 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5037 begin
5038 Set_Etype (Result, Standard_Natural);
5039 return Result;
5040 end Make_Level_Literal;
5042 -- Start of processing for Dynamic_Accessibility_Level
5044 begin
5045 if Is_Entity_Name (Expr) then
5046 E := Entity (Expr);
5048 if Present (Renamed_Object (E)) then
5049 return Dynamic_Accessibility_Level (Renamed_Object (E));
5050 end if;
5052 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5053 if Present (Extra_Accessibility (E)) then
5054 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5055 end if;
5056 end if;
5057 end if;
5059 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5061 case Nkind (Expr) is
5063 -- For access discriminant, the level of the enclosing object
5065 when N_Selected_Component =>
5066 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5067 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5068 E_Anonymous_Access_Type
5069 then
5070 return Make_Level_Literal (Object_Access_Level (Expr));
5071 end if;
5073 when N_Attribute_Reference =>
5074 case Get_Attribute_Id (Attribute_Name (Expr)) is
5076 -- For X'Access, the level of the prefix X
5078 when Attribute_Access =>
5079 return Make_Level_Literal
5080 (Object_Access_Level (Prefix (Expr)));
5082 -- Treat the unchecked attributes as library-level
5084 when Attribute_Unchecked_Access |
5085 Attribute_Unrestricted_Access =>
5086 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5088 -- No other access-valued attributes
5090 when others =>
5091 raise Program_Error;
5092 end case;
5094 when N_Allocator =>
5096 -- Unimplemented: depends on context. As an actual parameter where
5097 -- formal type is anonymous, use
5098 -- Scope_Depth (Current_Scope) + 1.
5099 -- For other cases, see 3.10.2(14/3) and following. ???
5101 null;
5103 when N_Type_Conversion =>
5104 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5106 -- Handle type conversions introduced for a rename of an
5107 -- Ada 2012 stand-alone object of an anonymous access type.
5109 return Dynamic_Accessibility_Level (Expression (Expr));
5110 end if;
5112 when others =>
5113 null;
5114 end case;
5116 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5117 end Dynamic_Accessibility_Level;
5119 -----------------------------------
5120 -- Effective_Extra_Accessibility --
5121 -----------------------------------
5123 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5124 begin
5125 if Present (Renamed_Object (Id))
5126 and then Is_Entity_Name (Renamed_Object (Id))
5127 then
5128 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5129 else
5130 return Extra_Accessibility (Id);
5131 end if;
5132 end Effective_Extra_Accessibility;
5134 -----------------------------
5135 -- Effective_Reads_Enabled --
5136 -----------------------------
5138 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5139 begin
5140 return Has_Enabled_Property (Id, Name_Effective_Reads);
5141 end Effective_Reads_Enabled;
5143 ------------------------------
5144 -- Effective_Writes_Enabled --
5145 ------------------------------
5147 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5148 begin
5149 return Has_Enabled_Property (Id, Name_Effective_Writes);
5150 end Effective_Writes_Enabled;
5152 ------------------------------
5153 -- Enclosing_Comp_Unit_Node --
5154 ------------------------------
5156 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5157 Current_Node : Node_Id;
5159 begin
5160 Current_Node := N;
5161 while Present (Current_Node)
5162 and then Nkind (Current_Node) /= N_Compilation_Unit
5163 loop
5164 Current_Node := Parent (Current_Node);
5165 end loop;
5167 if Nkind (Current_Node) /= N_Compilation_Unit then
5168 return Empty;
5169 else
5170 return Current_Node;
5171 end if;
5172 end Enclosing_Comp_Unit_Node;
5174 --------------------------
5175 -- Enclosing_CPP_Parent --
5176 --------------------------
5178 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5179 Parent_Typ : Entity_Id := Typ;
5181 begin
5182 while not Is_CPP_Class (Parent_Typ)
5183 and then Etype (Parent_Typ) /= Parent_Typ
5184 loop
5185 Parent_Typ := Etype (Parent_Typ);
5187 if Is_Private_Type (Parent_Typ) then
5188 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5189 end if;
5190 end loop;
5192 pragma Assert (Is_CPP_Class (Parent_Typ));
5193 return Parent_Typ;
5194 end Enclosing_CPP_Parent;
5196 ----------------------------
5197 -- Enclosing_Generic_Body --
5198 ----------------------------
5200 function Enclosing_Generic_Body
5201 (N : Node_Id) return Node_Id
5203 P : Node_Id;
5204 Decl : Node_Id;
5205 Spec : Node_Id;
5207 begin
5208 P := Parent (N);
5209 while Present (P) loop
5210 if Nkind (P) = N_Package_Body
5211 or else Nkind (P) = N_Subprogram_Body
5212 then
5213 Spec := Corresponding_Spec (P);
5215 if Present (Spec) then
5216 Decl := Unit_Declaration_Node (Spec);
5218 if Nkind (Decl) = N_Generic_Package_Declaration
5219 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5220 then
5221 return P;
5222 end if;
5223 end if;
5224 end if;
5226 P := Parent (P);
5227 end loop;
5229 return Empty;
5230 end Enclosing_Generic_Body;
5232 ----------------------------
5233 -- Enclosing_Generic_Unit --
5234 ----------------------------
5236 function Enclosing_Generic_Unit
5237 (N : Node_Id) return Node_Id
5239 P : Node_Id;
5240 Decl : Node_Id;
5241 Spec : Node_Id;
5243 begin
5244 P := Parent (N);
5245 while Present (P) loop
5246 if Nkind (P) = N_Generic_Package_Declaration
5247 or else Nkind (P) = N_Generic_Subprogram_Declaration
5248 then
5249 return P;
5251 elsif Nkind (P) = N_Package_Body
5252 or else Nkind (P) = N_Subprogram_Body
5253 then
5254 Spec := Corresponding_Spec (P);
5256 if Present (Spec) then
5257 Decl := Unit_Declaration_Node (Spec);
5259 if Nkind (Decl) = N_Generic_Package_Declaration
5260 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5261 then
5262 return Decl;
5263 end if;
5264 end if;
5265 end if;
5267 P := Parent (P);
5268 end loop;
5270 return Empty;
5271 end Enclosing_Generic_Unit;
5273 -------------------------------
5274 -- Enclosing_Lib_Unit_Entity --
5275 -------------------------------
5277 function Enclosing_Lib_Unit_Entity
5278 (E : Entity_Id := Current_Scope) return Entity_Id
5280 Unit_Entity : Entity_Id;
5282 begin
5283 -- Look for enclosing library unit entity by following scope links.
5284 -- Equivalent to, but faster than indexing through the scope stack.
5286 Unit_Entity := E;
5287 while (Present (Scope (Unit_Entity))
5288 and then Scope (Unit_Entity) /= Standard_Standard)
5289 and not Is_Child_Unit (Unit_Entity)
5290 loop
5291 Unit_Entity := Scope (Unit_Entity);
5292 end loop;
5294 return Unit_Entity;
5295 end Enclosing_Lib_Unit_Entity;
5297 -----------------------
5298 -- Enclosing_Package --
5299 -----------------------
5301 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5302 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5304 begin
5305 if Dynamic_Scope = Standard_Standard then
5306 return Standard_Standard;
5308 elsif Dynamic_Scope = Empty then
5309 return Empty;
5311 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5312 E_Generic_Package)
5313 then
5314 return Dynamic_Scope;
5316 else
5317 return Enclosing_Package (Dynamic_Scope);
5318 end if;
5319 end Enclosing_Package;
5321 --------------------------
5322 -- Enclosing_Subprogram --
5323 --------------------------
5325 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5326 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5328 begin
5329 if Dynamic_Scope = Standard_Standard then
5330 return Empty;
5332 elsif Dynamic_Scope = Empty then
5333 return Empty;
5335 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5336 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5338 elsif Ekind (Dynamic_Scope) = E_Block
5339 or else Ekind (Dynamic_Scope) = E_Return_Statement
5340 then
5341 return Enclosing_Subprogram (Dynamic_Scope);
5343 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5344 return Get_Task_Body_Procedure (Dynamic_Scope);
5346 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5347 and then Present (Full_View (Dynamic_Scope))
5348 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5349 then
5350 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5352 -- No body is generated if the protected operation is eliminated
5354 elsif Convention (Dynamic_Scope) = Convention_Protected
5355 and then not Is_Eliminated (Dynamic_Scope)
5356 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5357 then
5358 return Protected_Body_Subprogram (Dynamic_Scope);
5360 else
5361 return Dynamic_Scope;
5362 end if;
5363 end Enclosing_Subprogram;
5365 ------------------------
5366 -- Ensure_Freeze_Node --
5367 ------------------------
5369 procedure Ensure_Freeze_Node (E : Entity_Id) is
5370 FN : Node_Id;
5371 begin
5372 if No (Freeze_Node (E)) then
5373 FN := Make_Freeze_Entity (Sloc (E));
5374 Set_Has_Delayed_Freeze (E);
5375 Set_Freeze_Node (E, FN);
5376 Set_Access_Types_To_Process (FN, No_Elist);
5377 Set_TSS_Elist (FN, No_Elist);
5378 Set_Entity (FN, E);
5379 end if;
5380 end Ensure_Freeze_Node;
5382 ----------------
5383 -- Enter_Name --
5384 ----------------
5386 procedure Enter_Name (Def_Id : Entity_Id) is
5387 C : constant Entity_Id := Current_Entity (Def_Id);
5388 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5389 S : constant Entity_Id := Current_Scope;
5391 begin
5392 Generate_Definition (Def_Id);
5394 -- Add new name to current scope declarations. Check for duplicate
5395 -- declaration, which may or may not be a genuine error.
5397 if Present (E) then
5399 -- Case of previous entity entered because of a missing declaration
5400 -- or else a bad subtype indication. Best is to use the new entity,
5401 -- and make the previous one invisible.
5403 if Etype (E) = Any_Type then
5404 Set_Is_Immediately_Visible (E, False);
5406 -- Case of renaming declaration constructed for package instances.
5407 -- if there is an explicit declaration with the same identifier,
5408 -- the renaming is not immediately visible any longer, but remains
5409 -- visible through selected component notation.
5411 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5412 and then not Comes_From_Source (E)
5413 then
5414 Set_Is_Immediately_Visible (E, False);
5416 -- The new entity may be the package renaming, which has the same
5417 -- same name as a generic formal which has been seen already.
5419 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5420 and then not Comes_From_Source (Def_Id)
5421 then
5422 Set_Is_Immediately_Visible (E, False);
5424 -- For a fat pointer corresponding to a remote access to subprogram,
5425 -- we use the same identifier as the RAS type, so that the proper
5426 -- name appears in the stub. This type is only retrieved through
5427 -- the RAS type and never by visibility, and is not added to the
5428 -- visibility list (see below).
5430 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
5431 and then Ekind (Def_Id) = E_Record_Type
5432 and then Present (Corresponding_Remote_Type (Def_Id))
5433 then
5434 null;
5436 -- Case of an implicit operation or derived literal. The new entity
5437 -- hides the implicit one, which is removed from all visibility,
5438 -- i.e. the entity list of its scope, and homonym chain of its name.
5440 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
5441 or else Is_Internal (E)
5442 then
5443 declare
5444 Prev : Entity_Id;
5445 Prev_Vis : Entity_Id;
5446 Decl : constant Node_Id := Parent (E);
5448 begin
5449 -- If E is an implicit declaration, it cannot be the first
5450 -- entity in the scope.
5452 Prev := First_Entity (Current_Scope);
5453 while Present (Prev) and then Next_Entity (Prev) /= E loop
5454 Next_Entity (Prev);
5455 end loop;
5457 if No (Prev) then
5459 -- If E is not on the entity chain of the current scope,
5460 -- it is an implicit declaration in the generic formal
5461 -- part of a generic subprogram. When analyzing the body,
5462 -- the generic formals are visible but not on the entity
5463 -- chain of the subprogram. The new entity will become
5464 -- the visible one in the body.
5466 pragma Assert
5467 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
5468 null;
5470 else
5471 Set_Next_Entity (Prev, Next_Entity (E));
5473 if No (Next_Entity (Prev)) then
5474 Set_Last_Entity (Current_Scope, Prev);
5475 end if;
5477 if E = Current_Entity (E) then
5478 Prev_Vis := Empty;
5480 else
5481 Prev_Vis := Current_Entity (E);
5482 while Homonym (Prev_Vis) /= E loop
5483 Prev_Vis := Homonym (Prev_Vis);
5484 end loop;
5485 end if;
5487 if Present (Prev_Vis) then
5489 -- Skip E in the visibility chain
5491 Set_Homonym (Prev_Vis, Homonym (E));
5493 else
5494 Set_Name_Entity_Id (Chars (E), Homonym (E));
5495 end if;
5496 end if;
5497 end;
5499 -- This section of code could use a comment ???
5501 elsif Present (Etype (E))
5502 and then Is_Concurrent_Type (Etype (E))
5503 and then E = Def_Id
5504 then
5505 return;
5507 -- If the homograph is a protected component renaming, it should not
5508 -- be hiding the current entity. Such renamings are treated as weak
5509 -- declarations.
5511 elsif Is_Prival (E) then
5512 Set_Is_Immediately_Visible (E, False);
5514 -- In this case the current entity is a protected component renaming.
5515 -- Perform minimal decoration by setting the scope and return since
5516 -- the prival should not be hiding other visible entities.
5518 elsif Is_Prival (Def_Id) then
5519 Set_Scope (Def_Id, Current_Scope);
5520 return;
5522 -- Analogous to privals, the discriminal generated for an entry index
5523 -- parameter acts as a weak declaration. Perform minimal decoration
5524 -- to avoid bogus errors.
5526 elsif Is_Discriminal (Def_Id)
5527 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
5528 then
5529 Set_Scope (Def_Id, Current_Scope);
5530 return;
5532 -- In the body or private part of an instance, a type extension may
5533 -- introduce a component with the same name as that of an actual. The
5534 -- legality rule is not enforced, but the semantics of the full type
5535 -- with two components of same name are not clear at this point???
5537 elsif In_Instance_Not_Visible then
5538 null;
5540 -- When compiling a package body, some child units may have become
5541 -- visible. They cannot conflict with local entities that hide them.
5543 elsif Is_Child_Unit (E)
5544 and then In_Open_Scopes (Scope (E))
5545 and then not Is_Immediately_Visible (E)
5546 then
5547 null;
5549 -- Conversely, with front-end inlining we may compile the parent body
5550 -- first, and a child unit subsequently. The context is now the
5551 -- parent spec, and body entities are not visible.
5553 elsif Is_Child_Unit (Def_Id)
5554 and then Is_Package_Body_Entity (E)
5555 and then not In_Package_Body (Current_Scope)
5556 then
5557 null;
5559 -- Case of genuine duplicate declaration
5561 else
5562 Error_Msg_Sloc := Sloc (E);
5564 -- If the previous declaration is an incomplete type declaration
5565 -- this may be an attempt to complete it with a private type. The
5566 -- following avoids confusing cascaded errors.
5568 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
5569 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
5570 then
5571 Error_Msg_N
5572 ("incomplete type cannot be completed with a private " &
5573 "declaration", Parent (Def_Id));
5574 Set_Is_Immediately_Visible (E, False);
5575 Set_Full_View (E, Def_Id);
5577 -- An inherited component of a record conflicts with a new
5578 -- discriminant. The discriminant is inserted first in the scope,
5579 -- but the error should be posted on it, not on the component.
5581 elsif Ekind (E) = E_Discriminant
5582 and then Present (Scope (Def_Id))
5583 and then Scope (Def_Id) /= Current_Scope
5584 then
5585 Error_Msg_Sloc := Sloc (Def_Id);
5586 Error_Msg_N ("& conflicts with declaration#", E);
5587 return;
5589 -- If the name of the unit appears in its own context clause, a
5590 -- dummy package with the name has already been created, and the
5591 -- error emitted. Try to continue quietly.
5593 elsif Error_Posted (E)
5594 and then Sloc (E) = No_Location
5595 and then Nkind (Parent (E)) = N_Package_Specification
5596 and then Current_Scope = Standard_Standard
5597 then
5598 Set_Scope (Def_Id, Current_Scope);
5599 return;
5601 else
5602 Error_Msg_N ("& conflicts with declaration#", Def_Id);
5604 -- Avoid cascaded messages with duplicate components in
5605 -- derived types.
5607 if Ekind_In (E, E_Component, E_Discriminant) then
5608 return;
5609 end if;
5610 end if;
5612 if Nkind (Parent (Parent (Def_Id))) =
5613 N_Generic_Subprogram_Declaration
5614 and then Def_Id =
5615 Defining_Entity (Specification (Parent (Parent (Def_Id))))
5616 then
5617 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
5618 end if;
5620 -- If entity is in standard, then we are in trouble, because it
5621 -- means that we have a library package with a duplicated name.
5622 -- That's hard to recover from, so abort.
5624 if S = Standard_Standard then
5625 raise Unrecoverable_Error;
5627 -- Otherwise we continue with the declaration. Having two
5628 -- identical declarations should not cause us too much trouble.
5630 else
5631 null;
5632 end if;
5633 end if;
5634 end if;
5636 -- If we fall through, declaration is OK, at least OK enough to continue
5638 -- If Def_Id is a discriminant or a record component we are in the midst
5639 -- of inheriting components in a derived record definition. Preserve
5640 -- their Ekind and Etype.
5642 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
5643 null;
5645 -- If a type is already set, leave it alone (happens when a type
5646 -- declaration is reanalyzed following a call to the optimizer).
5648 elsif Present (Etype (Def_Id)) then
5649 null;
5651 -- Otherwise, the kind E_Void insures that premature uses of the entity
5652 -- will be detected. Any_Type insures that no cascaded errors will occur
5654 else
5655 Set_Ekind (Def_Id, E_Void);
5656 Set_Etype (Def_Id, Any_Type);
5657 end if;
5659 -- Inherited discriminants and components in derived record types are
5660 -- immediately visible. Itypes are not.
5662 -- Unless the Itype is for a record type with a corresponding remote
5663 -- type (what is that about, it was not commented ???)
5665 if Ekind_In (Def_Id, E_Discriminant, E_Component)
5666 or else
5667 ((not Is_Record_Type (Def_Id)
5668 or else No (Corresponding_Remote_Type (Def_Id)))
5669 and then not Is_Itype (Def_Id))
5670 then
5671 Set_Is_Immediately_Visible (Def_Id);
5672 Set_Current_Entity (Def_Id);
5673 end if;
5675 Set_Homonym (Def_Id, C);
5676 Append_Entity (Def_Id, S);
5677 Set_Public_Status (Def_Id);
5679 -- Declaring a homonym is not allowed in SPARK ...
5681 if Present (C) and then Restriction_Check_Required (SPARK_05) then
5682 declare
5683 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
5684 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
5685 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
5687 begin
5688 -- ... unless the new declaration is in a subprogram, and the
5689 -- visible declaration is a variable declaration or a parameter
5690 -- specification outside that subprogram.
5692 if Present (Enclosing_Subp)
5693 and then Nkind_In (Parent (C), N_Object_Declaration,
5694 N_Parameter_Specification)
5695 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
5696 then
5697 null;
5699 -- ... or the new declaration is in a package, and the visible
5700 -- declaration occurs outside that package.
5702 elsif Present (Enclosing_Pack)
5703 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
5704 then
5705 null;
5707 -- ... or the new declaration is a component declaration in a
5708 -- record type definition.
5710 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
5711 null;
5713 -- Don't issue error for non-source entities
5715 elsif Comes_From_Source (Def_Id)
5716 and then Comes_From_Source (C)
5717 then
5718 Error_Msg_Sloc := Sloc (C);
5719 Check_SPARK_05_Restriction
5720 ("redeclaration of identifier &#", Def_Id);
5721 end if;
5722 end;
5723 end if;
5725 -- Warn if new entity hides an old one
5727 if Warn_On_Hiding and then Present (C)
5729 -- Don't warn for record components since they always have a well
5730 -- defined scope which does not confuse other uses. Note that in
5731 -- some cases, Ekind has not been set yet.
5733 and then Ekind (C) /= E_Component
5734 and then Ekind (C) /= E_Discriminant
5735 and then Nkind (Parent (C)) /= N_Component_Declaration
5736 and then Ekind (Def_Id) /= E_Component
5737 and then Ekind (Def_Id) /= E_Discriminant
5738 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
5740 -- Don't warn for one character variables. It is too common to use
5741 -- such variables as locals and will just cause too many false hits.
5743 and then Length_Of_Name (Chars (C)) /= 1
5745 -- Don't warn for non-source entities
5747 and then Comes_From_Source (C)
5748 and then Comes_From_Source (Def_Id)
5750 -- Don't warn unless entity in question is in extended main source
5752 and then In_Extended_Main_Source_Unit (Def_Id)
5754 -- Finally, the hidden entity must be either immediately visible or
5755 -- use visible (i.e. from a used package).
5757 and then
5758 (Is_Immediately_Visible (C)
5759 or else
5760 Is_Potentially_Use_Visible (C))
5761 then
5762 Error_Msg_Sloc := Sloc (C);
5763 Error_Msg_N ("declaration hides &#?h?", Def_Id);
5764 end if;
5765 end Enter_Name;
5767 ---------------
5768 -- Entity_Of --
5769 ---------------
5771 function Entity_Of (N : Node_Id) return Entity_Id is
5772 Id : Entity_Id;
5774 begin
5775 Id := Empty;
5777 if Is_Entity_Name (N) then
5778 Id := Entity (N);
5780 -- Follow a possible chain of renamings to reach the root renamed
5781 -- object.
5783 while Present (Id) and then Present (Renamed_Object (Id)) loop
5784 if Is_Entity_Name (Renamed_Object (Id)) then
5785 Id := Entity (Renamed_Object (Id));
5786 else
5787 Id := Empty;
5788 exit;
5789 end if;
5790 end loop;
5791 end if;
5793 return Id;
5794 end Entity_Of;
5796 --------------------------
5797 -- Explain_Limited_Type --
5798 --------------------------
5800 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
5801 C : Entity_Id;
5803 begin
5804 -- For array, component type must be limited
5806 if Is_Array_Type (T) then
5807 Error_Msg_Node_2 := T;
5808 Error_Msg_NE
5809 ("\component type& of type& is limited", N, Component_Type (T));
5810 Explain_Limited_Type (Component_Type (T), N);
5812 elsif Is_Record_Type (T) then
5814 -- No need for extra messages if explicit limited record
5816 if Is_Limited_Record (Base_Type (T)) then
5817 return;
5818 end if;
5820 -- Otherwise find a limited component. Check only components that
5821 -- come from source, or inherited components that appear in the
5822 -- source of the ancestor.
5824 C := First_Component (T);
5825 while Present (C) loop
5826 if Is_Limited_Type (Etype (C))
5827 and then
5828 (Comes_From_Source (C)
5829 or else
5830 (Present (Original_Record_Component (C))
5831 and then
5832 Comes_From_Source (Original_Record_Component (C))))
5833 then
5834 Error_Msg_Node_2 := T;
5835 Error_Msg_NE ("\component& of type& has limited type", N, C);
5836 Explain_Limited_Type (Etype (C), N);
5837 return;
5838 end if;
5840 Next_Component (C);
5841 end loop;
5843 -- The type may be declared explicitly limited, even if no component
5844 -- of it is limited, in which case we fall out of the loop.
5845 return;
5846 end if;
5847 end Explain_Limited_Type;
5849 -------------------------------
5850 -- Extensions_Visible_Status --
5851 -------------------------------
5853 function Extensions_Visible_Status
5854 (Id : Entity_Id) return Extensions_Visible_Mode
5856 Arg : Node_Id;
5857 Decl : Node_Id;
5858 Expr : Node_Id;
5859 Prag : Node_Id;
5860 Subp : Entity_Id;
5862 begin
5863 -- When a formal parameter is subject to Extensions_Visible, the pragma
5864 -- is stored in the contract of related subprogram.
5866 if Is_Formal (Id) then
5867 Subp := Scope (Id);
5869 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
5870 Subp := Id;
5872 -- No other construct carries this pragma
5874 else
5875 return Extensions_Visible_None;
5876 end if;
5878 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
5880 -- In certain cases analysis may request the Extensions_Visible status
5881 -- of an expression function before the pragma has been analyzed yet.
5882 -- Inspect the declarative items after the expression function looking
5883 -- for the pragma (if any).
5885 if No (Prag) and then Is_Expression_Function (Subp) then
5886 Decl := Next (Unit_Declaration_Node (Subp));
5887 while Present (Decl) loop
5888 if Nkind (Decl) = N_Pragma
5889 and then Pragma_Name (Decl) = Name_Extensions_Visible
5890 then
5891 Prag := Decl;
5892 exit;
5894 -- A source construct ends the region where Extensions_Visible may
5895 -- appear, stop the traversal. An expanded expression function is
5896 -- no longer a source construct, but it must still be recognized.
5898 elsif Comes_From_Source (Decl)
5899 or else
5900 (Nkind_In (Decl, N_Subprogram_Body,
5901 N_Subprogram_Declaration)
5902 and then Is_Expression_Function (Defining_Entity (Decl)))
5903 then
5904 exit;
5905 end if;
5907 Next (Decl);
5908 end loop;
5909 end if;
5911 -- Extract the value from the Boolean expression (if any)
5913 if Present (Prag) then
5914 Arg := First (Pragma_Argument_Associations (Prag));
5916 if Present (Arg) then
5917 Expr := Get_Pragma_Arg (Arg);
5919 -- When the associated subprogram is an expression function, the
5920 -- argument of the pragma may not have been analyzed.
5922 if not Analyzed (Expr) then
5923 Preanalyze_And_Resolve (Expr, Standard_Boolean);
5924 end if;
5926 -- Guard against cascading errors when the argument of pragma
5927 -- Extensions_Visible is not a valid static Boolean expression.
5929 if Error_Posted (Expr) then
5930 return Extensions_Visible_None;
5932 elsif Is_True (Expr_Value (Expr)) then
5933 return Extensions_Visible_True;
5935 else
5936 return Extensions_Visible_False;
5937 end if;
5939 -- Otherwise the aspect or pragma defaults to True
5941 else
5942 return Extensions_Visible_True;
5943 end if;
5945 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
5946 -- directly specified. In SPARK code, its value defaults to "False".
5948 elsif SPARK_Mode = On then
5949 return Extensions_Visible_False;
5951 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
5952 -- "True".
5954 else
5955 return Extensions_Visible_True;
5956 end if;
5957 end Extensions_Visible_Status;
5959 -----------------
5960 -- Find_Actual --
5961 -----------------
5963 procedure Find_Actual
5964 (N : Node_Id;
5965 Formal : out Entity_Id;
5966 Call : out Node_Id)
5968 Parnt : constant Node_Id := Parent (N);
5969 Actual : Node_Id;
5971 begin
5972 if Nkind_In (Parnt, N_Indexed_Component, N_Selected_Component)
5973 and then N = Prefix (Parnt)
5974 then
5975 Find_Actual (Parnt, Formal, Call);
5976 return;
5978 elsif Nkind (Parnt) = N_Parameter_Association
5979 and then N = Explicit_Actual_Parameter (Parnt)
5980 then
5981 Call := Parent (Parnt);
5983 elsif Nkind (Parnt) in N_Subprogram_Call then
5984 Call := Parnt;
5986 else
5987 Formal := Empty;
5988 Call := Empty;
5989 return;
5990 end if;
5992 -- If we have a call to a subprogram look for the parameter. Note that
5993 -- we exclude overloaded calls, since we don't know enough to be sure
5994 -- of giving the right answer in this case.
5996 if Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
5997 and then Is_Entity_Name (Name (Call))
5998 and then Present (Entity (Name (Call)))
5999 and then Is_Overloadable (Entity (Name (Call)))
6000 and then not Is_Overloaded (Name (Call))
6001 then
6002 -- If node is name in call it is not an actual
6004 if N = Name (Call) then
6005 Call := Empty;
6006 Formal := Empty;
6007 return;
6008 end if;
6010 -- Fall here if we are definitely a parameter
6012 Actual := First_Actual (Call);
6013 Formal := First_Formal (Entity (Name (Call)));
6014 while Present (Formal) and then Present (Actual) loop
6015 if Actual = N then
6016 return;
6018 -- An actual that is the prefix in a prefixed call may have
6019 -- been rewritten in the call, after the deferred reference
6020 -- was collected. Check if sloc and kinds and names match.
6022 elsif Sloc (Actual) = Sloc (N)
6023 and then Nkind (Actual) = N_Identifier
6024 and then Nkind (Actual) = Nkind (N)
6025 and then Chars (Actual) = Chars (N)
6026 then
6027 return;
6029 else
6030 Actual := Next_Actual (Actual);
6031 Formal := Next_Formal (Formal);
6032 end if;
6033 end loop;
6034 end if;
6036 -- Fall through here if we did not find matching actual
6038 Formal := Empty;
6039 Call := Empty;
6040 end Find_Actual;
6042 ---------------------------
6043 -- Find_Body_Discriminal --
6044 ---------------------------
6046 function Find_Body_Discriminal
6047 (Spec_Discriminant : Entity_Id) return Entity_Id
6049 Tsk : Entity_Id;
6050 Disc : Entity_Id;
6052 begin
6053 -- If expansion is suppressed, then the scope can be the concurrent type
6054 -- itself rather than a corresponding concurrent record type.
6056 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6057 Tsk := Scope (Spec_Discriminant);
6059 else
6060 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6062 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6063 end if;
6065 -- Find discriminant of original concurrent type, and use its current
6066 -- discriminal, which is the renaming within the task/protected body.
6068 Disc := First_Discriminant (Tsk);
6069 while Present (Disc) loop
6070 if Chars (Disc) = Chars (Spec_Discriminant) then
6071 return Discriminal (Disc);
6072 end if;
6074 Next_Discriminant (Disc);
6075 end loop;
6077 -- That loop should always succeed in finding a matching entry and
6078 -- returning. Fatal error if not.
6080 raise Program_Error;
6081 end Find_Body_Discriminal;
6083 -------------------------------------
6084 -- Find_Corresponding_Discriminant --
6085 -------------------------------------
6087 function Find_Corresponding_Discriminant
6088 (Id : Node_Id;
6089 Typ : Entity_Id) return Entity_Id
6091 Par_Disc : Entity_Id;
6092 Old_Disc : Entity_Id;
6093 New_Disc : Entity_Id;
6095 begin
6096 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6098 -- The original type may currently be private, and the discriminant
6099 -- only appear on its full view.
6101 if Is_Private_Type (Scope (Par_Disc))
6102 and then not Has_Discriminants (Scope (Par_Disc))
6103 and then Present (Full_View (Scope (Par_Disc)))
6104 then
6105 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6106 else
6107 Old_Disc := First_Discriminant (Scope (Par_Disc));
6108 end if;
6110 if Is_Class_Wide_Type (Typ) then
6111 New_Disc := First_Discriminant (Root_Type (Typ));
6112 else
6113 New_Disc := First_Discriminant (Typ);
6114 end if;
6116 while Present (Old_Disc) and then Present (New_Disc) loop
6117 if Old_Disc = Par_Disc then
6118 return New_Disc;
6119 end if;
6121 Next_Discriminant (Old_Disc);
6122 Next_Discriminant (New_Disc);
6123 end loop;
6125 -- Should always find it
6127 raise Program_Error;
6128 end Find_Corresponding_Discriminant;
6130 ----------------------------------
6131 -- Find_Enclosing_Iterator_Loop --
6132 ----------------------------------
6134 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6135 Constr : Node_Id;
6136 S : Entity_Id;
6138 begin
6139 -- Traverse the scope chain looking for an iterator loop. Such loops are
6140 -- usually transformed into blocks, hence the use of Original_Node.
6142 S := Id;
6143 while Present (S) and then S /= Standard_Standard loop
6144 if Ekind (S) = E_Loop
6145 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6146 then
6147 Constr := Original_Node (Label_Construct (Parent (S)));
6149 if Nkind (Constr) = N_Loop_Statement
6150 and then Present (Iteration_Scheme (Constr))
6151 and then Nkind (Iterator_Specification
6152 (Iteration_Scheme (Constr))) =
6153 N_Iterator_Specification
6154 then
6155 return S;
6156 end if;
6157 end if;
6159 S := Scope (S);
6160 end loop;
6162 return Empty;
6163 end Find_Enclosing_Iterator_Loop;
6165 ------------------------------------
6166 -- Find_Loop_In_Conditional_Block --
6167 ------------------------------------
6169 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
6170 Stmt : Node_Id;
6172 begin
6173 Stmt := N;
6175 if Nkind (Stmt) = N_If_Statement then
6176 Stmt := First (Then_Statements (Stmt));
6177 end if;
6179 pragma Assert (Nkind (Stmt) = N_Block_Statement);
6181 -- Inspect the statements of the conditional block. In general the loop
6182 -- should be the first statement in the statement sequence of the block,
6183 -- but the finalization machinery may have introduced extra object
6184 -- declarations.
6186 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
6187 while Present (Stmt) loop
6188 if Nkind (Stmt) = N_Loop_Statement then
6189 return Stmt;
6190 end if;
6192 Next (Stmt);
6193 end loop;
6195 -- The expansion of attribute 'Loop_Entry produced a malformed block
6197 raise Program_Error;
6198 end Find_Loop_In_Conditional_Block;
6200 --------------------------
6201 -- Find_Overlaid_Entity --
6202 --------------------------
6204 procedure Find_Overlaid_Entity
6205 (N : Node_Id;
6206 Ent : out Entity_Id;
6207 Off : out Boolean)
6209 Expr : Node_Id;
6211 begin
6212 -- We are looking for one of the two following forms:
6214 -- for X'Address use Y'Address
6216 -- or
6218 -- Const : constant Address := expr;
6219 -- ...
6220 -- for X'Address use Const;
6222 -- In the second case, the expr is either Y'Address, or recursively a
6223 -- constant that eventually references Y'Address.
6225 Ent := Empty;
6226 Off := False;
6228 if Nkind (N) = N_Attribute_Definition_Clause
6229 and then Chars (N) = Name_Address
6230 then
6231 Expr := Expression (N);
6233 -- This loop checks the form of the expression for Y'Address,
6234 -- using recursion to deal with intermediate constants.
6236 loop
6237 -- Check for Y'Address
6239 if Nkind (Expr) = N_Attribute_Reference
6240 and then Attribute_Name (Expr) = Name_Address
6241 then
6242 Expr := Prefix (Expr);
6243 exit;
6245 -- Check for Const where Const is a constant entity
6247 elsif Is_Entity_Name (Expr)
6248 and then Ekind (Entity (Expr)) = E_Constant
6249 then
6250 Expr := Constant_Value (Entity (Expr));
6252 -- Anything else does not need checking
6254 else
6255 return;
6256 end if;
6257 end loop;
6259 -- This loop checks the form of the prefix for an entity, using
6260 -- recursion to deal with intermediate components.
6262 loop
6263 -- Check for Y where Y is an entity
6265 if Is_Entity_Name (Expr) then
6266 Ent := Entity (Expr);
6267 return;
6269 -- Check for components
6271 elsif
6272 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6273 then
6274 Expr := Prefix (Expr);
6275 Off := True;
6277 -- Anything else does not need checking
6279 else
6280 return;
6281 end if;
6282 end loop;
6283 end if;
6284 end Find_Overlaid_Entity;
6286 -------------------------
6287 -- Find_Parameter_Type --
6288 -------------------------
6290 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6291 begin
6292 if Nkind (Param) /= N_Parameter_Specification then
6293 return Empty;
6295 -- For an access parameter, obtain the type from the formal entity
6296 -- itself, because access to subprogram nodes do not carry a type.
6297 -- Shouldn't we always use the formal entity ???
6299 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6300 return Etype (Defining_Identifier (Param));
6302 else
6303 return Etype (Parameter_Type (Param));
6304 end if;
6305 end Find_Parameter_Type;
6307 -----------------------------------
6308 -- Find_Placement_In_State_Space --
6309 -----------------------------------
6311 procedure Find_Placement_In_State_Space
6312 (Item_Id : Entity_Id;
6313 Placement : out State_Space_Kind;
6314 Pack_Id : out Entity_Id)
6316 Context : Entity_Id;
6318 begin
6319 -- Assume that the item does not appear in the state space of a package
6321 Placement := Not_In_Package;
6322 Pack_Id := Empty;
6324 -- Climb the scope stack and examine the enclosing context
6326 Context := Scope (Item_Id);
6327 while Present (Context) and then Context /= Standard_Standard loop
6328 if Ekind (Context) = E_Package then
6329 Pack_Id := Context;
6331 -- A package body is a cut off point for the traversal as the item
6332 -- cannot be visible to the outside from this point on. Note that
6333 -- this test must be done first as a body is also classified as a
6334 -- private part.
6336 if In_Package_Body (Context) then
6337 Placement := Body_State_Space;
6338 return;
6340 -- The private part of a package is a cut off point for the
6341 -- traversal as the item cannot be visible to the outside from
6342 -- this point on.
6344 elsif In_Private_Part (Context) then
6345 Placement := Private_State_Space;
6346 return;
6348 -- When the item appears in the visible state space of a package,
6349 -- continue to climb the scope stack as this may not be the final
6350 -- state space.
6352 else
6353 Placement := Visible_State_Space;
6355 -- The visible state space of a child unit acts as the proper
6356 -- placement of an item.
6358 if Is_Child_Unit (Context) then
6359 return;
6360 end if;
6361 end if;
6363 -- The item or its enclosing package appear in a construct that has
6364 -- no state space.
6366 else
6367 Placement := Not_In_Package;
6368 return;
6369 end if;
6371 Context := Scope (Context);
6372 end loop;
6373 end Find_Placement_In_State_Space;
6375 ------------------------
6376 -- Find_Specific_Type --
6377 ------------------------
6379 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6380 Typ : Entity_Id := Root_Type (CW);
6382 begin
6383 if Ekind (Typ) = E_Incomplete_Type then
6384 if From_Limited_With (Typ) then
6385 Typ := Non_Limited_View (Typ);
6386 else
6387 Typ := Full_View (Typ);
6388 end if;
6389 end if;
6391 if Is_Private_Type (Typ)
6392 and then not Is_Tagged_Type (Typ)
6393 and then Present (Full_View (Typ))
6394 then
6395 return Full_View (Typ);
6396 else
6397 return Typ;
6398 end if;
6399 end Find_Specific_Type;
6401 -----------------------------
6402 -- Find_Static_Alternative --
6403 -----------------------------
6405 function Find_Static_Alternative (N : Node_Id) return Node_Id is
6406 Expr : constant Node_Id := Expression (N);
6407 Val : constant Uint := Expr_Value (Expr);
6408 Alt : Node_Id;
6409 Choice : Node_Id;
6411 begin
6412 Alt := First (Alternatives (N));
6414 Search : loop
6415 if Nkind (Alt) /= N_Pragma then
6416 Choice := First (Discrete_Choices (Alt));
6417 while Present (Choice) loop
6419 -- Others choice, always matches
6421 if Nkind (Choice) = N_Others_Choice then
6422 exit Search;
6424 -- Range, check if value is in the range
6426 elsif Nkind (Choice) = N_Range then
6427 exit Search when
6428 Val >= Expr_Value (Low_Bound (Choice))
6429 and then
6430 Val <= Expr_Value (High_Bound (Choice));
6432 -- Choice is a subtype name. Note that we know it must
6433 -- be a static subtype, since otherwise it would have
6434 -- been diagnosed as illegal.
6436 elsif Is_Entity_Name (Choice)
6437 and then Is_Type (Entity (Choice))
6438 then
6439 exit Search when Is_In_Range (Expr, Etype (Choice),
6440 Assume_Valid => False);
6442 -- Choice is a subtype indication
6444 elsif Nkind (Choice) = N_Subtype_Indication then
6445 declare
6446 C : constant Node_Id := Constraint (Choice);
6447 R : constant Node_Id := Range_Expression (C);
6449 begin
6450 exit Search when
6451 Val >= Expr_Value (Low_Bound (R))
6452 and then
6453 Val <= Expr_Value (High_Bound (R));
6454 end;
6456 -- Choice is a simple expression
6458 else
6459 exit Search when Val = Expr_Value (Choice);
6460 end if;
6462 Next (Choice);
6463 end loop;
6464 end if;
6466 Next (Alt);
6467 pragma Assert (Present (Alt));
6468 end loop Search;
6470 -- The above loop *must* terminate by finding a match, since
6471 -- we know the case statement is valid, and the value of the
6472 -- expression is known at compile time. When we fall out of
6473 -- the loop, Alt points to the alternative that we know will
6474 -- be selected at run time.
6476 return Alt;
6477 end Find_Static_Alternative;
6479 ------------------
6480 -- First_Actual --
6481 ------------------
6483 function First_Actual (Node : Node_Id) return Node_Id is
6484 N : Node_Id;
6486 begin
6487 if No (Parameter_Associations (Node)) then
6488 return Empty;
6489 end if;
6491 N := First (Parameter_Associations (Node));
6493 if Nkind (N) = N_Parameter_Association then
6494 return First_Named_Actual (Node);
6495 else
6496 return N;
6497 end if;
6498 end First_Actual;
6500 -----------------------
6501 -- Gather_Components --
6502 -----------------------
6504 procedure Gather_Components
6505 (Typ : Entity_Id;
6506 Comp_List : Node_Id;
6507 Governed_By : List_Id;
6508 Into : Elist_Id;
6509 Report_Errors : out Boolean)
6511 Assoc : Node_Id;
6512 Variant : Node_Id;
6513 Discrete_Choice : Node_Id;
6514 Comp_Item : Node_Id;
6516 Discrim : Entity_Id;
6517 Discrim_Name : Node_Id;
6518 Discrim_Value : Node_Id;
6520 begin
6521 Report_Errors := False;
6523 if No (Comp_List) or else Null_Present (Comp_List) then
6524 return;
6526 elsif Present (Component_Items (Comp_List)) then
6527 Comp_Item := First (Component_Items (Comp_List));
6529 else
6530 Comp_Item := Empty;
6531 end if;
6533 while Present (Comp_Item) loop
6535 -- Skip the tag of a tagged record, the interface tags, as well
6536 -- as all items that are not user components (anonymous types,
6537 -- rep clauses, Parent field, controller field).
6539 if Nkind (Comp_Item) = N_Component_Declaration then
6540 declare
6541 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
6542 begin
6543 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
6544 Append_Elmt (Comp, Into);
6545 end if;
6546 end;
6547 end if;
6549 Next (Comp_Item);
6550 end loop;
6552 if No (Variant_Part (Comp_List)) then
6553 return;
6554 else
6555 Discrim_Name := Name (Variant_Part (Comp_List));
6556 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
6557 end if;
6559 -- Look for the discriminant that governs this variant part.
6560 -- The discriminant *must* be in the Governed_By List
6562 Assoc := First (Governed_By);
6563 Find_Constraint : loop
6564 Discrim := First (Choices (Assoc));
6565 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
6566 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
6567 and then
6568 Chars (Corresponding_Discriminant (Entity (Discrim))) =
6569 Chars (Discrim_Name))
6570 or else Chars (Original_Record_Component (Entity (Discrim)))
6571 = Chars (Discrim_Name);
6573 if No (Next (Assoc)) then
6574 if not Is_Constrained (Typ)
6575 and then Is_Derived_Type (Typ)
6576 and then Present (Stored_Constraint (Typ))
6577 then
6578 -- If the type is a tagged type with inherited discriminants,
6579 -- use the stored constraint on the parent in order to find
6580 -- the values of discriminants that are otherwise hidden by an
6581 -- explicit constraint. Renamed discriminants are handled in
6582 -- the code above.
6584 -- If several parent discriminants are renamed by a single
6585 -- discriminant of the derived type, the call to obtain the
6586 -- Corresponding_Discriminant field only retrieves the last
6587 -- of them. We recover the constraint on the others from the
6588 -- Stored_Constraint as well.
6590 declare
6591 D : Entity_Id;
6592 C : Elmt_Id;
6594 begin
6595 D := First_Discriminant (Etype (Typ));
6596 C := First_Elmt (Stored_Constraint (Typ));
6597 while Present (D) and then Present (C) loop
6598 if Chars (Discrim_Name) = Chars (D) then
6599 if Is_Entity_Name (Node (C))
6600 and then Entity (Node (C)) = Entity (Discrim)
6601 then
6602 -- D is renamed by Discrim, whose value is given in
6603 -- Assoc.
6605 null;
6607 else
6608 Assoc :=
6609 Make_Component_Association (Sloc (Typ),
6610 New_List
6611 (New_Occurrence_Of (D, Sloc (Typ))),
6612 Duplicate_Subexpr_No_Checks (Node (C)));
6613 end if;
6614 exit Find_Constraint;
6615 end if;
6617 Next_Discriminant (D);
6618 Next_Elmt (C);
6619 end loop;
6620 end;
6621 end if;
6622 end if;
6624 if No (Next (Assoc)) then
6625 Error_Msg_NE (" missing value for discriminant&",
6626 First (Governed_By), Discrim_Name);
6627 Report_Errors := True;
6628 return;
6629 end if;
6631 Next (Assoc);
6632 end loop Find_Constraint;
6634 Discrim_Value := Expression (Assoc);
6636 if not Is_OK_Static_Expression (Discrim_Value) then
6638 -- If the variant part is governed by a discriminant of the type
6639 -- this is an error. If the variant part and the discriminant are
6640 -- inherited from an ancestor this is legal (AI05-120) unless the
6641 -- components are being gathered for an aggregate, in which case
6642 -- the caller must check Report_Errors.
6644 if Scope (Original_Record_Component
6645 ((Entity (First (Choices (Assoc)))))) = Typ
6646 then
6647 Error_Msg_FE
6648 ("value for discriminant & must be static!",
6649 Discrim_Value, Discrim);
6650 Why_Not_Static (Discrim_Value);
6651 end if;
6653 Report_Errors := True;
6654 return;
6655 end if;
6657 Search_For_Discriminant_Value : declare
6658 Low : Node_Id;
6659 High : Node_Id;
6661 UI_High : Uint;
6662 UI_Low : Uint;
6663 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
6665 begin
6666 Find_Discrete_Value : while Present (Variant) loop
6667 Discrete_Choice := First (Discrete_Choices (Variant));
6668 while Present (Discrete_Choice) loop
6669 exit Find_Discrete_Value when
6670 Nkind (Discrete_Choice) = N_Others_Choice;
6672 Get_Index_Bounds (Discrete_Choice, Low, High);
6674 UI_Low := Expr_Value (Low);
6675 UI_High := Expr_Value (High);
6677 exit Find_Discrete_Value when
6678 UI_Low <= UI_Discrim_Value
6679 and then
6680 UI_High >= UI_Discrim_Value;
6682 Next (Discrete_Choice);
6683 end loop;
6685 Next_Non_Pragma (Variant);
6686 end loop Find_Discrete_Value;
6687 end Search_For_Discriminant_Value;
6689 if No (Variant) then
6690 Error_Msg_NE
6691 ("value of discriminant & is out of range", Discrim_Value, Discrim);
6692 Report_Errors := True;
6693 return;
6694 end if;
6696 -- If we have found the corresponding choice, recursively add its
6697 -- components to the Into list.
6699 Gather_Components
6700 (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
6701 end Gather_Components;
6703 ------------------------
6704 -- Get_Actual_Subtype --
6705 ------------------------
6707 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
6708 Typ : constant Entity_Id := Etype (N);
6709 Utyp : Entity_Id := Underlying_Type (Typ);
6710 Decl : Node_Id;
6711 Atyp : Entity_Id;
6713 begin
6714 if No (Utyp) then
6715 Utyp := Typ;
6716 end if;
6718 -- If what we have is an identifier that references a subprogram
6719 -- formal, or a variable or constant object, then we get the actual
6720 -- subtype from the referenced entity if one has been built.
6722 if Nkind (N) = N_Identifier
6723 and then
6724 (Is_Formal (Entity (N))
6725 or else Ekind (Entity (N)) = E_Constant
6726 or else Ekind (Entity (N)) = E_Variable)
6727 and then Present (Actual_Subtype (Entity (N)))
6728 then
6729 return Actual_Subtype (Entity (N));
6731 -- Actual subtype of unchecked union is always itself. We never need
6732 -- the "real" actual subtype. If we did, we couldn't get it anyway
6733 -- because the discriminant is not available. The restrictions on
6734 -- Unchecked_Union are designed to make sure that this is OK.
6736 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
6737 return Typ;
6739 -- Here for the unconstrained case, we must find actual subtype
6740 -- No actual subtype is available, so we must build it on the fly.
6742 -- Checking the type, not the underlying type, for constrainedness
6743 -- seems to be necessary. Maybe all the tests should be on the type???
6745 elsif (not Is_Constrained (Typ))
6746 and then (Is_Array_Type (Utyp)
6747 or else (Is_Record_Type (Utyp)
6748 and then Has_Discriminants (Utyp)))
6749 and then not Has_Unknown_Discriminants (Utyp)
6750 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
6751 then
6752 -- Nothing to do if in spec expression (why not???)
6754 if In_Spec_Expression then
6755 return Typ;
6757 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
6759 -- If the type has no discriminants, there is no subtype to
6760 -- build, even if the underlying type is discriminated.
6762 return Typ;
6764 -- Else build the actual subtype
6766 else
6767 Decl := Build_Actual_Subtype (Typ, N);
6768 Atyp := Defining_Identifier (Decl);
6770 -- If Build_Actual_Subtype generated a new declaration then use it
6772 if Atyp /= Typ then
6774 -- The actual subtype is an Itype, so analyze the declaration,
6775 -- but do not attach it to the tree, to get the type defined.
6777 Set_Parent (Decl, N);
6778 Set_Is_Itype (Atyp);
6779 Analyze (Decl, Suppress => All_Checks);
6780 Set_Associated_Node_For_Itype (Atyp, N);
6781 Set_Has_Delayed_Freeze (Atyp, False);
6783 -- We need to freeze the actual subtype immediately. This is
6784 -- needed, because otherwise this Itype will not get frozen
6785 -- at all, and it is always safe to freeze on creation because
6786 -- any associated types must be frozen at this point.
6788 Freeze_Itype (Atyp, N);
6789 return Atyp;
6791 -- Otherwise we did not build a declaration, so return original
6793 else
6794 return Typ;
6795 end if;
6796 end if;
6798 -- For all remaining cases, the actual subtype is the same as
6799 -- the nominal type.
6801 else
6802 return Typ;
6803 end if;
6804 end Get_Actual_Subtype;
6806 -------------------------------------
6807 -- Get_Actual_Subtype_If_Available --
6808 -------------------------------------
6810 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
6811 Typ : constant Entity_Id := Etype (N);
6813 begin
6814 -- If what we have is an identifier that references a subprogram
6815 -- formal, or a variable or constant object, then we get the actual
6816 -- subtype from the referenced entity if one has been built.
6818 if Nkind (N) = N_Identifier
6819 and then
6820 (Is_Formal (Entity (N))
6821 or else Ekind (Entity (N)) = E_Constant
6822 or else Ekind (Entity (N)) = E_Variable)
6823 and then Present (Actual_Subtype (Entity (N)))
6824 then
6825 return Actual_Subtype (Entity (N));
6827 -- Otherwise the Etype of N is returned unchanged
6829 else
6830 return Typ;
6831 end if;
6832 end Get_Actual_Subtype_If_Available;
6834 ------------------------
6835 -- Get_Body_From_Stub --
6836 ------------------------
6838 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
6839 begin
6840 return Proper_Body (Unit (Library_Unit (N)));
6841 end Get_Body_From_Stub;
6843 ---------------------
6844 -- Get_Cursor_Type --
6845 ---------------------
6847 function Get_Cursor_Type
6848 (Aspect : Node_Id;
6849 Typ : Entity_Id) return Entity_Id
6851 Assoc : Node_Id;
6852 Func : Entity_Id;
6853 First_Op : Entity_Id;
6854 Cursor : Entity_Id;
6856 begin
6857 -- If error already detected, return
6859 if Error_Posted (Aspect) then
6860 return Any_Type;
6861 end if;
6863 -- The cursor type for an Iterable aspect is the return type of a
6864 -- non-overloaded First primitive operation. Locate association for
6865 -- First.
6867 Assoc := First (Component_Associations (Expression (Aspect)));
6868 First_Op := Any_Id;
6869 while Present (Assoc) loop
6870 if Chars (First (Choices (Assoc))) = Name_First then
6871 First_Op := Expression (Assoc);
6872 exit;
6873 end if;
6875 Next (Assoc);
6876 end loop;
6878 if First_Op = Any_Id then
6879 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
6880 return Any_Type;
6881 end if;
6883 Cursor := Any_Type;
6885 -- Locate function with desired name and profile in scope of type
6887 Func := First_Entity (Scope (Typ));
6888 while Present (Func) loop
6889 if Chars (Func) = Chars (First_Op)
6890 and then Ekind (Func) = E_Function
6891 and then Present (First_Formal (Func))
6892 and then Etype (First_Formal (Func)) = Typ
6893 and then No (Next_Formal (First_Formal (Func)))
6894 then
6895 if Cursor /= Any_Type then
6896 Error_Msg_N
6897 ("Operation First for iterable type must be unique", Aspect);
6898 return Any_Type;
6899 else
6900 Cursor := Etype (Func);
6901 end if;
6902 end if;
6904 Next_Entity (Func);
6905 end loop;
6907 -- If not found, no way to resolve remaining primitives.
6909 if Cursor = Any_Type then
6910 Error_Msg_N
6911 ("No legal primitive operation First for Iterable type", Aspect);
6912 end if;
6914 return Cursor;
6915 end Get_Cursor_Type;
6917 -------------------------------
6918 -- Get_Default_External_Name --
6919 -------------------------------
6921 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
6922 begin
6923 Get_Decoded_Name_String (Chars (E));
6925 if Opt.External_Name_Imp_Casing = Uppercase then
6926 Set_Casing (All_Upper_Case);
6927 else
6928 Set_Casing (All_Lower_Case);
6929 end if;
6931 return
6932 Make_String_Literal (Sloc (E),
6933 Strval => String_From_Name_Buffer);
6934 end Get_Default_External_Name;
6936 --------------------------
6937 -- Get_Enclosing_Object --
6938 --------------------------
6940 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
6941 begin
6942 if Is_Entity_Name (N) then
6943 return Entity (N);
6944 else
6945 case Nkind (N) is
6946 when N_Indexed_Component |
6947 N_Slice |
6948 N_Selected_Component =>
6950 -- If not generating code, a dereference may be left implicit.
6951 -- In thoses cases, return Empty.
6953 if Is_Access_Type (Etype (Prefix (N))) then
6954 return Empty;
6955 else
6956 return Get_Enclosing_Object (Prefix (N));
6957 end if;
6959 when N_Type_Conversion =>
6960 return Get_Enclosing_Object (Expression (N));
6962 when others =>
6963 return Empty;
6964 end case;
6965 end if;
6966 end Get_Enclosing_Object;
6968 ---------------------------
6969 -- Get_Enum_Lit_From_Pos --
6970 ---------------------------
6972 function Get_Enum_Lit_From_Pos
6973 (T : Entity_Id;
6974 Pos : Uint;
6975 Loc : Source_Ptr) return Node_Id
6977 Btyp : Entity_Id := Base_Type (T);
6978 Lit : Node_Id;
6980 begin
6981 -- In the case where the literal is of type Character, Wide_Character
6982 -- or Wide_Wide_Character or of a type derived from them, there needs
6983 -- to be some special handling since there is no explicit chain of
6984 -- literals to search. Instead, an N_Character_Literal node is created
6985 -- with the appropriate Char_Code and Chars fields.
6987 if Is_Standard_Character_Type (T) then
6988 Set_Character_Literal_Name (UI_To_CC (Pos));
6989 return
6990 Make_Character_Literal (Loc,
6991 Chars => Name_Find,
6992 Char_Literal_Value => Pos);
6994 -- For all other cases, we have a complete table of literals, and
6995 -- we simply iterate through the chain of literal until the one
6996 -- with the desired position value is found.
6998 else
6999 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7000 Btyp := Full_View (Btyp);
7001 end if;
7003 Lit := First_Literal (Btyp);
7004 for J in 1 .. UI_To_Int (Pos) loop
7005 Next_Literal (Lit);
7006 end loop;
7008 return New_Occurrence_Of (Lit, Loc);
7009 end if;
7010 end Get_Enum_Lit_From_Pos;
7012 ---------------------------------
7013 -- Get_Ensures_From_CTC_Pragma --
7014 ---------------------------------
7016 function Get_Ensures_From_CTC_Pragma (N : Node_Id) return Node_Id is
7017 Args : constant List_Id := Pragma_Argument_Associations (N);
7018 Res : Node_Id;
7020 begin
7021 if List_Length (Args) = 4 then
7022 Res := Pick (Args, 4);
7024 elsif List_Length (Args) = 3 then
7025 Res := Pick (Args, 3);
7027 if Chars (Res) /= Name_Ensures then
7028 Res := Empty;
7029 end if;
7031 else
7032 Res := Empty;
7033 end if;
7035 return Res;
7036 end Get_Ensures_From_CTC_Pragma;
7038 ------------------------
7039 -- Get_Generic_Entity --
7040 ------------------------
7042 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7043 Ent : constant Entity_Id := Entity (Name (N));
7044 begin
7045 if Present (Renamed_Object (Ent)) then
7046 return Renamed_Object (Ent);
7047 else
7048 return Ent;
7049 end if;
7050 end Get_Generic_Entity;
7052 -------------------------------------
7053 -- Get_Incomplete_View_Of_Ancestor --
7054 -------------------------------------
7056 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7057 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7058 Par_Scope : Entity_Id;
7059 Par_Type : Entity_Id;
7061 begin
7062 -- The incomplete view of an ancestor is only relevant for private
7063 -- derived types in child units.
7065 if not Is_Derived_Type (E)
7066 or else not Is_Child_Unit (Cur_Unit)
7067 then
7068 return Empty;
7070 else
7071 Par_Scope := Scope (Cur_Unit);
7072 if No (Par_Scope) then
7073 return Empty;
7074 end if;
7076 Par_Type := Etype (Base_Type (E));
7078 -- Traverse list of ancestor types until we find one declared in
7079 -- a parent or grandparent unit (two levels seem sufficient).
7081 while Present (Par_Type) loop
7082 if Scope (Par_Type) = Par_Scope
7083 or else Scope (Par_Type) = Scope (Par_Scope)
7084 then
7085 return Par_Type;
7087 elsif not Is_Derived_Type (Par_Type) then
7088 return Empty;
7090 else
7091 Par_Type := Etype (Base_Type (Par_Type));
7092 end if;
7093 end loop;
7095 -- If none found, there is no relevant ancestor type.
7097 return Empty;
7098 end if;
7099 end Get_Incomplete_View_Of_Ancestor;
7101 ----------------------
7102 -- Get_Index_Bounds --
7103 ----------------------
7105 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
7106 Kind : constant Node_Kind := Nkind (N);
7107 R : Node_Id;
7109 begin
7110 if Kind = N_Range then
7111 L := Low_Bound (N);
7112 H := High_Bound (N);
7114 elsif Kind = N_Subtype_Indication then
7115 R := Range_Expression (Constraint (N));
7117 if R = Error then
7118 L := Error;
7119 H := Error;
7120 return;
7122 else
7123 L := Low_Bound (Range_Expression (Constraint (N)));
7124 H := High_Bound (Range_Expression (Constraint (N)));
7125 end if;
7127 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
7128 if Error_Posted (Scalar_Range (Entity (N))) then
7129 L := Error;
7130 H := Error;
7132 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
7133 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
7135 else
7136 L := Low_Bound (Scalar_Range (Entity (N)));
7137 H := High_Bound (Scalar_Range (Entity (N)));
7138 end if;
7140 else
7141 -- N is an expression, indicating a range with one value
7143 L := N;
7144 H := N;
7145 end if;
7146 end Get_Index_Bounds;
7148 ---------------------------------
7149 -- Get_Iterable_Type_Primitive --
7150 ---------------------------------
7152 function Get_Iterable_Type_Primitive
7153 (Typ : Entity_Id;
7154 Nam : Name_Id) return Entity_Id
7156 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
7157 Assoc : Node_Id;
7159 begin
7160 if No (Funcs) then
7161 return Empty;
7163 else
7164 Assoc := First (Component_Associations (Funcs));
7165 while Present (Assoc) loop
7166 if Chars (First (Choices (Assoc))) = Nam then
7167 return Entity (Expression (Assoc));
7168 end if;
7170 Assoc := Next (Assoc);
7171 end loop;
7173 return Empty;
7174 end if;
7175 end Get_Iterable_Type_Primitive;
7177 ----------------------------------
7178 -- Get_Library_Unit_Name_string --
7179 ----------------------------------
7181 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
7182 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
7184 begin
7185 Get_Unit_Name_String (Unit_Name_Id);
7187 -- Remove seven last character (" (spec)" or " (body)")
7189 Name_Len := Name_Len - 7;
7190 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
7191 end Get_Library_Unit_Name_String;
7193 ------------------------
7194 -- Get_Name_Entity_Id --
7195 ------------------------
7197 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
7198 begin
7199 return Entity_Id (Get_Name_Table_Int (Id));
7200 end Get_Name_Entity_Id;
7202 ------------------------------
7203 -- Get_Name_From_CTC_Pragma --
7204 ------------------------------
7206 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
7207 Arg : constant Node_Id :=
7208 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
7209 begin
7210 return Strval (Expr_Value_S (Arg));
7211 end Get_Name_From_CTC_Pragma;
7213 -----------------------
7214 -- Get_Parent_Entity --
7215 -----------------------
7217 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
7218 begin
7219 if Nkind (Unit) = N_Package_Body
7220 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
7221 then
7222 return Defining_Entity
7223 (Specification (Instance_Spec (Original_Node (Unit))));
7224 elsif Nkind (Unit) = N_Package_Instantiation then
7225 return Defining_Entity (Specification (Instance_Spec (Unit)));
7226 else
7227 return Defining_Entity (Unit);
7228 end if;
7229 end Get_Parent_Entity;
7230 -------------------
7231 -- Get_Pragma_Id --
7232 -------------------
7234 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
7235 begin
7236 return Get_Pragma_Id (Pragma_Name (N));
7237 end Get_Pragma_Id;
7239 -----------------------
7240 -- Get_Reason_String --
7241 -----------------------
7243 procedure Get_Reason_String (N : Node_Id) is
7244 begin
7245 if Nkind (N) = N_String_Literal then
7246 Store_String_Chars (Strval (N));
7248 elsif Nkind (N) = N_Op_Concat then
7249 Get_Reason_String (Left_Opnd (N));
7250 Get_Reason_String (Right_Opnd (N));
7252 -- If not of required form, error
7254 else
7255 Error_Msg_N
7256 ("Reason for pragma Warnings has wrong form", N);
7257 Error_Msg_N
7258 ("\must be string literal or concatenation of string literals", N);
7259 return;
7260 end if;
7261 end Get_Reason_String;
7263 ---------------------------
7264 -- Get_Referenced_Object --
7265 ---------------------------
7267 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7268 R : Node_Id;
7270 begin
7271 R := N;
7272 while Is_Entity_Name (R)
7273 and then Present (Renamed_Object (Entity (R)))
7274 loop
7275 R := Renamed_Object (Entity (R));
7276 end loop;
7278 return R;
7279 end Get_Referenced_Object;
7281 ------------------------
7282 -- Get_Renamed_Entity --
7283 ------------------------
7285 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7286 R : Entity_Id;
7288 begin
7289 R := E;
7290 while Present (Renamed_Entity (R)) loop
7291 R := Renamed_Entity (R);
7292 end loop;
7294 return R;
7295 end Get_Renamed_Entity;
7297 ----------------------------------
7298 -- Get_Requires_From_CTC_Pragma --
7299 ----------------------------------
7301 function Get_Requires_From_CTC_Pragma (N : Node_Id) return Node_Id is
7302 Args : constant List_Id := Pragma_Argument_Associations (N);
7303 Res : Node_Id;
7305 begin
7306 if List_Length (Args) >= 3 then
7307 Res := Pick (Args, 3);
7309 if Chars (Res) /= Name_Requires then
7310 Res := Empty;
7311 end if;
7313 else
7314 Res := Empty;
7315 end if;
7317 return Res;
7318 end Get_Requires_From_CTC_Pragma;
7320 -------------------------
7321 -- Get_Subprogram_Body --
7322 -------------------------
7324 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
7325 Decl : Node_Id;
7327 begin
7328 Decl := Unit_Declaration_Node (E);
7330 if Nkind (Decl) = N_Subprogram_Body then
7331 return Decl;
7333 -- The below comment is bad, because it is possible for
7334 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7336 else -- Nkind (Decl) = N_Subprogram_Declaration
7338 if Present (Corresponding_Body (Decl)) then
7339 return Unit_Declaration_Node (Corresponding_Body (Decl));
7341 -- Imported subprogram case
7343 else
7344 return Empty;
7345 end if;
7346 end if;
7347 end Get_Subprogram_Body;
7349 ---------------------------
7350 -- Get_Subprogram_Entity --
7351 ---------------------------
7353 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7354 Subp : Node_Id;
7355 Subp_Id : Entity_Id;
7357 begin
7358 if Nkind (Nod) = N_Accept_Statement then
7359 Subp := Entry_Direct_Name (Nod);
7361 elsif Nkind (Nod) = N_Slice then
7362 Subp := Prefix (Nod);
7364 else
7365 Subp := Name (Nod);
7366 end if;
7368 -- Strip the subprogram call
7370 loop
7371 if Nkind_In (Subp, N_Explicit_Dereference,
7372 N_Indexed_Component,
7373 N_Selected_Component)
7374 then
7375 Subp := Prefix (Subp);
7377 elsif Nkind_In (Subp, N_Type_Conversion,
7378 N_Unchecked_Type_Conversion)
7379 then
7380 Subp := Expression (Subp);
7382 else
7383 exit;
7384 end if;
7385 end loop;
7387 -- Extract the entity of the subprogram call
7389 if Is_Entity_Name (Subp) then
7390 Subp_Id := Entity (Subp);
7392 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
7393 Subp_Id := Directly_Designated_Type (Subp_Id);
7394 end if;
7396 if Is_Subprogram (Subp_Id) then
7397 return Subp_Id;
7398 else
7399 return Empty;
7400 end if;
7402 -- The search did not find a construct that denotes a subprogram
7404 else
7405 return Empty;
7406 end if;
7407 end Get_Subprogram_Entity;
7409 -----------------------------
7410 -- Get_Task_Body_Procedure --
7411 -----------------------------
7413 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
7414 begin
7415 -- Note: A task type may be the completion of a private type with
7416 -- discriminants. When performing elaboration checks on a task
7417 -- declaration, the current view of the type may be the private one,
7418 -- and the procedure that holds the body of the task is held in its
7419 -- underlying type.
7421 -- This is an odd function, why not have Task_Body_Procedure do
7422 -- the following digging???
7424 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
7425 end Get_Task_Body_Procedure;
7427 -----------------------
7428 -- Has_Access_Values --
7429 -----------------------
7431 function Has_Access_Values (T : Entity_Id) return Boolean is
7432 Typ : constant Entity_Id := Underlying_Type (T);
7434 begin
7435 -- Case of a private type which is not completed yet. This can only
7436 -- happen in the case of a generic format type appearing directly, or
7437 -- as a component of the type to which this function is being applied
7438 -- at the top level. Return False in this case, since we certainly do
7439 -- not know that the type contains access types.
7441 if No (Typ) then
7442 return False;
7444 elsif Is_Access_Type (Typ) then
7445 return True;
7447 elsif Is_Array_Type (Typ) then
7448 return Has_Access_Values (Component_Type (Typ));
7450 elsif Is_Record_Type (Typ) then
7451 declare
7452 Comp : Entity_Id;
7454 begin
7455 -- Loop to Check components
7457 Comp := First_Component_Or_Discriminant (Typ);
7458 while Present (Comp) loop
7460 -- Check for access component, tag field does not count, even
7461 -- though it is implemented internally using an access type.
7463 if Has_Access_Values (Etype (Comp))
7464 and then Chars (Comp) /= Name_uTag
7465 then
7466 return True;
7467 end if;
7469 Next_Component_Or_Discriminant (Comp);
7470 end loop;
7471 end;
7473 return False;
7475 else
7476 return False;
7477 end if;
7478 end Has_Access_Values;
7480 ------------------------------
7481 -- Has_Compatible_Alignment --
7482 ------------------------------
7484 function Has_Compatible_Alignment
7485 (Obj : Entity_Id;
7486 Expr : Node_Id) return Alignment_Result
7488 function Has_Compatible_Alignment_Internal
7489 (Obj : Entity_Id;
7490 Expr : Node_Id;
7491 Default : Alignment_Result) return Alignment_Result;
7492 -- This is the internal recursive function that actually does the work.
7493 -- There is one additional parameter, which says what the result should
7494 -- be if no alignment information is found, and there is no definite
7495 -- indication of compatible alignments. At the outer level, this is set
7496 -- to Unknown, but for internal recursive calls in the case where types
7497 -- are known to be correct, it is set to Known_Compatible.
7499 ---------------------------------------
7500 -- Has_Compatible_Alignment_Internal --
7501 ---------------------------------------
7503 function Has_Compatible_Alignment_Internal
7504 (Obj : Entity_Id;
7505 Expr : Node_Id;
7506 Default : Alignment_Result) return Alignment_Result
7508 Result : Alignment_Result := Known_Compatible;
7509 -- Holds the current status of the result. Note that once a value of
7510 -- Known_Incompatible is set, it is sticky and does not get changed
7511 -- to Unknown (the value in Result only gets worse as we go along,
7512 -- never better).
7514 Offs : Uint := No_Uint;
7515 -- Set to a factor of the offset from the base object when Expr is a
7516 -- selected or indexed component, based on Component_Bit_Offset and
7517 -- Component_Size respectively. A negative value is used to represent
7518 -- a value which is not known at compile time.
7520 procedure Check_Prefix;
7521 -- Checks the prefix recursively in the case where the expression
7522 -- is an indexed or selected component.
7524 procedure Set_Result (R : Alignment_Result);
7525 -- If R represents a worse outcome (unknown instead of known
7526 -- compatible, or known incompatible), then set Result to R.
7528 ------------------
7529 -- Check_Prefix --
7530 ------------------
7532 procedure Check_Prefix is
7533 begin
7534 -- The subtlety here is that in doing a recursive call to check
7535 -- the prefix, we have to decide what to do in the case where we
7536 -- don't find any specific indication of an alignment problem.
7538 -- At the outer level, we normally set Unknown as the result in
7539 -- this case, since we can only set Known_Compatible if we really
7540 -- know that the alignment value is OK, but for the recursive
7541 -- call, in the case where the types match, and we have not
7542 -- specified a peculiar alignment for the object, we are only
7543 -- concerned about suspicious rep clauses, the default case does
7544 -- not affect us, since the compiler will, in the absence of such
7545 -- rep clauses, ensure that the alignment is correct.
7547 if Default = Known_Compatible
7548 or else
7549 (Etype (Obj) = Etype (Expr)
7550 and then (Unknown_Alignment (Obj)
7551 or else
7552 Alignment (Obj) = Alignment (Etype (Obj))))
7553 then
7554 Set_Result
7555 (Has_Compatible_Alignment_Internal
7556 (Obj, Prefix (Expr), Known_Compatible));
7558 -- In all other cases, we need a full check on the prefix
7560 else
7561 Set_Result
7562 (Has_Compatible_Alignment_Internal
7563 (Obj, Prefix (Expr), Unknown));
7564 end if;
7565 end Check_Prefix;
7567 ----------------
7568 -- Set_Result --
7569 ----------------
7571 procedure Set_Result (R : Alignment_Result) is
7572 begin
7573 if R > Result then
7574 Result := R;
7575 end if;
7576 end Set_Result;
7578 -- Start of processing for Has_Compatible_Alignment_Internal
7580 begin
7581 -- If Expr is a selected component, we must make sure there is no
7582 -- potentially troublesome component clause, and that the record is
7583 -- not packed.
7585 if Nkind (Expr) = N_Selected_Component then
7587 -- Packed record always generate unknown alignment
7589 if Is_Packed (Etype (Prefix (Expr))) then
7590 Set_Result (Unknown);
7591 end if;
7593 -- Check prefix and component offset
7595 Check_Prefix;
7596 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
7598 -- If Expr is an indexed component, we must make sure there is no
7599 -- potentially troublesome Component_Size clause and that the array
7600 -- is not bit-packed.
7602 elsif Nkind (Expr) = N_Indexed_Component then
7603 declare
7604 Typ : constant Entity_Id := Etype (Prefix (Expr));
7605 Ind : constant Node_Id := First_Index (Typ);
7607 begin
7608 -- Bit packed array always generates unknown alignment
7610 if Is_Bit_Packed_Array (Typ) then
7611 Set_Result (Unknown);
7612 end if;
7614 -- Check prefix and component offset
7616 Check_Prefix;
7617 Offs := Component_Size (Typ);
7619 -- Small optimization: compute the full offset when possible
7621 if Offs /= No_Uint
7622 and then Offs > Uint_0
7623 and then Present (Ind)
7624 and then Nkind (Ind) = N_Range
7625 and then Compile_Time_Known_Value (Low_Bound (Ind))
7626 and then Compile_Time_Known_Value (First (Expressions (Expr)))
7627 then
7628 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
7629 - Expr_Value (Low_Bound ((Ind))));
7630 end if;
7631 end;
7632 end if;
7634 -- If we have a null offset, the result is entirely determined by
7635 -- the base object and has already been computed recursively.
7637 if Offs = Uint_0 then
7638 null;
7640 -- Case where we know the alignment of the object
7642 elsif Known_Alignment (Obj) then
7643 declare
7644 ObjA : constant Uint := Alignment (Obj);
7645 ExpA : Uint := No_Uint;
7646 SizA : Uint := No_Uint;
7648 begin
7649 -- If alignment of Obj is 1, then we are always OK
7651 if ObjA = 1 then
7652 Set_Result (Known_Compatible);
7654 -- Alignment of Obj is greater than 1, so we need to check
7656 else
7657 -- If we have an offset, see if it is compatible
7659 if Offs /= No_Uint and Offs > Uint_0 then
7660 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
7661 Set_Result (Known_Incompatible);
7662 end if;
7664 -- See if Expr is an object with known alignment
7666 elsif Is_Entity_Name (Expr)
7667 and then Known_Alignment (Entity (Expr))
7668 then
7669 ExpA := Alignment (Entity (Expr));
7671 -- Otherwise, we can use the alignment of the type of
7672 -- Expr given that we already checked for
7673 -- discombobulating rep clauses for the cases of indexed
7674 -- and selected components above.
7676 elsif Known_Alignment (Etype (Expr)) then
7677 ExpA := Alignment (Etype (Expr));
7679 -- Otherwise the alignment is unknown
7681 else
7682 Set_Result (Default);
7683 end if;
7685 -- If we got an alignment, see if it is acceptable
7687 if ExpA /= No_Uint and then ExpA < ObjA then
7688 Set_Result (Known_Incompatible);
7689 end if;
7691 -- If Expr is not a piece of a larger object, see if size
7692 -- is given. If so, check that it is not too small for the
7693 -- required alignment.
7695 if Offs /= No_Uint then
7696 null;
7698 -- See if Expr is an object with known size
7700 elsif Is_Entity_Name (Expr)
7701 and then Known_Static_Esize (Entity (Expr))
7702 then
7703 SizA := Esize (Entity (Expr));
7705 -- Otherwise, we check the object size of the Expr type
7707 elsif Known_Static_Esize (Etype (Expr)) then
7708 SizA := Esize (Etype (Expr));
7709 end if;
7711 -- If we got a size, see if it is a multiple of the Obj
7712 -- alignment, if not, then the alignment cannot be
7713 -- acceptable, since the size is always a multiple of the
7714 -- alignment.
7716 if SizA /= No_Uint then
7717 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
7718 Set_Result (Known_Incompatible);
7719 end if;
7720 end if;
7721 end if;
7722 end;
7724 -- If we do not know required alignment, any non-zero offset is a
7725 -- potential problem (but certainly may be OK, so result is unknown).
7727 elsif Offs /= No_Uint then
7728 Set_Result (Unknown);
7730 -- If we can't find the result by direct comparison of alignment
7731 -- values, then there is still one case that we can determine known
7732 -- result, and that is when we can determine that the types are the
7733 -- same, and no alignments are specified. Then we known that the
7734 -- alignments are compatible, even if we don't know the alignment
7735 -- value in the front end.
7737 elsif Etype (Obj) = Etype (Expr) then
7739 -- Types are the same, but we have to check for possible size
7740 -- and alignments on the Expr object that may make the alignment
7741 -- different, even though the types are the same.
7743 if Is_Entity_Name (Expr) then
7745 -- First check alignment of the Expr object. Any alignment less
7746 -- than Maximum_Alignment is worrisome since this is the case
7747 -- where we do not know the alignment of Obj.
7749 if Known_Alignment (Entity (Expr))
7750 and then UI_To_Int (Alignment (Entity (Expr))) <
7751 Ttypes.Maximum_Alignment
7752 then
7753 Set_Result (Unknown);
7755 -- Now check size of Expr object. Any size that is not an
7756 -- even multiple of Maximum_Alignment is also worrisome
7757 -- since it may cause the alignment of the object to be less
7758 -- than the alignment of the type.
7760 elsif Known_Static_Esize (Entity (Expr))
7761 and then
7762 (UI_To_Int (Esize (Entity (Expr))) mod
7763 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
7764 /= 0
7765 then
7766 Set_Result (Unknown);
7768 -- Otherwise same type is decisive
7770 else
7771 Set_Result (Known_Compatible);
7772 end if;
7773 end if;
7775 -- Another case to deal with is when there is an explicit size or
7776 -- alignment clause when the types are not the same. If so, then the
7777 -- result is Unknown. We don't need to do this test if the Default is
7778 -- Unknown, since that result will be set in any case.
7780 elsif Default /= Unknown
7781 and then (Has_Size_Clause (Etype (Expr))
7782 or else
7783 Has_Alignment_Clause (Etype (Expr)))
7784 then
7785 Set_Result (Unknown);
7787 -- If no indication found, set default
7789 else
7790 Set_Result (Default);
7791 end if;
7793 -- Return worst result found
7795 return Result;
7796 end Has_Compatible_Alignment_Internal;
7798 -- Start of processing for Has_Compatible_Alignment
7800 begin
7801 -- If Obj has no specified alignment, then set alignment from the type
7802 -- alignment. Perhaps we should always do this, but for sure we should
7803 -- do it when there is an address clause since we can do more if the
7804 -- alignment is known.
7806 if Unknown_Alignment (Obj) then
7807 Set_Alignment (Obj, Alignment (Etype (Obj)));
7808 end if;
7810 -- Now do the internal call that does all the work
7812 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
7813 end Has_Compatible_Alignment;
7815 ----------------------
7816 -- Has_Declarations --
7817 ----------------------
7819 function Has_Declarations (N : Node_Id) return Boolean is
7820 begin
7821 return Nkind_In (Nkind (N), N_Accept_Statement,
7822 N_Block_Statement,
7823 N_Compilation_Unit_Aux,
7824 N_Entry_Body,
7825 N_Package_Body,
7826 N_Protected_Body,
7827 N_Subprogram_Body,
7828 N_Task_Body,
7829 N_Package_Specification);
7830 end Has_Declarations;
7832 ---------------------------------
7833 -- Has_Defaulted_Discriminants --
7834 ---------------------------------
7836 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
7837 begin
7838 return Has_Discriminants (Typ)
7839 and then Present (First_Discriminant (Typ))
7840 and then Present (Discriminant_Default_Value
7841 (First_Discriminant (Typ)));
7842 end Has_Defaulted_Discriminants;
7844 -------------------
7845 -- Has_Denormals --
7846 -------------------
7848 function Has_Denormals (E : Entity_Id) return Boolean is
7849 begin
7850 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
7851 end Has_Denormals;
7853 -------------------------------------------
7854 -- Has_Discriminant_Dependent_Constraint --
7855 -------------------------------------------
7857 function Has_Discriminant_Dependent_Constraint
7858 (Comp : Entity_Id) return Boolean
7860 Comp_Decl : constant Node_Id := Parent (Comp);
7861 Subt_Indic : Node_Id;
7862 Constr : Node_Id;
7863 Assn : Node_Id;
7865 begin
7866 -- Discriminants can't depend on discriminants
7868 if Ekind (Comp) = E_Discriminant then
7869 return False;
7871 else
7872 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
7874 if Nkind (Subt_Indic) = N_Subtype_Indication then
7875 Constr := Constraint (Subt_Indic);
7877 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
7878 Assn := First (Constraints (Constr));
7879 while Present (Assn) loop
7880 case Nkind (Assn) is
7881 when N_Subtype_Indication |
7882 N_Range |
7883 N_Identifier
7885 if Depends_On_Discriminant (Assn) then
7886 return True;
7887 end if;
7889 when N_Discriminant_Association =>
7890 if Depends_On_Discriminant (Expression (Assn)) then
7891 return True;
7892 end if;
7894 when others =>
7895 null;
7896 end case;
7898 Next (Assn);
7899 end loop;
7900 end if;
7901 end if;
7902 end if;
7904 return False;
7905 end Has_Discriminant_Dependent_Constraint;
7907 --------------------------
7908 -- Has_Enabled_Property --
7909 --------------------------
7911 function Has_Enabled_Property
7912 (Item_Id : Entity_Id;
7913 Property : Name_Id) return Boolean
7915 function State_Has_Enabled_Property return Boolean;
7916 -- Determine whether a state denoted by Item_Id has the property enabled
7918 function Variable_Has_Enabled_Property return Boolean;
7919 -- Determine whether a variable denoted by Item_Id has the property
7920 -- enabled.
7922 --------------------------------
7923 -- State_Has_Enabled_Property --
7924 --------------------------------
7926 function State_Has_Enabled_Property return Boolean is
7927 Decl : constant Node_Id := Parent (Item_Id);
7928 Opt : Node_Id;
7929 Opt_Nam : Node_Id;
7930 Prop : Node_Id;
7931 Prop_Nam : Node_Id;
7932 Props : Node_Id;
7934 begin
7935 -- The declaration of an external abstract state appears as an
7936 -- extension aggregate. If this is not the case, properties can never
7937 -- be set.
7939 if Nkind (Decl) /= N_Extension_Aggregate then
7940 return False;
7941 end if;
7943 -- When External appears as a simple option, it automatically enables
7944 -- all properties.
7946 Opt := First (Expressions (Decl));
7947 while Present (Opt) loop
7948 if Nkind (Opt) = N_Identifier
7949 and then Chars (Opt) = Name_External
7950 then
7951 return True;
7952 end if;
7954 Next (Opt);
7955 end loop;
7957 -- When External specifies particular properties, inspect those and
7958 -- find the desired one (if any).
7960 Opt := First (Component_Associations (Decl));
7961 while Present (Opt) loop
7962 Opt_Nam := First (Choices (Opt));
7964 if Nkind (Opt_Nam) = N_Identifier
7965 and then Chars (Opt_Nam) = Name_External
7966 then
7967 Props := Expression (Opt);
7969 -- Multiple properties appear as an aggregate
7971 if Nkind (Props) = N_Aggregate then
7973 -- Simple property form
7975 Prop := First (Expressions (Props));
7976 while Present (Prop) loop
7977 if Chars (Prop) = Property then
7978 return True;
7979 end if;
7981 Next (Prop);
7982 end loop;
7984 -- Property with expression form
7986 Prop := First (Component_Associations (Props));
7987 while Present (Prop) loop
7988 Prop_Nam := First (Choices (Prop));
7990 -- The property can be represented in two ways:
7991 -- others => <value>
7992 -- <property> => <value>
7994 if Nkind (Prop_Nam) = N_Others_Choice
7995 or else (Nkind (Prop_Nam) = N_Identifier
7996 and then Chars (Prop_Nam) = Property)
7997 then
7998 return Is_True (Expr_Value (Expression (Prop)));
7999 end if;
8001 Next (Prop);
8002 end loop;
8004 -- Single property
8006 else
8007 return Chars (Props) = Property;
8008 end if;
8009 end if;
8011 Next (Opt);
8012 end loop;
8014 return False;
8015 end State_Has_Enabled_Property;
8017 -----------------------------------
8018 -- Variable_Has_Enabled_Property --
8019 -----------------------------------
8021 function Variable_Has_Enabled_Property return Boolean is
8022 function Is_Enabled (Prag : Node_Id) return Boolean;
8023 -- Determine whether property pragma Prag (if present) denotes an
8024 -- enabled property.
8026 ----------------
8027 -- Is_Enabled --
8028 ----------------
8030 function Is_Enabled (Prag : Node_Id) return Boolean is
8031 Arg2 : Node_Id;
8033 begin
8034 if Present (Prag) then
8035 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
8037 -- The pragma has an optional Boolean expression, the related
8038 -- property is enabled only when the expression evaluates to
8039 -- True.
8041 if Present (Arg2) then
8042 return Is_True (Expr_Value (Get_Pragma_Arg (Arg2)));
8044 -- Otherwise the lack of expression enables the property by
8045 -- default.
8047 else
8048 return True;
8049 end if;
8051 -- The property was never set in the first place
8053 else
8054 return False;
8055 end if;
8056 end Is_Enabled;
8058 -- Local variables
8060 AR : constant Node_Id :=
8061 Get_Pragma (Item_Id, Pragma_Async_Readers);
8062 AW : constant Node_Id :=
8063 Get_Pragma (Item_Id, Pragma_Async_Writers);
8064 ER : constant Node_Id :=
8065 Get_Pragma (Item_Id, Pragma_Effective_Reads);
8066 EW : constant Node_Id :=
8067 Get_Pragma (Item_Id, Pragma_Effective_Writes);
8069 -- Start of processing for Variable_Has_Enabled_Property
8071 begin
8072 -- A non-effectively volatile object can never possess external
8073 -- properties.
8075 if not Is_Effectively_Volatile (Item_Id) then
8076 return False;
8078 -- External properties related to variables come in two flavors -
8079 -- explicit and implicit. The explicit case is characterized by the
8080 -- presence of a property pragma with an optional Boolean flag. The
8081 -- property is enabled when the flag evaluates to True or the flag is
8082 -- missing altogether.
8084 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
8085 return True;
8087 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
8088 return True;
8090 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
8091 return True;
8093 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
8094 return True;
8096 -- The implicit case lacks all property pragmas
8098 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
8099 return True;
8101 else
8102 return False;
8103 end if;
8104 end Variable_Has_Enabled_Property;
8106 -- Start of processing for Has_Enabled_Property
8108 begin
8109 -- Abstract states and variables have a flexible scheme of specifying
8110 -- external properties.
8112 if Ekind (Item_Id) = E_Abstract_State then
8113 return State_Has_Enabled_Property;
8115 elsif Ekind (Item_Id) = E_Variable then
8116 return Variable_Has_Enabled_Property;
8118 -- Otherwise a property is enabled when the related item is effectively
8119 -- volatile.
8121 else
8122 return Is_Effectively_Volatile (Item_Id);
8123 end if;
8124 end Has_Enabled_Property;
8126 --------------------
8127 -- Has_Infinities --
8128 --------------------
8130 function Has_Infinities (E : Entity_Id) return Boolean is
8131 begin
8132 return
8133 Is_Floating_Point_Type (E)
8134 and then Nkind (Scalar_Range (E)) = N_Range
8135 and then Includes_Infinities (Scalar_Range (E));
8136 end Has_Infinities;
8138 --------------------
8139 -- Has_Interfaces --
8140 --------------------
8142 function Has_Interfaces
8143 (T : Entity_Id;
8144 Use_Full_View : Boolean := True) return Boolean
8146 Typ : Entity_Id := Base_Type (T);
8148 begin
8149 -- Handle concurrent types
8151 if Is_Concurrent_Type (Typ) then
8152 Typ := Corresponding_Record_Type (Typ);
8153 end if;
8155 if not Present (Typ)
8156 or else not Is_Record_Type (Typ)
8157 or else not Is_Tagged_Type (Typ)
8158 then
8159 return False;
8160 end if;
8162 -- Handle private types
8164 if Use_Full_View and then Present (Full_View (Typ)) then
8165 Typ := Full_View (Typ);
8166 end if;
8168 -- Handle concurrent record types
8170 if Is_Concurrent_Record_Type (Typ)
8171 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
8172 then
8173 return True;
8174 end if;
8176 loop
8177 if Is_Interface (Typ)
8178 or else
8179 (Is_Record_Type (Typ)
8180 and then Present (Interfaces (Typ))
8181 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
8182 then
8183 return True;
8184 end if;
8186 exit when Etype (Typ) = Typ
8188 -- Handle private types
8190 or else (Present (Full_View (Etype (Typ)))
8191 and then Full_View (Etype (Typ)) = Typ)
8193 -- Protect frontend against wrong sources with cyclic derivations
8195 or else Etype (Typ) = T;
8197 -- Climb to the ancestor type handling private types
8199 if Present (Full_View (Etype (Typ))) then
8200 Typ := Full_View (Etype (Typ));
8201 else
8202 Typ := Etype (Typ);
8203 end if;
8204 end loop;
8206 return False;
8207 end Has_Interfaces;
8209 ---------------------------------
8210 -- Has_No_Obvious_Side_Effects --
8211 ---------------------------------
8213 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
8214 begin
8215 -- For now, just handle literals, constants, and non-volatile
8216 -- variables and expressions combining these with operators or
8217 -- short circuit forms.
8219 if Nkind (N) in N_Numeric_Or_String_Literal then
8220 return True;
8222 elsif Nkind (N) = N_Character_Literal then
8223 return True;
8225 elsif Nkind (N) in N_Unary_Op then
8226 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
8228 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
8229 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
8230 and then
8231 Has_No_Obvious_Side_Effects (Right_Opnd (N));
8233 elsif Nkind (N) = N_Expression_With_Actions
8234 and then Is_Empty_List (Actions (N))
8235 then
8236 return Has_No_Obvious_Side_Effects (Expression (N));
8238 elsif Nkind (N) in N_Has_Entity then
8239 return Present (Entity (N))
8240 and then Ekind_In (Entity (N), E_Variable,
8241 E_Constant,
8242 E_Enumeration_Literal,
8243 E_In_Parameter,
8244 E_Out_Parameter,
8245 E_In_Out_Parameter)
8246 and then not Is_Volatile (Entity (N));
8248 else
8249 return False;
8250 end if;
8251 end Has_No_Obvious_Side_Effects;
8253 ------------------------
8254 -- Has_Null_Exclusion --
8255 ------------------------
8257 function Has_Null_Exclusion (N : Node_Id) return Boolean is
8258 begin
8259 case Nkind (N) is
8260 when N_Access_Definition |
8261 N_Access_Function_Definition |
8262 N_Access_Procedure_Definition |
8263 N_Access_To_Object_Definition |
8264 N_Allocator |
8265 N_Derived_Type_Definition |
8266 N_Function_Specification |
8267 N_Subtype_Declaration =>
8268 return Null_Exclusion_Present (N);
8270 when N_Component_Definition |
8271 N_Formal_Object_Declaration |
8272 N_Object_Renaming_Declaration =>
8273 if Present (Subtype_Mark (N)) then
8274 return Null_Exclusion_Present (N);
8275 else pragma Assert (Present (Access_Definition (N)));
8276 return Null_Exclusion_Present (Access_Definition (N));
8277 end if;
8279 when N_Discriminant_Specification =>
8280 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
8281 return Null_Exclusion_Present (Discriminant_Type (N));
8282 else
8283 return Null_Exclusion_Present (N);
8284 end if;
8286 when N_Object_Declaration =>
8287 if Nkind (Object_Definition (N)) = N_Access_Definition then
8288 return Null_Exclusion_Present (Object_Definition (N));
8289 else
8290 return Null_Exclusion_Present (N);
8291 end if;
8293 when N_Parameter_Specification =>
8294 if Nkind (Parameter_Type (N)) = N_Access_Definition then
8295 return Null_Exclusion_Present (Parameter_Type (N));
8296 else
8297 return Null_Exclusion_Present (N);
8298 end if;
8300 when others =>
8301 return False;
8303 end case;
8304 end Has_Null_Exclusion;
8306 ------------------------
8307 -- Has_Null_Extension --
8308 ------------------------
8310 function Has_Null_Extension (T : Entity_Id) return Boolean is
8311 B : constant Entity_Id := Base_Type (T);
8312 Comps : Node_Id;
8313 Ext : Node_Id;
8315 begin
8316 if Nkind (Parent (B)) = N_Full_Type_Declaration
8317 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
8318 then
8319 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
8321 if Present (Ext) then
8322 if Null_Present (Ext) then
8323 return True;
8324 else
8325 Comps := Component_List (Ext);
8327 -- The null component list is rewritten during analysis to
8328 -- include the parent component. Any other component indicates
8329 -- that the extension was not originally null.
8331 return Null_Present (Comps)
8332 or else No (Next (First (Component_Items (Comps))));
8333 end if;
8334 else
8335 return False;
8336 end if;
8338 else
8339 return False;
8340 end if;
8341 end Has_Null_Extension;
8343 -------------------------------
8344 -- Has_Overriding_Initialize --
8345 -------------------------------
8347 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
8348 BT : constant Entity_Id := Base_Type (T);
8349 P : Elmt_Id;
8351 begin
8352 if Is_Controlled (BT) then
8353 if Is_RTU (Scope (BT), Ada_Finalization) then
8354 return False;
8356 elsif Present (Primitive_Operations (BT)) then
8357 P := First_Elmt (Primitive_Operations (BT));
8358 while Present (P) loop
8359 declare
8360 Init : constant Entity_Id := Node (P);
8361 Formal : constant Entity_Id := First_Formal (Init);
8362 begin
8363 if Ekind (Init) = E_Procedure
8364 and then Chars (Init) = Name_Initialize
8365 and then Comes_From_Source (Init)
8366 and then Present (Formal)
8367 and then Etype (Formal) = BT
8368 and then No (Next_Formal (Formal))
8369 and then (Ada_Version < Ada_2012
8370 or else not Null_Present (Parent (Init)))
8371 then
8372 return True;
8373 end if;
8374 end;
8376 Next_Elmt (P);
8377 end loop;
8378 end if;
8380 -- Here if type itself does not have a non-null Initialize operation:
8381 -- check immediate ancestor.
8383 if Is_Derived_Type (BT)
8384 and then Has_Overriding_Initialize (Etype (BT))
8385 then
8386 return True;
8387 end if;
8388 end if;
8390 return False;
8391 end Has_Overriding_Initialize;
8393 --------------------------------------
8394 -- Has_Preelaborable_Initialization --
8395 --------------------------------------
8397 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
8398 Has_PE : Boolean;
8400 procedure Check_Components (E : Entity_Id);
8401 -- Check component/discriminant chain, sets Has_PE False if a component
8402 -- or discriminant does not meet the preelaborable initialization rules.
8404 ----------------------
8405 -- Check_Components --
8406 ----------------------
8408 procedure Check_Components (E : Entity_Id) is
8409 Ent : Entity_Id;
8410 Exp : Node_Id;
8412 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
8413 -- Returns True if and only if the expression denoted by N does not
8414 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8416 ---------------------------------
8417 -- Is_Preelaborable_Expression --
8418 ---------------------------------
8420 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
8421 Exp : Node_Id;
8422 Assn : Node_Id;
8423 Choice : Node_Id;
8424 Comp_Type : Entity_Id;
8425 Is_Array_Aggr : Boolean;
8427 begin
8428 if Is_OK_Static_Expression (N) then
8429 return True;
8431 elsif Nkind (N) = N_Null then
8432 return True;
8434 -- Attributes are allowed in general, even if their prefix is a
8435 -- formal type. (It seems that certain attributes known not to be
8436 -- static might not be allowed, but there are no rules to prevent
8437 -- them.)
8439 elsif Nkind (N) = N_Attribute_Reference then
8440 return True;
8442 -- The name of a discriminant evaluated within its parent type is
8443 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8444 -- names that denote discriminals as well as discriminants to
8445 -- catch references occurring within init procs.
8447 elsif Is_Entity_Name (N)
8448 and then
8449 (Ekind (Entity (N)) = E_Discriminant
8450 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
8451 and then Present (Discriminal_Link (Entity (N)))))
8452 then
8453 return True;
8455 elsif Nkind (N) = N_Qualified_Expression then
8456 return Is_Preelaborable_Expression (Expression (N));
8458 -- For aggregates we have to check that each of the associations
8459 -- is preelaborable.
8461 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
8462 Is_Array_Aggr := Is_Array_Type (Etype (N));
8464 if Is_Array_Aggr then
8465 Comp_Type := Component_Type (Etype (N));
8466 end if;
8468 -- Check the ancestor part of extension aggregates, which must
8469 -- be either the name of a type that has preelaborable init or
8470 -- an expression that is preelaborable.
8472 if Nkind (N) = N_Extension_Aggregate then
8473 declare
8474 Anc_Part : constant Node_Id := Ancestor_Part (N);
8476 begin
8477 if Is_Entity_Name (Anc_Part)
8478 and then Is_Type (Entity (Anc_Part))
8479 then
8480 if not Has_Preelaborable_Initialization
8481 (Entity (Anc_Part))
8482 then
8483 return False;
8484 end if;
8486 elsif not Is_Preelaborable_Expression (Anc_Part) then
8487 return False;
8488 end if;
8489 end;
8490 end if;
8492 -- Check positional associations
8494 Exp := First (Expressions (N));
8495 while Present (Exp) loop
8496 if not Is_Preelaborable_Expression (Exp) then
8497 return False;
8498 end if;
8500 Next (Exp);
8501 end loop;
8503 -- Check named associations
8505 Assn := First (Component_Associations (N));
8506 while Present (Assn) loop
8507 Choice := First (Choices (Assn));
8508 while Present (Choice) loop
8509 if Is_Array_Aggr then
8510 if Nkind (Choice) = N_Others_Choice then
8511 null;
8513 elsif Nkind (Choice) = N_Range then
8514 if not Is_OK_Static_Range (Choice) then
8515 return False;
8516 end if;
8518 elsif not Is_OK_Static_Expression (Choice) then
8519 return False;
8520 end if;
8522 else
8523 Comp_Type := Etype (Choice);
8524 end if;
8526 Next (Choice);
8527 end loop;
8529 -- If the association has a <> at this point, then we have
8530 -- to check whether the component's type has preelaborable
8531 -- initialization. Note that this only occurs when the
8532 -- association's corresponding component does not have a
8533 -- default expression, the latter case having already been
8534 -- expanded as an expression for the association.
8536 if Box_Present (Assn) then
8537 if not Has_Preelaborable_Initialization (Comp_Type) then
8538 return False;
8539 end if;
8541 -- In the expression case we check whether the expression
8542 -- is preelaborable.
8544 elsif
8545 not Is_Preelaborable_Expression (Expression (Assn))
8546 then
8547 return False;
8548 end if;
8550 Next (Assn);
8551 end loop;
8553 -- If we get here then aggregate as a whole is preelaborable
8555 return True;
8557 -- All other cases are not preelaborable
8559 else
8560 return False;
8561 end if;
8562 end Is_Preelaborable_Expression;
8564 -- Start of processing for Check_Components
8566 begin
8567 -- Loop through entities of record or protected type
8569 Ent := E;
8570 while Present (Ent) loop
8572 -- We are interested only in components and discriminants
8574 Exp := Empty;
8576 case Ekind (Ent) is
8577 when E_Component =>
8579 -- Get default expression if any. If there is no declaration
8580 -- node, it means we have an internal entity. The parent and
8581 -- tag fields are examples of such entities. For such cases,
8582 -- we just test the type of the entity.
8584 if Present (Declaration_Node (Ent)) then
8585 Exp := Expression (Declaration_Node (Ent));
8586 end if;
8588 when E_Discriminant =>
8590 -- Note: for a renamed discriminant, the Declaration_Node
8591 -- may point to the one from the ancestor, and have a
8592 -- different expression, so use the proper attribute to
8593 -- retrieve the expression from the derived constraint.
8595 Exp := Discriminant_Default_Value (Ent);
8597 when others =>
8598 goto Check_Next_Entity;
8599 end case;
8601 -- A component has PI if it has no default expression and the
8602 -- component type has PI.
8604 if No (Exp) then
8605 if not Has_Preelaborable_Initialization (Etype (Ent)) then
8606 Has_PE := False;
8607 exit;
8608 end if;
8610 -- Require the default expression to be preelaborable
8612 elsif not Is_Preelaborable_Expression (Exp) then
8613 Has_PE := False;
8614 exit;
8615 end if;
8617 <<Check_Next_Entity>>
8618 Next_Entity (Ent);
8619 end loop;
8620 end Check_Components;
8622 -- Start of processing for Has_Preelaborable_Initialization
8624 begin
8625 -- Immediate return if already marked as known preelaborable init. This
8626 -- covers types for which this function has already been called once
8627 -- and returned True (in which case the result is cached), and also
8628 -- types to which a pragma Preelaborable_Initialization applies.
8630 if Known_To_Have_Preelab_Init (E) then
8631 return True;
8632 end if;
8634 -- If the type is a subtype representing a generic actual type, then
8635 -- test whether its base type has preelaborable initialization since
8636 -- the subtype representing the actual does not inherit this attribute
8637 -- from the actual or formal. (but maybe it should???)
8639 if Is_Generic_Actual_Type (E) then
8640 return Has_Preelaborable_Initialization (Base_Type (E));
8641 end if;
8643 -- All elementary types have preelaborable initialization
8645 if Is_Elementary_Type (E) then
8646 Has_PE := True;
8648 -- Array types have PI if the component type has PI
8650 elsif Is_Array_Type (E) then
8651 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
8653 -- A derived type has preelaborable initialization if its parent type
8654 -- has preelaborable initialization and (in the case of a derived record
8655 -- extension) if the non-inherited components all have preelaborable
8656 -- initialization. However, a user-defined controlled type with an
8657 -- overriding Initialize procedure does not have preelaborable
8658 -- initialization.
8660 elsif Is_Derived_Type (E) then
8662 -- If the derived type is a private extension then it doesn't have
8663 -- preelaborable initialization.
8665 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
8666 return False;
8667 end if;
8669 -- First check whether ancestor type has preelaborable initialization
8671 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
8673 -- If OK, check extension components (if any)
8675 if Has_PE and then Is_Record_Type (E) then
8676 Check_Components (First_Entity (E));
8677 end if;
8679 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8680 -- with a user defined Initialize procedure does not have PI. If
8681 -- the type is untagged, the control primitives come from a component
8682 -- that has already been checked.
8684 if Has_PE
8685 and then Is_Controlled (E)
8686 and then Is_Tagged_Type (E)
8687 and then Has_Overriding_Initialize (E)
8688 then
8689 Has_PE := False;
8690 end if;
8692 -- Private types not derived from a type having preelaborable init and
8693 -- that are not marked with pragma Preelaborable_Initialization do not
8694 -- have preelaborable initialization.
8696 elsif Is_Private_Type (E) then
8697 return False;
8699 -- Record type has PI if it is non private and all components have PI
8701 elsif Is_Record_Type (E) then
8702 Has_PE := True;
8703 Check_Components (First_Entity (E));
8705 -- Protected types must not have entries, and components must meet
8706 -- same set of rules as for record components.
8708 elsif Is_Protected_Type (E) then
8709 if Has_Entries (E) then
8710 Has_PE := False;
8711 else
8712 Has_PE := True;
8713 Check_Components (First_Entity (E));
8714 Check_Components (First_Private_Entity (E));
8715 end if;
8717 -- Type System.Address always has preelaborable initialization
8719 elsif Is_RTE (E, RE_Address) then
8720 Has_PE := True;
8722 -- In all other cases, type does not have preelaborable initialization
8724 else
8725 return False;
8726 end if;
8728 -- If type has preelaborable initialization, cache result
8730 if Has_PE then
8731 Set_Known_To_Have_Preelab_Init (E);
8732 end if;
8734 return Has_PE;
8735 end Has_Preelaborable_Initialization;
8737 ---------------------------
8738 -- Has_Private_Component --
8739 ---------------------------
8741 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
8742 Btype : Entity_Id := Base_Type (Type_Id);
8743 Component : Entity_Id;
8745 begin
8746 if Error_Posted (Type_Id)
8747 or else Error_Posted (Btype)
8748 then
8749 return False;
8750 end if;
8752 if Is_Class_Wide_Type (Btype) then
8753 Btype := Root_Type (Btype);
8754 end if;
8756 if Is_Private_Type (Btype) then
8757 declare
8758 UT : constant Entity_Id := Underlying_Type (Btype);
8759 begin
8760 if No (UT) then
8761 if No (Full_View (Btype)) then
8762 return not Is_Generic_Type (Btype)
8763 and then
8764 not Is_Generic_Type (Root_Type (Btype));
8765 else
8766 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
8767 end if;
8768 else
8769 return not Is_Frozen (UT) and then Has_Private_Component (UT);
8770 end if;
8771 end;
8773 elsif Is_Array_Type (Btype) then
8774 return Has_Private_Component (Component_Type (Btype));
8776 elsif Is_Record_Type (Btype) then
8777 Component := First_Component (Btype);
8778 while Present (Component) loop
8779 if Has_Private_Component (Etype (Component)) then
8780 return True;
8781 end if;
8783 Next_Component (Component);
8784 end loop;
8786 return False;
8788 elsif Is_Protected_Type (Btype)
8789 and then Present (Corresponding_Record_Type (Btype))
8790 then
8791 return Has_Private_Component (Corresponding_Record_Type (Btype));
8793 else
8794 return False;
8795 end if;
8796 end Has_Private_Component;
8798 ----------------------
8799 -- Has_Signed_Zeros --
8800 ----------------------
8802 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
8803 begin
8804 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
8805 end Has_Signed_Zeros;
8807 -----------------------------
8808 -- Has_Static_Array_Bounds --
8809 -----------------------------
8811 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
8812 Ndims : constant Nat := Number_Dimensions (Typ);
8814 Index : Node_Id;
8815 Low : Node_Id;
8816 High : Node_Id;
8818 begin
8819 -- Unconstrained types do not have static bounds
8821 if not Is_Constrained (Typ) then
8822 return False;
8823 end if;
8825 -- First treat string literals specially, as the lower bound and length
8826 -- of string literals are not stored like those of arrays.
8828 -- A string literal always has static bounds
8830 if Ekind (Typ) = E_String_Literal_Subtype then
8831 return True;
8832 end if;
8834 -- Treat all dimensions in turn
8836 Index := First_Index (Typ);
8837 for Indx in 1 .. Ndims loop
8839 -- In case of an illegal index which is not a discrete type, return
8840 -- that the type is not static.
8842 if not Is_Discrete_Type (Etype (Index))
8843 or else Etype (Index) = Any_Type
8844 then
8845 return False;
8846 end if;
8848 Get_Index_Bounds (Index, Low, High);
8850 if Error_Posted (Low) or else Error_Posted (High) then
8851 return False;
8852 end if;
8854 if Is_OK_Static_Expression (Low)
8855 and then
8856 Is_OK_Static_Expression (High)
8857 then
8858 null;
8859 else
8860 return False;
8861 end if;
8863 Next (Index);
8864 end loop;
8866 -- If we fall through the loop, all indexes matched
8868 return True;
8869 end Has_Static_Array_Bounds;
8871 ----------------
8872 -- Has_Stream --
8873 ----------------
8875 function Has_Stream (T : Entity_Id) return Boolean is
8876 E : Entity_Id;
8878 begin
8879 if No (T) then
8880 return False;
8882 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
8883 return True;
8885 elsif Is_Array_Type (T) then
8886 return Has_Stream (Component_Type (T));
8888 elsif Is_Record_Type (T) then
8889 E := First_Component (T);
8890 while Present (E) loop
8891 if Has_Stream (Etype (E)) then
8892 return True;
8893 else
8894 Next_Component (E);
8895 end if;
8896 end loop;
8898 return False;
8900 elsif Is_Private_Type (T) then
8901 return Has_Stream (Underlying_Type (T));
8903 else
8904 return False;
8905 end if;
8906 end Has_Stream;
8908 ----------------
8909 -- Has_Suffix --
8910 ----------------
8912 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
8913 begin
8914 Get_Name_String (Chars (E));
8915 return Name_Buffer (Name_Len) = Suffix;
8916 end Has_Suffix;
8918 ----------------
8919 -- Add_Suffix --
8920 ----------------
8922 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8923 begin
8924 Get_Name_String (Chars (E));
8925 Add_Char_To_Name_Buffer (Suffix);
8926 return Name_Find;
8927 end Add_Suffix;
8929 -------------------
8930 -- Remove_Suffix --
8931 -------------------
8933 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8934 begin
8935 pragma Assert (Has_Suffix (E, Suffix));
8936 Get_Name_String (Chars (E));
8937 Name_Len := Name_Len - 1;
8938 return Name_Find;
8939 end Remove_Suffix;
8941 --------------------------
8942 -- Has_Tagged_Component --
8943 --------------------------
8945 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
8946 Comp : Entity_Id;
8948 begin
8949 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
8950 return Has_Tagged_Component (Underlying_Type (Typ));
8952 elsif Is_Array_Type (Typ) then
8953 return Has_Tagged_Component (Component_Type (Typ));
8955 elsif Is_Tagged_Type (Typ) then
8956 return True;
8958 elsif Is_Record_Type (Typ) then
8959 Comp := First_Component (Typ);
8960 while Present (Comp) loop
8961 if Has_Tagged_Component (Etype (Comp)) then
8962 return True;
8963 end if;
8965 Next_Component (Comp);
8966 end loop;
8968 return False;
8970 else
8971 return False;
8972 end if;
8973 end Has_Tagged_Component;
8975 ----------------------------
8976 -- Has_Volatile_Component --
8977 ----------------------------
8979 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
8980 Comp : Entity_Id;
8982 begin
8983 if Has_Volatile_Components (Typ) then
8984 return True;
8986 elsif Is_Array_Type (Typ) then
8987 return Is_Volatile (Component_Type (Typ));
8989 elsif Is_Record_Type (Typ) then
8990 Comp := First_Component (Typ);
8991 while Present (Comp) loop
8992 if Is_Volatile_Object (Comp) then
8993 return True;
8994 end if;
8996 Comp := Next_Component (Comp);
8997 end loop;
8998 end if;
9000 return False;
9001 end Has_Volatile_Component;
9003 -------------------------
9004 -- Implementation_Kind --
9005 -------------------------
9007 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
9008 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
9009 Arg : Node_Id;
9010 begin
9011 pragma Assert (Present (Impl_Prag));
9012 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
9013 return Chars (Get_Pragma_Arg (Arg));
9014 end Implementation_Kind;
9016 --------------------------
9017 -- Implements_Interface --
9018 --------------------------
9020 function Implements_Interface
9021 (Typ_Ent : Entity_Id;
9022 Iface_Ent : Entity_Id;
9023 Exclude_Parents : Boolean := False) return Boolean
9025 Ifaces_List : Elist_Id;
9026 Elmt : Elmt_Id;
9027 Iface : Entity_Id := Base_Type (Iface_Ent);
9028 Typ : Entity_Id := Base_Type (Typ_Ent);
9030 begin
9031 if Is_Class_Wide_Type (Typ) then
9032 Typ := Root_Type (Typ);
9033 end if;
9035 if not Has_Interfaces (Typ) then
9036 return False;
9037 end if;
9039 if Is_Class_Wide_Type (Iface) then
9040 Iface := Root_Type (Iface);
9041 end if;
9043 Collect_Interfaces (Typ, Ifaces_List);
9045 Elmt := First_Elmt (Ifaces_List);
9046 while Present (Elmt) loop
9047 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
9048 and then Exclude_Parents
9049 then
9050 null;
9052 elsif Node (Elmt) = Iface then
9053 return True;
9054 end if;
9056 Next_Elmt (Elmt);
9057 end loop;
9059 return False;
9060 end Implements_Interface;
9062 ------------------------------------
9063 -- In_Assertion_Expression_Pragma --
9064 ------------------------------------
9066 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
9067 Par : Node_Id;
9068 Prag : Node_Id := Empty;
9070 begin
9071 -- Climb the parent chain looking for an enclosing pragma
9073 Par := N;
9074 while Present (Par) loop
9075 if Nkind (Par) = N_Pragma then
9076 Prag := Par;
9077 exit;
9079 -- Precondition-like pragmas are expanded into if statements, check
9080 -- the original node instead.
9082 elsif Nkind (Original_Node (Par)) = N_Pragma then
9083 Prag := Original_Node (Par);
9084 exit;
9086 -- The expansion of attribute 'Old generates a constant to capture
9087 -- the result of the prefix. If the parent traversal reaches
9088 -- one of these constants, then the node technically came from a
9089 -- postcondition-like pragma. Note that the Ekind is not tested here
9090 -- because N may be the expression of an object declaration which is
9091 -- currently being analyzed. Such objects carry Ekind of E_Void.
9093 elsif Nkind (Par) = N_Object_Declaration
9094 and then Constant_Present (Par)
9095 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
9096 then
9097 return True;
9099 -- Prevent the search from going too far
9101 elsif Is_Body_Or_Package_Declaration (Par) then
9102 return False;
9103 end if;
9105 Par := Parent (Par);
9106 end loop;
9108 return
9109 Present (Prag)
9110 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
9111 end In_Assertion_Expression_Pragma;
9113 -----------------
9114 -- In_Instance --
9115 -----------------
9117 function In_Instance return Boolean is
9118 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9119 S : Entity_Id;
9121 begin
9122 S := Current_Scope;
9123 while Present (S) and then S /= Standard_Standard loop
9124 if Ekind_In (S, E_Function, E_Package, E_Procedure)
9125 and then Is_Generic_Instance (S)
9126 then
9127 -- A child instance is always compiled in the context of a parent
9128 -- instance. Nevertheless, the actuals are not analyzed in an
9129 -- instance context. We detect this case by examining the current
9130 -- compilation unit, which must be a child instance, and checking
9131 -- that it is not currently on the scope stack.
9133 if Is_Child_Unit (Curr_Unit)
9134 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9135 N_Package_Instantiation
9136 and then not In_Open_Scopes (Curr_Unit)
9137 then
9138 return False;
9139 else
9140 return True;
9141 end if;
9142 end if;
9144 S := Scope (S);
9145 end loop;
9147 return False;
9148 end In_Instance;
9150 ----------------------
9151 -- In_Instance_Body --
9152 ----------------------
9154 function In_Instance_Body return Boolean is
9155 S : Entity_Id;
9157 begin
9158 S := Current_Scope;
9159 while Present (S) and then S /= Standard_Standard loop
9160 if Ekind_In (S, E_Function, E_Procedure)
9161 and then Is_Generic_Instance (S)
9162 then
9163 return True;
9165 elsif Ekind (S) = E_Package
9166 and then In_Package_Body (S)
9167 and then Is_Generic_Instance (S)
9168 then
9169 return True;
9170 end if;
9172 S := Scope (S);
9173 end loop;
9175 return False;
9176 end In_Instance_Body;
9178 -----------------------------
9179 -- In_Instance_Not_Visible --
9180 -----------------------------
9182 function In_Instance_Not_Visible return Boolean is
9183 S : Entity_Id;
9185 begin
9186 S := Current_Scope;
9187 while Present (S) and then S /= Standard_Standard loop
9188 if Ekind_In (S, E_Function, E_Procedure)
9189 and then Is_Generic_Instance (S)
9190 then
9191 return True;
9193 elsif Ekind (S) = E_Package
9194 and then (In_Package_Body (S) or else In_Private_Part (S))
9195 and then Is_Generic_Instance (S)
9196 then
9197 return True;
9198 end if;
9200 S := Scope (S);
9201 end loop;
9203 return False;
9204 end In_Instance_Not_Visible;
9206 ------------------------------
9207 -- In_Instance_Visible_Part --
9208 ------------------------------
9210 function In_Instance_Visible_Part return Boolean is
9211 S : Entity_Id;
9213 begin
9214 S := Current_Scope;
9215 while Present (S) and then S /= Standard_Standard loop
9216 if Ekind (S) = E_Package
9217 and then Is_Generic_Instance (S)
9218 and then not In_Package_Body (S)
9219 and then not In_Private_Part (S)
9220 then
9221 return True;
9222 end if;
9224 S := Scope (S);
9225 end loop;
9227 return False;
9228 end In_Instance_Visible_Part;
9230 ---------------------
9231 -- In_Package_Body --
9232 ---------------------
9234 function In_Package_Body return Boolean is
9235 S : Entity_Id;
9237 begin
9238 S := Current_Scope;
9239 while Present (S) and then S /= Standard_Standard loop
9240 if Ekind (S) = E_Package and then In_Package_Body (S) then
9241 return True;
9242 else
9243 S := Scope (S);
9244 end if;
9245 end loop;
9247 return False;
9248 end In_Package_Body;
9250 --------------------------------
9251 -- In_Parameter_Specification --
9252 --------------------------------
9254 function In_Parameter_Specification (N : Node_Id) return Boolean is
9255 PN : Node_Id;
9257 begin
9258 PN := Parent (N);
9259 while Present (PN) loop
9260 if Nkind (PN) = N_Parameter_Specification then
9261 return True;
9262 end if;
9264 PN := Parent (PN);
9265 end loop;
9267 return False;
9268 end In_Parameter_Specification;
9270 --------------------------
9271 -- In_Pragma_Expression --
9272 --------------------------
9274 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
9275 P : Node_Id;
9276 begin
9277 P := Parent (N);
9278 loop
9279 if No (P) then
9280 return False;
9281 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
9282 return True;
9283 else
9284 P := Parent (P);
9285 end if;
9286 end loop;
9287 end In_Pragma_Expression;
9289 -------------------------------------
9290 -- In_Reverse_Storage_Order_Object --
9291 -------------------------------------
9293 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
9294 Pref : Node_Id;
9295 Btyp : Entity_Id := Empty;
9297 begin
9298 -- Climb up indexed components
9300 Pref := N;
9301 loop
9302 case Nkind (Pref) is
9303 when N_Selected_Component =>
9304 Pref := Prefix (Pref);
9305 exit;
9307 when N_Indexed_Component =>
9308 Pref := Prefix (Pref);
9310 when others =>
9311 Pref := Empty;
9312 exit;
9313 end case;
9314 end loop;
9316 if Present (Pref) then
9317 Btyp := Base_Type (Etype (Pref));
9318 end if;
9320 return Present (Btyp)
9321 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
9322 and then Reverse_Storage_Order (Btyp);
9323 end In_Reverse_Storage_Order_Object;
9325 --------------------------------------
9326 -- In_Subprogram_Or_Concurrent_Unit --
9327 --------------------------------------
9329 function In_Subprogram_Or_Concurrent_Unit return Boolean is
9330 E : Entity_Id;
9331 K : Entity_Kind;
9333 begin
9334 -- Use scope chain to check successively outer scopes
9336 E := Current_Scope;
9337 loop
9338 K := Ekind (E);
9340 if K in Subprogram_Kind
9341 or else K in Concurrent_Kind
9342 or else K in Generic_Subprogram_Kind
9343 then
9344 return True;
9346 elsif E = Standard_Standard then
9347 return False;
9348 end if;
9350 E := Scope (E);
9351 end loop;
9352 end In_Subprogram_Or_Concurrent_Unit;
9354 ---------------------
9355 -- In_Visible_Part --
9356 ---------------------
9358 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
9359 begin
9360 return Is_Package_Or_Generic_Package (Scope_Id)
9361 and then In_Open_Scopes (Scope_Id)
9362 and then not In_Package_Body (Scope_Id)
9363 and then not In_Private_Part (Scope_Id);
9364 end In_Visible_Part;
9366 --------------------------------
9367 -- Incomplete_Or_Partial_View --
9368 --------------------------------
9370 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
9371 function Inspect_Decls
9372 (Decls : List_Id;
9373 Taft : Boolean := False) return Entity_Id;
9374 -- Check whether a declarative region contains the incomplete or partial
9375 -- view of Id.
9377 -------------------
9378 -- Inspect_Decls --
9379 -------------------
9381 function Inspect_Decls
9382 (Decls : List_Id;
9383 Taft : Boolean := False) return Entity_Id
9385 Decl : Node_Id;
9386 Match : Node_Id;
9388 begin
9389 Decl := First (Decls);
9390 while Present (Decl) loop
9391 Match := Empty;
9393 if Taft then
9394 if Nkind (Decl) = N_Incomplete_Type_Declaration then
9395 Match := Defining_Identifier (Decl);
9396 end if;
9398 else
9399 if Nkind_In (Decl, N_Private_Extension_Declaration,
9400 N_Private_Type_Declaration)
9401 then
9402 Match := Defining_Identifier (Decl);
9403 end if;
9404 end if;
9406 if Present (Match)
9407 and then Present (Full_View (Match))
9408 and then Full_View (Match) = Id
9409 then
9410 return Match;
9411 end if;
9413 Next (Decl);
9414 end loop;
9416 return Empty;
9417 end Inspect_Decls;
9419 -- Local variables
9421 Prev : Entity_Id;
9423 -- Start of processing for Incomplete_Or_Partial_View
9425 begin
9426 -- Deferred constant or incomplete type case
9428 Prev := Current_Entity_In_Scope (Id);
9430 if Present (Prev)
9431 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
9432 and then Present (Full_View (Prev))
9433 and then Full_View (Prev) = Id
9434 then
9435 return Prev;
9436 end if;
9438 -- Private or Taft amendment type case
9440 declare
9441 Pkg : constant Entity_Id := Scope (Id);
9442 Pkg_Decl : Node_Id := Pkg;
9444 begin
9445 if Present (Pkg) and then Ekind (Pkg) = E_Package then
9446 while Nkind (Pkg_Decl) /= N_Package_Specification loop
9447 Pkg_Decl := Parent (Pkg_Decl);
9448 end loop;
9450 -- It is knows that Typ has a private view, look for it in the
9451 -- visible declarations of the enclosing scope. A special case
9452 -- of this is when the two views have been exchanged - the full
9453 -- appears earlier than the private.
9455 if Has_Private_Declaration (Id) then
9456 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
9458 -- Exchanged view case, look in the private declarations
9460 if No (Prev) then
9461 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
9462 end if;
9464 return Prev;
9466 -- Otherwise if this is the package body, then Typ is a potential
9467 -- Taft amendment type. The incomplete view should be located in
9468 -- the private declarations of the enclosing scope.
9470 elsif In_Package_Body (Pkg) then
9471 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
9472 end if;
9473 end if;
9474 end;
9476 -- The type has no incomplete or private view
9478 return Empty;
9479 end Incomplete_Or_Partial_View;
9481 -----------------------------------------
9482 -- Inherit_Default_Init_Cond_Procedure --
9483 -----------------------------------------
9485 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
9486 Par_Typ : constant Entity_Id := Etype (Typ);
9488 begin
9489 -- A derived type inherits the default initial condition procedure of
9490 -- its parent type.
9492 if No (Default_Init_Cond_Procedure (Typ)) then
9493 Set_Default_Init_Cond_Procedure
9494 (Typ, Default_Init_Cond_Procedure (Par_Typ));
9495 end if;
9496 end Inherit_Default_Init_Cond_Procedure;
9498 ----------------------------
9499 -- Inherit_Rep_Item_Chain --
9500 ----------------------------
9502 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
9503 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
9504 Item : Node_Id := Empty;
9505 Last_Item : Node_Id := Empty;
9507 begin
9508 -- Reach the end of the destination type's chain (if any) and capture
9509 -- the last item.
9511 Item := First_Rep_Item (Typ);
9512 while Present (Item) loop
9514 -- Do not inherit a chain that has been inherited already
9516 if Item = From_Item then
9517 return;
9518 end if;
9520 Last_Item := Item;
9521 Item := Next_Rep_Item (Item);
9522 end loop;
9524 -- When the destination type has a rep item chain, the chain of the
9525 -- source type is appended to it.
9527 if Present (Last_Item) then
9528 Set_Next_Rep_Item (Last_Item, From_Item);
9530 -- Otherwise the destination type directly inherits the rep item chain
9531 -- of the source type (if any).
9533 else
9534 Set_First_Rep_Item (Typ, From_Item);
9535 end if;
9536 end Inherit_Rep_Item_Chain;
9538 ---------------------------------
9539 -- Inherit_Subprogram_Contract --
9540 ---------------------------------
9542 procedure Inherit_Subprogram_Contract
9543 (Subp : Entity_Id;
9544 From_Subp : Entity_Id)
9546 procedure Inherit_Pragma (Prag_Id : Pragma_Id);
9547 -- Propagate a pragma denoted by Prag_Id from From_Subp's contract to
9548 -- Subp's contract.
9550 --------------------
9551 -- Inherit_Pragma --
9552 --------------------
9554 procedure Inherit_Pragma (Prag_Id : Pragma_Id) is
9555 Prag : constant Node_Id := Get_Pragma (From_Subp, Prag_Id);
9556 New_Prag : Node_Id;
9558 begin
9559 -- A pragma cannot be part of more than one First_Pragma/Next_Pragma
9560 -- chains, therefore the node must be replicated. The new pragma is
9561 -- flagged is inherited for distrinction purposes.
9563 if Present (Prag) then
9564 New_Prag := New_Copy_Tree (Prag);
9565 Set_Is_Inherited (New_Prag);
9567 Add_Contract_Item (New_Prag, Subp);
9568 end if;
9569 end Inherit_Pragma;
9571 -- Start of processing for Inherit_Subprogram_Contract
9573 begin
9574 -- Inheritance is carried out only when both entities are subprograms
9575 -- with contracts.
9577 if Is_Subprogram_Or_Generic_Subprogram (Subp)
9578 and then Is_Subprogram_Or_Generic_Subprogram (From_Subp)
9579 and then Present (Contract (Subp))
9580 and then Present (Contract (From_Subp))
9581 then
9582 Inherit_Pragma (Pragma_Extensions_Visible);
9583 end if;
9584 end Inherit_Subprogram_Contract;
9586 ---------------------------------
9587 -- Insert_Explicit_Dereference --
9588 ---------------------------------
9590 procedure Insert_Explicit_Dereference (N : Node_Id) is
9591 New_Prefix : constant Node_Id := Relocate_Node (N);
9592 Ent : Entity_Id := Empty;
9593 Pref : Node_Id;
9594 I : Interp_Index;
9595 It : Interp;
9596 T : Entity_Id;
9598 begin
9599 Save_Interps (N, New_Prefix);
9601 Rewrite (N,
9602 Make_Explicit_Dereference (Sloc (Parent (N)),
9603 Prefix => New_Prefix));
9605 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
9607 if Is_Overloaded (New_Prefix) then
9609 -- The dereference is also overloaded, and its interpretations are
9610 -- the designated types of the interpretations of the original node.
9612 Set_Etype (N, Any_Type);
9614 Get_First_Interp (New_Prefix, I, It);
9615 while Present (It.Nam) loop
9616 T := It.Typ;
9618 if Is_Access_Type (T) then
9619 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
9620 end if;
9622 Get_Next_Interp (I, It);
9623 end loop;
9625 End_Interp_List;
9627 else
9628 -- Prefix is unambiguous: mark the original prefix (which might
9629 -- Come_From_Source) as a reference, since the new (relocated) one
9630 -- won't be taken into account.
9632 if Is_Entity_Name (New_Prefix) then
9633 Ent := Entity (New_Prefix);
9634 Pref := New_Prefix;
9636 -- For a retrieval of a subcomponent of some composite object,
9637 -- retrieve the ultimate entity if there is one.
9639 elsif Nkind_In (New_Prefix, N_Selected_Component,
9640 N_Indexed_Component)
9641 then
9642 Pref := Prefix (New_Prefix);
9643 while Present (Pref)
9644 and then Nkind_In (Pref, N_Selected_Component,
9645 N_Indexed_Component)
9646 loop
9647 Pref := Prefix (Pref);
9648 end loop;
9650 if Present (Pref) and then Is_Entity_Name (Pref) then
9651 Ent := Entity (Pref);
9652 end if;
9653 end if;
9655 -- Place the reference on the entity node
9657 if Present (Ent) then
9658 Generate_Reference (Ent, Pref);
9659 end if;
9660 end if;
9661 end Insert_Explicit_Dereference;
9663 ------------------------------------------
9664 -- Inspect_Deferred_Constant_Completion --
9665 ------------------------------------------
9667 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
9668 Decl : Node_Id;
9670 begin
9671 Decl := First (Decls);
9672 while Present (Decl) loop
9674 -- Deferred constant signature
9676 if Nkind (Decl) = N_Object_Declaration
9677 and then Constant_Present (Decl)
9678 and then No (Expression (Decl))
9680 -- No need to check internally generated constants
9682 and then Comes_From_Source (Decl)
9684 -- The constant is not completed. A full object declaration or a
9685 -- pragma Import complete a deferred constant.
9687 and then not Has_Completion (Defining_Identifier (Decl))
9688 then
9689 Error_Msg_N
9690 ("constant declaration requires initialization expression",
9691 Defining_Identifier (Decl));
9692 end if;
9694 Decl := Next (Decl);
9695 end loop;
9696 end Inspect_Deferred_Constant_Completion;
9698 -----------------------------
9699 -- Is_Actual_Out_Parameter --
9700 -----------------------------
9702 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
9703 Formal : Entity_Id;
9704 Call : Node_Id;
9705 begin
9706 Find_Actual (N, Formal, Call);
9707 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
9708 end Is_Actual_Out_Parameter;
9710 -------------------------
9711 -- Is_Actual_Parameter --
9712 -------------------------
9714 function Is_Actual_Parameter (N : Node_Id) return Boolean is
9715 PK : constant Node_Kind := Nkind (Parent (N));
9717 begin
9718 case PK is
9719 when N_Parameter_Association =>
9720 return N = Explicit_Actual_Parameter (Parent (N));
9722 when N_Subprogram_Call =>
9723 return Is_List_Member (N)
9724 and then
9725 List_Containing (N) = Parameter_Associations (Parent (N));
9727 when others =>
9728 return False;
9729 end case;
9730 end Is_Actual_Parameter;
9732 --------------------------------
9733 -- Is_Actual_Tagged_Parameter --
9734 --------------------------------
9736 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
9737 Formal : Entity_Id;
9738 Call : Node_Id;
9739 begin
9740 Find_Actual (N, Formal, Call);
9741 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
9742 end Is_Actual_Tagged_Parameter;
9744 ---------------------
9745 -- Is_Aliased_View --
9746 ---------------------
9748 function Is_Aliased_View (Obj : Node_Id) return Boolean is
9749 E : Entity_Id;
9751 begin
9752 if Is_Entity_Name (Obj) then
9753 E := Entity (Obj);
9755 return
9756 (Is_Object (E)
9757 and then
9758 (Is_Aliased (E)
9759 or else (Present (Renamed_Object (E))
9760 and then Is_Aliased_View (Renamed_Object (E)))))
9762 or else ((Is_Formal (E)
9763 or else Ekind_In (E, E_Generic_In_Out_Parameter,
9764 E_Generic_In_Parameter))
9765 and then Is_Tagged_Type (Etype (E)))
9767 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
9769 -- Current instance of type, either directly or as rewritten
9770 -- reference to the current object.
9772 or else (Is_Entity_Name (Original_Node (Obj))
9773 and then Present (Entity (Original_Node (Obj)))
9774 and then Is_Type (Entity (Original_Node (Obj))))
9776 or else (Is_Type (E) and then E = Current_Scope)
9778 or else (Is_Incomplete_Or_Private_Type (E)
9779 and then Full_View (E) = Current_Scope)
9781 -- Ada 2012 AI05-0053: the return object of an extended return
9782 -- statement is aliased if its type is immutably limited.
9784 or else (Is_Return_Object (E)
9785 and then Is_Limited_View (Etype (E)));
9787 elsif Nkind (Obj) = N_Selected_Component then
9788 return Is_Aliased (Entity (Selector_Name (Obj)));
9790 elsif Nkind (Obj) = N_Indexed_Component then
9791 return Has_Aliased_Components (Etype (Prefix (Obj)))
9792 or else
9793 (Is_Access_Type (Etype (Prefix (Obj)))
9794 and then Has_Aliased_Components
9795 (Designated_Type (Etype (Prefix (Obj)))));
9797 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
9798 return Is_Tagged_Type (Etype (Obj))
9799 and then Is_Aliased_View (Expression (Obj));
9801 elsif Nkind (Obj) = N_Explicit_Dereference then
9802 return Nkind (Original_Node (Obj)) /= N_Function_Call;
9804 else
9805 return False;
9806 end if;
9807 end Is_Aliased_View;
9809 -------------------------
9810 -- Is_Ancestor_Package --
9811 -------------------------
9813 function Is_Ancestor_Package
9814 (E1 : Entity_Id;
9815 E2 : Entity_Id) return Boolean
9817 Par : Entity_Id;
9819 begin
9820 Par := E2;
9821 while Present (Par) and then Par /= Standard_Standard loop
9822 if Par = E1 then
9823 return True;
9824 end if;
9826 Par := Scope (Par);
9827 end loop;
9829 return False;
9830 end Is_Ancestor_Package;
9832 ----------------------
9833 -- Is_Atomic_Object --
9834 ----------------------
9836 function Is_Atomic_Object (N : Node_Id) return Boolean is
9838 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
9839 -- Determines if given object has atomic components
9841 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
9842 -- If prefix is an implicit dereference, examine designated type
9844 ----------------------
9845 -- Is_Atomic_Prefix --
9846 ----------------------
9848 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
9849 begin
9850 if Is_Access_Type (Etype (N)) then
9851 return
9852 Has_Atomic_Components (Designated_Type (Etype (N)));
9853 else
9854 return Object_Has_Atomic_Components (N);
9855 end if;
9856 end Is_Atomic_Prefix;
9858 ----------------------------------
9859 -- Object_Has_Atomic_Components --
9860 ----------------------------------
9862 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
9863 begin
9864 if Has_Atomic_Components (Etype (N))
9865 or else Is_Atomic (Etype (N))
9866 then
9867 return True;
9869 elsif Is_Entity_Name (N)
9870 and then (Has_Atomic_Components (Entity (N))
9871 or else Is_Atomic (Entity (N)))
9872 then
9873 return True;
9875 elsif Nkind (N) = N_Selected_Component
9876 and then Is_Atomic (Entity (Selector_Name (N)))
9877 then
9878 return True;
9880 elsif Nkind (N) = N_Indexed_Component
9881 or else Nkind (N) = N_Selected_Component
9882 then
9883 return Is_Atomic_Prefix (Prefix (N));
9885 else
9886 return False;
9887 end if;
9888 end Object_Has_Atomic_Components;
9890 -- Start of processing for Is_Atomic_Object
9892 begin
9893 -- Predicate is not relevant to subprograms
9895 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
9896 return False;
9898 elsif Is_Atomic (Etype (N))
9899 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
9900 then
9901 return True;
9903 elsif Nkind (N) = N_Selected_Component
9904 and then Is_Atomic (Entity (Selector_Name (N)))
9905 then
9906 return True;
9908 elsif Nkind (N) = N_Indexed_Component
9909 or else Nkind (N) = N_Selected_Component
9910 then
9911 return Is_Atomic_Prefix (Prefix (N));
9913 else
9914 return False;
9915 end if;
9916 end Is_Atomic_Object;
9918 -------------------------
9919 -- Is_Attribute_Result --
9920 -------------------------
9922 function Is_Attribute_Result (N : Node_Id) return Boolean is
9923 begin
9924 return Nkind (N) = N_Attribute_Reference
9925 and then Attribute_Name (N) = Name_Result;
9926 end Is_Attribute_Result;
9928 ------------------------------------
9929 -- Is_Body_Or_Package_Declaration --
9930 ------------------------------------
9932 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
9933 begin
9934 return Nkind_In (N, N_Entry_Body,
9935 N_Package_Body,
9936 N_Package_Declaration,
9937 N_Protected_Body,
9938 N_Subprogram_Body,
9939 N_Task_Body);
9940 end Is_Body_Or_Package_Declaration;
9942 -----------------------
9943 -- Is_Bounded_String --
9944 -----------------------
9946 function Is_Bounded_String (T : Entity_Id) return Boolean is
9947 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
9949 begin
9950 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9951 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9952 -- be True for all the Bounded_String types in instances of the
9953 -- Generic_Bounded_Length generics, and for types derived from those.
9955 return Present (Under)
9956 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
9957 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
9958 Is_RTE (Root_Type (Under), RO_WW_Super_String));
9959 end Is_Bounded_String;
9961 -------------------------
9962 -- Is_Child_Or_Sibling --
9963 -------------------------
9965 function Is_Child_Or_Sibling
9966 (Pack_1 : Entity_Id;
9967 Pack_2 : Entity_Id) return Boolean
9969 function Distance_From_Standard (Pack : Entity_Id) return Nat;
9970 -- Given an arbitrary package, return the number of "climbs" necessary
9971 -- to reach scope Standard_Standard.
9973 procedure Equalize_Depths
9974 (Pack : in out Entity_Id;
9975 Depth : in out Nat;
9976 Depth_To_Reach : Nat);
9977 -- Given an arbitrary package, its depth and a target depth to reach,
9978 -- climb the scope chain until the said depth is reached. The pointer
9979 -- to the package and its depth a modified during the climb.
9981 ----------------------------
9982 -- Distance_From_Standard --
9983 ----------------------------
9985 function Distance_From_Standard (Pack : Entity_Id) return Nat is
9986 Dist : Nat;
9987 Scop : Entity_Id;
9989 begin
9990 Dist := 0;
9991 Scop := Pack;
9992 while Present (Scop) and then Scop /= Standard_Standard loop
9993 Dist := Dist + 1;
9994 Scop := Scope (Scop);
9995 end loop;
9997 return Dist;
9998 end Distance_From_Standard;
10000 ---------------------
10001 -- Equalize_Depths --
10002 ---------------------
10004 procedure Equalize_Depths
10005 (Pack : in out Entity_Id;
10006 Depth : in out Nat;
10007 Depth_To_Reach : Nat)
10009 begin
10010 -- The package must be at a greater or equal depth
10012 if Depth < Depth_To_Reach then
10013 raise Program_Error;
10014 end if;
10016 -- Climb the scope chain until the desired depth is reached
10018 while Present (Pack) and then Depth /= Depth_To_Reach loop
10019 Pack := Scope (Pack);
10020 Depth := Depth - 1;
10021 end loop;
10022 end Equalize_Depths;
10024 -- Local variables
10026 P_1 : Entity_Id := Pack_1;
10027 P_1_Child : Boolean := False;
10028 P_1_Depth : Nat := Distance_From_Standard (P_1);
10029 P_2 : Entity_Id := Pack_2;
10030 P_2_Child : Boolean := False;
10031 P_2_Depth : Nat := Distance_From_Standard (P_2);
10033 -- Start of processing for Is_Child_Or_Sibling
10035 begin
10036 pragma Assert
10037 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
10039 -- Both packages denote the same entity, therefore they cannot be
10040 -- children or siblings.
10042 if P_1 = P_2 then
10043 return False;
10045 -- One of the packages is at a deeper level than the other. Note that
10046 -- both may still come from differen hierarchies.
10048 -- (root) P_2
10049 -- / \ :
10050 -- X P_2 or X
10051 -- : :
10052 -- P_1 P_1
10054 elsif P_1_Depth > P_2_Depth then
10055 Equalize_Depths
10056 (Pack => P_1,
10057 Depth => P_1_Depth,
10058 Depth_To_Reach => P_2_Depth);
10059 P_1_Child := True;
10061 -- (root) P_1
10062 -- / \ :
10063 -- P_1 X or X
10064 -- : :
10065 -- P_2 P_2
10067 elsif P_2_Depth > P_1_Depth then
10068 Equalize_Depths
10069 (Pack => P_2,
10070 Depth => P_2_Depth,
10071 Depth_To_Reach => P_1_Depth);
10072 P_2_Child := True;
10073 end if;
10075 -- At this stage the package pointers have been elevated to the same
10076 -- depth. If the related entities are the same, then one package is a
10077 -- potential child of the other:
10079 -- P_1
10080 -- :
10081 -- X became P_1 P_2 or vica versa
10082 -- :
10083 -- P_2
10085 if P_1 = P_2 then
10086 if P_1_Child then
10087 return Is_Child_Unit (Pack_1);
10089 else pragma Assert (P_2_Child);
10090 return Is_Child_Unit (Pack_2);
10091 end if;
10093 -- The packages may come from the same package chain or from entirely
10094 -- different hierarcies. To determine this, climb the scope stack until
10095 -- a common root is found.
10097 -- (root) (root 1) (root 2)
10098 -- / \ | |
10099 -- P_1 P_2 P_1 P_2
10101 else
10102 while Present (P_1) and then Present (P_2) loop
10104 -- The two packages may be siblings
10106 if P_1 = P_2 then
10107 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
10108 end if;
10110 P_1 := Scope (P_1);
10111 P_2 := Scope (P_2);
10112 end loop;
10113 end if;
10115 return False;
10116 end Is_Child_Or_Sibling;
10118 -----------------------------
10119 -- Is_Concurrent_Interface --
10120 -----------------------------
10122 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
10123 begin
10124 return Is_Interface (T)
10125 and then
10126 (Is_Protected_Interface (T)
10127 or else Is_Synchronized_Interface (T)
10128 or else Is_Task_Interface (T));
10129 end Is_Concurrent_Interface;
10131 ---------------------------
10132 -- Is_Container_Element --
10133 ---------------------------
10135 function Is_Container_Element (Exp : Node_Id) return Boolean is
10136 Loc : constant Source_Ptr := Sloc (Exp);
10137 Pref : constant Node_Id := Prefix (Exp);
10139 Call : Node_Id;
10140 -- Call to an indexing aspect
10142 Cont_Typ : Entity_Id;
10143 -- The type of the container being accessed
10145 Elem_Typ : Entity_Id;
10146 -- Its element type
10148 Indexing : Entity_Id;
10149 Is_Const : Boolean;
10150 -- Indicates that constant indexing is used, and the element is thus
10151 -- a constant.
10153 Ref_Typ : Entity_Id;
10154 -- The reference type returned by the indexing operation
10156 begin
10157 -- If C is a container, in a context that imposes the element type of
10158 -- that container, the indexing notation C (X) is rewritten as:
10160 -- Indexing (C, X).Discr.all
10162 -- where Indexing is one of the indexing aspects of the container.
10163 -- If the context does not require a reference, the construct can be
10164 -- rewritten as
10166 -- Element (C, X)
10168 -- First, verify that the construct has the proper form
10170 if not Expander_Active then
10171 return False;
10173 elsif Nkind (Pref) /= N_Selected_Component then
10174 return False;
10176 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
10177 return False;
10179 else
10180 Call := Prefix (Pref);
10181 Ref_Typ := Etype (Call);
10182 end if;
10184 if not Has_Implicit_Dereference (Ref_Typ)
10185 or else No (First (Parameter_Associations (Call)))
10186 or else not Is_Entity_Name (Name (Call))
10187 then
10188 return False;
10189 end if;
10191 -- Retrieve type of container object, and its iterator aspects
10193 Cont_Typ := Etype (First (Parameter_Associations (Call)));
10194 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
10195 Is_Const := False;
10197 if No (Indexing) then
10199 -- Container should have at least one indexing operation
10201 return False;
10203 elsif Entity (Name (Call)) /= Entity (Indexing) then
10205 -- This may be a variable indexing operation
10207 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
10209 if No (Indexing)
10210 or else Entity (Name (Call)) /= Entity (Indexing)
10211 then
10212 return False;
10213 end if;
10215 else
10216 Is_Const := True;
10217 end if;
10219 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
10221 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
10222 return False;
10223 end if;
10225 -- Check that the expression is not the target of an assignment, in
10226 -- which case the rewriting is not possible.
10228 if not Is_Const then
10229 declare
10230 Par : Node_Id;
10232 begin
10233 Par := Exp;
10234 while Present (Par)
10235 loop
10236 if Nkind (Parent (Par)) = N_Assignment_Statement
10237 and then Par = Name (Parent (Par))
10238 then
10239 return False;
10241 -- A renaming produces a reference, and the transformation
10242 -- does not apply.
10244 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
10245 return False;
10247 elsif Nkind_In
10248 (Nkind (Parent (Par)), N_Function_Call,
10249 N_Procedure_Call_Statement,
10250 N_Entry_Call_Statement)
10251 then
10252 -- Check that the element is not part of an actual for an
10253 -- in-out parameter.
10255 declare
10256 F : Entity_Id;
10257 A : Node_Id;
10259 begin
10260 F := First_Formal (Entity (Name (Parent (Par))));
10261 A := First (Parameter_Associations (Parent (Par)));
10262 while Present (F) loop
10263 if A = Par and then Ekind (F) /= E_In_Parameter then
10264 return False;
10265 end if;
10267 Next_Formal (F);
10268 Next (A);
10269 end loop;
10270 end;
10272 -- E_In_Parameter in a call: element is not modified.
10274 exit;
10275 end if;
10277 Par := Parent (Par);
10278 end loop;
10279 end;
10280 end if;
10282 -- The expression has the proper form and the context requires the
10283 -- element type. Retrieve the Element function of the container and
10284 -- rewrite the construct as a call to it.
10286 declare
10287 Op : Elmt_Id;
10289 begin
10290 Op := First_Elmt (Primitive_Operations (Cont_Typ));
10291 while Present (Op) loop
10292 exit when Chars (Node (Op)) = Name_Element;
10293 Next_Elmt (Op);
10294 end loop;
10296 if No (Op) then
10297 return False;
10299 else
10300 Rewrite (Exp,
10301 Make_Function_Call (Loc,
10302 Name => New_Occurrence_Of (Node (Op), Loc),
10303 Parameter_Associations => Parameter_Associations (Call)));
10304 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
10305 return True;
10306 end if;
10307 end;
10308 end Is_Container_Element;
10310 -----------------------
10311 -- Is_Constant_Bound --
10312 -----------------------
10314 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
10315 begin
10316 if Compile_Time_Known_Value (Exp) then
10317 return True;
10319 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10320 return Is_Constant_Object (Entity (Exp))
10321 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10323 elsif Nkind (Exp) in N_Binary_Op then
10324 return Is_Constant_Bound (Left_Opnd (Exp))
10325 and then Is_Constant_Bound (Right_Opnd (Exp))
10326 and then Scope (Entity (Exp)) = Standard_Standard;
10328 else
10329 return False;
10330 end if;
10331 end Is_Constant_Bound;
10333 --------------------------------------
10334 -- Is_Controlling_Limited_Procedure --
10335 --------------------------------------
10337 function Is_Controlling_Limited_Procedure
10338 (Proc_Nam : Entity_Id) return Boolean
10340 Param_Typ : Entity_Id := Empty;
10342 begin
10343 if Ekind (Proc_Nam) = E_Procedure
10344 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
10345 then
10346 Param_Typ := Etype (Parameter_Type (First (
10347 Parameter_Specifications (Parent (Proc_Nam)))));
10349 -- In this case where an Itype was created, the procedure call has been
10350 -- rewritten.
10352 elsif Present (Associated_Node_For_Itype (Proc_Nam))
10353 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
10354 and then
10355 Present (Parameter_Associations
10356 (Associated_Node_For_Itype (Proc_Nam)))
10357 then
10358 Param_Typ :=
10359 Etype (First (Parameter_Associations
10360 (Associated_Node_For_Itype (Proc_Nam))));
10361 end if;
10363 if Present (Param_Typ) then
10364 return
10365 Is_Interface (Param_Typ)
10366 and then Is_Limited_Record (Param_Typ);
10367 end if;
10369 return False;
10370 end Is_Controlling_Limited_Procedure;
10372 -----------------------------
10373 -- Is_CPP_Constructor_Call --
10374 -----------------------------
10376 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
10377 begin
10378 return Nkind (N) = N_Function_Call
10379 and then Is_CPP_Class (Etype (Etype (N)))
10380 and then Is_Constructor (Entity (Name (N)))
10381 and then Is_Imported (Entity (Name (N)));
10382 end Is_CPP_Constructor_Call;
10384 --------------------
10385 -- Is_Declaration --
10386 --------------------
10388 function Is_Declaration (N : Node_Id) return Boolean is
10389 begin
10390 case Nkind (N) is
10391 when N_Abstract_Subprogram_Declaration |
10392 N_Exception_Declaration |
10393 N_Exception_Renaming_Declaration |
10394 N_Full_Type_Declaration |
10395 N_Generic_Function_Renaming_Declaration |
10396 N_Generic_Package_Declaration |
10397 N_Generic_Package_Renaming_Declaration |
10398 N_Generic_Procedure_Renaming_Declaration |
10399 N_Generic_Subprogram_Declaration |
10400 N_Number_Declaration |
10401 N_Object_Declaration |
10402 N_Object_Renaming_Declaration |
10403 N_Package_Declaration |
10404 N_Package_Renaming_Declaration |
10405 N_Private_Extension_Declaration |
10406 N_Private_Type_Declaration |
10407 N_Subprogram_Declaration |
10408 N_Subprogram_Renaming_Declaration |
10409 N_Subtype_Declaration =>
10410 return True;
10412 when others =>
10413 return False;
10414 end case;
10415 end Is_Declaration;
10417 -----------------
10418 -- Is_Delegate --
10419 -----------------
10421 function Is_Delegate (T : Entity_Id) return Boolean is
10422 Desig_Type : Entity_Id;
10424 begin
10425 if VM_Target /= CLI_Target then
10426 return False;
10427 end if;
10429 -- Access-to-subprograms are delegates in CIL
10431 if Ekind (T) = E_Access_Subprogram_Type then
10432 return True;
10433 end if;
10435 if not Is_Access_Type (T) then
10437 -- A delegate is a managed pointer. If no designated type is defined
10438 -- it means that it's not a delegate.
10440 return False;
10441 end if;
10443 Desig_Type := Etype (Directly_Designated_Type (T));
10445 if not Is_Tagged_Type (Desig_Type) then
10446 return False;
10447 end if;
10449 -- Test if the type is inherited from [mscorlib]System.Delegate
10451 while Etype (Desig_Type) /= Desig_Type loop
10452 if Chars (Scope (Desig_Type)) /= No_Name
10453 and then Is_Imported (Scope (Desig_Type))
10454 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
10455 then
10456 return True;
10457 end if;
10459 Desig_Type := Etype (Desig_Type);
10460 end loop;
10462 return False;
10463 end Is_Delegate;
10465 ----------------------------------------------
10466 -- Is_Dependent_Component_Of_Mutable_Object --
10467 ----------------------------------------------
10469 function Is_Dependent_Component_Of_Mutable_Object
10470 (Object : Node_Id) return Boolean
10472 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
10473 -- Returns True if and only if Comp is declared within a variant part
10475 --------------------------------
10476 -- Is_Declared_Within_Variant --
10477 --------------------------------
10479 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
10480 Comp_Decl : constant Node_Id := Parent (Comp);
10481 Comp_List : constant Node_Id := Parent (Comp_Decl);
10482 begin
10483 return Nkind (Parent (Comp_List)) = N_Variant;
10484 end Is_Declared_Within_Variant;
10486 P : Node_Id;
10487 Prefix_Type : Entity_Id;
10488 P_Aliased : Boolean := False;
10489 Comp : Entity_Id;
10491 Deref : Node_Id := Object;
10492 -- Dereference node, in something like X.all.Y(2)
10494 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10496 begin
10497 -- Find the dereference node if any
10499 while Nkind_In (Deref, N_Indexed_Component,
10500 N_Selected_Component,
10501 N_Slice)
10502 loop
10503 Deref := Prefix (Deref);
10504 end loop;
10506 -- Ada 2005: If we have a component or slice of a dereference,
10507 -- something like X.all.Y (2), and the type of X is access-to-constant,
10508 -- Is_Variable will return False, because it is indeed a constant
10509 -- view. But it might be a view of a variable object, so we want the
10510 -- following condition to be True in that case.
10512 if Is_Variable (Object)
10513 or else (Ada_Version >= Ada_2005
10514 and then Nkind (Deref) = N_Explicit_Dereference)
10515 then
10516 if Nkind (Object) = N_Selected_Component then
10517 P := Prefix (Object);
10518 Prefix_Type := Etype (P);
10520 if Is_Entity_Name (P) then
10521 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
10522 Prefix_Type := Base_Type (Prefix_Type);
10523 end if;
10525 if Is_Aliased (Entity (P)) then
10526 P_Aliased := True;
10527 end if;
10529 -- A discriminant check on a selected component may be expanded
10530 -- into a dereference when removing side-effects. Recover the
10531 -- original node and its type, which may be unconstrained.
10533 elsif Nkind (P) = N_Explicit_Dereference
10534 and then not (Comes_From_Source (P))
10535 then
10536 P := Original_Node (P);
10537 Prefix_Type := Etype (P);
10539 else
10540 -- Check for prefix being an aliased component???
10542 null;
10544 end if;
10546 -- A heap object is constrained by its initial value
10548 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10549 -- the dereferenced case, since the access value might denote an
10550 -- unconstrained aliased object, whereas in Ada 95 the designated
10551 -- object is guaranteed to be constrained. A worst-case assumption
10552 -- has to apply in Ada 2005 because we can't tell at compile
10553 -- time whether the object is "constrained by its initial value"
10554 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10555 -- rules (these rules are acknowledged to need fixing).
10557 if Ada_Version < Ada_2005 then
10558 if Is_Access_Type (Prefix_Type)
10559 or else Nkind (P) = N_Explicit_Dereference
10560 then
10561 return False;
10562 end if;
10564 else pragma Assert (Ada_Version >= Ada_2005);
10565 if Is_Access_Type (Prefix_Type) then
10567 -- If the access type is pool-specific, and there is no
10568 -- constrained partial view of the designated type, then the
10569 -- designated object is known to be constrained.
10571 if Ekind (Prefix_Type) = E_Access_Type
10572 and then not Object_Type_Has_Constrained_Partial_View
10573 (Typ => Designated_Type (Prefix_Type),
10574 Scop => Current_Scope)
10575 then
10576 return False;
10578 -- Otherwise (general access type, or there is a constrained
10579 -- partial view of the designated type), we need to check
10580 -- based on the designated type.
10582 else
10583 Prefix_Type := Designated_Type (Prefix_Type);
10584 end if;
10585 end if;
10586 end if;
10588 Comp :=
10589 Original_Record_Component (Entity (Selector_Name (Object)));
10591 -- As per AI-0017, the renaming is illegal in a generic body, even
10592 -- if the subtype is indefinite.
10594 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10596 if not Is_Constrained (Prefix_Type)
10597 and then (not Is_Indefinite_Subtype (Prefix_Type)
10598 or else
10599 (Is_Generic_Type (Prefix_Type)
10600 and then Ekind (Current_Scope) = E_Generic_Package
10601 and then In_Package_Body (Current_Scope)))
10603 and then (Is_Declared_Within_Variant (Comp)
10604 or else Has_Discriminant_Dependent_Constraint (Comp))
10605 and then (not P_Aliased or else Ada_Version >= Ada_2005)
10606 then
10607 return True;
10609 -- If the prefix is of an access type at this point, then we want
10610 -- to return False, rather than calling this function recursively
10611 -- on the access object (which itself might be a discriminant-
10612 -- dependent component of some other object, but that isn't
10613 -- relevant to checking the object passed to us). This avoids
10614 -- issuing wrong errors when compiling with -gnatc, where there
10615 -- can be implicit dereferences that have not been expanded.
10617 elsif Is_Access_Type (Etype (Prefix (Object))) then
10618 return False;
10620 else
10621 return
10622 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10623 end if;
10625 elsif Nkind (Object) = N_Indexed_Component
10626 or else Nkind (Object) = N_Slice
10627 then
10628 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10630 -- A type conversion that Is_Variable is a view conversion:
10631 -- go back to the denoted object.
10633 elsif Nkind (Object) = N_Type_Conversion then
10634 return
10635 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
10636 end if;
10637 end if;
10639 return False;
10640 end Is_Dependent_Component_Of_Mutable_Object;
10642 ---------------------
10643 -- Is_Dereferenced --
10644 ---------------------
10646 function Is_Dereferenced (N : Node_Id) return Boolean is
10647 P : constant Node_Id := Parent (N);
10648 begin
10649 return Nkind_In (P, N_Selected_Component,
10650 N_Explicit_Dereference,
10651 N_Indexed_Component,
10652 N_Slice)
10653 and then Prefix (P) = N;
10654 end Is_Dereferenced;
10656 ----------------------
10657 -- Is_Descendent_Of --
10658 ----------------------
10660 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
10661 T : Entity_Id;
10662 Etyp : Entity_Id;
10664 begin
10665 pragma Assert (Nkind (T1) in N_Entity);
10666 pragma Assert (Nkind (T2) in N_Entity);
10668 T := Base_Type (T1);
10670 -- Immediate return if the types match
10672 if T = T2 then
10673 return True;
10675 -- Comment needed here ???
10677 elsif Ekind (T) = E_Class_Wide_Type then
10678 return Etype (T) = T2;
10680 -- All other cases
10682 else
10683 loop
10684 Etyp := Etype (T);
10686 -- Done if we found the type we are looking for
10688 if Etyp = T2 then
10689 return True;
10691 -- Done if no more derivations to check
10693 elsif T = T1
10694 or else T = Etyp
10695 then
10696 return False;
10698 -- Following test catches error cases resulting from prev errors
10700 elsif No (Etyp) then
10701 return False;
10703 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
10704 return False;
10706 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
10707 return False;
10708 end if;
10710 T := Base_Type (Etyp);
10711 end loop;
10712 end if;
10713 end Is_Descendent_Of;
10715 -----------------------------
10716 -- Is_Effectively_Volatile --
10717 -----------------------------
10719 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
10720 begin
10721 if Is_Type (Id) then
10723 -- An arbitrary type is effectively volatile when it is subject to
10724 -- pragma Atomic or Volatile.
10726 if Is_Volatile (Id) then
10727 return True;
10729 -- An array type is effectively volatile when it is subject to pragma
10730 -- Atomic_Components or Volatile_Components or its compolent type is
10731 -- effectively volatile.
10733 elsif Is_Array_Type (Id) then
10734 return
10735 Has_Volatile_Components (Id)
10736 or else
10737 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
10739 else
10740 return False;
10741 end if;
10743 -- Otherwise Id denotes an object
10745 else
10746 return
10747 Is_Volatile (Id)
10748 or else Has_Volatile_Components (Id)
10749 or else Is_Effectively_Volatile (Etype (Id));
10750 end if;
10751 end Is_Effectively_Volatile;
10753 ------------------------------------
10754 -- Is_Effectively_Volatile_Object --
10755 ------------------------------------
10757 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
10758 begin
10759 if Is_Entity_Name (N) then
10760 return Is_Effectively_Volatile (Entity (N));
10762 elsif Nkind (N) = N_Expanded_Name then
10763 return Is_Effectively_Volatile (Entity (N));
10765 elsif Nkind (N) = N_Indexed_Component then
10766 return Is_Effectively_Volatile_Object (Prefix (N));
10768 elsif Nkind (N) = N_Selected_Component then
10769 return
10770 Is_Effectively_Volatile_Object (Prefix (N))
10771 or else
10772 Is_Effectively_Volatile_Object (Selector_Name (N));
10774 else
10775 return False;
10776 end if;
10777 end Is_Effectively_Volatile_Object;
10779 ----------------------------
10780 -- Is_Expression_Function --
10781 ----------------------------
10783 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
10784 Decl : Node_Id;
10786 begin
10787 if Ekind (Subp) /= E_Function then
10788 return False;
10790 else
10791 Decl := Unit_Declaration_Node (Subp);
10792 return Nkind (Decl) = N_Subprogram_Declaration
10793 and then
10794 (Nkind (Original_Node (Decl)) = N_Expression_Function
10795 or else
10796 (Present (Corresponding_Body (Decl))
10797 and then
10798 Nkind (Original_Node
10799 (Unit_Declaration_Node
10800 (Corresponding_Body (Decl)))) =
10801 N_Expression_Function));
10802 end if;
10803 end Is_Expression_Function;
10805 -----------------------
10806 -- Is_EVF_Expression --
10807 -----------------------
10809 function Is_EVF_Expression (N : Node_Id) return Boolean is
10810 Orig_N : constant Node_Id := Original_Node (N);
10811 Alt : Node_Id;
10812 Expr : Node_Id;
10813 Id : Entity_Id;
10815 begin
10816 -- Detect a reference to a formal parameter of a specific tagged type
10817 -- whose related subprogram is subject to pragma Expresions_Visible with
10818 -- value "False".
10820 if Is_Entity_Name (N) and then Present (Entity (N)) then
10821 Id := Entity (N);
10823 return
10824 Is_Formal (Id)
10825 and then Is_Specific_Tagged_Type (Etype (Id))
10826 and then Extensions_Visible_Status (Id) =
10827 Extensions_Visible_False;
10829 -- A case expression is an EVF expression when it contains at least one
10830 -- EVF dependent_expression. Note that a case expression may have been
10831 -- expanded, hence the use of Original_Node.
10833 elsif Nkind (Orig_N) = N_Case_Expression then
10834 Alt := First (Alternatives (Orig_N));
10835 while Present (Alt) loop
10836 if Is_EVF_Expression (Expression (Alt)) then
10837 return True;
10838 end if;
10840 Next (Alt);
10841 end loop;
10843 -- An if expression is an EVF expression when it contains at least one
10844 -- EVF dependent_expression. Note that an if expression may have been
10845 -- expanded, hence the use of Original_Node.
10847 elsif Nkind (Orig_N) = N_If_Expression then
10848 Expr := Next (First (Expressions (Orig_N)));
10849 while Present (Expr) loop
10850 if Is_EVF_Expression (Expr) then
10851 return True;
10852 end if;
10854 Next (Expr);
10855 end loop;
10857 -- A qualified expression or a type conversion is an EVF expression when
10858 -- its operand is an EVF expression.
10860 elsif Nkind_In (N, N_Qualified_Expression,
10861 N_Unchecked_Type_Conversion,
10862 N_Type_Conversion)
10863 then
10864 return Is_EVF_Expression (Expression (N));
10866 -- Attributes 'Loop_Entry, 'Old and 'Update are an EVF expression when
10867 -- their prefix denotes an EVF expression.
10869 elsif Nkind (N) = N_Attribute_Reference
10870 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
10871 Name_Old,
10872 Name_Update)
10873 then
10874 return Is_EVF_Expression (Prefix (N));
10875 end if;
10877 return False;
10878 end Is_EVF_Expression;
10880 --------------
10881 -- Is_False --
10882 --------------
10884 function Is_False (U : Uint) return Boolean is
10885 begin
10886 return (U = 0);
10887 end Is_False;
10889 ---------------------------
10890 -- Is_Fixed_Model_Number --
10891 ---------------------------
10893 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
10894 S : constant Ureal := Small_Value (T);
10895 M : Urealp.Save_Mark;
10896 R : Boolean;
10897 begin
10898 M := Urealp.Mark;
10899 R := (U = UR_Trunc (U / S) * S);
10900 Urealp.Release (M);
10901 return R;
10902 end Is_Fixed_Model_Number;
10904 -------------------------------
10905 -- Is_Fully_Initialized_Type --
10906 -------------------------------
10908 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
10909 begin
10910 -- Scalar types
10912 if Is_Scalar_Type (Typ) then
10914 -- A scalar type with an aspect Default_Value is fully initialized
10916 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
10917 -- of a scalar type, but we don't take that into account here, since
10918 -- we don't want these to affect warnings.
10920 return Has_Default_Aspect (Typ);
10922 elsif Is_Access_Type (Typ) then
10923 return True;
10925 elsif Is_Array_Type (Typ) then
10926 if Is_Fully_Initialized_Type (Component_Type (Typ))
10927 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
10928 then
10929 return True;
10930 end if;
10932 -- An interesting case, if we have a constrained type one of whose
10933 -- bounds is known to be null, then there are no elements to be
10934 -- initialized, so all the elements are initialized.
10936 if Is_Constrained (Typ) then
10937 declare
10938 Indx : Node_Id;
10939 Indx_Typ : Entity_Id;
10940 Lbd, Hbd : Node_Id;
10942 begin
10943 Indx := First_Index (Typ);
10944 while Present (Indx) loop
10945 if Etype (Indx) = Any_Type then
10946 return False;
10948 -- If index is a range, use directly
10950 elsif Nkind (Indx) = N_Range then
10951 Lbd := Low_Bound (Indx);
10952 Hbd := High_Bound (Indx);
10954 else
10955 Indx_Typ := Etype (Indx);
10957 if Is_Private_Type (Indx_Typ) then
10958 Indx_Typ := Full_View (Indx_Typ);
10959 end if;
10961 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
10962 return False;
10963 else
10964 Lbd := Type_Low_Bound (Indx_Typ);
10965 Hbd := Type_High_Bound (Indx_Typ);
10966 end if;
10967 end if;
10969 if Compile_Time_Known_Value (Lbd)
10970 and then
10971 Compile_Time_Known_Value (Hbd)
10972 then
10973 if Expr_Value (Hbd) < Expr_Value (Lbd) then
10974 return True;
10975 end if;
10976 end if;
10978 Next_Index (Indx);
10979 end loop;
10980 end;
10981 end if;
10983 -- If no null indexes, then type is not fully initialized
10985 return False;
10987 -- Record types
10989 elsif Is_Record_Type (Typ) then
10990 if Has_Discriminants (Typ)
10991 and then
10992 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
10993 and then Is_Fully_Initialized_Variant (Typ)
10994 then
10995 return True;
10996 end if;
10998 -- We consider bounded string types to be fully initialized, because
10999 -- otherwise we get false alarms when the Data component is not
11000 -- default-initialized.
11002 if Is_Bounded_String (Typ) then
11003 return True;
11004 end if;
11006 -- Controlled records are considered to be fully initialized if
11007 -- there is a user defined Initialize routine. This may not be
11008 -- entirely correct, but as the spec notes, we are guessing here
11009 -- what is best from the point of view of issuing warnings.
11011 if Is_Controlled (Typ) then
11012 declare
11013 Utyp : constant Entity_Id := Underlying_Type (Typ);
11015 begin
11016 if Present (Utyp) then
11017 declare
11018 Init : constant Entity_Id :=
11019 (Find_Prim_Op
11020 (Underlying_Type (Typ), Name_Initialize));
11022 begin
11023 if Present (Init)
11024 and then Comes_From_Source (Init)
11025 and then not
11026 Is_Predefined_File_Name
11027 (File_Name (Get_Source_File_Index (Sloc (Init))))
11028 then
11029 return True;
11031 elsif Has_Null_Extension (Typ)
11032 and then
11033 Is_Fully_Initialized_Type
11034 (Etype (Base_Type (Typ)))
11035 then
11036 return True;
11037 end if;
11038 end;
11039 end if;
11040 end;
11041 end if;
11043 -- Otherwise see if all record components are initialized
11045 declare
11046 Ent : Entity_Id;
11048 begin
11049 Ent := First_Entity (Typ);
11050 while Present (Ent) loop
11051 if Ekind (Ent) = E_Component
11052 and then (No (Parent (Ent))
11053 or else No (Expression (Parent (Ent))))
11054 and then not Is_Fully_Initialized_Type (Etype (Ent))
11056 -- Special VM case for tag components, which need to be
11057 -- defined in this case, but are never initialized as VMs
11058 -- are using other dispatching mechanisms. Ignore this
11059 -- uninitialized case. Note that this applies both to the
11060 -- uTag entry and the main vtable pointer (CPP_Class case).
11062 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
11063 then
11064 return False;
11065 end if;
11067 Next_Entity (Ent);
11068 end loop;
11069 end;
11071 -- No uninitialized components, so type is fully initialized.
11072 -- Note that this catches the case of no components as well.
11074 return True;
11076 elsif Is_Concurrent_Type (Typ) then
11077 return True;
11079 elsif Is_Private_Type (Typ) then
11080 declare
11081 U : constant Entity_Id := Underlying_Type (Typ);
11083 begin
11084 if No (U) then
11085 return False;
11086 else
11087 return Is_Fully_Initialized_Type (U);
11088 end if;
11089 end;
11091 else
11092 return False;
11093 end if;
11094 end Is_Fully_Initialized_Type;
11096 ----------------------------------
11097 -- Is_Fully_Initialized_Variant --
11098 ----------------------------------
11100 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
11101 Loc : constant Source_Ptr := Sloc (Typ);
11102 Constraints : constant List_Id := New_List;
11103 Components : constant Elist_Id := New_Elmt_List;
11104 Comp_Elmt : Elmt_Id;
11105 Comp_Id : Node_Id;
11106 Comp_List : Node_Id;
11107 Discr : Entity_Id;
11108 Discr_Val : Node_Id;
11110 Report_Errors : Boolean;
11111 pragma Warnings (Off, Report_Errors);
11113 begin
11114 if Serious_Errors_Detected > 0 then
11115 return False;
11116 end if;
11118 if Is_Record_Type (Typ)
11119 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11120 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
11121 then
11122 Comp_List := Component_List (Type_Definition (Parent (Typ)));
11124 Discr := First_Discriminant (Typ);
11125 while Present (Discr) loop
11126 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
11127 Discr_Val := Expression (Parent (Discr));
11129 if Present (Discr_Val)
11130 and then Is_OK_Static_Expression (Discr_Val)
11131 then
11132 Append_To (Constraints,
11133 Make_Component_Association (Loc,
11134 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
11135 Expression => New_Copy (Discr_Val)));
11136 else
11137 return False;
11138 end if;
11139 else
11140 return False;
11141 end if;
11143 Next_Discriminant (Discr);
11144 end loop;
11146 Gather_Components
11147 (Typ => Typ,
11148 Comp_List => Comp_List,
11149 Governed_By => Constraints,
11150 Into => Components,
11151 Report_Errors => Report_Errors);
11153 -- Check that each component present is fully initialized
11155 Comp_Elmt := First_Elmt (Components);
11156 while Present (Comp_Elmt) loop
11157 Comp_Id := Node (Comp_Elmt);
11159 if Ekind (Comp_Id) = E_Component
11160 and then (No (Parent (Comp_Id))
11161 or else No (Expression (Parent (Comp_Id))))
11162 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
11163 then
11164 return False;
11165 end if;
11167 Next_Elmt (Comp_Elmt);
11168 end loop;
11170 return True;
11172 elsif Is_Private_Type (Typ) then
11173 declare
11174 U : constant Entity_Id := Underlying_Type (Typ);
11176 begin
11177 if No (U) then
11178 return False;
11179 else
11180 return Is_Fully_Initialized_Variant (U);
11181 end if;
11182 end;
11184 else
11185 return False;
11186 end if;
11187 end Is_Fully_Initialized_Variant;
11189 ----------------------------
11190 -- Is_Inherited_Operation --
11191 ----------------------------
11193 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
11194 pragma Assert (Is_Overloadable (E));
11195 Kind : constant Node_Kind := Nkind (Parent (E));
11196 begin
11197 return Kind = N_Full_Type_Declaration
11198 or else Kind = N_Private_Extension_Declaration
11199 or else Kind = N_Subtype_Declaration
11200 or else (Ekind (E) = E_Enumeration_Literal
11201 and then Is_Derived_Type (Etype (E)));
11202 end Is_Inherited_Operation;
11204 -------------------------------------
11205 -- Is_Inherited_Operation_For_Type --
11206 -------------------------------------
11208 function Is_Inherited_Operation_For_Type
11209 (E : Entity_Id;
11210 Typ : Entity_Id) return Boolean
11212 begin
11213 -- Check that the operation has been created by the type declaration
11215 return Is_Inherited_Operation (E)
11216 and then Defining_Identifier (Parent (E)) = Typ;
11217 end Is_Inherited_Operation_For_Type;
11219 -----------------
11220 -- Is_Iterator --
11221 -----------------
11223 function Is_Iterator (Typ : Entity_Id) return Boolean is
11224 Ifaces_List : Elist_Id;
11225 Iface_Elmt : Elmt_Id;
11226 Iface : Entity_Id;
11228 begin
11229 if Is_Class_Wide_Type (Typ)
11230 and then Nam_In (Chars (Etype (Typ)), Name_Forward_Iterator,
11231 Name_Reversible_Iterator)
11232 and then
11233 Is_Predefined_File_Name
11234 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
11235 then
11236 return True;
11238 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
11239 return False;
11241 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
11242 return True;
11244 else
11245 Collect_Interfaces (Typ, Ifaces_List);
11247 Iface_Elmt := First_Elmt (Ifaces_List);
11248 while Present (Iface_Elmt) loop
11249 Iface := Node (Iface_Elmt);
11250 if Chars (Iface) = Name_Forward_Iterator
11251 and then
11252 Is_Predefined_File_Name
11253 (Unit_File_Name (Get_Source_Unit (Iface)))
11254 then
11255 return True;
11256 end if;
11258 Next_Elmt (Iface_Elmt);
11259 end loop;
11261 return False;
11262 end if;
11263 end Is_Iterator;
11265 ------------
11266 -- Is_LHS --
11267 ------------
11269 -- We seem to have a lot of overlapping functions that do similar things
11270 -- (testing for left hand sides or lvalues???).
11272 function Is_LHS (N : Node_Id) return Is_LHS_Result is
11273 P : constant Node_Id := Parent (N);
11275 begin
11276 -- Return True if we are the left hand side of an assignment statement
11278 if Nkind (P) = N_Assignment_Statement then
11279 if Name (P) = N then
11280 return Yes;
11281 else
11282 return No;
11283 end if;
11285 -- Case of prefix of indexed or selected component or slice
11287 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
11288 and then N = Prefix (P)
11289 then
11290 -- Here we have the case where the parent P is N.Q or N(Q .. R).
11291 -- If P is an LHS, then N is also effectively an LHS, but there
11292 -- is an important exception. If N is of an access type, then
11293 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
11294 -- case this makes N.all a left hand side but not N itself.
11296 -- If we don't know the type yet, this is the case where we return
11297 -- Unknown, since the answer depends on the type which is unknown.
11299 if No (Etype (N)) then
11300 return Unknown;
11302 -- We have an Etype set, so we can check it
11304 elsif Is_Access_Type (Etype (N)) then
11305 return No;
11307 -- OK, not access type case, so just test whole expression
11309 else
11310 return Is_LHS (P);
11311 end if;
11313 -- All other cases are not left hand sides
11315 else
11316 return No;
11317 end if;
11318 end Is_LHS;
11320 -----------------------------
11321 -- Is_Library_Level_Entity --
11322 -----------------------------
11324 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
11325 begin
11326 -- The following is a small optimization, and it also properly handles
11327 -- discriminals, which in task bodies might appear in expressions before
11328 -- the corresponding procedure has been created, and which therefore do
11329 -- not have an assigned scope.
11331 if Is_Formal (E) then
11332 return False;
11333 end if;
11335 -- Normal test is simply that the enclosing dynamic scope is Standard
11337 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
11338 end Is_Library_Level_Entity;
11340 --------------------------------
11341 -- Is_Limited_Class_Wide_Type --
11342 --------------------------------
11344 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
11345 begin
11346 return
11347 Is_Class_Wide_Type (Typ)
11348 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
11349 end Is_Limited_Class_Wide_Type;
11351 ---------------------------------
11352 -- Is_Local_Variable_Reference --
11353 ---------------------------------
11355 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
11356 begin
11357 if not Is_Entity_Name (Expr) then
11358 return False;
11360 else
11361 declare
11362 Ent : constant Entity_Id := Entity (Expr);
11363 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
11364 begin
11365 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
11366 return False;
11367 else
11368 return Present (Sub) and then Sub = Current_Subprogram;
11369 end if;
11370 end;
11371 end if;
11372 end Is_Local_Variable_Reference;
11374 -------------------------
11375 -- Is_Object_Reference --
11376 -------------------------
11378 function Is_Object_Reference (N : Node_Id) return Boolean is
11380 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
11381 -- Determine whether N is the name of an internally-generated renaming
11383 --------------------------------------
11384 -- Is_Internally_Generated_Renaming --
11385 --------------------------------------
11387 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
11388 P : Node_Id;
11390 begin
11391 P := N;
11392 while Present (P) loop
11393 if Nkind (P) = N_Object_Renaming_Declaration then
11394 return not Comes_From_Source (P);
11395 elsif Is_List_Member (P) then
11396 return False;
11397 end if;
11399 P := Parent (P);
11400 end loop;
11402 return False;
11403 end Is_Internally_Generated_Renaming;
11405 -- Start of processing for Is_Object_Reference
11407 begin
11408 if Is_Entity_Name (N) then
11409 return Present (Entity (N)) and then Is_Object (Entity (N));
11411 else
11412 case Nkind (N) is
11413 when N_Indexed_Component | N_Slice =>
11414 return
11415 Is_Object_Reference (Prefix (N))
11416 or else Is_Access_Type (Etype (Prefix (N)));
11418 -- In Ada 95, a function call is a constant object; a procedure
11419 -- call is not.
11421 when N_Function_Call =>
11422 return Etype (N) /= Standard_Void_Type;
11424 -- Attributes 'Input, 'Old and 'Result produce objects
11426 when N_Attribute_Reference =>
11427 return
11428 Nam_In
11429 (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
11431 when N_Selected_Component =>
11432 return
11433 Is_Object_Reference (Selector_Name (N))
11434 and then
11435 (Is_Object_Reference (Prefix (N))
11436 or else Is_Access_Type (Etype (Prefix (N))));
11438 when N_Explicit_Dereference =>
11439 return True;
11441 -- A view conversion of a tagged object is an object reference
11443 when N_Type_Conversion =>
11444 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
11445 and then Is_Tagged_Type (Etype (Expression (N)))
11446 and then Is_Object_Reference (Expression (N));
11448 -- An unchecked type conversion is considered to be an object if
11449 -- the operand is an object (this construction arises only as a
11450 -- result of expansion activities).
11452 when N_Unchecked_Type_Conversion =>
11453 return True;
11455 -- Allow string literals to act as objects as long as they appear
11456 -- in internally-generated renamings. The expansion of iterators
11457 -- may generate such renamings when the range involves a string
11458 -- literal.
11460 when N_String_Literal =>
11461 return Is_Internally_Generated_Renaming (Parent (N));
11463 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11464 -- This allows disambiguation of function calls and the use
11465 -- of aggregates in more contexts.
11467 when N_Qualified_Expression =>
11468 if Ada_Version < Ada_2012 then
11469 return False;
11470 else
11471 return Is_Object_Reference (Expression (N))
11472 or else Nkind (Expression (N)) = N_Aggregate;
11473 end if;
11475 when others =>
11476 return False;
11477 end case;
11478 end if;
11479 end Is_Object_Reference;
11481 -----------------------------------
11482 -- Is_OK_Variable_For_Out_Formal --
11483 -----------------------------------
11485 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
11486 begin
11487 Note_Possible_Modification (AV, Sure => True);
11489 -- We must reject parenthesized variable names. Comes_From_Source is
11490 -- checked because there are currently cases where the compiler violates
11491 -- this rule (e.g. passing a task object to its controlled Initialize
11492 -- routine). This should be properly documented in sinfo???
11494 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
11495 return False;
11497 -- A variable is always allowed
11499 elsif Is_Variable (AV) then
11500 return True;
11502 -- Generalized indexing operations are rewritten as explicit
11503 -- dereferences, and it is only during resolution that we can
11504 -- check whether the context requires an access_to_variable type.
11506 elsif Nkind (AV) = N_Explicit_Dereference
11507 and then Ada_Version >= Ada_2012
11508 and then Nkind (Original_Node (AV)) = N_Indexed_Component
11509 and then Present (Etype (Original_Node (AV)))
11510 and then Has_Implicit_Dereference (Etype (Original_Node (AV)))
11511 then
11512 return not Is_Access_Constant (Etype (Prefix (AV)));
11514 -- Unchecked conversions are allowed only if they come from the
11515 -- generated code, which sometimes uses unchecked conversions for out
11516 -- parameters in cases where code generation is unaffected. We tell
11517 -- source unchecked conversions by seeing if they are rewrites of
11518 -- an original Unchecked_Conversion function call, or of an explicit
11519 -- conversion of a function call or an aggregate (as may happen in the
11520 -- expansion of a packed array aggregate).
11522 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
11523 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
11524 return False;
11526 elsif Comes_From_Source (AV)
11527 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
11528 then
11529 return False;
11531 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
11532 return Is_OK_Variable_For_Out_Formal (Expression (AV));
11534 else
11535 return True;
11536 end if;
11538 -- Normal type conversions are allowed if argument is a variable
11540 elsif Nkind (AV) = N_Type_Conversion then
11541 if Is_Variable (Expression (AV))
11542 and then Paren_Count (Expression (AV)) = 0
11543 then
11544 Note_Possible_Modification (Expression (AV), Sure => True);
11545 return True;
11547 -- We also allow a non-parenthesized expression that raises
11548 -- constraint error if it rewrites what used to be a variable
11550 elsif Raises_Constraint_Error (Expression (AV))
11551 and then Paren_Count (Expression (AV)) = 0
11552 and then Is_Variable (Original_Node (Expression (AV)))
11553 then
11554 return True;
11556 -- Type conversion of something other than a variable
11558 else
11559 return False;
11560 end if;
11562 -- If this node is rewritten, then test the original form, if that is
11563 -- OK, then we consider the rewritten node OK (for example, if the
11564 -- original node is a conversion, then Is_Variable will not be true
11565 -- but we still want to allow the conversion if it converts a variable).
11567 elsif Original_Node (AV) /= AV then
11569 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11570 -- Reference function.
11572 if Ada_Version >= Ada_2012
11573 and then Nkind (Original_Node (AV)) = N_Function_Call
11574 and then
11575 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
11576 then
11577 return True;
11579 else
11580 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
11581 end if;
11583 -- All other non-variables are rejected
11585 else
11586 return False;
11587 end if;
11588 end Is_OK_Variable_For_Out_Formal;
11590 -----------------------------------
11591 -- Is_Partially_Initialized_Type --
11592 -----------------------------------
11594 function Is_Partially_Initialized_Type
11595 (Typ : Entity_Id;
11596 Include_Implicit : Boolean := True) return Boolean
11598 begin
11599 if Is_Scalar_Type (Typ) then
11600 return False;
11602 elsif Is_Access_Type (Typ) then
11603 return Include_Implicit;
11605 elsif Is_Array_Type (Typ) then
11607 -- If component type is partially initialized, so is array type
11609 if Is_Partially_Initialized_Type
11610 (Component_Type (Typ), Include_Implicit)
11611 then
11612 return True;
11614 -- Otherwise we are only partially initialized if we are fully
11615 -- initialized (this is the empty array case, no point in us
11616 -- duplicating that code here).
11618 else
11619 return Is_Fully_Initialized_Type (Typ);
11620 end if;
11622 elsif Is_Record_Type (Typ) then
11624 -- A discriminated type is always partially initialized if in
11625 -- all mode
11627 if Has_Discriminants (Typ) and then Include_Implicit then
11628 return True;
11630 -- A tagged type is always partially initialized
11632 elsif Is_Tagged_Type (Typ) then
11633 return True;
11635 -- Case of non-discriminated record
11637 else
11638 declare
11639 Ent : Entity_Id;
11641 Component_Present : Boolean := False;
11642 -- Set True if at least one component is present. If no
11643 -- components are present, then record type is fully
11644 -- initialized (another odd case, like the null array).
11646 begin
11647 -- Loop through components
11649 Ent := First_Entity (Typ);
11650 while Present (Ent) loop
11651 if Ekind (Ent) = E_Component then
11652 Component_Present := True;
11654 -- If a component has an initialization expression then
11655 -- the enclosing record type is partially initialized
11657 if Present (Parent (Ent))
11658 and then Present (Expression (Parent (Ent)))
11659 then
11660 return True;
11662 -- If a component is of a type which is itself partially
11663 -- initialized, then the enclosing record type is also.
11665 elsif Is_Partially_Initialized_Type
11666 (Etype (Ent), Include_Implicit)
11667 then
11668 return True;
11669 end if;
11670 end if;
11672 Next_Entity (Ent);
11673 end loop;
11675 -- No initialized components found. If we found any components
11676 -- they were all uninitialized so the result is false.
11678 if Component_Present then
11679 return False;
11681 -- But if we found no components, then all the components are
11682 -- initialized so we consider the type to be initialized.
11684 else
11685 return True;
11686 end if;
11687 end;
11688 end if;
11690 -- Concurrent types are always fully initialized
11692 elsif Is_Concurrent_Type (Typ) then
11693 return True;
11695 -- For a private type, go to underlying type. If there is no underlying
11696 -- type then just assume this partially initialized. Not clear if this
11697 -- can happen in a non-error case, but no harm in testing for this.
11699 elsif Is_Private_Type (Typ) then
11700 declare
11701 U : constant Entity_Id := Underlying_Type (Typ);
11702 begin
11703 if No (U) then
11704 return True;
11705 else
11706 return Is_Partially_Initialized_Type (U, Include_Implicit);
11707 end if;
11708 end;
11710 -- For any other type (are there any?) assume partially initialized
11712 else
11713 return True;
11714 end if;
11715 end Is_Partially_Initialized_Type;
11717 ------------------------------------
11718 -- Is_Potentially_Persistent_Type --
11719 ------------------------------------
11721 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
11722 Comp : Entity_Id;
11723 Indx : Node_Id;
11725 begin
11726 -- For private type, test corresponding full type
11728 if Is_Private_Type (T) then
11729 return Is_Potentially_Persistent_Type (Full_View (T));
11731 -- Scalar types are potentially persistent
11733 elsif Is_Scalar_Type (T) then
11734 return True;
11736 -- Record type is potentially persistent if not tagged and the types of
11737 -- all it components are potentially persistent, and no component has
11738 -- an initialization expression.
11740 elsif Is_Record_Type (T)
11741 and then not Is_Tagged_Type (T)
11742 and then not Is_Partially_Initialized_Type (T)
11743 then
11744 Comp := First_Component (T);
11745 while Present (Comp) loop
11746 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
11747 return False;
11748 else
11749 Next_Entity (Comp);
11750 end if;
11751 end loop;
11753 return True;
11755 -- Array type is potentially persistent if its component type is
11756 -- potentially persistent and if all its constraints are static.
11758 elsif Is_Array_Type (T) then
11759 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
11760 return False;
11761 end if;
11763 Indx := First_Index (T);
11764 while Present (Indx) loop
11765 if not Is_OK_Static_Subtype (Etype (Indx)) then
11766 return False;
11767 else
11768 Next_Index (Indx);
11769 end if;
11770 end loop;
11772 return True;
11774 -- All other types are not potentially persistent
11776 else
11777 return False;
11778 end if;
11779 end Is_Potentially_Persistent_Type;
11781 --------------------------------
11782 -- Is_Potentially_Unevaluated --
11783 --------------------------------
11785 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
11786 Par : Node_Id;
11787 Expr : Node_Id;
11789 begin
11790 Expr := N;
11791 Par := Parent (N);
11793 -- A postcondition whose expression is a short-circuit is broken down
11794 -- into individual aspects for better exception reporting. The original
11795 -- short-circuit expression is rewritten as the second operand, and an
11796 -- occurrence of 'Old in that operand is potentially unevaluated.
11797 -- See Sem_ch13.adb for details of this transformation.
11799 if Nkind (Original_Node (Par)) = N_And_Then then
11800 return True;
11801 end if;
11803 while not Nkind_In (Par, N_If_Expression,
11804 N_Case_Expression,
11805 N_And_Then,
11806 N_Or_Else,
11807 N_In,
11808 N_Not_In)
11809 loop
11810 Expr := Par;
11811 Par := Parent (Par);
11813 -- If the context is not an expression, or if is the result of
11814 -- expansion of an enclosing construct (such as another attribute)
11815 -- the predicate does not apply.
11817 if Nkind (Par) not in N_Subexpr
11818 or else not Comes_From_Source (Par)
11819 then
11820 return False;
11821 end if;
11822 end loop;
11824 if Nkind (Par) = N_If_Expression then
11825 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
11827 elsif Nkind (Par) = N_Case_Expression then
11828 return Expr /= Expression (Par);
11830 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
11831 return Expr = Right_Opnd (Par);
11833 elsif Nkind_In (Par, N_In, N_Not_In) then
11834 return Expr /= Left_Opnd (Par);
11836 else
11837 return False;
11838 end if;
11839 end Is_Potentially_Unevaluated;
11841 ---------------------------------
11842 -- Is_Protected_Self_Reference --
11843 ---------------------------------
11845 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
11847 function In_Access_Definition (N : Node_Id) return Boolean;
11848 -- Returns true if N belongs to an access definition
11850 --------------------------
11851 -- In_Access_Definition --
11852 --------------------------
11854 function In_Access_Definition (N : Node_Id) return Boolean is
11855 P : Node_Id;
11857 begin
11858 P := Parent (N);
11859 while Present (P) loop
11860 if Nkind (P) = N_Access_Definition then
11861 return True;
11862 end if;
11864 P := Parent (P);
11865 end loop;
11867 return False;
11868 end In_Access_Definition;
11870 -- Start of processing for Is_Protected_Self_Reference
11872 begin
11873 -- Verify that prefix is analyzed and has the proper form. Note that
11874 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
11875 -- which also produce the address of an entity, do not analyze their
11876 -- prefix because they denote entities that are not necessarily visible.
11877 -- Neither of them can apply to a protected type.
11879 return Ada_Version >= Ada_2005
11880 and then Is_Entity_Name (N)
11881 and then Present (Entity (N))
11882 and then Is_Protected_Type (Entity (N))
11883 and then In_Open_Scopes (Entity (N))
11884 and then not In_Access_Definition (N);
11885 end Is_Protected_Self_Reference;
11887 -----------------------------
11888 -- Is_RCI_Pkg_Spec_Or_Body --
11889 -----------------------------
11891 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
11893 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
11894 -- Return True if the unit of Cunit is an RCI package declaration
11896 ---------------------------
11897 -- Is_RCI_Pkg_Decl_Cunit --
11898 ---------------------------
11900 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
11901 The_Unit : constant Node_Id := Unit (Cunit);
11903 begin
11904 if Nkind (The_Unit) /= N_Package_Declaration then
11905 return False;
11906 end if;
11908 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
11909 end Is_RCI_Pkg_Decl_Cunit;
11911 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
11913 begin
11914 return Is_RCI_Pkg_Decl_Cunit (Cunit)
11915 or else
11916 (Nkind (Unit (Cunit)) = N_Package_Body
11917 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
11918 end Is_RCI_Pkg_Spec_Or_Body;
11920 -----------------------------------------
11921 -- Is_Remote_Access_To_Class_Wide_Type --
11922 -----------------------------------------
11924 function Is_Remote_Access_To_Class_Wide_Type
11925 (E : Entity_Id) return Boolean
11927 begin
11928 -- A remote access to class-wide type is a general access to object type
11929 -- declared in the visible part of a Remote_Types or Remote_Call_
11930 -- Interface unit.
11932 return Ekind (E) = E_General_Access_Type
11933 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
11934 end Is_Remote_Access_To_Class_Wide_Type;
11936 -----------------------------------------
11937 -- Is_Remote_Access_To_Subprogram_Type --
11938 -----------------------------------------
11940 function Is_Remote_Access_To_Subprogram_Type
11941 (E : Entity_Id) return Boolean
11943 begin
11944 return (Ekind (E) = E_Access_Subprogram_Type
11945 or else (Ekind (E) = E_Record_Type
11946 and then Present (Corresponding_Remote_Type (E))))
11947 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
11948 end Is_Remote_Access_To_Subprogram_Type;
11950 --------------------
11951 -- Is_Remote_Call --
11952 --------------------
11954 function Is_Remote_Call (N : Node_Id) return Boolean is
11955 begin
11956 if Nkind (N) not in N_Subprogram_Call then
11958 -- An entry call cannot be remote
11960 return False;
11962 elsif Nkind (Name (N)) in N_Has_Entity
11963 and then Is_Remote_Call_Interface (Entity (Name (N)))
11964 then
11965 -- A subprogram declared in the spec of a RCI package is remote
11967 return True;
11969 elsif Nkind (Name (N)) = N_Explicit_Dereference
11970 and then Is_Remote_Access_To_Subprogram_Type
11971 (Etype (Prefix (Name (N))))
11972 then
11973 -- The dereference of a RAS is a remote call
11975 return True;
11977 elsif Present (Controlling_Argument (N))
11978 and then Is_Remote_Access_To_Class_Wide_Type
11979 (Etype (Controlling_Argument (N)))
11980 then
11981 -- Any primitive operation call with a controlling argument of
11982 -- a RACW type is a remote call.
11984 return True;
11985 end if;
11987 -- All other calls are local calls
11989 return False;
11990 end Is_Remote_Call;
11992 ----------------------
11993 -- Is_Renamed_Entry --
11994 ----------------------
11996 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
11997 Orig_Node : Node_Id := Empty;
11998 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
12000 function Is_Entry (Nam : Node_Id) return Boolean;
12001 -- Determine whether Nam is an entry. Traverse selectors if there are
12002 -- nested selected components.
12004 --------------
12005 -- Is_Entry --
12006 --------------
12008 function Is_Entry (Nam : Node_Id) return Boolean is
12009 begin
12010 if Nkind (Nam) = N_Selected_Component then
12011 return Is_Entry (Selector_Name (Nam));
12012 end if;
12014 return Ekind (Entity (Nam)) = E_Entry;
12015 end Is_Entry;
12017 -- Start of processing for Is_Renamed_Entry
12019 begin
12020 if Present (Alias (Proc_Nam)) then
12021 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
12022 end if;
12024 -- Look for a rewritten subprogram renaming declaration
12026 if Nkind (Subp_Decl) = N_Subprogram_Declaration
12027 and then Present (Original_Node (Subp_Decl))
12028 then
12029 Orig_Node := Original_Node (Subp_Decl);
12030 end if;
12032 -- The rewritten subprogram is actually an entry
12034 if Present (Orig_Node)
12035 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
12036 and then Is_Entry (Name (Orig_Node))
12037 then
12038 return True;
12039 end if;
12041 return False;
12042 end Is_Renamed_Entry;
12044 ----------------------------
12045 -- Is_Reversible_Iterator --
12046 ----------------------------
12048 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
12049 Ifaces_List : Elist_Id;
12050 Iface_Elmt : Elmt_Id;
12051 Iface : Entity_Id;
12053 begin
12054 if Is_Class_Wide_Type (Typ)
12055 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
12056 and then Is_Predefined_File_Name
12057 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
12058 then
12059 return True;
12061 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
12062 return False;
12064 else
12065 Collect_Interfaces (Typ, Ifaces_List);
12067 Iface_Elmt := First_Elmt (Ifaces_List);
12068 while Present (Iface_Elmt) loop
12069 Iface := Node (Iface_Elmt);
12070 if Chars (Iface) = Name_Reversible_Iterator
12071 and then
12072 Is_Predefined_File_Name
12073 (Unit_File_Name (Get_Source_Unit (Iface)))
12074 then
12075 return True;
12076 end if;
12078 Next_Elmt (Iface_Elmt);
12079 end loop;
12080 end if;
12082 return False;
12083 end Is_Reversible_Iterator;
12085 ----------------------
12086 -- Is_Selector_Name --
12087 ----------------------
12089 function Is_Selector_Name (N : Node_Id) return Boolean is
12090 begin
12091 if not Is_List_Member (N) then
12092 declare
12093 P : constant Node_Id := Parent (N);
12094 begin
12095 return Nkind_In (P, N_Expanded_Name,
12096 N_Generic_Association,
12097 N_Parameter_Association,
12098 N_Selected_Component)
12099 and then Selector_Name (P) = N;
12100 end;
12102 else
12103 declare
12104 L : constant List_Id := List_Containing (N);
12105 P : constant Node_Id := Parent (L);
12106 begin
12107 return (Nkind (P) = N_Discriminant_Association
12108 and then Selector_Names (P) = L)
12109 or else
12110 (Nkind (P) = N_Component_Association
12111 and then Choices (P) = L);
12112 end;
12113 end if;
12114 end Is_Selector_Name;
12116 -------------------------------------
12117 -- Is_SPARK_05_Initialization_Expr --
12118 -------------------------------------
12120 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
12121 Is_Ok : Boolean;
12122 Expr : Node_Id;
12123 Comp_Assn : Node_Id;
12124 Orig_N : constant Node_Id := Original_Node (N);
12126 begin
12127 Is_Ok := True;
12129 if not Comes_From_Source (Orig_N) then
12130 goto Done;
12131 end if;
12133 pragma Assert (Nkind (Orig_N) in N_Subexpr);
12135 case Nkind (Orig_N) is
12136 when N_Character_Literal |
12137 N_Integer_Literal |
12138 N_Real_Literal |
12139 N_String_Literal =>
12140 null;
12142 when N_Identifier |
12143 N_Expanded_Name =>
12144 if Is_Entity_Name (Orig_N)
12145 and then Present (Entity (Orig_N)) -- needed in some cases
12146 then
12147 case Ekind (Entity (Orig_N)) is
12148 when E_Constant |
12149 E_Enumeration_Literal |
12150 E_Named_Integer |
12151 E_Named_Real =>
12152 null;
12153 when others =>
12154 if Is_Type (Entity (Orig_N)) then
12155 null;
12156 else
12157 Is_Ok := False;
12158 end if;
12159 end case;
12160 end if;
12162 when N_Qualified_Expression |
12163 N_Type_Conversion =>
12164 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
12166 when N_Unary_Op =>
12167 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12169 when N_Binary_Op |
12170 N_Short_Circuit |
12171 N_Membership_Test =>
12172 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
12173 and then
12174 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12176 when N_Aggregate |
12177 N_Extension_Aggregate =>
12178 if Nkind (Orig_N) = N_Extension_Aggregate then
12179 Is_Ok :=
12180 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
12181 end if;
12183 Expr := First (Expressions (Orig_N));
12184 while Present (Expr) loop
12185 if not Is_SPARK_05_Initialization_Expr (Expr) then
12186 Is_Ok := False;
12187 goto Done;
12188 end if;
12190 Next (Expr);
12191 end loop;
12193 Comp_Assn := First (Component_Associations (Orig_N));
12194 while Present (Comp_Assn) loop
12195 Expr := Expression (Comp_Assn);
12197 -- Note: test for Present here needed for box assocation
12199 if Present (Expr)
12200 and then not Is_SPARK_05_Initialization_Expr (Expr)
12201 then
12202 Is_Ok := False;
12203 goto Done;
12204 end if;
12206 Next (Comp_Assn);
12207 end loop;
12209 when N_Attribute_Reference =>
12210 if Nkind (Prefix (Orig_N)) in N_Subexpr then
12211 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
12212 end if;
12214 Expr := First (Expressions (Orig_N));
12215 while Present (Expr) loop
12216 if not Is_SPARK_05_Initialization_Expr (Expr) then
12217 Is_Ok := False;
12218 goto Done;
12219 end if;
12221 Next (Expr);
12222 end loop;
12224 -- Selected components might be expanded named not yet resolved, so
12225 -- default on the safe side. (Eg on sparklex.ads)
12227 when N_Selected_Component =>
12228 null;
12230 when others =>
12231 Is_Ok := False;
12232 end case;
12234 <<Done>>
12235 return Is_Ok;
12236 end Is_SPARK_05_Initialization_Expr;
12238 ----------------------------------
12239 -- Is_SPARK_05_Object_Reference --
12240 ----------------------------------
12242 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
12243 begin
12244 if Is_Entity_Name (N) then
12245 return Present (Entity (N))
12246 and then
12247 (Ekind_In (Entity (N), E_Constant, E_Variable)
12248 or else Ekind (Entity (N)) in Formal_Kind);
12250 else
12251 case Nkind (N) is
12252 when N_Selected_Component =>
12253 return Is_SPARK_05_Object_Reference (Prefix (N));
12255 when others =>
12256 return False;
12257 end case;
12258 end if;
12259 end Is_SPARK_05_Object_Reference;
12261 -----------------------------
12262 -- Is_Specific_Tagged_Type --
12263 -----------------------------
12265 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
12266 Full_Typ : Entity_Id;
12268 begin
12269 -- Handle private types
12271 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
12272 Full_Typ := Full_View (Typ);
12273 else
12274 Full_Typ := Typ;
12275 end if;
12277 -- A specific tagged type is a non-class-wide tagged type
12279 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
12280 end Is_Specific_Tagged_Type;
12282 ------------------
12283 -- Is_Statement --
12284 ------------------
12286 function Is_Statement (N : Node_Id) return Boolean is
12287 begin
12288 return
12289 Nkind (N) in N_Statement_Other_Than_Procedure_Call
12290 or else Nkind (N) = N_Procedure_Call_Statement;
12291 end Is_Statement;
12293 --------------------------------------------------
12294 -- Is_Subprogram_Stub_Without_Prior_Declaration --
12295 --------------------------------------------------
12297 function Is_Subprogram_Stub_Without_Prior_Declaration
12298 (N : Node_Id) return Boolean
12300 begin
12301 -- A subprogram stub without prior declaration serves as declaration for
12302 -- the actual subprogram body. As such, it has an attached defining
12303 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
12305 return Nkind (N) = N_Subprogram_Body_Stub
12306 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
12307 end Is_Subprogram_Stub_Without_Prior_Declaration;
12309 ---------------------------------
12310 -- Is_Synchronized_Tagged_Type --
12311 ---------------------------------
12313 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
12314 Kind : constant Entity_Kind := Ekind (Base_Type (E));
12316 begin
12317 -- A task or protected type derived from an interface is a tagged type.
12318 -- Such a tagged type is called a synchronized tagged type, as are
12319 -- synchronized interfaces and private extensions whose declaration
12320 -- includes the reserved word synchronized.
12322 return (Is_Tagged_Type (E)
12323 and then (Kind = E_Task_Type
12324 or else
12325 Kind = E_Protected_Type))
12326 or else
12327 (Is_Interface (E)
12328 and then Is_Synchronized_Interface (E))
12329 or else
12330 (Ekind (E) = E_Record_Type_With_Private
12331 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
12332 and then (Synchronized_Present (Parent (E))
12333 or else Is_Synchronized_Interface (Etype (E))));
12334 end Is_Synchronized_Tagged_Type;
12336 -----------------
12337 -- Is_Transfer --
12338 -----------------
12340 function Is_Transfer (N : Node_Id) return Boolean is
12341 Kind : constant Node_Kind := Nkind (N);
12343 begin
12344 if Kind = N_Simple_Return_Statement
12345 or else
12346 Kind = N_Extended_Return_Statement
12347 or else
12348 Kind = N_Goto_Statement
12349 or else
12350 Kind = N_Raise_Statement
12351 or else
12352 Kind = N_Requeue_Statement
12353 then
12354 return True;
12356 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
12357 and then No (Condition (N))
12358 then
12359 return True;
12361 elsif Kind = N_Procedure_Call_Statement
12362 and then Is_Entity_Name (Name (N))
12363 and then Present (Entity (Name (N)))
12364 and then No_Return (Entity (Name (N)))
12365 then
12366 return True;
12368 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
12369 return True;
12371 else
12372 return False;
12373 end if;
12374 end Is_Transfer;
12376 -------------
12377 -- Is_True --
12378 -------------
12380 function Is_True (U : Uint) return Boolean is
12381 begin
12382 return (U /= 0);
12383 end Is_True;
12385 --------------------------------------
12386 -- Is_Unchecked_Conversion_Instance --
12387 --------------------------------------
12389 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
12390 Gen_Par : Entity_Id;
12392 begin
12393 -- Look for a function whose generic parent is the predefined intrinsic
12394 -- function Unchecked_Conversion.
12396 if Ekind (Id) = E_Function then
12397 Gen_Par := Generic_Parent (Parent (Id));
12399 return
12400 Present (Gen_Par)
12401 and then Chars (Gen_Par) = Name_Unchecked_Conversion
12402 and then Is_Intrinsic_Subprogram (Gen_Par)
12403 and then Is_Predefined_File_Name
12404 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
12405 end if;
12407 return False;
12408 end Is_Unchecked_Conversion_Instance;
12410 -------------------------------
12411 -- Is_Universal_Numeric_Type --
12412 -------------------------------
12414 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
12415 begin
12416 return T = Universal_Integer or else T = Universal_Real;
12417 end Is_Universal_Numeric_Type;
12419 -------------------
12420 -- Is_Value_Type --
12421 -------------------
12423 function Is_Value_Type (T : Entity_Id) return Boolean is
12424 begin
12425 return VM_Target = CLI_Target
12426 and then Nkind (T) in N_Has_Chars
12427 and then Chars (T) /= No_Name
12428 and then Get_Name_String (Chars (T)) = "valuetype";
12429 end Is_Value_Type;
12431 ----------------------------
12432 -- Is_Variable_Size_Array --
12433 ----------------------------
12435 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
12436 Idx : Node_Id;
12438 begin
12439 pragma Assert (Is_Array_Type (E));
12441 -- Check if some index is initialized with a non-constant value
12443 Idx := First_Index (E);
12444 while Present (Idx) loop
12445 if Nkind (Idx) = N_Range then
12446 if not Is_Constant_Bound (Low_Bound (Idx))
12447 or else not Is_Constant_Bound (High_Bound (Idx))
12448 then
12449 return True;
12450 end if;
12451 end if;
12453 Idx := Next_Index (Idx);
12454 end loop;
12456 return False;
12457 end Is_Variable_Size_Array;
12459 -----------------------------
12460 -- Is_Variable_Size_Record --
12461 -----------------------------
12463 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
12464 Comp : Entity_Id;
12465 Comp_Typ : Entity_Id;
12467 begin
12468 pragma Assert (Is_Record_Type (E));
12470 Comp := First_Entity (E);
12471 while Present (Comp) loop
12472 Comp_Typ := Etype (Comp);
12474 -- Recursive call if the record type has discriminants
12476 if Is_Record_Type (Comp_Typ)
12477 and then Has_Discriminants (Comp_Typ)
12478 and then Is_Variable_Size_Record (Comp_Typ)
12479 then
12480 return True;
12482 elsif Is_Array_Type (Comp_Typ)
12483 and then Is_Variable_Size_Array (Comp_Typ)
12484 then
12485 return True;
12486 end if;
12488 Next_Entity (Comp);
12489 end loop;
12491 return False;
12492 end Is_Variable_Size_Record;
12494 -----------------
12495 -- Is_Variable --
12496 -----------------
12498 function Is_Variable
12499 (N : Node_Id;
12500 Use_Original_Node : Boolean := True) return Boolean
12502 Orig_Node : Node_Id;
12504 function In_Protected_Function (E : Entity_Id) return Boolean;
12505 -- Within a protected function, the private components of the enclosing
12506 -- protected type are constants. A function nested within a (protected)
12507 -- procedure is not itself protected. Within the body of a protected
12508 -- function the current instance of the protected type is a constant.
12510 function Is_Variable_Prefix (P : Node_Id) return Boolean;
12511 -- Prefixes can involve implicit dereferences, in which case we must
12512 -- test for the case of a reference of a constant access type, which can
12513 -- can never be a variable.
12515 ---------------------------
12516 -- In_Protected_Function --
12517 ---------------------------
12519 function In_Protected_Function (E : Entity_Id) return Boolean is
12520 Prot : Entity_Id;
12521 S : Entity_Id;
12523 begin
12524 -- E is the current instance of a type
12526 if Is_Type (E) then
12527 Prot := E;
12529 -- E is an object
12531 else
12532 Prot := Scope (E);
12533 end if;
12535 if not Is_Protected_Type (Prot) then
12536 return False;
12538 else
12539 S := Current_Scope;
12540 while Present (S) and then S /= Prot loop
12541 if Ekind (S) = E_Function and then Scope (S) = Prot then
12542 return True;
12543 end if;
12545 S := Scope (S);
12546 end loop;
12548 return False;
12549 end if;
12550 end In_Protected_Function;
12552 ------------------------
12553 -- Is_Variable_Prefix --
12554 ------------------------
12556 function Is_Variable_Prefix (P : Node_Id) return Boolean is
12557 begin
12558 if Is_Access_Type (Etype (P)) then
12559 return not Is_Access_Constant (Root_Type (Etype (P)));
12561 -- For the case of an indexed component whose prefix has a packed
12562 -- array type, the prefix has been rewritten into a type conversion.
12563 -- Determine variable-ness from the converted expression.
12565 elsif Nkind (P) = N_Type_Conversion
12566 and then not Comes_From_Source (P)
12567 and then Is_Array_Type (Etype (P))
12568 and then Is_Packed (Etype (P))
12569 then
12570 return Is_Variable (Expression (P));
12572 else
12573 return Is_Variable (P);
12574 end if;
12575 end Is_Variable_Prefix;
12577 -- Start of processing for Is_Variable
12579 begin
12580 -- Check if we perform the test on the original node since this may be a
12581 -- test of syntactic categories which must not be disturbed by whatever
12582 -- rewriting might have occurred. For example, an aggregate, which is
12583 -- certainly NOT a variable, could be turned into a variable by
12584 -- expansion.
12586 if Use_Original_Node then
12587 Orig_Node := Original_Node (N);
12588 else
12589 Orig_Node := N;
12590 end if;
12592 -- Definitely OK if Assignment_OK is set. Since this is something that
12593 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12595 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
12596 return True;
12598 -- Normally we go to the original node, but there is one exception where
12599 -- we use the rewritten node, namely when it is an explicit dereference.
12600 -- The generated code may rewrite a prefix which is an access type with
12601 -- an explicit dereference. The dereference is a variable, even though
12602 -- the original node may not be (since it could be a constant of the
12603 -- access type).
12605 -- In Ada 2005 we have a further case to consider: the prefix may be a
12606 -- function call given in prefix notation. The original node appears to
12607 -- be a selected component, but we need to examine the call.
12609 elsif Nkind (N) = N_Explicit_Dereference
12610 and then Nkind (Orig_Node) /= N_Explicit_Dereference
12611 and then Present (Etype (Orig_Node))
12612 and then Is_Access_Type (Etype (Orig_Node))
12613 then
12614 -- Note that if the prefix is an explicit dereference that does not
12615 -- come from source, we must check for a rewritten function call in
12616 -- prefixed notation before other forms of rewriting, to prevent a
12617 -- compiler crash.
12619 return
12620 (Nkind (Orig_Node) = N_Function_Call
12621 and then not Is_Access_Constant (Etype (Prefix (N))))
12622 or else
12623 Is_Variable_Prefix (Original_Node (Prefix (N)));
12625 -- in Ada 2012, the dereference may have been added for a type with
12626 -- a declared implicit dereference aspect. Check that it is not an
12627 -- access to constant.
12629 elsif Nkind (N) = N_Explicit_Dereference
12630 and then Present (Etype (Orig_Node))
12631 and then Ada_Version >= Ada_2012
12632 and then Has_Implicit_Dereference (Etype (Orig_Node))
12633 then
12634 return not Is_Access_Constant (Etype (Prefix (N)));
12636 -- A function call is never a variable
12638 elsif Nkind (N) = N_Function_Call then
12639 return False;
12641 -- All remaining checks use the original node
12643 elsif Is_Entity_Name (Orig_Node)
12644 and then Present (Entity (Orig_Node))
12645 then
12646 declare
12647 E : constant Entity_Id := Entity (Orig_Node);
12648 K : constant Entity_Kind := Ekind (E);
12650 begin
12651 return (K = E_Variable
12652 and then Nkind (Parent (E)) /= N_Exception_Handler)
12653 or else (K = E_Component
12654 and then not In_Protected_Function (E))
12655 or else K = E_Out_Parameter
12656 or else K = E_In_Out_Parameter
12657 or else K = E_Generic_In_Out_Parameter
12659 -- Current instance of type. If this is a protected type, check
12660 -- we are not within the body of one of its protected functions.
12662 or else (Is_Type (E)
12663 and then In_Open_Scopes (E)
12664 and then not In_Protected_Function (E))
12666 or else (Is_Incomplete_Or_Private_Type (E)
12667 and then In_Open_Scopes (Full_View (E)));
12668 end;
12670 else
12671 case Nkind (Orig_Node) is
12672 when N_Indexed_Component | N_Slice =>
12673 return Is_Variable_Prefix (Prefix (Orig_Node));
12675 when N_Selected_Component =>
12676 return (Is_Variable (Selector_Name (Orig_Node))
12677 and then Is_Variable_Prefix (Prefix (Orig_Node)))
12678 or else
12679 (Nkind (N) = N_Expanded_Name
12680 and then Scope (Entity (N)) = Entity (Prefix (N)));
12682 -- For an explicit dereference, the type of the prefix cannot
12683 -- be an access to constant or an access to subprogram.
12685 when N_Explicit_Dereference =>
12686 declare
12687 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
12688 begin
12689 return Is_Access_Type (Typ)
12690 and then not Is_Access_Constant (Root_Type (Typ))
12691 and then Ekind (Typ) /= E_Access_Subprogram_Type;
12692 end;
12694 -- The type conversion is the case where we do not deal with the
12695 -- context dependent special case of an actual parameter. Thus
12696 -- the type conversion is only considered a variable for the
12697 -- purposes of this routine if the target type is tagged. However,
12698 -- a type conversion is considered to be a variable if it does not
12699 -- come from source (this deals for example with the conversions
12700 -- of expressions to their actual subtypes).
12702 when N_Type_Conversion =>
12703 return Is_Variable (Expression (Orig_Node))
12704 and then
12705 (not Comes_From_Source (Orig_Node)
12706 or else
12707 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
12708 and then
12709 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
12711 -- GNAT allows an unchecked type conversion as a variable. This
12712 -- only affects the generation of internal expanded code, since
12713 -- calls to instantiations of Unchecked_Conversion are never
12714 -- considered variables (since they are function calls).
12716 when N_Unchecked_Type_Conversion =>
12717 return Is_Variable (Expression (Orig_Node));
12719 when others =>
12720 return False;
12721 end case;
12722 end if;
12723 end Is_Variable;
12725 ---------------------------
12726 -- Is_Visibly_Controlled --
12727 ---------------------------
12729 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
12730 Root : constant Entity_Id := Root_Type (T);
12731 begin
12732 return Chars (Scope (Root)) = Name_Finalization
12733 and then Chars (Scope (Scope (Root))) = Name_Ada
12734 and then Scope (Scope (Scope (Root))) = Standard_Standard;
12735 end Is_Visibly_Controlled;
12737 ------------------------
12738 -- Is_Volatile_Object --
12739 ------------------------
12741 function Is_Volatile_Object (N : Node_Id) return Boolean is
12743 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
12744 -- If prefix is an implicit dereference, examine designated type
12746 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
12747 -- Determines if given object has volatile components
12749 ------------------------
12750 -- Is_Volatile_Prefix --
12751 ------------------------
12753 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
12754 Typ : constant Entity_Id := Etype (N);
12756 begin
12757 if Is_Access_Type (Typ) then
12758 declare
12759 Dtyp : constant Entity_Id := Designated_Type (Typ);
12761 begin
12762 return Is_Volatile (Dtyp)
12763 or else Has_Volatile_Components (Dtyp);
12764 end;
12766 else
12767 return Object_Has_Volatile_Components (N);
12768 end if;
12769 end Is_Volatile_Prefix;
12771 ------------------------------------
12772 -- Object_Has_Volatile_Components --
12773 ------------------------------------
12775 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
12776 Typ : constant Entity_Id := Etype (N);
12778 begin
12779 if Is_Volatile (Typ)
12780 or else Has_Volatile_Components (Typ)
12781 then
12782 return True;
12784 elsif Is_Entity_Name (N)
12785 and then (Has_Volatile_Components (Entity (N))
12786 or else Is_Volatile (Entity (N)))
12787 then
12788 return True;
12790 elsif Nkind (N) = N_Indexed_Component
12791 or else Nkind (N) = N_Selected_Component
12792 then
12793 return Is_Volatile_Prefix (Prefix (N));
12795 else
12796 return False;
12797 end if;
12798 end Object_Has_Volatile_Components;
12800 -- Start of processing for Is_Volatile_Object
12802 begin
12803 if Nkind (N) = N_Defining_Identifier then
12804 return Is_Volatile (N) or else Is_Volatile (Etype (N));
12806 elsif Nkind (N) = N_Expanded_Name then
12807 return Is_Volatile_Object (Entity (N));
12809 elsif Is_Volatile (Etype (N))
12810 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
12811 then
12812 return True;
12814 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
12815 and then Is_Volatile_Prefix (Prefix (N))
12816 then
12817 return True;
12819 elsif Nkind (N) = N_Selected_Component
12820 and then Is_Volatile (Entity (Selector_Name (N)))
12821 then
12822 return True;
12824 else
12825 return False;
12826 end if;
12827 end Is_Volatile_Object;
12829 ---------------------------
12830 -- Itype_Has_Declaration --
12831 ---------------------------
12833 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
12834 begin
12835 pragma Assert (Is_Itype (Id));
12836 return Present (Parent (Id))
12837 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
12838 N_Subtype_Declaration)
12839 and then Defining_Entity (Parent (Id)) = Id;
12840 end Itype_Has_Declaration;
12842 -------------------------
12843 -- Kill_Current_Values --
12844 -------------------------
12846 procedure Kill_Current_Values
12847 (Ent : Entity_Id;
12848 Last_Assignment_Only : Boolean := False)
12850 begin
12851 if Is_Assignable (Ent) then
12852 Set_Last_Assignment (Ent, Empty);
12853 end if;
12855 if Is_Object (Ent) then
12856 if not Last_Assignment_Only then
12857 Kill_Checks (Ent);
12858 Set_Current_Value (Ent, Empty);
12860 if not Can_Never_Be_Null (Ent) then
12861 Set_Is_Known_Non_Null (Ent, False);
12862 end if;
12864 Set_Is_Known_Null (Ent, False);
12866 -- Reset Is_Known_Valid unless type is always valid, or if we have
12867 -- a loop parameter (loop parameters are always valid, since their
12868 -- bounds are defined by the bounds given in the loop header).
12870 if not Is_Known_Valid (Etype (Ent))
12871 and then Ekind (Ent) /= E_Loop_Parameter
12872 then
12873 Set_Is_Known_Valid (Ent, False);
12874 end if;
12875 end if;
12876 end if;
12877 end Kill_Current_Values;
12879 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
12880 S : Entity_Id;
12882 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
12883 -- Clear current value for entity E and all entities chained to E
12885 ------------------------------------------
12886 -- Kill_Current_Values_For_Entity_Chain --
12887 ------------------------------------------
12889 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
12890 Ent : Entity_Id;
12891 begin
12892 Ent := E;
12893 while Present (Ent) loop
12894 Kill_Current_Values (Ent, Last_Assignment_Only);
12895 Next_Entity (Ent);
12896 end loop;
12897 end Kill_Current_Values_For_Entity_Chain;
12899 -- Start of processing for Kill_Current_Values
12901 begin
12902 -- Kill all saved checks, a special case of killing saved values
12904 if not Last_Assignment_Only then
12905 Kill_All_Checks;
12906 end if;
12908 -- Loop through relevant scopes, which includes the current scope and
12909 -- any parent scopes if the current scope is a block or a package.
12911 S := Current_Scope;
12912 Scope_Loop : loop
12914 -- Clear current values of all entities in current scope
12916 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
12918 -- If scope is a package, also clear current values of all private
12919 -- entities in the scope.
12921 if Is_Package_Or_Generic_Package (S)
12922 or else Is_Concurrent_Type (S)
12923 then
12924 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
12925 end if;
12927 -- If this is a not a subprogram, deal with parents
12929 if not Is_Subprogram (S) then
12930 S := Scope (S);
12931 exit Scope_Loop when S = Standard_Standard;
12932 else
12933 exit Scope_Loop;
12934 end if;
12935 end loop Scope_Loop;
12936 end Kill_Current_Values;
12938 --------------------------
12939 -- Kill_Size_Check_Code --
12940 --------------------------
12942 procedure Kill_Size_Check_Code (E : Entity_Id) is
12943 begin
12944 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12945 and then Present (Size_Check_Code (E))
12946 then
12947 Remove (Size_Check_Code (E));
12948 Set_Size_Check_Code (E, Empty);
12949 end if;
12950 end Kill_Size_Check_Code;
12952 --------------------------
12953 -- Known_To_Be_Assigned --
12954 --------------------------
12956 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
12957 P : constant Node_Id := Parent (N);
12959 begin
12960 case Nkind (P) is
12962 -- Test left side of assignment
12964 when N_Assignment_Statement =>
12965 return N = Name (P);
12967 -- Function call arguments are never lvalues
12969 when N_Function_Call =>
12970 return False;
12972 -- Positional parameter for procedure or accept call
12974 when N_Procedure_Call_Statement |
12975 N_Accept_Statement
12977 declare
12978 Proc : Entity_Id;
12979 Form : Entity_Id;
12980 Act : Node_Id;
12982 begin
12983 Proc := Get_Subprogram_Entity (P);
12985 if No (Proc) then
12986 return False;
12987 end if;
12989 -- If we are not a list member, something is strange, so
12990 -- be conservative and return False.
12992 if not Is_List_Member (N) then
12993 return False;
12994 end if;
12996 -- We are going to find the right formal by stepping forward
12997 -- through the formals, as we step backwards in the actuals.
12999 Form := First_Formal (Proc);
13000 Act := N;
13001 loop
13002 -- If no formal, something is weird, so be conservative
13003 -- and return False.
13005 if No (Form) then
13006 return False;
13007 end if;
13009 Prev (Act);
13010 exit when No (Act);
13011 Next_Formal (Form);
13012 end loop;
13014 return Ekind (Form) /= E_In_Parameter;
13015 end;
13017 -- Named parameter for procedure or accept call
13019 when N_Parameter_Association =>
13020 declare
13021 Proc : Entity_Id;
13022 Form : Entity_Id;
13024 begin
13025 Proc := Get_Subprogram_Entity (Parent (P));
13027 if No (Proc) then
13028 return False;
13029 end if;
13031 -- Loop through formals to find the one that matches
13033 Form := First_Formal (Proc);
13034 loop
13035 -- If no matching formal, that's peculiar, some kind of
13036 -- previous error, so return False to be conservative.
13037 -- Actually this also happens in legal code in the case
13038 -- where P is a parameter association for an Extra_Formal???
13040 if No (Form) then
13041 return False;
13042 end if;
13044 -- Else test for match
13046 if Chars (Form) = Chars (Selector_Name (P)) then
13047 return Ekind (Form) /= E_In_Parameter;
13048 end if;
13050 Next_Formal (Form);
13051 end loop;
13052 end;
13054 -- Test for appearing in a conversion that itself appears
13055 -- in an lvalue context, since this should be an lvalue.
13057 when N_Type_Conversion =>
13058 return Known_To_Be_Assigned (P);
13060 -- All other references are definitely not known to be modifications
13062 when others =>
13063 return False;
13065 end case;
13066 end Known_To_Be_Assigned;
13068 ---------------------------
13069 -- Last_Source_Statement --
13070 ---------------------------
13072 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
13073 N : Node_Id;
13075 begin
13076 N := Last (Statements (HSS));
13077 while Present (N) loop
13078 exit when Comes_From_Source (N);
13079 Prev (N);
13080 end loop;
13082 return N;
13083 end Last_Source_Statement;
13085 ----------------------------------
13086 -- Matching_Static_Array_Bounds --
13087 ----------------------------------
13089 function Matching_Static_Array_Bounds
13090 (L_Typ : Node_Id;
13091 R_Typ : Node_Id) return Boolean
13093 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
13094 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
13096 L_Index : Node_Id;
13097 R_Index : Node_Id;
13098 L_Low : Node_Id;
13099 L_High : Node_Id;
13100 L_Len : Uint;
13101 R_Low : Node_Id;
13102 R_High : Node_Id;
13103 R_Len : Uint;
13105 begin
13106 if L_Ndims /= R_Ndims then
13107 return False;
13108 end if;
13110 -- Unconstrained types do not have static bounds
13112 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
13113 return False;
13114 end if;
13116 -- First treat specially the first dimension, as the lower bound and
13117 -- length of string literals are not stored like those of arrays.
13119 if Ekind (L_Typ) = E_String_Literal_Subtype then
13120 L_Low := String_Literal_Low_Bound (L_Typ);
13121 L_Len := String_Literal_Length (L_Typ);
13122 else
13123 L_Index := First_Index (L_Typ);
13124 Get_Index_Bounds (L_Index, L_Low, L_High);
13126 if Is_OK_Static_Expression (L_Low)
13127 and then
13128 Is_OK_Static_Expression (L_High)
13129 then
13130 if Expr_Value (L_High) < Expr_Value (L_Low) then
13131 L_Len := Uint_0;
13132 else
13133 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
13134 end if;
13135 else
13136 return False;
13137 end if;
13138 end if;
13140 if Ekind (R_Typ) = E_String_Literal_Subtype then
13141 R_Low := String_Literal_Low_Bound (R_Typ);
13142 R_Len := String_Literal_Length (R_Typ);
13143 else
13144 R_Index := First_Index (R_Typ);
13145 Get_Index_Bounds (R_Index, R_Low, R_High);
13147 if Is_OK_Static_Expression (R_Low)
13148 and then
13149 Is_OK_Static_Expression (R_High)
13150 then
13151 if Expr_Value (R_High) < Expr_Value (R_Low) then
13152 R_Len := Uint_0;
13153 else
13154 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
13155 end if;
13156 else
13157 return False;
13158 end if;
13159 end if;
13161 if (Is_OK_Static_Expression (L_Low)
13162 and then
13163 Is_OK_Static_Expression (R_Low))
13164 and then Expr_Value (L_Low) = Expr_Value (R_Low)
13165 and then L_Len = R_Len
13166 then
13167 null;
13168 else
13169 return False;
13170 end if;
13172 -- Then treat all other dimensions
13174 for Indx in 2 .. L_Ndims loop
13175 Next (L_Index);
13176 Next (R_Index);
13178 Get_Index_Bounds (L_Index, L_Low, L_High);
13179 Get_Index_Bounds (R_Index, R_Low, R_High);
13181 if (Is_OK_Static_Expression (L_Low) and then
13182 Is_OK_Static_Expression (L_High) and then
13183 Is_OK_Static_Expression (R_Low) and then
13184 Is_OK_Static_Expression (R_High))
13185 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
13186 and then
13187 Expr_Value (L_High) = Expr_Value (R_High))
13188 then
13189 null;
13190 else
13191 return False;
13192 end if;
13193 end loop;
13195 -- If we fall through the loop, all indexes matched
13197 return True;
13198 end Matching_Static_Array_Bounds;
13200 -------------------
13201 -- May_Be_Lvalue --
13202 -------------------
13204 function May_Be_Lvalue (N : Node_Id) return Boolean is
13205 P : constant Node_Id := Parent (N);
13207 begin
13208 case Nkind (P) is
13210 -- Test left side of assignment
13212 when N_Assignment_Statement =>
13213 return N = Name (P);
13215 -- Test prefix of component or attribute. Note that the prefix of an
13216 -- explicit or implicit dereference cannot be an l-value.
13218 when N_Attribute_Reference =>
13219 return N = Prefix (P)
13220 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
13222 -- For an expanded name, the name is an lvalue if the expanded name
13223 -- is an lvalue, but the prefix is never an lvalue, since it is just
13224 -- the scope where the name is found.
13226 when N_Expanded_Name =>
13227 if N = Prefix (P) then
13228 return May_Be_Lvalue (P);
13229 else
13230 return False;
13231 end if;
13233 -- For a selected component A.B, A is certainly an lvalue if A.B is.
13234 -- B is a little interesting, if we have A.B := 3, there is some
13235 -- discussion as to whether B is an lvalue or not, we choose to say
13236 -- it is. Note however that A is not an lvalue if it is of an access
13237 -- type since this is an implicit dereference.
13239 when N_Selected_Component =>
13240 if N = Prefix (P)
13241 and then Present (Etype (N))
13242 and then Is_Access_Type (Etype (N))
13243 then
13244 return False;
13245 else
13246 return May_Be_Lvalue (P);
13247 end if;
13249 -- For an indexed component or slice, the index or slice bounds is
13250 -- never an lvalue. The prefix is an lvalue if the indexed component
13251 -- or slice is an lvalue, except if it is an access type, where we
13252 -- have an implicit dereference.
13254 when N_Indexed_Component | N_Slice =>
13255 if N /= Prefix (P)
13256 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
13257 then
13258 return False;
13259 else
13260 return May_Be_Lvalue (P);
13261 end if;
13263 -- Prefix of a reference is an lvalue if the reference is an lvalue
13265 when N_Reference =>
13266 return May_Be_Lvalue (P);
13268 -- Prefix of explicit dereference is never an lvalue
13270 when N_Explicit_Dereference =>
13271 return False;
13273 -- Positional parameter for subprogram, entry, or accept call.
13274 -- In older versions of Ada function call arguments are never
13275 -- lvalues. In Ada 2012 functions can have in-out parameters.
13277 when N_Subprogram_Call |
13278 N_Entry_Call_Statement |
13279 N_Accept_Statement
13281 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
13282 return False;
13283 end if;
13285 -- The following mechanism is clumsy and fragile. A single flag
13286 -- set in Resolve_Actuals would be preferable ???
13288 declare
13289 Proc : Entity_Id;
13290 Form : Entity_Id;
13291 Act : Node_Id;
13293 begin
13294 Proc := Get_Subprogram_Entity (P);
13296 if No (Proc) then
13297 return True;
13298 end if;
13300 -- If we are not a list member, something is strange, so be
13301 -- conservative and return True.
13303 if not Is_List_Member (N) then
13304 return True;
13305 end if;
13307 -- We are going to find the right formal by stepping forward
13308 -- through the formals, as we step backwards in the actuals.
13310 Form := First_Formal (Proc);
13311 Act := N;
13312 loop
13313 -- If no formal, something is weird, so be conservative and
13314 -- return True.
13316 if No (Form) then
13317 return True;
13318 end if;
13320 Prev (Act);
13321 exit when No (Act);
13322 Next_Formal (Form);
13323 end loop;
13325 return Ekind (Form) /= E_In_Parameter;
13326 end;
13328 -- Named parameter for procedure or accept call
13330 when N_Parameter_Association =>
13331 declare
13332 Proc : Entity_Id;
13333 Form : Entity_Id;
13335 begin
13336 Proc := Get_Subprogram_Entity (Parent (P));
13338 if No (Proc) then
13339 return True;
13340 end if;
13342 -- Loop through formals to find the one that matches
13344 Form := First_Formal (Proc);
13345 loop
13346 -- If no matching formal, that's peculiar, some kind of
13347 -- previous error, so return True to be conservative.
13348 -- Actually happens with legal code for an unresolved call
13349 -- where we may get the wrong homonym???
13351 if No (Form) then
13352 return True;
13353 end if;
13355 -- Else test for match
13357 if Chars (Form) = Chars (Selector_Name (P)) then
13358 return Ekind (Form) /= E_In_Parameter;
13359 end if;
13361 Next_Formal (Form);
13362 end loop;
13363 end;
13365 -- Test for appearing in a conversion that itself appears in an
13366 -- lvalue context, since this should be an lvalue.
13368 when N_Type_Conversion =>
13369 return May_Be_Lvalue (P);
13371 -- Test for appearance in object renaming declaration
13373 when N_Object_Renaming_Declaration =>
13374 return True;
13376 -- All other references are definitely not lvalues
13378 when others =>
13379 return False;
13381 end case;
13382 end May_Be_Lvalue;
13384 -----------------------
13385 -- Mark_Coextensions --
13386 -----------------------
13388 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
13389 Is_Dynamic : Boolean;
13390 -- Indicates whether the context causes nested coextensions to be
13391 -- dynamic or static
13393 function Mark_Allocator (N : Node_Id) return Traverse_Result;
13394 -- Recognize an allocator node and label it as a dynamic coextension
13396 --------------------
13397 -- Mark_Allocator --
13398 --------------------
13400 function Mark_Allocator (N : Node_Id) return Traverse_Result is
13401 begin
13402 if Nkind (N) = N_Allocator then
13403 if Is_Dynamic then
13404 Set_Is_Dynamic_Coextension (N);
13406 -- If the allocator expression is potentially dynamic, it may
13407 -- be expanded out of order and require dynamic allocation
13408 -- anyway, so we treat the coextension itself as dynamic.
13409 -- Potential optimization ???
13411 elsif Nkind (Expression (N)) = N_Qualified_Expression
13412 and then Nkind (Expression (Expression (N))) = N_Op_Concat
13413 then
13414 Set_Is_Dynamic_Coextension (N);
13415 else
13416 Set_Is_Static_Coextension (N);
13417 end if;
13418 end if;
13420 return OK;
13421 end Mark_Allocator;
13423 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
13425 -- Start of processing Mark_Coextensions
13427 begin
13428 case Nkind (Context_Nod) is
13430 -- Comment here ???
13432 when N_Assignment_Statement =>
13433 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
13435 -- An allocator that is a component of a returned aggregate
13436 -- must be dynamic.
13438 when N_Simple_Return_Statement =>
13439 declare
13440 Expr : constant Node_Id := Expression (Context_Nod);
13441 begin
13442 Is_Dynamic :=
13443 Nkind (Expr) = N_Allocator
13444 or else
13445 (Nkind (Expr) = N_Qualified_Expression
13446 and then Nkind (Expression (Expr)) = N_Aggregate);
13447 end;
13449 -- An alloctor within an object declaration in an extended return
13450 -- statement is of necessity dynamic.
13452 when N_Object_Declaration =>
13453 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
13454 or else
13455 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
13457 -- This routine should not be called for constructs which may not
13458 -- contain coextensions.
13460 when others =>
13461 raise Program_Error;
13462 end case;
13464 Mark_Allocators (Root_Nod);
13465 end Mark_Coextensions;
13467 ----------------------
13468 -- Needs_One_Actual --
13469 ----------------------
13471 function Needs_One_Actual (E : Entity_Id) return Boolean is
13472 Formal : Entity_Id;
13474 begin
13475 -- Ada 2005 or later, and formals present
13477 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
13478 Formal := Next_Formal (First_Formal (E));
13479 while Present (Formal) loop
13480 if No (Default_Value (Formal)) then
13481 return False;
13482 end if;
13484 Next_Formal (Formal);
13485 end loop;
13487 return True;
13489 -- Ada 83/95 or no formals
13491 else
13492 return False;
13493 end if;
13494 end Needs_One_Actual;
13496 ------------------------
13497 -- New_Copy_List_Tree --
13498 ------------------------
13500 function New_Copy_List_Tree (List : List_Id) return List_Id is
13501 NL : List_Id;
13502 E : Node_Id;
13504 begin
13505 if List = No_List then
13506 return No_List;
13508 else
13509 NL := New_List;
13510 E := First (List);
13512 while Present (E) loop
13513 Append (New_Copy_Tree (E), NL);
13514 E := Next (E);
13515 end loop;
13517 return NL;
13518 end if;
13519 end New_Copy_List_Tree;
13521 --------------------------------------------------
13522 -- New_Copy_Tree Auxiliary Data and Subprograms --
13523 --------------------------------------------------
13525 use Atree.Unchecked_Access;
13526 use Atree_Private_Part;
13528 -- Our approach here requires a two pass traversal of the tree. The
13529 -- first pass visits all nodes that eventually will be copied looking
13530 -- for defining Itypes. If any defining Itypes are found, then they are
13531 -- copied, and an entry is added to the replacement map. In the second
13532 -- phase, the tree is copied, using the replacement map to replace any
13533 -- Itype references within the copied tree.
13535 -- The following hash tables are used if the Map supplied has more
13536 -- than hash threshold entries to speed up access to the map. If
13537 -- there are fewer entries, then the map is searched sequentially
13538 -- (because setting up a hash table for only a few entries takes
13539 -- more time than it saves.
13541 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
13542 -- Hash function used for hash operations
13544 -------------------
13545 -- New_Copy_Hash --
13546 -------------------
13548 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
13549 begin
13550 return Nat (E) mod (NCT_Header_Num'Last + 1);
13551 end New_Copy_Hash;
13553 ---------------
13554 -- NCT_Assoc --
13555 ---------------
13557 -- The hash table NCT_Assoc associates old entities in the table
13558 -- with their corresponding new entities (i.e. the pairs of entries
13559 -- presented in the original Map argument are Key-Element pairs).
13561 package NCT_Assoc is new Simple_HTable (
13562 Header_Num => NCT_Header_Num,
13563 Element => Entity_Id,
13564 No_Element => Empty,
13565 Key => Entity_Id,
13566 Hash => New_Copy_Hash,
13567 Equal => Types."=");
13569 ---------------------
13570 -- NCT_Itype_Assoc --
13571 ---------------------
13573 -- The hash table NCT_Itype_Assoc contains entries only for those
13574 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13575 -- The key is the associated node, and the element is the new node
13576 -- itself (NOT the associated node for the new node).
13578 package NCT_Itype_Assoc is new Simple_HTable (
13579 Header_Num => NCT_Header_Num,
13580 Element => Entity_Id,
13581 No_Element => Empty,
13582 Key => Entity_Id,
13583 Hash => New_Copy_Hash,
13584 Equal => Types."=");
13586 -------------------
13587 -- New_Copy_Tree --
13588 -------------------
13590 function New_Copy_Tree
13591 (Source : Node_Id;
13592 Map : Elist_Id := No_Elist;
13593 New_Sloc : Source_Ptr := No_Location;
13594 New_Scope : Entity_Id := Empty) return Node_Id
13596 Actual_Map : Elist_Id := Map;
13597 -- This is the actual map for the copy. It is initialized with the
13598 -- given elements, and then enlarged as required for Itypes that are
13599 -- copied during the first phase of the copy operation. The visit
13600 -- procedures add elements to this map as Itypes are encountered.
13601 -- The reason we cannot use Map directly, is that it may well be
13602 -- (and normally is) initialized to No_Elist, and if we have mapped
13603 -- entities, we have to reset it to point to a real Elist.
13605 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
13606 -- Called during second phase to map entities into their corresponding
13607 -- copies using Actual_Map. If the argument is not an entity, or is not
13608 -- in Actual_Map, then it is returned unchanged.
13610 procedure Build_NCT_Hash_Tables;
13611 -- Builds hash tables (number of elements >= threshold value)
13613 function Copy_Elist_With_Replacement
13614 (Old_Elist : Elist_Id) return Elist_Id;
13615 -- Called during second phase to copy element list doing replacements
13617 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
13618 -- Called during the second phase to process a copied Itype. The actual
13619 -- copy happened during the first phase (so that we could make the entry
13620 -- in the mapping), but we still have to deal with the descendents of
13621 -- the copied Itype and copy them where necessary.
13623 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
13624 -- Called during second phase to copy list doing replacements
13626 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
13627 -- Called during second phase to copy node doing replacements
13629 procedure Visit_Elist (E : Elist_Id);
13630 -- Called during first phase to visit all elements of an Elist
13632 procedure Visit_Field (F : Union_Id; N : Node_Id);
13633 -- Visit a single field, recursing to call Visit_Node or Visit_List
13634 -- if the field is a syntactic descendent of the current node (i.e.
13635 -- its parent is Node N).
13637 procedure Visit_Itype (Old_Itype : Entity_Id);
13638 -- Called during first phase to visit subsidiary fields of a defining
13639 -- Itype, and also create a copy and make an entry in the replacement
13640 -- map for the new copy.
13642 procedure Visit_List (L : List_Id);
13643 -- Called during first phase to visit all elements of a List
13645 procedure Visit_Node (N : Node_Or_Entity_Id);
13646 -- Called during first phase to visit a node and all its subtrees
13648 -----------
13649 -- Assoc --
13650 -----------
13652 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
13653 E : Elmt_Id;
13654 Ent : Entity_Id;
13656 begin
13657 if not Has_Extension (N) or else No (Actual_Map) then
13658 return N;
13660 elsif NCT_Hash_Tables_Used then
13661 Ent := NCT_Assoc.Get (Entity_Id (N));
13663 if Present (Ent) then
13664 return Ent;
13665 else
13666 return N;
13667 end if;
13669 -- No hash table used, do serial search
13671 else
13672 E := First_Elmt (Actual_Map);
13673 while Present (E) loop
13674 if Node (E) = N then
13675 return Node (Next_Elmt (E));
13676 else
13677 E := Next_Elmt (Next_Elmt (E));
13678 end if;
13679 end loop;
13680 end if;
13682 return N;
13683 end Assoc;
13685 ---------------------------
13686 -- Build_NCT_Hash_Tables --
13687 ---------------------------
13689 procedure Build_NCT_Hash_Tables is
13690 Elmt : Elmt_Id;
13691 Ent : Entity_Id;
13692 begin
13693 if NCT_Hash_Table_Setup then
13694 NCT_Assoc.Reset;
13695 NCT_Itype_Assoc.Reset;
13696 end if;
13698 Elmt := First_Elmt (Actual_Map);
13699 while Present (Elmt) loop
13700 Ent := Node (Elmt);
13702 -- Get new entity, and associate old and new
13704 Next_Elmt (Elmt);
13705 NCT_Assoc.Set (Ent, Node (Elmt));
13707 if Is_Type (Ent) then
13708 declare
13709 Anode : constant Entity_Id :=
13710 Associated_Node_For_Itype (Ent);
13712 begin
13713 if Present (Anode) then
13715 -- Enter a link between the associated node of the
13716 -- old Itype and the new Itype, for updating later
13717 -- when node is copied.
13719 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
13720 end if;
13721 end;
13722 end if;
13724 Next_Elmt (Elmt);
13725 end loop;
13727 NCT_Hash_Tables_Used := True;
13728 NCT_Hash_Table_Setup := True;
13729 end Build_NCT_Hash_Tables;
13731 ---------------------------------
13732 -- Copy_Elist_With_Replacement --
13733 ---------------------------------
13735 function Copy_Elist_With_Replacement
13736 (Old_Elist : Elist_Id) return Elist_Id
13738 M : Elmt_Id;
13739 New_Elist : Elist_Id;
13741 begin
13742 if No (Old_Elist) then
13743 return No_Elist;
13745 else
13746 New_Elist := New_Elmt_List;
13748 M := First_Elmt (Old_Elist);
13749 while Present (M) loop
13750 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
13751 Next_Elmt (M);
13752 end loop;
13753 end if;
13755 return New_Elist;
13756 end Copy_Elist_With_Replacement;
13758 ---------------------------------
13759 -- Copy_Itype_With_Replacement --
13760 ---------------------------------
13762 -- This routine exactly parallels its phase one analog Visit_Itype,
13764 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
13765 begin
13766 -- Translate Next_Entity, Scope and Etype fields, in case they
13767 -- reference entities that have been mapped into copies.
13769 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
13770 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
13772 if Present (New_Scope) then
13773 Set_Scope (New_Itype, New_Scope);
13774 else
13775 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
13776 end if;
13778 -- Copy referenced fields
13780 if Is_Discrete_Type (New_Itype) then
13781 Set_Scalar_Range (New_Itype,
13782 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
13784 elsif Has_Discriminants (Base_Type (New_Itype)) then
13785 Set_Discriminant_Constraint (New_Itype,
13786 Copy_Elist_With_Replacement
13787 (Discriminant_Constraint (New_Itype)));
13789 elsif Is_Array_Type (New_Itype) then
13790 if Present (First_Index (New_Itype)) then
13791 Set_First_Index (New_Itype,
13792 First (Copy_List_With_Replacement
13793 (List_Containing (First_Index (New_Itype)))));
13794 end if;
13796 if Is_Packed (New_Itype) then
13797 Set_Packed_Array_Impl_Type (New_Itype,
13798 Copy_Node_With_Replacement
13799 (Packed_Array_Impl_Type (New_Itype)));
13800 end if;
13801 end if;
13802 end Copy_Itype_With_Replacement;
13804 --------------------------------
13805 -- Copy_List_With_Replacement --
13806 --------------------------------
13808 function Copy_List_With_Replacement
13809 (Old_List : List_Id) return List_Id
13811 New_List : List_Id;
13812 E : Node_Id;
13814 begin
13815 if Old_List = No_List then
13816 return No_List;
13818 else
13819 New_List := Empty_List;
13821 E := First (Old_List);
13822 while Present (E) loop
13823 Append (Copy_Node_With_Replacement (E), New_List);
13824 Next (E);
13825 end loop;
13827 return New_List;
13828 end if;
13829 end Copy_List_With_Replacement;
13831 --------------------------------
13832 -- Copy_Node_With_Replacement --
13833 --------------------------------
13835 function Copy_Node_With_Replacement
13836 (Old_Node : Node_Id) return Node_Id
13838 New_Node : Node_Id;
13840 procedure Adjust_Named_Associations
13841 (Old_Node : Node_Id;
13842 New_Node : Node_Id);
13843 -- If a call node has named associations, these are chained through
13844 -- the First_Named_Actual, Next_Named_Actual links. These must be
13845 -- propagated separately to the new parameter list, because these
13846 -- are not syntactic fields.
13848 function Copy_Field_With_Replacement
13849 (Field : Union_Id) return Union_Id;
13850 -- Given Field, which is a field of Old_Node, return a copy of it
13851 -- if it is a syntactic field (i.e. its parent is Node), setting
13852 -- the parent of the copy to poit to New_Node. Otherwise returns
13853 -- the field (possibly mapped if it is an entity).
13855 -------------------------------
13856 -- Adjust_Named_Associations --
13857 -------------------------------
13859 procedure Adjust_Named_Associations
13860 (Old_Node : Node_Id;
13861 New_Node : Node_Id)
13863 Old_E : Node_Id;
13864 New_E : Node_Id;
13866 Old_Next : Node_Id;
13867 New_Next : Node_Id;
13869 begin
13870 Old_E := First (Parameter_Associations (Old_Node));
13871 New_E := First (Parameter_Associations (New_Node));
13872 while Present (Old_E) loop
13873 if Nkind (Old_E) = N_Parameter_Association
13874 and then Present (Next_Named_Actual (Old_E))
13875 then
13876 if First_Named_Actual (Old_Node)
13877 = Explicit_Actual_Parameter (Old_E)
13878 then
13879 Set_First_Named_Actual
13880 (New_Node, Explicit_Actual_Parameter (New_E));
13881 end if;
13883 -- Now scan parameter list from the beginning,to locate
13884 -- next named actual, which can be out of order.
13886 Old_Next := First (Parameter_Associations (Old_Node));
13887 New_Next := First (Parameter_Associations (New_Node));
13889 while Nkind (Old_Next) /= N_Parameter_Association
13890 or else Explicit_Actual_Parameter (Old_Next)
13891 /= Next_Named_Actual (Old_E)
13892 loop
13893 Next (Old_Next);
13894 Next (New_Next);
13895 end loop;
13897 Set_Next_Named_Actual
13898 (New_E, Explicit_Actual_Parameter (New_Next));
13899 end if;
13901 Next (Old_E);
13902 Next (New_E);
13903 end loop;
13904 end Adjust_Named_Associations;
13906 ---------------------------------
13907 -- Copy_Field_With_Replacement --
13908 ---------------------------------
13910 function Copy_Field_With_Replacement
13911 (Field : Union_Id) return Union_Id
13913 begin
13914 if Field = Union_Id (Empty) then
13915 return Field;
13917 elsif Field in Node_Range then
13918 declare
13919 Old_N : constant Node_Id := Node_Id (Field);
13920 New_N : Node_Id;
13922 begin
13923 -- If syntactic field, as indicated by the parent pointer
13924 -- being set, then copy the referenced node recursively.
13926 if Parent (Old_N) = Old_Node then
13927 New_N := Copy_Node_With_Replacement (Old_N);
13929 if New_N /= Old_N then
13930 Set_Parent (New_N, New_Node);
13931 end if;
13933 -- For semantic fields, update possible entity reference
13934 -- from the replacement map.
13936 else
13937 New_N := Assoc (Old_N);
13938 end if;
13940 return Union_Id (New_N);
13941 end;
13943 elsif Field in List_Range then
13944 declare
13945 Old_L : constant List_Id := List_Id (Field);
13946 New_L : List_Id;
13948 begin
13949 -- If syntactic field, as indicated by the parent pointer,
13950 -- then recursively copy the entire referenced list.
13952 if Parent (Old_L) = Old_Node then
13953 New_L := Copy_List_With_Replacement (Old_L);
13954 Set_Parent (New_L, New_Node);
13956 -- For semantic list, just returned unchanged
13958 else
13959 New_L := Old_L;
13960 end if;
13962 return Union_Id (New_L);
13963 end;
13965 -- Anything other than a list or a node is returned unchanged
13967 else
13968 return Field;
13969 end if;
13970 end Copy_Field_With_Replacement;
13972 -- Start of processing for Copy_Node_With_Replacement
13974 begin
13975 if Old_Node <= Empty_Or_Error then
13976 return Old_Node;
13978 elsif Has_Extension (Old_Node) then
13979 return Assoc (Old_Node);
13981 else
13982 New_Node := New_Copy (Old_Node);
13984 -- If the node we are copying is the associated node of a
13985 -- previously copied Itype, then adjust the associated node
13986 -- of the copy of that Itype accordingly.
13988 if Present (Actual_Map) then
13989 declare
13990 E : Elmt_Id;
13991 Ent : Entity_Id;
13993 begin
13994 -- Case of hash table used
13996 if NCT_Hash_Tables_Used then
13997 Ent := NCT_Itype_Assoc.Get (Old_Node);
13999 if Present (Ent) then
14000 Set_Associated_Node_For_Itype (Ent, New_Node);
14001 end if;
14003 -- Case of no hash table used
14005 else
14006 E := First_Elmt (Actual_Map);
14007 while Present (E) loop
14008 if Is_Itype (Node (E))
14009 and then
14010 Old_Node = Associated_Node_For_Itype (Node (E))
14011 then
14012 Set_Associated_Node_For_Itype
14013 (Node (Next_Elmt (E)), New_Node);
14014 end if;
14016 E := Next_Elmt (Next_Elmt (E));
14017 end loop;
14018 end if;
14019 end;
14020 end if;
14022 -- Recursively copy descendents
14024 Set_Field1
14025 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
14026 Set_Field2
14027 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
14028 Set_Field3
14029 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
14030 Set_Field4
14031 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
14032 Set_Field5
14033 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
14035 -- Adjust Sloc of new node if necessary
14037 if New_Sloc /= No_Location then
14038 Set_Sloc (New_Node, New_Sloc);
14040 -- If we adjust the Sloc, then we are essentially making
14041 -- a completely new node, so the Comes_From_Source flag
14042 -- should be reset to the proper default value.
14044 Nodes.Table (New_Node).Comes_From_Source :=
14045 Default_Node.Comes_From_Source;
14046 end if;
14048 -- If the node is call and has named associations,
14049 -- set the corresponding links in the copy.
14051 if (Nkind (Old_Node) = N_Function_Call
14052 or else Nkind (Old_Node) = N_Entry_Call_Statement
14053 or else
14054 Nkind (Old_Node) = N_Procedure_Call_Statement)
14055 and then Present (First_Named_Actual (Old_Node))
14056 then
14057 Adjust_Named_Associations (Old_Node, New_Node);
14058 end if;
14060 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
14061 -- The replacement mechanism applies to entities, and is not used
14062 -- here. Eventually we may need a more general graph-copying
14063 -- routine. For now, do a sequential search to find desired node.
14065 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
14066 and then Present (First_Real_Statement (Old_Node))
14067 then
14068 declare
14069 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
14070 N1, N2 : Node_Id;
14072 begin
14073 N1 := First (Statements (Old_Node));
14074 N2 := First (Statements (New_Node));
14076 while N1 /= Old_F loop
14077 Next (N1);
14078 Next (N2);
14079 end loop;
14081 Set_First_Real_Statement (New_Node, N2);
14082 end;
14083 end if;
14084 end if;
14086 -- All done, return copied node
14088 return New_Node;
14089 end Copy_Node_With_Replacement;
14091 -----------------
14092 -- Visit_Elist --
14093 -----------------
14095 procedure Visit_Elist (E : Elist_Id) is
14096 Elmt : Elmt_Id;
14097 begin
14098 if Present (E) then
14099 Elmt := First_Elmt (E);
14101 while Elmt /= No_Elmt loop
14102 Visit_Node (Node (Elmt));
14103 Next_Elmt (Elmt);
14104 end loop;
14105 end if;
14106 end Visit_Elist;
14108 -----------------
14109 -- Visit_Field --
14110 -----------------
14112 procedure Visit_Field (F : Union_Id; N : Node_Id) is
14113 begin
14114 if F = Union_Id (Empty) then
14115 return;
14117 elsif F in Node_Range then
14119 -- Copy node if it is syntactic, i.e. its parent pointer is
14120 -- set to point to the field that referenced it (certain
14121 -- Itypes will also meet this criterion, which is fine, since
14122 -- these are clearly Itypes that do need to be copied, since
14123 -- we are copying their parent.)
14125 if Parent (Node_Id (F)) = N then
14126 Visit_Node (Node_Id (F));
14127 return;
14129 -- Another case, if we are pointing to an Itype, then we want
14130 -- to copy it if its associated node is somewhere in the tree
14131 -- being copied.
14133 -- Note: the exclusion of self-referential copies is just an
14134 -- optimization, since the search of the already copied list
14135 -- would catch it, but it is a common case (Etype pointing
14136 -- to itself for an Itype that is a base type).
14138 elsif Has_Extension (Node_Id (F))
14139 and then Is_Itype (Entity_Id (F))
14140 and then Node_Id (F) /= N
14141 then
14142 declare
14143 P : Node_Id;
14145 begin
14146 P := Associated_Node_For_Itype (Node_Id (F));
14147 while Present (P) loop
14148 if P = Source then
14149 Visit_Node (Node_Id (F));
14150 return;
14151 else
14152 P := Parent (P);
14153 end if;
14154 end loop;
14156 -- An Itype whose parent is not being copied definitely
14157 -- should NOT be copied, since it does not belong in any
14158 -- sense to the copied subtree.
14160 return;
14161 end;
14162 end if;
14164 elsif F in List_Range and then Parent (List_Id (F)) = N then
14165 Visit_List (List_Id (F));
14166 return;
14167 end if;
14168 end Visit_Field;
14170 -----------------
14171 -- Visit_Itype --
14172 -----------------
14174 procedure Visit_Itype (Old_Itype : Entity_Id) is
14175 New_Itype : Entity_Id;
14176 E : Elmt_Id;
14177 Ent : Entity_Id;
14179 begin
14180 -- Itypes that describe the designated type of access to subprograms
14181 -- have the structure of subprogram declarations, with signatures,
14182 -- etc. Either we duplicate the signatures completely, or choose to
14183 -- share such itypes, which is fine because their elaboration will
14184 -- have no side effects.
14186 if Ekind (Old_Itype) = E_Subprogram_Type then
14187 return;
14188 end if;
14190 New_Itype := New_Copy (Old_Itype);
14192 -- The new Itype has all the attributes of the old one, and
14193 -- we just copy the contents of the entity. However, the back-end
14194 -- needs different names for debugging purposes, so we create a
14195 -- new internal name for it in all cases.
14197 Set_Chars (New_Itype, New_Internal_Name ('T'));
14199 -- If our associated node is an entity that has already been copied,
14200 -- then set the associated node of the copy to point to the right
14201 -- copy. If we have copied an Itype that is itself the associated
14202 -- node of some previously copied Itype, then we set the right
14203 -- pointer in the other direction.
14205 if Present (Actual_Map) then
14207 -- Case of hash tables used
14209 if NCT_Hash_Tables_Used then
14211 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
14213 if Present (Ent) then
14214 Set_Associated_Node_For_Itype (New_Itype, Ent);
14215 end if;
14217 Ent := NCT_Itype_Assoc.Get (Old_Itype);
14218 if Present (Ent) then
14219 Set_Associated_Node_For_Itype (Ent, New_Itype);
14221 -- If the hash table has no association for this Itype and
14222 -- its associated node, enter one now.
14224 else
14225 NCT_Itype_Assoc.Set
14226 (Associated_Node_For_Itype (Old_Itype), New_Itype);
14227 end if;
14229 -- Case of hash tables not used
14231 else
14232 E := First_Elmt (Actual_Map);
14233 while Present (E) loop
14234 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
14235 Set_Associated_Node_For_Itype
14236 (New_Itype, Node (Next_Elmt (E)));
14237 end if;
14239 if Is_Type (Node (E))
14240 and then Old_Itype = Associated_Node_For_Itype (Node (E))
14241 then
14242 Set_Associated_Node_For_Itype
14243 (Node (Next_Elmt (E)), New_Itype);
14244 end if;
14246 E := Next_Elmt (Next_Elmt (E));
14247 end loop;
14248 end if;
14249 end if;
14251 if Present (Freeze_Node (New_Itype)) then
14252 Set_Is_Frozen (New_Itype, False);
14253 Set_Freeze_Node (New_Itype, Empty);
14254 end if;
14256 -- Add new association to map
14258 if No (Actual_Map) then
14259 Actual_Map := New_Elmt_List;
14260 end if;
14262 Append_Elmt (Old_Itype, Actual_Map);
14263 Append_Elmt (New_Itype, Actual_Map);
14265 if NCT_Hash_Tables_Used then
14266 NCT_Assoc.Set (Old_Itype, New_Itype);
14268 else
14269 NCT_Table_Entries := NCT_Table_Entries + 1;
14271 if NCT_Table_Entries > NCT_Hash_Threshold then
14272 Build_NCT_Hash_Tables;
14273 end if;
14274 end if;
14276 -- If a record subtype is simply copied, the entity list will be
14277 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
14279 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
14280 Set_Cloned_Subtype (New_Itype, Old_Itype);
14281 end if;
14283 -- Visit descendents that eventually get copied
14285 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
14287 if Is_Discrete_Type (Old_Itype) then
14288 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
14290 elsif Has_Discriminants (Base_Type (Old_Itype)) then
14291 -- ??? This should involve call to Visit_Field
14292 Visit_Elist (Discriminant_Constraint (Old_Itype));
14294 elsif Is_Array_Type (Old_Itype) then
14295 if Present (First_Index (Old_Itype)) then
14296 Visit_Field (Union_Id (List_Containing
14297 (First_Index (Old_Itype))),
14298 Old_Itype);
14299 end if;
14301 if Is_Packed (Old_Itype) then
14302 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
14303 Old_Itype);
14304 end if;
14305 end if;
14306 end Visit_Itype;
14308 ----------------
14309 -- Visit_List --
14310 ----------------
14312 procedure Visit_List (L : List_Id) is
14313 N : Node_Id;
14314 begin
14315 if L /= No_List then
14316 N := First (L);
14318 while Present (N) loop
14319 Visit_Node (N);
14320 Next (N);
14321 end loop;
14322 end if;
14323 end Visit_List;
14325 ----------------
14326 -- Visit_Node --
14327 ----------------
14329 procedure Visit_Node (N : Node_Or_Entity_Id) is
14331 -- Start of processing for Visit_Node
14333 begin
14334 -- Handle case of an Itype, which must be copied
14336 if Has_Extension (N) and then Is_Itype (N) then
14338 -- Nothing to do if already in the list. This can happen with an
14339 -- Itype entity that appears more than once in the tree.
14340 -- Note that we do not want to visit descendents in this case.
14342 -- Test for already in list when hash table is used
14344 if NCT_Hash_Tables_Used then
14345 if Present (NCT_Assoc.Get (Entity_Id (N))) then
14346 return;
14347 end if;
14349 -- Test for already in list when hash table not used
14351 else
14352 declare
14353 E : Elmt_Id;
14354 begin
14355 if Present (Actual_Map) then
14356 E := First_Elmt (Actual_Map);
14357 while Present (E) loop
14358 if Node (E) = N then
14359 return;
14360 else
14361 E := Next_Elmt (Next_Elmt (E));
14362 end if;
14363 end loop;
14364 end if;
14365 end;
14366 end if;
14368 Visit_Itype (N);
14369 end if;
14371 -- Visit descendents
14373 Visit_Field (Field1 (N), N);
14374 Visit_Field (Field2 (N), N);
14375 Visit_Field (Field3 (N), N);
14376 Visit_Field (Field4 (N), N);
14377 Visit_Field (Field5 (N), N);
14378 end Visit_Node;
14380 -- Start of processing for New_Copy_Tree
14382 begin
14383 Actual_Map := Map;
14385 -- See if we should use hash table
14387 if No (Actual_Map) then
14388 NCT_Hash_Tables_Used := False;
14390 else
14391 declare
14392 Elmt : Elmt_Id;
14394 begin
14395 NCT_Table_Entries := 0;
14397 Elmt := First_Elmt (Actual_Map);
14398 while Present (Elmt) loop
14399 NCT_Table_Entries := NCT_Table_Entries + 1;
14400 Next_Elmt (Elmt);
14401 Next_Elmt (Elmt);
14402 end loop;
14404 if NCT_Table_Entries > NCT_Hash_Threshold then
14405 Build_NCT_Hash_Tables;
14406 else
14407 NCT_Hash_Tables_Used := False;
14408 end if;
14409 end;
14410 end if;
14412 -- Hash table set up if required, now start phase one by visiting
14413 -- top node (we will recursively visit the descendents).
14415 Visit_Node (Source);
14417 -- Now the second phase of the copy can start. First we process
14418 -- all the mapped entities, copying their descendents.
14420 if Present (Actual_Map) then
14421 declare
14422 Elmt : Elmt_Id;
14423 New_Itype : Entity_Id;
14424 begin
14425 Elmt := First_Elmt (Actual_Map);
14426 while Present (Elmt) loop
14427 Next_Elmt (Elmt);
14428 New_Itype := Node (Elmt);
14429 Copy_Itype_With_Replacement (New_Itype);
14430 Next_Elmt (Elmt);
14431 end loop;
14432 end;
14433 end if;
14435 -- Now we can copy the actual tree
14437 return Copy_Node_With_Replacement (Source);
14438 end New_Copy_Tree;
14440 -------------------------
14441 -- New_External_Entity --
14442 -------------------------
14444 function New_External_Entity
14445 (Kind : Entity_Kind;
14446 Scope_Id : Entity_Id;
14447 Sloc_Value : Source_Ptr;
14448 Related_Id : Entity_Id;
14449 Suffix : Character;
14450 Suffix_Index : Nat := 0;
14451 Prefix : Character := ' ') return Entity_Id
14453 N : constant Entity_Id :=
14454 Make_Defining_Identifier (Sloc_Value,
14455 New_External_Name
14456 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
14458 begin
14459 Set_Ekind (N, Kind);
14460 Set_Is_Internal (N, True);
14461 Append_Entity (N, Scope_Id);
14462 Set_Public_Status (N);
14464 if Kind in Type_Kind then
14465 Init_Size_Align (N);
14466 end if;
14468 return N;
14469 end New_External_Entity;
14471 -------------------------
14472 -- New_Internal_Entity --
14473 -------------------------
14475 function New_Internal_Entity
14476 (Kind : Entity_Kind;
14477 Scope_Id : Entity_Id;
14478 Sloc_Value : Source_Ptr;
14479 Id_Char : Character) return Entity_Id
14481 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
14483 begin
14484 Set_Ekind (N, Kind);
14485 Set_Is_Internal (N, True);
14486 Append_Entity (N, Scope_Id);
14488 if Kind in Type_Kind then
14489 Init_Size_Align (N);
14490 end if;
14492 return N;
14493 end New_Internal_Entity;
14495 -----------------
14496 -- Next_Actual --
14497 -----------------
14499 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
14500 N : Node_Id;
14502 begin
14503 -- If we are pointing at a positional parameter, it is a member of a
14504 -- node list (the list of parameters), and the next parameter is the
14505 -- next node on the list, unless we hit a parameter association, then
14506 -- we shift to using the chain whose head is the First_Named_Actual in
14507 -- the parent, and then is threaded using the Next_Named_Actual of the
14508 -- Parameter_Association. All this fiddling is because the original node
14509 -- list is in the textual call order, and what we need is the
14510 -- declaration order.
14512 if Is_List_Member (Actual_Id) then
14513 N := Next (Actual_Id);
14515 if Nkind (N) = N_Parameter_Association then
14516 return First_Named_Actual (Parent (Actual_Id));
14517 else
14518 return N;
14519 end if;
14521 else
14522 return Next_Named_Actual (Parent (Actual_Id));
14523 end if;
14524 end Next_Actual;
14526 procedure Next_Actual (Actual_Id : in out Node_Id) is
14527 begin
14528 Actual_Id := Next_Actual (Actual_Id);
14529 end Next_Actual;
14531 -----------------------
14532 -- Normalize_Actuals --
14533 -----------------------
14535 -- Chain actuals according to formals of subprogram. If there are no named
14536 -- associations, the chain is simply the list of Parameter Associations,
14537 -- since the order is the same as the declaration order. If there are named
14538 -- associations, then the First_Named_Actual field in the N_Function_Call
14539 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14540 -- node for the parameter that comes first in declaration order. The
14541 -- remaining named parameters are then chained in declaration order using
14542 -- Next_Named_Actual.
14544 -- This routine also verifies that the number of actuals is compatible with
14545 -- the number and default values of formals, but performs no type checking
14546 -- (type checking is done by the caller).
14548 -- If the matching succeeds, Success is set to True and the caller proceeds
14549 -- with type-checking. If the match is unsuccessful, then Success is set to
14550 -- False, and the caller attempts a different interpretation, if there is
14551 -- one.
14553 -- If the flag Report is on, the call is not overloaded, and a failure to
14554 -- match can be reported here, rather than in the caller.
14556 procedure Normalize_Actuals
14557 (N : Node_Id;
14558 S : Entity_Id;
14559 Report : Boolean;
14560 Success : out Boolean)
14562 Actuals : constant List_Id := Parameter_Associations (N);
14563 Actual : Node_Id := Empty;
14564 Formal : Entity_Id;
14565 Last : Node_Id := Empty;
14566 First_Named : Node_Id := Empty;
14567 Found : Boolean;
14569 Formals_To_Match : Integer := 0;
14570 Actuals_To_Match : Integer := 0;
14572 procedure Chain (A : Node_Id);
14573 -- Add named actual at the proper place in the list, using the
14574 -- Next_Named_Actual link.
14576 function Reporting return Boolean;
14577 -- Determines if an error is to be reported. To report an error, we
14578 -- need Report to be True, and also we do not report errors caused
14579 -- by calls to init procs that occur within other init procs. Such
14580 -- errors must always be cascaded errors, since if all the types are
14581 -- declared correctly, the compiler will certainly build decent calls.
14583 -----------
14584 -- Chain --
14585 -----------
14587 procedure Chain (A : Node_Id) is
14588 begin
14589 if No (Last) then
14591 -- Call node points to first actual in list
14593 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
14595 else
14596 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
14597 end if;
14599 Last := A;
14600 Set_Next_Named_Actual (Last, Empty);
14601 end Chain;
14603 ---------------
14604 -- Reporting --
14605 ---------------
14607 function Reporting return Boolean is
14608 begin
14609 if not Report then
14610 return False;
14612 elsif not Within_Init_Proc then
14613 return True;
14615 elsif Is_Init_Proc (Entity (Name (N))) then
14616 return False;
14618 else
14619 return True;
14620 end if;
14621 end Reporting;
14623 -- Start of processing for Normalize_Actuals
14625 begin
14626 if Is_Access_Type (S) then
14628 -- The name in the call is a function call that returns an access
14629 -- to subprogram. The designated type has the list of formals.
14631 Formal := First_Formal (Designated_Type (S));
14632 else
14633 Formal := First_Formal (S);
14634 end if;
14636 while Present (Formal) loop
14637 Formals_To_Match := Formals_To_Match + 1;
14638 Next_Formal (Formal);
14639 end loop;
14641 -- Find if there is a named association, and verify that no positional
14642 -- associations appear after named ones.
14644 if Present (Actuals) then
14645 Actual := First (Actuals);
14646 end if;
14648 while Present (Actual)
14649 and then Nkind (Actual) /= N_Parameter_Association
14650 loop
14651 Actuals_To_Match := Actuals_To_Match + 1;
14652 Next (Actual);
14653 end loop;
14655 if No (Actual) and Actuals_To_Match = Formals_To_Match then
14657 -- Most common case: positional notation, no defaults
14659 Success := True;
14660 return;
14662 elsif Actuals_To_Match > Formals_To_Match then
14664 -- Too many actuals: will not work
14666 if Reporting then
14667 if Is_Entity_Name (Name (N)) then
14668 Error_Msg_N ("too many arguments in call to&", Name (N));
14669 else
14670 Error_Msg_N ("too many arguments in call", N);
14671 end if;
14672 end if;
14674 Success := False;
14675 return;
14676 end if;
14678 First_Named := Actual;
14680 while Present (Actual) loop
14681 if Nkind (Actual) /= N_Parameter_Association then
14682 Error_Msg_N
14683 ("positional parameters not allowed after named ones", Actual);
14684 Success := False;
14685 return;
14687 else
14688 Actuals_To_Match := Actuals_To_Match + 1;
14689 end if;
14691 Next (Actual);
14692 end loop;
14694 if Present (Actuals) then
14695 Actual := First (Actuals);
14696 end if;
14698 Formal := First_Formal (S);
14699 while Present (Formal) loop
14701 -- Match the formals in order. If the corresponding actual is
14702 -- positional, nothing to do. Else scan the list of named actuals
14703 -- to find the one with the right name.
14705 if Present (Actual)
14706 and then Nkind (Actual) /= N_Parameter_Association
14707 then
14708 Next (Actual);
14709 Actuals_To_Match := Actuals_To_Match - 1;
14710 Formals_To_Match := Formals_To_Match - 1;
14712 else
14713 -- For named parameters, search the list of actuals to find
14714 -- one that matches the next formal name.
14716 Actual := First_Named;
14717 Found := False;
14718 while Present (Actual) loop
14719 if Chars (Selector_Name (Actual)) = Chars (Formal) then
14720 Found := True;
14721 Chain (Actual);
14722 Actuals_To_Match := Actuals_To_Match - 1;
14723 Formals_To_Match := Formals_To_Match - 1;
14724 exit;
14725 end if;
14727 Next (Actual);
14728 end loop;
14730 if not Found then
14731 if Ekind (Formal) /= E_In_Parameter
14732 or else No (Default_Value (Formal))
14733 then
14734 if Reporting then
14735 if (Comes_From_Source (S)
14736 or else Sloc (S) = Standard_Location)
14737 and then Is_Overloadable (S)
14738 then
14739 if No (Actuals)
14740 and then
14741 Nkind_In (Parent (N), N_Procedure_Call_Statement,
14742 N_Function_Call,
14743 N_Parameter_Association)
14744 and then Ekind (S) /= E_Function
14745 then
14746 Set_Etype (N, Etype (S));
14748 else
14749 Error_Msg_Name_1 := Chars (S);
14750 Error_Msg_Sloc := Sloc (S);
14751 Error_Msg_NE
14752 ("missing argument for parameter & "
14753 & "in call to % declared #", N, Formal);
14754 end if;
14756 elsif Is_Overloadable (S) then
14757 Error_Msg_Name_1 := Chars (S);
14759 -- Point to type derivation that generated the
14760 -- operation.
14762 Error_Msg_Sloc := Sloc (Parent (S));
14764 Error_Msg_NE
14765 ("missing argument for parameter & "
14766 & "in call to % (inherited) #", N, Formal);
14768 else
14769 Error_Msg_NE
14770 ("missing argument for parameter &", N, Formal);
14771 end if;
14772 end if;
14774 Success := False;
14775 return;
14777 else
14778 Formals_To_Match := Formals_To_Match - 1;
14779 end if;
14780 end if;
14781 end if;
14783 Next_Formal (Formal);
14784 end loop;
14786 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
14787 Success := True;
14788 return;
14790 else
14791 if Reporting then
14793 -- Find some superfluous named actual that did not get
14794 -- attached to the list of associations.
14796 Actual := First (Actuals);
14797 while Present (Actual) loop
14798 if Nkind (Actual) = N_Parameter_Association
14799 and then Actual /= Last
14800 and then No (Next_Named_Actual (Actual))
14801 then
14802 Error_Msg_N ("unmatched actual & in call",
14803 Selector_Name (Actual));
14804 exit;
14805 end if;
14807 Next (Actual);
14808 end loop;
14809 end if;
14811 Success := False;
14812 return;
14813 end if;
14814 end Normalize_Actuals;
14816 --------------------------------
14817 -- Note_Possible_Modification --
14818 --------------------------------
14820 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
14821 Modification_Comes_From_Source : constant Boolean :=
14822 Comes_From_Source (Parent (N));
14824 Ent : Entity_Id;
14825 Exp : Node_Id;
14827 begin
14828 -- Loop to find referenced entity, if there is one
14830 Exp := N;
14831 loop
14832 Ent := Empty;
14834 if Is_Entity_Name (Exp) then
14835 Ent := Entity (Exp);
14837 -- If the entity is missing, it is an undeclared identifier,
14838 -- and there is nothing to annotate.
14840 if No (Ent) then
14841 return;
14842 end if;
14844 elsif Nkind (Exp) = N_Explicit_Dereference then
14845 declare
14846 P : constant Node_Id := Prefix (Exp);
14848 begin
14849 -- In formal verification mode, keep track of all reads and
14850 -- writes through explicit dereferences.
14852 if GNATprove_Mode then
14853 SPARK_Specific.Generate_Dereference (N, 'm');
14854 end if;
14856 if Nkind (P) = N_Selected_Component
14857 and then Present (Entry_Formal (Entity (Selector_Name (P))))
14858 then
14859 -- Case of a reference to an entry formal
14861 Ent := Entry_Formal (Entity (Selector_Name (P)));
14863 elsif Nkind (P) = N_Identifier
14864 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
14865 and then Present (Expression (Parent (Entity (P))))
14866 and then Nkind (Expression (Parent (Entity (P)))) =
14867 N_Reference
14868 then
14869 -- Case of a reference to a value on which side effects have
14870 -- been removed.
14872 Exp := Prefix (Expression (Parent (Entity (P))));
14873 goto Continue;
14875 else
14876 return;
14877 end if;
14878 end;
14880 elsif Nkind_In (Exp, N_Type_Conversion,
14881 N_Unchecked_Type_Conversion)
14882 then
14883 Exp := Expression (Exp);
14884 goto Continue;
14886 elsif Nkind_In (Exp, N_Slice,
14887 N_Indexed_Component,
14888 N_Selected_Component)
14889 then
14890 -- Special check, if the prefix is an access type, then return
14891 -- since we are modifying the thing pointed to, not the prefix.
14892 -- When we are expanding, most usually the prefix is replaced
14893 -- by an explicit dereference, and this test is not needed, but
14894 -- in some cases (notably -gnatc mode and generics) when we do
14895 -- not do full expansion, we need this special test.
14897 if Is_Access_Type (Etype (Prefix (Exp))) then
14898 return;
14900 -- Otherwise go to prefix and keep going
14902 else
14903 Exp := Prefix (Exp);
14904 goto Continue;
14905 end if;
14907 -- All other cases, not a modification
14909 else
14910 return;
14911 end if;
14913 -- Now look for entity being referenced
14915 if Present (Ent) then
14916 if Is_Object (Ent) then
14917 if Comes_From_Source (Exp)
14918 or else Modification_Comes_From_Source
14919 then
14920 -- Give warning if pragma unmodified given and we are
14921 -- sure this is a modification.
14923 if Has_Pragma_Unmodified (Ent) and then Sure then
14924 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
14925 end if;
14927 Set_Never_Set_In_Source (Ent, False);
14928 end if;
14930 Set_Is_True_Constant (Ent, False);
14931 Set_Current_Value (Ent, Empty);
14932 Set_Is_Known_Null (Ent, False);
14934 if not Can_Never_Be_Null (Ent) then
14935 Set_Is_Known_Non_Null (Ent, False);
14936 end if;
14938 -- Follow renaming chain
14940 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
14941 and then Present (Renamed_Object (Ent))
14942 then
14943 Exp := Renamed_Object (Ent);
14945 -- If the entity is the loop variable in an iteration over
14946 -- a container, retrieve container expression to indicate
14947 -- possible modificastion.
14949 if Present (Related_Expression (Ent))
14950 and then Nkind (Parent (Related_Expression (Ent))) =
14951 N_Iterator_Specification
14952 then
14953 Exp := Original_Node (Related_Expression (Ent));
14954 end if;
14956 goto Continue;
14958 -- The expression may be the renaming of a subcomponent of an
14959 -- array or container. The assignment to the subcomponent is
14960 -- a modification of the container.
14962 elsif Comes_From_Source (Original_Node (Exp))
14963 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
14964 N_Indexed_Component)
14965 then
14966 Exp := Prefix (Original_Node (Exp));
14967 goto Continue;
14968 end if;
14970 -- Generate a reference only if the assignment comes from
14971 -- source. This excludes, for example, calls to a dispatching
14972 -- assignment operation when the left-hand side is tagged. In
14973 -- GNATprove mode, we need those references also on generated
14974 -- code, as these are used to compute the local effects of
14975 -- subprograms.
14977 if Modification_Comes_From_Source or GNATprove_Mode then
14978 Generate_Reference (Ent, Exp, 'm');
14980 -- If the target of the assignment is the bound variable
14981 -- in an iterator, indicate that the corresponding array
14982 -- or container is also modified.
14984 if Ada_Version >= Ada_2012
14985 and then Nkind (Parent (Ent)) = N_Iterator_Specification
14986 then
14987 declare
14988 Domain : constant Node_Id := Name (Parent (Ent));
14990 begin
14991 -- TBD : in the full version of the construct, the
14992 -- domain of iteration can be given by an expression.
14994 if Is_Entity_Name (Domain) then
14995 Generate_Reference (Entity (Domain), Exp, 'm');
14996 Set_Is_True_Constant (Entity (Domain), False);
14997 Set_Never_Set_In_Source (Entity (Domain), False);
14998 end if;
14999 end;
15000 end if;
15001 end if;
15003 Check_Nested_Access (Ent);
15004 end if;
15006 Kill_Checks (Ent);
15008 -- If we are sure this is a modification from source, and we know
15009 -- this modifies a constant, then give an appropriate warning.
15011 if Overlays_Constant (Ent)
15012 and then (Modification_Comes_From_Source and Sure)
15013 then
15014 declare
15015 A : constant Node_Id := Address_Clause (Ent);
15016 begin
15017 if Present (A) then
15018 declare
15019 Exp : constant Node_Id := Expression (A);
15020 begin
15021 if Nkind (Exp) = N_Attribute_Reference
15022 and then Attribute_Name (Exp) = Name_Address
15023 and then Is_Entity_Name (Prefix (Exp))
15024 then
15025 Error_Msg_Sloc := Sloc (A);
15026 Error_Msg_NE
15027 ("constant& may be modified via address "
15028 & "clause#??", N, Entity (Prefix (Exp)));
15029 end if;
15030 end;
15031 end if;
15032 end;
15033 end if;
15035 return;
15036 end if;
15038 <<Continue>>
15039 null;
15040 end loop;
15041 end Note_Possible_Modification;
15043 -------------------------
15044 -- Object_Access_Level --
15045 -------------------------
15047 -- Returns the static accessibility level of the view denoted by Obj. Note
15048 -- that the value returned is the result of a call to Scope_Depth. Only
15049 -- scope depths associated with dynamic scopes can actually be returned.
15050 -- Since only relative levels matter for accessibility checking, the fact
15051 -- that the distance between successive levels of accessibility is not
15052 -- always one is immaterial (invariant: if level(E2) is deeper than
15053 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
15055 function Object_Access_Level (Obj : Node_Id) return Uint is
15056 function Is_Interface_Conversion (N : Node_Id) return Boolean;
15057 -- Determine whether N is a construct of the form
15058 -- Some_Type (Operand._tag'Address)
15059 -- This construct appears in the context of dispatching calls.
15061 function Reference_To (Obj : Node_Id) return Node_Id;
15062 -- An explicit dereference is created when removing side-effects from
15063 -- expressions for constraint checking purposes. In this case a local
15064 -- access type is created for it. The correct access level is that of
15065 -- the original source node. We detect this case by noting that the
15066 -- prefix of the dereference is created by an object declaration whose
15067 -- initial expression is a reference.
15069 -----------------------------
15070 -- Is_Interface_Conversion --
15071 -----------------------------
15073 function Is_Interface_Conversion (N : Node_Id) return Boolean is
15074 begin
15075 return Nkind (N) = N_Unchecked_Type_Conversion
15076 and then Nkind (Expression (N)) = N_Attribute_Reference
15077 and then Attribute_Name (Expression (N)) = Name_Address;
15078 end Is_Interface_Conversion;
15080 ------------------
15081 -- Reference_To --
15082 ------------------
15084 function Reference_To (Obj : Node_Id) return Node_Id is
15085 Pref : constant Node_Id := Prefix (Obj);
15086 begin
15087 if Is_Entity_Name (Pref)
15088 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
15089 and then Present (Expression (Parent (Entity (Pref))))
15090 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
15091 then
15092 return (Prefix (Expression (Parent (Entity (Pref)))));
15093 else
15094 return Empty;
15095 end if;
15096 end Reference_To;
15098 -- Local variables
15100 E : Entity_Id;
15102 -- Start of processing for Object_Access_Level
15104 begin
15105 if Nkind (Obj) = N_Defining_Identifier
15106 or else Is_Entity_Name (Obj)
15107 then
15108 if Nkind (Obj) = N_Defining_Identifier then
15109 E := Obj;
15110 else
15111 E := Entity (Obj);
15112 end if;
15114 if Is_Prival (E) then
15115 E := Prival_Link (E);
15116 end if;
15118 -- If E is a type then it denotes a current instance. For this case
15119 -- we add one to the normal accessibility level of the type to ensure
15120 -- that current instances are treated as always being deeper than
15121 -- than the level of any visible named access type (see 3.10.2(21)).
15123 if Is_Type (E) then
15124 return Type_Access_Level (E) + 1;
15126 elsif Present (Renamed_Object (E)) then
15127 return Object_Access_Level (Renamed_Object (E));
15129 -- Similarly, if E is a component of the current instance of a
15130 -- protected type, any instance of it is assumed to be at a deeper
15131 -- level than the type. For a protected object (whose type is an
15132 -- anonymous protected type) its components are at the same level
15133 -- as the type itself.
15135 elsif not Is_Overloadable (E)
15136 and then Ekind (Scope (E)) = E_Protected_Type
15137 and then Comes_From_Source (Scope (E))
15138 then
15139 return Type_Access_Level (Scope (E)) + 1;
15141 else
15142 -- Aliased formals take their access level from the point of call.
15143 -- This is smaller than the level of the subprogram itself.
15145 if Is_Formal (E) and then Is_Aliased (E) then
15146 return Type_Access_Level (Etype (E));
15148 else
15149 return Scope_Depth (Enclosing_Dynamic_Scope (E));
15150 end if;
15151 end if;
15153 elsif Nkind (Obj) = N_Selected_Component then
15154 if Is_Access_Type (Etype (Prefix (Obj))) then
15155 return Type_Access_Level (Etype (Prefix (Obj)));
15156 else
15157 return Object_Access_Level (Prefix (Obj));
15158 end if;
15160 elsif Nkind (Obj) = N_Indexed_Component then
15161 if Is_Access_Type (Etype (Prefix (Obj))) then
15162 return Type_Access_Level (Etype (Prefix (Obj)));
15163 else
15164 return Object_Access_Level (Prefix (Obj));
15165 end if;
15167 elsif Nkind (Obj) = N_Explicit_Dereference then
15169 -- If the prefix is a selected access discriminant then we make a
15170 -- recursive call on the prefix, which will in turn check the level
15171 -- of the prefix object of the selected discriminant.
15173 -- In Ada 2012, if the discriminant has implicit dereference and
15174 -- the context is a selected component, treat this as an object of
15175 -- unknown scope (see below). This is necessary in compile-only mode;
15176 -- otherwise expansion will already have transformed the prefix into
15177 -- a temporary.
15179 if Nkind (Prefix (Obj)) = N_Selected_Component
15180 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
15181 and then
15182 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
15183 and then
15184 (not Has_Implicit_Dereference
15185 (Entity (Selector_Name (Prefix (Obj))))
15186 or else Nkind (Parent (Obj)) /= N_Selected_Component)
15187 then
15188 return Object_Access_Level (Prefix (Obj));
15190 -- Detect an interface conversion in the context of a dispatching
15191 -- call. Use the original form of the conversion to find the access
15192 -- level of the operand.
15194 elsif Is_Interface (Etype (Obj))
15195 and then Is_Interface_Conversion (Prefix (Obj))
15196 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
15197 then
15198 return Object_Access_Level (Original_Node (Obj));
15200 elsif not Comes_From_Source (Obj) then
15201 declare
15202 Ref : constant Node_Id := Reference_To (Obj);
15203 begin
15204 if Present (Ref) then
15205 return Object_Access_Level (Ref);
15206 else
15207 return Type_Access_Level (Etype (Prefix (Obj)));
15208 end if;
15209 end;
15211 else
15212 return Type_Access_Level (Etype (Prefix (Obj)));
15213 end if;
15215 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
15216 return Object_Access_Level (Expression (Obj));
15218 elsif Nkind (Obj) = N_Function_Call then
15220 -- Function results are objects, so we get either the access level of
15221 -- the function or, in the case of an indirect call, the level of the
15222 -- access-to-subprogram type. (This code is used for Ada 95, but it
15223 -- looks wrong, because it seems that we should be checking the level
15224 -- of the call itself, even for Ada 95. However, using the Ada 2005
15225 -- version of the code causes regressions in several tests that are
15226 -- compiled with -gnat95. ???)
15228 if Ada_Version < Ada_2005 then
15229 if Is_Entity_Name (Name (Obj)) then
15230 return Subprogram_Access_Level (Entity (Name (Obj)));
15231 else
15232 return Type_Access_Level (Etype (Prefix (Name (Obj))));
15233 end if;
15235 -- For Ada 2005, the level of the result object of a function call is
15236 -- defined to be the level of the call's innermost enclosing master.
15237 -- We determine that by querying the depth of the innermost enclosing
15238 -- dynamic scope.
15240 else
15241 Return_Master_Scope_Depth_Of_Call : declare
15243 function Innermost_Master_Scope_Depth
15244 (N : Node_Id) return Uint;
15245 -- Returns the scope depth of the given node's innermost
15246 -- enclosing dynamic scope (effectively the accessibility
15247 -- level of the innermost enclosing master).
15249 ----------------------------------
15250 -- Innermost_Master_Scope_Depth --
15251 ----------------------------------
15253 function Innermost_Master_Scope_Depth
15254 (N : Node_Id) return Uint
15256 Node_Par : Node_Id := Parent (N);
15258 begin
15259 -- Locate the nearest enclosing node (by traversing Parents)
15260 -- that Defining_Entity can be applied to, and return the
15261 -- depth of that entity's nearest enclosing dynamic scope.
15263 while Present (Node_Par) loop
15264 case Nkind (Node_Par) is
15265 when N_Component_Declaration |
15266 N_Entry_Declaration |
15267 N_Formal_Object_Declaration |
15268 N_Formal_Type_Declaration |
15269 N_Full_Type_Declaration |
15270 N_Incomplete_Type_Declaration |
15271 N_Loop_Parameter_Specification |
15272 N_Object_Declaration |
15273 N_Protected_Type_Declaration |
15274 N_Private_Extension_Declaration |
15275 N_Private_Type_Declaration |
15276 N_Subtype_Declaration |
15277 N_Function_Specification |
15278 N_Procedure_Specification |
15279 N_Task_Type_Declaration |
15280 N_Body_Stub |
15281 N_Generic_Instantiation |
15282 N_Proper_Body |
15283 N_Implicit_Label_Declaration |
15284 N_Package_Declaration |
15285 N_Single_Task_Declaration |
15286 N_Subprogram_Declaration |
15287 N_Generic_Declaration |
15288 N_Renaming_Declaration |
15289 N_Block_Statement |
15290 N_Formal_Subprogram_Declaration |
15291 N_Abstract_Subprogram_Declaration |
15292 N_Entry_Body |
15293 N_Exception_Declaration |
15294 N_Formal_Package_Declaration |
15295 N_Number_Declaration |
15296 N_Package_Specification |
15297 N_Parameter_Specification |
15298 N_Single_Protected_Declaration |
15299 N_Subunit =>
15301 return Scope_Depth
15302 (Nearest_Dynamic_Scope
15303 (Defining_Entity (Node_Par)));
15305 when others =>
15306 null;
15307 end case;
15309 Node_Par := Parent (Node_Par);
15310 end loop;
15312 pragma Assert (False);
15314 -- Should never reach the following return
15316 return Scope_Depth (Current_Scope) + 1;
15317 end Innermost_Master_Scope_Depth;
15319 -- Start of processing for Return_Master_Scope_Depth_Of_Call
15321 begin
15322 return Innermost_Master_Scope_Depth (Obj);
15323 end Return_Master_Scope_Depth_Of_Call;
15324 end if;
15326 -- For convenience we handle qualified expressions, even though they
15327 -- aren't technically object names.
15329 elsif Nkind (Obj) = N_Qualified_Expression then
15330 return Object_Access_Level (Expression (Obj));
15332 -- Ditto for aggregates. They have the level of the temporary that
15333 -- will hold their value.
15335 elsif Nkind (Obj) = N_Aggregate then
15336 return Object_Access_Level (Current_Scope);
15338 -- Otherwise return the scope level of Standard. (If there are cases
15339 -- that fall through to this point they will be treated as having
15340 -- global accessibility for now. ???)
15342 else
15343 return Scope_Depth (Standard_Standard);
15344 end if;
15345 end Object_Access_Level;
15347 --------------------------
15348 -- Original_Aspect_Name --
15349 --------------------------
15351 function Original_Aspect_Name (N : Node_Id) return Name_Id is
15352 Pras : Node_Id;
15353 Name : Name_Id;
15355 begin
15356 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
15357 Pras := N;
15359 if Is_Rewrite_Substitution (Pras)
15360 and then Nkind (Original_Node (Pras)) = N_Pragma
15361 then
15362 Pras := Original_Node (Pras);
15363 end if;
15365 -- Case where we came from aspect specication
15367 if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
15368 Pras := Corresponding_Aspect (Pras);
15369 end if;
15371 -- Get name from aspect or pragma
15373 if Nkind (Pras) = N_Pragma then
15374 Name := Pragma_Name (Pras);
15375 else
15376 Name := Chars (Identifier (Pras));
15377 end if;
15379 -- Deal with 'Class
15381 if Class_Present (Pras) then
15382 case Name is
15384 -- Names that need converting to special _xxx form
15386 when Name_Pre |
15387 Name_Pre_Class =>
15388 Name := Name_uPre;
15390 when Name_Post |
15391 Name_Post_Class =>
15392 Name := Name_uPost;
15394 when Name_Invariant =>
15395 Name := Name_uInvariant;
15397 when Name_Type_Invariant |
15398 Name_Type_Invariant_Class =>
15399 Name := Name_uType_Invariant;
15401 -- Nothing to do for other cases (e.g. a Check that derived
15402 -- from Pre_Class and has the flag set). Also we do nothing
15403 -- if the name is already in special _xxx form.
15405 when others =>
15406 null;
15407 end case;
15408 end if;
15410 return Name;
15411 end Original_Aspect_Name;
15413 --------------------------------------
15414 -- Original_Corresponding_Operation --
15415 --------------------------------------
15417 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
15419 Typ : constant Entity_Id := Find_Dispatching_Type (S);
15421 begin
15422 -- If S is an inherited primitive S2 the original corresponding
15423 -- operation of S is the original corresponding operation of S2
15425 if Present (Alias (S))
15426 and then Find_Dispatching_Type (Alias (S)) /= Typ
15427 then
15428 return Original_Corresponding_Operation (Alias (S));
15430 -- If S overrides an inherited subprogram S2 the original corresponding
15431 -- operation of S is the original corresponding operation of S2
15433 elsif Present (Overridden_Operation (S)) then
15434 return Original_Corresponding_Operation (Overridden_Operation (S));
15436 -- otherwise it is S itself
15438 else
15439 return S;
15440 end if;
15441 end Original_Corresponding_Operation;
15443 ----------------------
15444 -- Policy_In_Effect --
15445 ----------------------
15447 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
15448 function Policy_In_List (List : Node_Id) return Name_Id;
15449 -- Determine the the mode of a policy in a N_Pragma list
15451 --------------------
15452 -- Policy_In_List --
15453 --------------------
15455 function Policy_In_List (List : Node_Id) return Name_Id is
15456 Arg : Node_Id;
15457 Expr : Node_Id;
15458 Prag : Node_Id;
15460 begin
15461 Prag := List;
15462 while Present (Prag) loop
15463 Arg := First (Pragma_Argument_Associations (Prag));
15464 Expr := Get_Pragma_Arg (Arg);
15466 -- The current Check_Policy pragma matches the requested policy,
15467 -- return the second argument which denotes the policy identifier.
15469 if Chars (Expr) = Policy then
15470 return Chars (Get_Pragma_Arg (Next (Arg)));
15471 end if;
15473 Prag := Next_Pragma (Prag);
15474 end loop;
15476 return No_Name;
15477 end Policy_In_List;
15479 -- Local variables
15481 Kind : Name_Id;
15483 -- Start of processing for Policy_In_Effect
15485 begin
15486 if not Is_Valid_Assertion_Kind (Policy) then
15487 raise Program_Error;
15488 end if;
15490 -- Inspect all policy pragmas that appear within scopes (if any)
15492 Kind := Policy_In_List (Check_Policy_List);
15494 -- Inspect all configuration policy pragmas (if any)
15496 if Kind = No_Name then
15497 Kind := Policy_In_List (Check_Policy_List_Config);
15498 end if;
15500 -- The context lacks policy pragmas, determine the mode based on whether
15501 -- assertions are enabled at the configuration level. This ensures that
15502 -- the policy is preserved when analyzing generics.
15504 if Kind = No_Name then
15505 if Assertions_Enabled_Config then
15506 Kind := Name_Check;
15507 else
15508 Kind := Name_Ignore;
15509 end if;
15510 end if;
15512 return Kind;
15513 end Policy_In_Effect;
15515 ----------------------------------
15516 -- Predicate_Tests_On_Arguments --
15517 ----------------------------------
15519 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
15520 begin
15521 -- Always test predicates on indirect call
15523 if Ekind (Subp) = E_Subprogram_Type then
15524 return True;
15526 -- Do not test predicates on call to generated default Finalize, since
15527 -- we are not interested in whether something we are finalizing (and
15528 -- typically destroying) satisfies its predicates.
15530 elsif Chars (Subp) = Name_Finalize
15531 and then not Comes_From_Source (Subp)
15532 then
15533 return False;
15535 -- Do not test predicates on any internally generated routines
15537 elsif Is_Internal_Name (Chars (Subp)) then
15538 return False;
15540 -- Do not test predicates on call to Init_Proc, since if needed the
15541 -- predicate test will occur at some other point.
15543 elsif Is_Init_Proc (Subp) then
15544 return False;
15546 -- Do not test predicates on call to predicate function, since this
15547 -- would cause infinite recursion.
15549 elsif Ekind (Subp) = E_Function
15550 and then (Is_Predicate_Function (Subp)
15551 or else
15552 Is_Predicate_Function_M (Subp))
15553 then
15554 return False;
15556 -- For now, no other exceptions
15558 else
15559 return True;
15560 end if;
15561 end Predicate_Tests_On_Arguments;
15563 -----------------------
15564 -- Private_Component --
15565 -----------------------
15567 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
15568 Ancestor : constant Entity_Id := Base_Type (Type_Id);
15570 function Trace_Components
15571 (T : Entity_Id;
15572 Check : Boolean) return Entity_Id;
15573 -- Recursive function that does the work, and checks against circular
15574 -- definition for each subcomponent type.
15576 ----------------------
15577 -- Trace_Components --
15578 ----------------------
15580 function Trace_Components
15581 (T : Entity_Id;
15582 Check : Boolean) return Entity_Id
15584 Btype : constant Entity_Id := Base_Type (T);
15585 Component : Entity_Id;
15586 P : Entity_Id;
15587 Candidate : Entity_Id := Empty;
15589 begin
15590 if Check and then Btype = Ancestor then
15591 Error_Msg_N ("circular type definition", Type_Id);
15592 return Any_Type;
15593 end if;
15595 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
15596 if Present (Full_View (Btype))
15597 and then Is_Record_Type (Full_View (Btype))
15598 and then not Is_Frozen (Btype)
15599 then
15600 -- To indicate that the ancestor depends on a private type, the
15601 -- current Btype is sufficient. However, to check for circular
15602 -- definition we must recurse on the full view.
15604 Candidate := Trace_Components (Full_View (Btype), True);
15606 if Candidate = Any_Type then
15607 return Any_Type;
15608 else
15609 return Btype;
15610 end if;
15612 else
15613 return Btype;
15614 end if;
15616 elsif Is_Array_Type (Btype) then
15617 return Trace_Components (Component_Type (Btype), True);
15619 elsif Is_Record_Type (Btype) then
15620 Component := First_Entity (Btype);
15621 while Present (Component)
15622 and then Comes_From_Source (Component)
15623 loop
15624 -- Skip anonymous types generated by constrained components
15626 if not Is_Type (Component) then
15627 P := Trace_Components (Etype (Component), True);
15629 if Present (P) then
15630 if P = Any_Type then
15631 return P;
15632 else
15633 Candidate := P;
15634 end if;
15635 end if;
15636 end if;
15638 Next_Entity (Component);
15639 end loop;
15641 return Candidate;
15643 else
15644 return Empty;
15645 end if;
15646 end Trace_Components;
15648 -- Start of processing for Private_Component
15650 begin
15651 return Trace_Components (Type_Id, False);
15652 end Private_Component;
15654 ---------------------------
15655 -- Primitive_Names_Match --
15656 ---------------------------
15658 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
15660 function Non_Internal_Name (E : Entity_Id) return Name_Id;
15661 -- Given an internal name, returns the corresponding non-internal name
15663 ------------------------
15664 -- Non_Internal_Name --
15665 ------------------------
15667 function Non_Internal_Name (E : Entity_Id) return Name_Id is
15668 begin
15669 Get_Name_String (Chars (E));
15670 Name_Len := Name_Len - 1;
15671 return Name_Find;
15672 end Non_Internal_Name;
15674 -- Start of processing for Primitive_Names_Match
15676 begin
15677 pragma Assert (Present (E1) and then Present (E2));
15679 return Chars (E1) = Chars (E2)
15680 or else
15681 (not Is_Internal_Name (Chars (E1))
15682 and then Is_Internal_Name (Chars (E2))
15683 and then Non_Internal_Name (E2) = Chars (E1))
15684 or else
15685 (not Is_Internal_Name (Chars (E2))
15686 and then Is_Internal_Name (Chars (E1))
15687 and then Non_Internal_Name (E1) = Chars (E2))
15688 or else
15689 (Is_Predefined_Dispatching_Operation (E1)
15690 and then Is_Predefined_Dispatching_Operation (E2)
15691 and then Same_TSS (E1, E2))
15692 or else
15693 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
15694 end Primitive_Names_Match;
15696 -----------------------
15697 -- Process_End_Label --
15698 -----------------------
15700 procedure Process_End_Label
15701 (N : Node_Id;
15702 Typ : Character;
15703 Ent : Entity_Id)
15705 Loc : Source_Ptr;
15706 Nam : Node_Id;
15707 Scop : Entity_Id;
15709 Label_Ref : Boolean;
15710 -- Set True if reference to end label itself is required
15712 Endl : Node_Id;
15713 -- Gets set to the operator symbol or identifier that references the
15714 -- entity Ent. For the child unit case, this is the identifier from the
15715 -- designator. For other cases, this is simply Endl.
15717 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
15718 -- N is an identifier node that appears as a parent unit reference in
15719 -- the case where Ent is a child unit. This procedure generates an
15720 -- appropriate cross-reference entry. E is the corresponding entity.
15722 -------------------------
15723 -- Generate_Parent_Ref --
15724 -------------------------
15726 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
15727 begin
15728 -- If names do not match, something weird, skip reference
15730 if Chars (E) = Chars (N) then
15732 -- Generate the reference. We do NOT consider this as a reference
15733 -- for unreferenced symbol purposes.
15735 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
15737 if Style_Check then
15738 Style.Check_Identifier (N, E);
15739 end if;
15740 end if;
15741 end Generate_Parent_Ref;
15743 -- Start of processing for Process_End_Label
15745 begin
15746 -- If no node, ignore. This happens in some error situations, and
15747 -- also for some internally generated structures where no end label
15748 -- references are required in any case.
15750 if No (N) then
15751 return;
15752 end if;
15754 -- Nothing to do if no End_Label, happens for internally generated
15755 -- constructs where we don't want an end label reference anyway. Also
15756 -- nothing to do if Endl is a string literal, which means there was
15757 -- some prior error (bad operator symbol)
15759 Endl := End_Label (N);
15761 if No (Endl) or else Nkind (Endl) = N_String_Literal then
15762 return;
15763 end if;
15765 -- Reference node is not in extended main source unit
15767 if not In_Extended_Main_Source_Unit (N) then
15769 -- Generally we do not collect references except for the extended
15770 -- main source unit. The one exception is the 'e' entry for a
15771 -- package spec, where it is useful for a client to have the
15772 -- ending information to define scopes.
15774 if Typ /= 'e' then
15775 return;
15777 else
15778 Label_Ref := False;
15780 -- For this case, we can ignore any parent references, but we
15781 -- need the package name itself for the 'e' entry.
15783 if Nkind (Endl) = N_Designator then
15784 Endl := Identifier (Endl);
15785 end if;
15786 end if;
15788 -- Reference is in extended main source unit
15790 else
15791 Label_Ref := True;
15793 -- For designator, generate references for the parent entries
15795 if Nkind (Endl) = N_Designator then
15797 -- Generate references for the prefix if the END line comes from
15798 -- source (otherwise we do not need these references) We climb the
15799 -- scope stack to find the expected entities.
15801 if Comes_From_Source (Endl) then
15802 Nam := Name (Endl);
15803 Scop := Current_Scope;
15804 while Nkind (Nam) = N_Selected_Component loop
15805 Scop := Scope (Scop);
15806 exit when No (Scop);
15807 Generate_Parent_Ref (Selector_Name (Nam), Scop);
15808 Nam := Prefix (Nam);
15809 end loop;
15811 if Present (Scop) then
15812 Generate_Parent_Ref (Nam, Scope (Scop));
15813 end if;
15814 end if;
15816 Endl := Identifier (Endl);
15817 end if;
15818 end if;
15820 -- If the end label is not for the given entity, then either we have
15821 -- some previous error, or this is a generic instantiation for which
15822 -- we do not need to make a cross-reference in this case anyway. In
15823 -- either case we simply ignore the call.
15825 if Chars (Ent) /= Chars (Endl) then
15826 return;
15827 end if;
15829 -- If label was really there, then generate a normal reference and then
15830 -- adjust the location in the end label to point past the name (which
15831 -- should almost always be the semicolon).
15833 Loc := Sloc (Endl);
15835 if Comes_From_Source (Endl) then
15837 -- If a label reference is required, then do the style check and
15838 -- generate an l-type cross-reference entry for the label
15840 if Label_Ref then
15841 if Style_Check then
15842 Style.Check_Identifier (Endl, Ent);
15843 end if;
15845 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
15846 end if;
15848 -- Set the location to point past the label (normally this will
15849 -- mean the semicolon immediately following the label). This is
15850 -- done for the sake of the 'e' or 't' entry generated below.
15852 Get_Decoded_Name_String (Chars (Endl));
15853 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
15855 else
15856 -- In SPARK mode, no missing label is allowed for packages and
15857 -- subprogram bodies. Detect those cases by testing whether
15858 -- Process_End_Label was called for a body (Typ = 't') or a package.
15860 if Restriction_Check_Required (SPARK_05)
15861 and then (Typ = 't' or else Ekind (Ent) = E_Package)
15862 then
15863 Error_Msg_Node_1 := Endl;
15864 Check_SPARK_05_Restriction
15865 ("`END &` required", Endl, Force => True);
15866 end if;
15867 end if;
15869 -- Now generate the e/t reference
15871 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
15873 -- Restore Sloc, in case modified above, since we have an identifier
15874 -- and the normal Sloc should be left set in the tree.
15876 Set_Sloc (Endl, Loc);
15877 end Process_End_Label;
15879 ----------------
15880 -- Referenced --
15881 ----------------
15883 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
15884 Seen : Boolean := False;
15886 function Is_Reference (N : Node_Id) return Traverse_Result;
15887 -- Determine whether node N denotes a reference to Id. If this is the
15888 -- case, set global flag Seen to True and stop the traversal.
15890 ------------------
15891 -- Is_Reference --
15892 ------------------
15894 function Is_Reference (N : Node_Id) return Traverse_Result is
15895 begin
15896 if Is_Entity_Name (N)
15897 and then Present (Entity (N))
15898 and then Entity (N) = Id
15899 then
15900 Seen := True;
15901 return Abandon;
15902 else
15903 return OK;
15904 end if;
15905 end Is_Reference;
15907 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
15909 -- Start of processing for Referenced
15911 begin
15912 Inspect_Expression (Expr);
15913 return Seen;
15914 end Referenced;
15916 ------------------------------------
15917 -- References_Generic_Formal_Type --
15918 ------------------------------------
15920 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
15922 function Process (N : Node_Id) return Traverse_Result;
15923 -- Process one node in search for generic formal type
15925 -------------
15926 -- Process --
15927 -------------
15929 function Process (N : Node_Id) return Traverse_Result is
15930 begin
15931 if Nkind (N) in N_Has_Entity then
15932 declare
15933 E : constant Entity_Id := Entity (N);
15934 begin
15935 if Present (E) then
15936 if Is_Generic_Type (E) then
15937 return Abandon;
15938 elsif Present (Etype (E))
15939 and then Is_Generic_Type (Etype (E))
15940 then
15941 return Abandon;
15942 end if;
15943 end if;
15944 end;
15945 end if;
15947 return Atree.OK;
15948 end Process;
15950 function Traverse is new Traverse_Func (Process);
15951 -- Traverse tree to look for generic type
15953 begin
15954 if Inside_A_Generic then
15955 return Traverse (N) = Abandon;
15956 else
15957 return False;
15958 end if;
15959 end References_Generic_Formal_Type;
15961 --------------------
15962 -- Remove_Homonym --
15963 --------------------
15965 procedure Remove_Homonym (E : Entity_Id) is
15966 Prev : Entity_Id := Empty;
15967 H : Entity_Id;
15969 begin
15970 if E = Current_Entity (E) then
15971 if Present (Homonym (E)) then
15972 Set_Current_Entity (Homonym (E));
15973 else
15974 Set_Name_Entity_Id (Chars (E), Empty);
15975 end if;
15977 else
15978 H := Current_Entity (E);
15979 while Present (H) and then H /= E loop
15980 Prev := H;
15981 H := Homonym (H);
15982 end loop;
15984 -- If E is not on the homonym chain, nothing to do
15986 if Present (H) then
15987 Set_Homonym (Prev, Homonym (E));
15988 end if;
15989 end if;
15990 end Remove_Homonym;
15992 ---------------------
15993 -- Rep_To_Pos_Flag --
15994 ---------------------
15996 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
15997 begin
15998 return New_Occurrence_Of
15999 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
16000 end Rep_To_Pos_Flag;
16002 --------------------
16003 -- Require_Entity --
16004 --------------------
16006 procedure Require_Entity (N : Node_Id) is
16007 begin
16008 if Is_Entity_Name (N) and then No (Entity (N)) then
16009 if Total_Errors_Detected /= 0 then
16010 Set_Entity (N, Any_Id);
16011 else
16012 raise Program_Error;
16013 end if;
16014 end if;
16015 end Require_Entity;
16017 -------------------------------
16018 -- Requires_State_Refinement --
16019 -------------------------------
16021 function Requires_State_Refinement
16022 (Spec_Id : Entity_Id;
16023 Body_Id : Entity_Id) return Boolean
16025 function Mode_Is_Off (Prag : Node_Id) return Boolean;
16026 -- Given pragma SPARK_Mode, determine whether the mode is Off
16028 -----------------
16029 -- Mode_Is_Off --
16030 -----------------
16032 function Mode_Is_Off (Prag : Node_Id) return Boolean is
16033 Mode : Node_Id;
16035 begin
16036 -- The default SPARK mode is On
16038 if No (Prag) then
16039 return False;
16040 end if;
16042 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
16044 -- Then the pragma lacks an argument, the default mode is On
16046 if No (Mode) then
16047 return False;
16048 else
16049 return Chars (Mode) = Name_Off;
16050 end if;
16051 end Mode_Is_Off;
16053 -- Start of processing for Requires_State_Refinement
16055 begin
16056 -- A package that does not define at least one abstract state cannot
16057 -- possibly require refinement.
16059 if No (Abstract_States (Spec_Id)) then
16060 return False;
16062 -- The package instroduces a single null state which does not merit
16063 -- refinement.
16065 elsif Has_Null_Abstract_State (Spec_Id) then
16066 return False;
16068 -- Check whether the package body is subject to pragma SPARK_Mode. If
16069 -- it is and the mode is Off, the package body is considered to be in
16070 -- regular Ada and does not require refinement.
16072 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
16073 return False;
16075 -- The body's SPARK_Mode may be inherited from a similar pragma that
16076 -- appears in the private declarations of the spec. The pragma we are
16077 -- interested appears as the second entry in SPARK_Pragma.
16079 elsif Present (SPARK_Pragma (Spec_Id))
16080 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
16081 then
16082 return False;
16084 -- The spec defines at least one abstract state and the body has no way
16085 -- of circumventing the refinement.
16087 else
16088 return True;
16089 end if;
16090 end Requires_State_Refinement;
16092 ------------------------------
16093 -- Requires_Transient_Scope --
16094 ------------------------------
16096 -- A transient scope is required when variable-sized temporaries are
16097 -- allocated in the primary or secondary stack, or when finalization
16098 -- actions must be generated before the next instruction.
16100 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
16101 Typ : constant Entity_Id := Underlying_Type (Id);
16103 -- Start of processing for Requires_Transient_Scope
16105 begin
16106 -- This is a private type which is not completed yet. This can only
16107 -- happen in a default expression (of a formal parameter or of a
16108 -- record component). Do not expand transient scope in this case
16110 if No (Typ) then
16111 return False;
16113 -- Do not expand transient scope for non-existent procedure return
16115 elsif Typ = Standard_Void_Type then
16116 return False;
16118 -- Elementary types do not require a transient scope
16120 elsif Is_Elementary_Type (Typ) then
16121 return False;
16123 -- Generally, indefinite subtypes require a transient scope, since the
16124 -- back end cannot generate temporaries, since this is not a valid type
16125 -- for declaring an object. It might be possible to relax this in the
16126 -- future, e.g. by declaring the maximum possible space for the type.
16128 elsif Is_Indefinite_Subtype (Typ) then
16129 return True;
16131 -- Functions returning tagged types may dispatch on result so their
16132 -- returned value is allocated on the secondary stack. Controlled
16133 -- type temporaries need finalization.
16135 elsif Is_Tagged_Type (Typ)
16136 or else Has_Controlled_Component (Typ)
16137 then
16138 return not Is_Value_Type (Typ);
16140 -- Record type
16142 elsif Is_Record_Type (Typ) then
16143 declare
16144 Comp : Entity_Id;
16145 begin
16146 Comp := First_Entity (Typ);
16147 while Present (Comp) loop
16148 if Ekind (Comp) = E_Component
16149 and then Requires_Transient_Scope (Etype (Comp))
16150 then
16151 return True;
16152 else
16153 Next_Entity (Comp);
16154 end if;
16155 end loop;
16156 end;
16158 return False;
16160 -- String literal types never require transient scope
16162 elsif Ekind (Typ) = E_String_Literal_Subtype then
16163 return False;
16165 -- Array type. Note that we already know that this is a constrained
16166 -- array, since unconstrained arrays will fail the indefinite test.
16168 elsif Is_Array_Type (Typ) then
16170 -- If component type requires a transient scope, the array does too
16172 if Requires_Transient_Scope (Component_Type (Typ)) then
16173 return True;
16175 -- Otherwise, we only need a transient scope if the size depends on
16176 -- the value of one or more discriminants.
16178 else
16179 return Size_Depends_On_Discriminant (Typ);
16180 end if;
16182 -- All other cases do not require a transient scope
16184 else
16185 return False;
16186 end if;
16187 end Requires_Transient_Scope;
16189 --------------------------
16190 -- Reset_Analyzed_Flags --
16191 --------------------------
16193 procedure Reset_Analyzed_Flags (N : Node_Id) is
16195 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
16196 -- Function used to reset Analyzed flags in tree. Note that we do
16197 -- not reset Analyzed flags in entities, since there is no need to
16198 -- reanalyze entities, and indeed, it is wrong to do so, since it
16199 -- can result in generating auxiliary stuff more than once.
16201 --------------------
16202 -- Clear_Analyzed --
16203 --------------------
16205 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
16206 begin
16207 if not Has_Extension (N) then
16208 Set_Analyzed (N, False);
16209 end if;
16211 return OK;
16212 end Clear_Analyzed;
16214 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
16216 -- Start of processing for Reset_Analyzed_Flags
16218 begin
16219 Reset_Analyzed (N);
16220 end Reset_Analyzed_Flags;
16222 ------------------------
16223 -- Restore_SPARK_Mode --
16224 ------------------------
16226 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
16227 begin
16228 SPARK_Mode := Mode;
16229 end Restore_SPARK_Mode;
16231 --------------------------------
16232 -- Returns_Unconstrained_Type --
16233 --------------------------------
16235 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
16236 begin
16237 return Ekind (Subp) = E_Function
16238 and then not Is_Scalar_Type (Etype (Subp))
16239 and then not Is_Access_Type (Etype (Subp))
16240 and then not Is_Constrained (Etype (Subp));
16241 end Returns_Unconstrained_Type;
16243 ----------------------------
16244 -- Root_Type_Of_Full_View --
16245 ----------------------------
16247 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
16248 Rtyp : constant Entity_Id := Root_Type (T);
16250 begin
16251 -- The root type of the full view may itself be a private type. Keep
16252 -- looking for the ultimate derivation parent.
16254 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
16255 return Root_Type_Of_Full_View (Full_View (Rtyp));
16256 else
16257 return Rtyp;
16258 end if;
16259 end Root_Type_Of_Full_View;
16261 ---------------------------
16262 -- Safe_To_Capture_Value --
16263 ---------------------------
16265 function Safe_To_Capture_Value
16266 (N : Node_Id;
16267 Ent : Entity_Id;
16268 Cond : Boolean := False) return Boolean
16270 begin
16271 -- The only entities for which we track constant values are variables
16272 -- which are not renamings, constants, out parameters, and in out
16273 -- parameters, so check if we have this case.
16275 -- Note: it may seem odd to track constant values for constants, but in
16276 -- fact this routine is used for other purposes than simply capturing
16277 -- the value. In particular, the setting of Known[_Non]_Null.
16279 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
16280 or else
16281 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
16282 then
16283 null;
16285 -- For conditionals, we also allow loop parameters and all formals,
16286 -- including in parameters.
16288 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
16289 null;
16291 -- For all other cases, not just unsafe, but impossible to capture
16292 -- Current_Value, since the above are the only entities which have
16293 -- Current_Value fields.
16295 else
16296 return False;
16297 end if;
16299 -- Skip if volatile or aliased, since funny things might be going on in
16300 -- these cases which we cannot necessarily track. Also skip any variable
16301 -- for which an address clause is given, or whose address is taken. Also
16302 -- never capture value of library level variables (an attempt to do so
16303 -- can occur in the case of package elaboration code).
16305 if Treat_As_Volatile (Ent)
16306 or else Is_Aliased (Ent)
16307 or else Present (Address_Clause (Ent))
16308 or else Address_Taken (Ent)
16309 or else (Is_Library_Level_Entity (Ent)
16310 and then Ekind (Ent) = E_Variable)
16311 then
16312 return False;
16313 end if;
16315 -- OK, all above conditions are met. We also require that the scope of
16316 -- the reference be the same as the scope of the entity, not counting
16317 -- packages and blocks and loops.
16319 declare
16320 E_Scope : constant Entity_Id := Scope (Ent);
16321 R_Scope : Entity_Id;
16323 begin
16324 R_Scope := Current_Scope;
16325 while R_Scope /= Standard_Standard loop
16326 exit when R_Scope = E_Scope;
16328 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
16329 return False;
16330 else
16331 R_Scope := Scope (R_Scope);
16332 end if;
16333 end loop;
16334 end;
16336 -- We also require that the reference does not appear in a context
16337 -- where it is not sure to be executed (i.e. a conditional context
16338 -- or an exception handler). We skip this if Cond is True, since the
16339 -- capturing of values from conditional tests handles this ok.
16341 if Cond then
16342 return True;
16343 end if;
16345 declare
16346 Desc : Node_Id;
16347 P : Node_Id;
16349 begin
16350 Desc := N;
16352 -- Seems dubious that case expressions are not handled here ???
16354 P := Parent (N);
16355 while Present (P) loop
16356 if Nkind (P) = N_If_Statement
16357 or else Nkind (P) = N_Case_Statement
16358 or else (Nkind (P) in N_Short_Circuit
16359 and then Desc = Right_Opnd (P))
16360 or else (Nkind (P) = N_If_Expression
16361 and then Desc /= First (Expressions (P)))
16362 or else Nkind (P) = N_Exception_Handler
16363 or else Nkind (P) = N_Selective_Accept
16364 or else Nkind (P) = N_Conditional_Entry_Call
16365 or else Nkind (P) = N_Timed_Entry_Call
16366 or else Nkind (P) = N_Asynchronous_Select
16367 then
16368 return False;
16370 else
16371 Desc := P;
16372 P := Parent (P);
16374 -- A special Ada 2012 case: the original node may be part
16375 -- of the else_actions of a conditional expression, in which
16376 -- case it might not have been expanded yet, and appears in
16377 -- a non-syntactic list of actions. In that case it is clearly
16378 -- not safe to save a value.
16380 if No (P)
16381 and then Is_List_Member (Desc)
16382 and then No (Parent (List_Containing (Desc)))
16383 then
16384 return False;
16385 end if;
16386 end if;
16387 end loop;
16388 end;
16390 -- OK, looks safe to set value
16392 return True;
16393 end Safe_To_Capture_Value;
16395 ---------------
16396 -- Same_Name --
16397 ---------------
16399 function Same_Name (N1, N2 : Node_Id) return Boolean is
16400 K1 : constant Node_Kind := Nkind (N1);
16401 K2 : constant Node_Kind := Nkind (N2);
16403 begin
16404 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
16405 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
16406 then
16407 return Chars (N1) = Chars (N2);
16409 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
16410 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
16411 then
16412 return Same_Name (Selector_Name (N1), Selector_Name (N2))
16413 and then Same_Name (Prefix (N1), Prefix (N2));
16415 else
16416 return False;
16417 end if;
16418 end Same_Name;
16420 -----------------
16421 -- Same_Object --
16422 -----------------
16424 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
16425 N1 : constant Node_Id := Original_Node (Node1);
16426 N2 : constant Node_Id := Original_Node (Node2);
16427 -- We do the tests on original nodes, since we are most interested
16428 -- in the original source, not any expansion that got in the way.
16430 K1 : constant Node_Kind := Nkind (N1);
16431 K2 : constant Node_Kind := Nkind (N2);
16433 begin
16434 -- First case, both are entities with same entity
16436 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
16437 declare
16438 EN1 : constant Entity_Id := Entity (N1);
16439 EN2 : constant Entity_Id := Entity (N2);
16440 begin
16441 if Present (EN1) and then Present (EN2)
16442 and then (Ekind_In (EN1, E_Variable, E_Constant)
16443 or else Is_Formal (EN1))
16444 and then EN1 = EN2
16445 then
16446 return True;
16447 end if;
16448 end;
16449 end if;
16451 -- Second case, selected component with same selector, same record
16453 if K1 = N_Selected_Component
16454 and then K2 = N_Selected_Component
16455 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
16456 then
16457 return Same_Object (Prefix (N1), Prefix (N2));
16459 -- Third case, indexed component with same subscripts, same array
16461 elsif K1 = N_Indexed_Component
16462 and then K2 = N_Indexed_Component
16463 and then Same_Object (Prefix (N1), Prefix (N2))
16464 then
16465 declare
16466 E1, E2 : Node_Id;
16467 begin
16468 E1 := First (Expressions (N1));
16469 E2 := First (Expressions (N2));
16470 while Present (E1) loop
16471 if not Same_Value (E1, E2) then
16472 return False;
16473 else
16474 Next (E1);
16475 Next (E2);
16476 end if;
16477 end loop;
16479 return True;
16480 end;
16482 -- Fourth case, slice of same array with same bounds
16484 elsif K1 = N_Slice
16485 and then K2 = N_Slice
16486 and then Nkind (Discrete_Range (N1)) = N_Range
16487 and then Nkind (Discrete_Range (N2)) = N_Range
16488 and then Same_Value (Low_Bound (Discrete_Range (N1)),
16489 Low_Bound (Discrete_Range (N2)))
16490 and then Same_Value (High_Bound (Discrete_Range (N1)),
16491 High_Bound (Discrete_Range (N2)))
16492 then
16493 return Same_Name (Prefix (N1), Prefix (N2));
16495 -- All other cases, not clearly the same object
16497 else
16498 return False;
16499 end if;
16500 end Same_Object;
16502 ---------------
16503 -- Same_Type --
16504 ---------------
16506 function Same_Type (T1, T2 : Entity_Id) return Boolean is
16507 begin
16508 if T1 = T2 then
16509 return True;
16511 elsif not Is_Constrained (T1)
16512 and then not Is_Constrained (T2)
16513 and then Base_Type (T1) = Base_Type (T2)
16514 then
16515 return True;
16517 -- For now don't bother with case of identical constraints, to be
16518 -- fiddled with later on perhaps (this is only used for optimization
16519 -- purposes, so it is not critical to do a best possible job)
16521 else
16522 return False;
16523 end if;
16524 end Same_Type;
16526 ----------------
16527 -- Same_Value --
16528 ----------------
16530 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
16531 begin
16532 if Compile_Time_Known_Value (Node1)
16533 and then Compile_Time_Known_Value (Node2)
16534 and then Expr_Value (Node1) = Expr_Value (Node2)
16535 then
16536 return True;
16537 elsif Same_Object (Node1, Node2) then
16538 return True;
16539 else
16540 return False;
16541 end if;
16542 end Same_Value;
16544 -----------------------------
16545 -- Save_SPARK_Mode_And_Set --
16546 -----------------------------
16548 procedure Save_SPARK_Mode_And_Set
16549 (Context : Entity_Id;
16550 Mode : out SPARK_Mode_Type)
16552 begin
16553 -- Save the current mode in effect
16555 Mode := SPARK_Mode;
16557 -- Do not consider illegal or partially decorated constructs
16559 if Ekind (Context) = E_Void or else Error_Posted (Context) then
16560 null;
16562 elsif Present (SPARK_Pragma (Context)) then
16563 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
16564 end if;
16565 end Save_SPARK_Mode_And_Set;
16567 -------------------------
16568 -- Scalar_Part_Present --
16569 -------------------------
16571 function Scalar_Part_Present (T : Entity_Id) return Boolean is
16572 C : Entity_Id;
16574 begin
16575 if Is_Scalar_Type (T) then
16576 return True;
16578 elsif Is_Array_Type (T) then
16579 return Scalar_Part_Present (Component_Type (T));
16581 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
16582 C := First_Component_Or_Discriminant (T);
16583 while Present (C) loop
16584 if Scalar_Part_Present (Etype (C)) then
16585 return True;
16586 else
16587 Next_Component_Or_Discriminant (C);
16588 end if;
16589 end loop;
16590 end if;
16592 return False;
16593 end Scalar_Part_Present;
16595 ------------------------
16596 -- Scope_Is_Transient --
16597 ------------------------
16599 function Scope_Is_Transient return Boolean is
16600 begin
16601 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
16602 end Scope_Is_Transient;
16604 ------------------
16605 -- Scope_Within --
16606 ------------------
16608 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
16609 Scop : Entity_Id;
16611 begin
16612 Scop := Scope1;
16613 while Scop /= Standard_Standard loop
16614 Scop := Scope (Scop);
16616 if Scop = Scope2 then
16617 return True;
16618 end if;
16619 end loop;
16621 return False;
16622 end Scope_Within;
16624 --------------------------
16625 -- Scope_Within_Or_Same --
16626 --------------------------
16628 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
16629 Scop : Entity_Id;
16631 begin
16632 Scop := Scope1;
16633 while Scop /= Standard_Standard loop
16634 if Scop = Scope2 then
16635 return True;
16636 else
16637 Scop := Scope (Scop);
16638 end if;
16639 end loop;
16641 return False;
16642 end Scope_Within_Or_Same;
16644 --------------------
16645 -- Set_Convention --
16646 --------------------
16648 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
16649 begin
16650 Basic_Set_Convention (E, Val);
16652 if Is_Type (E)
16653 and then Is_Access_Subprogram_Type (Base_Type (E))
16654 and then Has_Foreign_Convention (E)
16655 then
16656 Set_Can_Use_Internal_Rep (E, False);
16657 end if;
16659 -- If E is an object or component, and the type of E is an anonymous
16660 -- access type with no convention set, then also set the convention of
16661 -- the anonymous access type. We do not do this for anonymous protected
16662 -- types, since protected types always have the default convention.
16664 if Present (Etype (E))
16665 and then (Is_Object (E)
16666 or else Ekind (E) = E_Component
16668 -- Allow E_Void (happens for pragma Convention appearing
16669 -- in the middle of a record applying to a component)
16671 or else Ekind (E) = E_Void)
16672 then
16673 declare
16674 Typ : constant Entity_Id := Etype (E);
16676 begin
16677 if Ekind_In (Typ, E_Anonymous_Access_Type,
16678 E_Anonymous_Access_Subprogram_Type)
16679 and then not Has_Convention_Pragma (Typ)
16680 then
16681 Basic_Set_Convention (Typ, Val);
16682 Set_Has_Convention_Pragma (Typ);
16684 -- And for the access subprogram type, deal similarly with the
16685 -- designated E_Subprogram_Type if it is also internal (which
16686 -- it always is?)
16688 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
16689 declare
16690 Dtype : constant Entity_Id := Designated_Type (Typ);
16691 begin
16692 if Ekind (Dtype) = E_Subprogram_Type
16693 and then Is_Itype (Dtype)
16694 and then not Has_Convention_Pragma (Dtype)
16695 then
16696 Basic_Set_Convention (Dtype, Val);
16697 Set_Has_Convention_Pragma (Dtype);
16698 end if;
16699 end;
16700 end if;
16701 end if;
16702 end;
16703 end if;
16704 end Set_Convention;
16706 ------------------------
16707 -- Set_Current_Entity --
16708 ------------------------
16710 -- The given entity is to be set as the currently visible definition of its
16711 -- associated name (i.e. the Node_Id associated with its name). All we have
16712 -- to do is to get the name from the identifier, and then set the
16713 -- associated Node_Id to point to the given entity.
16715 procedure Set_Current_Entity (E : Entity_Id) is
16716 begin
16717 Set_Name_Entity_Id (Chars (E), E);
16718 end Set_Current_Entity;
16720 ---------------------------
16721 -- Set_Debug_Info_Needed --
16722 ---------------------------
16724 procedure Set_Debug_Info_Needed (T : Entity_Id) is
16726 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
16727 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
16728 -- Used to set debug info in a related node if not set already
16730 --------------------------------------
16731 -- Set_Debug_Info_Needed_If_Not_Set --
16732 --------------------------------------
16734 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
16735 begin
16736 if Present (E) and then not Needs_Debug_Info (E) then
16737 Set_Debug_Info_Needed (E);
16739 -- For a private type, indicate that the full view also needs
16740 -- debug information.
16742 if Is_Type (E)
16743 and then Is_Private_Type (E)
16744 and then Present (Full_View (E))
16745 then
16746 Set_Debug_Info_Needed (Full_View (E));
16747 end if;
16748 end if;
16749 end Set_Debug_Info_Needed_If_Not_Set;
16751 -- Start of processing for Set_Debug_Info_Needed
16753 begin
16754 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16755 -- indicates that Debug_Info_Needed is never required for the entity.
16756 -- Nothing to do if entity comes from a predefined file. Library files
16757 -- are compiled without debug information, but inlined bodies of these
16758 -- routines may appear in user code, and debug information on them ends
16759 -- up complicating debugging the user code.
16761 if No (T)
16762 or else Debug_Info_Off (T)
16763 then
16764 return;
16766 elsif In_Inlined_Body
16767 and then Is_Predefined_File_Name
16768 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
16769 then
16770 Set_Needs_Debug_Info (T, False);
16771 end if;
16773 -- Set flag in entity itself. Note that we will go through the following
16774 -- circuitry even if the flag is already set on T. That's intentional,
16775 -- it makes sure that the flag will be set in subsidiary entities.
16777 Set_Needs_Debug_Info (T);
16779 -- Set flag on subsidiary entities if not set already
16781 if Is_Object (T) then
16782 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
16784 elsif Is_Type (T) then
16785 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
16787 if Is_Record_Type (T) then
16788 declare
16789 Ent : Entity_Id := First_Entity (T);
16790 begin
16791 while Present (Ent) loop
16792 Set_Debug_Info_Needed_If_Not_Set (Ent);
16793 Next_Entity (Ent);
16794 end loop;
16795 end;
16797 -- For a class wide subtype, we also need debug information
16798 -- for the equivalent type.
16800 if Ekind (T) = E_Class_Wide_Subtype then
16801 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
16802 end if;
16804 elsif Is_Array_Type (T) then
16805 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
16807 declare
16808 Indx : Node_Id := First_Index (T);
16809 begin
16810 while Present (Indx) loop
16811 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
16812 Indx := Next_Index (Indx);
16813 end loop;
16814 end;
16816 -- For a packed array type, we also need debug information for
16817 -- the type used to represent the packed array. Conversely, we
16818 -- also need it for the former if we need it for the latter.
16820 if Is_Packed (T) then
16821 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
16822 end if;
16824 if Is_Packed_Array_Impl_Type (T) then
16825 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
16826 end if;
16828 elsif Is_Access_Type (T) then
16829 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
16831 elsif Is_Private_Type (T) then
16832 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
16834 elsif Is_Protected_Type (T) then
16835 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
16837 elsif Is_Scalar_Type (T) then
16839 -- If the subrange bounds are materialized by dedicated constant
16840 -- objects, also include them in the debug info to make sure the
16841 -- debugger can properly use them.
16843 if Present (Scalar_Range (T))
16844 and then Nkind (Scalar_Range (T)) = N_Range
16845 then
16846 declare
16847 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
16848 High_Bnd : constant Node_Id := Type_High_Bound (T);
16850 begin
16851 if Is_Entity_Name (Low_Bnd) then
16852 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
16853 end if;
16855 if Is_Entity_Name (High_Bnd) then
16856 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
16857 end if;
16858 end;
16859 end if;
16860 end if;
16861 end if;
16862 end Set_Debug_Info_Needed;
16864 ----------------------------
16865 -- Set_Entity_With_Checks --
16866 ----------------------------
16868 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
16869 Val_Actual : Entity_Id;
16870 Nod : Node_Id;
16871 Post_Node : Node_Id;
16873 begin
16874 -- Unconditionally set the entity
16876 Set_Entity (N, Val);
16878 -- The node to post on is the selector in the case of an expanded name,
16879 -- and otherwise the node itself.
16881 if Nkind (N) = N_Expanded_Name then
16882 Post_Node := Selector_Name (N);
16883 else
16884 Post_Node := N;
16885 end if;
16887 -- Check for violation of No_Fixed_IO
16889 if Restriction_Check_Required (No_Fixed_IO)
16890 and then
16891 ((RTU_Loaded (Ada_Text_IO)
16892 and then (Is_RTE (Val, RE_Decimal_IO)
16893 or else
16894 Is_RTE (Val, RE_Fixed_IO)))
16896 or else
16897 (RTU_Loaded (Ada_Wide_Text_IO)
16898 and then (Is_RTE (Val, RO_WT_Decimal_IO)
16899 or else
16900 Is_RTE (Val, RO_WT_Fixed_IO)))
16902 or else
16903 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
16904 and then (Is_RTE (Val, RO_WW_Decimal_IO)
16905 or else
16906 Is_RTE (Val, RO_WW_Fixed_IO))))
16908 -- A special extra check, don't complain about a reference from within
16909 -- the Ada.Interrupts package itself!
16911 and then not In_Same_Extended_Unit (N, Val)
16912 then
16913 Check_Restriction (No_Fixed_IO, Post_Node);
16914 end if;
16916 -- Remaining checks are only done on source nodes. Note that we test
16917 -- for violation of No_Fixed_IO even on non-source nodes, because the
16918 -- cases for checking violations of this restriction are instantiations
16919 -- where the reference in the instance has Comes_From_Source False.
16921 if not Comes_From_Source (N) then
16922 return;
16923 end if;
16925 -- Check for violation of No_Abort_Statements, which is triggered by
16926 -- call to Ada.Task_Identification.Abort_Task.
16928 if Restriction_Check_Required (No_Abort_Statements)
16929 and then (Is_RTE (Val, RE_Abort_Task))
16931 -- A special extra check, don't complain about a reference from within
16932 -- the Ada.Task_Identification package itself!
16934 and then not In_Same_Extended_Unit (N, Val)
16935 then
16936 Check_Restriction (No_Abort_Statements, Post_Node);
16937 end if;
16939 if Val = Standard_Long_Long_Integer then
16940 Check_Restriction (No_Long_Long_Integers, Post_Node);
16941 end if;
16943 -- Check for violation of No_Dynamic_Attachment
16945 if Restriction_Check_Required (No_Dynamic_Attachment)
16946 and then RTU_Loaded (Ada_Interrupts)
16947 and then (Is_RTE (Val, RE_Is_Reserved) or else
16948 Is_RTE (Val, RE_Is_Attached) or else
16949 Is_RTE (Val, RE_Current_Handler) or else
16950 Is_RTE (Val, RE_Attach_Handler) or else
16951 Is_RTE (Val, RE_Exchange_Handler) or else
16952 Is_RTE (Val, RE_Detach_Handler) or else
16953 Is_RTE (Val, RE_Reference))
16955 -- A special extra check, don't complain about a reference from within
16956 -- the Ada.Interrupts package itself!
16958 and then not In_Same_Extended_Unit (N, Val)
16959 then
16960 Check_Restriction (No_Dynamic_Attachment, Post_Node);
16961 end if;
16963 -- Check for No_Implementation_Identifiers
16965 if Restriction_Check_Required (No_Implementation_Identifiers) then
16967 -- We have an implementation defined entity if it is marked as
16968 -- implementation defined, or is defined in a package marked as
16969 -- implementation defined. However, library packages themselves
16970 -- are excluded (we don't want to flag Interfaces itself, just
16971 -- the entities within it).
16973 if (Is_Implementation_Defined (Val)
16974 or else
16975 (Present (Scope (Val))
16976 and then Is_Implementation_Defined (Scope (Val))))
16977 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
16978 and then Is_Library_Level_Entity (Val))
16979 then
16980 Check_Restriction (No_Implementation_Identifiers, Post_Node);
16981 end if;
16982 end if;
16984 -- Do the style check
16986 if Style_Check
16987 and then not Suppress_Style_Checks (Val)
16988 and then not In_Instance
16989 then
16990 if Nkind (N) = N_Identifier then
16991 Nod := N;
16992 elsif Nkind (N) = N_Expanded_Name then
16993 Nod := Selector_Name (N);
16994 else
16995 return;
16996 end if;
16998 -- A special situation arises for derived operations, where we want
16999 -- to do the check against the parent (since the Sloc of the derived
17000 -- operation points to the derived type declaration itself).
17002 Val_Actual := Val;
17003 while not Comes_From_Source (Val_Actual)
17004 and then Nkind (Val_Actual) in N_Entity
17005 and then (Ekind (Val_Actual) = E_Enumeration_Literal
17006 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
17007 and then Present (Alias (Val_Actual))
17008 loop
17009 Val_Actual := Alias (Val_Actual);
17010 end loop;
17012 -- Renaming declarations for generic actuals do not come from source,
17013 -- and have a different name from that of the entity they rename, so
17014 -- there is no style check to perform here.
17016 if Chars (Nod) = Chars (Val_Actual) then
17017 Style.Check_Identifier (Nod, Val_Actual);
17018 end if;
17019 end if;
17021 Set_Entity (N, Val);
17022 end Set_Entity_With_Checks;
17024 ------------------------
17025 -- Set_Name_Entity_Id --
17026 ------------------------
17028 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
17029 begin
17030 Set_Name_Table_Int (Id, Int (Val));
17031 end Set_Name_Entity_Id;
17033 ---------------------
17034 -- Set_Next_Actual --
17035 ---------------------
17037 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
17038 begin
17039 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
17040 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
17041 end if;
17042 end Set_Next_Actual;
17044 ----------------------------------
17045 -- Set_Optimize_Alignment_Flags --
17046 ----------------------------------
17048 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
17049 begin
17050 if Optimize_Alignment = 'S' then
17051 Set_Optimize_Alignment_Space (E);
17052 elsif Optimize_Alignment = 'T' then
17053 Set_Optimize_Alignment_Time (E);
17054 end if;
17055 end Set_Optimize_Alignment_Flags;
17057 -----------------------
17058 -- Set_Public_Status --
17059 -----------------------
17061 procedure Set_Public_Status (Id : Entity_Id) is
17062 S : constant Entity_Id := Current_Scope;
17064 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
17065 -- Determines if E is defined within handled statement sequence or
17066 -- an if statement, returns True if so, False otherwise.
17068 ----------------------
17069 -- Within_HSS_Or_If --
17070 ----------------------
17072 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
17073 N : Node_Id;
17074 begin
17075 N := Declaration_Node (E);
17076 loop
17077 N := Parent (N);
17079 if No (N) then
17080 return False;
17082 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
17083 N_If_Statement)
17084 then
17085 return True;
17086 end if;
17087 end loop;
17088 end Within_HSS_Or_If;
17090 -- Start of processing for Set_Public_Status
17092 begin
17093 -- Everything in the scope of Standard is public
17095 if S = Standard_Standard then
17096 Set_Is_Public (Id);
17098 -- Entity is definitely not public if enclosing scope is not public
17100 elsif not Is_Public (S) then
17101 return;
17103 -- An object or function declaration that occurs in a handled sequence
17104 -- of statements or within an if statement is the declaration for a
17105 -- temporary object or local subprogram generated by the expander. It
17106 -- never needs to be made public and furthermore, making it public can
17107 -- cause back end problems.
17109 elsif Nkind_In (Parent (Id), N_Object_Declaration,
17110 N_Function_Specification)
17111 and then Within_HSS_Or_If (Id)
17112 then
17113 return;
17115 -- Entities in public packages or records are public
17117 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
17118 Set_Is_Public (Id);
17120 -- The bounds of an entry family declaration can generate object
17121 -- declarations that are visible to the back-end, e.g. in the
17122 -- the declaration of a composite type that contains tasks.
17124 elsif Is_Concurrent_Type (S)
17125 and then not Has_Completion (S)
17126 and then Nkind (Parent (Id)) = N_Object_Declaration
17127 then
17128 Set_Is_Public (Id);
17129 end if;
17130 end Set_Public_Status;
17132 -----------------------------
17133 -- Set_Referenced_Modified --
17134 -----------------------------
17136 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
17137 Pref : Node_Id;
17139 begin
17140 -- Deal with indexed or selected component where prefix is modified
17142 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
17143 Pref := Prefix (N);
17145 -- If prefix is access type, then it is the designated object that is
17146 -- being modified, which means we have no entity to set the flag on.
17148 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
17149 return;
17151 -- Otherwise chase the prefix
17153 else
17154 Set_Referenced_Modified (Pref, Out_Param);
17155 end if;
17157 -- Otherwise see if we have an entity name (only other case to process)
17159 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17160 Set_Referenced_As_LHS (Entity (N), not Out_Param);
17161 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
17162 end if;
17163 end Set_Referenced_Modified;
17165 ----------------------------
17166 -- Set_Scope_Is_Transient --
17167 ----------------------------
17169 procedure Set_Scope_Is_Transient (V : Boolean := True) is
17170 begin
17171 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
17172 end Set_Scope_Is_Transient;
17174 -------------------
17175 -- Set_Size_Info --
17176 -------------------
17178 procedure Set_Size_Info (T1, T2 : Entity_Id) is
17179 begin
17180 -- We copy Esize, but not RM_Size, since in general RM_Size is
17181 -- subtype specific and does not get inherited by all subtypes.
17183 Set_Esize (T1, Esize (T2));
17184 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
17186 if Is_Discrete_Or_Fixed_Point_Type (T1)
17187 and then
17188 Is_Discrete_Or_Fixed_Point_Type (T2)
17189 then
17190 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
17191 end if;
17193 Set_Alignment (T1, Alignment (T2));
17194 end Set_Size_Info;
17196 --------------------
17197 -- Static_Boolean --
17198 --------------------
17200 function Static_Boolean (N : Node_Id) return Uint is
17201 begin
17202 Analyze_And_Resolve (N, Standard_Boolean);
17204 if N = Error
17205 or else Error_Posted (N)
17206 or else Etype (N) = Any_Type
17207 then
17208 return No_Uint;
17209 end if;
17211 if Is_OK_Static_Expression (N) then
17212 if not Raises_Constraint_Error (N) then
17213 return Expr_Value (N);
17214 else
17215 return No_Uint;
17216 end if;
17218 elsif Etype (N) = Any_Type then
17219 return No_Uint;
17221 else
17222 Flag_Non_Static_Expr
17223 ("static boolean expression required here", N);
17224 return No_Uint;
17225 end if;
17226 end Static_Boolean;
17228 --------------------
17229 -- Static_Integer --
17230 --------------------
17232 function Static_Integer (N : Node_Id) return Uint is
17233 begin
17234 Analyze_And_Resolve (N, Any_Integer);
17236 if N = Error
17237 or else Error_Posted (N)
17238 or else Etype (N) = Any_Type
17239 then
17240 return No_Uint;
17241 end if;
17243 if Is_OK_Static_Expression (N) then
17244 if not Raises_Constraint_Error (N) then
17245 return Expr_Value (N);
17246 else
17247 return No_Uint;
17248 end if;
17250 elsif Etype (N) = Any_Type then
17251 return No_Uint;
17253 else
17254 Flag_Non_Static_Expr
17255 ("static integer expression required here", N);
17256 return No_Uint;
17257 end if;
17258 end Static_Integer;
17260 --------------------------
17261 -- Statically_Different --
17262 --------------------------
17264 function Statically_Different (E1, E2 : Node_Id) return Boolean is
17265 R1 : constant Node_Id := Get_Referenced_Object (E1);
17266 R2 : constant Node_Id := Get_Referenced_Object (E2);
17267 begin
17268 return Is_Entity_Name (R1)
17269 and then Is_Entity_Name (R2)
17270 and then Entity (R1) /= Entity (R2)
17271 and then not Is_Formal (Entity (R1))
17272 and then not Is_Formal (Entity (R2));
17273 end Statically_Different;
17275 --------------------------------------
17276 -- Subject_To_Loop_Entry_Attributes --
17277 --------------------------------------
17279 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
17280 Stmt : Node_Id;
17282 begin
17283 Stmt := N;
17285 -- The expansion mechanism transform a loop subject to at least one
17286 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
17287 -- the conditional part.
17289 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
17290 and then Nkind (Original_Node (N)) = N_Loop_Statement
17291 then
17292 Stmt := Original_Node (N);
17293 end if;
17295 return
17296 Nkind (Stmt) = N_Loop_Statement
17297 and then Present (Identifier (Stmt))
17298 and then Present (Entity (Identifier (Stmt)))
17299 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
17300 end Subject_To_Loop_Entry_Attributes;
17302 -----------------------------
17303 -- Subprogram_Access_Level --
17304 -----------------------------
17306 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
17307 begin
17308 if Present (Alias (Subp)) then
17309 return Subprogram_Access_Level (Alias (Subp));
17310 else
17311 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
17312 end if;
17313 end Subprogram_Access_Level;
17315 -------------------------------
17316 -- Support_Atomic_Primitives --
17317 -------------------------------
17319 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
17320 Size : Int;
17322 begin
17323 -- Verify the alignment of Typ is known
17325 if not Known_Alignment (Typ) then
17326 return False;
17327 end if;
17329 if Known_Static_Esize (Typ) then
17330 Size := UI_To_Int (Esize (Typ));
17332 -- If the Esize (Object_Size) is unknown at compile time, look at the
17333 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
17335 elsif Known_Static_RM_Size (Typ) then
17336 Size := UI_To_Int (RM_Size (Typ));
17338 -- Otherwise, the size is considered to be unknown.
17340 else
17341 return False;
17342 end if;
17344 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
17345 -- Typ is properly aligned.
17347 case Size is
17348 when 8 | 16 | 32 | 64 =>
17349 return Size = UI_To_Int (Alignment (Typ)) * 8;
17350 when others =>
17351 return False;
17352 end case;
17353 end Support_Atomic_Primitives;
17355 -----------------
17356 -- Trace_Scope --
17357 -----------------
17359 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
17360 begin
17361 if Debug_Flag_W then
17362 for J in 0 .. Scope_Stack.Last loop
17363 Write_Str (" ");
17364 end loop;
17366 Write_Str (Msg);
17367 Write_Name (Chars (E));
17368 Write_Str (" from ");
17369 Write_Location (Sloc (N));
17370 Write_Eol;
17371 end if;
17372 end Trace_Scope;
17374 -----------------------
17375 -- Transfer_Entities --
17376 -----------------------
17378 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
17379 procedure Set_Public_Status_Of (Id : Entity_Id);
17380 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
17381 -- Set_Public_Status. If successfull and Id denotes a record type, set
17382 -- the Is_Public attribute of its fields.
17384 --------------------------
17385 -- Set_Public_Status_Of --
17386 --------------------------
17388 procedure Set_Public_Status_Of (Id : Entity_Id) is
17389 Field : Entity_Id;
17391 begin
17392 if not Is_Public (Id) then
17393 Set_Public_Status (Id);
17395 -- When the input entity is a public record type, ensure that all
17396 -- its internal fields are also exposed to the linker. The fields
17397 -- of a class-wide type are never made public.
17399 if Is_Public (Id)
17400 and then Is_Record_Type (Id)
17401 and then not Is_Class_Wide_Type (Id)
17402 then
17403 Field := First_Entity (Id);
17404 while Present (Field) loop
17405 Set_Is_Public (Field);
17406 Next_Entity (Field);
17407 end loop;
17408 end if;
17409 end if;
17410 end Set_Public_Status_Of;
17412 -- Local variables
17414 Full_Id : Entity_Id;
17415 Id : Entity_Id;
17417 -- Start of processing for Transfer_Entities
17419 begin
17420 Id := First_Entity (From);
17422 if Present (Id) then
17424 -- Merge the entity chain of the source scope with that of the
17425 -- destination scope.
17427 if Present (Last_Entity (To)) then
17428 Set_Next_Entity (Last_Entity (To), Id);
17429 else
17430 Set_First_Entity (To, Id);
17431 end if;
17433 Set_Last_Entity (To, Last_Entity (From));
17435 -- Inspect the entities of the source scope and update their Scope
17436 -- attribute.
17438 while Present (Id) loop
17439 Set_Scope (Id, To);
17440 Set_Public_Status_Of (Id);
17442 -- Handle an internally generated full view for a private type
17444 if Is_Private_Type (Id)
17445 and then Present (Full_View (Id))
17446 and then Is_Itype (Full_View (Id))
17447 then
17448 Full_Id := Full_View (Id);
17450 Set_Scope (Full_Id, To);
17451 Set_Public_Status_Of (Full_Id);
17452 end if;
17454 Next_Entity (Id);
17455 end loop;
17457 Set_First_Entity (From, Empty);
17458 Set_Last_Entity (From, Empty);
17459 end if;
17460 end Transfer_Entities;
17462 -----------------------
17463 -- Type_Access_Level --
17464 -----------------------
17466 function Type_Access_Level (Typ : Entity_Id) return Uint is
17467 Btyp : Entity_Id;
17469 begin
17470 Btyp := Base_Type (Typ);
17472 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
17473 -- simply use the level where the type is declared. This is true for
17474 -- stand-alone object declarations, and for anonymous access types
17475 -- associated with components the level is the same as that of the
17476 -- enclosing composite type. However, special treatment is needed for
17477 -- the cases of access parameters, return objects of an anonymous access
17478 -- type, and, in Ada 95, access discriminants of limited types.
17480 if Is_Access_Type (Btyp) then
17481 if Ekind (Btyp) = E_Anonymous_Access_Type then
17483 -- If the type is a nonlocal anonymous access type (such as for
17484 -- an access parameter) we treat it as being declared at the
17485 -- library level to ensure that names such as X.all'access don't
17486 -- fail static accessibility checks.
17488 if not Is_Local_Anonymous_Access (Typ) then
17489 return Scope_Depth (Standard_Standard);
17491 -- If this is a return object, the accessibility level is that of
17492 -- the result subtype of the enclosing function. The test here is
17493 -- little complicated, because we have to account for extended
17494 -- return statements that have been rewritten as blocks, in which
17495 -- case we have to find and the Is_Return_Object attribute of the
17496 -- itype's associated object. It would be nice to find a way to
17497 -- simplify this test, but it doesn't seem worthwhile to add a new
17498 -- flag just for purposes of this test. ???
17500 elsif Ekind (Scope (Btyp)) = E_Return_Statement
17501 or else
17502 (Is_Itype (Btyp)
17503 and then Nkind (Associated_Node_For_Itype (Btyp)) =
17504 N_Object_Declaration
17505 and then Is_Return_Object
17506 (Defining_Identifier
17507 (Associated_Node_For_Itype (Btyp))))
17508 then
17509 declare
17510 Scop : Entity_Id;
17512 begin
17513 Scop := Scope (Scope (Btyp));
17514 while Present (Scop) loop
17515 exit when Ekind (Scop) = E_Function;
17516 Scop := Scope (Scop);
17517 end loop;
17519 -- Treat the return object's type as having the level of the
17520 -- function's result subtype (as per RM05-6.5(5.3/2)).
17522 return Type_Access_Level (Etype (Scop));
17523 end;
17524 end if;
17525 end if;
17527 Btyp := Root_Type (Btyp);
17529 -- The accessibility level of anonymous access types associated with
17530 -- discriminants is that of the current instance of the type, and
17531 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
17533 -- AI-402: access discriminants have accessibility based on the
17534 -- object rather than the type in Ada 2005, so the above paragraph
17535 -- doesn't apply.
17537 -- ??? Needs completion with rules from AI-416
17539 if Ada_Version <= Ada_95
17540 and then Ekind (Typ) = E_Anonymous_Access_Type
17541 and then Present (Associated_Node_For_Itype (Typ))
17542 and then Nkind (Associated_Node_For_Itype (Typ)) =
17543 N_Discriminant_Specification
17544 then
17545 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
17546 end if;
17547 end if;
17549 -- Return library level for a generic formal type. This is done because
17550 -- RM(10.3.2) says that "The statically deeper relationship does not
17551 -- apply to ... a descendant of a generic formal type". Rather than
17552 -- checking at each point where a static accessibility check is
17553 -- performed to see if we are dealing with a formal type, this rule is
17554 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
17555 -- return extreme values for a formal type; Deepest_Type_Access_Level
17556 -- returns Int'Last. By calling the appropriate function from among the
17557 -- two, we ensure that the static accessibility check will pass if we
17558 -- happen to run into a formal type. More specifically, we should call
17559 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
17560 -- call occurs as part of a static accessibility check and the error
17561 -- case is the case where the type's level is too shallow (as opposed
17562 -- to too deep).
17564 if Is_Generic_Type (Root_Type (Btyp)) then
17565 return Scope_Depth (Standard_Standard);
17566 end if;
17568 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
17569 end Type_Access_Level;
17571 ------------------------------------
17572 -- Type_Without_Stream_Operation --
17573 ------------------------------------
17575 function Type_Without_Stream_Operation
17576 (T : Entity_Id;
17577 Op : TSS_Name_Type := TSS_Null) return Entity_Id
17579 BT : constant Entity_Id := Base_Type (T);
17580 Op_Missing : Boolean;
17582 begin
17583 if not Restriction_Active (No_Default_Stream_Attributes) then
17584 return Empty;
17585 end if;
17587 if Is_Elementary_Type (T) then
17588 if Op = TSS_Null then
17589 Op_Missing :=
17590 No (TSS (BT, TSS_Stream_Read))
17591 or else No (TSS (BT, TSS_Stream_Write));
17593 else
17594 Op_Missing := No (TSS (BT, Op));
17595 end if;
17597 if Op_Missing then
17598 return T;
17599 else
17600 return Empty;
17601 end if;
17603 elsif Is_Array_Type (T) then
17604 return Type_Without_Stream_Operation (Component_Type (T), Op);
17606 elsif Is_Record_Type (T) then
17607 declare
17608 Comp : Entity_Id;
17609 C_Typ : Entity_Id;
17611 begin
17612 Comp := First_Component (T);
17613 while Present (Comp) loop
17614 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
17616 if Present (C_Typ) then
17617 return C_Typ;
17618 end if;
17620 Next_Component (Comp);
17621 end loop;
17623 return Empty;
17624 end;
17626 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
17627 return Type_Without_Stream_Operation (Full_View (T), Op);
17628 else
17629 return Empty;
17630 end if;
17631 end Type_Without_Stream_Operation;
17633 ----------------------------
17634 -- Unique_Defining_Entity --
17635 ----------------------------
17637 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
17638 begin
17639 return Unique_Entity (Defining_Entity (N));
17640 end Unique_Defining_Entity;
17642 -------------------
17643 -- Unique_Entity --
17644 -------------------
17646 function Unique_Entity (E : Entity_Id) return Entity_Id is
17647 U : Entity_Id := E;
17648 P : Node_Id;
17650 begin
17651 case Ekind (E) is
17652 when E_Constant =>
17653 if Present (Full_View (E)) then
17654 U := Full_View (E);
17655 end if;
17657 when Type_Kind =>
17658 if Present (Full_View (E)) then
17659 U := Full_View (E);
17660 end if;
17662 when E_Package_Body =>
17663 P := Parent (E);
17665 if Nkind (P) = N_Defining_Program_Unit_Name then
17666 P := Parent (P);
17667 end if;
17669 U := Corresponding_Spec (P);
17671 when E_Subprogram_Body =>
17672 P := Parent (E);
17674 if Nkind (P) = N_Defining_Program_Unit_Name then
17675 P := Parent (P);
17676 end if;
17678 P := Parent (P);
17680 if Nkind (P) = N_Subprogram_Body_Stub then
17681 if Present (Library_Unit (P)) then
17683 -- Get to the function or procedure (generic) entity through
17684 -- the body entity.
17686 U :=
17687 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
17688 end if;
17689 else
17690 U := Corresponding_Spec (P);
17691 end if;
17693 when Formal_Kind =>
17694 if Present (Spec_Entity (E)) then
17695 U := Spec_Entity (E);
17696 end if;
17698 when others =>
17699 null;
17700 end case;
17702 return U;
17703 end Unique_Entity;
17705 -----------------
17706 -- Unique_Name --
17707 -----------------
17709 function Unique_Name (E : Entity_Id) return String is
17711 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17712 -- reliable, as they may not include the overloading suffix. Instead,
17713 -- when looking for the name of E or one of its enclosing scope, we get
17714 -- the name of the corresponding Unique_Entity.
17716 function Get_Scoped_Name (E : Entity_Id) return String;
17717 -- Return the name of E prefixed by all the names of the scopes to which
17718 -- E belongs, except for Standard.
17720 ---------------------
17721 -- Get_Scoped_Name --
17722 ---------------------
17724 function Get_Scoped_Name (E : Entity_Id) return String is
17725 Name : constant String := Get_Name_String (Chars (E));
17726 begin
17727 if Has_Fully_Qualified_Name (E)
17728 or else Scope (E) = Standard_Standard
17729 then
17730 return Name;
17731 else
17732 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
17733 end if;
17734 end Get_Scoped_Name;
17736 -- Start of processing for Unique_Name
17738 begin
17739 if E = Standard_Standard then
17740 return Get_Name_String (Name_Standard);
17742 elsif Scope (E) = Standard_Standard
17743 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
17744 then
17745 return Get_Name_String (Name_Standard) & "__" &
17746 Get_Name_String (Chars (E));
17748 elsif Ekind (E) = E_Enumeration_Literal then
17749 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
17751 else
17752 return Get_Scoped_Name (Unique_Entity (E));
17753 end if;
17754 end Unique_Name;
17756 ---------------------
17757 -- Unit_Is_Visible --
17758 ---------------------
17760 function Unit_Is_Visible (U : Entity_Id) return Boolean is
17761 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
17762 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
17764 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
17765 -- For a child unit, check whether unit appears in a with_clause
17766 -- of a parent.
17768 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
17769 -- Scan the context clause of one compilation unit looking for a
17770 -- with_clause for the unit in question.
17772 ----------------------------
17773 -- Unit_In_Parent_Context --
17774 ----------------------------
17776 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
17777 begin
17778 if Unit_In_Context (Par_Unit) then
17779 return True;
17781 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
17782 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
17784 else
17785 return False;
17786 end if;
17787 end Unit_In_Parent_Context;
17789 ---------------------
17790 -- Unit_In_Context --
17791 ---------------------
17793 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
17794 Clause : Node_Id;
17796 begin
17797 Clause := First (Context_Items (Comp_Unit));
17798 while Present (Clause) loop
17799 if Nkind (Clause) = N_With_Clause then
17800 if Library_Unit (Clause) = U then
17801 return True;
17803 -- The with_clause may denote a renaming of the unit we are
17804 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17806 elsif
17807 Renamed_Entity (Entity (Name (Clause))) =
17808 Defining_Entity (Unit (U))
17809 then
17810 return True;
17811 end if;
17812 end if;
17814 Next (Clause);
17815 end loop;
17817 return False;
17818 end Unit_In_Context;
17820 -- Start of processing for Unit_Is_Visible
17822 begin
17823 -- The currrent unit is directly visible
17825 if Curr = U then
17826 return True;
17828 elsif Unit_In_Context (Curr) then
17829 return True;
17831 -- If the current unit is a body, check the context of the spec
17833 elsif Nkind (Unit (Curr)) = N_Package_Body
17834 or else
17835 (Nkind (Unit (Curr)) = N_Subprogram_Body
17836 and then not Acts_As_Spec (Unit (Curr)))
17837 then
17838 if Unit_In_Context (Library_Unit (Curr)) then
17839 return True;
17840 end if;
17841 end if;
17843 -- If the spec is a child unit, examine the parents
17845 if Is_Child_Unit (Curr_Entity) then
17846 if Nkind (Unit (Curr)) in N_Unit_Body then
17847 return
17848 Unit_In_Parent_Context
17849 (Parent_Spec (Unit (Library_Unit (Curr))));
17850 else
17851 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
17852 end if;
17854 else
17855 return False;
17856 end if;
17857 end Unit_Is_Visible;
17859 ------------------------------
17860 -- Universal_Interpretation --
17861 ------------------------------
17863 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
17864 Index : Interp_Index;
17865 It : Interp;
17867 begin
17868 -- The argument may be a formal parameter of an operator or subprogram
17869 -- with multiple interpretations, or else an expression for an actual.
17871 if Nkind (Opnd) = N_Defining_Identifier
17872 or else not Is_Overloaded (Opnd)
17873 then
17874 if Etype (Opnd) = Universal_Integer
17875 or else Etype (Opnd) = Universal_Real
17876 then
17877 return Etype (Opnd);
17878 else
17879 return Empty;
17880 end if;
17882 else
17883 Get_First_Interp (Opnd, Index, It);
17884 while Present (It.Typ) loop
17885 if It.Typ = Universal_Integer
17886 or else It.Typ = Universal_Real
17887 then
17888 return It.Typ;
17889 end if;
17891 Get_Next_Interp (Index, It);
17892 end loop;
17894 return Empty;
17895 end if;
17896 end Universal_Interpretation;
17898 ---------------
17899 -- Unqualify --
17900 ---------------
17902 function Unqualify (Expr : Node_Id) return Node_Id is
17903 begin
17904 -- Recurse to handle unlikely case of multiple levels of qualification
17906 if Nkind (Expr) = N_Qualified_Expression then
17907 return Unqualify (Expression (Expr));
17909 -- Normal case, not a qualified expression
17911 else
17912 return Expr;
17913 end if;
17914 end Unqualify;
17916 -----------------------
17917 -- Visible_Ancestors --
17918 -----------------------
17920 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
17921 List_1 : Elist_Id;
17922 List_2 : Elist_Id;
17923 Elmt : Elmt_Id;
17925 begin
17926 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
17928 -- Collect all the parents and progenitors of Typ. If the full-view of
17929 -- private parents and progenitors is available then it is used to
17930 -- generate the list of visible ancestors; otherwise their partial
17931 -- view is added to the resulting list.
17933 Collect_Parents
17934 (T => Typ,
17935 List => List_1,
17936 Use_Full_View => True);
17938 Collect_Interfaces
17939 (T => Typ,
17940 Ifaces_List => List_2,
17941 Exclude_Parents => True,
17942 Use_Full_View => True);
17944 -- Join the two lists. Avoid duplications because an interface may
17945 -- simultaneously be parent and progenitor of a type.
17947 Elmt := First_Elmt (List_2);
17948 while Present (Elmt) loop
17949 Append_Unique_Elmt (Node (Elmt), List_1);
17950 Next_Elmt (Elmt);
17951 end loop;
17953 return List_1;
17954 end Visible_Ancestors;
17956 ----------------------
17957 -- Within_Init_Proc --
17958 ----------------------
17960 function Within_Init_Proc return Boolean is
17961 S : Entity_Id;
17963 begin
17964 S := Current_Scope;
17965 while not Is_Overloadable (S) loop
17966 if S = Standard_Standard then
17967 return False;
17968 else
17969 S := Scope (S);
17970 end if;
17971 end loop;
17973 return Is_Init_Proc (S);
17974 end Within_Init_Proc;
17976 ------------------
17977 -- Within_Scope --
17978 ------------------
17980 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
17981 SE : Entity_Id;
17982 begin
17983 SE := Scope (E);
17984 loop
17985 if SE = S then
17986 return True;
17987 elsif SE = Standard_Standard then
17988 return False;
17989 else
17990 SE := Scope (SE);
17991 end if;
17992 end loop;
17993 end Within_Scope;
17995 ----------------
17996 -- Wrong_Type --
17997 ----------------
17999 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
18000 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
18001 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
18003 Matching_Field : Entity_Id;
18004 -- Entity to give a more precise suggestion on how to write a one-
18005 -- element positional aggregate.
18007 function Has_One_Matching_Field return Boolean;
18008 -- Determines if Expec_Type is a record type with a single component or
18009 -- discriminant whose type matches the found type or is one dimensional
18010 -- array whose component type matches the found type. In the case of
18011 -- one discriminant, we ignore the variant parts. That's not accurate,
18012 -- but good enough for the warning.
18014 ----------------------------
18015 -- Has_One_Matching_Field --
18016 ----------------------------
18018 function Has_One_Matching_Field return Boolean is
18019 E : Entity_Id;
18021 begin
18022 Matching_Field := Empty;
18024 if Is_Array_Type (Expec_Type)
18025 and then Number_Dimensions (Expec_Type) = 1
18026 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
18027 then
18028 -- Use type name if available. This excludes multidimensional
18029 -- arrays and anonymous arrays.
18031 if Comes_From_Source (Expec_Type) then
18032 Matching_Field := Expec_Type;
18034 -- For an assignment, use name of target
18036 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
18037 and then Is_Entity_Name (Name (Parent (Expr)))
18038 then
18039 Matching_Field := Entity (Name (Parent (Expr)));
18040 end if;
18042 return True;
18044 elsif not Is_Record_Type (Expec_Type) then
18045 return False;
18047 else
18048 E := First_Entity (Expec_Type);
18049 loop
18050 if No (E) then
18051 return False;
18053 elsif not Ekind_In (E, E_Discriminant, E_Component)
18054 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
18055 then
18056 Next_Entity (E);
18058 else
18059 exit;
18060 end if;
18061 end loop;
18063 if not Covers (Etype (E), Found_Type) then
18064 return False;
18066 elsif Present (Next_Entity (E))
18067 and then (Ekind (E) = E_Component
18068 or else Ekind (Next_Entity (E)) = E_Discriminant)
18069 then
18070 return False;
18072 else
18073 Matching_Field := E;
18074 return True;
18075 end if;
18076 end if;
18077 end Has_One_Matching_Field;
18079 -- Start of processing for Wrong_Type
18081 begin
18082 -- Don't output message if either type is Any_Type, or if a message
18083 -- has already been posted for this node. We need to do the latter
18084 -- check explicitly (it is ordinarily done in Errout), because we
18085 -- are using ! to force the output of the error messages.
18087 if Expec_Type = Any_Type
18088 or else Found_Type = Any_Type
18089 or else Error_Posted (Expr)
18090 then
18091 return;
18093 -- If one of the types is a Taft-Amendment type and the other it its
18094 -- completion, it must be an illegal use of a TAT in the spec, for
18095 -- which an error was already emitted. Avoid cascaded errors.
18097 elsif Is_Incomplete_Type (Expec_Type)
18098 and then Has_Completion_In_Body (Expec_Type)
18099 and then Full_View (Expec_Type) = Etype (Expr)
18100 then
18101 return;
18103 elsif Is_Incomplete_Type (Etype (Expr))
18104 and then Has_Completion_In_Body (Etype (Expr))
18105 and then Full_View (Etype (Expr)) = Expec_Type
18106 then
18107 return;
18109 -- In an instance, there is an ongoing problem with completion of
18110 -- type derived from private types. Their structure is what Gigi
18111 -- expects, but the Etype is the parent type rather than the
18112 -- derived private type itself. Do not flag error in this case. The
18113 -- private completion is an entity without a parent, like an Itype.
18114 -- Similarly, full and partial views may be incorrect in the instance.
18115 -- There is no simple way to insure that it is consistent ???
18117 -- A similar view discrepancy can happen in an inlined body, for the
18118 -- same reason: inserted body may be outside of the original package
18119 -- and only partial views are visible at the point of insertion.
18121 elsif In_Instance or else In_Inlined_Body then
18122 if Etype (Etype (Expr)) = Etype (Expected_Type)
18123 and then
18124 (Has_Private_Declaration (Expected_Type)
18125 or else Has_Private_Declaration (Etype (Expr)))
18126 and then No (Parent (Expected_Type))
18127 then
18128 return;
18130 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
18131 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
18132 then
18133 return;
18135 elsif Is_Private_Type (Expected_Type)
18136 and then Present (Full_View (Expected_Type))
18137 and then Covers (Full_View (Expected_Type), Etype (Expr))
18138 then
18139 return;
18140 end if;
18141 end if;
18143 -- An interesting special check. If the expression is parenthesized
18144 -- and its type corresponds to the type of the sole component of the
18145 -- expected record type, or to the component type of the expected one
18146 -- dimensional array type, then assume we have a bad aggregate attempt.
18148 if Nkind (Expr) in N_Subexpr
18149 and then Paren_Count (Expr) /= 0
18150 and then Has_One_Matching_Field
18151 then
18152 Error_Msg_N ("positional aggregate cannot have one component", Expr);
18153 if Present (Matching_Field) then
18154 if Is_Array_Type (Expec_Type) then
18155 Error_Msg_NE
18156 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
18158 else
18159 Error_Msg_NE
18160 ("\write instead `& ='> ...`", Expr, Matching_Field);
18161 end if;
18162 end if;
18164 -- Another special check, if we are looking for a pool-specific access
18165 -- type and we found an E_Access_Attribute_Type, then we have the case
18166 -- of an Access attribute being used in a context which needs a pool-
18167 -- specific type, which is never allowed. The one extra check we make
18168 -- is that the expected designated type covers the Found_Type.
18170 elsif Is_Access_Type (Expec_Type)
18171 and then Ekind (Found_Type) = E_Access_Attribute_Type
18172 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
18173 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
18174 and then Covers
18175 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
18176 then
18177 Error_Msg_N -- CODEFIX
18178 ("result must be general access type!", Expr);
18179 Error_Msg_NE -- CODEFIX
18180 ("add ALL to }!", Expr, Expec_Type);
18182 -- Another special check, if the expected type is an integer type,
18183 -- but the expression is of type System.Address, and the parent is
18184 -- an addition or subtraction operation whose left operand is the
18185 -- expression in question and whose right operand is of an integral
18186 -- type, then this is an attempt at address arithmetic, so give
18187 -- appropriate message.
18189 elsif Is_Integer_Type (Expec_Type)
18190 and then Is_RTE (Found_Type, RE_Address)
18191 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
18192 and then Expr = Left_Opnd (Parent (Expr))
18193 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
18194 then
18195 Error_Msg_N
18196 ("address arithmetic not predefined in package System",
18197 Parent (Expr));
18198 Error_Msg_N
18199 ("\possible missing with/use of System.Storage_Elements",
18200 Parent (Expr));
18201 return;
18203 -- If the expected type is an anonymous access type, as for access
18204 -- parameters and discriminants, the error is on the designated types.
18206 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
18207 if Comes_From_Source (Expec_Type) then
18208 Error_Msg_NE ("expected}!", Expr, Expec_Type);
18209 else
18210 Error_Msg_NE
18211 ("expected an access type with designated}",
18212 Expr, Designated_Type (Expec_Type));
18213 end if;
18215 if Is_Access_Type (Found_Type)
18216 and then not Comes_From_Source (Found_Type)
18217 then
18218 Error_Msg_NE
18219 ("\\found an access type with designated}!",
18220 Expr, Designated_Type (Found_Type));
18221 else
18222 if From_Limited_With (Found_Type) then
18223 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
18224 Error_Msg_Qual_Level := 99;
18225 Error_Msg_NE -- CODEFIX
18226 ("\\missing `WITH &;", Expr, Scope (Found_Type));
18227 Error_Msg_Qual_Level := 0;
18228 else
18229 Error_Msg_NE ("found}!", Expr, Found_Type);
18230 end if;
18231 end if;
18233 -- Normal case of one type found, some other type expected
18235 else
18236 -- If the names of the two types are the same, see if some number
18237 -- of levels of qualification will help. Don't try more than three
18238 -- levels, and if we get to standard, it's no use (and probably
18239 -- represents an error in the compiler) Also do not bother with
18240 -- internal scope names.
18242 declare
18243 Expec_Scope : Entity_Id;
18244 Found_Scope : Entity_Id;
18246 begin
18247 Expec_Scope := Expec_Type;
18248 Found_Scope := Found_Type;
18250 for Levels in Int range 0 .. 3 loop
18251 if Chars (Expec_Scope) /= Chars (Found_Scope) then
18252 Error_Msg_Qual_Level := Levels;
18253 exit;
18254 end if;
18256 Expec_Scope := Scope (Expec_Scope);
18257 Found_Scope := Scope (Found_Scope);
18259 exit when Expec_Scope = Standard_Standard
18260 or else Found_Scope = Standard_Standard
18261 or else not Comes_From_Source (Expec_Scope)
18262 or else not Comes_From_Source (Found_Scope);
18263 end loop;
18264 end;
18266 if Is_Record_Type (Expec_Type)
18267 and then Present (Corresponding_Remote_Type (Expec_Type))
18268 then
18269 Error_Msg_NE ("expected}!", Expr,
18270 Corresponding_Remote_Type (Expec_Type));
18271 else
18272 Error_Msg_NE ("expected}!", Expr, Expec_Type);
18273 end if;
18275 if Is_Entity_Name (Expr)
18276 and then Is_Package_Or_Generic_Package (Entity (Expr))
18277 then
18278 Error_Msg_N ("\\found package name!", Expr);
18280 elsif Is_Entity_Name (Expr)
18281 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
18282 then
18283 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
18284 Error_Msg_N
18285 ("found procedure name, possibly missing Access attribute!",
18286 Expr);
18287 else
18288 Error_Msg_N
18289 ("\\found procedure name instead of function!", Expr);
18290 end if;
18292 elsif Nkind (Expr) = N_Function_Call
18293 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
18294 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
18295 and then No (Parameter_Associations (Expr))
18296 then
18297 Error_Msg_N
18298 ("found function name, possibly missing Access attribute!",
18299 Expr);
18301 -- Catch common error: a prefix or infix operator which is not
18302 -- directly visible because the type isn't.
18304 elsif Nkind (Expr) in N_Op
18305 and then Is_Overloaded (Expr)
18306 and then not Is_Immediately_Visible (Expec_Type)
18307 and then not Is_Potentially_Use_Visible (Expec_Type)
18308 and then not In_Use (Expec_Type)
18309 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
18310 then
18311 Error_Msg_N
18312 ("operator of the type is not directly visible!", Expr);
18314 elsif Ekind (Found_Type) = E_Void
18315 and then Present (Parent (Found_Type))
18316 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
18317 then
18318 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
18320 else
18321 Error_Msg_NE ("\\found}!", Expr, Found_Type);
18322 end if;
18324 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
18325 -- of the same modular type, and (M1 and M2) = 0 was intended.
18327 if Expec_Type = Standard_Boolean
18328 and then Is_Modular_Integer_Type (Found_Type)
18329 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
18330 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
18331 then
18332 declare
18333 Op : constant Node_Id := Right_Opnd (Parent (Expr));
18334 L : constant Node_Id := Left_Opnd (Op);
18335 R : constant Node_Id := Right_Opnd (Op);
18337 begin
18338 -- The case for the message is when the left operand of the
18339 -- comparison is the same modular type, or when it is an
18340 -- integer literal (or other universal integer expression),
18341 -- which would have been typed as the modular type if the
18342 -- parens had been there.
18344 if (Etype (L) = Found_Type
18345 or else
18346 Etype (L) = Universal_Integer)
18347 and then Is_Integer_Type (Etype (R))
18348 then
18349 Error_Msg_N
18350 ("\\possible missing parens for modular operation", Expr);
18351 end if;
18352 end;
18353 end if;
18355 -- Reset error message qualification indication
18357 Error_Msg_Qual_Level := 0;
18358 end if;
18359 end Wrong_Type;
18361 end Sem_Util;